⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 video_vo.c

📁 sample on embedded linux
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>#include <pthread.h>#include <errno.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <sys/select.h>#include <sys/time.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <sys/stat.h>#include <fcntl.h>#include <arpa/inet.h>#include "hi_common_api.h"char args[10][255];#define HI_ALIGN_LENGTH(v,a) ((((v) + ((a)-1)) & (~((a)-1))))typedef struct hiVDEC_RECEIVE_THTREAD_ARGS{    HI_S32 chnum;    VDEC_CHN ChanID;}VDEC_RECEIVE_THTREAD_ARGS;/*for rtp********************************************************************/#define IN#define OUT#define IO#define RPT_MAX_PACKET_BUFF 4096#define HI_SockLen_T socklen_t#define HI_Pthread_T pthread_t#define HI_SSIZE_T ssize_ttypedef unsigned short  HI_PORT;typedef int RTP_SOCKET;HI_S32 s32vdecthreadflag;HI_S32 s32vdecsendthreadflag;volatile int oout[4] = {1, 1, 1, 1};int send_chn[4] = {0, 1, 2, 3};//int send_chn[4] = {3, 2, 0, 1};VDEC_CHN ChanID[4];void* receive_thread_multi(void *args){    VDEC_RECEIVE_THTREAD_ARGS *parg = args;    int i;    int vdec_ch;    int vo_chn;    VDEC_FRAMEINFO_S frameinfo;    while(s32vdecthreadflag)    {        for (i=0;i<parg->chnum;i++)        {            vdec_ch = ChanID[i];            vo_chn = send_chn[vdec_ch];            HI_VDEC_Receive(vdec_ch, &frameinfo, NULL, HI_TRUE);            if (frameinfo.value)            {                if(oout[vo_chn])                {                    if(HI_VO_SendData(vo_chn, &frameinfo) != HI_SUCCESS)                    {                        HI_VDEC_ReleaseVideoBuf(vdec_ch, &frameinfo);                    }                }                else                {                    HI_VDEC_ReleaseVideoBuf(vdec_ch, &frameinfo);                }            }        }        //usleep(1000);    }    printf("break while!\n");    pthread_exit(NULL);}void * vo_test_Video_Decoder_MultiChannel(void * tt_args)//void* vo_setattr_thread(void *args){    VDEC_ATTR_TYPE_E type = VDEC_ATTR_ALL;    VDEC_ChannelPara_S config;    HI_S32 ret;    HI_U64 pts;    VDEC_STREAM_S stream;    char fnStream[] = "dec.h264";    FILE*      fhStream;    HI_U32 len_nalu = 0;    char *streambuf;    pthread_t thread;    static VDEC_RECEIVE_THTREAD_ARGS arg;    int Maxchnum = atoi(args[1]);    int chindex = atoi(args[2]);    int i;    streambuf = malloc(0x10000);    if (NULL == streambuf)    {        printf("malloc failed !\n");        return;    }    *streambuf = 0x0;    *(streambuf+1) = 0x0;    *(streambuf+2) = 0x0;    *(streambuf+3) = 0x1;    /*set config value*/    config.type = VDEC_H264;    config.framenumber = 10;    config.picformat = VDEC_DEFAULT_PICTUREFORMAT;    /*create all the VDEC cahnnel*/    for (i=0;i<Maxchnum;i++)    {        ret = HI_VDEC_CreateCH(&ChanID[i], type, &config);        if (HI_SUCCESS == ret)        {            printf("test_Video_Decoder_MultiChannel:Create a Channel: %d\n",ChanID[i]);        }        else        {            printf("test_Video_Decoder_MultiChannel:failed at create ch %d\n",i);            exit(-1);        }    }    printf("** file to decode is %s . **\n", fnStream);    fhStream = fopen(fnStream, "rb");    if (fhStream == NULL)    {        printf("open file %s to decode error: %#x.\n", fnStream, errno);        return;    }    arg.ChanID = ChanID[chindex];    arg.chnum = Maxchnum;    s32vdecthreadflag = 1;    pthread_create(&thread, NULL, receive_thread_multi, &arg);    stream.Dataaddr = (ADDR)streambuf;    pts = 0;    while(1)    {        if (1 != fread(&len_nalu, 4, 1, fhStream))        {            printf("read nalu length error.\n");            break;        }        stream.Datalen = len_nalu;        len_nalu = HI_ALIGN_LENGTH(len_nalu, 2);        if ( len_nalu != fread(streambuf+4, 1,len_nalu, fhStream) )        {            printf("read nalu error.\n");            break;        }        stream.Datalen += 4;        stream.pts = pts;        for (i=0;i<Maxchnum;i++)        {            ret = HI_VDEC_SendStream(ChanID[i], &stream, HI_TRUE);            while(HI_SUCCESS != ret)            {                if(HI_ERR_VDEC_NO_PAYLOAD == ret)break;                /*retry*/                ret = HI_VDEC_SendStream(ChanID[i], &stream, HI_TRUE);            }        }        pts++;        if (150000== pts)break;    }    fclose(fhStream);    /*wait until all the data is decode over*/    usleep(500000);    s32vdecthreadflag = 0;    pthread_join(thread, NULL);    /*destroy all the decode channel*/    for (i=0;i<Maxchnum;i++)    {        ret = HI_VDEC_DestroyCH(ChanID[i]);        if (HI_SUCCESS == ret)        {            printf("test_Video_Decoder_MultiChannel:destroy ch %d\n",ChanID[i]);        }    }    free(streambuf);}#define PACKET_HEADER_SIZE 8#define RECEIVEBUF_NUM 100HI_S32 file_fd;HI_S32 onrecv_count = 0;HI_CHAR receivebuf[RECEIVEBUF_NUM][2048+PACKET_HEADER_SIZE];HI_S32 read_pointer;HI_S32 write_pointer;/*read data from receive buffer*/void* sendstream_thread(void *args){    VDEC_RECEIVE_THTREAD_ARGS *parg = args;    HI_S32 retrycount = 0;    VDEC_STREAM_S stream;    HI_S32 ret;    while(s32vdecsendthreadflag)    {        while(read_pointer != write_pointer)        {            stream.Dataaddr = (ADDR)&receivebuf[read_pointer][8];            stream.Datalen = *((HI_S32 *)(&receivebuf[read_pointer][0]));            stream.pts = *((HI_S32 *)(&receivebuf[read_pointer][4]));            ret = HI_VDEC_SendStream(parg->ChanID, &stream, HI_TRUE);            while(HI_SUCCESS != ret)            {                if(HI_ERR_VDEC_NO_PAYLOAD == ret)break;                //printf("*");                /*protect measure*/                if(retrycount > 80000)                {                    printf("HI_VDEC_SendStream failed at %d retries\n",retrycount);                    //exit(1);                    break;                }                ret = HI_VDEC_SendStream(parg->ChanID, &stream, HI_TRUE);                retrycount++;            }            retrycount = 0;            read_pointer++;            //printf("read_pointer %d\n",read_pointer);            if(read_pointer == RECEIVEBUF_NUM)read_pointer = 0;        }//        usleep(100);    }    printf("sendstream_thread break while!\n");    pthread_exit(NULL);}static HI_BOOL g_s32VencStopFlag[VENC_MAX_CHN_NUM] =     {HI_FALSE, HI_FALSE, HI_FALSE, HI_FALSE, HI_FALSE, HI_FALSE, HI_FALSE, HI_FALSE};void* vo_setattr_thread(void *args){    int i;    VO_CHN_ATTR_S  chn_attr ;    int l_oout[4];    memcpy(&l_oout, &oout, sizeof(int)*4);    /* wait for VDEC to create the channel */    sleep(10);    /* disable all the vo channel */    for(i=0; i<4; i++)    {        if(l_oout[i])        {            fprintf(stderr, "VO[%d] enable->disable......", i);            fflush(stderr);            oout[i] = 0;            /* wait data from VDEC*/            //sleep(1);            fprintf(stderr, "done!\n");                        if( HI_VO_GetChnAttr(i, &chn_attr)!= HI_SUCCESS)            {                printf("HI_VO_GetChnAttr error\n");            }            chn_attr.enable = HI_FALSE;            if ( HI_VO_SetChnAttr(i, &chn_attr)!= HI_SUCCESS)            {                printf("HI_VO_SetChnAttr error\n");            }        }        sleep(2);    }    /* enable VO channel */    for(i=0; i<4; i++)    {        fprintf(stderr, "VO[%d] disable->enable......", i);        fflush(stderr);                if(l_oout[i])        {            if( HI_VO_GetChnAttr(i, &chn_attr)!= HI_SUCCESS)            {                printf("HI_VO_GetChnAttr error\n");            }            chn_attr.enable = HI_TRUE;            if ( HI_VO_SetChnAttr(i, &chn_attr)!= HI_SUCCESS)            {                printf("HI_VO_SetChnAttr error\n");            }            //sleep(1);            oout[i] = 1;                 fprintf(stderr, "done!\n");        }        sleep(2);    }    /* disable  all vo channel */    for(i=0; i<4; i++)    {        if(l_oout[i])        {            fprintf(stderr, "VO[%d] enable->disable......", i);            fflush(stderr);            oout[i] = 0;            /* wait data from VO*/            //sleep(1);            fprintf(stderr, "done!\n");                        if( HI_VO_GetChnAttr(i, &chn_attr)!= HI_SUCCESS)            {                printf("HI_VO_GetChnAttr error\n");            }            chn_attr.enable = HI_FALSE;            if ( HI_VO_SetChnAttr(i, &chn_attr)!= HI_SUCCESS)            {                printf("HI_VO_SetChnAttr error\n");            }        }        sleep(2);    }    }void vo_test_open(VIDEO_NORM_E compose_mode){    if(HI_VO_Init() != HI_SUCCESS)    {        printf("VO INIT ERROR\n");        return ;    }    VO_PUBLIC_ATTR_S  pub_attr ;    memset(&pub_attr, 0, sizeof(VO_PUBLIC_ATTR_S));    if(HI_VO_GetPublicAttr(&pub_attr) != HI_SUCCESS)    {        printf("HI_VO_GetPublicAttr error\n");        return;    }    pub_attr.enable = HI_TRUE;    /* TV mode */    pub_attr.display_mode = VO_MODE_BT656;    pub_attr.tv_config.enMaster = VIDEO_CONTROL_MODE_MASTER;    pub_attr.tv_config.compose_mode = compose_mode;    pub_attr.tv_config.seriatim_mode = HI_TRUE;    pub_attr.background_color = 0x00ff00;   /* blue */    pub_attr.vo_chn_img_num = 4;    pub_attr.pip_buf_num = 4;    if(HI_VO_SetPublicAttr(&pub_attr) != HI_SUCCESS)    {        printf("HI_VO_SetPublicAttr error\n");        return;    }    VO_CHN_ATTR_S  chn_attr ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -