static gboolean
gst_rtp_g722_pay_setcaps (GstRTPBasePayload * basepayload, GstCaps * caps)
{
  GstRtpG722Pay *rtpg722pay;
  GstStructure *structure;
  gint rate, channels, clock_rate;
  gboolean res;
  gchar *params;
#if 0
  GstAudioChannelPosition *pos;
  const GstRTPChannelOrder *order;
#endif
  GstRTPBaseAudioPayload *rtpbaseaudiopayload;

  rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (basepayload);
  rtpg722pay = GST_RTP_G722_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;

  /* FIXME: Do something with the channel positions */
#if 0
  /* 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;
#endif

  /* Clock rate is always 8000 Hz for G722 according to
   * RFC 3551 although the sampling rate is 16000 Hz */
  clock_rate = 8000;

  gst_rtp_base_payload_set_options (basepayload, "audio",
      basepayload->pt != GST_RTP_PAYLOAD_G722, "G722", clock_rate);
  params = g_strdup_printf ("%d", channels);

#if 0
  if (!order && channels > 2) {
    GST_ELEMENT_WARNING (rtpg722pay, STREAM, DECODE,
        (NULL), ("Unknown channel order for %d channels", channels));
  }

  if (order && order->name) {
    res = gst_rtp_base_payload_set_outcaps (basepayload,
        "encoding-params", G_TYPE_STRING, params, "channels", G_TYPE_INT,
        channels, "channel-order", G_TYPE_STRING, order->name, NULL);
  } else {
#endif
    res = gst_rtp_base_payload_set_outcaps (basepayload,
        "encoding-params", G_TYPE_STRING, params, "channels", G_TYPE_INT,
        channels, NULL);
#if 0
  }
#endif

  g_free (params);
#if 0
  g_free (pos);
#endif

  rtpg722pay->rate = rate;
  rtpg722pay->channels = channels;

  /* bits-per-sample is 4 * channels for G722, but as the RTP clock runs at
   * half speed (8 instead of 16 khz), pretend it's 8 bits per sample
   * channels. */
  gst_rtp_base_audio_payload_set_samplebits_options (rtpbaseaudiopayload,
      8 * rtpg722pay->channels);

  return res;

  /* ERRORS */
no_rate:
  {
    GST_DEBUG_OBJECT (rtpg722pay, "no rate given");
    return FALSE;
  }
no_channels:
  {
    GST_DEBUG_OBJECT (rtpg722pay, "no channels given");
    return FALSE;
  }
}
Example #2
0
static gboolean
gst_rtp_g722_pay_setcaps (GstBaseRTPPayload * basepayload, GstCaps * caps)
{
    GstRtpG722Pay *rtpg722pay;
    GstStructure *structure;
    gint rate, channels, clock_rate;
    gboolean res;
    gchar *params;
    GstAudioChannelPosition *pos;
    const GstRTPChannelOrder *order;
    GstBaseRTPAudioPayload *basertpaudiopayload;

    basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (basepayload);
    rtpg722pay = GST_RTP_G722_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;

    /* Clock rate is always 8000 Hz for G722 according to
     * RFC 3551 although the sampling rate is 16000 Hz */
    clock_rate = 8000;

    gst_basertppayload_set_options (basepayload, "audio", TRUE, "G722",
                                    clock_rate);
    params = g_strdup_printf ("%d", channels);

    if (!order && channels > 2) {
        GST_ELEMENT_WARNING (rtpg722pay, 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);

    rtpg722pay->rate = rate;
    rtpg722pay->channels = channels;

    /* octet-per-sample is 1 * channels for G722 */
    gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
            4 * rtpg722pay->channels);

    return res;

    /* ERRORS */
no_rate:
    {
        GST_DEBUG_OBJECT (rtpg722pay, "no rate given");
        return FALSE;
    }
no_channels:
    {
        GST_DEBUG_OBJECT (rtpg722pay, "no channels given");
        return FALSE;
    }
}