Linux Publisher Usage
Device
In order to begin a broadcast session, you will need to discover the video device to use. The device
code included with the Linux SDK can be used for cameras that support H264
output.
To do so, you issue the following command in a terminal - replacing the X
with the desired video
device number:
v4l2-ctl -d /dev/videoX --list-formats
As an example v4l2-ctl -d /dev/video0 --list-formats
outputs something similar to the following:
Index : 0
Type : Video Capture
Pixel Format: 'MJPG' (compressed)
Name : Motion-JPEG
Index : 1
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUYV 4:2:2
With a USB camera connected that supports H264
output, issuing the above command with /dev/video1
will print something of the following:
Index : 0
Type : Video Capture
Pixel Format: 'H264' (compressed)
Name : H.264
With the desired device found, you can setup the r5config
to be consumed.
r5config
You will then provide 1
as the video index in the r5config
in order to use that device for a broadcast session. Along with the video
index, you also specify the desired resolution and format.
The full configuration will look like the following:
config.video = 1;
config.width = 1920;
config.height = 1080;
config.video_format = fourcc('H', '2', '6', '4');
Loading
To start, you will want to loader the shared libary:
libfuncs pointer;
pointer.handle = dlopen(so_path_selected, RTLD_LAZY);
Session Start
If the shared library is successfully loaded and, either using the provided device
control or your own, start a broadcast session:
if (pointer.handle) {
pointer.get_version = (pget_version)dlsym((void*)pointer.handle, "get_version");
pointer.create_session = (pcreate_session)dlsym((void*)pointer.handle, "create_session");
pointer.close_session = (pclose_session)dlsym((void*)pointer.handle, "close_session");
uint32_t version = pointer.get_version();
printf("Red5Pro SDK version %d.%d.%d \n", ((version >> 16) & 0xFFFF) , ((version >> 8) & 0xFF) , ((version) & 0xFF));
r5session* session = pointer.create_session();
if (session && session->mem_ptr) {
set_config(session->config);
r5device* vfl2 = (r5device*)malloc(sizeof(r5device));
make_vfl2_device(vfl2);
session->set_r5camera(session->mem_ptr, vfl2);
if (!session->init(session->mem_ptr, session->config)) {
session->start(session->mem_ptr);
return 0; // publishing successfully
} else {
return 1; // there was a problem
}
}
}
And the set_config
function to define the r5config
settings as described in previous section:
voic set_config (r5config *config) {
conf->audio = 0xFF;
conf->video = 1;
conf->width = 1920;
conf->height = 1080;
conf->video_format = fourcc('H','2','6','4');
conf->audio_rate = 16000;
conf->channel_count = 1;
conf->video_bitrate = 750;
conf->video_framerate = 30;
conf->protocol = r5_rtsp;
strcpy(conf->contextName, "live");
strcpy(conf->hostName, "xxx.xxx.xxx.xxx");
strcpy(conf->streamName, "stream1");
conf->recordType = R5RecordTypeLive;
conf->rtp_aux_out = NULL;
conf->statusCallback = &print_status;
conf->remoteCallback = NULL;
}
Replace the
hostName
value ofxxx.xxx.xxx.xxx
with the IP of your Red5 Pro Server deployment.
Session Close
Be sure to properly clean up resources once you are done broadcasting:
session->stop(session->mem_ptr);
r5device* cam = session->get_r5camera(session->mem_ptr);
pointer.close_session(session);
free(cam);
The Linux icon used in this article is provided from iconfinder under Creative Commons 3.0 License