diff options
Diffstat (limited to 'audio')
-rw-r--r-- | audio/decode/dec_audio.c | 53 | ||||
-rw-r--r-- | audio/decode/dec_audio.h | 5 | ||||
-rw-r--r-- | audio/filter/af.c | 26 | ||||
-rw-r--r-- | audio/filter/af.h | 2 |
4 files changed, 19 insertions, 67 deletions
diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c index 4b8ae7949c..29674f3e0e 100644 --- a/audio/decode/dec_audio.c +++ b/audio/decode/dec_audio.c @@ -164,57 +164,13 @@ void audio_uninit(struct dec_audio *d_audio) { if (!d_audio) return; - if (d_audio->afilter) { - MP_VERBOSE(d_audio, "Uninit audio filters...\n"); - af_destroy(d_audio->afilter); - d_audio->afilter = NULL; - } + MP_VERBOSE(d_audio, "Uninit audio filters...\n"); + af_destroy(d_audio->afilter); uninit_decoder(d_audio); talloc_free(d_audio->decode_buffer); talloc_free(d_audio); } - -int audio_init_filters(struct dec_audio *d_audio, int in_samplerate, - int *out_samplerate, struct mp_chmap *out_channels, - int *out_format) -{ - if (!d_audio->afilter) - d_audio->afilter = af_new(d_audio->global); - struct af_stream *afs = d_audio->afilter; - - // input format: same as codec's output format: - mp_audio_buffer_get_format(d_audio->decode_buffer, &afs->input); - // Sample rate can be different when adjusting playback speed - afs->input.rate = in_samplerate; - - // output format: same as ao driver's input format (if missing, fallback to input) - afs->output.rate = *out_samplerate; - mp_audio_set_channels(&afs->output, out_channels); - mp_audio_set_format(&afs->output, *out_format); - - afs->replaygain_data = d_audio->replaygain_data; - - char *s_from = mp_audio_config_to_str(&afs->input); - char *s_to = mp_audio_config_to_str(&afs->output); - MP_VERBOSE(d_audio, "Building audio filter chain for %s -> %s...\n", s_from, s_to); - talloc_free(s_from); - talloc_free(s_to); - - // let's autoprobe it! - if (af_init(afs) != 0) { - af_destroy(afs); - d_audio->afilter = NULL; - return 0; // failed :( - } - - *out_samplerate = afs->output.rate; - *out_channels = afs->output.channels; - *out_format = afs->output.format; - - return 1; -} - /* Decode packets until we know the audio format. Then reinit the buffer. * Returns AD_OK on success, negative AD_* code otherwise. * Also returns AD_OK if already initialized (and does nothing). @@ -304,7 +260,7 @@ static int filter_n_bytes(struct dec_audio *da, struct mp_audio_buffer *outbuf, int audio_decode(struct dec_audio *d_audio, struct mp_audio_buffer *outbuf, int minsamples) { - if (!d_audio->afilter) + if (d_audio->afilter->initialized < 1) return AD_ERR; // Indicates that a filter seems to be buffering large amounts of data @@ -354,8 +310,7 @@ void audio_reset_decoding(struct dec_audio *d_audio) { if (d_audio->ad_driver) d_audio->ad_driver->control(d_audio, ADCTRL_RESET, NULL); - if (d_audio->afilter) - af_control_all(d_audio->afilter, AF_CONTROL_RESET, NULL); + af_control_all(d_audio->afilter, AF_CONTROL_RESET, NULL); d_audio->pts = MP_NOPTS_VALUE; d_audio->pts_offset = 0; if (d_audio->decode_buffer) diff --git a/audio/decode/dec_audio.h b/audio/decode/dec_audio.h index b76ff0b95c..08fa87e8a7 100644 --- a/audio/decode/dec_audio.h +++ b/audio/decode/dec_audio.h @@ -36,7 +36,6 @@ struct dec_audio { struct mp_audio_buffer *decode_buffer; struct af_stream *afilter; char *decoder_desc; - struct replaygain_data *replaygain_data; int init_retries; // set by decoder struct mp_audio decoded; // decoded audio set by last decode_packet() call @@ -65,8 +64,4 @@ int initial_audio_decode(struct dec_audio *d_audio); void audio_reset_decoding(struct dec_audio *d_audio); void audio_uninit(struct dec_audio *d_audio); -int audio_init_filters(struct dec_audio *d_audio, int in_samplerate, - int *out_samplerate, struct mp_chmap *out_channels, - int *out_format); - #endif /* MPLAYER_DEC_AUDIO_H */ diff --git a/audio/filter/af.c b/audio/filter/af.c index 72029f1013..176946b6d4 100644 --- a/audio/filter/af.c +++ b/audio/filter/af.c @@ -558,22 +558,27 @@ static int af_reinit(struct af_stream *s) MP_ERR(s, "Reinitialization did not work, " "audio filter '%s' returned error code %i\n", af->info->name, rv); - af_print_filter_chain(s, af, MSGL_ERR); - return AF_ERROR; + goto error; } } - af_print_filter_chain(s, NULL, MSGL_V); - /* Set previously unset fields in s->output to those of the filter chain * output. This is used to make the output format fixed, and even if you * insert new filters or change the input format, the output format won't * change. (Audio outputs generally can't change format at runtime.) */ af_copy_unset_fields(&s->output, &s->filter_output); - return af_config_equals(&s->output, &s->filter_output) ? AF_OK : AF_ERROR; + if (af_config_equals(&s->output, &s->filter_output)) { + s->initialized = 1; + af_print_filter_chain(s, NULL, MSGL_V); + return AF_OK; + } + + goto error; negotiate_error: MP_ERR(s, "Unable to convert audio input format to output format.\n"); +error: + s->initialized = -1; af_print_filter_chain(s, af, MSGL_ERR); return AF_ERROR; } @@ -583,6 +588,7 @@ void af_uninit(struct af_stream *s) { while (s->first->next && s->first->next != s->last) af_remove(s, s->first->next); + s->initialized = 0; } struct af_stream *af_new(struct mpv_global *global) @@ -632,10 +638,6 @@ void af_destroy(struct af_stream *s) The return value is 0 if success and -1 if failure */ int af_init(struct af_stream *s) { - // Sanity check - if (!s) - return -1; - // Precaution in case caller is misbehaving mp_audio_set_null_data(&s->input); mp_audio_set_null_data(&s->output); @@ -647,6 +649,7 @@ int af_init(struct af_stream *s) for (int i = 0; list && list[i].name; i++) { if (!af_prepend(s, s->last, list[i].name, list[i].attribs)) { af_uninit(s); + s->initialized = -1; return -1; } } @@ -655,7 +658,6 @@ int af_init(struct af_stream *s) if (af_reinit(s) != AF_OK) { // Something is stuffed audio out will not work MP_ERR(s, "Could not create audio filter chain.\n"); - af_uninit(s); return -1; } return 0; @@ -668,9 +670,6 @@ int af_init(struct af_stream *s) struct af_instance *af_add(struct af_stream *s, char *name, char **args) { struct af_instance *new; - // Sanity check - if (!s || !s->first || !name) - return NULL; // Insert the filter somewhere nice if (af_is_conversion_filter(s->first->next)) new = af_append(s, s->first->next, name, args); @@ -698,6 +697,7 @@ struct af_instance *af_add(struct af_stream *s, char *name, char **args) int af_filter(struct af_stream *s, struct mp_audio *data, int flags) { struct af_instance *af = s->first; + assert(s->initialized > 0); assert(mp_audio_config_equals(af->data, data)); // Iterate through all filters while (af) { diff --git a/audio/filter/af.h b/audio/filter/af.h index bec0e823fe..579ac271ef 100644 --- a/audio/filter/af.h +++ b/audio/filter/af.h @@ -80,6 +80,8 @@ struct af_instance { // Current audio stream struct af_stream { + int initialized; // 0: no, 1: yes, -1: attempted to, but failed + // The first and last filter in the list struct af_instance *first; struct af_instance *last; |