tencent cloud

All product documents
SDK Call Procedure
Last updated: 2025-02-11 16:50:28
SDK Call Procedure
Last updated: 2025-02-11 16:50:28

Recommended Steps

Note
The registration of onSignalState callback should be called before SDK initialization, and other callback functions can be registered after initialization.

Step 1: Initialization

Register the onSignalState callback, call the Init interface to initialize SDK by loading a json config file or inputting a json config string.

Step 2: Register callback functions as needed

According to needs, register permission callback, report data callback, log callback, video connection status callback, video media and link information callback, latency information callback, video image data callback and other functions to handle corresponding status information and events.

Step 3: Set video rendering window handle

If rendering video by the application program based on the SDK callback video image data, this step can be skipped. If rendering video by SDK (only support for windows), call TRRO_setWindows interface to link the video receiver handle ID and the video rendering window handle, so that the video stream received by the receiver handle can be rendered on the linked video window.

Step 4: Connect video streams

Call TRRO_connect interface to pull the specified video streams of the specified field devices through the specified video receiver handle. This interface can be called multiple times to connect video streams from different devices. If the video receiver handle is switched to recevie a new video stream, the old video stream will be automatically disconnected. TRRO_disconnect interface can also be called to disconnect the video stream.

Step 5: Send control data as needed

call TRRO_sendControlData Interface to send the input binary data to the specified field device. Before calling the interface, the operation permission for the field device should be the master permissoin. TRRO_requestPermission and TRRO_OnOperationPermissionState interfaces can be used to request and check the operation permission.

Step 6: Destory the SDK

When the program exits, call the destroy interface to destroy the SDK, especially for C# since C# program may not automatically destroy dll resource when it exits.

Sample Code

#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "trro_remote.h"

//This sample does not include render code
int main() {
//register signal state callback
TRRO_registerSignalStateCallback(nullptr, [](void *context, SignalState state) {
if(state == kTrroReady) {
//connect to server successfully
printf("init success \\n");
}
if (state == kTrroAuthFailed) {
//auth failed
printf("device_id or password is incorrect\\n");
}
if (state == kTrroKickout) {
//kicked out caused by the same device ID login
printf("the device is kicked by server, may be there is another device using the same device id\\n");
}
});

// init function can be replaced by other init function, e.g. json string as input
int ret = TRRO_initJsonPath("./config.json");
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);
}
}
//register the callback functions as needed
//register video connection state callback
TRRO_registerOnState(this, [](void* context, const char* gwid, int stream_id, int conn_fd, int state) {
printf("###### onstate gwid %s, streamid %d conn_fd %d state %d\\n", gwid, stream_id, conn_fd, state);
});
//register video transmission state callback
TRRO_registerOnMediaState(this, [](void* context, int windows_id, int fps, int bps, int rtt, long long decd, int jitter,
long long packets_lost, long long packets_received, int stun) {
printf("onMediaState window id %d fps %d bps %d rtt %d decd %lld rb %d lost %lld rec %lld stun %d\\n",windows_id, fps, bps, rtt, decd, jitter, packets_lost, packets_received, stun);
});
//register video latency info callback
TRRO_registerAllLatencyCallback(this, [](void* context, const char* gwid, int windows_id, long long latency1, long long latency2, long long gateway_time, int vcct) {
printf("allLatency %s, %d, latency1 %lld latency2 %lld video time %lld, vcct %d\\n", gwid, windows_id, latency1, latency2, gateway_time, vcct);
});
//register video image data callback, can be used for application program rendering
TRRO_registerRemoteFrameCallback(this, [](void * context, const char * gwid, int stream_id, int conn_id, const char* data, int width, int height, long long videotime) {
//here can realize the rendering functions, but please do not block the callback thread.
//you can try the async way to render video otherwise the video will be lagging
//showMyVideo(gwid, conn_id, (unsigned char*)data, width, height);
});

//receiver handle ID array
int confds[8] = {0,1,2,3,4,5,6,7};
//rendering windows handle
WindowIdType window_hwnds[8] = { nullptr};
//for SDK internal rendering, set the target win32 HWND, only for windows;
//for application program rendering, just set nullptr,and realize showMyVideo function
TRRO_setWindows(confds, window_hwnds, 8);
//connect the video streams, assume two devices, each with 4 video streams.
int stream_num = 4;
int stream_indexs[4] = {0,1,2,3};
//connect field device1, 4 video streams (0-3), using the receiver handle (0-3)
TRRO_connect("field_deviceId1", "", stream_num , &stream_indexs[0], &confds[0]);
//connect field device1, 4 video streams (0-3), using the receiver handle (4-7)
TRRO_connect("field_deviceId2", "", stream_num , &stream_indexs[0], &confds[4]);
//wait for exiting
while(true){
sleep(3000);
// Disconnect the video stream
TRRO_disconnectAll();
// Exit the SDK and release resources
TRRO_destroy();
break;
}
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