📄 avirecord.c
字号:
/********************************************************************************
Copyright (c) 2002 Sunplus Technology Co., Ltd.
Module Name: avirecord.c
Function : AVI recording function
Environment: Keil C51 Compiler
Creation : 2002/03/18 yichang
***********************************************************************************/
#include "general.h"
#include "main.h"
#include "sdramhw.h"
#include "image.h"
#include "doslink.h"
#include "dosusr.h"
#include "ui.h"
#include "quantdef.h"
//#include "avioption.h"
#include "cardfunc.h"
#include "dosvar.h"
#include "uiflow.h"
//patch4.4@yichang@for valid signal begin
extern void DELAY_1ms(void);
//patch4.4@yichang@for valid signal end
#if (SMC_OPTION || NANDF_OPTION)
#include "smcfunc.h"
#endif
#if (CFC_OPTION)
#include "cffunc.h"
#endif
#if (SDF_OPTION)
#include "sdfunc.h"
#endif
//patch4.2@richie@ds0511 begin
#if (DOSRAM_OPTION)
#include "dramfunc.h"
#endif
//patch4.2@richie@ds0511 end
//patch3.2@ada@0401 For Multi-Frame Play Back
#include "initio.h"
//Joe@2003.3.3 19:50 add begin
#include "JoeToEvb.h"
//Joe@2003.3.3 19:50 add end
#include "unistd.h"
//patch4.2@yichang@0522
//patch4.4@yichang@move definition to other file, begin
//#define K_MAX_AVI_CHUNCKS (ULONG)( ((ULONG)4194304 - K_SDRAM_Idx1BufAddr) / 8 )
//patch4.4@yichang@move definition to other file, end
xdata USHORT G_AVIWidth;
xdata USHORT G_AVIHeight;
//patch4.2@andrew@0520 for video ae/awb
extern BYTE VIDEO;
extern bit AE_START;
//patch4.3@rihie@vz
extern xdata UCHAR G_ucZoomFactor;
//patch5.0@richie@sdram mapping begin
//patch4.5@richie@smooth zoom begin
extern xdata USHORT G_usZoomX;
//patch4.5@richie@smooth zoom end
//patch5.0@richie@sdram mapping end
//patch4.3@richie@zo v begin
extern xdata USHORT G_usZoomOSDTimer;
sbit PWR_DET = P3^4;
//version4.0@yichang@0513 use function call to reduce code
//-----------------------------------------------------------------------------
//WriteAudID2Dram(ULONG addr)
//-----------------------------------------------------------------------------
void WriteAudID2Dram(ULONG addr) USING_0
{
L2_DRAMSetStartAddr(addr, K_SDRAM_NoPrefetch );
L2_DRAMWriteWord(0x30,0x31);
L2_DRAMWriteWord(0x77,0x62);
L2_DRAMWriteWord(0x00,0x02);
L2_DRAMWriteWord(0x00,0x00);
}
//version4.0@yichang@0513 use function call to reduce code
//-----------------------------------------------------------------------------
//WriteVidIndex2Dram(ULONG MoviOfset, ULONG size , ULONG AVIIdxAddr)
//-----------------------------------------------------------------------------
void WriteVidIndex2Dram(ULONG MoviOfset, ULONG size , ULONG AVIIdxAddr) USING_0
{
//patch5.0@cytsai@AVI index begin
// Video chunk 0x1C00 ~ 0x1C0F
XBYTE[0x1C00] = 0x30; XBYTE[0x1C01] = 0x30;
XBYTE[0x1C02] = 0x64; XBYTE[0x1C03] = 0x63;
XBYTE[0x1C04] = 0x10; XBYTE[0x1C05] = 0x00;
XBYTE[0x1C06] = 0x00; XBYTE[0x1C07] = 0x00;
XBYTE[0x1C08] = (UCHAR)MoviOfset; XBYTE[0x1C09] = (UCHAR)(MoviOfset>>8);
XBYTE[0x1C0A] = (UCHAR)(MoviOfset>>16); XBYTE[0x1C0B] = (UCHAR)(MoviOfset>>24);
XBYTE[0x1C0C] = (UCHAR)size; XBYTE[0x1C0D] = (UCHAR)(size>>8);
XBYTE[0x1C0E] = (UCHAR)(size>>16); XBYTE[0x1C0F] = (UCHAR)(size>>24);
L2_SetSRAMDMA(0x0C00);
L2_SetDRAMDMA(AVIIdxAddr);
L2_DoDMA(1,0,16,0,0);
//patch5.0@cytsai@AVI index end
}
//version4.0@yichang@0513 use function call to reduce code
//-----------------------------------------------------------------------------
//void WriteAudIndex2Dram(ULONG MoviOfset, ULONG AVIIdxAddr)
//-----------------------------------------------------------------------------
void WriteAudIndex2Dram(ULONG MoviOfset, ULONG AVIIdxAddr) USING_0
{
//patch5.0@cytsai@AVI index begin
// Audio chunk 0x1C00 ~ 0x1C0F
XBYTE[0x1C00] = 0x30; XBYTE[0x1C01] = 0x31;
XBYTE[0x1C02] = 0x77; XBYTE[0x1C03] = 0x62;
XBYTE[0x1C04] = 0x00; XBYTE[0x1C05] = 0x00;
XBYTE[0x1C06] = 0x00; XBYTE[0x1C07] = 0x00;
XBYTE[0x1C0C] = 0x00; XBYTE[0x1C0D] = 0x02;
XBYTE[0x1C0E] = 0x00; XBYTE[0x1C0F] = 0x00;
XBYTE[0x1C08] = (UCHAR)MoviOfset; XBYTE[0x1C09] = (UCHAR)(MoviOfset>>8);
XBYTE[0x1C0A] = (UCHAR)(MoviOfset>>16); XBYTE[0x1C0B] = (UCHAR)(MoviOfset>>24);
L2_SetSRAMDMA(0x0C00);
L2_SetDRAMDMA(AVIIdxAddr);
L2_DoDMA(1,0,16,0,0);
//patch5.0@cytsai@AVI index end
}
//version4.0@yichang@0513 use function call to reduce code
//-----------------------------------------------------------------------------
//CopyAudio2Sram512(ULONG AudioAddr, ULONG SramAddr)
//-----------------------------------------------------------------------------
void CopyAudio2Sram512(ULONG AudioAddr, ULONG SramAddr) USING_0
{
L2_SetDRAMDMA(AudioAddr);
L2_SetSRAMDMA(SramAddr);
L2_SetDRAMAudDMACnt(1); // Enable DRAMAuddMACnt
L2_DoDMA(0,1,512,0,0);
L2_SetDRAMAudDMACnt(0);
}
//version4.0@yichang@0513 use function call to reduce code
//-----------------------------------------------------------------------------
//AudioPageLink(USHORT fHandle, ULONG pageAddr, USHORT SecNu)
//-----------------------------------------------------------------------------
void AudioPageLink(USHORT fHandle, ULONG pageAddr, USHORT SecNu) USING_0
{
USHORT offset;
ULONG UsedDramAddr;
offset = SecNu;
UsedDramAddr = pageAddr + offset/2;
offset = 512-offset;
L2_SetDRAMDMA(UsedDramAddr);
//patch4.4@yichang@change SRAM address begin
//L2_SetSRAMDMA(0x0A00);
L2_SetSRAMDMA(0x0C00);
//patch4.4@yichang@change SRAM address end
L2_DoDMA(1,0,offset,0,0);
M_Card_File_Write(fHandle, K_File_SrcDataDram2Card, 512, pageAddr, 0);
//SecAddr++;
//patch4.4@yichang@change SRAM address begin
//UsedDramAddr = 0x0A00+offset;
UsedDramAddr = 0x0C00+offset;
//patch4.4@yichang@change SRAM address end
offset = 512-offset;
L2_SetSRAMDMA(UsedDramAddr);
L2_SetDRAMDMA(pageAddr);
L2_DoDMA(1,0,offset,0,0);
}
//patch4.3@richie@zo v begin
//version4.0@yichang@0513 for AVI recording initialization
//-----------------------------------------------------------------------------
//void L1_InitAVIPreview(void)
//-----------------------------------------------------------------------------
void L1_InitAVIPreview(void) USING_0
{
USHORT imgHeight,imgWidth,imgOffX,imgOffY,jpegHeight;
UCHAR aviFactor;
UCHAR osdStr[5];
//patch4.4@yichang@for valid signal begin
UCHAR i;
aviFactor = G_ucZoomFactor;
L2_SetDisplayType(G_DisplayType);
L2_SetCamMode(0);
//patch5.0@richie@sdram mapping begin
L2_SetAFBAddr(K_SDRAM_AviPvwBufAddrA);
L2_SetBFBAddr(K_SDRAM_AviPvwBufAddrB);
L2_SetRFBAddr(K_SDRAM_AviPvwBufAddrA);
//patch5.0@richie@sdram mapping end
L2_SetDisplayType(21);
//patch5.0@richie@avi size begin
L2_SetACDSPWidth(G_usVideoClip_Width);
L2_SetBCDSPWidth(G_usVideoClip_Width);
L2_SetRCDSPWidth(G_usVideoClip_Width);
L2_SetDisplayMode(1,1);
L2_WaitVD(0, 1);
L2_SetDisplayType(21);
{
imgWidth = G_MHSize;
imgHeight = G_MVSize;
jpegHeight = imgHeight - 13;
if (jpegHeight >= 480) jpegHeight = 480;
else if (jpegHeight >= 360) jpegHeight = 360;
else if (jpegHeight >= 320) jpegHeight = 320;
else if (jpegHeight >= 300) jpegHeight = 300;
else if (jpegHeight >= 288) jpegHeight = 288;
else if (jpegHeight >= 280) jpegHeight = 280;
else if (jpegHeight >= 270) jpegHeight = 270;
else if (jpegHeight >= 264) jpegHeight = 264;
else if (jpegHeight >= 240) jpegHeight = 240;
else if (jpegHeight >= 220) jpegHeight = 220;
else if (jpegHeight >= 210) jpegHeight = 210;
else if (jpegHeight >= 200) jpegHeight = 200;
else if (jpegHeight >= 180) jpegHeight = 180;
else if (jpegHeight >= 160) jpegHeight = 160;
else if (jpegHeight >= 120) jpegHeight = 120;
if (G_usVideoClip_Height == 144)
{
//jpegHeight need smaller than 288 * 2
if (jpegHeight > 288)
jpegHeight = 288;
}
//patch5.0@richie@avi size end
//change to following codes to resolve the ratio problem
imgWidth = imgWidth - (((imgHeight - 13 - jpegHeight) * 4) / 3);
imgHeight = jpegHeight + 13;
imgOffX = (((G_MHSize - imgWidth) / 2) >> 1) << 1;
imgOffY = (((G_MVSize - imgHeight) / 2) >> 1) << 1;
//patch4.4@richie@zv end
}
L2_SetDisplayType(21);
L2_SetFrontImgOffsetm(imgOffX, imgOffY);
L2_SetFrontImgSizem(imgWidth, imgHeight);
//patch4.5@richie@view range (remove '+ 16' of second parameter)
//this one don't need to mark +16
//patch5.0@richie@avi size begin
L2_SetCDSPScale(imgWidth, G_usVideoClip_Width + 16);
//L2_SetCDSPScale(imgWidth, K_VIDEOCLIP_Width);
if(jpegHeight%G_usVideoClip_Height)
{
L2_SetAFBSize(G_usVideoClip_Width,jpegHeight-1);
L2_SetBFBSize(G_usVideoClip_Width,jpegHeight-1);
L2_SetRFBSize(G_usVideoClip_Width,jpegHeight-1);
}
else
{
L2_SetAFBSize(G_usVideoClip_Width,jpegHeight);
L2_SetBFBSize(G_usVideoClip_Width,jpegHeight);
L2_SetRFBSize(G_usVideoClip_Width,jpegHeight);
}
L2_SetJPEGVscale(jpegHeight, G_usVideoClip_Height);
//patch4.1@yichang@0515 for correcting display ratio
L2_SetDisplaySrcImgSize(G_usVideoClip_Width, jpegHeight/*imgHeight - 13*/, G_DisplayType);
//patch5.0@richie@avi size end
//printf("G_usVideoClip_Width = %d,jpegHeight = %d\n",G_usVideoClip_Width,jpegHeight);
L1_InitSPCA533(1);
}
//patch4.3@richie@zo v end
//version4.0@yichang@0513 use function call to reduce code
//-----------------------------------------------------------------------------
//void FillDramLong(ULONG address, ULONG value)
//-----------------------------------------------------------------------------
void FillDramLong(ULONG address, ULONG value) USING_0
{
L2_DRAMSetStartAddr(address, K_SDRAM_NoPrefetch );
L2_DRAMWriteWord((UCHAR)value,(UCHAR)(value>>8));
L2_DRAMWriteWord((UCHAR)(value>>16),(UCHAR)(value>>24));
}
//-----------------------------------------------------------------------------
//L1_VideoClip
//-----------------------------------------------------------------------------
//patch4.2@andrew@0523 video ae/awb
//patch3.2@ada@0401 For Multi-Frame Play Back
extern unsigned char G_MANUAL_WB_Flag;
UCHAR L1_VideoClip() USING_0
{
USHORT i;
UCHAR QTable[128];
ULONG Compsize;
ULONG AVIIdxAddr;
ULONG SecAddr;
ULONG SecCnt;
ULONG AVLCAddr;
ULONG BVLCAddr;
USHORT SecNu;
ULONG DRAMAudBufCnt;
ULONG MoviOfset;
ULONG VidChunkCnt;
ULONG AudChunkCnt;
ULONG AviSize;
ULONG MoviSize;
ULONG tmp0;
UCHAR tmp1;
BYTE sts;
USHORT freeCluster;
USHORT usedCluster;
USHORT fHandle;
ULONG DramDMAaddr;
ULONG fragmentAddr;
BYTE name[12];
ULONG UsedDramAddr;
//version4.0@yichang@0513 change data type
ULONG totalChuck;
float TframeRate;
UCHAR AudDMACnt;
ULONG RecordVidCnt;
ULONG usedSize;
ULONG dwScale,dwRate;
BYTE rwMode;
ULONG AvlcAddr, BvlcAddr ;
ULONG AudioAddr, AVIHeadAddr;
//Joe@2003.3.12 18:44 add begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -