Hacker Guide/VLM Internals
VideoLAN Manager is a small media manager designed to control multiple streams with only one instance of VLC. It allows multiple streaming and video on demand (VoD). VLM can be controlled through the telnet and http interfaces of VLC as described in Documentation:Streaming_HowTo/VLM.
This document will describe the internals of VLM including data structures and functions, as well the the libvlc bindings for control of vlm.
In a running instance of VLC or libvlc only 1 instance of VLM can be running. This instance of VLM is represented by struct vlm_t as defined in src/input/vlm_internal.h. vlm_t contains a list of Medias, Schedules and vod servers, as well as a lock for the data structure, and a unique id. In essence, the vlm_t data structure is the global container for all VLM related data.
Medias and Instances
A Media is composed with a list of inputs (the video and audio streams you want to stream), an output (how and where you want to stream them) and some options.
There are two types of medias:
- vod: A vod media is commonly used for Video on Demand. It will be launched only if a vod client asks for it.
- broadcast: A broadcast media is very close to a TV program or channel. It is launched, stopped or paused by the administrator and may be repeated several times. The client has no control over this media.
A media is represented by the structure vlm_media_sys_t defined in src/input/vlm_internal.h. Each vlm_media_sys_t contains a configuration structure, a list of instances of the media, as well as a structure representing a vod server which is initialized only if the media is of type vod.
The configuration structure is of type vlm_media_t (a misnomer due to historical reasons) and contains the name of the media, as well as its type and a host of other details. It is defined in src/input/vlm_internal.h also.
A media instance is represented by the structure vlm_media_instance_sys_t defined in src/input/vlm_internal.h also. This structure contains a playlist index as well as the current input thread and output stream instance. Mulitple media instances can exist for each media.
Each VOD server is represented by the struct vod_t. This structure contains a pointer to the module that will be loaded to help the vod server, as well as a pointer to an RTSP server. It also contains several function pointers to help create and delete vod medias of type vod_media_t. Each vod_media_t is actually referenced by a vlm_media_sys_t if that media is of vod type. vod_t is defined in include/vlc_vod.h and vod_media_t is defined in modules/misc/rtsp.c
The layout of the main vlm structures hierarchically looks like this:
vlm_t vlm_media_sys_t vlm_media_t vlm_media_instance_sys_t vod_media_t vod_t
Initializing VLM and Adding Medias
Since VLM is a part of libvlc, I will describe initialization of VLM with respect to libvlc. If we want to use VLM we are probably going to have at least one media. Therefore we can use the libvlc functions libvlc_vlm_add_broadcast() or libvlc_vlm_add_vod() to instantiate and initialize VLM. Each one of these functions checks to see if a VLM instance exists. If it does not, the function creates a vlm_t instance and creates and adds either a broadcast or vod media to the vlm_t instance. If the media is of type vod, then a separate vod_media_t is created and linked to the media of type vlm_media_sys_t and a vod server of type vod_t is created and linked to the vlm_t instance.
Note also, that the VLM instance is attached to the libvlc instance as a singleton, therefore allowing only one VLM instance per libvlc instance. Both libvlc_vlm_add_broadcast() and libvlc_vlm_add_vod() wrap around the VLM() macro which actually does the instantiation, initialization, and binding of the VLM instance to the libvlc instance. These functions are found in the src/control/vlm.c.