You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

738 lines
19KB

  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. * @file
  25. * @brief Vividas VIV (.viv) file demuxer
  26. * @author Andrzej Szombierski [qq at kuku eu org] (2010-07)
  27. * @sa http://wiki.multimedia.cx/index.php?title=Vividas_VIV
  28. */
  29. #include "libavutil/intreadwrite.h"
  30. #include "avio_internal.h"
  31. #include "avformat.h"
  32. #include "internal.h"
  33. #define MAX_AUDIO_SUBPACKETS 100
  34. typedef struct VIV_SB_block {
  35. int size, n_packets;
  36. int64_t byte_offset;
  37. int64_t packet_offset;
  38. } VIV_SB_block;
  39. typedef struct VIV_SB_entry {
  40. int size, flag;
  41. } VIV_SB_entry;
  42. typedef struct VIV_AudioSubpacket {
  43. int start, pcm_bytes;
  44. } VIV_AudioSubpacket;
  45. typedef struct VividasDemuxContext {
  46. int n_sb_blocks;
  47. VIV_SB_block *sb_blocks;
  48. uint32_t sb_key;
  49. int64_t sb_offset;
  50. int current_sb, current_sb_entry;
  51. uint8_t *sb_buf;
  52. AVIOContext *sb_pb;
  53. int n_sb_entries;
  54. VIV_SB_entry *sb_entries;
  55. int n_audio_subpackets;
  56. int current_audio_subpacket;
  57. int64_t audio_sample;
  58. VIV_AudioSubpacket audio_subpackets[MAX_AUDIO_SUBPACKETS];
  59. } VividasDemuxContext;
  60. static int viv_probe(const AVProbeData *p)
  61. {
  62. if (memcmp(p->buf, "vividas03", 9))
  63. return 0;
  64. return AVPROBE_SCORE_MAX;
  65. }
  66. static const uint8_t keybits[32] = {
  67. 20, 52, 111, 10, 27, 71, 142, 53,
  68. 82, 138, 1, 78, 86, 121, 183, 85,
  69. 105, 152, 39, 140, 172, 11, 64, 144,
  70. 155, 6, 71, 163, 186, 49, 126, 43,
  71. };
  72. static uint32_t decode_key(uint8_t *buf)
  73. {
  74. uint32_t key = 0;
  75. for (int i = 0; i < 32; i++) {
  76. unsigned p = keybits[i];
  77. key |= ((buf[p] >> ((i*5+3)&7)) & 1u) << i;
  78. }
  79. return key;
  80. }
  81. static void put_v(uint8_t *p, unsigned v)
  82. {
  83. if (v>>28)
  84. *p++ = ((v>>28)&0x7f)|0x80;
  85. if (v>>21)
  86. *p++ = ((v>>21)&0x7f)|0x80;
  87. if (v>>14)
  88. *p++ = ((v>>14)&0x7f)|0x80;
  89. if (v>>7)
  90. *p++ = ((v>>7)&0x7f)|0x80;
  91. }
  92. static unsigned recover_key(unsigned char sample[4], unsigned expected_size)
  93. {
  94. unsigned char plaintext[8] = { 'S', 'B' };
  95. put_v(plaintext+2, expected_size);
  96. return AV_RL32(sample) ^ AV_RL32(plaintext);
  97. }
  98. static void xor_block(void *p1, void *p2, unsigned size, int key, unsigned *key_ptr)
  99. {
  100. unsigned *d1 = p1;
  101. unsigned *d2 = p2;
  102. unsigned k = *key_ptr;
  103. size >>= 2;
  104. while (size > 0) {
  105. *d2 = *d1 ^ (HAVE_BIGENDIAN ? av_bswap32(k) : k);
  106. k += key;
  107. d1++;
  108. d2++;
  109. size--;
  110. }
  111. *key_ptr = k;
  112. }
  113. static void decode_block(uint8_t *src, uint8_t *dest, unsigned size,
  114. uint32_t key, uint32_t *key_ptr,
  115. int align)
  116. {
  117. unsigned s = size;
  118. char tmp[4];
  119. int a2;
  120. if (!size)
  121. return;
  122. align &= 3;
  123. a2 = (4 - align) & 3;
  124. if (align) {
  125. uint32_t tmpkey = *key_ptr - key;
  126. memcpy(tmp + align, src, a2);
  127. xor_block(tmp, tmp, 4, key, &tmpkey);
  128. memcpy(dest, tmp + align, a2);
  129. s -= a2;
  130. }
  131. if (s >= 4) {
  132. if (!align)
  133. align = 4;
  134. xor_block(src + a2, dest + a2, s & ~3,
  135. key, key_ptr);
  136. s &= 3;
  137. }
  138. if (s) {
  139. size -= s;
  140. memcpy(tmp, src + size, s);
  141. xor_block(&tmp, &tmp, 4, key, key_ptr);
  142. memcpy(dest + size, tmp, s);
  143. }
  144. }
  145. static uint32_t get_v(uint8_t *p, int len)
  146. {
  147. uint32_t v = 0;
  148. const uint8_t *end = p + len;
  149. do {
  150. if (p >= end || v >= UINT_MAX / 128 - *p)
  151. return v;
  152. v <<= 7;
  153. v += *p & 0x7f;
  154. } while (*p++ & 0x80);
  155. return v;
  156. }
  157. static uint8_t *read_vblock(AVIOContext *src, uint32_t *size,
  158. uint32_t key, uint32_t *k2, int align)
  159. {
  160. uint8_t tmp[4];
  161. uint8_t *buf;
  162. unsigned n;
  163. if (avio_read(src, tmp, 4) != 4)
  164. return NULL;
  165. decode_block(tmp, tmp, 4, key, k2, align);
  166. n = get_v(tmp, 4);
  167. if (n < 4)
  168. return NULL;
  169. buf = av_malloc(n);
  170. if (!buf)
  171. return NULL;
  172. *size = n;
  173. n -= 4;
  174. memcpy(buf, tmp, 4);
  175. if (avio_read(src, buf + 4, n) == n) {
  176. decode_block(buf + 4, buf + 4, n, key, k2, align + 4);
  177. } else {
  178. av_free(buf);
  179. buf = NULL;
  180. }
  181. return buf;
  182. }
  183. static uint8_t *read_sb_block(AVIOContext *src, unsigned *size,
  184. uint32_t *key, unsigned expected_size)
  185. {
  186. uint8_t *buf;
  187. uint8_t ibuf[8], sbuf[8];
  188. uint32_t k2;
  189. unsigned n;
  190. if (avio_read(src, ibuf, 8) < 8)
  191. return NULL;
  192. k2 = *key;
  193. decode_block(ibuf, sbuf, 8, *key, &k2, 0);
  194. n = get_v(sbuf+2, 6);
  195. if (sbuf[0] != 'S' || sbuf[1] != 'B' || (expected_size>0 && n != expected_size)) {
  196. uint32_t tmpkey = recover_key(ibuf, expected_size);
  197. k2 = tmpkey;
  198. decode_block(ibuf, sbuf, 8, tmpkey, &k2, 0);
  199. n = get_v(sbuf+2, 6);
  200. if (sbuf[0] != 'S' || sbuf[1] != 'B' || expected_size != n)
  201. return NULL;
  202. *key = tmpkey;
  203. }
  204. if (n < 8)
  205. return NULL;
  206. buf = av_malloc(n);
  207. if (!buf)
  208. return NULL;
  209. memcpy(buf, sbuf, 8);
  210. *size = n;
  211. n -= 8;
  212. if (avio_read(src, buf+8, n) < n) {
  213. av_free(buf);
  214. return NULL;
  215. }
  216. decode_block(buf + 8, buf + 8, n, *key, &k2, 0);
  217. return buf;
  218. }
  219. static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *buf, int size)
  220. {
  221. int i,j;
  222. int64_t off;
  223. int val_1;
  224. int num_video, num_audio;
  225. AVIOContext *pb;
  226. pb = avio_alloc_context(buf, size, 0, NULL, NULL, NULL, NULL);
  227. if (!pb)
  228. return AVERROR(ENOMEM);
  229. ffio_read_varlen(pb); // track_header_len
  230. avio_r8(pb); // '1'
  231. val_1 = ffio_read_varlen(pb);
  232. for (i=0;i<val_1;i++) {
  233. int c = avio_r8(pb);
  234. for (j=0;j<c;j++) {
  235. avio_r8(pb); // val_3
  236. avio_r8(pb); // val_4
  237. }
  238. }
  239. avio_r8(pb); // num_streams
  240. off = avio_tell(pb);
  241. off += ffio_read_varlen(pb); // val_5
  242. avio_r8(pb); // '2'
  243. num_video = avio_r8(pb);
  244. avio_seek(pb, off, SEEK_SET);
  245. if (num_video != 1)
  246. av_log(s, AV_LOG_WARNING, "number of video tracks %d is not 1\n", num_video);
  247. for (i = 0; i < num_video; i++) {
  248. AVStream *st = avformat_new_stream(s, NULL);
  249. st->id = i;
  250. st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
  251. st->codecpar->codec_id = AV_CODEC_ID_VP6;
  252. off = avio_tell(pb);
  253. off += ffio_read_varlen(pb);
  254. avio_r8(pb); // '3'
  255. avio_r8(pb); // val_7
  256. st->time_base.num = avio_rl32(pb); // frame_time
  257. st->time_base.den = avio_rl32(pb); // time_base
  258. st->nb_frames = avio_rl32(pb); // n frames
  259. st->codecpar->width = avio_rl16(pb); // width
  260. st->codecpar->height = avio_rl16(pb); // height
  261. avio_r8(pb); // val_8
  262. avio_rl32(pb); // val_9
  263. avio_seek(pb, off, SEEK_SET);
  264. }
  265. off = avio_tell(pb);
  266. off += ffio_read_varlen(pb); // val_10
  267. avio_r8(pb); // '4'
  268. num_audio = avio_r8(pb);
  269. avio_seek(pb, off, SEEK_SET);
  270. if (num_audio != 1)
  271. av_log(s, AV_LOG_WARNING, "number of audio tracks %d is not 1\n", num_audio);
  272. for(i=0;i<num_audio;i++) {
  273. int q;
  274. AVStream *st = avformat_new_stream(s, NULL);
  275. st->id = num_video + i;
  276. st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
  277. st->codecpar->codec_id = AV_CODEC_ID_VORBIS;
  278. off = avio_tell(pb);
  279. off += ffio_read_varlen(pb); // length
  280. avio_r8(pb); // '5'
  281. avio_r8(pb); //codec_id
  282. avio_rl16(pb); //codec_subid
  283. st->codecpar->channels = avio_rl16(pb); // channels
  284. st->codecpar->sample_rate = avio_rl32(pb); // sample_rate
  285. avio_seek(pb, 10, SEEK_CUR); // data_1
  286. q = avio_r8(pb);
  287. avio_seek(pb, q, SEEK_CUR); // data_2
  288. avio_r8(pb); // zeropad
  289. if (avio_tell(pb) < off) {
  290. int num_data;
  291. int xd_size = 0;
  292. int data_len[256];
  293. int offset = 1;
  294. uint8_t *p;
  295. ffio_read_varlen(pb); // val_13
  296. avio_r8(pb); // '19'
  297. ffio_read_varlen(pb); // len_3
  298. num_data = avio_r8(pb);
  299. for (j = 0; j < num_data; j++) {
  300. data_len[j] = ffio_read_varlen(pb);
  301. xd_size += data_len[j];
  302. }
  303. st->codecpar->extradata_size = 64 + xd_size + xd_size / 255;
  304. if (ff_alloc_extradata(st->codecpar, st->codecpar->extradata_size))
  305. return AVERROR(ENOMEM);
  306. p = st->codecpar->extradata;
  307. p[0] = 2;
  308. for (j = 0; j < num_data - 1; j++)
  309. offset += av_xiphlacing(&p[offset], data_len[j]);
  310. for (j = 0; j < num_data; j++) {
  311. int ret = avio_read(pb, &p[offset], data_len[j]);
  312. if (ret < data_len[j]) {
  313. st->codecpar->extradata_size = 0;
  314. av_freep(&st->codecpar->extradata);
  315. break;
  316. }
  317. offset += data_len[j];
  318. }
  319. if (offset < st->codecpar->extradata_size)
  320. st->codecpar->extradata_size = offset;
  321. }
  322. }
  323. av_free(pb);
  324. return 0;
  325. }
  326. static void track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *buf, unsigned size)
  327. {
  328. int64_t off;
  329. int64_t poff;
  330. int maxnp=0;
  331. AVIOContext *pb;
  332. int i;
  333. pb = avio_alloc_context(buf, size, 0, NULL, NULL, NULL, NULL);
  334. if (!pb)
  335. return;
  336. ffio_read_varlen(pb); // track_index_len
  337. avio_r8(pb); // 'c'
  338. viv->n_sb_blocks = ffio_read_varlen(pb);
  339. viv->sb_blocks = av_calloc(viv->n_sb_blocks, sizeof(VIV_SB_block));
  340. if (!viv->sb_blocks) {
  341. viv->n_sb_blocks = 0;
  342. av_free(pb);
  343. return;
  344. }
  345. off = 0;
  346. poff = 0;
  347. for (i = 0; i < viv->n_sb_blocks; i++) {
  348. viv->sb_blocks[i].byte_offset = off;
  349. viv->sb_blocks[i].packet_offset = poff;
  350. viv->sb_blocks[i].size = ffio_read_varlen(pb);
  351. viv->sb_blocks[i].n_packets = ffio_read_varlen(pb);
  352. off += viv->sb_blocks[i].size;
  353. poff += viv->sb_blocks[i].n_packets;
  354. if (maxnp < viv->sb_blocks[i].n_packets)
  355. maxnp = viv->sb_blocks[i].n_packets;
  356. }
  357. viv->sb_entries = av_calloc(maxnp, sizeof(VIV_SB_entry));
  358. av_free(pb);
  359. }
  360. static void load_sb_block(AVFormatContext *s, VividasDemuxContext *viv, unsigned expected_size)
  361. {
  362. uint32_t size = 0;
  363. int i;
  364. AVIOContext *pb = 0;
  365. if (viv->sb_pb) {
  366. av_free(viv->sb_pb);
  367. viv->sb_pb = NULL;
  368. }
  369. if (viv->sb_buf)
  370. av_free(viv->sb_buf);
  371. viv->sb_buf = read_sb_block(s->pb, &size, &viv->sb_key, expected_size);
  372. if (!viv->sb_buf) {
  373. return;
  374. }
  375. pb = avio_alloc_context(viv->sb_buf, size, 0, NULL, NULL, NULL, NULL);
  376. if (!pb)
  377. return;
  378. viv->sb_pb = pb;
  379. avio_r8(pb); // 'S'
  380. avio_r8(pb); // 'B'
  381. ffio_read_varlen(pb); // size
  382. avio_r8(pb); // junk
  383. ffio_read_varlen(pb); // first packet
  384. viv->n_sb_entries = viv->sb_blocks[viv->current_sb].n_packets;
  385. for (i = 0; i < viv->n_sb_entries; i++) {
  386. viv->sb_entries[i].size = ffio_read_varlen(pb);
  387. viv->sb_entries[i].flag = avio_r8(pb);
  388. }
  389. ffio_read_varlen(pb);
  390. avio_r8(pb);
  391. viv->current_sb_entry = 0;
  392. }
  393. static int viv_read_header(AVFormatContext *s)
  394. {
  395. VividasDemuxContext *viv = s->priv_data;
  396. AVIOContext *pb = s->pb;
  397. int64_t header_end;
  398. int num_tracks;
  399. uint32_t key, k2;
  400. uint32_t v;
  401. uint8_t keybuffer[187];
  402. uint32_t b22_size = 0;
  403. uint32_t b22_key = 0;
  404. uint8_t *buf = 0;
  405. int ret;
  406. avio_skip(pb, 9);
  407. header_end = avio_tell(pb);
  408. header_end += ffio_read_varlen(pb);
  409. num_tracks = avio_r8(pb);
  410. if (num_tracks != 1) {
  411. av_log(s, AV_LOG_ERROR, "number of tracks %d is not 1\n", num_tracks);
  412. return AVERROR(EINVAL);
  413. }
  414. v = avio_r8(pb);
  415. avio_seek(pb, v, SEEK_CUR);
  416. avio_read(pb, keybuffer, 187);
  417. key = decode_key(keybuffer);
  418. viv->sb_key = key;
  419. avio_rl32(pb);
  420. for (;;) {
  421. int64_t here = avio_tell(pb);
  422. int block_len, block_type;
  423. if (here >= header_end)
  424. break;
  425. block_len = ffio_read_varlen(pb);
  426. block_type = avio_r8(pb);
  427. if (block_type == 22) {
  428. avio_read(pb, keybuffer, 187);
  429. b22_key = decode_key(keybuffer);
  430. b22_size = avio_rl32(pb);
  431. }
  432. avio_seek(pb, here + block_len, SEEK_SET);
  433. }
  434. if (b22_size) {
  435. k2 = b22_key;
  436. buf = read_vblock(pb, &v, b22_key, &k2, 0);
  437. if (!buf)
  438. return AVERROR(EIO);
  439. av_free(buf);
  440. }
  441. k2 = key;
  442. buf = read_vblock(pb, &v, key, &k2, 0);
  443. if (!buf)
  444. return AVERROR(EIO);
  445. ret = track_header(viv, s, buf, v);
  446. av_free(buf);
  447. if (ret < 0)
  448. return ret;
  449. buf = read_vblock(pb, &v, key, &k2, v);
  450. if (!buf)
  451. return AVERROR(EIO);
  452. track_index(viv, s, buf, v);
  453. av_free(buf);
  454. viv->sb_offset = avio_tell(pb);
  455. if (viv->n_sb_blocks > 0) {
  456. viv->current_sb = 0;
  457. load_sb_block(s, viv, viv->sb_blocks[0].size);
  458. } else {
  459. viv->current_sb = -1;
  460. }
  461. return 0;
  462. }
  463. static int viv_read_packet(AVFormatContext *s,
  464. AVPacket *pkt)
  465. {
  466. VividasDemuxContext *viv = s->priv_data;
  467. AVIOContext *pb;
  468. int64_t off;
  469. int ret;
  470. if (!viv->sb_pb)
  471. return AVERROR(EIO);
  472. if (avio_feof(viv->sb_pb))
  473. return AVERROR_EOF;
  474. if (viv->current_audio_subpacket < viv->n_audio_subpackets) {
  475. AVStream *astream;
  476. int size = viv->audio_subpackets[viv->current_audio_subpacket+1].start - viv->audio_subpackets[viv->current_audio_subpacket].start;
  477. pb = viv->sb_pb;
  478. ret = av_get_packet(pb, pkt, size);
  479. if (ret < 0)
  480. return ret;
  481. pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
  482. pkt->stream_index = 1;
  483. astream = s->streams[pkt->stream_index];
  484. pkt->pts = av_rescale(viv->audio_sample, astream->time_base.den, astream->time_base.num) / astream->codecpar->sample_rate;
  485. viv->audio_sample += viv->audio_subpackets[viv->current_audio_subpacket].pcm_bytes / 2 / astream->codecpar->channels;
  486. pkt->flags |= AV_PKT_FLAG_KEY;
  487. viv->current_audio_subpacket++;
  488. return 0;
  489. }
  490. if (viv->current_sb_entry >= viv->n_sb_entries) {
  491. if (viv->current_sb+1 >= viv->n_sb_blocks)
  492. return AVERROR(EIO);
  493. viv->current_sb++;
  494. load_sb_block(s, viv, 0);
  495. viv->current_sb_entry = 0;
  496. }
  497. pb = viv->sb_pb;
  498. if (!pb)
  499. return AVERROR(EIO);
  500. off = avio_tell(pb);
  501. off += viv->sb_entries[viv->current_sb_entry].size;
  502. if (viv->sb_entries[viv->current_sb_entry].flag == 0) {
  503. uint64_t v_size = ffio_read_varlen(pb);
  504. ffio_read_varlen(pb);
  505. if (v_size > INT_MAX)
  506. return AVERROR_INVALIDDATA;
  507. ret = av_get_packet(pb, pkt, v_size);
  508. if (ret < 0)
  509. return ret;
  510. pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
  511. pkt->pts = viv->sb_blocks[viv->current_sb].packet_offset + viv->current_sb_entry;
  512. pkt->flags |= (pkt->data[0]&0x80)?0:AV_PKT_FLAG_KEY;
  513. pkt->stream_index = 0;
  514. for (int i = 0; i < MAX_AUDIO_SUBPACKETS - 1; i++) {
  515. int start, pcm_bytes;
  516. start = ffio_read_varlen(pb);
  517. pcm_bytes = ffio_read_varlen(pb);
  518. if (i > 0 && start == 0)
  519. break;
  520. viv->n_audio_subpackets = i + 1;
  521. viv->audio_subpackets[i].start = start;
  522. viv->audio_subpackets[i].pcm_bytes = pcm_bytes;
  523. }
  524. viv->audio_subpackets[viv->n_audio_subpackets].start = (int)(off - avio_tell(pb));
  525. viv->current_audio_subpacket = 0;
  526. } else {
  527. uint64_t v_size = ffio_read_varlen(pb);
  528. if (v_size > INT_MAX)
  529. return AVERROR_INVALIDDATA;
  530. ret = av_get_packet(pb, pkt, v_size);
  531. if (ret < 0)
  532. return ret;
  533. pkt->pos += viv->sb_offset + viv->sb_blocks[viv->current_sb].byte_offset;
  534. pkt->pts = viv->sb_blocks[viv->current_sb].packet_offset + viv->current_sb_entry;
  535. pkt->flags |= (pkt->data[0] & 0x80) ? 0 : AV_PKT_FLAG_KEY;
  536. pkt->stream_index = 0;
  537. }
  538. viv->current_sb_entry++;
  539. return 0;
  540. }
  541. static int viv_read_close(AVFormatContext *s)
  542. {
  543. VividasDemuxContext *viv = s->priv_data;
  544. av_freep(&viv->sb_pb);
  545. av_freep(&viv->sb_buf);
  546. av_freep(&viv->sb_blocks);
  547. av_freep(&viv->sb_entries);
  548. return 0;
  549. }
  550. static int viv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
  551. {
  552. VividasDemuxContext *viv = s->priv_data;
  553. int64_t frame;
  554. if (stream_index == 0)
  555. frame = timestamp;
  556. else
  557. frame = av_rescale_q(timestamp, s->streams[0]->time_base, s->streams[stream_index]->time_base);
  558. for (int i = 0; i < viv->n_sb_blocks; i++) {
  559. if (frame >= viv->sb_blocks[i].packet_offset && frame < viv->sb_blocks[i].packet_offset + viv->sb_blocks[i].n_packets) {
  560. // flush audio packet queue
  561. viv->current_audio_subpacket = 0;
  562. viv->n_audio_subpackets = 0;
  563. viv->current_sb = i;
  564. // seek to ith sb block
  565. avio_seek(s->pb, viv->sb_offset + viv->sb_blocks[i].byte_offset, SEEK_SET);
  566. // load the block
  567. load_sb_block(s, viv, 0);
  568. // most problematic part: guess audio offset
  569. viv->audio_sample = av_rescale_q(viv->sb_blocks[i].packet_offset, av_make_q(s->streams[1]->codecpar->sample_rate, 1), av_inv_q(s->streams[0]->time_base));
  570. // hand-tuned 1.s a/v offset
  571. viv->audio_sample += s->streams[1]->codecpar->sample_rate;
  572. viv->current_sb_entry = 0;
  573. return 1;
  574. }
  575. }
  576. return 0;
  577. }
  578. AVInputFormat ff_vividas_demuxer = {
  579. .name = "vividas",
  580. .long_name = NULL_IF_CONFIG_SMALL("Vividas VIV"),
  581. .priv_data_size = sizeof(VividasDemuxContext),
  582. .read_probe = viv_probe,
  583. .read_header = viv_read_header,
  584. .read_packet = viv_read_packet,
  585. .read_close = viv_read_close,
  586. .read_seek = viv_read_seek,
  587. };