[FFmpeg-devel] patch for libdc1394.c

Vitor Sessak vitor1001
Sun Jan 6 00:20:20 CET 2008


Hi,

Alessandro Sappia wrote:
> Hi all,
> I'm writing some software using the development version of libdc1394.
> To learn how the new library works I used to patch ffmpeg libdc1394
> in order to use the new version of the library.
> 
> I send this patch now that libdc1394 version 2.0.0 is out.

[...]

Just some nitpicking...

> Index: libavdevice/libdc1394.c
> ===================================================================
> --- libavdevice/libdc1394.c	(revisione 11423)
> +++ libavdevice/libdc1394.c	(copia locale)
> @@ -1,6 +1,7 @@
>  /*
>   * IIDC1394 grab interface (uses libdc1394 and libraw1394)
>   * Copyright (c) 2004 Roman Shaposhnik
> + * Copyright (c) 2008 Alessandro Sappia
>   *
>   * This file is part of FFmpeg.
>   *
> @@ -20,18 +21,28 @@
>   */
>  
>  #include "avformat.h"
> -
> +#include "config.h"
> +#ifdef ENABLE_LIBDC1394_1
>  #include <libraw1394/raw1394.h>
>  #include <libdc1394/dc1394_control.h>
> +#else
> +#include <sched.h>
> +#include <dc1394/dc1394.h>
> +#endif
>  
>  #undef free
>  
>  typedef struct dc1394_data {
> +#ifdef ENABLE_LIBDC1394_1
>      raw1394handle_t handle;
>      dc1394_cameracapture camera;
> +#else
> +    dc1394_t *d;
> +    dc1394camera_t *camera;
> +    dc1394video_frame_t * frame;
> +#endif
>      int current_frame;
>      int fps;
> -

The empty line removal is cosmetical

>      AVPacket packet;
>  } dc1394_data;
>  
> @@ -41,41 +52,69 @@
>      enum PixelFormat pix_fmt;
>      int frame_size_id;
>  } dc1394_frame_formats[] = {
> +#ifdef ENABLE_LIBDC1394_1
>      { 320, 240, PIX_FMT_UYVY422, MODE_320x240_YUV422 },
>      { 640, 480, PIX_FMT_UYYVYY411, MODE_640x480_YUV411 },
>      { 640, 480, PIX_FMT_UYVY422, MODE_640x480_YUV422 },
> -    {   0,   0, 0, MODE_320x240_YUV422 } /* default -- gotta be the last one */
> +    { 320, 240, PIX_FMT_UYVY422, MODE_320x240_YUV422 } /* default -- gotta be the last one */

Unrelated to adapting to the new version of the library (one thing per
patch, please)

> +#else
> +    { 320, 240, PIX_FMT_UYVY422, DC1394_VIDEO_MODE_320x240_YUV422 },
> +    { 640, 480, PIX_FMT_UYYVYY411, DC1394_VIDEO_MODE_640x480_YUV411 },
> +    { 640, 480, PIX_FMT_UYVY422, DC1394_VIDEO_MODE_640x480_YUV422 },
> +    { 320, 240, PIX_FMT_UYVY422, DC1394_VIDEO_MODE_320x240_YUV422 } /* default -- gotta be the last one */
> +#endif
>  };
>  
>  struct dc1394_frame_rate {
>      int frame_rate;
>      int frame_rate_id;
>  } dc1394_frame_rates[] = {
> +#ifdef ENABLE_LIBDC1394_1
>      {  1875, FRAMERATE_1_875 },
>      {  3750, FRAMERATE_3_75  },
>      {  7500, FRAMERATE_7_5   },
>      { 15000, FRAMERATE_15    },
>      { 30000, FRAMERATE_30    },
>      { 60000, FRAMERATE_60    },
> -    {     0, FRAMERATE_30    } /* default -- gotta be the last one */
> +    { 30000, FRAMERATE_30    } /* default -- gotta be the last one */

Same thing

> +#else
> +    {  1875, DC1394_FRAMERATE_1_875 },
> +    {  3750, DC1394_FRAMERATE_3_75  },
> +    {  7500, DC1394_FRAMERATE_7_5   },
> +    { 15000, DC1394_FRAMERATE_15    },
> +    { 30000, DC1394_FRAMERATE_30    },
> +    { 60000, DC1394_FRAMERATE_60    },
> +    {120000, DC1394_FRAMERATE_120,  },
> +    {240000, DC1394_FRAMERATE_240   },
> +    { 30000, DC1394_FRAMERATE_30    } /* default -- gotta be the last one */
> +#endif
>  };
>  
>  static int dc1394_read_header(AVFormatContext *c, AVFormatParameters * ap)
>  {
>      dc1394_data* dc1394 = c->priv_data;
>      AVStream* vst;
> +#ifdef ENABLE_LIBDC1394_1
>      nodeid_t* camera_nodes;
> -    int res;
> -    struct dc1394_frame_format *fmt;
> -    struct dc1394_frame_rate *fps;
> +#else
> +    dc1394camera_list_t *list;
> +    int width,height;
> +#endif
> +    int res, i;
> +    struct dc1394_frame_format *fmt = dc1394_frame_formats;
> +    struct dc1394_frame_rate *fps = dc1394_frame_rates;
>  
> -    for (fmt = dc1394_frame_formats; fmt->width; fmt++)
> -         if (fmt->pix_fmt == ap->pix_fmt && fmt->width == ap->width && fmt->height == ap->height)
> +    for (i = 1 ; i < sizeof(dc1394_frame_formats)/sizeof(struct dc1394_frame_format); i++,fmt++) {
> +         if (fmt->pix_fmt == ap->pix_fmt && fmt->width == ap->width && fmt->height == ap->height){
>               break;
> +         }
> +    }

The brackets addition is cosmetical

>  
> -    for (fps = dc1394_frame_rates; fps->frame_rate; fps++)
> -         if (fps->frame_rate == av_rescale(1000, ap->time_base.den, ap->time_base.num))
> +    for (i = 1 ; i < sizeof(dc1394_frame_rates)/sizeof(struct dc1394_frame_rate); i++,fps++) {
> +         if (fps->frame_rate == av_rescale(1000, ap->time_base.den, ap->time_base.num)) {
>               break;
> +         }
> +    }

Same thing

>      dc1394_destroy_handle(dc1394->handle);
> +    av_free(dc1394->camera);
> +#else
> +    dc1394_camera_free (dc1394->camera);
> +#endif
>  out:
> +#ifndef ENABLE_LIBDC1394_1
> +    dc1394_free(dc1394->d);
> +#endif
>      return -1;
>  }
>  
> @@ -147,25 +259,34 @@
>  {
>      struct dc1394_data *dc1394 = c->priv_data;
>      int res;
> -

Cosmetical

>      /* discard stale frame */
>      if (dc1394->current_frame++) {
> +#ifdef ENABLE_LIBDC1394_1
>          if (dc1394_dma_done_with_buffer(&dc1394->camera) != DC1394_SUCCESS)
> +#else
> +        if (dc1394_capture_enqueue(dc1394->camera, dc1394->frame) != DC1394_SUCCESS)
> +#endif
>              av_log(c, AV_LOG_ERROR, "failed to release %d frame\n", dc1394->current_frame);
>      }
> -
> +#ifdef ENABLE_LIBDC1394_1
>      res = dc1394_dma_single_capture(&dc1394->camera);
> -
> +#else
> +    res = dc1394_capture_dequeue(dc1394->camera, DC1394_CAPTURE_POLICY_WAIT, &dc1394->frame);
> +#endif
>      if (res == DC1394_SUCCESS) {
> +#ifdef ENABLE_LIBDC1394_1
>          dc1394->packet.data = (uint8_t *)(dc1394->camera.capture_buffer);
> -        dc1394->packet.pts = (dc1394->current_frame * 1000000) / dc1394->fps;
> -        res = dc1394->packet.size;
> +#else
> +        dc1394->packet.data = (uint8_t *)(dc1394->frame->image);
> +#endif
> +        dc1394->packet.pts = (dc1394->current_frame  * 1000000) / (dc1394->fps);

The parenthesis is useless and adding it is cosmetical

> +        res = dc1394->packet.size = dc1394->frame->image_bytes;
>      } else {
>          av_log(c, AV_LOG_ERROR, "DMA capture failed\n");
>          dc1394->packet.data = NULL;
> +        dc1394->packet.size = 0;
>          res = -1;
>      }
> -

Cosmetical. I suggest to open the patch in a text editor to see if it is 
as simple as possible before sending...

-Vitor






More information about the ffmpeg-devel mailing list