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.

1268 lines
37KB

  1. /*
  2. * ASF compatible encoder and decoder.
  3. * Copyright (c) 2000, 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 "mpegaudio.h"
  22. #define PACKET_SIZE 3200
  23. #define PACKET_HEADER_SIZE 12
  24. #define FRAME_HEADER_SIZE 17
  25. typedef struct {
  26. int num;
  27. int seq;
  28. /* use for reading */
  29. AVPacket pkt;
  30. int frag_offset;
  31. int timestamp;
  32. INT64 duration;
  33. int ds_span; /* descrambling */
  34. int ds_packet_size;
  35. int ds_chunk_size;
  36. int ds_data_size;
  37. int ds_silence_data;
  38. } ASFStream;
  39. typedef struct {
  40. UINT32 v1;
  41. UINT16 v2;
  42. UINT16 v3;
  43. UINT8 v4[8];
  44. } GUID;
  45. typedef struct __attribute__((packed)) {
  46. GUID guid; // generated by client computer
  47. uint64_t file_size; // in bytes
  48. // invalid if broadcasting
  49. uint64_t create_time; // time of creation, in 100-nanosecond units since 1.1.1601
  50. // invalid if broadcasting
  51. uint64_t packets_count; // how many packets are there in the file
  52. // invalid if broadcasting
  53. uint64_t play_time; // play time, in 100-nanosecond units
  54. // invalid if broadcasting
  55. uint64_t send_time; // time to send file, in 100-nanosecond units
  56. // invalid if broadcasting (could be ignored)
  57. uint32_t preroll; // timestamp of the first packet, in milliseconds
  58. // if nonzero - substract from time
  59. uint32_t ignore; // preroll is 64bit - but let's just ignore it
  60. uint32_t flags; // 0x01 - broadcast
  61. // 0x02 - seekable
  62. // rest is reserved should be 0
  63. uint32_t min_pktsize; // size of a data packet
  64. // invalid if broadcasting
  65. uint32_t max_pktsize; // shall be the same as for min_pktsize
  66. // invalid if broadcasting
  67. uint32_t max_bitrate; // bandwith of stream in bps
  68. // should be the sum of bitrates of the
  69. // individual media streams
  70. } ASFMainHeader;
  71. typedef struct {
  72. int seqno;
  73. int packet_size;
  74. int is_streamed;
  75. int asfid2avid[128]; /* conversion table from asf ID 2 AVStream ID */
  76. ASFStream streams[128]; /* it's max number and it's not that big */
  77. /* non streamed additonnal info */
  78. INT64 nb_packets;
  79. INT64 duration; /* in 100ns units */
  80. /* packet filling */
  81. int packet_size_left;
  82. int packet_timestamp_start;
  83. int packet_timestamp_end;
  84. int packet_nb_frames;
  85. UINT8 packet_buf[PACKET_SIZE];
  86. ByteIOContext pb;
  87. /* only for reading */
  88. uint64_t data_offset; /* begining of the first data packet */
  89. ASFMainHeader hdr;
  90. int packet_flags;
  91. int packet_property;
  92. int packet_timestamp;
  93. int packet_segsizetype;
  94. int packet_segments;
  95. int packet_seq;
  96. int packet_replic_size;
  97. int packet_key_frame;
  98. int packet_padsize;
  99. int packet_frag_offset;
  100. int packet_frag_size;
  101. int packet_frag_timestamp;
  102. int packet_multi_size;
  103. int packet_obj_size;
  104. int packet_time_delta;
  105. int packet_time_start;
  106. int stream_index;
  107. ASFStream* asf_st; /* currently decoded stream */
  108. } ASFContext;
  109. static const GUID asf_header = {
  110. 0x75B22630, 0x668E, 0x11CF, { 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C },
  111. };
  112. static const GUID file_header = {
  113. 0x8CABDCA1, 0xA947, 0x11CF, { 0x8E, 0xE4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
  114. };
  115. static const GUID stream_header = {
  116. 0xB7DC0791, 0xA9B7, 0x11CF, { 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
  117. };
  118. static const GUID audio_stream = {
  119. 0xF8699E40, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
  120. };
  121. static const GUID audio_conceal_none = {
  122. // 0x49f1a440, 0x4ece, 0x11d0, { 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 },
  123. // New value lifted from avifile
  124. 0x20fb5700, 0x5b55, 0x11cf, { 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b },
  125. };
  126. static const GUID video_stream = {
  127. 0xBC19EFC0, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
  128. };
  129. static const GUID video_conceal_none = {
  130. 0x20FB5700, 0x5B55, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
  131. };
  132. static const GUID comment_header = {
  133. 0x75b22633, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c },
  134. };
  135. static const GUID codec_comment_header = {
  136. 0x86D15240, 0x311D, 0x11D0, { 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 },
  137. };
  138. static const GUID codec_comment1_header = {
  139. 0x86d15241, 0x311d, 0x11d0, { 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 },
  140. };
  141. static const GUID data_header = {
  142. 0x75b22636, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c },
  143. };
  144. static const GUID index_guid = {
  145. 0x33000890, 0xe5b1, 0x11cf, { 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb },
  146. };
  147. static const GUID head1_guid = {
  148. 0x5fbf03b5, 0xa92e, 0x11cf, { 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 },
  149. };
  150. static const GUID head2_guid = {
  151. 0xabd3d211, 0xa9ba, 0x11cf, { 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 },
  152. };
  153. /* I am not a number !!! This GUID is the one found on the PC used to
  154. generate the stream */
  155. static const GUID my_guid = {
  156. 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 },
  157. };
  158. static void put_guid(ByteIOContext *s, const GUID *g)
  159. {
  160. int i;
  161. put_le32(s, g->v1);
  162. put_le16(s, g->v2);
  163. put_le16(s, g->v3);
  164. for(i=0;i<8;i++)
  165. put_byte(s, g->v4[i]);
  166. }
  167. static void put_str16(ByteIOContext *s, const char *tag)
  168. {
  169. int c;
  170. put_le16(s,strlen(tag) + 1);
  171. for(;;) {
  172. c = (UINT8)*tag++;
  173. put_le16(s, c);
  174. if (c == '\0')
  175. break;
  176. }
  177. }
  178. static void put_str16_nolen(ByteIOContext *s, const char *tag)
  179. {
  180. int c;
  181. for(;;) {
  182. c = (UINT8)*tag++;
  183. put_le16(s, c);
  184. if (c == '\0')
  185. break;
  186. }
  187. }
  188. static INT64 put_header(ByteIOContext *pb, const GUID *g)
  189. {
  190. INT64 pos;
  191. pos = url_ftell(pb);
  192. put_guid(pb, g);
  193. put_le64(pb, 24);
  194. return pos;
  195. }
  196. /* update header size */
  197. static void end_header(ByteIOContext *pb, INT64 pos)
  198. {
  199. INT64 pos1;
  200. pos1 = url_ftell(pb);
  201. url_fseek(pb, pos + 16, SEEK_SET);
  202. put_le64(pb, pos1 - pos);
  203. url_fseek(pb, pos1, SEEK_SET);
  204. }
  205. /* write an asf chunk (only used in streaming case) */
  206. static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
  207. {
  208. ASFContext *asf = s->priv_data;
  209. ByteIOContext *pb = &s->pb;
  210. int length;
  211. length = payload_length + 8;
  212. put_le16(pb, type);
  213. put_le16(pb, length);
  214. put_le32(pb, asf->seqno);
  215. put_le16(pb, flags); /* unknown bytes */
  216. put_le16(pb, length);
  217. asf->seqno++;
  218. }
  219. /* convert from unix to windows time */
  220. static INT64 unix_to_file_time(int ti)
  221. {
  222. INT64 t;
  223. t = ti * INT64_C(10000000);
  224. t += INT64_C(116444736000000000);
  225. return t;
  226. }
  227. /* write the header (used two times if non streamed) */
  228. static int asf_write_header1(AVFormatContext *s, INT64 file_size, INT64 data_chunk_size)
  229. {
  230. ASFContext *asf = s->priv_data;
  231. ByteIOContext *pb = &s->pb;
  232. int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
  233. int has_title;
  234. AVCodecContext *enc;
  235. INT64 header_offset, cur_pos, hpos;
  236. int bit_rate;
  237. has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);
  238. bit_rate = 0;
  239. for(n=0;n<s->nb_streams;n++) {
  240. enc = &s->streams[n]->codec;
  241. bit_rate += enc->bit_rate;
  242. }
  243. if (asf->is_streamed) {
  244. put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
  245. }
  246. put_guid(pb, &asf_header);
  247. put_le64(pb, -1); /* header length, will be patched after */
  248. put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */
  249. put_byte(pb, 1); /* ??? */
  250. put_byte(pb, 2); /* ??? */
  251. /* file header */
  252. header_offset = url_ftell(pb);
  253. hpos = put_header(pb, &file_header);
  254. put_guid(pb, &my_guid);
  255. put_le64(pb, file_size);
  256. file_time = 0;
  257. put_le64(pb, unix_to_file_time(file_time));
  258. put_le64(pb, asf->nb_packets); /* number of packets */
  259. put_le64(pb, asf->duration); /* end time stamp (in 100ns units) */
  260. put_le64(pb, asf->duration); /* duration (in 100ns units) */
  261. put_le32(pb, 0); /* start time stamp */
  262. put_le32(pb, 0); /* ??? */
  263. put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */
  264. put_le32(pb, asf->packet_size); /* packet size */
  265. put_le32(pb, asf->packet_size); /* packet size */
  266. put_le32(pb, bit_rate); /* Nominal data rate in bps */
  267. end_header(pb, hpos);
  268. /* unknown headers */
  269. hpos = put_header(pb, &head1_guid);
  270. put_guid(pb, &head2_guid);
  271. put_le32(pb, 6);
  272. put_le16(pb, 0);
  273. end_header(pb, hpos);
  274. /* title and other infos */
  275. if (has_title) {
  276. hpos = put_header(pb, &comment_header);
  277. put_le16(pb, 2 * (strlen(s->title) + 1));
  278. put_le16(pb, 2 * (strlen(s->author) + 1));
  279. put_le16(pb, 2 * (strlen(s->copyright) + 1));
  280. put_le16(pb, 2 * (strlen(s->comment) + 1));
  281. put_le16(pb, 0);
  282. put_str16_nolen(pb, s->title);
  283. put_str16_nolen(pb, s->author);
  284. put_str16_nolen(pb, s->copyright);
  285. put_str16_nolen(pb, s->comment);
  286. end_header(pb, hpos);
  287. }
  288. /* stream headers */
  289. for(n=0;n<s->nb_streams;n++) {
  290. INT64 es_pos;
  291. // ASFStream *stream = &asf->streams[n];
  292. enc = &s->streams[n]->codec;
  293. asf->streams[n].num = n + 1;
  294. asf->streams[n].seq = 0;
  295. switch(enc->codec_type) {
  296. case CODEC_TYPE_AUDIO:
  297. wav_extra_size = 0;
  298. extra_size = 18 + wav_extra_size;
  299. extra_size2 = 0;
  300. break;
  301. default:
  302. case CODEC_TYPE_VIDEO:
  303. wav_extra_size = 0;
  304. extra_size = 0x33;
  305. extra_size2 = 0;
  306. break;
  307. }
  308. hpos = put_header(pb, &stream_header);
  309. if (enc->codec_type == CODEC_TYPE_AUDIO) {
  310. put_guid(pb, &audio_stream);
  311. put_guid(pb, &audio_conceal_none);
  312. } else {
  313. put_guid(pb, &video_stream);
  314. put_guid(pb, &video_conceal_none);
  315. }
  316. put_le64(pb, 0); /* ??? */
  317. es_pos = url_ftell(pb);
  318. put_le32(pb, extra_size); /* wav header len */
  319. put_le32(pb, extra_size2); /* additional data len */
  320. put_le16(pb, n + 1); /* stream number */
  321. put_le32(pb, 0); /* ??? */
  322. if (enc->codec_type == CODEC_TYPE_AUDIO) {
  323. /* WAVEFORMATEX header */
  324. int wavsize = put_wav_header(pb, enc);
  325. if (wavsize < 0)
  326. return -1;
  327. if (wavsize != extra_size) {
  328. cur_pos = url_ftell(pb);
  329. url_fseek(pb, es_pos, SEEK_SET);
  330. put_le32(pb, wavsize); /* wav header len */
  331. url_fseek(pb, cur_pos, SEEK_SET);
  332. }
  333. } else {
  334. put_le32(pb, enc->width);
  335. put_le32(pb, enc->height);
  336. put_byte(pb, 2); /* ??? */
  337. put_le16(pb, 40); /* size */
  338. /* BITMAPINFOHEADER header */
  339. put_bmp_header(pb, enc, codec_bmp_tags);
  340. }
  341. end_header(pb, hpos);
  342. }
  343. /* media comments */
  344. hpos = put_header(pb, &codec_comment_header);
  345. put_guid(pb, &codec_comment1_header);
  346. put_le32(pb, s->nb_streams);
  347. for(n=0;n<s->nb_streams;n++) {
  348. AVCodec *p;
  349. enc = &s->streams[n]->codec;
  350. p = avcodec_find_encoder(enc->codec_id);
  351. put_le16(pb, asf->streams[n].num);
  352. put_str16(pb, p ? p->name : enc->codec_name);
  353. put_le16(pb, 0); /* no parameters */
  354. /* id */
  355. if (enc->codec_type == CODEC_TYPE_AUDIO) {
  356. put_le16(pb, 2);
  357. put_le16(pb, codec_get_tag(codec_wav_tags, enc->codec_id));
  358. } else {
  359. put_le16(pb, 4);
  360. put_le32(pb, codec_get_tag(codec_bmp_tags, enc->codec_id));
  361. }
  362. }
  363. end_header(pb, hpos);
  364. /* patch the header size fields */
  365. cur_pos = url_ftell(pb);
  366. header_size = cur_pos - header_offset;
  367. if (asf->is_streamed) {
  368. header_size += 8 + 30 + 50;
  369. url_fseek(pb, header_offset - 10 - 30, SEEK_SET);
  370. put_le16(pb, header_size);
  371. url_fseek(pb, header_offset - 2 - 30, SEEK_SET);
  372. put_le16(pb, header_size);
  373. header_size -= 8 + 30 + 50;
  374. }
  375. header_size += 24 + 6;
  376. url_fseek(pb, header_offset - 14, SEEK_SET);
  377. put_le64(pb, header_size);
  378. url_fseek(pb, cur_pos, SEEK_SET);
  379. /* movie chunk, followed by packets of packet_size */
  380. asf->data_offset = cur_pos;
  381. put_guid(pb, &data_header);
  382. put_le64(pb, data_chunk_size);
  383. put_guid(pb, &my_guid);
  384. put_le64(pb, asf->nb_packets); /* nb packets */
  385. put_byte(pb, 1); /* ??? */
  386. put_byte(pb, 1); /* ??? */
  387. return 0;
  388. }
  389. static int asf_write_header(AVFormatContext *s)
  390. {
  391. ASFContext *asf = s->priv_data;
  392. av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
  393. asf->packet_size = PACKET_SIZE;
  394. asf->nb_packets = 0;
  395. if (asf_write_header1(s, 0, 50) < 0) {
  396. //av_free(asf);
  397. return -1;
  398. }
  399. put_flush_packet(&s->pb);
  400. asf->packet_nb_frames = 0;
  401. asf->packet_timestamp_start = -1;
  402. asf->packet_timestamp_end = -1;
  403. asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
  404. init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
  405. NULL, NULL, NULL, NULL);
  406. return 0;
  407. }
  408. static int asf_write_stream_header(AVFormatContext *s)
  409. {
  410. ASFContext *asf = s->priv_data;
  411. asf->is_streamed = 1;
  412. return asf_write_header(s);
  413. }
  414. /* write a fixed size packet */
  415. static int put_packet(AVFormatContext *s,
  416. unsigned int timestamp, unsigned int duration,
  417. int nb_frames, int padsize)
  418. {
  419. ASFContext *asf = s->priv_data;
  420. ByteIOContext *pb = &s->pb;
  421. int flags;
  422. if (asf->is_streamed) {
  423. put_chunk(s, 0x4424, asf->packet_size, 0);
  424. }
  425. put_byte(pb, 0x82);
  426. put_le16(pb, 0);
  427. flags = 0x01; /* nb segments present */
  428. if (padsize > 0) {
  429. if (padsize < 256)
  430. flags |= 0x08;
  431. else
  432. flags |= 0x10;
  433. }
  434. put_byte(pb, flags); /* flags */
  435. put_byte(pb, 0x5d);
  436. if (flags & 0x10)
  437. put_le16(pb, padsize - 2);
  438. if (flags & 0x08)
  439. put_byte(pb, padsize - 1);
  440. put_le32(pb, timestamp);
  441. put_le16(pb, duration);
  442. put_byte(pb, nb_frames | 0x80);
  443. return PACKET_HEADER_SIZE + ((flags & 0x18) >> 3);
  444. }
  445. static void flush_packet(AVFormatContext *s)
  446. {
  447. ASFContext *asf = s->priv_data;
  448. int hdr_size, ptr;
  449. hdr_size = put_packet(s, asf->packet_timestamp_start,
  450. asf->packet_timestamp_end - asf->packet_timestamp_start,
  451. asf->packet_nb_frames, asf->packet_size_left);
  452. /* Clear out the padding bytes */
  453. ptr = asf->packet_size - hdr_size - asf->packet_size_left;
  454. memset(asf->packet_buf + ptr, 0, asf->packet_size_left);
  455. put_buffer(&s->pb, asf->packet_buf, asf->packet_size - hdr_size);
  456. put_flush_packet(&s->pb);
  457. asf->nb_packets++;
  458. asf->packet_nb_frames = 0;
  459. asf->packet_timestamp_start = -1;
  460. asf->packet_timestamp_end = -1;
  461. asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
  462. init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
  463. NULL, NULL, NULL, NULL);
  464. }
  465. static void put_frame_header(AVFormatContext *s, ASFStream *stream, int timestamp,
  466. int payload_size, int frag_offset, int frag_len)
  467. {
  468. ASFContext *asf = s->priv_data;
  469. ByteIOContext *pb = &asf->pb;
  470. int val;
  471. val = stream->num;
  472. if (s->streams[val - 1]->codec.key_frame /* && frag_offset == 0 */)
  473. val |= 0x80;
  474. put_byte(pb, val);
  475. put_byte(pb, stream->seq);
  476. put_le32(pb, frag_offset); /* fragment offset */
  477. put_byte(pb, 0x08); /* flags */
  478. put_le32(pb, payload_size);
  479. put_le32(pb, timestamp);
  480. put_le16(pb, frag_len);
  481. }
  482. /* Output a frame. We suppose that payload_size <= PACKET_SIZE.
  483. It is there that you understand that the ASF format is really
  484. crap. They have misread the MPEG Systems spec !
  485. */
  486. static void put_frame(AVFormatContext *s, ASFStream *stream, int timestamp,
  487. UINT8 *buf, int payload_size)
  488. {
  489. ASFContext *asf = s->priv_data;
  490. int frag_pos, frag_len, frag_len1;
  491. frag_pos = 0;
  492. while (frag_pos < payload_size) {
  493. frag_len = payload_size - frag_pos;
  494. frag_len1 = asf->packet_size_left - FRAME_HEADER_SIZE;
  495. if (frag_len1 > 0) {
  496. if (frag_len > frag_len1)
  497. frag_len = frag_len1;
  498. put_frame_header(s, stream, timestamp, payload_size, frag_pos, frag_len);
  499. put_buffer(&asf->pb, buf, frag_len);
  500. asf->packet_size_left -= (frag_len + FRAME_HEADER_SIZE);
  501. asf->packet_timestamp_end = timestamp;
  502. if (asf->packet_timestamp_start == -1)
  503. asf->packet_timestamp_start = timestamp;
  504. asf->packet_nb_frames++;
  505. } else {
  506. frag_len = 0;
  507. }
  508. frag_pos += frag_len;
  509. buf += frag_len;
  510. /* output the frame if filled */
  511. if (asf->packet_size_left <= FRAME_HEADER_SIZE)
  512. flush_packet(s);
  513. }
  514. stream->seq++;
  515. }
  516. static int asf_write_packet(AVFormatContext *s, int stream_index,
  517. UINT8 *buf, int size, int timestamp)
  518. {
  519. ASFContext *asf = s->priv_data;
  520. ASFStream *stream;
  521. INT64 duration;
  522. AVCodecContext *codec;
  523. codec = &s->streams[stream_index]->codec;
  524. stream = &asf->streams[stream_index];
  525. if (codec->codec_type == CODEC_TYPE_AUDIO) {
  526. duration = (codec->frame_number * codec->frame_size * INT64_C(10000000)) /
  527. codec->sample_rate;
  528. } else {
  529. duration = codec->frame_number *
  530. ((INT64_C(10000000) * FRAME_RATE_BASE) / codec->frame_rate);
  531. }
  532. if (duration > asf->duration)
  533. asf->duration = duration;
  534. put_frame(s, stream, timestamp, buf, size);
  535. return 0;
  536. }
  537. static int asf_write_trailer(AVFormatContext *s)
  538. {
  539. ASFContext *asf = s->priv_data;
  540. INT64 file_size;
  541. /* flush the current packet */
  542. if (asf->pb.buf_ptr > asf->pb.buffer)
  543. flush_packet(s);
  544. if (asf->is_streamed) {
  545. put_chunk(s, 0x4524, 0, 0); /* end of stream */
  546. } else {
  547. /* rewrite an updated header */
  548. file_size = url_ftell(&s->pb);
  549. url_fseek(&s->pb, 0, SEEK_SET);
  550. asf_write_header1(s, file_size, file_size - asf->data_offset);
  551. }
  552. put_flush_packet(&s->pb);
  553. return 0;
  554. }
  555. /**********************************/
  556. /* decoding */
  557. //#define DEBUG
  558. #ifdef DEBUG
  559. static void print_guid(const GUID *g)
  560. {
  561. int i;
  562. printf("0x%08x, 0x%04x, 0x%04x, {", g->v1, g->v2, g->v3);
  563. for(i=0;i<8;i++)
  564. printf(" 0x%02x,", g->v4[i]);
  565. printf("}\n");
  566. }
  567. #endif
  568. static void get_guid(ByteIOContext *s, GUID *g)
  569. {
  570. int i;
  571. g->v1 = get_le32(s);
  572. g->v2 = get_le16(s);
  573. g->v3 = get_le16(s);
  574. for(i=0;i<8;i++)
  575. g->v4[i] = get_byte(s);
  576. }
  577. #if 0
  578. static void get_str16(ByteIOContext *pb, char *buf, int buf_size)
  579. {
  580. int len, c;
  581. char *q;
  582. len = get_le16(pb);
  583. q = buf;
  584. while (len > 0) {
  585. c = get_le16(pb);
  586. if ((q - buf) < buf_size - 1)
  587. *q++ = c;
  588. len--;
  589. }
  590. *q = '\0';
  591. }
  592. #endif
  593. static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size)
  594. {
  595. int c;
  596. char *q;
  597. q = buf;
  598. while (len > 0) {
  599. c = get_le16(pb);
  600. if ((q - buf) < buf_size - 1)
  601. *q++ = c;
  602. len-=2;
  603. }
  604. *q = '\0';
  605. }
  606. static int asf_probe(AVProbeData *pd)
  607. {
  608. GUID g;
  609. const unsigned char *p;
  610. int i;
  611. /* check file header */
  612. if (pd->buf_size <= 32)
  613. return 0;
  614. p = pd->buf;
  615. g.v1 = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
  616. p += 4;
  617. g.v2 = p[0] | (p[1] << 8);
  618. p += 2;
  619. g.v3 = p[0] | (p[1] << 8);
  620. p += 2;
  621. for(i=0;i<8;i++)
  622. g.v4[i] = *p++;
  623. if (!memcmp(&g, &asf_header, sizeof(GUID)))
  624. return AVPROBE_SCORE_MAX;
  625. else
  626. return 0;
  627. }
  628. static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
  629. {
  630. ASFContext *asf = s->priv_data;
  631. GUID g;
  632. ByteIOContext *pb = &s->pb;
  633. AVStream *st;
  634. ASFStream *asf_st;
  635. int size, i, bps;
  636. INT64 gsize;
  637. av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
  638. get_guid(pb, &g);
  639. if (memcmp(&g, &asf_header, sizeof(GUID)))
  640. goto fail;
  641. get_le64(pb);
  642. get_le32(pb);
  643. get_byte(pb);
  644. get_byte(pb);
  645. memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
  646. for(;;) {
  647. get_guid(pb, &g);
  648. gsize = get_le64(pb);
  649. #ifdef DEBUG
  650. printf("%08Lx: ", url_ftell(pb) - 24);
  651. print_guid(&g);
  652. printf(" size=0x%Lx\n", gsize);
  653. #endif
  654. if (gsize < 24)
  655. goto fail;
  656. if (!memcmp(&g, &file_header, sizeof(GUID))) {
  657. get_guid(pb, &asf->hdr.guid);
  658. asf->hdr.file_size = get_le64(pb);
  659. asf->hdr.create_time = get_le64(pb);
  660. asf->hdr.packets_count = get_le64(pb);
  661. asf->hdr.play_time = get_le64(pb);
  662. asf->hdr.send_time = get_le64(pb);
  663. asf->hdr.preroll = get_le32(pb);
  664. asf->hdr.ignore = get_le32(pb);
  665. asf->hdr.flags = get_le32(pb);
  666. asf->hdr.min_pktsize = get_le32(pb);
  667. asf->hdr.max_pktsize = get_le32(pb);
  668. asf->hdr.max_bitrate = get_le32(pb);
  669. asf->packet_size = asf->hdr.max_pktsize;
  670. asf->nb_packets = asf->hdr.packets_count;
  671. } else if (!memcmp(&g, &stream_header, sizeof(GUID))) {
  672. int type, id, total_size;
  673. unsigned int tag1;
  674. INT64 pos1, pos2;
  675. pos1 = url_ftell(pb);
  676. st = av_mallocz(sizeof(AVStream));
  677. if (!st)
  678. goto fail;
  679. s->streams[s->nb_streams] = st;
  680. asf_st = av_mallocz(sizeof(ASFStream));
  681. if (!asf_st)
  682. goto fail;
  683. st->priv_data = asf_st;
  684. st->time_length = (asf->hdr.send_time - asf->hdr.preroll) / 10; // us
  685. get_guid(pb, &g);
  686. if (!memcmp(&g, &audio_stream, sizeof(GUID))) {
  687. type = CODEC_TYPE_AUDIO;
  688. } else if (!memcmp(&g, &video_stream, sizeof(GUID))) {
  689. type = CODEC_TYPE_VIDEO;
  690. } else {
  691. goto fail;
  692. }
  693. get_guid(pb, &g);
  694. total_size = get_le64(pb);
  695. get_le32(pb);
  696. get_le32(pb);
  697. st->id = get_le16(pb) & 0x7f; /* stream id */
  698. // mapping of asf ID to AV stream ID;
  699. asf->asfid2avid[st->id] = s->nb_streams++;
  700. get_le32(pb);
  701. st->codec.codec_type = type;
  702. st->codec.frame_rate = 1000000; // us
  703. if (type == CODEC_TYPE_AUDIO) {
  704. id = get_le16(pb);
  705. st->codec.codec_tag = id;
  706. st->codec.channels = get_le16(pb);
  707. st->codec.sample_rate = get_le32(pb);
  708. st->codec.bit_rate = get_le32(pb) * 8;
  709. st->codec.block_align = get_le16(pb); /* block align */
  710. bps = get_le16(pb); /* bits per sample */
  711. st->codec.codec_id = wav_codec_get_id(id, bps);
  712. size = get_le16(pb);
  713. if (size > 0) {
  714. st->extra_data = av_mallocz(size);
  715. get_buffer(pb, st->extra_data, size);
  716. st->extra_data_size = size;
  717. }
  718. /* We have to init the frame size at some point .... */
  719. pos2 = url_ftell(pb);
  720. if (gsize > (pos2 + 8 - pos1 + 24)) {
  721. asf_st->ds_span = get_byte(pb);
  722. asf_st->ds_packet_size = get_le16(pb);
  723. asf_st->ds_chunk_size = get_le16(pb);
  724. asf_st->ds_data_size = get_le16(pb);
  725. asf_st->ds_silence_data = get_byte(pb);
  726. }
  727. //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n",
  728. // asf_st->ds_packet_size, asf_st->ds_chunk_size,
  729. // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data);
  730. if (asf_st->ds_span > 1) {
  731. if (!asf_st->ds_chunk_size
  732. || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1))
  733. asf_st->ds_span = 0; // disable descrambling
  734. }
  735. switch (st->codec.codec_id) {
  736. case CODEC_ID_MP3LAME:
  737. st->codec.frame_size = MPA_FRAME_SIZE;
  738. break;
  739. case CODEC_ID_PCM_S16LE:
  740. case CODEC_ID_PCM_S16BE:
  741. case CODEC_ID_PCM_U16LE:
  742. case CODEC_ID_PCM_U16BE:
  743. case CODEC_ID_PCM_S8:
  744. case CODEC_ID_PCM_U8:
  745. case CODEC_ID_PCM_ALAW:
  746. case CODEC_ID_PCM_MULAW:
  747. st->codec.frame_size = 1;
  748. break;
  749. default:
  750. /* This is probably wrong, but it prevents a crash later */
  751. st->codec.frame_size = 1;
  752. break;
  753. }
  754. } else {
  755. get_le32(pb);
  756. get_le32(pb);
  757. get_byte(pb);
  758. size = get_le16(pb); /* size */
  759. get_le32(pb); /* size */
  760. st->codec.width = get_le32(pb);
  761. st->codec.height = get_le32(pb);
  762. /* not available for asf */
  763. get_le16(pb); /* panes */
  764. get_le16(pb); /* depth */
  765. tag1 = get_le32(pb);
  766. url_fskip(pb, 20);
  767. if (size > 40) {
  768. st->extra_data_size = size - 40;
  769. st->extra_data = av_mallocz(st->extra_data_size);
  770. get_buffer(pb, st->extra_data, st->extra_data_size);
  771. }
  772. st->codec.codec_tag = tag1;
  773. st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
  774. }
  775. pos2 = url_ftell(pb);
  776. url_fskip(pb, gsize - (pos2 - pos1 + 24));
  777. } else if (!memcmp(&g, &data_header, sizeof(GUID))) {
  778. break;
  779. } else if (!memcmp(&g, &comment_header, sizeof(GUID))) {
  780. int len1, len2, len3, len4, len5;
  781. len1 = get_le16(pb);
  782. len2 = get_le16(pb);
  783. len3 = get_le16(pb);
  784. len4 = get_le16(pb);
  785. len5 = get_le16(pb);
  786. get_str16_nolen(pb, len1, s->title, sizeof(s->title));
  787. get_str16_nolen(pb, len2, s->author, sizeof(s->author));
  788. get_str16_nolen(pb, len3, s->copyright, sizeof(s->copyright));
  789. get_str16_nolen(pb, len4, s->comment, sizeof(s->comment));
  790. url_fskip(pb, len5);
  791. #if 0
  792. } else if (!memcmp(&g, &head1_guid, sizeof(GUID))) {
  793. int v1, v2;
  794. get_guid(pb, &g);
  795. v1 = get_le32(pb);
  796. v2 = get_le16(pb);
  797. } else if (!memcmp(&g, &codec_comment_header, sizeof(GUID))) {
  798. int len, v1, n, num;
  799. char str[256], *q;
  800. char tag[16];
  801. get_guid(pb, &g);
  802. print_guid(&g);
  803. n = get_le32(pb);
  804. for(i=0;i<n;i++) {
  805. num = get_le16(pb); /* stream number */
  806. get_str16(pb, str, sizeof(str));
  807. get_str16(pb, str, sizeof(str));
  808. len = get_le16(pb);
  809. q = tag;
  810. while (len > 0) {
  811. v1 = get_byte(pb);
  812. if ((q - tag) < sizeof(tag) - 1)
  813. *q++ = v1;
  814. len--;
  815. }
  816. *q = '\0';
  817. }
  818. #endif
  819. } else if (url_feof(pb)) {
  820. goto fail;
  821. } else {
  822. url_fseek(pb, gsize - 24, SEEK_CUR);
  823. }
  824. }
  825. get_guid(pb, &g);
  826. get_le64(pb);
  827. get_byte(pb);
  828. get_byte(pb);
  829. if (url_feof(pb))
  830. goto fail;
  831. asf->data_offset = url_ftell(pb);
  832. asf->packet_size_left = 0;
  833. return 0;
  834. fail:
  835. for(i=0;i<s->nb_streams;i++) {
  836. AVStream *st = s->streams[i];
  837. if (st) {
  838. av_free(st->priv_data);
  839. av_free(st->extra_data);
  840. }
  841. av_free(st);
  842. }
  843. //av_free(asf);
  844. return -1;
  845. }
  846. #define DO_2BITS(bits, var, defval) \
  847. switch (bits & 3) \
  848. { \
  849. case 3: var = get_le32(pb); rsize += 4; break; \
  850. case 2: var = get_le16(pb); rsize += 2; break; \
  851. case 1: var = get_byte(pb); rsize++; break; \
  852. default: var = defval; break; \
  853. }
  854. static int asf_get_packet(AVFormatContext *s)
  855. {
  856. ASFContext *asf = s->priv_data;
  857. ByteIOContext *pb = &s->pb;
  858. uint32_t packet_length, padsize;
  859. int rsize = 11;
  860. int c = get_byte(pb);
  861. if (c != 0x82) {
  862. printf("BAD HRD %x at:%Ld\n", c, url_ftell(pb));
  863. return -EIO;
  864. }
  865. if ((c & 0x0f) == 2) { // always true for now
  866. if (get_le16(pb) != 0) {
  867. printf("ff asf BAD NO ZERO\n");
  868. return -EIO;
  869. }
  870. }
  871. asf->packet_flags = get_byte(pb);
  872. asf->packet_property = get_byte(pb);
  873. DO_2BITS(asf->packet_flags >> 5, packet_length, asf->packet_size);
  874. DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
  875. DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
  876. asf->packet_timestamp = get_le32(pb);
  877. get_le16(pb); /* duration */
  878. // rsize has at least 11 bytes which have to be present
  879. if (asf->packet_flags & 0x01) {
  880. asf->packet_segsizetype = get_byte(pb); rsize++;
  881. asf->packet_segments = asf->packet_segsizetype & 0x3f;
  882. } else {
  883. asf->packet_segments = 1;
  884. asf->packet_segsizetype = 0x80;
  885. }
  886. asf->packet_size_left = packet_length - padsize - rsize;
  887. asf->packet_padsize = padsize;
  888. #ifdef DEBUG
  889. printf("packet: size=%d padsize=%d left=%d\n", asf->packet_size, asf->packet_padsize, asf->packet_size_left);
  890. #endif
  891. return 0;
  892. }
  893. static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
  894. {
  895. ASFContext *asf = s->priv_data;
  896. ASFStream *asf_st = 0;
  897. ByteIOContext *pb = &s->pb;
  898. //static int pc = 0;
  899. for (;;) {
  900. int rsize = 0;
  901. if (asf->packet_size_left < FRAME_HEADER_SIZE
  902. || asf->packet_segments < 1) {
  903. //asf->packet_size_left <= asf->packet_padsize) {
  904. int ret = asf->packet_size_left + asf->packet_padsize;
  905. //printf("PacketLeftSize:%d Pad:%d Pos:%Ld\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb));
  906. /* fail safe */
  907. url_fskip(pb, ret);
  908. ret = asf_get_packet(s);
  909. //printf("READ ASF PACKET %d r:%d c:%d\n", ret, asf->packet_size_left, pc++);
  910. if (ret < 0)
  911. return -EIO;
  912. asf->packet_time_start = 0;
  913. continue;
  914. }
  915. if (asf->packet_time_start == 0) {
  916. /* read frame header */
  917. int num = get_byte(pb);
  918. asf->packet_segments--;
  919. rsize++;
  920. asf->packet_key_frame = (num & 0x80) >> 7;
  921. asf->stream_index = asf->asfid2avid[num & 0x7f];
  922. // sequence should be ignored!
  923. DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
  924. DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
  925. DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
  926. if (asf->packet_replic_size > 1) {
  927. // it should be always at least 8 bytes - FIXME validate
  928. asf->packet_obj_size = get_le32(pb);
  929. asf->packet_frag_timestamp = get_le32(pb); // timestamp
  930. rsize += asf->packet_replic_size; // FIXME - check validity
  931. } else {
  932. // multipacket - frag_offset is beginig timestamp
  933. asf->packet_time_start = asf->packet_frag_offset;
  934. asf->packet_frag_offset = 0;
  935. asf->packet_frag_timestamp = asf->packet_timestamp;
  936. if (asf->packet_replic_size == 1) {
  937. asf->packet_time_delta = get_byte(pb);
  938. rsize++;
  939. }
  940. }
  941. if (asf->packet_flags & 0x01) {
  942. DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
  943. //printf("Fragsize %d\n", asf->packet_frag_size);
  944. } else {
  945. asf->packet_frag_size = asf->packet_size_left - rsize;
  946. //printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
  947. }
  948. if (asf->packet_replic_size == 1) {
  949. asf->packet_multi_size = asf->packet_frag_size;
  950. if (asf->packet_multi_size > asf->packet_size_left) {
  951. asf->packet_segments = 0;
  952. continue;
  953. }
  954. }
  955. #undef DO_2BITS
  956. asf->packet_size_left -= rsize;
  957. //printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
  958. if (asf->stream_index < 0) {
  959. asf->packet_time_start = 0;
  960. /* unhandled packet (should not happen) */
  961. url_fskip(pb, asf->packet_frag_size);
  962. asf->packet_size_left -= asf->packet_frag_size;
  963. printf("ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f);
  964. continue;
  965. }
  966. asf->asf_st = s->streams[asf->stream_index]->priv_data;
  967. }
  968. asf_st = asf->asf_st;
  969. if ((asf->packet_frag_offset != asf_st->frag_offset
  970. || (asf->packet_frag_offset
  971. && asf->packet_seq != asf_st->seq)) // seq should be ignored
  972. ) {
  973. /* cannot continue current packet: free it */
  974. // FIXME better check if packet was already allocated
  975. printf("ff asf parser skips: %d - %d o:%d - %d %d %d fl:%d\n",
  976. asf_st->pkt.size,
  977. asf->packet_obj_size,
  978. asf->packet_frag_offset, asf_st->frag_offset,
  979. asf->packet_seq, asf_st->seq, asf->packet_frag_size);
  980. if (asf_st->pkt.size)
  981. av_free_packet(&asf_st->pkt);
  982. asf_st->frag_offset = 0;
  983. if (asf->packet_frag_offset != 0) {
  984. url_fskip(pb, asf->packet_frag_size);
  985. printf("ff asf parser skiping %db\n", asf->packet_frag_size);
  986. asf->packet_size_left -= asf->packet_frag_size;
  987. continue;
  988. }
  989. }
  990. if (asf->packet_replic_size == 1) {
  991. // frag_offset is here used as the begining timestamp
  992. asf->packet_frag_timestamp = asf->packet_time_start;
  993. asf->packet_time_start += asf->packet_time_delta;
  994. asf->packet_obj_size = asf->packet_frag_size = get_byte(pb);
  995. asf->packet_size_left--;
  996. asf->packet_multi_size--;
  997. if (asf->packet_multi_size < asf->packet_obj_size)
  998. {
  999. asf->packet_time_start = 0;
  1000. url_fskip(pb, asf->packet_multi_size);
  1001. asf->packet_size_left -= asf->packet_multi_size;
  1002. continue;
  1003. }
  1004. asf->packet_multi_size -= asf->packet_obj_size;
  1005. //printf("COMPRESS size %d %d %d ms:%d\n", asf->packet_obj_size, asf->packet_frag_timestamp, asf->packet_size_left, asf->packet_multi_size);
  1006. }
  1007. if (asf_st->frag_offset == 0) {
  1008. /* new packet */
  1009. av_new_packet(&asf_st->pkt, asf->packet_obj_size);
  1010. asf_st->seq = asf->packet_seq;
  1011. asf_st->pkt.pts = asf->packet_frag_timestamp - asf->hdr.preroll;
  1012. asf_st->pkt.pts *= 1000; // us
  1013. asf_st->pkt.stream_index = asf->stream_index;
  1014. if (asf->packet_key_frame)
  1015. asf_st->pkt.flags |= PKT_FLAG_KEY;
  1016. }
  1017. /* read data */
  1018. //printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
  1019. // asf->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
  1020. // asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
  1021. asf->packet_size_left -= asf->packet_frag_size;
  1022. if (asf->packet_size_left < 0)
  1023. continue;
  1024. get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
  1025. asf->packet_frag_size);
  1026. asf_st->frag_offset += asf->packet_frag_size;
  1027. /* test if whole packet is read */
  1028. if (asf_st->frag_offset == asf_st->pkt.size) {
  1029. /* return packet */
  1030. if (asf_st->ds_span > 1) {
  1031. /* packet descrambling */
  1032. char* newdata = av_malloc(asf_st->pkt.size);
  1033. if (newdata) {
  1034. int offset = 0;
  1035. while (offset < asf_st->pkt.size) {
  1036. int off = offset / asf_st->ds_chunk_size;
  1037. int row = off / asf_st->ds_span;
  1038. int col = off % asf_st->ds_span;
  1039. int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
  1040. //printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx);
  1041. memcpy(newdata + offset,
  1042. asf_st->pkt.data + idx * asf_st->ds_chunk_size,
  1043. asf_st->ds_chunk_size);
  1044. offset += asf_st->ds_chunk_size;
  1045. }
  1046. av_free(asf_st->pkt.data);
  1047. asf_st->pkt.data = newdata;
  1048. }
  1049. }
  1050. asf_st->frag_offset = 0;
  1051. memcpy(pkt, &asf_st->pkt, sizeof(AVPacket));
  1052. //printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size);
  1053. asf_st->pkt.size = 0;
  1054. asf_st->pkt.data = 0;
  1055. break; // packet completed
  1056. }
  1057. }
  1058. return 0;
  1059. }
  1060. static int asf_read_close(AVFormatContext *s)
  1061. {
  1062. //ASFContext *asf = s->priv_data;
  1063. int i;
  1064. for(i=0;i<s->nb_streams;i++) {
  1065. AVStream *st = s->streams[i];
  1066. av_free(st->priv_data);
  1067. av_free(st->extra_data);
  1068. }
  1069. //av_free(asf);
  1070. return 0;
  1071. }
  1072. static int asf_read_seek(AVFormatContext *s, int64_t pts)
  1073. {
  1074. printf("SEEK TO %Ld", pts);
  1075. return -1;
  1076. }
  1077. AVInputFormat asf_iformat = {
  1078. "asf",
  1079. "asf format",
  1080. sizeof(ASFContext),
  1081. asf_probe,
  1082. asf_read_header,
  1083. asf_read_packet,
  1084. asf_read_close,
  1085. asf_read_seek,
  1086. };
  1087. AVOutputFormat asf_oformat = {
  1088. "asf",
  1089. "asf format",
  1090. "application/octet-stream",
  1091. "asf,wmv",
  1092. sizeof(ASFContext),
  1093. #ifdef CONFIG_MP3LAME
  1094. CODEC_ID_MP3LAME,
  1095. #else
  1096. CODEC_ID_MP2,
  1097. #endif
  1098. CODEC_ID_MSMPEG4,
  1099. asf_write_header,
  1100. asf_write_packet,
  1101. asf_write_trailer,
  1102. };
  1103. AVOutputFormat asf_stream_oformat = {
  1104. "asf_stream",
  1105. "asf format",
  1106. "application/octet-stream",
  1107. "asf,wmv",
  1108. sizeof(ASFContext),
  1109. #ifdef CONFIG_MP3LAME
  1110. CODEC_ID_MP3LAME,
  1111. #else
  1112. CODEC_ID_MP2,
  1113. #endif
  1114. CODEC_ID_MSMPEG4,
  1115. asf_write_stream_header,
  1116. asf_write_packet,
  1117. asf_write_trailer,
  1118. };
  1119. int asf_init(void)
  1120. {
  1121. av_register_input_format(&asf_iformat);
  1122. av_register_output_format(&asf_oformat);
  1123. av_register_output_format(&asf_stream_oformat);
  1124. return 0;
  1125. }