FFmpeg  4.2.1
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/intreadwrite.h"
32 #include "avio_internal.h"
33 #include "avformat.h"
34 #include "internal.h"
35 
36 #define MAX_AUDIO_SUBPACKETS 100
37 
38 typedef struct VIV_SB_block {
40  int64_t byte_offset;
41  int64_t packet_offset;
42 } VIV_SB_block;
43 
44 typedef struct VIV_SB_entry {
45  int size, flag;
46 } VIV_SB_entry;
47 
48 typedef struct VIV_AudioSubpacket {
49  int start, pcm_bytes;
51 
52 typedef struct VividasDemuxContext {
55 
56  uint32_t sb_key;
57  int64_t sb_offset;
58 
59  int current_sb, current_sb_entry;
64 
67 
68  int64_t audio_sample;
69 
72 
73 static int viv_probe(const AVProbeData *p)
74 {
75  if (memcmp(p->buf, "vividas03", 9))
76  return 0;
77 
78  return AVPROBE_SCORE_MAX;
79 }
80 
81 static const uint8_t keybits[32] = {
82  20, 52, 111, 10, 27, 71, 142, 53,
83  82, 138, 1, 78, 86, 121, 183, 85,
84 105, 152, 39, 140, 172, 11, 64, 144,
85 155, 6, 71, 163, 186, 49, 126, 43,
86 };
87 
88 static uint32_t decode_key(uint8_t *buf)
89 {
90  uint32_t key = 0;
91 
92  for (int i = 0; i < 32; i++) {
93  unsigned p = keybits[i];
94  key |= ((buf[p] >> ((i*5+3)&7)) & 1u) << i;
95  }
96 
97  return key;
98 }
99 
100 static void put_v(uint8_t *p, unsigned v)
101 {
102  if (v>>28)
103  *p++ = ((v>>28)&0x7f)|0x80;
104  if (v>>21)
105  *p++ = ((v>>21)&0x7f)|0x80;
106  if (v>>14)
107  *p++ = ((v>>14)&0x7f)|0x80;
108  if (v>>7)
109  *p++ = ((v>>7)&0x7f)|0x80;
110 }
111 
112 static unsigned recover_key(unsigned char sample[4], unsigned expected_size)
113 {
114  unsigned char plaintext[8] = { 'S', 'B' };
115 
116  put_v(plaintext+2, expected_size);
117 
118  return AV_RL32(sample) ^ AV_RL32(plaintext);
119 }
120 
121 static void xor_block(void *p1, void *p2, unsigned size, int key, unsigned *key_ptr)
122 {
123  unsigned *d1 = p1;
124  unsigned *d2 = p2;
125  unsigned k = *key_ptr;
126 
127  size >>= 2;
128 
129  while (size > 0) {
130  *d2 = *d1 ^ (HAVE_BIGENDIAN ? av_bswap32(k) : k);
131  k += key;
132  d1++;
133  d2++;
134  size--;
135  }
136 
137  *key_ptr = k;
138 }
139 
140 static void decode_block(uint8_t *src, uint8_t *dest, unsigned size,
141  uint32_t key, uint32_t *key_ptr,
142  int align)
143 {
144  unsigned s = size;
145  char tmp[4];
146  int a2;
147 
148  if (!size)
149  return;
150 
151  align &= 3;
152  a2 = (4 - align) & 3;
153 
154  if (align) {
155  uint32_t tmpkey = *key_ptr - key;
156  if (a2 > s) {
157  a2 = s;
158  avpriv_request_sample(NULL, "tiny aligned block\n");
159  }
160  memcpy(tmp + align, src, a2);
161  xor_block(tmp, tmp, 4, key, &tmpkey);
162  memcpy(dest, tmp + align, a2);
163  s -= a2;
164  }
165 
166  if (s >= 4) {
167  if (!align)
168  align = 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 + 4);
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, num_audio;
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  for (j=0;j<c;j++) {
300  avio_r8(pb); // val_3
301  avio_r8(pb); // val_4
302  }
303  }
304 
305  avio_r8(pb); // num_streams
306 
307  off = avio_tell(pb);
308  off += ffio_read_varlen(pb); // val_5
309 
310  avio_r8(pb); // '2'
311  num_video = avio_r8(pb);
312 
313  avio_seek(pb, off, SEEK_SET);
314  if (num_video != 1)
315  av_log(s, AV_LOG_WARNING, "number of video tracks %d is not 1\n", num_video);
316 
317  for (i = 0; i < num_video; i++) {
319 
320  st->id = i;
321 
324 
325  off = avio_tell(pb);
326  off += ffio_read_varlen(pb);
327  avio_r8(pb); // '3'
328  avio_r8(pb); // val_7
329  st->time_base.num = avio_rl32(pb); // frame_time
330  st->time_base.den = avio_rl32(pb); // time_base
331  st->nb_frames = avio_rl32(pb); // n frames
332  st->codecpar->width = avio_rl16(pb); // width
333  st->codecpar->height = avio_rl16(pb); // height
334  avio_r8(pb); // val_8
335  avio_rl32(pb); // val_9
336 
337  avio_seek(pb, off, SEEK_SET);
338  }
339 
340  off = avio_tell(pb);
341  off += ffio_read_varlen(pb); // val_10
342  avio_r8(pb); // '4'
343  num_audio = avio_r8(pb);
344  avio_seek(pb, off, SEEK_SET);
345 
346  if (num_audio != 1)
347  av_log(s, AV_LOG_WARNING, "number of audio tracks %d is not 1\n", num_audio);
348 
349  for(i=0;i<num_audio;i++) {
350  int q;
352 
353  st->id = num_video + i;
354 
357 
358  off = avio_tell(pb);
359  off += ffio_read_varlen(pb); // length
360  avio_r8(pb); // '5'
361  avio_r8(pb); //codec_id
362  avio_rl16(pb); //codec_subid
363  st->codecpar->channels = avio_rl16(pb); // channels
364  st->codecpar->sample_rate = avio_rl32(pb); // sample_rate
365  avio_seek(pb, 10, SEEK_CUR); // data_1
366  q = avio_r8(pb);
367  avio_seek(pb, q, SEEK_CUR); // data_2
368  avio_r8(pb); // zeropad
369 
370  if (avio_tell(pb) < off) {
371  int num_data;
372  int xd_size = 0;
373  int data_len[256];
374  int offset = 1;
375  uint8_t *p;
376  ffio_read_varlen(pb); // val_13
377  avio_r8(pb); // '19'
378  ffio_read_varlen(pb); // len_3
379  num_data = avio_r8(pb);
380  for (j = 0; j < num_data; j++) {
381  uint64_t len = ffio_read_varlen(pb);
382  if (len > INT_MAX/2 - xd_size) {
383  av_free(pb);
384  return AVERROR_INVALIDDATA;
385  }
386  data_len[j] = len;
387  xd_size += len;
388  }
389 
390  st->codecpar->extradata_size = 64 + xd_size + xd_size / 255;
392  av_free(pb);
393  return AVERROR(ENOMEM);
394  }
395 
396  p = st->codecpar->extradata;
397  p[0] = 2;
398 
399  for (j = 0; j < num_data - 1; j++) {
400  unsigned delta = av_xiphlacing(&p[offset], data_len[j]);
401  if (delta > data_len[j]) {
402  av_free(pb);
403  return AVERROR_INVALIDDATA;
404  }
405  offset += delta;
406  }
407 
408  for (j = 0; j < num_data; j++) {
409  int ret = avio_read(pb, &p[offset], data_len[j]);
410  if (ret < data_len[j]) {
411  st->codecpar->extradata_size = 0;
412  av_freep(&st->codecpar->extradata);
413  break;
414  }
415  offset += data_len[j];
416  }
417 
418  if (offset < st->codecpar->extradata_size)
420  }
421  }
422 
423  av_free(pb);
424  return 0;
425 }
426 
428 {
429  int64_t off;
430  int64_t poff;
431  int maxnp=0;
432  AVIOContext *pb;
433  int i;
434 
435  pb = avio_alloc_context(buf, size, 0, NULL, NULL, NULL, NULL);
436  if (!pb)
437  return;
438 
439  ffio_read_varlen(pb); // track_index_len
440  avio_r8(pb); // 'c'
441  viv->n_sb_blocks = ffio_read_varlen(pb);
442  viv->sb_blocks = av_calloc(viv->n_sb_blocks, sizeof(VIV_SB_block));
443  if (!viv->sb_blocks) {
444  viv->n_sb_blocks = 0;
445  av_free(pb);
446  return;
447  }
448 
449  off = 0;
450  poff = 0;
451 
452  for (i = 0; i < viv->n_sb_blocks; i++) {
453  viv->sb_blocks[i].byte_offset = off;
454  viv->sb_blocks[i].packet_offset = poff;
455 
456  viv->sb_blocks[i].size = ffio_read_varlen(pb);
458 
459  off += viv->sb_blocks[i].size;
460  poff += viv->sb_blocks[i].n_packets;
461 
462 
463  if (maxnp < viv->sb_blocks[i].n_packets)
464  maxnp = viv->sb_blocks[i].n_packets;
465  }
466 
467  viv->sb_entries = av_calloc(maxnp, sizeof(VIV_SB_entry));
468  av_free(pb);
469 }
470 
471 static void load_sb_block(AVFormatContext *s, VividasDemuxContext *viv, unsigned expected_size)
472 {
473  uint32_t size = 0;
474  int i;
475  AVIOContext *pb = 0;
476 
477  if (viv->sb_pb) {
478  av_free(viv->sb_pb);
479  viv->sb_pb = NULL;
480  }
481 
482  if (viv->sb_buf)
483  av_free(viv->sb_buf);
484 
485  viv->sb_buf = read_sb_block(s->pb, &size, &viv->sb_key, expected_size);
486  if (!viv->sb_buf) {
487  return;
488  }
489 
490  pb = avio_alloc_context(viv->sb_buf, size, 0, NULL, NULL, NULL, NULL);
491  if (!pb)
492  return;
493 
494  viv->sb_pb = pb;
495 
496  avio_r8(pb); // 'S'
497  avio_r8(pb); // 'B'
498  ffio_read_varlen(pb); // size
499  avio_r8(pb); // junk
500  ffio_read_varlen(pb); // first packet
501 
502  viv->n_sb_entries = viv->sb_blocks[viv->current_sb].n_packets;
503 
504  for (i = 0; i < viv->n_sb_entries; i++) {
505  viv->sb_entries[i].size = ffio_read_varlen(pb);
506  viv->sb_entries[i].flag = avio_r8(pb);
507  }
508 
509  ffio_read_varlen(pb);
510  avio_r8(pb);
511 
512  viv->current_sb_entry = 0;
513 }
514 
516 {
517  VividasDemuxContext *viv = s->priv_data;
518  AVIOContext *pb = s->pb;
519  int64_t header_end;
520  int num_tracks;
521  uint32_t key, k2;
522  uint32_t v;
523  uint8_t keybuffer[187];
524  uint32_t b22_size = 0;
525  uint32_t b22_key = 0;
526  uint8_t *buf = 0;
527  int ret;
528 
529  avio_skip(pb, 9);
530 
531  header_end = avio_tell(pb);
532 
533  header_end += ffio_read_varlen(pb);
534 
535  num_tracks = avio_r8(pb);
536 
537  if (num_tracks != 1) {
538  av_log(s, AV_LOG_ERROR, "number of tracks %d is not 1\n", num_tracks);
539  return AVERROR(EINVAL);
540  }
541 
542  v = avio_r8(pb);
543  avio_seek(pb, v, SEEK_CUR);
544 
545  avio_read(pb, keybuffer, 187);
546  key = decode_key(keybuffer);
547  viv->sb_key = key;
548 
549  avio_rl32(pb);
550 
551  for (;;) {
552  int64_t here = avio_tell(pb);
553  int block_len, block_type;
554 
555  if (here >= header_end)
556  break;
557 
558  block_len = ffio_read_varlen(pb);
559  if (avio_feof(pb) || block_len <= 0)
560  return AVERROR_INVALIDDATA;
561 
562  block_type = avio_r8(pb);
563 
564  if (block_type == 22) {
565  avio_read(pb, keybuffer, 187);
566  b22_key = decode_key(keybuffer);
567  b22_size = avio_rl32(pb);
568  }
569 
570  avio_seek(pb, here + block_len, SEEK_SET);
571  }
572 
573  if (b22_size) {
574  k2 = b22_key;
575  buf = read_vblock(pb, &v, b22_key, &k2, 0);
576  if (!buf)
577  return AVERROR(EIO);
578 
579  av_free(buf);
580  }
581 
582  k2 = key;
583  buf = read_vblock(pb, &v, key, &k2, 0);
584  if (!buf)
585  return AVERROR(EIO);
586  ret = track_header(viv, s, buf, v);
587  av_free(buf);
588  if (ret < 0)
589  return ret;
590 
591  buf = read_vblock(pb, &v, key, &k2, v);
592  if (!buf)
593  return AVERROR(EIO);
594  track_index(viv, s, buf, v);
595  av_free(buf);
596 
597  viv->sb_offset = avio_tell(pb);
598  if (viv->n_sb_blocks > 0) {
599  viv->current_sb = 0;
600  load_sb_block(s, viv, viv->sb_blocks[0].size);
601  } else {
602  viv->current_sb = -1;
603  }
604 
605  return 0;
606 }
607 
609  AVPacket *pkt)
610 {
611  VividasDemuxContext *viv = s->priv_data;
612  AVIOContext *pb;
613  int64_t off;
614  int ret;
615 
616  if (!viv->sb_pb)
617  return AVERROR(EIO);
618  if (avio_feof(viv->sb_pb))
619  return AVERROR_EOF;
620 
622  AVStream *astream;
624 
625  pb = viv->sb_pb;
626  ret = av_get_packet(pb, pkt, size);
627  if (ret < 0)
628  return ret;
629  pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
630 
631  pkt->stream_index = 1;
632  astream = s->streams[pkt->stream_index];
633 
634  pkt->pts = av_rescale(viv->audio_sample, astream->time_base.den, astream->time_base.num) / astream->codecpar->sample_rate;
636  pkt->flags |= AV_PKT_FLAG_KEY;
638  return 0;
639  }
640 
641  if (viv->current_sb_entry >= viv->n_sb_entries) {
642  if (viv->current_sb+1 >= viv->n_sb_blocks)
643  return AVERROR(EIO);
644  viv->current_sb++;
645 
646  load_sb_block(s, viv, 0);
647  viv->current_sb_entry = 0;
648  }
649 
650  pb = viv->sb_pb;
651  if (!pb)
652  return AVERROR(EIO);
653  off = avio_tell(pb);
654  off += viv->sb_entries[viv->current_sb_entry].size;
655 
656  if (viv->sb_entries[viv->current_sb_entry].flag == 0) {
657  uint64_t v_size = ffio_read_varlen(pb);
658 
659  ffio_read_varlen(pb);
660  if (v_size > INT_MAX)
661  return AVERROR_INVALIDDATA;
662  ret = av_get_packet(pb, pkt, v_size);
663  if (ret < 0)
664  return ret;
665  pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
666 
667  pkt->pts = viv->sb_blocks[viv->current_sb].packet_offset + viv->current_sb_entry;
668  pkt->flags |= (pkt->data[0]&0x80)?0:AV_PKT_FLAG_KEY;
669  pkt->stream_index = 0;
670 
671  for (int i = 0; i < MAX_AUDIO_SUBPACKETS - 1; i++) {
672  int start, pcm_bytes;
673  start = ffio_read_varlen(pb);
674  pcm_bytes = ffio_read_varlen(pb);
675 
676  if (i > 0 && start == 0)
677  break;
678 
679  viv->n_audio_subpackets = i + 1;
680  viv->audio_subpackets[i].start = start;
681  viv->audio_subpackets[i].pcm_bytes = pcm_bytes;
682  }
683  viv->audio_subpackets[viv->n_audio_subpackets].start = (int)(off - avio_tell(pb));
684  viv->current_audio_subpacket = 0;
685 
686  } else {
687  uint64_t v_size = ffio_read_varlen(pb);
688 
689  if (v_size > INT_MAX)
690  return AVERROR_INVALIDDATA;
691  ret = av_get_packet(pb, pkt, v_size);
692  if (ret < 0)
693  return ret;
694  pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
695  pkt->pts = viv->sb_blocks[viv->current_sb].packet_offset + viv->current_sb_entry;
696  pkt->flags |= (pkt->data[0] & 0x80) ? 0 : AV_PKT_FLAG_KEY;
697  pkt->stream_index = 0;
698  }
699 
700  viv->current_sb_entry++;
701 
702  return 0;
703 }
704 
706 {
707  VividasDemuxContext *viv = s->priv_data;
708 
709  av_freep(&viv->sb_pb);
710  av_freep(&viv->sb_buf);
711  av_freep(&viv->sb_blocks);
712  av_freep(&viv->sb_entries);
713 
714  return 0;
715 }
716 
717 static int viv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
718 {
719  VividasDemuxContext *viv = s->priv_data;
720  int64_t frame;
721 
722  if (stream_index == 0)
723  frame = timestamp;
724  else
725  frame = av_rescale_q(timestamp, s->streams[0]->time_base, s->streams[stream_index]->time_base);
726 
727  for (int i = 0; i < viv->n_sb_blocks; i++) {
728  if (frame >= viv->sb_blocks[i].packet_offset && frame < viv->sb_blocks[i].packet_offset + viv->sb_blocks[i].n_packets) {
729  // flush audio packet queue
730  viv->current_audio_subpacket = 0;
731  viv->n_audio_subpackets = 0;
732  viv->current_sb = i;
733  // seek to ith sb block
734  avio_seek(s->pb, viv->sb_offset + viv->sb_blocks[i].byte_offset, SEEK_SET);
735  // load the block
736  load_sb_block(s, viv, 0);
737  // most problematic part: guess audio offset
739  // hand-tuned 1.s a/v offset
740  viv->audio_sample += s->streams[1]->codecpar->sample_rate;
741  viv->current_sb_entry = 0;
742  return 1;
743  }
744  }
745  return 0;
746 }
747 
749  .name = "vividas",
750  .long_name = NULL_IF_CONFIG_SMALL("Vividas VIV"),
751  .priv_data_size = sizeof(VividasDemuxContext),
757 };
#define NULL
Definition: coverity.c:32
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition: aviobuf.c:929
static uint8_t * read_vblock(AVIOContext *src, uint32_t *size, uint32_t key, uint32_t *k2, int align)
Definition: vividas.c:197
Bytestream IO Context.
Definition: avio.h:161
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static uint32_t get_v(uint8_t *p, int len)
Definition: vividas.c:182
static void decode_block(uint8_t *src, uint8_t *dest, unsigned size, uint32_t key, uint32_t *key_ptr, int align)
Definition: vividas.c:140
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1497
int64_t packet_offset
Definition: vividas.c:41
#define avpriv_request_sample(...)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3957
int num
Numerator.
Definition: rational.h:59
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:246
int n_audio_subpackets
Definition: vividas.c:65
static unsigned recover_key(unsigned char sample[4], unsigned expected_size)
Definition: vividas.c:112
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:331
int size
Definition: vividas.c:45
const char * key
static AVPacket pkt
#define src
Definition: vp8dsp.c:254
#define sample
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
Format I/O context.
Definition: avformat.h:1358
Definition: vividas.c:44
uint8_t
#define av_malloc(s)
int width
Video only.
Definition: avcodec.h:4023
float delta
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
int id
Format-specific stream ID.
Definition: avformat.h:888
VIV_SB_block * sb_blocks
Definition: vividas.c:54
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4459
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:252
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1426
static AVFrame * frame
int flag
Definition: vividas.c:45
uint8_t * data
Definition: avcodec.h:1477
#define AVERROR_EOF
End of file.
Definition: error.h:55
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
uint32_t sb_key
Definition: vividas.c:56
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:310
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
#define av_log(a,...)
AVIOContext * sb_pb
Definition: vividas.c:61
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:647
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1509
static const uint8_t plaintext[8]
Definition: blowfish.c:112
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
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
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static uint8_t * read_sb_block(AVIOContext *src, unsigned *size, uint32_t *key, unsigned expected_size)
Definition: vividas.c:232
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:769
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3953
static int viv_read_header(AVFormatContext *s)
Definition: vividas.c:515
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
int64_t sb_offset
Definition: vividas.c:57
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1483
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3975
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:638
VIV_SB_entry * sb_entries
Definition: vividas.c:63
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:448
static int viv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: vividas.c:717
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:3288
AVInputFormat ff_vividas_demuxer
Definition: vividas.c:748
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
static void xor_block(void *p1, void *p2, unsigned size, int key, unsigned *key_ptr)
Definition: vividas.c:121
#define a2
Definition: regdef.h:48
#define s(width, name)
Definition: cbs_vp9.c:257
#define AV_RL32
Definition: intreadwrite.h:146
int n
Definition: avisynth_c.h:760
static void track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *buf, unsigned size)
Definition: vividas.c:427
#define MAX_AUDIO_SUBPACKETS
Definition: vividas.c:36
int current_audio_subpacket
Definition: vividas.c:66
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:530
Stream structure.
Definition: avformat.h:881
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
const AVS_VideoInfo int align
Definition: avisynth_c.h:887
#define av_bswap32
Definition: bswap.h:33
AVIOContext * pb
I/O context.
Definition: avformat.h:1400
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
static uint32_t decode_key(uint8_t *buf)
Definition: vividas.c:88
void * buf
Definition: avisynth_c.h:766
int64_t audio_sample
Definition: vividas.c:68
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
Definition: utils.c:1744
int n_packets
Definition: vividas.c:39
static int viv_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: vividas.c:608
This structure contains the data a format has to probe a file.
Definition: avformat.h:446
#define flags(name, subs,...)
Definition: cbs_av1.c:561
static int read_probe(const AVProbeData *pd)
Definition: jvdec.c:55
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
int sample_rate
Audio only.
Definition: avcodec.h:4067
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:458
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:753
Main libavformat public API header.
int
static void load_sb_block(AVFormatContext *s, VividasDemuxContext *viv, unsigned expected_size)
Definition: vividas.c:471
#define flag(name)
Definition: cbs_av1.c:553
static double c[64]
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:932
uint8_t * sb_buf
Definition: vividas.c:60
int den
Denominator.
Definition: rational.h:60
static int viv_read_close(AVFormatContext *s)
Definition: vividas.c:705
static int viv_probe(const AVProbeData *p)
Definition: vividas.c:73
#define av_free(p)
int len
void * priv_data
Format private data.
Definition: avformat.h:1386
static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *buf, int size)
Definition: vividas.c:280
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3971
int channels
Audio only.
Definition: avcodec.h:4063
static const uint8_t keybits[32]
Definition: vividas.c:81
#define av_freep(p)
VIV_AudioSubpacket audio_subpackets[MAX_AUDIO_SUBPACKETS]
Definition: vividas.c:70
void INT64 start
Definition: avisynth_c.h:766
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:654
int size
Definition: vividas.c:39
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1028
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:358
#define HAVE_BIGENDIAN
Definition: config.h:199
int stream_index
Definition: avcodec.h:1479
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:910
This structure stores compressed data.
Definition: avcodec.h:1454
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1470
static void put_v(uint8_t *p, unsigned v)
Definition: vividas.c:100
int64_t byte_offset
Definition: vividas.c:40
static uint8_t tmp[11]
Definition: aes_ctr.c:26