From 9736f3309acf387e42aef847f594463e3351bbc2 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 20 Jul 2014 20:42:03 +0200 Subject: audio: use symbolic constants instead of magic integers Similar to commit 26468743. --- audio/decode/ad_lavc.c | 2 +- audio/decode/ad_mpg123.c | 7 +++---- audio/decode/ad_spdif.c | 4 ++-- audio/decode/dec_audio.c | 10 +++++----- audio/decode/dec_audio.h | 7 +++++++ player/audio.c | 7 +++---- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index 404cf19560..ad00e65be6 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -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)) diff --git a/audio/decode/ad_mpg123.c b/audio/decode/ad_mpg123.c index ec4dc04485..055285cccd 100644 --- a/audio/decode/ad_mpg123.c +++ b/audio/decode/ad_mpg123.c @@ -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) diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c index c055715a32..1042fdeb48 100644 --- a/audio/decode/ad_spdif.c +++ b/audio/decode/ad_spdif.c @@ -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; } diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c index b8d83e899c..b8e14dfbf3 100644 --- a/audio/decode/dec_audio.c +++ b/audio/decode/dec_audio.c @@ -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, diff --git a/audio/decode/dec_audio.h b/audio/decode/dec_audio.h index 9108f6f035..27c2040947 100644 --- a/audio/decode/dec_audio.h +++ b/audio/decode/dec_audio.h @@ -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, diff --git a/player/audio.c b/player/audio.c index d0f78b3643..d893206764 100644 --- a/player/audio.c +++ b/player/audio.c @@ -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; -- cgit v1.2.3