Setting up the video

The multimedia rendering component of the BlackBerry Native SDK for Tablet OS is called mm-renderer and it needs an output window to display your video. Here, we'll use the screen.h library to create and initialize a top-level window and window group.

In main.c, the first thing to do is set up some variables and initialize the BlackBerry Platform Servicess library. This will allow us to take care of user input later on.

int rc;
int exit_application = 0;

// Screen variables
screen_context_t    screen_context = 0;
screen_window_t        screen_window = 0;
int size[2]    = {0,0};

// Renderer variables
mmr_connection_t*     mmr_connection = 0;
mmr_context_t*        mmr_context = 0;

// I/O variables
int                    video_device_output_id = -1;
int                    audio_device_output_id = -1;


After initialization, let's create a window context and a window assigned to a window group. The window group allows the window to have children.

screen_create_context(&screen_context, SCREEN_APPLICATION_CONTEXT);

screen_create_window(&screen_window, screen_context);

screen_create_window_group(screen_window, window_group_name);

Here, window_group_name was declared earlier in the file as:

static const char *window_group_name = "videosamplewindowgroup";

Set the properties of the window to specify the screen pixel format and how the window will be used. For this video, we want to have the highest possible image quality so we specify a 32-bit pixel format (RGBA8888). We also set the intended usage of the window to specify native libraries.

int format = SCREEN_FORMAT_RGBA8888;
screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_FORMAT, &format);

screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_USAGE, &usage);

Set the number of render buffers allocated to the window.

screen_create_window_buffers(screen_window, 1);

Connect and configure the renderer

Now that the window properties are all set up, it's time to connect the application to the multimedia renderer to take advantage of its playback API. Once connected, a context is required to uniquely identify the application to the renderer. The first thing to do is create a connection to mm-renderer, passing in NULL to use the default name provided by the library.

mmr_connection = mmr_connect(NULL);

Next, we can create a context for the application, giving it a unique name and setting the file permissions of the directory it uses to allow global read and write.

mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO);

Here, video_context_name was declared earlier in the file as:

static const char *video_context_name = "samplevideocontextname";

Configure the input and output

Now that we have a connection to the multimedia renderer, we need to tell it where to play the media. Since we want to see and hear the video, we need to attach the mm-renderer context to the window created earlier and to something that outputs audio. We do this by attaching the mm-renderer context to the output window, using the name of the window and window group created earlier.

video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video");

Here, video_device_url was declared earlier in the file as:

static const char *video_device_url = 

We also attach the mm-renderer context to the output audio device. In this case, we're using the default audio output.

audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio");

Here, audio_device_url was declared earlier in the file as:

static const char *audio_device_url = "audio:default";