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.

637 lines
20KB

  1. /* Electronic Arts Multimedia File Demuxer
  2. * Copyright (c) 2004 The ffmpeg Project
  3. * Copyright (c) 2006-2008 Peter Ross
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * Electronic Arts Multimedia file demuxer (WVE/UV2/etc.)
  24. * by Robin Kay (komadori at gekkou.co.uk)
  25. */
  26. #include "libavutil/intreadwrite.h"
  27. #include "avformat.h"
  28. #include "internal.h"
  29. #define SCHl_TAG MKTAG('S', 'C', 'H', 'l')
  30. #define SEAD_TAG MKTAG('S', 'E', 'A', 'D') /* Sxxx header */
  31. #define SNDC_TAG MKTAG('S', 'N', 'D', 'C') /* Sxxx data */
  32. #define SEND_TAG MKTAG('S', 'E', 'N', 'D') /* Sxxx end */
  33. #define SHEN_TAG MKTAG('S', 'H', 'E', 'N') /* SxEN header */
  34. #define SDEN_TAG MKTAG('S', 'D', 'E', 'N') /* SxEN data */
  35. #define SEEN_TAG MKTAG('S', 'E', 'E', 'N') /* SxEN end */
  36. #define ISNh_TAG MKTAG('1', 'S', 'N', 'h') /* 1SNx header */
  37. #define EACS_TAG MKTAG('E', 'A', 'C', 'S')
  38. #define ISNd_TAG MKTAG('1', 'S', 'N', 'd') /* 1SNx data */
  39. #define ISNe_TAG MKTAG('1', 'S', 'N', 'e') /* 1SNx end */
  40. #define PT00_TAG MKTAG('P', 'T', 0x0, 0x0)
  41. #define GSTR_TAG MKTAG('G', 'S', 'T', 'R')
  42. #define SCDl_TAG MKTAG('S', 'C', 'D', 'l')
  43. #define SCEl_TAG MKTAG('S', 'C', 'E', 'l')
  44. #define kVGT_TAG MKTAG('k', 'V', 'G', 'T') /* TGV i-frame */
  45. #define fVGT_TAG MKTAG('f', 'V', 'G', 'T') /* TGV p-frame */
  46. #define mTCD_TAG MKTAG('m', 'T', 'C', 'D') /* MDEC */
  47. #define MADk_TAG MKTAG('M', 'A', 'D', 'k') /* MAD i-frame */
  48. #define MADm_TAG MKTAG('M', 'A', 'D', 'm') /* MAD p-frame */
  49. #define MADe_TAG MKTAG('M', 'A', 'D', 'e') /* MAD lqp-frame */
  50. #define MPCh_TAG MKTAG('M', 'P', 'C', 'h') /* MPEG2 */
  51. #define TGQs_TAG MKTAG('T', 'G', 'Q', 's') /* TGQ i-frame (appears in .TGQ files) */
  52. #define pQGT_TAG MKTAG('p', 'Q', 'G', 'T') /* TGQ i-frame (appears in .UV files) */
  53. #define pIQT_TAG MKTAG('p', 'I', 'Q', 'T') /* TQI/UV2 i-frame (.UV2/.WVE) */
  54. #define MVhd_TAG MKTAG('M', 'V', 'h', 'd')
  55. #define MV0K_TAG MKTAG('M', 'V', '0', 'K')
  56. #define MV0F_TAG MKTAG('M', 'V', '0', 'F')
  57. #define MVIh_TAG MKTAG('M', 'V', 'I', 'h') /* CMV header */
  58. #define MVIf_TAG MKTAG('M', 'V', 'I', 'f') /* CMV i-frame */
  59. typedef struct EaDemuxContext {
  60. int big_endian;
  61. enum AVCodecID video_codec;
  62. AVRational time_base;
  63. int width, height;
  64. int nb_frames;
  65. int video_stream_index;
  66. enum AVCodecID audio_codec;
  67. int audio_stream_index;
  68. int bytes;
  69. int sample_rate;
  70. int num_channels;
  71. int num_samples;
  72. } EaDemuxContext;
  73. static uint32_t read_arbitary(AVIOContext *pb) {
  74. uint8_t size, byte;
  75. int i;
  76. uint32_t word;
  77. size = avio_r8(pb);
  78. word = 0;
  79. for (i = 0; i < size; i++) {
  80. byte = avio_r8(pb);
  81. word <<= 8;
  82. word |= byte;
  83. }
  84. return word;
  85. }
  86. /*
  87. * Process PT/GSTR sound header
  88. * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx
  89. */
  90. static int process_audio_header_elements(AVFormatContext *s)
  91. {
  92. int inHeader = 1;
  93. EaDemuxContext *ea = s->priv_data;
  94. AVIOContext *pb = s->pb;
  95. int compression_type = -1, revision = -1, revision2 = -1;
  96. ea->bytes = 2;
  97. ea->sample_rate = -1;
  98. ea->num_channels = 1;
  99. while (!url_feof(pb) && inHeader) {
  100. int inSubheader;
  101. uint8_t byte;
  102. byte = avio_r8(pb);
  103. switch (byte) {
  104. case 0xFD:
  105. av_log (s, AV_LOG_DEBUG, "entered audio subheader\n");
  106. inSubheader = 1;
  107. while (!url_feof(pb) && inSubheader) {
  108. uint8_t subbyte;
  109. subbyte = avio_r8(pb);
  110. switch (subbyte) {
  111. case 0x80:
  112. revision = read_arbitary(pb);
  113. av_log (s, AV_LOG_DEBUG, "revision (element 0x80) set to 0x%08x\n", revision);
  114. break;
  115. case 0x82:
  116. ea->num_channels = read_arbitary(pb);
  117. av_log (s, AV_LOG_DEBUG, "num_channels (element 0x82) set to 0x%08x\n", ea->num_channels);
  118. break;
  119. case 0x83:
  120. compression_type = read_arbitary(pb);
  121. av_log (s, AV_LOG_DEBUG, "compression_type (element 0x83) set to 0x%08x\n", compression_type);
  122. break;
  123. case 0x84:
  124. ea->sample_rate = read_arbitary(pb);
  125. av_log (s, AV_LOG_DEBUG, "sample_rate (element 0x84) set to %i\n", ea->sample_rate);
  126. break;
  127. case 0x85:
  128. ea->num_samples = read_arbitary(pb);
  129. av_log (s, AV_LOG_DEBUG, "num_samples (element 0x85) set to 0x%08x\n", ea->num_samples);
  130. break;
  131. case 0x8A:
  132. av_log (s, AV_LOG_DEBUG, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
  133. av_log (s, AV_LOG_DEBUG, "exited audio subheader\n");
  134. inSubheader = 0;
  135. break;
  136. case 0xA0:
  137. revision2 = read_arbitary(pb);
  138. av_log (s, AV_LOG_DEBUG, "revision2 (element 0xA0) set to 0x%08x\n", revision2);
  139. break;
  140. case 0xFF:
  141. av_log (s, AV_LOG_DEBUG, "end of header block reached (within audio subheader)\n");
  142. inSubheader = 0;
  143. inHeader = 0;
  144. break;
  145. default:
  146. av_log (s, AV_LOG_DEBUG, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
  147. break;
  148. }
  149. }
  150. break;
  151. case 0xFF:
  152. av_log (s, AV_LOG_DEBUG, "end of header block reached\n");
  153. inHeader = 0;
  154. break;
  155. default:
  156. av_log (s, AV_LOG_DEBUG, "header element 0x%02x set to 0x%08x\n", byte, read_arbitary(pb));
  157. break;
  158. }
  159. }
  160. switch (compression_type) {
  161. case 0: ea->audio_codec = AV_CODEC_ID_PCM_S16LE; break;
  162. case 7: ea->audio_codec = AV_CODEC_ID_ADPCM_EA; break;
  163. case -1:
  164. switch (revision) {
  165. case 1: ea->audio_codec = AV_CODEC_ID_ADPCM_EA_R1; break;
  166. case 2: ea->audio_codec = AV_CODEC_ID_ADPCM_EA_R2; break;
  167. case 3: ea->audio_codec = AV_CODEC_ID_ADPCM_EA_R3; break;
  168. case -1: break;
  169. default:
  170. av_log_ask_for_sample(s, "unsupported stream type; revision=%i\n", revision);
  171. return 0;
  172. }
  173. switch (revision2) {
  174. case 8: ea->audio_codec = AV_CODEC_ID_PCM_S16LE_PLANAR; break;
  175. case 10:
  176. switch (revision) {
  177. case -1:
  178. case 2: ea->audio_codec = AV_CODEC_ID_ADPCM_EA_R1; break;
  179. case 3: ea->audio_codec = AV_CODEC_ID_ADPCM_EA_R2; break;
  180. default:
  181. av_log_ask_for_sample(s, "unsupported stream type; revision=%i, revision2=%i\n", revision, revision2);
  182. return 0;
  183. }
  184. break;
  185. case 16: ea->audio_codec = AV_CODEC_ID_MP3; break;
  186. case -1: break;
  187. default:
  188. ea->audio_codec = AV_CODEC_ID_NONE;
  189. av_log_ask_for_sample(s, "unsupported stream type; revision2=%i\n", revision2);
  190. return 0;
  191. }
  192. break;
  193. default:
  194. av_log_ask_for_sample(s, "unsupported stream type; compression_type=%i\n", compression_type);
  195. return 0;
  196. }
  197. if (ea->sample_rate == -1)
  198. ea->sample_rate = revision==3 ? 48000 : 22050;
  199. return 1;
  200. }
  201. /*
  202. * Process EACS sound header
  203. * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx
  204. */
  205. static int process_audio_header_eacs(AVFormatContext *s)
  206. {
  207. EaDemuxContext *ea = s->priv_data;
  208. AVIOContext *pb = s->pb;
  209. int compression_type;
  210. ea->sample_rate = ea->big_endian ? avio_rb32(pb) : avio_rl32(pb);
  211. ea->bytes = avio_r8(pb); /* 1=8-bit, 2=16-bit */
  212. ea->num_channels = avio_r8(pb);
  213. compression_type = avio_r8(pb);
  214. avio_skip(pb, 13);
  215. switch (compression_type) {
  216. case 0:
  217. switch (ea->bytes) {
  218. case 1: ea->audio_codec = AV_CODEC_ID_PCM_S8; break;
  219. case 2: ea->audio_codec = AV_CODEC_ID_PCM_S16LE; break;
  220. }
  221. break;
  222. case 1: ea->audio_codec = AV_CODEC_ID_PCM_MULAW; ea->bytes = 1; break;
  223. case 2: ea->audio_codec = AV_CODEC_ID_ADPCM_IMA_EA_EACS; break;
  224. default:
  225. av_log_ask_for_sample(s, "unsupported stream type; audio compression_type=%i\n", compression_type);
  226. }
  227. return 1;
  228. }
  229. /*
  230. * Process SEAD sound header
  231. * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx
  232. */
  233. static int process_audio_header_sead(AVFormatContext *s)
  234. {
  235. EaDemuxContext *ea = s->priv_data;
  236. AVIOContext *pb = s->pb;
  237. ea->sample_rate = avio_rl32(pb);
  238. ea->bytes = avio_rl32(pb); /* 1=8-bit, 2=16-bit */
  239. ea->num_channels = avio_rl32(pb);
  240. ea->audio_codec = AV_CODEC_ID_ADPCM_IMA_EA_SEAD;
  241. return 1;
  242. }
  243. static int process_video_header_mdec(AVFormatContext *s)
  244. {
  245. EaDemuxContext *ea = s->priv_data;
  246. AVIOContext *pb = s->pb;
  247. avio_skip(pb, 4);
  248. ea->width = avio_rl16(pb);
  249. ea->height = avio_rl16(pb);
  250. ea->time_base = (AVRational){1,15};
  251. ea->video_codec = AV_CODEC_ID_MDEC;
  252. return 1;
  253. }
  254. static int process_video_header_vp6(AVFormatContext *s)
  255. {
  256. EaDemuxContext *ea = s->priv_data;
  257. AVIOContext *pb = s->pb;
  258. avio_skip(pb, 8);
  259. ea->nb_frames = avio_rl32(pb);
  260. avio_skip(pb, 4);
  261. ea->time_base.den = avio_rl32(pb);
  262. ea->time_base.num = avio_rl32(pb);
  263. ea->video_codec = AV_CODEC_ID_VP6;
  264. return 1;
  265. }
  266. static int process_video_header_cmv(AVFormatContext *s)
  267. {
  268. EaDemuxContext *ea = s->priv_data;
  269. int fps;
  270. avio_skip(s->pb, 10);
  271. fps = avio_rl16(s->pb);
  272. if (fps)
  273. ea->time_base = (AVRational){1, fps};
  274. ea->video_codec = AV_CODEC_ID_CMV;
  275. return 0;
  276. }
  277. /*
  278. * Process EA file header
  279. * Returns 1 if the EA file is valid and successfully opened, 0 otherwise
  280. */
  281. static int process_ea_header(AVFormatContext *s) {
  282. uint32_t blockid, size = 0;
  283. EaDemuxContext *ea = s->priv_data;
  284. AVIOContext *pb = s->pb;
  285. int i;
  286. for (i=0; i<5 && (!ea->audio_codec || !ea->video_codec); i++) {
  287. unsigned int startpos = avio_tell(pb);
  288. int err = 0;
  289. blockid = avio_rl32(pb);
  290. size = avio_rl32(pb);
  291. if (i == 0)
  292. ea->big_endian = size > 0x000FFFFF;
  293. if (ea->big_endian)
  294. size = av_bswap32(size);
  295. switch (blockid) {
  296. case ISNh_TAG:
  297. if (avio_rl32(pb) != EACS_TAG) {
  298. av_log_ask_for_sample(s, "unknown 1SNh headerid\n");
  299. return 0;
  300. }
  301. err = process_audio_header_eacs(s);
  302. break;
  303. case SCHl_TAG :
  304. case SHEN_TAG :
  305. blockid = avio_rl32(pb);
  306. if (blockid == GSTR_TAG) {
  307. avio_skip(pb, 4);
  308. } else if ((blockid & 0xFFFF)!=PT00_TAG) {
  309. av_log_ask_for_sample(s, "unknown SCHl headerid\n");
  310. return 0;
  311. }
  312. err = process_audio_header_elements(s);
  313. break;
  314. case SEAD_TAG:
  315. err = process_audio_header_sead(s);
  316. break;
  317. case MVIh_TAG :
  318. err = process_video_header_cmv(s);
  319. break;
  320. case kVGT_TAG:
  321. ea->video_codec = AV_CODEC_ID_TGV;
  322. break;
  323. case mTCD_TAG :
  324. err = process_video_header_mdec(s);
  325. break;
  326. case MPCh_TAG:
  327. ea->video_codec = AV_CODEC_ID_MPEG2VIDEO;
  328. break;
  329. case pQGT_TAG:
  330. case TGQs_TAG:
  331. ea->video_codec = AV_CODEC_ID_TGQ;
  332. break;
  333. case pIQT_TAG:
  334. ea->video_codec = AV_CODEC_ID_TQI;
  335. break;
  336. case MADk_TAG :
  337. ea->video_codec = AV_CODEC_ID_MAD;
  338. break;
  339. case MVhd_TAG :
  340. err = process_video_header_vp6(s);
  341. break;
  342. }
  343. if (err < 0) {
  344. av_log(s, AV_LOG_ERROR, "error parsing header: %i\n", err);
  345. return err;
  346. }
  347. avio_seek(pb, startpos + size, SEEK_SET);
  348. }
  349. avio_seek(pb, 0, SEEK_SET);
  350. return 1;
  351. }
  352. static int ea_probe(AVProbeData *p)
  353. {
  354. switch (AV_RL32(&p->buf[0])) {
  355. case ISNh_TAG:
  356. case SCHl_TAG:
  357. case SEAD_TAG:
  358. case SHEN_TAG:
  359. case kVGT_TAG:
  360. case MADk_TAG:
  361. case MPCh_TAG:
  362. case MVhd_TAG:
  363. case MVIh_TAG:
  364. break;
  365. default:
  366. return 0;
  367. }
  368. if (AV_RL32(&p->buf[4]) > 0xfffff && AV_RB32(&p->buf[4]) > 0xfffff)
  369. return 0;
  370. return AVPROBE_SCORE_MAX;
  371. }
  372. static int ea_read_header(AVFormatContext *s)
  373. {
  374. EaDemuxContext *ea = s->priv_data;
  375. AVStream *st;
  376. if (process_ea_header(s)<=0)
  377. return AVERROR(EIO);
  378. if (ea->video_codec) {
  379. /* initialize the video decoder stream */
  380. st = avformat_new_stream(s, NULL);
  381. if (!st)
  382. return AVERROR(ENOMEM);
  383. ea->video_stream_index = st->index;
  384. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  385. st->codec->codec_id = ea->video_codec;
  386. // parsing is necessary to make FFmpeg generate correct timestamps
  387. if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO)
  388. st->need_parsing = AVSTREAM_PARSE_HEADERS;
  389. st->codec->codec_tag = 0; /* no fourcc */
  390. st->codec->width = ea->width;
  391. st->codec->height = ea->height;
  392. st->duration = st->nb_frames = ea->nb_frames;
  393. if (ea->time_base.num)
  394. avpriv_set_pts_info(st, 64, ea->time_base.num, ea->time_base.den);
  395. st->r_frame_rate =
  396. st->avg_frame_rate = av_inv_q(ea->time_base);
  397. }
  398. if (ea->audio_codec) {
  399. if (ea->num_channels <= 0) {
  400. av_log(s, AV_LOG_WARNING, "Unsupported number of channels: %d\n", ea->num_channels);
  401. ea->audio_codec = 0;
  402. return 1;
  403. }
  404. if (ea->sample_rate <= 0) {
  405. av_log(s, AV_LOG_ERROR, "Unsupported sample rate: %d\n", ea->sample_rate);
  406. ea->audio_codec = 0;
  407. return 1;
  408. }
  409. if (ea->bytes <= 0) {
  410. av_log(s, AV_LOG_ERROR, "Invalid number of bytes per sample: %d\n", ea->bytes);
  411. ea->audio_codec = AV_CODEC_ID_NONE;
  412. return 1;
  413. }
  414. /* initialize the audio decoder stream */
  415. st = avformat_new_stream(s, NULL);
  416. if (!st)
  417. return AVERROR(ENOMEM);
  418. avpriv_set_pts_info(st, 33, 1, ea->sample_rate);
  419. st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  420. st->codec->codec_id = ea->audio_codec;
  421. st->codec->codec_tag = 0; /* no tag */
  422. st->codec->channels = ea->num_channels;
  423. st->codec->sample_rate = ea->sample_rate;
  424. st->codec->bits_per_coded_sample = ea->bytes * 8;
  425. st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
  426. st->codec->bits_per_coded_sample / 4;
  427. st->codec->block_align = st->codec->channels*st->codec->bits_per_coded_sample;
  428. ea->audio_stream_index = st->index;
  429. st->start_time = 0;
  430. }
  431. return 1;
  432. }
  433. static int ea_read_packet(AVFormatContext *s,
  434. AVPacket *pkt)
  435. {
  436. EaDemuxContext *ea = s->priv_data;
  437. AVIOContext *pb = s->pb;
  438. int ret = 0;
  439. int packet_read = 0;
  440. int partial_packet = 0;
  441. unsigned int chunk_type, chunk_size;
  442. int key = 0;
  443. int av_uninit(num_samples);
  444. while (!packet_read || partial_packet) {
  445. chunk_type = avio_rl32(pb);
  446. chunk_size = ea->big_endian ? avio_rb32(pb) : avio_rl32(pb);
  447. if (chunk_size <= 8)
  448. return AVERROR_INVALIDDATA;
  449. chunk_size -= 8;
  450. switch (chunk_type) {
  451. /* audio data */
  452. case ISNh_TAG:
  453. /* header chunk also contains data; skip over the header portion*/
  454. if (chunk_size < 32)
  455. return AVERROR_INVALIDDATA;
  456. avio_skip(pb, 32);
  457. chunk_size -= 32;
  458. case ISNd_TAG:
  459. case SCDl_TAG:
  460. case SNDC_TAG:
  461. case SDEN_TAG:
  462. if (!ea->audio_codec) {
  463. avio_skip(pb, chunk_size);
  464. break;
  465. } else if (ea->audio_codec == AV_CODEC_ID_PCM_S16LE_PLANAR ||
  466. ea->audio_codec == AV_CODEC_ID_MP3) {
  467. num_samples = avio_rl32(pb);
  468. avio_skip(pb, 8);
  469. chunk_size -= 12;
  470. }
  471. if (partial_packet) {
  472. av_log_ask_for_sample(s, "video header followed by audio packet not supported.\n");
  473. av_free_packet(pkt);
  474. partial_packet = 0;
  475. }
  476. ret = av_get_packet(pb, pkt, chunk_size);
  477. if (ret < 0)
  478. return ret;
  479. pkt->stream_index = ea->audio_stream_index;
  480. switch (ea->audio_codec) {
  481. case AV_CODEC_ID_ADPCM_EA:
  482. case AV_CODEC_ID_ADPCM_EA_R1:
  483. case AV_CODEC_ID_ADPCM_EA_R2:
  484. case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
  485. if (pkt->size >= 4)
  486. pkt->duration = AV_RL32(pkt->data);
  487. break;
  488. case AV_CODEC_ID_ADPCM_EA_R3:
  489. if (pkt->size >= 4)
  490. pkt->duration = AV_RB32(pkt->data);
  491. break;
  492. case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
  493. pkt->duration = ret * 2 / ea->num_channels;
  494. break;
  495. case AV_CODEC_ID_PCM_S16LE_PLANAR:
  496. case AV_CODEC_ID_MP3:
  497. pkt->duration = num_samples;
  498. break;
  499. default:
  500. pkt->duration = chunk_size / (ea->bytes * ea->num_channels);
  501. }
  502. packet_read = 1;
  503. break;
  504. /* ending tag */
  505. case 0:
  506. case ISNe_TAG:
  507. case SCEl_TAG:
  508. case SEND_TAG:
  509. case SEEN_TAG:
  510. ret = AVERROR(EIO);
  511. packet_read = 1;
  512. break;
  513. case MVIh_TAG:
  514. case kVGT_TAG:
  515. case pQGT_TAG:
  516. case TGQs_TAG:
  517. case MADk_TAG:
  518. key = AV_PKT_FLAG_KEY;
  519. case MVIf_TAG:
  520. case fVGT_TAG:
  521. case MADm_TAG:
  522. case MADe_TAG:
  523. avio_seek(pb, -8, SEEK_CUR); // include chunk preamble
  524. chunk_size += 8;
  525. goto get_video_packet;
  526. case mTCD_TAG:
  527. avio_skip(pb, 8); // skip ea dct header
  528. chunk_size -= 8;
  529. goto get_video_packet;
  530. case MV0K_TAG:
  531. case MPCh_TAG:
  532. case pIQT_TAG:
  533. key = AV_PKT_FLAG_KEY;
  534. case MV0F_TAG:
  535. get_video_packet:
  536. if (partial_packet) {
  537. ret = av_append_packet(pb, pkt, chunk_size);
  538. } else
  539. ret = av_get_packet(pb, pkt, chunk_size);
  540. if (ret < 0) {
  541. packet_read = 1;
  542. break;
  543. }
  544. partial_packet = chunk_type == MVIh_TAG;
  545. pkt->stream_index = ea->video_stream_index;
  546. pkt->flags |= key;
  547. packet_read = 1;
  548. break;
  549. default:
  550. avio_skip(pb, chunk_size);
  551. break;
  552. }
  553. }
  554. if (ret < 0 && partial_packet)
  555. av_free_packet(pkt);
  556. return ret;
  557. }
  558. AVInputFormat ff_ea_demuxer = {
  559. .name = "ea",
  560. .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts Multimedia"),
  561. .priv_data_size = sizeof(EaDemuxContext),
  562. .read_probe = ea_probe,
  563. .read_header = ea_read_header,
  564. .read_packet = ea_read_packet,
  565. };