The TranscodingManager component is the entry point for executing transcoding requests in the Java environment. This class offers two different ways for constructing requests: OMA-based and simplified.
The part of API based on the OMA approach follows its specification and uses the TranscodingRequest and TranscodingResponse classes as the primary Data Transfer Objects to communicate with the transcoding server.
The first two methods: processSync() and processAsync() are the core for the whole framework. They send an OMA transcoding request to the server in synchronous and asynchronous mode respectively. The synchronous version returns a TranscodingResponse instance, which contains a set of JobResult instances for all scheduled jobs (see below). In case a client does not want to perform any transcoding, but merely load a source media file into the server's storage, there is a TranscodingUtils.setNoTranscoding() method available, which sets the appropriate flag. Once having a request sent, there are two simple methods to obtain the current status of any of its jobs: isSourceFileReady() and isTranscodedFileReady(). Both let clients check the availability of a source and an output media file respectively, whose processing has been previously scheduled by a job of the specified identity (within a given request). For those who require more detailed info the API offers getTranscodingInfo() method, through which client can obtain more detailed description of a job status. The returned JobResult object (returned as well within the processSync response) contains Output instance with the location (URL) of a result file (a source one in case of "no transcoding" flag imposed, otherwise a transcoded one). More information is carried within the JobResult.OutputMediaProperties' extension data. For clients convenience TranscodingUtils class offers two methods: getResultState() and getResultInfo(). The first returns phase (TranscodingState.getPhase()) and estimated progress (TranscodingState.getPercentage()) of a transcoding process. The latter one provides the detailed information about the result file. The result info covers: the file duration in seconds (if it is audio or video) and file size in KBs of a processed file. Both info refers either to a source or a transcoded file depending on "no transcoding" flag setting. In case of a source file one may get some additional data: the boolean value stating whether the source file has been loaded in its entirety, the optional number of downloaded segments (see DownloadTransformation) and its storage loading timestamp in milliseconds.
For those interested in a more straight-forward approach, there is a simplified slice of API available.
The methods are actually the counterparts of the API methods described before; instead of a fully-fledged request object these methods accept a URL of the media file to be transcoded along with a transcoding profile id and an optional size limit of the output file. As mentioned elsewhere the server maintains a list of predefined profiles (each with a unique id); each one is actually a predefined set of transcoding parameters. For the clients focused on mobile environments, the TranscodingManager component provides some utility methods for constructing transcoding requests on behalf of particular devices.
The first method constructs a transcoding request for a URL source of the media file, a User-Agent identifier corresponding to the mobile device, the actual media type (Image, Audio, Video or Text) and an optional size limit. The second enforces the desired dimensions of the output media file (which applies only to images and videos). Alternatively one may use the third option, which specifies the required media dimensions as percentage of a device screen size. Last but not least, there is the fourth method, by which the streaming transformation can be requested (videos only). In all these cases the server takes responsibility for translating the User-Agent string (with optional dimensions) into a set of transcoding parameters. Otherwise it is the client who has to provide values. Please mind that in case of audios and videos one has to specify proper codecs in mime format; please refer to a special MediaConstants class, which defines most popular codec names and content types.
Alembik SOAP service is built on the JAX-WS 2.1.x technology following the OMA STI guidelines. The WSDL file of the transcoding service is located at the following location (of any Alembik server instance):
Most WSDL service methods are the extact counterparts of those of TranscodingService; the only difference is that the asynchronous mode is not exposed through a separate method, but is enforced by passing the asynchro string in the TranscodingRequest's policyRef field. Please have a look at simple examples of SOAP envelopes, which represent transcoding request and transcoding response. The thorough description of service objects can be found in the OMA-STI specification. Note that several proprietary extensions have been added in all the places where OMA did not provide sufficient coverage. All of them are explained in detail in the sections relevant to the functionality they affect.
Another way for scheduling media transcoding is exposed through a set of Java servlets. The principal component of the HTTP API is org.alembik.http.SyncTranscodingServlet, which is mapped at the server-side by /transcode path. The servlet carries out transcoding in the synchronous mode and if successfully finished it redirects a client to a result file; in case of failure the client is served with an error image or page. Asynchronous processing is realized by org.alembik.http.AsyncTranscodingServlet, available through /transcodeAsync path. Unfortunately this mode is currently not supported in Tomcat container. The status checking mechanism comes with org.alembik.http.IsFileReadyServlet exposed via /isReady path. The components checks the transcoding process state and returns one of the following results:
Note that this servlet works in the same manner for both synchronous and asynchronous jobs. The fourth API component is org.alembik.http.TimeoutTranscodingServlet and it is mapped with /timeoutTranscode path. The servlet calls the standard (synchronous) transcoding servlet with a given connection timeout set for a given amount of milliseconds passed by timeout parameter (default value is 5000 milliseconds). If the waiting time elapses and there is no result available yet, it returns an error (see above). Hence if the transcoding process is finished on time (HTTP response arrival or job in the RELEASED state), it returns a result file; otherwise (socket timeout error or timeout expiry) it redirects client to an error image/page. As one may observe the servlet can be used for the asynchronous mode emulation in the application containers which do not support it. Moreover, clients can easily distinguish a failure from processing/release states by examining the HTTP response headers. All transcoding errors are returned/redirected with Alembik-Status header set to 404, which otherwise is set to 200. All the servlets work in a very intuitive manner; they accept all possible property names of OMA TranscodingJob object (including the composite ones too) as URL path parameters and directly returns transcoded output to the requesting client. The only exception are transformations and extension data properties, which are handled in a different manner. Any attribute for a particular transformation can be passed by appending the transformation name and then the attribute name itself (both dot-separated) to target.transformation prefix. The extension data maps are handled in a similar way: an extension property name has to be added just behind extensionData string of a pertinent object.
For the sake of making the URLs shorter there have been introduced several abbreviations:
All these constant values are defined in the Constants class. Below there are presented several examples of abbreviated URL parameters:
Note that transcoding a media file with a User-Agent as the sole "formatting" parameter requires determination of the proper result's media type:
The User-Agent itself can be passed either within HTTP header or as target.profileID parameter. Thus final URLs might look like those below:
Mind that Alembik API package contains the JobUtils class, which provides utility methods for converting a TranscodingJob object into a set of URL parameters and vice versa. Below there is a list of the most important and useful transcoding URL parameters accepted by Alembik transcoding servlets.
|