The media data loop

Each device that is registered gets its own thread in which the media data loop (function MediaDataLoop) is running. The media data loop is an endless loop that handles server requests and fulfills the purpose of the plugin. The server calls the media data loop after startup for each device instance.

 

The first thing that a media data loop should do is waiting for valid plugin device settings. The following example (in pseudo code) should demonstrate this:

 

// wait until the settings for the plugin device are available

if (WaitForNewSettingsOrAbort() == peStop) return; // Leave loop on stop request

ReadNewSettings(); // Read initial device settings

 

After doing internal device instance creation or device instance initialization the endless loop should follow. The endless loop waits for events, that the server fires. The events are defined by the help of a filter definition. Here is an example (in pseudo code) for this:

 

PluginNextEventFilter filter =

static_cast<PluginNextEventFilter>(pefNewSettings | pefCreateNewVideoData);

 

// here the media data loop starts

for (;;)

{

// wait until the server fires the next event for this plugin

PluginNextEvent pluginEvent = simpleDevice->WaitForNextEvent(filter);

switch (pluginEvent)

{

 

The following types of server events are actually supported (not a complete list):

 

Method Function
peCreateNewVideoData The server requests a new image from the plugin
peNewSettings The server notifies the plugin about new settings, that are available
peNewDeviceTask The server notifies the plugin about new task settings especially for this device
peStop The server notifies the plugin, that the plugin should stop its media data loop