rtsp: only create transport when needed

Only create the StreamTransport when configured.
This commit is contained in:
Wim Taymans 2012-10-28 00:23:57 +02:00
parent 66a29c7ed9
commit 543aa383e7
5 changed files with 56 additions and 38 deletions

View file

@ -537,12 +537,13 @@ unlink_session_transports (GstRTSPClient * client, GstRTSPSession * session,
GstRTSPStreamTransport *trans; GstRTSPStreamTransport *trans;
GstRTSPTransport *tr; GstRTSPTransport *tr;
/* get the stream as configured in the session */
trans = gst_rtsp_session_media_get_transport (media, i);
/* get the transport, if there is no transport configured, skip this stream */ /* get the transport, if there is no transport configured, skip this stream */
if (!(tr = trans->transport)) trans = gst_rtsp_session_media_get_transport (media, i);
if (trans == NULL)
continue; continue;
tr = trans->transport;
if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) { if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
/* for TCP, unlink the stream from the TCP connection of the client */ /* for TCP, unlink the stream from the TCP connection of the client */
unlink_transport (client, session, trans); unlink_transport (client, session, trans);
@ -815,13 +816,13 @@ handle_play_request (GstRTSPClient * client, GstRTSPClientState * state)
gchar *uristr; gchar *uristr;
guint rtptime, seq; guint rtptime, seq;
/* get the stream as configured in the session */
trans = gst_rtsp_session_media_get_transport (media, i);
/* get the transport, if there is no transport configured, skip this stream */ /* get the transport, if there is no transport configured, skip this stream */
if (!(tr = trans->transport)) { trans = gst_rtsp_session_media_get_transport (media, i);
if (trans == NULL) {
GST_INFO ("stream %d is not configured", i); GST_INFO ("stream %d is not configured", i);
continue; continue;
} }
tr = trans->transport;
if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) { if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
/* for TCP, link the stream to the TCP connection of the client */ /* for TCP, link the stream to the TCP connection of the client */
@ -1153,8 +1154,7 @@ handle_setup_request (GstRTSPClient * client, GstRTSPClientState * state)
configure_client_transport (client, state, ct); configure_client_transport (client, state, ct);
/* set in the session media transport */ /* set in the session media transport */
trans = gst_rtsp_session_media_get_transport (sessmedia, streamid); trans = gst_rtsp_session_media_set_transport (sessmedia, stream, ct);
gst_rtsp_stream_transport_set_transport (trans, ct);
/* configure keepalive for this transport */ /* configure keepalive for this transport */
gst_rtsp_stream_transport_set_keepalive (trans, gst_rtsp_stream_transport_set_keepalive (trans,

View file

@ -116,12 +116,42 @@ gst_rtsp_session_media_new (const GstRTSPUrl * url, GstRTSPMedia * media)
return result; return result;
} }
/**
* gst_rtsp_session_media_set_transport:
* @media: a #GstRTSPSessionMedia
* @stream: a #GstRTSPStream
* @tr: a #GstRTSPTransport
*
* Configure the transport for @stream to @tr in @media.
*
* Returns: the new or updated #GstRTSPStreamTransport for @stream.
*/
GstRTSPStreamTransport *
gst_rtsp_session_media_set_transport (GstRTSPSessionMedia * media,
GstRTSPStream * stream, GstRTSPTransport * tr)
{
GstRTSPStreamTransport *result;
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), NULL);
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
g_return_val_if_fail (stream->idx < media->transports->len, NULL);
result = g_ptr_array_index (media->transports, stream->idx);
if (result == NULL) {
result = gst_rtsp_stream_transport_new (stream, tr);
g_ptr_array_index (media->transports, stream->idx) = result;
} else {
gst_rtsp_stream_transport_set_transport (result, tr);
}
return result;
}
/** /**
* gst_rtsp_session_media_get_transport: * gst_rtsp_session_media_get_transport:
* @media: a #GstRTSPSessionMedia * @media: a #GstRTSPSessionMedia
* @idx: the stream index * @idx: the stream index
* *
* Get a previously created or create a new #GstRTSPStreamTransport at @idx. * Get a previously created #GstRTSPStreamTransport for the stream at @idx.
* *
* Returns: a #GstRTSPStreamTransport that is valid until the session of @media * Returns: a #GstRTSPStreamTransport that is valid until the session of @media
* is unreffed. * is unreffed.
@ -132,30 +162,11 @@ gst_rtsp_session_media_get_transport (GstRTSPSessionMedia * media, guint idx)
GstRTSPStreamTransport *result; GstRTSPStreamTransport *result;
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), NULL); g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), NULL);
g_return_val_if_fail (media->media != NULL, NULL); g_return_val_if_fail (idx < media->transports->len, NULL);
if (idx >= media->transports->len)
return NULL;
result = g_ptr_array_index (media->transports, idx); result = g_ptr_array_index (media->transports, idx);
if (result == NULL) {
GstRTSPStream *stream;
stream = gst_rtsp_media_get_stream (media->media, idx);
if (stream == NULL)
goto no_media;
result = gst_rtsp_stream_transport_new (stream);
g_ptr_array_index (media->transports, idx) = result;
}
return result; return result;
/* ERRORS */
no_media:
{
return NULL;
}
} }
/** /**

View file

@ -75,6 +75,9 @@ gboolean gst_rtsp_session_media_set_state (GstRTSPSessionMe
GstState state); GstState state);
/* get stream transport config */ /* get stream transport config */
GstRTSPStreamTransport * gst_rtsp_session_media_set_transport (GstRTSPSessionMedia *media,
GstRTSPStream *stream,
GstRTSPTransport *tr);
GstRTSPStreamTransport * gst_rtsp_session_media_get_transport (GstRTSPSessionMedia *media, GstRTSPStreamTransport * gst_rtsp_session_media_get_transport (GstRTSPSessionMedia *media,
guint idx); guint idx);

View file

@ -82,21 +82,24 @@ gst_rtsp_stream_transport_finalize (GObject * obj)
/** /**
* gst_rtsp_stream_transport_new: * gst_rtsp_stream_transport_new:
* @stream: a #GstRTSPStream * @stream: a #GstRTSPStream
* @tr: (transfer full): a GstRTSPTransport
* *
* Create a new #GstRTSPStreamTransport that can be used to manage * Create a new #GstRTSPStreamTransport that can be used to manage
* @stream. * @stream with transport @tr.
* *
* Returns: a new #GstRTSPStreamTransport * Returns: a new #GstRTSPStreamTransport
*/ */
GstRTSPStreamTransport * GstRTSPStreamTransport *
gst_rtsp_stream_transport_new (GstRTSPStream * stream) gst_rtsp_stream_transport_new (GstRTSPStream * stream, GstRTSPTransport * tr)
{ {
GstRTSPStreamTransport *trans; GstRTSPStreamTransport *trans;
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL); g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
g_return_val_if_fail (tr != NULL, NULL);
trans = g_object_new (GST_TYPE_RTSP_STREAM_TRANSPORT, NULL); trans = g_object_new (GST_TYPE_RTSP_STREAM_TRANSPORT, NULL);
trans->stream = stream; trans->stream = stream;
trans->transport = tr;
return trans; return trans;
} }
@ -150,20 +153,20 @@ gst_rtsp_stream_transport_set_keepalive (GstRTSPStreamTransport * trans,
/** /**
* gst_rtsp_stream_transport_set_transport: * gst_rtsp_stream_transport_set_transport:
* @trans: a #GstRTSPStreamTransport * @trans: a #GstRTSPStreamTransport
* @ct: a client #GstRTSPTransport * @tr: (transfer full): a client #GstRTSPTransport
* *
* Set @ct as the client transport. This function takes ownership of * Set @ct as the client transport. This function takes ownership of
* the passed @ct. * the passed @tr.
*/ */
void void
gst_rtsp_stream_transport_set_transport (GstRTSPStreamTransport * trans, gst_rtsp_stream_transport_set_transport (GstRTSPStreamTransport * trans,
GstRTSPTransport * ct) GstRTSPTransport * tr)
{ {
g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans)); g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
g_return_if_fail (ct != NULL); g_return_if_fail (tr != NULL);
/* keep track of the transports in the stream. */ /* keep track of the transports in the stream. */
if (trans->transport) if (trans->transport)
gst_rtsp_transport_free (trans->transport); gst_rtsp_transport_free (trans->transport);
trans->transport = ct; trans->transport = tr;
} }

View file

@ -89,10 +89,11 @@ struct _GstRTSPStreamTransportClass {
GType gst_rtsp_stream_transport_get_type (void); GType gst_rtsp_stream_transport_get_type (void);
GstRTSPStreamTransport * gst_rtsp_stream_transport_new (GstRTSPStream *stream); GstRTSPStreamTransport * gst_rtsp_stream_transport_new (GstRTSPStream *stream,
GstRTSPTransport *tr);
void gst_rtsp_stream_transport_set_transport (GstRTSPStreamTransport *trans, void gst_rtsp_stream_transport_set_transport (GstRTSPStreamTransport *trans,
GstRTSPTransport * ct); GstRTSPTransport * tr);
void gst_rtsp_stream_transport_set_callbacks (GstRTSPStreamTransport *trans, void gst_rtsp_stream_transport_set_callbacks (GstRTSPStreamTransport *trans,
GstRTSPSendFunc send_rtp, GstRTSPSendFunc send_rtp,