mirror of https://github.com/mpv-player/mpv
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) {
|
switch (cmd) {
|
||||||
case DEMUXER_CTRL_GET_TIME_LENGTH:
|
case DEMUXER_CTRL_GET_TIME_LENGTH:
|
||||||
if (in->time_length < 0)
|
if (in->time_length < 0)
|
||||||
return DEMUXER_CTRL_NOTIMPL;
|
return CONTROL_FALSE;
|
||||||
*(double *)arg = in->time_length;
|
*(double *)arg = in->time_length;
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
case DEMUXER_CTRL_STREAM_CTRL: {
|
case DEMUXER_CTRL_STREAM_CTRL: {
|
||||||
struct demux_ctrl_stream_ctrl *c = arg;
|
struct demux_ctrl_stream_ctrl *c = arg;
|
||||||
int r = cached_stream_control(in, c->ctrl, c->arg);
|
int r = cached_stream_control(in, c->ctrl, c->arg);
|
||||||
if (r == STREAM_ERROR)
|
if (r == STREAM_ERROR)
|
||||||
break;
|
break;
|
||||||
c->res = r;
|
c->res = r;
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
}
|
}
|
||||||
case DEMUXER_CTRL_GET_BITRATE_STATS: {
|
case DEMUXER_CTRL_GET_BITRATE_STATS: {
|
||||||
double *rates = arg;
|
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)
|
if (ds->selected && ds->bitrate >= 0)
|
||||||
rates[ds->type] = MPMAX(0, rates[ds->type]) + ds->bitrate;
|
rates[ds->type] = MPMAX(0, rates[ds->type]) + ds->bitrate;
|
||||||
}
|
}
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
}
|
}
|
||||||
case DEMUXER_CTRL_GET_READER_STATE: {
|
case DEMUXER_CTRL_GET_READER_STATE: {
|
||||||
struct demux_ctrl_reader_state *r = arg;
|
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_duration = 0;
|
||||||
r->ts_range[0] = MP_ADD_PTS(r->ts_range[0], in->ts_offset);
|
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);
|
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 {
|
struct demux_control_args {
|
||||||
|
@ -1714,7 +1714,7 @@ static void thread_demux_control(void *p)
|
||||||
int cmd = args->cmd;
|
int cmd = args->cmd;
|
||||||
void *arg = args->arg;
|
void *arg = args->arg;
|
||||||
struct demux_internal *in = demuxer->in;
|
struct demux_internal *in = demuxer->in;
|
||||||
int r = DEMUXER_CTRL_NOTIMPL;
|
int r = CONTROL_UNKNOWN;
|
||||||
|
|
||||||
if (cmd == DEMUXER_CTRL_STREAM_CTRL) {
|
if (cmd == DEMUXER_CTRL_STREAM_CTRL) {
|
||||||
struct demux_ctrl_stream_ctrl *c = arg;
|
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);
|
MP_VERBOSE(demuxer, "blocking for STREAM_CTRL %d\n", c->ctrl);
|
||||||
c->res = stream_control(demuxer->stream, c->ctrl, c->arg);
|
c->res = stream_control(demuxer->stream, c->ctrl, c->arg);
|
||||||
if (c->res != STREAM_UNSUPPORTED)
|
if (c->res != STREAM_UNSUPPORTED)
|
||||||
r = DEMUXER_CTRL_OK;
|
r = CONTROL_OK;
|
||||||
}
|
}
|
||||||
if (r != DEMUXER_CTRL_OK) {
|
if (r != CONTROL_OK) {
|
||||||
if (in->threading)
|
if (in->threading)
|
||||||
MP_VERBOSE(demuxer, "blocking for DEMUXER_CTRL %d\n", cmd);
|
MP_VERBOSE(demuxer, "blocking for DEMUXER_CTRL %d\n", cmd);
|
||||||
if (demuxer->desc->control)
|
if (demuxer->desc->control)
|
||||||
|
@ -1743,7 +1743,7 @@ int demux_control(demuxer_t *demuxer, int cmd, void *arg)
|
||||||
pthread_mutex_lock(&in->lock);
|
pthread_mutex_lock(&in->lock);
|
||||||
int cr = cached_demux_control(in, cmd, arg);
|
int cr = cached_demux_control(in, cmd, arg);
|
||||||
pthread_mutex_unlock(&in->lock);
|
pthread_mutex_unlock(&in->lock);
|
||||||
if (cr != DEMUXER_CTRL_DONTKNOW)
|
if (cr != CONTROL_UNKNOWN)
|
||||||
return cr;
|
return cr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,11 +30,6 @@
|
||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
#include "stheader.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 {
|
enum demux_ctrl {
|
||||||
DEMUXER_CTRL_SWITCHED_TRACKS = 1,
|
DEMUXER_CTRL_SWITCHED_TRACKS = 1,
|
||||||
DEMUXER_CTRL_GET_TIME_LENGTH,
|
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)
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_TIME_LENGTH, &len) < 1)
|
||||||
break;
|
break;
|
||||||
*(double *)arg = len;
|
*(double *)arg = len;
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
}
|
}
|
||||||
case DEMUXER_CTRL_RESYNC:
|
case DEMUXER_CTRL_RESYNC:
|
||||||
demux_flush(p->slave);
|
demux_flush(p->slave);
|
||||||
break; // relay to slave demuxer
|
break; // relay to slave demuxer
|
||||||
case DEMUXER_CTRL_SWITCHED_TRACKS:
|
case DEMUXER_CTRL_SWITCHED_TRACKS:
|
||||||
reselect_streams(demuxer);
|
reselect_streams(demuxer);
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
}
|
}
|
||||||
return demux_control(p->slave, cmd, arg);
|
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;
|
double duration = av_duration > 0 ? av_duration : total_duration;
|
||||||
if (duration <= 0)
|
if (duration <= 0)
|
||||||
return DEMUXER_CTRL_DONTKNOW;
|
return CONTROL_FALSE;
|
||||||
*(double *)arg = duration;
|
*(double *)arg = duration;
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
*((double *)arg) = (double)priv->avfc->duration / AV_TIME_BASE;
|
*((double *)arg) = (double)priv->avfc->duration / AV_TIME_BASE;
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
|
|
||||||
case DEMUXER_CTRL_SWITCHED_TRACKS:
|
case DEMUXER_CTRL_SWITCHED_TRACKS:
|
||||||
{
|
{
|
||||||
select_tracks(demuxer, 0);
|
select_tracks(demuxer, 0);
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
}
|
}
|
||||||
case DEMUXER_CTRL_IDENTIFY_PROGRAM:
|
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;
|
prog->vid = prog->aid = prog->sid = -2;
|
||||||
if (priv->avfc->nb_programs < 1)
|
if (priv->avfc->nb_programs < 1)
|
||||||
return DEMUXER_CTRL_DONTKNOW;
|
return CONTROL_FALSE;
|
||||||
|
|
||||||
if (prog->progid == -1) {
|
if (prog->progid == -1) {
|
||||||
p = 0;
|
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)
|
if (priv->avfc->programs[i]->id == prog->progid)
|
||||||
break;
|
break;
|
||||||
if (i == priv->avfc->nb_programs)
|
if (i == priv->avfc->nb_programs)
|
||||||
return DEMUXER_CTRL_DONTKNOW;
|
return CONTROL_FALSE;
|
||||||
p = i;
|
p = i;
|
||||||
}
|
}
|
||||||
start = p;
|
start = p;
|
||||||
|
@ -1126,7 +1126,7 @@ redo:
|
||||||
if (prog->progid == -1 && prog->vid == -2 && prog->aid == -2) {
|
if (prog->progid == -1 && prog->vid == -2 && prog->aid == -2) {
|
||||||
p = (p + 1) % priv->avfc->nb_programs;
|
p = (p + 1) % priv->avfc->nb_programs;
|
||||||
if (p == start)
|
if (p == start)
|
||||||
return DEMUXER_CTRL_DONTKNOW;
|
return CONTROL_FALSE;
|
||||||
goto redo;
|
goto redo;
|
||||||
}
|
}
|
||||||
priv->cur_program = prog->progid = program->id;
|
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.
|
// Enforce metadata update even if no explicit METADATA_UPDATED since we switched program.
|
||||||
demux_changed(demuxer, DEMUX_EVENT_METADATA);
|
demux_changed(demuxer, DEMUX_EVENT_METADATA);
|
||||||
|
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
}
|
}
|
||||||
case DEMUXER_CTRL_RESYNC:
|
case DEMUXER_CTRL_RESYNC:
|
||||||
/* NOTE:
|
/* NOTE:
|
||||||
|
@ -1157,15 +1157,15 @@ redo:
|
||||||
priv->avfc->pb->pos = stream_tell(priv->stream);
|
priv->avfc->pb->pos = stream_tell(priv->stream);
|
||||||
av_seek_frame(priv->avfc, 0, stream_tell(priv->stream),
|
av_seek_frame(priv->avfc, 0, stream_tell(priv->stream),
|
||||||
AVSEEK_FLAG_BYTE);
|
AVSEEK_FLAG_BYTE);
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
case DEMUXER_CTRL_REPLACE_STREAM:
|
case DEMUXER_CTRL_REPLACE_STREAM:
|
||||||
if (priv->own_stream)
|
if (priv->own_stream)
|
||||||
free_stream(priv->stream);
|
free_stream(priv->stream);
|
||||||
priv->own_stream = false;
|
priv->own_stream = false;
|
||||||
priv->stream = demuxer->stream;
|
priv->stream = demuxer->stream;
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
default:
|
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) {
|
switch (cmd) {
|
||||||
case DEMUXER_CTRL_GET_TIME_LENGTH:
|
case DEMUXER_CTRL_GET_TIME_LENGTH:
|
||||||
*((double *)arg) = (double)mf->nr_of_files / mf->sh->codec->fps;
|
*((double *)arg) = (double)mf->nr_of_files / mf->sh->codec->fps;
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
|
|
||||||
default:
|
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) {
|
switch (cmd) {
|
||||||
case DEMUXER_CTRL_GET_TIME_LENGTH:
|
case DEMUXER_CTRL_GET_TIME_LENGTH:
|
||||||
if (mkv_d->duration == 0)
|
if (mkv_d->duration == 0)
|
||||||
return DEMUXER_CTRL_DONTKNOW;
|
return CONTROL_FALSE;
|
||||||
|
|
||||||
*((double *) arg) = (double) mkv_d->duration;
|
*((double *) arg) = (double) mkv_d->duration;
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
default:
|
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;
|
stream_t *s = demuxer->stream;
|
||||||
int64_t end = 0;
|
int64_t end = 0;
|
||||||
if (stream_control(s, STREAM_CTRL_GET_SIZE, &end) != STREAM_OK)
|
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;
|
*((double *) arg) = (end / p->frame_size) / p->frame_rate;
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
}
|
}
|
||||||
default:
|
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) {
|
switch (cmd) {
|
||||||
case DEMUXER_CTRL_GET_TIME_LENGTH: {
|
case DEMUXER_CTRL_GET_TIME_LENGTH: {
|
||||||
*(double *)arg = p->duration;
|
*(double *)arg = p->duration;
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
}
|
}
|
||||||
case DEMUXER_CTRL_SWITCHED_TRACKS:
|
case DEMUXER_CTRL_SWITCHED_TRACKS:
|
||||||
reselect_streams(demuxer);
|
reselect_streams(demuxer);
|
||||||
return DEMUXER_CTRL_OK;
|
return CONTROL_OK;
|
||||||
}
|
}
|
||||||
return DEMUXER_CTRL_NOTIMPL;
|
return CONTROL_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
const demuxer_desc_t demuxer_desc_timeline = {
|
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);
|
tvi_handle_t *tvh=(tvi_handle_t*)(demuxer->priv);
|
||||||
if (cmd != DEMUXER_CTRL_STREAM_CTRL)
|
if (cmd != DEMUXER_CTRL_STREAM_CTRL)
|
||||||
return DEMUXER_CTRL_NOTIMPL;
|
return CONTROL_UNKNOWN;
|
||||||
struct demux_ctrl_stream_ctrl *ctrl = arg;
|
struct demux_ctrl_stream_ctrl *ctrl = arg;
|
||||||
ctrl->res = tv_stream_control(tvh, ctrl->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 = {
|
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)
|
int action, void *arg)
|
||||||
{
|
{
|
||||||
MPContext *mpctx = ctx;
|
MPContext *mpctx = ctx;
|
||||||
demux_program_t prog;
|
demux_program_t prog = {0};
|
||||||
|
|
||||||
struct demuxer *demuxer = mpctx->demuxer;
|
struct demuxer *demuxer = mpctx->demuxer;
|
||||||
if (!demuxer || !mpctx->playback_initialized)
|
if (!demuxer || !mpctx->playback_initialized)
|
||||||
|
@ -2384,7 +2384,7 @@ static int mp_property_program(void *ctx, struct m_property *prop,
|
||||||
else
|
else
|
||||||
prog.progid = -1;
|
prog.progid = -1;
|
||||||
if (demux_control(demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM, &prog) ==
|
if (demux_control(demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM, &prog) ==
|
||||||
DEMUXER_CTRL_NOTIMPL)
|
CONTROL_UNKNOWN)
|
||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
|
|
||||||
if (prog.aid < 0 && prog.vid < 0) {
|
if (prog.aid < 0 && prog.vid < 0) {
|
||||||
|
|
Loading…
Reference in New Issue