Commit 12f050a8 authored by Stefan Westerfeld's avatar Stefan Westerfeld

avfilter/asubprocess: support 16, 24 and 32 bit subprocess input wavs

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 0bee9b20
......@@ -207,6 +207,7 @@ typedef struct AndioWMarkContext {
int fd;
int state;
unsigned int chunk_size;
int in_bit_depth;
int out_bit_depth;
SP *sp;
int nb_samples;
......@@ -217,7 +218,8 @@ typedef struct AndioWMarkContext {
#define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
static const AVOption asubprocess_options[] = {
{ "command", "set command to run as subprocess", OFFSET(command), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, A},
{ "command", "set command to run as subprocess", OFFSET(command), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, A},
{ "bits", "set wav bit depth for subprocess input", OFFSET(in_bit_depth), AV_OPT_TYPE_INT, {.i64=32}, 0, 32, A},
{ NULL },
};
......@@ -230,6 +232,10 @@ static av_cold int init(AVFilterContext *ctx)
av_log(ctx, AV_LOG_ERROR, "No command provided\n");
return AVERROR(EINVAL);
}
if (s->in_bit_depth != 16 && s->in_bit_depth != 24 && s->in_bit_depth != 32) {
av_log(ctx, AV_LOG_ERROR, "Only 16, 24 and 32 input bit depth supported\n");
return AVERROR(EINVAL);
}
return 0;
}
......@@ -249,7 +255,7 @@ static int config_input(AVFilterLink *inlink)
AVFilterContext *ctx = inlink->dst;
ASubProcessContext *s = ctx->priv;
s->sp = sp_new (s->command);
int bit_depth = 16;
int bit_depth = s->in_bit_depth;
int sample_rate = inlink->sample_rate;
int nb_channels = inlink->ch_layout.nb_channels;
AVIOContext *wav_header = NULL;
......@@ -305,10 +311,29 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
short buffer[100000];
int k = 0;
int32_t *xd = (int32_t *)in->data[0];
for (k = 0; k < in->nb_samples * inlink->ch_layout.nb_channels; k++) {
AV_WL16 (buffer + k, xd[k] >> 16);
int sample_size = s->in_bit_depth / 8;
int todo = in->nb_samples * inlink->ch_layout.nb_channels;
if (s->in_bit_depth == 16)
{
for (k = 0; k < todo; k++)
AV_WL16 (buffer + k, xd[k] >> 16);
}
if (s->in_bit_depth == 24)
{
uint8_t *in = (uint8_t *) buffer;
for (int k = 0; k < todo; k++)
{
AV_WL24 (in, xd[k] >> 8);
in += 3;
}
}
if (s->in_bit_depth == 32)
{
int32_t *i32buffer = (int32_t *) buffer;
for (k = 0; k < todo; k++)
AV_WL32 (i32buffer + k, xd[k]);
}
sp_write (s->sp, buffer, 2 * k);
sp_write (s->sp, buffer, sample_size * todo);
if (s->eof)
{
while (!sp_write (s->sp, 0, 0))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment