More cleanups

Don't keep a reference to the GstRTSPMedia in the stream.
Free more things when freeing the GstRTSPMedia.
This commit is contained in:
Wim Taymans 2009-01-30 16:24:10 +01:00
parent 1b9225078b
commit 27f069b43c
4 changed files with 29 additions and 23 deletions

View file

@ -435,19 +435,16 @@ handle_setup_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPMessage *re
}
g_strfreev (transports);
g_free (ct->destination);
ct->destination = g_strdup (inet_ntoa (client->address.sin_addr));
/* we have not found anything usable, error out */
if (!have_transport) {
if (!have_transport)
goto unsupported_transports;
}
/* we have a valid transport, check if we can handle it */
if (ct->trans != GST_RTSP_TRANS_RTP)
goto unsupported_transports;
if (ct->profile != GST_RTSP_PROFILE_AVP)
goto unsupported_transports;
supported = GST_RTSP_LOWER_TRANS_UDP |
GST_RTSP_LOWER_TRANS_UDP_MCAST | GST_RTSP_LOWER_TRANS_TCP;
if (!(ct->lower_transport & supported))
@ -456,6 +453,10 @@ handle_setup_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPMessage *re
if (client->session_pool == NULL)
goto no_pool;
/* we have a valid transport now, set the destination of the client. */
g_free (ct->destination);
ct->destination = g_strdup (inet_ntoa (client->address.sin_addr));
/* a setup request creates a session for a client, check if the client already
* sent a session id to us */
res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
@ -478,6 +479,7 @@ handle_setup_request (GstRTSPClient *client, GstRTSPUrl *uri, GstRTSPMessage *re
/* get a handle to the configuration of the media in the session */
if ((m = find_media (client, uri, request))) {
/* manage the media in our session now */
media = gst_rtsp_session_manage_media (session, uri, m);
}
}

View file

@ -416,7 +416,6 @@ default_construct (GstRTSPMediaFactory *factory, const GstRTSPUrl *url)
/* create the stream */
stream = g_new0 (GstRTSPMediaStream, 1);
stream->media = media;
stream->payloader = pay;
pad = gst_element_get_static_pad (pay, "src");

View file

@ -56,11 +56,16 @@ static void
gst_rtsp_media_init (GstRTSPMedia * media)
{
media->streams = g_array_new (FALSE, TRUE, sizeof (GstRTSPMediaStream *));
media->complete = FALSE;
}
static void
gst_rtsp_media_stream_free (GstRTSPMediaStream *stream)
{
if (stream->caps)
gst_caps_unref (stream->caps);
g_free (stream);
}
static void
@ -80,6 +85,8 @@ gst_rtsp_media_finalize (GObject * obj)
}
g_array_free (media->streams, TRUE);
gst_object_unref (media->pipeline);
G_OBJECT_CLASS (gst_rtsp_media_parent_class)->finalize (obj);
}
@ -188,7 +195,8 @@ gst_rtsp_media_n_streams (GstRTSPMedia *media)
*
* Retrieve the stream with index @idx from @media.
*
* Returns: the #GstRTSPMediaStream at index @idx.
* Returns: the #GstRTSPMediaStream at index @idx or %NULL when a stream with
* that index did not exist.
*/
GstRTSPMediaStream *
gst_rtsp_media_get_stream (GstRTSPMedia *media, guint idx)
@ -196,9 +204,11 @@ gst_rtsp_media_get_stream (GstRTSPMedia *media, guint idx)
GstRTSPMediaStream *res;
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
g_return_val_if_fail (idx < media->streams->len, NULL);
res = g_array_index (media->streams, GstRTSPMediaStream *, idx);
if (idx < media->streams->len)
res = g_array_index (media->streams, GstRTSPMediaStream *, idx);
else
res = NULL;
return res;
}
@ -315,19 +325,13 @@ again:
/* we keep these elements, we configure all in configure_transport when the
* server told us to really use the UDP ports. */
stream->udpsrc[0] = gst_object_ref (udpsrc0);
stream->udpsrc[1] = gst_object_ref (udpsrc1);
stream->udpsink[0] = gst_object_ref (udpsink0);
stream->udpsink[1] = gst_object_ref (udpsink1);
stream->udpsrc[0] = udpsrc0;
stream->udpsrc[1] = udpsrc1;
stream->udpsink[0] = udpsink0;
stream->udpsink[1] = udpsink1;
stream->server_port.min = rtpport;
stream->server_port.max = rtcpport;
/* they are ours now */
gst_object_sink (udpsrc0);
gst_object_sink (udpsrc1);
gst_object_sink (udpsink0);
gst_object_sink (udpsink1);
return TRUE;
/* ERRORS */
@ -504,6 +508,7 @@ gst_rtsp_media_prepare (GstRTSPMedia *media)
/* and back to PAUSED for live pipelines */
ret = gst_element_set_state (media->pipeline, GST_STATE_PAUSED);
/* unlock the udp src elements */
n_streams = gst_rtsp_media_n_streams (media);
for (i = 0; i < n_streams; i++) {
GstRTSPMediaStream *stream;

View file

@ -59,14 +59,10 @@ typedef struct _GstRTSPMediaClass GstRTSPMediaClass;
* The definition of a media stream. The streams are identified by @id.
*/
struct _GstRTSPMediaStream {
GstRTSPMedia *media;
GstPad *srcpad;
GstElement *payloader;
gboolean prepared;
GstRTSPRange server_port;
/* pads on the rtpbin */
GstPad *recv_rtcp_sink;
GstPad *send_rtp_sink;
@ -78,6 +74,9 @@ struct _GstRTSPMediaStream {
GstElement *udpsrc[2];
GstElement *udpsink[2];
/* server ports for sending/receiving */
GstRTSPRange server_port;
/* the caps of the stream */
gulong caps_sig;
GstCaps *caps;
@ -102,6 +101,7 @@ struct _GstRTSPMedia {
GObject parent;
gboolean shared;
gboolean complete;
GstElement *element;
GArray *streams;