OpenShot Library | libopenshot  0.3.0
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 
42 private:
45 
47  static AudioDeviceManagerSingleton* m_pInstance;
48 
49 public:
51  std::string initialise_error;
52 
55 
58 
61  static AudioDeviceManagerSingleton* Instance(int rate, int channels);
62 
64  juce::AudioDeviceManager audioDeviceManager;
65 
67  void CloseAudioDevice();
68  };
69 
73  class AudioPlaybackThread : juce::Thread
74  {
75  juce::AudioSourcePlayer player;
76  juce::AudioTransportSource transport;
77  juce::MixerAudioSource mixer;
78  AudioReaderSource *source;
79  double sampleRate;
80  int numChannels;
81  juce::WaitableEvent play;
82  bool is_playing;
83  juce::TimeSliceThread time_thread;
84  openshot::VideoCacheThread *videoCache;
85 
90 
92  void Reader(openshot::ReaderBase *reader);
93 
95  std::shared_ptr<openshot::Frame> getFrame();
96 
98  void Play();
99 
101  void Seek(int64_t new_position);
102 
104  void Stop();
105 
107  void run();
108 
110  void setSpeed(int new_speed) { if (source) source->setSpeed(new_speed); }
111 
113  int getSpeed() const { if (source) return source->getSpeed(); else return 1; }
114 
116  std::string getError()
117  {
119  }
120 
122  double getDefaultSampleRate()
123  {
125  }
126 
128  std::vector<std::pair<std::string, std::string>> getAudioDeviceNames()
129  {
130  AudioDevices devs;
131  return devs.getNames();
132  };
133 
134  friend class PlayerPrivate;
135  friend class QtPlayer;
136 };
137 
138 } // namespace openshot
139 
140 #endif // OPENSHOT_AUDIO_PLAYBACK_THREAD_H
Header file for Audio Device Info struct.
Header file for AudioReaderSource class.
Header file for ReaderBase class.
Header file for RendererBase class.
Source file for VideoCacheThread class.
Singleton wrapper for AudioDeviceManager (to prevent multiple instances).
double defaultSampleRate
Default sample rate (as detected)
static AudioDeviceManagerSingleton * Instance()
Override with default sample rate & channels (44100, 2) and no preferred audio device.
juce::AudioDeviceManager audioDeviceManager
Public device manager property.
std::string initialise_error
Error found during JUCE initialise method.
A class which probes the available audio devices.
Definition: AudioDevices.h:35
AudioDeviceList getNames()
The audio playback thread.
This class is used to expose any ReaderBase derived class as an AudioSource in JUCE.
int getSpeed() const
Get Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster,...
void setSpeed(int new_speed)
Set Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster,...
The private part of QtPlayer class, which contains an audio thread and video thread,...
Definition: PlayerPrivate.h:31
This class is used to playback a video from a reader.
Definition: QtPlayer.h:33
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:76
The video cache class.
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:29