static void gst_audio_parse_setup_channel_positions (GstAudioParse * ap) { GstAudioChannelPosition *pos, *to; g_free (ap->channel_pos); g_free (ap->channel_order); ap->channel_pos = NULL; ap->channel_order = NULL; if (!ap->channel_positions) { GST_DEBUG_OBJECT (ap, "no channel positions"); /* implicit mapping for 1- and 2-channel audio is okay */ /* will come up with one in other cases also */ return; } pos = gst_audio_parse_get_channel_positions (ap->channel_positions); if (ap->channels != ap->channel_positions->n_values || !gst_audio_check_valid_channel_positions (pos, ap->channels, FALSE)) { GST_DEBUG_OBJECT (ap, "invalid channel position"); g_free (pos); return; } /* ok, got something we can work with now */ to = g_new (GstAudioChannelPosition, ap->channels); memcpy (to, pos, ap->channels * sizeof (to[0])); gst_audio_channel_positions_to_valid_order (to, ap->channels); ap->channel_pos = pos; ap->channel_order = to; }
static gboolean gst_raw_audio_parse_update_channel_reordering_flag (GstRawAudioParseConfig * config) { g_assert (config->num_channels > 0); /* If the channel_positions array contains channel positions which are in an * order that conforms to the valid GStreamer order, ensure that channel * reordering is disabled. * Otherwise, if the order of the positions in the channel_positions array * does not conform to the GStreamer order, ensure it is enabled. */ if (gst_audio_check_valid_channel_positions (config->channel_positions, config->num_channels, TRUE)) { config->needs_channel_reordering = FALSE; return TRUE; } else { config->needs_channel_reordering = TRUE; memcpy (config->reordered_channel_positions, config->channel_positions, sizeof (GstAudioChannelPosition) * config->num_channels); return gst_audio_channel_positions_to_valid_order (config->reordered_channel_positions, config->num_channels); } }
/** * gst_audio_info_set_format: * @info: a #GstAudioInfo * @format: the format * @rate: the samplerate * @channels: the number of channels * @position: the channel positions * * Set the default info for the audio info of @format and @rate and @channels. * * Note: This initializes @info first, no values are preserved. */ void gst_audio_info_set_format (GstAudioInfo * info, GstAudioFormat format, gint rate, gint channels, const GstAudioChannelPosition * position) { const GstAudioFormatInfo *finfo; gint i; g_return_if_fail (info != NULL); g_return_if_fail (format != GST_AUDIO_FORMAT_UNKNOWN); g_return_if_fail (channels <= 64 || position == NULL); gst_audio_info_init (info); finfo = gst_audio_format_get_info (format); info->flags = 0; info->layout = GST_AUDIO_LAYOUT_INTERLEAVED; info->finfo = finfo; info->rate = rate; info->channels = channels; info->bpf = (finfo->width * channels) / 8; memset (&info->position, 0xff, sizeof (info->position)); if (!position && channels == 1) { info->position[0] = GST_AUDIO_CHANNEL_POSITION_MONO; return; } else if (!position && channels == 2) { info->position[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT; info->position[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT; return; } else { if (!position || !gst_audio_check_valid_channel_positions (position, channels, TRUE)) { if (position) g_warning ("Invalid channel positions"); } else { memcpy (&info->position, position, info->channels * sizeof (info->position[0])); if (info->position[0] == GST_AUDIO_CHANNEL_POSITION_NONE) info->flags |= GST_AUDIO_FLAG_UNPOSITIONED; return; } } /* Otherwise a NONE layout */ info->flags |= GST_AUDIO_FLAG_UNPOSITIONED; for (i = 0; i < MIN (64, channels); i++) info->position[i] = GST_AUDIO_CHANNEL_POSITION_NONE; }
static void gst_imx_audio_uniaudio_dec_fill_channel_positions(GstImxAudioUniaudioDec *imx_audio_uniaudio_dec, uint32 const *uniaudio_out_layout, guint num_channels) { guint i; gsize num_chanpos_bytes = num_channels * sizeof(GstAudioChannelPosition); imx_audio_uniaudio_dec->original_channel_positions = g_malloc0(num_chanpos_bytes); imx_audio_uniaudio_dec->reordered_channel_positions = g_malloc0(num_chanpos_bytes); if (num_channels == 1) { imx_audio_uniaudio_dec->original_channel_positions[0] = GST_AUDIO_CHANNEL_POSITION_MONO; } else { for (i = 0; i < num_channels; ++i) { GstAudioChannelPosition *pos = &(imx_audio_uniaudio_dec->original_channel_positions[i]); switch (uniaudio_out_layout[i]) { case UA_CHANNEL_FRONT_LEFT: *pos = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT; break; case UA_CHANNEL_FRONT_RIGHT: *pos = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT; break; case UA_CHANNEL_REAR_CENTER: *pos = GST_AUDIO_CHANNEL_POSITION_REAR_CENTER; break; case UA_CHANNEL_REAR_LEFT: *pos = GST_AUDIO_CHANNEL_POSITION_REAR_LEFT; break; case UA_CHANNEL_REAR_RIGHT: *pos = GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT; break; case UA_CHANNEL_LFE: *pos = GST_AUDIO_CHANNEL_POSITION_LFE1; break; case UA_CHANNEL_FRONT_CENTER: *pos = GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER; break; case UA_CHANNEL_FRONT_LEFT_CENTER: *pos = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT; break; case UA_CHANNEL_FRONT_RIGHT_CENTER: *pos = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT; break; case UA_CHANNEL_SIDE_LEFT: *pos = GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT; break; case UA_CHANNEL_SIDE_RIGHT: *pos = GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT; break; default: *pos = GST_AUDIO_CHANNEL_POSITION_INVALID; } } } if (gst_audio_check_valid_channel_positions(imx_audio_uniaudio_dec->original_channel_positions, num_channels, TRUE)) { GST_DEBUG_OBJECT(imx_audio_uniaudio_dec, "channel positions are in valid order, no need to reorder channels"); imx_audio_uniaudio_dec->reordered_channel_positions = imx_audio_uniaudio_dec->original_channel_positions; } else { GST_DEBUG_OBJECT(imx_audio_uniaudio_dec, "channel positions are not in valid order -> need to reorder channels"); memcpy(imx_audio_uniaudio_dec->reordered_channel_positions, imx_audio_uniaudio_dec->original_channel_positions, num_chanpos_bytes); gst_audio_channel_positions_to_valid_order(imx_audio_uniaudio_dec->reordered_channel_positions, num_channels); } }
GstAudioRingBufferSpec * gst_pulse_channel_map_to_gst (const pa_channel_map * map, GstAudioRingBufferSpec * spec) { gint i, j; gboolean invalid = FALSE; gint channels; GstAudioChannelPosition *pos; channels = GST_AUDIO_INFO_CHANNELS (&spec->info); g_return_val_if_fail (map->channels == channels, NULL); pos = spec->info.position; for (j = 0; j < channels; j++) { for (i = 0; j < channels && i < G_N_ELEMENTS (gst_pa_pos_table); i++) { if (map->map[j] == gst_pa_pos_table[i].pa_pos) { pos[j] = gst_pa_pos_table[i].gst_pos; break; } } if (i == G_N_ELEMENTS (gst_pa_pos_table)) return NULL; } if (!invalid && !gst_audio_check_valid_channel_positions (pos, channels, FALSE)) invalid = TRUE; if (invalid) { for (i = 0; i < channels; i++) pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE; } else { if (pos[0] != GST_AUDIO_CHANNEL_POSITION_NONE) spec->info.flags &= ~GST_AUDIO_FLAG_UNPOSITIONED; } return spec; }