2013-09-12 17:52:10 -05:00
|
|
|
/**
|
|
|
|
|
* @file
|
2013-11-06 23:17:35 -06:00
|
|
|
* @brief Source file for QtPlayer class
|
2014-01-25 03:38:38 +08:00
|
|
|
* @author Duzy Chan <code@duzy.info>
|
2014-03-21 01:25:17 -05:00
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* LICENSE
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2019-06-11 06:48:32 -04:00
|
|
|
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
2014-03-29 18:49:22 -05:00
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
2014-07-11 16:52:14 -05:00
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-07-11 16:52:14 -05:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-07-11 16:52:14 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-12 17:52:10 -05:00
|
|
|
*/
|
|
|
|
|
|
2020-10-18 07:43:37 -04:00
|
|
|
#include "Clip.h"
|
|
|
|
|
#include "FFmpegReader.h"
|
|
|
|
|
#include "Timeline.h"
|
|
|
|
|
#include "QtPlayer.h"
|
|
|
|
|
#include "Qt/PlayerPrivate.h"
|
|
|
|
|
#include "Qt/VideoRenderer.h"
|
2011-10-11 08:44:27 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
namespace openshot
|
2014-03-30 23:21:30 -05:00
|
|
|
{
|
2019-09-21 00:14:32 -04:00
|
|
|
// Delegating constructor
|
|
|
|
|
QtPlayer::QtPlayer()
|
|
|
|
|
: QtPlayer::QtPlayer(new VideoRenderer())
|
|
|
|
|
{ }
|
2014-03-30 23:21:30 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// Constructor
|
|
|
|
|
QtPlayer::QtPlayer(openshot::RendererBase *rb)
|
|
|
|
|
: PlayerBase()
|
|
|
|
|
, p(new openshot::PlayerPrivate(rb))
|
|
|
|
|
, threads_started(false)
|
|
|
|
|
{
|
|
|
|
|
reader = NULL;
|
|
|
|
|
}
|
2011-10-11 08:44:27 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
QtPlayer::~QtPlayer()
|
|
|
|
|
{
|
|
|
|
|
if (mode != PLAYBACK_STOPPED)
|
|
|
|
|
Stop();
|
2017-03-21 14:38:42 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
delete p;
|
|
|
|
|
}
|
2011-10-11 08:44:27 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
void QtPlayer::CloseAudioDevice()
|
|
|
|
|
{
|
|
|
|
|
// Close audio device (only do this once, when all audio playback is finished)
|
|
|
|
|
openshot::AudioDeviceManagerSingleton::Instance()->CloseAudioDevice();
|
|
|
|
|
}
|
2017-03-26 23:51:03 -07:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// 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 "";
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-04 00:55:47 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
/// Get Audio Devices from JUCE
|
|
|
|
|
std::vector<openshot::AudioDeviceInfo> QtPlayer::GetAudioDeviceNames() {
|
|
|
|
|
if (reader && threads_started) {
|
|
|
|
|
return p->audioPlayback->getAudioDeviceNames();
|
|
|
|
|
} else {
|
|
|
|
|
return std::vector<openshot::AudioDeviceInfo>();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-23 16:45:02 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
void QtPlayer::SetSource(const std::string &source)
|
|
|
|
|
{
|
|
|
|
|
FFmpegReader *ffreader = new FFmpegReader(source);
|
|
|
|
|
ffreader->DisplayInfo();
|
2016-01-05 01:59:50 -06:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
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);
|
2016-01-05 01:59:50 -06:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
Timeline* tm = (Timeline*)reader;
|
|
|
|
|
tm->AddClip(c);
|
|
|
|
|
tm->Open();
|
2015-06-01 00:20:14 -07:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// Set the reader
|
|
|
|
|
Reader(reader);
|
|
|
|
|
}
|
2011-10-11 08:44:27 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
void QtPlayer::Play()
|
|
|
|
|
{
|
|
|
|
|
// Set mode to playing, and speed to normal
|
|
|
|
|
mode = PLAYBACK_PLAY;
|
|
|
|
|
Speed(1);
|
2015-02-04 23:56:43 -06:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
if (reader && !threads_started) {
|
|
|
|
|
// Start thread only once
|
|
|
|
|
p->startPlayback();
|
|
|
|
|
threads_started = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-25 03:38:38 +08:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
void QtPlayer::Loading()
|
|
|
|
|
{
|
|
|
|
|
mode = PLAYBACK_LOADING;
|
|
|
|
|
}
|
2014-01-25 03:38:38 +08:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
/// Get the current mode
|
|
|
|
|
openshot::PlaybackMode QtPlayer::Mode()
|
|
|
|
|
{
|
|
|
|
|
return mode;
|
|
|
|
|
}
|
2014-03-23 01:12:29 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
void QtPlayer::Pause()
|
|
|
|
|
{
|
|
|
|
|
mode = PLAYBACK_PAUSED;
|
|
|
|
|
Speed(0);
|
|
|
|
|
}
|
2014-01-25 03:38:38 +08:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
int64_t QtPlayer::Position()
|
|
|
|
|
{
|
|
|
|
|
return p->video_position;
|
|
|
|
|
}
|
2014-01-25 03:38:38 +08:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
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);
|
2015-06-01 00:20:14 -07:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// Update current position
|
|
|
|
|
p->video_position = new_frame;
|
2014-04-02 16:48:27 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// Clear last position (to force refresh)
|
|
|
|
|
p->last_video_position = 0;
|
2015-06-01 00:20:14 -07:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// Notify audio thread that seek has occurred
|
|
|
|
|
p->audioPlayback->Seek(new_frame);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-25 03:38:38 +08:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
void QtPlayer::Stop()
|
|
|
|
|
{
|
|
|
|
|
// Change mode to stopped
|
|
|
|
|
mode = PLAYBACK_STOPPED;
|
2015-12-04 01:10:40 -06:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// Notify threads of stopping
|
|
|
|
|
if (reader && threads_started) {
|
|
|
|
|
p->videoCache->Stop();
|
|
|
|
|
p->audioPlayback->Stop();
|
2015-12-04 01:10:40 -06:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// Kill all threads
|
|
|
|
|
p->stopPlayback();
|
|
|
|
|
}
|
2015-12-04 01:10:40 -06:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
p->video_position = 0;
|
|
|
|
|
threads_started = false;
|
|
|
|
|
}
|
2014-03-23 01:12:29 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// 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);
|
|
|
|
|
}
|
2014-03-23 01:12:29 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// Get the current reader, such as a FFmpegReader
|
|
|
|
|
openshot::ReaderBase* QtPlayer::Reader() {
|
|
|
|
|
return reader;
|
|
|
|
|
}
|
2014-03-23 01:12:29 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// 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);
|
|
|
|
|
}
|
2014-03-30 23:21:30 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// Get the Renderer pointer address (for Python to cast back into a QObject)
|
|
|
|
|
int64_t QtPlayer::GetRendererQObject() {
|
|
|
|
|
return (int64_t)(VideoRenderer*)p->renderer;
|
|
|
|
|
}
|
2014-04-02 16:48:27 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// Get the Playback speed
|
|
|
|
|
float QtPlayer::Speed() {
|
|
|
|
|
return speed;
|
|
|
|
|
}
|
2014-03-23 01:12:29 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// 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);
|
|
|
|
|
}
|
2014-03-23 01:12:29 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// Get the Volume
|
|
|
|
|
float QtPlayer::Volume() {
|
|
|
|
|
return volume;
|
|
|
|
|
}
|
2014-03-23 01:12:29 -05:00
|
|
|
|
2019-09-21 00:14:32 -04:00
|
|
|
// Set the Volume multiplier (1.0 = normal volume, <1.0 = quieter, >1.0 louder)
|
|
|
|
|
void QtPlayer::Volume(float new_volume) {
|
|
|
|
|
volume = new_volume;
|
|
|
|
|
}
|
|
|
|
|
}
|