annotate TOOLS/asfinfo.c @ 36545:f0e92381681d

Add support for files with MLTI chunks. Fixes 06.rm and 08_lect_01.rm from FFmpeg trac #2152 Fixes also files from ftp://ftp.aduni.org/videos/ The patch has these limitations: - no multirate files with MLTI chunks - no mixed files (eg. MLTI for audio but not for video) - no MLTI for video together with non-ra audio (eg. ralf) - only DATA v0 (no v1, versions greater than 1 should not exist) Files with these feature shuld not really exist anyway. Also video MLTI files with only one stream are supported but untested
author rtogni
date Sun, 19 Jan 2014 15:12:46 +0000
parents 675679c82f5f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30416
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
1 /*
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
2 * This program is free software; you can redistribute it and/or modify
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
3 * it under the terms of the GNU General Public License as published by
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
4 * the Free Software Foundation; either version 2 of the License, or
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
5 * (at your option) any later version.
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
6 *
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
7 * This program is distributed in the hope that it will be useful,
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
10 * GNU General Public License for more details.
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
11 *
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
12 * You should have received a copy of the GNU General Public License along
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
13 * with this program; if not, write to the Free Software Foundation, Inc.,
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
15 */
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 27636
diff changeset
16
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 #define SAVE_STREAMS
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 // simple ASF header display program by A'rpi/ESP-team
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 // .asf fileformat docs from http://divx.euro.ru
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
25 typedef struct __attribute__((packed))
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 {
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
27 long biSize; // sizeof(BITMAPINFOHEADER)
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
28 long biWidth;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
29 long biHeight;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
30 short biPlanes; // unused
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
31 short biBitCount;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
32 long biCompression; // fourcc of image
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
33 long biSizeImage; // size of image. For uncompressed images
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
34 // ( biCompression 0 or 3 ) can be zero.
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
37 long biXPelsPerMeter; // unused
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
38 long biYPelsPerMeter; // unused
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
39 long biClrUsed; // valid only for palettized images.
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
40 // Number of colors in palette.
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
41 long biClrImportant;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 } BITMAPINFOHEADER;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 typedef struct
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 {
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
46 short wFormatTag; // value that identifies compression format
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
47 short nChannels;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
48 long nSamplesPerSec;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
49 long nAvgBytesPerSec;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
50 short nBlockAlign; // size of a data sample
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
51 short wBitsPerSample;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
52 short cbSize; // size of format-specific data
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 } WAVEFORMATEX;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 typedef struct __attribute__((packed)) {
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
56 unsigned char guid[16];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 unsigned long long size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 } ASF_obj_header_t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 typedef struct __attribute__((packed)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 ASF_obj_header_t objh;
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
62 unsigned int cno; // number of subchunks
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
63 unsigned char v1; // unknown (0x01)
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
64 unsigned char v2; // unknown (0x02)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 } ASF_header_t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 typedef struct __attribute__((packed)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 unsigned char client[16]; // Client GUID
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 unsigned long long file_size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 unsigned long long creat_time; //File creation time FILETIME 8
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 unsigned long long packets; //Number of packets UINT64 8
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 unsigned long long end_timestamp; //Timestamp of the end position UINT64 8
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 unsigned long long duration; //Duration of the playback UINT64 8
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 unsigned long start_timestamp; //Timestamp of the start position UINT32 4
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 unsigned long unk1; //Unknown, maybe reserved ( usually contains 0 ) UINT32 4
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 unsigned long flags; //Unknown, maybe flags ( usually contains 2 ) UINT32 4
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 unsigned long packetsize; //Size of packet, in bytes UINT32 4
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 unsigned long packetsize2; //Size of packet ( confirm ) UINT32 4
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 unsigned long frame_size; //Size of uncompressed video frame UINT32 4
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 } ASF_file_header_t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 typedef struct __attribute__((packed)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 unsigned char type[16]; // Stream type (audio/video) GUID 16
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 unsigned char concealment[16]; // Audio error concealment type GUID 16
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 unsigned long long unk1; // Unknown, maybe reserved ( usually contains 0 ) UINT64 8
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 unsigned long type_size; //Total size of type-specific data UINT32 4
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 unsigned long stream_size; //Size of stream-specific data UINT32 4
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 unsigned short stream_no; //Stream number UINT16 2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 unsigned long unk2; //Unknown UINT32 4
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 } ASF_stream_header_t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 typedef struct __attribute__((packed)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 unsigned char streamno;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 unsigned char seq;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 unsigned long x;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 unsigned char flag;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 } ASF_segmhdr_t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 ASF_header_t asfh;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 ASF_obj_header_t objh;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 ASF_file_header_t fileh;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 ASF_stream_header_t streamh;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 unsigned char buffer[8192];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107
26575
1ca484e74f18 Mark all functions that are only used within the file as static.
diego
parents: 25308
diff changeset
108 static char* chunk_type(unsigned char* guid){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 switch(*((unsigned int*)guid)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 case 0xF8699E40: return "guid_audio_stream";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 case 0xBC19EFC0: return "guid_video_stream";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 case 0x49f1a440: return "guid_audio_conceal_none";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 case 0xbfc3cd50: return "guid_audio_conceal_interleave";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 case 0x75B22630: return "guid_header";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 case 0x75b22636: return "guid_data_chunk";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 case 0x33000890: return "guid_index_chunk";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 case 0xB7DC0791: return "guid_stream_header";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 case 0xD6E229D1: return "guid_header_2_0";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 case 0x8CABDCA1: return "guid_file_header";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123
26575
1ca484e74f18 Mark all functions that are only used within the file as static.
diego
parents: 25308
diff changeset
124 static void print_wave_header(WAVEFORMATEX *h){
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
125 printf("======= WAVE Format =======\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
127 printf("Format Tag: %d (0x%X)\n", h->wFormatTag, h->wFormatTag);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
128 printf("Channels: %d\n", h->nChannels);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
129 printf("Samplerate: %ld\n", h->nSamplesPerSec);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
130 printf("avg byte/sec: %ld\n", h->nAvgBytesPerSec);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
131 printf("Block align: %d\n", h->nBlockAlign);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
132 printf("bits/sample: %d\n", h->wBitsPerSample);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
133 printf("cbSize: %d\n", h->cbSize);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
134
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 switch(h->wFormatTag){
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
136 case 0x01: printf("Audio in PCM format\n"); break;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
137 case 0x50: printf("Audio in MPEG Layer 1/2 format\n"); break;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
138 case 0x55: printf("Audio in MPEG Layer-3 format\n"); break; // ACM
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
139 case 0x02: printf("Audio in MS ADPCM format\n"); break; // ACM
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
140 case 0x11: printf("Audio in IMA ADPCM format\n"); break; // ACM
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
141 case 0x31:
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
142 case 0x32: printf("Audio in MS GSM 6.10 format\n"); break; // ACM
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
143 case 0x160:
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
144 case 0x161: printf("Audio in DivX WMA format\n"); break; // ACM
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
145 default: printf("Audio in UNKNOWN (id=0x%X) format\n", h->wFormatTag);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 printf("===========================\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150
26575
1ca484e74f18 Mark all functions that are only used within the file as static.
diego
parents: 25308
diff changeset
151 static void print_video_header(BITMAPINFOHEADER *h){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 printf("======= VIDEO Format ======\n");
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
153 printf(" biSize %ld\n", h->biSize);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
154 printf(" biWidth %ld\n", h->biWidth);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
155 printf(" biHeight %ld\n", h->biHeight);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
156 printf(" biPlanes %d\n", h->biPlanes);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
157 printf(" biBitCount %d\n", h->biBitCount);
32687
8bb538487b50 Fix printf format string warning
siretart
parents: 30633
diff changeset
158 printf(" biCompression %ld='%.4s'\n", h->biCompression, (const char*)&h->biCompression);
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
159 printf(" biSizeImage %ld\n", h->biSizeImage);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 printf("===========================\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 FILE* streams[128];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
165 int main(int argc, char* argv[]){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
166 FILE *f = fopen(argc > 1 ? argv[1] : "Alice Deejay - Back In My Life.asf", "rb");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
168 if(!f){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
169 printf("file not found\n");
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
170 exit(1);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
171 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
173 //printf("sizeof=%d\n", sizeof(objh));
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
174 //printf("sizeof=%d\n", sizeof(asfh));
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
176 fread(&asfh, sizeof(asfh), 1, f); // header obj
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
177 //for(i = 0; i < 16; i++)
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
178 // printf("%02X ", asfh.objh.guid[i]);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
179 printf("[%s] %d (subchunks: %d)\n", chunk_type(asfh.objh.guid),
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
180 (int) asfh.objh.size, asfh.cno);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
182 while(fread(&objh, sizeof(objh), 1, f) > 0){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
183 int pos = ftell(f);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
184 //for(i = 0; i < 16; i++)
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
185 // printf("%02X ", objh.guid[i]);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
186 printf("0x%08X [%s] %d\n", pos-sizeof(objh), chunk_type(objh.guid),
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
187 (int) objh.size);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
188 switch(*((unsigned int*)&objh.guid)){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
189 case 0xB7DC0791: // guid_stream_header
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
190 fread(&streamh, sizeof(streamh), 1, f);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
191 printf("stream type: %s\n", chunk_type(streamh.type));
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
192 printf("stream concealment: %s\n", chunk_type(streamh.concealment));
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
193 printf("type: %d bytes, stream: %d bytes ID: %d\n",
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
194 (int)streamh.type_size, (int)streamh.stream_size,
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
195 (int)streamh.stream_no);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
196 printf("FILEPOS=0x%lX\n", ftell(f));
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
197 // type-specific data:
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
198 fread(buffer,streamh.type_size,1,f);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
199 switch(*((unsigned int*)&streamh.type)){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
200 case 0xF8699E40: // guid_audio_stream
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
201 print_wave_header((WAVEFORMATEX*)buffer);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
202 break;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
203 case 0xBC19EFC0: // guid_video_stream
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
204 print_video_header((BITMAPINFOHEADER*)&buffer[4 + 4 + 1 + 2]);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
205 break;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
206 }
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
207 // stream-specific data:
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
208 fread(buffer, streamh.stream_size, 1, f);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 break;
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
210 //case 0xD6E229D1:
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
211 // return "guid_header_2_0";
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
212 case 0x8CABDCA1: // guid_file_header
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
213 fread(&fileh, sizeof(fileh), 1, f);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
214 printf("packets: %d flags: %d pack_size: %d frame_size: %d\n",
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
215 (int)fileh.packets, (int)fileh.flags, (int)fileh.packetsize,
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
216 (int)fileh.frame_size);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 break;
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
218 case 0x75b22636: // guid_data_chunk
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
219 { int endp = pos + objh.size - sizeof(objh);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
220 unsigned char* packet = malloc((int)fileh.packetsize);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
221 int fpos;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
222 fseek(f, 26, SEEK_CUR);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
223 while((fpos = ftell(f)) < endp){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
224 fread(packet, (int)fileh.packetsize, 1, f);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
225 if(packet[0] == 0x82){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
226 unsigned char flags = packet[3];
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
227 unsigned char* p = &packet[5];
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
228 unsigned long time;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
229 unsigned short duration;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
230 int segs = 1;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
231 int seg;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
232 int padding=0;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
233 if(flags & 8){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
234 padding = p[0];
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
235 ++p;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
236 } else
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
237 if(flags & 16){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
238 padding = p[0] | (p[1] << 8);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
239 p += 2;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
240 }
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
241 time = *((unsigned long*)p);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
242 p += 4;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
243 duration = *((unsigned short*)p);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
244 p += 2;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
245 if(flags & 1){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
246 segs = p[0] - 0x80;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
247 ++p;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
248 }
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
249 printf("%08X: flag=%02X segs=%d pad=%d time=%ld dur=%d\n",
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
250 fpos, flags, segs, padding, time, duration);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
251 for(seg = 0; seg < segs; seg++){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
252 ASF_segmhdr_t* sh = (ASF_segmhdr_t*)p;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
253 int len = 0;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
254 p += sizeof(ASF_segmhdr_t);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
255 if(sh->flag & 8) p+=8;// else
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
256 if(sh->flag & 1) ++p;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
257 if(flags & 1){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
258 len = *((unsigned short*)p);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
259 p += 2;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
260 }
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
261 printf(" seg #%d: streamno=%d seq=%d flag=%02X len=%d\n",
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
262 seg, sh->streamno&0x7F, sh->seq, sh->flag, len);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
263 #ifdef SAVE_STREAMS
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
264 if(!streams[sh->streamno & 0x7F]){
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
265 char name[256];
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
266 snprintf(name, 256, "stream%02X.dat", sh->streamno & 0x7F);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
267 streams[sh->streamno & 0x7F] = fopen(name, "wb");
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
268 }
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
269 fwrite(p, len, 1, streams[sh->streamno & 0x7F]);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
270 #endif
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
271 p += len;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
272 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 } else
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
274 printf("%08X: UNKNOWN %02X %02X %02X %02X %02X...\n", fpos,
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
275 packet[0], packet[1], packet[2], packet[3], packet[4]);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
276 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 }
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
278 break;
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
279
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
280 //case 0x33000890:
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
281 // return "guid_index_chunk";
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
283 }
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
284 fseek(f, pos + objh.size - sizeof(objh), SEEK_SET);
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
285 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286
32688
675679c82f5f add missing fclose
siretart
parents: 32687
diff changeset
287 fclose(f);
27636
b45a3ae01e54 cosmetics: prettyprinting
diego
parents: 26575
diff changeset
288 return 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 }