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.

716 lines
22KB

  1. /*
  2. * AVI decoder.
  3. * Copyright (c) 2001 Fabrice Bellard.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "avformat.h"
  20. #include "avi.h"
  21. #include "dv.h"
  22. //#define DEBUG
  23. //#define DEBUG_SEEK
  24. typedef struct AVIIndexEntry {
  25. unsigned int flags;
  26. unsigned int pos;
  27. unsigned int cum_len; /* sum of all lengths before this packet */
  28. } AVIIndexEntry;
  29. typedef struct AVIStream {
  30. AVIIndexEntry *index_entries;
  31. int nb_index_entries;
  32. int index_entries_allocated_size;
  33. int frame_offset; /* current frame (video) or byte (audio) counter
  34. (used to compute the pts) */
  35. int scale;
  36. int rate;
  37. int sample_size; /* audio only data */
  38. int start;
  39. int new_frame_offset; /* temporary storage (used during seek) */
  40. int cum_len; /* temporary storage (used during seek) */
  41. } AVIStream;
  42. typedef struct {
  43. int64_t riff_end;
  44. int64_t movi_end;
  45. offset_t movi_list;
  46. int index_loaded;
  47. DVDemuxContext* dv_demux;
  48. } AVIContext;
  49. #ifdef DEBUG
  50. static void print_tag(const char *str, unsigned int tag, int size)
  51. {
  52. printf("%s: tag=%c%c%c%c size=0x%x\n",
  53. str, tag & 0xff,
  54. (tag >> 8) & 0xff,
  55. (tag >> 16) & 0xff,
  56. (tag >> 24) & 0xff,
  57. size);
  58. }
  59. #endif
  60. static int get_riff(AVIContext *avi, ByteIOContext *pb)
  61. {
  62. uint32_t tag;
  63. /* check RIFF header */
  64. tag = get_le32(pb);
  65. if (tag != MKTAG('R', 'I', 'F', 'F'))
  66. return -1;
  67. avi->riff_end = get_le32(pb); /* RIFF chunk size */
  68. avi->riff_end += url_ftell(pb); /* RIFF chunk end */
  69. tag = get_le32(pb);
  70. if (tag != MKTAG('A', 'V', 'I', ' ') && tag != MKTAG('A', 'V', 'I', 'X'))
  71. return -1;
  72. return 0;
  73. }
  74. static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
  75. {
  76. AVIContext *avi = s->priv_data;
  77. ByteIOContext *pb = &s->pb;
  78. uint32_t tag, tag1, handler;
  79. int codec_type, stream_index, frame_period, bit_rate, scale, rate;
  80. unsigned int size, nb_frames;
  81. int i, n;
  82. AVStream *st;
  83. AVIStream *ast;
  84. int xan_video = 0; /* hack to support Xan A/V */
  85. if (get_riff(avi, pb) < 0)
  86. return -1;
  87. /* first list tag */
  88. stream_index = -1;
  89. codec_type = -1;
  90. frame_period = 0;
  91. for(;;) {
  92. if (url_feof(pb))
  93. goto fail;
  94. tag = get_le32(pb);
  95. size = get_le32(pb);
  96. #ifdef DEBUG
  97. print_tag("tag", tag, size);
  98. #endif
  99. switch(tag) {
  100. case MKTAG('L', 'I', 'S', 'T'):
  101. /* ignored, except when start of video packets */
  102. tag1 = get_le32(pb);
  103. #ifdef DEBUG
  104. print_tag("list", tag1, 0);
  105. #endif
  106. if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
  107. avi->movi_list = url_ftell(pb) - 4;
  108. avi->movi_end = avi->movi_list + size;
  109. #ifdef DEBUG
  110. printf("movi end=%Lx\n", avi->movi_end);
  111. #endif
  112. goto end_of_header;
  113. }
  114. break;
  115. case MKTAG('a', 'v', 'i', 'h'):
  116. /* avi header */
  117. /* using frame_period is bad idea */
  118. frame_period = get_le32(pb);
  119. bit_rate = get_le32(pb) * 8;
  120. url_fskip(pb, 4 * 4);
  121. n = get_le32(pb);
  122. for(i=0;i<n;i++) {
  123. AVIStream *ast;
  124. st = av_new_stream(s, i);
  125. if (!st)
  126. goto fail;
  127. ast = av_mallocz(sizeof(AVIStream));
  128. if (!ast)
  129. goto fail;
  130. st->priv_data = ast;
  131. }
  132. url_fskip(pb, size - 7 * 4);
  133. break;
  134. case MKTAG('s', 't', 'r', 'h'):
  135. /* stream header */
  136. stream_index++;
  137. tag1 = get_le32(pb);
  138. handler = get_le32(pb); /* codec tag */
  139. switch(tag1) {
  140. case MKTAG('i', 'a', 'v', 's'):
  141. case MKTAG('i', 'v', 'a', 's'):
  142. /*
  143. * After some consideration -- I don't think we
  144. * have to support anything but DV in a type1 AVIs.
  145. */
  146. if (s->nb_streams != 1)
  147. goto fail;
  148. if (handler != MKTAG('d', 'v', 's', 'd') &&
  149. handler != MKTAG('d', 'v', 'h', 'd') &&
  150. handler != MKTAG('d', 'v', 's', 'l'))
  151. goto fail;
  152. av_freep(&s->streams[0]->codec.extradata);
  153. av_freep(&s->streams[0]);
  154. s->nb_streams = 0;
  155. avi->dv_demux = dv_init_demux(s);
  156. if (!avi->dv_demux)
  157. goto fail;
  158. stream_index = s->nb_streams - 1;
  159. url_fskip(pb, size - 8);
  160. break;
  161. case MKTAG('v', 'i', 'd', 's'):
  162. codec_type = CODEC_TYPE_VIDEO;
  163. if (stream_index >= s->nb_streams) {
  164. url_fskip(pb, size - 8);
  165. break;
  166. }
  167. st = s->streams[stream_index];
  168. ast = st->priv_data;
  169. st->codec.stream_codec_tag= handler;
  170. get_le32(pb); /* flags */
  171. get_le16(pb); /* priority */
  172. get_le16(pb); /* language */
  173. get_le32(pb); /* XXX: initial frame ? */
  174. scale = get_le32(pb); /* scale */
  175. rate = get_le32(pb); /* rate */
  176. if(scale && rate){
  177. }else if(frame_period){
  178. rate = 1000000;
  179. scale = frame_period;
  180. }else{
  181. rate = 25;
  182. scale = 1;
  183. }
  184. ast->rate = rate;
  185. ast->scale = scale;
  186. av_set_pts_info(st, 64, scale, rate);
  187. st->codec.frame_rate = rate;
  188. st->codec.frame_rate_base = scale;
  189. get_le32(pb); /* start */
  190. nb_frames = get_le32(pb);
  191. st->start_time = 0;
  192. st->duration = av_rescale(nb_frames,
  193. st->codec.frame_rate_base * AV_TIME_BASE,
  194. st->codec.frame_rate);
  195. url_fskip(pb, size - 9 * 4);
  196. break;
  197. case MKTAG('a', 'u', 'd', 's'):
  198. {
  199. unsigned int length;
  200. codec_type = CODEC_TYPE_AUDIO;
  201. if (stream_index >= s->nb_streams) {
  202. url_fskip(pb, size - 8);
  203. break;
  204. }
  205. st = s->streams[stream_index];
  206. ast = st->priv_data;
  207. get_le32(pb); /* flags */
  208. get_le16(pb); /* priority */
  209. get_le16(pb); /* language */
  210. get_le32(pb); /* initial frame */
  211. ast->scale = get_le32(pb); /* scale */
  212. ast->rate = get_le32(pb);
  213. av_set_pts_info(st, 64, ast->scale, ast->rate);
  214. ast->start= get_le32(pb); /* start */
  215. length = get_le32(pb); /* length, in samples or bytes */
  216. get_le32(pb); /* buffer size */
  217. get_le32(pb); /* quality */
  218. ast->sample_size = get_le32(pb); /* sample ssize */
  219. //av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d\n", ast->scale, ast->rate, ast->sample_size, ast->start);
  220. st->start_time = 0;
  221. if (ast->rate != 0)
  222. st->duration = (int64_t)length * AV_TIME_BASE / ast->rate;
  223. url_fskip(pb, size - 12 * 4);
  224. }
  225. break;
  226. default:
  227. goto fail;
  228. }
  229. break;
  230. case MKTAG('s', 't', 'r', 'f'):
  231. /* stream header */
  232. if (stream_index >= s->nb_streams || avi->dv_demux) {
  233. url_fskip(pb, size);
  234. } else {
  235. st = s->streams[stream_index];
  236. switch(codec_type) {
  237. case CODEC_TYPE_VIDEO:
  238. get_le32(pb); /* size */
  239. st->codec.width = get_le32(pb);
  240. st->codec.height = get_le32(pb);
  241. get_le16(pb); /* panes */
  242. st->codec.bits_per_sample= get_le16(pb); /* depth */
  243. tag1 = get_le32(pb);
  244. get_le32(pb); /* ImageSize */
  245. get_le32(pb); /* XPelsPerMeter */
  246. get_le32(pb); /* YPelsPerMeter */
  247. get_le32(pb); /* ClrUsed */
  248. get_le32(pb); /* ClrImportant */
  249. st->codec.extradata_size= size - 10*4;
  250. st->codec.extradata= av_malloc(st->codec.extradata_size);
  251. get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
  252. if(st->codec.extradata_size & 1) //FIXME check if the encoder really did this correctly
  253. get_byte(pb);
  254. /* Extract palette from extradata if bpp <= 8 */
  255. /* This code assumes that extradata contains only palette */
  256. /* This is true for all paletted codecs implemented in ffmpeg */
  257. if (st->codec.extradata_size && (st->codec.bits_per_sample <= 8)) {
  258. st->codec.palctrl = av_mallocz(sizeof(AVPaletteControl));
  259. #ifdef WORDS_BIGENDIAN
  260. for (i = 0; i < FFMIN(st->codec.extradata_size, AVPALETTE_SIZE)/4; i++)
  261. st->codec.palctrl->palette[i] = bswap_32(((uint32_t*)st->codec.extradata)[i]);
  262. #else
  263. memcpy(st->codec.palctrl->palette, st->codec.extradata,
  264. FFMIN(st->codec.extradata_size, AVPALETTE_SIZE));
  265. #endif
  266. st->codec.palctrl->palette_changed = 1;
  267. }
  268. #ifdef DEBUG
  269. print_tag("video", tag1, 0);
  270. #endif
  271. st->codec.codec_type = CODEC_TYPE_VIDEO;
  272. st->codec.codec_tag = tag1;
  273. st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
  274. if (st->codec.codec_id == CODEC_ID_XAN_WC4)
  275. xan_video = 1;
  276. // url_fskip(pb, size - 5 * 4);
  277. break;
  278. case CODEC_TYPE_AUDIO:
  279. get_wav_header(pb, &st->codec, size);
  280. if (size%2) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
  281. url_fskip(pb, 1);
  282. /* special case time: To support Xan DPCM, hardcode
  283. * the format if Xxan is the video codec */
  284. st->need_parsing = 1;
  285. /* force parsing as several audio frames can be in
  286. one packet */
  287. if (xan_video)
  288. st->codec.codec_id = CODEC_ID_XAN_DPCM;
  289. break;
  290. default:
  291. url_fskip(pb, size);
  292. break;
  293. }
  294. }
  295. break;
  296. default:
  297. /* skip tag */
  298. size += (size & 1);
  299. url_fskip(pb, size);
  300. break;
  301. }
  302. }
  303. end_of_header:
  304. /* check stream number */
  305. if (stream_index != s->nb_streams - 1) {
  306. fail:
  307. for(i=0;i<s->nb_streams;i++) {
  308. av_freep(&s->streams[i]->codec.extradata);
  309. av_freep(&s->streams[i]);
  310. }
  311. return -1;
  312. }
  313. return 0;
  314. }
  315. static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
  316. {
  317. AVIContext *avi = s->priv_data;
  318. ByteIOContext *pb = &s->pb;
  319. int n, d[8], size, i;
  320. void* dstr;
  321. memset(d, -1, sizeof(int)*8);
  322. if (avi->dv_demux) {
  323. size = dv_get_packet(avi->dv_demux, pkt);
  324. if (size >= 0)
  325. return size;
  326. }
  327. for(i=url_ftell(pb); !url_feof(pb); i++) {
  328. int j;
  329. if (i >= avi->movi_end) { /* Let's see if it's an OpenDML AVI */
  330. uint32_t tag, size, tag2;
  331. url_fskip(pb, avi->riff_end - url_ftell(pb));
  332. if (get_riff(avi, pb) < 0)
  333. return -1;
  334. tag = get_le32(pb);
  335. size = get_le32(pb);
  336. tag2 = get_le32(pb);
  337. if (tag == MKTAG('L','I','S','T') && tag2 == MKTAG('m','o','v','i'))
  338. avi->movi_end = url_ftell(pb) + size - 4;
  339. else
  340. return -1;
  341. }
  342. for(j=0; j<7; j++)
  343. d[j]= d[j+1];
  344. d[7]= get_byte(pb);
  345. size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24);
  346. //parse ix##
  347. n= (d[2] - '0') * 10 + (d[3] - '0');
  348. if( d[2] >= '0' && d[2] <= '9'
  349. && d[3] >= '0' && d[3] <= '9'
  350. && d[0] == 'i' && d[1] == 'x'
  351. && n < s->nb_streams
  352. && i + size <= avi->movi_end){
  353. url_fskip(pb, size);
  354. }
  355. //parse ##dc/##wb
  356. n= (d[0] - '0') * 10 + (d[1] - '0');
  357. if( d[0] >= '0' && d[0] <= '9'
  358. && d[1] >= '0' && d[1] <= '9'
  359. && ((d[2] == 'd' && d[3] == 'c') ||
  360. (d[2] == 'w' && d[3] == 'b') ||
  361. (d[2] == 'd' && d[3] == 'b') ||
  362. (d[2] == '_' && d[3] == '_'))
  363. && n < s->nb_streams
  364. && i + size <= avi->movi_end) {
  365. av_new_packet(pkt, size);
  366. get_buffer(pb, pkt->data, size);
  367. if (size & 1) {
  368. get_byte(pb);
  369. size++;
  370. }
  371. if (avi->dv_demux) {
  372. dstr = pkt->destruct;
  373. size = dv_produce_packet(avi->dv_demux, pkt,
  374. pkt->data, pkt->size);
  375. pkt->destruct = dstr;
  376. pkt->flags |= PKT_FLAG_KEY;
  377. } else {
  378. AVStream *st;
  379. AVIStream *ast;
  380. st = s->streams[n];
  381. ast = st->priv_data;
  382. /* XXX: how to handle B frames in avi ? */
  383. pkt->pts = ast->frame_offset;
  384. if(ast->sample_size)
  385. pkt->pts /= ast->sample_size;
  386. //printf("%Ld %d %d %d %d\n", pkt->pts, ast->frame_offset, ast->scale, AV_TIME_BASE, ast->rate);
  387. pkt->stream_index = n;
  388. /* FIXME: We really should read index for that */
  389. if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
  390. if (ast->frame_offset < ast->nb_index_entries) {
  391. if (ast->index_entries[ast->frame_offset].flags & AVIIF_INDEX)
  392. pkt->flags |= PKT_FLAG_KEY;
  393. } else {
  394. /* if no index, better to say that all frames
  395. are key frames */
  396. pkt->flags |= PKT_FLAG_KEY;
  397. }
  398. } else {
  399. pkt->flags |= PKT_FLAG_KEY;
  400. }
  401. if(ast->sample_size)
  402. ast->frame_offset += pkt->size;
  403. else
  404. ast->frame_offset++;
  405. }
  406. return size;
  407. }
  408. }
  409. return -1;
  410. }
  411. /* XXX: we make the implicit supposition that the position are sorted
  412. for each stream */
  413. static int avi_read_idx1(AVFormatContext *s, int size)
  414. {
  415. ByteIOContext *pb = &s->pb;
  416. int nb_index_entries, i;
  417. AVStream *st;
  418. AVIStream *ast;
  419. AVIIndexEntry *ie, *entries;
  420. unsigned int index, tag, flags, pos, len;
  421. nb_index_entries = size / 16;
  422. if (nb_index_entries <= 0)
  423. return -1;
  424. /* read the entries and sort them in each stream component */
  425. for(i = 0; i < nb_index_entries; i++) {
  426. tag = get_le32(pb);
  427. flags = get_le32(pb);
  428. pos = get_le32(pb);
  429. len = get_le32(pb);
  430. #if defined(DEBUG_SEEK) && 0
  431. printf("%d: tag=0x%x flags=0x%x pos=0x%x len=%d\n",
  432. i, tag, flags, pos, len);
  433. #endif
  434. index = ((tag & 0xff) - '0') * 10;
  435. index += ((tag >> 8) & 0xff) - '0';
  436. if (index >= s->nb_streams)
  437. continue;
  438. st = s->streams[index];
  439. ast = st->priv_data;
  440. entries = av_fast_realloc(ast->index_entries,
  441. &ast->index_entries_allocated_size,
  442. (ast->nb_index_entries + 1) *
  443. sizeof(AVIIndexEntry));
  444. if (entries) {
  445. ast->index_entries = entries;
  446. ie = &entries[ast->nb_index_entries++];
  447. ie->flags = flags;
  448. ie->pos = pos;
  449. ie->cum_len = ast->cum_len;
  450. ast->cum_len += len;
  451. }
  452. }
  453. return 0;
  454. }
  455. static int avi_load_index(AVFormatContext *s)
  456. {
  457. AVIContext *avi = s->priv_data;
  458. ByteIOContext *pb = &s->pb;
  459. uint32_t tag, size;
  460. offset_t pos= url_ftell(pb);
  461. url_fseek(pb, avi->movi_end, SEEK_SET);
  462. #ifdef DEBUG_SEEK
  463. printf("movi_end=0x%llx\n", avi->movi_end);
  464. #endif
  465. for(;;) {
  466. if (url_feof(pb))
  467. break;
  468. tag = get_le32(pb);
  469. size = get_le32(pb);
  470. #ifdef DEBUG_SEEK
  471. printf("tag=%c%c%c%c size=0x%x\n",
  472. tag & 0xff,
  473. (tag >> 8) & 0xff,
  474. (tag >> 16) & 0xff,
  475. (tag >> 24) & 0xff,
  476. size);
  477. #endif
  478. switch(tag) {
  479. case MKTAG('i', 'd', 'x', '1'):
  480. if (avi_read_idx1(s, size) < 0)
  481. goto skip;
  482. else
  483. goto the_end;
  484. break;
  485. default:
  486. skip:
  487. size += (size & 1);
  488. url_fskip(pb, size);
  489. break;
  490. }
  491. }
  492. the_end:
  493. url_fseek(pb, pos, SEEK_SET);
  494. return 0;
  495. }
  496. /* return the index entry whose position is immediately >= 'wanted_pos' */
  497. static int locate_frame_in_index(AVIIndexEntry *entries,
  498. int nb_entries, int wanted_pos)
  499. {
  500. int a, b, m, pos;
  501. a = 0;
  502. b = nb_entries - 1;
  503. while (a <= b) {
  504. m = (a + b) >> 1;
  505. pos = entries[m].pos;
  506. if (pos == wanted_pos)
  507. goto found;
  508. else if (pos > wanted_pos) {
  509. b = m - 1;
  510. } else {
  511. a = m + 1;
  512. }
  513. }
  514. m = a;
  515. if (m > 0)
  516. m--;
  517. found:
  518. return m;
  519. }
  520. static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp)
  521. {
  522. AVIContext *avi = s->priv_data;
  523. AVStream *st;
  524. AVIStream *ast;
  525. int frame_number, i;
  526. int64_t pos;
  527. if (!avi->index_loaded) {
  528. /* we only load the index on demand */
  529. avi_load_index(s);
  530. avi->index_loaded = 1;
  531. }
  532. if (stream_index < 0) {
  533. for(i = 0; i < s->nb_streams; i++) {
  534. st = s->streams[i];
  535. if (st->codec.codec_type == CODEC_TYPE_VIDEO)
  536. goto found;
  537. }
  538. return -1;
  539. found:
  540. stream_index = i;
  541. }
  542. st = s->streams[stream_index];
  543. if (st->codec.codec_type != CODEC_TYPE_VIDEO)
  544. return -1;
  545. ast = st->priv_data;
  546. /* compute the frame number */
  547. frame_number = (timestamp * ast->rate) /
  548. (ast->scale * (int64_t)AV_TIME_BASE);
  549. #ifdef DEBUG_SEEK
  550. printf("timestamp=%0.3f nb_indexes=%d frame_number=%d\n",
  551. (double)timestamp / AV_TIME_BASE,
  552. ast->nb_index_entries, frame_number);
  553. #endif
  554. /* find a closest key frame before */
  555. if (frame_number >= ast->nb_index_entries)
  556. return -1;
  557. while (frame_number >= 0 &&
  558. !(ast->index_entries[frame_number].flags & AVIIF_INDEX))
  559. frame_number--;
  560. if (frame_number < 0)
  561. return -1;
  562. ast->new_frame_offset = frame_number;
  563. /* find the position */
  564. pos = ast->index_entries[frame_number].pos;
  565. #ifdef DEBUG_SEEK
  566. printf("key_frame_number=%d pos=0x%llx\n",
  567. frame_number, pos);
  568. #endif
  569. /* update the frame counters for all the other stream by looking
  570. at the positions just after the one found */
  571. for(i = 0; i < s->nb_streams; i++) {
  572. int j;
  573. if (i != stream_index) {
  574. st = s->streams[i];
  575. ast = st->priv_data;
  576. if (ast->nb_index_entries <= 0)
  577. return -1;
  578. j = locate_frame_in_index(ast->index_entries,
  579. ast->nb_index_entries,
  580. pos);
  581. /* get next frame */
  582. if ((j + 1) < ast->nb_index_entries)
  583. j++;
  584. /* extract the current frame number */
  585. if (ast->sample_size==0)
  586. ast->new_frame_offset = j;
  587. else
  588. ast->new_frame_offset = ast->index_entries[j].cum_len;
  589. }
  590. }
  591. /* everything is OK now. We can update the frame offsets */
  592. for(i = 0; i < s->nb_streams; i++) {
  593. st = s->streams[i];
  594. ast = st->priv_data;
  595. ast->frame_offset = ast->new_frame_offset;
  596. #ifdef DEBUG_SEEK
  597. printf("%d: frame_offset=%d\n", i,
  598. ast->frame_offset);
  599. #endif
  600. }
  601. /* do the seek */
  602. pos += avi->movi_list;
  603. url_fseek(&s->pb, pos, SEEK_SET);
  604. return 0;
  605. }
  606. static int avi_read_close(AVFormatContext *s)
  607. {
  608. int i;
  609. AVIContext *avi = s->priv_data;
  610. for(i=0;i<s->nb_streams;i++) {
  611. AVStream *st = s->streams[i];
  612. AVIStream *ast = st->priv_data;
  613. if(ast){
  614. av_free(ast->index_entries);
  615. av_free(ast);
  616. }
  617. av_free(st->codec.extradata);
  618. av_free(st->codec.palctrl);
  619. }
  620. if (avi->dv_demux)
  621. av_free(avi->dv_demux);
  622. return 0;
  623. }
  624. static int avi_probe(AVProbeData *p)
  625. {
  626. /* check file header */
  627. if (p->buf_size <= 32)
  628. return 0;
  629. if (p->buf[0] == 'R' && p->buf[1] == 'I' &&
  630. p->buf[2] == 'F' && p->buf[3] == 'F' &&
  631. p->buf[8] == 'A' && p->buf[9] == 'V' &&
  632. p->buf[10] == 'I' && p->buf[11] == ' ')
  633. return AVPROBE_SCORE_MAX;
  634. else
  635. return 0;
  636. }
  637. static AVInputFormat avi_iformat = {
  638. "avi",
  639. "avi format",
  640. sizeof(AVIContext),
  641. avi_probe,
  642. avi_read_header,
  643. avi_read_packet,
  644. avi_read_close,
  645. avi_read_seek,
  646. };
  647. int avidec_init(void)
  648. {
  649. av_register_input_format(&avi_iformat);
  650. return 0;
  651. }