asfdec.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  1. /*
  2. * ASF compatible demuxer
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  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. #include "libavutil/common.h"
  22. #include "libavcodec/mpegaudio.h"
  23. #include "avformat.h"
  24. #include "riff.h"
  25. #include "asf.h"
  26. #include "asfcrypt.h"
  27. void ff_mms_set_stream_selection(URLContext *h, AVFormatContext *format);
  28. #undef NDEBUG
  29. #include <assert.h>
  30. #define FRAME_HEADER_SIZE 17
  31. // Fix Me! FRAME_HEADER_SIZE may be different.
  32. static const ff_asf_guid index_guid = {
  33. 0x90, 0x08, 0x00, 0x33, 0xb1, 0xe5, 0xcf, 0x11, 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb
  34. };
  35. static const ff_asf_guid stream_bitrate_guid = { /* (http://get.to/sdp) */
  36. 0xce, 0x75, 0xf8, 0x7b, 0x8d, 0x46, 0xd1, 0x11, 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2
  37. };
  38. /**********************************/
  39. /* decoding */
  40. //#define DEBUG
  41. #ifdef DEBUG
  42. #define PRINT_IF_GUID(g,cmp) \
  43. if (!guidcmp(g, &cmp)) \
  44. dprintf(NULL, "(GUID: %s) ", #cmp)
  45. static void print_guid(const ff_asf_guid *g)
  46. {
  47. int i;
  48. PRINT_IF_GUID(g, ff_asf_header);
  49. else PRINT_IF_GUID(g, ff_asf_file_header);
  50. else PRINT_IF_GUID(g, ff_asf_stream_header);
  51. else PRINT_IF_GUID(g, ff_asf_audio_stream);
  52. else PRINT_IF_GUID(g, ff_asf_audio_conceal_none);
  53. else PRINT_IF_GUID(g, ff_asf_video_stream);
  54. else PRINT_IF_GUID(g, ff_asf_video_conceal_none);
  55. else PRINT_IF_GUID(g, ff_asf_command_stream);
  56. else PRINT_IF_GUID(g, ff_asf_comment_header);
  57. else PRINT_IF_GUID(g, ff_asf_codec_comment_header);
  58. else PRINT_IF_GUID(g, ff_asf_codec_comment1_header);
  59. else PRINT_IF_GUID(g, ff_asf_data_header);
  60. else PRINT_IF_GUID(g, index_guid);
  61. else PRINT_IF_GUID(g, ff_asf_head1_guid);
  62. else PRINT_IF_GUID(g, ff_asf_head2_guid);
  63. else PRINT_IF_GUID(g, ff_asf_my_guid);
  64. else PRINT_IF_GUID(g, ff_asf_ext_stream_header);
  65. else PRINT_IF_GUID(g, ff_asf_extended_content_header);
  66. else PRINT_IF_GUID(g, ff_asf_ext_stream_embed_stream_header);
  67. else PRINT_IF_GUID(g, ff_asf_ext_stream_audio_stream);
  68. else PRINT_IF_GUID(g, ff_asf_metadata_header);
  69. else PRINT_IF_GUID(g, stream_bitrate_guid);
  70. else
  71. dprintf(NULL, "(GUID: unknown) ");
  72. for(i=0;i<16;i++)
  73. dprintf(NULL, " 0x%02x,", (*g)[i]);
  74. dprintf(NULL, "}\n");
  75. }
  76. #undef PRINT_IF_GUID
  77. #else
  78. #define print_guid(g)
  79. #endif
  80. static int guidcmp(const void *g1, const void *g2)
  81. {
  82. return memcmp(g1, g2, sizeof(ff_asf_guid));
  83. }
  84. static void get_guid(ByteIOContext *s, ff_asf_guid *g)
  85. {
  86. assert(sizeof(*g) == 16);
  87. get_buffer(s, *g, sizeof(*g));
  88. }
  89. #if 0
  90. static void get_str16(ByteIOContext *pb, char *buf, int buf_size)
  91. {
  92. int len, c;
  93. char *q;
  94. len = get_le16(pb);
  95. q = buf;
  96. while (len > 0) {
  97. c = get_le16(pb);
  98. if ((q - buf) < buf_size - 1)
  99. *q++ = c;
  100. len--;
  101. }
  102. *q = '\0';
  103. }
  104. #endif
  105. static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size)
  106. {
  107. char* q = buf;
  108. len /= 2;
  109. while (len--) {
  110. uint8_t tmp;
  111. PUT_UTF8(get_le16(pb), tmp, if (q - buf < buf_size - 1) *q++ = tmp;)
  112. }
  113. *q = '\0';
  114. }
  115. static int asf_probe(AVProbeData *pd)
  116. {
  117. /* check file header */
  118. if (!guidcmp(pd->buf, &ff_asf_header))
  119. return AVPROBE_SCORE_MAX;
  120. else
  121. return 0;
  122. }
  123. static int get_value(ByteIOContext *pb, int type){
  124. switch(type){
  125. case 2: return get_le32(pb);
  126. case 3: return get_le32(pb);
  127. case 4: return get_le64(pb);
  128. case 5: return get_le16(pb);
  129. default:return INT_MIN;
  130. }
  131. }
  132. static void get_tag(AVFormatContext *s, const char *key, int type, int len)
  133. {
  134. char value[1024];
  135. if (type <= 1) { // unicode or byte
  136. get_str16_nolen(s->pb, len, value, sizeof(value));
  137. } else if (type <= 5) { // boolean or DWORD or QWORD or WORD
  138. uint64_t num = get_value(s->pb, type);
  139. snprintf(value, sizeof(value), "%"PRIu64, num);
  140. } else {
  141. url_fskip(s->pb, len);
  142. return;
  143. }
  144. if (!strncmp(key, "WM/", 3))
  145. key += 3;
  146. av_metadata_set(&s->metadata, key, value);
  147. }
  148. static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
  149. {
  150. ASFContext *asf = s->priv_data;
  151. ff_asf_guid g;
  152. ByteIOContext *pb = s->pb;
  153. AVStream *st;
  154. ASFStream *asf_st;
  155. int size, i;
  156. int64_t gsize;
  157. AVRational dar[128];
  158. uint32_t bitrate[128];
  159. memset(dar, 0, sizeof(dar));
  160. memset(bitrate, 0, sizeof(bitrate));
  161. get_guid(pb, &g);
  162. if (guidcmp(&g, &ff_asf_header))
  163. return -1;
  164. get_le64(pb);
  165. get_le32(pb);
  166. get_byte(pb);
  167. get_byte(pb);
  168. memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
  169. for(;;) {
  170. get_guid(pb, &g);
  171. gsize = get_le64(pb);
  172. dprintf(s, "%08"PRIx64": ", url_ftell(pb) - 24);
  173. print_guid(&g);
  174. dprintf(s, " size=0x%"PRIx64"\n", gsize);
  175. if (!guidcmp(&g, &ff_asf_data_header)) {
  176. asf->data_object_offset = url_ftell(pb);
  177. // if not streaming, gsize is not unlimited (how?), and there is enough space in the file..
  178. if (!(asf->hdr.flags & 0x01) && gsize >= 100) {
  179. asf->data_object_size = gsize - 24;
  180. } else {
  181. asf->data_object_size = (uint64_t)-1;
  182. }
  183. break;
  184. }
  185. if (gsize < 24)
  186. return -1;
  187. if (!guidcmp(&g, &ff_asf_file_header)) {
  188. get_guid(pb, &asf->hdr.guid);
  189. asf->hdr.file_size = get_le64(pb);
  190. asf->hdr.create_time = get_le64(pb);
  191. asf->nb_packets = get_le64(pb);
  192. asf->hdr.play_time = get_le64(pb);
  193. asf->hdr.send_time = get_le64(pb);
  194. asf->hdr.preroll = get_le32(pb);
  195. asf->hdr.ignore = get_le32(pb);
  196. asf->hdr.flags = get_le32(pb);
  197. asf->hdr.min_pktsize = get_le32(pb);
  198. asf->hdr.max_pktsize = get_le32(pb);
  199. asf->hdr.max_bitrate = get_le32(pb);
  200. asf->packet_size = asf->hdr.max_pktsize;
  201. } else if (!guidcmp(&g, &ff_asf_stream_header)) {
  202. enum CodecType type;
  203. int type_specific_size, sizeX;
  204. uint64_t total_size;
  205. unsigned int tag1;
  206. int64_t pos1, pos2, start_time;
  207. int test_for_ext_stream_audio, is_dvr_ms_audio=0;
  208. pos1 = url_ftell(pb);
  209. st = av_new_stream(s, 0);
  210. if (!st)
  211. return AVERROR(ENOMEM);
  212. av_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
  213. asf_st = av_mallocz(sizeof(ASFStream));
  214. if (!asf_st)
  215. return AVERROR(ENOMEM);
  216. st->priv_data = asf_st;
  217. start_time = asf->hdr.preroll;
  218. if(!(asf->hdr.flags & 0x01)) { // if we aren't streaming...
  219. st->duration = asf->hdr.send_time /
  220. (10000000 / 1000) - start_time;
  221. }
  222. get_guid(pb, &g);
  223. test_for_ext_stream_audio = 0;
  224. if (!guidcmp(&g, &ff_asf_audio_stream)) {
  225. type = CODEC_TYPE_AUDIO;
  226. } else if (!guidcmp(&g, &ff_asf_video_stream)) {
  227. type = CODEC_TYPE_VIDEO;
  228. } else if (!guidcmp(&g, &ff_asf_command_stream)) {
  229. type = CODEC_TYPE_DATA;
  230. } else if (!guidcmp(&g, &ff_asf_ext_stream_embed_stream_header)) {
  231. test_for_ext_stream_audio = 1;
  232. type = CODEC_TYPE_UNKNOWN;
  233. } else {
  234. return -1;
  235. }
  236. get_guid(pb, &g);
  237. total_size = get_le64(pb);
  238. type_specific_size = get_le32(pb);
  239. get_le32(pb);
  240. st->id = get_le16(pb) & 0x7f; /* stream id */
  241. // mapping of asf ID to AV stream ID;
  242. asf->asfid2avid[st->id] = s->nb_streams - 1;
  243. get_le32(pb);
  244. if (test_for_ext_stream_audio) {
  245. get_guid(pb, &g);
  246. if (!guidcmp(&g, &ff_asf_ext_stream_audio_stream)) {
  247. type = CODEC_TYPE_AUDIO;
  248. is_dvr_ms_audio=1;
  249. get_guid(pb, &g);
  250. get_le32(pb);
  251. get_le32(pb);
  252. get_le32(pb);
  253. get_guid(pb, &g);
  254. get_le32(pb);
  255. }
  256. }
  257. st->codec->codec_type = type;
  258. if (type == CODEC_TYPE_AUDIO) {
  259. get_wav_header(pb, st->codec, type_specific_size);
  260. if (is_dvr_ms_audio) {
  261. // codec_id and codec_tag are unreliable in dvr_ms
  262. // files. Set them later by probing stream.
  263. st->codec->codec_id = CODEC_ID_PROBE;
  264. st->codec->codec_tag = 0;
  265. }
  266. if (st->codec->codec_id == CODEC_ID_AAC) {
  267. st->need_parsing = AVSTREAM_PARSE_NONE;
  268. } else {
  269. st->need_parsing = AVSTREAM_PARSE_FULL;
  270. }
  271. /* We have to init the frame size at some point .... */
  272. pos2 = url_ftell(pb);
  273. if (gsize >= (pos2 + 8 - pos1 + 24)) {
  274. asf_st->ds_span = get_byte(pb);
  275. asf_st->ds_packet_size = get_le16(pb);
  276. asf_st->ds_chunk_size = get_le16(pb);
  277. get_le16(pb); //ds_data_size
  278. get_byte(pb); //ds_silence_data
  279. }
  280. //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n",
  281. // asf_st->ds_packet_size, asf_st->ds_chunk_size,
  282. // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data);
  283. if (asf_st->ds_span > 1) {
  284. if (!asf_st->ds_chunk_size
  285. || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1)
  286. || asf_st->ds_packet_size % asf_st->ds_chunk_size)
  287. asf_st->ds_span = 0; // disable descrambling
  288. }
  289. switch (st->codec->codec_id) {
  290. case CODEC_ID_MP3:
  291. st->codec->frame_size = MPA_FRAME_SIZE;
  292. break;
  293. case CODEC_ID_PCM_S16LE:
  294. case CODEC_ID_PCM_S16BE:
  295. case CODEC_ID_PCM_U16LE:
  296. case CODEC_ID_PCM_U16BE:
  297. case CODEC_ID_PCM_S8:
  298. case CODEC_ID_PCM_U8:
  299. case CODEC_ID_PCM_ALAW:
  300. case CODEC_ID_PCM_MULAW:
  301. st->codec->frame_size = 1;
  302. break;
  303. default:
  304. /* This is probably wrong, but it prevents a crash later */
  305. st->codec->frame_size = 1;
  306. break;
  307. }
  308. } else if (type == CODEC_TYPE_VIDEO) {
  309. get_le32(pb);
  310. get_le32(pb);
  311. get_byte(pb);
  312. size = get_le16(pb); /* size */
  313. sizeX= get_le32(pb); /* size */
  314. st->codec->width = get_le32(pb);
  315. st->codec->height = get_le32(pb);
  316. /* not available for asf */
  317. get_le16(pb); /* panes */
  318. st->codec->bits_per_coded_sample = get_le16(pb); /* depth */
  319. tag1 = get_le32(pb);
  320. url_fskip(pb, 20);
  321. // av_log(s, AV_LOG_DEBUG, "size:%d tsize:%d sizeX:%d\n", size, total_size, sizeX);
  322. size= sizeX;
  323. if (size > 40) {
  324. st->codec->extradata_size = size - 40;
  325. st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
  326. get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
  327. }
  328. /* Extract palette from extradata if bpp <= 8 */
  329. /* This code assumes that extradata contains only palette */
  330. /* This is true for all paletted codecs implemented in ffmpeg */
  331. if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) {
  332. st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl));
  333. #ifdef WORDS_BIGENDIAN
  334. for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++)
  335. st->codec->palctrl->palette[i] = bswap_32(((uint32_t*)st->codec->extradata)[i]);
  336. #else
  337. memcpy(st->codec->palctrl->palette, st->codec->extradata,
  338. FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));
  339. #endif
  340. st->codec->palctrl->palette_changed = 1;
  341. }
  342. st->codec->codec_tag = tag1;
  343. st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1);
  344. if(tag1 == MKTAG('D', 'V', 'R', ' '))
  345. st->need_parsing = AVSTREAM_PARSE_FULL;
  346. }
  347. pos2 = url_ftell(pb);
  348. url_fskip(pb, gsize - (pos2 - pos1 + 24));
  349. } else if (!guidcmp(&g, &ff_asf_comment_header)) {
  350. int len1, len2, len3, len4, len5;
  351. len1 = get_le16(pb);
  352. len2 = get_le16(pb);
  353. len3 = get_le16(pb);
  354. len4 = get_le16(pb);
  355. len5 = get_le16(pb);
  356. get_tag(s, "title" , 0, len1);
  357. get_tag(s, "author" , 0, len2);
  358. get_tag(s, "copyright", 0, len3);
  359. get_tag(s, "comment" , 0, len4);
  360. url_fskip(pb, len5);
  361. } else if (!guidcmp(&g, &stream_bitrate_guid)) {
  362. int stream_count = get_le16(pb);
  363. int j;
  364. // av_log(s, AV_LOG_ERROR, "stream bitrate properties\n");
  365. // av_log(s, AV_LOG_ERROR, "streams %d\n", streams);
  366. for(j = 0; j < stream_count; j++) {
  367. int flags, bitrate, stream_id;
  368. flags= get_le16(pb);
  369. bitrate= get_le32(pb);
  370. stream_id= (flags & 0x7f);
  371. // av_log(s, AV_LOG_ERROR, "flags: 0x%x stream id %d, bitrate %d\n", flags, stream_id, bitrate);
  372. asf->stream_bitrates[stream_id]= bitrate;
  373. }
  374. } else if (!guidcmp(&g, &ff_asf_extended_content_header)) {
  375. int desc_count, i;
  376. desc_count = get_le16(pb);
  377. for(i=0;i<desc_count;i++) {
  378. int name_len,value_type,value_len;
  379. char name[1024];
  380. name_len = get_le16(pb);
  381. get_str16_nolen(pb, name_len, name, sizeof(name));
  382. value_type = get_le16(pb);
  383. value_len = get_le16(pb);
  384. get_tag(s, name, value_type, value_len);
  385. }
  386. } else if (!guidcmp(&g, &ff_asf_metadata_header)) {
  387. int n, stream_num, name_len, value_len, value_type, value_num;
  388. n = get_le16(pb);
  389. for(i=0;i<n;i++) {
  390. char name[1024];
  391. get_le16(pb); //lang_list_index
  392. stream_num= get_le16(pb);
  393. name_len= get_le16(pb);
  394. value_type= get_le16(pb);
  395. value_len= get_le32(pb);
  396. get_str16_nolen(pb, name_len, name, sizeof(name));
  397. //av_log(s, AV_LOG_ERROR, "%d %d %d %d %d <%s>\n", i, stream_num, name_len, value_type, value_len, name);
  398. value_num= get_le16(pb);//we should use get_value() here but it does not work 2 is le16 here but le32 elsewhere
  399. url_fskip(pb, value_len - 2);
  400. if(stream_num<128){
  401. if (!strcmp(name, "AspectRatioX")) dar[stream_num].num= value_num;
  402. else if(!strcmp(name, "AspectRatioY")) dar[stream_num].den= value_num;
  403. }
  404. }
  405. } else if (!guidcmp(&g, &ff_asf_ext_stream_header)) {
  406. int ext_len, payload_ext_ct, stream_ct;
  407. uint32_t ext_d, leak_rate, stream_num;
  408. int64_t pos_ex_st;
  409. pos_ex_st = url_ftell(pb);
  410. get_le64(pb); // starttime
  411. get_le64(pb); // endtime
  412. leak_rate = get_le32(pb); // leak-datarate
  413. get_le32(pb); // bucket-datasize
  414. get_le32(pb); // init-bucket-fullness
  415. get_le32(pb); // alt-leak-datarate
  416. get_le32(pb); // alt-bucket-datasize
  417. get_le32(pb); // alt-init-bucket-fullness
  418. get_le32(pb); // max-object-size
  419. get_le32(pb); // flags (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved)
  420. stream_num = get_le16(pb); // stream-num
  421. get_le16(pb); // stream-language-id-index
  422. get_le64(pb); // avg frametime in 100ns units
  423. stream_ct = get_le16(pb); //stream-name-count
  424. payload_ext_ct = get_le16(pb); //payload-extension-system-count
  425. if (stream_num < 128)
  426. bitrate[stream_num] = leak_rate;
  427. for (i=0; i<stream_ct; i++){
  428. get_le16(pb);
  429. ext_len = get_le16(pb);
  430. url_fseek(pb, ext_len, SEEK_CUR);
  431. }
  432. for (i=0; i<payload_ext_ct; i++){
  433. get_guid(pb, &g);
  434. ext_d=get_le16(pb);
  435. ext_len=get_le32(pb);
  436. url_fseek(pb, ext_len, SEEK_CUR);
  437. }
  438. // there could be a optional stream properties object to follow
  439. // if so the next iteration will pick it up
  440. } else if (!guidcmp(&g, &ff_asf_head1_guid)) {
  441. int v1, v2;
  442. get_guid(pb, &g);
  443. v1 = get_le32(pb);
  444. v2 = get_le16(pb);
  445. #if 0
  446. } else if (!guidcmp(&g, &ff_asf_codec_comment_header)) {
  447. int len, v1, n, num;
  448. char str[256], *q;
  449. char tag[16];
  450. get_guid(pb, &g);
  451. print_guid(&g);
  452. n = get_le32(pb);
  453. for(i=0;i<n;i++) {
  454. num = get_le16(pb); /* stream number */
  455. get_str16(pb, str, sizeof(str));
  456. get_str16(pb, str, sizeof(str));
  457. len = get_le16(pb);
  458. q = tag;
  459. while (len > 0) {
  460. v1 = get_byte(pb);
  461. if ((q - tag) < sizeof(tag) - 1)
  462. *q++ = v1;
  463. len--;
  464. }
  465. *q = '\0';
  466. }
  467. #endif
  468. } else if (url_feof(pb)) {
  469. return -1;
  470. } else {
  471. url_fseek(pb, gsize - 24, SEEK_CUR);
  472. }
  473. }
  474. get_guid(pb, &g);
  475. get_le64(pb);
  476. get_byte(pb);
  477. get_byte(pb);
  478. if (url_feof(pb))
  479. return -1;
  480. asf->data_offset = url_ftell(pb);
  481. asf->packet_size_left = 0;
  482. for(i=0; i<128; i++){
  483. int stream_num= asf->asfid2avid[i];
  484. if(stream_num>=0){
  485. AVStream *st = s->streams[stream_num];
  486. if (!st->codec->bit_rate)
  487. st->codec->bit_rate = bitrate[i];
  488. if (dar[i].num > 0 && dar[i].den > 0)
  489. av_reduce(&st->sample_aspect_ratio.num,
  490. &st->sample_aspect_ratio.den,
  491. dar[i].num, dar[i].den, INT_MAX);
  492. //av_log(s, AV_LOG_ERROR, "dar %d:%d sar=%d:%d\n", dar[i].num, dar[i].den, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
  493. }
  494. }
  495. return 0;
  496. }
  497. #define DO_2BITS(bits, var, defval) \
  498. switch (bits & 3) \
  499. { \
  500. case 3: var = get_le32(pb); rsize += 4; break; \
  501. case 2: var = get_le16(pb); rsize += 2; break; \
  502. case 1: var = get_byte(pb); rsize++; break; \
  503. default: var = defval; break; \
  504. }
  505. int ff_asf_get_packet(AVFormatContext *s, ByteIOContext *pb)
  506. {
  507. ASFContext *asf = s->priv_data;
  508. uint32_t packet_length, padsize;
  509. int rsize = 8;
  510. int c, d, e, off;
  511. off= (url_ftell(pb) - s->data_offset) % asf->packet_size + 3;
  512. c=d=e=-1;
  513. while(off-- > 0){
  514. c=d; d=e;
  515. e= get_byte(pb);
  516. if(c == 0x82 && !d && !e)
  517. break;
  518. }
  519. if (c != 0x82) {
  520. if (!url_feof(pb))
  521. av_log(s, AV_LOG_ERROR, "ff asf bad header %x at:%"PRId64"\n", c, url_ftell(pb));
  522. }
  523. if ((c & 0x8f) == 0x82) {
  524. if (d || e) {
  525. if (!url_feof(pb))
  526. av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n");
  527. return -1;
  528. }
  529. c= get_byte(pb);
  530. d= get_byte(pb);
  531. rsize+=3;
  532. }else{
  533. url_fseek(pb, -1, SEEK_CUR); //FIXME
  534. }
  535. asf->packet_flags = c;
  536. asf->packet_property = d;
  537. DO_2BITS(asf->packet_flags >> 5, packet_length, asf->packet_size);
  538. DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
  539. DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
  540. //the following checks prevent overflows and infinite loops
  541. if(packet_length >= (1U<<29)){
  542. av_log(s, AV_LOG_ERROR, "invalid packet_length %d at:%"PRId64"\n", packet_length, url_ftell(pb));
  543. return -1;
  544. }
  545. if(padsize >= packet_length){
  546. av_log(s, AV_LOG_ERROR, "invalid padsize %d at:%"PRId64"\n", padsize, url_ftell(pb));
  547. return -1;
  548. }
  549. asf->packet_timestamp = get_le32(pb);
  550. get_le16(pb); /* duration */
  551. // rsize has at least 11 bytes which have to be present
  552. if (asf->packet_flags & 0x01) {
  553. asf->packet_segsizetype = get_byte(pb); rsize++;
  554. asf->packet_segments = asf->packet_segsizetype & 0x3f;
  555. } else {
  556. asf->packet_segments = 1;
  557. asf->packet_segsizetype = 0x80;
  558. }
  559. asf->packet_size_left = packet_length - padsize - rsize;
  560. if (packet_length < asf->hdr.min_pktsize)
  561. padsize += asf->hdr.min_pktsize - packet_length;
  562. asf->packet_padsize = padsize;
  563. dprintf(s, "packet: size=%d padsize=%d left=%d\n", asf->packet_size, asf->packet_padsize, asf->packet_size_left);
  564. return 0;
  565. }
  566. /**
  567. *
  568. * @return <0 if error
  569. */
  570. static int asf_read_frame_header(AVFormatContext *s, ByteIOContext *pb){
  571. ASFContext *asf = s->priv_data;
  572. int rsize = 1;
  573. int num = get_byte(pb);
  574. int64_t ts0, ts1;
  575. asf->packet_segments--;
  576. asf->packet_key_frame = num >> 7;
  577. asf->stream_index = asf->asfid2avid[num & 0x7f];
  578. // sequence should be ignored!
  579. DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
  580. DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
  581. DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
  582. //printf("key:%d stream:%d seq:%d offset:%d replic_size:%d\n", asf->packet_key_frame, asf->stream_index, asf->packet_seq, //asf->packet_frag_offset, asf->packet_replic_size);
  583. if (asf->packet_replic_size >= 8) {
  584. asf->packet_obj_size = get_le32(pb);
  585. if(asf->packet_obj_size >= (1<<24) || asf->packet_obj_size <= 0){
  586. av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n");
  587. return -1;
  588. }
  589. asf->packet_frag_timestamp = get_le32(pb); // timestamp
  590. if(asf->packet_replic_size >= 8+38+4){
  591. // for(i=0; i<asf->packet_replic_size-8; i++)
  592. // av_log(s, AV_LOG_DEBUG, "%02X ",get_byte(pb));
  593. // av_log(s, AV_LOG_DEBUG, "\n");
  594. url_fskip(pb, 10);
  595. ts0= get_le64(pb);
  596. ts1= get_le64(pb);
  597. url_fskip(pb, 12);
  598. get_le32(pb);
  599. url_fskip(pb, asf->packet_replic_size - 8 - 38 - 4);
  600. if(ts0!= -1) asf->packet_frag_timestamp= ts0/10000;
  601. else asf->packet_frag_timestamp= AV_NOPTS_VALUE;
  602. }else
  603. url_fskip(pb, asf->packet_replic_size - 8);
  604. rsize += asf->packet_replic_size; // FIXME - check validity
  605. } else if (asf->packet_replic_size==1){
  606. // multipacket - frag_offset is beginning timestamp
  607. asf->packet_time_start = asf->packet_frag_offset;
  608. asf->packet_frag_offset = 0;
  609. asf->packet_frag_timestamp = asf->packet_timestamp;
  610. asf->packet_time_delta = get_byte(pb);
  611. rsize++;
  612. }else if(asf->packet_replic_size!=0){
  613. av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n", asf->packet_replic_size);
  614. return -1;
  615. }
  616. if (asf->packet_flags & 0x01) {
  617. DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
  618. if(asf->packet_frag_size > asf->packet_size_left - rsize){
  619. av_log(s, AV_LOG_ERROR, "packet_frag_size is invalid\n");
  620. return -1;
  621. }
  622. //printf("Fragsize %d\n", asf->packet_frag_size);
  623. } else {
  624. asf->packet_frag_size = asf->packet_size_left - rsize;
  625. //printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
  626. }
  627. if (asf->packet_replic_size == 1) {
  628. asf->packet_multi_size = asf->packet_frag_size;
  629. if (asf->packet_multi_size > asf->packet_size_left)
  630. return -1;
  631. }
  632. asf->packet_size_left -= rsize;
  633. //printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
  634. return 0;
  635. }
  636. int ff_asf_parse_packet(AVFormatContext *s, ByteIOContext *pb, AVPacket *pkt)
  637. {
  638. ASFContext *asf = s->priv_data;
  639. ASFStream *asf_st = 0;
  640. for (;;) {
  641. if(url_feof(pb))
  642. return AVERROR(EIO);
  643. if (asf->packet_size_left < FRAME_HEADER_SIZE
  644. || asf->packet_segments < 1) {
  645. //asf->packet_size_left <= asf->packet_padsize) {
  646. int ret = asf->packet_size_left + asf->packet_padsize;
  647. //printf("PacketLeftSize:%d Pad:%d Pos:%"PRId64"\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb));
  648. assert(ret>=0);
  649. /* fail safe */
  650. url_fskip(pb, ret);
  651. asf->packet_pos= url_ftell(pb);
  652. if (asf->data_object_size != (uint64_t)-1 &&
  653. (asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
  654. return AVERROR(EIO); /* Do not exceed the size of the data object */
  655. return 1;
  656. }
  657. if (asf->packet_time_start == 0) {
  658. if(asf_read_frame_header(s, pb) < 0){
  659. asf->packet_segments= 0;
  660. continue;
  661. }
  662. if (asf->stream_index < 0
  663. || s->streams[asf->stream_index]->discard >= AVDISCARD_ALL
  664. || (!asf->packet_key_frame && s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)
  665. ) {
  666. asf->packet_time_start = 0;
  667. /* unhandled packet (should not happen) */
  668. url_fskip(pb, asf->packet_frag_size);
  669. asf->packet_size_left -= asf->packet_frag_size;
  670. if(asf->stream_index < 0)
  671. av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n", asf->packet_frag_size);
  672. continue;
  673. }
  674. asf->asf_st = s->streams[asf->stream_index]->priv_data;
  675. }
  676. asf_st = asf->asf_st;
  677. if (asf->packet_replic_size == 1) {
  678. // frag_offset is here used as the beginning timestamp
  679. asf->packet_frag_timestamp = asf->packet_time_start;
  680. asf->packet_time_start += asf->packet_time_delta;
  681. asf->packet_obj_size = asf->packet_frag_size = get_byte(pb);
  682. asf->packet_size_left--;
  683. asf->packet_multi_size--;
  684. if (asf->packet_multi_size < asf->packet_obj_size)
  685. {
  686. asf->packet_time_start = 0;
  687. url_fskip(pb, asf->packet_multi_size);
  688. asf->packet_size_left -= asf->packet_multi_size;
  689. continue;
  690. }
  691. asf->packet_multi_size -= asf->packet_obj_size;
  692. //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);
  693. }
  694. if( /*asf->packet_frag_size == asf->packet_obj_size*/
  695. asf_st->frag_offset + asf->packet_frag_size <= asf_st->pkt.size
  696. && asf_st->frag_offset + asf->packet_frag_size > asf->packet_obj_size){
  697. av_log(s, AV_LOG_INFO, "ignoring invalid packet_obj_size (%d %d %d %d)\n",
  698. asf_st->frag_offset, asf->packet_frag_size,
  699. asf->packet_obj_size, asf_st->pkt.size);
  700. asf->packet_obj_size= asf_st->pkt.size;
  701. }
  702. if ( asf_st->pkt.size != asf->packet_obj_size
  703. || asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) { //FIXME is this condition sufficient?
  704. if(asf_st->pkt.data){
  705. av_log(s, AV_LOG_INFO, "freeing incomplete packet size %d, new %d\n", asf_st->pkt.size, asf->packet_obj_size);
  706. asf_st->frag_offset = 0;
  707. av_free_packet(&asf_st->pkt);
  708. }
  709. /* new packet */
  710. av_new_packet(&asf_st->pkt, asf->packet_obj_size);
  711. asf_st->seq = asf->packet_seq;
  712. asf_st->pkt.dts = asf->packet_frag_timestamp;
  713. asf_st->pkt.stream_index = asf->stream_index;
  714. asf_st->pkt.pos =
  715. asf_st->packet_pos= asf->packet_pos;
  716. //printf("new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n",
  717. //asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & PKT_FLAG_KEY,
  718. //s->streams[asf->stream_index]->codec->codec_type == CODEC_TYPE_AUDIO, asf->packet_obj_size);
  719. if (s->streams[asf->stream_index]->codec->codec_type == CODEC_TYPE_AUDIO)
  720. asf->packet_key_frame = 1;
  721. if (asf->packet_key_frame)
  722. asf_st->pkt.flags |= PKT_FLAG_KEY;
  723. }
  724. /* read data */
  725. //printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
  726. // asf->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
  727. // asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
  728. asf->packet_size_left -= asf->packet_frag_size;
  729. if (asf->packet_size_left < 0)
  730. continue;
  731. if( asf->packet_frag_offset >= asf_st->pkt.size
  732. || asf->packet_frag_size > asf_st->pkt.size - asf->packet_frag_offset){
  733. av_log(s, AV_LOG_ERROR, "packet fragment position invalid %u,%u not in %u\n",
  734. asf->packet_frag_offset, asf->packet_frag_size, asf_st->pkt.size);
  735. continue;
  736. }
  737. get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
  738. asf->packet_frag_size);
  739. if (s->key && s->keylen == 20)
  740. ff_asfcrypt_dec(s->key, asf_st->pkt.data + asf->packet_frag_offset,
  741. asf->packet_frag_size);
  742. asf_st->frag_offset += asf->packet_frag_size;
  743. /* test if whole packet is read */
  744. if (asf_st->frag_offset == asf_st->pkt.size) {
  745. //workaround for macroshit radio DVR-MS files
  746. if( s->streams[asf->stream_index]->codec->codec_id == CODEC_ID_MPEG2VIDEO
  747. && asf_st->pkt.size > 100){
  748. int i;
  749. for(i=0; i<asf_st->pkt.size && !asf_st->pkt.data[i]; i++);
  750. if(i == asf_st->pkt.size){
  751. av_log(s, AV_LOG_DEBUG, "discarding ms fart\n");
  752. asf_st->frag_offset = 0;
  753. av_free_packet(&asf_st->pkt);
  754. continue;
  755. }
  756. }
  757. /* return packet */
  758. if (asf_st->ds_span > 1) {
  759. if(asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span){
  760. av_log(s, AV_LOG_ERROR, "pkt.size != ds_packet_size * ds_span (%d %d %d)\n", asf_st->pkt.size, asf_st->ds_packet_size, asf_st->ds_span);
  761. }else{
  762. /* packet descrambling */
  763. uint8_t *newdata = av_malloc(asf_st->pkt.size);
  764. if (newdata) {
  765. int offset = 0;
  766. while (offset < asf_st->pkt.size) {
  767. int off = offset / asf_st->ds_chunk_size;
  768. int row = off / asf_st->ds_span;
  769. int col = off % asf_st->ds_span;
  770. int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
  771. //printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx);
  772. assert(offset + asf_st->ds_chunk_size <= asf_st->pkt.size);
  773. assert(idx+1 <= asf_st->pkt.size / asf_st->ds_chunk_size);
  774. memcpy(newdata + offset,
  775. asf_st->pkt.data + idx * asf_st->ds_chunk_size,
  776. asf_st->ds_chunk_size);
  777. offset += asf_st->ds_chunk_size;
  778. }
  779. av_free(asf_st->pkt.data);
  780. asf_st->pkt.data = newdata;
  781. }
  782. }
  783. }
  784. asf_st->frag_offset = 0;
  785. *pkt= asf_st->pkt;
  786. //printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size);
  787. asf_st->pkt.size = 0;
  788. asf_st->pkt.data = 0;
  789. break; // packet completed
  790. }
  791. }
  792. return 0;
  793. }
  794. static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
  795. {
  796. ASFContext *asf = s->priv_data;
  797. for (;;) {
  798. int ret;
  799. /* parse cached packets, if any */
  800. if ((ret = ff_asf_parse_packet(s, s->pb, pkt)) <= 0)
  801. return ret;
  802. if ((ret = ff_asf_get_packet(s, s->pb)) < 0)
  803. assert(asf->packet_size_left < FRAME_HEADER_SIZE || asf->packet_segments < 1);
  804. asf->packet_time_start = 0;
  805. }
  806. return 0;
  807. }
  808. // Added to support seeking after packets have been read
  809. // If information is not reset, read_packet fails due to
  810. // leftover information from previous reads
  811. static void asf_reset_header(AVFormatContext *s)
  812. {
  813. ASFContext *asf = s->priv_data;
  814. ASFStream *asf_st;
  815. int i;
  816. asf->packet_nb_frames = 0;
  817. asf->packet_size_left = 0;
  818. asf->packet_segments = 0;
  819. asf->packet_flags = 0;
  820. asf->packet_property = 0;
  821. asf->packet_timestamp = 0;
  822. asf->packet_segsizetype = 0;
  823. asf->packet_segments = 0;
  824. asf->packet_seq = 0;
  825. asf->packet_replic_size = 0;
  826. asf->packet_key_frame = 0;
  827. asf->packet_padsize = 0;
  828. asf->packet_frag_offset = 0;
  829. asf->packet_frag_size = 0;
  830. asf->packet_frag_timestamp = 0;
  831. asf->packet_multi_size = 0;
  832. asf->packet_obj_size = 0;
  833. asf->packet_time_delta = 0;
  834. asf->packet_time_start = 0;
  835. for(i=0; i<s->nb_streams; i++){
  836. asf_st= s->streams[i]->priv_data;
  837. av_free_packet(&asf_st->pkt);
  838. asf_st->frag_offset=0;
  839. asf_st->seq=0;
  840. }
  841. asf->asf_st= NULL;
  842. }
  843. static int asf_read_close(AVFormatContext *s)
  844. {
  845. int i;
  846. asf_reset_header(s);
  847. for(i=0;i<s->nb_streams;i++) {
  848. AVStream *st = s->streams[i];
  849. av_free(st->codec->palctrl);
  850. }
  851. return 0;
  852. }
  853. static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
  854. {
  855. ASFContext *asf = s->priv_data;
  856. AVPacket pkt1, *pkt = &pkt1;
  857. ASFStream *asf_st;
  858. int64_t pts;
  859. int64_t pos= *ppos;
  860. int i;
  861. int64_t start_pos[s->nb_streams];
  862. for(i=0; i<s->nb_streams; i++){
  863. start_pos[i]= pos;
  864. }
  865. pos= (pos+asf->packet_size-1-s->data_offset)/asf->packet_size*asf->packet_size+ s->data_offset;
  866. *ppos= pos;
  867. url_fseek(s->pb, pos, SEEK_SET);
  868. //printf("asf_read_pts\n");
  869. asf_reset_header(s);
  870. for(;;){
  871. if (av_read_frame(s, pkt) < 0){
  872. av_log(s, AV_LOG_INFO, "asf_read_pts failed\n");
  873. return AV_NOPTS_VALUE;
  874. }
  875. pts= pkt->pts;
  876. av_free_packet(pkt);
  877. if(pkt->flags&PKT_FLAG_KEY){
  878. i= pkt->stream_index;
  879. asf_st= s->streams[i]->priv_data;
  880. // assert((asf_st->packet_pos - s->data_offset) % asf->packet_size == 0);
  881. pos= asf_st->packet_pos;
  882. av_add_index_entry(s->streams[i], pos, pts, pkt->size, pos - start_pos[i] + 1, AVINDEX_KEYFRAME);
  883. start_pos[i]= asf_st->packet_pos + 1;
  884. if(pkt->stream_index == stream_index)
  885. break;
  886. }
  887. }
  888. *ppos= pos;
  889. //printf("found keyframe at %"PRId64" stream %d stamp:%"PRId64"\n", *ppos, stream_index, pts);
  890. return pts;
  891. }
  892. static void asf_build_simple_index(AVFormatContext *s, int stream_index)
  893. {
  894. ff_asf_guid g;
  895. ASFContext *asf = s->priv_data;
  896. int64_t gsize, itime;
  897. int64_t pos, current_pos, index_pts;
  898. int i;
  899. int pct,ict;
  900. current_pos = url_ftell(s->pb);
  901. url_fseek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET);
  902. get_guid(s->pb, &g);
  903. if (!guidcmp(&g, &index_guid)) {
  904. gsize = get_le64(s->pb);
  905. get_guid(s->pb, &g);
  906. itime=get_le64(s->pb);
  907. pct=get_le32(s->pb);
  908. ict=get_le32(s->pb);
  909. av_log(s, AV_LOG_DEBUG, "itime:0x%"PRIx64", pct:%d, ict:%d\n",itime,pct,ict);
  910. for (i=0;i<ict;i++){
  911. int pktnum=get_le32(s->pb);
  912. int pktct =get_le16(s->pb);
  913. av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d\n", pktnum, pktct);
  914. pos=s->data_offset + asf->packet_size*(int64_t)pktnum;
  915. index_pts=av_rescale(itime, i, 10000);
  916. av_add_index_entry(s->streams[stream_index], pos, index_pts, asf->packet_size, 0, AVINDEX_KEYFRAME);
  917. }
  918. asf->index_read= 1;
  919. }
  920. url_fseek(s->pb, current_pos, SEEK_SET);
  921. }
  922. static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
  923. {
  924. ASFContext *asf = s->priv_data;
  925. AVStream *st = s->streams[stream_index];
  926. int64_t pos;
  927. int index;
  928. if (asf->packet_size <= 0)
  929. return -1;
  930. /* Try using the protocol's read_seek if available */
  931. if(s->pb) {
  932. int ret = av_url_read_fseek(s->pb, stream_index, pts, flags);
  933. if(ret >= 0)
  934. asf_reset_header(s);
  935. if (ret != AVERROR(ENOSYS))
  936. return ret;
  937. }
  938. if (!asf->index_read)
  939. asf_build_simple_index(s, stream_index);
  940. if(!(asf->index_read && st->index_entries)){
  941. if(av_seek_frame_binary(s, stream_index, pts, flags)<0)
  942. return -1;
  943. }else{
  944. index= av_index_search_timestamp(st, pts, flags);
  945. if(index<0)
  946. return -1;
  947. /* find the position */
  948. pos = st->index_entries[index].pos;
  949. pts = st->index_entries[index].timestamp;
  950. // various attempts to find key frame have failed so far
  951. // asf_reset_header(s);
  952. // url_fseek(s->pb, pos, SEEK_SET);
  953. // key_pos = pos;
  954. // for(i=0;i<16;i++){
  955. // pos = url_ftell(s->pb);
  956. // if (av_read_frame(s, &pkt) < 0){
  957. // av_log(s, AV_LOG_INFO, "seek failed\n");
  958. // return -1;
  959. // }
  960. // asf_st = s->streams[stream_index]->priv_data;
  961. // pos += st->parser->frame_offset;
  962. //
  963. // if (pkt.size > b) {
  964. // b = pkt.size;
  965. // key_pos = pos;
  966. // }
  967. //
  968. // av_free_packet(&pkt);
  969. // }
  970. /* do the seek */
  971. av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos);
  972. url_fseek(s->pb, pos, SEEK_SET);
  973. }
  974. asf_reset_header(s);
  975. return 0;
  976. }
  977. AVInputFormat asf_demuxer = {
  978. "asf",
  979. NULL_IF_CONFIG_SMALL("ASF format"),
  980. sizeof(ASFContext),
  981. asf_probe,
  982. asf_read_header,
  983. asf_read_packet,
  984. asf_read_close,
  985. asf_read_seek,
  986. asf_read_pts,
  987. .metadata_conv = ff_asf_metadata_conv,
  988. };