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/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  memcpy(tmp + align, src, a2);
157  xor_block(tmp, tmp, 4, key, &tmpkey);
158  memcpy(dest, tmp + align, a2);
159  s -= a2;
160  }
161 
162  if (s >= 4) {
163  if (!align)
164  align = 4;
165  xor_block(src + a2, dest + a2, s & ~3,
166  key, key_ptr);
167  s &= 3;
168  }
169 
170  if (s) {
171  size -= s;
172  memcpy(tmp, src + size, s);
173  xor_block(&tmp, &tmp, 4, key, key_ptr);
174  memcpy(dest + size, tmp, s);
175  }
176 }
177 
178 static uint32_t get_v(uint8_t *p, int len)
179 {
180  uint32_t v = 0;
181  const uint8_t *end = p + len;
182 
183  do {
184  if (p >= end || v >= UINT_MAX / 128 - *p)
185  return v;
186  v <<= 7;
187  v += *p & 0x7f;
188  } while (*p++ & 0x80);
189 
190  return v;
191 }
192 
193 static uint8_t *read_vblock(AVIOContext *src, uint32_t *size,
194  uint32_t key, uint32_t *k2, int align)
195 {
196  uint8_t tmp[4];
197  uint8_t *buf;
198  unsigned n;
199 
200  if (avio_read(src, tmp, 4) != 4)
201  return NULL;
202 
203  decode_block(tmp, tmp, 4, key, k2, align);
204 
205  n = get_v(tmp, 4);
206  if (n < 4)
207  return NULL;
208 
209  buf = av_malloc(n);
210  if (!buf)
211  return NULL;
212 
213  *size = n;
214  n -= 4;
215 
216  memcpy(buf, tmp, 4);
217 
218  if (avio_read(src, buf + 4, n) == n) {
219  decode_block(buf + 4, buf + 4, n, key, k2, align + 4);
220  } else {
221  av_free(buf);
222  buf = NULL;
223  }
224 
225  return buf;
226 }
227 
229  uint32_t *key, unsigned expected_size)
230 {
231  uint8_t *buf;
232  uint8_t ibuf[8], sbuf[8];
233  uint32_t k2;
234  unsigned n;
235 
236  if (avio_read(src, ibuf, 8) < 8)
237  return NULL;
238 
239  k2 = *key;
240  decode_block(ibuf, sbuf, 8, *key, &k2, 0);
241 
242  n = get_v(sbuf+2, 6);
243 
244  if (sbuf[0] != 'S' || sbuf[1] != 'B' || (expected_size>0 && n != expected_size)) {
245  uint32_t tmpkey = recover_key(ibuf, expected_size);
246  k2 = tmpkey;
247  decode_block(ibuf, sbuf, 8, tmpkey, &k2, 0);
248  n = get_v(sbuf+2, 6);
249  if (sbuf[0] != 'S' || sbuf[1] != 'B' || expected_size != n)
250  return NULL;
251  *key = tmpkey;
252  }
253 
254  if (n < 8)
255  return NULL;
256 
257  buf = av_malloc(n);
258  if (!buf)
259  return NULL;
260 
261  memcpy(buf, sbuf, 8);
262 
263  *size = n;
264  n -= 8;
265 
266  if (avio_read(src, buf+8, n) < n) {
267  av_free(buf);
268  return NULL;
269  }
270 
271  decode_block(buf + 8, buf + 8, n, *key, &k2, 0);
272 
273  return buf;
274 }
275 
277 {
278  int i,j;
279  int64_t off;
280  int val_1;
281  int num_video, num_audio;
282  AVIOContext *pb;
283 
284  pb = avio_alloc_context(buf, size, 0, NULL, NULL, NULL, NULL);
285  if (!pb)
286  return AVERROR(ENOMEM);
287 
288  ffio_read_varlen(pb); // track_header_len
289  avio_r8(pb); // '1'
290 
291  val_1 = ffio_read_varlen(pb);
292 
293  for (i=0;i<val_1;i++) {
294  int c = avio_r8(pb);
295  for (j=0;j<c;j++) {
296  avio_r8(pb); // val_3
297  avio_r8(pb); // val_4
298  }
299  }
300 
301  avio_r8(pb); // num_streams
302 
303  off = avio_tell(pb);
304  off += ffio_read_varlen(pb); // val_5
305 
306  avio_r8(pb); // '2'
307  num_video = avio_r8(pb);
308 
309  avio_seek(pb, off, SEEK_SET);
310  if (num_video != 1)
311  av_log(s, AV_LOG_WARNING, "number of video tracks %d is not 1\n", num_video);
312 
313  for (i = 0; i < num_video; i++) {
315 
316  st->id = i;
317 
320 
321  off = avio_tell(pb);
322  off += ffio_read_varlen(pb);
323  avio_r8(pb); // '3'
324  avio_r8(pb); // val_7
325  st->time_base.num = avio_rl32(pb); // frame_time
326  st->time_base.den = avio_rl32(pb); // time_base
327  st->nb_frames = avio_rl32(pb); // n frames
328  st->codecpar->width = avio_rl16(pb); // width
329  st->codecpar->height = avio_rl16(pb); // height
330  avio_r8(pb); // val_8
331  avio_rl32(pb); // val_9
332 
333  avio_seek(pb, off, SEEK_SET);
334  }
335 
336  off = avio_tell(pb);
337  off += ffio_read_varlen(pb); // val_10
338  avio_r8(pb); // '4'
339  num_audio = avio_r8(pb);
340  avio_seek(pb, off, SEEK_SET);
341 
342  if (num_audio != 1)
343  av_log(s, AV_LOG_WARNING, "number of audio tracks %d is not 1\n", num_audio);
344 
345  for(i=0;i<num_audio;i++) {
346  int q;
348 
349  st->id = num_video + i;
350 
353 
354  off = avio_tell(pb);
355  off += ffio_read_varlen(pb); // length
356  avio_r8(pb); // '5'
357  avio_r8(pb); //codec_id
358  avio_rl16(pb); //codec_subid
359  st->codecpar->channels = avio_rl16(pb); // channels
360  st->codecpar->sample_rate = avio_rl32(pb); // sample_rate
361  avio_seek(pb, 10, SEEK_CUR); // data_1
362  q = avio_r8(pb);
363  avio_seek(pb, q, SEEK_CUR); // data_2
364  avio_r8(pb); // zeropad
365 
366  if (avio_tell(pb) < off) {
367  int num_data;
368  int xd_size = 0;
369  int data_len[256];
370  int offset = 1;
371  uint8_t *p;
372  ffio_read_varlen(pb); // val_13
373  avio_r8(pb); // '19'
374  ffio_read_varlen(pb); // len_3
375  num_data = avio_r8(pb);
376  for (j = 0; j < num_data; j++) {
377  uint64_t len = ffio_read_varlen(pb);
378  if (len > INT_MAX/2 - xd_size) {
379  av_free(pb);
380  return AVERROR_INVALIDDATA;
381  }
382  data_len[j] = len;
383  xd_size += len;
384  }
385 
386  st->codecpar->extradata_size = 64 + xd_size + xd_size / 255;
388  av_free(pb);
389  return AVERROR(ENOMEM);
390  }
391 
392  p = st->codecpar->extradata;
393  p[0] = 2;
394 
395  for (j = 0; j < num_data - 1; j++) {
396  unsigned delta = av_xiphlacing(&p[offset], data_len[j]);
397  if (delta > data_len[j]) {
398  av_free(pb);
399  return AVERROR_INVALIDDATA;
400  }
401  offset += delta;
402  }
403 
404  for (j = 0; j < num_data; j++) {
405  int ret = avio_read(pb, &p[offset], data_len[j]);
406  if (ret < data_len[j]) {
407  st->codecpar->extradata_size = 0;
408  av_freep(&st->codecpar->extradata);
409  break;
410  }
411  offset += data_len[j];
412  }
413 
414  if (offset < st->codecpar->extradata_size)
416  }
417  }
418 
419  av_free(pb);
420  return 0;
421 }
422 
424 {
425  int64_t off;
426  int64_t poff;
427  int maxnp=0;
428  AVIOContext *pb;
429  int i;
430 
431  pb = avio_alloc_context(buf, size, 0, NULL, NULL, NULL, NULL);
432  if (!pb)
433  return;
434 
435  ffio_read_varlen(pb); // track_index_len
436  avio_r8(pb); // 'c'
437  viv->n_sb_blocks = ffio_read_varlen(pb);
438  viv->sb_blocks = av_calloc(viv->n_sb_blocks, sizeof(VIV_SB_block));
439  if (!viv->sb_blocks) {
440  viv->n_sb_blocks = 0;
441  av_free(pb);
442  return;
443  }
444 
445  off = 0;
446  poff = 0;
447 
448  for (i = 0; i < viv->n_sb_blocks; i++) {
449  viv->sb_blocks[i].byte_offset = off;
450  viv->sb_blocks[i].packet_offset = poff;
451 
452  viv->sb_blocks[i].size = ffio_read_varlen(pb);
454 
455  off += viv->sb_blocks[i].size;
456  poff += viv->sb_blocks[i].n_packets;
457 
458 
459  if (maxnp < viv->sb_blocks[i].n_packets)
460  maxnp = viv->sb_blocks[i].n_packets;
461  }
462 
463  viv->sb_entries = av_calloc(maxnp, sizeof(VIV_SB_entry));
464  av_free(pb);
465 }
466 
467 static void load_sb_block(AVFormatContext *s, VividasDemuxContext *viv, unsigned expected_size)
468 {
469  uint32_t size = 0;
470  int i;
471  AVIOContext *pb = 0;
472 
473  if (viv->sb_pb) {
474  av_free(viv->sb_pb);
475  viv->sb_pb = NULL;
476  }
477 
478  if (viv->sb_buf)
479  av_free(viv->sb_buf);
480 
481  viv->sb_buf = read_sb_block(s->pb, &size, &viv->sb_key, expected_size);
482  if (!viv->sb_buf) {
483  return;
484  }
485 
486  pb = avio_alloc_context(viv->sb_buf, size, 0, NULL, NULL, NULL, NULL);
487  if (!pb)
488  return;
489 
490  viv->sb_pb = pb;
491 
492  avio_r8(pb); // 'S'
493  avio_r8(pb); // 'B'
494  ffio_read_varlen(pb); // size
495  avio_r8(pb); // junk
496  ffio_read_varlen(pb); // first packet
497 
498  viv->n_sb_entries = viv->sb_blocks[viv->current_sb].n_packets;
499 
500  for (i = 0; i < viv->n_sb_entries; i++) {
501  viv->sb_entries[i].size = ffio_read_varlen(pb);
502  viv->sb_entries[i].flag = avio_r8(pb);
503  }
504 
505  ffio_read_varlen(pb);
506  avio_r8(pb);
507 
508  viv->current_sb_entry = 0;
509 }
510 
512 {
513  VividasDemuxContext *viv = s->priv_data;
514  AVIOContext *pb = s->pb;
515  int64_t header_end;
516  int num_tracks;
517  uint32_t key, k2;
518  uint32_t v;
519  uint8_t keybuffer[187];
520  uint32_t b22_size = 0;
521  uint32_t b22_key = 0;
522  uint8_t *buf = 0;
523  int ret;
524 
525  avio_skip(pb, 9);
526 
527  header_end = avio_tell(pb);
528 
529  header_end += ffio_read_varlen(pb);
530 
531  num_tracks = avio_r8(pb);
532 
533  if (num_tracks != 1) {
534  av_log(s, AV_LOG_ERROR, "number of tracks %d is not 1\n", num_tracks);
535  return AVERROR(EINVAL);
536  }
537 
538  v = avio_r8(pb);
539  avio_seek(pb, v, SEEK_CUR);
540 
541  avio_read(pb, keybuffer, 187);
542  key = decode_key(keybuffer);
543  viv->sb_key = key;
544 
545  avio_rl32(pb);
546 
547  for (;;) {
548  int64_t here = avio_tell(pb);
549  int block_len, block_type;
550 
551  if (here >= header_end)
552  break;
553 
554  block_len = ffio_read_varlen(pb);
555  if (avio_feof(pb) || block_len <= 0)
556  return AVERROR_INVALIDDATA;
557 
558  block_type = avio_r8(pb);
559 
560  if (block_type == 22) {
561  avio_read(pb, keybuffer, 187);
562  b22_key = decode_key(keybuffer);
563  b22_size = avio_rl32(pb);
564  }
565 
566  avio_seek(pb, here + block_len, SEEK_SET);
567  }
568 
569  if (b22_size) {
570  k2 = b22_key;
571  buf = read_vblock(pb, &v, b22_key, &k2, 0);
572  if (!buf)
573  return AVERROR(EIO);
574 
575  av_free(buf);
576  }
577 
578  k2 = key;
579  buf = read_vblock(pb, &v, key, &k2, 0);
580  if (!buf)
581  return AVERROR(EIO);
582  ret = track_header(viv, s, buf, v);
583  av_free(buf);
584  if (ret < 0)
585  return ret;
586 
587  buf = read_vblock(pb, &v, key, &k2, v);
588  if (!buf)
589  return AVERROR(EIO);
590  track_index(viv, s, buf, v);
591  av_free(buf);
592 
593  viv->sb_offset = avio_tell(pb);
594  if (viv->n_sb_blocks > 0) {
595  viv->current_sb = 0;
596  load_sb_block(s, viv, viv->sb_blocks[0].size);
597  } else {
598  viv->current_sb = -1;
599  }
600 
601  return 0;
602 }
603 
605  AVPacket *pkt)
606 {
607  VividasDemuxContext *viv = s->priv_data;
608  AVIOContext *pb;
609  int64_t off;
610  int ret;
611 
612  if (!viv->sb_pb)
613  return AVERROR(EIO);
614  if (avio_feof(viv->sb_pb))
615  return AVERROR_EOF;
616 
618  AVStream *astream;
620 
621  pb = viv->sb_pb;
622  ret = av_get_packet(pb, pkt, size);
623  if (ret < 0)
624  return ret;
625  pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
626 
627  pkt->stream_index = 1;
628  astream = s->streams[pkt->stream_index];
629 
630  pkt->pts = av_rescale(viv->audio_sample, astream->time_base.den, astream->time_base.num) / astream->codecpar->sample_rate;
632  pkt->flags |= AV_PKT_FLAG_KEY;
634  return 0;
635  }
636 
637  if (viv->current_sb_entry >= viv->n_sb_entries) {
638  if (viv->current_sb+1 >= viv->n_sb_blocks)
639  return AVERROR(EIO);
640  viv->current_sb++;
641 
642  load_sb_block(s, viv, 0);
643  viv->current_sb_entry = 0;
644  }
645 
646  pb = viv->sb_pb;
647  if (!pb)
648  return AVERROR(EIO);
649  off = avio_tell(pb);
650  off += viv->sb_entries[viv->current_sb_entry].size;
651 
652  if (viv->sb_entries[viv->current_sb_entry].flag == 0) {
653  uint64_t v_size = ffio_read_varlen(pb);
654 
655  ffio_read_varlen(pb);
656  if (v_size > INT_MAX)
657  return AVERROR_INVALIDDATA;
658  ret = av_get_packet(pb, pkt, v_size);
659  if (ret < 0)
660  return ret;
661  pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
662 
663  pkt->pts = viv->sb_blocks[viv->current_sb].packet_offset + viv->current_sb_entry;
664  pkt->flags |= (pkt->data[0]&0x80)?0:AV_PKT_FLAG_KEY;
665  pkt->stream_index = 0;
666 
667  for (int i = 0; i < MAX_AUDIO_SUBPACKETS - 1; i++) {
668  int start, pcm_bytes;
669  start = ffio_read_varlen(pb);
670  pcm_bytes = ffio_read_varlen(pb);
671 
672  if (i > 0 && start == 0)
673  break;
674 
675  viv->n_audio_subpackets = i + 1;
676  viv->audio_subpackets[i].start = start;
677  viv->audio_subpackets[i].pcm_bytes = pcm_bytes;
678  }
679  viv->audio_subpackets[viv->n_audio_subpackets].start = (int)(off - avio_tell(pb));
680  viv->current_audio_subpacket = 0;
681 
682  } else {
683  uint64_t v_size = ffio_read_varlen(pb);
684 
685  if (v_size > INT_MAX)
686  return AVERROR_INVALIDDATA;
687  ret = av_get_packet(pb, pkt, v_size);
688  if (ret < 0)
689  return ret;
690  pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
691  pkt->pts = viv->sb_blocks[viv->current_sb].packet_offset + viv->current_sb_entry;
692  pkt->flags |= (pkt->data[0] & 0x80) ? 0 : AV_PKT_FLAG_KEY;
693  pkt->stream_index = 0;
694  }
695 
696  viv->current_sb_entry++;
697 
698  return 0;
699 }
700 
702 {
703  VividasDemuxContext *viv = s->priv_data;
704 
705  av_freep(&viv->sb_pb);
706  av_freep(&viv->sb_buf);
707  av_freep(&viv->sb_blocks);
708  av_freep(&viv->sb_entries);
709 
710  return 0;
711 }
712 
713 static int viv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
714 {
715  VividasDemuxContext *viv = s->priv_data;
716  int64_t frame;
717 
718  if (stream_index == 0)
719  frame = timestamp;
720  else
721  frame = av_rescale_q(timestamp, s->streams[0]->time_base, s->streams[stream_index]->time_base);
722 
723  for (int i = 0; i < viv->n_sb_blocks; i++) {
724  if (frame >= viv->sb_blocks[i].packet_offset && frame < viv->sb_blocks[i].packet_offset + viv->sb_blocks[i].n_packets) {
725  // flush audio packet queue
726  viv->current_audio_subpacket = 0;
727  viv->n_audio_subpackets = 0;
728  viv->current_sb = i;
729  // seek to ith sb block
730  avio_seek(s->pb, viv->sb_offset + viv->sb_blocks[i].byte_offset, SEEK_SET);
731  // load the block
732  load_sb_block(s, viv, 0);
733  // most problematic part: guess audio offset
735  // hand-tuned 1.s a/v offset
736  viv->audio_sample += s->streams[1]->codecpar->sample_rate;
737  viv->current_sb_entry = 0;
738  return 1;
739  }
740  }
741  return 0;
742 }
743 
745  .name = "vividas",
746  .long_name = NULL_IF_CONFIG_SMALL("Vividas VIV"),
747  .priv_data_size = sizeof(VividasDemuxContext),
753 };
#define NULL
Definition: coverity.c:32
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition: aviobuf.c:932
static uint8_t * read_vblock(AVIOContext *src, uint32_t *size, uint32_t key, uint32_t *k2, int align)
Definition: vividas.c:193
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:178
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
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:334
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
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
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
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
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:4465
#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
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
ptrdiff_t size
Definition: opengl_enc.c:100
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:650
#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:228
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:772
#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:511
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:641
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:713
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:3294
AVInputFormat ff_vividas_demuxer
Definition: vividas.c:744
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
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
#define s(width, name)
Definition: cbs_vp9.c:257
int n
Definition: avisynth_c.h:760
static void track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *buf, unsigned size)
Definition: vividas.c:423
#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:604
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:756
Main libavformat public API header.
int
static void load_sb_block(AVFormatContext *s, VividasDemuxContext *viv, unsigned expected_size)
Definition: vividas.c:467
#define flag(name)
Definition: cbs_av1.c:553
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:701
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:276
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:361
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
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
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
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