Skip to content

3. Building Your First Application

3.1 Overview

This chapter demonstrates how to create a webcam application using AVT SDK. This example showcases basic video capture and display functionality, illustrating key features of the SDK.

3.2 Project Setup

  1. Create a new project directory:

    mkdir webcam_demo && cd webcam_demo
    
  2. Create project files:

    • main.cpp: Application source code
    • CMakeLists.txt: Build configuration file

3.3 Application Code

3.3.1 Main Application (main.cpp)

main .cpp
#include "AvtCore.h"
#include "AvtList.h"
#include "Graph/AvtGraph.h"
#include "Device/AvtVideoSourceDevice.h"
#include "Device/Manager/AvtDeviceManager.h"
#include "Source/AvtVideoSourceProperty.h"
#include "Utility/ToString.h"

#include <iostream>
#include <csignal>
#include <unistd.h>

using namespace AVTSDK;
using namespace AVTSDK::Device;
using namespace AVTSDK::Device::Manager;
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()
{
    // Init the Avt Core with log level = warning
    AvtCore::init(AvtLogLevel::LOG_LEVEL_WARNING, AvtLogType::LOG_TYPE_DELAYED);

    AvtGraph *graph = nullptr;
    do {
        AvtList<AvtVideoSourceDevice> videoDeviceList;

        // Find the camera register in gstreamer
        AvtDeviceManager::getVideoSourceDeviceList(videoDeviceList);
        if (videoDeviceList.size() == 0) {
            cout << "Not found any device." << endl;
            break;
        }

        // Enable Video
        AvtGraphFeature ft;
        ft.mVideo.mEnable = true;

        // Enable preview on windowID = 0
        auto &vFt = ft.mVideo.mProperty;
        vFt.mGraphicsAPI = AvtGraphicsAPI::GRAPHICS_API_QCOM;
        vFt.mPreview.mEnable = true;
        vFt.mPreview.mProperty.mWindowID = 0;


        // Fill the Camera Attributes to start preview
        AvtVideoSourceProperty prop;
        prop.mLockDevice = true;

        // Choose the first Camera
        AvtVideoSourceDevice& dev = videoDeviceList.at(0);
        prop.mDevice = dev;
        if (dev.mVideoCaps.size() == 0){
            cout << " device not supply any format." << endl;
            break;
        }

        // Choose the first Caps for its format and resolution
        prop.mFormat = dev.mVideoCaps.at(0).mFormat;
        prop.mResolution = dev.mVideoCaps.at(0).mResolution;
        auto devCaps = dev.mVideoCaps.at(0);
        if (devCaps.mFrameRateList.size() == 0 ){
            cout << " device not supply any framerate for the specific caps." << endl;
            break;
        }

        // Choose the first framerate for its format and resolution
        auto devCapFrameRate = devCaps.mFrameRateList.at(0);
        prop.mFrameRate = devCapFrameRate.mMaxFrameRate;

        // Output webcam Info
        auto webcamInfo = Utility::toString(prop);
        cout << webcamInfo << endl;

        AvtResult result;

        // Create the filter graph (analogous to Gstreamer pipeline)
        graph = new AvtGraph(ft);
        graph->createGraph();
        int sourceID;

        // Add a video source into Graph according to the property
        result = graph->addSource(prop, sourceID);
        if (result != AvtResult::AVT_RESULT_OK) {
            cout << "Failed to add video source" << endl;
            break;
        }

        // Start the Graph
        result = graph->runGraph();
        if (result != AvtResult::AVT_RESULT_OK) {
            cout << "Failed to run graph";
            break;
        }

        signal(SIGINT, signalHandler);
        while (running)
            sleep(1);

    } while (false);


    // End the Graph
    if (graph)
        delete graph;

    // Uninit the Avt Core
    AvtCore::uninit();
    return 0;
}

3.3.2 Build Configuration (CMakeLists.txt)

CMakeLists.txt
project(webcam_demo)

# Set C++ standard
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Set installation paths
set(BIN_INSTALL_PATH ${CMAKE_SOURCE_DIR}/output/bin)
set(SRC_INSTALL_PATH ${CMAKE_SOURCE_DIR}/output/src)

# Add executable
add_executable(${PROJECT_NAME} main.cpp)

# Add defintions
add_definitions(-D__ENABLE_GST__
                -D__ENABLE_VIDEO_SOURCE__)

# Link required libraries
target_link_libraries(${PROJECT_NAME} PRIVATE
    avtsdk
    gstreamer-1.0
    glib-2.0
    gobject-2.0
    gstbase-1.0
    gstvideo-1.0
    gstrtspserver-1.0
)

# Set installation target
install(TARGETS ${PROJECT_NAME} DESTINATION ${BIN_INSTALL_PATH})

3.4 Building and Deployment

3.4.1 Build Steps

# Create and enter build directory
mkdir build && cd build

# Configure project with toolchain
cp <TOOLCHAIN_INSTALL_PATH>/avermedia-qcom-ql601_toolchain/avermedia-qcom-ql601_arm64_toolchain.cmake ./
cmake --toolchain ./avermedia-qcom-ql601_arm64_toolchain.cmake ../

# Build the application
make

3.4.2 Deployment and Testing

# Copy to QL601 device
scp ./webcam_demo root@<QL601_DEVICE_IP>:/opt/

# Run the application
ssh root@<QL601_DEVICE_IP> "/opt/webcam_demo"

Application Location

The application is installed in the /opt directory which has read-write permissions by default.

3.5 Conclusion

In this getting started guide, we have:

  • Set up the AVT SDK development environment
  • Created a basic webcam application using the SDK
  • Learned how to build and deploy applications to the QL601 device

This foundation prepares you for more advanced development with the AVT SDK. Here are the recommended next steps: