Initial commit contains ebuild for xf86-video-openchrome driver and modified ebuilds for
[openchrome.git] / media-video / mplayer / files / mplayer-xvmc-vld.r24967.patch
blobf7f10775cfeb26ef7b1d24d2727b1303099f3e8f
1 Index: codec-cfg.c
2 ===================================================================
3 --- codec-cfg.c (revision 24967)
4 +++ codec-cfg.c (working copy)
5 @@ -179,6 +179,7 @@
6 {"ZRMJPEGIT", IMGFMT_ZRMJPEGIT},
7 {"ZRMJPEGIB", IMGFMT_ZRMJPEGIB},
9 + {"VLD_MPEG2",IMGFMT_XVMC_VLD_MPEG2},
10 {"IDCT_MPEG2",IMGFMT_XVMC_IDCT_MPEG2},
11 {"MOCO_MPEG2",IMGFMT_XVMC_MOCO_MPEG2},
13 Index: configure
14 ===================================================================
15 --- configure (revision 24967)
16 +++ configure (working copy)
17 @@ -527,6 +527,7 @@
18 _dga2=auto
19 _xv=auto
20 _xvmc=no #auto when complete
21 +_xvmc_vld=auto
22 _sdl=auto
23 _directx=auto
24 _win32waveout=auto
25 @@ -3901,7 +3902,7 @@
26 _novomodules="x11 $_novomodules"
27 _res_comment="check if the dev(el) packages are installed"
28 # disable stuff that depends on X
29 - _xv=no ; _xvmc=no ; _xinerama=no ; _vm=no ; _xf86keysym=no
30 + _xv=no ; _xvmc=no ; _xvmc_vld=no ; _xinerama=no ; _vm=no ; _xf86keysym=no
32 echores "$_x11"
34 @@ -4001,6 +4002,31 @@
35 echores "$_xvmc"
38 +echocheck "XvMC VLD"
39 +if test "$_xvmc" = yes ; then
40 + _xvmc_vld=no
41 + cat > $TMPC <<EOF
42 +#include <X11/Xlib.h>
43 +#include <X11/extensions/Xvlib.h>
44 +#include <X11/extensions/XvMClib.h>
45 +#include <X11/extensions/vldXvMC.h>
46 +int main(void) {
47 + (void) XvMCQueryExtension(0,0,0);
48 + (void) XvMCCreateContext(0,0,0,0,0,0,0);
49 + return 0; }
50 +EOF
51 + cc_check -lXvMC -l$_xvmclib && _xvmc_vld=yes
52 + if test "$_xvmc_vld" = yes ; then
53 + _def_xvmc_vld='#define HAVE_XVMC_VLD 1'
54 + _libs_mencoder="$_libs_mencoder -l$_xvmclib"
55 + else
56 + _def_xvmc_vld='#undef HAVE_XVMC_VLD'
57 + _libavdecoders=`echo $_libavdecoders | sed -e s/MPEG_XVMC_VLD_DECODER// `
58 + fi
59 +fi
60 +echores "$_xvmc_vld"
63 echocheck "Xinerama"
64 if test "$_xinerama" = auto ; then
65 cat > $TMPC <<EOF
66 @@ -8455,6 +8481,7 @@
67 $_def_x11
68 $_def_xv
69 $_def_xvmc
70 +$_def_xvmc_vld
71 $_def_vm
72 $_def_xf86keysym
73 $_def_xinerama
74 Index: etc/codecs.conf
75 ===================================================================
76 --- etc/codecs.conf (revision 24967)
77 +++ etc/codecs.conf (working copy)
78 @@ -128,6 +128,7 @@
79 fourcc MMES,mmes ; matrox mpeg2 in avi
80 driver ffmpeg
81 dll "mpegvideo_xvmc"
82 + out VLD_MPEG2
83 out IDCT_MPEG2
84 out MOCO_MPEG2
86 Index: help/help_mp-en.h
87 ===================================================================
88 --- help/help_mp-en.h (revision 24967)
89 +++ help/help_mp-en.h (working copy)
90 @@ -1645,6 +1645,7 @@
91 #define MSGTR_MPCODECS_DRIFailure "[VD_FFMPEG] DRI failure.\n"
92 #define MSGTR_MPCODECS_CouldntAllocateImageForCodec "[VD_FFMPEG] Couldn't allocate image for codec.\n"
93 #define MSGTR_MPCODECS_XVMCAcceleratedMPEG2 "[VD_FFMPEG] XVMC-accelerated MPEG-2.\n"
94 +#define MSGTR_MPCODECS_XVMCVLDAcceleratedMPEG2 "[VD_FFMPEG] XVMC-VLD-accelerated MPEG-2.\n"
95 #define MSGTR_MPCODECS_TryingPixfmt "[VD_FFMPEG] Trying pixfmt=%d.\n"
96 #define MSGTR_MPCODECS_McGetBufferShouldWorkOnlyWithXVMC "[VD_FFMPEG] The mc_get_buffer should work only with XVMC acceleration!!"
97 #define MSGTR_MPCODECS_UnexpectedInitVoError "[VD_FFMPEG] Unexpected init_vo error.\n"
98 Index: libavcodec/xvmcvideo.c
99 ===================================================================
100 --- libavcodec/xvmcvideo.c (revision 10927)
101 +++ libavcodec/xvmcvideo.c (working copy)
102 @@ -68,11 +68,68 @@
106 +#ifdef HAVE_XVMC_VLD
107 +static XvMCSurface* findPastSurface(MpegEncContext *s,
108 + xvmc_render_state_t *render)
110 + Picture *lastp = s->last_picture_ptr;
111 + xvmc_render_state_t *last = NULL;
113 + if (NULL!=lastp) {
114 + last = (xvmc_render_state_t*)(lastp->data[2]);
115 + if (B_TYPE==last->pict_type)
116 + av_log(s->avctx,AV_LOG_DEBUG, "Past frame is a B frame in findPastSurface, this is bad.\n");
117 + //assert(B_TYPE!=last->pict_type);
120 + if (NULL==last)
121 + if (!s->first_field)
122 + last = render; // predict second field from the first
123 + else
124 + return 0;
126 + if (last->magic != MP_XVMC_RENDER_MAGIC)
127 + return 0;
129 + return (last->state & MP_XVMC_STATE_PREDICTION) ? last->p_surface : 0;
132 +static XvMCSurface* findFutureSurface(MpegEncContext *s)
134 + Picture *nextp = s->next_picture_ptr;
135 + xvmc_render_state_t *next = NULL;
137 + if (NULL!=nextp) {
138 + next = (xvmc_render_state_t*)(nextp->data[2]);
139 + if (B_TYPE==next->pict_type)
140 + av_log(s->avctx,AV_LOG_DEBUG, "Next frame is a B frame in findFutureSurface, thisis bad.\n");
141 + //assert(B_TYPE!=next->pict_type);
144 + assert(NULL!=next);
146 + if (next->magic != MP_XVMC_RENDER_MAGIC)
147 + return 0;
149 + return (next->state & MP_XVMC_STATE_PREDICTION) ? next->p_surface : 0;
151 +#endif //HAVE_XVMC_VLD
153 //these functions should be called on every new field or/and frame
154 //They should be safe if they are called few times for same field!
155 int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx){
156 xvmc_render_state_t * render,* last, * next;
158 +#ifdef HAVE_XVMC_VLD
159 + XvMCMpegControl binfo;
160 + XvMCQMatrix qmatrix;
161 + int i;
162 + Status status;
164 + memset(&binfo, 0, sizeof(binfo));
165 + memset(&qmatrix, 0, sizeof(qmatrix));
166 +#endif
168 assert(avctx != NULL);
170 render = (xvmc_render_state_t*)s->current_picture.data[2];
171 @@ -83,12 +140,53 @@
172 render->picture_structure = s->picture_structure;
173 render->flags = (s->first_field)? 0: XVMC_SECOND_FIELD;
175 +#ifdef HAVE_XVMC_VLD
176 + if (s->avctx->xvmc_acceleration == 4)
178 + if (render->picture_structure == PICT_FRAME)
179 + render->flags |= XVMC_FRAME_PICTURE;
180 + else if (render->picture_structure == PICT_TOP_FIELD)
181 + render->flags |= XVMC_TOP_FIELD;
182 + else if (render->picture_structure == PICT_BOTTOM_FIELD)
183 + render->flags |= XVMC_BOTTOM_FIELD;
185 + else
186 +#endif
188 //make sure that all data is drawn by XVMC_end_frame
189 assert(render->filled_mv_blocks_num==0);
192 render->p_future_surface = NULL;
193 render->p_past_surface = NULL;
195 + render->pict_type = s->pict_type; // for later frame dropping use
197 +#ifdef HAVE_XVMC_VLD
198 + if (s->avctx->xvmc_acceleration == 4)
200 + switch(s->pict_type){
201 + case I_TYPE:
202 + break;
203 + case B_TYPE:
204 + render->p_past_surface = findPastSurface(s, render);
205 + render->p_future_surface = findFutureSurface(s);
206 + if (!render->p_past_surface)
207 + av_log(avctx, AV_LOG_ERROR, "error: decoding B frame and past frame is null!");
208 + else if (!render->p_future_surface)
209 + av_log(avctx, AV_LOG_ERROR, "error: decoding B frame and future frame is null!");
210 + break;
212 + case P_TYPE:
213 + render->p_past_surface = findPastSurface(s, render);
214 + render->p_future_surface = render->p_surface;
215 + if (!render->p_past_surface)
216 + av_log(avctx, AV_LOG_ERROR, "error: decoding P frame and past frame is null!");
217 + break;
219 +} else
220 +#endif
222 switch(s->pict_type){
223 case I_TYPE:
224 return 0;// no prediction from other frames
225 @@ -109,6 +207,94 @@
226 render->p_past_surface = last->p_surface;
227 return 0;
231 +#ifdef HAVE_XVMC_VLD
232 + if (s->avctx->xvmc_acceleration == 4)
234 + for (i = 0; i < 64; i++){
235 + qmatrix.intra_quantiser_matrix[i] = s->intra_matrix[s->dsp.idct_permutation[i]];
236 + qmatrix.non_intra_quantiser_matrix[i] = s->inter_matrix[s->dsp.idct_permutation[i]];
237 + qmatrix.chroma_intra_quantiser_matrix[i] = s->chroma_intra_matrix[s->dsp.idct_permutation[i]];
238 + qmatrix.chroma_non_intra_quantiser_matrix[i] = s->chroma_inter_matrix[s->dsp.idct_permutation[i]];
241 + qmatrix.load_intra_quantiser_matrix = 1;
242 + qmatrix.load_non_intra_quantiser_matrix = 1;
243 + qmatrix.load_chroma_intra_quantiser_matrix = 1;
244 + qmatrix.load_chroma_non_intra_quantiser_matrix = 1;
247 + binfo.flags = 0;
248 + if (s->alternate_scan)
249 + binfo.flags |= XVMC_ALTERNATE_SCAN;
250 + if (s->top_field_first)
251 + binfo.flags |= XVMC_TOP_FIELD_FIRST;
252 + if (s->frame_pred_frame_dct)
253 + binfo.flags |= XVMC_PRED_DCT_FRAME;
254 + else
255 + binfo.flags |= XVMC_PRED_DCT_FIELD;
257 + if (s->intra_vlc_format)
258 + binfo.flags |= XVMC_INTRA_VLC_FORMAT;
259 + if (!s->first_field && !s->progressive_sequence)
260 + binfo.flags |= XVMC_SECOND_FIELD;
261 + if (s->q_scale_type)
262 + binfo.flags |= XVMC_Q_SCALE_TYPE;
263 + if (s->concealment_motion_vectors)
264 + binfo.flags |= XVMC_CONCEALMENT_MOTION_VECTORS;
265 + if (s->progressive_sequence)
266 + binfo.flags |= XVMC_PROGRESSIVE_SEQUENCE;
268 + binfo.picture_structure = s->picture_structure;
269 + switch (s->pict_type)
271 + case I_TYPE: binfo.picture_coding_type = XVMC_I_PICTURE; break;
272 + case P_TYPE: binfo.picture_coding_type = XVMC_P_PICTURE; break;
273 + case B_TYPE: binfo.picture_coding_type = XVMC_B_PICTURE; break;
274 + default: av_log(avctx, AV_LOG_ERROR, "%s: Unknown picture coding type: %d\n", __FUNCTION__, s->pict_type);
277 + binfo.intra_dc_precision = s->intra_dc_precision;;
279 + if (s->codec_id == CODEC_ID_MPEG2VIDEO)
280 + binfo.mpeg_coding = 2;
281 + else
282 + binfo.mpeg_coding = 1;
284 + s->mb_width = (s->width + 15) / 16;
285 + s->mb_height = (s->codec_id == CODEC_ID_MPEG2VIDEO && !s->progressive_sequence) ?
286 + 2 * ((s->height + 31) / 32) : (s->height + 15) / 16;
288 + if (s->codec_id == CODEC_ID_MPEG2VIDEO)
290 + binfo.FVMV_range = (s->mpeg_f_code[0][1] - 1);
291 + binfo.FHMV_range = (s->mpeg_f_code[0][0] - 1);
292 + binfo.BVMV_range = (s->mpeg_f_code[1][1] - 1);
293 + binfo.BHMV_range = (s->mpeg_f_code[1][0] - 1);
295 +else
297 + binfo.FVMV_range = (s->mpeg_f_code[0][0] - 1);
298 + binfo.FHMV_range = (s->mpeg_f_code[0][0] - 1);
299 + binfo.BVMV_range = (s->mpeg_f_code[1][1] - 1);
300 + binfo.BHMV_range = (s->mpeg_f_code[1][1] - 1);
303 + status = XvMCLoadQMatrix(render->disp, render->ctx, &qmatrix);
304 + if (status)
305 + av_log(avctx,AV_LOG_ERROR, "XvMCLoadQMatrix: Error: %d\n", status);
307 + status = XvMCBeginSurface(render->disp, render->ctx, render->p_surface,
308 + render->p_past_surface, render->p_future_surface,
309 + &binfo);
310 + if (status)
311 + av_log(avctx,AV_LOG_ERROR, "XvMCBeginSurface: Error: %d\n", status);
313 + if (!status)
314 + return 0;
316 +#endif
318 return -1;
320 @@ -118,11 +304,23 @@
321 render = (xvmc_render_state_t*)s->current_picture.data[2];
322 assert(render != NULL);
324 +#ifdef HAVE_XVMC_VLD
325 + if (s->avctx->xvmc_acceleration == 4)
327 + XvMCFlushSurface(render->disp, render->p_surface);
328 + XvMCSyncSurface(render->disp, render->p_surface);
330 + s->error_count = 0;
332 + else
333 +#endif
335 if(render->filled_mv_blocks_num > 0){
336 // printf("xvmcvideo.c: rendering %d left blocks after last slice!!!\n",render->filled_mv_blocks_num );
337 ff_draw_horiz_band(s,0,0);
342 void XVMC_decode_mb(MpegEncContext *s){
343 XvMCMacroBlock * mv_block;
344 @@ -311,4 +509,50 @@
348 +#ifdef HAVE_XVMC_VLD
349 +static int length_to_next_start(uint8_t* pbuf_ptr, int buf_size)
351 + uint8_t* buf_ptr;
352 + unsigned int state = 0xFFFFFFFF, v;
354 + buf_ptr = pbuf_ptr;
355 + while (buf_ptr < pbuf_ptr + buf_size)
357 + v = *buf_ptr++;
358 + if (state == 0x000001) {
359 + return buf_ptr - pbuf_ptr - 4;
361 + state = ((state << 8) | v) & 0xffffff;
363 + return -1;
366 +#define SLICE_MIN_START_CODE 0x00000101
367 +#define SLICE_MAX_START_CODE 0x000001af
369 +void XVMC_decode_slice(MpegEncContext *s, int mb_y, uint8_t* buffer, int buf_size)
371 + int slicelen = length_to_next_start(buffer, buf_size);
372 + xvmc_render_state_t* render;
374 + if (slicelen < 0)
376 + if ((mb_y == s->mb_height - 1) ||
377 + (!s->progressive_sequence && mb_y == (s->mb_height >> 1) -1) ||
378 + (s->codec_id != CODEC_ID_MPEG2VIDEO))
379 + slicelen = buf_size;
380 + else
381 + return;
384 + render = (xvmc_render_state_t*)s->current_picture.data[2];
385 + render->slice_code = SLICE_MIN_START_CODE + mb_y;
386 + render->slice_data = buffer;
387 + render->slice_datalen = slicelen;
389 + ff_draw_horiz_band(s, 0, 0);
391 #endif
393 +#endif
395 Index: libavcodec/xvmc_render.h
396 ===================================================================
397 --- libavcodec/xvmc_render.h (revision 10927)
398 +++ libavcodec/xvmc_render.h (working copy)
399 @@ -28,6 +28,9 @@
400 #include <X11/extensions/Xvlib.h>
401 #include <X11/extensions/XvMClib.h>
403 +#ifdef HAVE_XVMC_VLD
404 +#include <X11/extensions/vldXvMC.h>
405 +#endif
407 //the surface should be shown, video driver manipulates this
408 #define MP_XVMC_STATE_DISPLAY_PENDING 1
409 @@ -50,6 +53,15 @@
410 int idct;//Do we use IDCT acceleration?
411 int chroma_format;//420,422,444
412 int unsigned_intra;//+-128 for intra pictures after clip
413 +#ifdef HAVE_XVMC_VLD
414 + // These are for the XVMC VLD slice interface
415 + int pict_type; //this is for skipping frames
416 + int slice_code;
417 + int slice_datalen;
418 + unsigned char *slice_data;
419 + Display *disp;
420 + XvMCContext *ctx;
421 +#endif
422 XvMCSurface* p_surface;//pointer to rendered surface, never changed
424 //these are changed by decoder
425 Index: libavcodec/mpeg12.c
426 ===================================================================
427 --- libavcodec/mpeg12.c (revision 10927)
428 +++ libavcodec/mpeg12.c (working copy)
429 @@ -70,6 +70,13 @@
430 extern void XVMC_pack_pblocks(MpegEncContext *s,int cbp);
431 extern void XVMC_init_block(MpegEncContext *s);//set s->block
434 +#ifdef HAVE_XVMC_VLD
435 +extern int XVMC_decode_slice(MpegEncContext *s, int start_code,
436 + uint8_t *buffer, int buf_size);
437 +int has_xvmc_vld = 0;
438 +#endif
440 static const enum PixelFormat pixfmt_yuv_420[]= {PIX_FMT_YUV420P,-1};
441 static const enum PixelFormat pixfmt_yuv_422[]= {PIX_FMT_YUV422P,-1};
442 static const enum PixelFormat pixfmt_yuv_444[]= {PIX_FMT_YUV444P,-1};
443 @@ -77,6 +84,11 @@
444 PIX_FMT_XVMC_MPEG2_IDCT,
445 PIX_FMT_XVMC_MPEG2_MC,
446 -1};
447 +static const enum PixelFormat pixfmt_xvmc_vld_mpg2_420[] = {
448 + PIX_FMT_XVMC_MPEG2_VLD,
449 + PIX_FMT_XVMC_MPEG2_IDCT,
450 + PIX_FMT_XVMC_MPEG2_MC,
451 + -1};
453 uint8_t ff_mpeg12_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3];
455 @@ -1313,6 +1325,9 @@
456 }//mpeg2
458 if(avctx->xvmc_acceleration){
459 + if (has_xvmc_vld)
460 + avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_vld_mpg2_420);
461 + else
462 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
463 }else{
464 if(s->chroma_format < 2){
465 @@ -1682,6 +1697,16 @@
466 return -1;
469 +#ifdef HAVE_XVMC_VLD
470 + if (s->avctx->xvmc_acceleration == 4){
471 + int used = XVMC_decode_slice(s, mb_y, *buf, buf_size);
472 + if (used < 0)
473 + return DECODE_SLICE_ERROR;
474 + *buf += used - 1;
475 + return DECODE_SLICE_OK;
477 +#endif
479 init_get_bits(&s->gb, *buf, buf_size*8);
481 ff_mpeg1_clean_buffers(s);
482 @@ -2077,6 +2102,9 @@
483 s->low_delay= 1;
485 if(avctx->xvmc_acceleration){
486 + if (has_xvmc_vld)
487 + avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_vld_mpg2_420);
488 + else
489 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
490 }else{
491 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_420);
492 @@ -2474,6 +2502,43 @@
494 #endif
496 +#ifdef HAVE_XVMC_VLD
497 +static int mpeg_xxmc_decode_init(AVCodecContext *avctx){
498 + Mpeg1Context *s;
499 + if (!has_xvmc_vld)
500 + return mpeg_mc_decode_init(avctx);
501 + if( avctx->thread_count > 1)
502 + return -1;
503 + if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
504 + return -1;
505 + if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) )
506 + dprintf("mpeg12.c: XVMC_VLD decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
508 + mpeg_decode_init(avctx);
509 + s = avctx->priv_data;
511 + avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_VLD;
512 + avctx->xvmc_acceleration = 4;
514 + return 0;
517 +AVCodec mpeg_xvmc_vld_decoder = {
518 + "mpegvideo_xvmc",
519 + CODEC_TYPE_VIDEO,
520 + CODEC_ID_MPEG2VIDEO_XVMC,
521 + sizeof(Mpeg1Context),
522 + mpeg_xxmc_decode_init,
523 + NULL,
524 + mpeg_decode_end,
525 + mpeg_decode_frame,
526 + CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL,
527 + .flush= ff_mpeg_flush,
530 +#endif
533 /* this is ugly i know, but the alternative is too make
534 hundreds of vars global and prefix them with ff_mpeg1_
535 which is far uglier. */
536 Index: libavcodec/allcodecs.c
537 ===================================================================
538 --- libavcodec/allcodecs.c (revision 10927)
539 +++ libavcodec/allcodecs.c (working copy)
540 @@ -104,6 +104,7 @@
541 REGISTER_ENCDEC (MJPEG, mjpeg);
542 REGISTER_DECODER (MJPEGB, mjpegb);
543 REGISTER_DECODER (MMVIDEO, mmvideo);
544 + REGISTER_DECODER (MPEG_XVMC_VLD, mpeg_xvmc_vld);
545 REGISTER_DECODER (MPEG_XVMC, mpeg_xvmc);
546 REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video);
547 REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video);
548 Index: libavutil/avutil.h
549 ===================================================================
550 --- libavutil/avutil.h (revision 10927)
551 +++ libavutil/avutil.h (working copy)
552 @@ -84,6 +84,7 @@
553 PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4, 24bpp, full scale (jpeg)
554 PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
555 PIX_FMT_XVMC_MPEG2_IDCT,
556 + PIX_FMT_XVMC_MPEG2_VLD,
557 PIX_FMT_UYVY422, ///< Packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
558 PIX_FMT_UYYVYY411, ///< Packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
559 PIX_FMT_BGR32, ///< Packed RGB 8:8:8, 32bpp, (msb)8A 8B 8G 8R(lsb), in cpu endianness
560 Index: libmpcodecs/vd_ffmpeg.c
561 ===================================================================
562 --- libmpcodecs/vd_ffmpeg.c (revision 24
563 967)
564 +++ libmpcodecs/vd_ffmpeg.c (working copy)
565 @@ -12,6 +12,7 @@
566 #include "mpbswap.h"
568 #include "vd_internal.h"
569 +#include "libvo/video_out.h"
571 static vd_info_t info = {
572 "FFmpeg's libavcodec codec family",
573 @@ -155,6 +156,8 @@
574 case IMGFMT_XVMC_IDCT_MPEG2:
575 case IMGFMT_XVMC_MOCO_MPEG2:
576 if(avctx->pix_fmt==PIX_FMT_XVMC_MPEG2_IDCT) return CONTROL_TRUE;
577 + case IMGFMT_XVMC_VLD_MPEG2:
578 + if(avctx->pix_fmt==PIX_FMT_XVMC_MPEG2_VLD) return CONTROL_TRUE;
579 #endif
581 return CONTROL_FALSE;
582 @@ -225,6 +228,9 @@
583 vd_ffmpeg_ctx *ctx;
584 AVCodec *lavc_codec;
585 int lowres_w=0;
586 +#ifdef HAVE_XVMC
587 + char *voname = 0;
588 +#endif
589 int do_vis_debug= lavc_param_vismv || (lavc_param_debug&(FF_DEBUG_VIS_MB_TYPE|FF_DEBUG_VIS_QP));
591 if(!avcodec_inited){
592 @@ -260,11 +266,23 @@
594 #ifdef HAVE_XVMC
596 + // Try and get the name of the selected vo system
597 + // so that if its _not_ xvmc we can fail gracefully
598 + // and mplayer can fall back to a sw decoder
599 + if (sh->video_out) {
600 + vo_info_t *voinfo;
601 + vo_functions_t * shvoc=sh->video_out;
602 + if (shvoc) {
603 + voinfo = shvoc->info;
604 + if (voinfo) voname=voinfo->short_name;
607 #ifdef CODEC_CAP_HWACCEL
608 - if(lavc_codec->capabilities & CODEC_CAP_HWACCEL){
609 + if((lavc_codec->capabilities & CODEC_CAP_HWACCEL) &&
610 #else
611 - if(lavc_codec->id == CODEC_ID_MPEG2VIDEO_XVMC){
612 + if((lavc_codec->id == CODEC_ID_MPEG2VIDEO_XVMC) &&
613 #endif /* CODEC_CAP_HWACCEL */
614 + voname && !strcmp(voname,"xvmc") ) {
615 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_XVMCAcceleratedCodec);
616 assert(ctx->do_dr1);//these are must to!
617 assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails
618 @@ -535,6 +553,7 @@
619 #ifdef HAVE_XVMC
620 case PIX_FMT_XVMC_MPEG2_MC:ctx->best_csp=IMGFMT_XVMC_MOCO_MPEG2;break;
621 case PIX_FMT_XVMC_MPEG2_IDCT:ctx->best_csp=IMGFMT_XVMC_IDCT_MPEG2;break;
622 + case PIX_FMT_XVMC_MPEG2_VLD:ctx->best_csp=IMGFMT_XVMC_VLD_MPEG2;break;
623 #endif
624 default:
625 ctx->best_csp=0;
626 @@ -919,7 +938,11 @@
627 avctx->get_buffer= mc_get_buffer;
628 avctx->release_buffer= mc_release_buffer;
629 avctx->draw_horiz_band = mc_render_slice;
630 + if (avctx->xvmc_acceleration != 4)
631 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_XVMCAcceleratedMPEG2);
632 + else
633 + mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_XVMCVLDAcceleratedMPEG2);
635 assert(ctx->do_dr1);//these are must to!
636 assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails
637 avctx->flags|= CODEC_FLAG_EMU_EDGE;//do i need that??!!
638 Index: libmpcodecs/img_format.c
639 ===================================================================
640 --- libmpcodecs/img_format.c (revision 24967)
641 +++ libmpcodecs/img_format.c (working copy)
642 @@ -67,6 +67,7 @@
643 case IMGFMT_ZRMJPEGIB: return("Zoran MJPEG bottom field first");
644 case IMGFMT_XVMC_MOCO_MPEG2: return("MPEG1/2 Motion Compensation");
645 case IMGFMT_XVMC_IDCT_MPEG2: return("MPEG1/2 Motion Compensation and IDCT");
646 + case IMGFMT_XVMC_VLD_MPEG2: return("MPEG1/2 Motion Compensation and VLD");
648 snprintf(unknow_format,20,"Unknown 0x%04x",format);
649 return unknow_format;
650 Index: libmpcodecs/img_format.h
651 ===================================================================
652 --- libmpcodecs/img_format.h (revision 24967)
653 +++ libmpcodecs/img_format.h (working copy)
654 @@ -107,6 +107,7 @@
655 //these are chroma420
656 #define IMGFMT_XVMC_MOCO_MPEG2 (IMGFMT_XVMC|0x02)
657 #define IMGFMT_XVMC_IDCT_MPEG2 (IMGFMT_XVMC|0x82)
658 +#define IMGFMT_XVMC_VLD_MPEG2 (IMGFMT_XVMC|0x42)
660 typedef struct {
661 void* data;
662 Index: libmpdemux/stheader.h
663 ===================================================================
664 --- libmpdemux/stheader.h (revision 24967)
665 +++ libmpdemux/stheader.h (working copy)
666 @@ -78,6 +78,7 @@
667 int disp_w,disp_h; // display size (filled by fileformat parser)
668 // output driver/filters: (set by libmpcodecs core)
669 unsigned int outfmtidx;
670 + void* video_out; // the video_out handle, used for this video stream
671 struct vf_instance_s *vfilter; // the video filter chain, used for this video stream
672 int vf_inited;
673 #ifdef DYNAMIC_PLUGINS
674 Index: libvo/vo_xvmc.c
675 ===================================================================
676 --- libvo/vo_xvmc.c (revision 24967)
677 +++ libvo/vo_xvmc.c (working copy)
678 @@ -23,6 +23,11 @@
679 #include <X11/extensions/Xvlib.h>
680 #include <X11/extensions/XvMClib.h>
682 +#ifdef HAVE_XVMC_VLD
683 +#include <X11/extensions/vldXvMC.h>
684 +extern int has_xvmc_vld;
685 +#endif
687 #include "x11_common.h"
688 #include "xvmc_render.h"
690 @@ -45,6 +50,7 @@
693 #define UNUSED(x) ((void)(x))
694 +extern unsigned int video_format;
696 #include "libavcodec/avcodec.h"
697 #if LIBAVCODEC_BUILD < ((51<<16)+(40<<8)+2)
698 @@ -59,6 +65,8 @@
699 static int xv_port_request = 0;
700 static int bob_deinterlace;
701 static int top_field_first;
702 +static int use_deint_one;
703 +static int use_tv_clip;
705 static int image_width,image_height;
706 static int image_format;
707 @@ -123,7 +131,7 @@
708 "XVideo Motion Compensation",
709 "xvmc",
710 "Ivan Kalvachev <iive@users.sf.net>",
711 - ""
712 + "Ivor Hewitt <ivor@ivor.org> - VIA VLD support"
715 LIBVO_EXTERN(xvmc);
716 @@ -196,7 +204,23 @@
718 //end of vo_xv shm/xvimage code
720 +int hasVLDAcceleration()
722 +#ifdef HAVE_XVMC_VLD
723 + return XVMC_VLD == (surface_info.mc_type & XVMC_VLD);
724 +#else
725 + return 0;
726 +#endif
729 static int xvmc_check_surface_format(uint32_t format, XvMCSurfaceInfo * surf_info){
730 +#ifdef HAVE_XVMC_VLD
731 + if (format == IMGFMT_XVMC_VLD_MPEG2 ){
732 + if( surf_info->mc_type != (XVMC_VLD|XVMC_MPEG_2) ) return -1;
733 + if( surf_info->chroma_format != XVMC_CHROMA_FORMAT_420 ) return -1;
734 + return 0;
736 +#endif
737 if ( format == IMGFMT_XVMC_IDCT_MPEG2 ){
738 if( surf_info->mc_type != (XVMC_IDCT|XVMC_MPEG_2) ) return -1;
739 if( surf_info->chroma_format != XVMC_CHROMA_FORMAT_420 ) return -1;
740 @@ -361,6 +385,59 @@
741 return VO_TRUE;
745 +static int
746 +check_xvmc_vld()
748 + int rez;
749 + XvAdaptorInfo* ai;
750 + XvMCSurfaceInfo* surf_info;
751 + int max_adaptor;
752 + int max_surf;
753 + int i;
754 + unsigned long p;
755 + int s;
757 + rez = XvQueryAdaptors(mDisplay, DefaultRootWindow(mDisplay),
758 + &max_adaptor,&ai);
759 + if (rez != Success) return;
761 + if (mp_msg_test(MSGT_VO, MSGL_DBG3))
762 + printf("vo_xvmc: Querying %d adaptors for VLD\n", max_adaptor);
764 + for (i = 0; i < max_adaptor; i++)
766 + if (mp_msg_test(MSGT_VO,MSGL_DBG3))
767 + printf("vo_xvmc: Quering adaptor #%d for VLD\n", i);
768 + if (ai[i].type == 0) continue;
770 + // Probing every XV port
771 + for (p = ai[i].base_id; p < ai[i].base_id + ai[i].num_ports; p++)
773 + // Respect the users wish
774 + if ((xv_port_request != 0) && (xv_port_request != p)) continue;
775 + if (mp_msg_test(MSGT_VO,MSGL_DBG3))
776 + printf("vo_xvmc: Probing port #%ld for VLD\n", p);
777 + surf_info = XvMCListSurfaceTypes(mDisplay, p, &max_surf);
778 + if (surf_info == NULL || max_surf == 0) continue;
780 + // We have XvMC list!
781 + for(s = 0; s < max_surf; s++)
783 + // We have match!
784 + if (XVMC_VLD == (surf_info[s].mc_type & XVMC_VLD))
785 + has_xvmc_vld = 1;
787 + XFree(surf_info);
790 + XvFreeAdaptorInfo(ai);
792 + if (mp_msg_test(MSGT_VO,MSGL_DBG3) && has_xvmc_vld)
793 + printf("vo_xvmc: Found VLD support in XvMC\n");
797 static int preinit(const char *arg){
798 int xv_version,xv_release,xv_request_base,xv_event_base,xv_error_base;
799 int mc_eventBase,mc_errorBase;
800 @@ -377,9 +454,16 @@
801 { "sleep", OPT_ARG_BOOL, &use_sleep, NULL },
802 { "queue", OPT_ARG_BOOL, &use_queue, NULL },
803 { "bobdeint", OPT_ARG_BOOL, &bob_deinterlace, NULL },
804 + { "onedeint", OPT_ARG_BOOL, &use_deint_one, NULL },
805 + { "tv-clip", OPT_ARG_BOOL, &use_tv_clip, NULL },
806 { NULL }
809 + // If the video is not MPEG1 or MPEG2, we can't decode it, so
810 + // fail cleanly to allow mplayer to fallback to another vo system
811 + if (video_format != 0x10000001 && video_format != 0x10000002) return -1;
814 //Obtain display handler
815 if (!vo_init()) return -1;//vo_xv
817 @@ -415,6 +499,8 @@
818 use_sleep = 0;
819 use_queue = 0;
820 bob_deinterlace = 0;
821 + use_deint_one = 0;
822 + use_tv_clip = 0;
824 /* parse suboptions */
825 if ( subopt_parse( arg, subopts ) != 0 )
826 @@ -424,6 +510,9 @@
828 xv_setup_colorkeyhandling( ck_method_arg.str, ck_src_arg.str );
830 + // Check whether XvMC supports VLD
831 + check_xvmc_vld();
833 return 0;
836 @@ -505,6 +594,8 @@
837 if(surface_info.chroma_format == XVMC_CHROMA_FORMAT_444)
838 blocks_per_macroblock = 12;
840 +if (!hasVLDAcceleration())
842 rez = XvMCCreateBlocks(mDisplay,&ctx,numblocks*blocks_per_macroblock,&data_blocks);
843 if( rez != Success ){
844 XvMCDestroyContext(mDisplay,&ctx);
845 @@ -520,6 +611,8 @@
847 printf("vo_xvmc: mv_blocks allocated\n");
851 if(surface_render==NULL)
852 surface_render=malloc(MAX_SURFACES*sizeof(xvmc_render_state_t));//easy mem debug
853 memset(surface_render,0,MAX_SURFACES*sizeof(xvmc_render_state_t));
854 @@ -538,6 +631,11 @@
855 surface_render[i].chroma_format = surface_info.chroma_format;
856 surface_render[i].unsigned_intra = (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED;
857 surface_render[i].p_surface = &surface_array[i];
859 + surface_render[i].state = 0;
860 + surface_render[i].disp = mDisplay;
861 + surface_render[i].ctx = &ctx;
863 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
864 printf("vo_xvmc: surface[%d] = %p .rndr=%p\n",i,&surface_array[i], &surface_render[i]);
866 @@ -993,6 +1091,8 @@
867 int rez;
868 int clipX,clipY,clipW,clipH;
869 int i;
870 + int srcY=0, srcH=image_height;
871 + int fieldnobob;
873 if(p_render_surface == NULL)
874 return;
875 @@ -1002,22 +1102,38 @@
876 clipW = vo_dwidth+vo_panscan_x;
877 clipH = vo_dheight+vo_panscan_y;
879 + if (use_tv_clip) {
880 + /*
881 + * Clip top few lines off to get rid of annoying flicker
882 + * when using bob de-interlacing on TV sourced video.
883 + */
884 + srcY+=4;
885 + srcH-=4;
888 if(draw_ck)
889 vo_xv_draw_colorkey(clipX,clipY,clipW,clipH);
891 if(benchmark)
892 return;
894 + fieldnobob = XVMC_FRAME_PICTURE;
896 + if (use_deint_one)
897 + fieldnobob = (top_field_first) ? XVMC_TOP_FIELD : XVMC_BOTTOM_FIELD;
899 for (i = 1; i <= bob_deinterlace + 1; i++) {
900 - int field = top_field_first ? i : i ^ 3;
901 + int field = top_field_first ? i : i ^ XVMC_FRAME_PICTURE;
902 rez = XvMCPutSurface(mDisplay, p_render_surface->p_surface,
903 vo_window,
904 - 0, 0, image_width, image_height,
905 + 0, srcY, image_width, srcH,
906 clipX, clipY, clipW, clipH,
907 - bob_deinterlace ? field : 3);
908 - //p_render_surface_to_show->display_flags);
909 + bob_deinterlace ? field : fieldnobob);
910 + if (i == 1 && bob_deinterlace) {
911 + usleep(10*1000);
913 if(rez != Success){
914 - printf("vo_xvmc: PutSurface failer, critical error %d!\n",rez);
915 + printf("vo_xvmc: PutSurface failure, critical error %d!\n",rez);
916 assert(0);
919 @@ -1109,9 +1225,11 @@
921 if( number_of_surfaces ){
923 + if (!hasVLDAcceleration())
925 XvMCDestroyMacroBlocks(mDisplay,&mv_blocks);
926 XvMCDestroyBlocks(mDisplay,&data_blocks);
929 for(i=0; i<number_of_surfaces; i++)
931 XvMCHideSurface(mDisplay,&surface_array[i]);//it doesn't hurt, I hope
932 @@ -1189,6 +1307,17 @@
933 assert( rndr != NULL );
934 assert( rndr->magic == MP_XVMC_RENDER_MAGIC );
936 + if (hasVLDAcceleration())
938 + rez = XvMCPutSlice2(mDisplay,&ctx,(char*)rndr->slice_data,
939 + rndr->slice_datalen,
940 + rndr->slice_code);
941 + if (rez)
942 + printf("vo_xxmc::slice Error %d\n",rez);
945 + else
947 rez = XvMCRenderSurface(mDisplay,&ctx,rndr->picture_structure,
948 rndr->p_surface,
949 rndr->p_past_surface,
950 @@ -1200,7 +1329,7 @@
951 if(rez != Success)
953 int i;
954 - printf("vo_xvmc::slice: RenderSirface returned %d\n",rez);
955 + printf("vo_xvmc::slice: RenderSurface returned %d\n",rez);
957 printf("vo_xvmc::slice: pict=%d,flags=%x,start_blocks=%d,num_blocks=%d\n",
958 rndr->picture_structure,rndr->flags,rndr->start_mv_blocks_num,
959 @@ -1228,6 +1357,7 @@
960 rez = XvMCFlushSurface(mDisplay, rndr->p_surface);
961 assert(rez==Success);
964 // rndr->start_mv_blocks_num += rndr->filled_mv_blocks_num;
965 rndr->start_mv_blocks_num = 0;
966 rndr->filled_mv_blocks_num = 0;
967 @@ -1337,8 +1467,16 @@
969 // these are shared!! so watch out
970 // do call RenderSurface before overwriting
971 +if (!hasVLDAcceleration())
973 mpi->planes[0] = (char*)data_blocks.blocks;
974 mpi->planes[1] = (char*)mv_blocks.macro_blocks;
976 +else
978 + mpi->planes[0] = 1;
979 + mpi->planes[1] = 0;
981 mpi->priv =
982 mpi->planes[2] = (char*)rndr;
984 Index: mencoder.c
985 ===================================================================
986 --- mencoder.c (revision 24967)
987 +++ mencoder.c (working copy)
988 @@ -771,6 +771,7 @@
989 mux_v->bih=NULL;
991 sh_video->codec=NULL;
992 +sh_video->video_out=NULL;
993 sh_video->vfilter=NULL; // fixme!
995 switch(mux_v->codec){
996 Index: mplayer.c
997 ===================================================================
998 --- mplayer.c (revision 24967)
999 +++ mplayer.c (working copy)
1000 @@ -85,6 +85,8 @@
1001 int quiet=0;
1002 int enable_mouse_movements=0;
1004 +unsigned int video_format=0;
1006 #ifdef WIN32
1007 char * proc_priority=NULL;
1008 #endif
1009 @@ -1897,10 +1899,16 @@
1010 //shouldn't we set dvideo->id=-2 when we fail?
1011 vo_config_count=0;
1012 //if((mpctx->video_out->preinit(vo_subdevice))!=0){
1014 + // let the video driver know what format the video is in so it can
1015 + // reject it if it wants - lets vo_xvmc fail if ffmpeg12mc codec not used
1016 + video_format=sh_video->format;
1018 if(!(mpctx->video_out=init_best_video_out(video_driver_list))){
1019 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
1020 goto err_out;
1022 + sh_video->video_out=mpctx->video_out;
1023 inited_flags|=INITED_VO;
1026 Index: xvmc_render.h
1027 ===================================================================
1028 --- xvmc_render.h (revision 24967)
1029 +++ xvmc_render.h (working copy)
1030 @@ -5,6 +5,9 @@
1031 #include <X11/extensions/Xvlib.h>
1032 #include <X11/extensions/XvMClib.h>
1034 +#ifdef HAVE_XVMC_VLD
1035 +#include <X11/extensions/vldXvMC.h>
1036 +#endif
1038 //the surface should be shown, video driver manipulate this
1039 #define MP_XVMC_STATE_DISPLAY_PENDING 1
1040 @@ -27,6 +30,15 @@
1041 int idct;//does we use IDCT acceleration?
1042 int chroma_format;//420,422,444
1043 int unsigned_intra;//+-128 for intra pictures after clip
1044 +#ifdef HAVE_XVMC_VLD
1045 + // These are for the XVMC VLD slice interface
1046 + int pict_type; //this is for skipping frames
1047 + int slice_code;
1048 + int slice_datalen;
1049 + unsigned char *slice_data;
1050 + Display *disp;
1051 + XvMCContext *ctx;
1052 +#endif
1053 XvMCSurface* p_surface;//pointer to rendered surface, never changed
1055 //these are changed by decoder