mirror of
https://github.com/mpv-player/mpv
synced 2024-12-22 14:52:43 +00:00
demux: replace custom return codes with CONTROL_ ones
This is more uniform, and potentially gets rid of some past copyrights. It might be that this subtly changes caching behavior (it seems before this, it synced to the demuxer if the length was unknown, which is not what we want.)
This commit is contained in:
parent
e0c50289d6
commit
f34e1a0dee
@ -1647,16 +1647,16 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg)
|
||||
switch (cmd) {
|
||||
case DEMUXER_CTRL_GET_TIME_LENGTH:
|
||||
if (in->time_length < 0)
|
||||
return DEMUXER_CTRL_NOTIMPL;
|
||||
return CONTROL_FALSE;
|
||||
*(double *)arg = in->time_length;
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
case DEMUXER_CTRL_STREAM_CTRL: {
|
||||
struct demux_ctrl_stream_ctrl *c = arg;
|
||||
int r = cached_stream_control(in, c->ctrl, c->arg);
|
||||
if (r == STREAM_ERROR)
|
||||
break;
|
||||
c->res = r;
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
}
|
||||
case DEMUXER_CTRL_GET_BITRATE_STATS: {
|
||||
double *rates = arg;
|
||||
@ -1667,7 +1667,7 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg)
|
||||
if (ds->selected && ds->bitrate >= 0)
|
||||
rates[ds->type] = MPMAX(0, rates[ds->type]) + ds->bitrate;
|
||||
}
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
}
|
||||
case DEMUXER_CTRL_GET_READER_STATE: {
|
||||
struct demux_ctrl_reader_state *r = arg;
|
||||
@ -1694,10 +1694,10 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg)
|
||||
r->ts_duration = 0;
|
||||
r->ts_range[0] = MP_ADD_PTS(r->ts_range[0], in->ts_offset);
|
||||
r->ts_range[1] = MP_ADD_PTS(r->ts_range[1], in->ts_offset);
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
}
|
||||
}
|
||||
return DEMUXER_CTRL_DONTKNOW;
|
||||
return CONTROL_UNKNOWN;
|
||||
}
|
||||
|
||||
struct demux_control_args {
|
||||
@ -1714,7 +1714,7 @@ static void thread_demux_control(void *p)
|
||||
int cmd = args->cmd;
|
||||
void *arg = args->arg;
|
||||
struct demux_internal *in = demuxer->in;
|
||||
int r = DEMUXER_CTRL_NOTIMPL;
|
||||
int r = CONTROL_UNKNOWN;
|
||||
|
||||
if (cmd == DEMUXER_CTRL_STREAM_CTRL) {
|
||||
struct demux_ctrl_stream_ctrl *c = arg;
|
||||
@ -1722,9 +1722,9 @@ static void thread_demux_control(void *p)
|
||||
MP_VERBOSE(demuxer, "blocking for STREAM_CTRL %d\n", c->ctrl);
|
||||
c->res = stream_control(demuxer->stream, c->ctrl, c->arg);
|
||||
if (c->res != STREAM_UNSUPPORTED)
|
||||
r = DEMUXER_CTRL_OK;
|
||||
r = CONTROL_OK;
|
||||
}
|
||||
if (r != DEMUXER_CTRL_OK) {
|
||||
if (r != CONTROL_OK) {
|
||||
if (in->threading)
|
||||
MP_VERBOSE(demuxer, "blocking for DEMUXER_CTRL %d\n", cmd);
|
||||
if (demuxer->desc->control)
|
||||
@ -1743,7 +1743,7 @@ int demux_control(demuxer_t *demuxer, int cmd, void *arg)
|
||||
pthread_mutex_lock(&in->lock);
|
||||
int cr = cached_demux_control(in, cmd, arg);
|
||||
pthread_mutex_unlock(&in->lock);
|
||||
if (cr != DEMUXER_CTRL_DONTKNOW)
|
||||
if (cr != CONTROL_UNKNOWN)
|
||||
return cr;
|
||||
}
|
||||
|
||||
|
@ -30,11 +30,6 @@
|
||||
#include "packet.h"
|
||||
#include "stheader.h"
|
||||
|
||||
// DEMUXER control commands/answers
|
||||
#define DEMUXER_CTRL_NOTIMPL -1
|
||||
#define DEMUXER_CTRL_DONTKNOW 0
|
||||
#define DEMUXER_CTRL_OK 1
|
||||
|
||||
enum demux_ctrl {
|
||||
DEMUXER_CTRL_SWITCHED_TRACKS = 1,
|
||||
DEMUXER_CTRL_GET_TIME_LENGTH,
|
||||
|
@ -357,14 +357,14 @@ static int d_control(demuxer_t *demuxer, int cmd, void *arg)
|
||||
if (stream_control(demuxer->stream, STREAM_CTRL_GET_TIME_LENGTH, &len) < 1)
|
||||
break;
|
||||
*(double *)arg = len;
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
}
|
||||
case DEMUXER_CTRL_RESYNC:
|
||||
demux_flush(p->slave);
|
||||
break; // relay to slave demuxer
|
||||
case DEMUXER_CTRL_SWITCHED_TRACKS:
|
||||
reselect_streams(demuxer);
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
}
|
||||
return demux_control(p->slave, cmd, arg);
|
||||
}
|
||||
|
@ -1061,18 +1061,18 @@ static int demux_lavf_control(demuxer_t *demuxer, int cmd, void *arg)
|
||||
}
|
||||
double duration = av_duration > 0 ? av_duration : total_duration;
|
||||
if (duration <= 0)
|
||||
return DEMUXER_CTRL_DONTKNOW;
|
||||
return CONTROL_FALSE;
|
||||
*(double *)arg = duration;
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
}
|
||||
|
||||
*((double *)arg) = (double)priv->avfc->duration / AV_TIME_BASE;
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
|
||||
case DEMUXER_CTRL_SWITCHED_TRACKS:
|
||||
{
|
||||
select_tracks(demuxer, 0);
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
}
|
||||
case DEMUXER_CTRL_IDENTIFY_PROGRAM:
|
||||
{
|
||||
@ -1085,7 +1085,7 @@ static int demux_lavf_control(demuxer_t *demuxer, int cmd, void *arg)
|
||||
|
||||
prog->vid = prog->aid = prog->sid = -2;
|
||||
if (priv->avfc->nb_programs < 1)
|
||||
return DEMUXER_CTRL_DONTKNOW;
|
||||
return CONTROL_FALSE;
|
||||
|
||||
if (prog->progid == -1) {
|
||||
p = 0;
|
||||
@ -1097,7 +1097,7 @@ static int demux_lavf_control(demuxer_t *demuxer, int cmd, void *arg)
|
||||
if (priv->avfc->programs[i]->id == prog->progid)
|
||||
break;
|
||||
if (i == priv->avfc->nb_programs)
|
||||
return DEMUXER_CTRL_DONTKNOW;
|
||||
return CONTROL_FALSE;
|
||||
p = i;
|
||||
}
|
||||
start = p;
|
||||
@ -1126,7 +1126,7 @@ redo:
|
||||
if (prog->progid == -1 && prog->vid == -2 && prog->aid == -2) {
|
||||
p = (p + 1) % priv->avfc->nb_programs;
|
||||
if (p == start)
|
||||
return DEMUXER_CTRL_DONTKNOW;
|
||||
return CONTROL_FALSE;
|
||||
goto redo;
|
||||
}
|
||||
priv->cur_program = prog->progid = program->id;
|
||||
@ -1136,7 +1136,7 @@ redo:
|
||||
// Enforce metadata update even if no explicit METADATA_UPDATED since we switched program.
|
||||
demux_changed(demuxer, DEMUX_EVENT_METADATA);
|
||||
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
}
|
||||
case DEMUXER_CTRL_RESYNC:
|
||||
/* NOTE:
|
||||
@ -1157,15 +1157,15 @@ redo:
|
||||
priv->avfc->pb->pos = stream_tell(priv->stream);
|
||||
av_seek_frame(priv->avfc, 0, stream_tell(priv->stream),
|
||||
AVSEEK_FLAG_BYTE);
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
case DEMUXER_CTRL_REPLACE_STREAM:
|
||||
if (priv->own_stream)
|
||||
free_stream(priv->stream);
|
||||
priv->own_stream = false;
|
||||
priv->stream = demuxer->stream;
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
default:
|
||||
return DEMUXER_CTRL_NOTIMPL;
|
||||
return CONTROL_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,10 +353,10 @@ static int demux_control_mf(demuxer_t *demuxer, int cmd, void *arg)
|
||||
switch (cmd) {
|
||||
case DEMUXER_CTRL_GET_TIME_LENGTH:
|
||||
*((double *)arg) = (double)mf->nr_of_files / mf->sh->codec->fps;
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
|
||||
default:
|
||||
return DEMUXER_CTRL_NOTIMPL;
|
||||
return CONTROL_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3123,12 +3123,12 @@ static int demux_mkv_control(demuxer_t *demuxer, int cmd, void *arg)
|
||||
switch (cmd) {
|
||||
case DEMUXER_CTRL_GET_TIME_LENGTH:
|
||||
if (mkv_d->duration == 0)
|
||||
return DEMUXER_CTRL_DONTKNOW;
|
||||
return CONTROL_FALSE;
|
||||
|
||||
*((double *) arg) = (double) mkv_d->duration;
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
default:
|
||||
return DEMUXER_CTRL_NOTIMPL;
|
||||
return CONTROL_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,13 +306,13 @@ static int raw_control(demuxer_t *demuxer, int cmd, void *arg)
|
||||
stream_t *s = demuxer->stream;
|
||||
int64_t end = 0;
|
||||
if (stream_control(s, STREAM_CTRL_GET_SIZE, &end) != STREAM_OK)
|
||||
return DEMUXER_CTRL_DONTKNOW;
|
||||
return CONTROL_FALSE;
|
||||
|
||||
*((double *) arg) = (end / p->frame_size) / p->frame_rate;
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
}
|
||||
default:
|
||||
return DEMUXER_CTRL_NOTIMPL;
|
||||
return CONTROL_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -436,13 +436,13 @@ static int d_control(struct demuxer *demuxer, int cmd, void *arg)
|
||||
switch (cmd) {
|
||||
case DEMUXER_CTRL_GET_TIME_LENGTH: {
|
||||
*(double *)arg = p->duration;
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
}
|
||||
case DEMUXER_CTRL_SWITCHED_TRACKS:
|
||||
reselect_streams(demuxer);
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
}
|
||||
return DEMUXER_CTRL_NOTIMPL;
|
||||
return CONTROL_UNKNOWN;
|
||||
}
|
||||
|
||||
const demuxer_desc_t demuxer_desc_timeline = {
|
||||
|
@ -227,10 +227,10 @@ static int demux_tv_control(demuxer_t *demuxer, int cmd, void *arg)
|
||||
{
|
||||
tvi_handle_t *tvh=(tvi_handle_t*)(demuxer->priv);
|
||||
if (cmd != DEMUXER_CTRL_STREAM_CTRL)
|
||||
return DEMUXER_CTRL_NOTIMPL;
|
||||
return CONTROL_UNKNOWN;
|
||||
struct demux_ctrl_stream_ctrl *ctrl = arg;
|
||||
ctrl->res = tv_stream_control(tvh, ctrl->ctrl, ctrl->arg);
|
||||
return DEMUXER_CTRL_OK;
|
||||
return CONTROL_OK;
|
||||
}
|
||||
|
||||
const demuxer_desc_t demuxer_desc_tv = {
|
||||
|
@ -2370,7 +2370,7 @@ static int mp_property_program(void *ctx, struct m_property *prop,
|
||||
int action, void *arg)
|
||||
{
|
||||
MPContext *mpctx = ctx;
|
||||
demux_program_t prog;
|
||||
demux_program_t prog = {0};
|
||||
|
||||
struct demuxer *demuxer = mpctx->demuxer;
|
||||
if (!demuxer || !mpctx->playback_initialized)
|
||||
@ -2384,7 +2384,7 @@ static int mp_property_program(void *ctx, struct m_property *prop,
|
||||
else
|
||||
prog.progid = -1;
|
||||
if (demux_control(demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM, &prog) ==
|
||||
DEMUXER_CTRL_NOTIMPL)
|
||||
CONTROL_UNKNOWN)
|
||||
return M_PROPERTY_ERROR;
|
||||
|
||||
if (prog.aid < 0 && prog.vid < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user