codecs.conf: Use fourcc instead of format where appropriate
[mplayer/greg.git] / libmpdemux / demux_asf.c
blobaef2f5ece05800026bad4656d4d7f7533516049b
1 /*
2 * ASF file parser for DEMUXER v0.3
3 * copyright (c) 2001 A'rpi/ESP-team
5 * This file is part of MPlayer.
7 * MPlayer is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * MPlayer 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
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <limits.h>
27 #include "config.h"
28 #include "mp_msg.h"
30 #include "stream/stream.h"
31 #include "asf.h"
32 #include "asfheader.h"
33 #include "demuxer.h"
34 #include "libmpcodecs/dec_audio.h"
35 #include "libvo/fastmemcpy.h"
36 #include "ffmpeg_files/intreadwrite.h"
38 // based on asf file-format doc by Eugene [http://divx.euro.ru]
40 /**
41 * \brief reads int stored in number of bytes given by len
42 * \param ptr pointer to read from, is incremented appropriately
43 * \param len lowest 2 bits indicate number of bytes to read
44 * \param def default value to return if len is invalid
46 static inline unsigned read_varlen(uint8_t **ptr, int len, int def) {
47 const uint8_t *p = *ptr;
48 len &= 3;
49 switch (len) {
50 case 1: *ptr += 1; return *p;
51 case 2: *ptr += 2; return AV_RL16(p);
52 case 3: *ptr += 4; return AV_RL32(p);
54 return def;
57 /**
58 * \brief checks if there is enough data to read the bytes given by len
59 * \param ptr pointer to read from
60 * \param endptr pointer to the end of the buffer
61 * \param len lowest 2 bits indicate number of bytes to read
63 static inline int check_varlen(uint8_t *ptr, uint8_t *endptr, int len) {
64 return len&3 ? ptr + (1<<((len&3) - 1)) <= endptr : 1;
67 static void asf_descrambling(unsigned char **src,unsigned len, struct asf_priv* asf){
68 unsigned char *dst;
69 unsigned char *s2=*src;
70 unsigned i=0,x,y;
71 if (len > UINT_MAX - MP_INPUT_BUFFER_PADDING_SIZE)
72 return;
73 dst = malloc(len + MP_INPUT_BUFFER_PADDING_SIZE);
74 while(len>=asf->scrambling_h*asf->scrambling_w*asf->scrambling_b+i){
75 // mp_msg(MSGT_DEMUX,MSGL_DBG4,"descrambling! (w=%d b=%d)\n",w,asf_scrambling_b);
76 //i+=asf_scrambling_h*asf_scrambling_w;
77 for(x=0;x<asf->scrambling_w;x++)
78 for(y=0;y<asf->scrambling_h;y++){
79 fast_memcpy(dst+i,s2+(y*asf->scrambling_w+x)*asf->scrambling_b,asf->scrambling_b);
80 i+=asf->scrambling_b;
82 s2+=asf->scrambling_h*asf->scrambling_w*asf->scrambling_b;
84 //if(i<len) fast_memcpy(dst+i,src+i,len-i);
85 free(*src);
86 *src = dst;
89 /*****************************************************************
90 * \brief initializes asf private data
93 static void init_priv (struct asf_priv* asf){
94 asf->last_vid_seq=-1;
95 asf->vid_ext_timing_index=-1;
96 asf->aud_ext_timing_index=-1;
97 asf->vid_ext_frame_index=-1;
100 static void demux_asf_append_to_packet(demux_packet_t* dp,unsigned char *data,int len,int offs)
102 if(dp->len!=offs && offs!=-1) mp_msg(MSGT_DEMUX,MSGL_V,"warning! fragment.len=%d BUT next fragment offset=%d \n",dp->len,offs);
103 dp->buffer=realloc(dp->buffer,dp->len+len+MP_INPUT_BUFFER_PADDING_SIZE);
104 fast_memcpy(dp->buffer+dp->len,data,len);
105 memset(dp->buffer+dp->len+len, 0, MP_INPUT_BUFFER_PADDING_SIZE);
106 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len);
107 dp->len+=len;
110 static int demux_asf_read_packet(demuxer_t *demux,unsigned char *data,int len,int id,int seq,uint64_t time,unsigned short dur,int offs,int keyframe){
111 struct asf_priv* asf = demux->priv;
112 demux_stream_t *ds=NULL;
113 int close_seg=0;
115 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"demux_asf.read_packet: id=%d seq=%d len=%d\n",id,seq,len);
117 if(demux->video->id==-1)
118 if(demux->v_streams[id])
119 demux->video->id=id;
121 if(demux->audio->id==-1)
122 if(demux->a_streams[id])
123 demux->audio->id=id;
125 if(id==demux->audio->id){
126 // audio
127 ds=demux->audio;
128 if(!ds->sh){
129 ds->sh=demux->a_streams[id];
130 mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected ASF audio ID = %d\n",ds->id);
132 } else
133 if(id==demux->video->id){
134 // video
135 ds=demux->video;
136 if(!ds->sh){
137 ds->sh=demux->v_streams[id];
138 mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected ASF video ID = %d\n",ds->id);
142 if(ds){
143 if(ds->asf_packet){
144 demux_packet_t* dp=ds->asf_packet;
146 if (ds==demux->video && asf->asf_is_dvr_ms) {
147 if (asf->new_vid_frame_seg) {
148 dp->pos=demux->filepos;
149 close_seg = 1;
150 } else seq = ds->asf_seq;
151 } else close_seg = ds->asf_seq!=seq;
153 if(close_seg){
154 // closed segment, finalize packet:
155 if(ds==demux->audio)
156 if(asf->scrambling_h>1 && asf->scrambling_w>1 && asf->scrambling_b>0)
157 asf_descrambling(&ds->asf_packet->buffer,ds->asf_packet->len,asf);
158 ds_add_packet(ds,ds->asf_packet);
159 ds->asf_packet=NULL;
160 } else {
161 // append data to it!
162 demux_asf_append_to_packet(dp,data,len,offs);
163 // we are ready now.
164 return 1;
167 // create new packet:
168 { demux_packet_t* dp;
169 if(offs>0){
170 mp_msg(MSGT_DEMUX,MSGL_V,"warning! broken fragment, %d bytes missing \n",offs);
171 return 0;
173 dp=new_demux_packet(len);
174 fast_memcpy(dp->buffer,data,len);
175 if (asf->asf_is_dvr_ms)
176 dp->pts=time*0.0000001;
177 else
178 dp->pts=time*0.001;
179 dp->flags=keyframe;
180 // if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur);
181 dp->pos=demux->filepos;
182 ds->asf_packet=dp;
183 ds->asf_seq=seq;
184 // we are ready now.
185 return 1;
189 return 0;
192 /*****************************************************************
193 * \brief read the replicated data associated with each segment
194 * \parameter pp reference to replicated data
195 * \parameter id stream number
196 * \parameter seq media object number
197 * \parameter keyframe key frame indicator - set to zero if keyframe, non-zero otherwise
198 * \parameter seg_time set to payload time when valid, if audio or new video frame payload, zero otherwise
201 static void get_payload_extension_data(demuxer_t *demux, unsigned char** pp, unsigned char id, unsigned int seq, int *keyframe, uint64_t *seg_time){
202 struct asf_priv* asf = demux->priv;
203 uint64_t payload_time; //100ns units
204 int i, ext_max, ext_timing_index;
205 uint8_t *pi = *pp+4;
207 if(demux->video->id==-1)
208 if(demux->v_streams[id])
209 demux->video->id=id;
211 if(demux->audio->id==-1)
212 if(demux->a_streams[id])
213 demux->audio->id=id;
215 if (id!=demux->video->id && id!=demux->audio->id) return;
217 if (id==demux->video->id) {
218 ext_max = asf->vid_repdata_count;
219 ext_timing_index = asf->vid_ext_timing_index;
220 } else {
221 ext_max = asf->aud_repdata_count;
222 ext_timing_index = asf->aud_ext_timing_index;
225 *seg_time=0.0;
226 asf->new_vid_frame_seg = 0;
228 for (i=0; i<ext_max; i++) {
229 uint16_t payextsize;
230 uint8_t segment_marker;
232 if (id==demux->video->id)
233 payextsize = asf->vid_repdata_sizes[i];
234 else
235 payextsize = asf->aud_repdata_sizes[i];
237 if (payextsize == 65535) {
238 payextsize = AV_RL16(pi);
239 pi+=2;
242 // if this is the timing info extension then read the payload time
243 if (i == ext_timing_index)
244 payload_time = AV_RL64(pi+8);
246 // if this is the video frame info extension then
247 // set the keyframe indicator, the 'new frame segment' indicator
248 // and (initially) the 'frame time'
249 if (i == asf->vid_ext_frame_index && id==demux->video->id) {
250 segment_marker = pi[0];
251 // Known video stream segment_marker values that
252 // contain useful information:
254 // NTSC/ATSC (29.97fps): 0X4A 01001010
255 // 0X4B 01001011
256 // 0X49 01001001
258 // PAL/ATSC (25fps): 0X3A 00111010
259 // 0X3B 00111011
260 // 0X39 00111001
262 // ATSC progressive (29.97fps): 0X7A 01111010
263 // 0X7B 01111011
264 // 0X79 01111001
265 // 11111111
266 // ^ this is new video frame marker
268 // ^^^^ these bits indicate the framerate
269 // 0X4 is 29.97i, 0X3 is 25i, 0X7 is 29.97p, ???=25p
271 // ^^^ these bits indicate the frame type:
272 // 001 means I-frame
273 // 010 and 011 probably mean P and B
275 asf->new_vid_frame_seg = (0X08 & segment_marker) && seq != asf->last_vid_seq;
277 if (asf->new_vid_frame_seg) asf->last_vid_seq = seq;
279 if (asf->avg_vid_frame_time == 0) {
280 // set the average frame time initially (in 100ns units).
281 // This is based on what works for known samples.
282 // It can be extended if more samples of different types can be obtained.
283 if (((segment_marker & 0XF0) >> 4) == 4) {
284 asf->avg_vid_frame_time = (uint64_t)((1.001 / 30.0) * 10000000.0);
285 asf->know_frame_time=1;
286 } else if (((segment_marker & 0XF0) >> 4) == 3) {
287 asf->avg_vid_frame_time = (uint64_t)(0.04 * 10000000.0);
288 asf->know_frame_time=1;
289 } else if (((segment_marker & 0XF0) >> 4) == 6) {
290 asf->avg_vid_frame_time = (uint64_t)(0.02 * 10000000.0);
291 asf->know_frame_time=1;
292 } else if (((segment_marker & 0XF0) >> 4) == 7) {
293 asf->avg_vid_frame_time = (uint64_t)((1.001 / 60.0) * 10000000.0);
294 asf->know_frame_time=1;
295 } else {
296 // we dont know the frame time initially so
297 // make a guess and then recalculate as we go.
298 asf->avg_vid_frame_time = (uint64_t)((1.001 / 60.0) * 10000000.0);
299 asf->know_frame_time=0;
302 *keyframe = (asf->new_vid_frame_seg && (segment_marker & 0X07) == 1);
304 pi +=payextsize;
307 if (id==demux->video->id && asf->new_vid_frame_seg) {
308 asf->vid_frame_ct++;
309 // Some samples only have timings on key frames and
310 // the rest contain non-cronological timestamps. Interpolating
311 // the values between key frames works for all samples.
312 if (*keyframe) {
313 asf->found_first_key_frame=1;
314 if (!asf->know_frame_time && asf->last_key_payload_time > 0) {
315 // We dont know average frametime so recalculate.
316 // Giving precedence to the 'weight' of the existing
317 // average limits damage done to new value when there is
318 // a sudden time jump which happens occasionally.
319 asf->avg_vid_frame_time =
320 (0.9 * asf->avg_vid_frame_time) +
321 (0.1 * ((payload_time - asf->last_key_payload_time) / asf->vid_frame_ct));
323 asf->last_key_payload_time = payload_time;
324 asf->vid_frame_ct = 1;
325 *seg_time = payload_time;
326 } else
327 *seg_time = (asf->last_key_payload_time + (asf->avg_vid_frame_time * (asf->vid_frame_ct-1)));
330 if (id==demux->audio->id) {
331 if (payload_time != -1)
332 asf->last_aud_diff = payload_time - asf->last_aud_pts;
333 asf->last_aud_pts += asf->last_aud_diff;
334 *seg_time = asf->last_aud_pts;
337 //static int num_elementary_packets100=0;
338 //static int num_elementary_packets101=0;
340 // return value:
341 // 0 = EOF or no stream found
342 // 1 = successfully read a packet
343 static int demux_asf_fill_buffer(demuxer_t *demux, demux_stream_t *ds){
344 struct asf_priv* asf = demux->priv;
346 demux->filepos=stream_tell(demux->stream);
347 // Brodcast stream have movi_start==movi_end
348 // Better test ?
349 if((demux->movi_start < demux->movi_end) && (demux->filepos>=demux->movi_end)){
350 demux->stream->eof=1;
351 return 0;
354 stream_read(demux->stream,asf->packet,asf->packetsize);
355 if(demux->stream->eof) return 0; // EOF
356 if(asf->packetsize < 2) return 0; // Packet too short
359 unsigned char* p=asf->packet;
360 unsigned char* p_end=asf->packet+asf->packetsize;
361 unsigned char flags=p[0];
362 unsigned char segtype=p[1];
363 unsigned padding;
364 unsigned plen;
365 unsigned sequence;
366 unsigned long time=0;
367 unsigned short duration=0;
369 int segs=1;
370 unsigned char segsizetype=0x80;
371 int seg=-1;
373 if( mp_msg_test(MSGT_DEMUX,MSGL_DBG2) ){
374 int i;
375 for(i=0;i<FFMIN(16, asf->packetsize);i++) printf(" %02X",asf->packet[i]);
376 printf("\n");
379 // skip ECC data if present by testing bit 7 of flags
380 // 1xxxbbbb -> ecc data present, skip bbbb byte(s)
381 // 0xxxxxxx -> payload parsing info starts
382 if (flags & 0x80)
384 p += (flags & 0x0f)+1;
385 if (p+1 >= p_end) return 0; // Packet too short
386 flags = p[0];
387 segtype = p[1];
390 //if(segtype!=0x5d) printf("Warning! packet[4] != 0x5d \n");
392 p+=2; // skip flags & segtype
394 // Read packet size (plen):
395 if(!check_varlen(p, p_end, flags>> 5)) return 0; // Not enough data
396 plen = read_varlen(&p, flags >> 5, 0);
398 // Read sequence:
399 if(!check_varlen(p, p_end, flags>> 1)) return 0; // Not enough data
400 sequence = read_varlen(&p, flags >> 1, 0);
402 // Read padding size (padding):
403 if(!check_varlen(p, p_end, flags>> 3)) return 0; // Not enough data
404 padding = read_varlen(&p, flags >> 3, 0);
406 if(((flags>>5)&3)!=0){
407 // Explicit (absoulte) packet size
408 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Explicit packet size specified: %d \n",plen);
409 if(plen>asf->packetsize) mp_msg(MSGT_DEMUX,MSGL_V,"Warning! plen>packetsize! (%d>%d) \n",plen,asf->packetsize);
410 } else {
411 // Padding (relative) size
412 plen=asf->packetsize-padding;
415 // Read time & duration:
416 if (p+5 >= p_end) return 0; // Packet too short
417 time = AV_RL32(p); p+=4;
418 duration = AV_RL16(p); p+=2;
420 // Read payload flags:
421 if(flags&1){
422 // multiple sub-packets
423 if (p >= p_end) return 0; // Packet too short
424 segsizetype=p[0]>>6;
425 segs=p[0] & 0x3F;
426 ++p;
428 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"%08"PRIu64": flag=%02X segs=%d seq=%u plen=%u pad=%u time=%ld dur=%d\n",
429 (uint64_t)demux->filepos,flags,segs,sequence,plen,padding,time,duration);
431 for(seg=0;seg<segs;seg++){
432 //ASF_segmhdr_t* sh;
433 unsigned char streamno;
434 unsigned int seq;
435 unsigned int x; // offset or timestamp
436 unsigned int rlen;
438 int len;
439 uint64_t time2=0;
440 int keyframe=0;
442 if(p>=p_end) {
443 mp_msg(MSGT_DEMUX,MSGL_V,"Warning! invalid packet 1, aborting parsing...\n");
444 break;
447 if( mp_msg_test(MSGT_DEMUX,MSGL_DBG2) ){
448 int i;
449 printf("seg %d:",seg);
450 for(i=0;i<FFMIN(16, p_end - p);i++) printf(" %02X",p[i]);
451 printf("\n");
454 streamno=p[0]&0x7F;
455 if(p[0]&0x80) keyframe=1;
456 p++;
458 // Read media object number (seq):
459 if(!check_varlen(p, p_end, segtype >> 4)) break; // Not enough data
460 seq = read_varlen(&p, segtype >> 4, 0);
462 // Read offset or timestamp:
463 if(!check_varlen(p, p_end, segtype >> 2)) break; // Not enough data
464 x = read_varlen(&p, segtype >> 2, 0);
466 // Read replic.data len:
467 if(!check_varlen(p, p_end, segtype)) break; // Not enough data
468 rlen = read_varlen(&p, segtype, 0);
470 // printf("### rlen=%d \n",rlen);
471 if (rlen < 0 || rlen > p_end - p) {
472 mp_msg(MSGT_DEMUX, MSGL_V, "invalid rlen=%d\n", rlen);
473 break;
476 switch(rlen){
477 case 0x01: // 1 = special, means grouping
478 //printf("grouping: %02X \n",p[0]);
479 ++p; // skip PTS delta
480 break;
481 default:
482 if(rlen>=8){
483 p+=4; // skip object size
484 if (p+3 >= p_end) break; // Packet too short
485 time2=AV_RL32(p); // read PTS
486 if (asf->asf_is_dvr_ms)
487 get_payload_extension_data(demux, &p, streamno, seq, &keyframe, &time2);
488 p+=rlen-4;
489 } else {
490 mp_msg(MSGT_DEMUX,MSGL_V,"unknown segment type (rlen): 0x%02X \n",rlen);
491 time2=0; // unknown
492 p+=rlen;
496 if(flags&1){
497 // multiple segments
498 if(!check_varlen(p, p_end, segsizetype)) break; // Not enough data
499 len = read_varlen(&p, segsizetype, plen-(p-asf->packet));
500 } else {
501 // single segment
502 len=plen-(p-asf->packet);
504 if(len<0 || (p+len)>p_end){
505 mp_msg(MSGT_DEMUX,MSGL_V,"ASF_parser: warning! segment len=%d\n",len);
506 len = p_end - p;
508 mp_dbg(MSGT_DEMUX,MSGL_DBG4," seg #%d: streamno=%d seq=%d type=%02X len=%d\n",seg,streamno,seq,rlen,len);
510 switch(rlen){
511 case 0x01:
512 // GROUPING:
513 //printf("ASF_parser: warning! grouping (flag=1) not yet supported!\n",len);
514 //printf(" total: %d \n",len);
515 while(len>0){
516 int len2=p[0];
517 p++;
518 //printf(" group part: %d bytes\n",len2);
519 if(len2 > len - 1 || len2 < 0) break; // Not enough data
520 len2 = FFMIN(len2, asf->packetsize);
521 demux_asf_read_packet(demux,p,len2,streamno,seq,x,duration,-1,keyframe);
522 p+=len2;
523 len-=len2+1;
524 ++seq;
526 if(len!=0){
527 mp_msg(MSGT_DEMUX,MSGL_V,"ASF_parser: warning! groups total != len\n");
529 break;
530 default:
531 // NO GROUPING:
532 //printf("fragment offset: %d \n",sh->x);
533 if (len <= 0) break;
534 if (!asf->asf_is_dvr_ms || asf->found_first_key_frame) {
535 len = FFMIN(len, asf->packetsize);
536 demux_asf_read_packet(demux,p,len,streamno,seq,time2,duration,x,keyframe);
538 p+=len;
539 break;
542 } // for segs
543 return 1; // success
546 mp_msg(MSGT_DEMUX,MSGL_V,"%08"PRIX64": UNKNOWN TYPE %02X %02X %02X %02X %02X...\n",(int64_t)demux->filepos,asf->packet[0],asf->packet[1],asf->packet[2],asf->packet[3],asf->packet[4]);
547 return 0;
550 #include "stheader.h"
552 static void demux_seek_asf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
553 struct asf_priv* asf = demuxer->priv;
554 demux_stream_t *d_audio=demuxer->audio;
555 demux_stream_t *d_video=demuxer->video;
556 sh_audio_t *sh_audio=d_audio->sh;
557 // sh_video_t *sh_video=d_video->sh;
559 //FIXME: OFF_T - didn't test ASF case yet (don't have a large asf...)
560 //FIXME: reports good or bad to steve@daviesfam.org please
562 //================= seek in ASF ==========================
563 float p_rate=asf->packetrate; // packets / sec
564 off_t rel_seek_packs=(flags&SEEK_FACTOR)? // FIXME: int may be enough?
565 (rel_seek_secs*(demuxer->movi_end-demuxer->movi_start)/asf->packetsize):
566 (rel_seek_secs*p_rate);
567 off_t rel_seek_bytes=rel_seek_packs*asf->packetsize;
568 off_t newpos;
569 //printf("ASF: packs: %d duration: %d \n",(int)fileh.packets,*((int*)&fileh.duration));
570 // printf("ASF_seek: %d secs -> %d packs -> %d bytes \n",
571 // rel_seek_secs,rel_seek_packs,rel_seek_bytes);
572 newpos=((flags&SEEK_ABSOLUTE)?demuxer->movi_start:demuxer->filepos)+rel_seek_bytes;
573 if(newpos<0 || newpos<demuxer->movi_start) newpos=demuxer->movi_start;
574 // printf("\r -- asf: newpos=%d -- \n",newpos);
575 stream_seek(demuxer->stream,newpos);
577 if (asf->asf_is_dvr_ms) asf->dvr_last_vid_pts = 0.0f;
579 if (d_video->id >= 0)
580 ds_fill_buffer(d_video);
581 if(sh_audio){
582 ds_fill_buffer(d_audio);
585 if (d_video->id >= 0)
586 while(1){
587 if(sh_audio && !d_audio->eof){
588 float a_pts=d_audio->pts;
589 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
590 // sync audio:
591 if (d_video->pts > a_pts){
592 skip_audio_frame(sh_audio);
593 // if(!ds_fill_buffer(d_audio)) sh_audio=NULL; // skip audio. EOF?
594 continue;
597 if(d_video->flags&1) break; // found a keyframe!
598 if(!ds_fill_buffer(d_video)) break; // skip frame. EOF?
604 static int demux_asf_control(demuxer_t *demuxer,int cmd, void *arg){
605 struct asf_priv* asf = demuxer->priv;
606 /* demux_stream_t *d_audio=demuxer->audio;
607 demux_stream_t *d_video=demuxer->video;
608 sh_audio_t *sh_audio=d_audio->sh;
609 sh_video_t *sh_video=d_video->sh;
611 switch(cmd) {
612 case DEMUXER_CTRL_GET_TIME_LENGTH:
613 *((double *)arg)=asf->movielength;
614 return DEMUXER_CTRL_OK;
616 case DEMUXER_CTRL_GET_PERCENT_POS:
617 return DEMUXER_CTRL_DONTKNOW;
619 default:
620 return DEMUXER_CTRL_NOTIMPL;
625 static demuxer_t* demux_open_asf(demuxer_t* demuxer)
627 struct asf_priv* asf = demuxer->priv;
628 sh_video_t *sh_video=NULL;
630 //---- ASF header:
631 if(!asf) return NULL;
632 init_priv(asf);
633 if (!read_asf_header(demuxer,asf))
634 return NULL;
635 stream_reset(demuxer->stream);
636 stream_seek(demuxer->stream,demuxer->movi_start);
637 // demuxer->idx_pos=0;
638 // demuxer->endpos=avi_header.movi_end;
639 if(demuxer->video->id != -2) {
640 if(!ds_fill_buffer(demuxer->video)){
641 mp_msg(MSGT_DEMUXER, MSGL_WARN, "ASF: %s",
642 mp_gtext("No video stream found.\n"));
643 demuxer->video->sh=NULL;
644 //printf("ASF: missing video stream!? contact the author, it may be a bug :(\n");
645 } else {
646 sh_video=demuxer->video->sh;
647 sh_video->fps=1000.0f; sh_video->frametime=0.001f;
649 if (asf->asf_is_dvr_ms) {
650 sh_video->bih->biWidth = 0;
651 sh_video->bih->biHeight = 0;
656 if(demuxer->audio->id!=-2){
657 mp_tmsg(MSGT_DEMUXER,MSGL_V,"ASF: Searching for audio stream (id:%d).\n",demuxer->audio->id);
658 if(!ds_fill_buffer(demuxer->audio)){
659 mp_msg(MSGT_DEMUXER, MSGL_INFO, "ASF: %s",
660 mp_gtext("No audio stream found -> no sound.\n"));
661 demuxer->audio->sh=NULL;
664 if(!demuxer->stream->seek)
665 demuxer->seekable=0;
667 return demuxer;
671 static void demux_close_asf(demuxer_t *demuxer) {
672 struct asf_priv* asf = demuxer->priv;
674 if (!asf) return;
676 free(asf->aud_repdata_sizes);
677 free(asf->vid_repdata_sizes);
678 free(asf->packet);
679 free(asf);
682 const demuxer_desc_t demuxer_desc_asf = {
683 "ASF demuxer",
684 "asf",
685 "ASF",
686 "A'rpi",
687 "ASF, WMV, WMA",
688 DEMUXER_TYPE_ASF,
689 1, // safe autodetect
690 asf_check_header,
691 demux_asf_fill_buffer,
692 demux_open_asf,
693 demux_close_asf,
694 demux_seek_asf,
695 demux_asf_control