mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-25 15:36:42 +00:00
mpapay: reset payloader on flush
Reset the payloader on a flush event. Handle DISCONT better.
This commit is contained in:
parent
eb6d552353
commit
984849f8fe
1 changed files with 50 additions and 9 deletions
|
@ -52,6 +52,7 @@ static void gst_rtp_mpa_pay_finalize (GObject * object);
|
||||||
|
|
||||||
static gboolean gst_rtp_mpa_pay_setcaps (GstBaseRTPPayload * payload,
|
static gboolean gst_rtp_mpa_pay_setcaps (GstBaseRTPPayload * payload,
|
||||||
GstCaps * caps);
|
GstCaps * caps);
|
||||||
|
static gboolean gst_rtp_mpa_pay_handle_event (GstPad * pad, GstEvent * event);
|
||||||
static GstFlowReturn gst_rtp_mpa_pay_handle_buffer (GstBaseRTPPayload * payload,
|
static GstFlowReturn gst_rtp_mpa_pay_handle_buffer (GstBaseRTPPayload * payload,
|
||||||
GstBuffer * buffer);
|
GstBuffer * buffer);
|
||||||
|
|
||||||
|
@ -85,6 +86,7 @@ gst_rtp_mpa_pay_class_init (GstRtpMPAPayClass * klass)
|
||||||
gobject_class->finalize = gst_rtp_mpa_pay_finalize;
|
gobject_class->finalize = gst_rtp_mpa_pay_finalize;
|
||||||
|
|
||||||
gstbasertppayload_class->set_caps = gst_rtp_mpa_pay_setcaps;
|
gstbasertppayload_class->set_caps = gst_rtp_mpa_pay_setcaps;
|
||||||
|
gstbasertppayload_class->handle_event = gst_rtp_mpa_pay_handle_event;
|
||||||
gstbasertppayload_class->handle_buffer = gst_rtp_mpa_pay_handle_buffer;
|
gstbasertppayload_class->handle_buffer = gst_rtp_mpa_pay_handle_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +109,15 @@ gst_rtp_mpa_pay_finalize (GObject * object)
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_rtp_mpa_pay_reset (GstRtpMPAPay * pay)
|
||||||
|
{
|
||||||
|
pay->first_ts = -1;
|
||||||
|
pay->duration = 0;
|
||||||
|
gst_adapter_clear (pay->adapter);
|
||||||
|
GST_DEBUG_OBJECT (pay, "reset depayloader");
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_rtp_mpa_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
|
gst_rtp_mpa_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
|
||||||
{
|
{
|
||||||
|
@ -118,6 +129,27 @@ gst_rtp_mpa_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_rtp_mpa_pay_handle_event (GstPad * pad, GstEvent * event)
|
||||||
|
{
|
||||||
|
GstRtpMPAPay *rtpmpapay;
|
||||||
|
|
||||||
|
rtpmpapay = GST_RTP_MPA_PAY (gst_pad_get_parent (pad));
|
||||||
|
|
||||||
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
|
case GST_EVENT_FLUSH_STOP:
|
||||||
|
gst_rtp_mpa_pay_reset (rtpmpapay);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_object_unref (rtpmpapay);
|
||||||
|
|
||||||
|
/* FALSE to let the parent handle the event as well */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_rtp_mpa_pay_flush (GstRtpMPAPay * rtpmpapay)
|
gst_rtp_mpa_pay_flush (GstRtpMPAPay * rtpmpapay)
|
||||||
{
|
{
|
||||||
|
@ -143,7 +175,7 @@ gst_rtp_mpa_pay_flush (GstRtpMPAPay * rtpmpapay)
|
||||||
guint payload_len;
|
guint payload_len;
|
||||||
guint packet_len;
|
guint packet_len;
|
||||||
|
|
||||||
/* this will be the total lenght of the packet */
|
/* this will be the total length of the packet */
|
||||||
packet_len = gst_rtp_buffer_calc_packet_len (4 + avail, 0, 0);
|
packet_len = gst_rtp_buffer_calc_packet_len (4 + avail, 0, 0);
|
||||||
|
|
||||||
/* fill one MTU or all available bytes */
|
/* fill one MTU or all available bytes */
|
||||||
|
@ -198,18 +230,20 @@ gst_rtp_mpa_pay_handle_buffer (GstBaseRTPPayload * basepayload,
|
||||||
GstFlowReturn ret;
|
GstFlowReturn ret;
|
||||||
guint size, avail;
|
guint size, avail;
|
||||||
guint packet_len;
|
guint packet_len;
|
||||||
GstClockTime duration;
|
GstClockTime duration, timestamp;
|
||||||
|
|
||||||
rtpmpapay = GST_RTP_MPA_PAY (basepayload);
|
rtpmpapay = GST_RTP_MPA_PAY (basepayload);
|
||||||
|
|
||||||
size = GST_BUFFER_SIZE (buffer);
|
size = GST_BUFFER_SIZE (buffer);
|
||||||
duration = GST_BUFFER_DURATION (buffer);
|
duration = GST_BUFFER_DURATION (buffer);
|
||||||
|
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
||||||
|
|
||||||
|
if (GST_BUFFER_IS_DISCONT (buffer)) {
|
||||||
|
GST_DEBUG_OBJECT (rtpmpapay, "DISCONT");
|
||||||
|
gst_rtp_mpa_pay_reset (rtpmpapay);
|
||||||
|
}
|
||||||
|
|
||||||
avail = gst_adapter_available (rtpmpapay->adapter);
|
avail = gst_adapter_available (rtpmpapay->adapter);
|
||||||
if (avail == 0) {
|
|
||||||
rtpmpapay->first_ts = GST_BUFFER_TIMESTAMP (buffer);
|
|
||||||
rtpmpapay->duration = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get packet length of previous data and this new data,
|
/* get packet length of previous data and this new data,
|
||||||
* payload length includes a 4 byte header */
|
* payload length includes a 4 byte header */
|
||||||
|
@ -220,14 +254,21 @@ gst_rtp_mpa_pay_handle_buffer (GstBaseRTPPayload * basepayload,
|
||||||
if (gst_basertppayload_is_filled (basepayload,
|
if (gst_basertppayload_is_filled (basepayload,
|
||||||
packet_len, rtpmpapay->duration + duration)) {
|
packet_len, rtpmpapay->duration + duration)) {
|
||||||
ret = gst_rtp_mpa_pay_flush (rtpmpapay);
|
ret = gst_rtp_mpa_pay_flush (rtpmpapay);
|
||||||
rtpmpapay->first_ts = GST_BUFFER_TIMESTAMP (buffer);
|
avail = 0;
|
||||||
rtpmpapay->duration = 0;
|
|
||||||
} else {
|
} else {
|
||||||
ret = GST_FLOW_OK;
|
ret = GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (avail == 0) {
|
||||||
|
GST_DEBUG_OBJECT (rtpmpapay,
|
||||||
|
"first packet, save timestamp %" GST_TIME_FORMAT,
|
||||||
|
GST_TIME_ARGS (timestamp));
|
||||||
|
rtpmpapay->first_ts = timestamp;
|
||||||
|
rtpmpapay->duration = 0;
|
||||||
|
}
|
||||||
|
|
||||||
gst_adapter_push (rtpmpapay->adapter, buffer);
|
gst_adapter_push (rtpmpapay->adapter, buffer);
|
||||||
rtpmpapay->duration += duration;
|
rtpmpapay->duration = duration;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue