Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read and carry out an user command from the console (stdin) while main loop is running in Gstreamer?

Tags:

c

io

glib

gstreamer

I can stream a video, but also I want to get user commands from the console (stdin) and carry out the command while streaming the video. For example, if user enters a text 'exit' to command line, I want it to quit from the loop. I can do it by creating my own thread but there must be a more clever way to do it in Gstreamer.

I use fdsrc to read from stdin and fakesink to printout the command as following:

...
userInput = gst_parse_launch("fdsrc ! fakesink dump=true", error);
gst_element_set_state (userInput, GST_STATE_PLAYING);
/* start streaming. the default port for RTSP streaming is 8554. */
g_print ("stream is ready at rtsp://127.0.0.1:8554/test1\n");
g_main_loop_run (loop);
gst_object_unref (userInput);
return 0;
...

But I do not know how to get the text entered by the user into a function. I feel like I need to use a callback function but fdsrc or fakesink does not have a callback function.

How can I get and process the text entered by the user while g_main_loop is running?

like image 470
aspirin Avatar asked Oct 27 '25 15:10

aspirin


1 Answers

Create a GIOChannel for stdin and attach it to your GMainLoop. It will be added in to the main poll loop for your program, and a callback (provided by you) will be called each time input is available on stdin. As long as GStreamer is using the same GMainLoop then they should run together without blocking each other, and without the need for you to explicitly run your GStreamer code in a separate thread.

See this gist for an example of using GIOChannel to receive and handle command line commands: https://gist.github.com/bert/260094/c099d4535694d91992a87e04864a3c05134afa3e

like image 194
Philip Withnall Avatar answered Oct 29 '25 05:10

Philip Withnall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!