No Video

Krzysztof Konopko krzysztof.konopko at youview.com
Mon Jan 7 02:24:39 PST 2013


Look how it's done in gst-launch.c:
- signal handler is installed

static void
sigint_setup (void)
{
  struct sigaction action;

  memset (&action, 0, sizeof (action));
  action.sa_handler = sigint_handler_sighandler;

  sigaction (SIGINT, &action, NULL);
}

- the signal handler sends the message

/* post an application specific message */
    gst_element_post_message (GST_ELEMENT (pipeline),
        gst_message_new_application (GST_OBJECT (pipeline),
            gst_structure_new ("GstLaunchInterrupt",
                "message", G_TYPE_STRING, "Pipeline interrupted", NULL)));

- the message is handled in the main loop

      case GST_MESSAGE_APPLICATION:{
        const GstStructure *s;

        s = gst_message_get_structure (message);

        if (gst_structure_has_name (s, "GstLaunchInterrupt")) {
          /* this application message is posted when we caught an
interrupt and
           * we need to stop the pipeline. */
          PRINT (_("Interrupt: Stopping pipeline ...\n"));
          res = ELR_INTERRUPT;
          goto exit;
        }
        break;
      }


Or you can read standard input and handle it in a bit simpler manner:
http://kriscience.blogspot.co.uk/2012/12/reading-standard-input-from-gmainloop.html

HTH,
Kris

On 07/01/13 10:13, Ian Davidson wrote:
> So, this is a C question - how do I trap the Ctrl-C?
> 
> Thanks
> 
> Ian
> 
> On 07/01/2013 10:09, Krzysztof Konopko wrote:
>> On 07/01/13 10:06, Ian Davidson wrote:
>>> Thanks David,
>>>
>>> The program ran after removing the single quotes - but just like my
>>> other program, the video does not show.
>>> I don't know whether this is significant - I run the program and it is
>>> supposed to start recording, then I press Ctrl-C to stop the recording.
>>> Have I got a problem where the file has not been 'finalised'?  If so, it
>>> would be because I do not know how to capture the Ctrl-C and tell the
>>> pipeline to stop.
>>>
>>> Ian
>>>
>>> On 07/01/2013 09:51, David Röthlisberger wrote:
>>>> On 7 Jan 2013, at 09:17, Ian Davidson wrote:
>>>>> Hi Kris,
>>>>>
>>>>> You are correct when you say that you did not explain why my program
>>>>> didn't work - but I tried your advice and now have 2 programs which
>>>>> don't work.
>>>>>
>>>>> I use a gst_parse_launch, passing it a string such as
>>>>> "v4l2src norm=PAL ! videorate !
>>>>> 'video/x-raw,format=(string)I420,width=320,height=240,framerate=(fraction)25/1'
>>>>>
>>>>> ! queue ! mux. alsasrc ! audioconvert !
>>>>> 'audio/x-raw,rate=44100,channels=2' ! queue ! mux. avimux name=mux !
>>>>> filesink location=file.avi"
>>>>> but when I run the program I get a message
>>>>> GStreamer-CRITICAL **: gst_element_make_from_uri: assertion
>>>>> `gst_uri_is_valid (uri)' failed
>>>> Have you tried removing the single-quotes? When you pass that to
>>>> gst-launch on the command line, the shell will have stripped the
>>>> quotes off, so what gst-launch saw isn't the same as what you are
>>>> passing to gst_parse_launch.
>>>>
>>>> _______________________________________________
>>>> gstreamer-devel mailing list
>>>> gstreamer-devel at lists.freedesktop.org
>>>> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>>>>
>> OK, got it. You need to send EOS and wait for the EOS message rather
>> than simple quit the main loop. AVI muxer needs to finalize the output.
>>
>> gst_element_send_event (pipeline, gst_event_new_eos ());
>>
>> Kris
>>
> 



More information about the gstreamer-devel mailing list