// Initialization and runtime control static int control(struct af_instance_s* af, int cmd, void* arg) { switch(cmd){ case AF_CONTROL_REINIT:{ char buf1[256]; char buf2[256]; af_data_t *data = arg; // Make sure this filter isn't redundant if(af->data->format == data->format && af->data->bps == data->bps) return AF_DETACH; // Allow trivial AC3-endianness conversion if (!AF_FORMAT_IS_AC3(af->data->format) || !AF_FORMAT_IS_AC3(data->format)) // Check for errors in configuration if((AF_OK != check_bps(data->bps)) || (AF_OK != check_format(data->format)) || (AF_OK != check_bps(af->data->bps)) || (AF_OK != check_format(af->data->format))) return AF_ERROR; mp_msg(MSGT_AFILTER, MSGL_V, "[format] Changing sample format from %s to %s\n", af_fmt2str(data->format,buf1,256), af_fmt2str(af->data->format,buf2,256)); af->data->rate = data->rate; af->data->nch = data->nch; af->mul = (double)af->data->bps / data->bps; af->play = play; // set default // look whether only endianness differences are there if ((af->data->format & ~AF_FORMAT_END_MASK) == (data->format & ~AF_FORMAT_END_MASK)) { mp_msg(MSGT_AFILTER, MSGL_V, "[format] Accelerated endianness conversion only\n"); af->play = play_swapendian; } if ((data->format == AF_FORMAT_FLOAT_NE) && (af->data->format == AF_FORMAT_S16_NE)) { mp_msg(MSGT_AFILTER, MSGL_V, "[format] Accelerated %s to %s conversion\n", af_fmt2str(data->format,buf1,256), af_fmt2str(af->data->format,buf2,256)); af->play = play_float_s16; } if ((data->format == AF_FORMAT_S16_NE) && (af->data->format == AF_FORMAT_FLOAT_NE)) { mp_msg(MSGT_AFILTER, MSGL_V, "[format] Accelerated %s to %s conversion\n", af_fmt2str(data->format,buf1,256), af_fmt2str(af->data->format,buf2,256)); af->play = play_s16_float; } return AF_OK; } case AF_CONTROL_COMMAND_LINE:{ int format = af_str2fmt_short(bstr0(arg)); if (format == -1) { mp_msg(MSGT_AFILTER, MSGL_ERR, "[format] %s is not a valid format\n", (char *)arg); return AF_ERROR; } if(AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format)) return AF_ERROR; return AF_OK; } case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:{ // Check for errors in configuration if(!AF_FORMAT_IS_AC3(*(int*)arg) && AF_OK != check_format(*(int*)arg)) return AF_ERROR; af->data->format = *(int*)arg; af->data->bps = af_fmt2bits(af->data->format)/8; return AF_OK; } } return AF_UNKNOWN; }
// Initialization and runtime control static int control(struct af_instance* af, int cmd, void* arg) { switch(cmd){ case AF_CONTROL_REINIT:{ char buf1[256]; char buf2[256]; struct mp_audio *data = arg; int supported_ac3 = 0; // Make sure this filter isn't redundant if(af->data->format == data->format) return AF_DETACH; // A bit complex because we can convert AC3 // to generic iec61937 but not the other way // round. if (AF_FORMAT_IS_AC3(af->data->format)) supported_ac3 = AF_FORMAT_IS_AC3(data->format); else if (AF_FORMAT_IS_IEC61937(af->data->format)) supported_ac3 = AF_FORMAT_IS_IEC61937(data->format); // Allow trivial AC3-endianness conversion if (!supported_ac3) // Check for errors in configuration if((AF_OK != check_bps(data->bps)) || (AF_OK != check_format(data->format)) || (AF_OK != check_bps(af->data->bps)) || (AF_OK != check_format(af->data->format))) return AF_ERROR; af_fmt2str(data->format,buf1,256); af_fmt2str(af->data->format,buf2,256); mp_msg(MSGT_AFILTER, MSGL_V, "[format] Changing sample format from %s to %s\n", buf1, buf2); af->data->rate = data->rate; mp_audio_set_channels(af->data, &data->channels); af->mul = (double)af->data->bps / data->bps; af->play = play; // set default // look whether only endianness differences are there if ((af->data->format & ~AF_FORMAT_END_MASK) == (data->format & ~AF_FORMAT_END_MASK)) { mp_msg(MSGT_AFILTER, MSGL_V, "[format] Accelerated endianness conversion only\n"); af->play = play_swapendian; } if ((data->format == AF_FORMAT_FLOAT_NE) && (af->data->format == AF_FORMAT_S16_NE)) { mp_msg(MSGT_AFILTER, MSGL_V, "[format] Accelerated %s to %s conversion\n", buf1, buf2); af->play = play_float_s16; } if ((data->format == AF_FORMAT_S16_NE) && (af->data->format == AF_FORMAT_FLOAT_NE)) { mp_msg(MSGT_AFILTER, MSGL_V, "[format] Accelerated %s to %s conversion\n", buf1, buf2); af->play = play_s16_float; } return AF_OK; } case AF_CONTROL_COMMAND_LINE:{ int format = af_str2fmt_short(bstr0(arg)); if (!format) { mp_msg(MSGT_AFILTER, MSGL_ERR, "[format] %s is not a valid format\n", (char *)arg); return AF_ERROR; } if(AF_OK != af->control(af, AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format)) return AF_ERROR; return AF_OK; } case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:{ // Check for errors in configuration if(!AF_FORMAT_IS_AC3(*(int*)arg) && AF_OK != check_format(*(int*)arg)) return AF_ERROR; mp_audio_set_format(af->data, *(int*)arg); return AF_OK; } } return AF_UNKNOWN; }