Skip to content

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.

  1. Initialization

    The program begins by initializing the AVT core with a warning-level log configuration.

  2. Device Availability Check

    It checks whether any video input devices are available. If none are found, the program exits early.

  3. Graph and Feature Setup

    AvtGraphFeature is the configuration structure for AvtGraph. It is configured to enable video preview. The appropriate graphics API (QCOM or NV) is selected based on the platform. The preview window ID is set to 0.

  4. Graph Creation

    A new AvtGraph instance is created using the configured AvtGraphFeature.

    Note

    If you have no idea what AvtGraph is, please refer to AVT SDK Multimedia Framework.

  5. Device Selection

    The user is prompted to select a camera device and its settings using DeviceHelper::selectVideoDevice().
    The resulting configuration is stored in AvtVideoSourceProperty, 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 the AvtVideoSourceProperty.

  6. 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.

  7. Graph Execution

    The graph is executed using runGraph(), which starts the video processing pipeline.

  8. 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.