From 526d578beee0fb6dc61e189bf2e185f688c9bef2 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 29 Jan 2016 22:46:28 +0100 Subject: [PATCH] player: refactor: some more minor decoder/output decoupling These changes don't make too much sense without context, but are preparation for later. Then the audio_src/video_src fields will be actually be NULL under circumstances. --- player/audio.c | 15 ++++++++------- player/osd.c | 3 ++- player/video.c | 20 ++++++++++++-------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/player/audio.c b/player/audio.c index 7e1137590e..d6cfd4fb61 100644 --- a/player/audio.c +++ b/player/audio.c @@ -171,14 +171,15 @@ static void ao_chain_reset_state(struct ao_chain *ao_c) ao_c->input_frame = NULL; af_seek_reset(ao_c->af); mp_audio_buffer_clear(ao_c->ao_buffer); + + if (ao_c->audio_src) + audio_reset_decoding(ao_c->audio_src); } void reset_audio_state(struct MPContext *mpctx) { - if (mpctx->ao_chain) { - audio_reset_decoding(mpctx->ao_chain->audio_src); + if (mpctx->ao_chain) ao_chain_reset_state(mpctx->ao_chain); - } mpctx->audio_status = mpctx->ao_chain ? STATUS_SYNCING : STATUS_EOF; mpctx->delay = 0; mpctx->audio_drop_throttle = 0; @@ -238,6 +239,9 @@ static void reinit_audio_filters_and_output(struct MPContext *mpctx) assert(ao_c); struct af_stream *afs = ao_c->af; + if (ao_c->input_frame) + mp_audio_copy_config(&ao_c->input_format, ao_c->input_frame); + struct mp_audio in_format = ao_c->input_format; if (!mp_audio_config_valid(&in_format)) { @@ -307,7 +311,7 @@ static void reinit_audio_filters_and_output(struct MPContext *mpctx) if (!mpctx->ao) { // If spdif was used, try to fallback to PCM. - if (spdif_fallback) { + if (spdif_fallback && ao_c->audio_src) { MP_VERBOSE(mpctx, "Falling back to PCM output.\n"); ao_c->spdif_passthrough = false; ao_c->spdif_failed = true; @@ -579,9 +583,6 @@ static int decode_new_frame(struct ao_chain *ao_c) res = audio_get_frame(ao_c->audio_src, &ao_c->input_frame); } - if (ao_c->input_frame) - mp_audio_copy_config(&ao_c->input_format, ao_c->input_frame); - switch (res) { case AUDIO_OK: return AD_OK; case AUDIO_WAIT: return AD_WAIT; diff --git a/player/osd.c b/player/osd.c index 45db9b2c77..b88feee9f6 100644 --- a/player/osd.c +++ b/player/osd.c @@ -246,7 +246,8 @@ static void print_status(struct MPContext *mpctx) talloc_free(r); } int64_t c = vo_get_drop_count(mpctx->video_out); - int dropped_frames = mpctx->vo_chain->video_src->dropped_frames; + struct dec_video *d_video = mpctx->vo_chain->video_src; + int dropped_frames = d_video ? d_video->dropped_frames : 0; if (c > 0 || dropped_frames > 0) { saddf(&line, " Dropped: %"PRId64, c); if (dropped_frames) diff --git a/player/video.c b/player/video.c index 1b30b398d8..eb506b21e9 100644 --- a/player/video.c +++ b/player/video.c @@ -237,14 +237,15 @@ static void vo_chain_reset_state(struct vo_chain *vo_c) if (vo_c->vf->initialized == 1) vf_seek_reset(vo_c->vf); vo_seek_reset(vo_c->vo); + + if (vo_c->video_src) + video_reset(vo_c->video_src); } void reset_video_state(struct MPContext *mpctx) { - if (mpctx->vo_chain) { - video_reset(mpctx->vo_chain->video_src); + if (mpctx->vo_chain) vo_chain_reset_state(mpctx->vo_chain); - } for (int n = 0; n < mpctx->num_next_frames; n++) mp_image_unrefp(&mpctx->next_frames[n]); @@ -422,7 +423,8 @@ static bool check_framedrop(struct MPContext *mpctx, struct vo_chain *vo_c) struct MPOpts *opts = mpctx->opts; // check for frame-drop: if (mpctx->video_status == STATUS_PLAYING && !mpctx->paused && - mpctx->audio_status == STATUS_PLAYING && !ao_untimed(mpctx->ao)) + mpctx->audio_status == STATUS_PLAYING && !ao_untimed(mpctx->ao) && + vo_c->video_src) { float fps = vo_c->container_fps; double frame_time = fps > 0 ? 1.0 / fps : 0; @@ -453,8 +455,6 @@ static int decode_image(struct MPContext *mpctx) assert(!vo_c->input_mpi); int st = video_get_frame(d_video, &vo_c->input_mpi); - if (vo_c->input_mpi) - vo_c->input_format = vo_c->input_mpi->params; switch (st) { case VIDEO_WAIT: return VD_WAIT; case VIDEO_EOF: return VD_EOF; @@ -510,7 +510,7 @@ static int video_filter(struct MPContext *mpctx, bool eof) // Most video filters don't work with hardware decoding, so this // might be the reason why filter reconfig failed. - if (vf->initialized < 0 && + if (vf->initialized < 0 && vo_c->video_src && video_vd_control(vo_c->video_src, VDCTRL_FORCE_HWDEC_FALLBACK, NULL) == CONTROL_OK) { @@ -558,6 +558,8 @@ static int video_decode_and_filter(struct MPContext *mpctx) if (r == VD_WAIT) return r; } + if (vo_c->input_mpi) + vo_c->input_format = vo_c->input_mpi->params; bool eof = !vo_c->input_mpi && (r == VD_EOF || r < 0); r = video_filter(mpctx, eof); @@ -636,7 +638,9 @@ static void handle_new_frame(struct MPContext *mpctx) mpctx->time_frame += frame_time / mpctx->video_speed; adjust_sync(mpctx, pts, frame_time); } - mpctx->dropped_frames_start = mpctx->vo_chain->video_src->dropped_frames; + struct dec_video *d_video = mpctx->vo_chain->video_src; + if (d_video) + mpctx->dropped_frames_start = d_video->dropped_frames; MP_TRACE(mpctx, "frametime=%5.3f\n", frame_time); }