[gst-devel] Text representation of a pipeline

Daniel Lenski dlenski at gmail.com
Thu Sep 13 23:51:34 CEST 2007

On 9/13/07, Andreas Tunek <andreas.tunek at gmail.com> wrote:
> Hi everybody
> I asked this on IRC, but maybe I should ask it here as well.
> Are there any plans to do something like gst_pipeline_to_string() so
> you can get a better overview what elements you pipeline consists of.
> Or is there any other way to represent the pipeline in a human
> readable way?
> tuna

I just wrote a python routine to do this, which could be
straightforwardly translated to C if you like.  It prints out a GST
element (recursively if it's a bin or pipeline), describing each
element's pads and what they link to, and the negotiated or possible
capabilities of those pads.  The output looks something like this:

 /pipeline0/ (pipeline)
       /pipeline0/filesrc0 (filesrc)
         .src => decodebin0.sink
       /pipeline0/decodebin0/ (decodebin)
         .src0 [audio/x-raw-int] ghosts mad0.src => ../audioconvert0.sink
         .sink ghosts typefind.sink <= ../filesrc0.src
             /pipeline0/decodebin0/typefind (typefind)
               .src [application/x-id3] => id3demux0.sink
               .sink <= ../decodebin0.sink.proxypad0
             /pipeline0/decodebin0/id3demux0 (id3demux)
               .src [application/x-apetag] => apedemux0.sink
               .sink [application/x-id3] <= typefind.src
             /pipeline0/decodebin0/apedemux0 (apedemux)
               .src [audio/mpeg] => mad0.sink
               .sink [application/x-apetag] <= id3demux0.src
             /pipeline0/decodebin0/mad0 (mad)
               .src [audio/x-raw-int] => ../decodebin0.src0.proxypad1
               .sink [audio/mpeg] <= apedemux0.src
       /pipeline0/audioconvert0 (audioconvert)
         .src [audio/x-raw-int] => alsasink0.sink
         .sink [audio/x-raw-int] <= decodebin0.src0
       /pipeline0/alsasink0 (alsasink)
         .sink [audio/x-raw-int] <= audioconvert0.src

... which corresponds to a "filesrc ! decodebin ! audioconvert !
alsasink" pipeline processing an MP3 file which has APE and ID3 tags.
The code's below, if you want it!  You just have to run
print_element(element).  Hope that helps,



import pygst
import gst
import os.path

def relpath(p1, p2):
    sep = os.path.sep

    # get common prefix (up to a slash)
    common = os.path.commonprefix((p1, p2))
    common = common[:common.rfind(sep)]

    # remove common prefix
    p1 = p1[len(common)+1:]
    p2 = p2[len(common)+1:]

    # number of seps in p1 is # of ..'s needed
    return "../" * p1.count(sep) + p2

def print_bin(bin, depth=0, recurse=-1, showcaps=True):
    for e in reversed(list(bin)):
        print_element(e, depth, recurse-1)

def print_element(e, depth=0, recurse=-1, showcaps=True):
    indentstr = depth * 6 * ' '

    # print element path and factory
    path = e.get_path_string() + (isinstance(e, gst.Bin) and '/' or '')
    factory = e.get_factory().get_name()
    print indentstr, '%s (%s)' % (path, factory)

    # print info about each pad
    for p in e.pads():
        name = p.get_name()

        # negotiated capabilities
        caps = p.get_negotiated_caps()
        if caps: capsname = caps[0].get_name()
        elif showcaps: capsname = '; '.join(s.to_string() for s in
        else: capsname = None

        # flags
        flags = []
        if not p.is_active(): flags.append('INACTIVE')
        if p.is_blocked(): flags.append('BLOCKED')

        # direction
        direc = (p.get_direction() is gst.PAD_SRC) and "=>" or "<="

        # peer
        peer = p.get_peer()
        if peer: peerpath = relpath(path, peer.get_path_string())
        else: peerpath = None

        # ghost target
        if isinstance(p, gst.GhostPad):
            target = p.get_target()
            if target: ghostpath = target.get_path_string()
            else: ghostpath = None
            ghostpath = None

        print indentstr, " ",
        if flags: print ','.join(flags),
        print ".%s" % name,
        if capsname: print '[%s]' % capsname,
        if ghostpath: print "ghosts %s" % relpath(path, ghostpath),
        print "%s %s" % (direc, peerpath)
        #if peerpath and peerpath.find('proxy')!=-1: print peer

    if recurse and isinstance(e, gst.Bin):
        print_bin(e, depth+1, recurse)

More information about the gstreamer-devel mailing list