Mercurial > mplayer.hg
annotate dec_video.c @ 1398:10e236ceac5e
update to perl debconf. fixed problem with configure.
author | eyck |
---|---|
date | Sat, 28 Jul 2001 07:54:52 +0000 |
parents | dbcb5b5e1fae |
children | c11f2a77ff70 |
rev | line source |
---|---|
1294 | 1 |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 | |
5 #include "config.h" | |
6 | |
7 extern int verbose; // defined in mplayer.c | |
8 extern int divx_quality; | |
9 | |
10 extern double video_time_usage; | |
11 extern double vout_time_usage; | |
12 | |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
13 extern int frameratecode2framerate[16]; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
14 |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1309
diff
changeset
|
15 #include "linux/timer.h" |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1309
diff
changeset
|
16 |
1294 | 17 #include "stream.h" |
18 #include "demuxer.h" | |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
19 #include "parse_es.h" |
1294 | 20 |
21 #include "wine/mmreg.h" | |
22 #include "wine/avifmt.h" | |
23 #include "wine/vfw.h" | |
24 | |
25 #include "codec-cfg.h" | |
26 #include "stheader.h" | |
27 | |
28 //#include <inttypes.h> | |
29 //#include "libvo/img_format.h" | |
30 | |
31 #include "libvo/video_out.h" | |
32 | |
33 #include "libmpeg2/mpeg2.h" | |
34 #include "libmpeg2/mpeg2_internal.h" | |
35 | |
36 extern picture_t *picture; // exported from libmpeg2/decode.c | |
37 | |
1297 | 38 extern int init_video_codec(sh_video_t *sh_video,int ex); |
1294 | 39 |
40 #ifdef USE_DIRECTSHOW | |
41 #include "loader/DirectShow/DS_VideoDec.h" | |
42 #endif | |
43 | |
44 #ifdef USE_LIBAVCODEC | |
45 #include "libavcodec/avcodec.h" | |
46 AVCodec *lavc_codec=NULL; | |
47 AVCodecContext lavc_context; | |
48 AVPicture lavc_picture; | |
49 #endif | |
50 | |
1349 | 51 #ifndef NEW_DECORE |
1294 | 52 #include "opendivx/decore.h" |
1349 | 53 #else |
54 #include <decore.h> | |
55 #endif | |
1294 | 56 |
57 //**************************************************************************// | |
58 // The OpenDivX stuff: | |
59 //**************************************************************************// | |
60 | |
61 #ifndef NEW_DECORE | |
62 | |
63 static unsigned char *opendivx_src[3]; | |
64 static int opendivx_stride[3]; | |
65 | |
66 // callback, the opendivx decoder calls this for each frame: | |
67 void convert_linux(unsigned char *puc_y, int stride_y, | |
68 unsigned char *puc_u, unsigned char *puc_v, int stride_uv, | |
69 unsigned char *bmp, int width_y, int height_y){ | |
70 | |
71 // printf("convert_yuv called %dx%d stride: %d,%d\n",width_y,height_y,stride_y,stride_uv); | |
72 | |
73 opendivx_src[0]=puc_y; | |
74 opendivx_src[1]=puc_u; | |
75 opendivx_src[2]=puc_v; | |
76 | |
77 opendivx_stride[0]=stride_y; | |
78 opendivx_stride[1]=stride_uv; | |
79 opendivx_stride[2]=stride_uv; | |
80 } | |
81 #endif | |
82 | |
83 | |
84 int init_video(sh_video_t *sh_video){ | |
85 unsigned int out_fmt=sh_video->codec->outfmt[sh_video->outfmtidx]; | |
86 | |
87 switch(sh_video->codec->driver){ | |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
88 #ifdef ARCH_X86 |
1294 | 89 case 2: { |
1297 | 90 if(!init_video_codec(sh_video,0)) { |
1294 | 91 // GUI_MSG( mplUnknowError ) |
92 // exit(1); | |
93 return 0; | |
94 } | |
95 if(verbose) printf("INFO: Win32 video codec init OK!\n"); | |
96 break; | |
97 } | |
1297 | 98 case 6: { |
99 if(!init_video_codec(sh_video,1)) { | |
100 // GUI_MSG( mplUnknowError ) | |
101 // exit(1); | |
102 return 0; | |
103 } | |
104 if(verbose) printf("INFO: Win32Ex video codec init OK!\n"); | |
105 break; | |
106 } | |
1294 | 107 case 4: { // Win32/DirectShow |
108 #ifndef USE_DIRECTSHOW | |
109 fprintf(stderr,"MPlayer was compiled WITHOUT directshow support!\n"); | |
110 return 0; | |
111 // GUI_MSG( mplCompileWithoutDSSupport ) | |
112 // exit(1); | |
113 #else | |
114 sh_video->our_out_buffer=NULL; | |
115 if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, &sh_video->our_out_buffer)){ | |
116 // if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, NULL)){ | |
117 printf("ERROR: Couldn't open required DirectShow codec: %s\n",sh_video->codec->dll); | |
118 printf("Maybe you forget to upgrade your win32 codecs?? It's time to download the new\n"); | |
119 printf("package from: ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip !\n"); | |
120 printf("Or you should disable DShow support: make distclean;make -f Makefile.No-DS\n"); | |
121 return 0; | |
122 // #ifdef HAVE_GUI | |
123 // if ( !nogui ) | |
124 // { | |
125 // strcpy( mplShMem->items.videodata.codecdll,sh_video->codec->dll ); | |
126 // mplSendMessage( mplDSCodecNotFound ); | |
127 // usec_sleep( 10000 ); | |
128 // } | |
129 // #endif | |
130 // exit(1); | |
131 } | |
132 | |
133 switch(out_fmt){ | |
134 case IMGFMT_YUY2: | |
135 case IMGFMT_UYVY: | |
136 DS_VideoDecoder_SetDestFmt(16,out_fmt);break; // packed YUV | |
137 case IMGFMT_YV12: | |
138 case IMGFMT_I420: | |
139 case IMGFMT_IYUV: | |
140 DS_VideoDecoder_SetDestFmt(12,out_fmt);break; // planar YUV | |
141 default: | |
142 DS_VideoDecoder_SetDestFmt(out_fmt&255,0); // RGB/BGR | |
143 } | |
144 | |
145 DS_VideoDecoder_Start(); | |
146 | |
147 DS_SetAttr_DivX("Quality",divx_quality); | |
148 // printf("DivX setting result = %d\n", DS_SetAttr_DivX("Quality",divx_quality) ); | |
149 // printf("DivX setting result = %d\n", DS_SetValue_DivX("Brightness",60) ); | |
150 | |
151 if(verbose) printf("INFO: Win32/DShow video codec init OK!\n"); | |
152 break; | |
153 #endif | |
154 } | |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
155 #else /* !ARCH_X86 */ |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
156 case 2: |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
157 case 4: |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
158 case 6: |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
159 fprintf(stderr,"MPlayer does not support win32 codecs on non-x86 platforms!\n"); |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
160 return 0; |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
161 #endif /* !ARCH_X86 */ |
1294 | 162 case 3: { // OpenDivX |
163 if(verbose) printf("OpenDivX video codec\n"); | |
164 { DEC_PARAM dec_param; | |
165 DEC_SET dec_set; | |
1349 | 166 memset(&dec_param,0,sizeof(dec_param)); |
1294 | 167 #ifdef NEW_DECORE |
168 dec_param.output_format=DEC_USER; | |
169 #else | |
170 dec_param.color_depth = 32; | |
171 #endif | |
172 dec_param.x_dim = sh_video->bih->biWidth; | |
173 dec_param.y_dim = sh_video->bih->biHeight; | |
174 decore(0x123, DEC_OPT_INIT, &dec_param, NULL); | |
175 dec_set.postproc_level = divx_quality; | |
176 decore(0x123, DEC_OPT_SETPP, &dec_set, NULL); | |
1349 | 177 } |
178 if(verbose) printf("INFO: OpenDivX video codec init OK!\n"); | |
179 break; | |
180 } | |
181 case 7: { // DivX4Linux | |
1352
5ac130627602
fixed shmem size, and now compiles without divx4linux too :)
arpi
parents:
1349
diff
changeset
|
182 #ifndef NEW_DECORE |
5ac130627602
fixed shmem size, and now compiles without divx4linux too :)
arpi
parents:
1349
diff
changeset
|
183 fprintf(stderr,"MPlayer was compiled WITHOUT DivX4Linux (libdivxdecore.so) support!\n"); |
5ac130627602
fixed shmem size, and now compiles without divx4linux too :)
arpi
parents:
1349
diff
changeset
|
184 return 0; //exit(1); |
5ac130627602
fixed shmem size, and now compiles without divx4linux too :)
arpi
parents:
1349
diff
changeset
|
185 #else |
1349 | 186 if(verbose) printf("DivX4Linux video codec\n"); |
187 { DEC_PARAM dec_param; | |
188 DEC_SET dec_set; | |
189 int bits=16; | |
190 memset(&dec_param,0,sizeof(dec_param)); | |
191 switch(out_fmt){ | |
192 case IMGFMT_YV12: dec_param.output_format=DEC_YV12;bits=12;break; | |
193 case IMGFMT_YUY2: dec_param.output_format=DEC_YUY2;break; | |
194 case IMGFMT_UYVY: dec_param.output_format=DEC_UYVY;break; | |
195 case IMGFMT_I420: dec_param.output_format=DEC_420;bits=12;break; | |
196 case IMGFMT_BGR15: dec_param.output_format=DEC_RGB555_INV;break; | |
197 case IMGFMT_BGR16: dec_param.output_format=DEC_RGB565_INV;break; | |
198 case IMGFMT_BGR24: dec_param.output_format=DEC_RGB24_INV;bits=24;break; | |
199 case IMGFMT_BGR32: dec_param.output_format=DEC_RGB32_INV;bits=32;break; | |
200 default: | |
201 fprintf(stderr,"Unsupported out_fmt: 0x%X\n",out_fmt); | |
202 return 0; | |
203 } | |
204 dec_param.x_dim = sh_video->bih->biWidth; | |
205 dec_param.y_dim = sh_video->bih->biHeight; | |
206 decore(0x123, DEC_OPT_INIT, &dec_param, NULL); | |
207 dec_set.postproc_level = divx_quality; | |
208 decore(0x123, DEC_OPT_SETPP, &dec_set, NULL); | |
1352
5ac130627602
fixed shmem size, and now compiles without divx4linux too :)
arpi
parents:
1349
diff
changeset
|
209 sh_video->our_out_buffer = shmem_alloc(((bits*dec_param.x_dim+7)/8)*dec_param.y_dim); |
5ac130627602
fixed shmem size, and now compiles without divx4linux too :)
arpi
parents:
1349
diff
changeset
|
210 // sh_video->our_out_buffer = shmem_alloc(dec_param.x_dim*dec_param.y_dim*5); |
1294 | 211 } |
212 if(verbose) printf("INFO: OpenDivX video codec init OK!\n"); | |
213 break; | |
1352
5ac130627602
fixed shmem size, and now compiles without divx4linux too :)
arpi
parents:
1349
diff
changeset
|
214 #endif |
1294 | 215 } |
216 case 5: { // FFmpeg's libavcodec | |
217 #ifndef USE_LIBAVCODEC | |
218 fprintf(stderr,"MPlayer was compiled WITHOUT libavcodec support!\n"); | |
219 return 0; //exit(1); | |
220 #else | |
221 if(verbose) printf("FFmpeg's libavcodec video codec\n"); | |
222 avcodec_init(); | |
223 avcodec_register_all(); | |
224 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_video->codec->dll); | |
225 if(!lavc_codec){ | |
226 fprintf(stderr,"Can't find codec '%s' in libavcodec...\n",sh_video->codec->dll); | |
227 return 0; //exit(1); | |
228 } | |
229 memset(&lavc_context, 0, sizeof(lavc_context)); | |
230 lavc_context.width=sh_video->disp_w; | |
231 lavc_context.height=sh_video->disp_h; | |
232 printf("libavcodec.size: %d x %d\n",lavc_context.width,lavc_context.height); | |
233 /* open it */ | |
234 if (avcodec_open(&lavc_context, lavc_codec) < 0) { | |
235 fprintf(stderr, "could not open codec\n"); | |
236 return 0; //exit(1); | |
237 } | |
238 | |
239 if(verbose) printf("INFO: libavcodec init OK!\n"); | |
240 break; | |
241 #endif | |
242 } | |
243 | |
244 case 1: { | |
245 // init libmpeg2: | |
246 #ifdef MPEG12_POSTPROC | |
247 picture->pp_options=divx_quality; | |
248 #else | |
249 if(divx_quality){ | |
250 printf("WARNING! You requested image postprocessing for an MPEG 1/2 video,\n"); | |
251 printf(" but compiled MPlayer without MPEG 1/2 postprocessing support!\n"); | |
252 printf(" #define MPEG12_POSTPROC in config.h, and recompile libmpeg2!\n"); | |
253 } | |
254 #endif | |
255 mpeg2_allocate_image_buffers (picture); | |
256 break; | |
257 } | |
258 } | |
259 | |
260 return 1; | |
261 } | |
262 | |
263 int decode_video(vo_functions_t *video_out,sh_video_t *sh_video,unsigned char *start,int in_size,int drop_frame){ | |
264 unsigned int out_fmt=sh_video->codec->outfmt[sh_video->outfmtidx]; | |
1360 | 265 int planar=(out_fmt==IMGFMT_YV12||out_fmt==IMGFMT_IYUV||out_fmt==IMGFMT_I420); |
1294 | 266 int blit_frame=0; |
267 | |
1360 | 268 uint8_t* planes_[3]; |
269 uint8_t** planes=planes_; | |
270 int stride_[3]; | |
271 int* stride=stride_; | |
272 | |
273 unsigned int t=GetTimer(); | |
274 unsigned int t2; | |
275 | |
1294 | 276 //-------------------- Decode a frame: ----------------------- |
277 switch(sh_video->codec->driver){ | |
278 case 3: { | |
279 // OpenDivX | |
280 DEC_FRAME dec_frame; | |
281 #ifdef NEW_DECORE | |
282 DEC_PICTURE dec_pic; | |
283 #endif | |
284 // let's decode | |
285 dec_frame.length = in_size; | |
286 dec_frame.bitstream = start; | |
1349 | 287 dec_frame.render_flag = drop_frame?0:1; |
288 | |
1294 | 289 #ifdef NEW_DECORE |
290 dec_frame.bmp=&dec_pic; | |
291 dec_pic.y=dec_pic.u=dec_pic.v=NULL; | |
1349 | 292 decore(0x123, (sh_video->format==mmioFOURCC('D','I','V','3'))?DEC_OPT_FRAME_311:DEC_OPT_FRAME, &dec_frame, NULL); |
293 #else | |
1360 | 294 opendivx_src[0]=NULL; |
1349 | 295 decore(0x123, 0, &dec_frame, NULL); |
1294 | 296 #endif |
1360 | 297 |
298 if(!drop_frame) | |
1294 | 299 |
1349 | 300 // let's display |
1294 | 301 #ifdef NEW_DECORE |
302 if(dec_pic.y){ | |
1360 | 303 planes[0]=dec_pic.y; |
304 planes[1]=dec_pic.u; | |
305 planes[2]=dec_pic.v; | |
1294 | 306 stride[0]=dec_pic.stride_y; |
307 stride[1]=stride[2]=dec_pic.stride_uv; | |
1360 | 308 blit_frame=2; |
1294 | 309 } |
310 #else | |
311 if(opendivx_src[0]){ | |
1360 | 312 planes=opendivx_src; stride=opendivx_stride; |
313 blit_frame=2; | |
1294 | 314 } |
315 #endif | |
316 | |
317 break; | |
318 } | |
1352
5ac130627602
fixed shmem size, and now compiles without divx4linux too :)
arpi
parents:
1349
diff
changeset
|
319 #ifdef NEW_DECORE |
1349 | 320 case 7: { |
321 // DivX4Linux | |
322 DEC_FRAME dec_frame; | |
323 // let's decode | |
324 dec_frame.length = in_size; | |
325 dec_frame.bitstream = start; | |
326 dec_frame.render_flag = drop_frame?0:1; | |
327 dec_frame.bmp=sh_video->our_out_buffer; | |
328 dec_frame.stride=sh_video->disp_w; | |
329 // printf("Decoding DivX4 frame\n"); | |
330 decore(0x123, (sh_video->format==mmioFOURCC('D','I','V','3'))?DEC_OPT_FRAME_311:DEC_OPT_FRAME, &dec_frame, NULL); | |
1360 | 331 if(!drop_frame) blit_frame=3; |
1349 | 332 break; |
333 } | |
1352
5ac130627602
fixed shmem size, and now compiles without divx4linux too :)
arpi
parents:
1349
diff
changeset
|
334 #endif |
1294 | 335 #ifdef USE_DIRECTSHOW |
336 case 4: { // W32/DirectShow | |
337 if(drop_frame<2) DS_VideoDecoder_DecodeFrame(start, in_size, 0, !drop_frame); | |
1362
11673118f37f
Fix segfault in DShow video decoder. Using directshow, the
jkeil
parents:
1360
diff
changeset
|
338 if(!drop_frame && sh_video->our_out_buffer) blit_frame=3; |
1294 | 339 break; |
340 } | |
341 #endif | |
342 #ifdef USE_LIBAVCODEC | |
343 case 5: { // libavcodec | |
344 int got_picture=0; | |
345 if(drop_frame<2 && in_size>0){ | |
346 int ret = avcodec_decode_video(&lavc_context, &lavc_picture, | |
347 &got_picture, start, in_size); | |
348 if(ret<0) fprintf(stderr, "Error while decoding frame!\n"); | |
1360 | 349 if(!drop_frame && got_picture){ |
350 planes=lavc_picture.data; | |
351 stride=lavc_picture.linesize; | |
352 blit_frame=2; | |
353 } | |
1294 | 354 } |
355 break; | |
356 } | |
357 #endif | |
1360 | 358 #ifdef ARCH_X86 |
1297 | 359 case 6: |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
360 case 2: |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
361 { |
1294 | 362 HRESULT ret; |
363 | |
1360 | 364 if(!in_size) break; |
365 | |
1294 | 366 sh_video->bih->biSizeImage = in_size; |
367 | |
368 // sh_video->bih->biWidth = 1280; | |
369 // sh_video->o_bih.biWidth = 1280; | |
370 // ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME|(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL), | |
1297 | 371 |
372 if(sh_video->codec->driver==6) | |
373 ret = ICDecompressEx(sh_video->hic, | |
374 ( (sh_video->ds->flags&1) ? 0 : ICDECOMPRESS_NOTKEYFRAME ) | | |
375 ( (drop_frame==2 && !(sh_video->ds->flags&1))?(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL):0 ) , | |
376 sh_video->bih, start, | |
377 &sh_video->o_bih, | |
378 drop_frame ? 0 : sh_video->our_out_buffer); | |
379 else | |
1294 | 380 ret = ICDecompress(sh_video->hic, |
381 ( (sh_video->ds->flags&1) ? 0 : ICDECOMPRESS_NOTKEYFRAME ) | | |
382 ( (drop_frame==2 && !(sh_video->ds->flags&1))?(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL):0 ) , | |
383 sh_video->bih, start, | |
384 &sh_video->o_bih, | |
385 drop_frame ? 0 : sh_video->our_out_buffer); | |
386 | |
387 if(ret){ printf("Error decompressing frame, err=%d\n",(int)ret);break; } | |
1360 | 388 |
389 if(!drop_frame) blit_frame=3; | |
1294 | 390 break; |
391 } | |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
392 #endif |
1365 | 393 case 1: |
394 mpeg2_decode_data(video_out, start, start+in_size,drop_frame); | |
395 if(!drop_frame) blit_frame=1; | |
1294 | 396 break; |
397 } // switch | |
398 //------------------------ frame decoded. -------------------- | |
399 | |
1367 | 400 #ifdef HAVE_MMX |
401 // some codecs is broken, and doesn't restore MMX state :( | |
402 // it happens usually with broken/damaged files. | |
403 __asm __volatile ("emms;":::"memory"); | |
404 #endif | |
405 | |
1360 | 406 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f; |
407 | |
408 switch(blit_frame){ | |
409 case 3: | |
410 if(planar){ | |
411 stride[0]=sh_video->disp_w; | |
412 stride[1]=stride[2]=sh_video->disp_w/2; | |
413 planes[0]=sh_video->our_out_buffer; | |
414 planes[2]=planes[0]+sh_video->disp_w*sh_video->disp_h; | |
415 planes[1]=planes[2]+sh_video->disp_w*sh_video->disp_h/4; | |
416 } else | |
417 planes[0]=sh_video->our_out_buffer; | |
418 case 2: | |
419 if(planar) | |
420 video_out->draw_slice(planes,stride,sh_video->disp_w,sh_video->disp_h,0,0); | |
421 else | |
422 video_out->draw_frame(planes); | |
423 t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f; | |
424 blit_frame=1; | |
425 break; | |
426 } | |
427 | |
1294 | 428 return blit_frame; |
429 } | |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
430 |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
431 |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
432 int video_read_properties(sh_video_t *sh_video){ |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
433 demux_stream_t *d_video=sh_video->ds; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
434 |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
435 // Determine image properties: |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
436 switch(d_video->demuxer->file_format){ |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
437 case DEMUXER_TYPE_AVI: |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
438 case DEMUXER_TYPE_ASF: { |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
439 // display info: |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
440 sh_video->format=sh_video->bih->biCompression; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
441 sh_video->disp_w=sh_video->bih->biWidth; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
442 sh_video->disp_h=abs(sh_video->bih->biHeight); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
443 break; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
444 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
445 case DEMUXER_TYPE_MPEG_ES: |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
446 case DEMUXER_TYPE_MPEG_PS: { |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
447 // Find sequence_header first: |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
448 if(verbose) printf("Searching for sequence header... ");fflush(stdout); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
449 while(1){ |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
450 int i=sync_video_packet(d_video); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
451 if(i==0x1B3) break; // found it! |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
452 if(!i || !skip_video_packet(d_video)){ |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
453 if(verbose) printf("NONE :(\n"); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
454 fprintf(stderr,"MPEG: FATAL: EOF while searching for sequence header\n"); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
455 return 0; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
456 // GUI_MSG( mplMPEGErrorSeqHeaderSearch ) |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
457 // exit(1); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
458 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
459 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
460 if(verbose) printf("OK!\n"); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
461 // sh_video=d_video->sh;sh_video->ds=d_video; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
462 sh_video->format=0x10000001; // mpeg video |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
463 mpeg2_init(); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
464 // ========= Read & process sequence header & extension ============ |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
465 videobuffer=shmem_alloc(VIDEOBUFFER_SIZE); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
466 if(!videobuffer){ |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
467 fprintf(stderr,"Cannot allocate shared memory\n"); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
468 return 0; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
469 // GUI_MSG( mplErrorShMemAlloc ) |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
470 // exit(0); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
471 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
472 videobuf_len=0; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
473 if(!read_video_packet(d_video)){ |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
474 fprintf(stderr,"FATAL: Cannot read sequence header!\n"); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
475 return 0; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
476 // GUI_MSG( mplMPEGErrorCannotReadSeqHeader ) |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
477 // exit(1); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
478 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
479 if(header_process_sequence_header (picture, &videobuffer[4])) { |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
480 printf ("bad sequence header!\n"); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
481 return 0; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
482 // GUI_MSG( mplMPEGErrorBadSeqHeader ) |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
483 // exit(1); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
484 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
485 if(sync_video_packet(d_video)==0x1B5){ // next packet is seq. ext. |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
486 videobuf_len=0; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
487 if(!read_video_packet(d_video)){ |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
488 fprintf(stderr,"FATAL: Cannot read sequence header extension!\n"); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
489 return 0; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
490 // GUI_MSG( mplMPEGErrorCannotReadSeqHeaderExt ) |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
491 // exit(1); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
492 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
493 if(header_process_extension (picture, &videobuffer[4])) { |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
494 printf ("bad sequence header extension!\n"); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
495 return 0; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
496 // GUI_MSG( mplMPEGErrorBadSeqHeaderExt ) |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
497 // exit(1); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
498 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
499 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
500 // display info: |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
501 sh_video->fps=frameratecode2framerate[picture->frame_rate_code]*0.0001f; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
502 if(!sh_video->fps){ |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
503 // if(!force_fps){ |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
504 // fprintf(stderr,"FPS not specified (or invalid) in the header! Use the -fps option!\n"); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
505 // return 0; //exit(1); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
506 // } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
507 sh_video->frametime=0; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
508 } else { |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
509 sh_video->frametime=10000.0f/(float)frameratecode2framerate[picture->frame_rate_code]; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
510 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
511 sh_video->disp_w=picture->display_picture_width; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
512 sh_video->disp_h=picture->display_picture_height; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
513 // info: |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
514 if(verbose) printf("mpeg bitrate: %d (%X)\n",picture->bitrate,picture->bitrate); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
515 printf("VIDEO: %s %dx%d (aspect %d) %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
516 picture->mpeg1?"MPEG1":"MPEG2", |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
517 sh_video->disp_w,sh_video->disp_h, |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
518 picture->aspect_ratio_information, |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
519 sh_video->fps, |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
520 picture->bitrate*0.5f, |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
521 picture->bitrate/16.0f ); |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
522 break; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
523 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
524 } // switch(file_format) |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
525 |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
526 return 1; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
527 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
528 |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
529 |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
530 |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
531 |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1367
diff
changeset
|
532 |