From 29d5936749e87302830e24696a0d678fa9e1aa4c Mon Sep 17 00:00:00 2001 From: Stian Selnes Date: Fri, 17 Nov 2017 15:11:41 +0100 Subject: [PATCH] rtpvp8pay: Add picture-id-offset property Add property to set the initial value for picture-id. RFC7741 says that picture-id MAY be initialized to a random value, thus it's also valid to simply set it to a fixed initial value. A fixed value is very useful for testing. Default behavior is not changed. Part-of: --- docs/gst_plugins_cache.json | 14 ++++++++++ gst/rtp/gstrtpvp8pay.c | 52 +++++++++++++++++++++++++++++-------- gst/rtp/gstrtpvp8pay.h | 1 + 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/docs/gst_plugins_cache.json b/docs/gst_plugins_cache.json index 87294c8356..cc6641a6af 100644 --- a/docs/gst_plugins_cache.json +++ b/docs/gst_plugins_cache.json @@ -15764,6 +15764,20 @@ "readable": true, "type": "GstVP8RTPPayMode", "writable": true + }, + "picture-id-offset": { + "blurb": "Offset to add to the initial picture-id (-1 = random)", + "conditionally-available": false, + "construct": false, + "construct-only": false, + "controllable": false, + "default": "-1", + "max": "32767", + "min": "-1", + "mutable": "null", + "readable": true, + "type": "gint", + "writable": true } }, "rank": "marginal" diff --git a/gst/rtp/gstrtpvp8pay.c b/gst/rtp/gstrtpvp8pay.c index 7012e3ae53..880ee775c7 100644 --- a/gst/rtp/gstrtpvp8pay.c +++ b/gst/rtp/gstrtpvp8pay.c @@ -39,11 +39,13 @@ GST_DEBUG_CATEGORY_STATIC (gst_rtp_vp8_pay_debug); #define GST_CAT_DEFAULT gst_rtp_vp8_pay_debug #define DEFAULT_PICTURE_ID_MODE VP8_PAY_NO_PICTURE_ID +#define DEFAULT_PICTURE_ID_OFFSET (-1) enum { PROP_0, - PROP_PICTURE_ID_MODE + PROP_PICTURE_ID_MODE, + PROP_PICTURE_ID_OFFSET }; #define GST_TYPE_RTP_VP8_PAY_PICTURE_ID_MODE (gst_rtp_vp8_pay_picture_id_mode_get_type()) @@ -93,7 +95,7 @@ GST_STATIC_PAD_TEMPLATE ("sink", GST_STATIC_CAPS ("video/x-vp8")); static gint -picture_id_bitsize_from_mode (PictureIDMode mode) +picture_id_field_len (PictureIDMode mode) { if (VP8_PAY_NO_PICTURE_ID == mode) return 0; @@ -105,20 +107,28 @@ picture_id_bitsize_from_mode (PictureIDMode mode) static void gst_rtp_vp8_pay_picture_id_reset (GstRtpVP8Pay * obj) { - gint picture_id_bitsize = picture_id_bitsize_from_mode (obj->picture_id_mode); - if (0 == picture_id_bitsize) - return; - obj->picture_id = g_random_int_range (0, 1 << picture_id_bitsize); + gint nbits; + + if (obj->picture_id_offset == -1) + obj->picture_id = g_random_int (); + else + obj->picture_id = obj->picture_id_offset; + + nbits = picture_id_field_len (obj->picture_id_mode); + obj->picture_id &= (1 << nbits) - 1; } static void gst_rtp_vp8_pay_picture_id_increment (GstRtpVP8Pay * obj) { - gint picture_id_bitsize = picture_id_bitsize_from_mode (obj->picture_id_mode); - if (0 == picture_id_bitsize) - return; - ++obj->picture_id; - obj->picture_id &= (1 << picture_id_bitsize) - 1; + gint nbits; + + if (obj->picture_id_mode == VP8_PAY_NO_PICTURE_ID) + return; + + nbits = picture_id_field_len (obj->picture_id_mode); + obj->picture_id++; + obj->picture_id &= (1 << nbits) - 1; } static void @@ -126,6 +136,7 @@ gst_rtp_vp8_pay_init (GstRtpVP8Pay * obj) { obj->picture_id_mode = DEFAULT_PICTURE_ID_MODE; gst_rtp_vp8_pay_picture_id_reset (obj); + obj->picture_id_offset = DEFAULT_PICTURE_ID_OFFSET; } static void @@ -144,6 +155,18 @@ gst_rtp_vp8_pay_class_init (GstRtpVP8PayClass * gst_rtp_vp8_pay_class) "The picture ID mode for payloading", GST_TYPE_RTP_VP8_PAY_PICTURE_ID_MODE, DEFAULT_PICTURE_ID_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + /** + * rtpvp8pay:picture-id-offset: + * + * Offset to add to the initial picture-id (-1 = random) + * + * Since: 1.20 + */ + g_object_class_install_property (gobject_class, PROP_PICTURE_ID_OFFSET, + g_param_spec_int ("picture-id-offset", "Picture ID offset", + "Offset to add to the initial picture-id (-1 = random)", + -1, 0x7FFF, DEFAULT_PICTURE_ID_OFFSET, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); gst_element_class_add_static_pad_template (element_class, &gst_rtp_vp8_pay_sink_template); @@ -175,6 +198,10 @@ gst_rtp_vp8_pay_set_property (GObject * object, rtpvp8pay->picture_id_mode = g_value_get_enum (value); gst_rtp_vp8_pay_picture_id_reset (rtpvp8pay); break; + case PROP_PICTURE_ID_OFFSET: + rtpvp8pay->picture_id_offset = g_value_get_int (value); + gst_rtp_vp8_pay_picture_id_reset (rtpvp8pay); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -191,6 +218,9 @@ gst_rtp_vp8_pay_get_property (GObject * object, case PROP_PICTURE_ID_MODE: g_value_set_enum (value, rtpvp8pay->picture_id_mode); break; + case PROP_PICTURE_ID_OFFSET: + g_value_set_int (value, rtpvp8pay->picture_id_offset); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; diff --git a/gst/rtp/gstrtpvp8pay.h b/gst/rtp/gstrtpvp8pay.h index 2472060671..2440a63482 100644 --- a/gst/rtp/gstrtpvp8pay.h +++ b/gst/rtp/gstrtpvp8pay.h @@ -62,6 +62,7 @@ struct _GstRtpVP8Pay guint partition_offset[10]; guint partition_size[9]; PictureIDMode picture_id_mode; + gint picture_id_offset; guint16 picture_id; };