CM Streaming
The CMStreaming (C3V Media Streaming API) is a set of streaming APIs for C3V media that depend on GStreamer. It wraps some of the GStreamer functionality in an API way to simplify the development process.
What can CM Streaming API do?
Provide easy-to-use streaming APIs for c3v platforms, helping users quickly develop stream-related applications like this sample.
Why use CM Streaming API?
The GStreamer is a very powerful media framework, but it can be a bit complicated to use. For some commonly used functions, wrapping them in APIs can achieve the effect of reuse, thus reducing redundant code.
For example, if need to get the YUV data from the sensor inside the program. In the GStreamer way, the developer should create elements, link them together, and then start it. The flow will be like this:
The main code will be like:
#include <gst/gst.h>
static GstFlowReturn _src_new_sample(GstElement *ele, gpointer data){
GstElement *sample;
g_singal_emit_by_name(ele, "pull-sample", &sample);
if(sample){
GstBuffer *buffer = gst_sample_get_buffer(sample);
......
}
}
int main(int argc, char* argv[]){
gst_init(&argc, &argv);
GstElement* bin = gst_pipeline_new(NULL);
g_assert(bin);
GstElement* src = gst_element_factory_make("v4l2src", NULL);
g_assert(src);
g_object_set(src, "device", "/dev/video0", NULL);
GstElement* sink = gst_element_factory_make("appsink", NULL);
g_assert(sink);
g_object_set(sink, "emit-signals", TRUE, NULL);
gint signal = g_signal_connect(sink, G_CALLBACK(_src_new_sample), NULL);
gst_bin_add_many(bin, src, sink, NULL);
gst_element_link(src, sink);
gst_element_set_state(bin, GST_STATE_PLAYING);
......
gst_element_set_state(bin, GST_STATE_NULL);
g_signal_handler_disconnect(sink, signal);
gst_object_unref(bin);
gst_deinit();
}
If now want to get data from another sensor, the developer needs to do the appeal process again. But in the CM Streaming API, the appeal process is packaged as API, users just need to call the API without caring about how it is implemented.
In the CM Streaming API way, the main code will be like this.
How to use CM Streaming API?
The CM Streaming API is based on the GStreamer v1.20.1, it needs many plugins support, such as ALSA, V4L2, AAC, OPUS, and so on. We also made some changes to the GStreamer source code for the C3V platform. Before using the CM Streaming API, please ensure that the environment is set correctly. For more details, please refer to here.
All functions of the CM streaming are included in a library called libcmstreaming.so. The user just needs to include the header files and add the library to the depends to use it.
The general flow of use is as follows:
For details, please refer to the API documents and demo.
How to get the library and demo code?
What’s more?
To work properly, it is important to make sure that the dependent library files are present.
The GStreamer depends on glib, it uses a lot of glib mechanisms. The code must be running with GMainLoop. Otherwise, the program functionality may be affected.
The CM streaming API is based on the GStreamer and designed for C3V, users need to have some basic knowledge of GStreamer and the C3V platform.
Â