MediaDevice

View Source Code

namespace VideoKit {
    /// <summary>
    /// Media device for streaming sample buffers.
    /// </summary>
    abstract class MediaDevice { ... }
}

The MediaDevice abstracts a hardware device capable of streaming media sample buffers. VideoKit currently provides two concrete implementations: AudioDevice and CameraDevice.


Identifying the Device

Media devices can be identified in several ways:

Inspecting the Unique Identifier

/// <summary>
/// Device unique ID.
/// </summary>
string uniqueId { get; }

The media device reports its unique identifier as a string.

Inspecting the Device Name

/// <summary>
/// Display friendly device name.
/// </summary>
string name { get; }

The media device reports its name as a human-friendly string.

Inspecting the Device Location

/// <summary>
/// Device location.
/// </summary>
Location location { get; }

Some media devices are able to report their location relative to the current device:

/// <summary>
/// Device location.
/// </summary>
enum Location : int {
    /// <summary>
    /// Device type is unknown.
    /// </summary>
    Unknown = 0,
    /// <summary>
    /// Device is internal.
    /// </summary>
    Internal = 1,
    /// <summary>
    /// Device is external.
    /// </summary>
    External = 2,
}

Checking for the Default Device

/// <summary>
/// Device is the default device for its media type.
/// </summary>
bool defaultForMediaType { get; }

Some media devices are able to report whether they are the default device for their media type.


Streaming Media

The main function of the MediaDevice is to stream sample buffers.

Checking the Streaming Status

/// <summary>
/// Whether the device is running.
/// </summary>
bool running { get; }

The media device reports whether it is currently streaming sample buffers.

Stopping the Stream

/// <summary>
/// Stop running.
/// </summary>
void StopRunning ();

When a media device is running, this method can be used to stop streaming sample buffers and cleanup resources.


Managing the Device State

For external media devices, we provide events to handle the availability of the device.

Listening for Disconnections

/// <summary>
/// Event raised when the device is disconnected.
/// </summary>
event Action onDisconnected { add; remove; }

External media devices expose this event to listen for when the media device is disconnected.


Was this page helpful?