1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 09:02:38 +00:00

some cleanup and fixes, but the badquality.asf is still buggy :(

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@6443 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
arpi 2002-06-16 02:53:22 +00:00
parent ac884de235
commit 988c45fb6a

View File

@ -151,18 +151,20 @@ int demux_asf_fill_buffer(demuxer_t *demux){
stream_read(demux->stream,asf_packet,asf_packetsize); stream_read(demux->stream,asf_packet,asf_packetsize);
if(demux->stream->eof) return 0; // EOF if(demux->stream->eof) return 0; // EOF
if(asf_packet[0]==0x82){ { unsigned char ecc_flags=asf_packet[0];
unsigned char flags=asf_packet[3]; unsigned char* p=&asf_packet[1+(ecc_flags&15)];
unsigned char segtype=asf_packet[4];
unsigned char* p=&asf_packet[5];
unsigned char* p_end=asf_packet+asf_packetsize; unsigned char* p_end=asf_packet+asf_packetsize;
unsigned long time; unsigned char flags=p[0];
unsigned short duration; unsigned char segtype=p[1];
int padding;
int plen;
int sequence;
unsigned long time=0;
unsigned short duration=0;
int segs=1; int segs=1;
unsigned char segsizetype=0x80; unsigned char segsizetype=0x80;
int seg; int seg=-1;
int padding=0;
int plen;
if(verbose>1){ if(verbose>1){
int i; int i;
@ -172,45 +174,63 @@ int demux_asf_fill_buffer(demuxer_t *demux){
//if(segtype!=0x5d) printf("Warning! packet[4] != 0x5d \n"); //if(segtype!=0x5d) printf("Warning! packet[4] != 0x5d \n");
// Calculate packet size (plen): p+=2; // skip flags & segtype
if(flags&0x40){
// Read packet size (plen):
switch((flags>>5)&3){
case 3: plen=LOAD_LE32(p);p+=4;break; // dword
case 2: plen=LOAD_LE16(p);p+=2;break; // word
case 1: plen=p[0];p++;break; // byte
}
// Read sequence:
switch((flags>>1)&3){
case 3: sequence=LOAD_LE32(p);p+=4;break; // dword
case 2: sequence=LOAD_LE16(p);p+=2;break; // word
case 1: sequence=p[0];p++;break; // byte
default: sequence=0;
}
// Read padding size (padding):
switch((flags>>3)&3){
case 3: padding=LOAD_LE32(p);p+=4;break; // dword
case 2: padding=LOAD_LE16(p);p+=2;break; // word
case 1: padding=p[0];p++;break; // byte
default: padding=0;
}
if(((flags>>5)&3)!=0){
// Explicit (absoulte) packet size // Explicit (absoulte) packet size
plen=LOAD_LE16(p); p+=2;
mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Explicit packet size specified: %d \n",plen); mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Explicit packet size specified: %d \n",plen);
if(plen>asf_packetsize) mp_msg(MSGT_DEMUX,MSGL_V,"Warning! plen>packetsize! (%d>%d) \n",plen,asf_packetsize); if(plen>asf_packetsize) mp_msg(MSGT_DEMUX,MSGL_V,"Warning! plen>packetsize! (%d>%d) \n",plen,asf_packetsize);
if(flags&(8|16)){
padding=p[0];p++;
if(flags&16){ padding|=p[0]<<8; p++;}
mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Warning! explicit=%d padding=%d \n",plen,asf_packetsize-padding);
}
} else { } else {
// Padding (relative) size // Padding (relative) size
if(flags&8){
padding=p[0];++p;
} else
if(flags&16){
padding=LOAD_LE16(p);p+=2;
}
plen=asf_packetsize-padding; plen=asf_packetsize-padding;
} }
// Read time & duration:
time = LOAD_LE32(p); p+=4; time = LOAD_LE32(p); p+=4;
duration = LOAD_LE16(p); p+=2; duration = LOAD_LE16(p); p+=2;
// Read payload flags:
if(flags&1){ if(flags&1){
segsizetype=p[0] & 0xC0; // multiple sub-packets
segsizetype=p[0]>>6;
segs=p[0] & 0x3F; segs=p[0] & 0x3F;
++p; ++p;
} }
mp_dbg(MSGT_DEMUX,MSGL_DBG4,"%08X: flag=%02X segs=%d pad=%d time=%ld dur=%d\n", mp_dbg(MSGT_DEMUX,MSGL_DBG4,"%08X: flag=%02X segs=%d seq=%d plen=%d pad=%d time=%ld dur=%d\n",
demux->filepos,flags,segs,padding,time,duration); demux->filepos,flags,segs,sequence,plen,padding,time,duration);
for(seg=0;seg<segs;seg++){ for(seg=0;seg<segs;seg++){
//ASF_segmhdr_t* sh; //ASF_segmhdr_t* sh;
unsigned char streamno; unsigned char streamno;
unsigned char seq; unsigned int seq;
unsigned int x; // offset or timestamp
unsigned int rlen;
//
int len; int len;
unsigned long x; unsigned int time2;
unsigned char type;
unsigned long time2;
int keyframe=0; int keyframe=0;
if(p>=p_end) mp_msg(MSGT_DEMUX,MSGL_V,"Warning! invalid packet 1, sig11 coming soon...\n"); if(p>=p_end) mp_msg(MSGT_DEMUX,MSGL_V,"Warning! invalid packet 1, sig11 coming soon...\n");
@ -224,49 +244,57 @@ int demux_asf_fill_buffer(demuxer_t *demux){
streamno=p[0]&0x7F; streamno=p[0]&0x7F;
if(p[0]&0x80) keyframe=1; if(p[0]&0x80) keyframe=1;
seq=p[1];
p+=2;
switch(segtype){
case 0x55:
x=*((unsigned char*)p);
p++; p++;
break;
case 0x59: // Read media object number (seq):
x=LOAD_LE16(p); switch((segtype>>4)&3){
p+=2; case 3: seq=LOAD_LE32(p);p+=4;break; // dword
break; case 2: seq=LOAD_LE16(p);p+=2;break; // word
case 0x5D: case 1: seq=p[0];p++;break; // byte
x=LOAD_LE32(p); default: seq=0;
p+=4;
break;
default:
mp_msg(MSGT_DEMUX,MSGL_V,"Warning! unknown segtype == 0x%2X \n",segtype);
x=0;
} }
type=p[0]; p++; // 0x01: grouping 0x08: single // Read offset or timestamp:
switch((segtype>>2)&3){
case 3: x=LOAD_LE32(p);p+=4;break; // dword
case 2: x=LOAD_LE16(p);p+=2;break; // word
case 1: x=p[0];p++;break; // byte
default: x=0;
}
switch(type){ // Read replic.data len:
case 0x01: switch((segtype)&3){
case 3: rlen=LOAD_LE32(p);p+=4;break; // dword
case 2: rlen=LOAD_LE16(p);p+=2;break; // word
case 1: rlen=p[0];p++;break; // byte
default: rlen=0;
}
// printf("### rlen=%d \n",rlen);
switch(rlen){
case 0x01: // 1 = special, means grouping
//printf("grouping: %02X \n",p[0]); //printf("grouping: %02X \n",p[0]);
++p; // skip unknown byte ++p; // skip PTS delta
break;
case 0x08:
//printf("!!! obj_length = %d\n",*((unsigned long*)p));
p+=4;
time2=LOAD_LE32(p);p+=4;
break; break;
default: default:
mp_msg(MSGT_DEMUX,MSGL_V,"unknown segment type: 0x%02X \n",type); if(rlen>=8){
p+=4; // skip object size
time2=LOAD_LE32(p); // read PTS
p+=rlen-4;
} else {
mp_msg(MSGT_DEMUX,MSGL_V,"unknown segment type (rlen): 0x%02X \n",rlen);
p+=rlen;
}
} }
if(flags&1){ if(flags&1){
// multiple segments // multiple segments
if(segsizetype==0x40){ switch(segsizetype){
len=*((unsigned char*)p);p++; // 1 byte case 3: len=LOAD_LE32(p);p+=4;break; // dword
} else { case 2: len=LOAD_LE16(p);p+=2;break; // word
len=LOAD_LE16(p);p+=2; // 2 byte case 1: len=p[0];p++;break; // byte
default: len=plen-(p-asf_packet); // ???
} }
} else { } else {
// single segment // single segment
@ -275,9 +303,9 @@ int demux_asf_fill_buffer(demuxer_t *demux){
if(len<0 || (p+len)>p_end){ if(len<0 || (p+len)>p_end){
mp_msg(MSGT_DEMUX,MSGL_V,"ASF_parser: warning! segment len=%d\n",len); mp_msg(MSGT_DEMUX,MSGL_V,"ASF_parser: warning! segment len=%d\n",len);
} }
mp_dbg(MSGT_DEMUX,MSGL_DBG4," seg #%d: streamno=%d seq=%d type=%02X len=%d\n",seg,streamno,seq,type,len); mp_dbg(MSGT_DEMUX,MSGL_DBG4," seg #%d: streamno=%d seq=%d type=%02X len=%d\n",seg,streamno,seq,rlen,len);
switch(type){ switch(rlen){
case 0x01: case 0x01:
// GROUPING: // GROUPING:
//printf("ASF_parser: warning! grouping (flag=1) not yet supported!\n",len); //printf("ASF_parser: warning! grouping (flag=1) not yet supported!\n",len);
@ -294,7 +322,7 @@ int demux_asf_fill_buffer(demuxer_t *demux){
mp_msg(MSGT_DEMUX,MSGL_V,"ASF_parser: warning! groups total != len\n"); mp_msg(MSGT_DEMUX,MSGL_V,"ASF_parser: warning! groups total != len\n");
} }
break; break;
case 0x08: default:
// NO GROUPING: // NO GROUPING:
//printf("fragment offset: %d \n",sh->x); //printf("fragment offset: %d \n",sh->x);
demux_asf_read_packet(demux,p,len,streamno,seq,time2,duration,x,keyframe); demux_asf_read_packet(demux,p,len,streamno,seq,time2,duration,x,keyframe);