2001-02-24 20:28:24 +00:00
|
|
|
// .asf fileformat docs from http://divx.euro.ru
|
|
|
|
|
2001-04-23 03:42:17 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
extern int verbose; // defined in mplayer.c
|
|
|
|
|
|
|
|
#include "stream.h"
|
|
|
|
#include "demuxer.h"
|
|
|
|
|
|
|
|
#include "wine/mmreg.h"
|
|
|
|
#include "wine/avifmt.h"
|
|
|
|
#include "wine/vfw.h"
|
|
|
|
|
|
|
|
#include "codec-cfg.h"
|
|
|
|
#include "stheader.h"
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
typedef struct __attribute__((packed)) {
|
|
|
|
unsigned char guid[16];
|
|
|
|
unsigned long long size;
|
|
|
|
} ASF_obj_header_t;
|
|
|
|
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
|
|
ASF_obj_header_t objh;
|
|
|
|
unsigned int cno; // number of subchunks
|
|
|
|
unsigned char v1; // unknown (0x01)
|
|
|
|
unsigned char v2; // unknown (0x02)
|
|
|
|
} ASF_header_t;
|
|
|
|
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
|
|
unsigned char client[16]; // Client GUID
|
|
|
|
unsigned long long file_size;
|
|
|
|
unsigned long long creat_time; //File creation time FILETIME 8
|
|
|
|
unsigned long long packets; //Number of packets UINT64 8
|
|
|
|
unsigned long long end_timestamp; //Timestamp of the end position UINT64 8
|
|
|
|
unsigned long long duration; //Duration of the playback UINT64 8
|
|
|
|
unsigned long start_timestamp; //Timestamp of the start position UINT32 4
|
|
|
|
unsigned long unk1; //Unknown, maybe reserved ( usually contains 0 ) UINT32 4
|
|
|
|
unsigned long flags; //Unknown, maybe flags ( usually contains 2 ) UINT32 4
|
|
|
|
unsigned long packetsize; //Size of packet, in bytes UINT32 4
|
|
|
|
unsigned long packetsize2; //Size of packet ( confirm ) UINT32 4
|
|
|
|
unsigned long frame_size; //Size of uncompressed video frame UINT32 4
|
|
|
|
} ASF_file_header_t;
|
|
|
|
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
|
|
unsigned char type[16]; // Stream type (audio/video) GUID 16
|
|
|
|
unsigned char concealment[16]; // Audio error concealment type GUID 16
|
|
|
|
unsigned long long unk1; // Unknown, maybe reserved ( usually contains 0 ) UINT64 8
|
|
|
|
unsigned long type_size; //Total size of type-specific data UINT32 4
|
|
|
|
unsigned long stream_size; //Size of stream-specific data UINT32 4
|
|
|
|
unsigned short stream_no; //Stream number UINT16 2
|
|
|
|
unsigned long unk2; //Unknown UINT32 4
|
|
|
|
} ASF_stream_header_t;
|
|
|
|
|
|
|
|
|
2001-04-23 03:42:17 +00:00
|
|
|
static ASF_header_t asfh;
|
|
|
|
static ASF_obj_header_t objh;
|
|
|
|
static ASF_file_header_t fileh;
|
|
|
|
static ASF_stream_header_t streamh;
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
unsigned char* asf_packet=NULL;
|
|
|
|
int asf_scrambling_h=1;
|
|
|
|
int asf_scrambling_w=1;
|
|
|
|
int asf_scrambling_b=1;
|
2001-04-23 03:42:17 +00:00
|
|
|
int asf_packetsize=0;
|
|
|
|
|
|
|
|
//int i;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
|
2001-04-23 03:42:17 +00:00
|
|
|
static char* asf_chunk_type(unsigned char* guid){
|
2001-02-24 20:28:24 +00:00
|
|
|
switch(*((unsigned int*)guid)){
|
|
|
|
case 0xF8699E40: return "guid_audio_stream";
|
|
|
|
case 0xBC19EFC0: return "guid_video_stream";
|
|
|
|
case 0x49f1a440: return "guid_audio_conceal_none";
|
|
|
|
case 0xbfc3cd50: return "guid_audio_conceal_interleave";
|
|
|
|
case 0x75B22630: return "guid_header";
|
|
|
|
case 0x75b22636: return "guid_data_chunk";
|
|
|
|
case 0x33000890: return "guid_index_chunk";
|
|
|
|
case 0xB7DC0791: return "guid_stream_header";
|
|
|
|
case 0xD6E229D1: return "guid_header_2_0";
|
|
|
|
case 0x8CABDCA1: return "guid_file_header";
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-04-23 03:42:17 +00:00
|
|
|
int asf_check_header(demuxer_t *demuxer){
|
2001-02-24 20:28:24 +00:00
|
|
|
unsigned char asfhdrguid[16]={0x30,0x26,0xB2,0x75,0x8E,0x66,0xCF,0x11,0xA6,0xD9,0x00,0xAA,0x00,0x62,0xCE,0x6C};
|
|
|
|
stream_read(demuxer->stream,(char*) &asfh,sizeof(asfh)); // header obj
|
|
|
|
// for(i=0;i<16;i++) printf(" %02X",temp[i]);printf("\n");
|
|
|
|
// for(i=0;i<16;i++) printf(" %02X",asfhdrguid[i]);printf("\n");
|
|
|
|
if(memcmp(asfhdrguid,asfh.objh.guid,16)){
|
|
|
|
if(verbose) printf("ASF_check: not ASF guid!\n");
|
|
|
|
return 0; // not ASF guid
|
|
|
|
}
|
|
|
|
if(asfh.cno>256){
|
|
|
|
if(verbose) printf("ASF_check: invalid subchunks_no %d\n",(int) asfh.cno);
|
|
|
|
return 0; // invalid header???
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-04-23 03:42:17 +00:00
|
|
|
int read_asf_header(demuxer_t *demuxer){
|
2001-02-24 20:28:24 +00:00
|
|
|
unsigned char buffer[512];
|
|
|
|
|
|
|
|
#if 1
|
2001-04-11 01:38:57 +00:00
|
|
|
//printf("ASF file! (subchunks: %d)\n",asfh.cno);
|
2001-02-24 20:28:24 +00:00
|
|
|
while(!stream_eof(demuxer->stream)){
|
|
|
|
int pos,endpos;
|
|
|
|
pos=stream_tell(demuxer->stream);
|
|
|
|
stream_read(demuxer->stream,(char*) &objh,sizeof(objh));
|
|
|
|
if(stream_eof(demuxer->stream)) break; // EOF
|
|
|
|
endpos=pos+objh.size;
|
|
|
|
// for(i=0;i<16;i++) printf("%02X ",objh.guid[i]);
|
2001-04-11 01:38:57 +00:00
|
|
|
//printf("0x%08X [%s] %d\n",pos, asf_chunk_type(objh.guid),(int) objh.size);
|
2001-02-24 20:28:24 +00:00
|
|
|
switch(*((unsigned int*)&objh.guid)){
|
|
|
|
case 0xB7DC0791: // guid_stream_header
|
|
|
|
stream_read(demuxer->stream,(char*) &streamh,sizeof(streamh));
|
2001-04-11 01:38:57 +00:00
|
|
|
if(verbose){
|
2001-02-24 20:28:24 +00:00
|
|
|
printf("stream type: %s\n",asf_chunk_type(streamh.type));
|
|
|
|
printf("stream concealment: %s\n",asf_chunk_type(streamh.concealment));
|
|
|
|
printf("type: %d bytes, stream: %d bytes ID: %d\n",(int)streamh.type_size,(int)streamh.stream_size,(int)streamh.stream_no);
|
|
|
|
printf("unk1: %lX unk2: %X\n",streamh.unk1,streamh.unk2);
|
|
|
|
printf("FILEPOS=0x%X\n",stream_tell(demuxer->stream));
|
2001-04-11 01:38:57 +00:00
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
// type-specific data:
|
|
|
|
stream_read(demuxer->stream,(char*) buffer,streamh.type_size);
|
|
|
|
switch(*((unsigned int*)&streamh.type)){
|
2001-04-06 01:18:59 +00:00
|
|
|
case 0xF8699E40: { // guid_audio_stream
|
2001-04-15 03:40:37 +00:00
|
|
|
sh_audio_t* sh_audio=new_sh_audio(streamh.stream_no & 0x7F);
|
2001-04-15 14:33:49 +00:00
|
|
|
sh_audio->wf=calloc((streamh.type_size<sizeof(WAVEFORMATEX))?sizeof(WAVEFORMATEX):streamh.type_size,1);
|
|
|
|
memcpy(sh_audio->wf,buffer,streamh.type_size);
|
|
|
|
if(verbose>=1) print_wave_header(sh_audio->wf);
|
2001-02-24 20:28:24 +00:00
|
|
|
if((*((unsigned int*)&streamh.concealment))==0xbfc3cd50){
|
|
|
|
stream_read(demuxer->stream,(char*) buffer,streamh.stream_size);
|
|
|
|
asf_scrambling_h=buffer[0];
|
|
|
|
asf_scrambling_w=(buffer[2]<<8)|buffer[1];
|
|
|
|
asf_scrambling_b=(buffer[4]<<8)|buffer[3];
|
|
|
|
asf_scrambling_w/=asf_scrambling_b;
|
|
|
|
} else {
|
|
|
|
asf_scrambling_b=asf_scrambling_h=asf_scrambling_w=1;
|
|
|
|
}
|
2001-04-11 01:38:57 +00:00
|
|
|
printf("ASF: audio scrambling: %d x %d x %d\n",asf_scrambling_h,asf_scrambling_w,asf_scrambling_b);
|
2001-04-15 03:40:37 +00:00
|
|
|
//if(demuxer->audio->id==-1) demuxer->audio->id=streamh.stream_no & 0x7F;
|
2001-02-24 20:28:24 +00:00
|
|
|
break;
|
2001-04-06 01:18:59 +00:00
|
|
|
}
|
|
|
|
case 0xBC19EFC0: { // guid_video_stream
|
2001-04-15 03:40:37 +00:00
|
|
|
sh_video_t* sh_video=new_sh_video(streamh.stream_no & 0x7F);
|
2001-04-15 14:33:49 +00:00
|
|
|
int len=streamh.type_size-(4+4+1+2);
|
|
|
|
// sh_video->bih=malloc(chunksize); memset(sh_video->bih,0,chunksize);
|
|
|
|
sh_video->bih=calloc((len<sizeof(BITMAPINFOHEADER))?sizeof(BITMAPINFOHEADER):len,1);
|
|
|
|
memcpy(sh_video->bih,&buffer[4+4+1+2],len);
|
2001-04-15 03:40:37 +00:00
|
|
|
//sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale;
|
|
|
|
//sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
|
2001-04-15 14:33:49 +00:00
|
|
|
if(verbose>=1) print_video_header(sh_video->bih);
|
2001-02-24 20:28:24 +00:00
|
|
|
//asf_video_id=streamh.stream_no & 0x7F;
|
2001-04-15 03:40:37 +00:00
|
|
|
//if(demuxer->video->id==-1) demuxer->video->id=streamh.stream_no & 0x7F;
|
2001-02-24 20:28:24 +00:00
|
|
|
break;
|
2001-04-06 01:18:59 +00:00
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
// stream-specific data:
|
|
|
|
// stream_read(demuxer->stream,(char*) buffer,streamh.stream_size);
|
|
|
|
break;
|
|
|
|
// case 0xD6E229D1: return "guid_header_2_0";
|
|
|
|
case 0x8CABDCA1: // guid_file_header
|
|
|
|
stream_read(demuxer->stream,(char*) &fileh,sizeof(fileh));
|
2001-04-11 01:38:57 +00:00
|
|
|
if(verbose) printf("ASF: packets: %d flags: %d pack_size: %d frame_size: %d\n",(int)fileh.packets,(int)fileh.flags,(int)fileh.packetsize,(int)fileh.frame_size);
|
2001-04-23 03:42:17 +00:00
|
|
|
asf_packetsize=fileh.packetsize;
|
|
|
|
asf_packet=malloc(asf_packetsize); // !!!
|
2001-02-24 20:28:24 +00:00
|
|
|
break;
|
|
|
|
case 0x75b22636: // guid_data_chunk
|
2001-04-23 03:42:17 +00:00
|
|
|
demuxer->movi_start=stream_tell(demuxer->stream)+26;
|
|
|
|
demuxer->movi_end=endpos;
|
|
|
|
if(verbose>=1) printf("Found movie at 0x%X - 0x%X\n",demuxer->movi_start,demuxer->movi_end);
|
2001-02-24 20:28:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// case 0x33000890: return "guid_index_chunk";
|
|
|
|
|
|
|
|
} // switch GUID
|
|
|
|
if(!stream_seek(demuxer->stream,endpos)) break;
|
|
|
|
} // while EOF
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if(verbose){
|
|
|
|
printf("ASF duration: %d\n",(int)fileh.duration);
|
|
|
|
printf("ASF start pts: %d\n",(int)fileh.start_timestamp);
|
|
|
|
printf("ASF end pts: %d\n",(int)fileh.end_timestamp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|