Rate This Document
Findability
Accuracy
Completeness
Readability

Communication API Description

The external communication APIs are necessary for the proper running of the video stream engine. These APIs are implemented by secondary developers and provided as a DLL. The following shows an API calling example.

// The function prototype declaration is implemented by users.
using OnNewConnectionCallback = void (*)(int connection);
using RegConnectionCBFunc = int (*)(OnNewConnectionCallback newConnCb);
using CloseConnectionFunc = int (*)(int connection);
using SendFullyFunc = ssize_t (*)(int connection, uint8_t *buf, size_t len); 
using RecvFunc = ssize_t (*)(int connection, uint8_t *buf, size_t len);
const char *soPath = "./libCommunication.so";

// The callback function notifies the server that a new connection has been established, which is implemented by the cloud phone engine.
// The input parameter connection indicates the valid handle to the new connection.
static void OnNewConnection(int conn);

void Test()  
{
    // Function symbol for dynamically loading the dynamic communication library
    void *handle = dlopen(soPath, RTLD_GLOBAL | RTLD_LAZY | RTLD_NODELETE);
    RegConnectionCBFunc regConnection = (RegConnectionCBFunc)dlsym(handle, "RegConnectionCB");
    CloseConnectionFunc closeConnection = (CloseConnectionFunc)dlsym(handle, "CloseConnection");
    SendFullyFunc sendFully = (SendFullyFunc)dlsym(handle, "SendFully");
    RecvFunc recvData = (RecvFunc)dlsym(handle, "Recv");
    size_t bufSize = 1024; 
    uint8_t *data = malloc(bufSize); 
    // Create a connection to the server.
    int connRet = regConnection(OnNewConnection);  
   // Send data.
    ssize_t ret = sendFully(conn, data, bufSize); 
    // Receive data.
    ret = recvData(conn, data, bufSize);
    // Release resources.
    free(data); 
    closeConnection(conn);
    dlclose(handle);
}

For details about the APIs, see RegConnectionCB to Recv.