ITVC architecture

Introduction
The Internet Tablet Video Converter (from now on called ITVC) application is composed of two main components. The UI takes care of only the user interface and high level business logic, it does not process, or even handle, media files directly. This job is working with media files is delegated to a Media Handler process. This approach removes the burden of dealing with the universe of codecs and media conversion from the UI portion of the app and leaving it free to specialize in what it does best: top notch user interface and usability. This architecture also enables ITVC to use different multimedia frameworks seamlessly by isolating them in a completely independent process: the Media Handler.

But all that wouldn't mean much if the communication between ITVC and Media Handler was complicated and hard to implement. Thus the communication is done using simple XML-like elements via TCP sockets. Easy to debug, parse and implement.

This simple and modular architecture also opens the door for third-party developers to easily make their own Media Handlers.

This document describes how ITVC and a Media Handler interact. This is all that one needs to know to be able to develop a Media Handler or to write their own code to interface to it.

Overview
The Media Handler acts as a server listening for TCP connections on a given port. The GUI front end then opens one or more simultaneous client sockets to the Media Handler port and exchanges data in a 2-way communication

The Media Handler is launched by the main ITVC application, which reads the mhstarter.cfg file (in its main installation directory) to determine which application to actually launch.

You can start the built-in Media Handler provided by ITVC by launching it manually outside of the main application. To do this, simply open up a command line terminal and change directory to the place where the ITVC app was installed. The port to be listened to by the Media Handler is given as a parameter when launching it. The following command line command, for instance, will open a Media Handler using port 1234:

$> ./mediahandler 1234

Executing the Media Handler without specifying the port is considered to be an error.

There can be only one instance of a Media Handler implementation running at any given time. So when a Media Handler is started it should check whether there's already another instance of itself (regardless of the port being used) running and if that's the case it should quit (leaving the existing one untouched). Please note this design principle if you decide to implement your own Media Handler.

ITVC will maintain a separate idle connection to the Media Handler with the sole purpose of checking whether the Media Handler process is still running. Communication Protocol

All communication is done using commands from the ITVC to a Media Handler. The data transfered is XML-like elements using regular ASCII characters for the tags. They are XML-like elements instead of regular XML because their format is very limited and strict in order to make the implementation of a command parser as simple as possible. No whitespaces is allowed inside or between the tags. All commands follows this syntax:

param1|param2|param3|...

Where command-name is the name of the command that is being issued and paramN is the command's Nth parameter. Parameters are separated by a vertical bar "|". For example: Every single byte between "" and the first "|" is considered to be the first parameter.

All defined command names and parameter values are case sensitive (they should be lower case, more specifically).

If a command has no parameters, it will look like the following:



The collapsed format is not supported, so the following is invalid:



When the execution of a command has finished, Media Handler replies with:

value

Where value is the result value. If a command succeeds, Media Handler will return the following ASCII string to ITVC:

ok

The result value "ok" means a successful command execution. Any value different than that means an error. An error result should be a terse english sentence in ASCII. When possible, a Media Handler should try to use one of the defined error messages.

The communication that can happen between ITVC issuing a command and Media Handler replying the result varies according to the command that has been issued.

Commands
A Media Handler has the following commands:

fetch-info
Gathers information from the specified media file and, optionally, creates a thumbnail of it.

Parameters: 1. Media's full file path. 2. Optional. Full file path of the thumbnail to be generated.

Example:

/Users/foo/myvideo.mov|/Users/foo/myvideo_thumbnail.png

Before sending the command result element, Media Handler will send one or more media properties complying with the following format:

value

Where name and value are set according to the following table:

Example session:

ITVC -> Media Handler: /Users/foo/myvideo.mov|/Users/foo/myvideo_thumbnail.png

Media Handler -> ITVC: Ogg Vorbis

Media Handler -> ITVC: 182

Media Handler -> ITVC: 3072

Media Handler -> ITVC: ok

transcode
Converts the specified media file according to the given parameters saving the resulting file at the specified file path.

Parameters: 1. Input path. Full file path of the media that's going to be converted. 2. Output path. Full file path of the conversion result. 3. Width, in pixels, of the converted media file. 4. Height, in pixels, of the converted media file. 5. Preferred video compression technology. 6. Video data rate, in bits per second. 7. Audio data rate, in bits per second. 8. Video refresh rate, in frames per second.

If the video encoder specified in the fifth parameter is not available (or cannot be used for some reason), the Media Handler may fallback to a more convenient one without returning any error or specific feedback. This fallback action is considered a normal (although undesired) behavior.

The table below defines the valid values (along with their respective meanings) for the video compression parameter:

Example:

C:\temp\myvideo.wmv|C:\temp\myconvertedvideo.mp4|400|240|mpeg4|350000|128000|24

During the conversion, Media Handler will inform ITVC about the conversion progress by sending progress messsages at arbitrary time intervals. Those messages have the following format:

number

Where number is a positive integer from 0 (inclusive, meaning 0% done) to 10000 (inclusive, meaning 100% done).

When Media Handler sends a progress status message, it waits for a response from ITVC on whether it should continue converting or promptly abort the conversion. The progress reply from ITVC has the following format:

value

Where value can be either "proceed", meaning that Media Handler should proceed with the conversion, or "abort", meaning that the conversion should stop at once.

Example session:

ITVC -> Media Handler: C:\temp\myvideo.wmv|C:\temp\myconvertedvideo.mp4|400|240|mpeg4|350000|128000|24

Media Handler -> ITVC: 204

ITVC -> Media Handler: proceed</progress-reply>

Media Handler -> ITVC: 510

ITVC -> Media Handler: proceed</progress-reply>

Media Handler -> ITVC: 948

ITVC -> Media Handler: proceed</progress-reply>

Media Handler -> ITVC: 1159

ITVC -> Media Handler: abort</progress-reply>

Media Handler -> ITVC: aborted

quit
Makes Media Handler's process exit.

Example:

Here's a of the interaction process between the ITVC GUI and the Media Handler process based on the above protocol.