From 6aebb10cea6c4e0cf7abd43108d42340da8f82e3 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Sat, 21 Sep 2019 00:14:32 -0400 Subject: [PATCH] More explicit prefixing in Qt/ and Player classes --- include/PlayerBase.h | 2 +- include/Qt/AudioPlaybackThread.h | 35 ++-- include/Qt/PlayerDemo.h | 4 +- include/Qt/PlayerPrivate.h | 20 +- include/Qt/VideoRenderWidget.h | 2 +- include/QtPlayer.h | 5 +- src/PlayerBase.cpp | 4 +- src/Qt/AudioPlaybackThread.cpp | 12 +- src/Qt/PlayerDemo.cpp | 2 +- src/Qt/PlayerPrivate.cpp | 56 +++--- src/QtPlayer.cpp | 301 ++++++++++++++++--------------- 11 files changed, 222 insertions(+), 221 deletions(-) diff --git a/include/PlayerBase.h b/include/PlayerBase.h index a66458ed..aa34c5d2 100644 --- a/include/PlayerBase.h +++ b/include/PlayerBase.h @@ -94,7 +94,7 @@ namespace openshot virtual void Stop() = 0; /// Get the current reader, such as a FFmpegReader - virtual ReaderBase* Reader() = 0; + virtual openshot::ReaderBase* Reader() = 0; /// Set the current reader, such as a FFmpegReader virtual void Reader(openshot::ReaderBase *new_reader) = 0; diff --git a/include/Qt/AudioPlaybackThread.h b/include/Qt/AudioPlaybackThread.h index 54bd490b..348a0f48 100644 --- a/include/Qt/AudioPlaybackThread.h +++ b/include/Qt/AudioPlaybackThread.h @@ -40,16 +40,13 @@ namespace openshot { - using juce::Thread; - using juce::WaitableEvent; - - struct SafeTimeSliceThread : TimeSliceThread + struct SafeTimeSliceThread : juce::TimeSliceThread { - SafeTimeSliceThread(const String & s) : TimeSliceThread(s) {} + SafeTimeSliceThread(const String & s) : juce::TimeSliceThread(s) {} void run() { try { - TimeSliceThread::run(); + juce::TimeSliceThread::run(); } catch (const TooManySeeks & e) { // ... } @@ -72,7 +69,7 @@ namespace openshot std::string initialise_error; /// List of valid audio device names - std::vector audio_device_names; + std::vector audio_device_names; /// Override with no channels and no preferred audio device static AudioDeviceManagerSingleton * Instance(); @@ -87,7 +84,7 @@ namespace openshot /** * @brief The audio playback thread */ - class AudioPlaybackThread : Thread + class AudioPlaybackThread : juce::Thread { AudioSourcePlayer player; AudioTransportSource transport; @@ -95,8 +92,8 @@ namespace openshot AudioReaderSource *source; double sampleRate; int numChannels; - WaitableEvent play; - WaitableEvent played; + juce::WaitableEvent play; + juce::WaitableEvent played; int buffer_size; bool is_playing; SafeTimeSliceThread time_thread; @@ -107,10 +104,10 @@ namespace openshot ~AudioPlaybackThread(); /// Set the current thread's reader - void Reader(ReaderBase *reader); + void Reader(openshot::ReaderBase *reader); /// Get the current frame object (which is filling the buffer) - std::shared_ptr getFrame(); + std::shared_ptr getFrame(); /// Get the current frame number being played int64_t getCurrentFramePosition(); @@ -133,11 +130,17 @@ namespace openshot /// Get Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...) int getSpeed() const { if (source) return source->getSpeed(); else return 1; } - /// Get Audio Error (if any) - std::string getError() { return AudioDeviceManagerSingleton::Instance()->initialise_error; } + /// Get Audio Error (if any) + std::string getError() + { + return AudioDeviceManagerSingleton::Instance()->initialise_error; + } - /// Get Audio Device Names (if any) - std::vector getAudioDeviceNames() { return AudioDeviceManagerSingleton::Instance()->audio_device_names; }; + /// Get Audio Device Names (if any) + std::vector getAudioDeviceNames() + { + return AudioDeviceManagerSingleton::Instance()->audio_device_names; + }; friend class PlayerPrivate; friend class QtPlayer; diff --git a/include/Qt/PlayerDemo.h b/include/Qt/PlayerDemo.h index cfed78bd..f444334b 100644 --- a/include/Qt/PlayerDemo.h +++ b/include/Qt/PlayerDemo.h @@ -46,8 +46,6 @@ namespace openshot class QtPlayer; } -using openshot::QtPlayer; - class PlayerDemo : public QWidget { Q_OBJECT @@ -67,7 +65,7 @@ private: QVBoxLayout *vbox; QMenuBar *menu; VideoRenderWidget *video; - QtPlayer *player; + openshot::QtPlayer *player; }; #endif // OPENSHOT_PLAYER_H diff --git a/include/Qt/PlayerPrivate.h b/include/Qt/PlayerPrivate.h index f846fb2a..e403c10e 100644 --- a/include/Qt/PlayerPrivate.h +++ b/include/Qt/PlayerPrivate.h @@ -41,27 +41,25 @@ namespace openshot { - using juce::Thread; - /** * @brief The private part of QtPlayer class, which contains an audio thread and video thread, * and controls the video timing and audio synchronization code. */ - class PlayerPrivate : Thread + class PlayerPrivate : juce::Thread { - std::shared_ptr frame; /// The current frame + std::shared_ptr frame; /// The current frame int64_t video_position; /// The current frame position. int64_t audio_position; /// The current frame position. - ReaderBase *reader; /// The reader which powers this player - AudioPlaybackThread *audioPlayback; /// The audio thread - VideoPlaybackThread *videoPlayback; /// The video thread - VideoCacheThread *videoCache; /// The cache thread + openshot::ReaderBase *reader; /// The reader which powers this player + openshot::AudioPlaybackThread *audioPlayback; /// The audio thread + openshot::VideoPlaybackThread *videoPlayback; /// The video thread + openshot::VideoCacheThread *videoCache; /// The cache thread int speed; /// The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...) - RendererBase *renderer; + openshot::RendererBase *renderer; int64_t last_video_position; /// The last frame actually displayed /// Constructor - PlayerPrivate(RendererBase *rb); + PlayerPrivate(openshot::RendererBase *rb); /// Destructor virtual ~PlayerPrivate(); @@ -75,7 +73,7 @@ namespace openshot void stopPlayback(int timeOutMilliseconds = -1); /// Get the next frame (based on speed and direction) - std::shared_ptr getFrame(); + std::shared_ptr getFrame(); /// The parent class of PlayerPrivate friend class QtPlayer; diff --git a/include/Qt/VideoRenderWidget.h b/include/Qt/VideoRenderWidget.h index 429940e7..07c61037 100644 --- a/include/Qt/VideoRenderWidget.h +++ b/include/Qt/VideoRenderWidget.h @@ -60,7 +60,7 @@ protected: QRect centeredViewport(int width, int height); private slots: - void present(const QImage &image); + void present(const QImage &image); }; diff --git a/include/QtPlayer.h b/include/QtPlayer.h index 8bb77060..7ddf6ada 100644 --- a/include/QtPlayer.h +++ b/include/QtPlayer.h @@ -44,9 +44,9 @@ namespace openshot * @brief This class is used to playback a video from a reader. * */ - class QtPlayer : public PlayerBase + class QtPlayer : public openshot::PlayerBase { - PlayerPrivate *p; + openshot::PlayerPrivate *p; bool threads_started; public: @@ -116,7 +116,6 @@ namespace openshot /// Set the Volume (1.0 = normal volume, <1.0 = quieter, >1.0 louder) void Volume(float new_volume); }; - } #endif diff --git a/src/PlayerBase.cpp b/src/PlayerBase.cpp index 3c904afd..f152fbbb 100644 --- a/src/PlayerBase.cpp +++ b/src/PlayerBase.cpp @@ -63,12 +63,12 @@ void PlayerBase::Stop() { } // Get the current reader, such as a FFmpegReader -ReaderBase* PlayerBase::Reader() { +openshot::ReaderBase* PlayerBase::Reader() { return reader; } // Set the current reader, such as a FFmpegReader -void PlayerBase::Reader(ReaderBase *new_reader) { +void PlayerBase::Reader(openshot::ReaderBase *new_reader) { reader = new_reader; } diff --git a/src/Qt/AudioPlaybackThread.cpp b/src/Qt/AudioPlaybackThread.cpp index 7a6e4569..44c837e7 100644 --- a/src/Qt/AudioPlaybackThread.cpp +++ b/src/Qt/AudioPlaybackThread.cpp @@ -66,13 +66,13 @@ namespace openshot for (int i = 0; i < m_pInstance->audioDeviceManager.getAvailableDeviceTypes().size(); ++i) { const AudioIODeviceType* t = m_pInstance->audioDeviceManager.getAvailableDeviceTypes()[i]; - const StringArray deviceNames = t->getDeviceNames (); + const juce::StringArray deviceNames = t->getDeviceNames (); for (int j = 0; j < deviceNames.size (); ++j ) { juce::String deviceName = deviceNames[j]; juce::String typeName = t->getTypeName(); - AudioDeviceInfo deviceInfo = {deviceName.toRawUTF8(), typeName.toRawUTF8()}; + openshot::AudioDeviceInfo deviceInfo = {deviceName.toRawUTF8(), typeName.toRawUTF8()}; m_pInstance->audio_device_names.push_back(deviceInfo); } } @@ -92,7 +92,7 @@ namespace openshot // Constructor AudioPlaybackThread::AudioPlaybackThread() - : Thread("audio-playback") + : juce::Thread("audio-playback") , player() , transport() , mixer() @@ -111,7 +111,7 @@ namespace openshot } // Set the reader object - void AudioPlaybackThread::Reader(ReaderBase *reader) { + void AudioPlaybackThread::Reader(openshot::ReaderBase *reader) { if (source) source->Reader(reader); else { @@ -132,10 +132,10 @@ namespace openshot } // Get the current frame object (which is filling the buffer) - std::shared_ptr AudioPlaybackThread::getFrame() + std::shared_ptr AudioPlaybackThread::getFrame() { if (source) return source->getFrame(); - return std::shared_ptr(); + return std::shared_ptr(); } // Get the currently playing frame number diff --git a/src/Qt/PlayerDemo.cpp b/src/Qt/PlayerDemo.cpp index 9b369b6d..ba20e5cf 100644 --- a/src/Qt/PlayerDemo.cpp +++ b/src/Qt/PlayerDemo.cpp @@ -39,7 +39,7 @@ PlayerDemo::PlayerDemo(QWidget *parent) , vbox(new QVBoxLayout(this)) , menu(new QMenuBar(this)) , video(new VideoRenderWidget(this)) - , player(new QtPlayer(video->GetRenderer())) + , player(new openshot::QtPlayer(video->GetRenderer())) { setWindowTitle("OpenShot Player"); diff --git a/src/Qt/PlayerPrivate.cpp b/src/Qt/PlayerPrivate.cpp index d0f17842..e7c881f8 100644 --- a/src/Qt/PlayerPrivate.cpp +++ b/src/Qt/PlayerPrivate.cpp @@ -33,22 +33,22 @@ namespace openshot { - // Constructor - PlayerPrivate::PlayerPrivate(RendererBase *rb) - : renderer(rb), Thread("player"), video_position(1), audio_position(0) - , audioPlayback(new AudioPlaybackThread()) - , videoPlayback(new VideoPlaybackThread(rb)) - , videoCache(new VideoCacheThread()) + // Constructor + PlayerPrivate::PlayerPrivate(openshot::RendererBase *rb) + : renderer(rb), Thread("player"), video_position(1), audio_position(0) + , audioPlayback(new openshot::AudioPlaybackThread()) + , videoPlayback(new openshot::VideoPlaybackThread(rb)) + , videoCache(new openshot::VideoCacheThread()) , speed(1), reader(NULL), last_video_position(1) { } // Destructor PlayerPrivate::~PlayerPrivate() { - stopPlayback(1000); - delete audioPlayback; - delete videoCache; - delete videoPlayback; + stopPlayback(1000); + delete audioPlayback; + delete videoCache; + delete videoPlayback; } // Start thread @@ -138,7 +138,7 @@ namespace openshot } // Get the next displayed frame (based on speed and direction) - std::shared_ptr PlayerPrivate::getFrame() + std::shared_ptr PlayerPrivate::getFrame() { try { // Get the next frame (based on speed) @@ -158,35 +158,33 @@ namespace openshot return reader->GetFrame(video_position); } - } catch (const ReaderClosed & e) { - // ... - } catch (const TooManySeeks & e) { - // ... - } catch (const OutOfBoundsFrame & e) { - // ... - } - return std::shared_ptr(); + } catch (const ReaderClosed & e) { + // ... + } catch (const TooManySeeks & e) { + // ... + } catch (const OutOfBoundsFrame & e) { + // ... + } + return std::shared_ptr(); } // Start video/audio playback bool PlayerPrivate::startPlayback() { - if (video_position < 0) return false; + if (video_position < 0) return false; - stopPlayback(-1); - startThread(1); - return true; + stopPlayback(-1); + startThread(1); + return true; } // Stop video/audio playback void PlayerPrivate::stopPlayback(int timeOutMilliseconds) { - if (isThreadRunning()) stopThread(timeOutMilliseconds); - if (audioPlayback->isThreadRunning() && reader->info.has_audio) audioPlayback->stopThread(timeOutMilliseconds); - if (videoCache->isThreadRunning() && reader->info.has_video) videoCache->stopThread(timeOutMilliseconds); - if (videoPlayback->isThreadRunning() && reader->info.has_video) videoPlayback->stopThread(timeOutMilliseconds); - + if (isThreadRunning()) stopThread(timeOutMilliseconds); + if (audioPlayback->isThreadRunning() && reader->info.has_audio) audioPlayback->stopThread(timeOutMilliseconds); + if (videoCache->isThreadRunning() && reader->info.has_video) videoCache->stopThread(timeOutMilliseconds); + if (videoPlayback->isThreadRunning() && reader->info.has_video) videoPlayback->stopThread(timeOutMilliseconds); } - } diff --git a/src/QtPlayer.cpp b/src/QtPlayer.cpp index dc43b3d5..e4d862d1 100644 --- a/src/QtPlayer.cpp +++ b/src/QtPlayer.cpp @@ -36,184 +36,189 @@ #include "../include/Qt/PlayerPrivate.h" #include "../include/Qt/VideoRenderer.h" -using namespace openshot; - -QtPlayer::QtPlayer() : PlayerBase(), p(new PlayerPrivate(new VideoRenderer())), threads_started(false) +namespace openshot { - reader = NULL; -} + // Delegating constructor + QtPlayer::QtPlayer() + : QtPlayer::QtPlayer(new VideoRenderer()) + { } -QtPlayer::QtPlayer(RendererBase *rb) : PlayerBase(), p(new PlayerPrivate(rb)), threads_started(false) -{ - reader = NULL; -} + // Constructor + QtPlayer::QtPlayer(openshot::RendererBase *rb) + : PlayerBase() + , p(new openshot::PlayerPrivate(rb)) + , threads_started(false) + { + reader = NULL; + } -QtPlayer::~QtPlayer() -{ - if (mode != PLAYBACK_STOPPED) - Stop(); + QtPlayer::~QtPlayer() + { + if (mode != PLAYBACK_STOPPED) + Stop(); - delete p; -} + delete p; + } -void QtPlayer::CloseAudioDevice() -{ - // Close audio device (only do this once, when all audio playback is finished) - AudioDeviceManagerSingleton::Instance()->CloseAudioDevice(); -} + void QtPlayer::CloseAudioDevice() + { + // Close audio device (only do this once, when all audio playback is finished) + openshot::AudioDeviceManagerSingleton::Instance()->CloseAudioDevice(); + } -// Return any error string during initialization -std::string QtPlayer::GetError() { - if (reader && threads_started) { - // Get error from audio thread (if any) - return p->audioPlayback->getError(); - } else { - return ""; - } -} + // Return any error string during initialization + std::string QtPlayer::GetError() { + if (reader && threads_started) { + // Get error from audio thread (if any) + return p->audioPlayback->getError(); + } else { + return ""; + } + } -/// Get Audio Devices from JUCE -std::vector QtPlayer::GetAudioDeviceNames() { - if (reader && threads_started) { - return p->audioPlayback->getAudioDeviceNames(); - } else { - return std::vector(); - } -} + /// Get Audio Devices from JUCE + std::vector QtPlayer::GetAudioDeviceNames() { + if (reader && threads_started) { + return p->audioPlayback->getAudioDeviceNames(); + } else { + return std::vector(); + } + } -void QtPlayer::SetSource(const std::string &source) -{ - FFmpegReader *ffreader = new FFmpegReader(source); - ffreader->DisplayInfo(); + void QtPlayer::SetSource(const std::string &source) + { + FFmpegReader *ffreader = new FFmpegReader(source); + ffreader->DisplayInfo(); - reader = new Timeline(ffreader->info.width, ffreader->info.height, ffreader->info.fps, ffreader->info.sample_rate, ffreader->info.channels, ffreader->info.channel_layout); - Clip *c = new Clip(source); + reader = new Timeline(ffreader->info.width, ffreader->info.height, ffreader->info.fps, ffreader->info.sample_rate, ffreader->info.channels, ffreader->info.channel_layout); + Clip *c = new Clip(source); - Timeline* tm = (Timeline*)reader; - tm->AddClip(c); - tm->Open(); + Timeline* tm = (Timeline*)reader; + tm->AddClip(c); + tm->Open(); - // Set the reader - Reader(reader); -} + // Set the reader + Reader(reader); + } -void QtPlayer::Play() -{ - // Set mode to playing, and speed to normal - mode = PLAYBACK_PLAY; - Speed(1); + void QtPlayer::Play() + { + // Set mode to playing, and speed to normal + mode = PLAYBACK_PLAY; + Speed(1); - if (reader && !threads_started) { - // Start thread only once - p->startPlayback(); - threads_started = true; - } -} + if (reader && !threads_started) { + // Start thread only once + p->startPlayback(); + threads_started = true; + } + } -void QtPlayer::Loading() -{ - mode = PLAYBACK_LOADING; -} + void QtPlayer::Loading() + { + mode = PLAYBACK_LOADING; + } -/// Get the current mode -PlaybackMode QtPlayer::Mode() -{ - return mode; -} + /// Get the current mode + openshot::PlaybackMode QtPlayer::Mode() + { + return mode; + } -void QtPlayer::Pause() -{ - mode = PLAYBACK_PAUSED; - Speed(0); -} + void QtPlayer::Pause() + { + mode = PLAYBACK_PAUSED; + Speed(0); + } -int64_t QtPlayer::Position() -{ - return p->video_position; -} + int64_t QtPlayer::Position() + { + return p->video_position; + } -void QtPlayer::Seek(int64_t new_frame) -{ - // Check for seek - if (reader && threads_started && new_frame > 0) { - // Notify cache thread that seek has occurred - p->videoCache->Seek(new_frame); + void QtPlayer::Seek(int64_t new_frame) + { + // Check for seek + if (reader && threads_started && new_frame > 0) { + // Notify cache thread that seek has occurred + p->videoCache->Seek(new_frame); - // Update current position - p->video_position = new_frame; + // Update current position + p->video_position = new_frame; - // Clear last position (to force refresh) - p->last_video_position = 0; + // Clear last position (to force refresh) + p->last_video_position = 0; - // Notify audio thread that seek has occurred - p->audioPlayback->Seek(new_frame); - } -} + // Notify audio thread that seek has occurred + p->audioPlayback->Seek(new_frame); + } + } -void QtPlayer::Stop() -{ - // Change mode to stopped - mode = PLAYBACK_STOPPED; + void QtPlayer::Stop() + { + // Change mode to stopped + mode = PLAYBACK_STOPPED; - // Notify threads of stopping - if (reader && threads_started) { - p->videoCache->Stop(); - p->audioPlayback->Stop(); + // Notify threads of stopping + if (reader && threads_started) { + p->videoCache->Stop(); + p->audioPlayback->Stop(); - // Kill all threads - p->stopPlayback(); - } + // Kill all threads + p->stopPlayback(); + } - p->video_position = 0; - threads_started = false; -} + p->video_position = 0; + threads_started = false; + } -// Set the reader object -void QtPlayer::Reader(ReaderBase *new_reader) -{ - // Set new reader. Note: Be sure to close and dispose of the old reader after calling this - reader = new_reader; - p->reader = new_reader; - p->videoCache->Reader(new_reader); - p->audioPlayback->Reader(new_reader); -} + // Set the reader object + void QtPlayer::Reader(openshot::ReaderBase *new_reader) + { + // Set new reader. Note: Be sure to close and dispose of the old reader after calling this + reader = new_reader; + p->reader = new_reader; + p->videoCache->Reader(new_reader); + p->audioPlayback->Reader(new_reader); + } -// Get the current reader, such as a FFmpegReader -ReaderBase* QtPlayer::Reader() { - return reader; -} + // Get the current reader, such as a FFmpegReader + openshot::ReaderBase* QtPlayer::Reader() { + return reader; + } -// Set the QWidget pointer to display the video on (as a LONG pointer id) -void QtPlayer::SetQWidget(int64_t qwidget_address) { - // Update override QWidget address on the video renderer - p->renderer->OverrideWidget(qwidget_address); -} + // Set the QWidget pointer to display the video on (as a LONG pointer id) + void QtPlayer::SetQWidget(int64_t qwidget_address) { + // Update override QWidget address on the video renderer + p->renderer->OverrideWidget(qwidget_address); + } -// Get the Renderer pointer address (for Python to cast back into a QObject) -int64_t QtPlayer::GetRendererQObject() { - return (int64_t)(VideoRenderer*)p->renderer; -} + // Get the Renderer pointer address (for Python to cast back into a QObject) + int64_t QtPlayer::GetRendererQObject() { + return (int64_t)(VideoRenderer*)p->renderer; + } -// Get the Playback speed -float QtPlayer::Speed() { - return speed; -} + // Get the Playback speed + float QtPlayer::Speed() { + return speed; + } -// Set the Playback speed multiplier (1.0 = normal speed, <1.0 = slower, >1.0 faster) -void QtPlayer::Speed(float new_speed) { - speed = new_speed; - p->speed = new_speed; - p->videoCache->setSpeed(new_speed); - if (p->reader->info.has_audio) - p->audioPlayback->setSpeed(new_speed); -} + // Set the Playback speed multiplier (1.0 = normal speed, <1.0 = slower, >1.0 faster) + void QtPlayer::Speed(float new_speed) { + speed = new_speed; + p->speed = new_speed; + p->videoCache->setSpeed(new_speed); + if (p->reader->info.has_audio) + p->audioPlayback->setSpeed(new_speed); + } -// Get the Volume -float QtPlayer::Volume() { - return volume; -} + // Get the Volume + float QtPlayer::Volume() { + return volume; + } -// Set the Volume multiplier (1.0 = normal volume, <1.0 = quieter, >1.0 louder) -void QtPlayer::Volume(float new_volume) { - volume = new_volume; -} + // Set the Volume multiplier (1.0 = normal volume, <1.0 = quieter, >1.0 louder) + void QtPlayer::Volume(float new_volume) { + volume = new_volume; + } +} \ No newline at end of file