static gboolean gst_rtp_L16_pay_setcaps (GstRTPBasePayload * basepayload, GstCaps * caps) { GstRtpL16Pay *rtpL16pay; gboolean res; gchar *params; GstAudioInfo *info; const GstRTPChannelOrder *order; GstRTPBaseAudioPayload *rtpbaseaudiopayload; rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (basepayload); rtpL16pay = GST_RTP_L16_PAY (basepayload); info = &rtpL16pay->info; gst_audio_info_init (info); if (!gst_audio_info_from_caps (info, caps)) goto invalid_caps; order = gst_rtp_channels_get_by_pos (info->channels, info->position); rtpL16pay->order = order; gst_rtp_base_payload_set_options (basepayload, "audio", TRUE, "L16", info->rate); params = g_strdup_printf ("%d", info->channels); if (!order && info->channels > 2) { GST_ELEMENT_WARNING (rtpL16pay, STREAM, DECODE, (NULL), ("Unknown channel order for %d channels", info->channels)); } if (order && order->name) { res = gst_rtp_base_payload_set_outcaps (basepayload, "encoding-params", G_TYPE_STRING, params, "channels", G_TYPE_INT, info->channels, "channel-order", G_TYPE_STRING, order->name, NULL); } else { res = gst_rtp_base_payload_set_outcaps (basepayload, "encoding-params", G_TYPE_STRING, params, "channels", G_TYPE_INT, info->channels, NULL); } g_free (params); /* octet-per-sample is 2 * channels for L16 */ gst_rtp_base_audio_payload_set_sample_options (rtpbaseaudiopayload, 2 * info->channels); return res; /* ERRORS */ invalid_caps: { GST_DEBUG_OBJECT (rtpL16pay, "invalid caps"); return FALSE; } }
static GstFlowReturn gst_rtp_L16_pay_handle_buffer (GstRTPBasePayload * basepayload, GstBuffer * buffer) { GstRtpL16Pay *rtpL16pay; rtpL16pay = GST_RTP_L16_PAY (basepayload); buffer = gst_buffer_make_writable (buffer); if (rtpL16pay->order && !gst_audio_buffer_reorder_channels (buffer, rtpL16pay->info.finfo->format, rtpL16pay->info.channels, rtpL16pay->info.position, rtpL16pay->order->pos)) { return GST_FLOW_ERROR; } return GST_RTP_BASE_PAYLOAD_CLASS (parent_class)->handle_buffer (basepayload, buffer); }
static gboolean gst_rtp_L16_pay_setcaps (GstBaseRTPPayload * basepayload, GstCaps * caps) { GstRtpL16Pay *rtpL16pay; GstStructure *structure; gint channels, rate; gboolean res; gchar *params; GstAudioChannelPosition *pos; const GstRTPChannelOrder *order; GstBaseRTPAudioPayload *basertpaudiopayload; basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (basepayload); rtpL16pay = GST_RTP_L16_PAY (basepayload); structure = gst_caps_get_structure (caps, 0); /* first parse input caps */ if (!gst_structure_get_int (structure, "rate", &rate)) goto no_rate; if (!gst_structure_get_int (structure, "channels", &channels)) goto no_channels; /* get the channel order */ pos = gst_audio_get_channel_positions (structure); if (pos) order = gst_rtp_channels_get_by_pos (channels, pos); else order = NULL; gst_basertppayload_set_options (basepayload, "audio", TRUE, "L16", rate); params = g_strdup_printf ("%d", channels); if (!order && channels > 2) { GST_ELEMENT_WARNING (rtpL16pay, STREAM, DECODE, (NULL), ("Unknown channel order for %d channels", channels)); } if (order && order->name) { res = gst_basertppayload_set_outcaps (basepayload, "encoding-params", G_TYPE_STRING, params, "channels", G_TYPE_INT, channels, "channel-order", G_TYPE_STRING, order->name, NULL); } else { res = gst_basertppayload_set_outcaps (basepayload, "encoding-params", G_TYPE_STRING, params, "channels", G_TYPE_INT, channels, NULL); } g_free (params); g_free (pos); rtpL16pay->rate = rate; rtpL16pay->channels = channels; /* octet-per-sample is 2 * channels for L16 */ gst_base_rtp_audio_payload_set_sample_options (basertpaudiopayload, 2 * rtpL16pay->channels); return res; /* ERRORS */ no_rate: { GST_DEBUG_OBJECT (rtpL16pay, "no rate given"); return FALSE; } no_channels: { GST_DEBUG_OBJECT (rtpL16pay, "no channels given"); return FALSE; } }