rtsp-media: Expose latency setting for setting the rtpbin latency

This commit is contained in:
Sebastian Dröge 2015-01-19 13:20:39 +01:00
parent 18d3244fd0
commit 35b2b10cf4
4 changed files with 140 additions and 0 deletions

View file

@ -62,6 +62,7 @@ struct _GstRTSPMediaFactoryPrivate
GstRTSPAddressPool *pool;
GstClockTime rtx_time;
guint latency;
GMutex medias_lock;
GHashTable *medias; /* protected by medias_lock */
@ -75,6 +76,7 @@ struct _GstRTSPMediaFactoryPrivate
#define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_UDP_MCAST | \
GST_RTSP_LOWER_TRANS_TCP
#define DEFAULT_BUFFER_SIZE 0x80000
#define DEFAULT_LATENCY 200
#define DEFAULT_RECORD FALSE
enum
@ -87,6 +89,7 @@ enum
PROP_PROFILES,
PROP_PROTOCOLS,
PROP_BUFFER_SIZE,
PROP_LATENCY,
PROP_RECORD,
PROP_LAST
};
@ -186,6 +189,11 @@ gst_rtsp_media_factory_class_init (GstRTSPMediaFactoryClass * klass)
"The kernel UDP buffer size to use", 0, G_MAXUINT,
DEFAULT_BUFFER_SIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_LATENCY,
g_param_spec_uint ("latency", "Latency",
"Latency used for receiving media in milliseconds", 0, G_MAXUINT,
DEFAULT_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/* FIXME: Should this be a flag property to allow RECORD and PLAY?
* Or just another boolean PLAY property that default to TRUE?
*/
@ -230,6 +238,7 @@ gst_rtsp_media_factory_init (GstRTSPMediaFactory * factory)
priv->profiles = DEFAULT_PROFILES;
priv->protocols = DEFAULT_PROTOCOLS;
priv->buffer_size = DEFAULT_BUFFER_SIZE;
priv->latency = DEFAULT_LATENCY;
g_mutex_init (&priv->lock);
g_mutex_init (&priv->medias_lock);
@ -286,6 +295,9 @@ gst_rtsp_media_factory_get_property (GObject * object, guint propid,
g_value_set_uint (value,
gst_rtsp_media_factory_get_buffer_size (factory));
break;
case PROP_LATENCY:
g_value_set_uint (value, gst_rtsp_media_factory_get_latency (factory));
break;
case PROP_RECORD:
g_value_set_boolean (value, gst_rtsp_media_factory_is_record (factory));
break;
@ -325,6 +337,9 @@ gst_rtsp_media_factory_set_property (GObject * object, guint propid,
gst_rtsp_media_factory_set_buffer_size (factory,
g_value_get_uint (value));
break;
case PROP_LATENCY:
gst_rtsp_media_factory_set_latency (factory, g_value_get_uint (value));
break;
case PROP_RECORD:
gst_rtsp_media_factory_set_record (factory, g_value_get_boolean (value));
break;
@ -892,6 +907,55 @@ gst_rtsp_media_factory_get_retransmission_time (GstRTSPMediaFactory * factory)
return res;
}
/**
* gst_rtsp_media_factory_set_latency:
* @factory: a #GstRTSPMediaFactory
* @latency: latency in milliseconds
*
* Configure the latency used for receiving media
*/
void
gst_rtsp_media_factory_set_latency (GstRTSPMediaFactory * factory,
guint latency)
{
GstRTSPMediaFactoryPrivate *priv;
g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
priv = factory->priv;
GST_DEBUG_OBJECT (factory, "latency %ums", latency);
GST_RTSP_MEDIA_FACTORY_LOCK (factory);
priv->latency = latency;
GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
}
/**
* gst_rtsp_media_factory_get_latency:
* @factory: a #GstRTSPMediaFactory
*
* Get the latency that is used for receiving media
*
* Returns: latency in milliseconds
*/
guint
gst_rtsp_media_factory_get_latency (GstRTSPMediaFactory * factory)
{
GstRTSPMediaFactoryPrivate *priv;
guint res;
g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), 0);
priv = factory->priv;
GST_RTSP_MEDIA_FACTORY_LOCK (factory);
res = priv->latency;
GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
return res;
}
static gboolean
compare_media (gpointer key, GstRTSPMedia * media1, GstRTSPMedia * media2)
{
@ -1155,6 +1219,7 @@ default_configure (GstRTSPMediaFactory * factory, GstRTSPMedia * media)
GstRTSPAddressPool *pool;
GstRTSPPermissions *perms;
GstClockTime rtx_time;
guint latency;
gboolean record;
/* configure the sharedness */
@ -1166,6 +1231,7 @@ default_configure (GstRTSPMediaFactory * factory, GstRTSPMedia * media)
profiles = priv->profiles;
protocols = priv->protocols;
rtx_time = priv->rtx_time;
latency = priv->latency;
record = priv->record;
GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
@ -1176,6 +1242,7 @@ default_configure (GstRTSPMediaFactory * factory, GstRTSPMedia * media)
gst_rtsp_media_set_profiles (media, profiles);
gst_rtsp_media_set_protocols (media, protocols);
gst_rtsp_media_set_retransmission_time (media, rtx_time);
gst_rtsp_media_set_latency (media, latency);
gst_rtsp_media_set_record (media, record);
if ((pool = gst_rtsp_media_factory_get_address_pool (factory))) {

View file

@ -145,6 +145,10 @@ void gst_rtsp_media_factory_set_retransmission_time (GstRTSPMed
GstClockTime time);
GstClockTime gst_rtsp_media_factory_get_retransmission_time (GstRTSPMediaFactory * factory);
void gst_rtsp_media_factory_set_latency (GstRTSPMediaFactory * factory,
guint latency);
guint gst_rtsp_media_factory_get_latency (GstRTSPMediaFactory * factory);
void gst_rtsp_media_factory_set_record (GstRTSPMediaFactory *factory,
gboolean record);
gboolean gst_rtsp_media_factory_is_record (GstRTSPMediaFactory *factory);

View file

@ -137,6 +137,7 @@ struct _GstRTSPMediaPrivate
GList *payloads; /* protected by lock */
GstClockTime rtx_time; /* protected by lock */
guint latency; /* protected by lock */
};
#define DEFAULT_SHARED FALSE
@ -148,6 +149,7 @@ struct _GstRTSPMediaPrivate
#define DEFAULT_EOS_SHUTDOWN FALSE
#define DEFAULT_BUFFER_SIZE 0x80000
#define DEFAULT_TIME_PROVIDER FALSE
#define DEFAULT_LATENCY 200
#define DEFAULT_RECORD FALSE
/* define to dump received RTCP packets */
@ -165,6 +167,7 @@ enum
PROP_BUFFER_SIZE,
PROP_ELEMENT,
PROP_TIME_PROVIDER,
PROP_LATENCY,
PROP_RECORD,
PROP_LAST
};
@ -293,6 +296,11 @@ gst_rtsp_media_class_init (GstRTSPMediaClass * klass)
"Use a NetTimeProvider for clients",
DEFAULT_TIME_PROVIDER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_LATENCY,
g_param_spec_uint ("latency", "Latency",
"Latency used for receiving media in milliseconds", 0, G_MAXUINT,
DEFAULT_BUFFER_SIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_RECORD,
g_param_spec_boolean ("record", "Record",
"If this media pipeline can be used for PLAY or RECORD",
@ -435,6 +443,9 @@ gst_rtsp_media_get_property (GObject * object, guint propid,
case PROP_TIME_PROVIDER:
g_value_set_boolean (value, gst_rtsp_media_is_time_provider (media));
break;
case PROP_LATENCY:
g_value_set_uint (value, gst_rtsp_media_get_latency (media));
break;
case PROP_RECORD:
g_value_set_boolean (value, gst_rtsp_media_is_record (media));
break;
@ -478,6 +489,9 @@ gst_rtsp_media_set_property (GObject * object, guint propid,
case PROP_TIME_PROVIDER:
gst_rtsp_media_use_time_provider (media, g_value_get_boolean (value));
break;
case PROP_LATENCY:
gst_rtsp_media_set_latency (media, g_value_get_uint (value));
break;
case PROP_RECORD:
gst_rtsp_media_set_record (media, g_value_get_boolean (value));
break;
@ -1181,6 +1195,56 @@ gst_rtsp_media_get_retransmission_time (GstRTSPMedia * media)
return res;
}
/**
* gst_rtsp_media_set_latncy:
* @media: a #GstRTSPMedia
* @latency: latency in milliseconds
*
* Configure the latency used for receiving media.
*/
void
gst_rtsp_media_set_latency (GstRTSPMedia * media, guint latency)
{
GstRTSPMediaPrivate *priv;
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
GST_LOG_OBJECT (media, "set latency %ums", latency);
priv = media->priv;
g_mutex_lock (&priv->lock);
priv->latency = latency;
if (priv->rtpbin)
g_object_set (priv->rtpbin, "latency", latency, NULL);
g_mutex_unlock (&priv->lock);
}
/**
* gst_rtsp_media_get_latency:
* @media: a #GstRTSPMedia
*
* Get the latency that is used for receiving media.
*
* Returns: latency in milliseconds
*/
guint
gst_rtsp_media_get_latency (GstRTSPMedia * media)
{
GstRTSPMediaPrivate *priv;
guint res;
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
priv = media->priv;
g_mutex_unlock (&priv->lock);
res = priv->latency;
g_mutex_unlock (&priv->lock);
return res;
}
/**
* gst_rtsp_media_use_time_provider:
* @media: a #GstRTSPMedia
@ -2408,6 +2472,8 @@ default_prepare (GstRTSPMedia * media, GstRTSPThread * thread)
if (priv->rtpbin != NULL) {
gboolean success = TRUE;
g_object_set (priv->rtpbin, "latency", priv->latency, NULL);
if (klass->setup_rtpbin)
success = klass->setup_rtpbin (media, priv->rtpbin);

View file

@ -196,6 +196,9 @@ guint gst_rtsp_media_get_buffer_size (GstRTSPMedia *media);
void gst_rtsp_media_set_retransmission_time (GstRTSPMedia *media, GstClockTime time);
GstClockTime gst_rtsp_media_get_retransmission_time (GstRTSPMedia *media);
void gst_rtsp_media_set_latency (GstRTSPMedia *media, guint latency);
guint gst_rtsp_media_get_latency (GstRTSPMedia *media);
void gst_rtsp_media_use_time_provider (GstRTSPMedia *media, gboolean time_provider);
gboolean gst_rtsp_media_is_time_provider (GstRTSPMedia *media);
GstNetTimeProvider * gst_rtsp_media_get_time_provider (GstRTSPMedia *media,