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 Libav.
6  *
7  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 
47 #include "libavutil/common.h"
48 #include "libavutil/intreadwrite.h"
49 #include "avcodec.h"
50 #include "internal.h"
51 #include "bytestream.h"
52 
53 #define VMD_HEADER_SIZE 0x330
54 #define PALETTE_COUNT 256
55 
56 /*
57  * Video Decoder
58  */
59 
60 typedef struct VmdVideoContext {
61 
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_get_le32(&gb);
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 + 8 > d_end || 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 + 1 > d_end || bytestream2_get_bytes_left(&gb) < 1)
126  return;
127  queue[qpos++] = *d++ = bytestream2_get_byte(&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 + chainlen > d_end)
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 
152 static int rle_unpack(const unsigned char *src, unsigned char *dest,
153  int src_count, int src_size, int dest_len)
154 {
155  unsigned char *pd;
156  int i, l;
157  unsigned char *dest_end = dest + dest_len;
158  GetByteContext gb;
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  }
167 
168  src_count >>= 1;
169  i = 0;
170  do {
171  if (bytestream2_get_bytes_left(&gb) < 1)
172  break;
173  l = bytestream2_get_byteu(&gb);
174  if (l & 0x80) {
175  l = (l & 0x7F) * 2;
176  if (pd + l > dest_end || bytestream2_get_bytes_left(&gb) < l)
177  return bytestream2_tell(&gb);
178  bytestream2_get_buffer(&gb, pd, l);
179  pd += l;
180  } else {
181  if (pd + i > dest_end || bytestream2_get_bytes_left(&gb) < 2)
182  return bytestream2_tell(&gb);
183  for (i = 0; i < l; i++) {
184  *pd++ = bytestream2_get_byteu(&gb);
185  *pd++ = bytestream2_get_byteu(&gb);
186  }
187  bytestream2_skip(&gb, 2);
188  }
189  i += l;
190  } while (i < 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  if (frame_x < 0 || frame_width < 0 ||
217  frame_x >= s->avctx->width ||
218  frame_width > s->avctx->width ||
219  frame_x + frame_width > s->avctx->width) {
221  "Invalid horizontal range %d-%d\n",
222  frame_x, frame_width);
223  return AVERROR_INVALIDDATA;
224  }
225  if (frame_y < 0 || frame_height < 0 ||
226  frame_y >= s->avctx->height ||
227  frame_height > s->avctx->height ||
228  frame_y + frame_height > s->avctx->height) {
230  "Invalid vertical range %d-%d\n",
231  frame_x, frame_width);
232  return AVERROR_INVALIDDATA;
233  }
234 
235  if ((frame_width == s->avctx->width && frame_height == s->avctx->height) &&
236  (frame_x || frame_y)) {
237 
238  s->x_off = frame_x;
239  s->y_off = frame_y;
240  }
241  frame_x -= s->x_off;
242  frame_y -= s->y_off;
243 
244  /* if only a certain region will be updated, copy the entire previous
245  * frame before the decode */
246  if (s->prev_frame.data[0] &&
247  (frame_x || frame_y || (frame_width != s->avctx->width) ||
248  (frame_height != s->avctx->height))) {
249 
250  memcpy(s->frame.data[0], s->prev_frame.data[0],
251  s->avctx->height * s->frame.linesize[0]);
252  }
253 
254  /* check if there is a new palette */
255  bytestream2_init(&gb, s->buf + 16, s->size - 16);
256  if (s->buf[15] & 0x02) {
257  bytestream2_skip(&gb, 2);
258  palette32 = (unsigned int *)s->palette;
260  for (i = 0; i < PALETTE_COUNT; i++) {
261  r = bytestream2_get_byteu(&gb) * 4;
262  g = bytestream2_get_byteu(&gb) * 4;
263  b = bytestream2_get_byteu(&gb) * 4;
264  palette32[i] = (r << 16) | (g << 8) | (b);
265  }
266  } else {
267  av_log(s->avctx, AV_LOG_ERROR, "Incomplete palette\n");
268  return AVERROR_INVALIDDATA;
269  }
270  s->size -= PALETTE_COUNT * 3 + 2;
271  }
272 
273  if (!s->size)
274  return 0;
275 
276  /* originally UnpackFrame in VAG's code */
277  if (bytestream2_get_bytes_left(&gb) < 1)
278  return AVERROR_INVALIDDATA;
279  meth = bytestream2_get_byteu(&gb);
280  if (meth & 0x80) {
283  meth &= 0x7F;
285  }
286 
287  dp = &s->frame.data[0][frame_y * s->frame.linesize[0] + frame_x];
288  pp = &s->prev_frame.data[0][frame_y * s->prev_frame.linesize[0] + frame_x];
289  switch (meth) {
290  case 1:
291  for (i = 0; i < frame_height; i++) {
292  ofs = 0;
293  do {
294  len = bytestream2_get_byte(&gb);
295  if (len & 0x80) {
296  len = (len & 0x7F) + 1;
297  if (ofs + len > frame_width ||
299  return AVERROR_INVALIDDATA;
300  bytestream2_get_buffer(&gb, &dp[ofs], len);
301  ofs += len;
302  } else {
303  /* interframe pixel copy */
304  if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])
305  return AVERROR_INVALIDDATA;
306  memcpy(&dp[ofs], &pp[ofs], len + 1);
307  ofs += len + 1;
308  }
309  } while (ofs < frame_width);
310  if (ofs > frame_width) {
312  "VMD video: offset > width (%d > %d)\n",
313  ofs, frame_width);
314  return AVERROR_INVALIDDATA;
315  }
316  dp += s->frame.linesize[0];
317  pp += s->prev_frame.linesize[0];
318  }
319  break;
320 
321  case 2:
322  for (i = 0; i < frame_height; i++) {
323  bytestream2_get_buffer(&gb, dp, frame_width);
324  dp += s->frame.linesize[0];
325  pp += s->prev_frame.linesize[0];
326  }
327  break;
328 
329  case 3:
330  for (i = 0; i < frame_height; i++) {
331  ofs = 0;
332  do {
333  len = bytestream2_get_byte(&gb);
334  if (len & 0x80) {
335  len = (len & 0x7F) + 1;
336  if (bytestream2_get_byte(&gb) == 0xFF)
337  len = rle_unpack(gb.buffer, &dp[ofs],
338  len, bytestream2_get_bytes_left(&gb),
339  frame_width - ofs);
340  else
341  bytestream2_get_buffer(&gb, &dp[ofs], len);
342  bytestream2_skip(&gb, len);
343  } else {
344  /* interframe pixel copy */
345  if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])
346  return AVERROR_INVALIDDATA;
347  memcpy(&dp[ofs], &pp[ofs], len + 1);
348  ofs += len + 1;
349  }
350  } while (ofs < frame_width);
351  if (ofs > frame_width) {
353  "VMD video: offset > width (%d > %d)\n",
354  ofs, frame_width);
355  return AVERROR_INVALIDDATA;
356  }
357  dp += s->frame.linesize[0];
358  pp += s->prev_frame.linesize[0];
359  }
360  break;
361  }
362  return 0;
363 }
364 
366 {
367  VmdVideoContext *s = avctx->priv_data;
368  int i;
369  unsigned int *palette32;
370  int palette_index = 0;
371  unsigned char r, g, b;
372  unsigned char *vmd_header;
373  unsigned char *raw_palette;
374 
375  s->avctx = avctx;
376  avctx->pix_fmt = AV_PIX_FMT_PAL8;
377 
378  /* make sure the VMD header made it */
379  if (s->avctx->extradata_size != VMD_HEADER_SIZE) {
380  av_log(s->avctx, AV_LOG_ERROR, "VMD video: expected extradata size of %d\n",
382  return -1;
383  }
384  vmd_header = (unsigned char *)avctx->extradata;
385 
386  s->unpack_buffer_size = AV_RL32(&vmd_header[800]);
388  if (!s->unpack_buffer)
389  return -1;
390 
391  /* load up the initial palette */
392  raw_palette = &vmd_header[28];
393  palette32 = (unsigned int *)s->palette;
394  for (i = 0; i < PALETTE_COUNT; i++) {
395  r = raw_palette[palette_index++] * 4;
396  g = raw_palette[palette_index++] * 4;
397  b = raw_palette[palette_index++] * 4;
398  palette32[i] = (r << 16) | (g << 8) | (b);
399  }
400 
401  return 0;
402 }
403 
405  void *data, int *got_frame,
406  AVPacket *avpkt)
407 {
408  const uint8_t *buf = avpkt->data;
409  int buf_size = avpkt->size;
410  VmdVideoContext *s = avctx->priv_data;
411 
412  s->buf = buf;
413  s->size = buf_size;
414 
415  if (buf_size < 16)
416  return AVERROR_INVALIDDATA;
417 
418  s->frame.reference = 1;
419  if (ff_get_buffer(avctx, &s->frame)) {
420  av_log(s->avctx, AV_LOG_ERROR, "VMD Video: get_buffer() failed\n");
421  return -1;
422  }
423 
424  vmd_decode(s);
425 
426  /* make the palette available on the way out */
427  memcpy(s->frame.data[1], s->palette, PALETTE_COUNT * 4);
428 
429  /* shuffle frames */
430  FFSWAP(AVFrame, s->frame, s->prev_frame);
431  if (s->frame.data[0])
432  avctx->release_buffer(avctx, &s->frame);
433 
434  *got_frame = 1;
435  *(AVFrame*)data = s->prev_frame;
436 
437  /* report that the buffer was completely consumed */
438  return buf_size;
439 }
440 
442 {
443  VmdVideoContext *s = avctx->priv_data;
444 
445  if (s->prev_frame.data[0])
446  avctx->release_buffer(avctx, &s->prev_frame);
448 
449  return 0;
450 }
451 
452 
453 /*
454  * Audio Decoder
455  */
456 
457 #define BLOCK_TYPE_AUDIO 1
458 #define BLOCK_TYPE_INITIAL 2
459 #define BLOCK_TYPE_SILENCE 3
460 
461 typedef struct VmdAudioContext {
463  int out_bps;
466 
467 static const uint16_t vmdaudio_table[128] = {
468  0x000, 0x008, 0x010, 0x020, 0x030, 0x040, 0x050, 0x060, 0x070, 0x080,
469  0x090, 0x0A0, 0x0B0, 0x0C0, 0x0D0, 0x0E0, 0x0F0, 0x100, 0x110, 0x120,
470  0x130, 0x140, 0x150, 0x160, 0x170, 0x180, 0x190, 0x1A0, 0x1B0, 0x1C0,
471  0x1D0, 0x1E0, 0x1F0, 0x200, 0x208, 0x210, 0x218, 0x220, 0x228, 0x230,
472  0x238, 0x240, 0x248, 0x250, 0x258, 0x260, 0x268, 0x270, 0x278, 0x280,
473  0x288, 0x290, 0x298, 0x2A0, 0x2A8, 0x2B0, 0x2B8, 0x2C0, 0x2C8, 0x2D0,
474  0x2D8, 0x2E0, 0x2E8, 0x2F0, 0x2F8, 0x300, 0x308, 0x310, 0x318, 0x320,
475  0x328, 0x330, 0x338, 0x340, 0x348, 0x350, 0x358, 0x360, 0x368, 0x370,
476  0x378, 0x380, 0x388, 0x390, 0x398, 0x3A0, 0x3A8, 0x3B0, 0x3B8, 0x3C0,
477  0x3C8, 0x3D0, 0x3D8, 0x3E0, 0x3E8, 0x3F0, 0x3F8, 0x400, 0x440, 0x480,
478  0x4C0, 0x500, 0x540, 0x580, 0x5C0, 0x600, 0x640, 0x680, 0x6C0, 0x700,
479  0x740, 0x780, 0x7C0, 0x800, 0x900, 0xA00, 0xB00, 0xC00, 0xD00, 0xE00,
480  0xF00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, 0x3000, 0x4000
481 };
482 
484 {
485  VmdAudioContext *s = avctx->priv_data;
486 
487  if (avctx->channels < 1 || avctx->channels > 2) {
488  av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
489  return AVERROR(EINVAL);
490  }
491  if (avctx->block_align < 1) {
492  av_log(avctx, AV_LOG_ERROR, "invalid block align\n");
493  return AVERROR(EINVAL);
494  }
495 
496  avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
498 
499  if (avctx->bits_per_coded_sample == 16)
500  avctx->sample_fmt = AV_SAMPLE_FMT_S16;
501  else
502  avctx->sample_fmt = AV_SAMPLE_FMT_U8;
504 
505  s->chunk_size = avctx->block_align + avctx->channels * (s->out_bps == 2);
506 
508  avctx->coded_frame = &s->frame;
509 
510  av_log(avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, "
511  "block align = %d, sample rate = %d\n",
512  avctx->channels, avctx->bits_per_coded_sample, avctx->block_align,
513  avctx->sample_rate);
514 
515  return 0;
516 }
517 
518 static void decode_audio_s16(int16_t *out, const uint8_t *buf, int buf_size,
519  int channels)
520 {
521  int ch;
522  const uint8_t *buf_end = buf + buf_size;
523  int predictor[2];
524  int st = channels - 1;
525 
526  /* decode initial raw sample */
527  for (ch = 0; ch < channels; ch++) {
528  predictor[ch] = (int16_t)AV_RL16(buf);
529  buf += 2;
530  *out++ = predictor[ch];
531  }
532 
533  /* decode DPCM samples */
534  ch = 0;
535  while (buf < buf_end) {
536  uint8_t b = *buf++;
537  if (b & 0x80)
538  predictor[ch] -= vmdaudio_table[b & 0x7F];
539  else
540  predictor[ch] += vmdaudio_table[b];
541  predictor[ch] = av_clip_int16(predictor[ch]);
542  *out++ = predictor[ch];
543  ch ^= st;
544  }
545 }
546 
547 static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
548  int *got_frame_ptr, AVPacket *avpkt)
549 {
550  const uint8_t *buf = avpkt->data;
551  const uint8_t *buf_end;
552  int buf_size = avpkt->size;
553  VmdAudioContext *s = avctx->priv_data;
554  int block_type, silent_chunks, audio_chunks;
555  int ret;
556  uint8_t *output_samples_u8;
557  int16_t *output_samples_s16;
558 
559  if (buf_size < 16) {
560  av_log(avctx, AV_LOG_WARNING, "skipping small junk packet\n");
561  *got_frame_ptr = 0;
562  return buf_size;
563  }
564 
565  block_type = buf[6];
566  if (block_type < BLOCK_TYPE_AUDIO || block_type > BLOCK_TYPE_SILENCE) {
567  av_log(avctx, AV_LOG_ERROR, "unknown block type: %d\n", block_type);
568  return AVERROR(EINVAL);
569  }
570  buf += 16;
571  buf_size -= 16;
572 
573  /* get number of silent chunks */
574  silent_chunks = 0;
575  if (block_type == BLOCK_TYPE_INITIAL) {
576  uint32_t flags;
577  if (buf_size < 4) {
578  av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
579  return AVERROR(EINVAL);
580  }
581  flags = AV_RB32(buf);
582  silent_chunks = av_popcount(flags);
583  buf += 4;
584  buf_size -= 4;
585  } else if (block_type == BLOCK_TYPE_SILENCE) {
586  silent_chunks = 1;
587  buf_size = 0; // should already be zero but set it just to be sure
588  }
589 
590  /* ensure output buffer is large enough */
591  audio_chunks = buf_size / s->chunk_size;
592 
593  /* drop incomplete chunks */
594  buf_size = audio_chunks * s->chunk_size;
595 
596  /* get output buffer */
597  s->frame.nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) / avctx->channels;
598  if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
599  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
600  return ret;
601  }
602  output_samples_u8 = s->frame.data[0];
603  output_samples_s16 = (int16_t *)s->frame.data[0];
604 
605  /* decode silent chunks */
606  if (silent_chunks > 0) {
607  int silent_size = FFMIN(avctx->block_align * silent_chunks,
608  s->frame.nb_samples * avctx->channels);
609  if (s->out_bps == 2) {
610  memset(output_samples_s16, 0x00, silent_size * 2);
611  output_samples_s16 += silent_size;
612  } else {
613  memset(output_samples_u8, 0x80, silent_size);
614  output_samples_u8 += silent_size;
615  }
616  }
617 
618  /* decode audio chunks */
619  if (audio_chunks > 0) {
620  buf_end = buf + (buf_size & ~(avctx->channels > 1));
621  while (buf + s->chunk_size <= buf_end) {
622  if (s->out_bps == 2) {
623  decode_audio_s16(output_samples_s16, buf, s->chunk_size,
624  avctx->channels);
625  output_samples_s16 += avctx->block_align;
626  } else {
627  memcpy(output_samples_u8, buf, s->chunk_size);
628  output_samples_u8 += avctx->block_align;
629  }
630  buf += s->chunk_size;
631  }
632  }
633 
634  *got_frame_ptr = 1;
635  *(AVFrame *)data = s->frame;
636 
637  return avpkt->size;
638 }
639 
640 
641 /*
642  * Public Data Structures
643  */
644 
646  .name = "vmdvideo",
647  .type = AVMEDIA_TYPE_VIDEO,
648  .id = AV_CODEC_ID_VMDVIDEO,
649  .priv_data_size = sizeof(VmdVideoContext),
653  .capabilities = CODEC_CAP_DR1,
654  .long_name = NULL_IF_CONFIG_SMALL("Sierra VMD video"),
655 };
656 
658  .name = "vmdaudio",
659  .type = AVMEDIA_TYPE_AUDIO,
660  .id = AV_CODEC_ID_VMDAUDIO,
661  .priv_data_size = sizeof(VmdAudioContext),
664  .capabilities = CODEC_CAP_DR1,
665  .long_name = NULL_IF_CONFIG_SMALL("Sierra VMD audio"),
666 };
AVFrame frame
Definition: vmdav.c:63
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:61
int chunk_size
Definition: vmdav.c:464
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
struct VmdVideoContext VmdVideoContext
#define BLOCK_TYPE_SILENCE
Definition: vmdav.c:459
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:2259
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2725
AVFrame frame
Definition: vmdav.c:462
int size
Definition: avcodec.h:916
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1533
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:130
#define AV_RL16
Definition: intreadwrite.h:42
#define AV_CH_LAYOUT_STEREO
signed 16 bits
Definition: samplefmt.h:52
AVCodec.
Definition: avcodec.h:2960
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2141
AVCodecContext * avctx
Definition: vmdav.c:62
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:228
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2112
uint8_t
AV_SAMPLE_FMT_U8
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:76
#define AV_RB32
Definition: intreadwrite.h:130
#define QUEUE_SIZE
Definition: vmdav.c:76
#define b
Definition: input.c:52
static int vmdvideo_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: vmdav.c:404
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1454
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:915
const uint8_t * buffer
Definition: bytestream.h:33
static int flags
Definition: log.c:42
unsigned char * unpack_buffer
Definition: vmdav.c:70
uint32_t tag
Definition: movenc.c:802
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2704
#define BLOCK_TYPE_INITIAL
Definition: vmdav.c:458
unsigned char palette[PALETTE_COUNT *4]
Definition: vmdav.c:69
static int init(AVCodecParserContext *s)
Definition: h264_parser.c:335
#define r
Definition: input.c:51
static void lz_unpack(const unsigned char *src, int src_len, unsigned char *dest, int dest_len)
Definition: vmdav.c:79
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:139
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
Definition: avcodec.h:1132
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. ...
Definition: internal.h:88
g
Definition: yuv2rgb.c:540
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:258
int unpack_buffer_size
Definition: vmdav.c:71
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:149
const unsigned char * buf
Definition: vmdav.c:66
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
const char * name
Name of the codec implementation.
Definition: avcodec.h:2967
static int rle_unpack(const unsigned char *src, unsigned char *dest, int src_count, int src_size, int dest_len)
Definition: vmdav.c:152
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2165
audio channel layout utility functions
int width
picture width / height.
Definition: avcodec.h:1508
static av_cold int vmdvideo_decode_end(AVCodecContext *avctx)
Definition: vmdav.c:441
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
Definition: utils.c:464
#define AV_RL32
Definition: intreadwrite.h:146
static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
Definition: vmdav.c:483
#define PALETTE_COUNT
Definition: vmdav.c:54
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:95
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:183
#define VMD_HEADER_SIZE
Definition: vmdav.c:53
AVCodec ff_vmdaudio_decoder
Definition: vmdav.c:657
static void decode_audio_s16(int16_t *out, const uint8_t *buf, int buf_size, int channels)
Definition: vmdav.c:518
external API header
int sample_rate
samples per second
Definition: avcodec.h:2104
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
static int vmd_decode(VmdVideoContext *s)
Definition: vmdav.c:195
main external API structure.
Definition: avcodec.h:1339
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:326
int extradata_size
Definition: avcodec.h:1455
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
Definition: utils.c:604
static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: vmdav.c:547
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
AVCodec ff_vmdvideo_decoder
Definition: vmdav.c:645
#define QUEUE_MASK
Definition: vmdav.c:77
common internal api header.
common internal and external API header
static av_cold int vmdvideo_decode_init(AVCodecContext *avctx)
Definition: vmdav.c:365
void * priv_data
Definition: avcodec.h:1382
int len
int channels
number of audio channels
Definition: avcodec.h:2105
static const uint16_t vmdaudio_table[128]
Definition: vmdav.c:467
AVFrame prev_frame
Definition: vmdav.c:64
#define AV_CH_LAYOUT_MONO
struct VmdAudioContext VmdAudioContext
This structure stores compressed data.
Definition: avcodec.h:898
int nb_samples
number of audio samples (per channel) described by this frame
Definition: avcodec.h:1042
for(j=16;j >0;--j)
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)