FFmpeg
vividas.c
Go to the documentation of this file.
1 /*
2  * Vividas VIV format Demuxer
3  * Copyright (c) 2012 Krzysztof Klinikowski
4  * Copyright (c) 2010 Andrzej Szombierski
5  * based on vivparse Copyright (c) 2007 Måns Rullgård
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 /**
25  * @file
26  * @brief Vividas VIV (.viv) file demuxer
27  * @author Andrzej Szombierski [qq at kuku eu org] (2010-07)
28  * @sa http://wiki.multimedia.cx/index.php?title=Vividas_VIV
29  */
30 
31 #include "libavutil/avassert.h"
32 #include "libavutil/intreadwrite.h"
33 #include "avio_internal.h"
34 #include "avformat.h"
35 #include "internal.h"
36 
37 #define MAX_AUDIO_SUBPACKETS 100
38 
39 typedef struct VIV_SB_block {
41  int64_t byte_offset;
42  int64_t packet_offset;
43 } VIV_SB_block;
44 
45 typedef struct VIV_SB_entry {
46  int size, flag;
47 } VIV_SB_entry;
48 
49 typedef struct VIV_AudioSubpacket {
52 
53 typedef struct VividasDemuxContext {
56  int num_audio;
57 
58  uint32_t sb_key;
59  int64_t sb_offset;
60 
66 
69 
70  int64_t audio_sample;
71 
74 
75 static int viv_probe(const AVProbeData *p)
76 {
77  if (memcmp(p->buf, "vividas03", 9))
78  return 0;
79 
80  return AVPROBE_SCORE_MAX;
81 }
82 
83 static const uint8_t keybits[32] = {
84  20, 52, 111, 10, 27, 71, 142, 53,
85  82, 138, 1, 78, 86, 121, 183, 85,
86 105, 152, 39, 140, 172, 11, 64, 144,
87 155, 6, 71, 163, 186, 49, 126, 43,
88 };
89 
90 static uint32_t decode_key(uint8_t *buf)
91 {
92  uint32_t key = 0;
93 
94  for (int i = 0; i < 32; i++) {
95  unsigned p = keybits[i];
96  key |= ((buf[p] >> ((i*5+3)&7)) & 1u) << i;
97  }
98 
99  return key;
100 }
101 
102 static void put_v(uint8_t *p, unsigned v)
103 {
104  if (v>>28)
105  *p++ = ((v>>28)&0x7f)|0x80;
106  if (v>>21)
107  *p++ = ((v>>21)&0x7f)|0x80;
108  if (v>>14)
109  *p++ = ((v>>14)&0x7f)|0x80;
110  if (v>>7)
111  *p++ = ((v>>7)&0x7f)|0x80;
112 }
113 
114 static unsigned recover_key(unsigned char sample[4], unsigned expected_size)
115 {
116  unsigned char plaintext[8] = { 'S', 'B' };
117 
118  put_v(plaintext+2, expected_size);
119 
120  return AV_RL32(sample) ^ AV_RL32(plaintext);
121 }
122 
123 static void xor_block(void *p1, void *p2, unsigned size, int key, unsigned *key_ptr)
124 {
125  unsigned *d1 = p1;
126  unsigned *d2 = p2;
127  unsigned k = *key_ptr;
128 
129  size >>= 2;
130 
131  while (size > 0) {
132  *d2 = *d1 ^ (HAVE_BIGENDIAN ? av_bswap32(k) : k);
133  k += key;
134  d1++;
135  d2++;
136  size--;
137  }
138 
139  *key_ptr = k;
140 }
141 
142 static void decode_block(uint8_t *src, uint8_t *dest, unsigned size,
143  uint32_t key, uint32_t *key_ptr,
144  int align)
145 {
146  unsigned s = size;
147  char tmp[4];
148  int a2;
149 
150  if (!size)
151  return;
152 
153  align &= 3;
154  a2 = (4 - align) & 3;
155 
156  if (align) {
157  uint32_t tmpkey = *key_ptr - key;
158  if (a2 > s) {
159  a2 = s;
160  avpriv_request_sample(NULL, "tiny aligned block\n");
161  }
162  memcpy(tmp + align, src, a2);
163  xor_block(tmp, tmp, 4, key, &tmpkey);
164  memcpy(dest, tmp + align, a2);
165  s -= a2;
166  }
167 
168  if (s >= 4) {
169  xor_block(src + a2, dest + a2, s & ~3,
170  key, key_ptr);
171  s &= 3;
172  }
173 
174  if (s) {
175  size -= s;
176  memcpy(tmp, src + size, s);
177  xor_block(&tmp, &tmp, 4, key, key_ptr);
178  memcpy(dest + size, tmp, s);
179  }
180 }
181 
182 static uint32_t get_v(uint8_t *p, int len)
183 {
184  uint32_t v = 0;
185  const uint8_t *end = p + len;
186 
187  do {
188  if (p >= end || v >= UINT_MAX / 128 - *p)
189  return v;
190  v <<= 7;
191  v += *p & 0x7f;
192  } while (*p++ & 0x80);
193 
194  return v;
195 }
196 
197 static uint8_t *read_vblock(AVIOContext *src, uint32_t *size,
198  uint32_t key, uint32_t *k2, int align)
199 {
200  uint8_t tmp[4];
201  uint8_t *buf;
202  unsigned n;
203 
204  if (avio_read(src, tmp, 4) != 4)
205  return NULL;
206 
207  decode_block(tmp, tmp, 4, key, k2, align);
208 
209  n = get_v(tmp, 4);
210  if (n < 4)
211  return NULL;
212 
213  buf = av_malloc(n);
214  if (!buf)
215  return NULL;
216 
217  *size = n;
218  n -= 4;
219 
220  memcpy(buf, tmp, 4);
221 
222  if (avio_read(src, buf + 4, n) == n) {
223  decode_block(buf + 4, buf + 4, n, key, k2, align);
224  } else {
225  av_free(buf);
226  buf = NULL;
227  }
228 
229  return buf;
230 }
231 
233  uint32_t *key, unsigned expected_size)
234 {
235  uint8_t *buf;
236  uint8_t ibuf[8], sbuf[8];
237  uint32_t k2;
238  unsigned n;
239 
240  if (avio_read(src, ibuf, 8) < 8)
241  return NULL;
242 
243  k2 = *key;
244  decode_block(ibuf, sbuf, 8, *key, &k2, 0);
245 
246  n = get_v(sbuf+2, 6);
247 
248  if (sbuf[0] != 'S' || sbuf[1] != 'B' || (expected_size>0 && n != expected_size)) {
249  uint32_t tmpkey = recover_key(ibuf, expected_size);
250  k2 = tmpkey;
251  decode_block(ibuf, sbuf, 8, tmpkey, &k2, 0);
252  n = get_v(sbuf+2, 6);
253  if (sbuf[0] != 'S' || sbuf[1] != 'B' || expected_size != n)
254  return NULL;
255  *key = tmpkey;
256  }
257 
258  if (n < 8)
259  return NULL;
260 
261  buf = av_malloc(n);
262  if (!buf)
263  return NULL;
264 
265  memcpy(buf, sbuf, 8);
266 
267  *size = n;
268  n -= 8;
269 
270  if (avio_read(src, buf+8, n) != n) {
271  av_free(buf);
272  return NULL;
273  }
274 
275  decode_block(buf + 8, buf + 8, n, *key, &k2, 0);
276 
277  return buf;
278 }
279 
281 {
282  int i,j;
283  int64_t off;
284  int val_1;
285  int num_video;
286  AVIOContext *pb;
287 
288  pb = avio_alloc_context(buf, size, 0, NULL, NULL, NULL, NULL);
289  if (!pb)
290  return AVERROR(ENOMEM);
291 
292  ffio_read_varlen(pb); // track_header_len
293  avio_r8(pb); // '1'
294 
295  val_1 = ffio_read_varlen(pb);
296 
297  for (i=0;i<val_1;i++) {
298  int c = avio_r8(pb);
299  if (avio_feof(pb))
300  return AVERROR_EOF;
301  for (j=0;j<c;j++) {
302  if (avio_feof(pb))
303  return AVERROR_EOF;
304  avio_r8(pb); // val_3
305  avio_r8(pb); // val_4
306  }
307  }
308 
309  avio_r8(pb); // num_streams
310 
311  off = avio_tell(pb);
312  off += ffio_read_varlen(pb); // val_5
313 
314  avio_r8(pb); // '2'
315  num_video = avio_r8(pb);
316 
317  avio_seek(pb, off, SEEK_SET);
318  if (num_video != 1) {
319  av_log(s, AV_LOG_ERROR, "number of video tracks %d is not 1\n", num_video);
320  return AVERROR_PATCHWELCOME;
321  }
322 
323  for (i = 0; i < num_video; i++) {
325 
326  st->id = i;
327 
330 
331  off = avio_tell(pb);
332  off += ffio_read_varlen(pb);
333  avio_r8(pb); // '3'
334  avio_r8(pb); // val_7
335  st->time_base.num = avio_rl32(pb); // frame_time
336  st->time_base.den = avio_rl32(pb); // time_base
337  st->nb_frames = avio_rl32(pb); // n frames
338  st->codecpar->width = avio_rl16(pb); // width
339  st->codecpar->height = avio_rl16(pb); // height
340  avio_r8(pb); // val_8
341  avio_rl32(pb); // val_9
342 
343  avio_seek(pb, off, SEEK_SET);
344  }
345 
346  off = avio_tell(pb);
347  off += ffio_read_varlen(pb); // val_10
348  avio_r8(pb); // '4'
349  viv->num_audio = avio_r8(pb);
350  avio_seek(pb, off, SEEK_SET);
351 
352  if (viv->num_audio != 1)
353  av_log(s, AV_LOG_WARNING, "number of audio tracks %d is not 1\n", viv->num_audio);
354 
355  for(i=0;i<viv->num_audio;i++) {
356  int q;
358 
359  st->id = num_video + i;
360 
363 
364  off = avio_tell(pb);
365  off += ffio_read_varlen(pb); // length
366  avio_r8(pb); // '5'
367  avio_r8(pb); //codec_id
368  avio_rl16(pb); //codec_subid
369  st->codecpar->channels = avio_rl16(pb); // channels
370  st->codecpar->sample_rate = avio_rl32(pb); // sample_rate
371  if (st->codecpar->sample_rate <= 0 || st->codecpar->channels <= 0)
372  return AVERROR_INVALIDDATA;
373  avio_seek(pb, 10, SEEK_CUR); // data_1
374  q = avio_r8(pb);
375  avio_seek(pb, q, SEEK_CUR); // data_2
376  avio_r8(pb); // zeropad
377 
378  if (avio_tell(pb) < off) {
379  int num_data;
380  int xd_size = 1;
381  int data_len[256];
382  int offset = 1;
383  uint8_t *p;
384  ffio_read_varlen(pb); // val_13
385  avio_r8(pb); // '19'
386  ffio_read_varlen(pb); // len_3
387  num_data = avio_r8(pb);
388  for (j = 0; j < num_data; j++) {
389  int64_t len = ffio_read_varlen(pb);
390  if (len < 0 || len > INT_MAX/2 - xd_size) {
391  av_free(pb);
392  return AVERROR_INVALIDDATA;
393  }
394  data_len[j] = len;
395  xd_size += len + 1 + len/255;
396  }
397 
398  if (ff_alloc_extradata(st->codecpar, xd_size)) {
399  av_free(pb);
400  return AVERROR(ENOMEM);
401  }
402 
403  p = st->codecpar->extradata;
404  p[0] = 2;
405 
406  for (j = 0; j < num_data - 1; j++) {
407  unsigned delta = av_xiphlacing(&p[offset], data_len[j]);
408  av_assert0(delta <= xd_size - offset);
409  offset += delta;
410  }
411 
412  for (j = 0; j < num_data; j++) {
413  int ret = avio_read(pb, &p[offset], data_len[j]);
414  if (ret < data_len[j]) {
415  st->codecpar->extradata_size = 0;
416  av_freep(&st->codecpar->extradata);
417  break;
418  }
419  av_assert0(data_len[j] <= xd_size - offset);
420  offset += data_len[j];
421  }
422 
423  if (offset < st->codecpar->extradata_size)
425  }
426  }
427 
428  av_free(pb);
429  return 0;
430 }
431 
433 {
434  int64_t off;
435  int64_t poff;
436  int maxnp=0;
437  AVIOContext *pb;
438  int i;
439  int64_t filesize = avio_size(s->pb);
440 
441  pb = avio_alloc_context(buf, size, 0, NULL, NULL, NULL, NULL);
442  if (!pb)
443  return AVERROR(ENOMEM);
444 
445  ffio_read_varlen(pb); // track_index_len
446  avio_r8(pb); // 'c'
447  viv->n_sb_blocks = ffio_read_varlen(pb);
448  if (viv->n_sb_blocks < 0 || viv->n_sb_blocks > size / 2)
449  goto error;
450  viv->sb_blocks = av_calloc(viv->n_sb_blocks, sizeof(VIV_SB_block));
451  if (!viv->sb_blocks) {
452  viv->n_sb_blocks = 0;
453  av_free(pb);
454  return AVERROR(ENOMEM);
455  }
456 
457  off = 0;
458  poff = 0;
459 
460  for (i = 0; i < viv->n_sb_blocks; i++) {
461  uint64_t size_tmp = ffio_read_varlen(pb);
462  uint64_t n_packets_tmp = ffio_read_varlen(pb);
463 
464  if (size_tmp > INT_MAX || n_packets_tmp > INT_MAX)
465  goto error;
466 
467  viv->sb_blocks[i].byte_offset = off;
468  viv->sb_blocks[i].packet_offset = poff;
469 
470  viv->sb_blocks[i].size = size_tmp;
471  viv->sb_blocks[i].n_packets = n_packets_tmp;
472 
473  off += viv->sb_blocks[i].size;
474  poff += viv->sb_blocks[i].n_packets;
475 
476  if (maxnp < viv->sb_blocks[i].n_packets)
477  maxnp = viv->sb_blocks[i].n_packets;
478  }
479 
480  if (filesize > 0 && poff > filesize)
481  goto error;
482 
483  viv->sb_entries = av_calloc(maxnp, sizeof(VIV_SB_entry));
484  av_free(pb);
485 
486  return 0;
487 error:
488  av_free(pb);
489  viv->n_sb_blocks = 0;
490  av_freep(&viv->sb_blocks);
491  return AVERROR_INVALIDDATA;
492 }
493 
494 static void load_sb_block(AVFormatContext *s, VividasDemuxContext *viv, unsigned expected_size)
495 {
496  uint32_t size = 0;
497  int i;
498  AVIOContext *pb = 0;
499 
500  if (viv->sb_pb) {
501  av_free(viv->sb_pb);
502  viv->sb_pb = NULL;
503  }
504 
505  if (viv->sb_buf)
506  av_free(viv->sb_buf);
507 
508  viv->sb_buf = read_sb_block(s->pb, &size, &viv->sb_key, expected_size);
509  if (!viv->sb_buf) {
510  return;
511  }
512 
513  pb = avio_alloc_context(viv->sb_buf, size, 0, NULL, NULL, NULL, NULL);
514  if (!pb)
515  return;
516 
517  viv->sb_pb = pb;
518 
519  avio_r8(pb); // 'S'
520  avio_r8(pb); // 'B'
521  ffio_read_varlen(pb); // size
522  avio_r8(pb); // junk
523  ffio_read_varlen(pb); // first packet
524 
525  viv->n_sb_entries = viv->sb_blocks[viv->current_sb].n_packets;
526 
527  for (i = 0; i < viv->n_sb_entries; i++) {
528  viv->sb_entries[i].size = ffio_read_varlen(pb);
529  viv->sb_entries[i].flag = avio_r8(pb);
530  }
531 
532  ffio_read_varlen(pb);
533  avio_r8(pb);
534 
535  viv->current_sb_entry = 0;
536 }
537 
539 {
540  VividasDemuxContext *viv = s->priv_data;
541  AVIOContext *pb = s->pb;
542  int64_t header_end;
543  int num_tracks;
544  uint32_t key, k2;
545  uint32_t v;
546  uint8_t keybuffer[187];
547  uint32_t b22_size = 0;
548  uint32_t b22_key = 0;
549  uint8_t *buf = 0;
550  int ret;
551 
552  avio_skip(pb, 9);
553 
554  header_end = avio_tell(pb);
555 
556  header_end += ffio_read_varlen(pb);
557 
558  num_tracks = avio_r8(pb);
559 
560  if (num_tracks != 1) {
561  av_log(s, AV_LOG_ERROR, "number of tracks %d is not 1\n", num_tracks);
562  return AVERROR(EINVAL);
563  }
564 
565  v = avio_r8(pb);
566  avio_seek(pb, v, SEEK_CUR);
567 
568  avio_read(pb, keybuffer, 187);
569  key = decode_key(keybuffer);
570  viv->sb_key = key;
571 
572  avio_rl32(pb);
573 
574  for (;;) {
575  int64_t here = avio_tell(pb);
576  int block_len, block_type;
577 
578  if (here >= header_end)
579  break;
580 
581  block_len = ffio_read_varlen(pb);
582  if (avio_feof(pb) || block_len <= 0)
583  return AVERROR_INVALIDDATA;
584 
585  block_type = avio_r8(pb);
586 
587  if (block_type == 22) {
588  avio_read(pb, keybuffer, 187);
589  b22_key = decode_key(keybuffer);
590  b22_size = avio_rl32(pb);
591  }
592 
593  avio_seek(pb, here + block_len, SEEK_SET);
594  }
595 
596  if (b22_size) {
597  k2 = b22_key;
598  buf = read_vblock(pb, &v, b22_key, &k2, 0);
599  if (!buf)
600  return AVERROR(EIO);
601 
602  av_free(buf);
603  }
604 
605  k2 = key;
606  buf = read_vblock(pb, &v, key, &k2, 0);
607  if (!buf)
608  return AVERROR(EIO);
609  ret = track_header(viv, s, buf, v);
610  av_free(buf);
611  if (ret < 0)
612  return ret;
613 
614  buf = read_vblock(pb, &v, key, &k2, v);
615  if (!buf)
616  return AVERROR(EIO);
617  ret = track_index(viv, s, buf, v);
618  av_free(buf);
619  if (ret < 0)
620  return ret;
621 
622  viv->sb_offset = avio_tell(pb);
623  if (viv->n_sb_blocks > 0) {
624  viv->current_sb = 0;
625  load_sb_block(s, viv, viv->sb_blocks[0].size);
626  } else {
627  viv->current_sb = -1;
628  }
629 
630  return 0;
631 }
632 
634  AVPacket *pkt)
635 {
636  VividasDemuxContext *viv = s->priv_data;
637  AVIOContext *pb;
638  int64_t off;
639  int ret;
640 
641  if (!viv->sb_pb)
642  return AVERROR(EIO);
643  if (avio_feof(viv->sb_pb))
644  return AVERROR_EOF;
645 
647  AVStream *astream;
649 
650  pb = viv->sb_pb;
651  ret = av_get_packet(pb, pkt, size);
652  if (ret < 0)
653  return ret;
654  pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
655 
656  pkt->stream_index = 1;
657  astream = s->streams[pkt->stream_index];
658 
659  pkt->pts = av_rescale(viv->audio_sample, astream->time_base.den, astream->time_base.num) / astream->codecpar->sample_rate;
663  return 0;
664  }
665 
666  if (viv->current_sb_entry >= viv->n_sb_entries) {
667  if (viv->current_sb+1 >= viv->n_sb_blocks)
668  return AVERROR(EIO);
669  viv->current_sb++;
670 
671  load_sb_block(s, viv, 0);
672  viv->current_sb_entry = 0;
673  }
674 
675  pb = viv->sb_pb;
676  if (!pb)
677  return AVERROR(EIO);
678  off = avio_tell(pb);
679 
680  if (viv->current_sb_entry >= viv->n_sb_entries)
681  return AVERROR_INVALIDDATA;
682 
683  off += viv->sb_entries[viv->current_sb_entry].size;
684 
685  if (viv->sb_entries[viv->current_sb_entry].flag == 0) {
686  uint64_t v_size = ffio_read_varlen(pb);
687 
688  if (!viv->num_audio)
689  return AVERROR_INVALIDDATA;
690 
691  ffio_read_varlen(pb);
692  if (v_size > INT_MAX || !v_size)
693  return AVERROR_INVALIDDATA;
694  ret = av_get_packet(pb, pkt, v_size);
695  if (ret < 0)
696  return ret;
697  pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
698 
700  pkt->flags |= (pkt->data[0]&0x80)?0:AV_PKT_FLAG_KEY;
701  pkt->stream_index = 0;
702 
703  for (int i = 0; i < MAX_AUDIO_SUBPACKETS - 1; i++) {
704  int start, pcm_bytes;
705  start = ffio_read_varlen(pb);
706  pcm_bytes = ffio_read_varlen(pb);
707 
708  if (i > 0 && start == 0)
709  break;
710 
711  viv->n_audio_subpackets = i + 1;
712  viv->audio_subpackets[i].start = start;
713  viv->audio_subpackets[i].pcm_bytes = pcm_bytes;
714  }
715  viv->audio_subpackets[viv->n_audio_subpackets].start = (int)(off - avio_tell(pb));
716  viv->current_audio_subpacket = 0;
717 
718  } else {
719  uint64_t v_size = ffio_read_varlen(pb);
720 
721  if (v_size > INT_MAX || !v_size)
722  return AVERROR_INVALIDDATA;
723  ret = av_get_packet(pb, pkt, v_size);
724  if (ret < 0)
725  return ret;
726  pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
728  pkt->flags |= (pkt->data[0] & 0x80) ? 0 : AV_PKT_FLAG_KEY;
729  pkt->stream_index = 0;
730  }
731 
732  viv->current_sb_entry++;
733 
734  return 0;
735 }
736 
738 {
739  VividasDemuxContext *viv = s->priv_data;
740 
741  av_freep(&viv->sb_pb);
742  av_freep(&viv->sb_buf);
743  av_freep(&viv->sb_blocks);
744  av_freep(&viv->sb_entries);
745 
746  return 0;
747 }
748 
749 static int viv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
750 {
751  VividasDemuxContext *viv = s->priv_data;
752  int64_t frame;
753 
754  if (stream_index == 0)
755  frame = timestamp;
756  else
757  frame = av_rescale_q(timestamp, s->streams[0]->time_base, s->streams[stream_index]->time_base);
758 
759  for (int i = 0; i < viv->n_sb_blocks; i++) {
760  if (frame >= viv->sb_blocks[i].packet_offset && frame < viv->sb_blocks[i].packet_offset + viv->sb_blocks[i].n_packets) {
761  // flush audio packet queue
762  viv->current_audio_subpacket = 0;
763  viv->n_audio_subpackets = 0;
764  viv->current_sb = i;
765  // seek to ith sb block
766  avio_seek(s->pb, viv->sb_offset + viv->sb_blocks[i].byte_offset, SEEK_SET);
767  // load the block
768  load_sb_block(s, viv, 0);
769  // most problematic part: guess audio offset
770  viv->audio_sample = av_rescale_q(viv->sb_blocks[i].packet_offset, av_make_q(s->streams[1]->codecpar->sample_rate, 1), av_inv_q(s->streams[0]->time_base));
771  // hand-tuned 1.s a/v offset
772  viv->audio_sample += s->streams[1]->codecpar->sample_rate;
773  viv->current_sb_entry = 0;
774  return 1;
775  }
776  }
777  return 0;
778 }
779 
781  .name = "vividas",
782  .long_name = NULL_IF_CONFIG_SMALL("Vividas VIV"),
783  .priv_data_size = sizeof(VividasDemuxContext),
789 };
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
put_v
static void put_v(uint8_t *p, unsigned v)
Definition: vividas.c:102
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3971
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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. Frame references ownership and permissions
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4480
av_xiphlacing
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
Definition: utils.c:1803
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3953
n
int n
Definition: avisynth_c.h:760
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:252
track_index
static int track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *buf, unsigned size)
Definition: vividas.c:432
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
VividasDemuxContext::sb_buf
uint8_t * sb_buf
Definition: vividas.c:62
AVPacket::data
uint8_t * data
Definition: avcodec.h:1477
AV_CODEC_ID_VP6
@ AV_CODEC_ID_VP6
Definition: avcodec.h:309
VividasDemuxContext::current_sb_entry
int current_sb_entry
Definition: vividas.c:61
VIV_SB_block
Definition: vividas.c:39
VividasDemuxContext::audio_sample
int64_t audio_sample
Definition: vividas.c:70
VIV_SB_block::byte_offset
int64_t byte_offset
Definition: vividas.c:41
VividasDemuxContext::current_audio_subpacket
int current_audio_subpacket
Definition: vividas.c:68
get_v
static uint32_t get_v(uint8_t *p, int len)
Definition: vividas.c:182
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:336
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1509
VividasDemuxContext::n_sb_blocks
int n_sb_blocks
Definition: vividas.c:54
read_vblock
static uint8_t * read_vblock(AVIOContext *src, uint32_t *size, uint32_t key, uint32_t *k2, int align)
Definition: vividas.c:197
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
recover_key
static unsigned recover_key(unsigned char sample[4], unsigned expected_size)
Definition: vividas.c:114
decode_block
static void decode_block(uint8_t *src, uint8_t *dest, unsigned size, uint32_t key, uint32_t *key_ptr, int align)
Definition: vividas.c:142
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:458
AVCodecParameters::channels
int channels
Audio only.
Definition: avcodec.h:4063
VIV_AudioSubpacket::start
int start
Definition: vividas.c:50
start
void INT64 start
Definition: avisynth_c.h:767
read_seek
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
viv_read_header
static int viv_read_header(AVFormatContext *s)
Definition: vividas.c:538
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
VividasDemuxContext::num_audio
int num_audio
Definition: vividas.c:56
VividasDemuxContext::current_sb
int current_sb
Definition: vividas.c:61
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:753
AVRational::num
int num
Numerator.
Definition: rational.h:59
src
#define src
Definition: vp8dsp.c:254
av_bswap32
#define av_bswap32
Definition: bswap.h:33
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
buf
void * buf
Definition: avisynth_c.h:766
AVInputFormat
Definition: avformat.h:640
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
ff_vividas_demuxer
AVInputFormat ff_vividas_demuxer
Definition: vividas.c:780
viv_read_seek
static int viv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: vividas.c:749
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:645
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:448
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: avcodec.h:4023
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
VIV_SB_entry
Definition: vividas.c:45
key
const char * key
Definition: hwcontext_opencl.c:168
AVFormatContext
Format I/O context.
Definition: avformat.h:1342
VIV_SB_entry::size
int size
Definition: vividas.c:46
internal.h
VividasDemuxContext::audio_subpackets
VIV_AudioSubpacket audio_subpackets[MAX_AUDIO_SUBPACKETS]
Definition: vividas.c:72
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1017
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:530
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:899
NULL
#define NULL
Definition: coverity.c:32
VIV_AudioSubpacket
Definition: vividas.c:49
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
read_sb_block
static uint8_t * read_sb_block(AVIOContext *src, unsigned *size, uint32_t *key, unsigned expected_size)
Definition: vividas.c:232
read_probe
static int read_probe(const AVProbeData *pd)
Definition: jvdec.c:55
VIV_SB_block::n_packets
int n_packets
Definition: vividas.c:40
xor_block
static void xor_block(void *p1, void *p2, unsigned size, int key, unsigned *key_ptr)
Definition: vividas.c:123
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:446
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: avcodec.h:4067
error
static void error(const char *err)
Definition: target_dec_fuzzer.c:61
AVStream::nb_frames
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:921
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3975
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:769
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
plaintext
static const uint8_t plaintext[8]
Definition: blowfish.c:112
sample
#define sample
Definition: flacdsp_template.c:44
size
int size
Definition: twinvq_data.h:11134
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:638
VIV_SB_entry::flag
int flag
Definition: vividas.c:46
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1483
ffio_read_varlen
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition: aviobuf.c:929
VIV_SB_block::size
int size
Definition: vividas.c:40
MAX_AUDIO_SUBPACKETS
#define MAX_AUDIO_SUBPACKETS
Definition: vividas.c:37
load_sb_block
static void load_sb_block(AVFormatContext *s, VividasDemuxContext *viv, unsigned expected_size)
Definition: vividas.c:494
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1470
VividasDemuxContext::sb_key
uint32_t sb_key
Definition: vividas.c:58
avio_internal.h
AVCodecParameters::height
int height
Definition: avcodec.h:4024
decode_key
static uint32_t decode_key(uint8_t *buf)
Definition: vividas.c:90
VividasDemuxContext
Definition: vividas.c:53
VIV_SB_block::packet_offset
int64_t packet_offset
Definition: vividas.c:42
a2
#define a2
Definition: regdef.h:48
delta
float delta
Definition: vorbis_enc_data.h:457
avio_alloc_context
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
Definition: aviobuf.c:131
viv_probe
static int viv_probe(const AVProbeData *p)
Definition: vividas.c:75
uint8_t
uint8_t
Definition: audio_convert.c:194
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
track_header
static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *buf, int size)
Definition: vividas.c:280
len
int len
Definition: vorbis_enc_data.h:452
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
av_get_packet
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:313
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:877
ret
ret
Definition: filter_design.txt:187
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVStream
Stream structure.
Definition: avformat.h:870
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:246
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
keybits
static const uint8_t keybits[32]
Definition: vividas.c:83
align
const AVS_VideoInfo int align
Definition: avisynth_c.h:887
avformat.h
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:88
viv_read_packet
static int viv_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: vividas.c:633
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
AVRational::den
int den
Denominator.
Definition: rational.h:60
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:647
VividasDemuxContext::n_audio_subpackets
int n_audio_subpackets
Definition: vividas.c:67
AVPacket::stream_index
int stream_index
Definition: avcodec.h:1479
VividasDemuxContext::n_sb_entries
int n_sb_entries
Definition: vividas.c:64
VividasDemuxContext::sb_pb
AVIOContext * sb_pb
Definition: vividas.c:63
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:331
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
VividasDemuxContext::sb_offset
int64_t sb_offset
Definition: vividas.c:59
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:39
VIV_AudioSubpacket::pcm_bytes
int pcm_bytes
Definition: vividas.c:50
VividasDemuxContext::sb_entries
VIV_SB_entry * sb_entries
Definition: vividas.c:65
viv_read_close
static int viv_read_close(AVFormatContext *s)
Definition: vividas.c:737
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
VividasDemuxContext::sb_blocks
VIV_SB_block * sb_blocks
Definition: vividas.c:55
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3957
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1454
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1497
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
AV_CODEC_ID_VORBIS
@ AV_CODEC_ID_VORBIS
Definition: avcodec.h:569
int
int
Definition: ffmpeg_filter.c:191
ff_alloc_extradata
int ff_alloc_extradata(AVCodecParameters *par, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0.
Definition: utils.c:3309
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:358