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.

640 lines
19KB

  1. /*
  2. * Sony OpenMG (OMA) demuxer
  3. *
  4. * Copyright (c) 2008, 2013 Maxim Poliakovski
  5. * 2008 Benjamin Larsson
  6. * 2011 David Goldwich
  7. *
  8. * This file is part of FFmpeg.
  9. *
  10. * FFmpeg is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * FFmpeg is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with FFmpeg; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. /**
  25. * @file
  26. * This is a demuxer for Sony OpenMG Music files
  27. *
  28. * Known file extensions: ".oma", "aa3"
  29. * The format of such files consists of three parts:
  30. * - "ea3" header carrying overall info and metadata. Except for starting with
  31. * "ea" instead of "ID", it's an ID3v2 header.
  32. * - "EA3" header is a Sony-specific header containing information about
  33. * the OpenMG file: codec type (usually ATRAC, can also be MP3 or WMA),
  34. * codec specific info (packet size, sample rate, channels and so on)
  35. * and DRM related info (file encryption, content id).
  36. * - Sound data organized in packets follow the EA3 header
  37. * (can be encrypted using the Sony DRM!).
  38. *
  39. * Supported decoders: ATRAC3, ATRAC3+, MP3, LPCM
  40. */
  41. #include <inttypes.h>
  42. #include "libavutil/channel_layout.h"
  43. #include "avformat.h"
  44. #include "internal.h"
  45. #include "libavutil/intreadwrite.h"
  46. #include "libavutil/des.h"
  47. #include "libavutil/mathematics.h"
  48. #include "oma.h"
  49. #include "pcm.h"
  50. #include "id3v2.h"
  51. static const uint64_t leaf_table[] = {
  52. 0xd79e8283acea4620, 0x7a9762f445afd0d8,
  53. 0x354d60a60b8c79f1, 0x584e1cde00b07aee,
  54. 0x1573cd93da7df623, 0x47f98d79620dd535
  55. };
  56. /** map ATRAC-X channel id to internal channel layout */
  57. static const uint64_t oma_chid_to_native_layout[7] = {
  58. AV_CH_LAYOUT_MONO,
  59. AV_CH_LAYOUT_STEREO,
  60. AV_CH_LAYOUT_SURROUND,
  61. AV_CH_LAYOUT_4POINT0,
  62. AV_CH_LAYOUT_5POINT1_BACK,
  63. AV_CH_LAYOUT_6POINT1_BACK,
  64. AV_CH_LAYOUT_7POINT1
  65. };
  66. /** map ATRAC-X channel id to total number of channels */
  67. static const int oma_chid_to_num_channels[7] = { 1, 2, 3, 4, 6, 7, 8 };
  68. typedef struct OMAContext {
  69. uint64_t content_start;
  70. int encrypted;
  71. uint16_t k_size;
  72. uint16_t e_size;
  73. uint16_t i_size;
  74. uint16_t s_size;
  75. uint32_t rid;
  76. uint8_t r_val[24];
  77. uint8_t n_val[24];
  78. uint8_t m_val[8];
  79. uint8_t s_val[8];
  80. uint8_t sm_val[8];
  81. uint8_t e_val[8];
  82. uint8_t iv[8];
  83. struct AVDES *av_des;
  84. int (*read_packet)(AVFormatContext *s, AVPacket *pkt);
  85. } OMAContext;
  86. static int oma_read_close(AVFormatContext *s)
  87. {
  88. OMAContext *oc = s->priv_data;
  89. av_freep(&oc->av_des);
  90. return 0;
  91. }
  92. static void hex_log(AVFormatContext *s, int level,
  93. const char *name, const uint8_t *value, int len)
  94. {
  95. char buf[33];
  96. len = FFMIN(len, 16);
  97. if (av_log_get_level() < level)
  98. return;
  99. ff_data_to_hex(buf, value, len, 1);
  100. buf[len << 1] = '\0';
  101. av_log(s, level, "%s: %s\n", name, buf);
  102. }
  103. static int kset(AVFormatContext *s, const uint8_t *r_val, const uint8_t *n_val,
  104. int len)
  105. {
  106. OMAContext *oc = s->priv_data;
  107. if (!r_val && !n_val)
  108. return -1;
  109. len = FFMIN(len, 16);
  110. /* use first 64 bits in the third round again */
  111. if (r_val) {
  112. if (r_val != oc->r_val) {
  113. memset(oc->r_val, 0, 24);
  114. memcpy(oc->r_val, r_val, len);
  115. }
  116. memcpy(&oc->r_val[16], r_val, 8);
  117. }
  118. if (n_val) {
  119. if (n_val != oc->n_val) {
  120. memset(oc->n_val, 0, 24);
  121. memcpy(oc->n_val, n_val, len);
  122. }
  123. memcpy(&oc->n_val[16], n_val, 8);
  124. }
  125. return 0;
  126. }
  127. #define OMA_RPROBE_M_VAL 48 + 1
  128. static int rprobe(AVFormatContext *s, uint8_t *enc_header, unsigned size,
  129. const uint8_t *r_val)
  130. {
  131. OMAContext *oc = s->priv_data;
  132. unsigned int pos;
  133. struct AVDES *av_des;
  134. if (!enc_header || !r_val ||
  135. size < OMA_ENC_HEADER_SIZE + oc->k_size + oc->e_size + oc->i_size ||
  136. size < OMA_RPROBE_M_VAL)
  137. return -1;
  138. av_des = av_des_alloc();
  139. if (!av_des)
  140. return AVERROR(ENOMEM);
  141. /* m_val */
  142. av_des_init(av_des, r_val, 192, 1);
  143. av_des_crypt(av_des, oc->m_val, &enc_header[48], 1, NULL, 1);
  144. /* s_val */
  145. av_des_init(av_des, oc->m_val, 64, 0);
  146. av_des_crypt(av_des, oc->s_val, NULL, 1, NULL, 0);
  147. /* sm_val */
  148. pos = OMA_ENC_HEADER_SIZE + oc->k_size + oc->e_size;
  149. av_des_init(av_des, oc->s_val, 64, 0);
  150. av_des_mac(av_des, oc->sm_val, &enc_header[pos], (oc->i_size >> 3));
  151. pos += oc->i_size;
  152. av_free(av_des);
  153. return memcmp(&enc_header[pos], oc->sm_val, 8) ? -1 : 0;
  154. }
  155. static int nprobe(AVFormatContext *s, uint8_t *enc_header, unsigned size,
  156. const uint8_t *n_val)
  157. {
  158. OMAContext *oc = s->priv_data;
  159. uint64_t pos;
  160. uint32_t taglen, datalen;
  161. struct AVDES *av_des;
  162. if (!enc_header || !n_val ||
  163. size < OMA_ENC_HEADER_SIZE + oc->k_size + 4)
  164. return -1;
  165. pos = OMA_ENC_HEADER_SIZE + oc->k_size;
  166. if (!memcmp(&enc_header[pos], "EKB ", 4))
  167. pos += 32;
  168. if (size < pos + 44)
  169. return -1;
  170. if (AV_RB32(&enc_header[pos]) != oc->rid)
  171. av_log(s, AV_LOG_DEBUG, "Mismatching RID\n");
  172. taglen = AV_RB32(&enc_header[pos + 32]);
  173. datalen = AV_RB32(&enc_header[pos + 36]) >> 4;
  174. pos += 44LL + taglen;
  175. if (pos + (((uint64_t)datalen) << 4) > size)
  176. return -1;
  177. av_des = av_des_alloc();
  178. if (!av_des)
  179. return AVERROR(ENOMEM);
  180. av_des_init(av_des, n_val, 192, 1);
  181. while (datalen-- > 0) {
  182. av_des_crypt(av_des, oc->r_val, &enc_header[pos], 2, NULL, 1);
  183. kset(s, oc->r_val, NULL, 16);
  184. if (!rprobe(s, enc_header, size, oc->r_val)) {
  185. av_free(av_des);
  186. return 0;
  187. }
  188. pos += 16;
  189. }
  190. av_free(av_des);
  191. return -1;
  192. }
  193. static int decrypt_init(AVFormatContext *s, ID3v2ExtraMeta *em, uint8_t *header)
  194. {
  195. OMAContext *oc = s->priv_data;
  196. ID3v2ExtraMetaGEOB *geob = NULL;
  197. uint8_t *gdata;
  198. oc->encrypted = 1;
  199. av_log(s, AV_LOG_INFO, "File is encrypted\n");
  200. /* find GEOB metadata */
  201. for (; em; em = em->next) {
  202. if (strcmp(em->tag, "GEOB"))
  203. continue;
  204. geob = &em->data.geob;
  205. if (!strcmp(geob->description, "OMG_LSI") ||
  206. !strcmp(geob->description, "OMG_BKLSI"))
  207. break;
  208. }
  209. if (!em) {
  210. av_log(s, AV_LOG_ERROR, "No encryption header found\n");
  211. return AVERROR_INVALIDDATA;
  212. }
  213. if (geob->datasize < 64) {
  214. av_log(s, AV_LOG_ERROR,
  215. "Invalid GEOB data size: %"PRIu32"\n", geob->datasize);
  216. return AVERROR_INVALIDDATA;
  217. }
  218. gdata = geob->data;
  219. if (AV_RB16(gdata) != 1)
  220. av_log(s, AV_LOG_WARNING, "Unknown version in encryption header\n");
  221. oc->k_size = AV_RB16(&gdata[2]);
  222. oc->e_size = AV_RB16(&gdata[4]);
  223. oc->i_size = AV_RB16(&gdata[6]);
  224. oc->s_size = AV_RB16(&gdata[8]);
  225. if (memcmp(&gdata[OMA_ENC_HEADER_SIZE], "KEYRING ", 12)) {
  226. av_log(s, AV_LOG_ERROR, "Invalid encryption header\n");
  227. return AVERROR_INVALIDDATA;
  228. }
  229. if (OMA_ENC_HEADER_SIZE + oc->k_size + oc->e_size + oc->i_size + 8 > geob->datasize ||
  230. OMA_ENC_HEADER_SIZE + 48 > geob->datasize) {
  231. av_log(s, AV_LOG_ERROR, "Too little GEOB data\n");
  232. return AVERROR_INVALIDDATA;
  233. }
  234. oc->rid = AV_RB32(&gdata[OMA_ENC_HEADER_SIZE + 28]);
  235. av_log(s, AV_LOG_DEBUG, "RID: %.8"PRIx32"\n", oc->rid);
  236. memcpy(oc->iv, &header[0x58], 8);
  237. hex_log(s, AV_LOG_DEBUG, "IV", oc->iv, 8);
  238. hex_log(s, AV_LOG_DEBUG, "CBC-MAC",
  239. &gdata[OMA_ENC_HEADER_SIZE + oc->k_size + oc->e_size + oc->i_size],
  240. 8);
  241. if (s->keylen > 0) {
  242. kset(s, s->key, s->key, s->keylen);
  243. }
  244. if (!memcmp(oc->r_val, (const uint8_t[8]){0}, 8) ||
  245. rprobe(s, gdata, geob->datasize, oc->r_val) < 0 &&
  246. nprobe(s, gdata, geob->datasize, oc->n_val) < 0) {
  247. int i;
  248. for (i = 0; i < FF_ARRAY_ELEMS(leaf_table); i += 2) {
  249. uint8_t buf[16];
  250. AV_WL64(buf, leaf_table[i]);
  251. AV_WL64(&buf[8], leaf_table[i + 1]);
  252. kset(s, buf, buf, 16);
  253. if (!rprobe(s, gdata, geob->datasize, oc->r_val) ||
  254. !nprobe(s, gdata, geob->datasize, oc->n_val))
  255. break;
  256. }
  257. if (i >= FF_ARRAY_ELEMS(leaf_table)) {
  258. av_log(s, AV_LOG_ERROR, "Invalid key\n");
  259. return AVERROR_INVALIDDATA;
  260. }
  261. }
  262. oc->av_des = av_des_alloc();
  263. if (!oc->av_des)
  264. return AVERROR(ENOMEM);
  265. /* e_val */
  266. av_des_init(oc->av_des, oc->m_val, 64, 0);
  267. av_des_crypt(oc->av_des, oc->e_val,
  268. &gdata[OMA_ENC_HEADER_SIZE + 40], 1, NULL, 0);
  269. hex_log(s, AV_LOG_DEBUG, "EK", oc->e_val, 8);
  270. /* init e_val */
  271. av_des_init(oc->av_des, oc->e_val, 64, 1);
  272. return 0;
  273. }
  274. static int read_packet(AVFormatContext *s, AVPacket *pkt)
  275. {
  276. OMAContext *oc = s->priv_data;
  277. AVStream *st = s->streams[0];
  278. int packet_size = st->codecpar->block_align;
  279. int byte_rate = st->codecpar->bit_rate >> 3;
  280. int64_t pos = avio_tell(s->pb);
  281. int ret = av_get_packet(s->pb, pkt, packet_size);
  282. if (ret < packet_size)
  283. pkt->flags |= AV_PKT_FLAG_CORRUPT;
  284. if (ret < 0)
  285. return ret;
  286. if (!ret)
  287. return AVERROR_EOF;
  288. pkt->stream_index = 0;
  289. if (pos >= oc->content_start && byte_rate > 0) {
  290. pkt->pts =
  291. pkt->dts = av_rescale(pos - oc->content_start, st->time_base.den,
  292. byte_rate * (int64_t)st->time_base.num);
  293. }
  294. if (oc->encrypted) {
  295. /* previous unencrypted block saved in IV for
  296. * the next packet (CBC mode) */
  297. if (ret == packet_size)
  298. av_des_crypt(oc->av_des, pkt->data, pkt->data,
  299. (packet_size >> 3), oc->iv, 1);
  300. else
  301. memset(oc->iv, 0, 8);
  302. }
  303. return ret;
  304. }
  305. static int aal_read_packet(AVFormatContext *s, AVPacket *pkt)
  306. {
  307. int64_t pos = avio_tell(s->pb);
  308. int ret, pts;
  309. int packet_size;
  310. unsigned tag;
  311. if (avio_feof(s->pb))
  312. return AVERROR_EOF;
  313. tag = avio_rb24(s->pb);
  314. if (tag == 0)
  315. return AVERROR_EOF;
  316. else if (tag != MKBETAG(0,'B','L','K'))
  317. return AVERROR_INVALIDDATA;
  318. avio_skip(s->pb, 1);
  319. packet_size = avio_rb16(s->pb);
  320. avio_skip(s->pb, 2);
  321. pts = avio_rb32(s->pb);
  322. avio_skip(s->pb, 12);
  323. ret = av_get_packet(s->pb, pkt, packet_size);
  324. if (ret < packet_size)
  325. pkt->flags |= AV_PKT_FLAG_CORRUPT;
  326. if (ret < 0)
  327. return ret;
  328. if (!ret)
  329. return AVERROR_EOF;
  330. pkt->stream_index = 0;
  331. pkt->pos = pos;
  332. if (s->streams[0]->codecpar->codec_id == AV_CODEC_ID_ATRAC3AL) {
  333. pkt->duration = 1024;
  334. pkt->pts = pts * 1024LL;
  335. } else {
  336. pkt->duration = 2048;
  337. pkt->pts = pts * 2048LL;
  338. }
  339. return ret;
  340. }
  341. static int oma_read_header(AVFormatContext *s)
  342. {
  343. int ret, framesize, jsflag, samplerate;
  344. uint32_t codec_params, channel_id;
  345. int16_t eid;
  346. uint8_t buf[EA3_HEADER_SIZE];
  347. uint8_t *edata;
  348. AVStream *st;
  349. ID3v2ExtraMeta *extra_meta;
  350. OMAContext *oc = s->priv_data;
  351. ff_id3v2_read(s, ID3v2_EA3_MAGIC, &extra_meta, 0);
  352. if ((ret = ff_id3v2_parse_chapters(s, extra_meta)) < 0) {
  353. ff_id3v2_free_extra_meta(&extra_meta);
  354. return ret;
  355. }
  356. ret = avio_read(s->pb, buf, EA3_HEADER_SIZE);
  357. if (ret < EA3_HEADER_SIZE) {
  358. ff_id3v2_free_extra_meta(&extra_meta);
  359. return -1;
  360. }
  361. if (memcmp(buf, ((const uint8_t[]){'E', 'A', '3'}), 3) ||
  362. buf[4] != 0 || buf[5] != EA3_HEADER_SIZE) {
  363. ff_id3v2_free_extra_meta(&extra_meta);
  364. av_log(s, AV_LOG_ERROR, "Couldn't find the EA3 header !\n");
  365. return AVERROR_INVALIDDATA;
  366. }
  367. oc->content_start = avio_tell(s->pb);
  368. /* encrypted file */
  369. eid = AV_RB16(&buf[6]);
  370. if (eid != -1 && eid != -128 && decrypt_init(s, extra_meta, buf) < 0) {
  371. ff_id3v2_free_extra_meta(&extra_meta);
  372. return -1;
  373. }
  374. ff_id3v2_free_extra_meta(&extra_meta);
  375. codec_params = AV_RB24(&buf[33]);
  376. st = avformat_new_stream(s, NULL);
  377. if (!st) {
  378. ret = AVERROR(ENOMEM);
  379. goto fail;
  380. }
  381. st->start_time = 0;
  382. st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
  383. st->codecpar->codec_tag = buf[32];
  384. st->codecpar->codec_id = ff_codec_get_id(ff_oma_codec_tags,
  385. st->codecpar->codec_tag);
  386. oc->read_packet = read_packet;
  387. switch (buf[32]) {
  388. case OMA_CODECID_ATRAC3:
  389. samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7] * 100;
  390. if (!samplerate) {
  391. av_log(s, AV_LOG_ERROR, "Unsupported sample rate\n");
  392. ret = AVERROR_INVALIDDATA;
  393. goto fail;
  394. }
  395. if (samplerate != 44100)
  396. avpriv_request_sample(s, "Sample rate %d", samplerate);
  397. framesize = (codec_params & 0x3FF) * 8;
  398. /* get stereo coding mode, 1 for joint-stereo */
  399. jsflag = (codec_params >> 17) & 1;
  400. st->codecpar->channels = 2;
  401. st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
  402. st->codecpar->sample_rate = samplerate;
  403. st->codecpar->bit_rate = st->codecpar->sample_rate * framesize / (1024 / 8);
  404. /* fake the ATRAC3 extradata
  405. * (wav format, makes stream copy to wav work) */
  406. if ((ret = ff_alloc_extradata(st->codecpar, 14)) < 0)
  407. goto fail;
  408. edata = st->codecpar->extradata;
  409. AV_WL16(&edata[0], 1); // always 1
  410. AV_WL32(&edata[2], samplerate); // samples rate
  411. AV_WL16(&edata[6], jsflag); // coding mode
  412. AV_WL16(&edata[8], jsflag); // coding mode
  413. AV_WL16(&edata[10], 1); // always 1
  414. // AV_WL16(&edata[12], 0); // always 0
  415. avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
  416. break;
  417. case OMA_CODECID_ATRAC3P:
  418. channel_id = (codec_params >> 10) & 7;
  419. if (!channel_id) {
  420. av_log(s, AV_LOG_ERROR,
  421. "Invalid ATRAC-X channel id: %"PRIu32"\n", channel_id);
  422. ret = AVERROR_INVALIDDATA;
  423. goto fail;
  424. }
  425. st->codecpar->channel_layout = oma_chid_to_native_layout[channel_id - 1];
  426. st->codecpar->channels = oma_chid_to_num_channels[channel_id - 1];
  427. framesize = ((codec_params & 0x3FF) * 8) + 8;
  428. samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7] * 100;
  429. if (!samplerate) {
  430. av_log(s, AV_LOG_ERROR, "Unsupported sample rate\n");
  431. ret = AVERROR_INVALIDDATA;
  432. goto fail;
  433. }
  434. st->codecpar->sample_rate = samplerate;
  435. st->codecpar->bit_rate = samplerate * framesize / (2048 / 8);
  436. avpriv_set_pts_info(st, 64, 1, samplerate);
  437. break;
  438. case OMA_CODECID_MP3:
  439. st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
  440. framesize = 1024;
  441. break;
  442. case OMA_CODECID_LPCM:
  443. /* PCM 44.1 kHz 16 bit stereo big-endian */
  444. st->codecpar->channels = 2;
  445. st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
  446. st->codecpar->sample_rate = 44100;
  447. framesize = 1024;
  448. /* bit rate = sample rate x PCM block align (= 4) x 8 */
  449. st->codecpar->bit_rate = st->codecpar->sample_rate * 32;
  450. st->codecpar->bits_per_coded_sample =
  451. av_get_bits_per_sample(st->codecpar->codec_id);
  452. avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
  453. break;
  454. case OMA_CODECID_ATRAC3AL:
  455. st->codecpar->channels = 2;
  456. st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
  457. st->codecpar->sample_rate = 44100;
  458. avpriv_set_pts_info(st, 64, 1, 44100);
  459. oc->read_packet = aal_read_packet;
  460. framesize = 4096;
  461. break;
  462. case OMA_CODECID_ATRAC3PAL:
  463. st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
  464. st->codecpar->channels = 2;
  465. st->codecpar->sample_rate = 44100;
  466. avpriv_set_pts_info(st, 64, 1, 44100);
  467. oc->read_packet = aal_read_packet;
  468. framesize = 4096;
  469. break;
  470. default:
  471. av_log(s, AV_LOG_ERROR, "Unsupported codec %d!\n", buf[32]);
  472. ret = AVERROR(ENOSYS);
  473. goto fail;
  474. }
  475. st->codecpar->block_align = framesize;
  476. return 0;
  477. fail:
  478. oma_read_close(s);
  479. return ret;
  480. }
  481. static int oma_read_packet(AVFormatContext *s, AVPacket *pkt)
  482. {
  483. OMAContext *oc = s->priv_data;
  484. return oc->read_packet(s, pkt);
  485. }
  486. static int oma_read_probe(const AVProbeData *p)
  487. {
  488. const uint8_t *buf = p->buf;
  489. unsigned tag_len = 0;
  490. if (p->buf_size >= ID3v2_HEADER_SIZE && ff_id3v2_match(buf, ID3v2_EA3_MAGIC))
  491. tag_len = ff_id3v2_tag_len(buf);
  492. /* This check cannot overflow as tag_len has at most 28 bits */
  493. if (p->buf_size < tag_len + 5)
  494. /* EA3 header comes late, might be outside of the probe buffer */
  495. return tag_len ? AVPROBE_SCORE_EXTENSION/2 : 0;
  496. buf += tag_len;
  497. if (!memcmp(buf, "EA3", 3) && !buf[4] && buf[5] == EA3_HEADER_SIZE)
  498. return AVPROBE_SCORE_MAX;
  499. else
  500. return 0;
  501. }
  502. static int oma_read_seek(struct AVFormatContext *s,
  503. int stream_index, int64_t timestamp, int flags)
  504. {
  505. OMAContext *oc = s->priv_data;
  506. AVStream *st = s->streams[0];
  507. int64_t err;
  508. if (st->codecpar->codec_id == AV_CODEC_ID_ATRAC3PAL ||
  509. st->codecpar->codec_id == AV_CODEC_ID_ATRAC3AL)
  510. return -1;
  511. err = ff_pcm_read_seek(s, stream_index, timestamp, flags);
  512. if (!oc->encrypted)
  513. return err;
  514. /* readjust IV for CBC */
  515. if (err || avio_tell(s->pb) < oc->content_start)
  516. goto wipe;
  517. if ((err = avio_seek(s->pb, -8, SEEK_CUR)) < 0)
  518. goto wipe;
  519. if ((err = avio_read(s->pb, oc->iv, 8)) < 8) {
  520. if (err >= 0)
  521. err = AVERROR_EOF;
  522. goto wipe;
  523. }
  524. return 0;
  525. wipe:
  526. memset(oc->iv, 0, 8);
  527. return err;
  528. }
  529. AVInputFormat ff_oma_demuxer = {
  530. .name = "oma",
  531. .long_name = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),
  532. .priv_data_size = sizeof(OMAContext),
  533. .read_probe = oma_read_probe,
  534. .read_header = oma_read_header,
  535. .read_packet = oma_read_packet,
  536. .read_seek = oma_read_seek,
  537. .read_close = oma_read_close,
  538. .flags = AVFMT_GENERIC_INDEX,
  539. .extensions = "oma,omg,aa3",
  540. .codec_tag = ff_oma_codec_tags_list,
  541. };