mirror of
https://github.com/mpv-player/mpv
synced 2024-11-18 21:16:10 +01:00
audio: use symbolic constants instead of magic integers
Similar to commit 26468743
.
This commit is contained in:
parent
e982b5b287
commit
9736f3309a
@ -398,7 +398,7 @@ static int decode_audio(struct dec_audio *da, struct mp_audio *buffer, int maxle
|
||||
|
||||
if (!priv->frame.samples) {
|
||||
if (decode_new_packet(da) < 0)
|
||||
return -1;
|
||||
return AD_ERR;
|
||||
}
|
||||
|
||||
if (!mp_audio_config_equals(buffer, &priv->frame))
|
||||
|
@ -309,7 +309,7 @@ static int decode_audio(struct dec_audio *da, struct mp_audio *buffer, int maxle
|
||||
|
||||
if (con->need_data) {
|
||||
if (feed_new_packet(da) < 0)
|
||||
return -1;
|
||||
return AD_ERR;
|
||||
}
|
||||
|
||||
if (!mp_audio_config_equals(&da->decoded, buffer))
|
||||
@ -338,9 +338,8 @@ static int decode_audio(struct dec_audio *da, struct mp_audio *buffer, int maxle
|
||||
return 0;
|
||||
|
||||
mpg123_fail:
|
||||
MP_ERR(da, "mpg123 decoding error: %s\n",
|
||||
mpg123_strerror(con->handle));
|
||||
return -1;
|
||||
MP_ERR(da, "mpg123 decoding error: %s\n", mpg123_strerror(con->handle));
|
||||
return AD_ERR;
|
||||
}
|
||||
|
||||
static int control(struct dec_audio *da, int cmd, void *arg)
|
||||
|
@ -200,7 +200,7 @@ static int decode_audio(struct dec_audio *da, struct mp_audio *buffer, int maxle
|
||||
|
||||
struct demux_packet *mpkt = demux_read_packet(da->header);
|
||||
if (!mpkt)
|
||||
return -1;
|
||||
return AD_ERR;
|
||||
|
||||
AVPacket pkt;
|
||||
mp_set_av_packet(&pkt, mpkt, NULL);
|
||||
@ -216,7 +216,7 @@ static int decode_audio(struct dec_audio *da, struct mp_audio *buffer, int maxle
|
||||
da->pts_offset += buffer->samples;
|
||||
talloc_free(mpkt);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
return AD_ERR;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ static int filter_n_bytes(struct dec_audio *da, struct mp_audio_buffer *outbuf,
|
||||
// first, and don't signal a format change to the caller yet.
|
||||
if (mp_audio_buffer_samples(da->decode_buffer) > 0)
|
||||
break;
|
||||
error = -2;
|
||||
error = AD_NEW_FMT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -274,7 +274,7 @@ static int filter_n_bytes(struct dec_audio *da, struct mp_audio_buffer *outbuf,
|
||||
bool eof = filter_data.samples == 0 && error < 0;
|
||||
|
||||
if (af_filter(da->afilter, &filter_data, eof ? AF_FILTER_FLAG_EOF : 0) < 0)
|
||||
return -1;
|
||||
return AD_ERR;
|
||||
|
||||
mp_audio_buffer_append(outbuf, &filter_data);
|
||||
if (eof && filter_data.samples > 0)
|
||||
@ -285,9 +285,9 @@ static int filter_n_bytes(struct dec_audio *da, struct mp_audio_buffer *outbuf,
|
||||
|
||||
// Assume the filter chain is drained from old data at this point.
|
||||
// (If not, the remaining old data is discarded.)
|
||||
if (error == -2) {
|
||||
if (error == AD_NEW_FMT) {
|
||||
if (!reinit_audio_buffer(da))
|
||||
error = -1; // switch to invalid format
|
||||
error = AD_ERR; // switch to invalid format
|
||||
}
|
||||
|
||||
return error;
|
||||
@ -295,7 +295,7 @@ static int filter_n_bytes(struct dec_audio *da, struct mp_audio_buffer *outbuf,
|
||||
|
||||
/* Try to get at least minsamples decoded+filtered samples in outbuf
|
||||
* (total length including possible existing data).
|
||||
* Return 0 on success, -1 on error/EOF (not distinguidaed).
|
||||
* Return 0 on success, or negative AD_* error code.
|
||||
* In the former case outbuf has at least minsamples buffered on return.
|
||||
* In case of EOF/error it might or might not be. */
|
||||
int audio_decode(struct dec_audio *d_audio, struct mp_audio_buffer *outbuf,
|
||||
|
@ -51,6 +51,13 @@ struct dec_audio {
|
||||
void *priv;
|
||||
};
|
||||
|
||||
enum {
|
||||
AD_OK = 0,
|
||||
AD_ERR = -1,
|
||||
AD_NEW_FMT = -2,
|
||||
AD_ASYNC_PLAY_DONE = -3,
|
||||
};
|
||||
|
||||
struct mp_decoder_list *audio_decoder_list(void);
|
||||
int audio_init_best_codec(struct dec_audio *d_audio, char *audio_decoders);
|
||||
int audio_decode(struct dec_audio *d_audio, struct mp_audio_buffer *outbuf,
|
||||
|
@ -297,7 +297,6 @@ static int write_silence_to_ao(struct MPContext *mpctx, int samples, int flags,
|
||||
return r;
|
||||
}
|
||||
|
||||
#define ASYNC_PLAY_DONE -3
|
||||
static int audio_start_sync(struct MPContext *mpctx, int playsize)
|
||||
{
|
||||
struct ao *ao = mpctx->ao;
|
||||
@ -374,7 +373,7 @@ static int audio_start_sync(struct MPContext *mpctx, int playsize)
|
||||
* in playsize. */
|
||||
write_silence_to_ao(mpctx, playsize, 0,
|
||||
written_pts - samples / real_samplerate);
|
||||
return ASYNC_PLAY_DONE;
|
||||
return AD_ASYNC_PLAY_DONE;
|
||||
}
|
||||
mpctx->syncing_audio = false;
|
||||
mp_audio_buffer_prepend_silence(mpctx->ao_buffer, samples);
|
||||
@ -418,7 +417,7 @@ int fill_audio_out_buffers(struct MPContext *mpctx, double endpts)
|
||||
res = audio_decode(d_audio, mpctx->ao_buffer, playsize);
|
||||
|
||||
if (res < 0) { // EOF, error or format change
|
||||
if (res == -2) {
|
||||
if (res == AD_NEW_FMT) {
|
||||
/* The format change isn't handled too gracefully. A more precise
|
||||
* implementation would require draining buffered old-format audio
|
||||
* while displaying video, then doing the output format switch.
|
||||
@ -427,7 +426,7 @@ int fill_audio_out_buffers(struct MPContext *mpctx, double endpts)
|
||||
uninit_player(mpctx, INITIALIZED_AO);
|
||||
reinit_audio_chain(mpctx);
|
||||
return -1;
|
||||
} else if (res == ASYNC_PLAY_DONE)
|
||||
} else if (res == AD_ASYNC_PLAY_DONE)
|
||||
return 0;
|
||||
else if (demux_stream_eof(d_audio->header))
|
||||
audio_eof = true;
|
||||
|
Loading…
Reference in New Issue
Block a user