Mercurial > mplayer.hg
annotate asfheader.c @ 573:548aa1c31d21
added compilation of fastmem test progs
author | arpi_esp |
---|---|
date | Sun, 22 Apr 2001 03:41:13 +0000 |
parents | 5251b0c57e39 |
children | 8511095c5283 |
rev | line source |
---|---|
1 | 1 // .asf fileformat docs from http://divx.euro.ru |
2 | |
3 typedef struct __attribute__((packed)) { | |
4 unsigned char guid[16]; | |
5 unsigned long long size; | |
6 } ASF_obj_header_t; | |
7 | |
8 typedef struct __attribute__((packed)) { | |
9 ASF_obj_header_t objh; | |
10 unsigned int cno; // number of subchunks | |
11 unsigned char v1; // unknown (0x01) | |
12 unsigned char v2; // unknown (0x02) | |
13 } ASF_header_t; | |
14 | |
15 typedef struct __attribute__((packed)) { | |
16 unsigned char client[16]; // Client GUID | |
17 unsigned long long file_size; | |
18 unsigned long long creat_time; //File creation time FILETIME 8 | |
19 unsigned long long packets; //Number of packets UINT64 8 | |
20 unsigned long long end_timestamp; //Timestamp of the end position UINT64 8 | |
21 unsigned long long duration; //Duration of the playback UINT64 8 | |
22 unsigned long start_timestamp; //Timestamp of the start position UINT32 4 | |
23 unsigned long unk1; //Unknown, maybe reserved ( usually contains 0 ) UINT32 4 | |
24 unsigned long flags; //Unknown, maybe flags ( usually contains 2 ) UINT32 4 | |
25 unsigned long packetsize; //Size of packet, in bytes UINT32 4 | |
26 unsigned long packetsize2; //Size of packet ( confirm ) UINT32 4 | |
27 unsigned long frame_size; //Size of uncompressed video frame UINT32 4 | |
28 } ASF_file_header_t; | |
29 | |
30 typedef struct __attribute__((packed)) { | |
31 unsigned char type[16]; // Stream type (audio/video) GUID 16 | |
32 unsigned char concealment[16]; // Audio error concealment type GUID 16 | |
33 unsigned long long unk1; // Unknown, maybe reserved ( usually contains 0 ) UINT64 8 | |
34 unsigned long type_size; //Total size of type-specific data UINT32 4 | |
35 unsigned long stream_size; //Size of stream-specific data UINT32 4 | |
36 unsigned short stream_no; //Stream number UINT16 2 | |
37 unsigned long unk2; //Unknown UINT32 4 | |
38 } ASF_stream_header_t; | |
39 | |
40 | |
41 ASF_header_t asfh; | |
42 ASF_obj_header_t objh; | |
43 ASF_file_header_t fileh; | |
44 ASF_stream_header_t streamh; | |
45 unsigned char* asf_packet=NULL; | |
46 //int asf_video_id=-1; | |
47 int asf_scrambling_h=1; | |
48 int asf_scrambling_w=1; | |
49 int asf_scrambling_b=1; | |
50 | |
51 int i; | |
52 | |
53 void asf_descrambling(unsigned char *src,int len){ | |
54 unsigned char *dst=malloc(len); | |
55 unsigned char *s2=src; | |
56 int i=0,x,y; | |
57 while(len-i>=asf_scrambling_h*asf_scrambling_w*asf_scrambling_b){ | |
58 // printf("descrambling! (w=%d b=%d)\n",w,asf_scrambling_b); | |
59 //i+=asf_scrambling_h*asf_scrambling_w; | |
60 for(x=0;x<asf_scrambling_w;x++) | |
61 for(y=0;y<asf_scrambling_h;y++){ | |
62 memcpy(dst+i,s2+(y*asf_scrambling_w+x)*asf_scrambling_b,asf_scrambling_b); | |
63 i+=asf_scrambling_b; | |
64 } | |
65 s2+=asf_scrambling_h*asf_scrambling_w*asf_scrambling_b; | |
66 } | |
67 //if(i<len) memcpy(dst+i,src+i,len-i); | |
68 memcpy(src,dst,i); | |
69 free(dst); | |
70 } | |
71 | |
72 char* asf_chunk_type(unsigned char* guid){ | |
73 switch(*((unsigned int*)guid)){ | |
74 case 0xF8699E40: return "guid_audio_stream"; | |
75 case 0xBC19EFC0: return "guid_video_stream"; | |
76 case 0x49f1a440: return "guid_audio_conceal_none"; | |
77 case 0xbfc3cd50: return "guid_audio_conceal_interleave"; | |
78 case 0x75B22630: return "guid_header"; | |
79 case 0x75b22636: return "guid_data_chunk"; | |
80 case 0x33000890: return "guid_index_chunk"; | |
81 case 0xB7DC0791: return "guid_stream_header"; | |
82 case 0xD6E229D1: return "guid_header_2_0"; | |
83 case 0x8CABDCA1: return "guid_file_header"; | |
84 } | |
85 return NULL; | |
86 } | |
87 | |
88 int asf_check_header(){ | |
89 unsigned char asfhdrguid[16]={0x30,0x26,0xB2,0x75,0x8E,0x66,0xCF,0x11,0xA6,0xD9,0x00,0xAA,0x00,0x62,0xCE,0x6C}; | |
90 stream_read(demuxer->stream,(char*) &asfh,sizeof(asfh)); // header obj | |
91 // for(i=0;i<16;i++) printf(" %02X",temp[i]);printf("\n"); | |
92 // for(i=0;i<16;i++) printf(" %02X",asfhdrguid[i]);printf("\n"); | |
93 if(memcmp(asfhdrguid,asfh.objh.guid,16)){ | |
94 if(verbose) printf("ASF_check: not ASF guid!\n"); | |
95 return 0; // not ASF guid | |
96 } | |
97 if(asfh.cno>256){ | |
98 if(verbose) printf("ASF_check: invalid subchunks_no %d\n",(int) asfh.cno); | |
99 return 0; // invalid header??? | |
100 } | |
101 return 1; | |
102 } | |
103 | |
104 int read_asf_header(){ | |
105 unsigned char buffer[512]; | |
106 | |
107 #if 1 | |
340 | 108 //printf("ASF file! (subchunks: %d)\n",asfh.cno); |
1 | 109 while(!stream_eof(demuxer->stream)){ |
110 int pos,endpos; | |
111 pos=stream_tell(demuxer->stream); | |
112 stream_read(demuxer->stream,(char*) &objh,sizeof(objh)); | |
113 if(stream_eof(demuxer->stream)) break; // EOF | |
114 endpos=pos+objh.size; | |
115 // for(i=0;i<16;i++) printf("%02X ",objh.guid[i]); | |
340 | 116 //printf("0x%08X [%s] %d\n",pos, asf_chunk_type(objh.guid),(int) objh.size); |
1 | 117 switch(*((unsigned int*)&objh.guid)){ |
118 case 0xB7DC0791: // guid_stream_header | |
119 stream_read(demuxer->stream,(char*) &streamh,sizeof(streamh)); | |
340 | 120 if(verbose){ |
1 | 121 printf("stream type: %s\n",asf_chunk_type(streamh.type)); |
122 printf("stream concealment: %s\n",asf_chunk_type(streamh.concealment)); | |
123 printf("type: %d bytes, stream: %d bytes ID: %d\n",(int)streamh.type_size,(int)streamh.stream_size,(int)streamh.stream_no); | |
124 printf("unk1: %lX unk2: %X\n",streamh.unk1,streamh.unk2); | |
125 printf("FILEPOS=0x%X\n",stream_tell(demuxer->stream)); | |
340 | 126 } |
1 | 127 // type-specific data: |
128 stream_read(demuxer->stream,(char*) buffer,streamh.type_size); | |
129 switch(*((unsigned int*)&streamh.type)){ | |
291 | 130 case 0xF8699E40: { // guid_audio_stream |
426 | 131 sh_audio_t* sh_audio=new_sh_audio(streamh.stream_no & 0x7F); |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
426
diff
changeset
|
132 sh_audio->wf=calloc((streamh.type_size<sizeof(WAVEFORMATEX))?sizeof(WAVEFORMATEX):streamh.type_size,1); |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
426
diff
changeset
|
133 memcpy(sh_audio->wf,buffer,streamh.type_size); |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
426
diff
changeset
|
134 if(verbose>=1) print_wave_header(sh_audio->wf); |
1 | 135 if((*((unsigned int*)&streamh.concealment))==0xbfc3cd50){ |
136 stream_read(demuxer->stream,(char*) buffer,streamh.stream_size); | |
137 asf_scrambling_h=buffer[0]; | |
138 asf_scrambling_w=(buffer[2]<<8)|buffer[1]; | |
139 asf_scrambling_b=(buffer[4]<<8)|buffer[3]; | |
140 asf_scrambling_w/=asf_scrambling_b; | |
141 } else { | |
142 asf_scrambling_b=asf_scrambling_h=asf_scrambling_w=1; | |
143 } | |
340 | 144 printf("ASF: audio scrambling: %d x %d x %d\n",asf_scrambling_h,asf_scrambling_w,asf_scrambling_b); |
426 | 145 //if(demuxer->audio->id==-1) demuxer->audio->id=streamh.stream_no & 0x7F; |
1 | 146 break; |
291 | 147 } |
148 case 0xBC19EFC0: { // guid_video_stream | |
426 | 149 sh_video_t* sh_video=new_sh_video(streamh.stream_no & 0x7F); |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
426
diff
changeset
|
150 int len=streamh.type_size-(4+4+1+2); |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
426
diff
changeset
|
151 // sh_video->bih=malloc(chunksize); memset(sh_video->bih,0,chunksize); |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
426
diff
changeset
|
152 sh_video->bih=calloc((len<sizeof(BITMAPINFOHEADER))?sizeof(BITMAPINFOHEADER):len,1); |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
426
diff
changeset
|
153 memcpy(sh_video->bih,&buffer[4+4+1+2],len); |
426 | 154 //sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; |
155 //sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
426
diff
changeset
|
156 if(verbose>=1) print_video_header(sh_video->bih); |
1 | 157 //asf_video_id=streamh.stream_no & 0x7F; |
426 | 158 //if(demuxer->video->id==-1) demuxer->video->id=streamh.stream_no & 0x7F; |
1 | 159 break; |
291 | 160 } |
1 | 161 } |
162 // stream-specific data: | |
163 // stream_read(demuxer->stream,(char*) buffer,streamh.stream_size); | |
164 break; | |
165 // case 0xD6E229D1: return "guid_header_2_0"; | |
166 case 0x8CABDCA1: // guid_file_header | |
167 stream_read(demuxer->stream,(char*) &fileh,sizeof(fileh)); | |
340 | 168 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); |
1 | 169 asf_packet=malloc(fileh.packetsize); // !!! |
170 break; | |
171 case 0x75b22636: // guid_data_chunk | |
172 avi_header.movi_start=stream_tell(demuxer->stream)+26; | |
173 avi_header.movi_end=endpos; | |
174 if(verbose>=1) printf("Found movie at 0x%X - 0x%X\n",avi_header.movi_start,avi_header.movi_end); | |
175 break; | |
176 | |
177 // case 0x33000890: return "guid_index_chunk"; | |
178 | |
179 } // switch GUID | |
180 if(!stream_seek(demuxer->stream,endpos)) break; | |
181 } // while EOF | |
182 | |
183 #if 0 | |
184 if(verbose){ | |
185 printf("ASF duration: %d\n",(int)fileh.duration); | |
186 printf("ASF start pts: %d\n",(int)fileh.start_timestamp); | |
187 printf("ASF end pts: %d\n",(int)fileh.end_timestamp); | |
188 } | |
189 #endif | |
190 | |
191 #endif | |
192 return 1; | |
193 } | |
194 |