Streaming API

Streaming and decoding can be controlled via the two main API of our SDK: HAL and SDK Driver.

Using HAL C++ API

Streaming events can be done using the HAL module with the I_EventsStream facility which exposes functions to start and stop the streaming as well as getting the raw events stream from the camera. An example can be seen in metavision_hal_showcase sample. Here we show the main statements related to the event stream:

Metavision::I_EventsStream *i_eventsstream = device->get_facility<Metavision::I_EventsStream>();
(...)
i_eventsstream->start();
(...)
while (!stop_decoding) {
    short ret = i_eventsstream->poll_buffer();
    if (ret < 0) {
        i_eventsstream->stop();
        uint8_t *raw_data = i_eventsstream->get_latest_raw_data(n_bytes);
        // do something with the data

To decode the raw events stream, the I_Decoder facility is provided in the HAL module. It offers functions to decode raw buffers into decoded event buffers, which are provided via C++ callbacks registered onto the I_EventDecoder facility. Like for streaming, an example can be seen in metavision_hal_showcase sample. Here we show the main statements related to the event decoding:

Metavision::I_EventDecoder<Metavision::EventCD> *i_cddecoder =
device->get_facility<Metavision::I_EventDecoder<Metavision::EventCD>>();
(...)
if (i_cddecoder) {
    // Register a lambda function to be called on every CD events
    i_cddecoder->add_event_buffer_callback(
        [&any_function](const Metavision::EventCD *begin, const Metavision::EventCD *end) {
            any_function.process_events(begin, end);
        });
}
(...)
Metavision::I_Decoder *i_decoder = device->get_facility<Metavision::I_Decoder>();
while (!stop_decoding) {
        // fetch the data with the event stream
        // then decode the data
        i_decoder->decode(raw_data, raw_data + n_bytes);

Note that in addition to CD events, HAL API can also decode the External Trigger events (see documentation on Accessing External Trigger Events) as shown in metavision_hal_showcase sample.

Note

This HAL API is also available in Python but if you want to stream and decode events in Python, it might be easier to leverage the EventsIterator presented in the sample Get Started with Python.

Using SDK Driver C++ API

the SDK Driver module provides a higher level Camera class built on the top of the HAL API. With this class, you only have to manage a camera object that you will have to start() and stop() without worrying about the management of the event stream. To get the event, you will register some callbacks on the events that will be automatically decoded for you. An example is shown in the sample Get Started with C++. Here we show the main statements related to the streaming:

cam = Metavision::Camera::from_first_available();
(...)
cam.cd().add_callback([&my_function](const Metavision::EventCD *ev_begin, const Metavision::EventCD *ev_end) {
    my_function.analyze_events(ev_begin, ev_end);
});
(...)
    cam.start();
    // loop until a stopping condition is met
cam.stop();

Note

The SDK Driver API is not available in Python but if you want to stream and decode events in Python, you can leverage the EventsIterator presented in the sample Get Started with Python.