hipersayanX / PipelineParser

Experimental pipeline parser for GStreamer like pipeline sintax.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python pipeline parser

This is an experimental pipeline parser for GStreamer like pipeline syntax. This parser is not aimed to be fully compatible with GStreamer, it just copies the model, not the mode. It also has an extra syntax for Qt signals and slots and supports pipeline diff. This parser is written in Python 3.

Syntax

A pipeline is basically an application for the graph theory, where each element is a node of the graph and each pipe is a connection between two nodes, and the data packets are transfered throw this connections. Bellow, the pipeline description format is explained.

Defining elements

The simplest way to define new elements in the pipeline is as follow:

element1 element2 element3 element4

This will create four independets elements (nodes) of type elementN with no connections between them (no data transfer). The parser will not check if these elements can be created or not. The types of the elements can be repeated as many as you want.

Setting properties

You can assign the properties for an alement as follow:

element1 prop1=value1 prop2=value2 element2 prop3=value3 element3 element4

Each property must be in the form key=value (with no spaces), and must be declared after the element containing that property. the name (key) for each property follow the common rule for most programming languages; only alphanumeric characters and underscore, and can't start with a number.
The rules for values (value) is as follow:

prop="value"            # String
prop='value'            # String
prop=value              # String
prop=3value*#?          # String
prop='Hello World!!!'   # String
prop=3                  # Int
prop=3.14               # Float
prop=.14                # Float (0.14)
prop=3.                 # Float (3.0)
prop=['value', 3, 3.14]                         # List
prop={'key1': 'value', "key2": [1, 2], 3: 3.14} # Dictionary

Lists and dictionaries uses the same syntax as in Python.
There is also a special property called objectName for assigning an identifying name to an element, this is equivalent to the name property of GStreamer. objectName values must follow the programming languages naming rules.

Linking the elements

If you want to connect one or more elements, you can use pipes ! (exclamation sign) as follow:

element1 prop1=value1 ! element2 prop3=value3 ! element3 element4

Here, element1 is connected with element2, and element2 is connected with element1 and element3, while element4 remains unconnected.
This means that element1 can share data packets with element2, but not with elemen3 or element4.
element2 can share data packets with element1 and elemen3, but not with element4.
element3 can share data packets with element2, but not with elemen1 or element4.
And element4 can't share data packets with none of these.

If you want to connect 3 or more elements to an element, you can use references as follows:

element1 prop1=value1 ! element2 objectName=refel2 ! element3 element4
refel2. ! element5 prop3=value3 ! element6 element4

In the example above, element1, element3 and element5 are connected to element2. To create a reference you must set the objectName property of an object you want to connect, and then connect the value of that property followed by a . (dot) with any other object or reference.

Defining signals & slots

This parser also add a special syntax for Qt based programs that allows connecting two elements using signals & slots. Here is an example:

element1 prop1=value1 signal1(int, QString)>refel2.slot2(int, QString) ! element2 objectName=refel2 ! element3 element4

This will connect the signal1 signal from element1 element to slot2 slot of the element2 element. The signals & slots syntax is as follow.

sender signal([type1, tipe2, ...])>receiver.slot([type1, tipe2, ...])
receiver sender.signal([type1, tipe2, ...])>slot([type1, tipe2, ...])
sender receiver.slot([type1, tipe2, ...])<signal([type1, tipe2, ...])
receiver slot([type1, tipe2, ...])<sender.signal([type1, tipe2, ...])
element signal([type1, tipe2, ...])>slot([type1, tipe2, ...])                 # Self connection
element slot([type1, tipe2, ...])<signal([type1, tipe2, ...])
element sender.signal([type1, tipe2, ...])>receiver.slot([type1, tipe2, ...]) # Extern connection
element receiver.slot([type1, tipe2, ...])<sender.signal([type1, tipe2, ...])

Parser module

Here is a little example:

# Create two pipelines.
pipeline1 = 'element1 prop1=value1 ! element2 prop3=value3 ! element3 element4'

pipeline2 = 'element1 prop1=value1 ! element2 objectName=refel2 ! element3 element4 objectName=refel4 ' \
            'refel2. ! element5 prop3=value3 ! element6 element7 signal>refel4.slot'

# Create a parser instance.
pp = PipelineParser()

# Returns a list of operations to convert from previous pipeline to the new.
ops = pp.pipelineDiff(pipeline1)
ops = pp.pipelineDiff(pipeline2)

# Parse a pipeline and returns the graph.
instances, connections, signalsAndSlots = pp.parsePipeline(pipeline2)

Pipeline routing mode

The pipeline routing mode defines the way in wich the graph nodes will be connected in the case in wich one or more elements types doesn't exist. Four case are possible:

  1. NoCheck: Build the pipeline as is.
  2. Fail: If an element doesn't exist return a void graph.
  3. Remove: If an element doesn't exist return a graph without the element and it's connections.
  4. Force: If an element doesn't exist try to connect all elements connected to the lost element.

You can setup the routing mode as follows:

pp = PipelineParser()

pp.setAvailableElementsTypes(['element1',
                              'element2',
                              #'element3', # This element doesn't exist
                              'element4',
                              'element5',
                              #'element6', # This element doesn't exist
                              'element10',
                              'element11',
                              'element12'])

pp.setPipelineRoutingMode(PipelineParser.PipelineRoutingMode.Force)

About

Experimental pipeline parser for GStreamer like pipeline sintax.

License:GNU General Public License v3.0


Languages

Language:Python 100.0%