static gboolean
gst_rtp_mp4g_pay_sink_event (GstRTPBasePayload * payload, GstEvent * event)
{
  GstRtpMP4GPay *rtpmp4gpay;

  rtpmp4gpay = GST_RTP_MP4G_PAY (payload);

  GST_DEBUG ("Got event: %s", GST_EVENT_TYPE_NAME (event));

  switch (GST_EVENT_TYPE (event)) {
    case GST_EVENT_SEGMENT:
    case GST_EVENT_EOS:
      /* This flush call makes sure that the last buffer is always pushed
       * to the base payloader */
      gst_rtp_mp4g_pay_flush (rtpmp4gpay);
      break;
    case GST_EVENT_FLUSH_STOP:
      gst_rtp_mp4g_pay_reset (rtpmp4gpay);
      break;
    default:
      break;
  }

  /* let parent handle event too */
  return GST_RTP_BASE_PAYLOAD_CLASS (parent_class)->sink_event (payload, event);
}
static gboolean
gst_rtp_mp4g_pay_handle_event (GstPad * pad, GstEvent * event)
{
  GstRtpMP4GPay *rtpmp4gpay;

  rtpmp4gpay = GST_RTP_MP4G_PAY (gst_pad_get_parent (pad));

  GST_DEBUG ("Got event: %s", GST_EVENT_TYPE_NAME (event));

  switch (GST_EVENT_TYPE (event)) {
    case GST_EVENT_NEWSEGMENT:
    case GST_EVENT_EOS:
      /* This flush call makes sure that the last buffer is always pushed
       * to the base payloader */
      gst_rtp_mp4g_pay_flush (rtpmp4gpay);
      break;
    case GST_EVENT_FLUSH_STOP:
      gst_rtp_mp4g_pay_reset (rtpmp4gpay);
      break;
    default:
      break;
  }

  g_object_unref (rtpmp4gpay);

  /* let parent handle event too */
  return FALSE;
}
static void
gst_rtp_mp4g_pay_finalize (GObject * object)
{
    GstRtpMP4GPay *rtpmp4gpay;

    rtpmp4gpay = GST_RTP_MP4G_PAY (object);

    gst_rtp_mp4g_pay_reset (rtpmp4gpay);

    g_object_unref (rtpmp4gpay->adapter);
    rtpmp4gpay->adapter = NULL;

    G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_rtp_mp4g_pay_cleanup (GstRtpMP4GPay * rtpmp4gpay)
{
  gst_rtp_mp4g_pay_reset (rtpmp4gpay);

  g_free (rtpmp4gpay->params);
  rtpmp4gpay->params = NULL;

  if (rtpmp4gpay->config)
    gst_buffer_unref (rtpmp4gpay->config);
  rtpmp4gpay->config = NULL;

  g_free (rtpmp4gpay->profile);
  rtpmp4gpay->profile = NULL;

  rtpmp4gpay->streamtype = NULL;
  rtpmp4gpay->mode = NULL;

  rtpmp4gpay->frame_len = 0;
}
static GstStateChangeReturn
gst_rtp_mp4g_pay_change_state (GstElement * element, GstStateChange transition)
{
    GstStateChangeReturn ret;
    GstRtpMP4GPay *rtpmp4gpay;

    rtpmp4gpay = GST_RTP_MP4G_PAY (element);

    switch (transition) {
    case GST_STATE_CHANGE_READY_TO_PAUSED:
        gst_rtp_mp4g_pay_reset (rtpmp4gpay);
        break;
    default:
        break;
    }

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

    return ret;
}