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

📄 dcautl.cpp

📁 Vxworks 下的视频采集程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include <stdio.h>
//#include <bios.h>
//#include <conio.h>
//#include <dos.h>
#include <time.h>
#include "xdefine.h"
#include "w99200f.h"

#define REL_MASTER_BUFFER_SIZE 4096 



int _dMem_Data[64];// 4*64=256 Bytes
int _dSDRAM_Data[2052]; // 2048*4=8192 Bytes
int _dAUDIO_Data[32]; // 32*4=128 Bytes
int _dDef_Regs[135];  // Default Value of Registers

extern char input_file[60];
extern char output_file[60];

extern unsigned long _IOBase;     // I/O base for video 
extern int  _ulODPR ;   // the Output port of the Output-FIFO
// Register Test
extern BOOL W99200WriteReg(int index, int value);

extern int W99200ReadReg (int index);
extern void W99200ReSet(); 
extern void W99200F_DELAY(void) ;
// I2C Test
extern BOOL  W99200I2CWrite(int Subadrs,int *Value,UINT Count);
extern BOOL  W99200I2CRead(int Subadrs,int *Value); 
// SDRAM Test
extern BOOL W99200SDRAM_Write(int Mem); 
extern BOOL W99200SDRAM_Read(int Mem);
extern BOOL W99200SDRAM_MARead(int Mem);
// MEMORY Test
extern BOOL W99200IMEM_Write(int Mem); 
extern BOOL W99200IMEM_Read(int Mem);
extern BOOL W99200IMEM_MARead(int Mem);
// AUDIO Test
extern BOOL W99200AUDIO_Read(void);
// 26QF
extern BOOL W9920026QF_Write(int index, int data);  
extern int W9920026QF_Read(int index);
// AUDIO CODEC Test
extern int AK4516ReadReg(int index);  
extern BOOL AK4516WriteReg(int index,int dvalue);
 
 
extern BOOL W99200FIFO_Thr(void); 
extern BOOL W99200FIFO_End(void); 


extern void W99200OutIndexdw(int Port, int IndexData,int DataAddress, int Data); 
extern int W99200InIndexdw(int Port, int IndexData, int DataAddress);
extern void W99200Outpdw(int port, int data);
extern int W99200Inpdw(int port);

// UTL Function 
BOOL UTL_LVE(char *szFileName, int dwLimit, int iUseMaster); //iUsemaster=1: Master mode, otherwise is not master mode
BOOL UTL_LVPT(void);  
BOOL UTL_LVSS(int);
BOOL UTL_SFE(int Size_H, int Size_V,int iCompress);
BOOL UTL_WFR(int Size_H, int Size_V);
BOOL UTL_RFR(int Size_H, int Size_V); 
BOOL UTL_SET_I2CVIDEO(void);  
BOOL UTL_AUDIOFIFO(char *szFileName, int dwLimit);



// For SFE Parameters;
extern int _SFE_FrameSizeX;
extern int _SFE_FrameSizeY;
extern char  _SFE_InFileName[60];
extern char  _SFE_OutFileName[60];  


// For LVE Parameters
extern int _LVE_PictureResoultion; // Reg:Video_Format
extern int _LVE_RC_Mtehod;
extern int _LVE_Bitrate;
  
// For Common Parameters
extern int _CaptureType;
extern int _CompressMethod;
extern int _Quality;
extern int _VideoStard; //0:NTSC,1:PAL
                                         
extern int iSA;

//**************************************************************************
//    Function    :UTL_LVE
//    Description :Live video encoding
//    Return      :BOOL
//************************************************************************** 
/*Modified by JJDS 16/3/2001to take filename and use the limit parameters as the time limit
*/
BOOL UTL_LVE(char *szFileName, int dwLimit, int iUseMaster)
{   

// ##### for Maste mode buffer
   char _cc0[REL_MASTER_BUFFER_SIZE+4], _cc1[REL_MASTER_BUFFER_SIZE+4];
   void *_pp0 = _cc0, *_pp1 = _cc1;
   char *_pcc0 = _cc0, *_pcc1 = _cc1;
   unsigned long _ulSeg, _ulOff, _ulAddr0, _ulAddr1;
// ##### for Maste mode buffer 
   int dRead=0; 
   int iMBufferIndex=0; 
   int key;
   int done=FALSE;
   int i;
   FILE *fp1; // Output file
   int *pRam;
   int j;  
   clock_t start_time,end_time;
   key=0;
   static int iFileCount = 0; 
   int nTemp=0;
   
   if (_LVE_Bitrate==0)
    _LVE_Bitrate=1024000;
   
   W99200WriteReg( PCR,0x61 ); 
   W99200WriteReg( PCR,0x60 );  
   for ( j=0 ; j < 4096 ; j++)
   {
      _cc0[j]= _cc1[j]=0;
   } 

    if (!szFileName)
    {
        printf("invalid filename\n");
        return FALSE;
    }
   fp1=fopen(szFileName,"w+b");
   if ( fp1==NULL)
   {
       printf(" \n encoding file open error !!! ");
       return FALSE;
   }

   // Set SAA7114
   UTL_SET_I2CVIDEO();

   // #### Video Reset          
   W99200WriteReg(Video_reset, 0xFF);//any data 

   // #### Initial the Internal memory:index 01~04 and 0c 

   BYTE DefaultRam[] = 
   {
     #include "Ram.h"
   };
   // index: 00~04  256 bytes
   for ( i=0 ; i < 5 ; i++)
   {
     pRam=(int *)(DefaultRam+(i*256));
     for ( j=0 ; j < 64 ; j++)
     {
        _dMem_Data[j]=*(pRam+j);
     }
     W99200IMEM_Write(i);
   } 
   // index: 0c  128 bytes
   pRam=(int *)(DefaultRam+(5*256));
   for ( j=0 ; j < 32 ; j++)
   {
        _dMem_Data[j]=*(pRam+j);
   }
   W99200IMEM_Write(0x0c); 
   
   // index:06    128 bytes 
   pRam=(int *)(DefaultRam+(6*256));
   for ( j=0 ; j < 32 ; j++)
   {
        _dMem_Data[j]=*(pRam+j);
   }
   W99200IMEM_Write(0x06);
     
   //5. Soft Reset          
   W99200WriteReg(Video_reset, 0xFF);//any data 

   //6. Configuration

   W99200WriteReg(Vint_enable, 0x00);
   W99200WriteReg(Vthreshold, 0x0f);// 60=15*4 int  
   W99200WriteReg(Vwork_mode,0x00); 
   
   if ( _LVE_PictureResoultion ==1 && _VideoStard==0) //NTSC,SIF 
      W99200WriteReg(Video_format,0x01); // SIF
   if ( _LVE_PictureResoultion ==2 && _VideoStard==0) //NTSC,QSIF
      W99200WriteReg(Video_format,0x02); // QSIF
   if ( _LVE_PictureResoultion ==1 && _VideoStard==1) //SQUARE,SIF 
      W99200WriteReg(Video_format,0x05); // SIF
   if ( _LVE_PictureResoultion ==2 && _VideoStard==1) //SQUARE,QSIF
      W99200WriteReg(Video_format,0x06); // QSIF      
   if ( _LVE_PictureResoultion ==1 && _VideoStard==2) //PAL,SIF 
      W99200WriteReg(Video_format,0x09); // SIF
   if ( _LVE_PictureResoultion ==2 && _VideoStard==2) //PAL,QSIF
      W99200WriteReg(Video_format,0x0a); // QSIF
   W99200WriteReg(Venc_cntl,0x6c);
          
   W99200WriteReg(Vframe_pattern,0x12);
   _LVE_Bitrate=_LVE_Bitrate/400; 
   int rate_m;
   int rate_l;
   rate_m= _LVE_Bitrate >> 8;
   rate_l= _LVE_Bitrate & 0x000000FF;
   W99200WriteReg(Vbit_rate_m,rate_m); // Bit-rate
   W99200WriteReg(Vbit_rate_l,rate_l); //
   W99200WriteReg(Vbv_size,0x32);//0x14);
   W99200WriteReg(Vbv_initial,0x31);//0x13);
   W99200WriteReg(Vquality,_Quality);    // 01(High) ~ 1F (Low) 
   W99200WriteReg(Vslice_header,0x01);
   W99200WriteReg(Vgop_header,0x01); 
   W99200WriteReg(Vit_hour,0x00);
   W99200WriteReg(Vit_minute,0x00);
   W99200WriteReg(Vit_second,0x00);
   W99200WriteReg(Vit_frame,0x00); 

   W99200WriteReg(Vin_offset,0x00);//00);
      
   if ( _LVE_RC_Mtehod == 0 ) // Constant Bitrate
      W99200WriteReg(Venc_cntl,0x4c);
    if ( _LVE_RC_Mtehod == 1 ) // Maximum Bitrate  
      W99200WriteReg(Venc_cntl,0x4d);
   if ( _LVE_RC_Mtehod == 2 ) // Variable Bitrate 
      W99200WriteReg(Venc_cntl,0x4e);  
   W99200WriteReg(Vin_picture,0x00);

   // #### for Master mode
   if ( iUseMaster == 1 )
   {
   // ##### Allocate Master Mode Buffer0  
       _ulSeg = _FP_SEG(_pp0);
       _ulOff = _FP_OFF(_pp0);
       _ulAddr0 = (_ulSeg << 4) + _ulOff;
       for( i = 1; i < 4; i ++ )    // Find the 4 address
       {
          if((_ulAddr0 & 0x0003L) == 0)
              break;
          _ulAddr0 ++;
          _pcc0 ++;
       }
   // ##### Allocate Master Mode Buffer1
       _ulSeg = _FP_SEG(_pp1);
       _ulOff = _FP_OFF(_pp1);
       _ulAddr1 = (_ulSeg << 4) + _ulOff;
       for( i = 1; i < 4; i ++ )    // Find the 4 address
       {
          if((_ulAddr1 & 0x0003L) == 0)
              break;
          _ulAddr1 ++;
          _pcc1 ++;
       }
      // ##### Set W99200 register for master mode
      W99200WriteReg(Vthreshold, 0x000F);// 15*4 double-word(60*4 bytes)
      W99200WriteReg(BBSR,0x03FB03FBL);  // Buffer Size -1 ( 1020-1 =1019=0x03FB ) uint is int 
                                         // Buffer Size must be multiple of threshold level int
                                         // So 1024/60=17.066 Buffer Size= 17*60=1020     
      // ##### Buffer 0
      W99200WriteReg(BBSAR0, _ulAddr0); // Main Memory address (Buffer0)
      W99200WriteReg(BBSTR0,0x03);      // Buffer ready
      // ##### Buffer 1
      W99200WriteReg(BBSAR1, _ulAddr1); // Main Memory address (Buffer1)
      W99200WriteReg(BBSTR1,0x03);      // Buffer ready
      // ##### Open Master Enable
      W99200WriteReg(PCICR,0x02);     
   }

     //7. VStart Command
   W99200WriteReg(Vstart,0xff); // any data
   start_time=clock();
   if ( dwLimit == 0) // No Time Limit=> until Press 'S'
   {
        printf(" \n Press 's' or 'S' to stop live video encoding\n");
        do
        {
            
            key=_bios_keybrd(_KEYBRD_READY)&0xff;
            if (key!=0 ) // any key is pressed
            {
                  key=_bios_keybrd(_KEYBRD_READ)&0xff;
                  if((key=='S')||(key=='s') ) // "s" key is pressed
                  {
                        W99200WriteReg(Vstop,0xff);//9. Stop command
                  }
            }
            //8. Reverse Data transfer + handling interrupts
            if ( iUseMaster == 1 )
            {      
                  // Poll BSTR0 to check if Buffer 0 is full 
                  dRead=W99200ReadReg(BBSTR0);
                  if ( ((dRead & 0x02) == 0x02 )  && iMBufferIndex == 0 )
                  {
                        if ( fwrite(_pcc0, sizeof(BYTE),4080,fp1) != 4080 )
                                printf( " Buffer 0 write file error!\n" );
                        W99200WriteReg(BBSTR0,0x03);
                        iMBufferIndex=1;
                  } 
                  // Poll BSTR1 to check if Buffer 1 is full 
                  dRead=W99200ReadReg(BBSTR1);
                  if ( ((dRead & 0x02) == 0x02 ) && iMBufferIndex ==1 )
                  {
                        if ( fwrite(_pcc1, sizeof(BYTE),4080,fp1) != 4080 )
                             printf( " Buffer 1 write file error!\n" );
                        W99200WriteReg(BBSTR1,0x03);
                        iMBufferIndex=0;
                  }
            } //if ( iUseMaster == 1 )
            else
            {
                  if ( W99200FIFO_Thr()== TRUE )
                  {
                        for( i=0 ; i <60  ; i++)
                        {
                            _dMem_Data[i]=W99200Inpdw(_IOBase+_ulODPR);
                        }
                        fwrite(_dMem_Data,sizeof(int),60,fp1);
                        
                  }
            }
        }while((key!='s')&&(key!='S') && (W99200FIFO_End()!=TRUE));
   }
   else
   {
        printf("Recording for %d seconds...", dwLimit);
//        printf(" \n Stop After %d Second",dwLimit);
        do
        {
           //8. Reverse Data transfer + handling interrupts
            if ( iUseMaster == 1 )
            {      
                  // Poll BSTR0 to check if Buffer 0 is full 
                  dRead=W99200ReadReg(BBSTR0);
                  if ( ((dRead & 0x02) == 0x02 )  && iMBufferIndex == 0 )
                  {
                        if ( fwrite(_pcc0, sizeof(BYTE),4080,fp1) != 4080 )
                                printf( " Buffer 0 write file error!\n" );
                        W99200WriteReg(BBSTR0,0x03);
                        iMBufferIndex=1;
                  } 
                  // Poll BSTR1 to check if Buffer 1 is full 
                  dRead=W99200ReadReg(BBSTR1);
                  if ( ((dRead & 0x02) == 0x02 ) && iMBufferIndex ==1 )
                  {
                        if ( fwrite(_pcc1, sizeof(BYTE),4080,fp1) != 4080 )
                             printf( " Buffer 1 write file error!\n" );
                        W99200WriteReg(BBSTR1,0x03);
                        iMBufferIndex=0;
                  }
            } //if ( iUseMaster == 1 )
            else
            {
                  if ( W99200FIFO_Thr()== TRUE )
                  {
                        for( i=0 ; i <60  ; i++)
                        {
                            _dMem_Data[i]=W99200Inpdw(_IOBase+_ulODPR);
                        }
                        fwrite(_dMem_Data,sizeof(int),60,fp1);
                        
                  }
            }
           end_time=clock(); 
           if((int)(end_time-start_time) > dwLimit*1000 ) // "s" key is pressed
                W99200WriteReg(Vstop,0xff);//9. Stop command       
        }while(((int)(end_time-start_time) <=dwLimit*1000) && (W99200FIFO_End()!=TRUE));
     
   }   
    //10. Reverse Data transfer + handling interrupts 
    if ( iUseMaster == 1 )
    {   
        
        if ( iMBufferIndex == 0 )
        {
            dRead=W99200ReadReg(BBFR);
            if ( fwrite(_pcc0, sizeof(BYTE),(unsigned int)dRead*4,fp1) != (unsigned int)(dRead*4) )
                   printf( " Buffer 0 write file error!\n" );
        }
        else
        {
            dRead=W99200ReadReg(BBFR);
            if ( fwrite(_pcc1, sizeof(BYTE),(unsigned int)(dRead*4),fp1) != (unsigned int)(dRead*4) )
                   printf( " Buffer 1 write file error!\n" );
        }
        W99200WriteReg(PCICR,0x00);     // Close Master Enable    
    }
    else
    {                    
      do 
      {
         if ( W99200FIFO_Thr()== TRUE )
         {
            for( i=0 ; i < 60 ; i++)
               _dMem_Data[i]=W99200Inpdw(_IOBase+_ulODPR);
            fwrite(_dMem_Data,sizeof(int),60,fp1);
         }
      } while ( W99200FIFO_End()!=TRUE  );// Pooling the End of Data
    }
    if ( dwLimit == 0)
    {
      end_time=clock();
      printf("\n Time : %ld second", (end_time-start_time)/1000 );
    }
    printf("\n OutPutFile : %s\n",szFileName);   
    fclose(fp1);
    return TRUE;
}  
  
//**************************************************************************
//    Function    :UTL_LVPT
//    Description :Live video pass through
//    Return      :BOOL
//************************************************************************** 
BOOL UTL_LVPT(void)
{
          return TRUE;
}

//**************************************************************************
//    Function    :UTL_LVSS
//    Description :Live video snap shot
//    Return      :BOOL
//************************************************************************** 
BOOL UTL_LVSS(int isize)
{            
    int dEnd=0;       
    int nTemp=0;
    // Set SAA7114
    UTL_SET_I2CVIDEO();   
    //1. Video Reset       
    W99200WriteReg(Video_reset, 0xFF);//any data  
    /*
    // Currently, Not support logo enable ,so 2,3 don't need to do. 
    //2. Write SDRAM bit-map(optional, for logo)
     
    //3. Video Reset
    W99200WriteReg(Video_reset, 0xFF);//any data
    */
    //4. Configuration
     W99200WriteReg(Vint_enable, 0x03);
     W99200WriteReg(Vthreshold, 0x0f);// 60=15*4 int     
     W99200WriteReg(Vwork_mode,0x02); // work mode   
     
     if ( _VideoStard == 0 ) // NTSC
     {
        if ( isize== 0 ) // full: 704*480
            W99200WriteReg(Video_format,0x00);
        else if (isize==1 ) // SIF: 352*240
            W99200WriteReg(Video_format,0x01);
        else
            W99200WriteReg(Video_format,0x02);// QSIF: 176*112
     }
     else // PAL
     {
        if ( isize== 0 ) // full: 704*576
            W99200WriteReg(Video_format,0x08);
        else if (isize==1 ) // SIF: 352*288
            W99200WriteReg(Video_format,0x09);
        else
            W99200WriteReg(Video_format,0x0A);// QSIF: 176*144
     } 
     W99200WriteReg(Vin_offset,0x00);// 
     W99200WriteReg(Vin_cntl,0xc);//

⌨️ 快捷键说明

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