2 * Copyright (C) 2019 Mathieu Duponchelle <mathieu@centricular.com>
3 * Copyright (C) 2020 Seungha Yang <seungha@centricular.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
24 #include <gst/rtsp-server/rtsp-server.h>
26 #include "test-replay-server.h"
28 GST_DEBUG_CATEGORY_STATIC (replay_server_debug);
29 #define GST_CAT_DEFAULT (replay_server_debug)
31 static GstStaticCaps raw_video_caps = GST_STATIC_CAPS ("video/x-raw");
32 static GstStaticCaps raw_audio_caps = GST_STATIC_CAPS ("audio/x-raw");
35 * gst_rtsp_media_factory_replay_get_demuxers (GstRTSPMediaFactoryReplay *
38 * gst_rtsp_media_factory_replay_get_payloaders (GstRTSPMediaFactoryReplay *
41 * gst_rtsp_media_factory_replay_get_decoders (GstRTSPMediaFactoryReplay *
51 gst_replay_bin_pad_unblock_and_free (GstReplayBinPad * pad)
53 if (pad->srcpad && pad->block_id) {
54 GST_DEBUG_OBJECT (pad->srcpad, "Unblock");
55 gst_pad_remove_probe (pad->srcpad, pad->block_id);
59 gst_clear_object (&pad->srcpad);
63 /* NOTE: this bin implementation is almost completely taken from rtsp-media-factory-uri
64 * but this example doesn't use the GstRTSPMediaFactoryURI object so that
65 * we can handle events and messages ourselves.
67 * - Handle segment-done message for looping given source
68 * - Drop all incoming seek event because client seek is not implemented
69 * and do initial segment seeking on no-more-pads signal
83 GstElement *uridecodebin;
84 GstElement *inner_bin;
87 GstRTSPMediaFactoryReplay *factory;
94 static void gst_replay_bin_dispose (GObject * object);
95 static void gst_replay_bin_finalize (GObject * object);
96 static void gst_replay_bin_handle_message (GstBin * bin, GstMessage * message);
98 static gboolean autoplug_continue_cb (GstElement * dbin, GstPad * pad,
99 GstCaps * caps, GstReplayBin * self);
100 static void pad_added_cb (GstElement * dbin, GstPad * pad, GstReplayBin * self);
101 static void no_more_pads_cb (GstElement * uribin, GstReplayBin * self);
103 #define gst_replay_bin_parent_class bin_parent_class
104 G_DEFINE_TYPE (GstReplayBin, gst_replay_bin, GST_TYPE_BIN);
107 gst_replay_bin_class_init (GstReplayBinClass * klass)
109 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
110 GstBinClass *bin_class = GST_BIN_CLASS (klass);
112 gobject_class->dispose = gst_replay_bin_dispose;
113 gobject_class->finalize = gst_replay_bin_finalize;
115 bin_class->handle_message = GST_DEBUG_FUNCPTR (gst_replay_bin_handle_message);
119 gst_replay_bin_init (GstReplayBin * self)
121 self->raw_vcaps = gst_static_caps_get (&raw_video_caps);
122 self->raw_acaps = gst_static_caps_get (&raw_audio_caps);
124 self->uridecodebin = gst_element_factory_make ("uridecodebin", NULL);
125 if (!self->uridecodebin) {
126 GST_ERROR_OBJECT (self, "uridecodebin is unavailable");
130 /* our bin will dynamically expose payloaded pads */
131 self->inner_bin = gst_bin_new ("dynpay0");
132 gst_bin_add (GST_BIN_CAST (self), self->inner_bin);
133 gst_bin_add (GST_BIN_CAST (self->inner_bin), self->uridecodebin);
135 g_signal_connect (self->uridecodebin, "autoplug-continue",
136 G_CALLBACK (autoplug_continue_cb), self);
137 g_signal_connect (self->uridecodebin, "pad-added",
138 G_CALLBACK (pad_added_cb), self);
139 g_signal_connect (self->uridecodebin, "no-more-pads",
140 G_CALLBACK (no_more_pads_cb), self);
144 g_mutex_init (&self->lock);
148 gst_replay_bin_dispose (GObject * object)
150 GstReplayBin *self = GST_REPLAY_BIN (object);
152 GST_DEBUG_OBJECT (self, "dispose");
154 gst_clear_caps (&self->raw_vcaps);
155 gst_clear_caps (&self->raw_acaps);
156 gst_clear_object (&self->factory);
159 g_list_free_full (self->srcpads,
160 (GDestroyNotify) gst_replay_bin_pad_unblock_and_free);
161 self->srcpads = NULL;
164 G_OBJECT_CLASS (bin_parent_class)->dispose (object);
168 gst_replay_bin_finalize (GObject * object)
170 GstReplayBin *self = GST_REPLAY_BIN (object);
172 g_mutex_clear (&self->lock);
174 G_OBJECT_CLASS (bin_parent_class)->finalize (object);
178 send_eos_foreach_srcpad (GstElement * element, GstPad * pad, gpointer user_data)
180 GST_DEBUG_OBJECT (pad, "Sending EOS to downstream");
181 gst_pad_push_event (pad, gst_event_new_eos ());
187 gst_replay_bin_do_segment_seek (GstElement * element, GstReplayBin * self)
191 ret = gst_element_seek (element, 1.0, GST_FORMAT_TIME,
192 GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_SEGMENT,
193 GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, -1);
196 GST_WARNING_OBJECT (self, "segment seeking failed");
197 gst_element_foreach_src_pad (element,
198 (GstElementForeachPadFunc) send_eos_foreach_srcpad, NULL);
203 gst_replay_bin_handle_message (GstBin * bin, GstMessage * message)
205 GstReplayBin *self = GST_REPLAY_BIN (bin);
207 if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE) {
208 gboolean next_loop = TRUE;
210 GST_DEBUG_OBJECT (self, "Have segment done message");
212 g_mutex_lock (&self->lock);
213 if (self->num_loops != -1) {
216 if (self->num_loops < 1)
221 /* Send seek event from non-streaming thread */
222 gst_element_call_async (GST_ELEMENT_CAST (self->uridecodebin),
223 (GstElementCallAsyncFunc) gst_replay_bin_do_segment_seek, self, NULL);
225 gst_element_foreach_src_pad (GST_ELEMENT_CAST (self->uridecodebin),
226 (GstElementForeachPadFunc) send_eos_foreach_srcpad, NULL);
229 g_mutex_unlock (&self->lock);
232 GST_BIN_CLASS (bin_parent_class)->handle_message (bin, message);
235 static GstElementFactory *
236 find_payloader (GstReplayBin * self, GstCaps * caps)
239 GstElementFactory *factory = NULL;
240 gboolean autoplug_more = FALSE;
241 GList *demuxers = NULL;
242 GList *payloaders = NULL;
244 demuxers = gst_rtsp_media_factory_replay_get_demuxers (self->factory);
246 /* first find a demuxer that can link */
247 list = gst_element_factory_list_filter (demuxers, caps, GST_PAD_SINK, FALSE);
250 GstStructure *structure = gst_caps_get_structure (caps, 0);
251 gboolean parsed = FALSE;
252 gint mpegversion = 0;
254 if (!gst_structure_get_boolean (structure, "parsed", &parsed) &&
255 gst_structure_has_name (structure, "audio/mpeg") &&
256 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
257 (mpegversion == 2 || mpegversion == 4)) {
258 /* for AAC it's framed=true instead of parsed=true */
259 gst_structure_get_boolean (structure, "framed", &parsed);
262 /* Avoid plugging parsers in a loop. This is not 100% correct, as some
263 * parsers don't set parsed=true in caps. We should do something like
264 * decodebin does and track decode chains and elements plugged in those
271 for (walk = list; walk; walk = walk->next) {
272 factory = GST_ELEMENT_FACTORY (walk->data);
273 klass = gst_element_factory_get_metadata (factory,
274 GST_ELEMENT_METADATA_KLASS);
275 if (strstr (klass, "Parser"))
276 /* caps have parsed=true, so skip this parser to avoid loops */
279 autoplug_more = TRUE;
283 /* caps don't have parsed=true set and we have a demuxer/parser */
284 autoplug_more = TRUE;
287 gst_plugin_feature_list_free (list);
291 /* we have a demuxer, try that one first */
294 payloaders = gst_rtsp_media_factory_replay_get_payloaders (self->factory);
296 /* no demuxer try a depayloader */
297 list = gst_element_factory_list_filter (payloaders,
298 caps, GST_PAD_SINK, FALSE);
302 gst_rtsp_media_factory_replay_get_decoders (self->factory);
303 /* no depayloader, try a decoder, we'll get to a payloader for a decoded
304 * video or audio format, worst case. */
305 list = gst_element_factory_list_filter (decoders,
306 caps, GST_PAD_SINK, FALSE);
309 /* we have a decoder, try that one first */
310 gst_plugin_feature_list_free (list);
316 factory = GST_ELEMENT_FACTORY_CAST (list->data);
317 g_object_ref (factory);
318 gst_plugin_feature_list_free (list);
325 autoplug_continue_cb (GstElement * dbin, GstPad * pad, GstCaps * caps,
328 GstElementFactory *factory;
330 GST_DEBUG_OBJECT (self, "found pad %s:%s of caps %" GST_PTR_FORMAT,
331 GST_DEBUG_PAD_NAME (pad), caps);
333 if (!(factory = find_payloader (self, caps)))
336 /* we found a payloader, stop autoplugging so we can plug the
338 GST_DEBUG_OBJECT (self, "found factory %s",
339 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
340 gst_object_unref (factory);
346 /* no payloader, continue autoplugging */
347 GST_DEBUG_OBJECT (self, "no payloader found for caps %" GST_PTR_FORMAT,
353 static GstPadProbeReturn
354 replay_bin_sink_probe (GstPad * pad, GstPadProbeInfo * info,
357 GstPadProbeReturn ret = GST_PAD_PROBE_OK;
359 if (GST_IS_EVENT (GST_PAD_PROBE_INFO_DATA (info))) {
360 GstEvent *event = GST_PAD_PROBE_INFO_EVENT (info);
362 switch (GST_EVENT_TYPE (event)) {
364 /* Ideally this shouldn't happen because we are responding
365 * seeking query with non-seekable */
366 GST_DEBUG_OBJECT (pad, "Drop seek event");
367 ret = GST_PAD_PROBE_DROP;
372 } else if (GST_IS_QUERY (GST_PAD_PROBE_INFO_DATA (info))) {
373 GstQuery *query = GST_PAD_PROBE_INFO_QUERY (info);
375 switch (GST_QUERY_TYPE (query)) {
376 case GST_QUERY_SEEKING:
378 /* FIXME: client seek is not implemented */
379 gst_query_set_seeking (query, GST_FORMAT_TIME, FALSE, 0,
380 GST_CLOCK_TIME_NONE);
381 ret = GST_PAD_PROBE_HANDLED;
384 case GST_QUERY_SEGMENT:
385 /* client seeking is not considered in here */
386 gst_query_set_segment (query,
387 1.0, GST_FORMAT_TIME, 0, GST_CLOCK_TIME_NONE);
388 ret = GST_PAD_PROBE_HANDLED;
398 static GstPadProbeReturn
399 replay_bin_src_block (GstPad * pad, GstPadProbeInfo * info, GstReplayBin * self)
401 GST_DEBUG_OBJECT (pad, "Block pad");
403 return GST_PAD_PROBE_OK;
407 pad_added_cb (GstElement * dbin, GstPad * pad, GstReplayBin * self)
409 GstElementFactory *factory;
410 GstElement *payloader;
412 GstPad *sinkpad, *srcpad, *ghostpad;
415 gchar *padname, *payloader_name;
416 GstElement *inner_bin = self->inner_bin;
417 GstReplayBinPad *bin_pad;
419 GST_DEBUG_OBJECT (self, "added pad %s:%s", GST_DEBUG_PAD_NAME (pad));
421 /* ref to make refcounting easier later */
422 gst_object_ref (pad);
423 padname = gst_pad_get_name (pad);
425 /* get pad caps first, then call get_caps, then fail */
426 if ((caps = gst_pad_get_current_caps (pad)) == NULL)
427 if ((caps = gst_pad_query_caps (pad, NULL)) == NULL)
430 /* check for raw caps */
431 if (gst_caps_can_intersect (caps, self->raw_vcaps)) {
432 /* we have raw video caps, insert converter */
433 convert = gst_element_factory_make ("videoconvert", NULL);
434 } else if (gst_caps_can_intersect (caps, self->raw_acaps)) {
435 /* we have raw audio caps, insert converter */
436 convert = gst_element_factory_make ("audioconvert", NULL);
442 gst_bin_add (GST_BIN_CAST (inner_bin), convert);
443 gst_element_sync_state_with_parent (convert);
445 sinkpad = gst_element_get_static_pad (convert, "sink");
446 gst_pad_link (pad, sinkpad);
447 gst_object_unref (sinkpad);
449 /* unref old pad, we reffed before */
450 gst_object_unref (pad);
452 /* continue with new pad and caps */
453 pad = gst_element_get_static_pad (convert, "src");
454 if ((caps = gst_pad_get_current_caps (pad)) == NULL)
455 if ((caps = gst_pad_query_caps (pad, NULL)) == NULL)
459 if (!(factory = find_payloader (self, caps)))
462 gst_caps_unref (caps);
464 /* we have a payloader now */
465 GST_DEBUG_OBJECT (self, "found payloader factory %s",
466 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
468 payloader_name = g_strdup_printf ("pay_%s", padname);
469 payloader = gst_element_factory_create (factory, payloader_name);
470 g_free (payloader_name);
471 if (payloader == NULL)
474 g_object_set (payloader, "pt", self->pt, NULL);
477 if (g_object_class_find_property (G_OBJECT_GET_CLASS (payloader),
479 g_object_set (payloader, "buffer-list", TRUE, NULL);
481 /* add the payloader to the pipeline */
482 gst_bin_add (GST_BIN_CAST (inner_bin), payloader);
483 gst_element_sync_state_with_parent (payloader);
485 /* link the pad to the sinkpad of the payloader */
486 sinkpad = gst_element_get_static_pad (payloader, "sink");
487 gst_pad_link (pad, sinkpad);
488 gst_object_unref (pad);
490 /* Add pad probe to handle events */
491 gst_pad_add_probe (sinkpad,
492 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM | GST_PAD_PROBE_TYPE_QUERY_UPSTREAM,
493 (GstPadProbeCallback) replay_bin_sink_probe, self, NULL);
494 gst_object_unref (sinkpad);
496 /* block data for initial segment seeking */
497 bin_pad = g_new0 (GstReplayBinPad, 1);
499 /* Move ownership of pad to this struct */
500 bin_pad->srcpad = gst_object_ref (dpad);
502 gst_pad_add_probe (dpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
503 (GstPadProbeCallback) replay_bin_src_block, self, NULL);
504 g_mutex_lock (&self->lock);
505 self->srcpads = g_list_append (self->srcpads, bin_pad);
506 g_mutex_unlock (&self->lock);
508 /* now expose the srcpad of the payloader as a ghostpad with the same name
509 * as the uridecodebin pad name. */
510 srcpad = gst_element_get_static_pad (payloader, "src");
511 ghostpad = gst_ghost_pad_new (padname, srcpad);
512 gst_object_unref (srcpad);
515 gst_pad_set_active (ghostpad, TRUE);
516 gst_element_add_pad (inner_bin, ghostpad);
523 GST_WARNING ("could not get caps from pad");
525 gst_object_unref (pad);
530 GST_DEBUG ("no payloader found");
532 gst_caps_unref (caps);
533 gst_object_unref (pad);
538 GST_ERROR ("could not create payloader from factory");
540 gst_caps_unref (caps);
541 gst_object_unref (pad);
547 gst_replay_bin_do_initial_segment_seek (GstElement * element,
554 query = gst_query_new_seeking (GST_FORMAT_TIME);
555 ret = gst_element_query (element, query);
558 GST_WARNING_OBJECT (self, "Cannot query seeking");
559 gst_query_unref (query);
563 gst_query_parse_seeking (query, NULL, &seekable, NULL, NULL);
564 gst_query_unref (query);
567 GST_WARNING_OBJECT (self, "Source is not seekable");
572 ret = gst_element_seek (element, 1.0, GST_FORMAT_TIME,
573 GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
574 GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, -1);
577 GST_WARNING_OBJECT (self, "segment seeking failed");
580 /* Unblock all pads then */
581 g_mutex_lock (&self->lock);
583 g_list_free_full (self->srcpads,
584 (GDestroyNotify) gst_replay_bin_pad_unblock_and_free);
585 self->srcpads = NULL;
587 g_mutex_unlock (&self->lock);
590 GST_WARNING_OBJECT (self, "Sending eos to all pads");
591 gst_element_foreach_src_pad (element,
592 (GstElementForeachPadFunc) send_eos_foreach_srcpad, NULL);
597 no_more_pads_cb (GstElement * uribin, GstReplayBin * self)
599 GST_DEBUG_OBJECT (self, "no-more-pads");
600 gst_element_no_more_pads (GST_ELEMENT_CAST (self->inner_bin));
602 /* Flush seeking from streaming thread might not be good idea.
603 * Do this from another (non-streaming) thread */
604 gst_element_call_async (GST_ELEMENT_CAST (self->uridecodebin),
605 (GstElementCallAsyncFunc) gst_replay_bin_do_initial_segment_seek,
610 gst_replay_bin_new (const gchar * uri, gint64 num_loops,
611 GstRTSPMediaFactoryReplay * factory, const gchar * name)
615 g_return_val_if_fail (uri != NULL, NULL);
616 g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), NULL);
619 name = "GstRelayBin";
621 self = GST_REPLAY_BIN (g_object_new (GST_TYPE_REPLAY_BIN,
622 "name", name, NULL));
624 if (!self->uridecodebin) {
625 gst_object_unref (self);
629 g_object_set (self->uridecodebin, "uri", uri, NULL);
630 self->factory = g_object_ref (factory);
631 self->num_loops = num_loops;
633 return GST_ELEMENT_CAST (self);
636 struct _GstRTSPMediaFactoryReplay
638 GstRTSPMediaFactory parent;
656 #define DEFAULT_NUM_LOOPS (-1)
658 static void gst_rtsp_media_factory_replay_get_property (GObject * object,
659 guint propid, GValue * value, GParamSpec * pspec);
660 static void gst_rtsp_media_factory_replay_set_property (GObject * object,
661 guint propid, const GValue * value, GParamSpec * pspec);
662 static void gst_rtsp_media_factory_replay_finalize (GObject * object);
665 * gst_rtsp_media_factory_replay_create_element (GstRTSPMediaFactory *
666 factory, const GstRTSPUrl * url);
676 payloader_filter (GstPluginFeature * feature, FilterData * self);
678 #define gst_rtsp_media_factory_replay_parent_class parent_class
679 G_DEFINE_TYPE (GstRTSPMediaFactoryReplay,
680 gst_rtsp_media_factory_replay, GST_TYPE_RTSP_MEDIA_FACTORY);
683 gst_rtsp_media_factory_replay_class_init (GstRTSPMediaFactoryReplayClass
686 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
687 GstRTSPMediaFactoryClass *mf_class = GST_RTSP_MEDIA_FACTORY_CLASS (klass);
689 gobject_class->get_property = gst_rtsp_media_factory_replay_get_property;
690 gobject_class->set_property = gst_rtsp_media_factory_replay_set_property;
691 gobject_class->finalize = gst_rtsp_media_factory_replay_finalize;
693 g_object_class_install_property (gobject_class, PROP_URI,
694 g_param_spec_string ("uri", "URI",
695 "The URI of the resource to stream", NULL,
696 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
698 g_object_class_install_property (gobject_class, PROP_NUM_LOOPS,
699 g_param_spec_int64 ("num-loops", "Num Loops",
700 "The number of loops (-1 = infinite)", -1, G_MAXINT64,
701 DEFAULT_NUM_LOOPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
703 mf_class->create_element =
704 GST_DEBUG_FUNCPTR (gst_rtsp_media_factory_replay_create_element);
708 gst_rtsp_media_factory_replay_init (GstRTSPMediaFactoryReplay * self)
710 FilterData data = { NULL, };
712 /* get the feature list using the filter */
713 gst_registry_feature_filter (gst_registry_get (), (GstPluginFeatureFilter)
714 payloader_filter, FALSE, &data);
718 g_list_sort (data.demux, gst_plugin_feature_rank_compare_func);
720 g_list_sort (data.payload, gst_plugin_feature_rank_compare_func);
722 g_list_sort (data.decode, gst_plugin_feature_rank_compare_func);
724 self->num_loops = DEFAULT_NUM_LOOPS;
728 gst_rtsp_media_factory_replay_get_property (GObject * object, guint propid,
729 GValue * value, GParamSpec * pspec)
731 GstRTSPMediaFactoryReplay *self = GST_RTSP_MEDIA_FACTORY_REPLAY (object);
735 g_value_take_string (value, self->uri);
738 g_value_set_int64 (value, self->num_loops);
741 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
746 gst_rtsp_media_factory_replay_set_property (GObject * object, guint propid,
747 const GValue * value, GParamSpec * pspec)
749 GstRTSPMediaFactoryReplay *self = GST_RTSP_MEDIA_FACTORY_REPLAY (object);
754 self->uri = g_value_dup_string (value);
757 self->num_loops = g_value_get_int64 (value);
760 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
765 gst_rtsp_media_factory_replay_finalize (GObject * object)
767 GstRTSPMediaFactoryReplay *self = GST_RTSP_MEDIA_FACTORY_REPLAY (object);
771 gst_plugin_feature_list_free (self->demuxers);
772 gst_plugin_feature_list_free (self->payloaders);
773 gst_plugin_feature_list_free (self->decoders);
775 G_OBJECT_CLASS (parent_class)->finalize (object);
779 gst_rtsp_media_factory_replay_create_element (GstRTSPMediaFactory * factory,
780 const GstRTSPUrl * url)
782 GstRTSPMediaFactoryReplay *self = GST_RTSP_MEDIA_FACTORY_REPLAY (factory);
784 return gst_replay_bin_new (self->uri, self->num_loops, self,
785 "GstRTSPMediaFactoryReplay");
789 payloader_filter (GstPluginFeature * feature, FilterData * data)
792 GstElementFactory *fact;
795 /* we only care about element factories */
796 if (G_UNLIKELY (!GST_IS_ELEMENT_FACTORY (feature)))
799 if (gst_plugin_feature_get_rank (feature) < GST_RANK_MARGINAL)
802 fact = GST_ELEMENT_FACTORY_CAST (feature);
804 klass = gst_element_factory_get_metadata (fact, GST_ELEMENT_METADATA_KLASS);
806 if (strstr (klass, "Decoder"))
807 list = &data->decode;
808 else if (strstr (klass, "Demux"))
810 else if (strstr (klass, "Parser") && strstr (klass, "Codec"))
812 else if (strstr (klass, "Payloader") && strstr (klass, "RTP"))
813 list = &data->payload;
816 GST_LOG ("adding %s", GST_OBJECT_NAME (fact));
817 *list = g_list_prepend (*list, gst_object_ref (fact));
824 gst_rtsp_media_factory_replay_get_demuxers (GstRTSPMediaFactoryReplay * factory)
826 return factory->demuxers;
830 gst_rtsp_media_factory_replay_get_payloaders (GstRTSPMediaFactoryReplay *
833 return factory->payloaders;
837 gst_rtsp_media_factory_replay_get_decoders (GstRTSPMediaFactoryReplay * factory)
839 return factory->decoders;
842 static GstRTSPMediaFactory *
843 gst_rtsp_media_factory_replay_new (const gchar * uri, gint64 num_loops)
845 GstRTSPMediaFactory *factory;
848 GST_RTSP_MEDIA_FACTORY (g_object_new
849 (GST_TYPE_RTSP_MEDIA_FACTORY_REPLAY, "uri", uri, "num-loops", num_loops,
856 main (int argc, char *argv[])
859 GstRTSPServer *server;
860 GstRTSPMountPoints *mounts;
861 GstRTSPMediaFactory *factory;
862 GOptionContext *optctx;
863 GError *error = NULL;
866 gint64 num_loops = -1;
867 GOptionEntry options[] = {
868 {"num-loops", 0, 0, G_OPTION_ARG_INT64, &num_loops,
869 "The number of loops (default = -1, infinite)", NULL},
873 optctx = g_option_context_new ("RTSP Replay Server");
874 g_option_context_add_main_entries (optctx, options, NULL);
875 g_option_context_add_group (optctx, gst_init_get_option_group ());
876 if (!g_option_context_parse (optctx, &argc, &argv, &error)) {
877 g_printerr ("Error parsing options: %s\n", error->message);
878 g_option_context_free (optctx);
879 g_clear_error (&error);
883 g_print ("%s\n", g_option_context_get_help (optctx, TRUE, NULL));
887 g_option_context_free (optctx);
889 /* check if URI is valid, otherwise convert filename to URI if it's a file */
890 if (gst_uri_is_valid (argv[1])) {
891 uri = g_strdup (argv[1]);
892 } else if (g_file_test (argv[1], G_FILE_TEST_EXISTS)) {
893 uri = gst_filename_to_uri (argv[1], NULL);
895 g_printerr ("Unrecognised command line argument '%s'.\n"
896 "Please pass an URI or file as argument!\n", argv[1]);
900 if (num_loops < -1 || num_loops == 0) {
901 g_printerr ("num-loop should be non-zero or -1");
905 GST_DEBUG_CATEGORY_INIT (replay_server_debug, "replay-server", 0,
906 "RTSP replay server");
909 g_print ("Run loop %" G_GINT64_FORMAT " times\n", num_loops);
911 loop = g_main_loop_new (NULL, FALSE);
913 server = gst_rtsp_server_new ();
915 mounts = gst_rtsp_server_get_mount_points (server);
916 factory = gst_rtsp_media_factory_replay_new (uri, num_loops);
919 gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
921 g_object_unref (mounts);
923 gst_rtsp_server_attach (server, NULL);
925 service = gst_rtsp_server_get_service (server);
926 g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", service);
928 g_main_loop_run (loop);