19,502
社区成员
发帖
与我相关
我的任务
分享
// TestCode.cpp : Defines the entry point for the console application.
//
#include <windows.h>
#include <stdio.h>
#include <ddraw.h>
#include "SsbSipH264Decode.h"
#include "FrameExtractor.h"
#include "H264Frames.h"
#include "mfc_decode.h"
#include "mfc_render.h"
#include "number_img.h"
#include "Record.h"
#include "icamprotocol.h"
#include "hw_lib.h"
//#define MAX_STREAM_BUFFER_NUM 5
static unsigned char delimiter_h264[4] = {0x00, 0x00, 0x00, 0x01};
int nLoop;
DWORD t1, t2, t_diff; // tick for performance measurement
int perf_disp_period = 100;
wchar_t str_performance[8];
float fps;
//decoder
unsigned char *pStrmBuf;
int nFrameLeng;
unsigned char *pYUVBuf;
int nYUVLeng;
FRAMEX_CTX *pFrameExCtx;
unsigned char *delimiter;
int delimiter_leng;
SSBSIP_H264_STREAM_INFO stream_info;
STREAM_BUFFER_INFO *streamBufferInfo;
SIZE_IMG_IDX size_img_idx;
void *decoderHandle;
void *hRender;
static int flag=0;
void *video_disp_handle;
extern queue<CAudioData> video_vData;
extern queue<CAudioData> first_vData;
//unsigned char firstvideo[1024*30];
extern CAudioData video_first;
extern int del_device_flg;
//extern FRAMEX_CTX *FrameExtractorInit(FRAMEX_IN_TYPE type, unsigned char delimiter[], int delim_leng, int delim_insert);
//static DWORD WINAPI mfcdec_demo(void)
int mfcdec_demo(void)
{
delimiter = delimiter_h264;
delimiter_leng = sizeof(delimiter_h264);
STREAM_BUFFER_INFO *streamBufferInfo;
int encoderFrameBufCounter=0;
CAudioData disp_data;
disp_data.data=(unsigned char*)malloc(1024*300*sizeof(unsigned char));
//init render
//int decoderBufCounter = 0;
//printf("896585868096086096\n");
///////////////////////////////////
// FrameExtractor Initialization //
///////////////////////////////////
pFrameExCtx = FrameExtractorInit(FRAMEX_IN_TYPE_MEM, delimiter, delimiter_leng, 1);
//////////////////////////////////////
/// 1. Create new instance ///
//////////////////////////////////////
//printf("front645646\n");
decoderHandle = SsbSipH264DecodeInit();
if (decoderHandle == NULL) {
RETAILMSG(1,(L"Decoder Init Failed.\n"));
return 0;
}
//printf("back45546\n");
/////////////////////////////////////////////
/// 2. Obtaining the Input Buffer ///
/// (SsbSipH264DecodeGetInBuf) ///
/////////////////////////////////////////////
pStrmBuf = (unsigned char *) SsbSipH264DecodeGetInBuf(decoderHandle, 204800);
if (pStrmBuf == NULL) {
RETAILMSG(1,(L"SsbSipH264DecodeGetInBuf Failed.\n"));
SsbSipH264DecodeDeInit(decoderHandle);
return 0;
}
/**********copy receive data***********/
memcpy(pStrmBuf,video_first.data,video_first.length);
nFrameLeng=video_first.length;
// for(int i=0;i<21;i++)
// {
// printf("pStrmBuf[%d]=%d\n",i,pStrmBuf[i]);
// }
// for(int i=0;i<5;i++)
// printf("video_vData.front().data[%d]=%d\n",i,video_vData.front().data[i]);
//printf("nFrameLeng=%d\n",nFrameLeng);
////////////////////////////////////////////////////////////////
/// 3. Configuring the instance with the config stream ///
/// (SsbSipH264DecodeExe) ///
////////////////////////////////////////////////////////////////
printf("nFrameLeng=%d\n",nFrameLeng);
if (SsbSipH264DecodeExe(decoderHandle, nFrameLeng) != SSBSIP_H264_DEC_RET_OK) {
// free(disp_data.data);
RETAILMSG(1,(L"H.264 Decoder Configuration Failed.\n"));
return 0;
}
/////////////////////////////////////
/// 4. Get stream information ///
/////////////////////////////////////
if((SsbSipH264DecodeGetConfig(decoderHandle, H264_DEC_GETCONF_STREAMINFO, &(stream_info)))==SSBSIP_H264_DEC_RET_OK)
printf("SsbSipH264DecodeGetConfig success!\n");
//RETAILMSG(1,(L"\n\t<STREAMINFO> width=%d height=%d.\n", stream_info[pip].width, stream_info[pip].height));
/*********************render for display************************/
// Performance display interval setting
hRender = mfc_render_create_overlay(MFC_RENDER_SURFACE_TYPE_YV12,
0, 0,
stream_info.width, stream_info.height,
256, 220);
// 320,240);
//352,208);
// 480,272);
if ((stream_info.width == 320) && (stream_info.height == 240)) {
size_img_idx = SIZE_IMG_QVGA;
perf_disp_period = 200;
}
else if ((stream_info.width == 640) && (stream_info.height == 480)) {
size_img_idx = SIZE_IMG_VGA;
perf_disp_period = 100;
}
else if ((stream_info.width == 720) && (stream_info.height == 480)) {
size_img_idx = SIZE_IMG_SD;
perf_disp_period = 60;
}
else if ((stream_info.width == 720) && (stream_info.height == 576)) {
size_img_idx = SIZE_IMG_SD;
perf_disp_period = 60;
}
else {
size_img_idx = SIZE_IMG_UNDEF;
perf_disp_period = 100;
}
t1 = GetTickCount();
for (nLoop=0; ; ) {
if(del_device_flg)
{
printf("release device@@@@@@@@@@@\n");
mfc_render_delete_overlay(hRender);
del_device_flg=0;
if(0==SsbSipH264DecodeDeInit(decoderHandle))
printf("close video device success!\n");
else
printf("close video device failed!\n");
break;
}
if(video_vData.size()!=0)
{
//直接copy到显示buffer //show camera yuv buffer to display
//memcpy(decoderOutBuf[decoderBufCounter],inYUVbuf[encoderFrameBufCounter],BUFF_SIZE);
//////////////////////////////////
/// 5. DECODE ///
/// (SsbSipH264DecodeExe) ///
//////////////////////////////////
if (SsbSipH264DecodeExe(decoderHandle, nFrameLeng) != SSBSIP_H264_DEC_RET_OK) {
// sprintf(msg, "\n\t Error in decoding -th video, %d-th frame\n", nLoop);
RETAILMSG(1,(L"DECODE ERROR\n"));
continue;
}
// printf("nFrameLeng=%d\n",nFrameLeng);
//////////////////////////////////////////////
/// 6. Obtaining the Output Buffer ///
/// (SsbSipH264DecodeGetOutBuf) ///
//////////////////////////////////////////////
pYUVBuf = (unsigned char *) SsbSipH264DecodeGetOutBuf(decoderHandle, (long *) &(nYUVLeng));
//printf("nYUVLeng=%ld\n",nYUVLeng);
mfc_render_do(hRender, pYUVBuf, stream_info.width, stream_info.height, MFC_RENDER_IMAGE_TYPE_YUV420);
mfc_render_flip(hRender);
// Next VIDEO stream //
//将解码流数据buffer送入解码器 //copy next stream frame to decoder
//printf("video_vData.size=%d\n",video_vData.size());
memcpy(pStrmBuf,video_vData.front().data,video_vData.front().length);
nFrameLeng=video_vData.front().length;
video_vData.pop();
nLoop++;
if (nLoop == perf_disp_period) {
t2 = GetTickCount();
t_diff = t2 - t1;
fps = (float)(1000 * nLoop) / t_diff;
wsprintf(str_performance, L"%3.1f", fps);
printf("Decoder =%s fps\n", str_performance);
nLoop = 0;
t1 = GetTickCount();
}
}
else
continue;
}
free(disp_data.data);
return 0;
}
,以上是我实现显示的代码,采用的是overlay的方式,请问该怎么解决这个问题呢?