r3d.c
Go to the documentation of this file.
1 /*
2  * R3D REDCODE demuxer
3  * Copyright (c) 2008 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 //#define DEBUG
23 
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/dict.h"
26 #include "libavutil/mathematics.h"
27 #include "avformat.h"
28 #include "internal.h"
29 
30 typedef struct {
32  unsigned *video_offsets;
33  unsigned rdvo_offset;
34 } R3DContext;
35 
36 typedef struct {
37  unsigned size;
38  uint32_t tag;
39  uint64_t offset;
40 } Atom;
41 
42 static int read_atom(AVFormatContext *s, Atom *atom)
43 {
44  atom->offset = avio_tell(s->pb);
45  atom->size = avio_rb32(s->pb);
46  if (atom->size < 8)
47  return -1;
48  atom->tag = avio_rl32(s->pb);
49  av_dlog(s, "atom %u %.4s offset %#"PRIx64"\n",
50  atom->size, (char*)&atom->tag, atom->offset);
51  return atom->size;
52 }
53 
55 {
57  char filename[258];
58  int tmp;
59  int av_unused tmp2;
60  AVRational framerate;
61 
62  if (!st)
63  return AVERROR(ENOMEM);
66 
67  tmp = avio_r8(s->pb); // major version
68  tmp2 = avio_r8(s->pb); // minor version
69  av_dlog(s, "version %d.%d\n", tmp, tmp2);
70 
71  tmp = avio_rb16(s->pb); // unknown
72  av_dlog(s, "unknown1 %d\n", tmp);
73 
74  tmp = avio_rb32(s->pb);
75  avpriv_set_pts_info(st, 32, 1, tmp);
76 
77  tmp = avio_rb32(s->pb); // filenum
78  av_dlog(s, "filenum %d\n", tmp);
79 
80  avio_skip(s->pb, 32); // unknown
81 
82  st->codec->width = avio_rb32(s->pb);
83  st->codec->height = avio_rb32(s->pb);
84 
85  tmp = avio_rb16(s->pb); // unknown
86  av_dlog(s, "unknown2 %d\n", tmp);
87 
88  framerate.num = avio_rb16(s->pb);
89  framerate.den = avio_rb16(s->pb);
90  if (framerate.num && framerate.den) {
91 #if FF_API_R_FRAME_RATE
92  st->r_frame_rate =
93 #endif
94  st->avg_frame_rate = framerate;
95  }
96 
97  tmp = avio_r8(s->pb); // audio channels
98  av_dlog(s, "audio channels %d\n", tmp);
99  if (tmp > 0) {
100  AVStream *ast = avformat_new_stream(s, NULL);
101  if (!ast)
102  return AVERROR(ENOMEM);
105  ast->codec->channels = tmp;
106  avpriv_set_pts_info(ast, 32, 1, st->time_base.den);
107  }
108 
109  avio_read(s->pb, filename, 257);
110  filename[sizeof(filename)-1] = 0;
111  av_dict_set(&st->metadata, "filename", filename, 0);
112 
113  av_dlog(s, "filename %s\n", filename);
114  av_dlog(s, "resolution %dx%d\n", st->codec->width, st->codec->height);
115  av_dlog(s, "timescale %d\n", st->time_base.den);
116  av_dlog(s, "frame rate %d/%d\n",
117  framerate.num, framerate.den);
118 
119  return 0;
120 }
121 
122 static int r3d_read_rdvo(AVFormatContext *s, Atom *atom)
123 {
124  R3DContext *r3d = s->priv_data;
125  AVStream *st = s->streams[0];
126  int i;
127 
128  r3d->video_offsets_count = (atom->size - 8) / 4;
129  r3d->video_offsets = av_malloc(atom->size);
130  if (!r3d->video_offsets)
131  return AVERROR(ENOMEM);
132 
133  for (i = 0; i < r3d->video_offsets_count; i++) {
134  r3d->video_offsets[i] = avio_rb32(s->pb);
135  if (!r3d->video_offsets[i]) {
136  r3d->video_offsets_count = i;
137  break;
138  }
139  av_dlog(s, "video offset %d: %#x\n", i, r3d->video_offsets[i]);
140  }
141 
142  if (st->avg_frame_rate.num)
145  st->time_base);
146  av_dlog(s, "duration %"PRId64"\n", st->duration);
147 
148  return 0;
149 }
150 
152 {
153  R3DContext *r3d = s->priv_data;
154  int av_unused tmp;
155 
156  r3d->rdvo_offset = avio_rb32(s->pb);
157  avio_rb32(s->pb); // rdvs offset
158  avio_rb32(s->pb); // rdao offset
159  avio_rb32(s->pb); // rdas offset
160 
161  tmp = avio_rb32(s->pb);
162  av_dlog(s, "num video chunks %d\n", tmp);
163 
164  tmp = avio_rb32(s->pb);
165  av_dlog(s, "num audio chunks %d\n", tmp);
166 
167  avio_skip(s->pb, 6*4);
168 }
169 
171 {
172  R3DContext *r3d = s->priv_data;
173  Atom atom;
174  int ret;
175 
176  if (read_atom(s, &atom) < 0) {
177  av_log(s, AV_LOG_ERROR, "error reading atom\n");
178  return -1;
179  }
180  if (atom.tag == MKTAG('R','E','D','1')) {
181  if ((ret = r3d_read_red1(s)) < 0) {
182  av_log(s, AV_LOG_ERROR, "error parsing 'red1' atom\n");
183  return ret;
184  }
185  } else {
186  av_log(s, AV_LOG_ERROR, "could not find 'red1' atom\n");
187  return -1;
188  }
189 
190  s->data_offset = avio_tell(s->pb);
191  av_dlog(s, "data offset %#"PRIx64"\n", s->data_offset);
192  if (!s->pb->seekable)
193  return 0;
194  // find REOB/REOF/REOS to load index
195  avio_seek(s->pb, avio_size(s->pb)-48-8, SEEK_SET);
196  if (read_atom(s, &atom) < 0)
197  av_log(s, AV_LOG_ERROR, "error reading end atom\n");
198 
199  if (atom.tag != MKTAG('R','E','O','B') &&
200  atom.tag != MKTAG('R','E','O','F') &&
201  atom.tag != MKTAG('R','E','O','S'))
202  goto out;
203 
204  r3d_read_reos(s);
205 
206  if (r3d->rdvo_offset) {
207  avio_seek(s->pb, r3d->rdvo_offset, SEEK_SET);
208  if (read_atom(s, &atom) < 0)
209  av_log(s, AV_LOG_ERROR, "error reading 'rdvo' atom\n");
210  if (atom.tag == MKTAG('R','D','V','O')) {
211  if (r3d_read_rdvo(s, &atom) < 0)
212  av_log(s, AV_LOG_ERROR, "error parsing 'rdvo' atom\n");
213  }
214  }
215 
216  out:
217  avio_seek(s->pb, s->data_offset, SEEK_SET);
218  return 0;
219 }
220 
222 {
223  AVStream *st = s->streams[0];
224  int tmp;
225  int av_unused tmp2;
226  uint64_t pos = avio_tell(s->pb);
227  unsigned dts;
228  int ret;
229 
230  dts = avio_rb32(s->pb);
231 
232  tmp = avio_rb32(s->pb);
233  av_dlog(s, "frame num %d\n", tmp);
234 
235  tmp = avio_r8(s->pb); // major version
236  tmp2 = avio_r8(s->pb); // minor version
237  av_dlog(s, "version %d.%d\n", tmp, tmp2);
238 
239  tmp = avio_rb16(s->pb); // unknown
240  av_dlog(s, "unknown %d\n", tmp);
241 
242  if (tmp > 4) {
243  tmp = avio_rb16(s->pb); // unknown
244  av_dlog(s, "unknown %d\n", tmp);
245 
246  tmp = avio_rb16(s->pb); // unknown
247  av_dlog(s, "unknown %d\n", tmp);
248 
249  tmp = avio_rb32(s->pb);
250  av_dlog(s, "width %d\n", tmp);
251  tmp = avio_rb32(s->pb);
252  av_dlog(s, "height %d\n", tmp);
253 
254  tmp = avio_rb32(s->pb);
255  av_dlog(s, "metadata len %d\n", tmp);
256  }
257  tmp = atom->size - 8 - (avio_tell(s->pb) - pos);
258  if (tmp < 0)
259  return -1;
260  ret = av_get_packet(s->pb, pkt, tmp);
261  if (ret < 0) {
262  av_log(s, AV_LOG_ERROR, "error reading video packet\n");
263  return -1;
264  }
265 
266  pkt->stream_index = 0;
267  pkt->dts = dts;
268  if (st->avg_frame_rate.num)
269  pkt->duration = (uint64_t)st->time_base.den*
271  av_dlog(s, "pkt dts %"PRId64" duration %d\n", pkt->dts, pkt->duration);
272 
273  return 0;
274 }
275 
277 {
278  AVStream *st = s->streams[1];
279  int av_unused tmp, tmp2;
280  int samples, size;
281  uint64_t pos = avio_tell(s->pb);
282  unsigned dts;
283  int ret;
284 
285  dts = avio_rb32(s->pb);
286 
287  st->codec->sample_rate = avio_rb32(s->pb);
288  if (st->codec->sample_rate < 0) {
289  av_log(s, AV_LOG_ERROR, "negative sample rate\n");
290  return AVERROR_INVALIDDATA;
291  }
292 
293  samples = avio_rb32(s->pb);
294 
295  tmp = avio_rb32(s->pb);
296  av_dlog(s, "packet num %d\n", tmp);
297 
298  tmp = avio_rb16(s->pb); // unknown
299  av_dlog(s, "unknown %d\n", tmp);
300 
301  tmp = avio_r8(s->pb); // major version
302  tmp2 = avio_r8(s->pb); // minor version
303  av_dlog(s, "version %d.%d\n", tmp, tmp2);
304 
305  tmp = avio_rb32(s->pb); // unknown
306  av_dlog(s, "unknown %d\n", tmp);
307 
308  size = atom->size - 8 - (avio_tell(s->pb) - pos);
309  if (size < 0)
310  return -1;
311  ret = av_get_packet(s->pb, pkt, size);
312  if (ret < 0) {
313  av_log(s, AV_LOG_ERROR, "error reading audio packet\n");
314  return ret;
315  }
316 
317  pkt->stream_index = 1;
318  pkt->dts = dts;
319  if (st->codec->sample_rate)
320  pkt->duration = av_rescale(samples, st->time_base.den, st->codec->sample_rate);
321  av_dlog(s, "pkt dts %"PRId64" duration %d samples %d sample rate %d\n",
322  pkt->dts, pkt->duration, samples, st->codec->sample_rate);
323 
324  return 0;
325 }
326 
328 {
329  Atom atom;
330  int err = 0;
331 
332  while (!err) {
333  if (read_atom(s, &atom) < 0) {
334  err = -1;
335  break;
336  }
337  switch (atom.tag) {
338  case MKTAG('R','E','D','V'):
339  if (s->streams[0]->discard == AVDISCARD_ALL)
340  goto skip;
341  if (!(err = r3d_read_redv(s, pkt, &atom)))
342  return 0;
343  break;
344  case MKTAG('R','E','D','A'):
345  if (s->nb_streams < 2)
346  return -1;
347  if (s->streams[1]->discard == AVDISCARD_ALL)
348  goto skip;
349  if (!(err = r3d_read_reda(s, pkt, &atom)))
350  return 0;
351  break;
352  default:
353  skip:
354  avio_skip(s->pb, atom.size-8);
355  }
356  }
357  return err;
358 }
359 
360 static int r3d_probe(AVProbeData *p)
361 {
362  if (AV_RL32(p->buf + 4) == MKTAG('R','E','D','1'))
363  return AVPROBE_SCORE_MAX;
364  return 0;
365 }
366 
367 static int r3d_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags)
368 {
369  AVStream *st = s->streams[0]; // video stream
370  R3DContext *r3d = s->priv_data;
371  int frame_num;
372 
373  if (!st->avg_frame_rate.num)
374  return -1;
375 
376  frame_num = av_rescale_q(sample_time, st->time_base,
377  av_inv_q(st->avg_frame_rate));
378  av_dlog(s, "seek frame num %d timestamp %"PRId64"\n",
379  frame_num, sample_time);
380 
381  if (frame_num < r3d->video_offsets_count) {
382  if (avio_seek(s->pb, r3d->video_offsets_count, SEEK_SET) < 0)
383  return -1;
384  } else {
385  av_log(s, AV_LOG_ERROR, "could not seek to frame %d\n", frame_num);
386  return -1;
387  }
388 
389  return 0;
390 }
391 
393 {
394  R3DContext *r3d = s->priv_data;
395 
396  av_freep(&r3d->video_offsets);
397 
398  return 0;
399 }
400 
402  .name = "r3d",
403  .long_name = NULL_IF_CONFIG_SMALL("REDCODE R3D"),
404  .priv_data_size = sizeof(R3DContext),
409  .read_seek = r3d_seek,
410 };
const char * s
Definition: avisynth_c.h:668
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
uint64_t offset
Definition: r3d.c:39
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:261
uint32_t tag
Definition: r3d.c:38
unsigned video_offsets_count
Definition: r3d.c:31
static int read_atom(AVFormatContext *s, Atom *atom)
Definition: r3d.c:42
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.
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
static int r3d_close(AVFormatContext *s)
Definition: r3d.c:392
int num
numerator
Definition: rational.h:44
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:199
unsigned size
Definition: r3d.c:37
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:256
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
int64_t data_offset
offset of the first packet
Definition: avformat.h:1242
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:595
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
Format I/O context.
Definition: avformat.h:944
Public dictionary API.
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:610
static AVPacket pkt
Definition: demuxing.c:56
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
Definition: avformat.h:992
static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom)
Definition: r3d.c:276
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:478
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:130
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:579
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static void r3d_read_reos(AVFormatContext *s)
Definition: r3d.c:151
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
Definition: r3d.c:36
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:716
Definition: r3d.c:30
unsigned rdvo_offset
Definition: r3d.c:33
int size
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:469
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:336
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:117
AVInputFormat ff_r3d_demuxer
Definition: r3d.c:401
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:118
static int read_probe(AVProbeData *pd)
ret
Definition: avfilter.c:821
int width
picture width / height.
#define AV_RL32
AVDictionary * metadata
Definition: avformat.h:711
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:517
Stream structure.
Definition: avformat.h:643
NULL
Definition: eval.c:55
enum AVMediaType codec_type
enum AVCodecID codec_id
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Definition: avformat.h:977
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:62
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
static int r3d_probe(AVProbeData *p)
Definition: r3d.c:360
synthesis window for stochastic i
rational number numerator/denominator
Definition: rational.h:43
static int r3d_read_rdvo(AVFormatContext *s, Atom *atom)
Definition: r3d.c:122
This structure contains the data a format has to probe a file.
Definition: avformat.h:334
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:122
unsigned * video_offsets
Definition: r3d.c:32
static int flags
Definition: cpu.c:23
static int r3d_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags)
Definition: r3d.c:367
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:696
#define AVPROBE_SCORE_MAX
maximum score, half of that is used for file-extension-based detection
Definition: avformat.h:340
Main libavformat public API header.
static int r3d_read_header(AVFormatContext *s)
Definition: r3d.c:170
static int r3d_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: r3d.c:327
int den
denominator
Definition: rational.h:45
int channels
number of audio channels
void * priv_data
Format private data.
Definition: avformat.h:964
static int r3d_read_redv(AVFormatContext *s, AVPacket *pkt, Atom *atom)
Definition: r3d.c:221
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static int r3d_read_red1(AVFormatContext *s)
Definition: r3d.c:54
Filter the word “frame” indicates either a video frame or a group of audio samples
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;}return ac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:679
#define MKTAG(a, b, c, d)
Definition: common.h:282
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:702
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:738
This structure stores compressed data.
#define av_unused
Definition: attributes.h:114