/** * gst_rtsp_media_factory_get_element: * @factory: a #GstRTSPMediaFactory * @url: the url used * * Returns: (transfer floating) a new #GstElement. */ GstElement * gst_rtsp_media_factory_get_element (GstRTSPMediaFactory * factory, const GstRTSPUrl * url) { GstRTSPMediaFactoryClass *klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS (factory); return klass->get_element (factory, url); }
static GstRTSPMedia * default_construct (GstRTSPMediaFactory * factory, const GstRTSPUrl * url) { GstRTSPMedia *media; GstElement *element, *pipeline; GstRTSPMediaFactoryClass *klass; GType media_gtype; klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS (factory); if (!klass->create_pipeline) goto no_create; element = gst_rtsp_media_factory_create_element (factory, url); if (element == NULL) goto no_element; GST_RTSP_MEDIA_FACTORY_LOCK (factory); media_gtype = factory->priv->media_gtype; GST_RTSP_MEDIA_FACTORY_UNLOCK (factory); /* create a new empty media */ media = g_object_new (media_gtype, "element", element, NULL); gst_rtsp_media_collect_streams (media); pipeline = klass->create_pipeline (factory, media); if (pipeline == NULL) goto no_pipeline; return media; /* ERRORS */ no_create: { g_critical ("no create_pipeline function"); return NULL; } no_element: { g_critical ("could not create element"); return NULL; } no_pipeline: { g_critical ("can't create pipeline"); g_object_unref (media); return NULL; } }
static GstRTSPMedia * default_construct (GstRTSPMediaFactory * factory, const GstRTSPUrl * url) { GstRTSPMedia *media; GstElement *element; GstRTSPMediaFactoryClass *klass; klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS (factory); if (!klass->create_pipeline) goto no_create; if (klass->get_element) element = klass->get_element (factory, url); else element = NULL; if (element == NULL) goto no_element; /* create a new empty media */ media = gst_rtsp_media_new (); media->element = element; media->pipeline = klass->create_pipeline (factory, media); if (media->pipeline == NULL) goto no_pipeline; gst_rtsp_media_factory_collect_streams (factory, url, media); return media; /* ERRORS */ no_create: { g_critical ("no create_pipeline function"); return NULL; } no_element: { g_critical ("could not create element"); return NULL; } no_pipeline: { g_critical ("can't create pipeline"); g_object_unref (media); return NULL; } }
void RTSPserverStorage::setSeek(std::string time){ if (factory->key) { if (this->timestamp != time) { this->timestamp = time; this->seek= time; if (true) { GstStateChangeReturn ret; GstPad *pad; GstState state; GstState rtspstate; gchar *key; GstRTSPMedia *media; GstRTSPMediaFactoryClass *klass; GstElement * source; GstElement * buffer; std::clog << "Key:" << factory->key << std::endl; klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS(this->factory); g_mutex_lock (this->factory->medias_lock); media = static_cast<GstRTSPMedia*> (g_hash_table_lookup( factory->medias, factory->key)); if (media) g_object_ref(media); if (media) { source = gst_bin_get_by_name(GST_BIN(media->element), "file"); // g_object_unref(source); g_object_unref(media); } } } } }
/** * gst_rtsp_media_factory_create_element: * @factory: a #GstRTSPMediaFactory * @url: the url used * * Construct and return a #GstElement that is a #GstBin containing * the elements to use for streaming the media. * * The bin should contain payloaders pay\%d for each stream. The default * implementation of this function returns the bin created from the * launch parameter. * * Returns: (transfer floating): a new #GstElement. */ GstElement * gst_rtsp_media_factory_create_element (GstRTSPMediaFactory * factory, const GstRTSPUrl * url) { GstRTSPMediaFactoryClass *klass; GstElement *result; g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), NULL); g_return_val_if_fail (url != NULL, NULL); klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS (factory); if (klass->create_element) result = klass->create_element (factory, url); else result = NULL; return result; }
/** * gst_rtsp_media_factory_construct: * @factory: a #GstRTSPMediaFactory * @url: the url used * * Prepare the media object and create its streams. Implementations * should create the needed gstreamer elements and add them to the result * object. No state changes should be performed on them yet. * * One or more GstRTSPMediaStream objects should be added to the result with * the srcpad member set to a source pad that produces buffer of type * application/x-rtp. * * Returns: a new #GstRTSPMedia if the media could be prepared. */ GstRTSPMedia * gst_rtsp_media_factory_construct (GstRTSPMediaFactory * factory, const GstRTSPUrl * url) { gchar *key; GstRTSPMedia *media; GstRTSPMediaFactoryClass *klass; klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS (factory); /* convert the url to a key for the hashtable. NULL return or a NULL function * will not cache anything for this factory. */ if (klass->gen_key) key = klass->gen_key (factory, url); else key = NULL; g_mutex_lock (&factory->medias_lock); if (key) { /* we have a key, see if we find a cached media */ media = g_hash_table_lookup (factory->medias, key); if (media) g_object_ref (media); } else media = NULL; if (media == NULL) { /* nothing cached found, try to create one */ if (klass->construct) { media = klass->construct (factory, url); if (media) g_signal_emit (factory, gst_rtsp_media_factory_signals[SIGNAL_MEDIA_CONSTRUCTED], 0, media, NULL); } else media = NULL; if (media) { /* configure the media */ if (klass->configure) klass->configure (factory, media); g_signal_emit (factory, gst_rtsp_media_factory_signals[SIGNAL_MEDIA_CONFIGURE], 0, media, NULL); /* check if we can cache this media */ if (gst_rtsp_media_is_shared (media)) { /* insert in the hashtable, takes ownership of the key */ g_object_ref (media); g_hash_table_insert (factory->medias, key, media); key = NULL; } if (!gst_rtsp_media_is_reusable (media)) { /* when not reusable, connect to the unprepare signal to remove the item * from our cache when it gets unprepared */ g_signal_connect (media, "unprepared", (GCallback) media_unprepared, factory); } } } g_mutex_unlock (&factory->medias_lock); if (key) g_free (key); GST_INFO ("constructed media %p for url %s", media, url->abspath); return media; }
void RTSPserverGate::setLocation(std::string a) { if (factory->key) { if (!lock_transition && pid == 0) { lock_transition = true; this->location = a; GstStateChangeReturn ret; GstPad *pad; GstState state; GstState rtspstate; gchar *key; GstRTSPMedia *media; GstRTSPMediaFactoryClass *klass; GstElement * source; GstElement * buffer; std::clog << "Key:" << factory->key << std::endl; klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS(this->factory); g_mutex_lock(this->factory->medias_lock); media = static_cast<GstRTSPMedia*> (g_hash_table_lookup( factory->medias, factory->key)); if (media) g_object_ref(media); if (media) { source = gst_bin_get_by_name(GST_BIN(media->element), "gate"); if (source) { std::clog << "########## address:" << std::endl; GstIterator* it = gst_element_iterate_src_pads(source); GstIteratorResult result = GST_ITERATOR_OK; if (result == GST_ITERATOR_OK) { gpointer p; result = gst_iterator_next(it, &p); GstPad* pad = GST_PAD(p); std::clog << "PadName: " << gst_pad_get_name(pad) << std::endl; gst_pad_set_blocked_async(pad, TRUE, gate_block_async_cb, this); //g_object_unref(pad); } gst_iterator_free(it); } g_mutex_unlock(this->factory->medias_lock); g_object_unref(media); } } } else { this->location = a; this->pipeline = "( rtspsrc location=" + this->location + " latency=1 name=gate ! rtph264depay name=buffer byte-stream=false ! queue2 max-size-bytes=100000000 use-buffering=true ! rtph264pay name=pay0 pt=96 )"; } }