FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
libdc1394.c
Go to the documentation of this file.
1 /*
2  * IIDC1394 grab interface (uses libdc1394 and libraw1394)
3  * Copyright (c) 2004 Roman Shaposhnik
4  * Copyright (c) 2008 Alessandro Sappia
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "config.h"
24 
25 #if HAVE_LIBDC1394_2
26 #include <dc1394/dc1394.h>
27 #elif HAVE_LIBDC1394_1
28 #include <libraw1394/raw1394.h>
29 #include <libdc1394/dc1394_control.h>
30 
31 #define DC1394_VIDEO_MODE_320x240_YUV422 MODE_320x240_YUV422
32 #define DC1394_VIDEO_MODE_640x480_YUV411 MODE_640x480_YUV411
33 #define DC1394_VIDEO_MODE_640x480_YUV422 MODE_640x480_YUV422
34 #define DC1394_FRAMERATE_1_875 FRAMERATE_1_875
35 #define DC1394_FRAMERATE_3_75 FRAMERATE_3_75
36 #define DC1394_FRAMERATE_7_5 FRAMERATE_7_5
37 #define DC1394_FRAMERATE_15 FRAMERATE_15
38 #define DC1394_FRAMERATE_30 FRAMERATE_30
39 #define DC1394_FRAMERATE_60 FRAMERATE_60
40 #define DC1394_FRAMERATE_120 FRAMERATE_120
41 #define DC1394_FRAMERATE_240 FRAMERATE_240
42 #endif
43 
44 #include "libavutil/internal.h"
45 #include "libavutil/log.h"
46 #include "libavutil/mathematics.h"
47 #include "libavutil/opt.h"
48 #include "libavutil/parseutils.h"
49 #include "libavutil/pixdesc.h"
50 
51 #include "libavformat/avformat.h"
52 #include "libavformat/internal.h"
53 
54 typedef struct dc1394_data {
55  AVClass *class;
56 #if HAVE_LIBDC1394_1
57  raw1394handle_t handle;
58  dc1394_cameracapture camera;
59  int channel;
60 #elif HAVE_LIBDC1394_2
61  dc1394_t *d;
62  dc1394camera_t *camera;
63  dc1394video_frame_t *frame;
64 #endif
66  int frame_rate; /**< frames per 1000 seconds (fps * 1000) */
67  char *video_size; /**< String describing video size, set by a private option. */
68  char *pixel_format; /**< Set by a private option. */
69  char *framerate; /**< Set by a private option. */
70 
72 } dc1394_data;
73 
75  int width;
76  int height;
80  { 320, 240, AV_PIX_FMT_UYVY422, DC1394_VIDEO_MODE_320x240_YUV422 },
81  { 640, 480, AV_PIX_FMT_GRAY8, DC1394_VIDEO_MODE_640x480_MONO8 },
82  { 640, 480, AV_PIX_FMT_UYYVYY411, DC1394_VIDEO_MODE_640x480_YUV411 },
83  { 640, 480, AV_PIX_FMT_UYVY422, DC1394_VIDEO_MODE_640x480_YUV422 },
84  { 0, 0, 0, 0 } /* gotta be the last one */
85 };
86 
90 } dc1394_frame_rates[] = {
91  { 1875, DC1394_FRAMERATE_1_875 },
92  { 3750, DC1394_FRAMERATE_3_75 },
93  { 7500, DC1394_FRAMERATE_7_5 },
94  { 15000, DC1394_FRAMERATE_15 },
95  { 30000, DC1394_FRAMERATE_30 },
96  { 60000, DC1394_FRAMERATE_60 },
97  {120000, DC1394_FRAMERATE_120 },
98  {240000, DC1394_FRAMERATE_240 },
99  { 0, 0 } /* gotta be the last one */
100 };
101 
102 #define OFFSET(x) offsetof(dc1394_data, x)
103 #define DEC AV_OPT_FLAG_DECODING_PARAM
104 static const AVOption options[] = {
105 #if HAVE_LIBDC1394_1
106  { "channel", "", offsetof(dc1394_data, channel), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
107 #endif
108  { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "qvga"}, 0, 0, DEC },
109  { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "uyvy422"}, 0, 0, DEC },
110  { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC },
111  { NULL },
112 };
113 
114 static const AVClass libdc1394_class = {
115  .class_name = "libdc1394 indev",
116  .item_name = av_default_item_name,
117  .option = options,
118  .version = LIBAVUTIL_VERSION_INT,
120 };
121 
122 
124  struct dc1394_frame_format **select_fmt, struct dc1394_frame_rate **select_fps)
125 {
126  dc1394_data* dc1394 = c->priv_data;
127  AVStream* vst;
128  struct dc1394_frame_format *fmt;
129  struct dc1394_frame_rate *fps;
130  enum AVPixelFormat pix_fmt;
131  int width, height;
132  AVRational framerate;
133  int ret = 0;
134 
135  if ((pix_fmt = av_get_pix_fmt(dc1394->pixel_format)) == AV_PIX_FMT_NONE) {
136  av_log(c, AV_LOG_ERROR, "No such pixel format: %s.\n", dc1394->pixel_format);
137  ret = AVERROR(EINVAL);
138  goto out;
139  }
140 
141  if ((ret = av_parse_video_size(&width, &height, dc1394->video_size)) < 0) {
142  av_log(c, AV_LOG_ERROR, "Could not parse video size '%s'.\n", dc1394->video_size);
143  goto out;
144  }
145  if ((ret = av_parse_video_rate(&framerate, dc1394->framerate)) < 0) {
146  av_log(c, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", dc1394->framerate);
147  goto out;
148  }
149  dc1394->frame_rate = av_rescale(1000, framerate.num, framerate.den);
150 
151  for (fmt = dc1394_frame_formats; fmt->width; fmt++)
152  if (fmt->pix_fmt == pix_fmt && fmt->width == width && fmt->height == height)
153  break;
154 
155  for (fps = dc1394_frame_rates; fps->frame_rate; fps++)
156  if (fps->frame_rate == dc1394->frame_rate)
157  break;
158 
159  if (!fps->frame_rate || !fmt->width) {
160  av_log(c, AV_LOG_ERROR, "Can't find matching camera format for %s, %dx%d@%d:1000fps\n", av_get_pix_fmt_name(pix_fmt),
161  width, height, dc1394->frame_rate);
162  ret = AVERROR(EINVAL);
163  goto out;
164  }
165 
166  /* create a video stream */
167  vst = avformat_new_stream(c, NULL);
168  if (!vst) {
169  ret = AVERROR(ENOMEM);
170  goto out;
171  }
172  avpriv_set_pts_info(vst, 64, 1, 1000);
175  vst->codec->time_base.den = framerate.num;
176  vst->codec->time_base.num = framerate.den;
177  vst->codec->width = fmt->width;
178  vst->codec->height = fmt->height;
179  vst->codec->pix_fmt = fmt->pix_fmt;
180 
181  /* packet init */
182  av_init_packet(&dc1394->packet);
183  dc1394->packet.size = avpicture_get_size(fmt->pix_fmt, fmt->width, fmt->height);
184  dc1394->packet.stream_index = vst->index;
185  dc1394->packet.flags |= AV_PKT_FLAG_KEY;
186 
187  dc1394->current_frame = 0;
188 
189  vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000);
190  *select_fps = fps;
191  *select_fmt = fmt;
192 out:
193  return ret;
194 }
195 
196 #if HAVE_LIBDC1394_1
197 static int dc1394_v1_read_header(AVFormatContext *c)
198 {
199  dc1394_data* dc1394 = c->priv_data;
200  AVStream* vst;
201  nodeid_t* camera_nodes;
202  int res;
203  struct dc1394_frame_format *fmt = NULL;
204  struct dc1394_frame_rate *fps = NULL;
205 
206  if (dc1394_read_common(c, &fmt, &fps) != 0)
207  return -1;
208 
209  /* Now let us prep the hardware. */
210  dc1394->handle = dc1394_create_handle(0); /* FIXME: gotta have ap->port */
211  if (!dc1394->handle) {
212  av_log(c, AV_LOG_ERROR, "Can't acquire dc1394 handle on port %d\n", 0 /* ap->port */);
213  goto out;
214  }
215  camera_nodes = dc1394_get_camera_nodes(dc1394->handle, &res, 1);
216  if (!camera_nodes || camera_nodes[dc1394->channel] == DC1394_NO_CAMERA) {
217  av_log(c, AV_LOG_ERROR, "There's no IIDC camera on the channel %d\n", dc1394->channel);
218  goto out_handle;
219  }
220  res = dc1394_dma_setup_capture(dc1394->handle, camera_nodes[dc1394->channel],
221  0,
222  FORMAT_VGA_NONCOMPRESSED,
223  fmt->frame_size_id,
224  SPEED_400,
225  fps->frame_rate_id, 8, 1,
226  c->filename,
227  &dc1394->camera);
228  dc1394_free_camera_nodes(camera_nodes);
229  if (res != DC1394_SUCCESS) {
230  av_log(c, AV_LOG_ERROR, "Can't prepare camera for the DMA capture\n");
231  goto out_handle;
232  }
233 
234  res = dc1394_start_iso_transmission(dc1394->handle, dc1394->camera.node);
235  if (res != DC1394_SUCCESS) {
236  av_log(c, AV_LOG_ERROR, "Can't start isochronous transmission\n");
237  goto out_handle_dma;
238  }
239 
240  return 0;
241 
242 out_handle_dma:
243  dc1394_dma_unlisten(dc1394->handle, &dc1394->camera);
244  dc1394_dma_release_camera(dc1394->handle, &dc1394->camera);
245 out_handle:
246  dc1394_destroy_handle(dc1394->handle);
247 out:
248  return -1;
249 }
250 
251 static int dc1394_v1_read_packet(AVFormatContext *c, AVPacket *pkt)
252 {
253  struct dc1394_data *dc1394 = c->priv_data;
254  int res;
255 
256  /* discard stale frame */
257  if (dc1394->current_frame++) {
258  if (dc1394_dma_done_with_buffer(&dc1394->camera) != DC1394_SUCCESS)
259  av_log(c, AV_LOG_ERROR, "failed to release %d frame\n", dc1394->current_frame);
260  }
261 
262  res = dc1394_dma_single_capture(&dc1394->camera);
263 
264  if (res == DC1394_SUCCESS) {
265  dc1394->packet.data = (uint8_t *)(dc1394->camera.capture_buffer);
266  dc1394->packet.pts = (dc1394->current_frame * 1000000) / dc1394->frame_rate;
267  res = dc1394->packet.size;
268  } else {
269  av_log(c, AV_LOG_ERROR, "DMA capture failed\n");
270  dc1394->packet.data = NULL;
271  res = -1;
272  }
273 
274  *pkt = dc1394->packet;
275  return res;
276 }
277 
278 static int dc1394_v1_close(AVFormatContext * context)
279 {
280  struct dc1394_data *dc1394 = context->priv_data;
281 
282  dc1394_stop_iso_transmission(dc1394->handle, dc1394->camera.node);
283  dc1394_dma_unlisten(dc1394->handle, &dc1394->camera);
284  dc1394_dma_release_camera(dc1394->handle, &dc1394->camera);
285  dc1394_destroy_handle(dc1394->handle);
286 
287  return 0;
288 }
289 
290 #elif HAVE_LIBDC1394_2
291 static int dc1394_v2_read_header(AVFormatContext *c)
292 {
293  dc1394_data* dc1394 = c->priv_data;
294  dc1394camera_list_t *list;
295  int res, i;
296  struct dc1394_frame_format *fmt = NULL;
297  struct dc1394_frame_rate *fps = NULL;
298 
299  if (dc1394_read_common(c, &fmt, &fps) != 0)
300  return -1;
301 
302  /* Now let us prep the hardware. */
303  dc1394->d = dc1394_new();
304  dc1394_camera_enumerate (dc1394->d, &list);
305  if ( !list || list->num == 0) {
306  av_log(c, AV_LOG_ERROR, "Unable to look for an IIDC camera\n\n");
307  goto out;
308  }
309 
310  /* FIXME: To select a specific camera I need to search in list its guid */
311  dc1394->camera = dc1394_camera_new (dc1394->d, list->ids[0].guid);
312  if (list->num > 1) {
313  av_log(c, AV_LOG_INFO, "Working with the first camera found\n");
314  }
315 
316  /* Freeing list of cameras */
317  dc1394_camera_free_list (list);
318 
319  /* Select MAX Speed possible from the cam */
320  if (dc1394->camera->bmode_capable>0) {
321  dc1394_video_set_operation_mode(dc1394->camera, DC1394_OPERATION_MODE_1394B);
322  i = DC1394_ISO_SPEED_800;
323  } else {
324  i = DC1394_ISO_SPEED_400;
325  }
326 
327  for (res = DC1394_FAILURE; i >= DC1394_ISO_SPEED_MIN && res != DC1394_SUCCESS; i--) {
328  res=dc1394_video_set_iso_speed(dc1394->camera, i);
329  }
330  if (res != DC1394_SUCCESS) {
331  av_log(c, AV_LOG_ERROR, "Couldn't set ISO Speed\n");
332  goto out_camera;
333  }
334 
335  if (dc1394_video_set_mode(dc1394->camera, fmt->frame_size_id) != DC1394_SUCCESS) {
336  av_log(c, AV_LOG_ERROR, "Couldn't set video format\n");
337  goto out_camera;
338  }
339 
340  if (dc1394_video_set_framerate(dc1394->camera,fps->frame_rate_id) != DC1394_SUCCESS) {
341  av_log(c, AV_LOG_ERROR, "Couldn't set framerate %d \n",fps->frame_rate);
342  goto out_camera;
343  }
344  if (dc1394_capture_setup(dc1394->camera, 10, DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS) {
345  av_log(c, AV_LOG_ERROR, "Cannot setup camera \n");
346  goto out_camera;
347  }
348 
349  if (dc1394_video_set_transmission(dc1394->camera, DC1394_ON) !=DC1394_SUCCESS) {
350  av_log(c, AV_LOG_ERROR, "Cannot start capture\n");
351  goto out_camera;
352  }
353  return 0;
354 
355 out_camera:
356  dc1394_capture_stop(dc1394->camera);
357  dc1394_video_set_transmission(dc1394->camera, DC1394_OFF);
358  dc1394_camera_free (dc1394->camera);
359 out:
360  dc1394_free(dc1394->d);
361  return -1;
362 }
363 
364 static int dc1394_v2_read_packet(AVFormatContext *c, AVPacket *pkt)
365 {
366  struct dc1394_data *dc1394 = c->priv_data;
367  int res;
368 
369  /* discard stale frame */
370  if (dc1394->current_frame++) {
371  if (dc1394_capture_enqueue(dc1394->camera, dc1394->frame) != DC1394_SUCCESS)
372  av_log(c, AV_LOG_ERROR, "failed to release %d frame\n", dc1394->current_frame);
373  }
374 
375  res = dc1394_capture_dequeue(dc1394->camera, DC1394_CAPTURE_POLICY_WAIT, &dc1394->frame);
376  if (res == DC1394_SUCCESS) {
377  dc1394->packet.data = (uint8_t *) dc1394->frame->image;
378  dc1394->packet.pts = dc1394->current_frame * 1000000 / dc1394->frame_rate;
379  res = dc1394->frame->image_bytes;
380  } else {
381  av_log(c, AV_LOG_ERROR, "DMA capture failed\n");
382  dc1394->packet.data = NULL;
383  res = -1;
384  }
385 
386  *pkt = dc1394->packet;
387  return res;
388 }
389 
390 static int dc1394_v2_close(AVFormatContext * context)
391 {
392  struct dc1394_data *dc1394 = context->priv_data;
393 
394  dc1394_video_set_transmission(dc1394->camera, DC1394_OFF);
395  dc1394_capture_stop(dc1394->camera);
396  dc1394_camera_free(dc1394->camera);
397  dc1394_free(dc1394->d);
398 
399  return 0;
400 }
401 
402 AVInputFormat ff_libdc1394_demuxer = {
403  .name = "libdc1394",
404  .long_name = NULL_IF_CONFIG_SMALL("dc1394 v.2 A/V grab"),
405  .priv_data_size = sizeof(struct dc1394_data),
406  .read_header = dc1394_v2_read_header,
407  .read_packet = dc1394_v2_read_packet,
408  .read_close = dc1394_v2_close,
409  .flags = AVFMT_NOFILE,
410  .priv_class = &libdc1394_class,
411 };
412 
413 #endif
414 #if HAVE_LIBDC1394_1
415 AVInputFormat ff_libdc1394_demuxer = {
416  .name = "libdc1394",
417  .long_name = NULL_IF_CONFIG_SMALL("dc1394 v.1 A/V grab"),
418  .priv_data_size = sizeof(struct dc1394_data),
419  .read_header = dc1394_v1_read_header,
420  .read_packet = dc1394_v1_read_packet,
421  .read_close = dc1394_v1_close,
422  .flags = AVFMT_NOFILE,
423  .priv_class = &libdc1394_class,
424 };
425 #endif
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:83
#define NULL
Definition: coverity.c:32
static enum AVPixelFormat pix_fmt
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:169
AVOption.
Definition: opt.h:255
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:138
const char * fmt
Definition: avisynth_c.h:632
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4006
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:843
int size
Definition: avcodec.h:1163
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1444
static AVPacket pkt
struct dc1394_frame_rate dc1394_frame_rates[]
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1369
Format I/O context.
Definition: avformat.h:1272
char * framerate
Set by a private option.
Definition: libdc1394.c:69
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
uint8_t
AVOptions.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:3672
static AVFrame * frame
uint8_t * data
Definition: avcodec.h:1162
#define av_log(a,...)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1208
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1168
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:861
common internal API header
int bit_rate
the average bitrate
Definition: avcodec.h:1305
char filename[1024]
input or output filename
Definition: avformat.h:1348
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:127
#define OFFSET(x)
Definition: libdc1394.c:102
ret
Definition: avfilter.c:974
int width
picture width / height.
Definition: avcodec.h:1414
enum AVPixelFormat pix_fmt
Definition: libdc1394.c:77
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:620
Stream structure.
Definition: avformat.h:842
char * pixel_format
Set by a private option.
Definition: libdc1394.c:68
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
enum AVMediaType codec_type
Definition: avcodec.h:1249
enum AVCodecID codec_id
Definition: avcodec.h:1258
static const AVOption options[]
Definition: libdc1394.c:104
static int dc1394_read_common(AVFormatContext *c, struct dc1394_frame_format **select_fmt, struct dc1394_frame_rate **select_fps)
Definition: libdc1394.c:123
static const AVClass libdc1394_class
Definition: libdc1394.c:114
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
Describe the class of an AVClass context structure.
Definition: log.h:67
rational number numerator/denominator
Definition: rational.h:43
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:286
misc parsing utilities
Main libavformat public API header.
int frame_rate
frames per 1000 seconds (fps * 1000)
Definition: libdc1394.c:66
Y , 8bpp.
Definition: pixfmt.h:71
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:465
char * video_size
String describing video size, set by a private option.
Definition: libdc1394.c:67
static double c[64]
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:49
int den
denominator
Definition: rational.h:45
struct dc1394_frame_format dc1394_frame_formats[]
void * priv_data
Format private data.
Definition: avformat.h:1300
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
Calculate the size in bytes that a picture of the given width and height would occupy if stored in th...
Definition: avpicture.c:49
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
#define DEC
Definition: libdc1394.c:103
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:628
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2023
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2011
int stream_index
Definition: avcodec.h:1164
AVPacket packet
Definition: libdc1394.c:71
packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
Definition: pixfmt.h:84
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
This structure stores compressed data.
Definition: avcodec.h:1139
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1155
int current_frame
Definition: libdc1394.c:65
static int width