📄 avilib.c
字号:
/*++
Copyright (c) 2001 Sunplus Technology Co., Ltd.
Module Name:
avilib.c
Abstract:
Module that provide service to avi file creation
Environment:
Keil C51 Compiler
Revision History:
09/03/2001 William Yeo created
--*/
//=============================================================================
//Header file
//=============================================================================
// WWW1 start
#include "general.h"
#if ( K_File_HaveVideo == 1 )
#include "cardimpt.h"
#include "cardlink.h"
#include "dosfunc.h"
#include "libfunc.h"
#if (SMC_OPTION || NANDF_OPTION)
#include "smcfunc.h"
#endif
#if (CFC_OPTION)
#include "cffunc.h"
#endif
#if (SDF_OPTION)
#include "sdfunc.h"
#endif
//version4.0@ada@0513 for MMC
#if (MMC_OPTION)
#include "mmcfunc.h"
#endif
//patch4.2@richie@ds0511 begin
#if (DOSRAM_OPTION)
#include "dramfunc.h"
#endif
//patch4.2@richie@ds0511 end
#include "avidef.h"
#include "aviusr.h"
// WWW1 end
//=============================================================================
//Symbol
//=============================================================================
//-----------------------------------------------------------------------------
//Constant
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//Variable
//-----------------------------------------------------------------------------
xdata ULONG G_File_SDRAM_AviIdx1BufAddr;
xdata ULONG G_File_AviVideoChunkCount;
xdata ULONG G_File_AviAudioChunkCount;
xdata ULONG G_File_AviTotalSize;
xdata ULONG G_File_AviFirstImageSize;
idata ULONG G_File_AviIdx1Count;
xdata ULONG G_File_AviFirstImageVlcSize;
//-------------------------------------
//File_AviIndexId
//-------------------------------------
void File_AviIndexId(void) USING_0
{
//set SDRAM buffer start address
L2_DRAMSetStartAddr(G_File_SDRAM_AviIdx1BufAddr, K_SDRAM_NoPrefetch);
G_ucStorData[0] = 'i';
G_ucStorData[1] = 'd';
G_ucStorData[2] = 'x';
G_ucStorData[3] = '1';
SDRAM_Sram2Dram(G_ucStorData, G_File_SDRAM_AviIdx1BufAddr, 4);
}
//-------------------------------------
//File_AviIndexSize
//-------------------------------------
void File_AviIndexSize(void) USING_0
{
ULONG size;
//calculate size
size = G_File_AviVideoChunkCount * 16;
//set SDRAM buffer start address
L2_DRAMSetStartAddr((G_File_SDRAM_AviIdx1BufAddr + 2), K_SDRAM_NoPrefetch);
G_ucStorData[0] = size;
G_ucStorData[1] = size >> 8;
G_ucStorData[2] = size >> 16;
G_ucStorData[3] = size >> 24;
SDRAM_Sram2Dram(G_ucStorData, G_File_SDRAM_AviIdx1BufAddr + 2, 4);
}
//-----------------------------------------------------------------------------
//File_AviWriteFirstFrame
//-----------------------------------------------------------------------------
ULONG File_AviWriteFirstFrame(void) USING_0
{
BYTE sts;
//initialization
G_File_AviFirstImageSize = 0;
//write one image
sts = M_Card_File_Write(1, K_File_SrcAviFifo2Card,0,0,1);
if (G_File_WritePageCount > 0)
{
G_File_AviFirstImageSize =
((ULONG)G_File_WritePageCount) << K_Card_PageSizeShift; //Junk header + Image header
}
G_File_AviFirstImageVlcSize = G_Image_VlcSize;
return G_File_AviFirstImageSize;
}
//-----------------------------------------------------------------------------
//File_AviWriteFrameData
//-----------------------------------------------------------------------------
ULONG File_AviWriteFrameData(void) USING_0
{
BYTE sts = TRUE;
ULONG size = 0;
//initialization
sts = M_Card_File_Write(1, K_File_SrcAviFifo2Card,0,0,1);
if (G_File_WritePageCount > 0)
{
size = (((ULONG)G_File_WritePageCount) << K_Card_PageSizeShift) + K_Card_PageSize; //Junk header + Image header
File_AviWriteFrameHeader(size - K_Card_PageSize + (0x16 - 0x08)); //Image padding
}
return size;
}
//-----------------------------------------------------------------------------
//File_AviWriteFrameHeader
//-----------------------------------------------------------------------------
BYTE File_AviWriteFrameHeader(USHORT size) USING_0
{
BYTE sts = TRUE;
data USHORT i;
//SizeField = PageSize - (("JUNK" + Junksize) + ("00db" + ImageSize + ImagePadding))
//idata USHORT junkSize = (WORD) (K_Card_PageSize - (0x08 + 0x16));
USHORT junkSize = 482;
//ID = "JUNK"
G_ucStorData[0] = 'J';
G_ucStorData[1] = 'U';
G_ucStorData[2] = 'N';
G_ucStorData[3] = 'K';
//Junk Size
G_ucStorData[4] = junkSize;
G_ucStorData[5] = junkSize >> 8;
G_ucStorData[6] = 0x00;
G_ucStorData[7] = 0x00;
//Junk Data
/*
for (i = 0; i < junkSize; i++)
G_ucStorData[k++] = 0x00;
*/
//ID = "00db"
// 490 = Junk Size + 8 = 482 + 8 = 490
G_ucStorData[490] = '0';
G_ucStorData[491] = '0';
G_ucStorData[492] = 'd';
G_ucStorData[493] = 'b';
//Size
G_ucStorData[494] = size;
G_ucStorData[495] = size >> 8;
G_ucStorData[496] = size >> 16;
G_ucStorData[497] = size >> 24;
G_ucStorData[498] = G_Image_VlcSize; // 00
G_ucStorData[499] = G_Image_VlcSize >> 8; // 01
G_ucStorData[500] = G_Image_VlcSize >> 16; // 02
G_ucStorData[501] = G_Image_VlcSize >> 24; // 03
G_ucStorData[502] = 0x00; // 04
G_ucStorData[503] = 0x00; // 05
G_ucStorData[504] = G_Image_QTableIndex; // 06
G_ucStorData[505] = 0; // 07
for (i = 506; i < 512; i++) // 08-0D
G_ucStorData[i] = 0x00;
M_SrcAviFrameHead_WritePage(G_File_FrameHdrLogAddr, G_File_FrameHdrPhyAddr, G_File_FrameHdrLogBlock);
return sts;
}
//-----------------------------------------------------------------------------
//File_AviWriteIndex
//-----------------------------------------------------------------------------
ULONG File_AviWriteIndex(void) USING_0
{
BYTE sts = TRUE;
ULONG size;
//calculate size
size = 8 + ( G_File_AviVideoChunkCount * 16 );
L2_DRAMSetStartAddr((G_File_SDRAM_AviIdx1BufAddr), K_SDRAM_Prefetch);
M_Card_File_Write(1, K_File_SrcDataDram2Card,( (size+K_Card_PageSize-1) >> K_Card_PageSizeShift ) << K_Card_PageSizeShift, G_File_SDRAM_AviIdx1BufAddr,0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -