build/vdpau: drop support for dynamic loading of libvdpau
[mplayer/glamo.git] / TOOLS / vivodump.c
blob8ee091509968d36ccc5a0de288d52b93211dfa01
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <inttypes.h>
6 #include "loader/wine/mmreg.h"
7 #include "loader/wine/vfw.h"
9 #include "stream/stream.h"
10 #include "libmpdemux/muxer.h"
11 #include "libmpdemux/demuxer.h"
13 /* linking hacks */
14 char *info_name;
15 char *info_artist;
16 char *info_genre;
17 char *info_subject;
18 char *info_copyright;
19 char *info_sourceform;
20 char *info_comment;
22 char* out_filename = NULL;
23 char* force_fourcc=NULL;
24 char* passtmpfile="divx2pass.log";
26 static const short h263_format[8][2] = {
27 { 0, 0 },
28 { 128, 96 },
29 { 176, 144 },
30 { 352, 288 },
31 { 704, 576 },
32 { 1408, 1152 },
33 { 320, 240 }
36 unsigned char* buffer;
37 int bufptr=0;
38 int bitcnt=0;
39 unsigned char buf=0;
41 static unsigned int x_get_bits(int n){
42 unsigned int x=0;
43 while(n-->0){
44 if(!bitcnt){
45 // fill buff
46 buf=buffer[bufptr++];
47 bitcnt=8;
49 //x=(x<<1)|(buf&1);buf>>=1;
50 x=(x<<1)|(buf>>7);buf<<=1;
51 --bitcnt;
53 return x;
56 #define get_bits(xxx,n) x_get_bits(n)
57 #define get_bits1(xxx) x_get_bits(1)
58 #define skip_bits(xxx,n) x_get_bits(n)
59 #define skip_bits1(xxx) x_get_bits(1)
61 int format;
62 int width=320;
63 int height=240;
65 /* most is hardcoded. should extend to handle all h263 streams */
66 static int h263_decode_picture_header(unsigned char *b_ptr)
68 int i;
70 for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n");
72 buffer=b_ptr;
73 bufptr=bitcnt=buf=0;
75 /* picture header */
76 if (get_bits(&s->gb, 22) != 0x20){
77 printf("bad picture header\n");
78 return -1;
80 skip_bits(&s->gb, 8); /* picture timestamp */
82 if (get_bits1(&s->gb) != 1){
83 printf("bad marker\n");
84 return -1; /* marker */
86 if (get_bits1(&s->gb) != 0){
87 printf("bad h263 id\n");
88 return -1; /* h263 id */
90 skip_bits1(&s->gb); /* split screen off */
91 skip_bits1(&s->gb); /* camera off */
92 skip_bits1(&s->gb); /* freeze picture release off */
94 format = get_bits(&s->gb, 3);
96 if (format != 7) {
97 printf("h263_plus = 0 format = %d\n",format);
98 /* H.263v1 */
99 width = h263_format[format][0];
100 height = h263_format[format][1];
101 printf("%d x %d\n",width,height);
102 // if (!width) return -1;
104 printf("pict_type=%d\n",get_bits1(&s->gb));
105 printf("unrestricted_mv=%d\n",get_bits1(&s->gb));
106 #if 1
107 printf("SAC: %d\n",get_bits1(&s->gb));
108 printf("advanced prediction mode: %d\n",get_bits1(&s->gb));
109 printf("PB frame: %d\n",get_bits1(&s->gb));
110 #else
111 if (get_bits1(&s->gb) != 0)
112 return -1; /* SAC: off */
113 if (get_bits1(&s->gb) != 0)
114 return -1; /* advanced prediction mode: off */
115 if (get_bits1(&s->gb) != 0)
116 return -1; /* not PB frame */
117 #endif
118 printf("qscale=%d\n",get_bits(&s->gb, 5));
119 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
120 } else {
121 printf("h263_plus = 1\n");
122 /* H.263v2 */
123 if (get_bits(&s->gb, 3) != 1){
124 printf("H.263v2 A error\n");
125 return -1;
127 if (get_bits(&s->gb, 3) != 6){ /* custom source format */
128 printf("custom source format\n");
129 return -1;
131 skip_bits(&s->gb, 12);
132 skip_bits(&s->gb, 3);
133 printf("pict_type=%d\n",get_bits(&s->gb, 3) + 1);
134 // if (s->pict_type != I_TYPE &&
135 // s->pict_type != P_TYPE)
136 // return -1;
137 skip_bits(&s->gb, 7);
138 skip_bits(&s->gb, 4); /* aspect ratio */
139 width = (get_bits(&s->gb, 9) + 1) * 4;
140 skip_bits1(&s->gb);
141 height = get_bits(&s->gb, 9) * 4;
142 printf("%d x %d\n",width,height);
143 //if (height == 0)
144 // return -1;
145 printf("qscale=%d\n",get_bits(&s->gb, 5));
148 /* PEI */
149 while (get_bits1(&s->gb) != 0) {
150 skip_bits(&s->gb, 8);
152 // s->f_code = 1;
153 // s->width = width;
154 // s->height = height;
155 return 0;
158 int postable[32768];
160 int main(int argc,char ** argv){
161 int c;
162 FILE *f;
163 FILE *f2;
164 muxer_t* avi;
165 muxer_stream_t* mux;
166 //unsigned char* buffer=malloc(0x200000);
167 int i,len;
168 int v_id=0;
169 int flag2=0;
170 int prefix=0;
172 // check if enough args were given
173 if ( argc < 3 ){
174 printf("Too few arguments given!\n"
175 "Usage: %s <input_file> <output_file>\n", argv[0]);
177 return -1;
179 // input
180 if(!(f=fopen(argv[1],"rb"))){
181 printf("Couldn't open input file.\n");
182 return -1;
184 // output
185 if(!(f2=fopen(argv[2],"wb"))){
186 printf("Couldn't open output file.\n");
187 return -1;
190 avi=muxer_new_muxer(MUXER_TYPE_AVI,f2);
191 mux=muxer_new_stream(avi,MUXER_TYPE_VIDEO);
193 mux->buffer_size=0x200000;
194 mux->buffer=malloc(mux->buffer_size);
196 mux->h.dwScale=1;
197 mux->h.dwRate=10;
199 mux->bih=malloc(sizeof(BITMAPINFOHEADER));
200 mux->bih->biSize=sizeof(BITMAPINFOHEADER);
201 mux->bih->biPlanes=1;
202 mux->bih->biBitCount=24;
203 mux->bih->biCompression=0x6f766976;// 7669766f;
204 muxer_write_header(avi);
207 c=fgetc(f); if(c) printf("error! not vivo file?\n");
208 len=0;
209 while((c=fgetc(f))>=0x80) len+=0x80*(c&0x0F);
210 len+=c;
211 printf("hdr1: %d\n",len);
212 for(i=0;i<len;i++) fgetc(f);
215 while((c=fgetc(f))>=0){
217 printf("%08lX %02X\n",ftell(f),c);
219 prefix=0;
220 if(c==0x82){
221 prefix=1;
222 //continue;
223 c=fgetc(f);
224 printf("%08lX %02X\n",ftell(f),c);
227 if(c==0x00){
228 // header
229 int len=0;
230 while((c=fgetc(f))>=0x80) len+=0x80*(c&0x0F);
231 len+=c;
232 printf("header: 00 (%d)\n",len);
233 for(i=0;i<len;i++) fgetc(f);
234 continue;
237 if((c&0xF0)==0x40){
238 // audio
239 len=24;
240 if(prefix) len=fgetc(f);
241 printf("audio: %02X (%d)\n",c,len);
242 for(i=0;i<len;i++) fgetc(f);
243 continue;
245 if((c&0xF0)==0x30){
246 // audio
247 len=40;
248 if(prefix) len=fgetc(f);
249 printf("audio: %02X (%d)\n",c,len);
250 for(i=0;i<len;i++) fgetc(f);
251 continue;
253 if(flag2 || (((c&0xF0)==0x10 || (c&0xF0)==0x20) && (c&0x0F)!=(v_id&0xF))){
254 // end of frame:
255 printf("Frame size: %d\n",mux->buffer_len);
256 h263_decode_picture_header(mux->buffer);
257 muxer_write_chunk(mux,mux->buffer_len,0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
258 mux->buffer_len=0;
260 if((v_id&0xF0)==0x10) fprintf(stderr,"hmm. last video packet %02X\n",v_id);
262 flag2=0;
263 if((c&0xF0)==0x10){
264 // 128 byte
265 len=128;
266 if(prefix) len=fgetc(f);
267 printf("video: %02X (%d)\n",c,len);
268 fread(mux->buffer+mux->buffer_len,len,1,f);
269 mux->buffer_len+=len;
270 v_id=c;
271 continue;
273 if((c&0xF0)==0x20){
274 int len=fgetc(f);
275 printf("video: %02X (%d)\n",c,len);
276 fread(mux->buffer+mux->buffer_len,len,1,f);
277 mux->buffer_len+=len;
278 flag2=1;
279 v_id=c;
280 continue;
282 printf("error: %02X!\n",c);
283 exit(1);
286 if(!width) width=320;
287 if(!height) height=240;
289 mux->bih->biWidth=width;
290 mux->bih->biHeight=height;
291 mux->bih->biSizeImage=3*width*height;
293 muxer_write_index(avi);
294 fseek(f2,0,SEEK_SET);
295 muxer_write_header(avi);
297 return 0;