diff --git a/ijkmedia/ijkplayer/ff_ffplay.c b/ijkmedia/ijkplayer/ff_ffplay.c index b2cfe90edd04d6b2cd56f566167648468299b115..f3778e43578708885658b80b332befb5ba5d3558 100644 --- a/ijkmedia/ijkplayer/ff_ffplay.c +++ b/ijkmedia/ijkplayer/ff_ffplay.c @@ -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); diff --git a/ijkmedia/ijkplayer/ff_ffplay.h b/ijkmedia/ijkplayer/ff_ffplay.h index bb0de8f5ca179b12e9bf7abe6a84b9129a712a31..db936b7acc0c6e2e59b84f9029385cf802abd1d4 100644 --- a/ijkmedia/ijkplayer/ff_ffplay.h +++ b/ijkmedia/ijkplayer/ff_ffplay.h @@ -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, diff --git a/ijkmedia/ijkplayer/ff_ffplay_debug.h b/ijkmedia/ijkplayer/ff_ffplay_debug.h index f1b8364df4e1bbbef4f35ddac156222e1a5b4bba..640fe7fce2999ed2846ea1c96700f1a2b91408c5 100644 --- a/ijkmedia/ijkplayer/ff_ffplay_debug.h +++ b/ijkmedia/ijkplayer/ff_ffplay_debug.h @@ -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 diff --git a/ijkmedia/ijkplayer/ff_ffplay_def.h b/ijkmedia/ijkplayer/ff_ffplay_def.h index 940ab725b2a5838214e3f3ebefcdb216e40297da..4876531aac0be5945ea1437dd4e5e3ea3089e057 100644 --- a/ijkmedia/ijkplayer/ff_ffplay_def.h +++ b/ijkmedia/ijkplayer/ff_ffplay_def.h @@ -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 { diff --git a/ijkmedia/ijksdl/ijksdl_timer.c b/ijkmedia/ijksdl/ijksdl_timer.c index 45959338fbfe99fcf6e5c3a926e379e021b040e9..c64990597566ef773dc65b26ceb72da19f4ff779 100644 --- a/ijkmedia/ijksdl/ijksdl_timer.c +++ b/ijkmedia/ijksdl/ijksdl_timer.c @@ -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; } } diff --git a/ijkmedia/ijksdl/ijksdl_timer.h b/ijkmedia/ijksdl/ijksdl_timer.h index 5ca07608167345fae449c60fa688260e1d973e44..e274706f5ad8ebfe1f356e8169b9e487fe907c7a 100644 --- a/ijkmedia/ijksdl/ijksdl_timer.h +++ b/ijkmedia/ijksdl/ijksdl_timer.h @@ -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; diff --git a/ios/IJKMediaPlayer/IJKMediaPlayer.xcodeproj/project.pbxproj b/ios/IJKMediaPlayer/IJKMediaPlayer.xcodeproj/project.pbxproj index ec7a9d668e60449c71be26fabf318277b4dd2d0b..84e25237a6cf1b8ddea421a907a15409be2009d4 100644 --- a/ios/IJKMediaPlayer/IJKMediaPlayer.xcodeproj/project.pbxproj +++ b/ios/IJKMediaPlayer/IJKMediaPlayer.xcodeproj/project.pbxproj @@ -195,6 +195,7 @@ E690403717EB079500CFD954 /* ijklog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ijklog.h; sourceTree = ""; }; E690403917EB079500CFD954 /* ijkutil_ios.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ijkutil_ios.h; sourceTree = ""; }; E690403A17EB079500CFD954 /* loghelp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = loghelp.h; sourceTree = ""; }; + E6C2FD391B300A390081D321 /* ff_ffplay_debug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ff_ffplay_debug.h; sourceTree = ""; }; E6EE92A1187810C5009EAB56 /* IJKAudioKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IJKAudioKit.h; path = IJKMediaPlayer/IJKAudioKit.h; sourceTree = ""; }; E6EE92A2187810C5009EAB56 /* IJKAudioKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IJKAudioKit.m; path = IJKMediaPlayer/IJKAudioKit.m; sourceTree = ""; }; E6EE92A61878230C009EAB56 /* ijksdl_aout_ios_audiounit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ijksdl_aout_ios_audiounit.h; sourceTree = ""; }; @@ -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 */,