From da601be78f011f22fcedc0c5691ddf32a5eef63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Zanelli?= <aurelien.zanelli@parrot.com> Date: Tue, 11 Mar 2014 10:32:46 +0100 Subject: [PATCH] sbcenc: Allow user to set channel-mode Don't return error when channel-mode is already set, just check that it is coherent with number of channels. https://bugzilla.gnome.org/show_bug.cgi?id=726098 --- ext/sbc/gstsbcenc.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/ext/sbc/gstsbcenc.c b/ext/sbc/gstsbcenc.c index d456190a51..6ef56b49e8 100644 --- a/ext/sbc/gstsbcenc.c +++ b/ext/sbc/gstsbcenc.c @@ -118,21 +118,10 @@ gst_sbc_enc_set_format (GstAudioEncoder * audio_enc, GstAudioInfo * info) GST_DEBUG_OBJECT (enc, "fixating caps %" GST_PTR_FORMAT, output_caps); output_caps = gst_caps_truncate (output_caps); s = gst_caps_get_structure (output_caps, 0); - if (enc->channels == 1) { - if (!gst_structure_fixate_field_string (s, "channel-mode", "mono")) { - GST_DEBUG_OBJECT (enc, "Failed to fixate channel-mode to mono"); - gst_caps_unref (output_caps); - return FALSE; - } - } else { - if (!gst_structure_fixate_field_string (s, "channel-mode", "joint") && - !gst_structure_fixate_field_string (s, "channel-mode", "stereo") && - !gst_structure_fixate_field_string (s, "channel-mode", "dual")) { - GST_DEBUG_OBJECT (enc, "Failed to fixate channel-mode for 2 channels"); - gst_caps_unref (output_caps); - return FALSE; - } - } + if (enc->channels == 1) + gst_structure_fixate_field_string (s, "channel-mode", "mono"); + else + gst_structure_fixate_field_string (s, "channel-mode", "joint"); gst_structure_fixate_field_nearest_int (s, "bitpool", 64); gst_structure_fixate_field_nearest_int (s, "blocks", 16); @@ -154,6 +143,25 @@ gst_sbc_enc_set_format (GstAudioEncoder * audio_enc, GstAudioInfo * info) allocation_method = gst_structure_get_string (s, "allocation-method"); channel_mode = gst_structure_get_string (s, "channel-mode"); + /* We want channel-mode and channels coherent */ + if (enc->channels == 1) { + if (g_strcmp0 (channel_mode, "mono") != 0) { + GST_ERROR_OBJECT (enc, "Can't have channel-mode '%s' for 1 channel", + channel_mode); + gst_caps_unref (output_caps); + return FALSE; + } + } else { + if (g_strcmp0 (channel_mode, "joint") != 0 && + g_strcmp0 (channel_mode, "stereo") != 0 && + g_strcmp0 (channel_mode, "dual") != 0) { + GST_ERROR_OBJECT (enc, "Can't have channel-mode '%s' for 2 channels", + channel_mode); + gst_caps_unref (output_caps); + return FALSE; + } + } + /* we want to be handed all available samples in handle_frame, but always * enough to encode a frame */ sampleframes_per_frame = enc->blocks * enc->subbands;