#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <thread>
#include "trro_field.h"
void externalVideoInput(int stream_id) {
int data_width = 1280;
int data_height = 720;
char *data = (char*)malloc(data_width*data_height*3/2);
memset(data, 0, data_size);
while(true) {
TRRO_externalVideoData(stream_id, data, data_width, data_height, 0);
usleep(33 * 1000);
}
free(data);
}
int main() {
TRRO_registerSignalStateCallback(nullptr, [](void *context, SignalState state) {
if(state == kTrroReady) {
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();
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 {
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");
}
});
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);
}
}
while(true){
sleep(30000);
}
return 0;
}