Skip to main content
Version: 0.0.x

C++ Quick Start

The C++ SDK enables real-time audio and video communication on native Linux devices such as Raspberry Pi, NVIDIA Jetson Nano, and Arduino Uno Q. It captures from V4L2 cameras and PulseAudio, and renders with SDL2.

Prerequisites

Before you get started, ensure you have the following:

  • Linux on arm64, armv7, or x86_64
  • CMake 3.16+
  • A C++17 compiler
  • Video SDK Developer Account (Not having one, follow Video SDK Dashboard)
tip

You can checkout the complete quick start example here.

Install VideoSDK C++ SDK

Step 1: Install the SDK

Install the C++ SDK and its system dependencies, then set up your project, by following the Integrate C++ SDK guide.

Step 2: Generate Token and Create Room

Generate a token and create a room by following the Authentication and Tokens guide.

Step 3: Write your main application

Create a main.cpp file with the following code. Set your meeting ID and token at the top of the file — the program prints an error and exits if they are left unset. It then joins the meeting, sends the device's microphone and camera while playing back the audio and video of other participants, and keeps running until you stop it with Ctrl+C.

main.cpp
// Set meetingId and token below, then build and run.
// Joins the meeting and streams audio/video until you press Ctrl+C.

#include <videosdk/videosdk.hpp>

#include <atomic>
#include <chrono>
#include <csignal>
#include <cstdio>
#include <string>
#include <thread>

namespace {

// Set your meeting ID and token here before building.
const std::string meetingId = "MEETING_ID";
const std::string token = "TOKEN";

constexpr const char *V4l2Device = "/dev/video0";
constexpr int CamWidth = 1280;
constexpr int CamHeight = 720;
constexpr int CamFps = 30;

std::atomic<bool> g_running{true};

extern "C" void handle_signal(int) { g_running.store(false); }

} // namespace

int main() {
// Make sure the meeting ID and token were set above.
if (meetingId.empty() || token.empty() ||
meetingId == "MEETING_ID" || token == "TOKEN") {
std::fprintf(stderr,
"Set meetingId and token in main.cpp before running.\n");
return 1;
}

// Configure the meeting
videosdk::MeetingConfig config;
config.meetingId = meetingId;
config.token = token;
config.name = "Raspberry Pi"; // Update the display name if required
videosdk::Meeting meeting(config);

// Notify when a remote participant joins the meeting
meeting.onParticipantJoined([](const std::string &id, const std::string &name) {
std::printf("* %s joined (%s)\n", name.c_str(), id.c_str());
});

// Notify when a remote participant leaves the meeting
meeting.onParticipantLeft([](const std::string &id) {
std::printf("* %s left\n", id.c_str());
});

// Notify when an unrecoverable error occurs during the session
meeting.onError([](videosdk::ErrorCode, const std::string &msg) {
std::fprintf(stderr, "! error: %s\n", msg.c_str());
});

// Cap the outgoing video bitrate (in kbps)
meeting.setVideoMaxBitrate(500);

// Connect the local participant to the meeting session
if (!meeting.join()) {
std::fprintf(stderr, "join failed\n");
return 2;
}

// Start playing back audio received from other participants
meeting.enableSpeaker();

// Start capturing and sending microphone audio
meeting.enableMic();

// Start capturing and sending camera video
meeting.enableCamera(V4l2Device, CamWidth, CamHeight, CamFps);

// Start rendering video received from other participants
meeting.enableVideoDisplay(CamWidth, CamHeight);

// Keep streaming until the user presses Ctrl+C.
std::signal(SIGINT, handle_signal);
std::signal(SIGTERM, handle_signal);
while (g_running.load())
std::this_thread::sleep_for(std::chrono::seconds(1));

// Call leave() to disconnect from the meeting
// meeting.leave();

return 0;
}

Step 4: Build & Run

Build your project and run the application:

mkdir build && cd build
cmake ..
make
./my_app

Step 5: Connecting with VideoSDK Client Applications

Integrate C++ devices with VideoSDK client applications. Ensure that both the C++ device and client apps connect to the same room for communication.

Got a Question? Ask us on discord