python and GStreamer questions |
2007-09-09
|
Josep had a GStreamer problem last Friday and really really wanted to bug me about it because everyone else he usually bugs about them is gone :) Julien was at IBC, Andy is doing an Andy, Mike is in the US, Zaheer is in London, and Jan is in Ireland. All with varying degrees of longetivity and permanence.
Now, I've hardly done any code with GStreamer for a while, but I helped him trawl through the log file he gave me until we found a likely symptom for his problem. He went away again then came back later asking me to check his theory about the bug.
Not to bore you with details, but it boiled down to a simple question he had: does gst_buffer_create_sub() set the master buffer's caps on the subbuffers it creates or not ?
Well, first of all, I have no idea. Second, why does he ask me, he's been working here for a year now so he should be able to find his way around GStreamer - but that's a post for a different day. Third, it's likely that the answer is in the documentation.
But most of all, why don't you just give it a try ?
He looked at me, puzzled, so I fired up an ipython shell. He said "Well, I don't know Python", and I replied "then it's time you give it a try, because you're about to get the answer to the question you asked me".
I could finish of the post here and lead you to believe that it's really easy to figure out the answer using ipython, but I'm guessing there might be more people out there who need a simple example to realize the power of trying things in ipython. So here goes - I'm pasting my session verbatim, mistakes and all, with comments in italics.
[thomas@level ~]$ ipython
import Python 2.5 (r25:51908, Apr 10 2007, 10:27:40)
Type "copyright", "credits" or "license" for more information.
IPython 0.7.2 -- An enhanced Interactive Python.
? -> Introduction to IPython's features.
%magic -> Information about IPython's 'magic' % functions.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: import gst
In [2]: gst = gst.Bu
gst.Buffer gst.Bus gst.BusSyncReply
gst.BufferFlag gst.BusFlags
In [2]: gst = gst.Buf
gst.Buffer gst.BufferFlag
In [2]: gst = gst.Buffer()
In [3]: caps = gst.caps_from_string('audio/x-raw-int,channels=2')
--------------------------------------------------------------------------- <type 'exceptions.AttributeError'> Traceback (most recent call last) /home/thomas/<ipython console> in <module>() <type 'exceptions.AttributeError'>: 'gst.Buffer' object has no attribute 'caps_from_string'
In [4]: caps = gst.caps_from_string('audio/x-raw-int,channels=2') --------------------------------------------------------------------------- <type 'exceptions.AttributeError'> Traceback (most recent call last) /home/thomas/<ipython console> in <module>() <type 'exceptions.AttributeError'>: 'gst.Buffer' object has no attribute 'caps_from_string'
In [5]: import gst
In [6]: b = gst.Buffer()
In [7]: caps = gst.caps_from_string('audio/x-raw-int,channels=2')
In [8]: b.set_caps(caps)
In [9]: b Out[9]: <gst .Buffer 0x9980c0 of size 0>
In [10]: b.caps Out[10]: <gstcaps at 0x927140>
In [11]: b.caps.to_string()
Out[11]: 'audio/x-raw-int, channels=(int)2'
In [12]: b = gst.Buffer('kakapipi')
In [13]: b Out[13]: <gst .Buffer 0x998140 of size 8 and data 0x6b616b61>
In [14]: b.set_caps(caps)
In [15]: c = b.create_sub(2, 4)
In [16]: c Out[16]: <gst .Buffer 0x9981c0 of size 4 and data 0x6b617069>
In [17]: c.caps
In [18]: c.caps.to_string() --------------------------------------------------------------------------- <type 'exceptions.AttributeError'> Traceback (most recent call last) /home/thomas/<ipython console> in <module>() <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'to_string'
So there's Josep's answer. I hope this makes getting answers from GStreamer easier for some people out there.
On a slightly related note, why is it so hard to copy and paste code or output in WordPress ? I've installed the code markup plug-in, disabled the advanced editor like it asked, and it still insisted on pretending anything in angle brackets was a tag that it then had to close, explicitly, in my text.