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

📄 testcode.c

📁 6410BSP3
💻 C
📖 第 1 页 / 共 2 页
字号:
        p_outbuf = SsbSipH264EncodeGetOutBuf(handle, &size);
        printD("[APP] Output Buf = 0x%X,  size = %d\n", (DWORD) p_outbuf, size);

// 
// 7. Make File
//
        if(i<ENC_MAKE_LOOF)
        {
            nWriteSize=fwrite(p_outbuf, 1, size, fp_out);
            if(nWriteSize!= size)
            {
                printD("[APP] Error fwrite :: size=%d \r\n", nWriteSize);
                break;
            }
        }        
        printD("[APP] %d Encoded.\r\n", i);
    }

    SsbSipH264EncodeDeInit(handle);
    printD("[APP]  Deinit\r\n");

    fclose(fp_in);
    fclose(fp_out);

    return 0;
}






////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//  H253 encoder 包访 抛胶飘 内靛
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
int H263_enc_test(char *InputFile, char *OutputFile, unsigned int uiWidth, unsigned int uiHeight, unsigned int uiframerate, unsigned int uibitrate)
{
    void               *handle;
    FILE            *fp_in, *fp_out;
    int                ret, i;
    unsigned int     width, height;
    unsigned int    frame_rate, bitrate, gop_num;
    unsigned int   intraqp, qpmax;
    float gamma;
    unsigned int   num_slices, h263_annex;    
    unsigned int   change_param[2];
    long               size;
    unsigned char *p_inbuf;
    unsigned char *p_outbuf;
    int            nWriteSize;

#ifdef FPS
    INT32    decodeTime;
    INT32    sum_decodeTime=0;
    INT32    ave_decodeTime=0;
#endif

    printD(" ***** H263 ENC START ***** \r\n\n");

//
// 0. Open File
//
    fp_in = fopen(InputFile,"rb");
    if (fp_in == NULL) 
    {
        printD("[APP]File not found\n");
        return 0;
    }
    fp_out = fopen(OutputFile, "wb");
    if (fp_out == NULL) 
    {
        printD("[APP]Cannot open the output file.\n");
        return 0;

    }

// 
// 1. Encode Create Instance
//
    width      = uiWidth;
    height     = uiHeight;
    frame_rate = uiframerate;
    bitrate    = uibitrate;
    gop_num    = frame_rate;

    intraqp = 10;
    qpmax = 10;
    gamma = 0.75;
    
    handle = SsbSipMPEG4EncodeInit(SSBSIPMFCENC_H263, width,      height,
                                   frame_rate, bitrate, gop_num, intraqp, qpmax, gamma);
    if (handle == NULL)
    {
        return 0;
    }
    printD("[APP]\n HANDLE = 0x%X.\n", (DWORD) handle);

// 
// 2. Initialize Instance
//
#define ANNEX_T_OFF                        (0<<0)
#define ANNEX_T_ON                        (1<<0)
#define ANNEX_K_OFF                        (0<<1)
#define ANNEX_K_ON                        (1<<1)
#define ANNEX_J_OFF                        (0<<2)
#define ANNEX_J_ON                        (1<<2)
#define ANNEX_I_OFF                        (0<<3)
#define ANNEX_I_ON                        (1<<3)
    num_slices = 1;
    SsbSipMPEG4EncodeSetConfig(handle, MPEG4_ENC_SETCONF_H263_NUM_SLICES, &num_slices);
    h263_annex = ANNEX_K_ON;
    SsbSipMPEG4EncodeSetConfig(handle, MPEG4_ENC_SETCONF_H263_ANNEX,      &h263_annex);

    if (SsbSipMPEG4EncodeExe(handle) != SSBSIP_MPEG4_ENC_RET_OK) {
        RETAILMSG(1,(L"MPEG4 Encoder Instance Initialization Failed.\r\n"));
        return 0;
    }

//
// 3. Get Input(YUV420) Buffer Address
//
    p_inbuf = SsbSipMPEG4EncodeGetInBuf(handle, 0);
    if (p_inbuf == NULL) {
        return 0;
    }
    
    for (i=0; i<ENC_LOOF; i++)
    {
        
//
// 4. Copy YUV into Input Buffer
//
        if( (fread(p_inbuf, 1, (width * height * 3) >> 1, fp_in)) != (width * height * 3) >> 1)
            break;

// 
// 5. Encode
//    
#ifdef FPS
        decodeTime = GetTickCount();
#endif
        do
        {
            ret = SsbSipMPEG4EncodeExe(handle) ;
            if(ret == SSBSIP_MPEG4_ENC_RET_OK)
                break;
            else
            {
//                if(ret == SSBSIP_MPEG4_ENC_RET_ERR_STATE_POWER_OFF)
                if(ret == -1004)
                               {
                    printD("[APP] MFC Sleeping -> Wait!!! .\r\n");
                    Sleep(1000);
                }
                else
                    break;
            }
        }while(1);

        if (ret != SSBSIP_MPEG4_ENC_RET_OK)
        {
            printD("[APP]H263 Encoder Failed! :: ret=%d \r\n", ret);
            break;
        }

#ifdef FPS
        decodeTime = GetTickCount() - decodeTime;
        sum_decodeTime+=decodeTime;
        ave_decodeTime=sum_decodeTime/(i+1);
        printf( "[Performance]decodeTime : %d  ave_decodeTime: %d \n", decodeTime,ave_decodeTime);
#endif

        printD("[APP] Encode, ret=%d\n", ret);


//
// 6. Get Output(Stream) Buffer Address
//
        p_outbuf = SsbSipMPEG4EncodeGetOutBuf(handle, &size);
//        printD("[APP] Output Buf = 0x%X,  size = %d\n", (DWORD) p_outbuf, size);

// 
// 7. Make File
//
        if(i<ENC_MAKE_LOOF)
        {
            nWriteSize=fwrite(p_outbuf, 1, size, fp_out);
            if(nWriteSize!= size)
            {
                printD("[APP] Error fwrite :: size=%d \r\n", nWriteSize);
                break;
            }
        }        
        printD("[APP] %d Encoded.\r\n", i);
    }

    SsbSipMPEG4EncodeDeInit(handle);
    printD("[APP]  Deinit\r\n");

    fclose(fp_in);
    fclose(fp_out);

    return 0;
}





////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//  MPEG4 encoder 包访 抛胶飘 内靛
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
int mpeg4_enc_test(char *InputFile, char *OutputFile, unsigned int uiWidth, unsigned int uiHeight, unsigned int uiframerate, unsigned int uibitrate)
{
    void               *handle;
    FILE            *fp_in, *fp_out;
    int                ret, i;
    unsigned int     width, height;
    unsigned int    frame_rate, bitrate, gop_num;
    unsigned int   intraqp, qpmax;
    float gamma;
    unsigned int   change_param[2];
    long               size;
    unsigned char *p_inbuf;
    unsigned char *p_outbuf;
    int            nWriteSize;

#ifdef FPS
    INT32    decodeTime;
    INT32    sum_decodeTime=0;
    INT32    ave_decodeTime=0;
#endif

    printD(" ***** MPEG4 ENC START ***** \r\n\n");

//
// 0. Open File
//
//    fp_in = fopen("\\My Documents\\news_qvga.yuv","rb");
    fp_in = fopen(InputFile,"rb");
    if (fp_in == NULL) 
    {
        printD("[APP]File not found\n");
        return 0;
    }
    fp_out = fopen(OutputFile, "wb");
    if (fp_out == NULL) 
    {
        printD("[APP]Cannot open the output file.\n");
        return 0;

    }

// 
// 1. Encode Create Instance
//
    width      = uiWidth;
    height     = uiHeight;
    frame_rate = uiframerate;
    bitrate    = uibitrate;
    gop_num    = frame_rate;

    intraqp = 10;
    qpmax = 10;
    gamma = 0.75;
    
    handle = SsbSipMPEG4EncodeInit(SSBSIPMFCENC_MPEG4, width,      height,
                                   frame_rate, bitrate, gop_num,intraqp, qpmax, gamma);
    if (handle == NULL)
    {
        return 0;
    }
    printD("[APP]\n HANDLE = 0x%X.\n", (DWORD) handle);

// 
// 2. Initialize Instance
//
    if (SsbSipMPEG4EncodeExe(handle) != SSBSIP_MPEG4_ENC_RET_OK) {
        RETAILMSG(1,(L"MPEG4 Encoder Instance Initialization Failed.\r\n"));
        return 0;
    }

//
// 3. Get Input(YUV420) Buffer Address
//
    p_inbuf = SsbSipMPEG4EncodeGetInBuf(handle, 0);
    if (p_inbuf == NULL) {
        return 0;
    }

    for (i=0; i<ENC_LOOF; i++)
    {

//
// 4. Copy YUV into Input Buffer
//
        if( (fread(p_inbuf, 1, (width * height * 3) >> 1, fp_in)) != (width * height * 3) >> 1)
            break;

// 
// 5. Encode
//        
#ifdef FPS
        decodeTime = GetTickCount();
#endif
        do
        {
            ret = SsbSipMPEG4EncodeExe(handle) ;
            if(ret == SSBSIP_MPEG4_ENC_RET_OK)
                break;
            else
            {
                if(ret == -1004)
                {
                    printD("[APP] MFC Sleeping -> Wait!!! .\r\n");
                    Sleep(1000);
                }
                else
                    break;
            }
        }while(1);

        if (ret != SSBSIP_MPEG4_ENC_RET_OK)
        {
            printD("[APP]MPEG4 Encoder Failed! :: ret=%d \r\n", ret);
            break;
        }

#ifdef FPS
        decodeTime = GetTickCount() - decodeTime;
        sum_decodeTime+=decodeTime;
        ave_decodeTime=sum_decodeTime/(i+1);
        printf( "[Performance]decodeTime : %d  ave_decodeTime: %d \n", decodeTime,ave_decodeTime);
#endif

        printD("[APP] Encode, ret=%d\n", ret);


//
// 6. Get Output(Stream) Buffer Address
//
        p_outbuf = SsbSipMPEG4EncodeGetOutBuf(handle, &size);
//        printD("[APP] Output Buf = 0x%X,  size = %d\n", (DWORD) p_outbuf, size);

// 
// 7. Make File
//
        if(i<    ENC_MAKE_LOOF)
        {
            nWriteSize=fwrite(p_outbuf, 1, size, fp_out);
            if(nWriteSize!= size)
            {
                printD("[APP] Error fwrite :: size=%d \r\n", nWriteSize);
                break;
            }
        }        
        printD("[APP] %d Encoded.\r\n", i);
        
    }

    SsbSipMPEG4EncodeDeInit(handle);
    printD("[APP]  Deinit\r\n");

    fclose(fp_in);
    fclose(fp_out);

    return 0;
}


int _tmain()
{
    char *InputFile;

    //
    // Encoding Test
    //
    InputFile = "\\Storage Card\\input_qvga.yuv";
    {H264_enc_test  (InputFile,"\\output.264",320,240,15,384);                 printD("[APP]EncEnd output.264 \r\n\n\n");     }
    {H263_enc_test  (InputFile,"\\output.263",320,240,15,384);                 printD("[APP]EncEnd output.263 \r\n\n\n");     }
    {mpeg4_enc_test(InputFile,"\\output.m4v",320,240,15,384);                printD("[APP]EncEnd output.m4v \r\n\n\n");    } 

    //
    // Decoding Test
    //
    InputFile = "\\Storage Card\\Input.m4v";
    {mpeg4dec_test (InputFile, "\\output_m4v.yuv");                                printD("[APP]DecEnd input.m4v \r\n\n\n"); }
    return 0;
}

⌨️ 快捷键说明

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