rtsp: fix MTU setting

Fix setting of the MTU. There is no need for a vmethod.
This commit is contained in:
Wim Taymans 2012-10-26 12:04:02 +02:00
parent 0c8c9e3282
commit 6b7ff45ca6
7 changed files with 104 additions and 41 deletions

View file

@ -912,7 +912,7 @@ handle_blocksize (GstRTSPMedia * media, GstRTSPMessage * request)
} else { } else {
if (blocksize > G_MAXUINT) if (blocksize > G_MAXUINT)
blocksize = G_MAXUINT; blocksize = G_MAXUINT;
gst_rtsp_media_handle_mtu (media, (guint) blocksize); gst_rtsp_media_set_mtu (media, blocksize);
} }
} }

View file

@ -42,6 +42,7 @@ typedef struct _GstRTSPMediaMappingClass GstRTSPMediaMappingClass;
/** /**
* GstRTSPMediaMapping: * GstRTSPMediaMapping:
* @parent: parent GObject
* @mappings: the mountpoint to media mappings * @mappings: the mountpoint to media mappings
* *
* Creates a #GstRTSPMediaFactory object for a given url. * Creates a #GstRTSPMediaFactory object for a given url.
@ -54,6 +55,7 @@ struct _GstRTSPMediaMapping {
/** /**
* GstRTSPMediaMappingClass: * GstRTSPMediaMappingClass:
* @parent_class: parent GObject class
* @find_factory: Create or return a previously cached #GstRTSPMediaFactory object * @find_factory: Create or return a previously cached #GstRTSPMediaFactory object
* for the given url. the default implementation will use the mappings * for the given url. the default implementation will use the mappings
* added with gst_rtsp_media_mapping_add_factory(). * added with gst_rtsp_media_mapping_add_factory().

View file

@ -32,6 +32,7 @@
#define DEFAULT_EOS_SHUTDOWN FALSE #define DEFAULT_EOS_SHUTDOWN FALSE
#define DEFAULT_BUFFER_SIZE 0x80000 #define DEFAULT_BUFFER_SIZE 0x80000
#define DEFAULT_MULTICAST_GROUP "224.2.0.1" #define DEFAULT_MULTICAST_GROUP "224.2.0.1"
#define DEFAULT_MTU 0
/* define to dump received RTCP packets */ /* define to dump received RTCP packets */
#undef DUMP_STATS #undef DUMP_STATS
@ -45,6 +46,7 @@ enum
PROP_EOS_SHUTDOWN, PROP_EOS_SHUTDOWN,
PROP_BUFFER_SIZE, PROP_BUFFER_SIZE,
PROP_MULTICAST_GROUP, PROP_MULTICAST_GROUP,
PROP_MTU,
PROP_LAST PROP_LAST
}; };
@ -71,7 +73,6 @@ static gboolean default_handle_message (GstRTSPMedia * media,
static void finish_unprepare (GstRTSPMedia * media); static void finish_unprepare (GstRTSPMedia * media);
static gboolean default_unprepare (GstRTSPMedia * media); static gboolean default_unprepare (GstRTSPMedia * media);
static void unlock_streams (GstRTSPMedia * media); static void unlock_streams (GstRTSPMedia * media);
static void default_handle_mtu (GstRTSPMedia * media, guint mtu);
static guint gst_rtsp_media_signals[SIGNAL_LAST] = { 0 }; static guint gst_rtsp_media_signals[SIGNAL_LAST] = { 0 };
@ -118,6 +119,12 @@ gst_rtsp_media_class_init (GstRTSPMediaClass * klass)
"The Multicast group to send media to", "The Multicast group to send media to",
DEFAULT_MULTICAST_GROUP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_MULTICAST_GROUP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_MTU,
g_param_spec_uint ("mtu", "MTU",
"The MTU for the payloaders (0 = default)",
0, G_MAXUINT, DEFAULT_MTU,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_rtsp_media_signals[SIGNAL_PREPARED] = gst_rtsp_media_signals[SIGNAL_PREPARED] =
g_signal_new ("prepared", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, g_signal_new ("prepared", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstRTSPMediaClass, prepared), NULL, NULL, G_STRUCT_OFFSET (GstRTSPMediaClass, prepared), NULL, NULL,
@ -142,7 +149,6 @@ gst_rtsp_media_class_init (GstRTSPMediaClass * klass)
klass->handle_message = default_handle_message; klass->handle_message = default_handle_message;
klass->unprepare = default_unprepare; klass->unprepare = default_unprepare;
klass->handle_mtu = default_handle_mtu;
} }
static void static void
@ -211,6 +217,9 @@ gst_rtsp_media_get_property (GObject * object, guint propid,
case PROP_MULTICAST_GROUP: case PROP_MULTICAST_GROUP:
g_value_take_string (value, gst_rtsp_media_get_multicast_group (media)); g_value_take_string (value, gst_rtsp_media_get_multicast_group (media));
break; break;
case PROP_MTU:
g_value_set_uint (value, gst_rtsp_media_get_mtu (media));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
} }
@ -241,6 +250,9 @@ gst_rtsp_media_set_property (GObject * object, guint propid,
case PROP_MULTICAST_GROUP: case PROP_MULTICAST_GROUP:
gst_rtsp_media_set_multicast_group (media, g_value_get_string (value)); gst_rtsp_media_set_multicast_group (media, g_value_get_string (value));
break; break;
case PROP_MTU:
gst_rtsp_media_set_mtu (media, g_value_get_uint (value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
} }
@ -570,6 +582,46 @@ gst_rtsp_media_get_auth (GstRTSPMedia * media)
return result; return result;
} }
/**
* gst_rtsp_media_set_mtu:
* @media: a #GstRTSPMedia
* @mtu: a new MTU
*
* Set maximum size of one RTP packet on the payloaders.
* The @mtu will be set on all streams.
*/
void
gst_rtsp_media_set_mtu (GstRTSPMedia * media, guint mtu)
{
gint i;
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
media->mtu = mtu;
for (i = 0; i < media->streams->len; i++) {
GstRTSPStream *stream;
GST_INFO ("Setting mtu %u for stream %d", mtu, i);
stream = g_ptr_array_index (media->streams, i);
gst_rtsp_stream_set_mtu (stream, mtu);
}
}
/**
* gst_rtsp_media_get_mtu:
* @media: a #GstRTSPMedia
*
* Get the configured MTU.
*/
guint
gst_rtsp_media_get_mtu (GstRTSPMedia * media)
{
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), 0);
return media->mtu;
}
/** /**
* gst_rtsp_media_collect_streams: * gst_rtsp_media_collect_streams:
* @media: a #GstRTSPMedia * @media: a #GstRTSPMedia
@ -663,6 +715,8 @@ gst_rtsp_media_create_stream (GstRTSPMedia * media, GstElement * payloader,
g_free (name); g_free (name);
stream = gst_rtsp_stream_new (idx, payloader, srcpad); stream = gst_rtsp_stream_new (idx, payloader, srcpad);
if (media->mtu)
gst_rtsp_stream_set_mtu (stream, media->mtu);
g_ptr_array_add (media->streams, stream); g_ptr_array_add (media->streams, stream);
@ -1394,37 +1448,3 @@ gst_rtsp_media_set_state (GstRTSPMedia * media, GstState state,
return TRUE; return TRUE;
} }
static void
default_handle_mtu (GstRTSPMedia * media, guint mtu)
{
gint i;
for (i = 0; i < media->streams->len; i++) {
GstRTSPStream *stream;
GST_INFO ("Setting mtu %d for stream %d", mtu, i);
stream = g_ptr_array_index (media->streams, i);
g_object_set (G_OBJECT (stream->payloader), "mtu", mtu, NULL);
}
}
/**
* gst_rtsp_media_handle_mtu:
* @media: a #GstRTSPMedia
* @mtu: the mtu
*
* Set maximum size of one RTP packet on the payloaders.
*/
void
gst_rtsp_media_handle_mtu (GstRTSPMedia * media, guint mtu)
{
GstRTSPMediaClass *klass;
klass = GST_RTSP_MEDIA_GET_CLASS (media);
if (klass->handle_mtu)
klass->handle_mtu (media, mtu);
}

View file

@ -106,6 +106,7 @@ struct _GstRTSPMedia {
guint buffer_size; guint buffer_size;
GstRTSPAuth *auth; GstRTSPAuth *auth;
gchar *multicast_group; gchar *multicast_group;
guint mtu;
GstElement *element; GstElement *element;
GPtrArray *streams; GPtrArray *streams;
@ -155,7 +156,6 @@ struct _GstRTSPMediaClass {
/* vmethods */ /* vmethods */
gboolean (*handle_message) (GstRTSPMedia *media, GstMessage *message); gboolean (*handle_message) (GstRTSPMedia *media, GstMessage *message);
gboolean (*unprepare) (GstRTSPMedia *media); gboolean (*unprepare) (GstRTSPMedia *media);
void (*handle_mtu) (GstRTSPMedia *media, guint mtu);
/* signals */ /* signals */
gboolean (*prepared) (GstRTSPMedia *media); gboolean (*prepared) (GstRTSPMedia *media);
@ -190,6 +190,9 @@ guint gst_rtsp_media_get_buffer_size (GstRTSPMedia *media);
void gst_rtsp_media_set_multicast_group (GstRTSPMedia *media, const gchar * mc); void gst_rtsp_media_set_multicast_group (GstRTSPMedia *media, const gchar * mc);
gchar * gst_rtsp_media_get_multicast_group (GstRTSPMedia *media); gchar * gst_rtsp_media_get_multicast_group (GstRTSPMedia *media);
void gst_rtsp_media_set_mtu (GstRTSPMedia *media, guint mtu);
guint gst_rtsp_media_get_mtu (GstRTSPMedia *media);
/* prepare the media for playback */ /* prepare the media for playback */
gboolean gst_rtsp_media_prepare (GstRTSPMedia *media); gboolean gst_rtsp_media_prepare (GstRTSPMedia *media);
@ -212,8 +215,6 @@ gchar * gst_rtsp_media_get_range_string (GstRTSPMedia *media, gboo
gboolean gst_rtsp_media_set_state (GstRTSPMedia *media, GstState state, gboolean gst_rtsp_media_set_state (GstRTSPMedia *media, GstState state,
GPtrArray *transports); GPtrArray *transports);
void gst_rtsp_media_handle_mtu (GstRTSPMedia *media, guint mtu);
G_END_DECLS G_END_DECLS
#endif /* __GST_RTSP_MEDIA_H__ */ #endif /* __GST_RTSP_MEDIA_H__ */

View file

@ -120,7 +120,9 @@ GstRTSPMediaMapping * gst_rtsp_server_get_media_mapping (GstRTSPServer *serve
void gst_rtsp_server_set_auth (GstRTSPServer *server, GstRTSPAuth *auth); void gst_rtsp_server_set_auth (GstRTSPServer *server, GstRTSPAuth *auth);
GstRTSPAuth * gst_rtsp_server_get_auth (GstRTSPServer *server); GstRTSPAuth * gst_rtsp_server_get_auth (GstRTSPServer *server);
gboolean gst_rtsp_server_transfer_connection (GstRTSPServer * server, GSocket *socket, const gchar * ip, gint port, const gchar *initial_buffer); gboolean gst_rtsp_server_transfer_connection (GstRTSPServer * server, GSocket *socket,
const gchar * ip, gint port,
const gchar *initial_buffer);
gboolean gst_rtsp_server_io_func (GSocket *socket, GIOCondition condition, gboolean gst_rtsp_server_io_func (GSocket *socket, GIOCondition condition,
GstRTSPServer *server); GstRTSPServer *server);

View file

@ -123,6 +123,41 @@ gst_rtsp_stream_new (guint idx, GstElement * payloader, GstPad * srcpad)
return stream; return stream;
} }
/**
* gst_rtsp_stream_set_mtu:
* @stream: a #GstRTSPStream
* @mtu: a new MTU
*
* Configure the mtu in the payloader of @stream to @mtu.
*/
void
gst_rtsp_stream_set_mtu (GstRTSPStream * stream, guint mtu)
{
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
g_object_set (G_OBJECT (stream->payloader), "mtu", mtu, NULL);
}
/**
* gst_rtsp_stream_get_mtu:
* @stream: a #GstRTSPStream
*
* Get the configured MTU in the payloader of @stream.
*
* Returns: the MTU of the payloader.
*/
guint
gst_rtsp_stream_get_mtu (GstRTSPStream * stream)
{
guint mtu;
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), 0);
g_object_get (G_OBJECT (stream->payloader), "mtu", &mtu, NULL);
return mtu;
}
static gboolean static gboolean
alloc_ports (GstRTSPStream * stream) alloc_ports (GstRTSPStream * stream)
{ {

View file

@ -119,6 +119,9 @@ GType gst_rtsp_stream_get_type (void);
GstRTSPStream * gst_rtsp_stream_new (guint idx, GstElement *payloader, GstRTSPStream * gst_rtsp_stream_new (guint idx, GstElement *payloader,
GstPad *srcpad); GstPad *srcpad);
void gst_rtsp_stream_set_mtu (GstRTSPStream * stream, guint mtu);
guint gst_rtsp_stream_get_mtu (GstRTSPStream * stream);
gboolean gst_rtsp_stream_join_bin (GstRTSPStream * stream, gboolean gst_rtsp_stream_join_bin (GstRTSPStream * stream,
GstBin *bin, GstElement *rtpbin); GstBin *bin, GstElement *rtpbin);
gboolean gst_rtsp_stream_leave_bin (GstRTSPStream * stream, gboolean gst_rtsp_stream_leave_bin (GstRTSPStream * stream,