static gboolean
gst_base_rtp_payload_audio_handle_event (GstPad * pad, GstEvent * event)
{
  GstBaseRTPAudioPayload *payload;
  gboolean res = FALSE;

  payload = GST_BASE_RTP_AUDIO_PAYLOAD (gst_pad_get_parent (pad));

  switch (GST_EVENT_TYPE (event)) {
    case GST_EVENT_EOS:
      /* flush remaining bytes in the adapter */
      gst_base_rtp_audio_payload_flush (payload, -1, -1);
      break;
    case GST_EVENT_FLUSH_STOP:
      gst_adapter_clear (payload->priv->adapter);
      break;
    default:
      break;
  }

  gst_object_unref (payload);

  /* return FALSE to let parent handle the remainder of the event */
  return res;
}
static GstStateChangeReturn
gst_base_rtp_payload_audio_change_state (GstElement * element,
    GstStateChange transition)
{
  GstBaseRTPAudioPayload *basertppayload;
  GstStateChangeReturn ret;

  basertppayload = GST_BASE_RTP_AUDIO_PAYLOAD (element);

  switch (transition) {
    case GST_STATE_CHANGE_READY_TO_PAUSED:
      basertppayload->priv->cached_mtu = -1;
      basertppayload->priv->last_rtptime = -1;
      basertppayload->priv->last_timestamp = -1;
      break;
    default:
      break;
  }

  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);

  switch (transition) {
    case GST_STATE_CHANGE_PAUSED_TO_READY:
      gst_adapter_clear (basertppayload->priv->adapter);
      break;
    default:
      break;
  }

  return ret;
}
Example #3
0
static void
gst_rtp_g722_pay_init (GstRtpG722Pay * rtpg722pay, GstRtpG722PayClass * klass)
{
    GstBaseRTPAudioPayload *basertpaudiopayload;

    basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (rtpg722pay);

    /* tell basertpaudiopayload that this is a sample based codec */
    gst_base_rtp_audio_payload_set_sample_based (basertpaudiopayload);
}
static void
gst_base_rtp_audio_payload_finalize (GObject * object)
{
  GstBaseRTPAudioPayload *payload;

  payload = GST_BASE_RTP_AUDIO_PAYLOAD (object);

  g_object_unref (payload->priv->adapter);

  GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
}
static void
gst_rtp_pcma_pay_init (GstRtpPmcaPay * rtppcmapay, GstRtpPmcaPayClass * klass)
{
  GstBaseRTPAudioPayload *basertpaudiopayload;

  basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (rtppcmapay);

  GST_BASE_RTP_PAYLOAD (rtppcmapay)->clock_rate = 8000;

  /* tell basertpaudiopayload that this is a sample based codec */
  gst_base_rtp_audio_payload_set_sample_based (basertpaudiopayload);

  /* octet-per-sample is 1 for PCM */
  gst_base_rtp_audio_payload_set_sample_options (basertpaudiopayload, 1);
}
static void
gst_base_rtp_audio_payload_get_property (GObject * object,
    guint prop_id, GValue * value, GParamSpec * pspec)
{
  GstBaseRTPAudioPayload *payload;

  payload = GST_BASE_RTP_AUDIO_PAYLOAD (object);

  switch (prop_id) {
    case PROP_BUFFER_LIST:
      g_value_set_boolean (value, payload->priv->buffer_list);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
static void
gst_rtp_siren_pay_init (GstRTPSirenPay * rtpsirenpay,
    GstRTPSirenPayClass * klass)
{
  GstBaseRTPPayload *basertppayload;
  GstBaseRTPAudioPayload *basertpaudiopayload;

  basertppayload = GST_BASE_RTP_PAYLOAD (rtpsirenpay);
  basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (rtpsirenpay);

  /* we don't set the payload type, it should be set by the application using
   * the pt property or the default 96 will be used */
  basertppayload->clock_rate = 16000;

  /* tell basertpaudiopayload that this is a frame based codec */
  gst_base_rtp_audio_payload_set_frame_based (basertpaudiopayload);
}
static gboolean
gst_rtp_siren_pay_setcaps (GstBaseRTPPayload * basertppayload, GstCaps * caps)
{
  GstRTPSirenPay *rtpsirenpay;
  GstBaseRTPAudioPayload *basertpaudiopayload;
  gint dct_length;
  GstStructure *structure;
  const char *payload_name;

  rtpsirenpay = GST_RTP_SIREN_PAY (basertppayload);
  basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (basertppayload);

  structure = gst_caps_get_structure (caps, 0);

  gst_structure_get_int (structure, "dct-length", &dct_length);
  if (dct_length != 320)
    goto wrong_dct;

  payload_name = gst_structure_get_name (structure);
  if (g_ascii_strcasecmp ("audio/x-siren", payload_name))
    goto wrong_caps;

  gst_basertppayload_set_options (basertppayload, "audio", TRUE, "SIREN",
      16000);
  /* set options for this frame based audio codec */
  gst_base_rtp_audio_payload_set_frame_options (basertpaudiopayload, 20, 40);

  return gst_basertppayload_set_outcaps (basertppayload, NULL);

  /* ERRORS */
wrong_dct:
  {
    GST_ERROR_OBJECT (rtpsirenpay, "dct-length must be 320, received %d",
        dct_length);
    return FALSE;
  }
wrong_caps:
  {
    GST_ERROR_OBJECT (rtpsirenpay, "expected audio/x-siren, received %s",
        payload_name);
    return FALSE;
  }
}
Example #9
0
static gboolean
gst_rtp_ilbc_pay_sink_setcaps (GstBaseRTPPayload * basertppayload,
    GstCaps * caps)
{
  GstRTPILBCPay *rtpilbcpay;
  GstBaseRTPAudioPayload *basertpaudiopayload;
  gboolean ret;
  gint mode;
  gchar *mode_str;
  GstStructure *structure;
  const char *payload_name;

  rtpilbcpay = GST_RTP_ILBC_PAY (basertppayload);
  basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (basertppayload);

  structure = gst_caps_get_structure (caps, 0);

  payload_name = gst_structure_get_name (structure);
  if (g_ascii_strcasecmp ("audio/x-iLBC", payload_name))
    goto wrong_caps;

  if (!gst_structure_get_int (structure, "mode", &mode))
    goto no_mode;

  if (mode != 20 && mode != 30)
    goto wrong_mode;

  gst_basertppayload_set_options (basertppayload, "audio", TRUE, "ILBC", 8000);
  /* set options for this frame based audio codec */
  gst_base_rtp_audio_payload_set_frame_options (basertpaudiopayload,
      mode, mode == 30 ? 50 : 38);

  mode_str = g_strdup_printf ("%d", mode);
  ret =
      gst_basertppayload_set_outcaps (basertppayload, "mode", G_TYPE_STRING,
      mode_str, NULL);
  g_free (mode_str);

  if (mode != rtpilbcpay->mode && rtpilbcpay->mode != -1)
    goto mode_changed;

  rtpilbcpay->mode = mode;

  return ret;

  /* ERRORS */
wrong_caps:
  {
    GST_ERROR_OBJECT (rtpilbcpay, "expected audio/x-iLBC, received %s",
        payload_name);
    return FALSE;
  }
no_mode:
  {
    GST_ERROR_OBJECT (rtpilbcpay, "did not receive a mode");
    return FALSE;
  }
wrong_mode:
  {
    GST_ERROR_OBJECT (rtpilbcpay, "mode must be 20 or 30, received %d", mode);
    return FALSE;
  }
mode_changed:
  {
    GST_ERROR_OBJECT (rtpilbcpay, "Mode has changed from %d to %d! "
        "Mode cannot change while streaming", rtpilbcpay->mode, mode);
    return FALSE;
  }
}
Example #10
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;
    }
}