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:
Wim Taymans 2011-06-02 19:21:24 +02:00
parent e6f8f7f310
commit 81ebc0a82e
4 changed files with 68 additions and 61 deletions

View file

@ -156,8 +156,8 @@ static GstFlowReturn gst_base_rtp_audio_payload_handle_buffer (GstBaseRTPPayload
static GstStateChangeReturn gst_base_rtp_payload_audio_change_state (GstElement
* element, GstStateChange transition);
static gboolean gst_base_rtp_payload_audio_handle_event (GstPad * pad,
GstEvent * event);
static gboolean gst_base_rtp_payload_audio_handle_event (GstBaseRTPPayload
* payload, GstEvent * event);
#define gst_base_rtp_audio_payload_parent_class parent_class
G_DEFINE_TYPE (GstBaseRTPAudioPayload, gst_base_rtp_audio_payload,
@ -953,12 +953,13 @@ gst_base_rtp_payload_audio_change_state (GstElement * element,
}
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;
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)) {
case GST_EVENT_EOS:
@ -972,9 +973,9 @@ gst_base_rtp_payload_audio_handle_event (GstPad * pad, GstEvent * event)
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;
}

View file

@ -68,7 +68,6 @@ static void gst_base_rtp_depayload_set_property (GObject * object,
static void gst_base_rtp_depayload_get_property (GObject * object,
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,
GstBuffer * in);
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");
g_return_if_fail (pad_template != NULL);
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_event_function (filter->sinkpad,
gst_base_rtp_depayload_handle_sink_event);
@ -181,16 +178,14 @@ gst_base_rtp_depayload_finalize (GObject * object)
}
static gboolean
gst_base_rtp_depayload_setcaps (GstPad * pad, GstCaps * caps)
gst_base_rtp_depayload_setcaps (GstBaseRTPDepayload * filter, GstCaps * caps)
{
GstBaseRTPDepayload *filter;
GstBaseRTPDepayloadClass *bclass;
GstBaseRTPDepayloadPrivate *priv;
gboolean res;
GstStructure *caps_struct;
const GValue *value;
filter = GST_BASE_RTP_DEPAYLOAD (gst_pad_get_parent (pad));
priv = filter->priv;
bclass = GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
@ -239,8 +234,6 @@ gst_base_rtp_depayload_setcaps (GstPad * pad, GstCaps * caps)
priv->negotiated = res;
gst_object_unref (filter);
return res;
}
@ -401,6 +394,16 @@ gst_base_rtp_depayload_handle_event (GstBaseRTPDepayload * filter,
filter->need_newsegment = TRUE;
filter->priv->next_seqnum = -1;
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:
{
gst_event_copy_segment (event, &filter->segment);

View file

@ -94,9 +94,10 @@ static void gst_basertppayload_init (GstBaseRTPPayload * basertppayload,
gpointer g_class);
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,
GstCaps * filter);
static gboolean gst_basertppayload_event_default (GstBaseRTPPayload *
basertppayload, GstEvent * event);
static gboolean gst_basertppayload_event (GstPad * pad, GstEvent * event);
static GstFlowReturn gst_basertppayload_chain (GstPad * pad,
GstBuffer * buffer);
@ -240,6 +241,8 @@ gst_basertppayload_class_init (GstBaseRTPPayloadClass * klass)
gstelement_class->change_state = gst_basertppayload_change_state;
klass->handle_event = gst_basertppayload_event_default;
GST_DEBUG_CATEGORY_INIT (basertppayload_debug, "basertppayload", 0,
"Base class for RTP Payloaders");
}
@ -265,8 +268,6 @@ gst_basertppayload_init (GstBaseRTPPayload * basertppayload, gpointer g_class)
g_return_if_fail (templ != NULL);
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_basertppayload_sink_getcaps);
gst_pad_set_event_function (basertppayload->sinkpad,
@ -324,25 +325,6 @@ gst_basertppayload_finalize (GObject * 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 *
gst_basertppayload_sink_getcaps (GstPad * pad, GstCaps * filter)
{
@ -376,33 +358,32 @@ gst_basertppayload_sink_getcaps (GstPad * pad, GstCaps * filter)
}
static gboolean
gst_basertppayload_event (GstPad * pad, GstEvent * event)
gst_basertppayload_event_default (GstBaseRTPPayload * basertppayload,
GstEvent * event)
{
GstBaseRTPPayload *basertppayload;
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;
}
gboolean res = FALSE;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_START:
res = gst_pad_event_default (pad, event);
res = gst_pad_event_default (basertppayload->sinkpad, event);
break;
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);
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:
{
GstSegment *segment;
@ -412,14 +393,36 @@ gst_basertppayload_event (GstPad * pad, GstEvent * event)
GST_DEBUG_OBJECT (basertppayload,
"configured SEGMENT %" GST_SEGMENT_FORMAT, segment);
/* fallthrough */
res = gst_pad_event_default (basertppayload->sinkpad, event);
break;
}
default:
res = gst_pad_event_default (pad, event);
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);
return res;
@ -816,8 +819,8 @@ gst_basertppayload_prepare_push (GstBaseRTPPayload * payload,
gst_buffer_get_size (GST_BUFFER (obj)), payload->seqnum, data.rtptime,
GST_TIME_ARGS (data.timestamp));
if (g_atomic_int_compare_and_exchange (&payload->
priv->notified_first_timestamp, 1, 0)) {
if (g_atomic_int_compare_and_exchange (&payload->priv->
notified_first_timestamp, 1, 0)) {
g_object_notify (G_OBJECT (payload), "timestamp");
g_object_notify (G_OBJECT (payload), "seqnum");
}

View file

@ -140,7 +140,7 @@ struct _GstBaseRTPPayloadClass
* the RTP buffers. This function takes ownership of the buffer. */
GstFlowReturn (*handle_buffer) (GstBaseRTPPayload *payload,
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);
/*< private >*/