From 5594718b6bda3a230e2e2c3cb06d2837c5a02688 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 18 Nov 2013 14:16:08 +0100 Subject: audio/filter: remove unneeded AF_CONTROLs, convert to enum The AF control commands used an elaborate and unnecessary organization for the command constants. Get rid of all that and convert the definitions to a simple enum. Also remove the control commands that were not really needed, because they were not used outside of the filters that implemented them. --- audio/filter/af.c | 12 ++-- audio/filter/af.h | 24 ++++++- audio/filter/af_center.c | 14 ++-- audio/filter/af_channels.c | 4 +- audio/filter/af_convert24.c | 2 +- audio/filter/af_convertsignendian.c | 2 +- audio/filter/af_delay.c | 34 +++------- audio/filter/af_export.c | 8 +-- audio/filter/af_lavrresample.c | 6 +- audio/filter/af_pan.c | 20 ++---- audio/filter/af_scaletempo.c | 10 +-- audio/filter/af_sub.c | 28 ++------ audio/filter/af_volume.c | 4 +- audio/filter/control.h | 127 ------------------------------------ 14 files changed, 66 insertions(+), 229 deletions(-) delete mode 100644 audio/filter/control.h (limited to 'audio/filter') diff --git a/audio/filter/af.c b/audio/filter/af.c index 03e85245e0..6f0241ec2b 100644 --- a/audio/filter/af.c +++ b/audio/filter/af.c @@ -438,7 +438,7 @@ static int af_fix_format_conversion(struct af_stream *s, if (!filter) return AF_ERROR; if (strcmp(filter, prev->info->name) == 0) { - if (prev->control(prev, AF_CONTROL_FORMAT_FMT, &dstfmt) == AF_OK) { + if (prev->control(prev, AF_CONTROL_SET_FORMAT, &dstfmt) == AF_OK) { *p_af = prev; return AF_OK; } @@ -447,7 +447,7 @@ static int af_fix_format_conversion(struct af_stream *s, if (new == NULL) return AF_ERROR; new->auto_inserted = true; - if (AF_OK != (rv = new->control(new, AF_CONTROL_FORMAT_FMT, &dstfmt))) + if (AF_OK != (rv = new->control(new, AF_CONTROL_SET_FORMAT, &dstfmt))) return rv; *p_af = new; return AF_OK; @@ -463,7 +463,7 @@ static int af_fix_channels(struct af_stream *s, struct af_instance **p_af, struct mp_audio actual = *prev->data; if (mp_chmap_equals(&actual.channels, &in.channels)) return AF_FALSE; - if (prev->control(prev, AF_CONTROL_CHANNELS, &in.channels) == AF_OK) { + if (prev->control(prev, AF_CONTROL_SET_CHANNELS, &in.channels) == AF_OK) { *p_af = prev; return AF_OK; } @@ -472,7 +472,7 @@ static int af_fix_channels(struct af_stream *s, struct af_instance **p_af, if (new == NULL) return AF_ERROR; new->auto_inserted = true; - if (AF_OK != (rv = new->control(new, AF_CONTROL_CHANNELS, &in.channels))) + if (AF_OK != (rv = new->control(new, AF_CONTROL_SET_CHANNELS, &in.channels))) return rv; *p_af = new; return AF_OK; @@ -487,7 +487,7 @@ static int af_fix_rate(struct af_stream *s, struct af_instance **p_af, struct mp_audio actual = *prev->data; if (actual.rate == in.rate) return AF_FALSE; - if (prev->control(prev, AF_CONTROL_RESAMPLE_RATE, &in.rate) == AF_OK) { + if (prev->control(prev, AF_CONTROL_SET_RESAMPLE_RATE, &in.rate) == AF_OK) { *p_af = prev; return AF_OK; } @@ -496,7 +496,7 @@ static int af_fix_rate(struct af_stream *s, struct af_instance **p_af, if (new == NULL) return AF_ERROR; new->auto_inserted = true; - if (AF_OK != (rv = new->control(new, AF_CONTROL_RESAMPLE_RATE, &in.rate))) + if (AF_OK != (rv = new->control(new, AF_CONTROL_SET_RESAMPLE_RATE, &in.rate))) return rv; *p_af = new; return AF_OK; diff --git a/audio/filter/af.h b/audio/filter/af.h index 3a56c4c081..5c7450721e 100644 --- a/audio/filter/af.h +++ b/audio/filter/af.h @@ -21,6 +21,7 @@ #include #include +#include #include "config.h" @@ -28,7 +29,6 @@ #include "audio/format.h" #include "audio/chmap.h" #include "audio/audio.h" -#include "control.h" #include "mpvcore/mp_msg.h" struct af_instance; @@ -96,6 +96,28 @@ struct af_stream { #define AF_ERROR -2 #define AF_FATAL -3 +// Parameters for af_control_* +enum af_control { + AF_CONTROL_REINIT = 1, + AF_CONTROL_COMMAND_LINE, + AF_CONTROL_SET_RESAMPLE_RATE, + AF_CONTROL_SET_FORMAT, + AF_CONTROL_SET_CHANNELS, + AF_CONTROL_SET_VOLUME, + AF_CONTROL_GET_VOLUME, + AF_CONTROL_SET_PAN_LEVEL, + AF_CONTROL_SET_PAN_NOUT, + AF_CONTROL_SET_PAN_BALANCE, + AF_CONTROL_GET_PAN_BALANCE, + AF_CONTROL_SET_PLAYBACK_SPEED, +}; + +// Argument for AF_CONTROL_SET_PAN_LEVEL +typedef struct af_control_ext_s { + void* arg; // Argument + int ch; // Chanel number +} af_control_ext_t; + struct af_stream *af_new(struct MPOpts *opts); void af_destroy(struct af_stream *s); int af_init(struct af_stream *s); diff --git a/audio/filter/af_center.c b/audio/filter/af_center.c index b64d5b54bd..fb026350a5 100644 --- a/audio/filter/af_center.c +++ b/audio/filter/af_center.c @@ -57,21 +57,15 @@ static int control(struct af_instance* af, int cmd, void* arg) case AF_CONTROL_COMMAND_LINE:{ int ch=1; sscanf(arg,"%i", &ch); - return control(af,AF_CONTROL_CENTER_CH | AF_CONTROL_SET, &ch); - } - case AF_CONTROL_CENTER_CH | AF_CONTROL_SET: // Requires reinit - // Sanity check - if((*(int*)arg >= AF_NCH) || (*(int*)arg < 0)){ + if((ch >= AF_NCH) || (ch < 0)){ mp_msg(MSGT_AFILTER, MSGL_ERR, "[sub] Center channel number must be between " - " 0 and %i current value is %i\n", AF_NCH-1, *(int*)arg); + " 0 and %i current value is %i\n", AF_NCH-1, ch); return AF_ERROR; } - s->ch = *(int*)arg; - return AF_OK; - case AF_CONTROL_CENTER_CH | AF_CONTROL_GET: - *(int*)arg = s->ch; + s->ch = ch; return AF_OK; } + } return AF_UNKNOWN; } diff --git a/audio/filter/af_channels.c b/audio/filter/af_channels.c index f77807a1af..d544e4d9c0 100644 --- a/audio/filter/af_channels.c +++ b/audio/filter/af_channels.c @@ -201,11 +201,11 @@ static int control(struct af_instance* af, int cmd, void* arg) struct mp_chmap chmap; mp_chmap_from_channels(&chmap, nch); - if (AF_OK != af->control(af, AF_CONTROL_CHANNELS | AF_CONTROL_SET, &chmap)) + if (AF_OK != af->control(af, AF_CONTROL_SET_CHANNELS, &chmap)) return AF_ERROR; return AF_OK; } - case AF_CONTROL_CHANNELS | AF_CONTROL_SET: + case AF_CONTROL_SET_CHANNELS: // Reinit must be called after this function has been called mp_audio_set_channels(af->data, (struct mp_chmap *)arg); diff --git a/audio/filter/af_convert24.c b/audio/filter/af_convert24.c index 0c3e6f8497..ddd30875cc 100644 --- a/audio/filter/af_convert24.c +++ b/audio/filter/af_convert24.c @@ -55,7 +55,7 @@ static int control(struct af_instance *af, int cmd, void *arg) return mp_audio_config_equals(in, &orig_in) ? AF_OK : AF_FALSE; } - case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET: { + case AF_CONTROL_SET_FORMAT: { mp_audio_set_format(af->data, *(int*)arg); return AF_OK; } diff --git a/audio/filter/af_convertsignendian.c b/audio/filter/af_convertsignendian.c index 65fffdf487..7ab99c9c74 100644 --- a/audio/filter/af_convertsignendian.c +++ b/audio/filter/af_convertsignendian.c @@ -55,7 +55,7 @@ static int control(struct af_instance *af, int cmd, void *arg) return mp_audio_config_equals(in, &orig_in) ? AF_OK : AF_FALSE; } - case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET: { + case AF_CONTROL_SET_FORMAT: { mp_audio_set_format(af->data, *(int*)arg); return AF_OK; } diff --git a/audio/filter/af_delay.c b/audio/filter/af_delay.c index e2ef57221d..e605ca71f4 100644 --- a/audio/filter/af_delay.c +++ b/audio/filter/af_delay.c @@ -65,7 +65,16 @@ static int control(struct af_instance* af, int cmd, void* arg) mp_msg(MSGT_AFILTER, MSGL_FATAL, "[delay] Out of memory\n"); } - return control(af,AF_CONTROL_DELAY_LEN | AF_CONTROL_SET,s->d); + if(AF_OK != af_from_ms(AF_NCH, s->d, s->wi, af->data->rate, 0.0, 1000.0)) + return AF_ERROR; + s->ri = 0; + for(i=0;id[i],0.0,1000.0)); + mp_msg(MSGT_AFILTER, MSGL_DBG3, "[delay] Channel %i delayed by %i samples\n", + i,s->wi[i]); + } + return AF_OK; } case AF_CONTROL_COMMAND_LINE:{ int n = 1; @@ -80,29 +89,6 @@ static int control(struct af_instance* af, int cmd, void* arg) } return AF_OK; } - case AF_CONTROL_DELAY_LEN | AF_CONTROL_SET:{ - int i; - if(AF_OK != af_from_ms(AF_NCH, arg, s->wi, af->data->rate, 0.0, 1000.0)) - return AF_ERROR; - s->ri = 0; - for(i=0;id[i],0.0,1000.0)); - mp_msg(MSGT_AFILTER, MSGL_DBG3, "[delay] Channel %i delayed by %i samples\n", - i,s->wi[i]); - } - return AF_OK; - } - case AF_CONTROL_DELAY_LEN | AF_CONTROL_GET:{ - int i; - for(i=0;iri > s->wi[i]) - s->wi[i] = L - (s->ri - s->wi[i]); - else - s->wi[i] = s->wi[i] - s->ri; - } - return af_to_ms(AF_NCH, s->wi, arg, af->data->rate); - } } return AF_UNKNOWN; } diff --git a/audio/filter/af_export.c b/audio/filter/af_export.c index 6c1ea6459b..c6f745ed50 100644 --- a/audio/filter/af_export.c +++ b/audio/filter/af_export.c @@ -161,19 +161,13 @@ static int control(struct af_instance* af, int cmd, void* arg) sscanf(str + i + 1, "%d", &(s->sz)); - return af->control(af, AF_CONTROL_EXPORT_SZ | AF_CONTROL_SET, &s->sz); - } - case AF_CONTROL_EXPORT_SZ | AF_CONTROL_SET: - s->sz = * (int *) arg; if((s->sz <= 0) || (s->sz > 2048)) mp_msg(MSGT_AFILTER, MSGL_ERR, "[export] Buffer size must be between" " 1 and 2048\n" ); return AF_OK; - case AF_CONTROL_EXPORT_SZ | AF_CONTROL_GET: - *(int*) arg = s->sz; - return AF_OK; + } } return AF_UNKNOWN; } diff --git a/audio/filter/af_lavrresample.c b/audio/filter/af_lavrresample.c index e5a9a40efc..f659511f82 100644 --- a/audio/filter/af_lavrresample.c +++ b/audio/filter/af_lavrresample.c @@ -259,18 +259,18 @@ static int control(struct af_instance *af, int cmd, void *arg) r = configure_lavrr(af, in, out); return r; } - case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET: { + case AF_CONTROL_SET_FORMAT: { if (af_to_avformat(*(int*)arg) == AV_SAMPLE_FMT_NONE) return AF_FALSE; mp_audio_set_format(af->data, *(int*)arg); return AF_OK; } - case AF_CONTROL_CHANNELS | AF_CONTROL_SET: { + case AF_CONTROL_SET_CHANNELS: { mp_audio_set_channels(af->data, (struct mp_chmap *)arg); return AF_OK; } - case AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET: + case AF_CONTROL_SET_RESAMPLE_RATE: out->rate = *(int *)arg; return AF_OK; } diff --git a/audio/filter/af_pan.c b/audio/filter/af_pan.c index 29d38c3860..f1bc63b73a 100644 --- a/audio/filter/af_pan.c +++ b/audio/filter/af_pan.c @@ -71,7 +71,7 @@ static int control(struct af_instance* af, int cmd, void* arg) int j,k; // Read number of outputs sscanf((char*)arg,"%i%n", &nch,&n); - if(AF_OK != control(af,AF_CONTROL_PAN_NOUT | AF_CONTROL_SET, &nch)) + if(AF_OK != control(af,AF_CONTROL_SET_PAN_NOUT, &nch)) return AF_ERROR; // Read pan values @@ -90,7 +90,7 @@ static int control(struct af_instance* af, int cmd, void* arg) } return AF_OK; } - case AF_CONTROL_PAN_LEVEL | AF_CONTROL_SET:{ + case AF_CONTROL_SET_PAN_LEVEL:{ int i; int ch = ((af_control_ext_t*)arg)->ch; float* level = ((af_control_ext_t*)arg)->arg; @@ -100,17 +100,7 @@ static int control(struct af_instance* af, int cmd, void* arg) s->level[ch][i] = level[i]; return AF_OK; } - case AF_CONTROL_PAN_LEVEL | AF_CONTROL_GET:{ - int i; - int ch = ((af_control_ext_t*)arg)->ch; - float* level = ((af_control_ext_t*)arg)->arg; - if (ch >= AF_NCH) - return AF_FALSE; - for(i=0;ilevel[ch][i]; - return AF_OK; - } - case AF_CONTROL_PAN_NOUT | AF_CONTROL_SET: + case AF_CONTROL_SET_PAN_NOUT: // Reinit must be called after this function has been called // Sanity check @@ -121,7 +111,7 @@ static int control(struct af_instance* af, int cmd, void* arg) } s->nch=((int*)arg)[0]; return AF_OK; - case AF_CONTROL_PAN_BALANCE | AF_CONTROL_SET:{ + case AF_CONTROL_SET_PAN_BALANCE:{ float val = *(float*)arg; if (s->nch) return AF_ERROR; @@ -133,7 +123,7 @@ static int control(struct af_instance* af, int cmd, void* arg) } return AF_OK; } - case AF_CONTROL_PAN_BALANCE | AF_CONTROL_GET: + case AF_CONTROL_GET_PAN_BALANCE: if (s->nch) return AF_ERROR; *(float*)arg = s->level[0][1] - s->level[1][0]; diff --git a/audio/filter/af_scaletempo.c b/audio/filter/af_scaletempo.c index 659b7971f5..9ec7b6b89b 100644 --- a/audio/filter/af_scaletempo.c +++ b/audio/filter/af_scaletempo.c @@ -413,7 +413,7 @@ static int control(struct af_instance *af, int cmd, void *arg) return af_test_output(af, (struct mp_audio *)arg); } - case AF_CONTROL_PLAYBACK_SPEED | AF_CONTROL_SET: { + case AF_CONTROL_SET_PLAYBACK_SPEED: { if (s->speed_tempo) { if (s->speed_pitch) break; @@ -428,14 +428,6 @@ static int control(struct af_instance *af, int cmd, void *arg) } return AF_OK; } - case AF_CONTROL_SCALETEMPO_AMOUNT | AF_CONTROL_SET: { - s->scale = *(float *)arg; - s->scale = s->speed * s->scale_nominal; - return AF_OK; - } - case AF_CONTROL_SCALETEMPO_AMOUNT | AF_CONTROL_GET: - *(float *)arg = s->scale; - return AF_OK; } return AF_UNKNOWN; } diff --git a/audio/filter/af_sub.c b/audio/filter/af_sub.c index cdb4c04ea3..975219cdcb 100644 --- a/audio/filter/af_sub.c +++ b/audio/filter/af_sub.c @@ -87,36 +87,22 @@ static int control(struct af_instance* af, int cmd, void* arg) int ch=5; float fc=60.0; sscanf(arg,"%f:%i", &fc , &ch); - if(AF_OK != control(af,AF_CONTROL_SUB_CH | AF_CONTROL_SET, &ch)) - return AF_ERROR; - return control(af,AF_CONTROL_SUB_FC | AF_CONTROL_SET, &fc); - } - case AF_CONTROL_SUB_CH | AF_CONTROL_SET: // Requires reinit // Sanity check - if((*(int*)arg >= AF_NCH) || (*(int*)arg < 0)){ + if(ch >= AF_NCH || ch < 0){ mp_msg(MSGT_AFILTER, MSGL_ERR, "[sub] Subwoofer channel number must be between " - " 0 and %i current value is %i\n", AF_NCH-1, *(int*)arg); + " 0 and %i current value is %i\n", AF_NCH-1, ch); return AF_ERROR; } - s->ch = *(int*)arg; - return AF_OK; - case AF_CONTROL_SUB_CH | AF_CONTROL_GET: - *(int*)arg = s->ch; - return AF_OK; - case AF_CONTROL_SUB_FC | AF_CONTROL_SET: // Requires reinit - // Sanity check - if((*(float*)arg > 300) || (*(float*)arg < 20)){ + s->ch = ch; + if(fc > 300 || fc < 20){ mp_msg(MSGT_AFILTER, MSGL_ERR, "[sub] Cutoff frequency must be between 20Hz and" - " 300Hz current value is %0.2f",*(float*)arg); + " 300Hz current value is %0.2f",fc); return AF_ERROR; } - // Set cutoff frequency - s->fc = *(float*)arg; - return AF_OK; - case AF_CONTROL_SUB_FC | AF_CONTROL_GET: - *(float*)arg = s->fc; + s->fc = fc; return AF_OK; } + } return AF_UNKNOWN; } diff --git a/audio/filter/af_volume.c b/audio/filter/af_volume.c index edf29d00f2..1b4d28fa44 100644 --- a/audio/filter/af_volume.c +++ b/audio/filter/af_volume.c @@ -56,10 +56,10 @@ static int control(struct af_instance *af, int cmd, void *arg) mp_audio_set_format(af->data, af_fmt_to_planar(af->data->format)); return af_test_output(af, in); } - case AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET: + case AF_CONTROL_SET_VOLUME: s->level = *(float *)arg; return AF_OK; - case AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_GET: + case AF_CONTROL_GET_VOLUME: *(float *)arg = s->level; return AF_OK; } diff --git a/audio/filter/control.h b/audio/filter/control.h deleted file mode 100644 index 562dce2dd4..0000000000 --- a/audio/filter/control.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPLAYER_CONTROL_H -#define MPLAYER_CONTROL_H - -#include - -/********************************************* -// Extended control used with arguments that operates on only one -// channel at the time -*/ -typedef struct af_control_ext_s{ - void* arg; // Argument - int ch; // Chanel number -}af_control_ext_t; - -/********************************************* -// Control parameters -*/ - -/* The control system is divided into 3 levels - mandatory calls - all filters must answer to all of these - optional calls - are optional - filter specific calls - applies only to some filters -*/ - -#define AF_CONTROL_MANDATORY 0x10000000 -#define AF_CONTROL_OPTIONAL 0x20000000 -#define AF_CONTROL_FILTER_SPECIFIC 0x40000000 - -// MANDATORY CALLS - -/* Reinitialize filter. The optional argument contains the new - configuration in form of a struct mp_audio struct. If the filter does not - support the new format the struct should be changed and AF_FALSE - should be returned. If the incoming and outgoing data streams are - identical the filter can return AF_DETACH. This will remove the - filter. */ -#define AF_CONTROL_REINIT 0x00000100 | AF_CONTROL_MANDATORY - -// OPTIONAL CALLS - -/* Commandline parameters. If there were any commandline parameters - for this specific filter, they will be given as a char* in the - argument */ -#define AF_CONTROL_COMMAND_LINE 0x00000300 | AF_CONTROL_OPTIONAL - - -// FILTER SPECIFIC CALLS - -// Basic operations: These can be ored with any of the below calls -// Set argument -#define AF_CONTROL_SET 0x00000000 -// Get argument -#define AF_CONTROL_GET 0x00000001 - -// Resample - -// Set output rate in resample -#define AF_CONTROL_RESAMPLE_RATE 0x00000100 | AF_CONTROL_FILTER_SPECIFIC - -// Format - -#define AF_CONTROL_FORMAT_FMT 0x00000400 | AF_CONTROL_FILTER_SPECIFIC - -// Channels - -// Set number of output channels in channels -#define AF_CONTROL_CHANNELS 0x00000600 | AF_CONTROL_FILTER_SPECIFIC - -// Volume - -// Set volume level, arg is a float* with the volume for all the channels -#define AF_CONTROL_VOLUME_LEVEL 0x00000D00 | AF_CONTROL_FILTER_SPECIFIC - -// Pan - -// Pan levels, arg is a control_ext with a float* -#define AF_CONTROL_PAN_LEVEL 0x00001A00 | AF_CONTROL_FILTER_SPECIFIC - -// Number of outputs from pan, arg is int* -#define AF_CONTROL_PAN_NOUT 0x00001B00 | AF_CONTROL_FILTER_SPECIFIC - -// Balance, arg is float*; range -1 (left) to 1 (right), 0 center -#define AF_CONTROL_PAN_BALANCE 0x00001C00 | AF_CONTROL_FILTER_SPECIFIC - - -// Delay length in ms, arg is a control_ext with a float* -#define AF_CONTROL_DELAY_LEN 0x00001E00 | AF_CONTROL_FILTER_SPECIFIC - - -// Subwoofer - -// Channel number which to insert the filtered data, arg in int* -#define AF_CONTROL_SUB_CH 0x00001F00 | AF_CONTROL_FILTER_SPECIFIC - -// Cutoff frequency [Hz] for lowpass filter, arg is float* -#define AF_CONTROL_SUB_FC 0x00002000 | AF_CONTROL_FILTER_SPECIFIC - - -// Export -#define AF_CONTROL_EXPORT_SZ 0x00003000 | AF_CONTROL_FILTER_SPECIFIC - -// Channel number which to inster the filtered data, arg in int* -#define AF_CONTROL_CENTER_CH 0x00003200 | AF_CONTROL_FILTER_SPECIFIC - - -#define AF_CONTROL_PLAYBACK_SPEED 0x00003500 | AF_CONTROL_FILTER_SPECIFIC -#define AF_CONTROL_SCALETEMPO_AMOUNT 0x00003600 | AF_CONTROL_FILTER_SPECIFIC - -#endif /* MPLAYER_CONTROL_H */ -- cgit v1.2.3