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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/728>
This commit is contained in:
Stian Selnes 2017-11-17 15:11:41 +01:00 committed by Tim-Philipp Müller
parent 543b7e5024
commit 29d5936749
3 changed files with 56 additions and 11 deletions

View file

@ -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"

View file

@ -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;

View file

@ -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;
};