⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fiavi.c

📁 dz3000_51.0.0.4.rar
💻 C
字号:
/*++

Copyright (c) 2001 Sunplus Technology Co., Ltd.

Module Name:

        fiavi.c

Abstract:

        Module that related to avi file recording

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 "cardui.h"
#include "libfunc.h"
#include "libvar.h"
// WWW1 end

//=============================================================================
//Symbol
//=============================================================================
//-----------------------------------------------------------------------------
//Constant
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//Variable
//-----------------------------------------------------------------------------
xdata   ULONG   G_File_SDRAM_AviIdx1BufSize;

//=============================================================================
//Program
//=============================================================================

//-----------------------------------------------------------------------------
//File_RecordAvi
//-----------------------------------------------------------------------------
/*++

Routine Description:

Arguments:
        none

Return Value:

        none

--*/
BYTE File_RecordAvi(UCHAR *name, UCHAR bAudio) USING_0
{
        UCHAR QTable[128];
        UCHAR sts;
        UCHAR firstImage;
        ULONG size;
        ULONG Idx1MaxCount;     //maximal allowed idx count for video
        USHORT freeCluster;
        USHORT usedCluster;
        USHORT fHandle;

        // maximal cluster requester, so that checking whole free disk space
        freeCluster = DOS_GetDiskSpace();

        sts = FALSE;

        // initial used cluster
        // 1 possible fdb cluster
        // add 300K size of cluster for safe
        usedCluster = 1 + ((ULONG)300L*1024L)/(ULONG)G_DOS_ClusterSize;

        if (freeCluster > usedCluster)
        {
                freeCluster -= usedCluster;

                // ensure 500 minimal data recorded
                usedCluster = (500L*1024L)/G_DOS_ClusterSize;
                if (usedCluster <= freeCluster)
                     sts = TRUE;
        }
        if ( sts == FALSE )
        {
        	//M_DOS_SetError(K_DOS_DiskFullErr); // WWW1
                return FALSE;
	}
	
        // request max free clusters as possible
        fHandle = File_Open(0,K_DOS_NewFile,100);
        if ( fHandle == 0 )
                return FALSE;

        // What if during recording the disk is full ?
        // This could handle, but it will consume many CPU time and
        // reduce frame rate. Current implementation is to have destroy
        // AVI file.

        L2_WriteQTable(K_QWriteTable, G_Image_QTableIndex, NULL);
        L2_ReadQTable(K_QReadTableZigzag, &G_Image_QTableIndex, QTable);

        firstImage = 1;
	G_File_AudioEnable = 0;        	// @WYEO, 102601
	G_Image_VlcSize = 0;		// @WYEO, 1023
        G_File_AviIdx1Count = 0;
        G_File_AviTotalSize = 512;  	//size of AVI header
        G_File_AviVideoChunkCount = 0;
        G_File_AviAudioChunkCount = 0;
        #if ( AUDIO_OPTION == 1 )
        G_File_AudioSize = 0;
        #endif

        // G_File_SDRAM_AviIdx1BufSize is in word unit, so need to multiply 2
        // -8 = File_AviIndexId + File_AviIndexSize
        // >> 4 for per idx is 16 byte
        // -16 byte for one audio idx
        Idx1MaxCount = ( ( G_File_SDRAM_AviIdx1BufSize << 1 ) - 8 - 16 ) >> 4;

        File_AviIndexId();              	//fill ID of idx1 chunk

        G_DOS_SDRAM_NextIntRetAddr = G_SDRAM_ImageAddr;

        L2_DRAMSetStartAddr(G_SDRAM_ImageAddr, K_SDRAM_NoPrefetch);

        SETMODE_ChangeCameraMode(K_MODE_IDLE);              //clear post buffer
        File_SetImageMode(1, bAudio);

        #if ( AUDIO_OPTION == 1 )
        if (bAudio)
                File_AudioSetMode();            //set audio mode
        #endif

	#if ( AUDIO_OPTION == 1 )
	if (bAudio)
        	TIMER0_Start();         	//start timer0
	#endif
	
        while (G_btStopStream == 0)
        {
                if ( G_File_AviIdx1Count < Idx1MaxCount )
                {
                        if (firstImage)
                                size = File_AviWriteFirstFrame();                       //write first image
                        else
                                size = File_AviWriteFrameData();                        //write one image
                        if (size)
                        {
                                File_AviSetIndex(size,bAudio,(firstImage==0));          //video index
                                G_File_AviTotalSize += size;                            //increase size
                                G_File_AviVideoChunkCount++;                                 //increase image count
                        }
                        else
                        {
                                //M_DEBUG_STOP_FACTOR(2); // WWWW1
                                G_btStopStream = 1;
                        }
                        firstImage = 0;

                        // image size + audio size + idx size + 1 cluster size
                        #if ( AUDIO_OPTION == 1 )
                        size = G_File_AviTotalSize + ( G_File_AudioSize << 1 ) + (G_File_AviIdx1Count << 4) + G_DOS_ClusterSize;
                        #else
                        size = G_File_AviTotalSize + (G_File_AviIdx1Count << 4) + G_DOS_ClusterSize;
                        #endif
                        usedCluster = size / G_DOS_ClusterSize;
                        if ( usedCluster >= freeCluster )
                        {
                                //M_DEBUG_STOP_FACTOR(3); // WWWW1
                                G_btStopStream = 1;
                        }
                        else
                                File_SendMessage( K_File_UI_VideoStrm1Frame, G_File_AviVideoChunkCount );
                }
                else
                        G_btStopStream = 1;
        }

	#if ( AUDIO_OPTION == 1 )
	if (bAudio)
        	TIMER0_Stop();			//stop timer0
	#endif
        File_StopClipMode(bAudio);

        G_btStopStream = 0;

        if ( G_File_AviVideoChunkCount == 0 )
                sts = FALSE;

        SETMODE_ChangeCameraMode(K_MODE_IDLE);
        SETMODE_ChangeCameraMode(K_MODE_PLAYBACK);                            //set upload mode

        if ( sts )
        {
                #if ( AUDIO_OPTION == 1 )
                if (bAudio)
                {
                        size = File_AviAudioSetHeader();                        //set audio header in SDRAM buffer
                        File_AviAudioSetIndex((G_File_AudioSize << 1)-8);       //audio index
                        File_AviAudioWriteData(size);                           //write audio samples
                        G_File_AviTotalSize += size;                            //increase size
                        G_File_AviVideoChunkCount++;                                 //increase image count
                }
                #endif

                File_AviIndexSize();                                            //fill Size of idx1 chunk
                G_File_AviTotalSize += File_AviWriteIndex();                    //write AVI index chunk

                File_AviWriteHeader(bAudio);                                    //write AVI header

                //#if ( K_DEBUG_APPENDINFO == 1 )// WWW1
                //G_File_AviTotalSize += M_DEBUG_CardWriteInfo();                 // DEBUG
                //#endif

                File_Close(1, name, K_DOS_NewFile, G_File_AviTotalSize);

        }

        #if ( AUDIO_OPTION == 1 )
        if (bAudio)
                G_File_AudioEnable = 0;                 // stop audio
        #endif

        SETMODE_ChangeCameraMode(K_MODE_IDLE);

        return sts;
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -