Getting started

Check out the source code. Compile the solution and run the project VlcPlayer.

You have to install the following dependencies on your development maschine:
Windows Phone Toolkit
Your Last About Dialog

Embed in your app

You have to add a reference to the assembly "StreamingClient". On the page where the player should be placed, add the control StreamingClient.Player.PlayerControl:

<Player:PlayerCtrl Name="PlayerControl"/>

To play a video, call the Start method on th control. The first parameter ist the URI of a video accessible by the VLC server. The second one contains the settings.

PlayerControl.Start(src, server.StreamingSettings);

For configuration of the streaming settings there is a control that can be reused:

<StreamManagment:SettingsCtrl ServerTypeVisibility="Collapsed" StreamingSettings="{Binding StreamingSettings, Mode=TwoWay}"/>

ServerType should always be VLC, so its selection box is hidden in this sample.

Feel free to examine the sample app VlcPlayer to see the usage of the controls.

Technical Details

Stream management

The stream setup of the VLC is managed by the VLM interface. This is handled by the class StreamingClient.StreamManagment.VlcAccess.

It creates a VOD item on your VLC server. The source is the given URI and has to be accessible by the VLC instance. The VOD item is configured for transcoding according to the StreamingSettings.

VlcPlayer does contain another VlcAccess class. This class does not handle video streams. It uses the VLCs web interface to browse you local file system.

Media playback

Basics

It is important to understand the difference between video codec and container format. These are usually mixed up.

The codec is the compression method used to encode the video. The container is the file (or stream) format with contains the video track (and the audio as well). I someone speaks of a MP4 file, it does mean:

Video Codec: MP4-Video
Audio Codec: AAC
File container: MP4

But it is also possible to encapsulate MP4 video in other containers, like TS (MPEG2-Transport-Stream) or FLV (Flash-Video) or use other audio formats.

Windows phone supports the following combinations (and some others not relevant here):

Video Codec

Audio Codec

Container

MP4

AAC

MP4

H264

AAC

MP4

WMV3

WMA2

ASF

Only ASF does support live streaming, but VLC cannot create WMV3 video. VLC can create MP4 and H264 video, but it cannot be encapsulated in ASF.

The idea is, to let the VLC create a video in a container that supports streaming. Than take this stream in your app and extract the raw video and audio tracks. These raw streams are given to the Windows Phone media framework and you are done.

There are some container formats available in VLC, that support streaming: TS, FLV, ASF... I choosed Ts because it is well documentated an can carry any codecs. The others have restrictions on the supported contents.

Implementation

The first step is to replace the default plabayck behavior of the common MediaElement with an own implementation. This is possible by setting its source to a class implementing MediaSteamSource:

VideoElement.SetSource(_mss);

In this library you can find this in the class StreamingClient.Player.VlcTsMediaStreamSource. It has the following jobs:

  • take the input stream (a HttpStream that loads the data from the VLC)
  • split the TS-stream in its video and audio parts
  • do some work, to make it understandable for the MediaElement (Byte-Order, Timing,...)
  • provide the video and audio frames to the MediaElement

The last one is implemented according to Implementing MediaStream Sources tutorial.

To perform the first 3 jobs you can think of the MediaStreamSource as a simple TS decoder. It is no full-fledged TS decoder like in your cable or sat box. It skips some tasks (analyzing PMT...) and because I know how that the VLCs streams have always a similar structure.

I don't want to explain the implementation of a TS decoder at this place. There are much better articles and books. To understand the implementation it is necassary to spend some days in studing some documentation. I'll give the resources that I used to get started:

Last edited Jul 18, 2012 at 8:18 AM by Pate, version 6

Comments

No comments yet.