diff options
author | Wim Taymans <wim.taymans@gmail.com> | 2005-09-15 13:57:56 +0000 |
---|---|---|
committer | Wim Taymans <wim.taymans@gmail.com> | 2005-09-15 13:57:56 +0000 |
commit | fc158bc3c2739eabfb092f7a45f6656ac8c96e25 (patch) | |
tree | 199f9ea3d2fddfcbc8315e95d6fe17c2e9936cd5 /gst/rtp/gstrtpamrpay.c | |
parent | c7468729e9e05fa3cbcf6ee1fbbd578c516e2200 (diff) |
Updates to payloader/depayloaders, make payloaders use the base classes.
Original commit message from CVS:
Updates to payloader/depayloaders, make payloaders use
the base classes.
Updated README with suggested RTP caps and how to convert
to/from SDP.
Added config descriptor in mp4v payloader.
Diffstat (limited to 'gst/rtp/gstrtpamrpay.c')
-rw-r--r-- | gst/rtp/gstrtpamrpay.c | 200 |
1 files changed, 36 insertions, 164 deletions
diff --git a/gst/rtp/gstrtpamrpay.c b/gst/rtp/gstrtpamrpay.c index a60648d7..9b867cfe 100644 --- a/gst/rtp/gstrtpamrpay.c +++ b/gst/rtp/gstrtpamrpay.c @@ -33,29 +33,10 @@ static GstElementDetails gst_rtp_amrenc_details = { "RTP packet parser", "Codec/Parser/Network", - "Encode AMR audio into RTP packets", + "Encode AMR audio into RTP packets (RFC 3267)", "Wim Taymans <wim@fluendo.com>" }; -/* RtpAMREnc signals and args */ -enum -{ - /* FILL ME */ - LAST_SIGNAL -}; - -#define DEFAULT_MTU 1024 -#define DEFAULT_PT 96 -#define DEFAULT_SSRC 0 - -enum -{ - PROP_0, - PROP_MTU, - PROP_PT, - PROP_SSRC -}; - static GstStaticPadTemplate gst_rtpamrenc_sink_template = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, @@ -68,34 +49,31 @@ GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS ("application/x-rtp, " + "media = (string) \"audio\", " + "payload = (int) [ 96, 255 ], " + "clock_rate = (int) 8000, " + "encoding_name = (string) \"AMR\", " + "encoding_params = (string) \"1\", " "octet-align = (boolean) TRUE, " "crc = (boolean) FALSE, " "robust-sorting = (boolean) FALSE, " "interleaving = (boolean) FALSE, " - "channels = (int) 1, " - "rate = (int) 8000, " "mode-set = (int) [ 0, 7 ], " "mode-change-period = (int) [ 1, MAX ], " "mode-change-neighbor = (boolean) { TRUE, FALSE }, " "maxptime = (int) [ 20, MAX ], " "ptime = (int) [ 20, MAX ]") ); - static void gst_rtpamrenc_class_init (GstRtpAMREncClass * klass); static void gst_rtpamrenc_base_init (GstRtpAMREncClass * klass); static void gst_rtpamrenc_init (GstRtpAMREnc * rtpamrenc); -static GstFlowReturn gst_rtpamrenc_chain (GstPad * pad, GstBuffer * buffer); - -static void gst_rtpamrenc_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec); -static void gst_rtpamrenc_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec); +static gboolean gst_rtpamrenc_setcaps (GstBaseRTPPayload * basepayload, + GstCaps * caps); +static GstFlowReturn gst_rtpamrenc_handle_buffer (GstBaseRTPPayload * pad, + GstBuffer * buffer); -static GstStateChangeReturn gst_rtpamrenc_change_state (GstElement * element, - GstStateChange transition); - -static GstElementClass *parent_class = NULL; +static GstBaseRTPPayloadClass *parent_class = NULL; static GType gst_rtpamrenc_get_type (void) @@ -116,7 +94,7 @@ gst_rtpamrenc_get_type (void) }; rtpamrenc_type = - g_type_register_static (GST_TYPE_ELEMENT, "GstRtpAMREnc", + g_type_register_static (GST_TYPE_BASE_RTP_PAYLOAD, "GstRtpAMREnc", &rtpamrenc_info, 0); } return rtpamrenc_type; @@ -140,64 +118,44 @@ gst_rtpamrenc_class_init (GstRtpAMREncClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; + GstBaseRTPPayloadClass *gstbasertppayload_class; gobject_class = (GObjectClass *) klass; gstelement_class = (GstElementClass *) klass; + gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass; + + parent_class = g_type_class_ref (GST_TYPE_BASE_RTP_PAYLOAD); - parent_class = g_type_class_ref (GST_TYPE_ELEMENT); - - gobject_class->set_property = gst_rtpamrenc_set_property; - gobject_class->get_property = gst_rtpamrenc_get_property; - - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MTU, - g_param_spec_uint ("mtu", "MTU", - "Maximum size of one packet", - 28, G_MAXUINT, DEFAULT_MTU, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PT, - g_param_spec_uint ("pt", "payload type", - "The payload type of the packets", - 0, 0x80, DEFAULT_PT, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SSRC, - g_param_spec_uint ("ssrc", "SSRC", - "The SSRC of the packets", - 0, G_MAXUINT, DEFAULT_SSRC, G_PARAM_READWRITE)); - - gstelement_class->change_state = gst_rtpamrenc_change_state; + gstbasertppayload_class->set_caps = gst_rtpamrenc_setcaps; + gstbasertppayload_class->handle_buffer = gst_rtpamrenc_handle_buffer; } static void gst_rtpamrenc_init (GstRtpAMREnc * rtpamrenc) { - GstCaps *caps; +} - rtpamrenc->srcpad = - gst_pad_new_from_template (gst_static_pad_template_get - (&gst_rtpamrenc_src_template), "src"); +static gboolean +gst_rtpamrenc_setcaps (GstBaseRTPPayload * basepayload, GstCaps * caps) +{ + GstRtpAMREnc *rtpamrenc; - caps = gst_caps_new_simple ("application/x-rtp", + rtpamrenc = GST_RTP_AMR_ENC (basepayload); + + gst_basertppayload_set_options (basepayload, "audio", TRUE, "AMR", 8000); + gst_basertppayload_set_outcaps (basepayload, + "encoding_params", G_TYPE_STRING, "1", "octet-align", G_TYPE_BOOLEAN, TRUE, "crc", G_TYPE_BOOLEAN, FALSE, "robust-sorting", G_TYPE_BOOLEAN, FALSE, - "interleaving", G_TYPE_BOOLEAN, FALSE, - "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL); - - gst_pad_set_caps (rtpamrenc->srcpad, caps); - gst_caps_unref (caps); - gst_element_add_pad (GST_ELEMENT (rtpamrenc), rtpamrenc->srcpad); - - rtpamrenc->sinkpad = - gst_pad_new_from_template (gst_static_pad_template_get - (&gst_rtpamrenc_sink_template), "sink"); - gst_pad_set_chain_function (rtpamrenc->sinkpad, gst_rtpamrenc_chain); - gst_element_add_pad (GST_ELEMENT (rtpamrenc), rtpamrenc->sinkpad); - - rtpamrenc->mtu = DEFAULT_MTU; - rtpamrenc->pt = DEFAULT_PT; - rtpamrenc->ssrc = DEFAULT_SSRC; + "interleaving", G_TYPE_BOOLEAN, FALSE, NULL); + + return TRUE; } static GstFlowReturn -gst_rtpamrenc_chain (GstPad * pad, GstBuffer * buffer) +gst_rtpamrenc_handle_buffer (GstBaseRTPPayload * basepayload, + GstBuffer * buffer) { GstRtpAMREnc *rtpamrenc; GstFlowReturn ret; @@ -206,7 +164,7 @@ gst_rtpamrenc_chain (GstPad * pad, GstBuffer * buffer) guint8 *payload, *data; GstClockTime timestamp; - rtpamrenc = GST_RTP_AMR_ENC (gst_pad_get_parent (pad)); + rtpamrenc = GST_RTP_AMR_ENC (basepayload); size = GST_BUFFER_SIZE (buffer); timestamp = GST_BUFFER_TIMESTAMP (buffer); @@ -221,12 +179,7 @@ gst_rtpamrenc_chain (GstPad * pad, GstBuffer * buffer) outbuf = gst_rtpbuffer_new_allocate (payload_len, 0, 0); /* FIXME, assert for now */ - g_assert (GST_BUFFER_SIZE (outbuf) < rtpamrenc->mtu); - - gst_rtpbuffer_set_payload_type (outbuf, rtpamrenc->pt); - gst_rtpbuffer_set_ssrc (outbuf, rtpamrenc->ssrc); - gst_rtpbuffer_set_seq (outbuf, rtpamrenc->seqnum++); - gst_rtpbuffer_set_timestamp (outbuf, timestamp * 8000 / GST_SECOND); + g_assert (GST_BUFFER_SIZE (outbuf) < GST_BASE_RTP_PAYLOAD_MTU (rtpamrenc)); /* copy timestamp */ GST_BUFFER_TIMESTAMP (outbuf) = timestamp; @@ -256,89 +209,8 @@ gst_rtpamrenc_chain (GstPad * pad, GstBuffer * buffer) gst_buffer_unref (buffer); - gst_buffer_set_caps (outbuf, GST_PAD_CAPS (rtpamrenc->srcpad)); - - ret = gst_pad_push (rtpamrenc->srcpad, outbuf); - - gst_object_unref (rtpamrenc); - - return ret; -} - -static void -gst_rtpamrenc_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) -{ - GstRtpAMREnc *rtpamrenc; + ret = gst_basertppayload_push (basepayload, outbuf); - rtpamrenc = GST_RTP_AMR_ENC (object); - - switch (prop_id) { - case PROP_MTU: - rtpamrenc->mtu = g_value_get_uint (value); - break; - case PROP_PT: - rtpamrenc->pt = g_value_get_uint (value); - break; - case PROP_SSRC: - rtpamrenc->ssrc = g_value_get_uint (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gst_rtpamrenc_get_property (GObject * object, guint prop_id, GValue * value, - GParamSpec * pspec) -{ - GstRtpAMREnc *rtpamrenc; - - rtpamrenc = GST_RTP_AMR_ENC (object); - - switch (prop_id) { - case PROP_MTU: - g_value_set_uint (value, rtpamrenc->mtu); - break; - case PROP_PT: - g_value_set_uint (value, rtpamrenc->pt); - break; - case PROP_SSRC: - g_value_set_uint (value, rtpamrenc->ssrc); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GstStateChangeReturn -gst_rtpamrenc_change_state (GstElement * element, GstStateChange transition) -{ - GstRtpAMREnc *rtpamrenc; - GstStateChangeReturn ret; - - rtpamrenc = GST_RTP_AMR_ENC (element); - - switch (transition) { - case GST_STATE_CHANGE_NULL_TO_READY: - break; - case GST_STATE_CHANGE_READY_TO_PAUSED: - rtpamrenc->seqnum = 0; - break; - default: - break; - } - - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); - - switch (transition) { - case GST_STATE_CHANGE_READY_TO_NULL: - break; - default: - break; - } return ret; } |