coherence.backends.test_storage (module) — Cohen3 0.8.0 documentation

# coherence.backends.test_storage (module)

A MediaServer backend to test Items.

Item information can be passed on the commandline or in the config as an XML fragment:

    coherence --plugin=backend:TestStore,name:Test,\
       item:<item><location>audio.mp3</location>\
            <mimetype>audio/mpeg</mimetype></item>,\
       item:<item><location>audio.ogg</location>\
            <mimetype>audio/ogg</mimetype></item>

    coherence --plugin='backend:TestStore,name:Test,\
       item:<item><type>gstreamer</type>\
            <pipeline>v4l2src num-buffers=1 ! video/x-raw-yuv,width=640,\
            height=480 ! ffmpegcolorspace ! jpegenc name=enc</pipeline>\
            <mimetype>image/jpeg></mimetype></item>'

‘video/x-raw-yuv,width=640,height=480’ won’t work here as it is a delimiter for the plugin string, so if you need things like that in the pipeline, you need to use a config file:

    coherence --plugin='backend:TestStore,name:Test,\
        item:<item><type>process</type>\
            <command>man date</command>\
            <mimetype>text/html</mimetype></item>'

The XML fragment has these elements:

> - type:
>   - file: the item is some file-system object (default)
>   - url: an item pointing to an object off-site
>   - gstreamer: the item is actually a GStreamer pipeline
>   - process: the items content is created by an external process
> - location: the filesystem path or an url (mandatory)
> - mimetype: the mimetype of the item (mandatory)
> - extension: an optional extension to append to the url created for the DIDLLite resource data
> - title: the ‘title’ this item should have (optional)
> - upnp_class: the DIDLLite class the item shall have, object.item will be taken as default
> - fourth_field: value for the 4th field of the protocolInfo phalanx, default is ‘*’
> - pipeline: a GStreamer pipeline that has to end with a bin named ‘enc’, some pipelines do only work properly when we have a glib mainloop running, so coherence needs to be started with -o glib:yes
> - command: the commandline for an external script to run, its output will be returned as the items content

In the config file the definition of this backend could look like this:

    <plugin active='yes'>
        <backend>TestStore</backend>
        <name>Test</name>
        <item>
            <location>/tmp/audio.mp3</location>
            <mimetype>audio/mpeg</mimetype>
        </item>
        <item>
            <location>/tmp/audio.ogg</location>
            <mimetype>audio/ogg</mimetype>
         </item>
    </plugin>

class `ExternalProcessProtocol`(caller)

  Bases: `twisted.internet.protocol.ProcessProtocol`

  `connectionMade`()

    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)

    Some data was received from stdout.

  `errReceived`(data)

    Some data was received from stderr.

  `inConnectionLost`()

    This will be called when stdin is closed.

  `outConnectionLost`()

    This will be called when stdout is closed.

  `errConnectionLost`()

    This will be called when stderr is closed.

  `processEnded`(status_object)

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

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

class `ExternalProcessPipeline`(pipeline, mimetype)

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

  `logCategory` = 'externalprocess'
  `addSlash` = True
  `render`(request)

    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 `ExternalProcessProducer`(pipeline, request)

  Bases: `coherence.log.LogAble`

  `logCategory` = 'externalprocess'
  `addSlash` = True
  `write_data`(data)
  `resumeProducing`()
  `pauseProducing`()
  `stopProducing`()

class `Item`(parent, id, title, location, url)

  Bases: `coherence.backend.BackendItem`

  `get_item`()

    Called by the CDS and the MediaServer web.

    Returns: | an UPnP ContentDirectoryServer DIDLLite object or a Deferred

  `get_name`()

    Called by the MediaServer web.

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

  `get_path`()

    Called by the MediaServer web.

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

  `get_size`()

class `ResourceItem`(parent, id, title, location, url)

  Bases: `coherence.backends.test_storage.Item`

  `get_name`()

    Called by the MediaServer web.

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

  `get_path`()

    Called by the MediaServer web.

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

  `get_size`()

class `Container`(id, store, parent_id, title)

  Bases: `coherence.backend.BackendItem`

  `add_child`(child)
  `get_children`(start=0, end=0)

    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`()

    Called by the CDS.

    Returns: | the number of its childs - len(childs) or a Deferred

  `get_path`()

    Called by the MediaServer web.

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

  `get_item`()

    Called by the CDS and the MediaServer web.

    Returns: | an UPnP ContentDirectoryServer DIDLLite object or a Deferred

  `get_name`()

    Called by the MediaServer web.

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

  `get_id`()

class `TestStore`(server, *args, **kwargs)

  Bases: `coherence.backend.BackendStore`

  `implements` = ['MediaServer']
  `get_upnp_class`(name)
  `get_next_id`()
  `get_by_id`(id)

    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.