Preview Demo
This demo demonstrates how to display the video source on the connected monitor directly. Simply choose the desired camera device and its relevant settings, including the supported format, resolution and framerate.
Code Example
#include "AvtCore.h"
#include "Graph/AvtGraph.h"
#include "DeviceHelper.h"
#include "Source/AvtVideoSourceProperty.h"
#include <iostream>
#include <csignal>
#include <unistd.h>
using namespace AVTSDK;
using namespace AVTSDK::Log;
using namespace AVTSDK::Graph;
using namespace AVTSDK::Source;
using namespace std;
bool running = true;
void signalHandler(int signum)
{
running = false;
}
int main()
{
AvtCore::init(AvtLogLevel::LOG_LEVEL_WARNING, AvtLogType::LOG_TYPE_DELAYED);
AvtGraph *graph = nullptr;
do {
DeviceHelper devHelper;
auto vDevCount = devHelper.getVideoDeviceCount();
if (vDevCount == 0) {
cout << "No Device" << endl;
break;
}
AvtGraphFeature ft;
ft.mVideo.mEnable = true;
auto &vFt = ft.mVideo.mProperty;
vFt.mPreview.mEnable = true;
vFt.mPreview.mProperty.mWindowID = 0;
vFt.mGraphicsAPI = AvtGraphicsAPI::GRAPHICS_API_QCOM;
graph = new AvtGraph(ft);
AvtVideoSourceProperty prop;
prop.mLockDevice = true;
if (!devHelper.selectVideoDevice(prop)) {
cout << "Failed to select the correct device or device property" << endl;
break;
}
AvtResult result;
graph->createGraph();
int sourceID;
result = graph->addSource(prop, sourceID);
if (result != AvtResult::AVT_RESULT_OK) {
cout << "Failed to add video source" << endl;
break;
}
result = graph->runGraph();
if (result != AvtResult::AVT_RESULT_OK) {
cout << "Failed to run graph";
break;
}
signal(SIGINT, signalHandler);
while (running)
sleep(1);
} while (false);
if (graph)
delete graph;
AvtCore::uninit();
return 0;
}
Explanation
Helper Classes
DeviceHelper is a helper class written for the demos and is not part of the library. For details about how to handle devices, please check the source code in DeviceHelper.cpp.
-
Initialization
The program begins by initializing the AVT core with a warning-level log configuration.
-
Device Availability Check
It checks whether any video input devices are available. If none are found, the program exits early.
-
Graph and Feature Setup
AvtGraphFeatureis the configuration structure forAvtGraph. It is configured to enable video preview. The appropriate graphics API (QCOMorNV) is selected based on the platform. The preview window ID is set to0. -
Graph Creation
A new
AvtGraphinstance is created using the configuredAvtGraphFeature.Note
If you have no idea what
AvtGraphis, please refer to AVT SDK Multimedia Framework. -
Device Selection
The user is prompted to select a camera device and its settings using
DeviceHelper::selectVideoDevice().
The resulting configuration is stored inAvtVideoSourceProperty, which is the configuration structure for a video source.Note
DeviceHelper::selectVideoDevice()is just a helper function to interact with the user. Typically, you need to implement your own device selection logic to configure theAvtVideoSourceProperty. -
Source Node Addition
The selected video source is added to the pipeline graph using
addSource(). A source ID is returned by the method but not used in this demo. -
Graph Execution
The graph is executed using
runGraph(), which starts the video processing pipeline. -
Runtime Loop and Termination
A signal handler is registered to listen for
SIGINT(Ctrl+C). The program enters a loop to keep the pipeline running until interrupted. Upon termination, the graph is deleted and the AVT core is uninitialized.