gst-switch python API

gstswitch Package

Python API for gst-switch

connection Module

connection deals with all low level method calls over dbus The Connection object is capable of invoking remote methods over dbus

class gstswitch.connection.Connection(address='unix:abstract=gstswitch', bus_name='info.duzy.gst.switch.SwitchController', object_path='/info/duzy/gst/switch/SwitchController', default_interface='info.duzy.gst.switch.SwitchControllerInterface')[source]

Bases: object

Class which makes all remote object class. Deals with lower level connection and remote method invoking

Default bus-address:
 unix:abstract=gstswitch
Param:None
CONNECTION_FLAGS = 1
address[source]

Get the address

adjust_pip(xpos, ypos, width, height)[source]
adjust_pip(in i dx,
in i dy, in i dw, in i dh, out u result);

Calls adjust_pip remotely

Parameters:
  • xpos – the X position of the PIP
  • ypos – the Y position of the PIP
  • width – the width of the PIP
  • height – the height of the PIP
Returns:

tuple with first element as result -

PIP has been changed succefully

bus_name[source]

Get the bus name

click_video(xpos, ypos, width, height)[source]
click_video(in i x,
in i y, in i fw, in i fh, out b result);

Calls click_video remotely

Parameters:
  • xpos
  • ypos
  • width
  • height
Returns:

tuple with first element True if requested

connect_dbus()[source]

Make a new connection using the parameters belonging to the class to the gst-switch-srv over dbus. Sets the self.connection

Params:None
Returns:Nothing
Raises ConnectionError:
 GError occurs while making a connection
default_interface[source]

Get the default interface

get_audio_port()[source]

get_audio_port(out i port); Calls get_audio_port remotely

Param:None
Returns:tuple wit first element audio port number
get_compose_port()[source]

get_compose_port(out i port); Calls get_compose_port remotely

Param:None
Returns:tuple with first element compose port number
get_encode_port()[source]

get_encode_port(out i port); Calls get_encode_port remotely

Param:None
Returns:tuple with first element encode port number
get_preview_ports()[source]

get_preview_ports(out s ports); Calls get_preview_ports remotely

Param:None
Returns:tuple with first element a string in the form of

‘[(3002, 1, 7), (3003, 1, 8)]’

mark_face(faces)[source]

mark_face(in a(iiii) faces); Calls mark_face remotely

Parameters:faces – tuple having four elements
Returns:tuple with first element True if requested
mark_tracking(faces)[source]

mark_tracking(in a(iiii) faces); Calls mark_tracking remotely

Parameters:faces – tuple having four elements
Returns:tuple with first element True if requested
new_record()[source]

new_record(out b result); Calls new_record remotely

Param:None:

returns: tuple with first element True if requested

object_path[source]

Get the object path

set_composite_mode(mode)[source]
set_composite_mode(in i channel,
out b result);

Calls set_composite_mode remotely

Parameters:mode – new composite mode
Returns:tuple with first element True if requested
set_encode_mode(channel)[source]
set_encode_mode(in i channel,
out b result);

Calls set_encode_mode remotely Does not do anything

Param:channel
Returns:tuple with first element True if requested
switch(channel, port)[source]
switch(in i channel,
in i port, out b result);

Calls switch remotely

Parameters:
  • channel – The channel to be switched, ‘A’, ‘B’, ‘a’
  • port – The target port number
Returns:

tuple with first element True if requested

controller Module

The controller is the interface for all remote method calls over dbus. The Controller class creates the controller, which can be used to invoke the remote methods.

class gstswitch.controller.Controller(address='unix:abstract=gstswitch', bus_name='info.duzy.gst.switch.SwitchController', object_path='/info/duzy/gst/switch/SwitchController', default_interface='info.duzy.gst.switch.SwitchControllerInterface')[source]

Bases: object

A Class to control all interactions with the gst-switch-srv over dbus. Provides the interface for higher level interactions

Param:None
address[source]

Get the address

adjust_pip(xpos, ypos, width, height)[source]

Change the PIP position and size

Parameters:
  • xpos – the x position of the PIP
  • ypos – the y position of the PIP
  • width – the width of the PIP
  • height – the height of the PIP
Returns:

result - PIP has been changed succefully

bus_name[source]

Get the bus name

click_video(xpos, ypos, width, height)[source]

User click on the video

Parameters:
  • xpos
  • ypos
  • width
  • height
Returns:

True when requested

default_interface[source]

Get the default interface

establish_connection()[source]

Establishes a fresh connection to the dbus Connection stored as self.connection

Param:None
Returns:None
get_audio_port()[source]

Get the audio port number

Param:None
Returns:audio port number
get_compose_port()[source]

Get the compose port number

Param:None
Returns:compose port number
get_encode_port()[source]

Get the encode port number

Param:None
Returns:encode port number
get_preview_ports()[source]

Get all the preview ports

Param:None
Returns:list of all preview ports
mark_face(faces)[source]

Mark faces

Parameters:faces – tuple having four elements
Returns:True when requested
mark_tracking(faces)[source]

Mark tracking

Parameters:faces – tuple having four elements
Returns:True when requested
new_record()[source]

Start a new recording

Param:None
object_path[source]

Get the object path

classmethod parse_preview_ports(res)[source]

Parses the preview_ports string

set_composite_mode(mode)[source]

Set the current composite mode. Modes between 0 and 3 are allowed.

Parameters:mode – new composite mode
Returns:True when requested
set_encode_mode(channel)[source]

Set the encode mode WARNING: THIS DOES NOT WORK.

Param:channel
Returns:True when requested
switch(channel, port)[source]

Switch the channel to the target port

Parameters:
  • channel – The channel to be switched, ‘A’, ‘B’, ‘a’
  • port – The target port number
Returns:

True when requested

exception Module

All custom exceptions come here

exception gstswitch.exception.BaseError[source]

Bases: exceptions.Exception

docstring for BaseError

exception gstswitch.exception.PathError[source]

Bases: gstswitch.exception.BaseError

docstring for PathError

exception gstswitch.exception.ServerProcessError[source]

Bases: gstswitch.exception.BaseError

docstring for ServerProcessError

exception gstswitch.exception.ConnectionError[source]

Bases: gstswitch.exception.BaseError

docstring for ConnectionError

exception gstswitch.exception.ConnectionReturnError[source]

Bases: gstswitch.exception.BaseError

docstring for ConnectionReturnError

exception gstswitch.exception.RangeError[source]

Bases: gstswitch.exception.BaseError

docstring for RangeError

exception gstswitch.exception.InvalidIndexError[source]

Bases: gstswitch.exception.BaseError

docstring for InvalidIndexError

helpers Module

Has helper classes which create test video and audio sources. It is also possible to create a preview out source showing the compose port output.

class gstswitch.helpers.TestSources(video_port=None, audio_port=None)[source]

Bases: object

A Controller of test sources feeding into the gst-switch-srv :param width: The width of the output video :param height: The height of the output video :param pattern: The videotestsrc pattern of the output video :param timeoverlay: True to enable a running time over video :param clockoverlay: True to enable current clock time over video

audio_port[source]

Get the audio port

get_test_audio()[source]

Returns a list of processes acting as audio test sources running :returns: A list containing all audio test sources running

get_test_video()[source]

Returns a list of processes acting as video test sources running :returns: A list containing all video test sources running

new_test_audio(freq=110, wave=None)[source]

Start a new test audio :param port: The port of where the TCP stream will be sent Should be same as audio port of gst-switch-src :param width: The width of the output audio :param height: The height of the output audio :param pattern: The audiotestsrc pattern of the output audio :param timeoverlay: True to enable a running time over audio :param clockoverlay: True to enable current clock time over audio

new_test_video(width=300, height=200, pattern=None, timeoverlay=False, clockoverlay=False)[source]

Start a new test video :param port: The port of where the TCP stream will be sent Should be same as video port of gst-switch-src :param width: The width of the output video :param height: The height of the output video :param pattern: The videotestsrc pattern of the output video :param timeoverlay: True to enable a running time over video :param clockoverlay: True to enable current clock time over video

running_tests_audio[source]

Get the currently running test audio list

running_tests_video[source]

Get the currently running test video list

terminate_audio()[source]

Terminate all test audio sources

terminate_index_audio(index)[source]

Terminate audio test source specified by index :param index: The index of the audio source to terminate Use get_test_audio for finding the index

terminate_index_video(index)[source]

Terminate video test source specified by index :param index: The index of the video source to terminate Use get_test_video for finding the index

terminate_video()[source]

Terminate all test video sources

video_port[source]

Get the video port

class gstswitch.helpers.PreviewSinks(preview_port=3001)[source]

Bases: object

A Controller for preview sinks to preview ports of gst-switch-srv :param preview_port: The preview port to get the preview

preview_port[source]

Get the preview port

run()[source]

Run the Preview Sink

terminate()[source]

End/Terminate the Preview Sink

server Module

The server deals with all operations controlling gst-switch-srv These include all OS related tasks

class gstswitch.server.Server(path=None, video_port=3000, audio_port=4000, control_port=5000, record_file=False)[source]

Bases: object

Control all server related operations

Parameters:path – Path where the executable gst-switch-srv

is located. Provide the full path. By default looks in the current $PATH. :param video_port: The video port number - default = 3000 :param audio_port: The audio port number - default = 4000 :param control_port: The control port number - default = 5000 :param record_file: The record file format :returns: nothing

SLEEP_TIME = 0.5
audio_port[source]

Get the audio port

control_port[source]

Get the control port

gcov_flush()[source]

Generate gcov coverage by sending the signal SIGUSR1 The generated gcda files are dumped in tools directory. Does not kill the process

Param:

None

Returns:

True when success

Raises:
  • ServerProcessError – If Server is not running
  • ServerProcessError – Unable to send signal
kill(cov=False)[source]

Kill the server process by sending signal.SIGKILL self.proc is made None on success

Param:

None

Returns:

True when success

Raises:
  • ServerProcessError – Process does not exist
  • ServerProcessError – Cannot kill process
classmethod make_coverage()[source]

Generate coverage Calls ‘make coverage’ to generate coverage in .gcov files

path[source]

Get the path

record_file[source]

Get the record file

run(gst_option='')[source]

Launch the server process

Param:None
Gst-option:Any gstreamer option.

Refer to http://www.linuxmanpages.com/man1/gst-launch-0.8.1.php#lbAF. Multiple can be added separated by spaces :returns: nothing :raises IOError: Fail to open /dev/null (os.devnull) :raises PathError: Unable to find gst-switch-srv at path specified :raises ServerProcessError: Running gst-switch-srv gives a OS based error.

terminate(cov=False)[source]

Terminate the server. self.proc is made None on success

Param:

None

Returns:

True when success

Raises:
  • ServerProcessError – Process does not exist
  • ServerProcessError – Cannot terminate process. Try killing it
video_port[source]

Get the video port

testsource Module

The testsource contains all gstreamer pipelines It provides the abse for all the other gstreamer components are build upon.

class gstswitch.testsource.Preview(port)[source]

Bases: object

A Preview Element :param port: The preview port

end()[source]

End/disable the pipeline

pause()[source]

Pause the pipeline

preview_port[source]

Get the Preview Port

run()[source]

Run the pipeline

class gstswitch.testsource.VideoSrc(port, width=300, height=200, pattern=None, timeoverlay=False, clockoverlay=False)[source]

Bases: object

A Test Video Source :param width: The width of the output video :param height: The height of the output video :param pattern: The videotestsrc pattern of the output video None for random :param timeoverlay: True to enable a running time over video :param clockoverlay: True to enable current clock time over video

HOST = 'localhost'
clockoverlay[source]

Get the Clockoverlay

end()[source]

End/disable the pipeline

classmethod generate_pattern(pattern)[source]

Generate a random pattern if not specified

height[source]

Get the height

pattern[source]

Get the Pattern

pause()[source]

End the pipeline

port[source]

Get the Video Port

run()[source]

Run the pipeline

timeoverlay[source]

Get the timeoverlay

width[source]

Get the width

class gstswitch.testsource.AudioSrc(port, freq=110, wave=None)[source]

Bases: object

docstring for AudioSrc

HOST = 'localhost'
end()[source]

End/disable the pipeline

freq[source]

Get the Frequency

classmethod generate_wave(wave)[source]

Generate a random wave if not specified

pause()[source]

End the pipeline

port[source]

Get the Audio Port

run()[source]

Run the pipeline

wave[source]

Get the wave number