Commit 1b352efb authored by michael's avatar michael

Fix race condition with reading between video_current_pts and video_current_pts_time.


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@21585 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 51ffddfa
...@@ -168,7 +168,7 @@ typedef struct VideoState { ...@@ -168,7 +168,7 @@ typedef struct VideoState {
AVStream *video_st; AVStream *video_st;
PacketQueue videoq; PacketQueue videoq;
double video_current_pts; ///<current displayed pts (different from video_clock if frame fifos are used) double video_current_pts; ///<current displayed pts (different from video_clock if frame fifos are used)
int64_t video_current_pts_time; ///<time (av_gettime) at which we updated video_current_pts - used to have running video pts double video_current_pts_drift; ///<video_current_pts - time (av_gettime) at which we updated video_current_pts - used to have running video pts
VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE]; VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE];
int pictq_size, pictq_rindex, pictq_windex; int pictq_size, pictq_rindex, pictq_windex;
SDL_mutex *pictq_mutex; SDL_mutex *pictq_mutex;
...@@ -942,7 +942,7 @@ static double get_video_clock(VideoState *is) ...@@ -942,7 +942,7 @@ static double get_video_clock(VideoState *is)
if (is->paused) { if (is->paused) {
return is->video_current_pts; return is->video_current_pts;
} else { } else {
return is->video_current_pts + (av_gettime() - is->video_current_pts_time) / 1000000.0; return is->video_current_pts_drift + av_gettime() / 1000000.0;
} }
} }
...@@ -990,15 +990,14 @@ static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int seek_by_by ...@@ -990,15 +990,14 @@ static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int seek_by_by
/* pause or resume the video */ /* pause or resume the video */
static void stream_pause(VideoState *is) static void stream_pause(VideoState *is)
{ {
is->paused = !is->paused; if (is->paused) {
if (!is->paused) { is->frame_timer += av_gettime() / 1000000.0 + is->video_current_pts_drift - is->video_current_pts;
if(is->read_pause_return != AVERROR(ENOSYS)){ if(is->read_pause_return != AVERROR(ENOSYS)){
is->video_current_pts = get_video_clock(is); is->video_current_pts = is->video_current_pts_drift + av_gettime() / 1000000.0;
} }
is->video_current_pts_drift = is->video_current_pts - av_gettime() / 1000000.0;
is->frame_timer += (av_gettime() - is->video_current_pts_time) / 1000000.0;
is->video_current_pts_time= av_gettime();
} }
is->paused = !is->paused;
} }
static double compute_frame_delay(double frame_current_pts, VideoState *is) static double compute_frame_delay(double frame_current_pts, VideoState *is)
...@@ -1070,7 +1069,7 @@ static void video_refresh_timer(void *opaque) ...@@ -1070,7 +1069,7 @@ static void video_refresh_timer(void *opaque)
/* update current video pts */ /* update current video pts */
is->video_current_pts = vp->pts; is->video_current_pts = vp->pts;
is->video_current_pts_time = av_gettime(); is->video_current_pts_drift = is->video_current_pts - av_gettime() / 1000000.0;
/* launch timer for next picture */ /* launch timer for next picture */
schedule_refresh(is, (int)(compute_frame_delay(vp->pts, is) * 1000 + 0.5)); schedule_refresh(is, (int)(compute_frame_delay(vp->pts, is) * 1000 + 0.5));
...@@ -1795,7 +1794,7 @@ static int stream_component_open(VideoState *is, int stream_index) ...@@ -1795,7 +1794,7 @@ static int stream_component_open(VideoState *is, int stream_index)
is->frame_last_delay = 40e-3; is->frame_last_delay = 40e-3;
is->frame_timer = (double)av_gettime() / 1000000.0; is->frame_timer = (double)av_gettime() / 1000000.0;
is->video_current_pts_time = av_gettime(); // is->video_current_pts_time = av_gettime();
packet_queue_init(&is->videoq); packet_queue_init(&is->videoq);
is->video_tid = SDL_CreateThread(video_thread, is); is->video_tid = SDL_CreateThread(video_thread, is);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment