From 2adb180f906c869af500f2647476399c8f8da20e Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Mon, 15 Jul 2013 19:19:12 +0800 Subject: [PATCH] ijkplayer: use seek target as current position before seek completed --- .../jni/ijkplayer/android/ijkplayer_android.c | 25 ++++++++++++++++--- ijkmediaplayer/jni/ijkplayer/ff_ffplay.c | 23 +++++++++-------- ijkmediaplayer/jni/ijkplayer/ff_ffplay_def.h | 10 +++++++- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/ijkmediaplayer/jni/ijkplayer/android/ijkplayer_android.c b/ijkmediaplayer/jni/ijkplayer/android/ijkplayer_android.c index 06ade31b..785aa499 100644 --- a/ijkmediaplayer/jni/ijkplayer/android/ijkplayer_android.c +++ b/ijkmediaplayer/jni/ijkplayer/android/ijkplayer_android.c @@ -54,6 +54,8 @@ typedef struct IjkMediaPlayer { void *weak_thiz; int restart_from_beginning; + int seek_req; + long seek_msec; } IjkMediaPlayer; inline static void ijkmp_destroy(IjkMediaPlayer *mp) @@ -292,7 +294,7 @@ static int ijkmp_start_l(IjkMediaPlayer *mp) ffp_remove_msg(mp->ffplayer, FFP_REQ_START); ffp_remove_msg(mp->ffplayer, FFP_REQ_PAUSE); - ffp_notify_msg(mp->ffplayer, FFP_REQ_START, 0, 0); + ffp_notify_msg1(mp->ffplayer, FFP_REQ_START); return 0; } @@ -332,7 +334,7 @@ static int ijkmp_pause_l(IjkMediaPlayer *mp) ffp_remove_msg(mp->ffplayer, FFP_REQ_START); ffp_remove_msg(mp->ffplayer, FFP_REQ_PAUSE); - ffp_notify_msg(mp->ffplayer, FFP_REQ_PAUSE, 0, 0); + ffp_notify_msg1(mp->ffplayer, FFP_REQ_PAUSE); return 0; } @@ -418,8 +420,10 @@ int ijkmp_seek_to_l(IjkMediaPlayer *mp, long msec) MP_RET_IF_FAILED(ikjmp_chkst_seek_l(mp->mp_state)); + mp->seek_req = 1; + mp->seek_msec = msec; ffp_remove_msg(mp->ffplayer, FFP_REQ_SEEK); - ffp_notify_msg(mp->ffplayer, FFP_REQ_SEEK, msec, 0); + ffp_notify_msg2(mp->ffplayer, FFP_REQ_SEEK, msec); // TODO: 9 64-bit long? return 0; @@ -446,7 +450,11 @@ long ijkmp_get_current_position(IjkMediaPlayer *mp) { assert(mp); pthread_mutex_lock(&mp->mutex); - long retval = ijkmp_get_current_position_l(mp); + long retval; + if (mp->seek_req) + retval = mp->seek_msec; + else + retval = ijkmp_get_current_position_l(mp); pthread_mutex_unlock(&mp->mutex); return retval; } @@ -524,6 +532,15 @@ int ijkmp_get_msg(IjkMediaPlayer *mp, AVMessage *msg, int block) pthread_mutex_unlock(&mp->mutex); break; + case FFP_MSG_SEEK_COMPLETE: + MPTRACE("ijkmp_get_msg: FFP_MSG_SEEK_COMPLETE"); + + pthread_mutex_lock(&mp->mutex); + mp->seek_req = 0; + mp->seek_msec = 0; + pthread_mutex_unlock(&mp->mutex); + break; + case FFP_REQ_START: MPTRACE("ijkmp_get_msg: FFP_REQ_START"); continue_wait_next_msg = 1; diff --git a/ijkmediaplayer/jni/ijkplayer/ff_ffplay.c b/ijkmediaplayer/jni/ijkplayer/ff_ffplay.c index efed376b..5b0b64dd 100644 --- a/ijkmediaplayer/jni/ijkplayer/ff_ffplay.c +++ b/ijkmediaplayer/jni/ijkplayer/ff_ffplay.c @@ -794,7 +794,7 @@ static int queue_picture(FFPlayer *ffp, AVFrame *src_frame, double pts, int64_t vp->height != src_frame->height) { if (vp->width != src_frame->width || vp->height != src_frame->height) - ffp_notify_msg(ffp, FFP_MSG_VIDEO_SIZE_CHANGED, src_frame->width, src_frame->height); + ffp_notify_msg3(ffp, FFP_MSG_VIDEO_SIZE_CHANGED, src_frame->width, src_frame->height); vp->allocated = 0; vp->reallocate = 0; @@ -1950,14 +1950,14 @@ static int read_thread(void *arg) ffp->infinite_buffer = 1; ffp->prepared = true; - ffp_notify_msg(ffp, FFP_MSG_PREPARED, 0, 0); + ffp_notify_msg1(ffp, FFP_MSG_PREPARED); if (is->video_st && is->video_st->codec) { AVCodecContext *avctx = is->video_st->codec; - ffp_notify_msg(ffp, FFP_MSG_VIDEO_SIZE_CHANGED, avctx->width, avctx->height); - ffp_notify_msg(ffp, FFP_MSG_SAR_CHANGED, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den); + ffp_notify_msg3(ffp, FFP_MSG_VIDEO_SIZE_CHANGED, avctx->width, avctx->height); + ffp_notify_msg3(ffp, FFP_MSG_SAR_CHANGED, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den); } if (ffp->auto_start) { - ffp_notify_msg(ffp, FFP_REQ_START, 0, 0); + ffp_notify_msg1(ffp, FFP_REQ_START); ffp->auto_start = 0; } @@ -2031,6 +2031,7 @@ static int read_thread(void *arg) if (is->pause_req) step_to_next_frame(ffp); SDL_UnlockMutex(ffp->is->play_mutex); + ffp_notify_msg1(ffp, FFP_MSG_SEEK_COMPLETE); } if (is->queue_attachments_req) { if (is->video_st && (is->video_st->disposition & AV_DISPOSITION_ATTACHED_PIC)) { @@ -2106,7 +2107,7 @@ static int read_thread(void *arg) // ALOGE("ffp_toggle_buffering: eof"); ffp_toggle_buffering(ffp, 0); toggle_pause(ffp, 1); - ffp_notify_msg(ffp, FFP_MSG_COMPLETED, 0, 0); + ffp_notify_msg1(ffp, FFP_MSG_COMPLETED); } } } @@ -2181,7 +2182,7 @@ static int read_thread(void *arg) if (last_buffered_time_percentage != buf_time_percent) { // ALOGE("time cache=%%%d (%d/%d)", buf_time_percent, cached_duration_in_ms, hwm_in_ms); last_buffered_time_percentage = buf_time_percent; - ffp_notify_msg(ffp, FFP_MSG_BUFFERING_TIME_UPDATE, cached_duration_in_ms, hwm_in_ms); + ffp_notify_msg3(ffp, FFP_MSG_BUFFERING_TIME_UPDATE, cached_duration_in_ms, hwm_in_ms); } } } @@ -2192,7 +2193,7 @@ static int read_thread(void *arg) if (last_buffered_size_percentage != buf_size_percent) { // ALOGE("size cache=%%%d (%d/%d)",buf_size_percent, cached_size, hwm_in_bytes); last_buffered_size_percentage = buf_size_percent; - ffp_notify_msg(ffp, FFP_MSG_BUFFERING_TIME_UPDATE, cached_size, hwm_in_bytes); + ffp_notify_msg3(ffp, FFP_MSG_BUFFERING_TIME_UPDATE, cached_size, hwm_in_bytes); } } @@ -2225,7 +2226,7 @@ static int read_thread(void *arg) if (!ffp->prepared || !is->abort_request) { ffp->last_error = last_error; - ffp_notify_msg(ffp, FFP_MSG_ERROR, last_error, 0); + ffp_notify_msg2(ffp, FFP_MSG_ERROR, last_error); } SDL_DestroyMutex(wait_mutex); @@ -2606,12 +2607,12 @@ void ffp_toggle_buffering_l(FFPlayer *ffp, int buffering_on) ALOGD("ffp_toggle_buffering_l: start"); is->buffering_on = 1; stream_update_pause_l(ffp); - ffp_notify_msg(ffp, FFP_MSG_BUFFERING_START, 0, 0); + ffp_notify_msg1(ffp, FFP_MSG_BUFFERING_START); } else if (!buffering_on && is->buffering_on){ ALOGD("ffp_toggle_buffering_l: end"); is->buffering_on = 0; stream_update_pause_l(ffp); - ffp_notify_msg(ffp, FFP_MSG_BUFFERING_END, 0, 0); + ffp_notify_msg1(ffp, FFP_MSG_BUFFERING_END); } } diff --git a/ijkmediaplayer/jni/ijkplayer/ff_ffplay_def.h b/ijkmediaplayer/jni/ijkplayer/ff_ffplay_def.h index 37848ac4..ae1097b2 100644 --- a/ijkmediaplayer/jni/ijkplayer/ff_ffplay_def.h +++ b/ijkmediaplayer/jni/ijkplayer/ff_ffplay_def.h @@ -503,7 +503,15 @@ inline static void ffp_reset_internal(FFPlayer *ffp) msg_queue_flush(&ffp->msg_queue); } -inline static void ffp_notify_msg(FFPlayer *ffp, int what, int arg1, int arg2) { +inline static void ffp_notify_msg1(FFPlayer *ffp, int what) { + msg_queue_put_simple3(&ffp->msg_queue, what, 0, 0); +} + +inline static void ffp_notify_msg2(FFPlayer *ffp, int what, int arg1) { + msg_queue_put_simple3(&ffp->msg_queue, what, arg1, 0); +} + +inline static void ffp_notify_msg3(FFPlayer *ffp, int what, int arg1, int arg2) { msg_queue_put_simple3(&ffp->msg_queue, what, arg1, arg2); } -- GitLab