stream video for a certain period

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

stream video for a certain period

Krishnan
Hi,

I am new to gstreamer. My requirement is to stream a camera for a certain
period (say 2 mins) and then switch camera and stream again for 2 mins and
so on. The code looks like this


loop = g_main_loop_new (NULL, FALSE);

 /* create a server instance */
 server = gst_rtsp_server_new ();
 gst_rtsp_server_set_service( server, "554" );


 /* get the mapping for this server, every server has a default mapper
object
  * that be used to map uri mount points to media factories */
 mapping = gst_rtsp_server_get_media_mapping (server);

 /* make a media factory for a test stream. The default media factory can
use
  * gst-launch syntax to create pipelines.
  * any launch line works as long as it contains elements named pay%d. Each
  * element with pay%d names will be a stream */
 factory = gst_rtsp_media_factory_new ();
 gst_rtsp_media_factory_set_launch (factory, argv[1]);
 gst_rtsp_media_factory_set_shared( factory, 1 );

 /* attach the test factory to the /test url */
 gst_rtsp_media_mapping_add_factory (mapping, "/test", factory);

 /* don't need the ref to the mapper anymore */
 g_object_unref (mapping);

 /* attach the server to the default maincontext */
 gst_rtsp_server_attach (server, NULL);

 /* start serving */
 g_main_loop_run (loop);


So, the g_main_loop_run (loop) function loops forever. How can I make it to
stop after certain period of time?

Thanks,
Krishnan

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: stream video for a certain period

Vineeth-2
See , http://developer.gnome.org/glib/2.29/glib-The-Main-Event-Loop.html#g-timeout-add-seconds and once the timeout happens, to come out of loop you can call loop quit
--vineeth


On Tue, Jul 12, 2011 at 12:04 AM, Saravanakrishnan <[hidden email]> wrote:
Hi,

I am new to gstreamer. My requirement is to stream a camera for a certain
period (say 2 mins) and then switch camera and stream again for 2 mins and
so on. The code looks like this


loop = g_main_loop_new (NULL, FALSE);

 /* create a server instance */
 server = gst_rtsp_server_new ();
 gst_rtsp_server_set_service( server, "554" );


 /* get the mapping for this server, every server has a default mapper
object
  * that be used to map uri mount points to media factories */
 mapping = gst_rtsp_server_get_media_mapping (server);

 /* make a media factory for a test stream. The default media factory can
use
  * gst-launch syntax to create pipelines.
  * any launch line works as long as it contains elements named pay%d. Each
  * element with pay%d names will be a stream */
 factory = gst_rtsp_media_factory_new ();
 gst_rtsp_media_factory_set_launch (factory, argv[1]);
 gst_rtsp_media_factory_set_shared( factory, 1 );

 /* attach the test factory to the /test url */
 gst_rtsp_media_mapping_add_factory (mapping, "/test", factory);

 /* don't need the ref to the mapper anymore */
 g_object_unref (mapping);

 /* attach the server to the default maincontext */
 gst_rtsp_server_attach (server, NULL);

 /* start serving */
 g_main_loop_run (loop);


So, the g_main_loop_run (loop) function loops forever. How can I make it to
stop after certain period of time?

Thanks,
Krishnan

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel



_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: stream video for a certain period

Krishnan
Hi Vineeth,

Thank you so much for the reply. I used the timeout function as you had suggested and it came out of the loop. But, the problem I am facing right now is that the server keeps holding the camera and hence I cannot access the camera again. So, I tried different functions to shutdown the server, clean the pipelines. But it didn't help. The following part of code would give you an idea of what I am trying to do...

        id = gst_rtsp_server_attach (server, NULL);
        // start serving
        g_timeout_add_seconds (10 , timeout_callback , loop);
        g_main_loop_run(loop);
        gboolean SHUTDOWN = FALSE;
        gboolean VALUE=TRUE;
        printf(" Is factory shutdown? = %s\n", (SHUTDOWN)?"true":"false");
        gst_rtsp_media_factory_set_eos_shutdown (factory,VALUE);
        SHUTDOWN = gst_rtsp_media_factory_is_eos_shutdown(factory);
        printf(" Is factory shutdown? = %s\n", (SHUTDOWN)?"true":"false");
        int remove=0;
        printf("\nRemove = %d", remove);
        remove = g_source_remove (id);
        printf("\nRemove = %d", remove);
        g_object_unref (server);
        g_main_loop_unref (loop);

I got the values of SHUTDOWN and remove as 1(which shows that the media factory is cleaned up and source is removed). Still, it failed to release the camera and when it loops to next iteration, I get the following error,

VIDIOC_S_FMT: Device or resource busy

This basically happens because the camera is held by rtsp-server and hence I cannot initialize the camera again (I have to intialize the camera again to switch between diff cameras).

Can you recommend which function I can use to free everything that rtsp-server uses, so that I can able to access the camera?

Thanks,
Krishnan.