FFmpeg
Loading...
Searching...
No Matches
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"
33#include "libavutil/mem.h"
34#include "avio_internal.h"
35#include "avformat.h"
36#include "demux.h"
37#include "internal.h"
38
39#define MAX_AUDIO_SUBPACKETS 100
40
46
47typedef struct VIV_SB_entry {
48 int size, flag;
50
54
76
77static int viv_probe(const AVProbeData *p)
78{
79 if (memcmp(p->buf, "vividas03", 9))
80 return 0;
81
82 return AVPROBE_SCORE_MAX;
83}
84
85static const uint8_t keybits[32] = {
86 20, 52, 111, 10, 27, 71, 142, 53,
87 82, 138, 1, 78, 86, 121, 183, 85,
88105, 152, 39, 140, 172, 11, 64, 144,
89155, 6, 71, 163, 186, 49, 126, 43,
90};
91
92static uint32_t decode_key(uint8_t *buf)
93{
94 uint32_t key = 0;
95
96 for (int i = 0; i < 32; i++) {
97 unsigned p = keybits[i];
98 key |= ((buf[p] >> ((i*5+3)&7)) & 1u) << i;
99 }
100
101 return key;
102}
103
104static void put_v(uint8_t *p, unsigned v)
105{
106 if (v>>28)
107 *p++ = ((v>>28)&0x7f)|0x80;
108 if (v>>21)
109 *p++ = ((v>>21)&0x7f)|0x80;
110 if (v>>14)
111 *p++ = ((v>>14)&0x7f)|0x80;
112 if (v>>7)
113 *p++ = ((v>>7)&0x7f)|0x80;
114}
115
116static unsigned recover_key(unsigned char sample[4], unsigned expected_size)
117{
118 unsigned char plaintext[8] = { 'S', 'B' };
119
120 put_v(plaintext+2, expected_size);
121
122 return AV_RL32(sample) ^ AV_RL32(plaintext);
123}
124
125static void xor_block(void *p1, void *p2, unsigned size, int key, unsigned *key_ptr)
126{
127 unsigned *d1 = p1;
128 unsigned *d2 = p2;
129 unsigned k = *key_ptr;
130
131 size >>= 2;
132
133 while (size > 0) {
134 AV_WN32(d2, AV_RN32(d1) ^ (HAVE_BIGENDIAN ? av_bswap32(k) : k));
135 k += key;
136 d1++;
137 d2++;
138 size--;
139 }
140
141 *key_ptr = k;
142}
143
144static void decode_block(uint8_t *src, uint8_t *dest, unsigned size,
145 uint32_t key, uint32_t *key_ptr,
146 int align)
147{
148 unsigned s = size;
149 char tmp[4];
150 int a2;
151
152 if (!size)
153 return;
154
155 align &= 3;
156 a2 = (4 - align) & 3;
157
158 if (align) {
159 uint32_t tmpkey = *key_ptr - key;
160 if (a2 > s) {
161 a2 = s;
162 avpriv_request_sample(NULL, "tiny aligned block");
163 }
164 memcpy(tmp + align, src, a2);
165 xor_block(tmp, tmp, 4, key, &tmpkey);
166 memcpy(dest, tmp + align, a2);
167 s -= a2;
168 }
169
170 if (s >= 4) {
171 xor_block(src + a2, dest + a2, s & ~3,
172 key, key_ptr);
173 s &= 3;
174 }
175
176 if (s) {
177 size -= s;
178 memcpy(tmp, src + size, s);
179 xor_block(&tmp, &tmp, 4, key, key_ptr);
180 memcpy(dest + size, tmp, s);
181 }
182}
183
184static uint32_t get_v(uint8_t *p, int len)
185{
186 uint32_t v = 0;
187 const uint8_t *end = p + len;
188
189 do {
190 if (p >= end || v >= UINT_MAX / 128 - *p)
191 return v;
192 v <<= 7;
193 v += *p & 0x7f;
194 } while (*p++ & 0x80);
195
196 return v;
197}
198
199static uint8_t *read_vblock(AVIOContext *src, uint32_t *size,
200 uint32_t key, uint32_t *k2, int align)
201{
202 uint8_t tmp[4];
203 uint8_t *buf;
204 unsigned n;
205
206 if (avio_read(src, tmp, 4) != 4)
207 return NULL;
208
209 decode_block(tmp, tmp, 4, key, k2, align);
210
211 n = get_v(tmp, 4);
212 if (n < 4)
213 return NULL;
214
215 buf = av_malloc(n);
216 if (!buf)
217 return NULL;
218
219 *size = n;
220 n -= 4;
221
222 memcpy(buf, tmp, 4);
223
224 if (avio_read(src, buf + 4, n) == n) {
225 decode_block(buf + 4, buf + 4, n, key, k2, align);
226 } else {
227 av_free(buf);
228 buf = NULL;
229 }
230
231 return buf;
232}
233
234static uint8_t *read_sb_block(AVIOContext *src, unsigned *size,
235 uint32_t *key, unsigned expected_size)
236{
237 uint8_t *buf;
238 uint8_t ibuf[8], sbuf[8];
239 uint32_t k2;
240 unsigned n;
241
242 if (avio_read(src, ibuf, 8) < 8)
243 return NULL;
244
245 k2 = *key;
246 decode_block(ibuf, sbuf, 8, *key, &k2, 0);
247
248 n = get_v(sbuf+2, 6);
249
250 if (sbuf[0] != 'S' || sbuf[1] != 'B' || (expected_size>0 && n != expected_size)) {
251 uint32_t tmpkey = recover_key(ibuf, expected_size);
252 k2 = tmpkey;
253 decode_block(ibuf, sbuf, 8, tmpkey, &k2, 0);
254 n = get_v(sbuf+2, 6);
255 if (sbuf[0] != 'S' || sbuf[1] != 'B' || expected_size != n)
256 return NULL;
257 *key = tmpkey;
258 }
259
260 if (n < 8)
261 return NULL;
262
263 buf = av_malloc(n);
264 if (!buf)
265 return NULL;
266
267 memcpy(buf, sbuf, 8);
268
269 *size = n;
270 n -= 8;
271
272 if (avio_read(src, buf+8, n) != n) {
273 av_free(buf);
274 return NULL;
275 }
276
277 decode_block(buf + 8, buf + 8, n, *key, &k2, 0);
278
279 return buf;
280}
281
283 const uint8_t *buf, int size)
284{
285 int i, j, ret;
286 int64_t off;
287 int val_1;
288 int num_video;
289 FFIOContext pb0;
290 AVIOContext *const pb = &pb0.pub;
291
292 ffio_init_read_context(&pb0, buf, size);
293
294 ffio_read_varlen(pb); // track_header_len
295 avio_r8(pb); // '1'
296
297 val_1 = ffio_read_varlen(pb);
298
299 for (i=0;i<val_1;i++) {
300 int c = avio_r8(pb);
301 if (avio_feof(pb))
302 return AVERROR_EOF;
303 for (j=0;j<c;j++) {
304 if (avio_feof(pb))
305 return AVERROR_EOF;
306 avio_r8(pb); // val_3
307 avio_r8(pb); // val_4
308 }
309 }
310
311 avio_r8(pb); // num_streams
312
313 off = avio_tell(pb);
314 off += ffio_read_varlen(pb); // val_5
315
316 avio_r8(pb); // '2'
317 num_video = avio_r8(pb);
318
319 avio_seek(pb, off, SEEK_SET);
320 if (num_video != 1) {
321 av_log(s, AV_LOG_ERROR, "number of video tracks %d is not 1\n", num_video);
323 }
324
325 for (i = 0; i < num_video; i++) {
327 int num, den;
328
329 if (!st)
330 return AVERROR(ENOMEM);
331
332 st->id = i;
333
336
337 off = avio_tell(pb);
338 off += ffio_read_varlen(pb);
339 avio_r8(pb); // '3'
340 avio_r8(pb); // val_7
341 num = avio_rl32(pb); // frame_time
342 den = avio_rl32(pb); // time_base
343 avpriv_set_pts_info(st, 64, num, den);
344 st->nb_frames = avio_rl32(pb); // n frames
345 st->codecpar->width = avio_rl16(pb); // width
346 st->codecpar->height = avio_rl16(pb); // height
347 avio_r8(pb); // val_8
348 avio_rl32(pb); // val_9
349
350 avio_seek(pb, off, SEEK_SET);
351 }
352
353 off = avio_tell(pb);
354 off += ffio_read_varlen(pb); // val_10
355 avio_r8(pb); // '4'
356 viv->num_audio = avio_r8(pb);
357 avio_seek(pb, off, SEEK_SET);
358
359 if (viv->num_audio != 1)
360 av_log(s, AV_LOG_WARNING, "number of audio tracks %d is not 1\n", viv->num_audio);
361
362 for(i=0;i<viv->num_audio;i++) {
363 int q;
365 if (!st)
366 return AVERROR(ENOMEM);
367
368 st->id = num_video + i;
369
372
373 off = avio_tell(pb);
374 off += ffio_read_varlen(pb); // length
375 avio_r8(pb); // '5'
376 avio_r8(pb); //codec_id
377 avio_rl16(pb); //codec_subid
378 st->codecpar->ch_layout.nb_channels = avio_rl16(pb); // channels
379 st->codecpar->sample_rate = avio_rl32(pb); // sample_rate
380 if (st->codecpar->sample_rate <= 0 || st->codecpar->ch_layout.nb_channels <= 0)
381 return AVERROR_INVALIDDATA;
382 avio_seek(pb, 10, SEEK_CUR); // data_1
383 q = avio_r8(pb);
384 avio_seek(pb, q, SEEK_CUR); // data_2
385 avio_r8(pb); // zeropad
386
387 if (avio_tell(pb) < off) {
388 int num_data;
389 int xd_size = 1;
390 int data_len[256];
391 int offset = 1;
392 uint8_t *p;
393 ffio_read_varlen(pb); // val_13
394 avio_r8(pb); // '19'
395 ffio_read_varlen(pb); // len_3
396 num_data = avio_r8(pb);
397 for (j = 0; j < num_data; j++) {
399 if (len < 0 || len > INT_MAX/2 - xd_size) {
400 return AVERROR_INVALIDDATA;
401 }
402 data_len[j] = len;
403 xd_size += len + 1 + len/255;
404 }
405
406 ret = ff_alloc_extradata(st->codecpar, xd_size);
407 if (ret < 0)
408 return ret;
409
410 p = st->codecpar->extradata;
411 p[0] = 2;
412
413 for (j = 0; j < num_data - 1; j++) {
414 unsigned delta = av_xiphlacing(&p[offset], data_len[j]);
415 av_assert0(delta <= xd_size - offset);
416 offset += delta;
417 }
418
419 for (j = 0; j < num_data; j++) {
420 ret = avio_read(pb, &p[offset], data_len[j]);
421 if (ret < data_len[j]) {
422 st->codecpar->extradata_size = 0;
424 break;
425 }
426 av_assert0(data_len[j] <= xd_size - offset);
427 offset += data_len[j];
428 }
429
430 if (offset < st->codecpar->extradata_size)
432 }
433 }
434
435 return 0;
436}
437
439 const uint8_t *buf, unsigned size)
440{
441 int64_t off;
442 int64_t poff;
443 int maxnp=0;
444 FFIOContext pb0;
445 AVIOContext *const pb = &pb0.pub;
446 int i;
448 uint64_t n_sb_blocks_tmp;
449
450 ffio_init_read_context(&pb0, buf, size);
451
452 ffio_read_varlen(pb); // track_index_len
453 avio_r8(pb); // 'c'
454 n_sb_blocks_tmp = ffio_read_varlen(pb);
455 if (n_sb_blocks_tmp > size / 2)
456 return AVERROR_INVALIDDATA;
457 viv->sb_blocks = av_calloc(n_sb_blocks_tmp, sizeof(*viv->sb_blocks));
458 if (!viv->sb_blocks) {
459 return AVERROR(ENOMEM);
460 }
461 viv->n_sb_blocks = n_sb_blocks_tmp;
462
463 off = 0;
464 poff = 0;
465
466 for (i = 0; i < viv->n_sb_blocks; i++) {
467 uint64_t size_tmp = ffio_read_varlen(pb);
468 uint64_t n_packets_tmp = ffio_read_varlen(pb);
469
470 if (size_tmp > INT_MAX || n_packets_tmp > INT_MAX)
471 return AVERROR_INVALIDDATA;
472
473 viv->sb_blocks[i].byte_offset = off;
474 viv->sb_blocks[i].packet_offset = poff;
475
476 viv->sb_blocks[i].size = size_tmp;
477 viv->sb_blocks[i].n_packets = n_packets_tmp;
478
479 off += viv->sb_blocks[i].size;
480 poff += viv->sb_blocks[i].n_packets;
481
482 if (maxnp < viv->sb_blocks[i].n_packets)
483 maxnp = viv->sb_blocks[i].n_packets;
484 }
485
486 if (filesize > 0 && poff > filesize)
487 return AVERROR_INVALIDDATA;
488
489 viv->sb_entries = av_calloc(maxnp, sizeof(VIV_SB_entry));
490 if (!viv->sb_entries)
491 return AVERROR(ENOMEM);
492
493 return 0;
494}
495
496static void load_sb_block(AVFormatContext *s, VividasDemuxContext *viv, unsigned expected_size)
497{
498 uint32_t size = 0;
499 int i;
500 AVIOContext *pb = 0;
501
502 if (viv->sb_pb) {
503 av_free(viv->sb_pb);
504 viv->sb_pb = NULL;
505 }
506
507 if (viv->sb_buf)
508 av_free(viv->sb_buf);
509
510 viv->sb_buf = read_sb_block(s->pb, &size, &viv->sb_key, expected_size);
511 if (!viv->sb_buf) {
512 return;
513 }
514
515 pb = avio_alloc_context(viv->sb_buf, size, 0, NULL, NULL, NULL, NULL);
516 if (!pb)
517 return;
518
519 viv->sb_pb = pb;
520
521 avio_r8(pb); // 'S'
522 avio_r8(pb); // 'B'
523 ffio_read_varlen(pb); // size
524 avio_r8(pb); // junk
525 ffio_read_varlen(pb); // first packet
526
527 viv->n_sb_entries = viv->sb_blocks[viv->current_sb].n_packets;
528
529 for (i = 0; i < viv->n_sb_entries; i++) {
530 viv->sb_entries[i].size = ffio_read_varlen(pb);
531 viv->sb_entries[i].flag = avio_r8(pb);
532 }
533
535 avio_r8(pb);
536
537 viv->current_sb_entry = 0;
538}
539
541{
542 VividasDemuxContext *viv = s->priv_data;
543 AVIOContext *pb = s->pb;
544 int64_t header_end;
545 int num_tracks;
546 uint32_t key, k2;
547 uint32_t v;
548 uint8_t keybuffer[187];
549 uint32_t b22_size = 0;
550 uint32_t b22_key = 0;
551 uint8_t *buf = 0;
552 int ret;
553
554 avio_skip(pb, 9);
555
556 header_end = avio_tell(pb);
557
558 header_end += ffio_read_varlen(pb);
559
560 num_tracks = avio_r8(pb);
561
562 if (num_tracks != 1) {
563 av_log(s, AV_LOG_ERROR, "number of tracks %d is not 1\n", num_tracks);
564 return AVERROR(EINVAL);
565 }
566
567 v = avio_r8(pb);
568 avio_seek(pb, v, SEEK_CUR);
569
570 ret = ffio_read_size(pb, keybuffer, 187);
571 if (ret < 0)
572 return ret;
573 key = decode_key(keybuffer);
574 viv->sb_key = key;
575
576 avio_rl32(pb);
577
578 for (;;) {
579 int64_t here = avio_tell(pb);
580 int block_len, block_type;
581
582 if (here >= header_end)
583 break;
584
585 block_len = ffio_read_varlen(pb);
586 if (avio_feof(pb) || block_len <= 0)
587 return AVERROR_INVALIDDATA;
588
589 block_type = avio_r8(pb);
590
591 if (block_type == 22) {
592 ret = ffio_read_size(pb, keybuffer, 187);
593 if (ret < 0)
594 return ret;
595 b22_key = decode_key(keybuffer);
596 b22_size = avio_rl32(pb);
597 }
598
599 avio_seek(pb, here + block_len, SEEK_SET);
600 }
601
602 if (b22_size) {
603 k2 = b22_key;
604 buf = read_vblock(pb, &v, b22_key, &k2, 0);
605 if (!buf)
606 return AVERROR_INVALIDDATA;
607
608 av_free(buf);
609 }
610
611 k2 = key;
612 buf = read_vblock(pb, &v, key, &k2, 0);
613 if (!buf)
614 return AVERROR_INVALIDDATA;
615 ret = track_header(viv, s, buf, v);
616 av_free(buf);
617 if (ret < 0)
618 return ret;
619
620 buf = read_vblock(pb, &v, key, &k2, v);
621 if (!buf)
622 return AVERROR_INVALIDDATA;
623 ret = track_index(viv, s, buf, v);
624 av_free(buf);
625 if (ret < 0)
626 return ret;
627
628 viv->sb_offset = avio_tell(pb);
629 if (viv->n_sb_blocks > 0) {
630 viv->current_sb = 0;
631 load_sb_block(s, viv, viv->sb_blocks[0].size);
632 } else {
633 viv->current_sb = -1;
634 }
635
636 return 0;
637}
638
640 AVPacket *pkt)
641{
642 VividasDemuxContext *viv = s->priv_data;
643 AVIOContext *pb;
644 int64_t off;
645 int ret;
646
647 if (!viv->sb_pb)
648 return AVERROR_INVALIDDATA;
649 if (avio_feof(viv->sb_pb))
650 return AVERROR_EOF;
651
653 AVStream *astream;
655
656 pb = viv->sb_pb;
657 ret = av_get_packet(pb, pkt, size);
658 if (ret < 0)
659 return ret;
660 pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
661
662 pkt->stream_index = 1;
663 astream = s->streams[pkt->stream_index];
664
665 pkt->pts = av_rescale_q(viv->audio_sample, av_make_q(1, astream->codecpar->sample_rate), astream->time_base);
668 pkt->flags |= AV_PKT_FLAG_KEY;
670 return 0;
671 }
672
673 if (viv->current_sb_entry >= viv->n_sb_entries) {
674 if (viv->current_sb+1 >= viv->n_sb_blocks)
675 return AVERROR_INVALIDDATA;
676 viv->current_sb++;
677
678 load_sb_block(s, viv, 0);
679 viv->current_sb_entry = 0;
680 }
681
682 pb = viv->sb_pb;
683 if (!pb)
684 return AVERROR_INVALIDDATA;
685 off = avio_tell(pb);
686
687 if (viv->current_sb_entry >= viv->n_sb_entries)
688 return AVERROR_INVALIDDATA;
689
690 off += viv->sb_entries[viv->current_sb_entry].size;
691
692 if (viv->sb_entries[viv->current_sb_entry].flag == 0) {
693 uint64_t v_size = ffio_read_varlen(pb);
694 int last = 0, last_start;
695
696 if (!viv->num_audio)
697 return AVERROR_INVALIDDATA;
698
700 if (v_size > INT_MAX || !v_size)
701 return AVERROR_INVALIDDATA;
702 ret = av_get_packet(pb, pkt, v_size);
703 if (ret < 0)
704 return ret;
705 pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
706
707 pkt->pts = viv->sb_blocks[viv->current_sb].packet_offset + viv->current_sb_entry;
708 pkt->flags |= (pkt->data[0]&0x80)?0:AV_PKT_FLAG_KEY;
709 pkt->stream_index = 0;
710
711 for (int i = 0; i < MAX_AUDIO_SUBPACKETS - 1; i++) {
712 int start, pcm_bytes;
713 start = ffio_read_varlen(pb);
714 pcm_bytes = ffio_read_varlen(pb);
715
716 if (i > 0 && start == 0)
717 break;
718 if (start < last)
719 return AVERROR_INVALIDDATA;
720
721 viv->n_audio_subpackets = i + 1;
722 last =
723 viv->audio_subpackets[i].start = start;
724 viv->audio_subpackets[i].pcm_bytes = pcm_bytes;
725 }
726 last_start =
727 viv->audio_subpackets[viv->n_audio_subpackets].start = (int)(off - avio_tell(pb));
728 if (last_start < last) {
729 viv->n_audio_subpackets = 0;
730 return AVERROR_INVALIDDATA;
731 }
733
734 } else {
735 uint64_t v_size = ffio_read_varlen(pb);
736
737 if (v_size > INT_MAX || !v_size)
738 return AVERROR_INVALIDDATA;
739 ret = av_get_packet(pb, pkt, v_size);
740 if (ret < 0)
741 return ret;
742 pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
743 pkt->pts = viv->sb_blocks[viv->current_sb].packet_offset + viv->current_sb_entry;
744 pkt->flags |= (pkt->data[0] & 0x80) ? 0 : AV_PKT_FLAG_KEY;
745 pkt->stream_index = 0;
746 }
747
748 viv->current_sb_entry++;
749
750 return 0;
751}
752
754{
755 VividasDemuxContext *viv = s->priv_data;
756
757 av_freep(&viv->sb_pb);
758 av_freep(&viv->sb_buf);
759 av_freep(&viv->sb_blocks);
760 av_freep(&viv->sb_entries);
761
762 return 0;
763}
764
765static int viv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
766{
767 VividasDemuxContext *viv = s->priv_data;
769
770 if (stream_index == 0)
771 frame = timestamp;
772 else
773 frame = av_rescale_q(timestamp, s->streams[0]->time_base, s->streams[stream_index]->time_base);
774
775 for (int i = 0; i < viv->n_sb_blocks; i++) {
776 if (frame >= viv->sb_blocks[i].packet_offset && frame < viv->sb_blocks[i].packet_offset + viv->sb_blocks[i].n_packets) {
777 viv->current_sb = i;
778 // seek to ith sb block
779 avio_seek(s->pb, viv->sb_offset + viv->sb_blocks[i].byte_offset, SEEK_SET);
780 // load the block
781 load_sb_block(s, viv, 0);
782 if (viv->num_audio) {
783 const AVCodecParameters *par = s->streams[1]->codecpar;
784 // flush audio packet queue
786 viv->n_audio_subpackets = 0;
787 // most problematic part: guess audio offset
789 av_make_q(par->sample_rate, 1),
790 av_inv_q(s->streams[0]->time_base));
791 // hand-tuned 1.s a/v offset
792 viv->audio_sample += par->sample_rate;
793 }
794 viv->current_sb_entry = 0;
795 return 1;
796 }
797 }
798 return 0;
799}
800
802 .p.name = "vividas",
803 .p.long_name = NULL_IF_CONFIG_SMALL("Vividas VIV"),
804 .priv_data_size = sizeof(VividasDemuxContext),
805 .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
811};
const FFInputFormat ff_vividas_demuxer
Definition vividas.c:801
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:834
Main libavformat public API header.
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:483
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:98
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition aviobuf.c:326
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:494
unsigned int avio_rl16(AVIOContext *s)
Definition aviobuf.c:717
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, const 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:109
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:615
unsigned int avio_rl32(AVIOContext *s)
Definition aviobuf.c:733
int avio_r8(AVIOContext *s)
Definition aviobuf.c:606
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition aviobuf.c:919
void ffio_init_read_context(FFIOContext *s, const uint8_t *buffer, int buffer_size)
Wrap a buffer in an AVIOContext for reading.
Definition aviobuf.c:99
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:665
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
Definition utils.c:836
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
Definition demux.h:35
static AVPacket * pkt
static AVFrame * frame
static int64_t filesize(AVIOContext *pb)
Definition ffmpeg_mux.c:51
const char * key
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
#define sample
@ AV_CODEC_ID_VP6
Definition codec_id.h:141
@ AV_CODEC_ID_VORBIS
Definition codec_id.h:458
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:650
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition rational.h:71
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition rational.h:159
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_WN32(p, v)
#define AV_RN32(p)
#define AV_RL32(p)
unsigned offset
Definition libaomenc.c:763
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:237
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static av_cold int read_close(AVFormatContext *ctx)
Definition libcdio.c:143
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition libcdio.c:151
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:264
Memory handling functions.
#define av_malloc(s)
Definition ops_static.c:52
#define av_bswap32
Definition bswap.h:47
int nb_channels
Number of channels in this layout.
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
int extradata_size
Size of the extradata content in bytes.
Definition codec_par.h:75
int height
The height of the video frame in pixels.
Definition codec_par.h:150
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
Format I/O context.
Definition avformat.h:1333
Bytestream IO Context.
Definition avio.h:160
This structure stores compressed data.
Definition packet.h:580
This structure contains the data a format has to probe a file.
Definition avformat.h:471
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int64_t nb_frames
number of frames in this stream if known or 0
Definition avformat.h:827
int id
Format-specific stream ID.
Definition avformat.h:778
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:805
AVIOContext pub
int64_t byte_offset
Definition vividas.c:43
int n_packets
Definition vividas.c:42
int64_t packet_offset
Definition vividas.c:44
Definition vividas.c:47
int size
Definition vividas.c:48
int flag
Definition vividas.c:48
uint8_t * sb_buf
Definition vividas.c:64
VIV_SB_entry * sb_entries
Definition vividas.c:67
VIV_SB_block * sb_blocks
Definition vividas.c:57
int64_t audio_sample
Definition vividas.c:72
AVIOContext * sb_pb
Definition vividas.c:65
int current_audio_subpacket
Definition vividas.c:70
VIV_AudioSubpacket audio_subpackets[MAX_AUDIO_SUBPACKETS]
Definition vividas.c:74
uint32_t sb_key
Definition vividas.c:60
int64_t sb_offset
Definition vividas.c:61
#define av_free(p)
#define avpriv_request_sample(...)
#define av_freep(p)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
static attribute_nonstring const uint8_t plaintext[8]
Definition blowfish.c:113
#define src
Definition vp8dsp.c:248
int size
static double a2(void *priv, double x, double y)
Definition vf_xfade.c:2030
static int viv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition vividas.c:765
static int track_index(VividasDemuxContext *viv, AVFormatContext *s, const uint8_t *buf, unsigned size)
Definition vividas.c:438
static uint8_t * read_sb_block(AVIOContext *src, unsigned *size, uint32_t *key, unsigned expected_size)
Definition vividas.c:234
static int viv_read_close(AVFormatContext *s)
Definition vividas.c:753
static void load_sb_block(AVFormatContext *s, VividasDemuxContext *viv, unsigned expected_size)
Definition vividas.c:496
static int viv_read_header(AVFormatContext *s)
Definition vividas.c:540
static void decode_block(uint8_t *src, uint8_t *dest, unsigned size, uint32_t key, uint32_t *key_ptr, int align)
Definition vividas.c:144
static int viv_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition vividas.c:639
static const uint8_t keybits[32]
Definition vividas.c:85
static int track_header(VividasDemuxContext *viv, AVFormatContext *s, const uint8_t *buf, int size)
Definition vividas.c:282
static int viv_probe(const AVProbeData *p)
Definition vividas.c:77
#define MAX_AUDIO_SUBPACKETS
Definition vividas.c:39
static uint32_t decode_key(uint8_t *buf)
Definition vividas.c:92
static unsigned recover_key(unsigned char sample[4], unsigned expected_size)
Definition vividas.c:116
static uint32_t get_v(uint8_t *p, int len)
Definition vividas.c:184
static uint8_t * read_vblock(AVIOContext *src, uint32_t *size, uint32_t key, uint32_t *k2, int align)
Definition vividas.c:199
static void put_v(uint8_t *p, unsigned v)
Definition vividas.c:104
static void xor_block(void *p1, void *p2, unsigned size, int key, unsigned *key_ptr)
Definition vividas.c:125
float delta
int len
static double c[64]