player: move audio and video decoder init to separate functions

Preparation.
This commit is contained in:
wm4 2016-02-05 21:50:37 +01:00
parent 242dbc6c2c
commit 8af70561a4
3 changed files with 75 additions and 34 deletions

View File

@ -358,6 +358,33 @@ init_error:
error_on_track(mpctx, track);
}
int init_audio_decoder(struct MPContext *mpctx, struct track *track)
{
assert(!track->d_audio);
if (!track->stream)
goto init_error;
track->d_audio = talloc_zero(NULL, struct dec_audio);
struct dec_audio *d_audio = track->d_audio;
d_audio->log = mp_log_new(d_audio, mpctx->log, "!ad");
d_audio->global = mpctx->global;
d_audio->opts = mpctx->opts;
d_audio->header = track->stream;
d_audio->try_spdif = true;
if (!audio_init_best_codec(d_audio))
goto init_error;
return 1;
init_error:
audio_uninit(track->d_audio);
track->d_audio = NULL;
error_on_track(mpctx, track);
return 0;
}
void reinit_audio_chain(struct MPContext *mpctx)
{
assert(!mpctx->ao_chain);
@ -378,21 +405,14 @@ void reinit_audio_chain(struct MPContext *mpctx)
ao_c->af->replaygain_data = sh->codec->replaygain_data;
ao_c->spdif_passthrough = true;
ao_c->pts = MP_NOPTS_VALUE;
ao_c->ao_buffer = mp_audio_buffer_create(NULL);
ao_c->ao = mpctx->ao;
struct dec_audio *d_audio = talloc_zero(NULL, struct dec_audio);
d_audio->log = mp_log_new(d_audio, mpctx->log, "!ad");
d_audio->global = mpctx->global;
d_audio->opts = mpctx->opts;
d_audio->header = sh;
track->d_audio = d_audio;
ao_c->audio_src = d_audio;
d_audio->try_spdif = ao_c->spdif_passthrough;
ao_c->ao_buffer = mp_audio_buffer_create(NULL);
if (!audio_init_best_codec(d_audio))
if (!init_audio_decoder(mpctx, track))
goto init_error;
ao_c->audio_src = track->d_audio;
reset_audio_state(mpctx);
if (mpctx->ao) {

View File

@ -429,6 +429,7 @@ typedef struct MPContext {
// audio.c
void reset_audio_state(struct MPContext *mpctx);
void reinit_audio_chain(struct MPContext *mpctx);
int init_audio_decoder(struct MPContext *mpctx, struct track *track);
int reinit_audio_filters(struct MPContext *mpctx);
double playing_audio_pts(struct MPContext *mpctx);
void fill_audio_out_buffers(struct MPContext *mpctx, double endpts);
@ -555,6 +556,7 @@ int video_get_colors(struct vo_chain *vo_c, const char *item, int *value);
int video_set_colors(struct vo_chain *vo_c, const char *item, int value);
int video_vf_vo_control(struct vo_chain *vo_c, int vf_cmd, void *data);
void reset_video_state(struct MPContext *mpctx);
int init_video_decoder(struct MPContext *mpctx, struct track *track);
int reinit_video_chain(struct MPContext *mpctx);
int reinit_video_filters(struct MPContext *mpctx);
void write_video(struct MPContext *mpctx, double endpts);

View File

@ -307,6 +307,42 @@ void uninit_video_chain(struct MPContext *mpctx)
}
}
int init_video_decoder(struct MPContext *mpctx, struct track *track)
{
assert(!track->d_video);
if (!track->stream)
goto err_out;
track->d_video = talloc_zero(NULL, struct dec_video);
struct dec_video *d_video = track->d_video;
d_video->global = mpctx->global;
d_video->log = mp_log_new(d_video, mpctx->log, "!vd");
d_video->opts = mpctx->opts;
d_video->header = track->stream;
d_video->fps = d_video->header->codec->fps;
if (mpctx->vo_chain)
d_video->hwdec_info = mpctx->vo_chain->hwdec_info;
MP_VERBOSE(d_video, "Container reported FPS: %f\n", d_video->fps);
if (d_video->opts->force_fps) {
d_video->fps = d_video->opts->force_fps;
MP_INFO(mpctx, "FPS forced to %5.3f.\n", d_video->fps);
MP_INFO(mpctx, "Use --no-correct-pts to force FPS based timing.\n");
}
if (!video_init_best_codec(d_video, d_video->opts->video_decoders))
goto err_out;
return 1;
err_out:
video_uninit(track->d_video);
track->d_video = NULL;
error_on_track(mpctx, track);
return 0;
}
int reinit_video_chain(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;
@ -342,37 +378,20 @@ int reinit_video_chain(struct MPContext *mpctx)
vo_control(vo_c->vo, VOCTRL_GET_HWDEC_INFO, &vo_c->hwdec_info);
track->d_video = talloc_zero(NULL, struct dec_video);
struct dec_video *d_video = track->d_video;
d_video->global = mpctx->global;
d_video->log = mp_log_new(d_video, mpctx->log, "!vd");
d_video->opts = mpctx->opts;
d_video->header = sh;
d_video->fps = sh->codec->fps;
d_video->hwdec_info = vo_c->hwdec_info;
if (!init_video_decoder(mpctx, track))
goto err_out;
MP_VERBOSE(d_video, "Container reported FPS: %f\n", sh->codec->fps);
if (opts->force_fps) {
d_video->fps = opts->force_fps;
MP_INFO(mpctx, "FPS forced to %5.3f.\n", d_video->fps);
MP_INFO(mpctx, "Use --no-correct-pts to force FPS based timing.\n");
}
vo_c->container_fps = d_video->fps;
vo_c->video_src = track->d_video;
vo_c->container_fps = vo_c->video_src->fps;
vo_c->is_coverart = !!sh->attached_picture;
vo_c->video_src = d_video;
#if HAVE_ENCODING
if (mpctx->encode_lavc_ctx)
encode_lavc_set_video_fps(mpctx->encode_lavc_ctx, d_video->fps);
encode_lavc_set_video_fps(mpctx->encode_lavc_ctx, vo_c->container_fps);
#endif
recreate_video_filters(mpctx);
if (!video_init_best_codec(d_video, opts->video_decoders))
goto err_out;
bool saver_state = opts->pause || !opts->stop_screensaver;
vo_control(vo_c->vo, saver_state ? VOCTRL_RESTORE_SCREENSAVER
: VOCTRL_KILL_SCREENSAVER, NULL);