FFmpeg  2.1.1
paf.c
Go to the documentation of this file.
1 /*
2  * Packed Animation File video and audio decoder
3  * Copyright (c) 2012 Paul B Mahol
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 #include "libavutil/intreadwrite.h"
23 #include "libavcodec/paf.h"
24 #include "bytestream.h"
25 #include "avcodec.h"
26 #include "copy_block.h"
27 #include "internal.h"
28 
29 
30 static const uint8_t block_sequences[16][8] =
31 {
32  { 0, 0, 0, 0, 0, 0, 0, 0 },
33  { 2, 0, 0, 0, 0, 0, 0, 0 },
34  { 5, 7, 0, 0, 0, 0, 0, 0 },
35  { 5, 0, 0, 0, 0, 0, 0, 0 },
36  { 6, 0, 0, 0, 0, 0, 0, 0 },
37  { 5, 7, 5, 7, 0, 0, 0, 0 },
38  { 5, 7, 5, 0, 0, 0, 0, 0 },
39  { 5, 7, 6, 0, 0, 0, 0, 0 },
40  { 5, 5, 0, 0, 0, 0, 0, 0 },
41  { 3, 0, 0, 0, 0, 0, 0, 0 },
42  { 6, 6, 0, 0, 0, 0, 0, 0 },
43  { 2, 4, 0, 0, 0, 0, 0, 0 },
44  { 2, 4, 5, 7, 0, 0, 0, 0 },
45  { 2, 4, 5, 0, 0, 0, 0, 0 },
46  { 2, 4, 6, 0, 0, 0, 0, 0 },
47  { 2, 4, 5, 7, 5, 7, 0, 0 }
48 };
49 
50 typedef struct PAFVideoDecContext {
53 
58 
61 
63 {
64  PAFVideoDecContext *c = avctx->priv_data;
65  int i;
66 
67  av_frame_free(&c->pic);
68 
69  for (i = 0; i < 4; i++)
70  av_freep(&c->frame[i]);
71 
72  return 0;
73 }
74 
76 {
77  PAFVideoDecContext *c = avctx->priv_data;
78  int i;
79 
80  if (avctx->height & 3 || avctx->width & 3) {
81  av_log(avctx, AV_LOG_ERROR, "width and height must be multiplies of 4\n");
82  return AVERROR_INVALIDDATA;
83  }
84 
85  avctx->pix_fmt = AV_PIX_FMT_PAL8;
86 
87  c->pic = av_frame_alloc();
88  if (!c->pic)
89  return AVERROR(ENOMEM);
90 
91  c->frame_size = FFALIGN(avctx->height, 256) * avctx->width;
92  c->video_size = avctx->height * avctx->width;
93  for (i = 0; i < 4; i++) {
94  c->frame[i] = av_mallocz(c->frame_size);
95  if (!c->frame[i]) {
96  paf_vid_close(avctx);
97  return AVERROR(ENOMEM);
98  }
99  }
100 
101  return 0;
102 }
103 
105 {
106  int x, y;
107 
108  x = b & 0x7F;
109  y = ((a & 0x3F) << 1) | (b >> 7 & 1);
110 
111  return y * 2 * avctx->width + x * 2;
112 }
113 
114 static void copy4h(AVCodecContext *avctx, uint8_t *dst)
115 {
116  PAFVideoDecContext *c = avctx->priv_data;
117  int i;
118 
119  for (i = 0; i < 4; i++) {
120  bytestream2_get_buffer(&c->gb, dst, 4);
121  dst += avctx->width;
122  }
123 }
124 
126 {
127  int i;
128 
129  for (i = 0; i < 4; i++) {
130  if ((mask >> 4) & (1 << (3 - i)))
131  dst[i] = color;
132  if ((mask & 15) & (1 << (3 - i)))
133  dst[avctx->width + i] = color;
134  }
135 }
136 
137 static void copy_src_mask(AVCodecContext *avctx, uint8_t mask, uint8_t *dst, const uint8_t *src)
138 {
139  int i;
140 
141  for (i = 0; i < 4; i++) {
142  if ((mask >> 4) & (1 << (3 - i)))
143  dst[i] = src[i];
144  if ((mask & 15) & (1 << (3 - i)))
145  dst[avctx->width + i] = src[avctx->width + i];
146  }
147 }
148 
149 static int decode_0(AVCodecContext *avctx, uint8_t code, uint8_t *pkt)
150 {
151  PAFVideoDecContext *c = avctx->priv_data;
152  uint32_t opcode_size, offset;
153  uint8_t *dst, *dend, mask = 0, color = 0, a, b, p;
154  const uint8_t *src, *send, *opcodes;
155  int i, j, x = 0;
156 
157  i = bytestream2_get_byte(&c->gb);
158  if (i) {
159  if (code & 0x10) {
160  int align;
161 
162  align = bytestream2_tell(&c->gb) & 3;
163  if (align)
164  bytestream2_skip(&c->gb, 4 - align);
165  }
166  do {
167  a = bytestream2_get_byte(&c->gb);
168  b = bytestream2_get_byte(&c->gb);
169  p = (a & 0xC0) >> 6;
170  dst = c->frame[p] + get_video_page_offset(avctx, a, b);
171  dend = c->frame[p] + c->frame_size;
172  offset = (b & 0x7F) * 2;
173  j = bytestream2_get_le16(&c->gb) + offset;
174 
175  do {
176  offset++;
177  if (dst + 3 * avctx->width + 4 > dend)
178  return AVERROR_INVALIDDATA;
179  copy4h(avctx, dst);
180  if ((offset & 0x3F) == 0)
181  dst += avctx->width * 3;
182  dst += 4;
183  } while (offset < j);
184  } while (--i);
185  }
186 
187  dst = c->frame[c->current_frame];
188  dend = c->frame[c->current_frame] + c->frame_size;
189  do {
190  a = bytestream2_get_byte(&c->gb);
191  b = bytestream2_get_byte(&c->gb);
192  p = (a & 0xC0) >> 6;
193  src = c->frame[p] + get_video_page_offset(avctx, a, b);
194  send = c->frame[p] + c->frame_size;
195  if ((src + 3 * avctx->width + 4 > send) ||
196  (dst + 3 * avctx->width + 4 > dend))
197  return AVERROR_INVALIDDATA;
198  copy_block4(dst, src, avctx->width, avctx->width, 4);
199  i++;
200  if ((i & 0x3F) == 0)
201  dst += avctx->width * 3;
202  dst += 4;
203  } while (i < c->video_size / 16);
204 
205  opcode_size = bytestream2_get_le16(&c->gb);
206  bytestream2_skip(&c->gb, 2);
207 
208  if (bytestream2_get_bytes_left(&c->gb) < opcode_size)
209  return AVERROR_INVALIDDATA;
210 
211  opcodes = pkt + bytestream2_tell(&c->gb);
212  bytestream2_skipu(&c->gb, opcode_size);
213 
214  dst = c->frame[c->current_frame];
215 
216  for (i = 0; i < avctx->height; i += 4, dst += avctx->width * 3) {
217  for (j = 0; j < avctx->width; j += 4, dst += 4) {
218  int opcode, k = 0;
219 
220  if (x > opcode_size)
221  return AVERROR_INVALIDDATA;
222  if (j & 4) {
223  opcode = opcodes[x] & 15;
224  x++;
225  } else {
226  opcode = opcodes[x] >> 4;
227  }
228 
229  while (block_sequences[opcode][k]) {
230 
231  offset = avctx->width * 2;
232  code = block_sequences[opcode][k++];
233 
234  switch (code) {
235  case 2:
236  offset = 0;
237  case 3:
238  color = bytestream2_get_byte(&c->gb);
239  case 4:
240  mask = bytestream2_get_byte(&c->gb);
241  copy_color_mask(avctx, mask, dst + offset, color);
242  break;
243  case 5:
244  offset = 0;
245  case 6:
246  a = bytestream2_get_byte(&c->gb);
247  b = bytestream2_get_byte(&c->gb);
248  p = (a & 0xC0) >> 6;
249  src = c->frame[p] + get_video_page_offset(avctx, a, b);
250  send = c->frame[p] + c->frame_size;
251  case 7:
252  if (src + offset + avctx->width + 4 > send)
253  return AVERROR_INVALIDDATA;
254  mask = bytestream2_get_byte(&c->gb);
255  copy_src_mask(avctx, mask, dst + offset, src + offset);
256  break;
257  }
258  }
259  }
260  }
261 
262  return 0;
263 }
264 
265 static int paf_vid_decode(AVCodecContext *avctx, void *data,
266  int *got_frame, AVPacket *pkt)
267 {
268  PAFVideoDecContext *c = avctx->priv_data;
269  uint8_t code, *dst, *src, *end;
270  int i, frame, ret;
271 
272  if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
273  return ret;
274 
275  bytestream2_init(&c->gb, pkt->data, pkt->size);
276 
277  code = bytestream2_get_byte(&c->gb);
278  if (code & 0x20) {
279  for (i = 0; i < 4; i++)
280  memset(c->frame[i], 0, c->frame_size);
281 
282  memset(c->pic->data[1], 0, AVPALETTE_SIZE);
283  c->current_frame = 0;
284  c->pic->key_frame = 1;
286  } else {
287  c->pic->key_frame = 0;
289  }
290 
291  if (code & 0x40) {
292  uint32_t *out = (uint32_t *)c->pic->data[1];
293  int index, count;
294 
295  index = bytestream2_get_byte(&c->gb);
296  count = bytestream2_get_byte(&c->gb) + 1;
297 
298  if (index + count > 256)
299  return AVERROR_INVALIDDATA;
300  if (bytestream2_get_bytes_left(&c->gb) < 3*count)
301  return AVERROR_INVALIDDATA;
302 
303  out += index;
304  for (i = 0; i < count; i++) {
305  unsigned r, g, b;
306 
307  r = bytestream2_get_byteu(&c->gb);
308  r = r << 2 | r >> 4;
309  g = bytestream2_get_byteu(&c->gb);
310  g = g << 2 | g >> 4;
311  b = bytestream2_get_byteu(&c->gb);
312  b = b << 2 | b >> 4;
313  *out++ = 0xFFU << 24 | r << 16 | g << 8 | b;
314  }
315  c->pic->palette_has_changed = 1;
316  }
317 
318  switch (code & 0x0F) {
319  case 0:
320  if ((ret = decode_0(avctx, code, pkt->data)) < 0)
321  return ret;
322  break;
323  case 1:
324  dst = c->frame[c->current_frame];
325  bytestream2_skip(&c->gb, 2);
327  return AVERROR_INVALIDDATA;
328  bytestream2_get_bufferu(&c->gb, dst, c->video_size);
329  break;
330  case 2:
331  frame = bytestream2_get_byte(&c->gb);
332  if (frame > 3)
333  return AVERROR_INVALIDDATA;
334  if (frame != c->current_frame)
335  memcpy(c->frame[c->current_frame], c->frame[frame], c->frame_size);
336  break;
337  case 4:
338  dst = c->frame[c->current_frame];
339  end = dst + c->video_size;
340 
341  bytestream2_skip(&c->gb, 2);
342 
343  while (dst < end) {
344  int8_t code;
345  int count;
346 
347  if (bytestream2_get_bytes_left(&c->gb) < 2)
348  return AVERROR_INVALIDDATA;
349 
350  code = bytestream2_get_byteu(&c->gb);
351  count = FFABS(code) + 1;
352 
353  if (dst + count > end)
354  return AVERROR_INVALIDDATA;
355  if (code < 0)
356  memset(dst, bytestream2_get_byteu(&c->gb), count);
357  else
358  bytestream2_get_buffer(&c->gb, dst, count);
359  dst += count;
360  }
361  break;
362  default:
363  avpriv_request_sample(avctx, "unknown/invalid code");
364  return AVERROR_INVALIDDATA;
365  }
366 
367  dst = c->pic->data[0];
368  src = c->frame[c->current_frame];
369  for (i = 0; i < avctx->height; i++) {
370  memcpy(dst, src, avctx->width);
371  dst += c->pic->linesize[0];
372  src += avctx->width;
373  }
374 
375  c->current_frame = (c->current_frame + 1) & 3;
376  if ((ret = av_frame_ref(data, c->pic)) < 0)
377  return ret;
378 
379  *got_frame = 1;
380 
381  return pkt->size;
382 }
383 
385 {
386  if (avctx->channels != 2) {
387  av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
388  return AVERROR_INVALIDDATA;
389  }
390 
392  avctx->sample_fmt = AV_SAMPLE_FMT_S16;
393 
394  return 0;
395 }
396 
397 static int paf_aud_decode(AVCodecContext *avctx, void *data,
398  int *got_frame_ptr, AVPacket *pkt)
399 {
400  AVFrame *frame = data;
401  uint8_t *buf = pkt->data;
402  int16_t *output_samples;
403  const uint8_t *t;
404  int frames, ret, i, j, k;
405 
406  frames = pkt->size / PAF_SOUND_FRAME_SIZE;
407  if (frames < 1)
408  return AVERROR_INVALIDDATA;
409 
410  frame->nb_samples = PAF_SOUND_SAMPLES * frames;
411  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
412  return ret;
413 
414  output_samples = (int16_t *)frame->data[0];
415  for (i = 0; i < frames; i++) {
416  t = buf + 256 * sizeof(uint16_t);
417  for (j = 0; j < PAF_SOUND_SAMPLES; j++) {
418  for (k = 0; k < 2; k++) {
419  *output_samples++ = AV_RL16(buf + *t * 2);
420  t++;
421  }
422  }
423  buf += PAF_SOUND_FRAME_SIZE;
424  }
425 
426  *got_frame_ptr = 1;
427 
428  return pkt->size;
429 }
430 
432  .name = "paf_video",
433  .long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Video"),
434  .type = AVMEDIA_TYPE_VIDEO,
435  .id = AV_CODEC_ID_PAF_VIDEO,
436  .priv_data_size = sizeof(PAFVideoDecContext),
437  .init = paf_vid_init,
438  .close = paf_vid_close,
440  .capabilities = CODEC_CAP_DR1,
441 };
442 
444  .name = "paf_audio",
445  .long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Audio"),
446  .type = AVMEDIA_TYPE_AUDIO,
447  .id = AV_CODEC_ID_PAF_AUDIO,
448  .init = paf_aud_init,
449  .decode = paf_aud_decode,
450  .capabilities = CODEC_CAP_DR1,
451 };
GetByteContext gb
Definition: paf.c:52
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
static int paf_aud_decode(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *pkt)
Definition: paf.c:397
#define PAF_SOUND_FRAME_SIZE
Definition: paf.h:26
static av_cold int paf_aud_init(AVCodecContext *avctx)
Definition: paf.c:384
uint8_t * frame[4]
Definition: paf.c:55
const char * g
Definition: vf_curves.c:104
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AV_RL16(x)
Definition: intreadwrite.h:245
static av_cold int paf_vid_init(AVCodecContext *avctx)
Definition: paf.c:75
static void copy_color_mask(AVCodecContext *avctx, uint8_t mask, uint8_t *dst, uint8_t color)
Definition: paf.c:125
int size
Definition: avcodec.h:1064
const char * b
Definition: vf_curves.c:105
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1342
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:131
#define AV_CH_LAYOUT_STEREO
AVCodec.
Definition: avcodec.h:2922
#define av_cold
Definition: avcodec.h:653
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:271
Predicted.
Definition: avcodec.h:2305
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:234
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1881
uint8_t
static int get_video_page_offset(AVCodecContext *avctx, uint8_t a, uint8_t b)
Definition: paf.c:104
int frame_size
Definition: paf.c:56
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:83
static const uint8_t offset[511][2]
Definition: vf_uspp.c:58
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
const char * name
Name of the codec implementation.
Definition: avcodec.h:2929
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by a given frame.
Definition: frame.c:247
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:742
const char data[16]
Definition: mxf.c:68
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
static av_cold int paf_vid_close(AVCodecContext *avctx)
Definition: paf.c:62
uint8_t * opcodes
Definition: paf.c:59
signed 16 bits
Definition: samplefmt.h:52
static AVFrame * frame
Definition: demuxing.c:51
#define U(x)
Definition: vp56_arith.h:37
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
static const uint16_t mask[17]
Definition: lzw.c:37
static int paf_vid_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *pkt)
Definition: paf.c:265
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:162
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:110
const char * r
Definition: vf_curves.c:103
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:261
int video_size
Definition: paf.c:57
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:152
AVFrame * pic
Definition: paf.c:51
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:123
Libavcodec external API header.
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1934
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
Definition: utils.c:986
static int64_t video_size
Definition: ffmpeg.c:124
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:167
static void copy_src_mask(AVCodecContext *avctx, uint8_t mask, uint8_t *dst, const uint8_t *src)
Definition: paf.c:137
float y
AVCodec ff_paf_audio_decoder
Definition: paf.c:443
ret
Definition: avfilter.c:961
int width
picture width / height.
Definition: avcodec.h:1314
#define AVPALETTE_SIZE
Definition: avcodec.h:4499
static void copy4h(AVCodecContext *avctx, uint8_t *dst)
Definition: paf.c:114
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:186
const AVS_VideoInfo int align
Definition: avisynth_c.h:695
AVCodec ff_paf_video_decoder
Definition: paf.c:431
AVS_Value src
Definition: avisynth_c.h:523
main external API structure.
Definition: avcodec.h:1146
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:538
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:941
void * buf
Definition: avisynth_c.h:594
int index
Definition: gxfenc.c:89
uint8_t * data
Definition: avcodec.h:1063
int palette_has_changed
Tell user application that palette has changed from previous frame.
Definition: frame.h:303
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
#define PAF_SOUND_SAMPLES
Definition: paf.h:25
#define FFABS(a)
Definition: avcodec.h:920
void * priv_data
Definition: avcodec.h:1182
int current_frame
Definition: paf.c:54
static int decode_0(AVCodecContext *avctx, uint8_t code, uint8_t *pkt)
Definition: paf.c:149
static float t
Definition: muxing.c:123
common internal api header.
static double c[64]
#define FFALIGN(x, a)
Definition: avcodec.h:930
#define AVERROR_INVALIDDATA
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){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));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=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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);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_dlog(ac->avr,"%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
int channels
number of audio channels
Definition: avcodec.h:1874
static void copy_block4(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
Definition: copy_block.h:37
int key_frame
1 -&gt; keyframe, 0-&gt; not
Definition: frame.h:162
#define AVERROR(e)
void INT64 INT64 count
Definition: avisynth_c.h:594
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
static AVPacket pkt
Definition: demuxing.c:52
8 bit with PIX_FMT_RGB32 palette
Definition: avcodec.h:4545
static const uint8_t block_sequences[16][8]
Definition: paf.c:30
This structure stores compressed data.
Definition: avcodec.h:1040
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:150
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
for(j=16;j >0;--j)
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:241