libavcodec/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 
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 
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 
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  .type = AVMEDIA_TYPE_VIDEO,
434  .id = AV_CODEC_ID_PAF_VIDEO,
435  .priv_data_size = sizeof(PAFVideoDecContext),
436  .init = paf_vid_init,
437  .close = paf_vid_close,
439  .capabilities = CODEC_CAP_DR1,
440  .long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Video"),
441 };
442 
444  .name = "paf_audio",
445  .type = AVMEDIA_TYPE_AUDIO,
446  .id = AV_CODEC_ID_PAF_AUDIO,
447  .init = paf_aud_init,
448  .decode = paf_aud_decode,
449  .capabilities = CODEC_CAP_DR1,
450  .long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Audio"),
451 };
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
GetByteContext gb
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
static int paf_aud_decode(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *pkt)
#define PAF_SOUND_FRAME_SIZE
Definition: paf.h:26
static av_cold int paf_aud_init(AVCodecContext *avctx)
uint8_t * frame[4]
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static av_cold int paf_vid_init(AVCodecContext *avctx)
static void copy_color_mask(AVCodecContext *avctx, uint8_t mask, uint8_t *dst, uint8_t color)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:130
#define AV_RL16
#define AV_CH_LAYOUT_STEREO
signed 16 bits
Definition: samplefmt.h:52
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:268
#define FFALIGN(x, a)
Definition: common.h:63
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
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
uint8_t
#define av_cold
Definition: attributes.h:78
static int get_video_page_offset(AVCodecContext *avctx, uint8_t a, uint8_t b)
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:79
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:77
#define AVPALETTE_SIZE
Definition: pixfmt.h:33
static AVPacket pkt
Definition: demuxing.c:56
#define b
Definition: input.c:42
end end
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
uint8_t * data
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:165
static av_cold int paf_vid_close(AVCodecContext *avctx)
Discrete Time axis x
#define U(x)
static const uint16_t mask[17]
Definition: lzw.c:37
static int paf_vid_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *pkt)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:159
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Spectrum Plot time data
const char * r
Definition: vf_curves.c:94
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:258
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:149
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
static const uint8_t offset[127][2]
Definition: vf_spp.c:70
external API header
uint64_t channel_layout
Audio channel layout.
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...
FFT buffer for g
Definition: stft_peak.m:17
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:144
static void copy_src_mask(AVCodecContext *avctx, uint8_t mask, uint8_t *dst, const uint8_t *src)
AVCodec ff_paf_audio_decoder
ret
Definition: avfilter.c:821
int width
picture width / height.
struct PAFVideoDecContext PAFVideoDecContext
t
Definition: genspecsines3.m:6
#define FFABS(a)
Definition: common.h:53
if it could not because there are no more frames
static void copy4h(AVCodecContext *avctx, uint8_t *dst)
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:183
const AVS_VideoInfo int align
Definition: avisynth_c.h:695
for k
AVCodec ff_paf_video_decoder
or the Software in violation of any applicable export control laws in any jurisdiction Except as provided by mandatorily applicable UPF has no obligation to provide you with source code to the Software In the event Software contains any source code
AVS_Value src
Definition: avisynth_c.h:523
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
main external API structure.
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
void * buf
Definition: avisynth_c.h:594
int index
Definition: gxfenc.c:89
synthesis window for stochastic i
int palette_has_changed
Tell user application that palette has changed from previous frame.
Definition: frame.h:280
#define PAF_SOUND_SAMPLES
Definition: paf.h:25
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
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:95
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by an given frame.
Definition: frame.c:228
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
static int decode_0(AVCodecContext *avctx, uint8_t code, uint8_t *pkt)
common internal api header.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:108
static double c[64]
function y
Definition: D.m:1
int channels
number of audio channels
static void copy_block4(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
Definition: copy_block.h:37
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:139
void INT64 INT64 count
Definition: avisynth_c.h:594
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
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
static const uint8_t block_sequences[16][8]
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:127
for(j=16;j >0;--j)
Predicted.
Definition: avutil.h:217