audio/video: merge decoder return values

Will be helpful for the coming filter support. I planned on merging
audio/video decoding, but this will have to wait a bit longer, so only
remove the duplicate status codes.
This commit is contained in:
wm4
2016-02-01 21:32:01 +01:00
parent 07d8a0e142
commit ab318aeea8
7 changed files with 43 additions and 46 deletions

View File

@@ -201,7 +201,7 @@ void audio_work(struct dec_audio *da)
return;
if (!da->packet && demux_read_packet_async(da->header, &da->packet) == 0) {
da->current_state = AUDIO_WAIT;
da->current_state = DATA_WAIT;
return;
}
@@ -218,30 +218,30 @@ void audio_work(struct dec_audio *da)
da->current_frame = NULL;
}
da->current_state = AUDIO_OK;
da->current_state = DATA_OK;
if (!da->current_frame) {
da->current_state = AUDIO_EOF;
da->current_state = DATA_EOF;
if (had_packet)
da->current_state = AUDIO_SKIP;
da->current_state = DATA_AGAIN;
}
fix_audio_pts(da);
}
// Fetch an audio frame decoded with audio_work(). Returns one of:
// AUDIO_OK: *out_frame is set to a new image
// AUDIO_WAIT: waiting for demuxer; will receive a wakeup signal
// AUDIO_EOF: end of file, no more frames to be expected
// AUDIO_SKIP: dropped frame or something similar
// DATA_OK: *out_frame is set to a new image
// DATA_WAIT: waiting for demuxer; will receive a wakeup signal
// DATA_EOF: end of file, no more frames to be expected
// DATA_AGAIN: dropped frame or something similar
int audio_get_frame(struct dec_audio *da, struct mp_audio **out_frame)
{
*out_frame = NULL;
if (da->current_frame) {
*out_frame = da->current_frame;
da->current_frame = NULL;
return AUDIO_OK;
return DATA_OK;
}
if (da->current_state == AUDIO_OK)
return AUDIO_SKIP;
if (da->current_state == DATA_OK)
return DATA_AGAIN;
return da->current_state;
}

View File

@@ -52,11 +52,6 @@ int audio_init_best_codec(struct dec_audio *d_audio);
void audio_uninit(struct dec_audio *d_audio);
void audio_work(struct dec_audio *d_audio);
#define AUDIO_OK 1
#define AUDIO_WAIT 0
#define AUDIO_EOF -1
#define AUDIO_SKIP -2
int audio_get_frame(struct dec_audio *d_audio, struct mp_audio **out_frame);
void audio_reset_decoding(struct dec_audio *d_audio);

View File

@@ -57,6 +57,13 @@ enum stream_type {
STREAM_TYPE_COUNT,
};
enum {
DATA_OK = 1,
DATA_WAIT = 0,
DATA_AGAIN = -1,
DATA_EOF = -2,
};
extern const char *const mpv_version;
extern const char *const mpv_builddate;

View File

@@ -577,16 +577,16 @@ static int decode_new_frame(struct ao_chain *ao_c)
if (ao_c->input_frame)
return AD_OK;
int res = AUDIO_SKIP;
while (res == AUDIO_SKIP) {
int res = DATA_AGAIN;
while (res == DATA_AGAIN) {
audio_work(ao_c->audio_src);
res = audio_get_frame(ao_c->audio_src, &ao_c->input_frame);
}
switch (res) {
case AUDIO_OK: return AD_OK;
case AUDIO_WAIT: return AD_WAIT;
case AUDIO_EOF: return AD_EOF;
case DATA_OK: return AD_OK;
case DATA_WAIT: return AD_WAIT;
case DATA_EOF: return AD_EOF;
default: abort();
}
}

View File

@@ -456,8 +456,8 @@ static int decode_image(struct MPContext *mpctx)
assert(!vo_c->input_mpi);
int st = video_get_frame(d_video, &vo_c->input_mpi);
switch (st) {
case VIDEO_WAIT: return VD_WAIT;
case VIDEO_EOF: return VD_EOF;
case DATA_WAIT: return VD_WAIT;
case DATA_EOF: return VD_EOF;
default: return VD_PROGRESS;
}
}

View File

@@ -67,7 +67,7 @@ void video_reset(struct dec_video *d_video)
d_video->codec_dts = MP_NOPTS_VALUE;
d_video->last_format = d_video->fixed_format = (struct mp_image_params){0};
d_video->dropped_frames = 0;
d_video->current_state = VIDEO_SKIP;
d_video->current_state = DATA_AGAIN;
mp_image_unrefp(&d_video->current_mpi);
}
@@ -382,24 +382,24 @@ void video_work(struct dec_video *d_video)
return;
if (d_video->header->attached_picture) {
if (d_video->current_state == VIDEO_SKIP && !d_video->cover_art_mpi) {
if (d_video->current_state == DATA_AGAIN && !d_video->cover_art_mpi) {
d_video->cover_art_mpi =
decode_packet(d_video, d_video->header->attached_picture, 0);
// Might need flush.
if (!d_video->cover_art_mpi)
d_video->cover_art_mpi = decode_packet(d_video, NULL, 0);
d_video->current_state = VIDEO_OK;
d_video->current_state = DATA_OK;
}
if (d_video->current_state == VIDEO_OK)
if (d_video->current_state == DATA_OK)
d_video->current_mpi = mp_image_new_ref(d_video->cover_art_mpi);
// (VIDEO_OK is returned the first time, when current_mpi is sill set)
d_video->current_state = VIDEO_EOF;
// (DATA_OK is returned the first time, when current_mpi is sill set)
d_video->current_state = DATA_EOF;
return;
}
struct demux_packet *pkt;
if (demux_read_packet_async(d_video->header, &pkt) == 0) {
d_video->current_state = VIDEO_WAIT;
d_video->current_state = DATA_WAIT;
return;
}
@@ -414,31 +414,31 @@ void video_work(struct dec_video *d_video)
bool had_packet = !!pkt;
talloc_free(pkt);
d_video->current_state = VIDEO_OK;
d_video->current_state = DATA_OK;
if (!d_video->current_mpi) {
d_video->current_state = VIDEO_EOF;
d_video->current_state = DATA_EOF;
if (had_packet) {
if (framedrop_type == 1)
d_video->dropped_frames += 1;
d_video->current_state = VIDEO_SKIP;
d_video->current_state = DATA_AGAIN;
}
}
}
// Fetch an image decoded with video_work(). Returns one of:
// VIDEO_OK: *out_mpi is set to a new image
// VIDEO_WAIT: waiting for demuxer; will receive a wakeup signal
// VIDEO_EOF: end of file, no more frames to be expected
// VIDEO_SKIP: dropped frame or something similar
// DATA_OK: *out_mpi is set to a new image
// DATA_WAIT: waiting for demuxer; will receive a wakeup signal
// DATA_EOF: end of file, no more frames to be expected
// DATA_AGAIN: dropped frame or something similar
int video_get_frame(struct dec_video *d_video, struct mp_image **out_mpi)
{
*out_mpi = NULL;
if (d_video->current_mpi) {
*out_mpi = d_video->current_mpi;
d_video->current_mpi = NULL;
return VIDEO_OK;
return DATA_OK;
}
if (d_video->current_state == VIDEO_OK)
return VIDEO_SKIP;
if (d_video->current_state == DATA_OK)
return DATA_AGAIN;
return d_video->current_state;
}

View File

@@ -84,16 +84,11 @@ bool video_init_best_codec(struct dec_video *d_video, char* video_decoders);
void video_uninit(struct dec_video *d_video);
void video_work(struct dec_video *d_video);
int video_get_frame(struct dec_video *d_video, struct mp_image **out_mpi);
void video_set_framedrop(struct dec_video *d_video, bool enabled);
void video_set_start(struct dec_video *d_video, double start_pts);
#define VIDEO_OK 1
#define VIDEO_WAIT 0
#define VIDEO_EOF -1
#define VIDEO_SKIP -2
int video_get_frame(struct dec_video *d_video, struct mp_image **out_mpi);
int video_vd_control(struct dec_video *d_video, int cmd, void *arg);
void video_reset(struct dec_video *d_video);
void video_reset_aspect(struct dec_video *d_video);