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

📄 videoapi.cpp

📁 Vxworks 下的视频采集程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    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);//

     W99200WriteReg(Vin_picture,0x00);  
     //5. Vstart command 
     W99200WriteReg(Vstart, 0xff);//  any data 
     //6. Wait to end of data
     do
     {
        dEnd=W99200ReadReg (Vint_source);
     } while(/*!kbhit() && */((dEnd & 0x0001)!= 0x0001));
    return TRUE;
}  

//**************************************************************************
//    Function    :UTL_SFE
//    Description :Single frame encoding
//    Return      :int
//************************************************************************** 
int UTL_SFE(int Size_H, int Size_V,int iCompress)
{   
     int i;
     FILE *fp1;
     int dSize_H=0x00;
     int dSize_V=0x00; 

     dSize_H=Size_H >>4;
     dSize_V=Size_V >>4;   
      
     fp1=fopen(_SFE_OutFileName,"w+b");
     if ( fp1==NULL)
     {
       printf(" \n encoding file open error !!! ");
       return FALSE;
     }
     //1. Video Reset     
     W99200WriteReg(Video_reset, 0xFF);//any data
    
     //2. Configuration 
     if ( iCompress==1)
        W99200WriteReg(Vwork_mode, 0x03); // MPEG
     else
        W99200WriteReg(Vwork_mode, 0x13); // JPEG    
     W99200WriteReg(Vint_enable, 0x03);
     W99200WriteReg(Vthreshold, 0x0f);// 60=15*4 int
   
     W99200WriteReg(Vsize_h,dSize_H);  //704:2c  352:16
     W99200WriteReg(Vsize_v,dSize_V);  //480:1e  240:0f   
     W99200WriteReg(Vquality,_Quality);    // 01(High) ~ 1F (Low) 
     if ( _VideoStard==0 ) //NTSC
      W99200WriteReg(Video_format,0x00);// 8:PAL, 0: NTSC, 4:SQUARE
     if ( _VideoStard==1 ) //SQUARE
      W99200WriteReg(Video_format,0x04);// 8:PAL, 0: NTSC, 4:SQUARE
     if ( _VideoStard==2 ) //PAL
      W99200WriteReg(Video_format,0x08);// 8:PAL, 0: NTSC, 4:SQUARE     
         //3. Start Command
          
     W99200WriteReg(Vstart, 0xff);//  any data   
     
     //4. Reverse data transfer according to data format
     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 
    
   //5. Stop command
     W99200WriteReg(Vstop,0xff); // any data  
     
     printf("\n OutPutFile : %s (Single Frame Encoding)",_SFE_OutFileName);   
     fclose(fp1);         
     return TRUE;
        
}  

//**************************************************************************
//    Function    :UTL_WFR
//    Description :Write a frame
//    Return      :int
//************************************************************************** 
int UTL_WFR(int Size_H, int Size_V)
{    
     int dSize_H=0x00;
     int dSize_V=0x00; 
     int *dtemp;
     FILE *fp1;
     
     dSize_H=Size_H >>4; // One Unit is 16 Pixel
     dSize_V=Size_V >>4; // One Unit is 16 Pixel
      
     fp1=fopen(_SFE_InFileName,"r+b");
     if ( fp1==NULL)
     {
       printf(" \n File( %s ) open error (Write a Frame) !!!",_SFE_InFileName);
       return FALSE;
     }
     
   //1. Video Reset
     W99200WriteReg(Video_reset, 0xff);//any data
   //2. Configuration
     W99200WriteReg(Vwork_mode, 0x0004);
     W99200WriteReg(Vsize_h, dSize_H);
     W99200WriteReg(Vsize_v, dSize_V);
   //3. Start Command 
     W99200WriteReg(Vstart, 0xff);// any data
     
   //4. Forward data transfer according to data format 
     while ( fread(dtemp,sizeof(int),1,fp1) >= 1 )
     {
        W99200WriteReg(Vdata_in, *dtemp);  
     }

   //5. Stop command
     W99200WriteReg(Vstop,0xff); // any data  
     fclose(fp1);
          return TRUE;
}  

//**************************************************************************
//    Function    :UTL_RFR
//    Description :Read a frame
//    Return      :int
//************************************************************************** 
int UTL_RFR(int Size_H, int Size_V)
{
         FILE *fp1; 
         int i;
     int dSize_H=0x00;
     int dSize_V=0x00; 

     dSize_H=Size_H >>4;
     dSize_V=Size_V >>4;   
      
     fp1=fopen(_SFE_OutFileName,"w+b"); 
        //1. Soft Reset   
          
     W99200WriteReg(Video_reset, 0xFF);//any data
    
   // 2. Configuration
     W99200WriteReg(Vint_enable, 0x03);
     W99200WriteReg(Vthreshold, 0x0f);// 60=15*4 int
     W99200WriteReg(Vsize_h,dSize_H);  //704:2c  352:16
     W99200WriteReg(Vsize_v,dSize_V);  //480:1e  240:0f 
     W99200WriteReg(Vwork_mode, 0x0005);   
  // 3. Start   
     W99200WriteReg(Vstart, 0xff);//  any data
   //4. Reverse data transfer according to data format
     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 
    fclose(fp1);  
    return TRUE;        
} 

int UTL_RSDRam(int dwPage)
{
         FILE *fp1; 
         int i;
         
         int start, count, j;
         
         char FileName[13];
         sprintf(FileName, "sdram%03x.hex", dwPage);
      
     fp1=fopen(FileName,"w+b"); 
        //1. Soft Reset   
          
    if (dwPage==0x100)
    {
        start=0x00;
        count=0x100;
    }        
    else
    {
        start=dwPage;
        count=1;
    }        
    printf("start=%x, count=%x, dwPage=%x\n", start, count, dwPage);            
    for (j=start;j<(start+count);j++)
    {
         printf("Reading page %x\n", j);
//         getch();
         W99200WriteReg(Video_reset, 0xFF);//any data
        
       // 2. Configuration
         W99200WriteReg(Vint_enable, 0x03);
         W99200WriteReg(Vthreshold, 0x0f);// 60=15*4 int
         W99200WriteReg(Vmem_select, j);   
         W99200WriteReg(Vwork_mode, 0x0007);   
      // 3. Start   
         W99200WriteReg(Vstart, 0xff);//  any data
       //4. Reverse data transfer according to data format
         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 
    }        
    fclose(fp1);  
    return TRUE;        
} 

#define PAGE_SIZE 8192

int UTL_WSDRam(int dwPage, char *szFilename)
{    
     int i;
     
      
/*     fp1=fopen(szFilename,"r+b");
     if ( fp1==NULL)
     {
       printf(" \n File( %s ) open error (Write a Frame) !!!",szFilename);
       return FALSE;
     }
  */   
   //1. Video Reset
     W99200WriteReg(Video_reset, 0xff);//any data
   //2. Configuration
     W99200WriteReg(Vwork_mode, 0x0006);
     W99200WriteReg(Vmem_select, dwPage);
   //3. Start Command 
     W99200WriteReg(Vstart, 0xff);// any data
     
   //4. Forward data transfer according to data format 
//     while ( fread(dtemp,sizeof(int),1,fp1) >= 1 )
    for(i=0;i<PAGE_SIZE;i++)
     {
        W99200WriteReg(Vdata_in, 0);  
     }

   //5. Stop command
     W99200WriteReg(Vstop,0xff); // any data  
//     fclose(fp1);
          return TRUE;
}  

int UTL_ClearSDRam(void)
{    
     int i, j;
     
      
/*     fp1=fopen(szFilename,"r+b");
     if ( fp1==NULL)
     {
       printf(" \n File( %s ) open error (Write a Frame) !!!",szFilename);
       return FALSE;
     }
  */   
   //1. Video Reset
    for (j=0;j<=0xff;j++)
    {
         W99200WriteReg(Video_reset, 0xff);//any data
       //2. Configuration
         W99200WriteReg(Vwork_mode, 0x0006);
         W99200WriteReg(Vmem_select, j);
       //3. Start Command 
         W99200WriteReg(Vstart, 0xff);// any data
         
       //4. Forward data transfer according to data format 
    //     while ( fread(dtemp,sizeof(int),1,fp1) >= 1 )
        for(i=0;i<PAGE_SIZE;i++)
         {
            W99200WriteReg(Vdata_in, 0);  
         }

   //5. Stop command
        W99200WriteReg(Vstop,0xff); // any data  
    }
//     fclose(fp1);
          return TRUE;
}  


int UTL_RSDRaml(void)
{
         int i;
         
         int start, count, j;
         
        //1. Soft Reset   
          
    start=0x00;
    count=0x100;
    printf("start=%x, count=%x\n", start, count);            
    while(/*!kbhit()*/1)
    {    
        for (j=start;j<(start+count);j++)
        {
             printf("Reading page %x\n", j);
    //         getch();
             W99200WriteReg(Video_reset, 0xFF);//any data
            
           // 2. Configuration
             W99200WriteReg(Vint_enable, 0x03);
             W99200WriteReg(Vthreshold, 0x0f);// 60=15*4 int
             W99200WriteReg(Vmem_select, j);   
             W99200WriteReg(Vwork_mode, 0x0007);   
          // 3. Start   
             W99200WriteReg(Vstart, 0xff);//  any data
           //4. Reverse data transfer according to data format
             do 
             {
              if ( W99200FIFO_Thr()== TRUE )
              {
                for( i=0 ; i < 60 ; i++)
                   _dMem_Data[i]=W99200Inpdw(_IOBase+_ulODPR);
              }
            } while ( W99200FIFO_End()!=TRUE  );// Pooling the End of Data 
        }        
    }        
    return TRUE;        
} 


//**************************************************************************
//    Function    :UTL_SET_I2CVIDEO
//    Description :Through I2C Set SAA7114
//    Return      :int
//************************************************************************** 
int UTL_SET_I2CVIDEO(void)
{
  FILE *fp;
  int dIndex,dValue;
  int dCount,i;
  dIndex=0;
  dValue=0;
  dCount=0; 
  if ( _VideoStard == 0 ) // NTSC 
  {
    if( (fp = fopen( "I2C_114N.IN", "r+" )) == NULL )
    {
        printf( "The file 'I2C_114N.IN' was not opened\n" );
        return 0;
    }        
  } 
  else
  {
    if( (fp = fopen( "I2C_114P.IN", "r+" )) == NULL )
    {
        printf( "The file 'I2C_114P.IN' was not opened\n" );
        return 0;
    }
  }
    
  fscanf(fp,"%d",&dCount); // Read the Count of Data
  for ( i=0 ; i < dCount ; i++ )
  {
    fscanf(fp,"%x %x",&dIndex, &dValue); // Read the index and value  
    //printf(" Write I2C(114), index->%x,%x\n",dIndex,dValue);
    W99200I2CWrite(dIndex,&dValue,1);
  }
  fclose(fp);
  return 1;   
           
} 

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();
}    

⌨️ 快捷键说明

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