Make Your Program Smarter: Real-Time Video Status and One-Click Snapshot!

Welcome to Chapter 10-5! In the previous practical exercises, we have successfully displayed the capture card's video on the window. However, real-world audio and video development is often more complex: What if the user suddenly unplugs the cable? How does the program know if the signal resolution suddenly changes? Or, what should we do if we want to capture and save a wonderful moment?

In this chapter, we will unlock two highly practical features of the NexVDO SDK: Callback and Snapshot. Let's first take a look at the final result we are going to achieve today:

image.png

We will add an information bar at the bottom of the window, which can display the current signal status in real-time (such as resolution, FPS, and whether there is no signal), along with two practical snapshot buttons. Are you ready? Let's get started!

Understanding Core APIs - Callback

Before we start coding, let's get to know today's main character:

A callback function is like an "informant" planted in your program. When a specific event occurs, the informant will proactively report back to you.

image.png

The NexVDO SDK provides two main types of Callbacks:

  1. Event Callback: Adopts a "passive trigger" mechanism. It is only called by the system when specific events occur (e.g., resolution change, signal removal, or no signal detected).

    image.png

  2. Data Callback: Responsible for "real-time supply". Once started, it continuously provides the raw video/audio data captured from the underlying layer to your main program in real time.

    image.png

When checking the user manual, you will notice that each Callback feature includes two very similar API names, for example:

What is the exact difference between these two? Simply put, one is for "registering contact info," and the other is "the format the informant uses to report back.”

1. Registering Contact Info:QCAP_REGISTER_... (Registration Function)

This function is proactively called by you. Its role is just like registering at the security guard's desk: "If you see a signal, please call me at this number." It only requires three basic parameters:

Type Parameter Input/Output Description
PVOID pDevice Input Specify the device handle.
PF_…._CALLBACK pCB Input Specify the callback function.
PVOID pUserData Input Pointer to custom user data.

⚠️ Development Reminder: The Iron Rule of Registration Timing! Please keep in mind: All Callbacks must be registered AFTER QCAP_CREATE. Don't rush to assign your informants before the device is even created!