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

📄 dcautl.cpp

📁 Vxworks 下的视频采集程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                      _dSDRAM_Data[i] = W99200Inpdw( _IOBase+4 );     //_ulODPR );
                 }
                 fwrite( _dSDRAM_Data, sizeof(int), 127, fp1 );              
              }
              
               end_time=clock(); 
           if((int)(end_time-start_time) > dwLimit*1000 ) // "s" key is pressed
           {
                dAudioTemp=W99200ReadReg (AFCR1);
                dAudioTemp=dAudioTemp | 0x0008;
                W99200WriteReg(AFCR1,dAudioTemp);// write "1" into A_START bit4  
           }           
        }while(((int)(end_time-start_time) <=dwLimit*1000) && (dAudioTemp=W99200ReadReg(AFISR) & 0x0020)!= 0x0020 ); 
    }            
    fclose(fp1);  
    end_time=clock();
    printf("\n Capture Time : %d second", (end_time-start_time)/1000 );

    // ### check lost data
    dAudioTemp=W99200ReadReg(AFISR);
    if ( dAudioTemp & 0x04 == 0x04 )
    {
        dAudioTemp=W99200ReadReg(ALDR0) & 0x00ff;  
        LostData=dAudioTemp;
        dAudioTemp=W99200ReadReg(ALDR1) & 0x00ff;
        dAudioTemp<<=8;
        LostData=LostData + dAudioTemp;
        printf(" \n Lost Data: %ldK ~ %ldK bytes\n ",LostData, LostData+1);
    }
    printf(" \n Ok! The audio data has been saved as the audio.pcm!\n");
    return TRUE;
} 

    
void DumpI2c(void)
{
   int k;
   int dwTemp;
   for (k=0;k<0x1f;k++)
   {
        W99200I2CRead(k,&dwTemp);
        printf("i2c[%x]=%x \t",k, dwTemp);
        if (!(k%5))
            printf("\n");
    }   
    getchar();
   for (k=0x30;k<0x5f;k++)
   {
        W99200I2CRead(k,&dwTemp);
        printf("i2c[%x]=%x \t",k, dwTemp);
//        if (!(k%5))
  //          printf("\n");
    }   
    getchar();
   for (k=0x80;k<0xef;k++)
   {
        W99200I2CRead(k,&dwTemp);
        printf("i2c[%x]=%x \t",k, dwTemp);
//        if (!(k%5))
  //          printf("\n");
    }   
    getchar();
}    


//**************************************************************************
//    Function    :UTL_LE
//    Description :Live video encoding and audio capture
//    Return      :BOOL
//    added JJDS 16/3/2001
//************************************************************************** 
BOOL UTL_LE(char *szVideoFileName, char *szAudioFileName, 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;

    int dAudioTemp;
    int LostData;
    FILE *fp2;
    int countIndex=0;
   
   _LVE_Bitrate=1024000;
   
   W99200WriteReg( PCR,0x61 ); 
   W99200WriteReg( PCR,0x60 );  
   for ( j=0 ; j < 4096 ; j++)
   {
      _cc0[j]= _cc1[j]=0;
   } 

    if (!szVideoFileName)
    {
        printf("invalid video filename\n");
        return FALSE;
    }
    if (!szAudioFileName)
    {
        printf("invalid audio filename\n");
        return FALSE;
    }
    
   fp1=fopen(szVideoFileName,"w+b");
   if ( fp1==NULL)
   {
       printf(" \n encoding file open error !!! ");
       return FALSE;
   }
   fp2=fopen(szAudioFileName,"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);     
   }

    dAudioTemp=0x07;
    // ### Initial OKI FIFO
    
    W99200WriteReg(AFCR1,dAudioTemp);

    dAudioTemp=0x0040;//Clear AIN_RST for lost data, first writ 1 then write 0                                  
    W99200WriteReg(AFCR0,dAudioTemp);
    W99200WriteReg(AFCR0,0x0003);
                        
    // ### Set Audio Start
    dAudioTemp=W99200ReadReg (AFCR1);
    dAudioTemp=dAudioTemp | 0x10;
    W99200WriteReg(AFCR1,dAudioTemp);// write "1" into A_START bit4  

     //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
                       dAudioTemp=W99200ReadReg (AFCR1);
                           dAudioTemp=dAudioTemp | 0x0008;
                       W99200WriteReg(AFCR1,dAudioTemp);// write "1" into A_START bit4  
                        
                  }
            }
            //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);
                        
                  }
            }

             dAudioTemp=W99200ReadReg(AFISR);
             if((dAudioTemp=dAudioTemp & 0x01) == 0x01) // Audio Ready
             {
                 W99200WriteReg( AFIRR, 0x01);
                 countIndex++;
                 W99200Outpdw( _IOBase, 0x67 );
                 for( i=0 ; i < 127  ; i++) // 508 bytes => 127 times: 127*4=508 bytes
                 {
                      _dSDRAM_Data[i] = W99200Inpdw( _IOBase+4 );     //_ulODPR );
                 }
                 fwrite( _dSDRAM_Data, sizeof(int), 127, fp2 );              
              }
            
        }while((key!='s')&&(key!='S') && (W99200FIFO_End()!=TRUE) && ((dAudioTemp=W99200ReadReg(AFISR) & 0x0020)!= 0x0020));
   }
   else
   {
        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);
                        
                  }
            }

             dAudioTemp=W99200ReadReg(AFISR);
             if((dAudioTemp=dAudioTemp & 0x01) == 0x01) // Audio Ready
             {
                 W99200WriteReg( AFIRR, 0x01);
                 countIndex++;
                 W99200Outpdw( _IOBase, 0x67 );
                 for( i=0 ; i < 127  ; i++) // 508 bytes => 127 times: 127*4=508 bytes
                 {
                      _dSDRAM_Data[i] = W99200Inpdw( _IOBase+4 );     //_ulODPR );
                 }
                 fwrite( _dSDRAM_Data, sizeof(int), 127, fp2 );              
              }
            
           end_time=clock(); 
           if((int)(end_time-start_time) > dwLimit*1000 ) // "s" key is pressed
           {
                W99200WriteReg(Vstop,0xff);//9. Stop command       
                dAudioTemp=W99200ReadReg (AFCR1);
                dAudioTemp=dAudioTemp | 0x0008;
                W99200WriteReg(AFCR1,dAudioTemp);// write "1" into A_START bit4  
            }                
        }while(((int)(end_time-start_time) <=dwLimit*1000) && (W99200FIFO_End()!=TRUE) && ((dAudioTemp=W99200ReadReg(AFISR) & 0x0020)!= 0x0020));
     
   }   
    //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 );
    }

    dAudioTemp=W99200ReadReg(AFISR);
    if ( dAudioTemp & 0x04 == 0x04 )
    {
        dAudioTemp=W99200ReadReg(ALDR0) & 0x00ff;  
        LostData=dAudioTemp;
        dAudioTemp=W99200ReadReg(ALDR1) & 0x00ff;
        dAudioTemp<<=8;
        LostData=LostData + dAudioTemp;
        printf(" \n Lost Data: %ldK ~ %ldK bytes\n ",LostData, LostData+1);
    }

    printf("\n Video OutPutFile : %s\n",szVideoFileName);   
    fclose(fp1);
    printf("\n Audio OutPutFile : %s\n",szVideoFileName);   
    fclose(fp2);
    return TRUE;
}  

⌨️ 快捷键说明

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