tencent cloud

All product documents
SDK Call Procedure
Last updated: 2025-02-11 16:48:24
SDK Call Procedure
Last updated: 2025-02-11 16:48:24


Recommended Steps

Note:
The signalState signaling callback registration needs to be invoked before the initialization function, other callback functions can be registered after initialization.

Step 1: Initialization

Call the Init interface to initialize the SDK with loading a JSON file or inputting a JSON string. . Before initialization, the signalState signaling callback interface should be registered first.

Step 2: Register the necessary callback functions

Register the required callback functions as needed, such as control message callback, log callback, connection status callback, video link information callback, latency information callback, to handle corresponding status information and events.

Step 3: Start SDK to enter video managed state

Invoke TRRO_start to enter the managed state. At this point, the SDK will listen to various requests, automatically carry out video capture, video streaming, and handle abnormal events such as network disconnection.

Step 4: Call the data send function as needed

When there is a need to input external video data or binary data, call the corresponding sending interface to input the video data or binary control/status data at the required sending time.

Sample Code

#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <thread>
#include "trro_field.h"

// External input video data
void externalVideoInput(int stream_id) {
int data_width = 1280;
int data_height = 720;
char *data = (char*)malloc(data_width*data_height*3/2);
// YUV420 video data, using all-zero simulated data (Green Map) in the sample for illustration
memset(data, 0, data_size);
while(true) {
TRRO_externalVideoData(stream_id, data, data_width, data_height, 0);
usleep(33 * 1000);
}
free(data);
}

// Main thread
int main() {
// Register signal callback
TRRO_registerSignalStateCallback(nullptr, [](void *context, SignalState state) {
if(state == kTrroReady) {
// Server connection successful, register callback function, and start SDK management
printf("init success \n");
TRRO_registerControlDataCallback(nullptr, [](void * context, const char* controlid, const char* msg, int len, int cmd) {
printf("receive control data from %s: %s\n", controlid, msg);
});
TRRO_registerOnState(nullptr, [](void* context, int stream_id, int state) {
printf("stream_id: %d, state: %d\n", stream_id, state);
});
TRRO_registerOnErrorEvent(nullptr, [](void* context, int error_code, const char* error_msg) {
printf("error_code %d, error_msg %s\n", error_code, error_msg);
});
TRRO_registerVideoCaptureCallback(nullptr, [](void *context, const char* data, int width, int height, int type, int stream_id) {});
TRRO_registerLatencyCallback(nullptr, [](void *context, int stream_id, int vcct){
printf("LatencyCallbac context: %p, stream id %d, vcct %d\n", context, stream_id, vcct);
});
TRRO_registerMediaState(nullptr, [](void* context, int stream_id, int fps, int bps, int rtt, long long lost, long long packets_send, int stun) {
printf("stream %d, fps %d, bps %d, rtt %d, lost %lld, packets_send %lld, stun %d\n", stream_id, fps, bps, rtt, lost, packets_send, stun);
});
TRRO_registerOperationPermissionRequest(nullptr, [](void* context, const char* remote_devid, int permission) {
printf("remote devid %s permission %d\n", remote_devid, permission);
});
int ret = TRRO_start();
// After init successfully connects to the service, TRRO SDK management can be started
if(TRRO_SUCCED == ret) {
printf("start succeed\n");
} else if (ret == -TRRO_INIT_LICENSE_FILE_ERROR || ret == -TRRO_INIT_LICENSE_CHECK_FAILED) {
printf("start license error, wait for regist or exit error:%d\n", ret);
} else {
// Pay attention to configuration issues
printf("start config error, please check config it, error:%d\n", ret);
}
}
if (state == kTrroAuthFailed) {
printf("device_id or password is incorrect\n");
}
if (state == kTrroKickout) {
printf("the device is kicked by server, may be there is another device using the same device id\n");
}
});

// It is recommended to use -1 for the last parameter to start in non-blocking mode and wait for the signaling connection success callback
// You can replace it with other initialization functions as needed, such as initializing with a configuration string
int ret = TRRO_initGwPathWithLicense("./config.json", "./license.txt", -1);
if(TRRO_SUCCED != ret) {
if (ret == -TRRO_SIGNAL_CONNECT_OUTTIME) {
printf("init process: wait for connecting\n");
} else {
printf("init fail ret %d\n", ret);
}
}

// Start an external input video data thread, input video data to stream 0, stream 0 protocol must be 'outside'
// std::thread t1(externalVideoInput, 0);
// t1.detach();
// Prevent the program from exiting
while(true){
sleep(30000);
}
return 0;
}

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon