📄 mfc_decode.cpp
字号:
/// 1. Create new instance ///
//////////////////////////////////////
handle[pip] = pFP_LIST[pip]->fp_SsbSipDecodeInit();
if (handle[pip] == NULL) {
RETAILMSG(1,(L"Decoder Init Failed.\n"));
return 0;
}
/////////////////////////////////////////////
/// 2. Obtaining the Input Buffer ///
/// (SsbSipH264DecodeGetInBuf) ///
/////////////////////////////////////////////
pStrmBuf[pip] = (unsigned char *) pFP_LIST[pip]->fp_SsbSipDecodeDecodeGetInBuf(handle[pip], 204800);
if (pStrmBuf[pip] == NULL) {
RETAILMSG(1,(L"SsbSipH264DecodeGetInBuf Failed.\n"));
pFP_LIST[pip]->fp_SsbSipDecodeDeInit(handle[pip]);
return 0;
}
//////////////////////////////
// CONFIG stream extraction //
//////////////////////////////
switch (codec_mode[pip]) {
case CODEC_MPEG4:
nFrameLeng[pip] = ExtractConfigStreamMpeg4(pFrameExCtx[pip], fp[pip], pStrmBuf[pip], INPUT_BUFFER_SIZE, NULL);
break;
case CODEC_H263:
nFrameLeng[pip] = ExtractConfigStreamH263(fp[pip], pStrmBuf[pip], INPUT_BUFFER_SIZE, NULL);
break;
case CODEC_H264:
nFrameLeng[pip] = ExtractConfigStreamH264(pFrameExCtx[pip], fp[pip], pStrmBuf[pip], INPUT_BUFFER_SIZE, NULL);
break;
case CODEC_VC1:
nFrameLeng[pip] = ExtractConfigStreamVC1(fp[pip], pStrmBuf[pip], INPUT_BUFFER_SIZE, NULL);
}
if (nFrameLeng[pip] == 0) {
RETAILMSG(1, (L"\nFailed in extracting the CONFIG stream."));
return 0;
}
////////////////////////////////////////////////////////////////
/// 3. Configuring the instance with the config stream ///
/// (SsbSipH264DecodeExe) ///
////////////////////////////////////////////////////////////////
if (pFP_LIST[pip]->fp_SsbSipDecodeExe(handle[pip], nFrameLeng[pip]) != SSBSIP_H264_DEC_RET_OK) {
RETAILMSG(1,(L"H.264 Decoder Configuration Failed.\n"));
return 0;
}
/////////////////////////////////////
/// 4. Get stream information ///
/////////////////////////////////////
pFP_LIST[pip]->fp_SsbSipDecodeGetConfig(handle[pip], H264_DEC_GETCONF_STREAMINFO, &(stream_info[pip]));
RETAILMSG(1,(L"\n\t<STREAMINFO> width=%d height=%d.\n", stream_info[pip].width, stream_info[pip].height));
#if (DECODED_OUTPUT == DECODED_OUT_DISP)
// Direct Draw surface creation
// The surface size is determined by the input video stream
// Because only one YV12 type surface is supported,
// 0-th surface is assigned as YV12 surface and the others are asssigned as RGB565.
if (pip == 0) {
hRender[pip] = mfc_render_create_overlay(MFC_RENDER_SURFACE_TYPE_YV12,
0, 0,
stream_info[pip].width, stream_info[pip].height,
// stream_info[pip].width, stream_info[pip].height);
800, 480);
}
else {
hRender[pip] = mfc_render_create_overlay(MFC_RENDER_SURFACE_TYPE_RGB565,
0, 0,
stream_info[pip].width, stream_info[pip].height,
stream_info[pip].width, stream_info[pip].height);
}
if (hRender[pip] == NULL) {
RETAILMSG(1, (L"\nMFC RENDER overlay surface [%d] creation failed.", pip));
return -1;
}
#endif
}
#if (DECODED_OUTPUT == DECODED_OUT_DISP)
#if (PROPERTY_WINDOW == 1)
hRender_property = mfc_render_create_overlay(MFC_RENDER_SURFACE_TYPE_RGB565,
0, 0,
PROPERTY_WINDOW_WIDTH, PROPERTY_WINDOW_HEIGHT,
PROPERTY_WINDOW_WIDTH, PROPERTY_WINDOW_HEIGHT);
if (hRender_property == NULL) {
RETAILMSG(1, (L"\nMFC RENDER overlay property surface creation failed."));
return -1;
}
if (NumImg_MemLoad(character_img) == FALSE) {
RETAILMSG(1, (L"\nMFC character image file cannot be found."));
return -1;
}
if (SizeImg_MemLoad(size_img) == FALSE) {
RETAILMSG(1, (L"\nMFC size image file cannot be found."));
return -1;
}
memset(g_property_window, 0xFF, sizeof(g_property_window));
#endif
// Performance display interval setting
if ((stream_info[0].width == 320) && (stream_info[0].height == 240)) {
size_img_idx = SIZE_IMG_QVGA;
perf_disp_period = 200;
}
else if ((stream_info[0].width == 640) && (stream_info[0].height == 480)) {
size_img_idx = SIZE_IMG_VGA;
perf_disp_period = 100;
}
else if ((stream_info[0].width == 720) && (stream_info[0].height == 480)) {
size_img_idx = SIZE_IMG_SD;
perf_disp_period = 60;
}
else if ((stream_info[0].width == 720) && (stream_info[0].height == 576)) {
size_img_idx = SIZE_IMG_SD;
perf_disp_period = 60;
}
else {
size_img_idx = SIZE_IMG_UNDEF;
perf_disp_period = 100;
}
#else
// Print Inteval of Performance value into colsole (Regardless of image size, it is set to fixed value.)
perf_disp_period = 60;
#endif
RETAILMSG(1,(L"\nSTARTING MFC decoding (PIP=%d)\n", num_pips));
t1 = GetTickCount();
for (nLoop=0; ; nLoop++) {
if (*force_exit) {
RETAILMSG(1,(L"\nFORCE EXIT\n"));
break;
}
for (pip=0; pip < num_pips; pip++) {
//////////////////////////////////
/// 5. DECODE ///
/// (SsbSipH264DecodeExe) ///
//////////////////////////////////
if (pFP_LIST[pip]->fp_SsbSipDecodeExe(handle[pip], nFrameLeng[pip]) != SSBSIP_H264_DEC_RET_OK) {
sprintf(msg, "\n\t Error in decoding %d-th video, %d-th frame\n", pip, nLoop);
LogMsg();
// *force_exit=1;
RETAILMSG(1,(L"\n-----------------------------\n"));
RETAILMSG(1,(L"DECODE ERROR\n"));
RETAILMSG(1,(L"DECODE ERROR\n"));
RETAILMSG(1,(L"DECODE ERROR\n"));
RETAILMSG(1,(L"DECODE ERROR\n"));
RETAILMSG(1,(L"-----------------------------\n"));
continue;
}
//////////////////////////////////////////////
/// 6. Obtaining the Output Buffer ///
/// (SsbSipH264DecodeGetOutBuf) ///
//////////////////////////////////////////////
pYUVBuf[pip] = (unsigned char *) pFP_LIST[pip]->fp_SsbSipDecodeDecodeGetOutBuf(handle[pip], (long *) &(nYUVLeng[pip]));
RETAILMSG(0,(L"\t [%d] decoded.\n", nLoop));
///////////////////////
// Next VIDEO stream //
///////////////////////
switch (codec_mode[pip]) {
case CODEC_VC1:
nFrameLeng[pip] = NextFrameVC1(fp[pip], pStrmBuf[pip], INPUT_BUFFER_SIZE, NULL);
break;
case CODEC_H263:
nFrameLeng[pip] = NextFrameH263(fp[pip], pStrmBuf[pip], INPUT_BUFFER_SIZE, NULL);
break;
default:
nFrameLeng[pip] = pFP_LIST[pip]->fp_NextFrame(pFrameExCtx[pip], fp[pip], pStrmBuf[pip], INPUT_BUFFER_SIZE, NULL);
}
if (nFrameLeng[pip] < 4) {
SSB_FILE_REWIND(fp[pip]);
RETAILMSG(1,(L"\n### REWIND.\n"));
switch (codec_mode[pip]) {
case CODEC_VC1:
nFrameLeng[pip] = ExtractConfigStreamVC1(fp[pip], pStrmBuf[pip], INPUT_BUFFER_SIZE, NULL);
break;
case CODEC_H263:
nFrameLeng[pip] = ExtractConfigStreamH263(fp[pip], pStrmBuf[pip], INPUT_BUFFER_SIZE, NULL);
break;
default:
FrameExtractorFirst(pFrameExCtx[pip], fp[pip]);
nFrameLeng[pip] = pFP_LIST[pip]->fp_NextFrame(pFrameExCtx[pip], fp[pip], pStrmBuf[pip], INPUT_BUFFER_SIZE, NULL);
}
}
#if (DECODED_OUTPUT == DECODED_OUT_FILE)
fwrite(pYUVBuf[pip], 1, nYUVLeng[pip], fp_out);
#elif (DECODED_OUTPUT == DECODED_OUT_DISP)
mfc_render_do(hRender[pip], pYUVBuf[pip], stream_info[pip].width, stream_info[pip].height, MFC_RENDER_IMAGE_TYPE_YUV420);
mfc_render_flip(hRender[pip]);
#endif
}
if (nLoop == perf_disp_period) {
t2 = GetTickCount();
t_diff = t2 - t1;
fps = (float)(1000 * nLoop) / t_diff;
wsprintf(str_performance, L"%3.1f", fps);
RETAILMSG(1,(L"Disp. Perf. =%s fps\n", str_performance));
nLoop = 0;
t1 = GetTickCount();
#if ((DECODED_OUTPUT == DECODED_OUT_DISP) && (PROPERTY_WINDOW == 1))
SizeImg_Write(size_img_idx, (unsigned char *) g_property_window, PROPERTY_WINDOW_WIDTH, PROPERTY_WINDOW_HEIGHT, 10, 10);
NumImg_Write_FPS(fps, (unsigned char *) g_property_window, PROPERTY_WINDOW_WIDTH, PROPERTY_WINDOW_HEIGHT, 90, 10);
mfc_render_do(hRender_property, (unsigned char *) g_property_window, PROPERTY_WINDOW_WIDTH, PROPERTY_WINDOW_HEIGHT, MFC_RENDER_IMAGE_TYPE_RGB565);
mfc_render_flip(hRender_property);
#endif
}
}
for (pip=0; pip < num_pips; pip++) {
///////////////////////////////////////
/// 7. SsbSipH264DecodeDeInit ///
///////////////////////////////////////
pFP_LIST[pip]->fp_SsbSipDecodeDeInit(handle[pip]);
SSB_FILE_CLOSE(fp[pip]);
#if (DECODED_OUTPUT == DECODED_OUT_FILE)
fclose(fp_out);
#elif (DECODED_OUTPUT == DECODED_OUT_DISP)
mfc_render_delete_overlay(hRender[pip]);
#if (PROPERTY_WINDOW == 1)
mfc_render_delete_overlay(hRender_property);
#endif
#endif
}
RETAILMSG(1,(L"\n\n@@@ Program ends.\n"));
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -