ext/faad/gstfaad.c: Don't set channel positions on regular mono and stereo cases.

Original commit message from CVS:
Patch by: Jonathan Matthew  <jonathan at kaolin wh9 net>
* ext/faad/gstfaad.c: (gst_faad_chanpos_to_gst),
(gst_faad_srcgetcaps), (gst_faad_update_caps):
Don't set channel positions on regular mono and stereo cases.
Fixes #476370.
This commit is contained in:
Jonathan Matthew 2007-09-19 21:18:27 +00:00 committed by Wim Taymans
parent d785a925c1
commit b020c43021
2 changed files with 54 additions and 22 deletions

View File

@ -1,3 +1,12 @@
2007-09-19 Wim Taymans <wim.taymans@gmail.com>
Patch by: Jonathan Matthew <jonathan at kaolin wh9 net>
* ext/faad/gstfaad.c: (gst_faad_chanpos_to_gst),
(gst_faad_srcgetcaps), (gst_faad_update_caps):
Don't set channel positions on regular mono and stereo cases.
Fixes #476370.
2007-09-19 Thijs Vermeir <thijsvermeir@gmail.com> 2007-09-19 Thijs Vermeir <thijsvermeir@gmail.com>
* gst/librfb/gstrfbsrc.c: * gst/librfb/gstrfbsrc.c:

View File

@ -440,14 +440,27 @@ gst_faad_chanpos_from_gst (GstAudioChannelPosition * pos, guint num)
*/ */
static GstAudioChannelPosition * static GstAudioChannelPosition *
gst_faad_chanpos_to_gst (guchar * fpos, guint num) gst_faad_chanpos_to_gst (GstFaad * faad, guchar * fpos, guint num,
GstAudioChannelPosition * channel_map_failed)
{ {
GstAudioChannelPosition *pos = g_new (GstAudioChannelPosition, num); GstAudioChannelPosition *pos = g_new (GstAudioChannelPosition, num);
guint n; guint n;
gboolean unknown_channel = FALSE; gboolean unknown_channel = FALSE;
*channel_map_failed = FALSE;
/* special handling for the common cases for mono and stereo */
if (num == 1 && fpos[0] == FRONT_CHANNEL_CENTER) {
GST_DEBUG_OBJECT (faad, "mono common case; won't set channel positions");
return NULL;
} else if (num == 2 && fpos[0] == FRONT_CHANNEL_LEFT
&& fpos[1] == FRONT_CHANNEL_RIGHT) {
GST_DEBUG_OBJECT (faad, "stereo common case; won't set channel positions");
return NULL;
}
for (n = 0; n < num; n++) { for (n = 0; n < num; n++) {
GST_DEBUG ("faad channel %d as %d", n, fpos[n]); GST_DEBUG_OBJECT (faad, "faad channel %d as %d", n, fpos[n]);
switch (fpos[n]) { switch (fpos[n]) {
case FRONT_CHANNEL_LEFT: case FRONT_CHANNEL_LEFT:
pos[n] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT; pos[n] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
@ -481,29 +494,29 @@ gst_faad_chanpos_to_gst (guchar * fpos, guint num)
pos[n] = GST_AUDIO_CHANNEL_POSITION_LFE; pos[n] = GST_AUDIO_CHANNEL_POSITION_LFE;
break; break;
default: default:
GST_DEBUG ("unknown channel %d at %d", fpos[n], n); GST_DEBUG_OBJECT (faad, "unknown channel %d at %d", fpos[n], n);
unknown_channel = TRUE; unknown_channel = TRUE;
break; break;
} }
} }
if (unknown_channel) { if (unknown_channel) {
g_free (pos);
pos = NULL;
switch (num) { switch (num) {
case 1:{ case 1:{
GST_DEBUG ("FAAD reports unknown 1 channel mapping. Forcing to mono"); GST_DEBUG_OBJECT (faad,
pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_MONO; "FAAD reports unknown 1 channel mapping. Forcing to mono");
break; break;
} }
case 2:{ case 2:{
GST_DEBUG ("FAAD reports unknown 2 channel mapping. Forcing to stereo"); GST_DEBUG_OBJECT (faad,
pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT; "FAAD reports unknown 2 channel mapping. Forcing to stereo");
pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
break; break;
} }
default:{ default:{
GST_WARNING ("Unsupported FAAD channel position 0x%x encountered", GST_WARNING ("Unsupported FAAD channel position 0x%x encountered",
fpos[n]); fpos[n]);
g_free (pos); *channel_map_failed = TRUE;
pos = NULL;
break; break;
} }
} }
@ -523,12 +536,13 @@ gst_faad_srcgetcaps (GstPad * pad)
if (!supported_positions) { if (!supported_positions) {
guchar *supported_fpos = g_new0 (guchar, num_supported_positions); guchar *supported_fpos = g_new0 (guchar, num_supported_positions);
gint n; gint n;
gboolean map_failed;
for (n = 0; n < num_supported_positions; n++) { for (n = 0; n < num_supported_positions; n++) {
supported_fpos[n] = n + FRONT_CHANNEL_CENTER; supported_fpos[n] = n + FRONT_CHANNEL_CENTER;
} }
supported_positions = gst_faad_chanpos_to_gst (supported_fpos, supported_positions = gst_faad_chanpos_to_gst (faad, supported_fpos,
num_supported_positions); num_supported_positions, &map_failed);
g_free (supported_fpos); g_free (supported_fpos);
} }
@ -593,15 +607,18 @@ gst_faad_srcgetcaps (GstPad * pad)
/* put channel information here */ /* put channel information here */
if (faad->channel_positions) { if (faad->channel_positions) {
GstAudioChannelPosition *pos; GstAudioChannelPosition *pos;
gboolean map_failed;
pos = gst_faad_chanpos_to_gst (faad->channel_positions, pos = gst_faad_chanpos_to_gst (faad, faad->channel_positions,
faad->channels); faad->channels, &map_failed);
if (!pos) { if (map_failed) {
gst_structure_free (str); gst_structure_free (str);
continue; continue;
} }
gst_audio_set_channel_positions (str, pos); if (pos) {
g_free (pos); gst_audio_set_channel_positions (str, pos);
g_free (pos);
}
} else { } else {
gst_audio_set_structure_channel_positions_list (str, gst_audio_set_structure_channel_positions_list (str,
supported_positions, num_supported_positions); supported_positions, num_supported_positions);
@ -1015,6 +1032,7 @@ gst_faad_update_caps (GstFaad * faad, faacDecFrameInfo * info)
{ {
GstAudioChannelPosition *pos; GstAudioChannelPosition *pos;
gboolean ret; gboolean ret;
gboolean channel_map_failed;
GstCaps *caps; GstCaps *caps;
/* store new negotiation information */ /* store new negotiation information */
@ -1033,16 +1051,21 @@ gst_faad_update_caps (GstFaad * faad, faacDecFrameInfo * info)
faad->bps = 16 / 8; faad->bps = 16 / 8;
pos = gst_faad_chanpos_to_gst (faad->channel_positions, faad->channels); channel_map_failed = FALSE;
if (!pos) { pos =
gst_faad_chanpos_to_gst (faad, faad->channel_positions, faad->channels,
&channel_map_failed);
if (channel_map_failed) {
GST_DEBUG_OBJECT (faad, "Could not map channel positions"); GST_DEBUG_OBJECT (faad, "Could not map channel positions");
gst_caps_unref (caps); gst_caps_unref (caps);
return FALSE; return FALSE;
} }
gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos); if (pos) {
g_free (pos); gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
g_free (pos);
}
GST_DEBUG ("New output caps: %" GST_PTR_FORMAT, caps); GST_DEBUG_OBJECT (faad, "New output caps: %" GST_PTR_FORMAT, caps);
ret = gst_pad_set_caps (faad->srcpad, caps); ret = gst_pad_set_caps (faad->srcpad, caps);
gst_caps_unref (caps); gst_caps_unref (caps);