Mpeg4ClipsCommon.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:26k
- /****************************************************************************************
- * Copyright (c) 2004 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: Mpeg4ClipsCommon.c $
- *
- * Description:
- * ============
- * MPEG4 Clips Common
- *
- * Log:
- * ====
- * $Revision: #12 $
- * $Change: 29756 $
- * Last Modified by $Author: robin.jiang $ at $DateTime: 2004/10/27 19:18:00 $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Playcore/Nav_Clips/Mpeg4ClipsCommon.c $
- *
- * 1 8/2/2004 RobinJ
- * Created
- *
- ****************************************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceNavigator)
- #include "Debugdbgmain.h"
- #endif
- #include "PlaycoreNav_ClipsMpeg4ClipsCommon.h"
- #include "Decoderlow_levelDEC_LL_API.h"
- #include "PlaycoreNav_ClipsPE_Clips.h"
- #include "PlaycoreCoremainCoreGDef.h"
- //#include "PlaycoreNav_ClipsAVI_private.h"
- #include "Drivedrv_api.h"
- #include "Decoderlow_levelDEC_LL_Reg.h"
- #include "DecoderDEC_Set_DVP_Gen_Regs.h"
- #define SCR_RATE 90000L
- // Robin_1011_2004_D
- #ifdef PATCH_VIDEO_NOT_B
- BOOL bRequestPAL60 = FALSE;
- #endif
- extern void DEC_set_display_video_format(DEC_LL_DECODED_FRAME_RATE v_format);
- // Note: Any change in the following calculation might affect the accuracy of GoTo time
- // <<< Robin_1003_2004_B, improve the accuracy
- ///////////////////////////////////////////////////////////////////////////
- // Function name : _caclFrameOfTime
- // Purpose : calculate the frame number, correspond to time
- // Input Parameters : wTime - Time
- // : dwRate - Time Rate
- // : dwScale - Time Scale
- // Output Parameters :
- // Return type : DWORD
- ///////////////////////////////////////////////////////////////////////////
- WORD caclTimeOfFrame(DWORD dwFrameNumber, DWORD dwRate, DWORD dwScale)
- {
- DWORD dwTimeDelta;
- DWORD dwDelta;
- DWORD dwDelta100, dwDelta10000;
- DWORD dwTime;
- dwTimeDelta = (1000UL*dwScale)/dwRate; // in ms
- dwDelta = (1000UL*dwScale) - (dwTimeDelta * dwRate);
- // Robin_0201_2005, avoid the calculate overflow
- if (((10000UL*dwDelta)/10000UL) == dwDelta)
- {
- dwDelta = (10000UL*dwDelta) / dwRate;
- }
- else if (((5000UL*dwDelta)/5000UL) == dwDelta)
- {
- dwDelta = ((5000UL*dwDelta) / dwRate) * 2;
- }
- else if (((1000UL*dwDelta)/1000UL) == dwDelta)
- {
- dwDelta = ((1000UL*dwDelta) / dwRate) * 10;
- }
- else if (((100UL*dwDelta)/100UL) == dwDelta)
- {
- dwDelta = ((100UL*dwDelta) / dwRate) * 100;
- }
-
- dwDelta100 = dwDelta/100;
- dwDelta10000 = dwDelta%100;
- dwTime = dwFrameNumber * dwTimeDelta;
- dwTime += ((dwFrameNumber*dwDelta100 + ((dwFrameNumber*dwDelta10000)/100))/100);
- dwTime = (dwTime+500UL)/1000UL;
- return (WORD)dwTime;
- }
- ///////////////////////////////////////////////////////////////////////////
- // Function name : _caclFrameOfTime
- // Purpose : calculate the frame number, correspond to time
- // Input Parameters : wTime - Time
- // : dwRate - Time Rate
- // : dwScale - Time Scale
- // Output Parameters :
- // Return type : DWORD
- ///////////////////////////////////////////////////////////////////////////
- DWORD caclFrameOfTime(WORD wTime, DWORD dwRate, DWORD dwScale)
- {
- DWORD dwFrameRate;
- DWORD dwDelta;
- DWORD dwDelta100, dwDelta10000;
- DWORD dwFrameNumber;
- dwFrameRate = dwRate/dwScale;
- dwDelta = dwRate - (dwFrameRate*dwScale);
- // Robin_0201_2005, avoid the calculate overflow
- if (((10000UL*dwDelta)/10000UL) == dwDelta)
- {
- dwDelta = (10000UL*dwDelta)/dwScale;
- }
- else if (((5000UL*dwDelta)/5000UL) == dwDelta)
- {
- dwDelta = ((5000UL*dwDelta) / dwScale) * 2;
- }
- else if (((1000UL*dwDelta)/1000UL) == dwDelta)
- {
- dwDelta = ((1000UL*dwDelta) / dwScale) * 10;
- }
- else if (((100UL*dwDelta)/100UL) == dwDelta)
- {
- dwDelta = ((100UL*dwDelta) / dwScale) * 100;
- }
-
- dwDelta100 = dwDelta/100;
- dwDelta10000 = dwDelta%100;
- dwFrameNumber = wTime * dwFrameRate;
- dwFrameNumber += ((wTime*dwDelta100 + ((wTime*dwDelta10000)/100))/100);
- return dwFrameNumber;
- }
- // >>> Robin_1003_2004_B
- ///////////////////////////////////////////////////////////////////////////
- // Function name : convertFOURCCToString
- // Purpose : Converts 32 FOURCC bits into a string.
- // Input Parameters : fourcc - 32 bits representing the FOURCC.
- // Output Parameters: str - The string representing the FOURCC.
- // Return type : none
- ///////////////////////////////////////////////////////////////////////////
- void convertFOURCCToString(FOURCC forcc, LPSTR str)
- {
- str[0] = (CHAR)(forcc & 0x000000ff);
- str[1] = (CHAR)(forcc >> 8);
- str[2] = (CHAR)(forcc >> 16);
- str[3] = (CHAR)(forcc >> 24);
- }
- /////////////////////////////////////////////////////////////////////////////
- // Private Services
- ///////////////////////////////////////////////////////////////////////////
- // Function name : qwTimeDiv10000
- // Purpose : 64bits in unit of 100ns to 32bits in unit of ms
- // Input Parameters : time - QWORD
- // Return type : DWORD
- // Description :
- ///////////////////////////////////////////////////////////////////////////
- DWORD qwTimeDiv10000(QWORD time)
- {
- DWORD temp, result;
- temp = (time[1] << 16) | (time[0] >> 16);
- result = (temp/10000UL);
- temp -= result * 10000UL;
- result <<= 16;
- temp <<= 16;
- temp += (time[0] & 0xFFFFUL);
- result += (temp/10000UL);
- return result;
- }
- void UTF8ToUnicode(BYTE* pUTFBuffer, WORD* pUnicodeBuffer, UINT16 uiBufferSize, WORD* wLastUnicode, WORD* uiUnicodeBufferSize)
- {
-
- while(uiBufferSize--)
- {
- if ((*pUTFBuffer) < 0x80)
- {
- if ((*wLastUnicode) != 0)
- {
- *(pUnicodeBuffer++) = (*wLastUnicode);
- (*uiUnicodeBufferSize)++;
- (*wLastUnicode) = 0;
- }
-
- *(pUnicodeBuffer++) = (WORD)*pUTFBuffer;
- (*uiUnicodeBufferSize)++;
- }
- else if ((*pUTFBuffer) < 0xc0) // trail byte
- {
- (*wLastUnicode) <<= 6;
- (*wLastUnicode) += ((*pUTFBuffer) - 0x80);
- }
- else
- {
- if ((*wLastUnicode) != 0)
- {
- *(pUnicodeBuffer++) = (*wLastUnicode);
- (*uiUnicodeBufferSize)++;
- (*wLastUnicode) = 0;
- }
- if ((*pUTFBuffer) < 0xe0)
- (*wLastUnicode) = ((*pUTFBuffer) - 0xc0);
- else
- (*wLastUnicode) = ((*pUTFBuffer) - 0xe0);
- }
-
- pUTFBuffer++;
- }
- }
- ///////////////////////////////////////////////////////////////////////////
- // Function name : determineDivXVersion
- // Purpose : Determines whether the DivX version is 3, 4 or 5.
- // Input Parameters : uiStreamNumber - The video stream number to determine
- // its version.
- // Return type : The DivX version.
- // Description : See the SW SPEC for details.
- ///////////////////////////////////////////////////////////////////////////
- DivXVesrion determineDivXVersion(FOURCC fourccHandle, FOURCC fouccCompression)
- {
- CHAR fccHandler[FOURCC_FIELD_LENGTH];
- CHAR compressionType[FOURCC_FIELD_LENGTH];
- DivXVesrion divxVersion = DIVX_UNKNOWN;
-
- convertFOURCCToString(fourccHandle, fccHandler);
- convertFOURCCToString(fouccCompression, compressionType);
- if ( (0 == strnicmp(fccHandler, "div3", FOURCC_FIELD_LENGTH)) ||
- (0 == strnicmp(fccHandler, "div4", FOURCC_FIELD_LENGTH)))
- {
- divxVersion = DIVX_3_11;
- }
- else if (0 == strnicmp(fccHandler, "mp43", FOURCC_FIELD_LENGTH))
- {
- divxVersion = MP43;
- }
- else if ((0 == strnicmp(compressionType, "div3", FOURCC_FIELD_LENGTH)) ||
- (0 == strnicmp(compressionType, "div4", FOURCC_FIELD_LENGTH)) )
- {
- divxVersion = DIVX_3_11;
- }
- else if (0 == strnicmp(compressionType, "mp43", FOURCC_FIELD_LENGTH))
- {
- divxVersion = MP43;
- }
- else if (0 == strnicmp(compressionType, "divx", FOURCC_FIELD_LENGTH))
- {
- divxVersion = DIVX_4_12;
- }
- else if ((0 == strnicmp(compressionType, "dx50", FOURCC_FIELD_LENGTH)) ||
- (0 == strnicmp(compressionType, "dxsb", FOURCC_FIELD_LENGTH)))
- {
- divxVersion = DIVX_5_0;
- }
- else if (0 == strnicmp(compressionType, "xvid", FOURCC_FIELD_LENGTH))
- {
- divxVersion = XVID;
- }
- else if (0 == strnicmp(compressionType, "rmp4", FOURCC_FIELD_LENGTH))
- {
- divxVersion = RMP4;
- }
- else if (0 == strnicmp(compressionType, "mp4s", FOURCC_FIELD_LENGTH))
- {
- divxVersion = MP4S;
- }
- else if ((0 == strnicmp(compressionType, "3ivx", FOURCC_FIELD_LENGTH)) ||
- (0 == strnicmp(compressionType, "3iv2", FOURCC_FIELD_LENGTH)))
- {
- divxVersion = _3IVX;
- }
- else if (0 == strnicmp(compressionType, "mp4v", FOURCC_FIELD_LENGTH))
- {
- divxVersion = MP4V;
- }
- if (DIVX_UNKNOWN == divxVersion)
- {
- dbg_printf(("WARNING: Could not identify Video Codecn"));
- }
- else
- {
- dbg_printf(("Video Codec: %dn", divxVersion));
- }
- return divxVersion;
- }
- ///////////////////////////////////////////////////////////////////////////
- // Function name : determineAudioInfo
- // Purpose : Determines the audio info of a an audio stream.
- // Input Parameters : none
- // Ouput Parameters : The audio info.
- // Return type : TRUE if the operation succeeded, FALSE otherwise.
- // Description : The function determines the audio SID.
- ///////////////////////////////////////////////////////////////////////////
- BOOL determineAudioInfo(UINT8* puiAudioSid, UINT8* puiAudioSidDecoder,DWORD* dwSampleRate)
- {
- /* Check if an audio stream was found */
-
- if ((_mpeg4AudioAvailableNum == 0) || (NO_STREAM == _mpeg4AudioStreamID))
- {
- *puiAudioSid = NO_STREAM;
- *puiAudioSidDecoder = NoAudio;
- *dwSampleRate = 0;
- return TRUE;
- }
- /* Determine the audio stream */
- switch (_mpeg4AudioCodec)
- {
-
- case MP3:
- *puiAudioSid = AUDIO_STREAM_MP3;
- *puiAudioSidDecoder = MP3_SID;
- break;
- case AC3:
- *puiAudioSid = AUDIO_STREAM_AC3;
- *puiAudioSidDecoder = AC3_SID;
- break;
- case MP2:
- *puiAudioSid = AUDIO_STREAM_MPEG;
- *puiAudioSidDecoder = MPEG_SID1;
- break;
- #ifdef D_ENABLE_ADPCM_SUPPORT
- case PCM:
- // <<< Robin_2004_0525_B,
- // in 2X16Mbits, if PCM sample rate is greater than 48000, playback without audio
- #ifdef SDRAM_2X16MBITS
- #ifdef NEW_2X16M_MAPPING
- if (_mpeg4AudioSamplesPerSec <= 48000UL)
- {
- *puiAudioSid = AUDIO_STREAM_ADPCM;
- *puiAudioSidDecoder = ADPCM_SID;
- }
- else
- #endif
- {
- dbg_printf(("PCM audio, sample rate is exceed 48K - not supported in 2X16M n"));
- *puiAudioSid = NO_STREAM;
- *puiAudioSidDecoder = NO_STREAM;
- // <<< Robin_0907_2004_C
- *dwSampleRate = 0;
- return TRUE;
- // >>> Robin_0907_2004_C
- }
- break;
- #endif
- // >>> Robin_2004_0525_B,
- case ADPCM:
- *puiAudioSid = AUDIO_STREAM_ADPCM;
- *puiAudioSidDecoder = ADPCM_SID;
- break;
- #endif
- #ifdef D_ENABLE_DIVX_WMA_SUPPORT
- case WMA:
- *puiAudioSid = AUDIO_STREAM_WMA;
- *puiAudioSidDecoder = WMA_SID;
- break;
- #endif
- #ifdef D_ENABLE_AAC_SUPPORT
- case AAC:
- *puiAudioSid = AUDIO_STREAM_AAC;
- *puiAudioSidDecoder = AAC_SID;
- break;
- #endif
-
- default:
- *puiAudioSid = NO_STREAM;
- *puiAudioSidDecoder = NO_STREAM;
- }
- *dwSampleRate = _mpeg4AudioSamplesPerSec;
- return TRUE;
- }
- AudioCodec determineAudioCodec(DWORD dwFormatTag, WORD wFormatTag, BOOL bMP4)
- {
- AudioCodec audioCodec = AUDIO_UNKNOWN;
-
- if (TRUE == bMP4) // mp4
- {
- switch (dwFormatTag)
- {
- case MKTAG('m', 'p', '4', 'a'):
- audioCodec = AAC;
- break;
- case MKTAG('.','m','p','3'):
- case 0x6D730055UL:
- case 0x5500736DUL:
- audioCodec = MP3;
- break;
- case MKTAG('m','s',0x20,0x20):
- audioCodec = AC3;
- break;
- case MKTAG('r','a','w',' '):
- case MKTAG('s','o','w','t'):
- audioCodec = PCM;
- break;
- case MKTAG('s','a','m','r'):
- case MKTAG('s','a','w','b'):
- dbg_printf(("AMR audio detected - not supportedn"));
- audioCodec = AUDIO_UNKNOWN;
- break;
- case MKTAG('i','m','a','4'):
- dbg_printf(("IMA-4 ADPCM audio detected - not supportedn"));
- audioCodec = AUDIO_UNKNOWN;
- break;
-
- default:
- dbg_printf(("Unknown audio detected- not supportedn"));
- audioCodec = AUDIO_UNKNOWN;
- }
- }
- else // avi, asf
- {
- switch (wFormatTag)
- {
- case MP3_AUDIO_SID:
- audioCodec = MP3;
- break;
- case AC3_AUDIO_SID:
- audioCodec = AC3;
- break;
- case MPEG_AUDIO_SID:
- audioCodec = MP2;
- break;
-
- case PCM_AUDIO_SID:
- audioCodec = PCM;
- break;
- case ADPCM_MS_AUDIO_SID:
- audioCodec = ADPCM;
- break;
- case PCM_ALAW_AUDIO_SID:
- case PCM_MULAW_AUDIO_SID:
- dbg_printf(("PCM audio detected - not supportedn"));
- audioCodec = AUDIO_UNKNOWN;
- break;
- case ADPCM_IMA_WAV_AUDIO_SID:
- case ADPCM_IMA_DK4_AUDIO_SID:
- case ADPCM_IMA_DK3_AUDIO_SID:
- dbg_printf(("ADPCM audio detected - not supportedn"));
- audioCodec = AUDIO_UNKNOWN;
- break;
-
- case WMAV2_AUDIO_SID:
- audioCodec = WMA;
- break;
-
- case WMAV1_AUDIO_SID:
- dbg_printf(("WMA V1 audio detected - not supportedn"));
- audioCodec = AUDIO_UNKNOWN;
- break;
- default:
- dbg_printf(("Unknown audio detected- not supportedn"));
- audioCodec = AUDIO_UNKNOWN;
- }
- }
- if (AUDIO_UNKNOWN == audioCodec)
- {
- dbg_printf(("WARNING: Could not identify Audio Codecn"));
- }
- else
- {
- dbg_printf(("Audio Codec: %dn", audioCodec));
- }
- return audioCodec;
- }
- ///////////////////////////////////////////////////////////////////////////
- // Function name : prePlayProcessing
- // Purpose : Calculate and send to the DVP the AVI file
- // parameters.
- // Input Parameters :
- // Return type :
- // Description :
- ///////////////////////////////////////////////////////////////////////////
- void prePlayProcessing(DWORD dwSamplingRate, UINT8 uiAudioSid,
- UINT8 uiAudioSIDDecoder, UINT8 uiVideoSid, BOOL bClipStart)
- {
- // DWORD dwWidth = _aviStreamsInfo[0]._aviStreamFormat._bitMapInfoHeader.lWidth;
- // DWORD dwHeight = _aviStreamsInfo[0]._aviStreamFormat._bitMapInfoHeader.lHeight;
- WORD wRoundedWidth, wRoundedHeight, wNumOfMB;
- DWORD dwFrameIncr, dwFixVal, dwFixFreq;
- WORD wAudStreamNum, wVidStreamNum,wSubStreamNum;
- WORD tempInputFps1;
- DWORD fieldCounter;
- UINT16 tempOutputFps;
- WORD audio_format,audio_block_align, audio_bitspersample;
- UINT8 uiOffsetToClear;
- #ifdef K1_WL
- DEC_LL_DECODED_FRAME_RATE v_format;
- #endif
- BOOL bInternalSubtitleIsText;
- #if 0
- /* set the width of the picture for slot machine replacement */
- DEC_AVI_SetPicWidth(dwWidth);
- #endif
- /* Kill any existing Zoom */
- //DEC_SetZoomScale(NO_ZOOM);
- // <<< Robin_1011_2004_D
- tempInputFps1 = (_mpeg4VideoRate*100)/_mpeg4VideoScale;
- #ifdef PATCH_VIDEO_NOT_B
- bRequestPAL60 = FALSE;
- if ((gps->tv_standard == TV_SYS_PAL) && (tempInputFps1>2550) && (FALSE == _bMPEG4IsBVopExist))
- {
- dbg_printf(("Video is 30f/s, No B-VOP, PAL TV output.n"));
- bRequestPAL60 = TRUE;
- }
- #endif
- // >>> Robin_1011_2004_D
- #ifdef SUPPORT_FLASH_CARD
- // if(IS_PLAYING_CARD)
- drv_abort_play();
- #endif
- // Clear the Share RAM
- for (uiOffsetToClear = 0; uiOffsetToClear < 16; uiOffsetToClear++)
- DEC_AVI_ClearSharedOffset(uiOffsetToClear);
- /* Set DVP indication that this is a pause-stop (and not pure pause) */
- DEC_AVI_SetDemuxSharedBit(AVI_FILE_PAUSE_OFFSET, AVI_FILE_PAUSE_BIT);
- /* Configure the Decoder to the appropriate bitstream type */
- DEC_Stop_DVP_ADP_cmd((UINT8)0);
- #ifndef SUPPORT_FLASH_CARD
- drv_abort_play();
- #endif
- DEC_AVI_SetDivXVersion(_mpeg4VideoCodec);
- if (SI_IS_CURRENT_AVI_CLIP)
- DEC_SetDiskType(DEC_DISC_TYPE_AVI);
- #ifdef IS_ASF_CAPABLE
- else if (SI_IS_CURRENT_ASF_CLIP)
- DEC_SetDiskType(DEC_DISC_TYPE_ASF);
- #endif
- #ifdef IS_MP4_CAPABLE
- else if (SI_IS_CURRENT_MP4_CLIP)
- DEC_SetDiskType(DEC_DISC_TYPE_MP4);
- #endif
- DEC_prepare_to_decode(); /* Downloads the DVP AVI microcode */
- gns.clips.iClipSamplingRate = dwSamplingRate;
- gcst.mAudioStream = uiAudioSid;
- DEC_SetSID(DEC_SID_TYPE_AUDIO, uiAudioSIDDecoder);
- DEC_SetSID(DEC_SID_TYPE_VIDEO, uiVideoSid);
- PE_Clips_SelectClock(eCT_Decoder);
- /* Calculate the parameters to be sent to the DEMUX */
- wRoundedWidth = ((_mpeg4VideoWidth + 15) / 16) * 16;
- wRoundedHeight = ((_mpeg4VideoHeight + 15) / 16) * 16;
-
- if (wRoundedWidth == 512 && ((_mpeg4VideoCodec != DIVX_3_11) && (_mpeg4VideoCodec != MP43))) // Robin_1125_2004, MP43 is same as DivX311
- {
- wNumOfMB = ((wRoundedWidth / 16) + 1) * (wRoundedHeight / 16);
- }
- else
- {
- wNumOfMB = (wRoundedWidth / 16) * (wRoundedHeight / 16);
- }
- if (SI_IS_CURRENT_AVI_CLIP)
- {
- wVidStreamNum = ((_mpeg4VideoStreamID+ '0') << 8) | '0';
- if (0xFF == uiAudioSid)
- {
- wAudStreamNum = 0xFF; // Instruct the DEMUX to drop the audio chunks
- }
- else
- {
- wAudStreamNum = ((_mpeg4AudioStreamID + '0') << 8) | '0';
- }
- wSubStreamNum = ((_mpeg4SubtitleStreamID + '0') <<8) | '0';
- }
- else
- {
- wVidStreamNum = _mpeg4VideoStreamID;
- wAudStreamNum = _mpeg4AudioStreamID;
- wSubStreamNum = _mpeg4SubtitleStreamID;
- }
- /* Frame Increment in 90KHZ */
- dwFrameIncr = (SCR_RATE*_mpeg4VideoScale)/(_mpeg4VideoRate);
- /* Rate Fix Value , Rate Fix Freq => every Rate Fix
- * Freq (7 Frames) add Rate Fix Value to the TimeStamp
- */
- dwFixVal = (((SCR_RATE*_mpeg4VideoScale) - (dwFrameIncr * _mpeg4VideoRate))*100)/(_mpeg4VideoRate);
- dwFixFreq = 100;
- /* set the video output according to the movie (PAL/NTSC)
- * mainlly used for Auto Mode
- * I will call this function only for clear case of PAL/NTSC
- */
- // <<< Robin_1011_2004_C
- if((tempInputFps1 > 2450 && tempInputFps1 < 2550) || wRoundedHeight > 480)
- {
- #ifdef K1_WL
- // DEC_LL_GetCodedVideoStandard(&v_format);
- // if ((DEC_LL_DECODED_FRAME_RATE_NTSC == v_format) && clr_tmp_string)
- // hide_time();
- // clr_tmp_string = TRUE;
- #endif
- DEC_set_display_video_format(DEC_LL_DECODED_FRAME_RATE_PAL); //TODO: change according to FPS of bitstream
- }
- else
- {
- #ifdef K1_WL
- // DEC_LL_GetCodedVideoStandard(&v_format);
- // if ((DEC_LL_DECODED_FRAME_RATE_PAL == v_format) && clr_tmp_string)
- // hide_time();
- // clr_tmp_string = TRUE;
- #endif
- DEC_set_display_video_format(DEC_LL_DECODED_FRAME_RATE_NTSC); //TODO: change according to FPS of bitstream
- }
- // >>> Robin_1011_2004_C
-
- //FW0408_2005D Move from AVIClip_play() because it should be set before play
- // Set AVI video scaling
- DEC_EnableManualScaling(PROG_SCALER_MODE_CCRAM);
- DEC_SetViewMode(gps->view_mode);
- /* Set picture size */
- DEC_set_coded_video_size(_mpeg4VideoWidth, _mpeg4VideoHeight);
- /* Set TV display aspect ratio */
- DEC_set_Display_AspectRatio(gps->tv_shape);
- if ((TRUE == bClipStart) && (_mpeg4VideoStreamID != NO_STREAM))
- {
- #ifdef PATCH_DIVX_GARBAGE
- DEC_LL_BackgroundSwitch(DEC_LL_BG_SWITCH_BACKGROUND);
- #endif
- gcst.mNeedScaling = TRUE; //FW_0526_2005B Should set before DVP start. In Divx3.11 ucode, DVP send scaling info right after video task start.
- }
- /* Calculate how many frames the DVP should drop */
- if (gcst.actual_tv_std == DEC_LL_OUT_VIDEO_STANDARD_PAL)
- {
- tempOutputFps = 2500; /* PAL output, multiplied by 100 */
- dbg_printf(("PALn"));
- }
- else
- {
- tempOutputFps = 2997; /* NTSC output, multiplied by 100 */;
- dbg_printf(("NTSCn"));
- }
- if (tempOutputFps > tempInputFps1)
- {
- /* need to repeat field every X fields */
- tempOutputFps -= tempInputFps1;
- /* Round fieldCounter up */
- fieldCounter = (tempInputFps1+tempOutputFps-1)/tempOutputFps;
- //fieldCounter = tempInputFps1/tempOutputFps;
- }
- else
- {
- /* need to drop frame every X frames */
- fieldCounter = 0;
- }
-
- dbg_printf(("nFrame incr: %ld, Frame fix val: %ld, Frame fix freq: %ldn",
- dwFrameIncr, dwFixVal, dwFixFreq-1));
- dbg_printf(("fieldCounter: %dn",fieldCounter));
- // RB_TBD, need change DVP
- #if (defined(D_ENABLE_DIVX_WMA_SUPPORT) || defined(D_ENABLE_ADPCM_SUPPORT))
- if (PCM == _mpeg4AudioCodec)
- audio_format = PCM_AUDIO_SID;
- else if (ADPCM == _mpeg4AudioCodec)
- audio_format = ADPCM_MS_AUDIO_SID;
- else if (WMA == _mpeg4AudioCodec)
- audio_format = WMAV2_AUDIO_SID;
- else if (MP3 == _mpeg4AudioCodec)
- audio_format = MP3_AUDIO_SID;
- else
- audio_format = 0;
- #else
- audio_format = 0;
- #endif
- #ifdef D_ENABLE_ADPCM_SUPPORT
- if (ADPCM == _mpeg4AudioCodec || PCM == _mpeg4AudioCodec)
- audio_bitspersample = _mpeg4AudioBitsPerSample_ADPCM;
- else
- audio_bitspersample = 0;
- #else
- audio_bitspersample = 0;
- #endif
- #ifdef D_ENABLE_DIVX_WMA_SUPPORT
- if (ADPCM == _mpeg4AudioCodec)
- audio_block_align = _mpeg4AudioBlockAlign_ADPCM;
- else if (WMA == _mpeg4AudioCodec)
- audio_block_align = _mpeg4AudioBlockAlign_WMA;
- else
- audio_block_align = 0;
- #else
- audio_block_align = 0;
- #endif
- bInternalSubtitleIsText = SI_CLIPS_MP4_INTERNAL_SUBTITLE_ON;
- // Robin_0730_2004, set the VCB/ACB fullness limit when NEW_2X16M_MAPPING
- #ifdef NEW_2X16M_MAPPING
- {
- UINT16 uiACBStartAddressAVI, uiSPBStartAddressAVI, uiAPPStartAddressAVI;
- UINT16 uiVCBSize, uiACBSize, uiSPBSize;
- MPEG4Clip_dynamic_malloc(&uiACBStartAddressAVI, &uiSPBStartAddressAVI, &uiAPPStartAddressAVI);
- uiVCBSize = uiACBStartAddressAVI - OSD_BUFFER_SIZE_AVI;
- uiACBSize = uiSPBStartAddressAVI - uiACBStartAddressAVI;
- uiSPBSize = SPB_SIZE_AVI;
-
- _mpeg4InternalSubtitleBufferStartAddr = uiSPBStartAddressAVI;
-
- DEC_AVI_SetFileParams(_mpeg4VideoWidth, _mpeg4VideoHeight,
- wRoundedWidth, wRoundedHeight, wNumOfMB,
- dwFrameIncr,
- dwFixVal, dwFixFreq-1, _bAVIDrmOn, wVidStreamNum, wAudStreamNum, wSubStreamNum,fieldCounter,
- (uiVCBSize*13), (uiACBSize*13), (DWORD)(uiSPBSize*1024UL),
- audio_format,audio_block_align,audio_bitspersample, bInternalSubtitleIsText);
- }
- #else
- _mpeg4InternalSubtitleBufferStartAddr = (OSD_BUFFER_SIZE_AVI+VCB_SIZE_AVI+ACB_SIZE_AVI);
- DEC_AVI_SetFileParams(_mpeg4VideoWidth, _mpeg4VideoHeight,
- wRoundedWidth, wRoundedHeight, wNumOfMB,
- dwFrameIncr,
- dwFixVal, dwFixFreq-1, _bAVIDrmOn, wVidStreamNum, wAudStreamNum, wSubStreamNum,fieldCounter,
- (VCB_SIZE_AVI*13), (ACB_SIZE_AVI*13), (SPB_SIZE_AVI*1024UL),
- audio_format,audio_block_align,audio_bitspersample,bInternalSubtitleIsText);
- #endif
- /* Signal to the demux media type - CD/DVD */
- if (SI_IS_CURRENT_AVI_CLIP)
- DEC_Set_DVP_Gen_For_Clips_Disc_Type(DEC_DISC_TYPE_AVI);
- #ifdef IS_ASF_CAPABLE
- else if (SI_IS_CURRENT_ASF_CLIP)
- DEC_Set_DVP_Gen_For_Clips_Disc_Type(DEC_DISC_TYPE_ASF);
- #endif
- #ifdef IS_MP4_CAPABLE
- else if (SI_IS_CURRENT_MP4_CLIP)
- DEC_Set_DVP_Gen_For_Clips_Disc_Type(DEC_DISC_TYPE_MP4);
- #endif
- if (_mpeg4VideoStreamID != NO_STREAM)
- DEC_Set_DVP_GEN_For_MPEG4_Audio_Only(FALSE);
- else
- DEC_Set_DVP_GEN_For_MPEG4_Audio_Only(TRUE);
- DEC_PlaybackCommand(DEC_PLAYBACK_CMD_PLAY, NULL);
- DEC_AVI_SetMBInfoAddr();
- // Robin_0809_2004, transfer the video header data
- if (_mpeg4VideoHeaderDataLength > 0)
- {
- WORD wVideoHeaderSize;
- BYTE videoHeaderBuff[MPEG4_VIDEO_HEADER_CACHE_SIZE];
- WORD wVideoHeaderCacheSize;
- WORD wOffset = 0;
- wVideoHeaderSize = _mpeg4VideoHeaderDataLength; // multiple of 2 bytes
- while (wVideoHeaderSize > 0)
- {
- wVideoHeaderCacheSize = min(wVideoHeaderSize,MPEG4_VIDEO_HEADER_CACHE_SIZE);
- sc_GetBytes(SC_MPEG4_VIDEO_HEADER_DATA_ADDR,
- wOffset,
- wVideoHeaderCacheSize,
- (BYTE*)&videoHeaderBuff
- );
- wOffset += wVideoHeaderCacheSize;
- DEC_AVI_TransferVideoHeader(wVideoHeaderCacheSize/2,(WORD*)&videoHeaderBuff);
- wVideoHeaderSize -= wVideoHeaderCacheSize;
- }
- }
- /* SubPicture Reset */
- /* set the SP switch */
- outport(SPSWITCH_ADDR, 0x5);
- // Robin_1011_2004_C
- // outport(SPSCALE_ADDR, 0x0);
- // Robin_1011_2004_D
- #ifdef PATCH_VIDEO_NOT_B
- bRequestPAL60 = FALSE;
- #endif
- // Set DVP indication that this is a pure pause
- DEC_AVI_ClearDemuxSharedBit(AVI_FILE_PAUSE_OFFSET, AVI_FILE_PAUSE_BIT);
- }
- #if defined(SDRAM_2X16MBITS) && defined(NEW_2X16M_MAPPING)
- void MPEG4Clip_dynamic_malloc(UINT16* uiACBStartAddressAVI, UINT16* uiSPBStartAddressAVI, UINT16* uiAPPStartAddressAVI)
- {
- UINT16 uiINDEXStartAddressAVI;
- // UINT16 uiSUBTITLEStartAddressAVI;
- UINT16 uiACBSizeAVI;
- *uiAPPStartAddressAVI = (UINT16)(_dwMPEG4ProcessingEndAddr>>9); // 512 word
- if ((_mpeg4SubtitleStreamID != NO_STREAM) && (_mpeg4SubtitleType == INTERNAL_SUBP || _mpeg4SubtitleType == INTERNAL_SUBT)) // RB_TBD
- *uiSPBStartAddressAVI = *uiAPPStartAddressAVI -SPB_SIZE_AVI;
- else
- *uiSPBStartAddressAVI = *uiAPPStartAddressAVI;
- if(SI_IS_CURRENT_AVI_CLIP && (TRUE == _bAVIVideoBeforeAudio))
- {
- if (PCM == _mpeg4AudioCodec)
- uiACBSizeAVI = (*uiSPBStartAddressAVI - OSD_BUFFER_SIZE_AVI) / 2;
- else
- uiACBSizeAVI = (*uiSPBStartAddressAVI - OSD_BUFFER_SIZE_AVI) / 6;
- }
- else if (PCM == _mpeg4AudioCodec)
- uiACBSizeAVI = 2 * (*uiSPBStartAddressAVI - OSD_BUFFER_SIZE_AVI) / 3;
- else
- uiACBSizeAVI = (*uiSPBStartAddressAVI - OSD_BUFFER_SIZE_AVI) / 3;
- if (uiACBSizeAVI < 150) // TBD..., need test
- uiACBSizeAVI = 150;
- *uiACBStartAddressAVI = *uiSPBStartAddressAVI - uiACBSizeAVI;
-
- #ifdef _DEBUG
- dbg_printf(("VCB start addresst: %d KBtVCB sizet: %d KBn", OSD_BUFFER_SIZE_AVI,*uiACBStartAddressAVI -OSD_BUFFER_SIZE_AVI ));
- dbg_printf(("ACB start addresst: %d KBtACB sizet: %d KBn", *uiACBStartAddressAVI,*uiSPBStartAddressAVI-*uiACBStartAddressAVI));
- dbg_printf(("SPB start addresst: %d KBtSPB sizet: %d KBn", *uiSPBStartAddressAVI,*uiAPPStartAddressAVI -*uiSPBStartAddressAVI ));
- // dbg_printf(("APP start addresst: %d KBtAPP sizet: %d KBn", *uiAPPStartAddressAVI, uiSUBTITLEStartAddressAVI -*uiAPPStartAddressAVI));
- // dbg_printf(("SUBTITLE start addresst: %d KBtSUBTITLE sizet: %d KBn", uiSUBTITLEStartAddressAVI,uiINDEXStartAddressAVI-uiSUBTITLEStartAddressAVI));
- #endif
- }
- #endif