OpenShot Library | libopenshot 0.2.7
AudioPlaybackThread.h
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Source file for AudioPlaybackThread class
4 * @author Duzy Chan <code@duzy.info>
5 * @author Jonathan Thomas <jonathan@openshot.org>
6 *
7 * @ref License
8 */
9
10/* LICENSE
11 *
12 * Copyright (c) 2008-2019 OpenShot Studios, LLC
13 * <http://www.openshotstudios.com/>. This file is part of
14 * OpenShot Library (libopenshot), an open-source project dedicated to
15 * delivering high quality video editing and animation solutions to the
16 * world. For more information visit <http://www.openshot.org/>.
17 *
18 * OpenShot Library (libopenshot) is free software: you can redistribute it
19 * and/or modify it under the terms of the GNU Lesser General Public License
20 * as published by the Free Software Foundation, either version 3 of the
21 * License, or (at your option) any later version.
22 *
23 * OpenShot Library (libopenshot) is distributed in the hope that it will be
24 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU Lesser General Public License for more details.
27 *
28 * You should have received a copy of the GNU Lesser General Public License
29 * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
30 */
31
32#ifndef OPENSHOT_AUDIO_PLAYBACK_THREAD_H
33#define OPENSHOT_AUDIO_PLAYBACK_THREAD_H
34
35#include "../ReaderBase.h"
36#include "../RendererBase.h"
37#include "../AudioReaderSource.h"
38#include "../AudioDeviceInfo.h"
39#include "../Settings.h"
40
41namespace openshot
42{
43
44 /**
45 * @brief Singleton wrapper for AudioDeviceManager (to prevent multiple instances).
46 */
48 private:
49 /// Default constructor (Don't allow user to create an instance of this singleton)
51
52 /// Private variable to keep track of singleton instance
53 static AudioDeviceManagerSingleton * m_pInstance;
54
55 public:
56 /// Error found during JUCE initialise method
57 std::string initialise_error;
58
59 /// List of valid audio device names
60 std::vector<openshot::AudioDeviceInfo> audio_device_names;
61
62 /// Override with no channels and no preferred audio device
64
65 /// Public device manager property
66 juce::AudioDeviceManager audioDeviceManager;
67
68 /// Close audio device
69 void CloseAudioDevice();
70 };
71
72 /**
73 * @brief The audio playback thread
74 */
75 class AudioPlaybackThread : juce::Thread
76 {
77 juce::AudioSourcePlayer player;
78 juce::AudioTransportSource transport;
79 juce::MixerAudioSource mixer;
80 AudioReaderSource *source;
81 double sampleRate;
82 int numChannels;
83 juce::WaitableEvent play;
84 juce::WaitableEvent played;
85 int buffer_size;
86 bool is_playing;
87 juce::TimeSliceThread time_thread;
88 /// Constructor
90 /// Destructor
92
93 /// Set the current thread's reader
94 void Reader(openshot::ReaderBase *reader);
95
96 /// Get the current frame object (which is filling the buffer)
97 std::shared_ptr<openshot::Frame> getFrame();
98
99 /// Get the current frame number being played
100 int64_t getCurrentFramePosition();
101
102 /// Play the audio
103 void Play();
104
105 /// Seek the audio thread
106 void Seek(int64_t new_position);
107
108 /// Stop the audio playback
109 void Stop();
110
111 /// Start thread
112 void run();
113
114 /// Set Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...)
115 void setSpeed(int new_speed) { if (source) source->setSpeed(new_speed); }
116
117 /// Get Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...)
118 int getSpeed() const { if (source) return source->getSpeed(); else return 1; }
119
120 /// Get Audio Error (if any)
121 std::string getError()
122 {
124 }
125
126 /// Get Audio Device Names (if any)
127 std::vector<openshot::AudioDeviceInfo> getAudioDeviceNames()
128 {
130 };
131
132 friend class PlayerPrivate;
133 friend class QtPlayer;
134 };
135
136}
137
138#endif // OPENSHOT_AUDIO_PLAYBACK_THREAD_H
Singleton wrapper for AudioDeviceManager (to prevent multiple instances).
void CloseAudioDevice()
Close audio device.
std::vector< openshot::AudioDeviceInfo > audio_device_names
List of valid audio device names.
static AudioDeviceManagerSingleton * Instance()
Override with no channels and no preferred audio device.
juce::AudioDeviceManager audioDeviceManager
Public device manager property.
std::string initialise_error
Error found during JUCE initialise method.
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:49
This class is used to playback a video from a reader.
Definition: QtPlayer.h:48
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:98
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:47