FFmpeg  4.2.2
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  int num_audio;
56 
57  uint32_t sb_key;
58  int64_t sb_offset;
59 
60  int current_sb, current_sb_entry;
65 
68 
69  int64_t audio_sample;
70 
73 
74 static int viv_probe(const AVProbeData *p)
75 {
76  if (memcmp(p->buf, "vividas03", 9))
77  return 0;
78 
79  return AVPROBE_SCORE_MAX;
80 }
81 
82 static const uint8_t keybits[32] = {
83  20, 52, 111, 10, 27, 71, 142, 53,
84  82, 138, 1, 78, 86, 121, 183, 85,
85 105, 152, 39, 140, 172, 11, 64, 144,
86 155, 6, 71, 163, 186, 49, 126, 43,
87 };
88 
89 static uint32_t decode_key(uint8_t *buf)
90 {
91  uint32_t key = 0;
92 
93  for (int i = 0; i < 32; i++) {
94  unsigned p = keybits[i];
95  key |= ((buf[p] >> ((i*5+3)&7)) & 1u) << i;
96  }
97 
98  return key;
99 }
100 
101 static void put_v(uint8_t *p, unsigned v)
102 {
103  if (v>>28)
104  *p++ = ((v>>28)&0x7f)|0x80;
105  if (v>>21)
106  *p++ = ((v>>21)&0x7f)|0x80;
107  if (v>>14)
108  *p++ = ((v>>14)&0x7f)|0x80;
109  if (v>>7)
110  *p++ = ((v>>7)&0x7f)|0x80;
111 }
112 
113 static unsigned recover_key(unsigned char sample[4], unsigned expected_size)
114 {
115  unsigned char plaintext[8] = { 'S', 'B' };
116 
117  put_v(plaintext+2, expected_size);
118 
119  return AV_RL32(sample) ^ AV_RL32(plaintext);
120 }
121 
122 static void xor_block(void *p1, void *p2, unsigned size, int key, unsigned *key_ptr)
123 {
124  unsigned *d1 = p1;
125  unsigned *d2 = p2;
126  unsigned k = *key_ptr;
127 
128  size >>= 2;
129 
130  while (size > 0) {
131  *d2 = *d1 ^ (HAVE_BIGENDIAN ? av_bswap32(k) : k);
132  k += key;
133  d1++;
134  d2++;
135  size--;
136  }
137 
138  *key_ptr = k;
139 }
140 
141 static void decode_block(uint8_t *src, uint8_t *dest, unsigned size,
142  uint32_t key, uint32_t *key_ptr,
143  int align)
144 {
145  unsigned s = size;
146  char tmp[4];
147  int a2;
148 
149  if (!size)
150  return;
151 
152  align &= 3;
153  a2 = (4 - align) & 3;
154 
155  if (align) {
156  uint32_t tmpkey = *key_ptr - key;
157  if (a2 > s) {
158  a2 = s;
159  avpriv_request_sample(NULL, "tiny aligned block\n");
160  }
161  memcpy(tmp + align, src, a2);
162  xor_block(tmp, tmp, 4, key, &tmpkey);
163  memcpy(dest, tmp + align, a2);
164  s -= a2;
165  }
166 
167  if (s >= 4) {
168  xor_block(src + a2, dest + a2, s & ~3,
169  key, key_ptr);
170  s &= 3;
171  }
172 
173  if (s) {
174  size -= s;
175  memcpy(tmp, src + size, s);
176  xor_block(&tmp, &tmp, 4, key, key_ptr);
177  memcpy(dest + size, tmp, s);
178  }
179 }
180 
181 static uint32_t get_v(uint8_t *p, int len)
182 {
183  uint32_t v = 0;
184  const uint8_t *end = p + len;
185 
186  do {
187  if (p >= end || v >= UINT_MAX / 128 - *p)
188  return v;
189  v <<= 7;
190  v += *p & 0x7f;
191  } while (*p++ & 0x80);
192 
193  return v;
194 }
195 
196 static uint8_t *read_vblock(AVIOContext *src, uint32_t *size,
197  uint32_t key, uint32_t *k2, int align)
198 {
199  uint8_t tmp[4];
200  uint8_t *buf;
201  unsigned n;
202 
203  if (avio_read(src, tmp, 4) != 4)
204  return NULL;
205 
206  decode_block(tmp, tmp, 4, key, k2, align);
207 
208  n = get_v(tmp, 4);
209  if (n < 4)
210  return NULL;
211 
212  buf = av_malloc(n);
213  if (!buf)
214  return NULL;
215 
216  *size = n;
217  n -= 4;
218 
219  memcpy(buf, tmp, 4);
220 
221  if (avio_read(src, buf + 4, n) == n) {
222  decode_block(buf + 4, buf + 4, n, key, k2, align);
223  } else {
224  av_free(buf);
225  buf = NULL;
226  }
227 
228  return buf;
229 }
230 
232  uint32_t *key, unsigned expected_size)
233 {
234  uint8_t *buf;
235  uint8_t ibuf[8], sbuf[8];
236  uint32_t k2;
237  unsigned n;
238 
239  if (avio_read(src, ibuf, 8) < 8)
240  return NULL;
241 
242  k2 = *key;
243  decode_block(ibuf, sbuf, 8, *key, &k2, 0);
244 
245  n = get_v(sbuf+2, 6);
246 
247  if (sbuf[0] != 'S' || sbuf[1] != 'B' || (expected_size>0 && n != expected_size)) {
248  uint32_t tmpkey = recover_key(ibuf, expected_size);
249  k2 = tmpkey;
250  decode_block(ibuf, sbuf, 8, tmpkey, &k2, 0);
251  n = get_v(sbuf+2, 6);
252  if (sbuf[0] != 'S' || sbuf[1] != 'B' || expected_size != n)
253  return NULL;
254  *key = tmpkey;
255  }
256 
257  if (n < 8)
258  return NULL;
259 
260  buf = av_malloc(n);
261  if (!buf)
262  return NULL;
263 
264  memcpy(buf, sbuf, 8);
265 
266  *size = n;
267  n -= 8;
268 
269  if (avio_read(src, buf+8, n) < n) {
270  av_free(buf);
271  return NULL;
272  }
273 
274  decode_block(buf + 8, buf + 8, n, *key, &k2, 0);
275 
276  return buf;
277 }
278 
280 {
281  int i,j;
282  int64_t off;
283  int val_1;
284  int num_video;
285  AVIOContext *pb;
286 
287  pb = avio_alloc_context(buf, size, 0, NULL, NULL, NULL, NULL);
288  if (!pb)
289  return AVERROR(ENOMEM);
290 
291  ffio_read_varlen(pb); // track_header_len
292  avio_r8(pb); // '1'
293 
294  val_1 = ffio_read_varlen(pb);
295 
296  for (i=0;i<val_1;i++) {
297  int c = avio_r8(pb);
298  for (j=0;j<c;j++) {
299  if (avio_feof(pb))
300  return AVERROR_EOF;
301  avio_r8(pb); // val_3
302  avio_r8(pb); // val_4
303  }
304  }
305 
306  avio_r8(pb); // num_streams
307 
308  off = avio_tell(pb);
309  off += ffio_read_varlen(pb); // val_5
310 
311  avio_r8(pb); // '2'
312  num_video = avio_r8(pb);
313 
314  avio_seek(pb, off, SEEK_SET);
315  if (num_video != 1) {
316  av_log(s, AV_LOG_ERROR, "number of video tracks %d is not 1\n", num_video);
317  return AVERROR_PATCHWELCOME;
318  }
319 
320  for (i = 0; i < num_video; i++) {
322 
323  st->id = i;
324 
327 
328  off = avio_tell(pb);
329  off += ffio_read_varlen(pb);
330  avio_r8(pb); // '3'
331  avio_r8(pb); // val_7
332  st->time_base.num = avio_rl32(pb); // frame_time
333  st->time_base.den = avio_rl32(pb); // time_base
334  st->nb_frames = avio_rl32(pb); // n frames
335  st->codecpar->width = avio_rl16(pb); // width
336  st->codecpar->height = avio_rl16(pb); // height
337  avio_r8(pb); // val_8
338  avio_rl32(pb); // val_9
339 
340  avio_seek(pb, off, SEEK_SET);
341  }
342 
343  off = avio_tell(pb);
344  off += ffio_read_varlen(pb); // val_10
345  avio_r8(pb); // '4'
346  viv->num_audio = avio_r8(pb);
347  avio_seek(pb, off, SEEK_SET);
348 
349  if (viv->num_audio != 1)
350  av_log(s, AV_LOG_WARNING, "number of audio tracks %d is not 1\n", viv->num_audio);
351 
352  for(i=0;i<viv->num_audio;i++) {
353  int q;
355 
356  st->id = num_video + i;
357 
360 
361  off = avio_tell(pb);
362  off += ffio_read_varlen(pb); // length
363  avio_r8(pb); // '5'
364  avio_r8(pb); //codec_id
365  avio_rl16(pb); //codec_subid
366  st->codecpar->channels = avio_rl16(pb); // channels
367  st->codecpar->sample_rate = avio_rl32(pb); // sample_rate
368  avio_seek(pb, 10, SEEK_CUR); // data_1
369  q = avio_r8(pb);
370  avio_seek(pb, q, SEEK_CUR); // data_2
371  avio_r8(pb); // zeropad
372 
373  if (avio_tell(pb) < off) {
374  int num_data;
375  int xd_size = 0;
376  int data_len[256];
377  int offset = 1;
378  uint8_t *p;
379  ffio_read_varlen(pb); // val_13
380  avio_r8(pb); // '19'
381  ffio_read_varlen(pb); // len_3
382  num_data = avio_r8(pb);
383  for (j = 0; j < num_data; j++) {
384  uint64_t len = ffio_read_varlen(pb);
385  if (len > INT_MAX/2 - xd_size) {
386  av_free(pb);
387  return AVERROR_INVALIDDATA;
388  }
389  data_len[j] = len;
390  xd_size += len;
391  }
392 
393  st->codecpar->extradata_size = 64 + xd_size + xd_size / 255;
395  av_free(pb);
396  return AVERROR(ENOMEM);
397  }
398 
399  p = st->codecpar->extradata;
400  p[0] = 2;
401 
402  for (j = 0; j < num_data - 1; j++) {
403  unsigned delta = av_xiphlacing(&p[offset], data_len[j]);
404  if (delta > data_len[j]) {
405  av_free(pb);
406  return AVERROR_INVALIDDATA;
407  }
408  offset += delta;
409  }
410 
411  for (j = 0; j < num_data; j++) {
412  int ret = avio_read(pb, &p[offset], data_len[j]);
413  if (ret < data_len[j]) {
414  st->codecpar->extradata_size = 0;
415  av_freep(&st->codecpar->extradata);
416  break;
417  }
418  offset += data_len[j];
419  }
420 
421  if (offset < st->codecpar->extradata_size)
423  }
424  }
425 
426  av_free(pb);
427  return 0;
428 }
429 
431 {
432  int64_t off;
433  int64_t poff;
434  int maxnp=0;
435  AVIOContext *pb;
436  int i;
437  int64_t filesize = avio_size(s->pb);
438 
439  pb = avio_alloc_context(buf, size, 0, NULL, NULL, NULL, NULL);
440  if (!pb)
441  return AVERROR(ENOMEM);
442 
443  ffio_read_varlen(pb); // track_index_len
444  avio_r8(pb); // 'c'
445  viv->n_sb_blocks = ffio_read_varlen(pb);
446  if (viv->n_sb_blocks < 0 || viv->n_sb_blocks > size / 2)
447  goto error;
448  viv->sb_blocks = av_calloc(viv->n_sb_blocks, sizeof(VIV_SB_block));
449  if (!viv->sb_blocks) {
450  viv->n_sb_blocks = 0;
451  av_free(pb);
452  return AVERROR(ENOMEM);
453  }
454 
455  off = 0;
456  poff = 0;
457 
458  for (i = 0; i < viv->n_sb_blocks; i++) {
459  uint64_t size_tmp = ffio_read_varlen(pb);
460  uint64_t n_packets_tmp = ffio_read_varlen(pb);
461 
462  if (size_tmp > INT_MAX || n_packets_tmp > INT_MAX)
463  goto error;
464 
465  viv->sb_blocks[i].byte_offset = off;
466  viv->sb_blocks[i].packet_offset = poff;
467 
468  viv->sb_blocks[i].size = size_tmp;
469  viv->sb_blocks[i].n_packets = n_packets_tmp;
470 
471  off += viv->sb_blocks[i].size;
472  poff += viv->sb_blocks[i].n_packets;
473 
474  if (maxnp < viv->sb_blocks[i].n_packets)
475  maxnp = viv->sb_blocks[i].n_packets;
476  }
477 
478  if (filesize > 0 && poff > filesize)
479  goto error;
480 
481  viv->sb_entries = av_calloc(maxnp, sizeof(VIV_SB_entry));
482  av_free(pb);
483 
484  return 0;
485 error:
486  av_free(pb);
487  viv->n_sb_blocks = 0;
488  av_freep(&viv->sb_blocks);
489  return AVERROR_INVALIDDATA;
490 }
491 
492 static void load_sb_block(AVFormatContext *s, VividasDemuxContext *viv, unsigned expected_size)
493 {
494  uint32_t size = 0;
495  int i;
496  AVIOContext *pb = 0;
497 
498  if (viv->sb_pb) {
499  av_free(viv->sb_pb);
500  viv->sb_pb = NULL;
501  }
502 
503  if (viv->sb_buf)
504  av_free(viv->sb_buf);
505 
506  viv->sb_buf = read_sb_block(s->pb, &size, &viv->sb_key, expected_size);
507  if (!viv->sb_buf) {
508  return;
509  }
510 
511  pb = avio_alloc_context(viv->sb_buf, size, 0, NULL, NULL, NULL, NULL);
512  if (!pb)
513  return;
514 
515  viv->sb_pb = pb;
516 
517  avio_r8(pb); // 'S'
518  avio_r8(pb); // 'B'
519  ffio_read_varlen(pb); // size
520  avio_r8(pb); // junk
521  ffio_read_varlen(pb); // first packet
522 
523  viv->n_sb_entries = viv->sb_blocks[viv->current_sb].n_packets;
524 
525  for (i = 0; i < viv->n_sb_entries; i++) {
526  viv->sb_entries[i].size = ffio_read_varlen(pb);
527  viv->sb_entries[i].flag = avio_r8(pb);
528  }
529 
530  ffio_read_varlen(pb);
531  avio_r8(pb);
532 
533  viv->current_sb_entry = 0;
534 }
535 
537 {
538  VividasDemuxContext *viv = s->priv_data;
539  AVIOContext *pb = s->pb;
540  int64_t header_end;
541  int num_tracks;
542  uint32_t key, k2;
543  uint32_t v;
544  uint8_t keybuffer[187];
545  uint32_t b22_size = 0;
546  uint32_t b22_key = 0;
547  uint8_t *buf = 0;
548  int ret;
549 
550  avio_skip(pb, 9);
551 
552  header_end = avio_tell(pb);
553 
554  header_end += ffio_read_varlen(pb);
555 
556  num_tracks = avio_r8(pb);
557 
558  if (num_tracks != 1) {
559  av_log(s, AV_LOG_ERROR, "number of tracks %d is not 1\n", num_tracks);
560  return AVERROR(EINVAL);
561  }
562 
563  v = avio_r8(pb);
564  avio_seek(pb, v, SEEK_CUR);
565 
566  avio_read(pb, keybuffer, 187);
567  key = decode_key(keybuffer);
568  viv->sb_key = key;
569 
570  avio_rl32(pb);
571 
572  for (;;) {
573  int64_t here = avio_tell(pb);
574  int block_len, block_type;
575 
576  if (here >= header_end)
577  break;
578 
579  block_len = ffio_read_varlen(pb);
580  if (avio_feof(pb) || block_len <= 0)
581  return AVERROR_INVALIDDATA;
582 
583  block_type = avio_r8(pb);
584 
585  if (block_type == 22) {
586  avio_read(pb, keybuffer, 187);
587  b22_key = decode_key(keybuffer);
588  b22_size = avio_rl32(pb);
589  }
590 
591  avio_seek(pb, here + block_len, SEEK_SET);
592  }
593 
594  if (b22_size) {
595  k2 = b22_key;
596  buf = read_vblock(pb, &v, b22_key, &k2, 0);
597  if (!buf)
598  return AVERROR(EIO);
599 
600  av_free(buf);
601  }
602 
603  k2 = key;
604  buf = read_vblock(pb, &v, key, &k2, 0);
605  if (!buf)
606  return AVERROR(EIO);
607  ret = track_header(viv, s, buf, v);
608  av_free(buf);
609  if (ret < 0)
610  return ret;
611 
612  buf = read_vblock(pb, &v, key, &k2, v);
613  if (!buf)
614  return AVERROR(EIO);
615  ret = track_index(viv, s, buf, v);
616  av_free(buf);
617  if (ret < 0)
618  return ret;
619 
620  viv->sb_offset = avio_tell(pb);
621  if (viv->n_sb_blocks > 0) {
622  viv->current_sb = 0;
623  load_sb_block(s, viv, viv->sb_blocks[0].size);
624  } else {
625  viv->current_sb = -1;
626  }
627 
628  return 0;
629 }
630 
632  AVPacket *pkt)
633 {
634  VividasDemuxContext *viv = s->priv_data;
635  AVIOContext *pb;
636  int64_t off;
637  int ret;
638 
639  if (!viv->sb_pb)
640  return AVERROR(EIO);
641  if (avio_feof(viv->sb_pb))
642  return AVERROR_EOF;
643 
645  AVStream *astream;
647 
648  pb = viv->sb_pb;
649  ret = av_get_packet(pb, pkt, size);
650  if (ret < 0)
651  return ret;
652  pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
653 
654  pkt->stream_index = 1;
655  astream = s->streams[pkt->stream_index];
656 
657  pkt->pts = av_rescale(viv->audio_sample, astream->time_base.den, astream->time_base.num) / astream->codecpar->sample_rate;
659  pkt->flags |= AV_PKT_FLAG_KEY;
661  return 0;
662  }
663 
664  if (viv->current_sb_entry >= viv->n_sb_entries) {
665  if (viv->current_sb+1 >= viv->n_sb_blocks)
666  return AVERROR(EIO);
667  viv->current_sb++;
668 
669  load_sb_block(s, viv, 0);
670  viv->current_sb_entry = 0;
671  }
672 
673  pb = viv->sb_pb;
674  if (!pb)
675  return AVERROR(EIO);
676  off = avio_tell(pb);
677  off += viv->sb_entries[viv->current_sb_entry].size;
678 
679  if (viv->sb_entries[viv->current_sb_entry].flag == 0) {
680  uint64_t v_size = ffio_read_varlen(pb);
681 
682  if (!viv->num_audio)
683  return AVERROR_INVALIDDATA;
684 
685  ffio_read_varlen(pb);
686  if (v_size > INT_MAX)
687  return AVERROR_INVALIDDATA;
688  ret = av_get_packet(pb, pkt, v_size);
689  if (ret < 0)
690  return ret;
691  pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
692 
693  pkt->pts = viv->sb_blocks[viv->current_sb].packet_offset + viv->current_sb_entry;
694  pkt->flags |= (pkt->data[0]&0x80)?0:AV_PKT_FLAG_KEY;
695  pkt->stream_index = 0;
696 
697  for (int i = 0; i < MAX_AUDIO_SUBPACKETS - 1; i++) {
698  int start, pcm_bytes;
699  start = ffio_read_varlen(pb);
700  pcm_bytes = ffio_read_varlen(pb);
701 
702  if (i > 0 && start == 0)
703  break;
704 
705  viv->n_audio_subpackets = i + 1;
706  viv->audio_subpackets[i].start = start;
707  viv->audio_subpackets[i].pcm_bytes = pcm_bytes;
708  }
709  viv->audio_subpackets[viv->n_audio_subpackets].start = (int)(off - avio_tell(pb));
710  viv->current_audio_subpacket = 0;
711 
712  } else {
713  uint64_t v_size = ffio_read_varlen(pb);
714 
715  if (v_size > INT_MAX)
716  return AVERROR_INVALIDDATA;
717  ret = av_get_packet(pb, pkt, v_size);
718  if (ret < 0)
719  return ret;
720  pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
721  pkt->pts = viv->sb_blocks[viv->current_sb].packet_offset + viv->current_sb_entry;
722  pkt->flags |= (pkt->data[0] & 0x80) ? 0 : AV_PKT_FLAG_KEY;
723  pkt->stream_index = 0;
724  }
725 
726  viv->current_sb_entry++;
727 
728  return 0;
729 }
730 
732 {
733  VividasDemuxContext *viv = s->priv_data;
734 
735  av_freep(&viv->sb_pb);
736  av_freep(&viv->sb_buf);
737  av_freep(&viv->sb_blocks);
738  av_freep(&viv->sb_entries);
739 
740  return 0;
741 }
742 
743 static int viv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
744 {
745  VividasDemuxContext *viv = s->priv_data;
746  int64_t frame;
747 
748  if (stream_index == 0)
749  frame = timestamp;
750  else
751  frame = av_rescale_q(timestamp, s->streams[0]->time_base, s->streams[stream_index]->time_base);
752 
753  for (int i = 0; i < viv->n_sb_blocks; i++) {
754  if (frame >= viv->sb_blocks[i].packet_offset && frame < viv->sb_blocks[i].packet_offset + viv->sb_blocks[i].n_packets) {
755  // flush audio packet queue
756  viv->current_audio_subpacket = 0;
757  viv->n_audio_subpackets = 0;
758  viv->current_sb = i;
759  // seek to ith sb block
760  avio_seek(s->pb, viv->sb_offset + viv->sb_blocks[i].byte_offset, SEEK_SET);
761  // load the block
762  load_sb_block(s, viv, 0);
763  // most problematic part: guess audio offset
765  // hand-tuned 1.s a/v offset
766  viv->audio_sample += s->streams[1]->codecpar->sample_rate;
767  viv->current_sb_entry = 0;
768  return 1;
769  }
770  }
771  return 0;
772 }
773 
775  .name = "vividas",
776  .long_name = NULL_IF_CONFIG_SMALL("Vividas VIV"),
777  .priv_data_size = sizeof(VividasDemuxContext),
783 };
#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:196
Bytestream IO Context.
Definition: avio.h:161
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:336
static uint32_t get_v(uint8_t *p, int len)
Definition: vividas.c:181
static void decode_block(uint8_t *src, uint8_t *dest, unsigned size, uint32_t key, uint32_t *key_ptr, int align)
Definition: vividas.c:141
#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:66
static unsigned recover_key(unsigned char sample[4], unsigned expected_size)
Definition: vividas.c:113
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:57
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:62
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:231
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:536
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
int64_t sb_offset
Definition: vividas.c:58
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:64
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:743
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:774
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:122
#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 error(const char *err)
#define MAX_AUDIO_SUBPACKETS
Definition: vividas.c:36
int current_audio_subpacket
Definition: vividas.c:67
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:530
Stream structure.
Definition: avformat.h:881
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
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:89
void * buf
Definition: avisynth_c.h:766
int64_t audio_sample
Definition: vividas.c:69
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
Definition: utils.c:1763
int n_packets
Definition: vividas.c:39
static int viv_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: vividas.c:631
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:492
#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:61
int den
Denominator.
Definition: rational.h:60
static int viv_read_close(AVFormatContext *s)
Definition: vividas.c:731
static int viv_probe(const AVProbeData *p)
Definition: vividas.c:74
#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:279
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:82
#define av_freep(p)
VIV_AudioSubpacket audio_subpackets[MAX_AUDIO_SUBPACKETS]
Definition: vividas.c:71
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
static int track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *buf, unsigned size)
Definition: vividas.c:430
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:101
int64_t byte_offset
Definition: vividas.c:40
static uint8_t tmp[11]
Definition: aes_ctr.c:26