OpenShot Library | libopenshot  0.3.1
AudioPlaybackThread.h
Go to the documentation of this file.
1 
10 // Copyright (c) 2008-2019 OpenShot Studios, LLC
11 //
12 // SPDX-License-Identifier: LGPL-3.0-or-later
13 
14 #ifndef OPENSHOT_AUDIO_PLAYBACK_THREAD_H
15 #define OPENSHOT_AUDIO_PLAYBACK_THREAD_H
16 
17 #include "ReaderBase.h"
18 #include "RendererBase.h"
19 #include "AudioReaderSource.h"
20 #include "AudioDevices.h"
21 #include "AudioReaderSource.h"
22 #include "Qt/VideoCacheThread.h"
23 
24 #include <OpenShotAudio.h>
25 #include <AppConfig.h>
26 #include <juce_audio_basics/juce_audio_basics.h>
27 #include <juce_audio_devices/juce_audio_devices.h>
28 
29 namespace openshot
30 {
31 
32 // Forward decls
33 class ReaderBase;
34 class Frame;
35 class PlayerPrivate;
36 class QtPlayer;
37 
38 
43 private:
46 
48  static AudioDeviceManagerSingleton* m_pInstance;
49 
50 public:
52  std::string initialise_error;
53 
56 
59 
62 
65  static AudioDeviceManagerSingleton* Instance(int rate, int channels);
66 
68  juce::AudioDeviceManager audioDeviceManager;
69 
71  void CloseAudioDevice();
72  };
73 
77  class AudioPlaybackThread : juce::Thread
78  {
79  juce::AudioSourcePlayer player;
80  juce::AudioTransportSource transport;
81  juce::MixerAudioSource mixer;
82  AudioReaderSource *source;
83  double sampleRate;
84  int numChannels;
85  juce::WaitableEvent play;
86  bool is_playing;
87  juce::TimeSliceThread time_thread;
88  openshot::VideoCacheThread *videoCache;
89 
94 
96  void Reader(openshot::ReaderBase *reader);
97 
99  std::shared_ptr<openshot::Frame> getFrame();
100 
102  void Play();
103 
105  void Seek(int64_t new_position);
106 
108  void Stop();
109 
111  void run();
112 
114  void setSpeed(int new_speed) { if (source) source->setSpeed(new_speed); }
115 
117  int getSpeed() const { if (source) return source->getSpeed(); else return 1; }
118 
120  std::string getError()
121  {
123  }
124 
126  double getDefaultSampleRate()
127  {
129  }
130 
132  AudioDeviceInfo getCurrentAudioDevice()
133  {
135  }
136 
138  AudioDeviceList getAudioDeviceNames()
139  {
140  AudioDevices devs;
141  return devs.getNames();
142  };
143 
144  friend class PlayerPrivate;
145  friend class QtPlayer;
146 };
147 
148 } // namespace openshot
149 
150 #endif // OPENSHOT_AUDIO_PLAYBACK_THREAD_H
std::vector< std::pair< std::string, std::string > > AudioDeviceList
Definition: AudioDevices.h:42
static AudioDeviceManagerSingleton * Instance()
Override with default sample rate & channels (44100, 2) and no preferred audio device.
juce::AudioDeviceManager audioDeviceManager
Public device manager property.
Source file for VideoCacheThread class.
The video cache class.
void CloseAudioDevice()
Close audio device.
Header file for ReaderBase class.
This class is used to playback a video from a reader.
Definition: QtPlayer.h:32
int getSpeed() const
Get Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...)
The audio playback thread.
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:75
std::string initialise_error
Error found during JUCE initialise method.
The private part of QtPlayer class, which contains an audio thread and video thread, and controls the video timing and audio synchronization code.
Definition: PlayerPrivate.h:30
double defaultSampleRate
Default sample rate (as detected)
This class is used to expose any ReaderBase derived class as an AudioSource in JUCE.
Header file for AudioReaderSource class.
Header file for Audio Device Info struct.
AudioDeviceInfo currentAudioDevice
Current open audio device (or last attempted device - if none were successful)
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
Header file for RendererBase class.
Singleton wrapper for AudioDeviceManager (to prevent multiple instances).
AudioDeviceList getNames()
A class which probes the available audio devices.
Definition: AudioDevices.h:45
void setSpeed(int new_speed)
Set Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...)
This struct hold information about Audio Devices.
Definition: AudioDevices.h:26