Querying caps

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

Querying caps

Andrey Nechypurenko-2
Hi Folks,

I am writing small python script to transmit rtp stream with
appsink/appsrc using following pipelines:

Sender:
videotestsrc is-live=true ! video/x-raw, width=640, height=480,
framerate=(fraction)30/1 ! videoconvert ! theoraenc ! rtptheorapay
name=payloader ! appsink name=sink

Receiver:
appsrc name=src ! rtptheoradepay ! decodebin ! videoconvert !
ximagesink sync=false

To playback the stream, as I understand, I need to set caps properly.
I.e. read them from sender payloader source pad and add caps filter
with ssrc, seqnum-offset, configuration, etc. between appsrc and
depayloader on receiver side. When I am running sender pipeline with
gst-launch -v, I can see all these caps. However, attempts to read
them from my python script always fails and this is where I hope to
get some help or hints from gstreamer Gurus.

Here is the code snipped where I am attempting to read caps in bus
message callback:

    if type == Gst.MessageType.STATE_CHANGED:
        prev, new, pending = message.parse_state_changed()
        if new == Gst.State.PAUSED:
            print('printing...')
            element = pipeline.get_by_name("payloader")
            for pad in element.srcpads:
                caps = pad.query_caps(None)
                print(caps.to_string())

Running this code generates the following output repeated seven times:
printing...
application/x-rtp, media=(string)video, payload=(int)[ 96, 127 ],
clock-rate=(int)90000, encoding-name=(string)THEORA

Attempt to read caps from appsink sink pad results in seven ANY outputs.

I would really appreciate if someone can shed the light why there are
seven state changes to the PAUSED state and what is more important for
me how to find missing caps such as ssrc, seqnum-offset,
configuration, etc.


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

Re: Querying caps

Sebastian Dröge-3
On Fr, 2016-07-08 at 09:17 +0200, Andrey Nechypurenko wrote:
>
> I would really appreciate if someone can shed the light why there are
> seven state changes to the PAUSED state

You get a state-changed message for every single element in your
pipeline and the pipeline itself whenever they change states.

>  and what is more important for
> me how to find missing caps such as ssrc, seqnum-offset,
> configuration, etc.

The most reliable way would be to connect to the "notify::caps" signal
of the sinkpad of appsink, or to use a pad probe on the sinkpad to
intercept the caps event.

--

Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (968 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Querying caps

Andrey Nechypurenko-2
Thank you Sebastian for clarifications!
I will try what you suggested.

Thanks!
Andrey.

On 12 July 2016 at 08:31, Sebastian Dröge <[hidden email]> wrote:

> On Fr, 2016-07-08 at 09:17 +0200, Andrey Nechypurenko wrote:
>>
>> I would really appreciate if someone can shed the light why there are
>> seven state changes to the PAUSED state
>
> You get a state-changed message for every single element in your
> pipeline and the pipeline itself whenever they change states.
>
>>  and what is more important for
>> me how to find missing caps such as ssrc, seqnum-offset,
>> configuration, etc.
>
> The most reliable way would be to connect to the "notify::caps" signal
> of the sinkpad of appsink, or to use a pad probe on the sinkpad to
> intercept the caps event.
>
> --
>
> Sebastian Dröge, Centricular Ltd · http://www.centricular.com
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Querying caps

Andrey Nechypurenko-2
In reply to this post by Sebastian Dröge-3
Hi Sebastian,

> The most reliable way would be to connect to the "notify::caps" signal
> of the sinkpad of appsink, or to use a pad probe on the sinkpad to
> intercept the caps event.

I was trying to follow your suggestion with "notify::caps" (please see
my complete python script below). Unfortunately I am still getting ANY
as a stringified caps. I am wondering if I am doing something wrong or
is there a bug or maybe the signal is not an appropriate mechanism in
this particular case and I should try your second suggestion with the
probe?

Thank you,
Andrey.

#!/usr/bin/env python3

import gi
gi.require_version('Gst', '1.0')
gi.require_version('Gtk', '3.0')
from gi.repository import GObject, Gst, Gtk

def notify_caps(pad, args):
    caps = pad.query_caps(None)
    print(caps.to_string()) # Always prints ANY <<<<<<

pstr = 'videotestsrc is-live=true ! ' \
   'video/x-raw, width=640, height=480, framerate=(fraction)30/1 ! ' \
   'theoraenc ! ' \
   'rtptheorapay name=payloader ! ' \
   'appsink name=sink'

GObject.threads_init()
Gst.init(None)

pipeline = Gst.parse_launch(pstr)
appsink = pipeline.get_by_name('sink')
for pad in appsink.sinkpads:
    pad.connect("notify::caps", notify_caps)

bus = pipeline.get_bus()
bus.add_signal_watch()

pipeline.set_state(Gst.State.PLAYING)

msg = bus.timed_pop_filtered(
    Gst.CLOCK_TIME_NONE,
    Gst.MessageType.ERROR | Gst.MessageType.EOS)

pipeline.set_state(Gst.State.NULL)
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Querying caps

Thiago Sousa Santos-2


On Wed, Jul 13, 2016 at 9:29 AM, Andrey Nechypurenko <[hidden email]> wrote:
Hi Sebastian,

> The most reliable way would be to connect to the "notify::caps" signal
> of the sinkpad of appsink, or to use a pad probe on the sinkpad to
> intercept the caps event.

I was trying to follow your suggestion with "notify::caps" (please see
my complete python script below). Unfortunately I am still getting ANY
as a stringified caps. I am wondering if I am doing something wrong or
is there a bug or maybe the signal is not an appropriate mechanism in
this particular case and I should try your second suggestion with the
probe?

You are using a 'query_caps' function that does a caps query on the pad. This will return all the possible caps that the pad can accept, in this case (appsink's sinkpad) it will be ANY. You want to use pad.get_current_caps (https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstPad.html#gst-pad-get-current-caps) that will return the currently set caps on that pad.

Regards,
 

Thank you,
Andrey.

#!/usr/bin/env python3

import gi
gi.require_version('Gst', '1.0')
gi.require_version('Gtk', '3.0')
from gi.repository import GObject, Gst, Gtk

def notify_caps(pad, args):
    caps = pad.query_caps(None)
    print(caps.to_string()) # Always prints ANY <<<<<<

pstr = 'videotestsrc is-live=true ! ' \
   'video/x-raw, width=640, height=480, framerate=(fraction)30/1 ! ' \
   'theoraenc ! ' \
   'rtptheorapay name=payloader ! ' \
   'appsink name=sink'

GObject.threads_init()
Gst.init(None)

pipeline = Gst.parse_launch(pstr)
appsink = pipeline.get_by_name('sink')
for pad in appsink.sinkpads:
    pad.connect("notify::caps", notify_caps)

bus = pipeline.get_bus()
bus.add_signal_watch()

pipeline.set_state(Gst.State.PLAYING)

msg = bus.timed_pop_filtered(
    Gst.CLOCK_TIME_NONE,
    Gst.MessageType.ERROR | Gst.MessageType.EOS)

pipeline.set_state(Gst.State.NULL)
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel



--
Thiago Sousa Santos

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

Re: Querying caps

Andrey Nechypurenko-2
>> I was trying to follow your suggestion with "notify::caps" (please see
>> my complete python script below). Unfortunately I am still getting ANY
>> as a stringified caps. I am wondering if I am doing something wrong or
>> is there a bug or maybe the signal is not an appropriate mechanism in
>> this particular case and I should try your second suggestion with the
>> probe?
>
> You are using a 'query_caps' function that does a caps query on the pad.
> This will return all the possible caps that the pad can accept, in this case
> (appsink's sinkpad) it will be ANY. You want to use pad.get_current_caps
> (https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstPad.html#gst-pad-get-current-caps)
> that will return the currently set caps on that pad.

Thank you very much Thiago!
It was exactly my mistake. Now I can see the caps!

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

Re: Querying caps

lsiden@gmail.com
In reply to this post by Sebastian Dröge-3
Here's a snippet of code I call before I run the pipeline.

    def _connect_signal_handlers(self):
        bus = self.pipeline.get_bus()
        bus.add_signal_watch()
        bus.connect("message::eos", self._on_eos)
        bus.connect("message::error", self._on_err)
        sinkpad = self.pipeline.get_by_name('demuxer').get_static_pad('sink')
        sinkpad.get_target().connect('notify::caps', self._on_notify_caps)

But the signal-handler _on_notify_caps is never called.  

I checked the docs and source for GstPad.  The only signals it sends are 'linked' and 'unlinked'.  'linked' never got called either when I tried to connect to it.

For now, the only way I get get sinkpad.get_current_caps() to return anything useful is to set a timer and wait a second or two, which of course is crude and won't fly in production.

I tried setting aysync-handling=true on the element with the sink pad in order to preroll that part of the pipeline, but no dice.  Then I tried calling this before setting the signal handler, but no dice:

    def _preroll_pipeline(self):
        self._set_and_wait_for_state_change(Gst.State.PLAYING)
        #self._set_and_wait_for_state_change(Gst.State.PAUSED)
        self.pipeline.set_state(Gst.State.PAUSED)

Am I missing something?
Reply | Threaded
Open this post in threaded view
|

Re: Querying caps

lsiden@gmail.com
I'm answering my own question.  My problem is that I had to set up the signal handler for notify::caps before I change the pipeline state to PLAYING.  So now the handler is getting called.

My problem now is how to set the caps I want on a filter before the pipeline actually outputs frames.  At this point its already rolling.  

My previous attempts to pre-roll the pipeline have not been successful.
Reply | Threaded
Open this post in threaded view
|

Re: Querying caps

Nicolas Dufresne-5
Le jeudi 23 mars 2017 à 08:24 -0700, [hidden email] a écrit :

> I'm answering my own question.  My problem is that I had to set up
> the signal
> handler for notify::caps before I change the pipeline state to
> PLAYING.  So
> now the handler is getting called.
>
> My problem now is how to set the caps I want on a filter before the
> pipeline
> actually outputs frames.  At this point its already rolling.  
>
> My previous attempts to pre-roll the pipeline have not been
> successful.
>
Would it be possible to provide a larger view on what you are trying to
do ? Would using blocking PadProbes helps ?

regards,
Nicolas
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Querying caps

lsiden@gmail.com

I tried the blocking probe but it didn't help.  Probably I didn't know how to use it properly.


On Thu, Mar 23, 2017, 14:42 Nicolas Dufresne-5 [via GStreamer-devel] <[hidden email]> wrote:
Le jeudi 23 mars 2017 à 08:24 -0700, [hidden email] a écrit :

> I'm answering my own question.  My problem is that I had to set up
> the signal
> handler for notify::caps before I change the pipeline state to
> PLAYING.  So
> now the handler is getting called.
>
> My problem now is how to set the caps I want on a filter before the
> pipeline
> actually outputs frames.  At this point its already rolling.  
>
> My previous attempts to pre-roll the pipeline have not been
> successful.
>
Would it be possible to provide a larger view on what you are trying to
do ? Would using blocking PadProbes helps ?

regards,
Nicolas
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (188 bytes) Download Attachment



If you reply to this email, your message will be added to the discussion below:
To unsubscribe from Querying caps, click here.
NAML