#include <stdlib.h>#include <unistd.h>#include <string.h>#include "trro_remote.h"//This sample does not include render codeint main() {//register signal state callbackTRRO_registerSignalStateCallback(nullptr, [](void *context, SignalState state) {if(state == kTrroReady) {//connect to server successfullyprintf("init success \\n");}if (state == kTrroAuthFailed) {//auth failedprintf("device_id or password is incorrect\\n");}if (state == kTrroKickout) {//kicked out caused by the same device ID loginprintf("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 inputint 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 callbackTRRO_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 callbackTRRO_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 callbackTRRO_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 renderingTRRO_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 arrayint confds[8] = {0,1,2,3,4,5,6,7};//rendering windows handleWindowIdType 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 functionTRRO_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 exitingwhile(true){sleep(3000);// Disconnect the video streamTRRO_disconnectAll();// Exit the SDK and release resourcesTRRO_destroy();break;}return 0;}
Feedback