提交 e01c84b4 编写于 作者: Z Zhang Rui

ffplay: improve buffer indicator

上级 e27e5cfc
......@@ -24,22 +24,22 @@
#ifndef FFPLAY__FF_FFMSG_H
#define FFPLAY__FF_FFMSG_H
#define FFP_MSG_FLUSH 0
#define FFP_MSG_ERROR 100 /* arg1 = error */
#define FFP_MSG_PREPARED 200
#define FFP_MSG_COMPLETED 300
#define FFP_MSG_VIDEO_SIZE_CHANGED 400 /* arg1 = width, arg2 = height */
#define FFP_MSG_SAR_CHANGED 401 /* arg1 = sar.num, arg2 = sar.den */
#define FFP_MSG_BUFFERING_START 500
#define FFP_MSG_BUFFERING_END 501
#define FFP_MSG_BUFFERING_UPDATE 502 /* arg1 = buffering head position in time */
#define FFP_MSG_BUFFERING_BYTES_UPDATE 503 /* arg1 = cached data in bytes, arg2 = high water mark */
#define FFP_MSG_BUFFERING_TIME_UPDATE 504 /* arg1 = cached duration in milliseconds, arg2 = high water mark */
#define FFP_MSG_SEEK_COMPLETE 600
#define FFP_MSG_PLAYBACK_STATE_CHANGED 700
#define FFP_MSG_FLUSH 0
#define FFP_MSG_ERROR 100 /* arg1 = error */
#define FFP_MSG_PREPARED 200
#define FFP_MSG_COMPLETED 300
#define FFP_MSG_VIDEO_SIZE_CHANGED 400 /* arg1 = width, arg2 = height */
#define FFP_MSG_SAR_CHANGED 401 /* arg1 = sar.num, arg2 = sar.den */
#define FFP_MSG_BUFFERING_START 500
#define FFP_MSG_BUFFERING_END 501
#define FFP_MSG_BUFFERING_UPDATE 502 /* arg1 = buffering head position in time, arg2 = minimum percent in time or bytes */
#define FFP_MSG_BUFFERING_BYTES_UPDATE 503 /* arg1 = cached data in bytes, arg2 = high water mark */
#define FFP_MSG_BUFFERING_TIME_UPDATE 504 /* arg1 = cached duration in milliseconds, arg2 = high water mark */
#define FFP_MSG_SEEK_COMPLETE 600
#define FFP_MSG_PLAYBACK_STATE_CHANGED 700
#define FFP_REQ_START 20001
#define FFP_REQ_PAUSE 20002
#define FFP_REQ_SEEK 20003
#define FFP_REQ_START 20001
#define FFP_REQ_PAUSE 20002
#define FFP_REQ_SEEK 20003
#endif
......@@ -2316,6 +2316,7 @@ static int read_thread(void *arg)
int buf_time_percent = -1;
int hwm_in_bytes = ffp->high_water_mark_in_bytes;
int need_start_buffering = 0;
int64_t buf_time_position = -1;
if (hwm_in_ms > 0) {
int cached_duration_in_ms = -1;
int64_t audio_cached_duration = -1;
......@@ -2349,6 +2350,7 @@ static int read_thread(void *arg)
}
if (cached_duration_in_ms >= 0) {
buf_time_position = ffp_get_current_position_l(ffp) + cached_duration_in_ms;
buf_time_percent = (int)av_rescale(cached_duration_in_ms, 1005, hwm_in_ms * 10);
if (last_buffered_time_percentage != buf_time_percent) {
#ifdef FFP_SHOW_DEMUX_CACHE
......@@ -2372,13 +2374,26 @@ static int read_thread(void *arg)
}
}
int buf_percent = -1;
if (buf_time_percent >= 0) {
// alwas depend on cache duration if valid
if (buf_time_percent >= 100)
need_start_buffering = 1;
buf_percent = buf_time_percent;
} else {
if (buf_size_percent >= 100)
need_start_buffering = 1;
buf_percent = buf_size_percent;
}
if (buf_time_percent >= 0 && buf_size_percent >= 0) {
buf_percent = FFMIN(buf_time_percent, buf_size_percent);
}
if (buf_percent) {
#ifdef FFP_SHOW_DEMUX_CACHE
ALOGE("buf pos=%"PRId64", %%%d\n", buf_time_position, buf_percent);
#endif
ffp_notify_msg3(ffp, FFP_MSG_BUFFERING_UPDATE, buf_time_position, buf_percent);
}
if (need_start_buffering) {
......
......@@ -43,6 +43,8 @@
BOOL _seeking;
NSInteger _bufferingTime;
NSInteger _bufferingPosition;
NSInteger _bufferingPercentage;
BOOL _keepScreenOnWhilePlaying;
......@@ -273,7 +275,8 @@
- (NSTimeInterval)playableDuration
{
return self.currentPlaybackTime + ((NSTimeInterval)_bufferingTime) / 1000;
// return self.currentPlaybackTime + ((NSTimeInterval)_bufferingTime) / 1000;
return ((NSTimeInterval)_bufferingPosition) / 1000;
}
- (void)setScalingMode: (MPMovieScalingMode) aScalingMode
......@@ -397,12 +400,14 @@
}
case FFP_MSG_BUFFERING_UPDATE:
// NSLog(@"FFP_MSG_BUFFERING_UPDATE: %d, %d", avmsg->arg1, avmsg->arg2);
_bufferingPosition = avmsg->arg1;
_bufferingPercentage = avmsg->arg2;
break;
case FFP_MSG_BUFFERING_BYTES_UPDATE:
// NSLog(@"FFP_MSG_BUFFERING_BYTES_UPDATE: %d", avmsg->arg1);
break;
case FFP_MSG_BUFFERING_TIME_UPDATE:
_bufferingTime = avmsg->arg1;
_bufferingTime = avmsg->arg1;
// NSLog(@"FFP_MSG_BUFFERING_TIME_UPDATE: %d", avmsg->arg1);
break;
case FFP_MSG_PLAYBACK_STATE_CHANGED:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册