hi3518e liteos5.2平台利用尚云API接口实现p2pmode 推视频流和音频流

1.在I:\hi3518ev200\liteos\Hi3518E_SDK_V5.0.5.0\mpp\sample\Makefile.param添加尚云的库文件libliteos_5.0.5.1.a,该推流库文件包含了一系列api函数,eg:

Common:
PPCS_Initialize, PPCS_DeInitialize
PPCS_NetworkDetect
PPCS_NetworkDetectByServer
PPCS_GetAPIVersion
PPCS_Share_Bandwidth
PPCS_Get_ServerIP
Device:
PPCS_Listen
PPCS_Listen_Break
PPCS_LoginStatus_Check
Client:
PPCS_Connect
PPCS_ConnectByServer
PPCS_Connect_Break
Session:
PPCS_Check
PPCS_Close
Read / Write data
PPCS_Read
PPCS_Write
Check Buffer size

PPCS_Check_Buffer


  SENSOR_LIBS += $(REL_LIB)/libliteos_5.0.5.1.a

2.在I:\hi3518ev200\liteos\Hi3518E_SDK_V5.0.5.0\mpp\lib添加尚云的接口库文件libliteos_5.0.5.1.a


3.添加尚云API接口的头文件

把C:\Users\Administrator\Desktop\尚云P2P\p2p\Release_PPCS_2.4.0_客户端&设备端\Include\PPCS目录下的3个文件添加到目录下面I:\hi3518ev200\liteos\Hi3518E_SDK_V5.0.5.0\mpp\include

PPCS_API.h

PPCS_Error.h

PPCS_Type.h


4.在具体应用venc目录下面的其中2个文件里面添加尚云api接口,实现p2p推流

(a)Sample_venc.c (hi3518ev200\liteos\hi3518e_sdk_v5.0.5.0\mpp\sample\venc) 60570 2018/1/15

int p2p_main()   
{


// 1. get P2P API Version
int APIVersion = PPCS_GetAPIVersion();
printf("P2P API Version: %d.%d.%d.%d\n",(APIVersion & 0xFF000000)>>24, 
(APIVersion & 0x00FF0000)>>16, 
(APIVersion & 0x0000FF00)>>8, 
(APIVersion & 0x000000FF)>>0);


    char DID[] = "PPCS-016655-FKHLR"; 
    char InitString[] = "EBGAEIBIKHJJGFJKEOGCFAEPHPMAHONDGJFPBKCPAJJMLFKBDBAGCJPBGOLKIKLKAJMJKFDOOFMOBECEJIMM";
    printf("The DID[] is : %s\n\n", DID);
    //printf("The InitString[] is : %s\n\n", InitString);


        //char APILicense[SIZE_APILICENSE];
    char APILicense[] = "AXIBQF:EasyView";
    //printf("000=====DID = %s\n", DID);
    //printf("000=====InitString = %s\n", InitString);
    //printf("000=====APILicense = %s\n", APILicense);



// 2. P2P Initialize
printf("PPCS_Initialize(%s) ...\n", InitString);
int ret = PPCS_Initialize((char *)InitString);
printf("PPCS_Initialize done! ret=%d\n", ret);

if (ERROR_PPCS_SUCCESSFUL != ret && ERROR_PPCS_ALREADY_INITIALIZED != ret)
{
printf("PPCS_Initialize failed!! ret=%d: %s\n", ret, getP2PErrorCodeInfo(ret));
return 0;
}


// 3. Network Detect   ?à?D???DD?a2??ê??¤??¨°?¨a??ì??¨°???ਢ???¨?3?¨o?à
st_PPCS_NetInfo NetInfo;
ret = PPCS_NetworkDetect(&NetInfo, 0);
if (0 > ret) printf("PPCS_NetworkDetect failed: ret=%d\n", ret);
showNetwork(NetInfo);
//const int Total_Times = TryTimes;
const int TryTimes = 1;
    printf("Time start #################################:%s.\n", __TIME__);
CreateThread_LoginStatus_Check();
printf("main CreateThread_LoginStatus_Check #################################\n");
while(1)
{
Call_P2P_Listen(DID, APILicense, TryTimes);
printf("Call_P2P_Listen:while\n");
}
    printf("Time:%s.\n", __TIME__);
    gThread_Exit = 1; // Exit the LoginStatus_Check thread
ret = PPCS_DeInitialize();
printf("PPCS_DeInitialize() done!\n");
return 0;


}    

int Call_P2P_Listen(const char *DID, const char *APILicense, int TryTimes)
{


gSessionID = PPCS_Listen(DID, 60, 0, 1, APILicense);
if(gSessionID  >= 0)
{    printf("Listen OK (gSessionID=%d): \n", gSessionID);
       RW_Test();
   //break;



else
{
printf("Listen failed (gSessionID=%d): ", gSessionID);
showErrorInfo(gSessionID);
return gSessionID;
}


usleep(50);
PPCS_Close(gSessionID);
printf("end -%02d-PPCS_Close(%d).\n", TryTimes, gSessionID);
return gSessionID;
}


int RW_Test()
{


pthread_t ThreadWriteID[TEST_NUMBER_OF_CHANNEL];
//pthread_t ThreadReadID[TEST_NUMBER_OF_CHANNEL];




memset(g_RW_Test_Info, 0, sizeof(g_RW_Test_Info));
// Creating a read-write test thread 
INT32 i = 0;
//for (i = 0; i < TEST_NUMBER_OF_CHANNEL; i++)
for (i = 0; i < 1; i++)
{


if (0 != pthread_create(&ThreadWriteID[i], NULL, &ThreadWrite, (void *)i)) 
printf("create ThreadWrite failed");




mSleep(10);
}

// Wait for thread to Exit
//INT32 i = 0;
for (i = 0; i < 1; i++)
{


//pthread_join(ThreadReadID[i], NULL);
pthread_join(ThreadWriteID[i], NULL);


}
printf("ThreadWriteID end\n");

// show transmission information for each channel


return 0;

}


void *ThreadWrite(void *arg)
{
    INT32 i = 0;
VENC_STREAM_S stStream;
int frameVideoLen = 0;
HI_CHAR* Buffer = (HI_CHAR*)malloc(MAX_WIDTH);
HI_CHAR* frameVideoBuf = (HI_CHAR*)malloc(MAX_WIDTH);
//char frameVideoBuf[200*1024];
int n1 = 0;
int ret = 0;
//char Buffer[200*1024];
INT32 Channel = (INT32)((UINTp)arg);
if (0 > Channel || 7 < Channel)
{
printf("ThreadWrite - Channel=%d !!\n", Channel);
my_Thread_exit(0);
}
//UCHAR *Buffer = (UCHAR *)malloc(TEST_WRITE_SIZE);
if (!Buffer) 
{
printf("ThreadWrite Channel %d - Malloc failed!!\n", Channel);
my_Thread_exit(0);
}
for (i = 0 ; i < TEST_WRITE_SIZE; i++) 
Buffer[i] = i%251; //0~250
printf("ThreadWrite Channel %d running... \n", Channel);

UINT32 TotalSize = 0;
UINT32 WriteSize = 0;
UINT32 tick = getTickCount();
if (ERROR_PPCS_SUCCESSFUL == PPCS_Check_Buffer(gSessionID, 0, &WriteSize, NULL))   // lin start 0319
{
        SAMPLE_VENC_CLASSIC();
    printf("ThreadWrite PPCS_Check_Buffer gSessionID=%d, Channel=%d   running... \n", gSessionID,0);


}
else
{
printf("ThreadWrite PPCS_Check_Buffer\n");
}
    printf("ThreadWrite END\n");
my_Thread_exit(NULL);  
}


(b)I:\hi3518ev200\liteos\Hi3518E_SDK_V5.0.5.0_wifionly_shangyun\mpp\sample\common\sample_comm_venc.c

                     step 2.4 : call mpi to get one-frame stream
                    *******************************************************/
                    stStream.u32PackCount = stStat.u32CurPacks;
                    s32Ret = HI_MPI_VENC_GetStream(i, &stStream, HI_TRUE);
                    if (HI_SUCCESS != s32Ret)
                    {
                        free(stStream.pstPack);
                        stStream.pstPack = NULL;
                        SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", \
                               s32Ret);
                        break;
                    }


//add clj 20180124
           #if 1
HI_S32 WriteSize = 0;
HI_S32 Channel = 0;

HI_S32 SessionID = gSessionID;
SAMPLE_PRT("HI_S32 gSessionID=%d\n",gSessionID);



                    while (ERROR_PPCS_SUCCESSFUL == PPCS_Check_Buffer(SessionID, Channel, &WriteSize, NULL))
                {
           SAMPLE_PRT("PPCS_Check_Buffer gSessionID=%d, Channel=%d, WriteSize=%x,   running... \n", gSessionID,Channel,WriteSize);
if((WriteSize < 256*1024))
{

HI_S32 frameVideoLen = 0;
HI_S32 j;
for (j = 0; j < stStream.u32PackCount; j++)
    {
memcpy(frameVideoBuf+frameVideoLen+sizeof(P2P_FRAME_HEAD_S), stStream.pstPack[j].u32PhyAddr+stStream.pstPack[j].u32Offset, 
stStream.pstPack[j].u32Len - stStream.pstPack[j].u32Offset);
frameVideoLen += stStream.pstPack[j].u32Len - stStream.pstPack[j].u32Offset;
    }
P2P_FRAME_HEAD_S stframehead={0};
stframehead.frameLen = frameVideoLen;


/*if( frameVideoBuf[sizeof(P2P_FRAME_HEAD_S)+4] == 0x67 ) {   //lin start 0316
printf("##### I frame !");
IFrameNum += 1;
} else {
printf("##### P frame !");
}*/                                                          //lin end 0316

memcpy(frameVideoBuf, &stframehead, sizeof(P2P_FRAME_HEAD_S));


//if( IFrameNum > 15 ) {    //lin  0316
            ret = PPCS_Write(gSessionID, Channel, (CHAR*)frameVideoBuf, frameVideoLen+sizeof(P2P_FRAME_HEAD_S));
//}    //lin  0316
   
if (0 > ret)
{
if (ERROR_PPCS_SESSION_CLOSED_TIMEOUT == ret)
SAMPLE_PRT("Session Closed TimeOUT!!\n");
else if (ERROR_PPCS_SESSION_CLOSED_REMOTE == ret)
SAMPLE_PRT("Session Remote Close!!\n");


break;
}


break;

}
else if(0 == WriteSize)
{
SAMPLE_PRT("WriteSize = 0\n");
break;
}
else
{
SAMPLE_PRT("WriteSize big > 256*1024\n");
//usleep(200);
break;   
}


}
//SAMPLE_PRT("while##############end SessionID=(%d)\n",SessionID);
#endif

5.编译 make root@dreams:~/ipc/hi3518ev200/liteos/Hi3518E_SDK_V5.0.5.0/mpp/sample# 

也可以在具体的应用下面编译:

譬如 make root@dreams:~/ipc/hi3518ev200/liteos/Hi3518E_SDK_V5.0.5.0/mpp/sample/venc/

你可能感兴趣的:(驱动管理)