annotate libmpdemux/demux_viv.c @ 2687:8c75a9a639c1

vivo demuxer
author arpi
date Sun, 04 Nov 2001 16:57:09 +0000
parents
children af8b2c0e4dad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
1 // VIVO file parser by A'rpi
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
2
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
3 #include <stdio.h>
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
4 #include <stdlib.h>
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
5 #include <unistd.h>
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
6
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
7 #include "config.h"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
8 #include "mp_msg.h"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
9 #include "help_mp.h"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
10
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
11 #include "stream.h"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
12 #include "demuxer.h"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
13 #include "stheader.h"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
14
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
15 #include "bswap.h"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
16
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
17 typedef struct {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
18 float fps;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
19 } vivo_priv_t;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
20
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
21 int vivo_check_file(demuxer_t* demuxer){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
22 int flags=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
23 int i=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
24 int len;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
25 int len2;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
26 int c;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
27 unsigned char buf[2048+256];
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
28 vivo_priv_t* priv;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
29
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
30 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for VIVO\n");
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
31
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
32 c=stream_read_char(demuxer->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
33 if(c) return 0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
34 len=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
35 while((c=stream_read_char(demuxer->stream))>=0x80){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
36 len+=0x80*(c-0x80);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
37 if(len>1024) return 0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
38 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
39 len+=c;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
40 printf("header block 1 size: %d\n",len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
41 //stream_skip(demuxer->stream,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
42 stream_read(demuxer->stream,buf,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
43 buf[len]=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
44 // printf("VIVO header: '%s'\n",buf);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
45
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
46 // parse header:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
47 i=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
48 while(i<len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
49 if(strncmp(buf+i,"Version:Vivo/1",14)) return 0; // bad version/type!
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
50
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
51 priv=malloc(sizeof(vivo_priv_t));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
52 memset(priv,0,sizeof(vivo_priv_t));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
53 demuxer->priv=priv;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
54
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
55 // TODO: parse FPS and other info (display title/author etc)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
56 priv->fps=10.0; // FIXME (parse from header)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
57
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
58 c=stream_read_char(demuxer->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
59 if(c) return 0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
60 len2=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
61 while((c=stream_read_char(demuxer->stream))>=0x80){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
62 len2+=0x80*(c-0x80);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
63 if(len+len2>2048) return 0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
64 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
65 len2+=c;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
66 printf("header block 2 size: %d\n",len2);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
67 stream_skip(demuxer->stream,len2);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
68 // stream_read(demuxer->stream,buf+len,len2);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
69
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
70 // c=stream_read_char(demuxer->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
71 // printf("first packet: %02X\n",c);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
72
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
73 return 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
74 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
75
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
76
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
77 // return value:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
78 // 0 = EOF or no stream found
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
79 // 1 = successfully read a packet
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
80 int demux_vivo_fill_buffer(demuxer_t *demux){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
81 demux_stream_t *ds=NULL;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
82 int c;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
83 int len=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
84 int seq;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
85 demux->filepos=stream_tell(demux->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
86
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
87 c=stream_read_char(demux->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
88 switch(c&0xF0){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
89 case 0x00: // header - skip it!
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
90 len=stream_read_char(demux->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
91 break;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
92 case 0x10: // video packet
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
93 len=128;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
94 ds=demux->video;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
95 break;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
96 case 0x20: // video packet
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
97 len=stream_read_char(demux->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
98 ds=demux->video;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
99 break;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
100 case 0x40: // audio packet
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
101 len=24;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
102 ds=demux->audio;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
103 break;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
104 default:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
105 mp_msg(MSGT_DEMUX,MSGL_WARN,"VIVO - unknown ID found: %02X contact author!\n",c);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
106 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
107
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
108 if(!ds){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
109 if(len) stream_skip(demux->stream,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
110 return 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
111 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
112
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
113 seq=c&0x0F;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
114
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
115 if(ds->asf_packet){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
116 if(ds->asf_seq!=seq){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
117 // closed segment, finalize packet:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
118 ds_add_packet(ds,ds->asf_packet);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
119 ds->asf_packet=NULL;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
120 } else {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
121 // append data to it!
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
122 demux_packet_t* dp=ds->asf_packet;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
123 dp->buffer=realloc(dp->buffer,dp->len+len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
124 //memcpy(dp->buffer+dp->len,data,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
125 stream_read(demux->stream,dp->buffer+dp->len,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
126 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
127 dp->len+=len;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
128 // we are ready now.
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
129 return 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
130 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
131 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
132 // create new packet:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
133 { demux_packet_t* dp;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
134 dp=new_demux_packet(len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
135 //memcpy(dp->buffer,data,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
136 stream_read(demux->stream,dp->buffer,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
137 // dp->pts=time*0.001f;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
138 // dp->flags=keyframe;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
139 // if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
140 dp->pos=demux->filepos;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
141 ds->asf_packet=dp;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
142 ds->asf_seq=seq;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
143 // we are ready now.
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
144 return 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
145 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
146
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
147 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
148
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
149 static const short h263_format[8][2] = {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
150 { 0, 0 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
151 { 128, 96 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
152 { 176, 144 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
153 { 352, 288 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
154 { 704, 576 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
155 { 1408, 1152 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
156 };
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
157
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
158 static unsigned char* buffer;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
159 static int bufptr=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
160 static int bitcnt=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
161 static unsigned char buf=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
162 static int format, width, height;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
163
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
164 static unsigned int x_get_bits(int n){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
165 unsigned int x=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
166 while(n-->0){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
167 if(!bitcnt){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
168 // fill buff
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
169 buf=buffer[bufptr++];
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
170 bitcnt=8;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
171 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
172 //x=(x<<1)|(buf&1);buf>>=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
173 x=(x<<1)|(buf>>7);buf<<=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
174 --bitcnt;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
175 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
176 return x;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
177 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
178
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
179 #define get_bits(xxx,n) x_get_bits(n)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
180 #define get_bits1(xxx) x_get_bits(1)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
181 #define skip_bits(xxx,n) x_get_bits(n)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
182 #define skip_bits1(xxx) x_get_bits(1)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
183
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
184 /* most is hardcoded. should extend to handle all h263 streams */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
185 static int h263_decode_picture_header(unsigned char *b_ptr)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
186 {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
187
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
188 buffer=b_ptr;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
189 bufptr=bitcnt=buf=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
190
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
191 /* picture header */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
192 if (get_bits(&s->gb, 22) != 0x20)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
193 return -1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
194 skip_bits(&s->gb, 8); /* picture timestamp */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
195
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
196 if (get_bits1(&s->gb) != 1)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
197 return -1; /* marker */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
198 if (get_bits1(&s->gb) != 0)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
199 return -1; /* h263 id */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
200 skip_bits1(&s->gb); /* split screen off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
201 skip_bits1(&s->gb); /* camera off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
202 skip_bits1(&s->gb); /* freeze picture release off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
203
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
204 format = get_bits(&s->gb, 3);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
205
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
206 if (format != 7) {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
207 printf("h263_plus = 0 format = %d\n",format);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
208 /* H.263v1 */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
209 width = h263_format[format][0];
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
210 height = h263_format[format][1];
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
211 printf("%d x %d\n",width,height);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
212 if (!width)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
213 return -1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
214
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
215 printf("pict_type=%d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
216 printf("unrestricted_mv=%d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
217 #if 1
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
218 printf("SAC: %d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
219 printf("advanced prediction mode: %d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
220 printf("PB frame: %d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
221 #else
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
222 if (get_bits1(&s->gb) != 0)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
223 return -1; /* SAC: off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
224 if (get_bits1(&s->gb) != 0)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
225 return -1; /* advanced prediction mode: off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
226 if (get_bits1(&s->gb) != 0)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
227 return -1; /* not PB frame */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
228 #endif
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
229 printf("qscale=%d\n",get_bits(&s->gb, 5));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
230 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
231 } else {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
232 printf("h263_plus = 1\n");
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
233 /* H.263v2 */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
234 if (get_bits(&s->gb, 3) != 1)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
235 return -1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
236 if (get_bits(&s->gb, 3) != 6) /* custom source format */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
237 return -1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
238 skip_bits(&s->gb, 12);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
239 skip_bits(&s->gb, 3);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
240 printf("pict_type=%d\n",get_bits(&s->gb, 3) + 1);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
241 // if (s->pict_type != I_TYPE &&
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
242 // s->pict_type != P_TYPE)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
243 // return -1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
244 skip_bits(&s->gb, 7);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
245 skip_bits(&s->gb, 4); /* aspect ratio */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
246 width = (get_bits(&s->gb, 9) + 1) * 4;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
247 skip_bits1(&s->gb);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
248 height = get_bits(&s->gb, 9) * 4;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
249 printf("%d x %d\n",width,height);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
250 if (height == 0)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
251 return -1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
252 printf("qscale=%d\n",get_bits(&s->gb, 5));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
253 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
254
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
255 /* PEI */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
256 while (get_bits1(&s->gb) != 0) {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
257 skip_bits(&s->gb, 8);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
258 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
259 // s->f_code = 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
260 // s->width = width;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
261 // s->height = height;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
262 return 0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
263 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
264
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
265
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
266 void demux_open_vivo(demuxer_t* demuxer){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
267 vivo_priv_t* priv=demuxer->priv;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
268
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
269 if(!ds_fill_buffer(demuxer->video)){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
270 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingVideoStreamBug);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
271 return;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
272 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
273
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
274 h263_decode_picture_header(demuxer->video->buffer);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
275
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
276
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
277 { sh_video_t* sh=new_sh_video(demuxer,0);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
278
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
279 sh->format=0x6f766976; // "vivo"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
280 if(!sh->fps) sh->fps=priv->fps;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
281 sh->frametime=1.0f/sh->fps;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
282 sh->disp_w=width; // FIXME
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
283 sh->disp_h=height;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
284
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
285 // emulate BITMAPINFOHEADER:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
286 sh->bih=malloc(sizeof(BITMAPINFOHEADER));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
287 memset(sh->bih,0,sizeof(BITMAPINFOHEADER));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
288 sh->bih->biSize=40;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
289 sh->bih->biWidth=sh->disp_w;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
290 sh->bih->biHeight=sh->disp_h;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
291 sh->bih->biPlanes=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
292 sh->bih->biBitCount=24;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
293 sh->bih->biCompression=sh->format;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
294 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight*3;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
295 demuxer->video->sh=sh; sh->ds=demuxer->video;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
296 demuxer->video->id=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
297 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
298
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
299 if(!ds_fill_buffer(demuxer->audio)){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
300 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingAudioStream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
301 } else
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
302 { sh_audio_t* sh=new_sh_audio(demuxer,1);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
303 sh->format=0x111; // 0x112
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
304 // Emulate WAVEFORMATEX struct:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
305 sh->wf=malloc(sizeof(WAVEFORMATEX));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
306 memset(sh->wf,0,sizeof(WAVEFORMATEX));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
307 sh->wf->nChannels=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
308 sh->wf->wBitsPerSample=16;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
309 sh->wf->nSamplesPerSec=22050;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
310 sh->wf->nAvgBytesPerSec=sh->wf->nChannels*sh->wf->wBitsPerSample*sh->wf->nSamplesPerSec/8;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
311 demuxer->audio->sh=sh; sh->ds=demuxer->audio;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
312 demuxer->audio->id=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
313 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
314
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
315
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
316 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
317