Mercurial > mplayer.hg
annotate dec_video.c @ 1316:40083e7ad5ce
Disable 3dnow when mmx is disabled.
author | atmos4 |
---|---|
date | Fri, 13 Jul 2001 19:49:15 +0000 |
parents | 598e3047ce13 |
children | b12e1817bcc2 |
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 | |
13 #include "stream.h" | |
14 #include "demuxer.h" | |
15 | |
16 #include "wine/mmreg.h" | |
17 #include "wine/avifmt.h" | |
18 #include "wine/vfw.h" | |
19 | |
20 #include "codec-cfg.h" | |
21 #include "stheader.h" | |
22 | |
23 //#include <inttypes.h> | |
24 //#include "libvo/img_format.h" | |
25 | |
26 #include "libvo/video_out.h" | |
27 | |
28 #include "libmpeg2/mpeg2.h" | |
29 #include "libmpeg2/mpeg2_internal.h" | |
30 | |
31 extern picture_t *picture; // exported from libmpeg2/decode.c | |
32 | |
1297 | 33 extern int init_video_codec(sh_video_t *sh_video,int ex); |
1294 | 34 |
35 #ifdef USE_DIRECTSHOW | |
36 #include "loader/DirectShow/DS_VideoDec.h" | |
37 #endif | |
38 | |
39 #ifdef USE_LIBAVCODEC | |
40 #include "libavcodec/avcodec.h" | |
41 AVCodec *lavc_codec=NULL; | |
42 AVCodecContext lavc_context; | |
43 AVPicture lavc_picture; | |
44 #endif | |
45 | |
46 #include "opendivx/decore.h" | |
47 | |
48 //**************************************************************************// | |
49 // The OpenDivX stuff: | |
50 //**************************************************************************// | |
51 | |
52 #ifndef NEW_DECORE | |
53 | |
54 static unsigned char *opendivx_src[3]; | |
55 static int opendivx_stride[3]; | |
56 | |
57 // callback, the opendivx decoder calls this for each frame: | |
58 void convert_linux(unsigned char *puc_y, int stride_y, | |
59 unsigned char *puc_u, unsigned char *puc_v, int stride_uv, | |
60 unsigned char *bmp, int width_y, int height_y){ | |
61 | |
62 // printf("convert_yuv called %dx%d stride: %d,%d\n",width_y,height_y,stride_y,stride_uv); | |
63 | |
64 opendivx_src[0]=puc_y; | |
65 opendivx_src[1]=puc_u; | |
66 opendivx_src[2]=puc_v; | |
67 | |
68 opendivx_stride[0]=stride_y; | |
69 opendivx_stride[1]=stride_uv; | |
70 opendivx_stride[2]=stride_uv; | |
71 } | |
72 #endif | |
73 | |
74 | |
75 int init_video(sh_video_t *sh_video){ | |
76 unsigned int out_fmt=sh_video->codec->outfmt[sh_video->outfmtidx]; | |
77 | |
78 switch(sh_video->codec->driver){ | |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
79 #ifdef ARCH_X86 |
1294 | 80 case 2: { |
1297 | 81 if(!init_video_codec(sh_video,0)) { |
1294 | 82 // GUI_MSG( mplUnknowError ) |
83 // exit(1); | |
84 return 0; | |
85 } | |
86 if(verbose) printf("INFO: Win32 video codec init OK!\n"); | |
87 break; | |
88 } | |
1297 | 89 case 6: { |
90 if(!init_video_codec(sh_video,1)) { | |
91 // GUI_MSG( mplUnknowError ) | |
92 // exit(1); | |
93 return 0; | |
94 } | |
95 if(verbose) printf("INFO: Win32Ex video codec init OK!\n"); | |
96 break; | |
97 } | |
1294 | 98 case 4: { // Win32/DirectShow |
99 #ifndef USE_DIRECTSHOW | |
100 fprintf(stderr,"MPlayer was compiled WITHOUT directshow support!\n"); | |
101 return 0; | |
102 // GUI_MSG( mplCompileWithoutDSSupport ) | |
103 // exit(1); | |
104 #else | |
105 sh_video->our_out_buffer=NULL; | |
106 if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, &sh_video->our_out_buffer)){ | |
107 // if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, NULL)){ | |
108 printf("ERROR: Couldn't open required DirectShow codec: %s\n",sh_video->codec->dll); | |
109 printf("Maybe you forget to upgrade your win32 codecs?? It's time to download the new\n"); | |
110 printf("package from: ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip !\n"); | |
111 printf("Or you should disable DShow support: make distclean;make -f Makefile.No-DS\n"); | |
112 return 0; | |
113 // #ifdef HAVE_GUI | |
114 // if ( !nogui ) | |
115 // { | |
116 // strcpy( mplShMem->items.videodata.codecdll,sh_video->codec->dll ); | |
117 // mplSendMessage( mplDSCodecNotFound ); | |
118 // usec_sleep( 10000 ); | |
119 // } | |
120 // #endif | |
121 // exit(1); | |
122 } | |
123 | |
124 switch(out_fmt){ | |
125 case IMGFMT_YUY2: | |
126 case IMGFMT_UYVY: | |
127 DS_VideoDecoder_SetDestFmt(16,out_fmt);break; // packed YUV | |
128 case IMGFMT_YV12: | |
129 case IMGFMT_I420: | |
130 case IMGFMT_IYUV: | |
131 DS_VideoDecoder_SetDestFmt(12,out_fmt);break; // planar YUV | |
132 default: | |
133 DS_VideoDecoder_SetDestFmt(out_fmt&255,0); // RGB/BGR | |
134 } | |
135 | |
136 DS_VideoDecoder_Start(); | |
137 | |
138 DS_SetAttr_DivX("Quality",divx_quality); | |
139 // printf("DivX setting result = %d\n", DS_SetAttr_DivX("Quality",divx_quality) ); | |
140 // printf("DivX setting result = %d\n", DS_SetValue_DivX("Brightness",60) ); | |
141 | |
142 if(verbose) printf("INFO: Win32/DShow video codec init OK!\n"); | |
143 break; | |
144 #endif | |
145 } | |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
146 #else /* !ARCH_X86 */ |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
147 case 2: |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
148 case 4: |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
149 case 6: |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
150 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
|
151 return 0; |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
152 #endif /* !ARCH_X86 */ |
1294 | 153 case 3: { // OpenDivX |
154 if(verbose) printf("OpenDivX video codec\n"); | |
155 { DEC_PARAM dec_param; | |
156 DEC_SET dec_set; | |
157 #ifdef NEW_DECORE | |
158 DEC_MEM_REQS dec_mem; | |
159 dec_param.output_format=DEC_USER; | |
160 #else | |
161 dec_param.color_depth = 32; | |
162 #endif | |
163 dec_param.x_dim = sh_video->bih->biWidth; | |
164 dec_param.y_dim = sh_video->bih->biHeight; | |
165 #ifdef NEW_DECORE | |
166 // 0.50-CVS new malloc scheme | |
167 decore(0x123, DEC_OPT_MEMORY_REQS, &dec_param, &dec_mem); | |
168 dec_param.buffers.mp4_edged_ref_buffers=malloc(dec_mem.mp4_edged_ref_buffers_size); | |
169 dec_param.buffers.mp4_edged_for_buffers=malloc(dec_mem.mp4_edged_for_buffers_size); | |
170 dec_param.buffers.mp4_display_buffers=malloc(dec_mem.mp4_display_buffers_size); | |
171 dec_param.buffers.mp4_state=malloc(dec_mem.mp4_state_size); | |
172 dec_param.buffers.mp4_tables=malloc(dec_mem.mp4_tables_size); | |
173 dec_param.buffers.mp4_stream=malloc(dec_mem.mp4_stream_size); | |
174 #endif | |
175 decore(0x123, DEC_OPT_INIT, &dec_param, NULL); | |
176 | |
177 dec_set.postproc_level = divx_quality; | |
178 decore(0x123, DEC_OPT_SETPP, &dec_set, NULL); | |
179 | |
180 } | |
181 if(verbose) printf("INFO: OpenDivX video codec init OK!\n"); | |
182 break; | |
183 } | |
184 case 5: { // FFmpeg's libavcodec | |
185 #ifndef USE_LIBAVCODEC | |
186 fprintf(stderr,"MPlayer was compiled WITHOUT libavcodec support!\n"); | |
187 return 0; //exit(1); | |
188 #else | |
189 if(verbose) printf("FFmpeg's libavcodec video codec\n"); | |
190 avcodec_init(); | |
191 avcodec_register_all(); | |
192 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_video->codec->dll); | |
193 if(!lavc_codec){ | |
194 fprintf(stderr,"Can't find codec '%s' in libavcodec...\n",sh_video->codec->dll); | |
195 return 0; //exit(1); | |
196 } | |
197 memset(&lavc_context, 0, sizeof(lavc_context)); | |
198 lavc_context.width=sh_video->disp_w; | |
199 lavc_context.height=sh_video->disp_h; | |
200 printf("libavcodec.size: %d x %d\n",lavc_context.width,lavc_context.height); | |
201 /* open it */ | |
202 if (avcodec_open(&lavc_context, lavc_codec) < 0) { | |
203 fprintf(stderr, "could not open codec\n"); | |
204 return 0; //exit(1); | |
205 } | |
206 | |
207 if(verbose) printf("INFO: libavcodec init OK!\n"); | |
208 break; | |
209 #endif | |
210 } | |
211 | |
212 case 1: { | |
213 // init libmpeg2: | |
214 #ifdef MPEG12_POSTPROC | |
215 picture->pp_options=divx_quality; | |
216 #else | |
217 if(divx_quality){ | |
218 printf("WARNING! You requested image postprocessing for an MPEG 1/2 video,\n"); | |
219 printf(" but compiled MPlayer without MPEG 1/2 postprocessing support!\n"); | |
220 printf(" #define MPEG12_POSTPROC in config.h, and recompile libmpeg2!\n"); | |
221 } | |
222 #endif | |
223 mpeg2_allocate_image_buffers (picture); | |
224 break; | |
225 } | |
226 } | |
227 | |
228 return 1; | |
229 } | |
230 | |
231 int decode_video(vo_functions_t *video_out,sh_video_t *sh_video,unsigned char *start,int in_size,int drop_frame){ | |
232 unsigned int out_fmt=sh_video->codec->outfmt[sh_video->outfmtidx]; | |
233 int blit_frame=0; | |
234 | |
235 //-------------------- Decode a frame: ----------------------- | |
236 switch(sh_video->codec->driver){ | |
237 case 3: { | |
238 // OpenDivX | |
239 unsigned int t=GetTimer(); | |
240 unsigned int t2; | |
241 DEC_FRAME dec_frame; | |
242 #ifdef NEW_DECORE | |
243 DEC_PICTURE dec_pic; | |
244 #endif | |
245 // let's decode | |
246 dec_frame.length = in_size; | |
247 dec_frame.bitstream = start; | |
248 dec_frame.render_flag = 1; | |
249 #ifdef NEW_DECORE | |
250 dec_frame.bmp=&dec_pic; | |
251 dec_pic.y=dec_pic.u=dec_pic.v=NULL; | |
252 #endif | |
253 decore(0x123, 0, &dec_frame, NULL); | |
254 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f; | |
255 | |
256 #ifdef NEW_DECORE | |
257 if(dec_pic.y){ | |
258 void* src[3]; | |
259 int stride[3]; | |
260 src[0]=dec_pic.y; | |
261 src[1]=dec_pic.u; | |
262 src[2]=dec_pic.v; | |
263 stride[0]=dec_pic.stride_y; | |
264 stride[1]=stride[2]=dec_pic.stride_uv; | |
265 video_out->draw_slice(src,stride, | |
266 sh_video->disp_w,sh_video->disp_h,0,0); | |
267 blit_frame=1; | |
268 } | |
269 #else | |
270 if(opendivx_src[0]){ | |
271 video_out->draw_slice(opendivx_src,opendivx_stride, | |
272 sh_video->disp_w,sh_video->disp_h,0,0); | |
273 opendivx_src[0]=NULL; | |
274 blit_frame=1; | |
275 } | |
276 #endif | |
277 t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f; | |
278 | |
279 break; | |
280 } | |
281 #ifdef USE_DIRECTSHOW | |
282 case 4: { // W32/DirectShow | |
283 unsigned int t=GetTimer(); | |
284 unsigned int t2; | |
285 | |
286 if(drop_frame<2) DS_VideoDecoder_DecodeFrame(start, in_size, 0, !drop_frame); | |
287 | |
288 if(!drop_frame && sh_video->our_out_buffer){ | |
289 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f; | |
290 if(out_fmt==IMGFMT_YV12||out_fmt==IMGFMT_IYUV||out_fmt==IMGFMT_I420){ | |
291 uint8_t* dst[3]; | |
292 int stride[3]; | |
293 stride[0]=sh_video->disp_w; | |
294 stride[1]=stride[2]=sh_video->disp_w/2; | |
295 dst[0]=sh_video->our_out_buffer; | |
296 dst[2]=dst[0]+sh_video->disp_w*sh_video->disp_h; | |
297 dst[1]=dst[2]+sh_video->disp_w*sh_video->disp_h/4; | |
298 video_out->draw_slice(dst,stride,sh_video->disp_w,sh_video->disp_h,0,0); | |
299 } else | |
300 video_out->draw_frame((uint8_t **)&sh_video->our_out_buffer); | |
301 t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f; | |
302 blit_frame=1; | |
303 } | |
304 break; | |
305 } | |
306 #endif | |
307 #ifdef USE_LIBAVCODEC | |
308 case 5: { // libavcodec | |
309 unsigned int t=GetTimer(); | |
310 unsigned int t2; | |
311 int got_picture=0; | |
312 | |
313 if(drop_frame<2 && in_size>0){ | |
314 int ret = avcodec_decode_video(&lavc_context, &lavc_picture, | |
315 &got_picture, start, in_size); | |
316 if(ret<0) fprintf(stderr, "Error while decoding frame!\n"); | |
317 } | |
318 | |
319 if(!drop_frame && got_picture){ | |
320 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f; | |
321 video_out->draw_slice(lavc_picture.data,lavc_picture.linesize,sh_video->disp_w,sh_video->disp_h,0,0); | |
322 t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f; | |
323 blit_frame=1; | |
324 } | |
325 | |
326 break; | |
327 } | |
328 #endif | |
1297 | 329 case 6: |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
330 case 2: |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
331 #ifdef ARCH_X86 |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
332 { |
1294 | 333 HRESULT ret; |
334 unsigned int t=GetTimer(); | |
335 unsigned int t2; | |
336 | |
337 if(in_size){ | |
338 sh_video->bih->biSizeImage = in_size; | |
339 | |
340 // sh_video->bih->biWidth = 1280; | |
341 // sh_video->o_bih.biWidth = 1280; | |
342 // ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME|(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL), | |
1297 | 343 |
344 if(sh_video->codec->driver==6) | |
345 ret = ICDecompressEx(sh_video->hic, | |
346 ( (sh_video->ds->flags&1) ? 0 : ICDECOMPRESS_NOTKEYFRAME ) | | |
347 ( (drop_frame==2 && !(sh_video->ds->flags&1))?(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL):0 ) , | |
348 sh_video->bih, start, | |
349 &sh_video->o_bih, | |
350 drop_frame ? 0 : sh_video->our_out_buffer); | |
351 else | |
1294 | 352 ret = ICDecompress(sh_video->hic, |
353 ( (sh_video->ds->flags&1) ? 0 : ICDECOMPRESS_NOTKEYFRAME ) | | |
354 ( (drop_frame==2 && !(sh_video->ds->flags&1))?(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL):0 ) , | |
355 sh_video->bih, start, | |
356 &sh_video->o_bih, | |
357 drop_frame ? 0 : sh_video->our_out_buffer); | |
358 | |
359 if(ret){ printf("Error decompressing frame, err=%d\n",(int)ret);break; } | |
360 } | |
361 // current_module="draw_frame"; | |
362 if(!drop_frame){ | |
363 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f; | |
364 // if(out_fmt==IMGFMT_YV12){ | |
365 if(out_fmt==IMGFMT_YV12||out_fmt==IMGFMT_IYUV||out_fmt==IMGFMT_I420){ | |
366 uint8_t* dst[3]; | |
367 int stride[3]; | |
368 stride[0]=sh_video->disp_w; | |
369 stride[1]=stride[2]=sh_video->disp_w/2; | |
370 dst[0]=sh_video->our_out_buffer; | |
371 dst[2]=dst[0]+sh_video->disp_w*sh_video->disp_h; | |
372 dst[1]=dst[2]+sh_video->disp_w*sh_video->disp_h/4; | |
373 video_out->draw_slice(dst,stride,sh_video->disp_w,sh_video->disp_h,0,0); | |
374 } else | |
375 video_out->draw_frame((uint8_t **)&sh_video->our_out_buffer); | |
376 t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f; | |
377 blit_frame=1; | |
378 } | |
379 break; | |
380 } | |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
381 #else |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
382 printf("Win32 video codec unavailable on non-x86 CPU -> force nosound :(\n"); |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
383 break; |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
384 #endif |
1294 | 385 case 1: { |
386 int in_frame=0; | |
387 int t=0; | |
388 float newfps; | |
389 | |
390 t-=GetTimer(); | |
391 mpeg2_decode_data(video_out, start, start+in_size,drop_frame); | |
392 t+=GetTimer(); video_time_usage+=t*0.000001; | |
393 blit_frame=1; | |
394 | |
395 break; | |
396 } | |
397 } // switch | |
398 //------------------------ frame decoded. -------------------- | |
399 | |
400 return blit_frame; | |
401 } |