提交 22611dbf 编写于 作者: Z Zhang Rui

ff_ffplay: use SDL_Profiler

上级 8f4bbe2a
......@@ -46,11 +46,6 @@
#define FFP_IO_STAT_STEP (50 * 1024)
#ifdef FFP_SHOW_VDPS
static int g_vdps_counter = 0;
static int64_t g_vdps_total_time = 0;
#endif
static int ffp_format_control_message(struct AVFormatContext *s, int type,
void *data, size_t data_size);
......@@ -333,6 +328,8 @@ static void decoder_init(Decoder *d, AVCodecContext *avctx, PacketQueue *queue,
d->queue = queue;
d->empty_queue_cond = empty_queue_cond;
d->start_pts = AV_NOPTS_VALUE;
SDL_ProfilerReset(&d->decode_profiler, -1);
}
static int decoder_decode_frame(FFPlayer *ffp, Decoder *d, AVFrame *frame, AVSubtitle *sub) {
......@@ -366,26 +363,18 @@ static int decoder_decode_frame(FFPlayer *ffp, Decoder *d, AVFrame *frame, AVSub
switch (d->avctx->codec_type) {
case AVMEDIA_TYPE_VIDEO: {
#ifdef FFP_SHOW_VDPS
int64_t start = SDL_GetTickHR();
SDL_ProfilerBegin(&d->decode_profiler);
#endif
ret = avcodec_decode_video2(d->avctx, frame, &got_frame, &d->pkt_temp);
#ifdef FFP_SHOW_VDPS
int64_t dur = SDL_GetTickHR() - start;
g_vdps_total_time += dur;
g_vdps_counter++;
int64_t avg_frame_time = 0;
if (g_vdps_counter > 0)
avg_frame_time = g_vdps_total_time / g_vdps_counter;
double fps = 0;
if (avg_frame_time > 0)
fps = 1.0f / avg_frame_time * 1000;
if (dur >= 30) {
ALOGE("vdps: [%f][%d] %"PRId64" ms/frame, vdps=%f, +%"PRId64"\n",
frame->pts, g_vdps_counter, (int64_t)avg_frame_time, fps, dur);
}
if (g_vdps_total_time >= FFP_XPS_PERIOD) {
g_vdps_total_time -= avg_frame_time;
g_vdps_counter--;
int64_t delta = SDL_ProfilerEnd(&d->decode_profiler);
if (delta >= 30) {
av_log(ffp, AV_LOG_DEBUG,
"vdps[%d]: %"PRId64" ms/frame, vdps=%f, +%"PRId64"\n",
d->decode_profiler.total_counter,
d->decode_profiler.average_elapsed,
d->decode_profiler.sample_per_seconds,
delta);
}
#endif
if (got_frame) {
......@@ -2110,6 +2099,7 @@ static int stream_component_open(FFPlayer *ffp, int stream_index)
if(is->video_st->avg_frame_rate.den && is->video_st->avg_frame_rate.num) {
double fps = av_q2d(is->video_st->avg_frame_rate);
SDL_ProfilerReset(&is->viddec.decode_profiler, fps + 0.5);
if (fps > ffp->max_fps && fps < 130.0) {
is->is_video_high_fps = 1;
ALOGI("fps: %lf (too high)\n", fps);
......
......@@ -31,7 +31,7 @@
void ffp_global_init();
void ffp_global_uninit();
void ffp_global_set_log_report(int use_report);
void ffp_global_set_log_levle(int log_leve);
void ffp_global_set_log_level(int log_level);
void ffp_io_stat_register(void (*cb)(const char *url, int type, int bytes));
void ffp_io_stat_complete_register(void (*cb)(const char *url,
int64_t read_bytes, int64_t total_size,
......
......@@ -25,7 +25,7 @@
#define FFP_XPS_PERIOD (3)
// #define FFP_SHOW_FPS
// #define FFP_SHOW_VDPS
#define FFP_SHOW_VDPS
// #define FFP_SHOW_AUDIO_DELAY
// #define FFP_SHOW_DEMUX_CACHE
// #define FFP_SHOW_BUF_POS
......
......@@ -190,6 +190,8 @@ typedef struct Decoder {
AVRational next_pts_tb;
SDL_Thread *decoder_tid;
SDL_Thread _decoder_tid;
SDL_Profiler decode_profiler;
} Decoder;
typedef struct VideoState {
......
......@@ -94,19 +94,25 @@ void SDL_ProfilerBegin(SDL_Profiler* profiler)
int64_t SDL_ProfilerEnd(SDL_Profiler* profiler)
{
int64_t delta = SDL_GetTickHR();
int64_t delta = SDL_GetTickHR() - profiler->begin_time;
if (profiler->max_sample > 0) {
profiler->total_elapsed += delta;
profiler->total_counter += 1;
if (profiler->total_counter > profiler->max_sample) {
profiler->total_elapsed -= profiler->average_elapsed;
profiler->total_counter -= 1;
profiler->sample_elapsed += delta;
profiler->sample_counter += 1;
if (profiler->sample_counter > profiler->max_sample) {
profiler->sample_elapsed -= profiler->average_elapsed;
profiler->sample_counter -= 1;
}
if (profiler->total_counter > 0) {
profiler->average_elapsed = profiler->total_elapsed / profiler->total_counter;
if (profiler->sample_counter > 0) {
profiler->average_elapsed = profiler->sample_elapsed / profiler->sample_counter;
}
if (profiler->sample_elapsed > 0) {
profiler->sample_per_seconds = profiler->sample_counter * 1000.f / profiler->sample_elapsed;
}
}
......
......@@ -34,7 +34,12 @@ Uint64 SDL_GetTickHR(void);
typedef struct SDL_Profiler {
int64_t total_elapsed;
int total_counter;
int64_t sample_elapsed;
int sample_counter;
float sample_per_seconds;
int64_t average_elapsed;
int64_t begin_time;
int max_sample;
......
......@@ -195,6 +195,7 @@
E690403717EB079500CFD954 /* ijklog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ijklog.h; sourceTree = "<group>"; };
E690403917EB079500CFD954 /* ijkutil_ios.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ijkutil_ios.h; sourceTree = "<group>"; };
E690403A17EB079500CFD954 /* loghelp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = loghelp.h; sourceTree = "<group>"; };
E6C2FD391B300A390081D321 /* ff_ffplay_debug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ff_ffplay_debug.h; sourceTree = "<group>"; };
E6EE92A1187810C5009EAB56 /* IJKAudioKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IJKAudioKit.h; path = IJKMediaPlayer/IJKAudioKit.h; sourceTree = "<group>"; };
E6EE92A2187810C5009EAB56 /* IJKAudioKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IJKAudioKit.m; path = IJKMediaPlayer/IJKAudioKit.m; sourceTree = "<group>"; };
E6EE92A61878230C009EAB56 /* ijksdl_aout_ios_audiounit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ijksdl_aout_ios_audiounit.h; sourceTree = "<group>"; };
......@@ -422,6 +423,7 @@
E67B91AD1A3801DB00717EA9 /* ff_ffpipenode.c */,
E67B91AE1A3801DB00717EA9 /* ff_ffpipenode.h */,
E6903FDD17EAFC6100CFD954 /* ff_ffplay_config.h */,
E6C2FD391B300A390081D321 /* ff_ffplay_debug.h */,
E6903FDE17EAFC6100CFD954 /* ff_ffplay_def.h */,
E6903FDB17EAFC6100CFD954 /* ff_ffplay.c */,
E6903FDC17EAFC6100CFD954 /* ff_ffplay.h */,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册