UgCS video streamer
stdin reading example

This is an example of obtaining video input data from from standard input pipe. Assuming the pipe provides H.264 stream. For example, to capture raw video from V4L2 device, encode it in H.264 and sink into this application:

ffmpeg -f v4l2 -framerate 30 -video_size 640x480 -i /dev/video0 -c libx264 -bsf:v h264_mp4toannexb -f h264 - | ./example
namespace {
bool done = false;
void
LogFunc(Log::Level, const char *msg)
{
fprintf(stderr, "%s\n", msg);
}
void
OnStreamerStatus(Streamer::Status status, void *)
{
fprintf(stderr, "Streamer status: %d\n", status);
done = true;
}
}
}
int
main(int argc, char **argv)
{
VsInitialize(LogFunc);
VsParams streamerParams;
streamerParams.vehicleId = "SampleVehicle-1";
streamerParams.targetUri = "urtp+connect://127.0.0.1:3341";
VideoStreamerHandle vs = VsCreate(&streamerParams, OnStreamerStatus, nullptr);
if (!vs) {
av_log(0, AV_LOG_ERROR, "Streamer instance creation failed\n");
return 1;
}
if (VsStart(vs)) {
av_log(0, AV_LOG_ERROR, "Streamer instance starting failed\n");
return 1;
}
std::freopen(nullptr, "rb", stdin);
if(std::ferror(stdin)) {
av_log(0, AV_LOG_ERROR, "Failed to reopen stdin: %s\n", std::strerror(errno));
return 1;
}
std::size_t n;
uint8_t buf[256];
while(!done && (n = std::fread(buf, 1, sizeof(buf), stdin)) > 0) {
if(std::ferror(stdin) && !std::feof(stdin)) {
av_log(0, AV_LOG_ERROR, "Failed to read stdin: %s\n", std::strerror(errno));
break;
}
if (VsFeedData(vs, buf,n)) {
av_log(0, AV_LOG_ERROR, "Failed to feed video packet\n");
break;
}
}
VsStop(vs);
VsDestroy(vs);
return 0;
}
VsTerminate
int VsTerminate()
VsFeedData
int VsFeedData(VideoStreamerHandle vs, const uint8_t *dataBuf, uint32_t bufSize)
VsInitialize
int VsInitialize(VsLogCallback logCbk)
VsStart
int VsStart(VideoStreamerHandle vs)
Streamer::Status::INITIALIZING
@ INITIALIZING
VsDestroy
void VsDestroy(VideoStreamerHandle vs)
Streamer::Status::OPERATIONAL
@ OPERATIONAL
video_streamer_c_api.h
VsStop
int VsStop(VideoStreamerHandle vs)
Streamer::Status
Status
Definition: streamer.h:44
VsParams::vehicleId
const char * vehicleId
Definition: video_streamer_c_api.h:77
VsParams::targetUri
const char * targetUri
Definition: video_streamer_c_api.h:88
VsCreate
VideoStreamerHandle VsCreate(const VsParams *params, VsStatusCallback statusCbk, VsQueueOverflowCallback queueOverflowCbk)
VsParams
Definition: video_streamer_c_api.h:73
VideoStreamerHandle
void * VideoStreamerHandle
Definition: video_streamer_c_api.h:39