2 ===================================================================
3 --- codec-cfg.c (revision 24967)
4 +++ codec-cfg.c (working copy)
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},
14 ===================================================================
15 --- configure (revision 24967)
16 +++ configure (working copy)
20 _xvmc=no #auto when complete
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
34 @@ -4001,6 +4002,31 @@
39 +if test "$_xvmc" = yes ; then
42 +#include <X11/Xlib.h>
43 +#include <X11/extensions/Xvlib.h>
44 +#include <X11/extensions/XvMClib.h>
45 +#include <X11/extensions/vldXvMC.h>
47 + (void) XvMCQueryExtension(0,0,0);
48 + (void) XvMCCreateContext(0,0,0,0,0,0,0);
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"
56 + _def_xvmc_vld='#undef HAVE_XVMC_VLD'
57 + _libavdecoders=`echo $_libavdecoders | sed -e s/MPEG_XVMC_VLD_DECODER// `
64 if test "$_xinerama" = auto ; then
74 Index: etc/codecs.conf
75 ===================================================================
76 --- etc/codecs.conf (revision 24967)
77 +++ etc/codecs.conf (working copy)
79 fourcc MMES,mmes ; matrox mpeg2 in avi
86 Index: help/help_mp-en.h
87 ===================================================================
88 --- help/help_mp-en.h (revision 24967)
89 +++ help/help_mp-en.h (working copy)
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)
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;
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);
121 + if (!s->first_field)
122 + last = render; // predict second field from the first
126 + if (last->magic != MP_XVMC_RENDER_MAGIC)
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;
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)
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;
164 + memset(&binfo, 0, sizeof(binfo));
165 + memset(&qmatrix, 0, sizeof(qmatrix));
168 assert(avctx != NULL);
170 render = (xvmc_render_state_t*)s->current_picture.data[2];
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;
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){
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!");
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!");
222 switch(s->pict_type){
224 return 0;// no prediction from other frames
226 render->p_past_surface = last->p_surface;
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;
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;
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;
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);
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);
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,
311 + av_log(avctx,AV_LOG_ERROR, "XvMCBeginSurface: Error: %d\n", status);
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;
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;
348 +#ifdef HAVE_XVMC_VLD
349 +static int length_to_next_start(uint8_t* pbuf_ptr, int buf_size)
352 + unsigned int state = 0xFFFFFFFF, v;
354 + buf_ptr = pbuf_ptr;
355 + while (buf_ptr < pbuf_ptr + buf_size)
358 + if (state == 0x000001) {
359 + return buf_ptr - pbuf_ptr - 4;
361 + state = ((state << 8) | v) & 0xffffff;
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;
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;
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);
395 Index: libavcodec/xvmc_render.h
396 ===================================================================
397 --- libavcodec/xvmc_render.h (revision 10927)
398 +++ libavcodec/xvmc_render.h (working copy)
400 #include <X11/extensions/Xvlib.h>
401 #include <X11/extensions/XvMClib.h>
403 +#ifdef HAVE_XVMC_VLD
404 +#include <X11/extensions/vldXvMC.h>
407 //the surface should be shown, video driver manipulates this
408 #define MP_XVMC_STATE_DISPLAY_PENDING 1
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
418 + unsigned char *slice_data;
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)
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;
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};
444 PIX_FMT_XVMC_MPEG2_IDCT,
445 PIX_FMT_XVMC_MPEG2_MC,
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,
453 uint8_t ff_mpeg12_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3];
455 @@ -1313,6 +1325,9 @@
458 if(avctx->xvmc_acceleration){
460 + avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_vld_mpg2_420);
462 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
464 if(s->chroma_format < 2){
465 @@ -1682,6 +1697,16 @@
469 +#ifdef HAVE_XVMC_VLD
470 + if (s->avctx->xvmc_acceleration == 4){
471 + int used = XVMC_decode_slice(s, mb_y, *buf, buf_size);
473 + return DECODE_SLICE_ERROR;
475 + return DECODE_SLICE_OK;
479 init_get_bits(&s->gb, *buf, buf_size*8);
481 ff_mpeg1_clean_buffers(s);
482 @@ -2077,6 +2102,9 @@
485 if(avctx->xvmc_acceleration){
487 + avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_vld_mpg2_420);
489 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
491 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_420);
492 @@ -2474,6 +2502,43 @@
496 +#ifdef HAVE_XVMC_VLD
497 +static int mpeg_xxmc_decode_init(AVCodecContext *avctx){
500 + return mpeg_mc_decode_init(avctx);
501 + if( avctx->thread_count > 1)
503 + if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
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;
517 +AVCodec mpeg_xvmc_vld_decoder = {
520 + CODEC_ID_MPEG2VIDEO_XVMC,
521 + sizeof(Mpeg1Context),
522 + mpeg_xxmc_decode_init,
526 + CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL,
527 + .flush= ff_mpeg_flush,
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)
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)
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
564 +++ libmpcodecs/vd_ffmpeg.c (working copy)
568 #include "vd_internal.h"
569 +#include "libvo/video_out.h"
571 static vd_info_t info = {
572 "FFmpeg's libavcodec codec family",
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;
581 return CONTROL_FALSE;
589 int do_vis_debug= lavc_param_vismv || (lavc_param_debug&(FF_DEBUG_VIS_MB_TYPE|FF_DEBUG_VIS_QP));
592 @@ -260,11 +266,23 @@
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) {
601 + vo_functions_t * shvoc=sh->video_out;
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) &&
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
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;
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);
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)
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)
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)
662 Index: libmpdemux/stheader.h
663 ===================================================================
664 --- libmpdemux/stheader.h (revision 24967)
665 +++ libmpdemux/stheader.h (working copy)
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
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)
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;
687 #include "x11_common.h"
688 #include "xvmc_render.h"
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)
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;
708 "XVideo Motion Compensation",
710 "Ivan Kalvachev <iive@users.sf.net>",
712 + "Ivor Hewitt <ivor@ivor.org> - VIA VLD support"
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);
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;
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;
750 + XvMCSurfaceInfo* surf_info;
757 + rez = XvQueryAdaptors(mDisplay, DefaultRootWindow(mDisplay),
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++)
784 + if (XVMC_VLD == (surf_info[s].mc_type & XVMC_VLD))
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;
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 },
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
824 /* parse suboptions */
825 if ( subopt_parse( arg, subopts ) != 0 )
828 xv_setup_colorkeyhandling( ck_method_arg.str, ck_src_arg.str );
830 + // Check whether XvMC supports VLD
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);
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));
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]);
868 int clipX,clipY,clipW,clipH;
870 + int srcY=0, srcH=image_height;
873 if(p_render_surface == NULL)
875 @@ -1002,22 +1102,38 @@
876 clipW = vo_dwidth+vo_panscan_x;
877 clipH = vo_dheight+vo_panscan_y;
881 + * Clip top few lines off to get rid of annoying flicker
882 + * when using bob de-interlacing on TV sourced video.
889 vo_xv_draw_colorkey(clipX,clipY,clipW,clipH);
894 + fieldnobob = XVMC_FRAME_PICTURE;
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,
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) {
914 - printf("vo_xvmc: PutSurface failer, critical error %d!\n",rez);
915 + printf("vo_xvmc: PutSurface failure, critical error %d!\n",rez);
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,
942 + printf("vo_xxmc::slice Error %d\n",rez);
947 rez = XvMCRenderSurface(mDisplay,&ctx,rndr->picture_structure,
949 rndr->p_past_surface,
950 @@ -1200,7 +1329,7 @@
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;
978 + mpi->planes[0] = 1;
979 + mpi->planes[1] = 0;
982 mpi->planes[2] = (char*)rndr;
985 ===================================================================
986 --- mencoder.c (revision 24967)
987 +++ mencoder.c (working copy)
991 sh_video->codec=NULL;
992 +sh_video->video_out=NULL;
993 sh_video->vfilter=NULL; // fixme!
995 switch(mux_v->codec){
997 ===================================================================
998 --- mplayer.c (revision 24967)
999 +++ mplayer.c (working copy)
1002 int enable_mouse_movements=0;
1004 +unsigned int video_format=0;
1007 char * proc_priority=NULL;
1009 @@ -1897,10 +1899,16 @@
1010 //shouldn't we set dvideo->id=-2 when we fail?
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);
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)
1031 #include <X11/extensions/Xvlib.h>
1032 #include <X11/extensions/XvMClib.h>
1034 +#ifdef HAVE_XVMC_VLD
1035 +#include <X11/extensions/vldXvMC.h>
1038 //the surface should be shown, video driver manipulate this
1039 #define MP_XVMC_STATE_DISPLAY_PENDING 1
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
1048 + int slice_datalen;
1049 + unsigned char *slice_data;
1053 XvMCSurface* p_surface;//pointer to rendered surface, never changed
1055 //these are changed by decoder