Skip to content

Adapter Developer Guide

Lukas Herman edited this page Feb 18, 2020 · 28 revisions

Note: This page is meant for developers who are interested in creating/maintaining new/current adapters. If you're only interested in using them, you probably want to visit the driver usage page instead.

Overview

The design for adapter/driver is heavily based on unix design principle, everything is a file. Therefore, you can always think of any adapter as a file, you open the adapter, read from it, and then close it:

Driver Lifecycle

How to implement a new Adapter?

Implement Adapter interface

First of all, any adapter has to implement the Adapter interface,

type Adapter interface {
	Open() error
	Close() error
	Properties() []prop.Media
}

This interface is being used to generalize different kinds of adapters. We use this interface so that we can store it in the driver manager (I'll talk about this more later).

As you've seen from the driver lifecycle diagram above, Adapter interface contains 2 out of 3 mentioned methods, and Properties.

Open

This method opens the underlying hardware through an OS interface. At this point, the adapter user can start getting its Properties and get data from it through, VideoRecord or AudioRecord (I'll talk more in the next section).

Close

Close is a cleanup method to free all used resources and stop the underlying hardware from transmitting data.

Properties

Properties return a list of prop.Media that the adapter supports. These values will later be chosen by the adapter user for VideoRecord or AudioRecord.

Clone this wiki locally