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.
This commit is contained in:
wm4 2013-03-21 00:58:05 +01:00
parent 8bf759e888
commit fc24ab9298
4 changed files with 10 additions and 17 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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;