FFmpeg  2.1.1
vmdav.c
Go to the documentation of this file.
1 /*
2  * Sierra VMD Audio & Video Decoders
3  * Copyright (C) 2004 the ffmpeg project
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 /**
23  * @file
24  * Sierra VMD audio & video decoders
25  * by Vladimir "VAG" Gneushev (vagsoft at mail.ru)
26  * for more information on the Sierra VMD format, visit:
27  * http://www.pcisys.net/~melanson/codecs/
28  *
29  * The video decoder outputs PAL8 colorspace data. The decoder expects
30  * a 0x330-byte VMD file header to be transmitted via extradata during
31  * codec initialization. Each encoded frame that is sent to this decoder
32  * is expected to be prepended with the appropriate 16-byte frame
33  * information record from the VMD file.
34  *
35  * The audio decoder, like the video decoder, expects each encoded data
36  * chunk to be prepended with the appropriate 16-byte frame information
37  * record from the VMD file. It does not require the 0x330-byte VMD file
38  * header, but it does need the audio setup parameters passed in through
39  * normal libavcodec API means.
40  */
41 
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 
46 #include "libavutil/avassert.h"
47 #include "libavutil/channel_layout.h"
48 #include "libavutil/common.h"
49 #include "libavutil/intreadwrite.h"
50 #include "avcodec.h"
51 #include "internal.h"
52 #include "bytestream.h"
53 
54 #define VMD_HEADER_SIZE 0x330
55 #define PALETTE_COUNT 256
56 
57 /*
58  * Video Decoder
59  */
60 
61 typedef struct VmdVideoContext {
62 
65 
66  const unsigned char *buf;
67  int size;
68 
69  unsigned char palette[PALETTE_COUNT * 4];
70  unsigned char *unpack_buffer;
72 
73  int x_off, y_off;
75 
76 #define QUEUE_SIZE 0x1000
77 #define QUEUE_MASK 0x0FFF
78 
79 static void lz_unpack(const unsigned char *src, int src_len,
80  unsigned char *dest, int dest_len)
81 {
82  unsigned char *d;
83  unsigned char *d_end;
84  unsigned char queue[QUEUE_SIZE];
85  unsigned int qpos;
86  unsigned int dataleft;
87  unsigned int chainofs;
88  unsigned int chainlen;
89  unsigned int speclen;
90  unsigned char tag;
91  unsigned int i, j;
92  GetByteContext gb;
93 
94  bytestream2_init(&gb, src, src_len);
95  d = dest;
96  d_end = d + dest_len;
97  dataleft = bytestream2_get_le32(&gb);
98  memset(queue, 0x20, QUEUE_SIZE);
99  if (bytestream2_get_bytes_left(&gb) < 4)
100  return;
101  if (bytestream2_peek_le32(&gb) == 0x56781234) {
102  bytestream2_skipu(&gb, 4);
103  qpos = 0x111;
104  speclen = 0xF + 3;
105  } else {
106  qpos = 0xFEE;
107  speclen = 100; /* no speclen */
108  }
109 
110  while (dataleft > 0 && bytestream2_get_bytes_left(&gb) > 0) {
111  tag = bytestream2_get_byteu(&gb);
112  if ((tag == 0xFF) && (dataleft > 8)) {
113  if (d_end - d < 8 || bytestream2_get_bytes_left(&gb) < 8)
114  return;
115  for (i = 0; i < 8; i++) {
116  queue[qpos++] = *d++ = bytestream2_get_byteu(&gb);
117  qpos &= QUEUE_MASK;
118  }
119  dataleft -= 8;
120  } else {
121  for (i = 0; i < 8; i++) {
122  if (dataleft == 0)
123  break;
124  if (tag & 0x01) {
125  if (d_end - d < 1 || bytestream2_get_bytes_left(&gb) < 1)
126  return;
127  queue[qpos++] = *d++ = bytestream2_get_byteu(&gb);
128  qpos &= QUEUE_MASK;
129  dataleft--;
130  } else {
131  chainofs = bytestream2_get_byte(&gb);
132  chainofs |= ((bytestream2_peek_byte(&gb) & 0xF0) << 4);
133  chainlen = (bytestream2_get_byte(&gb) & 0x0F) + 3;
134  if (chainlen == speclen) {
135  chainlen = bytestream2_get_byte(&gb) + 0xF + 3;
136  }
137  if (d_end - d < chainlen)
138  return;
139  for (j = 0; j < chainlen; j++) {
140  *d = queue[chainofs++ & QUEUE_MASK];
141  queue[qpos++] = *d++;
142  qpos &= QUEUE_MASK;
143  }
144  dataleft -= chainlen;
145  }
146  tag >>= 1;
147  }
148  }
149  }
150 }
151 static int rle_unpack(const unsigned char *src, unsigned char *dest,
152  int src_count, int src_size, int dest_len)
153 {
154  unsigned char *pd;
155  int i, l, used = 0;
156  unsigned char *dest_end = dest + dest_len;
157  GetByteContext gb;
158  uint16_t run_val;
159 
160  bytestream2_init(&gb, src, src_size);
161  pd = dest;
162  if (src_count & 1) {
163  if (bytestream2_get_bytes_left(&gb) < 1)
164  return 0;
165  *pd++ = bytestream2_get_byteu(&gb);
166  used++;
167  }
168 
169  do {
170  if (bytestream2_get_bytes_left(&gb) < 1)
171  break;
172  l = bytestream2_get_byteu(&gb);
173  if (l & 0x80) {
174  l = (l & 0x7F) * 2;
175  if (dest_end - pd < l || bytestream2_get_bytes_left(&gb) < l)
176  return bytestream2_tell(&gb);
177  bytestream2_get_bufferu(&gb, pd, l);
178  pd += l;
179  } else {
180  if (dest_end - pd < 2*l || bytestream2_get_bytes_left(&gb) < 2)
181  return bytestream2_tell(&gb);
182  run_val = bytestream2_get_ne16(&gb);
183  for (i = 0; i < l; i++) {
184  AV_WN16(pd, run_val);
185  pd += 2;
186  }
187  l *= 2;
188  }
189  used += l;
190  } while (used < src_count);
191 
192  return bytestream2_tell(&gb);
193 }
194 
196 {
197  int i;
198  unsigned int *palette32;
199  unsigned char r, g, b;
200 
201  GetByteContext gb;
202 
203  unsigned char meth;
204  unsigned char *dp; /* pointer to current frame */
205  unsigned char *pp; /* pointer to previous frame */
206  unsigned char len;
207  int ofs;
208 
209  int frame_x, frame_y;
210  int frame_width, frame_height;
211 
212  frame_x = AV_RL16(&s->buf[6]);
213  frame_y = AV_RL16(&s->buf[8]);
214  frame_width = AV_RL16(&s->buf[10]) - frame_x + 1;
215  frame_height = AV_RL16(&s->buf[12]) - frame_y + 1;
216 
217  if ((frame_width == s->avctx->width && frame_height == s->avctx->height) &&
218  (frame_x || frame_y)) {
219 
220  s->x_off = frame_x;
221  s->y_off = frame_y;
222  }
223  frame_x -= s->x_off;
224  frame_y -= s->y_off;
225 
226  if (frame_x < 0 || frame_width < 0 ||
227  frame_x >= s->avctx->width ||
228  frame_width > s->avctx->width ||
229  frame_x + frame_width > s->avctx->width) {
231  "Invalid horizontal range %d-%d\n",
232  frame_x, frame_width);
233  return AVERROR_INVALIDDATA;
234  }
235  if (frame_y < 0 || frame_height < 0 ||
236  frame_y >= s->avctx->height ||
237  frame_height > s->avctx->height ||
238  frame_y + frame_height > s->avctx->height) {
240  "Invalid vertical range %d-%d\n",
241  frame_x, frame_width);
242  return AVERROR_INVALIDDATA;
243  }
244 
245  /* if only a certain region will be updated, copy the entire previous
246  * frame before the decode */
247  if (s->prev_frame.data[0] &&
248  (frame_x || frame_y || (frame_width != s->avctx->width) ||
249  (frame_height != s->avctx->height))) {
250 
251  memcpy(frame->data[0], s->prev_frame.data[0],
252  s->avctx->height * frame->linesize[0]);
253  }
254 
255  /* check if there is a new palette */
256  bytestream2_init(&gb, s->buf + 16, s->size - 16);
257  if (s->buf[15] & 0x02) {
258  bytestream2_skip(&gb, 2);
259  palette32 = (unsigned int *)s->palette;
261  for (i = 0; i < PALETTE_COUNT; i++) {
262  r = bytestream2_get_byteu(&gb) * 4;
263  g = bytestream2_get_byteu(&gb) * 4;
264  b = bytestream2_get_byteu(&gb) * 4;
265  palette32[i] = 0xFFU << 24 | (r << 16) | (g << 8) | (b);
266  palette32[i] |= palette32[i] >> 6 & 0x30303;
267  }
268  } else {
269  av_log(s->avctx, AV_LOG_ERROR, "Incomplete palette\n");
270  return AVERROR_INVALIDDATA;
271  }
272  }
273 
274  if (!s->size)
275  return 0;
276 
277  /* originally UnpackFrame in VAG's code */
278  if (bytestream2_get_bytes_left(&gb) < 1)
279  return AVERROR_INVALIDDATA;
280  meth = bytestream2_get_byteu(&gb);
281  if (meth & 0x80) {
282  if (!s->unpack_buffer_size) {
284  "Trying to unpack LZ-compressed frame with no LZ buffer\n");
285  return AVERROR_INVALIDDATA;
286  }
289  meth &= 0x7F;
291  }
292 
293  dp = &frame->data[0][frame_y * frame->linesize[0] + frame_x];
294  pp = &s->prev_frame.data[0][frame_y * s->prev_frame.linesize[0] + frame_x];
295  switch (meth) {
296  case 1:
297  for (i = 0; i < frame_height; i++) {
298  ofs = 0;
299  do {
300  len = bytestream2_get_byte(&gb);
301  if (len & 0x80) {
302  len = (len & 0x7F) + 1;
303  if (ofs + len > frame_width ||
305  return AVERROR_INVALIDDATA;
306  bytestream2_get_bufferu(&gb, &dp[ofs], len);
307  ofs += len;
308  } else {
309  /* interframe pixel copy */
310  if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])
311  return AVERROR_INVALIDDATA;
312  memcpy(&dp[ofs], &pp[ofs], len + 1);
313  ofs += len + 1;
314  }
315  } while (ofs < frame_width);
316  if (ofs > frame_width) {
318  "offset > width (%d > %d)\n",
319  ofs, frame_width);
320  return AVERROR_INVALIDDATA;
321  }
322  dp += frame->linesize[0];
323  pp += s->prev_frame.linesize[0];
324  }
325  break;
326 
327  case 2:
328  for (i = 0; i < frame_height; i++) {
329  bytestream2_get_buffer(&gb, dp, frame_width);
330  dp += frame->linesize[0];
331  pp += s->prev_frame.linesize[0];
332  }
333  break;
334 
335  case 3:
336  for (i = 0; i < frame_height; i++) {
337  ofs = 0;
338  do {
339  len = bytestream2_get_byte(&gb);
340  if (len & 0x80) {
341  len = (len & 0x7F) + 1;
342  if (bytestream2_peek_byte(&gb) == 0xFF) {
343  int slen = len;
344  bytestream2_get_byte(&gb);
345  len = rle_unpack(gb.buffer, &dp[ofs],
346  len, bytestream2_get_bytes_left(&gb),
347  frame_width - ofs);
348  ofs += slen;
349  bytestream2_skip(&gb, len);
350  } else {
351  bytestream2_get_buffer(&gb, &dp[ofs], len);
352  ofs += len;
353  }
354  } else {
355  /* interframe pixel copy */
356  if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])
357  return AVERROR_INVALIDDATA;
358  memcpy(&dp[ofs], &pp[ofs], len + 1);
359  ofs += len + 1;
360  }
361  } while (ofs < frame_width);
362  if (ofs > frame_width) {
364  "offset > width (%d > %d)\n",
365  ofs, frame_width);
366  return AVERROR_INVALIDDATA;
367  }
368  dp += frame->linesize[0];
369  pp += s->prev_frame.linesize[0];
370  }
371  break;
372  }
373  return 0;
374 }
375 
377 {
378  VmdVideoContext *s = avctx->priv_data;
379  int i;
380  unsigned int *palette32;
381  int palette_index = 0;
382  unsigned char r, g, b;
383  unsigned char *vmd_header;
384  unsigned char *raw_palette;
385 
386  s->avctx = avctx;
387  avctx->pix_fmt = AV_PIX_FMT_PAL8;
388 
389  /* make sure the VMD header made it */
390  if (s->avctx->extradata_size != VMD_HEADER_SIZE) {
391  av_log(s->avctx, AV_LOG_ERROR, "expected extradata size of %d\n",
393  return AVERROR_INVALIDDATA;
394  }
395  vmd_header = (unsigned char *)avctx->extradata;
396 
397  s->unpack_buffer_size = AV_RL32(&vmd_header[800]);
398  if (s->unpack_buffer_size) {
400  if (!s->unpack_buffer)
401  return AVERROR(ENOMEM);
402  }
403 
404  /* load up the initial palette */
405  raw_palette = &vmd_header[28];
406  palette32 = (unsigned int *)s->palette;
407  for (i = 0; i < PALETTE_COUNT; i++) {
408  r = raw_palette[palette_index++] * 4;
409  g = raw_palette[palette_index++] * 4;
410  b = raw_palette[palette_index++] * 4;
411  palette32[i] = 0xFFU << 24 | (r << 16) | (g << 8) | (b);
412  palette32[i] |= palette32[i] >> 6 & 0x30303;
413  }
414 
416 
417  return 0;
418 }
419 
421  void *data, int *got_frame,
422  AVPacket *avpkt)
423 {
424  const uint8_t *buf = avpkt->data;
425  int buf_size = avpkt->size;
426  VmdVideoContext *s = avctx->priv_data;
427  AVFrame *frame = data;
428  int ret;
429 
430  s->buf = buf;
431  s->size = buf_size;
432 
433  if (buf_size < 16)
434  return AVERROR_INVALIDDATA;
435 
436  if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
437  return ret;
438 
439  if ((ret = vmd_decode(s, frame)) < 0)
440  return ret;
441 
442  /* make the palette available on the way out */
443  memcpy(frame->data[1], s->palette, PALETTE_COUNT * 4);
444 
445  /* shuffle frames */
447  if ((ret = av_frame_ref(&s->prev_frame, frame)) < 0)
448  return ret;
449 
450  *got_frame = 1;
451 
452  /* report that the buffer was completely consumed */
453  return buf_size;
454 }
455 
457 {
458  VmdVideoContext *s = avctx->priv_data;
459 
462 
463  return 0;
464 }
465 
466 
467 /*
468  * Audio Decoder
469  */
470 
471 #define BLOCK_TYPE_AUDIO 1
472 #define BLOCK_TYPE_INITIAL 2
473 #define BLOCK_TYPE_SILENCE 3
474 
475 typedef struct VmdAudioContext {
476  int out_bps;
479 
480 static const uint16_t vmdaudio_table[128] = {
481  0x000, 0x008, 0x010, 0x020, 0x030, 0x040, 0x050, 0x060, 0x070, 0x080,
482  0x090, 0x0A0, 0x0B0, 0x0C0, 0x0D0, 0x0E0, 0x0F0, 0x100, 0x110, 0x120,
483  0x130, 0x140, 0x150, 0x160, 0x170, 0x180, 0x190, 0x1A0, 0x1B0, 0x1C0,
484  0x1D0, 0x1E0, 0x1F0, 0x200, 0x208, 0x210, 0x218, 0x220, 0x228, 0x230,
485  0x238, 0x240, 0x248, 0x250, 0x258, 0x260, 0x268, 0x270, 0x278, 0x280,
486  0x288, 0x290, 0x298, 0x2A0, 0x2A8, 0x2B0, 0x2B8, 0x2C0, 0x2C8, 0x2D0,
487  0x2D8, 0x2E0, 0x2E8, 0x2F0, 0x2F8, 0x300, 0x308, 0x310, 0x318, 0x320,
488  0x328, 0x330, 0x338, 0x340, 0x348, 0x350, 0x358, 0x360, 0x368, 0x370,
489  0x378, 0x380, 0x388, 0x390, 0x398, 0x3A0, 0x3A8, 0x3B0, 0x3B8, 0x3C0,
490  0x3C8, 0x3D0, 0x3D8, 0x3E0, 0x3E8, 0x3F0, 0x3F8, 0x400, 0x440, 0x480,
491  0x4C0, 0x500, 0x540, 0x580, 0x5C0, 0x600, 0x640, 0x680, 0x6C0, 0x700,
492  0x740, 0x780, 0x7C0, 0x800, 0x900, 0xA00, 0xB00, 0xC00, 0xD00, 0xE00,
493  0xF00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, 0x3000, 0x4000
494 };
495 
497 {
498  VmdAudioContext *s = avctx->priv_data;
499 
500  if (avctx->channels < 1 || avctx->channels > 2) {
501  av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
502  return AVERROR(EINVAL);
503  }
504  if (avctx->block_align < 1 || avctx->block_align % avctx->channels) {
505  av_log(avctx, AV_LOG_ERROR, "invalid block align\n");
506  return AVERROR(EINVAL);
507  }
508 
509  avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
511 
512  if (avctx->bits_per_coded_sample == 16)
513  avctx->sample_fmt = AV_SAMPLE_FMT_S16;
514  else
515  avctx->sample_fmt = AV_SAMPLE_FMT_U8;
517 
518  s->chunk_size = avctx->block_align + avctx->channels * (s->out_bps == 2);
519 
520  av_log(avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, "
521  "block align = %d, sample rate = %d\n",
522  avctx->channels, avctx->bits_per_coded_sample, avctx->block_align,
523  avctx->sample_rate);
524 
525  return 0;
526 }
527 
528 static void decode_audio_s16(int16_t *out, const uint8_t *buf, int buf_size,
529  int channels)
530 {
531  int ch;
532  const uint8_t *buf_end = buf + buf_size;
533  int predictor[2];
534  int st = channels - 1;
535 
536  /* decode initial raw sample */
537  for (ch = 0; ch < channels; ch++) {
538  predictor[ch] = (int16_t)AV_RL16(buf);
539  buf += 2;
540  *out++ = predictor[ch];
541  }
542 
543  /* decode DPCM samples */
544  ch = 0;
545  while (buf < buf_end) {
546  uint8_t b = *buf++;
547  if (b & 0x80)
548  predictor[ch] -= vmdaudio_table[b & 0x7F];
549  else
550  predictor[ch] += vmdaudio_table[b];
551  predictor[ch] = av_clip_int16(predictor[ch]);
552  *out++ = predictor[ch];
553  ch ^= st;
554  }
555 }
556 
557 static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
558  int *got_frame_ptr, AVPacket *avpkt)
559 {
560  AVFrame *frame = data;
561  const uint8_t *buf = avpkt->data;
562  const uint8_t *buf_end;
563  int buf_size = avpkt->size;
564  VmdAudioContext *s = avctx->priv_data;
565  int block_type, silent_chunks, audio_chunks;
566  int ret;
567  uint8_t *output_samples_u8;
568  int16_t *output_samples_s16;
569 
570  if (buf_size < 16) {
571  av_log(avctx, AV_LOG_WARNING, "skipping small junk packet\n");
572  *got_frame_ptr = 0;
573  return buf_size;
574  }
575 
576  block_type = buf[6];
577  if (block_type < BLOCK_TYPE_AUDIO || block_type > BLOCK_TYPE_SILENCE) {
578  av_log(avctx, AV_LOG_ERROR, "unknown block type: %d\n", block_type);
579  return AVERROR(EINVAL);
580  }
581  buf += 16;
582  buf_size -= 16;
583 
584  /* get number of silent chunks */
585  silent_chunks = 0;
586  if (block_type == BLOCK_TYPE_INITIAL) {
587  uint32_t flags;
588  if (buf_size < 4) {
589  av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
590  return AVERROR(EINVAL);
591  }
592  flags = AV_RB32(buf);
593  silent_chunks = av_popcount(flags);
594  buf += 4;
595  buf_size -= 4;
596  } else if (block_type == BLOCK_TYPE_SILENCE) {
597  silent_chunks = 1;
598  buf_size = 0; // should already be zero but set it just to be sure
599  }
600 
601  /* ensure output buffer is large enough */
602  audio_chunks = buf_size / s->chunk_size;
603 
604  /* drop incomplete chunks */
605  buf_size = audio_chunks * s->chunk_size;
606 
607  /* get output buffer */
608  frame->nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) /
609  avctx->channels;
610  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
611  return ret;
612  output_samples_u8 = frame->data[0];
613  output_samples_s16 = (int16_t *)frame->data[0];
614 
615  /* decode silent chunks */
616  if (silent_chunks > 0) {
617  int silent_size = avctx->block_align * silent_chunks;
618  av_assert0(avctx->block_align * silent_chunks <= frame->nb_samples * avctx->channels);
619 
620  if (s->out_bps == 2) {
621  memset(output_samples_s16, 0x00, silent_size * 2);
622  output_samples_s16 += silent_size;
623  } else {
624  memset(output_samples_u8, 0x80, silent_size);
625  output_samples_u8 += silent_size;
626  }
627  }
628 
629  /* decode audio chunks */
630  if (audio_chunks > 0) {
631  buf_end = buf + buf_size;
632  av_assert0((buf_size & (avctx->channels > 1)) == 0);
633  while (buf_end - buf >= s->chunk_size) {
634  if (s->out_bps == 2) {
635  decode_audio_s16(output_samples_s16, buf, s->chunk_size,
636  avctx->channels);
637  output_samples_s16 += avctx->block_align;
638  } else {
639  memcpy(output_samples_u8, buf, s->chunk_size);
640  output_samples_u8 += avctx->block_align;
641  }
642  buf += s->chunk_size;
643  }
644  }
645 
646  *got_frame_ptr = 1;
647 
648  return avpkt->size;
649 }
650 
651 
652 /*
653  * Public Data Structures
654  */
655 
657  .name = "vmdvideo",
658  .long_name = NULL_IF_CONFIG_SMALL("Sierra VMD video"),
659  .type = AVMEDIA_TYPE_VIDEO,
660  .id = AV_CODEC_ID_VMDVIDEO,
661  .priv_data_size = sizeof(VmdVideoContext),
665  .capabilities = CODEC_CAP_DR1,
666 };
667 
669  .name = "vmdaudio",
670  .long_name = NULL_IF_CONFIG_SMALL("Sierra VMD audio"),
671  .type = AVMEDIA_TYPE_AUDIO,
672  .id = AV_CODEC_ID_VMDAUDIO,
673  .priv_data_size = sizeof(VmdAudioContext),
676  .capabilities = CODEC_CAP_DR1,
677 };
static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
Definition: vmdav.c:195
const char * s
Definition: avisynth_c.h:668
int chunk_size
Definition: vmdav.c:477
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
#define BLOCK_TYPE_SILENCE
Definition: vmdav.c:473
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: avcodec.h:4153
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
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
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:1910
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:271
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1254
AVCodecContext * avctx
Definition: vmdav.c:63
unsigned 8 bits
Definition: samplefmt.h:51
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
Definition: avfilter.c:965
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1881
uint8_t
#define QUEUE_SIZE
Definition: vmdav.c:76
static int vmdvideo_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: vmdav.c:420
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
const uint8_t * buffer
Definition: bytestream.h:34
unsigned char * unpack_buffer
Definition: vmdav.c:70
uint32_t tag
Definition: movenc.c:961
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2563
#define BLOCK_TYPE_INITIAL
Definition: vmdav.c:472
unsigned char palette[PALETTE_COUNT *4]
Definition: vmdav.c:69
signed 16 bits
Definition: samplefmt.h:52
static AVFrame * frame
Definition: demuxing.c:51
static void lz_unpack(const unsigned char *src, int src_len, unsigned char *dest, int dest_len)
Definition: vmdav.c:79
#define AV_WN16(p, v)
Definition: intreadwrite.h:364
static void predictor(uint8_t *src, int size)
Definition: exr.c:192
#define U(x)
Definition: vp56_arith.h:37
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:219
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:162
#define bytestream2_get_ne16
Definition: bytestream.h:113
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
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 unpack_buffer_size
Definition: vmdav.c:71
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: avcodec.h:4168
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:152
const unsigned char * buf
Definition: vmdav.c:66
Libavcodec external API header.
static int rle_unpack(const unsigned char *src, unsigned char *dest, int src_count, int src_size, int dest_len)
Definition: vmdav.c:151
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1934
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:351
ret
Definition: avfilter.c:961
int width
picture width / height.
Definition: avcodec.h:1314
static av_cold int vmdvideo_decode_end(AVCodecContext *avctx)
Definition: vmdav.c:456
void * av_malloc(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:73
static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
Definition: vmdav.c:496
#define PALETTE_COUNT
Definition: vmdav.c:55
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:186
#define VMD_HEADER_SIZE
Definition: vmdav.c:54
AVCodec ff_vmdaudio_decoder
Definition: vmdav.c:668
static void decode_audio_s16(int16_t *out, const uint8_t *buf, int buf_size, int channels)
Definition: vmdav.c:528
AVS_Value src
Definition: avisynth_c.h:523
int sample_rate
samples per second
Definition: avcodec.h:1873
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 extradata_size
Definition: avcodec.h:1255
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
Definition: utils.c:1046
uint8_t * data
Definition: avcodec.h:1063
static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: vmdav.c:557
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
void * priv_data
Definition: avcodec.h:1182
static int flags
Definition: cpu.c:45
AVCodec ff_vmdvideo_decoder
Definition: vmdav.c:656
#define QUEUE_MASK
Definition: vmdav.c:77
common internal api header.
static av_cold int vmdvideo_decode_init(AVCodecContext *avctx)
Definition: vmdav.c:376
#define AV_RB32(x)
Definition: intreadwrite.h:258
#define AVERROR_INVALIDDATA
#define AV_RL32(x)
Definition: intreadwrite.h:275
int len
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
#define AVERROR(e)
static const uint16_t vmdaudio_table[128]
Definition: vmdav.c:480
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVFrame prev_frame
Definition: vmdav.c:64
8 bit with PIX_FMT_RGB32 palette
Definition: avcodec.h:4545
#define AV_CH_LAYOUT_MONO
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:104
This structure stores compressed data.
Definition: avcodec.h:1040
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:910
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)