SReview containers a number of internal APIs, which are useful to know about if you want to administer the SReview system. Additionally, if you want to contribute to SReview, it helps to be aware of them.
The APIs are documented in POD format, but it's useful to have a bit of an overview; that's what this document attempts to provide.
The SReview::Files API provides access to media files. Any component
of the system that wants to access a file must use this API. This
allows for abstracting away the way in which the files are accessed. As
of this writing, implementations exist to access and detect files
directly on the filesystem (locally or via NFS), via an Amazon
S3-compatible API, via plain HTTP, via HTTP with nginx JSON indexes, and
via SSH.
The Files API places each file in a "collection". A collection is a
logical grouping of files that can be accessed in a uniform way. For
instance, the "input directory" (as configured through the inputglob
configuration parameter) defines one collection.
The SReview::Files implementation to access files is configured at the
collection level, through the accessmethods configuration parameter.
This parameter should be a hash where each key is the name of a
collection to configure the collection implementation for, and the value
is the name of the implementing collection class, with the
SReview::Files::Collection:: prefix dropped.
If the accessmethods configuration item does not contain a key for the
relevant collection, then the collection cannot be created and SReview
will produce an error.
SReview requires at least three collections:
- The
inputcollection contains raw files as they are received from the camera. The location where files in this collection are found is configured by theinputglobconfiguration item. For backwards compatibility reasons, this collection looks for files by way of an input glob, rather than a root URL; it is the only collection which requires that, but this distinction may be removed at a future point. - The
intermediatecollection contains the files that are served to the public for the review webinterface. The location where files in this collection are found is configured by thepubdirconfiguration item. For the webinterface to work, it must be served on the URL configured by thevid_prefixconfiguration item (which may be host-relative if it is served on the same hostname as the SReview webinterface itself). - The
outputcollection contains the finalized files that are produced by SReview. The location for this collection is configured by theoutputdirconfiguration item. This is the location where all transcoded files (the output of SReview) are written to bysreview-transcode; thesreview-uploadscript, however, reads files from this collection. If theoutputdiris somehow directly readable over the Internet, then the use ofsreview-uploadis not required and theuploadingstate can be skipped. However, this may not be desireable, as thedirectimplementation (for direct filesystem access) does not use temporary files and writes directly to this collection, which may therefore result in incomplete files appearing to users.
These three collections are not optional and therefore assumed to always be present.
If the inject functionality is enabled, then an extra collection, the
name of which should be specified the inject_collection configuration
item, is required. When doing so, an entry for the collection should be
present in the accessmethods configuration item, and the
extra_collections configuration item (which should also be a hash)
should contain a key for the same collection name with as its value the
base URL of the collection.
In some cases, it may be desireable to copy the files from one
collection to another as a way to upload scripts from the
sreview-upload script. In that case, the sreview-copy script can be
used, with relevant values in the accessmethods and
extra_collections configuration items.
Creating an object is done by way of the SReview::Files::Factory::create
method. See the POD documentation for SReview::Files::Factory for details.
All SReview configuration is done through two dedicated modules,
SReview::Config and SReview::Config::Common. The former provides the
API, whereas the latter provides the specific configuration variables
used by SReview.
SReview supports setting configuration in the following ways:
-
Via environment variables. When doing so, the name of the environment variable should be the name of the configuration variable in upper case, prefixed with
SREVIEW_. For instance, the configuration iteminput_profilecan be set through the environment variableSREVIEW_INPUT_PROFILE. Each environment variable must be encoded in JSON; this includes strings, which means they need to have embedded quotes. -
Via a configuration file, which is found using the following algorithm:
- If an environment variable
SREVIEW_WDIRexists, look for a fileconfig.pmin the directory pointed to by that variable. If it exists, use that. - If a file
config.pmexists in the current working directory, use that. - If a file
config.pmexists in the directory/etc/sreview, use that.
- If an environment variable
If a value is set in an environment variable, it takes precedence over any value in the configuration file. If a value is not set in an environment variable, and no value exists in a configuration file, the built-in defaults, if any, will be used.
If environment variables are set and a configuration file is found too, then both take effect. However, only one configuration file will be considered; you can't have multiple configuration files. That said, as the configuration file is a perl script, you can include a different configuration file using normal perl syntax.
A dedicated tool, sreview-config, exists to manage configuration
items. It will parse the configuration in exactly the same way that the
other tools do, and it will then allow you to do things with that parsed
configuration.
It can:
- Rewrite the configuration file with the default comments and all configuration values that are set to non-default values explicitly set;
- Dump the configuration file as it would be written by step 1. to
standard output (note: redirecting this output to a file that is
in the search path of the current configuration will result in
sreview-configfinding an empty file, which means it will set everything to defaults; do not do that); - Extract the value of one specific configuration item to standard output (in JSON format);
- Allow you to override one specific value on the command line before doing any of the above. However, this option only works for string options, and does not use the JSON encoding; it is therefore not recommended. Instead, you should set environment variables to override single options if you need to do this.
For more details, see the L manual page.