annotate libmpdemux/demux_viv.c @ 2743:1438574ccdc3

dvb test, /dev/ost/video: Check for character device (-c) instead of file existance (-e), the -e test is not available on solaris' /bin/sh.
author jkeil
date Tue, 06 Nov 2001 16:56:27 +0000
parents af8b2c0e4dad
children 6caec0df4189
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
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
49 if(strncmp(buf+i,"Version:Vivo/",13)) return 0; // bad version/type!
2687
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
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
58 #if 0
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
59 c=stream_read_char(demuxer->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
60 if(c) return 0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
61 len2=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
62 while((c=stream_read_char(demuxer->stream))>=0x80){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
63 len2+=0x80*(c-0x80);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
64 if(len+len2>2048) return 0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
65 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
66 len2+=c;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
67 printf("header block 2 size: %d\n",len2);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
68 stream_skip(demuxer->stream,len2);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
69 // stream_read(demuxer->stream,buf+len,len2);
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
70 #endif
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
71
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
72 // c=stream_read_char(demuxer->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
73 // printf("first packet: %02X\n",c);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
74
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
75 return 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
76 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
77
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
78
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
79 // return value:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
80 // 0 = EOF or no stream found
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
81 // 1 = successfully read a packet
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
82 int demux_vivo_fill_buffer(demuxer_t *demux){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
83 demux_stream_t *ds=NULL;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
84 int c;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
85 int len=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
86 int seq;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
87 demux->filepos=stream_tell(demux->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
88
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
89 c=stream_read_char(demux->stream);
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
90 // printf("c=%02X\n",c);
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
91 switch(c&0xF0){
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
92 case 0x00: // header - skip it!
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
93 len=stream_read_char(demux->stream);
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
94 // printf("header: %02X\n",len);
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
95 if(len>=0x80) len=0x80*(len-0x80)+stream_read_char(demux->stream);
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
96 printf("vivo extra header: %d bytes\n",len);
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
97 break;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
98 case 0x10: // video packet
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
99 len=128;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
100 ds=demux->video;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
101 break;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
102 case 0x20: // video packet
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
103 len=stream_read_char(demux->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
104 ds=demux->video;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
105 break;
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
106 case 0x30: // audio ?
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
107 len=0x28;
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
108 ds=demux->audio;
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
109 break;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
110 case 0x40: // audio packet
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
111 len=24;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
112 ds=demux->audio;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
113 break;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
114 default:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
115 mp_msg(MSGT_DEMUX,MSGL_WARN,"VIVO - unknown ID found: %02X contact author!\n",c);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
116 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
117
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
118 if(!ds || ds->id<-1){
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
119 if(len) stream_skip(demux->stream,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
120 return 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
121 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
122
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
123 seq=c&0x0F;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
124
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
125 if(ds->asf_packet){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
126 if(ds->asf_seq!=seq){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
127 // closed segment, finalize packet:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
128 ds_add_packet(ds,ds->asf_packet);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
129 ds->asf_packet=NULL;
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
130 // printf("packet!\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
131 } else {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
132 // append data to it!
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
133 demux_packet_t* dp=ds->asf_packet;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
134 dp->buffer=realloc(dp->buffer,dp->len+len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
135 //memcpy(dp->buffer+dp->len,data,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
136 stream_read(demux->stream,dp->buffer+dp->len,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
137 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
138 dp->len+=len;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
139 // we are ready now.
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
140 if((c&0xF0)==0x20) --ds->asf_seq; // hack!
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
141 return 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
142 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
143 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
144 // create new packet:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
145 { demux_packet_t* dp;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
146 dp=new_demux_packet(len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
147 //memcpy(dp->buffer,data,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
148 stream_read(demux->stream,dp->buffer,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
149 // dp->pts=time*0.001f;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
150 // dp->flags=keyframe;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
151 // if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
152 dp->pos=demux->filepos;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
153 ds->asf_packet=dp;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
154 ds->asf_seq=seq;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
155 // we are ready now.
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
156 return 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
157 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
158
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
159 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
160
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
161 static const short h263_format[8][2] = {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
162 { 0, 0 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
163 { 128, 96 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
164 { 176, 144 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
165 { 352, 288 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
166 { 704, 576 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
167 { 1408, 1152 },
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
168 { 320, 240 } // ???????
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
169 };
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
170
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
171 static unsigned char* buffer;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
172 static int bufptr=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
173 static int bitcnt=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
174 static unsigned char buf=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
175 static int format, width, height;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
176
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
177 static unsigned int x_get_bits(int n){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
178 unsigned int x=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
179 while(n-->0){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
180 if(!bitcnt){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
181 // fill buff
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
182 buf=buffer[bufptr++];
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
183 bitcnt=8;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
184 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
185 //x=(x<<1)|(buf&1);buf>>=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
186 x=(x<<1)|(buf>>7);buf<<=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
187 --bitcnt;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
188 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
189 return x;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
190 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
191
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
192 #define get_bits(xxx,n) x_get_bits(n)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
193 #define get_bits1(xxx) x_get_bits(1)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
194 #define skip_bits(xxx,n) x_get_bits(n)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
195 #define skip_bits1(xxx) x_get_bits(1)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
196
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
197 /* most is hardcoded. should extend to handle all h263 streams */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
198 static int h263_decode_picture_header(unsigned char *b_ptr)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
199 {
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
200 int i;
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
201
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
202 // for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
203
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
204 buffer=b_ptr;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
205 bufptr=bitcnt=buf=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
206
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
207 /* picture header */
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
208 if (get_bits(&s->gb, 22) != 0x20){
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
209 printf("bad picture header\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
210 return -1;
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
211 }
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
212 skip_bits(&s->gb, 8); /* picture timestamp */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
213
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
214 if (get_bits1(&s->gb) != 1){
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
215 printf("bad marker\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
216 return -1; /* marker */
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
217 }
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
218 if (get_bits1(&s->gb) != 0){
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
219 printf("bad h263 id\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
220 return -1; /* h263 id */
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
221 }
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
222 skip_bits1(&s->gb); /* split screen off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
223 skip_bits1(&s->gb); /* camera off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
224 skip_bits1(&s->gb); /* freeze picture release off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
225
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
226 format = get_bits(&s->gb, 3);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
227
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
228 if (format != 7) {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
229 printf("h263_plus = 0 format = %d\n",format);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
230 /* H.263v1 */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
231 width = h263_format[format][0];
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
232 height = h263_format[format][1];
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
233 printf("%d x %d\n",width,height);
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
234 // if (!width) return -1;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
235
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
236 printf("pict_type=%d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
237 printf("unrestricted_mv=%d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
238 #if 1
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
239 printf("SAC: %d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
240 printf("advanced prediction mode: %d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
241 printf("PB frame: %d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
242 #else
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
243 if (get_bits1(&s->gb) != 0)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
244 return -1; /* SAC: off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
245 if (get_bits1(&s->gb) != 0)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
246 return -1; /* advanced prediction mode: off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
247 if (get_bits1(&s->gb) != 0)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
248 return -1; /* not PB frame */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
249 #endif
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
250 printf("qscale=%d\n",get_bits(&s->gb, 5));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
251 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
252 } else {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
253 printf("h263_plus = 1\n");
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
254 /* H.263v2 */
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
255 if (get_bits(&s->gb, 3) != 1){
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
256 printf("H.263v2 A error\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
257 return -1;
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
258 }
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
259 if (get_bits(&s->gb, 3) != 6){ /* custom source format */
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
260 printf("custom source format\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
261 return -1;
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
262 }
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
263 skip_bits(&s->gb, 12);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
264 skip_bits(&s->gb, 3);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
265 printf("pict_type=%d\n",get_bits(&s->gb, 3) + 1);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
266 // if (s->pict_type != I_TYPE &&
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
267 // s->pict_type != P_TYPE)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
268 // return -1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
269 skip_bits(&s->gb, 7);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
270 skip_bits(&s->gb, 4); /* aspect ratio */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
271 width = (get_bits(&s->gb, 9) + 1) * 4;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
272 skip_bits1(&s->gb);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
273 height = get_bits(&s->gb, 9) * 4;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
274 printf("%d x %d\n",width,height);
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
275 //if (height == 0)
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
276 // return -1;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
277 printf("qscale=%d\n",get_bits(&s->gb, 5));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
278 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
279
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
280 /* PEI */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
281 while (get_bits1(&s->gb) != 0) {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
282 skip_bits(&s->gb, 8);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
283 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
284 // s->f_code = 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
285 // s->width = width;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
286 // s->height = height;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
287 return 0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
288 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
289
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
290
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
291
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
292 void demux_open_vivo(demuxer_t* demuxer){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
293 vivo_priv_t* priv=demuxer->priv;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
294
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
295 if(!ds_fill_buffer(demuxer->video)){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
296 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingVideoStreamBug);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
297 return;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
298 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
299
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
300 h263_decode_picture_header(demuxer->video->buffer);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
301
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
302
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
303 { sh_video_t* sh=new_sh_video(demuxer,0);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
304
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
305 sh->format=0x6f766976; // "vivo"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
306 if(!sh->fps) sh->fps=priv->fps;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
307 sh->frametime=1.0f/sh->fps;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
308 sh->disp_w=width; // FIXME
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
309 sh->disp_h=height;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
310
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
311 // emulate BITMAPINFOHEADER:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
312 sh->bih=malloc(sizeof(BITMAPINFOHEADER));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
313 memset(sh->bih,0,sizeof(BITMAPINFOHEADER));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
314 sh->bih->biSize=40;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
315 sh->bih->biWidth=sh->disp_w;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
316 sh->bih->biHeight=sh->disp_h;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
317 sh->bih->biPlanes=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
318 sh->bih->biBitCount=24;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
319 sh->bih->biCompression=sh->format;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
320 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight*3;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
321 demuxer->video->sh=sh; sh->ds=demuxer->video;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
322 demuxer->video->id=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
323 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
324
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
325 if(demuxer->audio->id>=-1){
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
326 if(!ds_fill_buffer(demuxer->audio)){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
327 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingAudioStream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
328 } else
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
329 { sh_audio_t* sh=new_sh_audio(demuxer,1);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
330 sh->format=0x111; // 0x112
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
331 // Emulate WAVEFORMATEX struct:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
332 sh->wf=malloc(sizeof(WAVEFORMATEX));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
333 memset(sh->wf,0,sizeof(WAVEFORMATEX));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
334 sh->wf->nChannels=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
335 sh->wf->wBitsPerSample=16;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
336 sh->wf->nSamplesPerSec=22050;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
337 sh->wf->nAvgBytesPerSec=sh->wf->nChannels*sh->wf->wBitsPerSample*sh->wf->nSamplesPerSec/8;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
338 demuxer->audio->sh=sh; sh->ds=demuxer->audio;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
339 demuxer->audio->id=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
340 }
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
341 }
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
342
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
343 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
344