comparison TOOLS/vivodump.c @ 2665:e8d949b1bc5d

dump h263 frame headers from vivo
author arpi
date Sun, 04 Nov 2001 00:00:38 +0000
parents
children a17fcca740ff
comparison
equal deleted inserted replaced
2664:f23882410024 2665:e8d949b1bc5d
1 #include <stdio.h>
2
3 static const short h263_format[8][2] = {
4 { 0, 0 },
5 { 128, 96 },
6 { 176, 144 },
7 { 352, 288 },
8 { 704, 576 },
9 { 1408, 1152 },
10 };
11
12 unsigned char* buffer;
13 int bufptr=0;
14 int bitcnt=0;
15 unsigned char buf=0;
16
17 unsigned int x_get_bits(int n){
18 unsigned int x=0;
19 while(n-->0){
20 if(!bitcnt){
21 // fill buff
22 buf=buffer[bufptr++];
23 bitcnt=8;
24 }
25 //x=(x<<1)|(buf&1);buf>>=1;
26 x=(x<<1)|(buf>>7);buf<<=1;
27 --bitcnt;
28 }
29 return x;
30 }
31
32 #define get_bits(xxx,n) x_get_bits(n)
33 #define get_bits1(xxx) x_get_bits(1)
34 #define skip_bits(xxx,n) x_get_bits(n)
35 #define skip_bits1(xxx) x_get_bits(1)
36
37 /* most is hardcoded. should extend to handle all h263 streams */
38 int h263_decode_picture_header(unsigned char *b_ptr)
39 {
40 int format, width, height;
41
42 buffer=b_ptr;
43 bufptr=bitcnt=buf=0;
44
45 /* picture header */
46 if (get_bits(&s->gb, 22) != 0x20)
47 return -1;
48 skip_bits(&s->gb, 8); /* picture timestamp */
49
50 if (get_bits1(&s->gb) != 1)
51 return -1; /* marker */
52 if (get_bits1(&s->gb) != 0)
53 return -1; /* h263 id */
54 skip_bits1(&s->gb); /* split screen off */
55 skip_bits1(&s->gb); /* camera off */
56 skip_bits1(&s->gb); /* freeze picture release off */
57
58 format = get_bits(&s->gb, 3);
59
60 if (format != 7) {
61 printf("h263_plus = 0 format = %d\n",format);
62 /* H.263v1 */
63 width = h263_format[format][0];
64 height = h263_format[format][1];
65 printf("%d x %d\n",width,height);
66 if (!width)
67 return -1;
68
69 printf("pict_type=%d\n",get_bits1(&s->gb));
70 printf("unrestricted_mv=%d\n",get_bits1(&s->gb));
71 #if 1
72 printf("SAC: %d\n",get_bits1(&s->gb));
73 printf("advanced prediction mode: %d\n",get_bits1(&s->gb));
74 printf("PB frame: %d\n",get_bits1(&s->gb));
75 #else
76 if (get_bits1(&s->gb) != 0)
77 return -1; /* SAC: off */
78 if (get_bits1(&s->gb) != 0)
79 return -1; /* advanced prediction mode: off */
80 if (get_bits1(&s->gb) != 0)
81 return -1; /* not PB frame */
82 #endif
83 printf("qscale=%d\n",get_bits(&s->gb, 5));
84 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
85 } else {
86 printf("h263_plus = 1\n");
87 /* H.263v2 */
88 if (get_bits(&s->gb, 3) != 1)
89 return -1;
90 if (get_bits(&s->gb, 3) != 6) /* custom source format */
91 return -1;
92 skip_bits(&s->gb, 12);
93 skip_bits(&s->gb, 3);
94 printf("pict_type=%d\n",get_bits(&s->gb, 3) + 1);
95 // if (s->pict_type != I_TYPE &&
96 // s->pict_type != P_TYPE)
97 // return -1;
98 skip_bits(&s->gb, 7);
99 skip_bits(&s->gb, 4); /* aspect ratio */
100 width = (get_bits(&s->gb, 9) + 1) * 4;
101 skip_bits1(&s->gb);
102 height = get_bits(&s->gb, 9) * 4;
103 printf("%d x %d\n",width,height);
104 if (height == 0)
105 return -1;
106 printf("qscale=%d\n",get_bits(&s->gb, 5));
107 }
108
109 /* PEI */
110 while (get_bits1(&s->gb) != 0) {
111 skip_bits(&s->gb, 8);
112 }
113 // s->f_code = 1;
114 // s->width = width;
115 // s->height = height;
116 return 0;
117 }
118
119
120 int main(){
121 int c;
122 unsigned int head=-1;
123 int pos=0;
124
125 while((c=getchar())>=0){
126 ++pos;
127 head=(head<<8)|c;
128 if((head&0xFFFFFF)==0x80){
129 unsigned char buf[33];
130 int i;
131 buf[0]=buf[1]=0; buf[2]=0x80;
132 printf("%08X: 00 00 80",pos);
133 for(i=0;i<30;i++){
134 c=getchar();++pos;
135 printf(" %02X",c);
136 buf[3+i]=c;
137 }
138 printf("\n");
139 h263_decode_picture_header(buf);
140 }
141 }
142
143
144 }