嵌入式网络视频采集源程序servfox解析02

 接嵌入式网络视频采集源程序servfox解析01


 跟踪进入 init_videoIn()

/*******************************************************************************************************

    init_videoIn()函数在spcav4l.c中定义,这个函数主要用来初始化视频采集设备。

int   

init_videoIn (struct vdIn *vd, char *device, int width, int height,int format, int grabmethod)
{

      /*************************************************************************************

          它的几个参数是由server.c中传递进来的:

          if (init_videoIn(&videoIn, videodevice, width, height, format,grabmethod) != 0)

             其中

                videoIn;在spcav4l.h中定义的struct vdIn videoIn结构体
                 videodevice = "/dev/video0";   //前面输入的
                 int width = 352;(640)
                 int height = 288;(320)
                 int format = VIDEO_PALETTE_JPEG;
                 int grabmethod = 1;

      **************************************************************************************/
  int err = -1;
  int i;
  if (vd == NULL || device == NULL)
    return -1;
  if (width == 0 || height == 0)
    return -1;
  if(grabmethod < 0 || grabmethod > 1)
      grabmethod = 1; //read by default,设置read方式为默认方式


  /*************************************************************************************

         // check format检查格式,

    我们先来看一下 struct vdIn结构体,在spcav4l.h中定义 ,它是对 Video4Linux视频设备数据

    结构的定义。
        struct vdIn {
    int fd;      //设备
描述符, 文件描述符
    char *videodevice ; //设备,
视频捕捉接口文件
    struct video_mmap vmmap;
    struct video_capability videocap;     // 包含设备的基本信息(设备名称、支持的最大最小分辨率、信号源                                                                    信息等)
    int mmapsize;
    struct video_mbuf videombuf;
    //映射的帧信息,实际是映射到摄像头存储缓冲区的帧信息,包括帧的                                                          大小(size),最多支持的帧数(frames) 每帧相对基址的偏移(offset)
    struct video_picture videopict;   //采集图像的各种属性
    struct video_window videowin;  
    struct video_channel videochan;   
    int cameratype ;      // 是否能capture,彩色还是黑白,是否  能裁剪等等
    char *cameraname;   //设备名称
    char bridge[9];
    int sizenative; // available size in jpeg
    int sizeothers;    // others palette
    int palette; // available palette
    int norme ; // set spca506 usb video grabber
    int channel ; // set spca506 usb video grabber
//信号源个数
    int grabMethod ;
    unsigned char *pFramebuffer;  
//指向内存映射的指针
    unsigned char *ptframe[4];   //指向压缩后的帧的指针数组
    int framelock[4];
    pthread_mutex_t grabmutex;  
// 视频采集线程和传输线程的互斥信号
    int framesizeIn ;   // 视频帧的大小
    volatile int frame_cour;   // 指向压缩后的帧的指针数组下标


    int bppIn;   // 采集的视频帧的BPP

               --- --------------------------------------------------------------------------------------------

 

                我们在流媒体文件的编码过程中总是试图得到最佳的图像质量,这可以通过调整编码过程中帧的         大小或编码码率来实现。在此可通过位每像素(BPP,BitPerPixel)来确定帧的大小或编码码率,从而            得到理想的图像质量。

        位每像素(BPP)是通过调整帧的大小或编码码率得到最佳图像质量的一个重要参考指标.

        如果已确认要编码的视频图像帧的大小,但不确定采用何种编码码率可以得到最佳的编码图像质量,        可采用如公式1确定编码码率。

        公式1:编码码率=位每像素×帧率×宽度×高度

            (Bitrate=BPP×FrameRate×Width×Height )

        ----------------------------------------------------------------------------------------------------
    int  hdrwidth;   // 采集的视频帧的宽度
    int  hdrheight;   // 采集的视频帧的高度
    int  formatIn;  
//采集的视频帧的格式
    int signalquit;   
//停止视频采集的信号
    };
   

  **************************************************************************************/
  vd->videodevice = NULL;
  vd->cameraname = NULL;
  vd->videodevice = NULL;
  vd->videodevice = (char *) realloc (vd->videodevice, 16);
  vd->cameraname = (char *) realloc (vd->cameraname, 32);

   /*************************************************************************************

       realloc

  	原型:extern void *realloc(void *mem_address, unsigned int newsize);
用法:#include <stdlib.h> 有些编译器需要#include <alloc.h>
功能:改变mem_address所指内存区域的大小为newsize长度
说明:如果重新分配成功则返回指向被分配内存的指针 ,否则返回空指针NULL。
当内存不再使用时,应使用free()函数将内存块释放。
注意:这里原始内存中的数据还是保持不变的。

   **************************************************************************************/
  snprintf (vd->videodevice, 12, "%s", device);

    /*************************************************************************************

      把server.c中传递进来的device指向的videodevice = "/dev/video0"复制到 vd->videodevice中

    使 vd->videodevice就指向 "/dev/video0"

   **************************************************************************************/

 
  if(debug) printf("video %s /n",vd->videodevice); 
  memset (vd->cameraname, 0, sizeof (vd->cameraname));
  memset(vd->bridge, 0, sizeof(vd->bridge));
  vd->signalquit = 1;    //信号设置
  vd->hdrwidth = width;//传递宽高
  vd->hdrheight = height;


  /*          compute the max frame size   */
  vd->formatIn = format;     //传进来的 format = VIDEO_PALETTE_JPEG;
  vd->bppIn = GetDepth (vd->formatIn);


    /**************************************************************************************

    GetDepth()是 前面声明的函数, spcav4l.c 后面有定义

      static int
    GetDepth (int format)
    {
      int depth;
  switch (format)
    {
  
   case VIDEO_PALETTE_JPEG:
      {
    depth = 8;       
      }

      break;
    case VIDEO_PALETTE_RAW:
      {
    depth = 8;       
      }
      break;
    case VIDEO_PALETTE_YUV420P:
      {
    depth = (8 * 3) >> 1;
      }
      break;
    case VIDEO_PALETTE_RGB565:
      depth = 16;
      break;
    case VIDEO_PALETTE_RGB24:
      depth = 24;
      break;
    case VIDEO_PALETTE_RGB32:
      {
    depth = 32;
      }
      break;
    default:
      depth = -1;
      break;
    }
  return depth;
}

    
    *****************************************************************************************/

  vd->grabMethod = grabmethod;        //mmap or read
  vd->pFramebuffer = NULL;


  /* init and check all setting */
  err = init_v4l (vd);  
跟踪进入 init_v4l (vd)

    **************************************************************************************/
    
init_v4l (vd)是 前面声明的函数,后面有定义,执行videodevice = "/dev/video0"的打开,
       我们跟踪进入
init_v4l (vd)来看看,看看它里面做了哪些工作

       跟踪进入 init_v4l (vd)

     

   **************************************************************************************/

       init_videoIn()函数还没有完,请看下一篇:嵌入式网络视频采集源程序servfox解析03
    

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章