2 * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 #include <gst/app/gstappsrc.h>
24 #include <gst/app/gstappsink.h>
26 #include "rtsp-media.h"
28 #define GST_RTSP_MEDIA_GET_PRIVATE(obj) \
29 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_MEDIA, GstRTSPMediaPrivate))
31 struct _GstRTSPMediaPrivate
38 GstRTSPLowerTrans protocols;
40 gboolean eos_shutdown;
43 GstRTSPAddressPool *pool;
49 GstRTSPMediaStatus status;
53 /* the pipeline for the media */
62 GstState target_state;
64 /* RTP session manager */
67 /* the range of media */
68 GstRTSPTimeRange range;
69 GstClockTime range_start;
70 GstClockTime range_stop;
73 #define DEFAULT_SHARED FALSE
74 #define DEFAULT_REUSABLE FALSE
75 #define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_TCP
76 //#define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP_MCAST
77 #define DEFAULT_EOS_SHUTDOWN FALSE
78 #define DEFAULT_BUFFER_SIZE 0x80000
80 /* define to dump received RTCP packets */
103 GST_DEBUG_CATEGORY_STATIC (rtsp_media_debug);
104 #define GST_CAT_DEFAULT rtsp_media_debug
106 static void gst_rtsp_media_get_property (GObject * object, guint propid,
107 GValue * value, GParamSpec * pspec);
108 static void gst_rtsp_media_set_property (GObject * object, guint propid,
109 const GValue * value, GParamSpec * pspec);
110 static void gst_rtsp_media_finalize (GObject * obj);
112 static gpointer do_loop (GstRTSPMediaClass * klass);
113 static gboolean default_handle_message (GstRTSPMedia * media,
114 GstMessage * message);
115 static void finish_unprepare (GstRTSPMedia * media);
116 static gboolean default_unprepare (GstRTSPMedia * media);
118 static guint gst_rtsp_media_signals[SIGNAL_LAST] = { 0 };
120 G_DEFINE_TYPE (GstRTSPMedia, gst_rtsp_media, G_TYPE_OBJECT);
123 gst_rtsp_media_class_init (GstRTSPMediaClass * klass)
125 GObjectClass *gobject_class;
127 g_type_class_add_private (klass, sizeof (GstRTSPMediaPrivate));
129 gobject_class = G_OBJECT_CLASS (klass);
131 gobject_class->get_property = gst_rtsp_media_get_property;
132 gobject_class->set_property = gst_rtsp_media_set_property;
133 gobject_class->finalize = gst_rtsp_media_finalize;
135 g_object_class_install_property (gobject_class, PROP_SHARED,
136 g_param_spec_boolean ("shared", "Shared",
137 "If this media pipeline can be shared", DEFAULT_SHARED,
138 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
140 g_object_class_install_property (gobject_class, PROP_REUSABLE,
141 g_param_spec_boolean ("reusable", "Reusable",
142 "If this media pipeline can be reused after an unprepare",
143 DEFAULT_REUSABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
145 g_object_class_install_property (gobject_class, PROP_PROTOCOLS,
146 g_param_spec_flags ("protocols", "Protocols",
147 "Allowed lower transport protocols", GST_TYPE_RTSP_LOWER_TRANS,
148 DEFAULT_PROTOCOLS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
150 g_object_class_install_property (gobject_class, PROP_EOS_SHUTDOWN,
151 g_param_spec_boolean ("eos-shutdown", "EOS Shutdown",
152 "Send an EOS event to the pipeline before unpreparing",
153 DEFAULT_EOS_SHUTDOWN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
155 g_object_class_install_property (gobject_class, PROP_BUFFER_SIZE,
156 g_param_spec_uint ("buffer-size", "Buffer Size",
157 "The kernel UDP buffer size to use", 0, G_MAXUINT,
158 DEFAULT_BUFFER_SIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
160 gst_rtsp_media_signals[SIGNAL_NEW_STREAM] =
161 g_signal_new ("new-stream", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
162 G_STRUCT_OFFSET (GstRTSPMediaClass, new_stream), NULL, NULL,
163 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_RTSP_STREAM);
165 gst_rtsp_media_signals[SIGNAL_PREPARED] =
166 g_signal_new ("prepared", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
167 G_STRUCT_OFFSET (GstRTSPMediaClass, prepared), NULL, NULL,
168 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
170 gst_rtsp_media_signals[SIGNAL_UNPREPARED] =
171 g_signal_new ("unprepared", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
172 G_STRUCT_OFFSET (GstRTSPMediaClass, unprepared), NULL, NULL,
173 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
175 gst_rtsp_media_signals[SIGNAL_NEW_STATE] =
176 g_signal_new ("new-state", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
177 G_STRUCT_OFFSET (GstRTSPMediaClass, new_state), NULL, NULL,
178 g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 0, G_TYPE_INT);
180 klass->context = g_main_context_new ();
181 klass->loop = g_main_loop_new (klass->context, TRUE);
183 GST_DEBUG_CATEGORY_INIT (rtsp_media_debug, "rtspmedia", 0, "GstRTSPMedia");
185 klass->thread = g_thread_new ("Bus Thread", (GThreadFunc) do_loop, klass);
187 klass->handle_message = default_handle_message;
188 klass->unprepare = default_unprepare;
192 gst_rtsp_media_init (GstRTSPMedia * media)
194 GstRTSPMediaPrivate *priv = GST_RTSP_MEDIA_GET_PRIVATE (media);
198 priv->streams = g_ptr_array_new_with_free_func (g_object_unref);
199 g_mutex_init (&priv->lock);
200 g_cond_init (&priv->cond);
201 g_rec_mutex_init (&priv->state_lock);
203 priv->shared = DEFAULT_SHARED;
204 priv->reusable = DEFAULT_REUSABLE;
205 priv->protocols = DEFAULT_PROTOCOLS;
206 priv->eos_shutdown = DEFAULT_EOS_SHUTDOWN;
207 priv->buffer_size = DEFAULT_BUFFER_SIZE;
211 gst_rtsp_media_finalize (GObject * obj)
213 GstRTSPMediaPrivate *priv;
216 media = GST_RTSP_MEDIA (obj);
219 GST_INFO ("finalize media %p", media);
221 gst_rtsp_media_unprepare (media);
223 g_ptr_array_unref (priv->streams);
225 g_list_free_full (priv->dynamic, gst_object_unref);
228 gst_object_unref (priv->pipeline);
229 gst_object_unref (priv->element);
231 g_object_unref (priv->auth);
233 g_object_unref (priv->pool);
234 g_mutex_clear (&priv->lock);
235 g_cond_clear (&priv->cond);
236 g_rec_mutex_clear (&priv->state_lock);
238 G_OBJECT_CLASS (gst_rtsp_media_parent_class)->finalize (obj);
242 gst_rtsp_media_get_property (GObject * object, guint propid,
243 GValue * value, GParamSpec * pspec)
245 GstRTSPMedia *media = GST_RTSP_MEDIA (object);
249 g_value_set_boolean (value, gst_rtsp_media_is_shared (media));
252 g_value_set_boolean (value, gst_rtsp_media_is_reusable (media));
255 g_value_set_flags (value, gst_rtsp_media_get_protocols (media));
257 case PROP_EOS_SHUTDOWN:
258 g_value_set_boolean (value, gst_rtsp_media_is_eos_shutdown (media));
260 case PROP_BUFFER_SIZE:
261 g_value_set_uint (value, gst_rtsp_media_get_buffer_size (media));
264 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
269 gst_rtsp_media_set_property (GObject * object, guint propid,
270 const GValue * value, GParamSpec * pspec)
272 GstRTSPMedia *media = GST_RTSP_MEDIA (object);
276 gst_rtsp_media_set_shared (media, g_value_get_boolean (value));
279 gst_rtsp_media_set_reusable (media, g_value_get_boolean (value));
282 gst_rtsp_media_set_protocols (media, g_value_get_flags (value));
284 case PROP_EOS_SHUTDOWN:
285 gst_rtsp_media_set_eos_shutdown (media, g_value_get_boolean (value));
287 case PROP_BUFFER_SIZE:
288 gst_rtsp_media_set_buffer_size (media, g_value_get_uint (value));
291 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
296 do_loop (GstRTSPMediaClass * klass)
298 GST_INFO ("enter mainloop");
299 g_main_loop_run (klass->loop);
300 GST_INFO ("exit mainloop");
305 /* must be called with state lock */
307 collect_media_stats (GstRTSPMedia * media)
309 GstRTSPMediaPrivate *priv = media->priv;
310 gint64 position, duration;
312 priv->range.unit = GST_RTSP_RANGE_NPT;
314 GST_INFO ("collect media stats");
317 priv->range.min.type = GST_RTSP_TIME_NOW;
318 priv->range.min.seconds = -1;
319 priv->range_start = -1;
320 priv->range.max.type = GST_RTSP_TIME_END;
321 priv->range.max.seconds = -1;
322 priv->range_stop = -1;
324 /* get the position */
325 if (!gst_element_query_position (priv->pipeline, GST_FORMAT_TIME,
327 GST_INFO ("position query failed");
331 /* get the duration */
332 if (!gst_element_query_duration (priv->pipeline, GST_FORMAT_TIME,
334 GST_INFO ("duration query failed");
338 GST_INFO ("stats: position %" GST_TIME_FORMAT ", duration %"
339 GST_TIME_FORMAT, GST_TIME_ARGS (position), GST_TIME_ARGS (duration));
341 if (position == -1) {
342 priv->range.min.type = GST_RTSP_TIME_NOW;
343 priv->range.min.seconds = -1;
344 priv->range_start = -1;
346 priv->range.min.type = GST_RTSP_TIME_SECONDS;
347 priv->range.min.seconds = ((gdouble) position) / GST_SECOND;
348 priv->range_start = position;
350 if (duration == -1) {
351 priv->range.max.type = GST_RTSP_TIME_END;
352 priv->range.max.seconds = -1;
353 priv->range_stop = -1;
355 priv->range.max.type = GST_RTSP_TIME_SECONDS;
356 priv->range.max.seconds = ((gdouble) duration) / GST_SECOND;
357 priv->range_stop = duration;
363 * gst_rtsp_media_new:
364 * @element: (transfer full): a #GstElement
366 * Create a new #GstRTSPMedia instance. @element is the bin element that
367 * provides the different streams. The #GstRTSPMedia object contains the
368 * element to produce RTP data for one or more related (audio/video/..)
371 * Ownership is taken of @element.
373 * Returns: a new #GstRTSPMedia object.
376 gst_rtsp_media_new (GstElement * element)
378 GstRTSPMedia *result;
380 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
382 result = g_object_new (GST_TYPE_RTSP_MEDIA, NULL);
383 result->priv->element = element;
389 * gst_rtsp_media_take_element:
390 * @media: a #GstRTSPMedia
391 * @pipeline: (transfer full): a #GstPipeline
393 * Set @pipeline as the #GstPipeline for @media. Ownership is
394 * taken of @pipeline.
397 gst_rtsp_media_take_pipeline (GstRTSPMedia * media, GstPipeline * pipeline)
399 GstRTSPMediaPrivate *priv;
402 g_return_if_fail (GST_IS_RTSP_MEDIA (media));
403 g_return_if_fail (GST_IS_PIPELINE (pipeline));
407 g_mutex_lock (&priv->lock);
408 old = priv->pipeline;
409 priv->pipeline = GST_ELEMENT_CAST (pipeline);
410 g_mutex_unlock (&priv->lock);
413 gst_object_unref (old);
415 gst_object_ref (priv->element);
416 gst_bin_add (GST_BIN_CAST (pipeline), priv->element);
420 * gst_rtsp_media_set_shared:
421 * @media: a #GstRTSPMedia
422 * @shared: the new value
424 * Set or unset if the pipeline for @media can be shared will multiple clients.
425 * When @shared is %TRUE, client requests for this media will share the media
429 gst_rtsp_media_set_shared (GstRTSPMedia * media, gboolean shared)
431 GstRTSPMediaPrivate *priv;
433 g_return_if_fail (GST_IS_RTSP_MEDIA (media));
437 g_mutex_lock (&priv->lock);
438 priv->shared = shared;
439 g_mutex_unlock (&priv->lock);
443 * gst_rtsp_media_is_shared:
444 * @media: a #GstRTSPMedia
446 * Check if the pipeline for @media can be shared between multiple clients.
448 * Returns: %TRUE if the media can be shared between clients.
451 gst_rtsp_media_is_shared (GstRTSPMedia * media)
453 GstRTSPMediaPrivate *priv;
456 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
460 g_mutex_lock (&priv->lock);
462 g_mutex_unlock (&priv->lock);
468 * gst_rtsp_media_set_reusable:
469 * @media: a #GstRTSPMedia
470 * @reusable: the new value
472 * Set or unset if the pipeline for @media can be reused after the pipeline has
476 gst_rtsp_media_set_reusable (GstRTSPMedia * media, gboolean reusable)
478 GstRTSPMediaPrivate *priv;
480 g_return_if_fail (GST_IS_RTSP_MEDIA (media));
484 g_mutex_lock (&priv->lock);
485 priv->reusable = reusable;
486 g_mutex_unlock (&priv->lock);
490 * gst_rtsp_media_is_reusable:
491 * @media: a #GstRTSPMedia
493 * Check if the pipeline for @media can be reused after an unprepare.
495 * Returns: %TRUE if the media can be reused
498 gst_rtsp_media_is_reusable (GstRTSPMedia * media)
500 GstRTSPMediaPrivate *priv;
503 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
507 g_mutex_lock (&priv->lock);
508 res = priv->reusable;
509 g_mutex_unlock (&priv->lock);
515 * gst_rtsp_media_set_protocols:
516 * @media: a #GstRTSPMedia
517 * @protocols: the new flags
519 * Configure the allowed lower transport for @media.
522 gst_rtsp_media_set_protocols (GstRTSPMedia * media, GstRTSPLowerTrans protocols)
524 GstRTSPMediaPrivate *priv;
526 g_return_if_fail (GST_IS_RTSP_MEDIA (media));
530 g_mutex_lock (&priv->lock);
531 priv->protocols = protocols;
532 g_mutex_unlock (&priv->lock);
536 * gst_rtsp_media_get_protocols:
537 * @media: a #GstRTSPMedia
539 * Get the allowed protocols of @media.
541 * Returns: a #GstRTSPLowerTrans
544 gst_rtsp_media_get_protocols (GstRTSPMedia * media)
546 GstRTSPMediaPrivate *priv;
547 GstRTSPLowerTrans res;
549 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media),
550 GST_RTSP_LOWER_TRANS_UNKNOWN);
554 g_mutex_lock (&priv->lock);
555 res = priv->protocols;
556 g_mutex_unlock (&priv->lock);
562 * gst_rtsp_media_set_eos_shutdown:
563 * @media: a #GstRTSPMedia
564 * @eos_shutdown: the new value
566 * Set or unset if an EOS event will be sent to the pipeline for @media before
570 gst_rtsp_media_set_eos_shutdown (GstRTSPMedia * media, gboolean eos_shutdown)
572 GstRTSPMediaPrivate *priv;
574 g_return_if_fail (GST_IS_RTSP_MEDIA (media));
578 g_mutex_lock (&priv->lock);
579 priv->eos_shutdown = eos_shutdown;
580 g_mutex_unlock (&priv->lock);
584 * gst_rtsp_media_is_eos_shutdown:
585 * @media: a #GstRTSPMedia
587 * Check if the pipeline for @media will send an EOS down the pipeline before
590 * Returns: %TRUE if the media will send EOS before unpreparing.
593 gst_rtsp_media_is_eos_shutdown (GstRTSPMedia * media)
595 GstRTSPMediaPrivate *priv;
598 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
602 g_mutex_lock (&priv->lock);
603 res = priv->eos_shutdown;
604 g_mutex_unlock (&priv->lock);
610 * gst_rtsp_media_set_buffer_size:
611 * @media: a #GstRTSPMedia
612 * @size: the new value
614 * Set the kernel UDP buffer size.
617 gst_rtsp_media_set_buffer_size (GstRTSPMedia * media, guint size)
619 GstRTSPMediaPrivate *priv;
621 g_return_if_fail (GST_IS_RTSP_MEDIA (media));
623 GST_LOG_OBJECT (media, "set buffer size %u", size);
627 g_mutex_lock (&priv->lock);
628 priv->buffer_size = size;
629 g_mutex_unlock (&priv->lock);
633 * gst_rtsp_media_get_buffer_size:
634 * @media: a #GstRTSPMedia
636 * Get the kernel UDP buffer size.
638 * Returns: the kernel UDP buffer size.
641 gst_rtsp_media_get_buffer_size (GstRTSPMedia * media)
643 GstRTSPMediaPrivate *priv;
646 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
650 g_mutex_unlock (&priv->lock);
651 res = priv->buffer_size;
652 g_mutex_unlock (&priv->lock);
658 * gst_rtsp_media_set_auth:
659 * @media: a #GstRTSPMedia
660 * @auth: a #GstRTSPAuth
662 * configure @auth to be used as the authentication manager of @media.
665 gst_rtsp_media_set_auth (GstRTSPMedia * media, GstRTSPAuth * auth)
667 GstRTSPMediaPrivate *priv;
670 g_return_if_fail (GST_IS_RTSP_MEDIA (media));
674 GST_LOG_OBJECT (media, "set auth %p", auth);
676 g_mutex_lock (&priv->lock);
677 if ((old = priv->auth) != auth)
678 priv->auth = auth ? g_object_ref (auth) : NULL;
681 g_mutex_unlock (&priv->lock);
684 g_object_unref (old);
688 * gst_rtsp_media_get_auth:
689 * @media: a #GstRTSPMedia
691 * Get the #GstRTSPAuth used as the authentication manager of @media.
693 * Returns: (transfer full): the #GstRTSPAuth of @media. g_object_unref() after
697 gst_rtsp_media_get_auth (GstRTSPMedia * media)
699 GstRTSPMediaPrivate *priv;
702 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
706 g_mutex_lock (&priv->lock);
707 if ((result = priv->auth))
708 g_object_ref (result);
709 g_mutex_unlock (&priv->lock);
715 * gst_rtsp_media_set_address_pool:
716 * @media: a #GstRTSPMedia
717 * @pool: a #GstRTSPAddressPool
719 * configure @pool to be used as the address pool of @media.
722 gst_rtsp_media_set_address_pool (GstRTSPMedia * media,
723 GstRTSPAddressPool * pool)
725 GstRTSPMediaPrivate *priv;
726 GstRTSPAddressPool *old;
728 g_return_if_fail (GST_IS_RTSP_MEDIA (media));
732 GST_LOG_OBJECT (media, "set address pool %p", pool);
734 g_mutex_lock (&priv->lock);
735 if ((old = priv->pool) != pool)
736 priv->pool = pool ? g_object_ref (pool) : NULL;
739 g_ptr_array_foreach (priv->streams, (GFunc) gst_rtsp_stream_set_address_pool,
741 g_mutex_unlock (&priv->lock);
744 g_object_unref (old);
748 * gst_rtsp_media_get_address_pool:
749 * @media: a #GstRTSPMedia
751 * Get the #GstRTSPAddressPool used as the address pool of @media.
753 * Returns: (transfer full): the #GstRTSPAddressPool of @media. g_object_unref() after
757 gst_rtsp_media_get_address_pool (GstRTSPMedia * media)
759 GstRTSPMediaPrivate *priv;
760 GstRTSPAddressPool *result;
762 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
766 g_mutex_lock (&priv->lock);
767 if ((result = priv->pool))
768 g_object_ref (result);
769 g_mutex_unlock (&priv->lock);
775 * gst_rtsp_media_collect_streams:
776 * @media: a #GstRTSPMedia
778 * Find all payloader elements, they should be named pay%d in the
779 * element of @media, and create #GstRTSPStreams for them.
781 * Collect all dynamic elements, named dynpay%d, and add them to
782 * the list of dynamic elements.
785 gst_rtsp_media_collect_streams (GstRTSPMedia * media)
787 GstRTSPMediaPrivate *priv;
788 GstElement *element, *elem;
793 g_return_if_fail (GST_IS_RTSP_MEDIA (media));
796 element = priv->element;
799 for (i = 0; have_elem; i++) {
804 name = g_strdup_printf ("pay%d", i);
805 if ((elem = gst_bin_get_by_name (GST_BIN (element), name))) {
806 GST_INFO ("found stream %d with payloader %p", i, elem);
808 /* take the pad of the payloader */
809 pad = gst_element_get_static_pad (elem, "src");
810 /* create the stream */
811 gst_rtsp_media_create_stream (media, elem, pad);
812 gst_object_unref (pad);
813 gst_object_unref (elem);
819 name = g_strdup_printf ("dynpay%d", i);
820 if ((elem = gst_bin_get_by_name (GST_BIN (element), name))) {
821 /* a stream that will dynamically create pads to provide RTP packets */
823 GST_INFO ("found dynamic element %d, %p", i, elem);
825 g_mutex_lock (&priv->lock);
826 priv->dynamic = g_list_prepend (priv->dynamic, elem);
827 g_mutex_unlock (&priv->lock);
836 * gst_rtsp_media_create_stream:
837 * @media: a #GstRTSPMedia
838 * @payloader: a #GstElement
839 * @srcpad: a source #GstPad
841 * Create a new stream in @media that provides RTP data on @srcpad.
842 * @srcpad should be a pad of an element inside @media->element.
844 * Returns: (transfer none): a new #GstRTSPStream that remains valid for as long
848 gst_rtsp_media_create_stream (GstRTSPMedia * media, GstElement * payloader,
851 GstRTSPMediaPrivate *priv;
852 GstRTSPStream *stream;
857 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
858 g_return_val_if_fail (GST_IS_ELEMENT (payloader), NULL);
859 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
860 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
864 g_mutex_lock (&priv->lock);
865 idx = priv->streams->len;
867 GST_DEBUG ("media %p: creating stream with index %d", media, idx);
869 name = g_strdup_printf ("src_%u", idx);
870 srcpad = gst_ghost_pad_new (name, pad);
871 gst_pad_set_active (srcpad, TRUE);
872 gst_element_add_pad (priv->element, srcpad);
875 stream = gst_rtsp_stream_new (idx, payloader, srcpad);
877 gst_rtsp_stream_set_address_pool (stream, priv->pool);
879 g_ptr_array_add (priv->streams, stream);
880 g_mutex_unlock (&priv->lock);
882 g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_NEW_STREAM], 0, stream,
889 * gst_rtsp_media_n_streams:
890 * @media: a #GstRTSPMedia
892 * Get the number of streams in this media.
894 * Returns: The number of streams.
897 gst_rtsp_media_n_streams (GstRTSPMedia * media)
899 GstRTSPMediaPrivate *priv;
902 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), 0);
906 g_mutex_lock (&priv->lock);
907 res = priv->streams->len;
908 g_mutex_unlock (&priv->lock);
914 * gst_rtsp_media_get_stream:
915 * @media: a #GstRTSPMedia
916 * @idx: the stream index
918 * Retrieve the stream with index @idx from @media.
920 * Returns: (transfer none): the #GstRTSPStream at index @idx or %NULL when a stream with
921 * that index did not exist.
924 gst_rtsp_media_get_stream (GstRTSPMedia * media, guint idx)
926 GstRTSPMediaPrivate *priv;
929 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
933 g_mutex_lock (&priv->lock);
934 if (idx < priv->streams->len)
935 res = g_ptr_array_index (priv->streams, idx);
938 g_mutex_unlock (&priv->lock);
944 * gst_rtsp_media_get_range_string:
945 * @media: a #GstRTSPMedia
946 * @play: for the PLAY request
948 * Get the current range as a string. @media must be prepared with
949 * gst_rtsp_media_prepare ().
951 * Returns: The range as a string, g_free() after usage.
954 gst_rtsp_media_get_range_string (GstRTSPMedia * media, gboolean play)
956 GstRTSPMediaPrivate *priv;
958 GstRTSPTimeRange range;
960 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
964 g_rec_mutex_lock (&priv->state_lock);
965 if (priv->status != GST_RTSP_MEDIA_STATUS_PREPARED)
968 g_mutex_lock (&priv->lock);
972 if (!play && priv->n_active > 0) {
973 range.min.type = GST_RTSP_TIME_NOW;
974 range.min.seconds = -1;
976 g_mutex_unlock (&priv->lock);
977 g_rec_mutex_unlock (&priv->state_lock);
979 result = gst_rtsp_range_to_string (&range);
986 GST_WARNING ("media %p was not prepared", media);
987 g_rec_mutex_unlock (&priv->state_lock);
993 * gst_rtsp_media_seek:
994 * @media: a #GstRTSPMedia
995 * @range: a #GstRTSPTimeRange
997 * Seek the pipeline of @media to @range. @media must be prepared with
998 * gst_rtsp_media_prepare().
1000 * Returns: %TRUE on success.
1003 gst_rtsp_media_seek (GstRTSPMedia * media, GstRTSPTimeRange * range)
1005 GstRTSPMediaPrivate *priv;
1008 GstClockTime start, stop;
1009 GstSeekType start_type, stop_type;
1011 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
1012 g_return_val_if_fail (range != NULL, FALSE);
1016 g_rec_mutex_lock (&priv->state_lock);
1017 if (priv->status != GST_RTSP_MEDIA_STATUS_PREPARED)
1020 if (!priv->seekable)
1023 /* depends on the current playing state of the pipeline. We might need to
1024 * queue this until we get EOS. */
1025 flags = GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_KEY_UNIT;
1027 start_type = stop_type = GST_SEEK_TYPE_NONE;
1029 if (!gst_rtsp_range_get_times (range, &start, &stop))
1032 GST_INFO ("got %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
1033 GST_TIME_ARGS (start), GST_TIME_ARGS (stop));
1034 GST_INFO ("current %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
1035 GST_TIME_ARGS (priv->range_start), GST_TIME_ARGS (priv->range_stop));
1037 if (priv->range_start == start)
1038 start = GST_CLOCK_TIME_NONE;
1039 else if (start != GST_CLOCK_TIME_NONE)
1040 start_type = GST_SEEK_TYPE_SET;
1042 if (priv->range_stop == stop)
1043 stop = GST_CLOCK_TIME_NONE;
1044 else if (stop != GST_CLOCK_TIME_NONE)
1045 stop_type = GST_SEEK_TYPE_SET;
1047 if (start != GST_CLOCK_TIME_NONE || stop != GST_CLOCK_TIME_NONE) {
1048 GST_INFO ("seeking to %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
1049 GST_TIME_ARGS (start), GST_TIME_ARGS (stop));
1051 res = gst_element_seek (priv->pipeline, 1.0, GST_FORMAT_TIME,
1052 flags, start_type, start, stop_type, stop);
1054 /* and block for the seek to complete */
1055 GST_INFO ("done seeking %d", res);
1056 gst_element_get_state (priv->pipeline, NULL, NULL, -1);
1057 GST_INFO ("prerolled again");
1059 collect_media_stats (media);
1061 GST_INFO ("no seek needed");
1064 g_rec_mutex_unlock (&priv->state_lock);
1071 g_rec_mutex_unlock (&priv->state_lock);
1072 GST_INFO ("media %p is not prepared", media);
1077 g_rec_mutex_unlock (&priv->state_lock);
1078 GST_INFO ("pipeline is not seekable");
1083 g_rec_mutex_unlock (&priv->state_lock);
1084 GST_WARNING ("seek unit %d not supported", range->unit);
1090 gst_rtsp_media_set_status (GstRTSPMedia * media, GstRTSPMediaStatus status)
1092 GstRTSPMediaPrivate *priv = media->priv;
1094 g_mutex_lock (&priv->lock);
1095 /* never overwrite the error status */
1096 if (priv->status != GST_RTSP_MEDIA_STATUS_ERROR)
1097 priv->status = status;
1098 GST_DEBUG ("setting new status to %d", status);
1099 g_cond_broadcast (&priv->cond);
1100 g_mutex_unlock (&priv->lock);
1104 * gst_rtsp_media_get_status:
1105 * @media: a #GstRTSPMedia
1107 * Get the status of @media. When @media is busy preparing, this function waits
1108 * until @media is prepared or in error.
1110 * Returns: the status of @media.
1113 gst_rtsp_media_get_status (GstRTSPMedia * media)
1115 GstRTSPMediaPrivate *priv = media->priv;
1116 GstRTSPMediaStatus result;
1119 g_mutex_lock (&priv->lock);
1120 end_time = g_get_monotonic_time () + 20 * G_TIME_SPAN_SECOND;
1121 /* while we are preparing, wait */
1122 while (priv->status == GST_RTSP_MEDIA_STATUS_PREPARING) {
1123 GST_DEBUG ("waiting for status change");
1124 if (!g_cond_wait_until (&priv->cond, &priv->lock, end_time)) {
1125 GST_DEBUG ("timeout, assuming error status");
1126 priv->status = GST_RTSP_MEDIA_STATUS_ERROR;
1129 /* could be success or error */
1130 result = priv->status;
1131 GST_DEBUG ("got status %d", result);
1132 g_mutex_unlock (&priv->lock);
1137 /* called with state-lock */
1139 default_handle_message (GstRTSPMedia * media, GstMessage * message)
1141 GstRTSPMediaPrivate *priv = media->priv;
1142 GstMessageType type;
1144 type = GST_MESSAGE_TYPE (message);
1147 case GST_MESSAGE_STATE_CHANGED:
1149 case GST_MESSAGE_BUFFERING:
1153 gst_message_parse_buffering (message, &percent);
1155 /* no state management needed for live pipelines */
1159 if (percent == 100) {
1160 /* a 100% message means buffering is done */
1161 priv->buffering = FALSE;
1162 /* if the desired state is playing, go back */
1163 if (priv->target_state == GST_STATE_PLAYING) {
1164 GST_INFO ("Buffering done, setting pipeline to PLAYING");
1165 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
1167 GST_INFO ("Buffering done");
1170 /* buffering busy */
1171 if (priv->buffering == FALSE) {
1172 if (priv->target_state == GST_STATE_PLAYING) {
1173 /* we were not buffering but PLAYING, PAUSE the pipeline. */
1174 GST_INFO ("Buffering, setting pipeline to PAUSED ...");
1175 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1177 GST_INFO ("Buffering ...");
1180 priv->buffering = TRUE;
1184 case GST_MESSAGE_LATENCY:
1186 gst_bin_recalculate_latency (GST_BIN_CAST (priv->pipeline));
1189 case GST_MESSAGE_ERROR:
1194 gst_message_parse_error (message, &gerror, &debug);
1195 GST_WARNING ("%p: got error %s (%s)", media, gerror->message, debug);
1196 g_error_free (gerror);
1199 gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_ERROR);
1202 case GST_MESSAGE_WARNING:
1207 gst_message_parse_warning (message, &gerror, &debug);
1208 GST_WARNING ("%p: got warning %s (%s)", media, gerror->message, debug);
1209 g_error_free (gerror);
1213 case GST_MESSAGE_ELEMENT:
1215 case GST_MESSAGE_STREAM_STATUS:
1217 case GST_MESSAGE_ASYNC_DONE:
1218 if (!priv->adding) {
1219 /* when we are dynamically adding pads, the addition of the udpsrc will
1220 * temporarily produce ASYNC_DONE messages. We have to ignore them and
1221 * wait for the final ASYNC_DONE after everything prerolled */
1222 GST_INFO ("%p: got ASYNC_DONE", media);
1223 collect_media_stats (media);
1225 gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_PREPARED);
1227 GST_INFO ("%p: ignoring ASYNC_DONE", media);
1230 case GST_MESSAGE_EOS:
1231 GST_INFO ("%p: got EOS", media);
1233 if (priv->status == GST_RTSP_MEDIA_STATUS_UNPREPARING) {
1234 GST_DEBUG ("shutting down after EOS");
1235 finish_unprepare (media);
1236 g_object_unref (media);
1240 GST_INFO ("%p: got message type %s", media,
1241 gst_message_type_get_name (type));
1248 bus_message (GstBus * bus, GstMessage * message, GstRTSPMedia * media)
1250 GstRTSPMediaPrivate *priv = media->priv;
1251 GstRTSPMediaClass *klass;
1254 klass = GST_RTSP_MEDIA_GET_CLASS (media);
1256 g_rec_mutex_lock (&priv->state_lock);
1257 if (klass->handle_message)
1258 ret = klass->handle_message (media, message);
1261 g_rec_mutex_unlock (&priv->state_lock);
1267 watch_destroyed (GstRTSPMedia * media)
1269 GST_DEBUG_OBJECT (media, "source destroyed");
1270 gst_object_unref (media);
1273 /* called from streaming threads */
1275 pad_added_cb (GstElement * element, GstPad * pad, GstRTSPMedia * media)
1277 GstRTSPMediaPrivate *priv = media->priv;
1278 GstRTSPStream *stream;
1280 /* FIXME, element is likely not a payloader, find the payloader here */
1281 stream = gst_rtsp_media_create_stream (media, element, pad);
1283 GST_INFO ("pad added %s:%s, stream %s", GST_DEBUG_PAD_NAME (pad), stream);
1285 g_rec_mutex_lock (&priv->state_lock);
1286 /* we will be adding elements below that will cause ASYNC_DONE to be
1287 * posted in the bus. We want to ignore those messages until the
1288 * pipeline really prerolled. */
1289 priv->adding = TRUE;
1291 /* join the element in the PAUSED state because this callback is
1292 * called from the streaming thread and it is PAUSED */
1293 gst_rtsp_stream_join_bin (stream, GST_BIN (priv->pipeline),
1294 priv->rtpbin, GST_STATE_PAUSED);
1296 priv->adding = FALSE;
1297 g_rec_mutex_unlock (&priv->state_lock);
1301 no_more_pads_cb (GstElement * element, GstRTSPMedia * media)
1303 GstRTSPMediaPrivate *priv = media->priv;
1304 GstElement *fakesink;
1306 g_mutex_lock (&priv->lock);
1307 GST_INFO ("no more pads");
1308 if ((fakesink = priv->fakesink)) {
1309 gst_object_ref (fakesink);
1310 priv->fakesink = NULL;
1311 g_mutex_unlock (&priv->lock);
1313 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
1314 gst_element_set_state (fakesink, GST_STATE_NULL);
1315 gst_object_unref (fakesink);
1316 GST_INFO ("removed fakesink");
1321 * gst_rtsp_media_prepare:
1322 * @media: a #GstRTSPMedia
1324 * Prepare @media for streaming. This function will create the pipeline and
1325 * other objects to manage the streaming.
1327 * It will preroll the pipeline and collect vital information about the streams
1328 * such as the duration.
1330 * Returns: %TRUE on success.
1333 gst_rtsp_media_prepare (GstRTSPMedia * media)
1335 GstRTSPMediaPrivate *priv;
1336 GstStateChangeReturn ret;
1337 GstRTSPMediaStatus status;
1339 GstRTSPMediaClass *klass;
1343 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
1347 g_rec_mutex_lock (&priv->state_lock);
1348 if (priv->status == GST_RTSP_MEDIA_STATUS_PREPARED)
1351 if (priv->status == GST_RTSP_MEDIA_STATUS_PREPARING)
1354 if (priv->status != GST_RTSP_MEDIA_STATUS_UNPREPARED)
1355 goto not_unprepared;
1357 if (!priv->reusable && priv->reused)
1360 priv->rtpbin = gst_element_factory_make ("rtpbin", NULL);
1361 if (priv->rtpbin == NULL)
1364 GST_INFO ("preparing media %p", media);
1366 /* reset some variables */
1367 priv->is_live = FALSE;
1368 priv->seekable = FALSE;
1369 priv->buffering = FALSE;
1370 /* we're preparing now */
1371 priv->status = GST_RTSP_MEDIA_STATUS_PREPARING;
1373 bus = gst_pipeline_get_bus (GST_PIPELINE_CAST (priv->pipeline));
1375 /* add the pipeline bus to our custom mainloop */
1376 priv->source = gst_bus_create_watch (bus);
1377 gst_object_unref (bus);
1379 g_source_set_callback (priv->source, (GSourceFunc) bus_message,
1380 gst_object_ref (media), (GDestroyNotify) watch_destroyed);
1382 klass = GST_RTSP_MEDIA_GET_CLASS (media);
1383 priv->id = g_source_attach (priv->source, klass->context);
1385 /* add stuff to the bin */
1386 gst_bin_add (GST_BIN (priv->pipeline), priv->rtpbin);
1388 /* link streams we already have, other streams might appear when we have
1389 * dynamic elements */
1390 for (i = 0; i < priv->streams->len; i++) {
1391 GstRTSPStream *stream;
1393 stream = g_ptr_array_index (priv->streams, i);
1395 gst_rtsp_stream_join_bin (stream, GST_BIN (priv->pipeline),
1396 priv->rtpbin, GST_STATE_NULL);
1399 for (walk = priv->dynamic; walk; walk = g_list_next (walk)) {
1400 GstElement *elem = walk->data;
1402 GST_INFO ("adding callbacks for dynamic element %p", elem);
1404 g_signal_connect (elem, "pad-added", (GCallback) pad_added_cb, media);
1405 g_signal_connect (elem, "no-more-pads", (GCallback) no_more_pads_cb, media);
1407 /* we add a fakesink here in order to make the state change async. We remove
1408 * the fakesink again in the no-more-pads callback. */
1409 priv->fakesink = gst_element_factory_make ("fakesink", "fakesink");
1410 gst_bin_add (GST_BIN (priv->pipeline), priv->fakesink);
1413 GST_INFO ("setting pipeline to PAUSED for media %p", media);
1414 /* first go to PAUSED */
1415 ret = gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1416 priv->target_state = GST_STATE_PAUSED;
1419 case GST_STATE_CHANGE_SUCCESS:
1420 GST_INFO ("SUCCESS state change for media %p", media);
1421 priv->seekable = TRUE;
1423 case GST_STATE_CHANGE_ASYNC:
1424 GST_INFO ("ASYNC state change for media %p", media);
1425 priv->seekable = TRUE;
1427 case GST_STATE_CHANGE_NO_PREROLL:
1428 /* we need to go to PLAYING */
1429 GST_INFO ("NO_PREROLL state change: live media %p", media);
1430 /* FIXME we disable seeking for live streams for now. We should perform a
1431 * seeking query in preroll instead */
1432 priv->seekable = FALSE;
1433 priv->is_live = TRUE;
1434 ret = gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
1435 if (ret == GST_STATE_CHANGE_FAILURE)
1438 case GST_STATE_CHANGE_FAILURE:
1442 g_rec_mutex_unlock (&priv->state_lock);
1444 /* now wait for all pads to be prerolled, FIXME, we should somehow be
1445 * able to do this async so that we don't block the server thread. */
1446 status = gst_rtsp_media_get_status (media);
1447 if (status == GST_RTSP_MEDIA_STATUS_ERROR)
1450 g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_PREPARED], 0, NULL);
1452 GST_INFO ("object %p is prerolled", media);
1459 GST_LOG ("media %p was prepared", media);
1460 g_rec_mutex_unlock (&priv->state_lock);
1466 GST_WARNING ("media %p was not unprepared", media);
1467 g_rec_mutex_unlock (&priv->state_lock);
1472 g_rec_mutex_unlock (&priv->state_lock);
1473 GST_WARNING ("can not reuse media %p", media);
1478 g_rec_mutex_unlock (&priv->state_lock);
1479 GST_WARNING ("no rtpbin element");
1480 g_warning ("failed to create element 'rtpbin', check your installation");
1485 GST_WARNING ("failed to preroll pipeline");
1486 gst_rtsp_media_unprepare (media);
1487 g_rec_mutex_unlock (&priv->state_lock);
1492 /* must be called with state-lock */
1494 finish_unprepare (GstRTSPMedia * media)
1496 GstRTSPMediaPrivate *priv = media->priv;
1499 GST_DEBUG ("shutting down");
1501 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1503 for (i = 0; i < priv->streams->len; i++) {
1504 GstRTSPStream *stream;
1506 GST_INFO ("Removing elements of stream %d from pipeline", i);
1508 stream = g_ptr_array_index (priv->streams, i);
1510 gst_rtsp_stream_leave_bin (stream, GST_BIN (priv->pipeline), priv->rtpbin);
1512 g_ptr_array_set_size (priv->streams, 0);
1514 gst_bin_remove (GST_BIN (priv->pipeline), priv->rtpbin);
1515 priv->rtpbin = NULL;
1517 gst_object_unref (priv->pipeline);
1518 priv->pipeline = NULL;
1520 priv->reused = TRUE;
1521 priv->status = GST_RTSP_MEDIA_STATUS_UNPREPARED;
1524 g_source_destroy (priv->source);
1525 g_source_unref (priv->source);
1526 priv->source = NULL;
1529 /* when the media is not reusable, this will effectively unref the media and
1531 g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_UNPREPARED], 0, NULL);
1534 /* called with state-lock */
1536 default_unprepare (GstRTSPMedia * media)
1538 GstRTSPMediaPrivate *priv = media->priv;
1540 if (priv->eos_shutdown) {
1541 GST_DEBUG ("sending EOS for shutdown");
1542 /* ref so that we don't disappear */
1543 g_object_ref (media);
1544 gst_element_send_event (priv->pipeline, gst_event_new_eos ());
1545 /* we need to go to playing again for the EOS to propagate, normally in this
1546 * state, nothing is receiving data from us anymore so this is ok. */
1547 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
1548 priv->status = GST_RTSP_MEDIA_STATUS_UNPREPARING;
1550 finish_unprepare (media);
1556 * gst_rtsp_media_unprepare:
1557 * @media: a #GstRTSPMedia
1559 * Unprepare @media. After this call, the media should be prepared again before
1560 * it can be used again. If the media is set to be non-reusable, a new instance
1563 * Returns: %TRUE on success.
1566 gst_rtsp_media_unprepare (GstRTSPMedia * media)
1568 GstRTSPMediaPrivate *priv;
1571 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
1575 g_rec_mutex_lock (&priv->state_lock);
1576 if (priv->status == GST_RTSP_MEDIA_STATUS_UNPREPARED)
1577 goto was_unprepared;
1579 GST_INFO ("unprepare media %p", media);
1580 priv->target_state = GST_STATE_NULL;
1583 if (priv->status == GST_RTSP_MEDIA_STATUS_PREPARED) {
1584 GstRTSPMediaClass *klass;
1586 klass = GST_RTSP_MEDIA_GET_CLASS (media);
1587 if (klass->unprepare)
1588 success = klass->unprepare (media);
1590 finish_unprepare (media);
1592 g_rec_mutex_unlock (&priv->state_lock);
1598 g_rec_mutex_unlock (&priv->state_lock);
1599 GST_INFO ("media %p was already unprepared", media);
1605 * gst_rtsp_media_set_state:
1606 * @media: a #GstRTSPMedia
1607 * @state: the target state of the media
1608 * @transports: a #GPtrArray of #GstRTSPStreamTransport pointers
1610 * Set the state of @media to @state and for the transports in @transports.
1612 * @media must be prepared with gst_rtsp_media_prepare();
1614 * Returns: %TRUE on success.
1617 gst_rtsp_media_set_state (GstRTSPMedia * media, GstState state,
1618 GPtrArray * transports)
1620 GstRTSPMediaPrivate *priv;
1622 gboolean activate, deactivate, do_state;
1625 g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
1626 g_return_val_if_fail (transports != NULL, FALSE);
1630 g_rec_mutex_lock (&priv->state_lock);
1631 if (priv->status != GST_RTSP_MEDIA_STATUS_PREPARED)
1634 /* NULL and READY are the same */
1635 if (state == GST_STATE_READY)
1636 state = GST_STATE_NULL;
1638 activate = deactivate = FALSE;
1640 GST_INFO ("going to state %s media %p", gst_element_state_get_name (state),
1644 case GST_STATE_NULL:
1645 case GST_STATE_PAUSED:
1646 /* we're going from PLAYING to PAUSED, READY or NULL, deactivate */
1647 if (priv->target_state == GST_STATE_PLAYING)
1650 case GST_STATE_PLAYING:
1651 /* we're going to PLAYING, activate */
1657 old_active = priv->n_active;
1659 for (i = 0; i < transports->len; i++) {
1660 GstRTSPStreamTransport *trans;
1662 /* we need a non-NULL entry in the array */
1663 trans = g_ptr_array_index (transports, i);
1668 if (gst_rtsp_stream_transport_set_active (trans, TRUE))
1670 } else if (deactivate) {
1671 if (gst_rtsp_stream_transport_set_active (trans, FALSE))
1676 /* we just activated the first media, do the playing state change */
1677 if (old_active == 0 && activate)
1679 /* if we have no more active media, do the downward state changes */
1680 else if (priv->n_active == 0)
1685 GST_INFO ("state %d active %d media %p do_state %d", state, priv->n_active,
1688 if (priv->target_state != state) {
1690 if (state == GST_STATE_NULL) {
1691 gst_rtsp_media_unprepare (media);
1693 GST_INFO ("state %s media %p", gst_element_state_get_name (state),
1695 priv->target_state = state;
1696 gst_element_set_state (priv->pipeline, state);
1699 g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_NEW_STATE], 0, state,
1703 /* remember where we are */
1704 if (state != GST_STATE_NULL && (state == GST_STATE_PAUSED ||
1705 old_active != priv->n_active))
1706 collect_media_stats (media);
1708 g_rec_mutex_unlock (&priv->state_lock);
1715 GST_WARNING ("media %p was not prepared", media);
1716 g_rec_mutex_unlock (&priv->state_lock);