コード例 #1
0
int internel_decoder::load_live_videsource(char *url,stream_context *streamcontext){
stream_context *sc = streamcontext;
AVInputFormat *format = NULL;

format = init_v4l(url);
if(format == NULL)
return - 1;


AVDictionary *options = NULL;
//av_dict_set(&options, "video_size", "640x480", 0);
//av_dict_set(&options, "pixel_format", "rgb24", 0);

if(avformat_open_input(&sc->pFormatCtx, url, format, &options)!=0){
return -1; 
}

if(avformat_find_stream_info(sc->pFormatCtx,NULL)<0){
return -1; 
}


get_first_streams(sc);
sc->totalduration = (double)(sc->pFormatCtx->duration / AV_TIME_BASE);
sc->start_time = (double)(sc->pFormatCtx->start_time / AV_TIME_BASE);
sc->is_seekable = 0;

return 0;
}
コード例 #2
0
ファイル: spcav4l.c プロジェクト: jameshilliard/WECB-BH-GPL
/****************************************************************************
*			Public
****************************************************************************/
int
init_videoIn (struct vdIn *vd, char *device, int width, int height,
	      int format, int grabmethod)
{
  int err = -1;
  int i;
  if (vd == NULL || device == NULL)
    return -1;
  printf("%s, %d\n", __FUNCTION__, __LINE__);
  if (width == 0 || height == 0)
    return -1;
  printf("%s, %d\n", __FUNCTION__, __LINE__);
  if(grabmethod < 0 || grabmethod > 1)
  	grabmethod = 1; //read by default;
	// check format 
  vd->videodevice = NULL;
  vd->cameraname = NULL;
  vd->videodevice = NULL;
  vd->videodevice = (char *) realloc (vd->videodevice, 16);
  vd->cameraname = (char *) realloc (vd->cameraname, 32);
  printf("%s, %d\n", __FUNCTION__, __LINE__);
  snprintf (vd->videodevice, 12, "%s", device);
  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; 
  vd->bppIn = GetDepth (vd->formatIn);
  vd->grabMethod = grabmethod;		//mmap or read 
  vd->pFramebuffer = NULL;
  printf("%s, %d\n", __FUNCTION__, __LINE__);
  /* init and check all setting */
  err = init_v4l (vd);
  /* allocate the 4 frames output buffer */
  for (i = 0; i < OUTFRMNUMB; i++)
    {
      vd->ptframe[i] = NULL;
      vd->ptframe[i] =
	(unsigned char *) realloc (vd->ptframe[i], sizeof(struct frame_t) + (size_t) vd->framesizeIn );
      vd->framelock[i] = 0;
    }
  vd->frame_cour = 0;
  
  printf("%s, %d\n", __FUNCTION__, __LINE__);
   pthread_mutex_init (&vd->grabmutex, NULL);
  return err;
}
コード例 #3
0
ファイル: v4l2lut8.c プロジェクト: MarkusVolk/martii-tdt
int main (int argc,char *argv[])
{
  int videofd1 = open("/dev/video0",O_RDWR);
  int videofd2 = open("/dev/video0",O_RDWR);
  IDirectFBSurface     *SurfaceHandle;
  IDirectFBSurface     *SurfaceHandle2;
  void *ptr,*ptr2;
  int pitch,pitch2;
  int colour_palette[256];
  int colour_palette2_real[256]; /* random... */
  int *colour_palette2 = colour_palette2_real;
  int is_lut8;

  is_lut8 = (argc > 1 && !strcmp (argv[1], "both"));

  memset(&colour_palette,0x0,4*256);
  //memset(&colour_palette[1],0xff,255*4);

  colour_palette[0] = 0xff000000; // black
  colour_palette[1] = 0xffff0000; // red
  colour_palette[2] = 0xff00ff00; // green
  colour_palette[3] = 0xff0000ff; // blue
  colour_palette[4] = 0xffffffff; // white
  colour_palette[5] = 0x80808000; // half-transp yellow
  colour_palette[6] = 0x00000000; // transp black

  if (videofd1 < 0)
    perror("Couldn't open video device 1\n");

  if (videofd2 < 0)
    perror("Couldn't open video device 2\n");
  
  v4l2_list_outputs (videofd1);

  fb_make_transparent();

  init_dfb(&SurfaceHandle,is_lut8);
  init_dfb(&SurfaceHandle2,1);

  v4l2_set_output_by_name (videofd1, "RGB1");
  v4l2_set_output_by_name (videofd2, "RGB2");
  init_v4l(videofd1,0,0,1280,720,is_lut8);
  init_v4l(videofd2,0,0,1280,720,1);

  printf("%s:%d\n",__FUNCTION__,__LINE__);


//  memcpy (colour_palette, colour_palette2, sizeof (colour_palette));
  colour_palette2 = colour_palette;

  {
    int coords = 60;
    int size   = 100;

    // clear
    if (!is_lut8) SurfaceHandle->Clear (SurfaceHandle, 0x00, 0x00, 0x00, 0x00);
    else {
      SurfaceHandle->SetColorIndex (SurfaceHandle, 0x6);
      SurfaceHandle->FillRectangle (SurfaceHandle, 0, 0, 600, 600);
    }
    // White
    if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x4);
    else SurfaceHandle->SetColor (SurfaceHandle, 0xff, 0xff, 0xff, 0xff);
    SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size);
    coords += size;
    // Red
    if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x1);
    else SurfaceHandle->SetColor (SurfaceHandle, 0xff, 0x00, 0x00, 0xff);
    SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size);
    coords += size;
    // Green
    if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x2);
    else SurfaceHandle->SetColor (SurfaceHandle, 0x00, 0xff, 0x00, 0xff);
    SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size);
    coords += size;
    // Blue
    if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x3);
    else SurfaceHandle->SetColor (SurfaceHandle, 0x00, 0x00, 0xff, 0xff);
    SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size);
    coords += size;
    // half transp yellow
    if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x5);
    else SurfaceHandle->SetColor (SurfaceHandle, 0x80, 0x80, 0x00, 0x80);
    SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size);
    coords += size;
    // transp
    if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x6);
    else SurfaceHandle->SetColor (SurfaceHandle, 0x00, 0x00, 0x00, 0x00);
    SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size);
    coords += size;
  }

  {
    int xcoords = 60 + (100 * 6), ycoords = 60;
    int size   = 100;

    // clear
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x6);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, 220, 220, 440, 440);
    // transp
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x6);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size);
    xcoords -= size; ycoords += size;
    // half transp yellow
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x5);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size);
    xcoords -= size; ycoords += size;
    // Blue
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x3);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size);
    xcoords -= size; ycoords += size;
    // Green
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x2);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size);
    xcoords -= size; ycoords += size;
    // Red
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x1);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size);
    xcoords -= size; ycoords += size;
    // White
    SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x4);
    SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size);
    xcoords -= size; ycoords += size;
  }
    
  DFBCHECK (SurfaceHandle->Lock (SurfaceHandle, DSLF_READ, &ptr, &pitch));
  DFBCHECK (SurfaceHandle2->Lock (SurfaceHandle2, DSLF_READ, &ptr2, &pitch2));

  printf("%s:%d\n",__FUNCTION__,__LINE__);

  zorder(videofd2,V4L2_CID_STM_Z_ORDER_RGB2,1);
  zorder(videofd1,V4L2_CID_STM_Z_ORDER_RGB1,2);

  queue_buffer( videofd1, ptr, (is_lut8 ? colour_palette : 0), 0ULL);

  stream_on( videofd1 );

  getchar();
  queue_buffer( videofd2, ptr2, colour_palette2, 0ULL); 

  printf("%s:%d\n",__FUNCTION__,__LINE__);

  stream_on( videofd2 );

  printf("%s:%d\n",__FUNCTION__,__LINE__);


  getchar();

  zorder(videofd2,V4L2_CID_STM_Z_ORDER_RGB2,2);
  zorder(videofd1,V4L2_CID_STM_Z_ORDER_RGB1,1);

  fprintf(stderr,"Press Return/Enter to quit\n");
  getchar();

  // This seems to dequeue all buffers too, but that's what the spec says
  // so this is ok.
  stream_off( videofd1 );
  stream_off( videofd2 );

  deinit_dfb();
  close(videofd1);  

  return 0;
}
コード例 #4
0
ファイル: rtv.c プロジェクト: myler/unix
int
init_videoIn (struct vdIn *vd, char *device, int width, int height,
              int format, int grabmethod, int channel)
{
    int err = 0;
    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;
    // check format
    vd->videodevice = NULL;
    vd->cameraname = NULL;
    vd->videodevice = NULL;
    vd->videodevice = (char *) realloc (vd->videodevice, 16); // pghpgh
    vd->cameraname = (char *) realloc (vd->cameraname, 32);
    
    snprintf (vd->videodevice, 12, "%s", device);
//    logger(TLOG_NOTICE, "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;
    vd->bppIn = GetDepth (vd->formatIn);
    vd->grabMethod = grabmethod;		//mmap or read
    vd->pFramebuffer = NULL;
    /* init and check all setting */
    if (init_v4l (vd, channel) == -1)
    {
        logger(TLOG_ERROR, "v4l init failed");
        return -1;
    }

    /* allocate the 4 frames output buffer */
    for (i = 0; i < OUTFRMNUMB; i++)
    {
        vd->ptframe[i] = NULL;
        vd->ptframe[i] =
            (unsigned char *) realloc (vd->ptframe[i], sizeof(struct frame_t) + (size_t) vd->framesizeIn );
        vd->framelock[i] = 0;
    }

//	printf("ddddddddddddddd%d\n", (size_t)vd->framesizeIn);
	
	vd->bmpBuffer[0] = (char *)realloc(vd->bmpBuffer[0], BMP_BUFF_SIZE);
	vd->bmpBuffer[1] = (char *)realloc(vd->bmpBuffer[1], BMP_BUFF_SIZE);

    
	
	vd->bmpIndex = 0;
	
    vd->frame_cour = 0;
    for (i = 0; i < OUTFRMNUMB; i++)
    {
        thread_syn_flag_set(&frame_syn_ctrl[channel][i].mutex_w,
                            &frame_syn_ctrl[channel][i].cond_w,
                            &frame_syn_ctrl[channel][i].flag_w);
        thread_syn_flag_clr(&frame_syn_ctrl[channel][i].mutex_r,
                            &frame_syn_ctrl[channel][i].cond_r,
                            &frame_syn_ctrl[channel][i].flag_r);
    }
    pthread_mutex_init (&vd->grabmutex, NULL);
    return err;
}