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)[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.
-
-
class
ExternalProcessPipeline
(pipeline, mimetype)[source]¶ Bases:
twisted.web.resource.Resource
,coherence.log.LogAble
-
logCategory
= 'externalprocess'¶
-
addSlash
= True¶
-
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
ExternalProcessProducer
(pipeline, request)[source]¶ Bases:
coherence.log.LogAble
-
logCategory
= 'externalprocess'¶
-
addSlash
= True¶
-
-
class
Item
(parent, id, title, location, url)[source]¶ Bases:
coherence.backend.BackendItem
-
get_item
()[source]¶ called by the CDS and the MediaServer web should return
- an UPnP ContentDirectoryServer DIDLLite object
- or a Deferred
-
get_name
()[source]¶ called by the MediaServer web should return
- the name of the item, it is always expected to be in unicode
-
-
class
ResourceItem
(parent, id, title, location, url)[source]¶ Bases:
coherence.backends.test_storage.Item
-
get_name
()[source]¶ called by the MediaServer web should return
- the name of the item, it is always expected to be in unicode
-
-
class
Container
(id, store, parent_id, title)[source]¶ Bases:
coherence.backend.BackendItem
-
get_children
(start=0, end=0)[source]¶ called by the CDS and the MediaServer web should return
- a list of its childs[start:end]
- or a Deferred
if end == 0, the request is for all childs after start - childs[start:]
-
get_child_count
()[source]¶ called by the CDS should return
- the number of its childs - len(childs)
- or a Deferred
-
get_path
()[source]¶ called by the MediaServer web should return
- 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 should return
- an UPnP ContentDirectoryServer DIDLLite object
- or a Deferred
-
-
class
TestStore
(server, *args, **kwargs)[source]¶ Bases:
coherence.backend.BackendStore
-
implements
= ['MediaServer']¶
-
get_by_id
(id)[source]¶ called by the CDS or the MediaServer web
id is the id property of our DIDLLite item
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
should return
- None when no matching item for that id is found,
- a BackendItem,
- or a Deferred
-