From fc24ab9298ff155ad94171c1b8f16f4da422376c Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 21 Mar 2013 00:58:05 +0100 Subject: audio/filter: replace pointless memcpys with assignments The change in af_scaletempo actually fixes a memory leak. af->data contained a pointer to an allocated buffer, which was overwritten during format negotiation. Set the format explicitly instead. --- audio/filter/af.c | 16 +++------------- audio/filter/af_dummy.c | 4 ++-- audio/filter/af_scaletempo.c | 5 ++++- audio/filter/af_tools.c | 2 +- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/audio/filter/af.c b/audio/filter/af.c index e240c83a40..9b00bf0fa5 100644 --- a/audio/filter/af.c +++ b/audio/filter/af.c @@ -288,7 +288,6 @@ static void af_print_filter_chain(struct af_stream *s) int af_reinit(struct af_stream *s, struct af_instance *af) { do { - struct mp_audio in; // Format of the input to current filter int rv = 0; // Return value // Check if there are any filters left in the list @@ -300,10 +299,7 @@ int af_reinit(struct af_stream *s, struct af_instance *af) } // Check if this is the first filter - if (!af->prev) - memcpy(&in, &(s->input), sizeof(struct mp_audio)); - else - memcpy(&in, af->prev->data, sizeof(struct mp_audio)); + struct mp_audio in = af->prev ? *(af->prev->data) : s->input; // Reset just in case... in.audio = NULL; in.len = 0; @@ -327,10 +323,7 @@ int af_reinit(struct af_stream *s, struct af_instance *af) (rv = new->control(new, AF_CONTROL_CHANNELS, &in.nch))) return rv; // Initialize channels filter - if (!new->prev) - memcpy(&in, &(s->input), sizeof(struct mp_audio)); - else - memcpy(&in, new->prev->data, sizeof(struct mp_audio)); + in = new->prev ? (*new->prev->data) : s->input; if (AF_OK != (rv = new->control(new, AF_CONTROL_REINIT, &in))) return rv; } @@ -347,10 +340,7 @@ int af_reinit(struct af_stream *s, struct af_instance *af) (rv = new->control(new, AF_CONTROL_FORMAT_FMT, &in.format))) return rv; // Initialize format filter - if (!new->prev) - memcpy(&in, &(s->input), sizeof(struct mp_audio)); - else - memcpy(&in, new->prev->data, sizeof(struct mp_audio)); + in = new->prev ? (*new->prev->data) : s->input; if (AF_OK != (rv = new->control(new, AF_CONTROL_REINIT, &in))) return rv; } diff --git a/audio/filter/af_dummy.c b/audio/filter/af_dummy.c index 29a5b3d4b8..5a54cdd80c 100644 --- a/audio/filter/af_dummy.c +++ b/audio/filter/af_dummy.c @@ -29,8 +29,8 @@ static int control(struct af_instance* af, int cmd, void* arg) { switch(cmd){ - case AF_CONTROL_REINIT: - memcpy(af->data,(struct mp_audio*)arg,sizeof(struct mp_audio)); + case AF_CONTROL_REINIT: ; + *af->data = *(struct mp_audio*)arg; mp_msg(MSGT_AFILTER, MSGL_V, "[dummy] Was reinitialized: %iHz/%ich/%s\n", af->data->rate,af->data->nch,af_fmt2str_short(af->data->format)); return AF_OK; diff --git a/audio/filter/af_scaletempo.c b/audio/filter/af_scaletempo.c index cf326fedfb..657fd7f712 100644 --- a/audio/filter/af_scaletempo.c +++ b/audio/filter/af_scaletempo.c @@ -305,7 +305,10 @@ static int control(struct af_instance* af, int cmd, void* arg) if (s->scale == 1.0) { if (s->speed_tempo && s->speed_pitch) return AF_DETACH; - memcpy(af->data, data, sizeof(struct mp_audio)); + af->data->format = data->format; + af->data->nch = data->nch; + af->data->rate = data->rate; + af->data->bps = data->bps; af->delay = 0; af->mul = 1; return af_test_output(af, data); diff --git a/audio/filter/af_tools.c b/audio/filter/af_tools.c index 0d5dc6c573..22534cda8d 100644 --- a/audio/filter/af_tools.c +++ b/audio/filter/af_tools.c @@ -91,7 +91,7 @@ int af_test_output(struct af_instance* af, struct mp_audio* out) (af->data->bps != out->bps) || (af->data->rate != out->rate) || (af->data->nch != out->nch)){ - memcpy(out,af->data,sizeof(struct mp_audio)); + *out = *af->data; return AF_FALSE; } return AF_OK; -- cgit v1.2.3