Skip to content

Commit

Permalink
player: refactor: eliminate MPContext.d_video
Browse files Browse the repository at this point in the history
Eventually we want the VO be driven by a A->V filter, so a decoder
doesn't even have to exist. Some features definitely require a decoder
though (like reporting the decoder in use, hardware decoding, etc.), so
for each thing which accessed d_video, it has to be redecided if and how
it can access decoder state.

At least the "framedrop" property slightly changes semantics: you can
now always set this property, even if no video is active.

Some untested changes in this commit, but our bio-based distributed
test suite has to take care of this.
  • Loading branch information
wm4 committed Jan 17, 2016
1 parent 004bc95 commit 4195a34
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 100 deletions.
4 changes: 2 additions & 2 deletions player/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ static bool get_sync_samples(struct MPContext *mpctx, int *skip)
if (written_pts == MP_NOPTS_VALUE && !mp_audio_buffer_samples(mpctx->ao_buffer))
return false; // no audio read yet

bool sync_to_video = mpctx->d_video && mpctx->sync_audio_to_video &&
bool sync_to_video = mpctx->vo_chain && mpctx->sync_audio_to_video &&
mpctx->video_status != STATUS_EOF;

double sync_pts = MP_NOPTS_VALUE;
Expand Down Expand Up @@ -545,7 +545,7 @@ void fill_audio_out_buffers(struct MPContext *mpctx, double endpts)
return; // try again next iteration
}

if (mpctx->d_video && d_audio->pts_reset) {
if (mpctx->vo_chain && d_audio->pts_reset) {
MP_VERBOSE(mpctx, "Reset playback due to audio timestamp reset.\n");
reset_playback_state(mpctx);
mpctx->sleeptime = 0;
Expand Down
86 changes: 43 additions & 43 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ static int mp_property_avsync(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->d_audio || !mpctx->d_video)
if (!mpctx->d_audio || !mpctx->vo_chain)
return M_PROPERTY_UNAVAILABLE;
if (action == M_PROPERTY_PRINT) {
*(char **)arg = talloc_asprintf(NULL, "%7.3f", mpctx->last_av_difference);
Expand All @@ -549,7 +549,7 @@ static int mp_property_total_avsync_change(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->d_audio || !mpctx->d_video)
if (!mpctx->d_audio || !mpctx->vo_chain)
return M_PROPERTY_UNAVAILABLE;
if (mpctx->total_avsync_change == MP_NOPTS_VALUE)
return M_PROPERTY_UNAVAILABLE;
Expand All @@ -560,17 +560,17 @@ static int mp_property_drop_frame_cnt(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->d_video)
if (!mpctx->vo_chain)
return M_PROPERTY_UNAVAILABLE;

return m_property_int_ro(action, arg, mpctx->d_video->dropped_frames);
return m_property_int_ro(action, arg, mpctx->vo_chain->video_src->dropped_frames);
}

static int mp_property_mistimed_frame_count(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->d_video || !mpctx->display_sync_active)
if (!mpctx->vo_chain || !mpctx->display_sync_active)
return M_PROPERTY_UNAVAILABLE;

return m_property_int_ro(action, arg, mpctx->mistimed_frames_total);
Expand All @@ -580,7 +580,7 @@ static int mp_property_vsync_ratio(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->d_video || !mpctx->display_sync_active)
if (!mpctx->vo_chain || !mpctx->display_sync_active)
return M_PROPERTY_UNAVAILABLE;

int vsyncs = 0, frames = 0;
Expand All @@ -602,7 +602,7 @@ static int mp_property_vo_drop_frame_count(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->d_video)
if (!mpctx->vo_chain)
return M_PROPERTY_UNAVAILABLE;

return m_property_int_ro(action, arg, vo_get_drop_count(mpctx->video_out));
Expand All @@ -612,7 +612,7 @@ static int mp_property_vo_delayed_frame_count(void *ctx, struct m_property *prop
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->d_video)
if (!mpctx->vo_chain)
return M_PROPERTY_UNAVAILABLE;

return m_property_int_ro(action, arg, vo_get_delayed_count(mpctx->video_out));
Expand Down Expand Up @@ -1696,7 +1696,7 @@ static int mp_property_audio_delay(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!(mpctx->d_audio && mpctx->d_video))
if (!(mpctx->d_audio && mpctx->vo_chain))
return M_PROPERTY_UNAVAILABLE;
float delay = mpctx->opts->audio_delay;
switch (action) {
Expand Down Expand Up @@ -2101,8 +2101,9 @@ static int mp_property_hwdec(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
struct track *track = mpctx->current_track[0][STREAM_VIDEO];
struct dec_video *vd = track ? track->d_video : NULL;
struct MPOpts *opts = mpctx->opts;
struct dec_video *vd = mpctx->d_video;

if (action == M_PROPERTY_SET) {
int new = *(int *)arg;
Expand Down Expand Up @@ -2133,7 +2134,8 @@ static int mp_property_hwdec_active(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
struct dec_video *vd = mpctx->d_video;
struct track *track = mpctx->current_track[0][STREAM_VIDEO];
struct dec_video *vd = track ? track->d_video : NULL;
bool active = false;
if (vd) {
int current = 0;
Expand All @@ -2147,7 +2149,8 @@ static int mp_property_detected_hwdec(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
struct dec_video *vd = mpctx->d_video;
struct track *track = mpctx->current_track[0][STREAM_VIDEO];
struct dec_video *vd = track ? track->d_video : NULL;

switch (action) {
case M_PROPERTY_GET_TYPE: {
Expand Down Expand Up @@ -2358,11 +2361,11 @@ static int get_frame_count(struct MPContext *mpctx)
{
struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer)
return 0;
if (!mpctx->d_video)
return 0;
return -1;
if (!mpctx->vo_chain)
return -1;
double len = get_time_length(mpctx);
double fps = mpctx->d_video->fps;
double fps = mpctx->vo_chain->container_fps;
if (len < 0 || fps <= 0)
return 0;

Expand All @@ -2373,32 +2376,23 @@ static int mp_property_frame_number(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->d_video)
int frames = get_frame_count(mpctx);
if (frames < 0)
return M_PROPERTY_UNAVAILABLE;

return m_property_int_ro(action, arg,
lrint(get_current_pos_ratio(mpctx, false) * get_frame_count(mpctx)));
lrint(get_current_pos_ratio(mpctx, false) * frames));
}

static int mp_property_frame_count(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;

if (!mpctx->d_video)
int frames = get_frame_count(mpctx);
if (frames < 0)
return M_PROPERTY_UNAVAILABLE;

return m_property_int_ro(action, arg, get_frame_count(mpctx));
}

static int mp_property_framedrop(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->d_video)
return M_PROPERTY_UNAVAILABLE;

return mp_property_generic_option(mpctx, prop, action, arg);
return m_property_int_ro(action, arg, frames);
}

static int mp_property_video_color(void *ctx, struct m_property *prop,
Expand Down Expand Up @@ -2433,7 +2427,8 @@ static int mp_property_video_format(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
const char *c = mpctx->d_video ? mpctx->d_video->header->codec->codec : NULL;
struct track *track = mpctx->current_track[0][STREAM_VIDEO];
const char *c = track && track->stream ? track->stream->codec->codec : NULL;
return m_property_strdup_ro(action, arg, c);
}

Expand All @@ -2442,7 +2437,8 @@ static int mp_property_video_codec(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
const char *c = mpctx->d_video ? mpctx->d_video->decoder_desc : NULL;
struct track *track = mpctx->current_track[0][STREAM_VIDEO];
const char *c = track->d_video ? track->d_video->decoder_desc : NULL;
return m_property_strdup_ro(action, arg, c);
}

Expand Down Expand Up @@ -2511,12 +2507,14 @@ static int mp_property_vd_imgparams(void *ctx, struct m_property *prop,
{
MPContext *mpctx = ctx;
struct vo_chain *vo_c = mpctx->vo_chain;
if (!vo_c && !mpctx->d_video)
struct track *track = mpctx->current_track[0][STREAM_VIDEO];
if (!vo_c || !track)
return M_PROPERTY_UNAVAILABLE;
struct mp_codec_params *c = mpctx->d_video->header->codec;
struct mp_codec_params *c =
track && track->stream ? track->stream->codec : NULL;
if (vo_c->vf->input_params.imgfmt) {
return property_imgparams(vo_c->vf->input_params, action, arg);
} else if (c->disp_w && c->disp_h) {
} else if (c && c->disp_w && c->disp_h) {
// Simplistic fallback for stupid scripts querying "width"/"height"
// before the first frame is decoded.
struct m_sub_property props[] = {
Expand Down Expand Up @@ -2744,7 +2742,7 @@ static int mp_property_fps(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
float fps = mpctx->d_video ? mpctx->d_video->fps : 0;
float fps = mpctx->vo_chain ? mpctx->vo_chain->container_fps : 0;
if (fps < 0.1 || !isfinite(fps))
return M_PROPERTY_UNAVAILABLE;;
return m_property_float_ro(action, arg, fps);
Expand All @@ -2754,7 +2752,7 @@ static int mp_property_vf_fps(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->d_video)
if (!mpctx->vo_chain)
return M_PROPERTY_UNAVAILABLE;
double avg = calc_average_frame_duration(mpctx);
if (avg <= 0)
Expand All @@ -2770,8 +2768,9 @@ static int mp_property_aspect(void *ctx, struct m_property *prop,
switch (action) {
case M_PROPERTY_SET: {
mpctx->opts->movie_aspect = *(float *)arg;
if (mpctx->d_video) {
video_reset_aspect(mpctx->d_video);
struct track *track = mpctx->current_track[0][STREAM_VIDEO];
if (track && track->d_video) {
video_reset_aspect(track->d_video);
mp_force_video_refresh(mpctx);
}
return M_PROPERTY_OK;
Expand All @@ -2785,8 +2784,9 @@ static int mp_property_aspect(void *ctx, struct m_property *prop,
}
case M_PROPERTY_GET: {
float aspect = mpctx->opts->movie_aspect;
if (mpctx->d_video && mpctx->vo_chain && aspect <= 0) {
struct dec_video *d_video = mpctx->d_video;
struct track *track = mpctx->current_track[0][STREAM_VIDEO];
if (track && track->d_video && mpctx->vo_chain && aspect <= 0) {
struct dec_video *d_video = track->d_video;
struct mp_codec_params *c = d_video->header->codec;
struct mp_image_params *params = &mpctx->vo_chain->vf->input_params;
if (params && params->p_w > 0 && params->p_h > 0) {
Expand Down Expand Up @@ -3575,7 +3575,7 @@ static const struct m_property mp_properties[] = {
{"ontop", mp_property_ontop},
{"border", mp_property_border},
{"on-all-workspaces", mp_property_all_workspaces},
{"framedrop", mp_property_framedrop},
{"framedrop", mp_property_generic_option},
{"gamma", mp_property_video_color},
{"brightness", mp_property_video_color},
{"contrast", mp_property_video_color},
Expand Down
9 changes: 8 additions & 1 deletion player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ struct track {
// Current subtitle state (or cached state if selected==false).
struct dec_sub *d_sub;

// Current video decoding state (NULL if selected==false)
struct dec_video *d_video;

// For external subtitles, which are read fully on init. Do not attempt
// to read packets from them.
bool preloaded;
Expand All @@ -153,6 +156,9 @@ struct track {
struct vo_chain {
struct mp_log *log;

struct mp_hwdec_info *hwdec_info;
double container_fps;

struct vf_chain *vf;
struct vo *vo;

Expand All @@ -161,6 +167,8 @@ struct vo_chain {

// Last known input_mpi format (so vf can be reinitialized any time).
struct mp_image_params input_format;

struct dec_video *video_src;
};

/* Note that playback can be paused, stopped, etc. at any time. While paused,
Expand Down Expand Up @@ -259,7 +267,6 @@ typedef struct MPContext {
// Currently, this is used for the secondary subtitle track only.
struct track *current_track[NUM_PTRACKS][STREAM_TYPE_COUNT];

struct dec_video *d_video;
struct dec_audio *d_audio;

// Uses: accessing metadata (consider ordered chapters case, where the main
Expand Down
3 changes: 0 additions & 3 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@

static void uninit_demuxer(struct MPContext *mpctx)
{
assert(!mpctx->d_video && !mpctx->d_audio);
for (int r = 0; r < NUM_PTRACKS; r++) {
for (int t = 0; t < STREAM_TYPE_COUNT; t++)
mpctx->current_track[r][t] = NULL;
Expand Down Expand Up @@ -1088,8 +1087,6 @@ static void play_current_file(struct MPContext *mpctx)

assert(mpctx->stream == NULL);
assert(mpctx->demuxer == NULL);
assert(mpctx->d_audio == NULL);
assert(mpctx->d_video == NULL);

if (process_open_hooks(mpctx) < 0)
goto terminate_playback;
Expand Down
8 changes: 4 additions & 4 deletions player/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static void print_status(struct MPContext *mpctx)

if (mpctx->d_audio)
saddf(&line, "A");
if (mpctx->d_video)
if (mpctx->vo_chain)
saddf(&line, "V");
saddf(&line, ": ");

Expand All @@ -217,7 +217,7 @@ static void print_status(struct MPContext *mpctx)
saddf(&line, " x%4.2f", opts->playback_speed);

// A-V sync
if (mpctx->d_audio && mpctx->d_video && mpctx->sync_audio_to_video) {
if (mpctx->d_audio && mpctx->vo_chain && mpctx->sync_audio_to_video) {
saddf(&line, " A-V:%7.3f", mpctx->last_av_difference);
if (fabs(mpctx->total_avsync_change) > 0.05)
saddf(&line, " ct:%7.3f", mpctx->total_avsync_change);
Expand All @@ -235,15 +235,15 @@ static void print_status(struct MPContext *mpctx)
#endif
{
// VO stats
if (mpctx->d_video) {
if (mpctx->vo_chain) {
if (mpctx->display_sync_active) {
char *r = mp_property_expand_string(mpctx, "${vsync-ratio}");
saddf(&line, " DS: %s/%"PRId64, r,
vo_get_delayed_count(mpctx->video_out));
talloc_free(r);
}
int64_t c = vo_get_drop_count(mpctx->video_out);
int dropped_frames = mpctx->d_video->dropped_frames;
int dropped_frames = mpctx->vo_chain->video_src->dropped_frames;
if (c > 0 || dropped_frames > 0) {
saddf(&line, " Dropped: %"PRId64, c);
if (dropped_frames)
Expand Down
Loading

0 comments on commit 4195a34

Please sign in to comment.