📄 mpeg4contrl.c
字号:
dispFrameNum = 0;
/* Stop frame display timer. */
Timer_PowerOffDeinit(0);
/* Close video file. */
AviFileClose();
#if 0 /* Free buffer. */
if (bitStreamBuf)
FREE(bitStreamBuf);
if (yuvBuf)
FREE(yuvBuf);
if (mbMvInfoBuf)
FREE(mbMvInfoBuf);
if (aviVideoScreen)
FREE(aviVideoScreen);
if (aviVideoLLPList)
FREE(aviVideoLLPList);
if (keyFrameList)
FREE(keyFrameList);
#endif
/* Reset DSP and Wating DWDMA transfer finish. */
/*SetRegBit32(0x1801c01c, 4);
delay_nops(400);
while(((ReadReg32(0x186f03a0)) & 0xc));*/
if (aviPlayState != AVI_STATE_INITIALIZING)
{
ClrRegBit32(0x1801c028, 16);
delay_nops(300);
SetRegBit32(0x1801c028, 16); /* nmi interrupt. */
delay_nops(2000);
ClrRegBit32(0x1801c028, 16);
/* wating for decoder exit. */
while ((GetDecStatus()) != XVIDCORE_DEC_EXIT)
{
delay_nops(300);
if ((timeOutCnt++) > 0x2ffff)
{
break;
}
}
}
while (Screen_GetMCUIFStatus() == BUSY);
aviPlayState = AVI_STATE_STOP;
/* Disable Dsp */
//PMU_ExitModule(PMU_VIDEOHIGH);
//DspDisable();
//RKFSFileClose(pfBitStream)
if (CODEC_AC3_DEC == CurrentCodec)
PMU_ExitModule(PMU_VIDEOLOW);
if (gSDModeFlag == 0)
{
if (gAviFunPmu == 2)
PMU_ExitModule(PMU_VIDEOMEDLOW);
else if (gAviFunPmu == 3)
PMU_ExitModule(PMU_VIDEOMED);
else if (gAviFunPmu == 4)
PMU_ExitModule(PMU_VIDEOMEDHIGH);
else if (gAviFunPmu == 5)
PMU_ExitModule(PMU_VIDEOHIGH);
else if (gAviFunPmu == 6)
PMU_ExitModule(PMU_VIDEOLOWL);
else if (gAviFunPmu == 7)
PMU_ExitModule(PMU_VIDEOLOWLL);
gAviFunPmu = 0;
}
else if (gSDModeFlag == 1)
{
PMU_ExitModule(PMU_VIDEOHIGH);
}
if ((yuvBuf == NULL) || (lastYuvBufId == -1))
return;
memcpy((yuvBuf+(YUV_BUFFER_NUM) * YUV_BUFFER_SIZE),(yuvBuf+(lastYuvBufId) * YUV_BUFFER_SIZE),YUV_BUFFER_SIZE);
Screen_Change(&aviVideoScreen[YUV_BUFFER_NUM]);
}
/********************************************************************************************
Func:
FrameDispCtrl()
Description:
start timer for frame displaying contrl .
Param:
None.
Return:
None
Author:
ljn
Date:
2007-11-2 13:30
Log:
********************************************************************************************/
void AviFrameDispCtrl(void *param)
{
/* set timer tick - 5 times per frame. */
StartHWVideoTimer(((avih.dwMicroSecPerFrame + (TIMER_ISR_NUM_PER_FRAME >> 1)) / TIMER_ISR_NUM_PER_FRAME), AviShowVideoFrame);
}
/********************************************************************************************
Func:
IsLastFrame()
Description:
Check if is last video frame or not?
Param:
None.
Return:
0: it is not last frame.
1: it is last frame.
Author:
ljn
Date:
2007-11-16 10:12
Log:
********************************************************************************************/
int AviIsLastFrame(void *param)
{
if ((aviPlayState == AVI_STATE_STOP) || (aviTimeOut >= 0x8ffff)) //skip mode @LJN
return 1;
aviTimeOut ++;
/* 'VideoChunkNum' is subtracted by 1, because of the video decoder may not decode the last frame. */
if ((IsLastBlockGot(filledBlockNum)) && (dispFrameNum >= (aviPointer.VideoChunkNum - 1))/*&&(!IsYuvReady(curFrame))*/)
return 1;
else
return 0;
}
/********************************************************************************************
Func:
VideoDecBufMalloc()
Description:
Malloc buffer for decoder.
Param:
None.
Return:
0: OK.
-1: Error.
Author:
ljn
Date:
2007-11-16 10:30
Log:
********************************************************************************************/
int AviVideoDecBufMalloc(void)
{
#if 0 /* use malloc. */
if ((bitStreamBuf = MALLOC(BITSREAM_BUFFER_SIZE * MAX_BITSREAM_BLOCK_NUM)) == 0)
return -1;
if ((yuvBuf = MALLOC(YUV_BUFFER_NUM * YUV_BUFFER_SIZE)) == 0)
return -1;
if ((mbMvInfoBuf = MALLOC(((avih.dwWidth + 15) >> 4) * ((avih.dwHeight + 15) >> 4) * 32)) == 0)
return -1;
if ((aviVideoScreen = (BACKGRND *)MALLOC(YUV_BUFFER_NUM * (sizeof(BACKGRND)))) == 0)
return -1;
if ((aviVideoLLPList = (DWDMALLP *)MALLOC(YUV_BUFFER_NUM * 1000 * (sizeof(DWDMALLP)))) == 0)
return -1;
#ifndef SEEK_TABLE
if ((keyFrameList = (KeyFrame *)MALLOC(6000 * (sizeof(KeyFrame)))) == 0)
{
if ((keyFrameList = (KeyFrame *)MALLOC(3000 * (sizeof(KeyFrame)))) == 0)
{
return -1;
}
}
#endif
#else /* use fixed buffer. */
bitStreamBuf = gVideoBufferMix;
yuvBuf = gVideoBufferMix + (BITSREAM_BUFFER_SIZE * MAX_BITSREAM_BLOCK_NUM);
mbMvInfoBuf = yuvBuf + ((YUV_BUFFER_NUM+1) * YUV_BUFFER_SIZE);
aviVideoScreen = (BACKGRND *)(mbMvInfoBuf + (((avih.dwWidth + 15) >> 4) * ((avih.dwHeight + 15) >> 4) * 32));
aviVideoLLPList = (DWDMALLP *)((char *)aviVideoScreen + ((YUV_BUFFER_NUM+1) * (sizeof(BACKGRND))));
aviVideoScreenTemp = (BACKGRND *)((char *)aviVideoLLPList + ((YUV_BUFFER_NUM+1) * 1000 * (sizeof(DWDMALLP))));
aviVideoLLPListTemp = (DWDMALLP *)((char *)aviVideoScreenTemp + (YUV_BUFFER_NUM * (sizeof(BACKGRND))));
aviVideoBufRemain = (char *)((char *)aviVideoLLPListTemp + (YUV_BUFFER_NUM * 1000 * (sizeof(DWDMALLP))));
#ifndef SEEK_TABLE
keyFrameList = (KeyFrame *)(gVideoBufferMix + SYSCFG_VIDEOBUF_LEN - 6000 * (sizeof(KeyFrame)));//(KeyFrame *)(aviVideoLLPList + (YUV_BUFFER_NUM * 1000 * (sizeof(DWDMALLP))));
#endif
#endif
return 0;
}
/********************************************************************************************
Func:
VideoDecInit()
Description:
Open avi file and parse it.
Param:
char *PathName - file path of video file.
Return:
0: OK.
-1: Error.
Author:
ljn
Date:
2007-11-16 10:37
Log:
********************************************************************************************/
int AviVideoFileInit(void *PathName)
{
int err;
aviPlayState = AVI_STATE_INITIALIZING;
if (AviFileInit((char *)PathName))
{
aviPlayState = AVI_STATE_STOP;
AviFileClose();
return AVI_FILE_OPEN_ERR;
}
if ((err = AviFileParsing(&aviPointer, &avih)))
{
if (err == AVI_FILE_AUDIO_CODEC_ERR) /* audio codec error is allowable. */
{
return err;
}
AviFileClose();
aviPlayState = AVI_STATE_STOP;
return err;
}
return AVI_FILE_PARSING_OK;
}
/********************************************************************************************
Func:
VideoDecInit()
Description:
Initialization for decoder and start it.
Param:
None.
Return:
0: OK.
-1: Error.
Author:
ljn
Date:
2007-11-16 10:37
Log:
********************************************************************************************/
extern BOOLEAN gVideoPmuFlag;
int AviVideoDecInit(void *param)
{
int i;
long avi_width, avi_height, stride;
if (aviPlayState != AVI_STATE_INITIALIZING)
return -1;
gVideoPmuFlag = 1;
PMU_ExitModule(PMU_VIDEOHIGH);
AviGetResolution(&avi_width, &avi_height);
stride = avi_width * avi_height;
if (gSDModeFlag == 0)
{
if (stride <= (320*240))
{
gAviFunPmu = 7;
PMU_EnterModule(PMU_VIDEOLOWLL);
}
else if (stride <= (480*272))
{
gAviFunPmu = 6;
PMU_EnterModule(PMU_VIDEOLOWL);
}
else if (stride <= (640 *272))
{
gAviFunPmu = 2;
PMU_EnterModule(PMU_VIDEOMEDLOW);
}
else if (stride <= (640 *480))
{
gAviFunPmu = 3;
PMU_EnterModule(PMU_VIDEOMED);
}
else if ((stride <= (720*480)) && (avi_width < 800))
{
gAviFunPmu = 4;
PMU_EnterModule(PMU_VIDEOMEDHIGH);
}
else
{
gAviFunPmu = 5;
PMU_EnterModule(PMU_VIDEOHIGH);
}
}
else if (gSDModeFlag == 1)
{
PMU_EnterModule(PMU_VIDEOHIGH);
}
/* Flow: */
/* a. Malloc Buffer for decoder. */
if (AviVideoDecBufMalloc())
return -1;
/* b. Enable DSP core and peripheral. */
DspEnable(); /* do this in pmu. */
/* c. Share data initialize. */
AviShareDataInit();
/* d. Create video screens. */
AviCreateVideoScreen(&avih);
/* e. Fill all bit stream buffer. */
for (i = 0;i < MAX_BITSREAM_BLOCK_NUM;i++)
{
if (AviFillBitStreamForDecoder(0) != 0)
{
return -1;
}
}
/* f. Load code and start decoder. */
if (stream_supported_flag.VideoCodecLib == VIDEO_CODEC_LIB_DIV3)
{
if (VideoDecoderLoad(aviVideoBufRemain, "DIV3"))
{
return -1;
}
}
else if (stream_supported_flag.VideoCodecLib == VIDEO_CODEC_LIB_MJPG)
{
//if(JtagBoot(0)){
// return -1;
//}
if (VideoDecoderLoad(aviVideoBufRemain, "MJPG"))
{
return -1;
}
}
else
{
if (VideoDecoderLoad(aviVideoBufRemain, "MPEG4"))
{
return -1;
}
}
/* g. Start frame diaplay timer. */
AviFrameDispCtrl(NULL);
aviPlayState = AVI_STATE_PALYING;
return 0;
}
/********************************************************************************************
Func:
AviFFD()
Description:
Avi fast forward.
Param:
step length.
Return:
0: OK.
-1: Reach last key frame.
Author:
ljn
Date:
2007-11-19 14:29
Log:
********************************************************************************************/
int AviFFD(unsigned int step)
{
/* do nothing when video is stoped. */
if ((aviPlayState == AVI_STATE_STOP) || (aviPlayState == AVI_STATE_INITIALIZING))
return 0;
if (aviPlayState == AVI_STATE_PAUSE)
AviPlayPause();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -