Loading...
Searching...
No Matches
AudioPlaybackThread.h
Go to the documentation of this file.
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef OPENSHOT_AUDIO_PLAYBACK_THREAD_H
#define OPENSHOT_AUDIO_PLAYBACK_THREAD_H
#include "ReaderBase.h"
#include "RendererBase.h"
#include "AudioReaderSource.h"
#include "AudioDevices.h"
#include "AudioReaderSource.h"
#include "Qt/VideoCacheThread.h"
#include <OpenShotAudio.h>
#include <AppConfig.h>
#include <juce_audio_basics/juce_audio_basics.h>
#include <juce_audio_devices/juce_audio_devices.h>
namespace openshot
{
// Forward decls
class ReaderBase;
class Frame;
class PlayerPrivate;
class QtPlayer;
class AudioDeviceManagerSingleton {
private:
AudioDeviceManagerSingleton(){ initialise_error=""; };
static AudioDeviceManagerSingleton* m_pInstance;
public:
std::string initialise_error;
double defaultSampleRate;
AudioDeviceInfo currentAudioDevice;
static AudioDeviceManagerSingleton* Instance();
static AudioDeviceManagerSingleton* Instance(int rate, int channels);
juce::AudioDeviceManager audioDeviceManager;
void CloseAudioDevice();
};
class AudioPlaybackThread : juce::Thread
{
juce::AudioSourcePlayer player;
juce::AudioTransportSource transport;
juce::MixerAudioSource mixer;
AudioReaderSource *source;
double sampleRate;
int numChannels;
juce::WaitableEvent play;
bool is_playing;
juce::TimeSliceThread time_thread;
openshot::VideoCacheThread *videoCache;
std::mutex transportMutex;
std::condition_variable transportCondition;
AudioPlaybackThread(openshot::VideoCacheThread* cache);
~AudioPlaybackThread();
void NotifyTransportStateChanged();
void Reader(openshot::ReaderBase *reader);
std::shared_ptr<openshot::Frame> getFrame();
void Play();
void Seek(int64_t new_position);
void Stop();
void run();
void setSpeed(int new_speed) { if (source) source->setSpeed(new_speed); }
int getSpeed() const { if (source) return source->getSpeed(); else return 1; }
std::string getError()
{
return AudioDeviceManagerSingleton::Instance()->initialise_error;
}
double getDefaultSampleRate()
{
return AudioDeviceManagerSingleton::Instance()->defaultSampleRate;
}
AudioDeviceInfo getCurrentAudioDevice()
{
return AudioDeviceManagerSingleton::Instance()->currentAudioDevice;
}
AudioDeviceList getAudioDeviceNames()
{
AudioDevices devs;
return devs.getNames();
};
friend class PlayerPrivate;
friend class QtPlayer;
};
} // namespace openshot
#endif // OPENSHOT_AUDIO_PLAYBACK_THREAD_H
AudioDevices.h
Header file for Audio Device Info struct.
AudioReaderSource.h
Header file for AudioReaderSource class.
ReaderBase.h
Header file for ReaderBase class.
RendererBase.h
Header file for RendererBase class.
VideoCacheThread.h
Header file for VideoCacheThread class.
openshot::AudioDeviceManagerSingleton::defaultSampleRate
double defaultSampleRate
Default sample rate (as detected).
Definition AudioPlaybackThread.h:55
openshot::AudioDeviceManagerSingleton::CloseAudioDevice
void CloseAudioDevice()
Close audio device.
Definition AudioPlaybackThread.cpp:178
openshot::AudioDeviceManagerSingleton::Instance
static AudioDeviceManagerSingleton * Instance()
Override with default sample rate & channels (44100, 2) and no preferred audio device.
Definition AudioPlaybackThread.cpp:39
openshot::AudioDeviceManagerSingleton::audioDeviceManager
juce::AudioDeviceManager audioDeviceManager
Public device manager property.
Definition AudioPlaybackThread.h:68
openshot::AudioDeviceManagerSingleton::currentAudioDevice
AudioDeviceInfo currentAudioDevice
Current open audio device (or last attempted device - if none were successful).
Definition AudioPlaybackThread.h:58
openshot::AudioDeviceManagerSingleton::initialise_error
std::string initialise_error
Error found during JUCE initialise method.
Definition AudioPlaybackThread.h:52
openshot::AudioDevices
A class which probes the available audio devices.
Definition AudioDevices.h:46
openshot::AudioDevices::getNames
AudioDeviceList getNames()
Definition AudioDevices.cpp:21
openshot::AudioPlaybackThread::QtPlayer
friend class QtPlayer
Definition AudioPlaybackThread.h:150
openshot::AudioPlaybackThread::PlayerPrivate
friend class PlayerPrivate
Definition AudioPlaybackThread.h:149
openshot::AudioReaderSource
This class is used to expose any ReaderBase derived class as an AudioSource in JUCE.
Definition AudioReaderSource.h:32
openshot::Frame
This class represents a single frame of video (i.e. image & audio data).
Definition Frame.h:89
openshot::PlayerPrivate
The private part of QtPlayer class, which contains an audio thread and video thread,...
Definition PlayerPrivate.h:31
openshot::QtPlayer
This class is used to playback a video from a reader.
Definition QtPlayer.h:33
openshot::ReaderBase
This abstract class is the base class, used by all readers in libopenshot.
Definition ReaderBase.h:76
openshot::VideoCacheThread
Handles prefetching and caching of video/audio frames for smooth playback.
Definition VideoCacheThread.h:34
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
openshot::AudioDeviceList
std::vector< std::pair< std::string, std::string > > AudioDeviceList
Definition AudioDevices.h:42
openshot::AudioDeviceInfo
This struct hold information about Audio Devices.
Definition AudioDevices.h:27