From ff4efd075f89fd99abe4475f24462ff208a71bb3 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 2 Jan 2012 15:03:54 +0100 Subject: [PATCH] audioconvert: handle unpositioned channels Refuse to convert between unpositioned layouts. --- gst/audioconvert/audioconvert.c | 19 +++++++++++++++++++ gst/audioconvert/gstchannelmix.c | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gst/audioconvert/audioconvert.c b/gst/audioconvert/audioconvert.c index 1e42a2d..652ca7a 100644 --- a/gst/audioconvert/audioconvert.c +++ b/gst/audioconvert/audioconvert.c @@ -606,6 +606,10 @@ audio_convert_prepare_context (AudioConvertCtx * ctx, GstAudioInfo * in, /* first clean the existing context */ audio_convert_clean_context (ctx); + if ((GST_AUDIO_INFO_CHANNELS (in) != GST_AUDIO_INFO_CHANNELS (out)) && + (GST_AUDIO_INFO_IS_UNPOSITIONED (in) + || GST_AUDIO_INFO_IS_UNPOSITIONED (out))) + goto unpositioned; ctx->in = *in; ctx->out = *out; @@ -613,6 +617,8 @@ audio_convert_prepare_context (AudioConvertCtx * ctx, GstAudioInfo * in, in_depth = GST_AUDIO_FORMAT_INFO_DEPTH (in->finfo); out_depth = GST_AUDIO_FORMAT_INFO_DEPTH (out->finfo); + GST_INFO ("depth in %d, out %d", in_depth, out_depth); + /* Don't dither or apply noise shaping if target depth is bigger than 20 bits * as DA converters only can do a SNR up to 20 bits in reality. * Also don't dither or apply noise shaping if target depth is larger than @@ -621,9 +627,11 @@ audio_convert_prepare_context (AudioConvertCtx * ctx, GstAudioInfo * in, || in_depth >= out_depth)) { ctx->dither = dither; ctx->ns = ns; + GST_INFO ("using dither %d and noise shaping %d", dither, ns); } else { ctx->dither = DITHER_NONE; ctx->ns = NOISE_SHAPING_NONE; + GST_INFO ("using no dither and noise shaping"); } /* Use simple error feedback when output sample rate is smaller than @@ -639,6 +647,8 @@ audio_convert_prepare_context (AudioConvertCtx * ctx, GstAudioInfo * in, idx_out = audio_convert_get_func_index (ctx, out->finfo); ctx->pack = pack_funcs[idx_out]; + GST_INFO ("func index in %d, out %d", idx_in, idx_out); + /* if both formats are float/double or we use noise shaping use double as * intermediate format and switch mixing */ if (!DOUBLE_INTERMEDIATE_FORMAT (ctx)) { @@ -665,9 +675,18 @@ audio_convert_prepare_context (AudioConvertCtx * ctx, GstAudioInfo * in, ctx->out_scale = GST_AUDIO_FORMAT_INFO_IS_INTEGER (out->finfo) ? (32 - out_depth) : 0; + GST_INFO ("scale in %d, out %d", ctx->in_scale, ctx->out_scale); + gst_audio_quantize_setup (ctx); return TRUE; + + /* ERRORS */ +unpositioned: + { + GST_WARNING ("unpositioned channels"); + return FALSE; + } } gboolean diff --git a/gst/audioconvert/gstchannelmix.c b/gst/audioconvert/gstchannelmix.c index a68f2c1..2694780 100644 --- a/gst/audioconvert/gstchannelmix.c +++ b/gst/audioconvert/gstchannelmix.c @@ -584,7 +584,8 @@ gst_channel_mix_fill_matrix (AudioConvertCtx * this) gst_channel_mix_fill_identical (this); - if (!GST_AUDIO_INFO_HAS_DEFAULT_POSITIONS (&this->in)) { + if (!GST_AUDIO_INFO_HAS_DEFAULT_POSITIONS (&this->in) && + !GST_AUDIO_INFO_IS_UNPOSITIONED (&this->in)) { gst_channel_mix_fill_compatible (this); gst_channel_mix_fill_others (this); gst_channel_mix_fill_normalize (this); -- 2.7.4