|
|
|
@ -462,68 +462,69 @@ public:
|
|
|
|
|
VideoPicture *vp;
|
|
|
|
|
double actual_delay, delay, sync_threshold, ref_clock, diff;
|
|
|
|
|
|
|
|
|
|
if(is->video_st)
|
|
|
|
|
if(!is->video_st)
|
|
|
|
|
{
|
|
|
|
|
if(is->pictq_size == 0)
|
|
|
|
|
schedule_refresh(is, 1);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vp = &is->pictq[is->pictq_rindex];
|
|
|
|
|
schedule_refresh(is, 100);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(is->pictq_size == 0)
|
|
|
|
|
{
|
|
|
|
|
schedule_refresh(is, 1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
is->video_current_pts = vp->pts;
|
|
|
|
|
is->video_current_pts_time = av_gettime();
|
|
|
|
|
vp = &is->pictq[is->pictq_rindex];
|
|
|
|
|
|
|
|
|
|
delay = vp->pts - is->frame_last_pts; /* the pts from last time */
|
|
|
|
|
if(delay <= 0 || delay >= 1.0) {
|
|
|
|
|
/* if incorrect delay, use previous one */
|
|
|
|
|
delay = is->frame_last_delay;
|
|
|
|
|
}
|
|
|
|
|
/* save for next time */
|
|
|
|
|
is->frame_last_delay = delay;
|
|
|
|
|
is->frame_last_pts = vp->pts;
|
|
|
|
|
is->video_current_pts = vp->pts;
|
|
|
|
|
is->video_current_pts_time = av_gettime();
|
|
|
|
|
|
|
|
|
|
/* update delay to sync to audio if not master source */
|
|
|
|
|
if(is->av_sync_type != AV_SYNC_VIDEO_MASTER)
|
|
|
|
|
{
|
|
|
|
|
ref_clock = get_master_clock(is);
|
|
|
|
|
diff = vp->pts - ref_clock;
|
|
|
|
|
delay = vp->pts - is->frame_last_pts; /* the pts from last time */
|
|
|
|
|
if(delay <= 0 || delay >= 1.0) {
|
|
|
|
|
/* if incorrect delay, use previous one */
|
|
|
|
|
delay = is->frame_last_delay;
|
|
|
|
|
}
|
|
|
|
|
/* save for next time */
|
|
|
|
|
is->frame_last_delay = delay;
|
|
|
|
|
is->frame_last_pts = vp->pts;
|
|
|
|
|
|
|
|
|
|
/* Skip or repeat the frame. Take delay into account
|
|
|
|
|
FFPlay still doesn't "know if this is the best guess." */
|
|
|
|
|
sync_threshold = (delay > AV_SYNC_THRESHOLD) ? delay : AV_SYNC_THRESHOLD;
|
|
|
|
|
if(fabs(diff) < AV_NOSYNC_THRESHOLD)
|
|
|
|
|
{
|
|
|
|
|
if(diff <= -sync_threshold)
|
|
|
|
|
delay = 0;
|
|
|
|
|
else if(diff >= sync_threshold)
|
|
|
|
|
delay = 2 * delay;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* update delay to sync to audio if not master source */
|
|
|
|
|
if(is->av_sync_type != AV_SYNC_VIDEO_MASTER)
|
|
|
|
|
{
|
|
|
|
|
ref_clock = get_master_clock(is);
|
|
|
|
|
diff = vp->pts - ref_clock;
|
|
|
|
|
|
|
|
|
|
is->frame_timer += delay;
|
|
|
|
|
/* computer the REAL delay */
|
|
|
|
|
actual_delay = is->frame_timer - (av_gettime() / 1000000.0);
|
|
|
|
|
if(actual_delay < 0.010)
|
|
|
|
|
{
|
|
|
|
|
/* Really it should skip the picture instead */
|
|
|
|
|
actual_delay = 0.010;
|
|
|
|
|
}
|
|
|
|
|
schedule_refresh(is, (int)(actual_delay * 1000 + 0.5));
|
|
|
|
|
|
|
|
|
|
/* show the picture! */
|
|
|
|
|
video_display(is);
|
|
|
|
|
|
|
|
|
|
/* update queue for next picture! */
|
|
|
|
|
if(++is->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE)
|
|
|
|
|
is->pictq_rindex = 0;
|
|
|
|
|
is->pictq_mutex.lock();
|
|
|
|
|
is->pictq_size--;
|
|
|
|
|
is->pictq_cond.notify_one ();
|
|
|
|
|
is->pictq_mutex.unlock ();
|
|
|
|
|
/* Skip or repeat the frame. Take delay into account
|
|
|
|
|
FFPlay still doesn't "know if this is the best guess." */
|
|
|
|
|
sync_threshold = (delay > AV_SYNC_THRESHOLD) ? delay : AV_SYNC_THRESHOLD;
|
|
|
|
|
if(fabs(diff) < AV_NOSYNC_THRESHOLD)
|
|
|
|
|
{
|
|
|
|
|
if(diff <= -sync_threshold)
|
|
|
|
|
delay = 0;
|
|
|
|
|
else if(diff >= sync_threshold)
|
|
|
|
|
delay = 2 * delay;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
schedule_refresh(is, 100);
|
|
|
|
|
|
|
|
|
|
is->frame_timer += delay;
|
|
|
|
|
/* computer the REAL delay */
|
|
|
|
|
actual_delay = is->frame_timer - (av_gettime() / 1000000.0);
|
|
|
|
|
if(actual_delay < 0.010)
|
|
|
|
|
{
|
|
|
|
|
/* Really it should skip the picture instead */
|
|
|
|
|
actual_delay = 0.010;
|
|
|
|
|
}
|
|
|
|
|
schedule_refresh(is, (int)(actual_delay * 1000 + 0.5));
|
|
|
|
|
|
|
|
|
|
/* show the picture! */
|
|
|
|
|
video_display(is);
|
|
|
|
|
|
|
|
|
|
/* update queue for next picture! */
|
|
|
|
|
if(++is->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE)
|
|
|
|
|
is->pictq_rindex = 0;
|
|
|
|
|
is->pictq_mutex.lock();
|
|
|
|
|
is->pictq_size--;
|
|
|
|
|
is->pictq_cond.notify_one ();
|
|
|
|
|
is->pictq_mutex.unlock ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int queue_picture(VideoState *is, AVFrame *pFrame, double pts)
|
|
|
|
|