coherence.backend (module)

Backend

A set of base classes related with backends.

Backend

The base class for all backends.

BackendStore

The base class for all MediaServer backend stores.

AbstractBackendStore

Inherits from BackendStore and extends his capabilities.

BackendItem

The base class for all MediaServer backend items.

Container

The base class for all containers. Actually his base class is the BackendItem with a few modifications which extends his capabilities to store backend items.

LazyContainer

Inherits from Container and extends his capabilities.

BackendRssMixin

A base class intended to be implemented into a subclass which creates a deferred chain to retrieve a RDF file, parse it, extract the metadata and reschedule itself.

Note

RDF (Resource Description Framework) is a family of World Wide Web Consortium specifications originally designed as a metadata data model.

See also

RDF extended information at wikipedia: https://en.wikipedia.org/wiki/Resource_Description_Framework

class Backend(server, *args, **kwargs)[source]

Bases: eventdispatcher.eventdispatcher.EventDispatcher, coherence.log.LogAble, coherence.extern.simple_plugin.Plugin

In the Backend class we initialize the very basic stuff needed to create a Backend and registers some basic events needed to be successfully detected by our server.

The init method for a backend, should probably most of the time be overwritten when the init is done and send a signal to its device. We can send this signal via two methods, depending on the nature of our backend. For instance, if we want that the backend to be notified without fetching any data we could simply set the attribute init_completed equal to True at the end of our init method of the backend, but in some cases, we will want to send this signal after some deferred call returns a result…in that case we should process slightly differently, you can see how to do that at the end of the init method of the class BackendBaseStore.

After that, the device will then setup, announce itself and should call to the backend’s method upnp_init().

    Changed in version 0.9.0:
  • Introduced inheritance from EventDispatcher

  • The emitted events changed:

    • Coherence.UPnP.Backend.init_completed => backend_init_completed

  • Added new event: backend_init_failed

  • Added new method on_init_failed()

  • Moved class method init_completed to on_init_completed and added class variable init_completed

Note

We can also use this init class to do whatever is necessary with the stuff we can extract from the config dict, connect maybe to an external data-source and start up the backend or if there are any UPnP service actions (Like maybe upnp_Browse for the CDS Browse action), that can’t be handled by the service classes itself, or need some special adjustments for the backend, they probably will need to be defined into the method __init__().

Parameters
  • server (object) – This usually should be an instance of our main class Coherence (the UPnP device that’s hosting our backend).

  • *args (list) – A list with extra arguments for the backend. This, must be implemented into the subclass (if needed).

  • **kwargs (dict) – An unpacked dictionary with the backend’s configuration.

logCategory = 'backend'
implements = []

A list of the device classe like:

[‘MediaServer’,’MediaRenderer’]

init_completed

To know whenever the backend init has completed. This has to be done in the actual backend, maybe it has to wait for an answer from an external data-source first…so…the backend should set this variable to True, then the method on_init_completed() will be automatically triggered dispatching an event announcing that the backend has been initialized.

__init__(server, *args, **kwargs)[source]
Parameters
  • server (object) – This usually should be an instance of our main class Coherence (the UPnP device that’s hosting our backend).

  • *args (list) – A list with extra arguments for the backend. This, must be implemented into the subclass (if needed).

  • **kwargs (dict) – An unpacked dictionary with the backend’s configuration.

on_init_completed(*args, **kwargs)[source]

Inform Coherence that this backend is ready for announcement. This method just accepts any form of arguments as we don’t under which circumstances it is called.

on_init_failed(*args, **kwargs)[source]

Inform Coherence that this backend has failed.

New in version 0.9.0.

upnp_init()[source]

This method gets called after the device is fired, here all initializations of service related state variables should happen, as the services aren’t available before that point.

class BackendStore(server, *args, **kwargs)[source]

Bases: coherence.backend.Backend

The base class for all MediaServer backend stores. Inherits from class Backend and extends his capabilities to make easy to create a Backend Store by setting an initial wmc mapping, and defining some attributes and methods needed by a Backend Store.

Parameters
  • server (object) – This usually should be an instance of our main class Coherence (the UPnP device that’s hosting our backend).

  • *args (list) – A list with extra arguments for the backend. This, must be implemented into the subclass (if needed).

  • **kwargs (dict) – An unpacked dictionary with the backend’s configuration.

Note

In case we want so serve something via the MediaServer web backend, the class BackendItem should pass an URI assembled of urlbase + ‘/’ + id to the Resource.

Warning

Remember to sent the event init_completed via setting to True the attribute init_completed. Check the base class Backend for instructions about how to do it.

logCategory = 'backend_store'
__init__(server, *args, **kwargs)[source]
Parameters
  • server (object) – This usually should be an instance of our main class Coherence (the UPnP device that’s hosting our backend).

  • *args (list) – A list with extra arguments for the backend. This, must be implemented into the subclass (if needed).

  • **kwargs (dict) – An unpacked dictionary with the backend’s configuration.

Note

In case we want so serve something via the MediaServer web backend, the class BackendItem should pass an URI assembled of urlbase + ‘/’ + id to the Resource.

Warning

Remember to sent the event init_completed via setting to True the attribute init_completed. Check the base class Backend for instructions about how to do it.

release()[source]

If anything needs to be cleaned up upon shutdown of this backend, this is the place for it. Should be overwritten in subclass.

_get_all_items(id)[source]

A helper method to get all items as a response to some XBox 360 UPnP Search action probably never be used as the backend will overwrite the wmc_mapping with more appropriate methods.

get_by_id(id)[source]
Parameters

id (object) – is the id property of our DIDLLite item

Returns

  • None when no matching item for that id is found,

  • a BackendItem,

  • or a Deferred

Called by the CDS or the MediaServer web.

Note

if this MediaServer implements containers that can share their content, like ‘all tracks’, ‘album’ and ‘album_of_artist’ (they all have the same track item as content), then the id may be passed by the CDS like this:

‘id@container’ or ‘id@container@container@container…’

therefore a

if isinstance(id, basestring):
    id = id.split('@',1)
    id = id[0]

may be appropriate as the first thing to do when entering this method.

class BackendItem(*args, **kwargs)[source]

Bases: eventdispatcher.eventdispatcher.EventDispatcher, coherence.log.LogAble

This is the base class for all MediaServer backend items.

Most of the time we collect the necessary data for an UPnP ContentDirectoryService Container or Object and instantiate it into the __init__()

self.item = DIDLLite.Container(id,parent_id,name,...)

or

self.item = DIDLLite.MusicTrack(id,parent_id,name,...)

To make that a valid UPnP CDS Object it needs one or more DIDLLite. Resource

self.item.res = []
res = DIDLLite.Resource(url, f'http-get:*:{mimetype}:*')
res.size = size
self.item.res.append(res)

Note

url should be the urlbase of our backend + ‘/’ + our id.

    Changed in version 0.9.0:
  • Introduced inheritance from EventDispatcher

  • Moved class variable update_id to class Container.update_id

  • Added class variable mimetype to benefit from the EventDispatcher’s properties

logCategory = 'backend_item'
name = 'backend_item_name'

the basename of a file, the album title, the artists name…is expected to be unicode

location = None

the filepath of our media file, or alternatively a FilePath or a ReverseProxyResource object

cover = None

if we have some album art image, let’s put the filepath or link into here

store = None

The backend store.

storage_id = None

The id of the backend store.

item = None

Usually an atomic object from Item or derived.

mimetype

The mimetype variable describes the protocol info for the object.

get_children(start=0, end=0)[source]

Called by the CDS and the MediaServer web.

Parameters
  • start (int) – the start.

  • end (int) – the end.

Returns

  • a list of its childs, from start to end.

  • or a Deferred

get_child_count()[source]

Called by the CDS.

Returns

  • the number of its childs - len(childs)

  • or a Deferred

get_item()[source]

Called by the CDS and the MediaServer web.

Returns

  • an UPnP ContentDirectoryServer DIDLLite object

  • or a Deferred

get_name()[source]

Called by the MediaServer web.

Returns

the name of the item, it is always expected to be in unicode.

get_path()[source]

Called by the MediaServer web.

Returns

the filepath where to find the media file that this item does refer to.

get_cover()[source]

Called by the MediaServer web.

Returns

the filepath where to find the album art file

Note

only needed when we have created for that item an albumArtURI property that does point back to us.

class BackendRssMixin[source]

Bases: object

update_data(rss_url, container=None)[source]

Creates a deferred chain to retrieve the rdf file, parse and extract the metadata and reschedule itself.

parse_data(xml_data, container)[source]

Extract media info and create BackendItems

queue_update(error_or_failure, rss_url, container)[source]
class Container(parent, title)[source]

Bases: coherence.backend.BackendItem

Represents a backend item which will contains backend items inside.

update_id

It represents the update id of thhe container. This should be incremented on every modification of the UPnP ContentDirectoryService Container, as we do in methods add_child() and remove_child().

children

A list of the backend items.

children_ids

A dictionary of the backend items by his id.

children_by_external_id

A dictionary of the backend items by his external id.

parent_id = -1

The id of the parent object. This will be automatically set whenever we set the attribute parent.

mimetype = 'directory'

The mimetype variable describes the protocol info for the object. In a Container this should be set to value directory or root.

parent

The parent object for this class.

on_parent(parent)[source]
register_child(child, external_id=None)[source]
add_child(child, external_id=None, update=True)[source]
remove_child(child, external_id=None, update=True)[source]
get_children(start=0, end=0)[source]

Called by the CDS and the MediaServer web.

Parameters
  • start (int) – the start.

  • end (int) – the end.

Returns

  • a list of its childs, from start to end.

  • or a Deferred

get_child_count()[source]

Called by the CDS.

Returns

  • the number of its childs - len(childs)

  • or a Deferred

get_path()[source]

Called by the MediaServer web.

Returns

the filepath where to find the media file that this item does refer to.

get_item()[source]

Called by the CDS and the MediaServer web.

Returns

  • an UPnP ContentDirectoryServer DIDLLite object

  • or a Deferred

get_name()[source]

Called by the MediaServer web.

Returns

the name of the item, it is always expected to be in unicode.

get_id()[source]
get_update_id()[source]
class LazyContainer(parent, title, external_id=None, refresh=0, childrenRetriever=None, **kwargs)[source]

Bases: coherence.backend.Container

logCategory = 'lazyContainer'
replace_by(item)[source]
add_child(child, external_id=None, update=True)[source]
update_children(new_children, old_children)[source]
start_children_retrieval_campaign()[source]
end_children_retrieval_campaign(success=True)[source]
retrieve_children(start=0, page=0)[source]
retrieve_all_children(start=0, request_count=0)[source]
get_children(start=0, request_count=0)[source]

Called by the CDS and the MediaServer web.

Parameters
  • start (int) – the start.

  • end (int) – the end.

Returns

  • a list of its childs, from start to end.

  • or a Deferred

class AbstractBackendStore(server, **kwargs)[source]

Bases: coherence.backend.BackendStore

len()[source]
set_root_item(item)[source]
get_root_id()[source]
get_root_item()[source]
append_item(item, storage_id=None)[source]
remove_item(item)[source]
get_by_id(id)[source]
Parameters

id (object) – is the id property of our DIDLLite item

Returns

  • None when no matching item for that id is found,

  • a BackendItem,

  • or a Deferred

Called by the CDS or the MediaServer web.

Note

if this MediaServer implements containers that can share their content, like ‘all tracks’, ‘album’ and ‘album_of_artist’ (they all have the same track item as content), then the id may be passed by the CDS like this:

‘id@container’ or ‘id@container@container@container…’

therefore a

if isinstance(id, basestring):
    id = id.split('@',1)
    id = id[0]

may be appropriate as the first thing to do when entering this method.

getnextID()[source]

coherence.base (module)

Base

The core of the project. Holds the class Coherence intended to be used to manage all the resources of the project. Also contains some other classes which are vital to the project.

SimpleRoot

A web resource representing a web site. Used to build the contents browser for our instance of a WebServer or WebServerUi.

WebServer

A class which takes care of dealing with the web representation of the running Coherence’s instance. This is the default webserver used.

WebServerUi

The default web server, WebServer, can be replaced by this class which will do the same thing as the default web server, but with a more polished interface.

Plugins

Manage all the available plugins for the Cohen3 project.

Coherence

The Main class of the Cohen3 project. The Coherence class controls all the servers initialization depending on the configuration passed.

class SimpleRoot(coherence)[source]

Bases: twisted.web.resource.Resource, coherence.log.LogAble

addSlash = True
logCategory = 'coherence'
getChild(name, request)[source]

Retrieve a ‘child’ resource from me.

Implement this to create dynamic resource generation – resources which are always available may be registered with self.putChild().

This will not be called if the class-level variable ‘isLeaf’ is set in your subclass; instead, the ‘postpath’ attribute of the request will be left as a list of the remaining path elements.

For example, the URL /foo/bar/baz will normally be:

| site.resource.getChild('foo').getChild('bar').getChild('baz').

However, if the resource returned by ‘bar’ has isLeaf set to true, then the getChild call will never be made on it.

Parameters and return value have the same meaning and requirements as those defined by L{IResource.getChildWithDefault}.

listchilds(uri)[source]
render(request)[source]

Render a given resource. See L{IResource}’s render method.

I delegate to methods of self with the form ‘render_METHOD’ where METHOD is the HTTP that was used to make the request. Examples: render_GET, render_HEAD, render_POST, and so on. Generally you should implement those methods instead of overriding this one.

render_METHOD methods are expected to return a byte string which will be the rendered page, unless the return value is C{server.NOT_DONE_YET}, in which case it is this class’s responsibility to write the results using C{request.write(data)} and then call C{request.finish()}.

Old code that overrides render() directly is likewise expected to return a byte string or NOT_DONE_YET.

@see: L{IResource.render}

class WebServer(ui, port, coherence)[source]

Bases: coherence.log.LogAble

logCategory = 'webserver'
_endpoint_listen(coherence, port)[source]
class WebServerUi(port, coherence, unittests=False)[source]

Bases: coherence.base.WebServer

logCategory = 'webserverui'
_endpoint_listen(coherence, port)[source]
_ws_endpoint_listen(coherence)[source]
class Plugins(ids=('coherence.plugins.backend.media_server', 'coherence.plugins.backend.media_renderer', 'coherence.plugins.backend.binary_light', 'coherence.plugins.backend.dimmable_light'))[source]

Bases: coherence.log.LogAble

logCategory = 'plugins'
_valids = ('coherence.plugins.backend.media_server', 'coherence.plugins.backend.media_renderer', 'coherence.plugins.backend.binary_light', 'coherence.plugins.backend.dimmable_light')
_plugins = {}
get(key, default=None)[source]
set(key, value)[source]
keys()[source]
_collect_from_module()[source]
_Plugins__initialized = False
_Plugins__instance = None
class Coherence(config=None)[source]

Bases: eventdispatcher.eventdispatcher.EventDispatcher, coherence.log.LogAble

The Main class of the Cohen3 project. The Coherence class controls all the servers initialization depending on the configuration passed. It is also capable of initialize the plugins defined in config variable or by configuration file. It supports the creation of multiple servers at once.

Example of a simple server via plugin AppleTrailersStore:

from coherence.base import Coherence
from coherence.upnp.core.uuid import UUID
from twisted.internet import reactor
new_uuid = UUID()

coherence = Coherence(
    {'logmode': 'info',
     'controlpoint': 'yes',
     'plugin': [{'backend': 'AppleTrailersStore',
                'name': 'Cohen3 Example FSStore',
                'uuid': new_uuid,
                }
                ]
     }
)
reactor.run()
    Changed in version 0.9.0:
  • Introduced inheritance from EventDispatcher

  • The emitted events changed:

    • Coherence.UPnP.Device.detection_completed => coherence_device_detection_completed

    • Coherence.UPnP.Device.removed => coherence_device_removed

    • Coherence.UPnP.RootDevice.removed => coherence_root_device_removed

  • Changed some variables to benefit from the EventDispatcher’s properties:

logCategory = 'coherence'
devices

A list of the added devices.

children

A dict containing the web resources.

_callbacks

A dict containing the callbacks, used by the methods subscribe() and unsubscribe().

active_backends

A dict containing the active backends.

ctrl

A coherence’s instance of class ControlPoint. This will be enabled if we request it by config dict or configuration file via keyword controlpoint = yes.

dbus

A coherence’s instance of class DBusPontoon. This will be enabled if we request it by config dict or configuration file via keyword use_dbus = yes.

json

A coherence’s instance of class JsonInterface. This will be enabled if we request it by config dict or configuration file via keyword json = yes.

msearch

A coherence’s instance of class MSearch. This is automatically enabled when Coherence is initialized

ssdp_server

A coherence’s instance of class SSDPServer. This is automatically enabled when Coherence is initialized

transcoder_manager

A coherence’s instance of class TranscoderManager. This will be enabled if we request itby config dict or configuration file via keyword transcoding = yes.

web_server

A coherence’s instance of class WebServer or WebServerUi. We can request our preference by config dict or configuration file. If we use the keyword web-ui = yes, then the class WebServerUi will be used, otherwise, the enabled web server will be of class WebServer.

clear()[source]

We do need this to survive multiple calls to Coherence during trial tests

setup_part2()[source]

Initializes the basic and optional services/devices and the enabled plugins (backends).

add_plugin(plugin, **kwargs)[source]
remove_plugin(plugin)[source]

Removes a backend from Coherence

Parameters

plugin (object) – is the object return by add_plugin or an UUID string.

static writeable_config()[source]

Do we have a new-style config file

store_plugin_config(uuid, items)[source]

Find the backend with uuid and store in its the config the key and value pair(s).

receiver(signal, *args, **kwargs)[source]
shutdown(force=False)[source]
check_devices()[source]

Iterate over devices and their embedded ones and renew subscriptions.

subscribe(name, callback)[source]
unsubscribe(name, callback)[source]
callback(name, *args)[source]
_Coherence__cls = None
_Coherence__incarnations = 0
_Coherence__initialized = False
_Coherence__instance = None
get_device_by_host(host)[source]
get_device_with_usn(usn)[source]
get_device_with_id(device_id)[source]
get_devices()[source]
get_local_devices()[source]
get_nonlocal_devices()[source]
is_device_added(infos)[source]

Check if the device exists in our list of created devices.

Parameters

infos (dict) – Information about the device

Returns

True if the device exists in our list of devices, otherwise, returns False.

New in version 0.9.0.

create_device(device_type, infos)[source]
add_device(device, *args)[source]
remove_device(device_type, infos)[source]
add_web_resource(name, sub)[source]
remove_web_resource(name)[source]
static check_louie(receiver, signal, method='connect')[source]

Check if the connect or disconnect method’s arguments are valid in order to automatically convert to EventDispatcher’s bind The old valid signals are:

  • Coherence.UPnP.Device.detection_completed

  • Coherence.UPnP.RootDevice.detection_completed

  • Coherence.UPnP.Device.removed

  • Coherence.UPnP.RootDevice.removed

New in version 0.9.0.

connect(receiver, signal=None, sender=None, weak=True)[source]

Wrapper method around the deprecated method louie.connect. It will check if the passed signal is supported by executing the method check_louie().

Warning

This will probably be removed at some point, if you use the connect method you should migrate to the new event system EventDispatcher.

Changed in version 0.9.0: Added EventDispatcher’s compatibility for some basic signals

disconnect(receiver, signal=None, sender=None, weak=True)[source]

Wrapper method around the deprecated method louie.disconnect. It will check if the passed signal is supported by executing the method check_louie().

Warning

This will probably be removed at some point, if you use the disconnect method you should migrate to the new event system EventDispatcher.

Changed in version 0.9.0: Added EventDispatcher’s compatibility for some basic signals

coherence.dbus_constants (module)

coherence.dbus_service (module)

coherence.json_service (module)

class JsonInterface(controlpoint)[source]

Bases: twisted.web.resource.Resource, coherence.log.LogAble

logCategory = 'json'
render_GET(request)[source]
render_POST(request)[source]
getChildWithDefault(path, request)[source]

Retrieve a static or dynamically generated child resource from me.

First checks if a resource was added manually by putChild, and then call getChild to check for dynamic resources. Only override if you want to affect behaviour of all child lookups, rather than just dynamic ones.

This will check to see if I have a pre-registered child resource of the given name, and call getChild if I do not.

@see: L{IResource.getChildWithDefault}

do_the_render(request)[source]
list_devices(request)[source]
call_action(action, request)[source]

coherence.log (module)

get_main_log_level()[source]
formatter_message(message, use_color=True)[source]
class ColoredFormatter(msg, use_color=True)[source]

Bases: logging.Formatter

format(record)[source]

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

class ColoredLogger(name)[source]

Bases: logging.Logger

FORMAT = '[%(levelname)-18s][$BOLD%(name)-15s$RESET] %(message)s ($BOLD%(filename)s$RESET:%(lineno)d)'
COLOR_FORMAT = '[%(levelname)-18s][\x1b[1m%(name)-15s\x1b[0m] %(message)s (\x1b[1m%(filename)s\x1b[0m:%(lineno)d)'
findCaller(stack_info=False, use_color=True)[source]

Find the stack frame of the caller so that we can note the source file name, line number and function name.

class LogAble[source]

Bases: object

Base class for objects that want to be able to log messages with different level of severity. The levels are, in order from least to most: log, debug, info, warning, error.

logCategory = 'default'

Implementors can provide a category to log their messages under.

_Loggable__logger = None
FORMAT = '[%(levelname)-18s][$BOLD%(name)-15s$RESET] %(message)s ($BOLD%(filename)s$RESET:%(lineno)d)'
COLOR_FORMAT = '[%(levelname)-18s][\x1b[1m%(name)-15s\x1b[0m] %(message)s (\x1b[1m%(filename)s\x1b[0m:%(lineno)d)'
log(message, *args, **kwargs)[source]
warning(message, *args, **kwargs)[source]
info(message, *args, **kwargs)[source]
critical(message, *args, **kwargs)[source]
debug(message, *args, **kwargs)[source]
error(message, *args, **kwargs)[source]
exception(message, *args, **kwargs)[source]
fatal(message, *args, **kwargs)
warn(message, *args, **kwargs)
msg(message, *args, **kwargs)
get_logger(log_category)[source]
init(logfilename=None, loglevel=30)[source]

coherence.transcoder (module)

Transcoder classes to be used in combination with a Coherence MediaServer, using GStreamer pipelines for the actually work and feeding the output into a http response.

get_transcoder_name(transcoder)[source]
class InternalTranscoder[source]

Bases: object

Just a class to inherit from and which we can look for upon creating our list of available transcoders.

class FakeTransformer(destination=None, request=None)[source]

Bases: gi.repository.Gst.Element, coherence.log.LogAble

logCategory = 'faker_datasink'
_sinkpadtemplate = <Gst.PadTemplate object at 0x7f2a9b219948 (GstPadTemplate at 0x38159f0)>
_srcpadtemplate = <Gst.PadTemplate object at 0x7f2a9b219510 (GstPadTemplate at 0x3815a80)>
get_fake_header()[source]
chainfunc(pad, buffer)[source]
class DataSink(destination=None, request=None)[source]

Bases: gi.repository.Gst.Element, coherence.log.LogAble

logCategory = 'transcoder_datasink'
_sinkpadtemplate = <Gst.PadTemplate object at 0x7f2a9b219a68 (GstPadTemplate at 0x3815b10)>
chainfunc(pad, inst, buffer)[source]
eventfunc(pad, inst, event)[source]
class GStreamerPipeline(pipeline, content_type)[source]

Bases: twisted.web.resource.Resource, coherence.log.LogAble

logCategory = 'gstreamer'
addSlash = True
parse_pipeline()[source]
start(request=None)[source]
new_preroll(appsink)[source]
new_buffer(appsink)[source]
eos(appsink)[source]
getChild(name, request)[source]

Retrieve a ‘child’ resource from me.

Implement this to create dynamic resource generation – resources which are always available may be registered with self.putChild().

This will not be called if the class-level variable ‘isLeaf’ is set in your subclass; instead, the ‘postpath’ attribute of the request will be left as a list of the remaining path elements.

For example, the URL /foo/bar/baz will normally be:

| site.resource.getChild('foo').getChild('bar').getChild('baz').

However, if the resource returned by ‘bar’ has isLeaf set to true, then the getChild call will never be made on it.

Parameters and return value have the same meaning and requirements as those defined by L{IResource.getChildWithDefault}.

render_GET(request)[source]
render_HEAD(request)[source]

Default handling of HEAD method.

I just return self.render_GET(request). When method is HEAD, the framework will handle this correctly.

requestFinished(result, request)[source]
on_message(bus, message)[source]
cleanup()[source]
class BaseTranscoder(uri, destination=None, content_type=None)[source]

Bases: twisted.web.resource.Resource, coherence.log.LogAble

logCategory = 'transcoder'
addSlash = True
getChild(name, request)[source]

Retrieve a ‘child’ resource from me.

Implement this to create dynamic resource generation – resources which are always available may be registered with self.putChild().

This will not be called if the class-level variable ‘isLeaf’ is set in your subclass; instead, the ‘postpath’ attribute of the request will be left as a list of the remaining path elements.

For example, the URL /foo/bar/baz will normally be:

| site.resource.getChild('foo').getChild('bar').getChild('baz').

However, if the resource returned by ‘bar’ has isLeaf set to true, then the getChild call will never be made on it.

Parameters and return value have the same meaning and requirements as those defined by L{IResource.getChildWithDefault}.

render_GET(request)[source]
render_HEAD(request)[source]

Default handling of HEAD method.

I just return self.render_GET(request). When method is HEAD, the framework will handle this correctly.

requestFinished(result)[source]
on_message(bus, message)[source]
cleanup()[source]
start(request=None)[source]

This method should be sub classed for each class which inherits from BaseTranscoder

class PCMTranscoder(uri, destination=None, content_type=None)[source]

Bases: coherence.transcoder.BaseTranscoder, coherence.transcoder.InternalTranscoder

contentType = 'audio/L16;rate=44100;channels=2'
name = 'lpcm'
start(request=None)[source]

This method should be sub classed for each class which inherits from BaseTranscoder

class WAVTranscoder(uri, destination=None, content_type=None)[source]

Bases: coherence.transcoder.BaseTranscoder, coherence.transcoder.InternalTranscoder

contentType = 'audio/x-wav'
name = 'wav'
start(request=None)[source]

This method should be sub classed for each class which inherits from BaseTranscoder

class MP3Transcoder(uri, destination=None, content_type=None)[source]

Bases: coherence.transcoder.BaseTranscoder, coherence.transcoder.InternalTranscoder

contentType = 'audio/mpeg'
name = 'mp3'
start(request=None)[source]

This method should be sub classed for each class which inherits from BaseTranscoder

class MP4Transcoder(uri, destination=None, content_type=None)[source]

Bases: coherence.transcoder.BaseTranscoder, coherence.transcoder.InternalTranscoder

Only works if H264 inside Quicktime/MP4 container is input Source has to be a valid uri

contentType = 'video/mp4'
name = 'mp4'
start(request=None)[source]

This method should be sub classed for each class which inherits from BaseTranscoder

class MP2TSTranscoder(uri, destination=None, content_type=None)[source]

Bases: coherence.transcoder.BaseTranscoder, coherence.transcoder.InternalTranscoder

contentType = 'video/mpeg'
name = 'mpegts'
start(request=None)[source]

This method should be sub classed for each class which inherits from BaseTranscoder

class ThumbTranscoder(uri, destination=None, content_type=None)[source]

Bases: coherence.transcoder.BaseTranscoder, coherence.transcoder.InternalTranscoder

Should create a valid thumbnail according to the DLNA spec

Warning

Neither width nor height must exceed 160px

contentType = 'image/jpeg'
name = 'thumb'
start(request=None)[source]

This method should be sub classed for each class which inherits from BaseTranscoder

class GStreamerTranscoder(uri, destination=None, content_type=None)[source]

Bases: coherence.transcoder.BaseTranscoder

A generic Transcoder based on GStreamer.

pipeline_description = None

The pipeline which will be parsed upon calling the start method, has to be set as the attribute pipeline_description to the instantiated class.

start(request=None)[source]

This method should be sub classed for each class which inherits from BaseTranscoder

class ExternalProcessProtocol(caller)[source]

Bases: twisted.internet.protocol.ProcessProtocol

connectionMade()[source]

Called when a connection is made.

This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.

outReceived(data)[source]

Some data was received from stdout.

errReceived(data)[source]

Some data was received from stderr.

inConnectionLost()[source]

This will be called when stdin is closed.

outConnectionLost()[source]

This will be called when stdout is closed.

errConnectionLost()[source]

This will be called when stderr is closed.

processEnded(status_object)[source]

Called when the child process exits and all file descriptors associated with it have been closed.

@type reason: L{twisted.python.failure.Failure}

class ExternalProcessProducer(pipeline, request)[source]

Bases: object

logCategory = 'externalprocess'
write_data(data)[source]
resumeProducing()[source]
pauseProducing()[source]
stopProducing()[source]
class ExternalProcessPipeline(uri)[source]

Bases: twisted.web.resource.Resource, coherence.log.LogAble

logCategory = 'externalprocess'
addSlash = False
pipeline_description = None
contentType = None
getChildWithDefault(path, request)[source]

Retrieve a static or dynamically generated child resource from me.

First checks if a resource was added manually by putChild, and then call getChild to check for dynamic resources. Only override if you want to affect behaviour of all child lookups, rather than just dynamic ones.

This will check to see if I have a pre-registered child resource of the given name, and call getChild if I do not.

@see: L{IResource.getChildWithDefault}

render(request)[source]

Render a given resource. See L{IResource}’s render method.

I delegate to methods of self with the form ‘render_METHOD’ where METHOD is the HTTP that was used to make the request. Examples: render_GET, render_HEAD, render_POST, and so on. Generally you should implement those methods instead of overriding this one.

render_METHOD methods are expected to return a byte string which will be the rendered page, unless the return value is C{server.NOT_DONE_YET}, in which case it is this class’s responsibility to write the results using C{request.write(data)} and then call C{request.finish()}.

Old code that overrides render() directly is likewise expected to return a byte string or NOT_DONE_YET.

@see: L{IResource.render}

transcoder_class_wrapper(klass, content_type, pipeline)[source]
class TranscoderManager(coherence=None)[source]

Bases: coherence.log.LogAble

Singleton class which holds information about all available transcoders. They are put into a transcoders dict with their id as the key.

We collect all internal transcoders by searching for all subclasses of InternalTranscoder, the class will be the value.

Transcoders defined in the config are parsed and stored as a dict in the transcoders dict.

In the config, a transcoder description has to look like this:

* preliminary, will be extended and might even change without further notice *

<transcoder>
    <pipeline>%s ...</pipeline> <!-- we need a %s here to insert the
                                    source uri (or can we have all the
                                    times pipelines we can prepend with
                                    a '%s !') and an element named mux
                                    where we can attach our sink -->
    <type>gstreamer</type>      <!-- could be gstreamer or process -->
    <name>mpegts</name>
    <target>video/mpeg</target>
    <fourth_field>              <!-- value for the 4th field of the
                                    protocolInfo phalanx, default is
                                    '*' -->
</transcoder>

Initializes the class TranscoderManager.

It should be called at least once with the main Coherence class passed as an argument, so we have access to the config.

logCategory = 'transcoder_manager'
_instance_ = None
__init__(coherence=None)[source]

Initializes the class TranscoderManager.

It should be called at least once with the main Coherence class passed as an argument, so we have access to the config.

select(name, uri, backend=None)[source]

coherence.tube_service (module)