17#include "../ReaderBase.h"
18#include "../RendererBase.h"
19#include "../AudioReaderSource.h"
20#include "../AudioDevices.h"
21#include "../Settings.h"
32 AudioDeviceManagerSingleton *AudioDeviceManagerSingleton::m_pInstance = NULL;
43 static std::mutex mutex;
44 std::lock_guard<std::mutex> lock(mutex);
50 AudioIODevice *foundAudioIODevice = NULL;
61 if (requested_device.
type.isEmpty() && !requested_device.
name.isEmpty()) {
62 for (
const auto t : mgr->getAvailableDeviceTypes()) {
64 for (
const auto n : t->getDeviceNames()) {
65 if (requested_device.
name.trim().equalsIgnoreCase(n.trim())) {
66 requested_device.
type = t->getTypeName();
74 std::vector<openshot::AudioDeviceInfo> devices{ { requested_device } };
75 for (
const auto t : mgr->getAvailableDeviceTypes()) {
77 for (
const auto n : t->getDeviceNames()) {
79 devices.push_back(device);
84 for (
auto attempt_device : devices) {
91 if (!attempt_device.type.isEmpty()) {
96 AudioDeviceManager::AudioDeviceSetup deviceSetup = AudioDeviceManager::AudioDeviceSetup();
97 deviceSetup.inputChannels = 0;
98 deviceSetup.outputChannels = channels;
103 int possible_rates[] { rate, 48000, 44100, 22050 };
104 for(
int attempt_rate : possible_rates) {
107 deviceSetup.sampleRate = attempt_rate;
127 if (foundAudioIODevice && foundAudioIODevice->getCurrentSampleRate() == attempt_rate) {
133 if (foundAudioIODevice) {
157 :
juce::Thread(
"audio-playback")
165 , time_thread(
"audio-buffer")
171 AudioPlaybackThread::~AudioPlaybackThread()
181 auto starting_frame = 1;
182 source =
new AudioReaderSource(reader, starting_frame);
197 std::shared_ptr<openshot::Frame> AudioPlaybackThread::getFrame()
199 if (source)
return source->
getFrame();
200 return std::shared_ptr<openshot::Frame>();
204 void AudioPlaybackThread::Seek(int64_t new_position)
207 source->
Seek(new_position);
212 void AudioPlaybackThread::Play() {
218 void AudioPlaybackThread::Stop() {
224 void AudioPlaybackThread::run()
226 while (!threadShouldExit())
228 if (source && !transport.isPlaying() && is_playing) {
230 AudioDeviceManagerSingleton *audioInstance =
234 audioInstance->audioDeviceManager.addAudioCallback(&player);
237 time_thread.startThread();
246 transport.setPosition(0);
247 transport.setGain(1.0);
250 mixer.addInputSource(&transport,
false);
251 player.setSource(&mixer);
256 while (!threadShouldExit() && transport.isPlaying() && is_playing)
257 std::this_thread::sleep_for(std::chrono::milliseconds(2));
264 transport.setSource(NULL);
266 player.setSource(NULL);
267 audioInstance->audioDeviceManager.removeAudioCallback(&player);
274 time_thread.stopThread(-1);
Source file for AudioPlaybackThread class.
Header file for global Settings class.
Singleton wrapper for AudioDeviceManager (to prevent multiple instances).
double defaultSampleRate
Default sample rate (as detected)
void CloseAudioDevice()
Close audio device.
static AudioDeviceManagerSingleton * Instance()
Override with default sample rate & channels (44100, 2) and no preferred audio device.
juce::AudioDeviceManager audioDeviceManager
Public device manager property.
AudioDeviceInfo currentAudioDevice
Current open audio device (or last attempted device - if none were successful)
std::string initialise_error
Error found during JUCE initialise method.
void Seek(int64_t new_position)
Seek to a specific frame.
void Reader(ReaderBase *audio_reader)
Set Reader.
std::shared_ptr< Frame > getFrame() const
Return the current frame object.
void setVideoCache(openshot::VideoCacheThread *newCache)
Set playback video cache thread (for pre-roll reference)
This abstract class is the base class, used by all readers in libopenshot.
openshot::ReaderInfo info
Information about the current media file.
std::string PLAYBACK_AUDIO_DEVICE_NAME
The audio device name to use during playback.
std::string PLAYBACK_AUDIO_DEVICE_TYPE
The device type for the playback audio devices.
static Settings * Instance()
Create or get an instance of this logger singleton (invoke the class with this method)
This namespace is the default namespace for all code in the openshot library.
This struct hold information about Audio Devices.
int channels
The number of audio channels used in the audio stream.
int sample_rate
The number of audio samples per second (44100 is a common sample rate)