Skip to content

Commit

Permalink
#46, fix playable duration not update bug
Browse files Browse the repository at this point in the history
  • Loading branch information
debugly committed Sep 12, 2024
1 parent 4da284e commit 2a1515c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 45 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tag k0.11.7
--------------------------------

- support avs3 video decoder,#45
- update playable statistics after seek,#44
- update playable statistics after seek,#46
- fix the palyable progress bar is never full bug
- fix ffp_get_current_position_l is on average 50ms slow after pause
- add the duration of the decoded frames to statistics
Expand Down
84 changes: 40 additions & 44 deletions ijkmedia/ijkplayer/ff_ffplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1625,10 +1625,50 @@ static void ffp_video_statistic_l(FFPlayer *ffp)
}
}

static void update_playable_duration(FFPlayer *ffp)
{
if (!ffp) {
return;
}
VideoState *is = ffp->is;
if (!is) {
return;
}
int cached_duration_in_ms = -1;
int64_t audio_cached_duration = -1;
int64_t video_cached_duration = -1;

if (is->audio_st) {
audio_cached_duration = ffp->stat.audio_cache.duration;
}

if (is->video_st) {
video_cached_duration = ffp->stat.video_cache.duration;
}

if (video_cached_duration > 0 && audio_cached_duration > 0) {
cached_duration_in_ms = (int)IJKMIN(video_cached_duration, audio_cached_duration);
} else if (video_cached_duration > 0) {
cached_duration_in_ms = (int)video_cached_duration;
} else if (audio_cached_duration > 0) {
cached_duration_in_ms = (int)audio_cached_duration;
}

if (cached_duration_in_ms >= 0) {
int64_t buf_time_position = ffp_get_current_position_l(ffp) + cached_duration_in_ms;
if (ffp->playable_duration_ms != buf_time_position) {
av_log(ffp, AV_LOG_DEBUG, "set playable_duration_ms:%lld,cached_duration_in_ms:%d\n", buf_time_position,cached_duration_in_ms);
ffp->playable_duration_ms = buf_time_position;
}
}
}

static void ffp_statistic_l(FFPlayer *ffp)
{
ffp_audio_statistic_l(ffp);
ffp_video_statistic_l(ffp);
//when paused player,need update playable statistics after seek
update_playable_duration(ffp);
}

static int get_video_frame(FFPlayer *ffp, AVFrame *frame)
Expand Down Expand Up @@ -3309,44 +3349,6 @@ static void reset_buffer_size(FFPlayer *ffp)
av_log(NULL, AV_LOG_INFO, "auto decision max buffer size:%dMB\n",ffp->dcc.max_buffer_size/1024/1024);
}

static void update_playable_duration(FFPlayer *ffp)
{
if (!ffp) {
return;
}
VideoState *is = ffp->is;
if (!is) {
return;
}
int cached_duration_in_ms = -1;
int64_t audio_cached_duration = -1;
int64_t video_cached_duration = -1;

if (is->audio_st) {
audio_cached_duration = ffp->stat.audio_cache.duration;
}

if (is->video_st) {
video_cached_duration = ffp->stat.video_cache.duration;
}

if (video_cached_duration > 0 && audio_cached_duration > 0) {
cached_duration_in_ms = (int)IJKMIN(video_cached_duration, audio_cached_duration);
} else if (video_cached_duration > 0) {
cached_duration_in_ms = (int)video_cached_duration;
} else if (audio_cached_duration > 0) {
cached_duration_in_ms = (int)audio_cached_duration;
}

if (cached_duration_in_ms >= 0) {
int64_t buf_time_position = ffp_get_current_position_l(ffp) + cached_duration_in_ms;
if (ffp->playable_duration_ms != buf_time_position) {
//av_log(ffp, AV_LOG_DEBUG, "set playable_duration_ms:%lld\n", buf_time_position);
ffp->playable_duration_ms = buf_time_position;
}
}
}

/* this thread gets the stream from the disk or the network */
static int read_thread(void *arg)
{
Expand Down Expand Up @@ -4940,12 +4942,6 @@ void ffp_toggle_buffering_l(FFPlayer *ffp, int buffering_on)
is->buffering_on = 0;
stream_update_pause_l(ffp);

//when paused player,need update playable statistics after seek
if (is->pause_req) {
ffp_statistic_l(ffp);
update_playable_duration(ffp);
}

if (is->seek_buffering) {
is->seek_buffering = 0;
ffp_notify_msg2(ffp, FFP_MSG_BUFFERING_END, 1);
Expand Down

0 comments on commit 2a1515c

Please sign in to comment.