diff options
author | Max Kellermann <max@duempel.org> | 2009-01-07 22:20:30 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-07 22:20:30 +0100 |
commit | 7f34e9410eeb638b44ba1c7f7711844bd410b3a7 (patch) | |
tree | ac6dfdc40ee3ad04733151ba396f153c719822cf | |
parent | 97b844ec72a415da962ee37d6f5b5e527ded13d3 (diff) | |
download | mpd-7f34e9410eeb638b44ba1c7f7711844bd410b3a7.tar.gz mpd-7f34e9410eeb638b44ba1c7f7711844bd410b3a7.tar.xz mpd-7f34e9410eeb638b44ba1c7f7711844bd410b3a7.zip |
pcm: added pcm_convert_deinit(), pcm_resample_deinit()
Free memory allocated by libsamplerate when the output or the decoder
is closed.
-rw-r--r-- | src/decoder_api.c | 2 | ||||
-rw-r--r-- | src/decoder_thread.c | 4 | ||||
-rw-r--r-- | src/output_thread.c | 4 | ||||
-rw-r--r-- | src/pcm_convert.c | 5 | ||||
-rw-r--r-- | src/pcm_convert.h | 2 | ||||
-rw-r--r-- | src/pcm_resample.h | 2 | ||||
-rw-r--r-- | src/pcm_resample_fallback.c | 5 | ||||
-rw-r--r-- | src/pcm_resample_libsamplerate.c | 7 |
8 files changed, 29 insertions, 2 deletions
diff --git a/src/decoder_api.c b/src/decoder_api.c index 76bf05754..63bb0f2f2 100644 --- a/src/decoder_api.c +++ b/src/decoder_api.c @@ -45,8 +45,6 @@ void decoder_initialized(struct decoder * decoder, assert(audio_format_defined(audio_format)); assert(audio_format_valid(audio_format)); - pcm_convert_init(&decoder->conv_state); - dc.in_audio_format = *audio_format; getOutputAudioFormat(audio_format, &dc.out_audio_format); diff --git a/src/decoder_thread.c b/src/decoder_thread.c index 2d2e50b39..12449237f 100644 --- a/src/decoder_thread.c +++ b/src/decoder_thread.c @@ -124,6 +124,8 @@ static void decoder_run_song(const struct song *song, const char *uri) return; } + pcm_convert_init(&decoder.conv_state); + ret = false; if (!song_is_file(song)) { unsigned int next = 0; @@ -187,6 +189,8 @@ static void decoder_run_song(const struct song *song, const char *uri) } } + pcm_convert_deinit(&decoder.conv_state); + music_pipe_flush(); if (close_instream) diff --git a/src/output_thread.c b/src/output_thread.c index 63c443ddc..1467d26a8 100644 --- a/src/output_thread.c +++ b/src/output_thread.c @@ -84,6 +84,7 @@ static void ao_play(struct audio_output *ao) if (!ret) { ao->plugin->cancel(ao->data); ao->plugin->close(ao->data); + pcm_convert_deinit(&ao->convState); ao->open = false; } @@ -118,6 +119,8 @@ static gpointer audio_output_task(gpointer arg) case AO_COMMAND_OPEN: assert(!ao->open); + + pcm_convert_init(&ao->convState); ret = ao->plugin->open(ao->data, &ao->outAudioFormat); @@ -134,6 +137,7 @@ static gpointer audio_output_task(gpointer arg) assert(ao->open); ao->plugin->cancel(ao->data); ao->plugin->close(ao->data); + ao->open = false; ao_command_finished(ao); break; diff --git a/src/pcm_convert.c b/src/pcm_convert.c index f9fc9a64b..13c7405e3 100644 --- a/src/pcm_convert.c +++ b/src/pcm_convert.c @@ -37,6 +37,11 @@ void pcm_convert_init(struct pcm_convert_state *state) pcm_dither_24_init(&state->dither); } +void pcm_convert_deinit(struct pcm_convert_state *state) +{ + pcm_resample_deinit(&state->resample); +} + static size_t pcm_convert_16(const struct audio_format *src_format, const void *src_buffer, size_t src_size, diff --git a/src/pcm_convert.h b/src/pcm_convert.h index ad54290b8..16aa05576 100644 --- a/src/pcm_convert.h +++ b/src/pcm_convert.h @@ -32,6 +32,8 @@ struct pcm_convert_state { void pcm_convert_init(struct pcm_convert_state *state); +void pcm_convert_deinit(struct pcm_convert_state *state); + size_t pcm_convert(const struct audio_format *inFormat, const void *src, size_t src_size, const struct audio_format *outFormat, diff --git a/src/pcm_resample.h b/src/pcm_resample.h index c80dfa8a3..69bf6316d 100644 --- a/src/pcm_resample.h +++ b/src/pcm_resample.h @@ -52,6 +52,8 @@ struct pcm_resample_state { void pcm_resample_init(struct pcm_resample_state *state); +void pcm_resample_deinit(struct pcm_resample_state *state); + size_t pcm_resample_16(uint8_t channels, unsigned src_rate, diff --git a/src/pcm_resample_fallback.c b/src/pcm_resample_fallback.c index a55efb824..560d68a87 100644 --- a/src/pcm_resample_fallback.c +++ b/src/pcm_resample_fallback.c @@ -22,6 +22,11 @@ #include <assert.h> #include <glib.h> +void pcm_resample_deinit(G_GNUC_UNUSED struct pcm_resample_state *state) +{ + /* no state, nothing to do */ +} + /* resampling code blatantly ripped from ESD */ size_t pcm_resample_16(uint8_t channels, diff --git a/src/pcm_resample_libsamplerate.c b/src/pcm_resample_libsamplerate.c index 95d7e5d7f..ff7a7f95f 100644 --- a/src/pcm_resample_libsamplerate.c +++ b/src/pcm_resample_libsamplerate.c @@ -29,6 +29,13 @@ #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "pcm" +void pcm_resample_deinit(G_GNUC_UNUSED struct pcm_resample_state *state) +{ + if (state->state != NULL) + state->state = src_delete(state->state); + +} + static int pcm_resample_get_converter(void) { const char *conf = getConfigParamValue(CONF_SAMPLERATE_CONVERTER); |