29 #include "../../include/Qt/PlayerPrivate.h"
35 : renderer(rb), Thread(
"player"), video_position(1), audio_position(0)
39 , speed(1), reader(NULL), last_video_position(1)
43 PlayerPrivate::~PlayerPrivate()
52 void PlayerPrivate::run()
60 audioPlayback->startThread(8);
62 videoCache->startThread(2);
63 videoPlayback->startThread(4);
66 while (!threadShouldExit()) {
72 const Time t1 = Time::getCurrentTime();
78 if ((speed == 0 && video_position == last_video_position) || (video_position > reader->
info.
video_length)) {
85 videoPlayback->frame = frame;
86 videoPlayback->render.signal();
89 last_video_position = video_position;
92 int64_t video_frame_diff = 0;
96 audioPlayback->Seek(video_position);
99 audio_position = audioPlayback->getCurrentFramePosition();
100 video_frame_diff = video_position - audio_position;
104 const Time t2 = Time::getCurrentTime();
107 int64_t render_time = t2.toMilliseconds() - t1.toMilliseconds();
110 int sleep_time = int(frame_time - render_time);
113 ZmqLogger::Instance()->
AppendDebugMethod(
"PlayerPrivate::run (determine sleep)",
"video_frame_diff", video_frame_diff,
"video_position", video_position,
"audio_position", audio_position,
"speed", speed,
"render_time", render_time,
"sleep_time", sleep_time);
122 sleep_time += (video_frame_diff * (1000.0 / reader->
info.
fps.
ToDouble()));
125 else if (video_frame_diff < -10 && reader->info.has_audio && reader->
info.
has_video) {
127 video_position += abs(video_frame_diff) / 2;
132 if (sleep_time > 0) usleep(sleep_time * 1000);
138 std::shared_ptr<Frame> PlayerPrivate::getFrame()
142 if (video_position + speed >= 1 && video_position + speed <= reader->info.video_length)
143 video_position = video_position + speed;
145 if (frame && frame->number == video_position && video_position == last_video_position) {
152 videoCache->setCurrentFramePosition(video_position);
155 return reader->
GetFrame(video_position);
165 return std::shared_ptr<Frame>();
169 bool PlayerPrivate::startPlayback()
171 if (video_position < 0)
return false;
179 void PlayerPrivate::stopPlayback(
int timeOutMilliseconds)
181 if (isThreadRunning()) stopThread(timeOutMilliseconds);
182 if (audioPlayback->isThreadRunning() && reader->
info.
has_audio) audioPlayback->stopThread(timeOutMilliseconds);
183 if (videoCache->isThreadRunning() && reader->
info.
has_video) videoCache->stopThread(timeOutMilliseconds);
184 if (videoPlayback->isThreadRunning() && reader->
info.
has_video) videoPlayback->stopThread(timeOutMilliseconds);
The audio playback thread.
Exception when a reader is closed, and a frame is requested.
bool has_video
Determines if this file has a video stream.
virtual std::shared_ptr< Frame > GetFrame(int64_t number)=0
bool has_audio
Determines if this file has an audio stream.
int64_t video_length
The number of frames in the video stream.
The video playback class.
void AppendDebugMethod(string method_name, string arg1_name, float arg1_value, string arg2_name, float arg2_value, string arg3_name, float arg3_value, string arg4_name, float arg4_value, string arg5_name, float arg5_value, string arg6_name, float arg6_value)
Append debug information.
ReaderInfo info
Information about the current media file.
Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
Exception for frames that are out of bounds.
static ZmqLogger * Instance()
Create or get an instance of this logger singleton (invoke the class with this method) ...
This is the base class of all Renderers in libopenshot.
double ToDouble()
Return this fraction as a double (i.e. 1/2 = 0.5)
Exception when too many seek attempts happen.