mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-17 22:06:41 +00:00
basertp: use caps event instead of setcaps function
Use the caps event instead of the setcaps function to configure caps. Use a default event handler for the base rtp payloader instead of the awkward way of handling the return value.
This commit is contained in:
parent
e6f8f7f310
commit
81ebc0a82e
4 changed files with 68 additions and 61 deletions
|
@ -156,8 +156,8 @@ static GstFlowReturn gst_base_rtp_audio_payload_handle_buffer (GstBaseRTPPayload
|
||||||
static GstStateChangeReturn gst_base_rtp_payload_audio_change_state (GstElement
|
static GstStateChangeReturn gst_base_rtp_payload_audio_change_state (GstElement
|
||||||
* element, GstStateChange transition);
|
* element, GstStateChange transition);
|
||||||
|
|
||||||
static gboolean gst_base_rtp_payload_audio_handle_event (GstPad * pad,
|
static gboolean gst_base_rtp_payload_audio_handle_event (GstBaseRTPPayload
|
||||||
GstEvent * event);
|
* payload, GstEvent * event);
|
||||||
|
|
||||||
#define gst_base_rtp_audio_payload_parent_class parent_class
|
#define gst_base_rtp_audio_payload_parent_class parent_class
|
||||||
G_DEFINE_TYPE (GstBaseRTPAudioPayload, gst_base_rtp_audio_payload,
|
G_DEFINE_TYPE (GstBaseRTPAudioPayload, gst_base_rtp_audio_payload,
|
||||||
|
@ -953,12 +953,13 @@ gst_base_rtp_payload_audio_change_state (GstElement * element,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_base_rtp_payload_audio_handle_event (GstPad * pad, GstEvent * event)
|
gst_base_rtp_payload_audio_handle_event (GstBaseRTPPayload * basep,
|
||||||
|
GstEvent * event)
|
||||||
{
|
{
|
||||||
GstBaseRTPAudioPayload *payload;
|
GstBaseRTPAudioPayload *payload;
|
||||||
gboolean res = FALSE;
|
gboolean res = FALSE;
|
||||||
|
|
||||||
payload = GST_BASE_RTP_AUDIO_PAYLOAD (gst_pad_get_parent (pad));
|
payload = GST_BASE_RTP_AUDIO_PAYLOAD (basep);
|
||||||
|
|
||||||
switch (GST_EVENT_TYPE (event)) {
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
case GST_EVENT_EOS:
|
case GST_EVENT_EOS:
|
||||||
|
@ -972,9 +973,9 @@ gst_base_rtp_payload_audio_handle_event (GstPad * pad, GstEvent * event)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_object_unref (payload);
|
/* let parent handle the remainder of the event */
|
||||||
|
res = GST_BASE_RTP_PAYLOAD_CLASS (parent_class)->handle_event (basep, event);
|
||||||
|
|
||||||
/* return FALSE to let parent handle the remainder of the event */
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,6 @@ static void gst_base_rtp_depayload_set_property (GObject * object,
|
||||||
static void gst_base_rtp_depayload_get_property (GObject * object,
|
static void gst_base_rtp_depayload_get_property (GObject * object,
|
||||||
guint prop_id, GValue * value, GParamSpec * pspec);
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
||||||
|
|
||||||
static gboolean gst_base_rtp_depayload_setcaps (GstPad * pad, GstCaps * caps);
|
|
||||||
static GstFlowReturn gst_base_rtp_depayload_chain (GstPad * pad,
|
static GstFlowReturn gst_base_rtp_depayload_chain (GstPad * pad,
|
||||||
GstBuffer * in);
|
GstBuffer * in);
|
||||||
static gboolean gst_base_rtp_depayload_handle_sink_event (GstPad * pad,
|
static gboolean gst_base_rtp_depayload_handle_sink_event (GstPad * pad,
|
||||||
|
@ -157,8 +156,6 @@ gst_base_rtp_depayload_init (GstBaseRTPDepayload * filter,
|
||||||
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "sink");
|
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "sink");
|
||||||
g_return_if_fail (pad_template != NULL);
|
g_return_if_fail (pad_template != NULL);
|
||||||
filter->sinkpad = gst_pad_new_from_template (pad_template, "sink");
|
filter->sinkpad = gst_pad_new_from_template (pad_template, "sink");
|
||||||
gst_pad_set_setcaps_function (filter->sinkpad,
|
|
||||||
gst_base_rtp_depayload_setcaps);
|
|
||||||
gst_pad_set_chain_function (filter->sinkpad, gst_base_rtp_depayload_chain);
|
gst_pad_set_chain_function (filter->sinkpad, gst_base_rtp_depayload_chain);
|
||||||
gst_pad_set_event_function (filter->sinkpad,
|
gst_pad_set_event_function (filter->sinkpad,
|
||||||
gst_base_rtp_depayload_handle_sink_event);
|
gst_base_rtp_depayload_handle_sink_event);
|
||||||
|
@ -181,16 +178,14 @@ gst_base_rtp_depayload_finalize (GObject * object)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_base_rtp_depayload_setcaps (GstPad * pad, GstCaps * caps)
|
gst_base_rtp_depayload_setcaps (GstBaseRTPDepayload * filter, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstBaseRTPDepayload *filter;
|
|
||||||
GstBaseRTPDepayloadClass *bclass;
|
GstBaseRTPDepayloadClass *bclass;
|
||||||
GstBaseRTPDepayloadPrivate *priv;
|
GstBaseRTPDepayloadPrivate *priv;
|
||||||
gboolean res;
|
gboolean res;
|
||||||
GstStructure *caps_struct;
|
GstStructure *caps_struct;
|
||||||
const GValue *value;
|
const GValue *value;
|
||||||
|
|
||||||
filter = GST_BASE_RTP_DEPAYLOAD (gst_pad_get_parent (pad));
|
|
||||||
priv = filter->priv;
|
priv = filter->priv;
|
||||||
|
|
||||||
bclass = GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
|
bclass = GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
|
||||||
|
@ -239,8 +234,6 @@ gst_base_rtp_depayload_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
|
|
||||||
priv->negotiated = res;
|
priv->negotiated = res;
|
||||||
|
|
||||||
gst_object_unref (filter);
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,6 +394,16 @@ gst_base_rtp_depayload_handle_event (GstBaseRTPDepayload * filter,
|
||||||
filter->need_newsegment = TRUE;
|
filter->need_newsegment = TRUE;
|
||||||
filter->priv->next_seqnum = -1;
|
filter->priv->next_seqnum = -1;
|
||||||
break;
|
break;
|
||||||
|
case GST_EVENT_CAPS:
|
||||||
|
{
|
||||||
|
GstCaps *caps;
|
||||||
|
|
||||||
|
gst_event_parse_caps (event, &caps);
|
||||||
|
|
||||||
|
res = gst_base_rtp_depayload_setcaps (filter, caps);
|
||||||
|
forward = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case GST_EVENT_SEGMENT:
|
case GST_EVENT_SEGMENT:
|
||||||
{
|
{
|
||||||
gst_event_copy_segment (event, &filter->segment);
|
gst_event_copy_segment (event, &filter->segment);
|
||||||
|
|
|
@ -94,9 +94,10 @@ static void gst_basertppayload_init (GstBaseRTPPayload * basertppayload,
|
||||||
gpointer g_class);
|
gpointer g_class);
|
||||||
static void gst_basertppayload_finalize (GObject * object);
|
static void gst_basertppayload_finalize (GObject * object);
|
||||||
|
|
||||||
static gboolean gst_basertppayload_sink_setcaps (GstPad * pad, GstCaps * caps);
|
|
||||||
static GstCaps *gst_basertppayload_sink_getcaps (GstPad * pad,
|
static GstCaps *gst_basertppayload_sink_getcaps (GstPad * pad,
|
||||||
GstCaps * filter);
|
GstCaps * filter);
|
||||||
|
static gboolean gst_basertppayload_event_default (GstBaseRTPPayload *
|
||||||
|
basertppayload, GstEvent * event);
|
||||||
static gboolean gst_basertppayload_event (GstPad * pad, GstEvent * event);
|
static gboolean gst_basertppayload_event (GstPad * pad, GstEvent * event);
|
||||||
static GstFlowReturn gst_basertppayload_chain (GstPad * pad,
|
static GstFlowReturn gst_basertppayload_chain (GstPad * pad,
|
||||||
GstBuffer * buffer);
|
GstBuffer * buffer);
|
||||||
|
@ -240,6 +241,8 @@ gst_basertppayload_class_init (GstBaseRTPPayloadClass * klass)
|
||||||
|
|
||||||
gstelement_class->change_state = gst_basertppayload_change_state;
|
gstelement_class->change_state = gst_basertppayload_change_state;
|
||||||
|
|
||||||
|
klass->handle_event = gst_basertppayload_event_default;
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_INIT (basertppayload_debug, "basertppayload", 0,
|
GST_DEBUG_CATEGORY_INIT (basertppayload_debug, "basertppayload", 0,
|
||||||
"Base class for RTP Payloaders");
|
"Base class for RTP Payloaders");
|
||||||
}
|
}
|
||||||
|
@ -265,8 +268,6 @@ gst_basertppayload_init (GstBaseRTPPayload * basertppayload, gpointer g_class)
|
||||||
g_return_if_fail (templ != NULL);
|
g_return_if_fail (templ != NULL);
|
||||||
|
|
||||||
basertppayload->sinkpad = gst_pad_new_from_template (templ, "sink");
|
basertppayload->sinkpad = gst_pad_new_from_template (templ, "sink");
|
||||||
gst_pad_set_setcaps_function (basertppayload->sinkpad,
|
|
||||||
gst_basertppayload_sink_setcaps);
|
|
||||||
gst_pad_set_getcaps_function (basertppayload->sinkpad,
|
gst_pad_set_getcaps_function (basertppayload->sinkpad,
|
||||||
gst_basertppayload_sink_getcaps);
|
gst_basertppayload_sink_getcaps);
|
||||||
gst_pad_set_event_function (basertppayload->sinkpad,
|
gst_pad_set_event_function (basertppayload->sinkpad,
|
||||||
|
@ -324,25 +325,6 @@ gst_basertppayload_finalize (GObject * object)
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_basertppayload_sink_setcaps (GstPad * pad, GstCaps * caps)
|
|
||||||
{
|
|
||||||
GstBaseRTPPayload *basertppayload;
|
|
||||||
GstBaseRTPPayloadClass *basertppayload_class;
|
|
||||||
gboolean ret = TRUE;
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (pad, "setting caps %" GST_PTR_FORMAT, caps);
|
|
||||||
basertppayload = GST_BASE_RTP_PAYLOAD (gst_pad_get_parent (pad));
|
|
||||||
basertppayload_class = GST_BASE_RTP_PAYLOAD_GET_CLASS (basertppayload);
|
|
||||||
|
|
||||||
if (basertppayload_class->set_caps)
|
|
||||||
ret = basertppayload_class->set_caps (basertppayload, caps);
|
|
||||||
|
|
||||||
gst_object_unref (basertppayload);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstCaps *
|
static GstCaps *
|
||||||
gst_basertppayload_sink_getcaps (GstPad * pad, GstCaps * filter)
|
gst_basertppayload_sink_getcaps (GstPad * pad, GstCaps * filter)
|
||||||
{
|
{
|
||||||
|
@ -376,33 +358,32 @@ gst_basertppayload_sink_getcaps (GstPad * pad, GstCaps * filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_basertppayload_event (GstPad * pad, GstEvent * event)
|
gst_basertppayload_event_default (GstBaseRTPPayload * basertppayload,
|
||||||
|
GstEvent * event)
|
||||||
{
|
{
|
||||||
GstBaseRTPPayload *basertppayload;
|
gboolean res = FALSE;
|
||||||
GstBaseRTPPayloadClass *basertppayload_class;
|
|
||||||
gboolean res;
|
|
||||||
|
|
||||||
basertppayload = GST_BASE_RTP_PAYLOAD (gst_pad_get_parent (pad));
|
|
||||||
if (G_UNLIKELY (basertppayload == NULL)) {
|
|
||||||
gst_event_unref (event);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
basertppayload_class = GST_BASE_RTP_PAYLOAD_GET_CLASS (basertppayload);
|
|
||||||
|
|
||||||
if (basertppayload_class->handle_event) {
|
|
||||||
res = basertppayload_class->handle_event (pad, event);
|
|
||||||
if (res)
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (GST_EVENT_TYPE (event)) {
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
case GST_EVENT_FLUSH_START:
|
case GST_EVENT_FLUSH_START:
|
||||||
res = gst_pad_event_default (pad, event);
|
res = gst_pad_event_default (basertppayload->sinkpad, event);
|
||||||
break;
|
break;
|
||||||
case GST_EVENT_FLUSH_STOP:
|
case GST_EVENT_FLUSH_STOP:
|
||||||
res = gst_pad_event_default (pad, event);
|
res = gst_pad_event_default (basertppayload->sinkpad, event);
|
||||||
gst_segment_init (&basertppayload->segment, GST_FORMAT_UNDEFINED);
|
gst_segment_init (&basertppayload->segment, GST_FORMAT_UNDEFINED);
|
||||||
break;
|
break;
|
||||||
|
case GST_EVENT_CAPS:
|
||||||
|
{
|
||||||
|
GstBaseRTPPayloadClass *basertppayload_class;
|
||||||
|
GstCaps *caps;
|
||||||
|
|
||||||
|
gst_event_parse_caps (event, &caps);
|
||||||
|
GST_DEBUG_OBJECT (basertppayload, "setting caps %" GST_PTR_FORMAT, caps);
|
||||||
|
|
||||||
|
basertppayload_class = GST_BASE_RTP_PAYLOAD_GET_CLASS (basertppayload);
|
||||||
|
if (basertppayload_class->set_caps)
|
||||||
|
res = basertppayload_class->set_caps (basertppayload, caps);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case GST_EVENT_SEGMENT:
|
case GST_EVENT_SEGMENT:
|
||||||
{
|
{
|
||||||
GstSegment *segment;
|
GstSegment *segment;
|
||||||
|
@ -412,14 +393,36 @@ gst_basertppayload_event (GstPad * pad, GstEvent * event)
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (basertppayload,
|
GST_DEBUG_OBJECT (basertppayload,
|
||||||
"configured SEGMENT %" GST_SEGMENT_FORMAT, segment);
|
"configured SEGMENT %" GST_SEGMENT_FORMAT, segment);
|
||||||
/* fallthrough */
|
res = gst_pad_event_default (basertppayload->sinkpad, event);
|
||||||
}
|
|
||||||
default:
|
|
||||||
res = gst_pad_event_default (pad, event);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
res = gst_pad_event_default (basertppayload->sinkpad, event);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_basertppayload_event (GstPad * pad, GstEvent * event)
|
||||||
|
{
|
||||||
|
GstBaseRTPPayload *basertppayload;
|
||||||
|
GstBaseRTPPayloadClass *basertppayload_class;
|
||||||
|
gboolean res = FALSE;
|
||||||
|
|
||||||
|
basertppayload = GST_BASE_RTP_PAYLOAD (gst_pad_get_parent (pad));
|
||||||
|
if (G_UNLIKELY (basertppayload == NULL)) {
|
||||||
|
gst_event_unref (event);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
basertppayload_class = GST_BASE_RTP_PAYLOAD_GET_CLASS (basertppayload);
|
||||||
|
|
||||||
|
if (basertppayload_class->handle_event)
|
||||||
|
res = basertppayload_class->handle_event (basertppayload, event);
|
||||||
|
else
|
||||||
|
gst_event_unref (event);
|
||||||
|
|
||||||
done:
|
|
||||||
gst_object_unref (basertppayload);
|
gst_object_unref (basertppayload);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -816,8 +819,8 @@ gst_basertppayload_prepare_push (GstBaseRTPPayload * payload,
|
||||||
gst_buffer_get_size (GST_BUFFER (obj)), payload->seqnum, data.rtptime,
|
gst_buffer_get_size (GST_BUFFER (obj)), payload->seqnum, data.rtptime,
|
||||||
GST_TIME_ARGS (data.timestamp));
|
GST_TIME_ARGS (data.timestamp));
|
||||||
|
|
||||||
if (g_atomic_int_compare_and_exchange (&payload->
|
if (g_atomic_int_compare_and_exchange (&payload->priv->
|
||||||
priv->notified_first_timestamp, 1, 0)) {
|
notified_first_timestamp, 1, 0)) {
|
||||||
g_object_notify (G_OBJECT (payload), "timestamp");
|
g_object_notify (G_OBJECT (payload), "timestamp");
|
||||||
g_object_notify (G_OBJECT (payload), "seqnum");
|
g_object_notify (G_OBJECT (payload), "seqnum");
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ struct _GstBaseRTPPayloadClass
|
||||||
* the RTP buffers. This function takes ownership of the buffer. */
|
* the RTP buffers. This function takes ownership of the buffer. */
|
||||||
GstFlowReturn (*handle_buffer) (GstBaseRTPPayload *payload,
|
GstFlowReturn (*handle_buffer) (GstBaseRTPPayload *payload,
|
||||||
GstBuffer *buffer);
|
GstBuffer *buffer);
|
||||||
gboolean (*handle_event) (GstPad * pad, GstEvent * event);
|
gboolean (*handle_event) (GstBaseRTPPayload *payload, GstEvent * event);
|
||||||
GstCaps * (*get_caps) (GstBaseRTPPayload *payload, GstPad * pad, GstCaps * filter);
|
GstCaps * (*get_caps) (GstBaseRTPPayload *payload, GstPad * pad, GstCaps * filter);
|
||||||
|
|
||||||
/*< private >*/
|
/*< private >*/
|
||||||
|
|
Loading…
Reference in a new issue