mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
Extract into its own function the code to compute frame delay.
Patch by Tomer Barletz gmail_address(last_name) Originally committed as revision 17431 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
1447aac4be
commit
49410784de
51
ffplay.c
51
ffplay.c
@ -1005,35 +1005,18 @@ static void stream_pause(VideoState *is)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called to display each frame */
|
static double compute_frame_delay(double frame_current_pts, VideoState *is)
|
||||||
static void video_refresh_timer(void *opaque)
|
|
||||||
{
|
{
|
||||||
VideoState *is = opaque;
|
|
||||||
VideoPicture *vp;
|
|
||||||
double actual_delay, delay, sync_threshold, ref_clock, diff;
|
double actual_delay, delay, sync_threshold, ref_clock, diff;
|
||||||
|
|
||||||
SubPicture *sp, *sp2;
|
|
||||||
|
|
||||||
if (is->video_st) {
|
|
||||||
if (is->pictq_size == 0) {
|
|
||||||
/* if no picture, need to wait */
|
|
||||||
schedule_refresh(is, 1);
|
|
||||||
} else {
|
|
||||||
/* dequeue the picture */
|
|
||||||
vp = &is->pictq[is->pictq_rindex];
|
|
||||||
|
|
||||||
/* update current video pts */
|
|
||||||
is->video_current_pts = vp->pts;
|
|
||||||
is->video_current_pts_time = av_gettime();
|
|
||||||
|
|
||||||
/* compute nominal delay */
|
/* compute nominal delay */
|
||||||
delay = vp->pts - is->frame_last_pts;
|
delay = frame_current_pts - is->frame_last_pts;
|
||||||
if (delay <= 0 || delay >= 10.0) {
|
if (delay <= 0 || delay >= 10.0) {
|
||||||
/* if incorrect delay, use previous one */
|
/* if incorrect delay, use previous one */
|
||||||
delay = is->frame_last_delay;
|
delay = is->frame_last_delay;
|
||||||
}
|
}
|
||||||
is->frame_last_delay = delay;
|
is->frame_last_delay = delay;
|
||||||
is->frame_last_pts = vp->pts;
|
is->frame_last_pts = frame_current_pts;
|
||||||
|
|
||||||
/* update delay to follow master synchronisation source */
|
/* update delay to follow master synchronisation source */
|
||||||
if (((is->av_sync_type == AV_SYNC_AUDIO_MASTER && is->audio_st) ||
|
if (((is->av_sync_type == AV_SYNC_AUDIO_MASTER && is->audio_st) ||
|
||||||
@ -1041,7 +1024,7 @@ static void video_refresh_timer(void *opaque)
|
|||||||
/* if video is slave, we try to correct big delays by
|
/* if video is slave, we try to correct big delays by
|
||||||
duplicating or deleting a frame */
|
duplicating or deleting a frame */
|
||||||
ref_clock = get_master_clock(is);
|
ref_clock = get_master_clock(is);
|
||||||
diff = vp->pts - ref_clock;
|
diff = frame_current_pts - ref_clock;
|
||||||
|
|
||||||
/* skip or repeat frame. We take into account the
|
/* skip or repeat frame. We take into account the
|
||||||
delay to compute the threshold. I still don't know
|
delay to compute the threshold. I still don't know
|
||||||
@ -1063,8 +1046,32 @@ static void video_refresh_timer(void *opaque)
|
|||||||
/* XXX: should skip picture */
|
/* XXX: should skip picture */
|
||||||
actual_delay = 0.010;
|
actual_delay = 0.010;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return actual_delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* called to display each frame */
|
||||||
|
static void video_refresh_timer(void *opaque)
|
||||||
|
{
|
||||||
|
VideoState *is = opaque;
|
||||||
|
VideoPicture *vp;
|
||||||
|
|
||||||
|
SubPicture *sp, *sp2;
|
||||||
|
|
||||||
|
if (is->video_st) {
|
||||||
|
if (is->pictq_size == 0) {
|
||||||
|
/* if no picture, need to wait */
|
||||||
|
schedule_refresh(is, 1);
|
||||||
|
} else {
|
||||||
|
/* dequeue the picture */
|
||||||
|
vp = &is->pictq[is->pictq_rindex];
|
||||||
|
|
||||||
|
/* update current video pts */
|
||||||
|
is->video_current_pts = vp->pts;
|
||||||
|
is->video_current_pts_time = av_gettime();
|
||||||
|
|
||||||
/* launch timer for next picture */
|
/* launch timer for next picture */
|
||||||
schedule_refresh(is, (int)(actual_delay * 1000 + 0.5));
|
schedule_refresh(is, (int)(compute_frame_delay(vp->pts, is) * 1000 + 0.5));
|
||||||
|
|
||||||
#if defined(DEBUG_SYNC)
|
#if defined(DEBUG_SYNC)
|
||||||
printf("video: delay=%0.3f actual_delay=%0.3f pts=%0.3f A-V=%f\n",
|
printf("video: delay=%0.3f actual_delay=%0.3f pts=%0.3f A-V=%f\n",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user