changeset 8799:cb4441bed13a libavcodec

Rename vdpauvideo.c --> vdpau.c and xvmcvideo.c --> xvmc.c to better fit the general libavcodec naming structure.
author diego
date Wed, 11 Feb 2009 12:01:59 +0000
parents a5c8210814d7
children 8ec0175bbcb5
files Makefile vdpau.c vdpauvideo.c xvmc.c xvmcvideo.c
diffstat 5 files changed, 617 insertions(+), 617 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Wed Feb 11 11:16:00 2009 +0000
+++ b/Makefile	Wed Feb 11 12:01:59 2009 +0000
@@ -103,7 +103,7 @@
 OBJS-$(CONFIG_H263P_ENCODER)           += mpegvideo_enc.o motion_est.o ratecontrol.o h263.o mpeg12data.o mpegvideo.o error_resilience.o
 OBJS-$(CONFIG_H264_DECODER)            += h264.o h264idct.o h264pred.o h264_parser.o cabac.o mpegvideo.o error_resilience.o
 OBJS-$(CONFIG_H264_ENCODER)            += h264enc.o h264dspenc.o
-OBJS-$(CONFIG_H264_VDPAU_DECODER)      += vdpauvideo.o h264.o h264idct.o h264pred.o h264_parser.o cabac.o mpegvideo.o error_resilience.o
+OBJS-$(CONFIG_H264_VDPAU_DECODER)      += vdpau.o h264.o h264idct.o h264pred.o h264_parser.o cabac.o mpegvideo.o error_resilience.o
 OBJS-$(CONFIG_HUFFYUV_DECODER)         += huffyuv.o
 OBJS-$(CONFIG_HUFFYUV_ENCODER)         += huffyuv.o
 OBJS-$(CONFIG_IDCIN_DECODER)           += idcinvideo.o
@@ -252,7 +252,7 @@
 OBJS-$(CONFIG_XAN_WC4_DECODER)         += xan.o
 OBJS-$(CONFIG_XL_DECODER)              += xl.o
 OBJS-$(CONFIG_XSUB_DECODER)            += xsubdec.o
-OBJS-$(CONFIG_XVMC)                    += xvmcvideo.o
+OBJS-$(CONFIG_XVMC)                    += xvmc.o
 OBJS-$(CONFIG_ZLIB_DECODER)            += lcldec.o
 OBJS-$(CONFIG_ZLIB_ENCODER)            += lclenc.o
 OBJS-$(CONFIG_ZMBV_DECODER)            += zmbv.o
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vdpau.c	Wed Feb 11 12:01:59 2009 +0000
@@ -0,0 +1,305 @@
+/*
+ * Video Decode and Presentation API for UNIX (VDPAU) is used for
+ * HW decode acceleration for MPEG-1/2, H.264 and VC-1.
+ *
+ * Copyright (c) 2008 NVIDIA
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <limits.h>
+#include "avcodec.h"
+#include "h264.h"
+#include "vc1.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+#include "vdpau.h"
+#include "vdpau_internal.h"
+
+/**
+ * \addtogroup VDPAU_Decoding
+ *
+ * @{
+ */
+
+void ff_vdpau_h264_set_reference_frames(MpegEncContext *s)
+{
+    H264Context *h = s->avctx->priv_data;
+    struct vdpau_render_state * render, * render_ref;
+    VdpReferenceFrameH264 * rf, * rf2;
+    Picture * pic;
+    int i, list, pic_frame_idx;
+
+    render = (struct vdpau_render_state*)s->current_picture_ptr->data[0];
+    assert(render);
+
+    rf = &render->info.h264.referenceFrames[0];
+#define H264_RF_COUNT FF_ARRAY_ELEMS(render->info.h264.referenceFrames)
+
+    for (list = 0; list < 2; ++list) {
+        Picture **lp = list ? h->long_ref : h->short_ref;
+        int ls = list ? h->long_ref_count : h->short_ref_count;
+
+        for (i = 0; i < ls; ++i) {
+            pic = lp[i];
+            if (!pic || !pic->reference)
+                continue;
+            pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num;
+
+            render_ref = (struct vdpau_render_state*)pic->data[0];
+            assert(render_ref);
+
+            rf2 = &render->info.h264.referenceFrames[0];
+            while (rf2 != rf) {
+                if (
+                    (rf2->surface == render_ref->surface)
+                    && (rf2->is_long_term == pic->long_ref)
+                    && (rf2->frame_idx == pic_frame_idx)
+                )
+                    break;
+                ++rf2;
+            }
+            if (rf2 != rf) {
+                rf2->top_is_reference    |= (pic->reference & PICT_TOP_FIELD)    ? VDP_TRUE : VDP_FALSE;
+                rf2->bottom_is_reference |= (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
+                continue;
+            }
+
+            if (rf >= &render->info.h264.referenceFrames[H264_RF_COUNT])
+                continue;
+
+            rf->surface             = render_ref->surface;
+            rf->is_long_term        = pic->long_ref;
+            rf->top_is_reference    = (pic->reference & PICT_TOP_FIELD)    ? VDP_TRUE : VDP_FALSE;
+            rf->bottom_is_reference = (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
+            rf->field_order_cnt[0]  = pic->field_poc[0];
+            rf->field_order_cnt[1]  = pic->field_poc[1];
+            rf->frame_idx           = pic_frame_idx;
+
+            ++rf;
+        }
+    }
+
+    for (; rf < &render->info.h264.referenceFrames[H264_RF_COUNT]; ++rf) {
+        rf->surface             = VDP_INVALID_HANDLE;
+        rf->is_long_term        = 0;
+        rf->top_is_reference    = 0;
+        rf->bottom_is_reference = 0;
+        rf->field_order_cnt[0]  = 0;
+        rf->field_order_cnt[1]  = 0;
+        rf->frame_idx           = 0;
+    }
+}
+
+void ff_vdpau_add_data_chunk(MpegEncContext *s,
+                             const uint8_t *buf, int buf_size)
+{
+    struct vdpau_render_state * render;
+
+    render = (struct vdpau_render_state*)s->current_picture_ptr->data[0];
+    assert(render);
+
+    render->bitstream_buffers= av_fast_realloc(
+        render->bitstream_buffers,
+        &render->bitstream_buffers_allocated,
+        sizeof(*render->bitstream_buffers)*(render->bitstream_buffers_used + 1)
+    );
+
+    render->bitstream_buffers[render->bitstream_buffers_used].struct_version  = VDP_BITSTREAM_BUFFER_VERSION;
+    render->bitstream_buffers[render->bitstream_buffers_used].bitstream       = buf;
+    render->bitstream_buffers[render->bitstream_buffers_used].bitstream_bytes = buf_size;
+    render->bitstream_buffers_used++;
+}
+
+void ff_vdpau_h264_picture_complete(MpegEncContext *s)
+{
+    H264Context *h = s->avctx->priv_data;
+    struct vdpau_render_state * render;
+
+    render = (struct vdpau_render_state*)s->current_picture_ptr->data[0];
+    assert(render);
+
+    render->info.h264.slice_count = h->slice_num;
+    if (render->info.h264.slice_count < 1)
+        return;
+
+    for (int i = 0; i < 2; ++i) {
+        int foc = s->current_picture_ptr->field_poc[i];
+        if (foc == INT_MAX)
+            foc = 0;
+        render->info.h264.field_order_cnt[i] = foc;
+    }
+
+    render->info.h264.is_reference                           = s->current_picture_ptr->reference ? VDP_TRUE : VDP_FALSE;
+    render->info.h264.frame_num                              = h->frame_num;
+    render->info.h264.field_pic_flag                         = s->picture_structure != PICT_FRAME;
+    render->info.h264.bottom_field_flag                      = s->picture_structure == PICT_BOTTOM_FIELD;
+    render->info.h264.num_ref_frames                         = h->sps.ref_frame_count;
+    render->info.h264.mb_adaptive_frame_field_flag           = h->sps.mb_aff;
+    render->info.h264.constrained_intra_pred_flag            = h->pps.constrained_intra_pred;
+    render->info.h264.weighted_pred_flag                     = h->pps.weighted_pred;
+    render->info.h264.weighted_bipred_idc                    = h->pps.weighted_bipred_idc;
+    render->info.h264.frame_mbs_only_flag                    = h->sps.frame_mbs_only_flag;
+    render->info.h264.transform_8x8_mode_flag                = h->pps.transform_8x8_mode;
+    render->info.h264.chroma_qp_index_offset                 = h->pps.chroma_qp_index_offset[0];
+    render->info.h264.second_chroma_qp_index_offset          = h->pps.chroma_qp_index_offset[1];
+    render->info.h264.pic_init_qp_minus26                    = h->pps.init_qp - 26;
+    render->info.h264.num_ref_idx_l0_active_minus1           = h->pps.ref_count[0] - 1;
+    render->info.h264.num_ref_idx_l1_active_minus1           = h->pps.ref_count[1] - 1;
+    render->info.h264.log2_max_frame_num_minus4              = h->sps.log2_max_frame_num - 4;
+    render->info.h264.pic_order_cnt_type                     = h->sps.poc_type;
+    render->info.h264.log2_max_pic_order_cnt_lsb_minus4      = h->sps.log2_max_poc_lsb - 4;
+    render->info.h264.delta_pic_order_always_zero_flag       = h->sps.delta_pic_order_always_zero_flag;
+    render->info.h264.direct_8x8_inference_flag              = h->sps.direct_8x8_inference_flag;
+    render->info.h264.entropy_coding_mode_flag               = h->pps.cabac;
+    render->info.h264.pic_order_present_flag                 = h->pps.pic_order_present;
+    render->info.h264.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present;
+    render->info.h264.redundant_pic_cnt_present_flag         = h->pps.redundant_pic_cnt_present;
+    memcpy(render->info.h264.scaling_lists_4x4, h->pps.scaling_matrix4, sizeof(render->info.h264.scaling_lists_4x4));
+    memcpy(render->info.h264.scaling_lists_8x8, h->pps.scaling_matrix8, sizeof(render->info.h264.scaling_lists_8x8));
+
+    ff_draw_horiz_band(s, 0, s->avctx->height);
+    render->bitstream_buffers_used = 0;
+}
+
+void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf,
+                                    int buf_size, int slice_count)
+{
+    struct vdpau_render_state * render, * last, * next;
+    int i;
+
+    render = (struct vdpau_render_state*)s->current_picture_ptr->data[0];
+    assert(render);
+
+    /* fill VdpPictureInfoMPEG1Or2 struct */
+    render->info.mpeg.picture_structure          = s->picture_structure;
+    render->info.mpeg.picture_coding_type        = s->pict_type;
+    render->info.mpeg.intra_dc_precision         = s->intra_dc_precision;
+    render->info.mpeg.frame_pred_frame_dct       = s->frame_pred_frame_dct;
+    render->info.mpeg.concealment_motion_vectors = s->concealment_motion_vectors;
+    render->info.mpeg.intra_vlc_format           = s->intra_vlc_format;
+    render->info.mpeg.alternate_scan             = s->alternate_scan;
+    render->info.mpeg.q_scale_type               = s->q_scale_type;
+    render->info.mpeg.top_field_first            = s->top_field_first;
+    render->info.mpeg.full_pel_forward_vector    = s->full_pel[0]; // MPEG-1 only.  Set 0 for MPEG-2
+    render->info.mpeg.full_pel_backward_vector   = s->full_pel[1]; // MPEG-1 only.  Set 0 for MPEG-2
+    render->info.mpeg.f_code[0][0]               = s->mpeg_f_code[0][0]; // For MPEG-1 fill both horiz. & vert.
+    render->info.mpeg.f_code[0][1]               = s->mpeg_f_code[0][1];
+    render->info.mpeg.f_code[1][0]               = s->mpeg_f_code[1][0];
+    render->info.mpeg.f_code[1][1]               = s->mpeg_f_code[1][1];
+    for (i = 0; i < 64; ++i) {
+        render->info.mpeg.intra_quantizer_matrix[i]     = s->intra_matrix[i];
+        render->info.mpeg.non_intra_quantizer_matrix[i] = s->inter_matrix[i];
+    }
+
+    render->info.mpeg.forward_reference          = VDP_INVALID_HANDLE;
+    render->info.mpeg.backward_reference         = VDP_INVALID_HANDLE;
+
+    switch(s->pict_type){
+    case  FF_B_TYPE:
+        next = (struct vdpau_render_state*)s->next_picture.data[0];
+        assert(next);
+        render->info.mpeg.backward_reference     = next->surface;
+        // no return here, going to set forward prediction
+    case  FF_P_TYPE:
+        last = (struct vdpau_render_state*)s->last_picture.data[0];
+        if (!last) // FIXME: Does this test make sense?
+            last = render; // predict second field from the first
+        render->info.mpeg.forward_reference      = last->surface;
+    }
+
+    ff_vdpau_add_data_chunk(s, buf, buf_size);
+
+    render->info.mpeg.slice_count                = slice_count;
+
+    if (slice_count)
+        ff_draw_horiz_band(s, 0, s->avctx->height);
+    render->bitstream_buffers_used               = 0;
+}
+
+void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf,
+                                 int buf_size)
+{
+    VC1Context *v = s->avctx->priv_data;
+    struct vdpau_render_state * render, * last, * next;
+
+    render = (struct vdpau_render_state*)s->current_picture.data[0];
+    assert(render);
+
+    /*  fill LvPictureInfoVC1 struct */
+    render->info.vc1.frame_coding_mode  = v->fcm;
+    render->info.vc1.postprocflag       = v->postprocflag;
+    render->info.vc1.pulldown           = v->broadcast;
+    render->info.vc1.interlace          = v->interlace;
+    render->info.vc1.tfcntrflag         = v->tfcntrflag;
+    render->info.vc1.finterpflag        = v->finterpflag;
+    render->info.vc1.psf                = v->psf;
+    render->info.vc1.dquant             = v->dquant;
+    render->info.vc1.panscan_flag       = v->panscanflag;
+    render->info.vc1.refdist_flag       = v->refdist_flag;
+    render->info.vc1.quantizer          = v->quantizer_mode;
+    render->info.vc1.extended_mv        = v->extended_mv;
+    render->info.vc1.extended_dmv       = v->extended_dmv;
+    render->info.vc1.overlap            = v->overlap;
+    render->info.vc1.vstransform        = v->vstransform;
+    render->info.vc1.loopfilter         = v->s.loop_filter;
+    render->info.vc1.fastuvmc           = v->fastuvmc;
+    render->info.vc1.range_mapy_flag    = v->range_mapy_flag;
+    render->info.vc1.range_mapy         = v->range_mapy;
+    render->info.vc1.range_mapuv_flag   = v->range_mapuv_flag;
+    render->info.vc1.range_mapuv        = v->range_mapuv;
+    /* Specific to simple/main profile only */
+    render->info.vc1.multires           = v->multires;
+    render->info.vc1.syncmarker         = v->s.resync_marker;
+    render->info.vc1.rangered           = v->rangered;
+    render->info.vc1.maxbframes         = v->s.max_b_frames;
+
+    render->info.vc1.deblockEnable      = v->postprocflag & 1;
+    render->info.vc1.pquant             = v->pq;
+
+    render->info.vc1.forward_reference  = VDP_INVALID_HANDLE;
+    render->info.vc1.backward_reference = VDP_INVALID_HANDLE;
+
+    if (v->bi_type)
+        render->info.vc1.picture_type = 4;
+    else
+        render->info.vc1.picture_type = s->pict_type - 1 + s->pict_type / 3;
+
+    switch(s->pict_type){
+    case  FF_B_TYPE:
+        next = (struct vdpau_render_state*)s->next_picture.data[0];
+        assert(next);
+        render->info.vc1.backward_reference = next->surface;
+        // no break here, going to set forward prediction
+    case  FF_P_TYPE:
+        last = (struct vdpau_render_state*)s->last_picture.data[0];
+        if (!last) // FIXME: Does this test make sense?
+            last = render; // predict second field from the first
+        render->info.vc1.forward_reference = last->surface;
+    }
+
+    ff_vdpau_add_data_chunk(s, buf, buf_size);
+
+    render->info.vc1.slice_count          = 1;
+
+    ff_draw_horiz_band(s, 0, s->avctx->height);
+    render->bitstream_buffers_used        = 0;
+}
+
+/* @}*/
--- a/vdpauvideo.c	Wed Feb 11 11:16:00 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,305 +0,0 @@
-/*
- * Video Decode and Presentation API for UNIX (VDPAU) is used for
- * HW decode acceleration for MPEG-1/2, H.264 and VC-1.
- *
- * Copyright (c) 2008 NVIDIA
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <limits.h>
-#include "avcodec.h"
-#include "h264.h"
-#include "vc1.h"
-
-#undef NDEBUG
-#include <assert.h>
-
-#include "vdpau.h"
-#include "vdpau_internal.h"
-
-/**
- * \addtogroup VDPAU_Decoding
- *
- * @{
- */
-
-void ff_vdpau_h264_set_reference_frames(MpegEncContext *s)
-{
-    H264Context *h = s->avctx->priv_data;
-    struct vdpau_render_state * render, * render_ref;
-    VdpReferenceFrameH264 * rf, * rf2;
-    Picture * pic;
-    int i, list, pic_frame_idx;
-
-    render = (struct vdpau_render_state*)s->current_picture_ptr->data[0];
-    assert(render);
-
-    rf = &render->info.h264.referenceFrames[0];
-#define H264_RF_COUNT FF_ARRAY_ELEMS(render->info.h264.referenceFrames)
-
-    for (list = 0; list < 2; ++list) {
-        Picture **lp = list ? h->long_ref : h->short_ref;
-        int ls = list ? h->long_ref_count : h->short_ref_count;
-
-        for (i = 0; i < ls; ++i) {
-            pic = lp[i];
-            if (!pic || !pic->reference)
-                continue;
-            pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num;
-
-            render_ref = (struct vdpau_render_state*)pic->data[0];
-            assert(render_ref);
-
-            rf2 = &render->info.h264.referenceFrames[0];
-            while (rf2 != rf) {
-                if (
-                    (rf2->surface == render_ref->surface)
-                    && (rf2->is_long_term == pic->long_ref)
-                    && (rf2->frame_idx == pic_frame_idx)
-                )
-                    break;
-                ++rf2;
-            }
-            if (rf2 != rf) {
-                rf2->top_is_reference    |= (pic->reference & PICT_TOP_FIELD)    ? VDP_TRUE : VDP_FALSE;
-                rf2->bottom_is_reference |= (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
-                continue;
-            }
-
-            if (rf >= &render->info.h264.referenceFrames[H264_RF_COUNT])
-                continue;
-
-            rf->surface             = render_ref->surface;
-            rf->is_long_term        = pic->long_ref;
-            rf->top_is_reference    = (pic->reference & PICT_TOP_FIELD)    ? VDP_TRUE : VDP_FALSE;
-            rf->bottom_is_reference = (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
-            rf->field_order_cnt[0]  = pic->field_poc[0];
-            rf->field_order_cnt[1]  = pic->field_poc[1];
-            rf->frame_idx           = pic_frame_idx;
-
-            ++rf;
-        }
-    }
-
-    for (; rf < &render->info.h264.referenceFrames[H264_RF_COUNT]; ++rf) {
-        rf->surface             = VDP_INVALID_HANDLE;
-        rf->is_long_term        = 0;
-        rf->top_is_reference    = 0;
-        rf->bottom_is_reference = 0;
-        rf->field_order_cnt[0]  = 0;
-        rf->field_order_cnt[1]  = 0;
-        rf->frame_idx           = 0;
-    }
-}
-
-void ff_vdpau_add_data_chunk(MpegEncContext *s,
-                             const uint8_t *buf, int buf_size)
-{
-    struct vdpau_render_state * render;
-
-    render = (struct vdpau_render_state*)s->current_picture_ptr->data[0];
-    assert(render);
-
-    render->bitstream_buffers= av_fast_realloc(
-        render->bitstream_buffers,
-        &render->bitstream_buffers_allocated,
-        sizeof(*render->bitstream_buffers)*(render->bitstream_buffers_used + 1)
-    );
-
-    render->bitstream_buffers[render->bitstream_buffers_used].struct_version  = VDP_BITSTREAM_BUFFER_VERSION;
-    render->bitstream_buffers[render->bitstream_buffers_used].bitstream       = buf;
-    render->bitstream_buffers[render->bitstream_buffers_used].bitstream_bytes = buf_size;
-    render->bitstream_buffers_used++;
-}
-
-void ff_vdpau_h264_picture_complete(MpegEncContext *s)
-{
-    H264Context *h = s->avctx->priv_data;
-    struct vdpau_render_state * render;
-
-    render = (struct vdpau_render_state*)s->current_picture_ptr->data[0];
-    assert(render);
-
-    render->info.h264.slice_count = h->slice_num;
-    if (render->info.h264.slice_count < 1)
-        return;
-
-    for (int i = 0; i < 2; ++i) {
-        int foc = s->current_picture_ptr->field_poc[i];
-        if (foc == INT_MAX)
-            foc = 0;
-        render->info.h264.field_order_cnt[i] = foc;
-    }
-
-    render->info.h264.is_reference                           = s->current_picture_ptr->reference ? VDP_TRUE : VDP_FALSE;
-    render->info.h264.frame_num                              = h->frame_num;
-    render->info.h264.field_pic_flag                         = s->picture_structure != PICT_FRAME;
-    render->info.h264.bottom_field_flag                      = s->picture_structure == PICT_BOTTOM_FIELD;
-    render->info.h264.num_ref_frames                         = h->sps.ref_frame_count;
-    render->info.h264.mb_adaptive_frame_field_flag           = h->sps.mb_aff;
-    render->info.h264.constrained_intra_pred_flag            = h->pps.constrained_intra_pred;
-    render->info.h264.weighted_pred_flag                     = h->pps.weighted_pred;
-    render->info.h264.weighted_bipred_idc                    = h->pps.weighted_bipred_idc;
-    render->info.h264.frame_mbs_only_flag                    = h->sps.frame_mbs_only_flag;
-    render->info.h264.transform_8x8_mode_flag                = h->pps.transform_8x8_mode;
-    render->info.h264.chroma_qp_index_offset                 = h->pps.chroma_qp_index_offset[0];
-    render->info.h264.second_chroma_qp_index_offset          = h->pps.chroma_qp_index_offset[1];
-    render->info.h264.pic_init_qp_minus26                    = h->pps.init_qp - 26;
-    render->info.h264.num_ref_idx_l0_active_minus1           = h->pps.ref_count[0] - 1;
-    render->info.h264.num_ref_idx_l1_active_minus1           = h->pps.ref_count[1] - 1;
-    render->info.h264.log2_max_frame_num_minus4              = h->sps.log2_max_frame_num - 4;
-    render->info.h264.pic_order_cnt_type                     = h->sps.poc_type;
-    render->info.h264.log2_max_pic_order_cnt_lsb_minus4      = h->sps.log2_max_poc_lsb - 4;
-    render->info.h264.delta_pic_order_always_zero_flag       = h->sps.delta_pic_order_always_zero_flag;
-    render->info.h264.direct_8x8_inference_flag              = h->sps.direct_8x8_inference_flag;
-    render->info.h264.entropy_coding_mode_flag               = h->pps.cabac;
-    render->info.h264.pic_order_present_flag                 = h->pps.pic_order_present;
-    render->info.h264.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present;
-    render->info.h264.redundant_pic_cnt_present_flag         = h->pps.redundant_pic_cnt_present;
-    memcpy(render->info.h264.scaling_lists_4x4, h->pps.scaling_matrix4, sizeof(render->info.h264.scaling_lists_4x4));
-    memcpy(render->info.h264.scaling_lists_8x8, h->pps.scaling_matrix8, sizeof(render->info.h264.scaling_lists_8x8));
-
-    ff_draw_horiz_band(s, 0, s->avctx->height);
-    render->bitstream_buffers_used = 0;
-}
-
-void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf,
-                                    int buf_size, int slice_count)
-{
-    struct vdpau_render_state * render, * last, * next;
-    int i;
-
-    render = (struct vdpau_render_state*)s->current_picture_ptr->data[0];
-    assert(render);
-
-    /* fill VdpPictureInfoMPEG1Or2 struct */
-    render->info.mpeg.picture_structure          = s->picture_structure;
-    render->info.mpeg.picture_coding_type        = s->pict_type;
-    render->info.mpeg.intra_dc_precision         = s->intra_dc_precision;
-    render->info.mpeg.frame_pred_frame_dct       = s->frame_pred_frame_dct;
-    render->info.mpeg.concealment_motion_vectors = s->concealment_motion_vectors;
-    render->info.mpeg.intra_vlc_format           = s->intra_vlc_format;
-    render->info.mpeg.alternate_scan             = s->alternate_scan;
-    render->info.mpeg.q_scale_type               = s->q_scale_type;
-    render->info.mpeg.top_field_first            = s->top_field_first;
-    render->info.mpeg.full_pel_forward_vector    = s->full_pel[0]; // MPEG-1 only.  Set 0 for MPEG-2
-    render->info.mpeg.full_pel_backward_vector   = s->full_pel[1]; // MPEG-1 only.  Set 0 for MPEG-2
-    render->info.mpeg.f_code[0][0]               = s->mpeg_f_code[0][0]; // For MPEG-1 fill both horiz. & vert.
-    render->info.mpeg.f_code[0][1]               = s->mpeg_f_code[0][1];
-    render->info.mpeg.f_code[1][0]               = s->mpeg_f_code[1][0];
-    render->info.mpeg.f_code[1][1]               = s->mpeg_f_code[1][1];
-    for (i = 0; i < 64; ++i) {
-        render->info.mpeg.intra_quantizer_matrix[i]     = s->intra_matrix[i];
-        render->info.mpeg.non_intra_quantizer_matrix[i] = s->inter_matrix[i];
-    }
-
-    render->info.mpeg.forward_reference          = VDP_INVALID_HANDLE;
-    render->info.mpeg.backward_reference         = VDP_INVALID_HANDLE;
-
-    switch(s->pict_type){
-    case  FF_B_TYPE:
-        next = (struct vdpau_render_state*)s->next_picture.data[0];
-        assert(next);
-        render->info.mpeg.backward_reference     = next->surface;
-        // no return here, going to set forward prediction
-    case  FF_P_TYPE:
-        last = (struct vdpau_render_state*)s->last_picture.data[0];
-        if (!last) // FIXME: Does this test make sense?
-            last = render; // predict second field from the first
-        render->info.mpeg.forward_reference      = last->surface;
-    }
-
-    ff_vdpau_add_data_chunk(s, buf, buf_size);
-
-    render->info.mpeg.slice_count                = slice_count;
-
-    if (slice_count)
-        ff_draw_horiz_band(s, 0, s->avctx->height);
-    render->bitstream_buffers_used               = 0;
-}
-
-void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf,
-                                 int buf_size)
-{
-    VC1Context *v = s->avctx->priv_data;
-    struct vdpau_render_state * render, * last, * next;
-
-    render = (struct vdpau_render_state*)s->current_picture.data[0];
-    assert(render);
-
-    /*  fill LvPictureInfoVC1 struct */
-    render->info.vc1.frame_coding_mode  = v->fcm;
-    render->info.vc1.postprocflag       = v->postprocflag;
-    render->info.vc1.pulldown           = v->broadcast;
-    render->info.vc1.interlace          = v->interlace;
-    render->info.vc1.tfcntrflag         = v->tfcntrflag;
-    render->info.vc1.finterpflag        = v->finterpflag;
-    render->info.vc1.psf                = v->psf;
-    render->info.vc1.dquant             = v->dquant;
-    render->info.vc1.panscan_flag       = v->panscanflag;
-    render->info.vc1.refdist_flag       = v->refdist_flag;
-    render->info.vc1.quantizer          = v->quantizer_mode;
-    render->info.vc1.extended_mv        = v->extended_mv;
-    render->info.vc1.extended_dmv       = v->extended_dmv;
-    render->info.vc1.overlap            = v->overlap;
-    render->info.vc1.vstransform        = v->vstransform;
-    render->info.vc1.loopfilter         = v->s.loop_filter;
-    render->info.vc1.fastuvmc           = v->fastuvmc;
-    render->info.vc1.range_mapy_flag    = v->range_mapy_flag;
-    render->info.vc1.range_mapy         = v->range_mapy;
-    render->info.vc1.range_mapuv_flag   = v->range_mapuv_flag;
-    render->info.vc1.range_mapuv        = v->range_mapuv;
-    /* Specific to simple/main profile only */
-    render->info.vc1.multires           = v->multires;
-    render->info.vc1.syncmarker         = v->s.resync_marker;
-    render->info.vc1.rangered           = v->rangered;
-    render->info.vc1.maxbframes         = v->s.max_b_frames;
-
-    render->info.vc1.deblockEnable      = v->postprocflag & 1;
-    render->info.vc1.pquant             = v->pq;
-
-    render->info.vc1.forward_reference  = VDP_INVALID_HANDLE;
-    render->info.vc1.backward_reference = VDP_INVALID_HANDLE;
-
-    if (v->bi_type)
-        render->info.vc1.picture_type = 4;
-    else
-        render->info.vc1.picture_type = s->pict_type - 1 + s->pict_type / 3;
-
-    switch(s->pict_type){
-    case  FF_B_TYPE:
-        next = (struct vdpau_render_state*)s->next_picture.data[0];
-        assert(next);
-        render->info.vc1.backward_reference = next->surface;
-        // no break here, going to set forward prediction
-    case  FF_P_TYPE:
-        last = (struct vdpau_render_state*)s->last_picture.data[0];
-        if (!last) // FIXME: Does this test make sense?
-            last = render; // predict second field from the first
-        render->info.vc1.forward_reference = last->surface;
-    }
-
-    ff_vdpau_add_data_chunk(s, buf, buf_size);
-
-    render->info.vc1.slice_count          = 1;
-
-    ff_draw_horiz_band(s, 0, s->avctx->height);
-    render->bitstream_buffers_used        = 0;
-}
-
-/* @}*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xvmc.c	Wed Feb 11 12:01:59 2009 +0000
@@ -0,0 +1,310 @@
+/*
+ * XVideo Motion Compensation
+ * Copyright (c) 2003 Ivan Kalvachev
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <limits.h>
+
+//avcodec include
+#include "avcodec.h"
+#include "dsputil.h"
+#include "mpegvideo.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+//X11 includes are in xvmc_render.h
+//by replacing it with non-X one
+//XvMC emulation could be performed
+
+#include "xvmc_render.h"
+
+//#include "xvmc_debug.h"
+
+//set s->block
+void XVMC_init_block(MpegEncContext *s){
+    struct xvmc_render_state * render;
+    render = (struct xvmc_render_state*)s->current_picture.data[2];
+    assert(render != NULL);
+    if( (render == NULL) || (render->magic != MP_XVMC_RENDER_MAGIC) ){
+        assert(0);
+        return;//make sure that this is a render packet
+    }
+    s->block =(DCTELEM *)(render->data_blocks+(render->next_free_data_block_num)*64);
+}
+
+void XVMC_pack_pblocks(MpegEncContext *s, int cbp){
+int i,j;
+const int mb_block_count = 4+(1<<s->chroma_format);
+
+    j=0;
+    cbp<<= 12-mb_block_count;
+    for(i=0; i<mb_block_count; i++){
+        if(cbp & (1<<11)) {
+           s->pblocks[i] = (short *)(&s->block[(j++)]);
+        }else{
+           s->pblocks[i] = NULL;
+        }
+        cbp+=cbp;
+//        printf("s->pblocks[%d]=%p ,s->block=%p cbp=%d\n",i,s->pblocks[i],s->block,cbp);
+    }
+}
+
+//These functions should be called on every new field and/or frame.
+//They should be safe if they are called a few times for the same field!
+int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx){
+    struct xvmc_render_state * render, * last, * next;
+
+    assert(avctx != NULL);
+
+    render = (struct xvmc_render_state*)s->current_picture.data[2];
+    assert(render != NULL);
+    if( (render == NULL) || (render->magic != MP_XVMC_RENDER_MAGIC) )
+        return -1;//make sure that this is render packet
+
+    render->picture_structure = s->picture_structure;
+    render->flags = (s->first_field)? 0: XVMC_SECOND_FIELD;
+
+//make sure that all data is drawn by XVMC_end_frame
+    assert(render->filled_mv_blocks_num==0);
+
+    render->p_future_surface = NULL;
+    render->p_past_surface = NULL;
+
+    switch(s->pict_type){
+        case  FF_I_TYPE:
+            return 0;// no prediction from other frames
+        case  FF_B_TYPE:
+            next = (struct xvmc_render_state*)s->next_picture.data[2];
+            assert(next!=NULL);
+            assert(next->state & MP_XVMC_STATE_PREDICTION);
+            if(next == NULL) return -1;
+            if(next->magic != MP_XVMC_RENDER_MAGIC) return -1;
+            render->p_future_surface = next->p_surface;
+            //no return here, going to set forward prediction
+        case  FF_P_TYPE:
+            last = (struct xvmc_render_state*)s->last_picture.data[2];
+            if(last == NULL)// && !s->first_field)
+                last = render;//predict second field from the first
+            if(last->magic != MP_XVMC_RENDER_MAGIC) return -1;
+            assert(last->state & MP_XVMC_STATE_PREDICTION);
+            render->p_past_surface = last->p_surface;
+            return 0;
+    }
+
+return -1;
+}
+
+void XVMC_field_end(MpegEncContext *s){
+    struct xvmc_render_state * render;
+    render = (struct xvmc_render_state*)s->current_picture.data[2];
+    assert(render != NULL);
+
+    if(render->filled_mv_blocks_num > 0){
+//        printf("xvmc: rendering %d left blocks after last slice!!!\n",render->filled_mv_blocks_num );
+        ff_draw_horiz_band(s,0,0);
+    }
+}
+
+void XVMC_decode_mb(MpegEncContext *s){
+XvMCMacroBlock * mv_block;
+struct xvmc_render_state * render;
+int i,cbp,blocks_per_mb;
+
+const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
+
+
+    if(s->encoding){
+        av_log(s->avctx, AV_LOG_ERROR, "XVMC doesn't support encoding!!!\n");
+        return;
+    }
+
+   //from MPV_decode_mb(),
+    /* update DC predictors for P macroblocks */
+    if (!s->mb_intra) {
+        s->last_dc[0] =
+        s->last_dc[1] =
+        s->last_dc[2] =  128 << s->intra_dc_precision;
+    }
+
+   //MC doesn't skip blocks
+    s->mb_skipped = 0;
+
+
+   // Do I need to export quant when I could not perform postprocessing?
+   // Anyway, it doesn't hurt.
+    s->current_picture.qscale_table[mb_xy] = s->qscale;
+
+//START OF XVMC specific code
+    render = (struct xvmc_render_state*)s->current_picture.data[2];
+    assert(render!=NULL);
+    assert(render->magic==MP_XVMC_RENDER_MAGIC);
+    assert(render->mv_blocks);
+
+    //take the next free macroblock
+    mv_block = &render->mv_blocks[render->start_mv_blocks_num +
+                                   render->filled_mv_blocks_num ];
+
+// memset(mv_block,0,sizeof(XvMCMacroBlock));
+
+    mv_block->x = s->mb_x;
+    mv_block->y = s->mb_y;
+    mv_block->dct_type = s->interlaced_dct;//XVMC_DCT_TYPE_FRAME/FIELD;
+//    mv_block->motion_type = 0;  //zero to silence warnings
+    if(s->mb_intra){
+        mv_block->macroblock_type = XVMC_MB_TYPE_INTRA;//no MC, all done
+    }else{
+        mv_block->macroblock_type = XVMC_MB_TYPE_PATTERN;
+
+        if(s->mv_dir & MV_DIR_FORWARD){
+            mv_block->macroblock_type|= XVMC_MB_TYPE_MOTION_FORWARD;
+            //pmv[n][dir][xy]=mv[dir][n][xy]
+            mv_block->PMV[0][0][0] = s->mv[0][0][0];
+            mv_block->PMV[0][0][1] = s->mv[0][0][1];
+            mv_block->PMV[1][0][0] = s->mv[0][1][0];
+            mv_block->PMV[1][0][1] = s->mv[0][1][1];
+        }
+        if(s->mv_dir & MV_DIR_BACKWARD){
+            mv_block->macroblock_type|=XVMC_MB_TYPE_MOTION_BACKWARD;
+            mv_block->PMV[0][1][0] = s->mv[1][0][0];
+            mv_block->PMV[0][1][1] = s->mv[1][0][1];
+            mv_block->PMV[1][1][0] = s->mv[1][1][0];
+            mv_block->PMV[1][1][1] = s->mv[1][1][1];
+        }
+
+        switch(s->mv_type){
+            case  MV_TYPE_16X16:
+                mv_block->motion_type = XVMC_PREDICTION_FRAME;
+                break;
+            case  MV_TYPE_16X8:
+                mv_block->motion_type = XVMC_PREDICTION_16x8;
+                break;
+            case  MV_TYPE_FIELD:
+                mv_block->motion_type = XVMC_PREDICTION_FIELD;
+                if(s->picture_structure == PICT_FRAME){
+                    mv_block->PMV[0][0][1]<<=1;
+                    mv_block->PMV[1][0][1]<<=1;
+                    mv_block->PMV[0][1][1]<<=1;
+                    mv_block->PMV[1][1][1]<<=1;
+                }
+                break;
+            case  MV_TYPE_DMV:
+                mv_block->motion_type = XVMC_PREDICTION_DUAL_PRIME;
+                if(s->picture_structure == PICT_FRAME){
+
+                    mv_block->PMV[0][0][0] = s->mv[0][0][0];//top from top
+                    mv_block->PMV[0][0][1] = s->mv[0][0][1]<<1;
+
+                    mv_block->PMV[0][1][0] = s->mv[0][0][0];//bottom from bottom
+                    mv_block->PMV[0][1][1] = s->mv[0][0][1]<<1;
+
+                    mv_block->PMV[1][0][0] = s->mv[0][2][0];//dmv00, top from bottom
+                    mv_block->PMV[1][0][1] = s->mv[0][2][1]<<1;//dmv01
+
+                    mv_block->PMV[1][1][0] = s->mv[0][3][0];//dmv10, bottom from top
+                    mv_block->PMV[1][1][1] = s->mv[0][3][1]<<1;//dmv11
+
+                }else{
+                    mv_block->PMV[0][1][0] = s->mv[0][2][0];//dmv00
+                    mv_block->PMV[0][1][1] = s->mv[0][2][1];//dmv01
+                }
+                break;
+            default:
+                assert(0);
+        }
+
+        mv_block->motion_vertical_field_select = 0;
+
+//set correct field references
+        if(s->mv_type == MV_TYPE_FIELD || s->mv_type == MV_TYPE_16X8){
+            if( s->field_select[0][0] ) mv_block->motion_vertical_field_select|=1;
+            if( s->field_select[1][0] ) mv_block->motion_vertical_field_select|=2;
+            if( s->field_select[0][1] ) mv_block->motion_vertical_field_select|=4;
+            if( s->field_select[1][1] ) mv_block->motion_vertical_field_select|=8;
+        }
+    }//!intra
+//time to handle data blocks;
+    mv_block->index = render->next_free_data_block_num;
+
+    blocks_per_mb = 6;
+    if( s->chroma_format >= 2){
+        blocks_per_mb = 4 + (1 << (s->chroma_format));
+    }
+
+//  calculate cbp
+    cbp = 0;
+    for(i=0; i<blocks_per_mb; i++) {
+        cbp+= cbp;
+        if(s->block_last_index[i] >= 0)
+            cbp++;
+    }
+
+    if(s->flags & CODEC_FLAG_GRAY){
+        if(s->mb_intra){//intra frames are always full chroma block
+            for(i=4; i<blocks_per_mb; i++){
+                memset(s->pblocks[i],0,sizeof(short)*8*8);//so we need to clear them
+                if(!render->unsigned_intra)
+                    s->pblocks[i][0] = 1<<10;
+            }
+        }else{
+            cbp&= 0xf << (blocks_per_mb - 4);
+            blocks_per_mb = 4;//luminance blocks only
+        }
+    }
+    mv_block->coded_block_pattern = cbp;
+    if(cbp == 0)
+        mv_block->macroblock_type &= ~XVMC_MB_TYPE_PATTERN;
+
+    for(i=0; i<blocks_per_mb; i++){
+        if(s->block_last_index[i] >= 0){
+            // I do not have unsigned_intra MOCO to test, hope it is OK.
+            if( (s->mb_intra) && ( render->idct || (!render->idct && !render->unsigned_intra)) )
+                s->pblocks[i][0]-=1<<10;
+            if(!render->idct){
+                s->dsp.idct(s->pblocks[i]);
+                //!!TODO!clip!!!
+            }
+//copy blocks only if the codec doesn't support pblocks reordering
+            if(s->avctx->xvmc_acceleration == 1){
+                memcpy(&render->data_blocks[(render->next_free_data_block_num)*64],
+                        s->pblocks[i],sizeof(short)*8*8);
+            }else{
+/*              if(s->pblocks[i] != &render->data_blocks[
+                        (render->next_free_data_block_num)*64]){
+                   printf("ERROR mb(%d,%d) s->pblocks[i]=%p data_block[]=%p\n",
+                   s->mb_x,s->mb_y, s->pblocks[i],
+                   &render->data_blocks[(render->next_free_data_block_num)*64]);
+                }*/
+            }
+            render->next_free_data_block_num++;
+        }
+    }
+    render->filled_mv_blocks_num++;
+
+    assert(render->filled_mv_blocks_num <= render->total_number_of_mv_blocks);
+    assert(render->next_free_data_block_num <= render->total_number_of_data_blocks);
+
+
+    if(render->filled_mv_blocks_num >= render->total_number_of_mv_blocks)
+        ff_draw_horiz_band(s,0,0);
+
+// DumpRenderInfo(render);
+// DumpMBlockInfo(mv_block);
+
+}
--- a/xvmcvideo.c	Wed Feb 11 11:16:00 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,310 +0,0 @@
-/*
- * XVideo Motion Compensation
- * Copyright (c) 2003 Ivan Kalvachev
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <limits.h>
-
-//avcodec include
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-#undef NDEBUG
-#include <assert.h>
-
-//X11 includes are in xvmc_render.h
-//by replacing it with non-X one
-//XvMC emulation could be performed
-
-#include "xvmc_render.h"
-
-//#include "xvmc_debug.h"
-
-//set s->block
-void XVMC_init_block(MpegEncContext *s){
-    struct xvmc_render_state * render;
-    render = (struct xvmc_render_state*)s->current_picture.data[2];
-    assert(render != NULL);
-    if( (render == NULL) || (render->magic != MP_XVMC_RENDER_MAGIC) ){
-        assert(0);
-        return;//make sure that this is a render packet
-    }
-    s->block =(DCTELEM *)(render->data_blocks+(render->next_free_data_block_num)*64);
-}
-
-void XVMC_pack_pblocks(MpegEncContext *s, int cbp){
-int i,j;
-const int mb_block_count = 4+(1<<s->chroma_format);
-
-    j=0;
-    cbp<<= 12-mb_block_count;
-    for(i=0; i<mb_block_count; i++){
-        if(cbp & (1<<11)) {
-           s->pblocks[i] = (short *)(&s->block[(j++)]);
-        }else{
-           s->pblocks[i] = NULL;
-        }
-        cbp+=cbp;
-//        printf("s->pblocks[%d]=%p ,s->block=%p cbp=%d\n",i,s->pblocks[i],s->block,cbp);
-    }
-}
-
-//These functions should be called on every new field and/or frame.
-//They should be safe if they are called a few times for the same field!
-int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx){
-    struct xvmc_render_state * render, * last, * next;
-
-    assert(avctx != NULL);
-
-    render = (struct xvmc_render_state*)s->current_picture.data[2];
-    assert(render != NULL);
-    if( (render == NULL) || (render->magic != MP_XVMC_RENDER_MAGIC) )
-        return -1;//make sure that this is render packet
-
-    render->picture_structure = s->picture_structure;
-    render->flags = (s->first_field)? 0: XVMC_SECOND_FIELD;
-
-//make sure that all data is drawn by XVMC_end_frame
-    assert(render->filled_mv_blocks_num==0);
-
-    render->p_future_surface = NULL;
-    render->p_past_surface = NULL;
-
-    switch(s->pict_type){
-        case  FF_I_TYPE:
-            return 0;// no prediction from other frames
-        case  FF_B_TYPE:
-            next = (struct xvmc_render_state*)s->next_picture.data[2];
-            assert(next!=NULL);
-            assert(next->state & MP_XVMC_STATE_PREDICTION);
-            if(next == NULL) return -1;
-            if(next->magic != MP_XVMC_RENDER_MAGIC) return -1;
-            render->p_future_surface = next->p_surface;
-            //no return here, going to set forward prediction
-        case  FF_P_TYPE:
-            last = (struct xvmc_render_state*)s->last_picture.data[2];
-            if(last == NULL)// && !s->first_field)
-                last = render;//predict second field from the first
-            if(last->magic != MP_XVMC_RENDER_MAGIC) return -1;
-            assert(last->state & MP_XVMC_STATE_PREDICTION);
-            render->p_past_surface = last->p_surface;
-            return 0;
-    }
-
-return -1;
-}
-
-void XVMC_field_end(MpegEncContext *s){
-    struct xvmc_render_state * render;
-    render = (struct xvmc_render_state*)s->current_picture.data[2];
-    assert(render != NULL);
-
-    if(render->filled_mv_blocks_num > 0){
-//        printf("xvmcvideo.c: rendering %d left blocks after last slice!!!\n",render->filled_mv_blocks_num );
-        ff_draw_horiz_band(s,0,0);
-    }
-}
-
-void XVMC_decode_mb(MpegEncContext *s){
-XvMCMacroBlock * mv_block;
-struct xvmc_render_state * render;
-int i,cbp,blocks_per_mb;
-
-const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
-
-
-    if(s->encoding){
-        av_log(s->avctx, AV_LOG_ERROR, "XVMC doesn't support encoding!!!\n");
-        return;
-    }
-
-   //from MPV_decode_mb(),
-    /* update DC predictors for P macroblocks */
-    if (!s->mb_intra) {
-        s->last_dc[0] =
-        s->last_dc[1] =
-        s->last_dc[2] =  128 << s->intra_dc_precision;
-    }
-
-   //MC doesn't skip blocks
-    s->mb_skipped = 0;
-
-
-   // Do I need to export quant when I could not perform postprocessing?
-   // Anyway, it doesn't hurt.
-    s->current_picture.qscale_table[mb_xy] = s->qscale;
-
-//START OF XVMC specific code
-    render = (struct xvmc_render_state*)s->current_picture.data[2];
-    assert(render!=NULL);
-    assert(render->magic==MP_XVMC_RENDER_MAGIC);
-    assert(render->mv_blocks);
-
-    //take the next free macroblock
-    mv_block = &render->mv_blocks[render->start_mv_blocks_num +
-                                   render->filled_mv_blocks_num ];
-
-// memset(mv_block,0,sizeof(XvMCMacroBlock));
-
-    mv_block->x = s->mb_x;
-    mv_block->y = s->mb_y;
-    mv_block->dct_type = s->interlaced_dct;//XVMC_DCT_TYPE_FRAME/FIELD;
-//    mv_block->motion_type = 0;  //zero to silence warnings
-    if(s->mb_intra){
-        mv_block->macroblock_type = XVMC_MB_TYPE_INTRA;//no MC, all done
-    }else{
-        mv_block->macroblock_type = XVMC_MB_TYPE_PATTERN;
-
-        if(s->mv_dir & MV_DIR_FORWARD){
-            mv_block->macroblock_type|= XVMC_MB_TYPE_MOTION_FORWARD;
-            //pmv[n][dir][xy]=mv[dir][n][xy]
-            mv_block->PMV[0][0][0] = s->mv[0][0][0];
-            mv_block->PMV[0][0][1] = s->mv[0][0][1];
-            mv_block->PMV[1][0][0] = s->mv[0][1][0];
-            mv_block->PMV[1][0][1] = s->mv[0][1][1];
-        }
-        if(s->mv_dir & MV_DIR_BACKWARD){
-            mv_block->macroblock_type|=XVMC_MB_TYPE_MOTION_BACKWARD;
-            mv_block->PMV[0][1][0] = s->mv[1][0][0];
-            mv_block->PMV[0][1][1] = s->mv[1][0][1];
-            mv_block->PMV[1][1][0] = s->mv[1][1][0];
-            mv_block->PMV[1][1][1] = s->mv[1][1][1];
-        }
-
-        switch(s->mv_type){
-            case  MV_TYPE_16X16:
-                mv_block->motion_type = XVMC_PREDICTION_FRAME;
-                break;
-            case  MV_TYPE_16X8:
-                mv_block->motion_type = XVMC_PREDICTION_16x8;
-                break;
-            case  MV_TYPE_FIELD:
-                mv_block->motion_type = XVMC_PREDICTION_FIELD;
-                if(s->picture_structure == PICT_FRAME){
-                    mv_block->PMV[0][0][1]<<=1;
-                    mv_block->PMV[1][0][1]<<=1;
-                    mv_block->PMV[0][1][1]<<=1;
-                    mv_block->PMV[1][1][1]<<=1;
-                }
-                break;
-            case  MV_TYPE_DMV:
-                mv_block->motion_type = XVMC_PREDICTION_DUAL_PRIME;
-                if(s->picture_structure == PICT_FRAME){
-
-                    mv_block->PMV[0][0][0] = s->mv[0][0][0];//top from top
-                    mv_block->PMV[0][0][1] = s->mv[0][0][1]<<1;
-
-                    mv_block->PMV[0][1][0] = s->mv[0][0][0];//bottom from bottom
-                    mv_block->PMV[0][1][1] = s->mv[0][0][1]<<1;
-
-                    mv_block->PMV[1][0][0] = s->mv[0][2][0];//dmv00, top from bottom
-                    mv_block->PMV[1][0][1] = s->mv[0][2][1]<<1;//dmv01
-
-                    mv_block->PMV[1][1][0] = s->mv[0][3][0];//dmv10, bottom from top
-                    mv_block->PMV[1][1][1] = s->mv[0][3][1]<<1;//dmv11
-
-                }else{
-                    mv_block->PMV[0][1][0] = s->mv[0][2][0];//dmv00
-                    mv_block->PMV[0][1][1] = s->mv[0][2][1];//dmv01
-                }
-                break;
-            default:
-                assert(0);
-        }
-
-        mv_block->motion_vertical_field_select = 0;
-
-//set correct field references
-        if(s->mv_type == MV_TYPE_FIELD || s->mv_type == MV_TYPE_16X8){
-            if( s->field_select[0][0] ) mv_block->motion_vertical_field_select|=1;
-            if( s->field_select[1][0] ) mv_block->motion_vertical_field_select|=2;
-            if( s->field_select[0][1] ) mv_block->motion_vertical_field_select|=4;
-            if( s->field_select[1][1] ) mv_block->motion_vertical_field_select|=8;
-        }
-    }//!intra
-//time to handle data blocks;
-    mv_block->index = render->next_free_data_block_num;
-
-    blocks_per_mb = 6;
-    if( s->chroma_format >= 2){
-        blocks_per_mb = 4 + (1 << (s->chroma_format));
-    }
-
-//  calculate cbp
-    cbp = 0;
-    for(i=0; i<blocks_per_mb; i++) {
-        cbp+= cbp;
-        if(s->block_last_index[i] >= 0)
-            cbp++;
-    }
-
-    if(s->flags & CODEC_FLAG_GRAY){
-        if(s->mb_intra){//intra frames are always full chroma block
-            for(i=4; i<blocks_per_mb; i++){
-                memset(s->pblocks[i],0,sizeof(short)*8*8);//so we need to clear them
-                if(!render->unsigned_intra)
-                    s->pblocks[i][0] = 1<<10;
-            }
-        }else{
-            cbp&= 0xf << (blocks_per_mb - 4);
-            blocks_per_mb = 4;//luminance blocks only
-        }
-    }
-    mv_block->coded_block_pattern = cbp;
-    if(cbp == 0)
-        mv_block->macroblock_type &= ~XVMC_MB_TYPE_PATTERN;
-
-    for(i=0; i<blocks_per_mb; i++){
-        if(s->block_last_index[i] >= 0){
-            // I do not have unsigned_intra MOCO to test, hope it is OK.
-            if( (s->mb_intra) && ( render->idct || (!render->idct && !render->unsigned_intra)) )
-                s->pblocks[i][0]-=1<<10;
-            if(!render->idct){
-                s->dsp.idct(s->pblocks[i]);
-                //!!TODO!clip!!!
-            }
-//copy blocks only if the codec doesn't support pblocks reordering
-            if(s->avctx->xvmc_acceleration == 1){
-                memcpy(&render->data_blocks[(render->next_free_data_block_num)*64],
-                        s->pblocks[i],sizeof(short)*8*8);
-            }else{
-/*              if(s->pblocks[i] != &render->data_blocks[
-                        (render->next_free_data_block_num)*64]){
-                   printf("ERROR mb(%d,%d) s->pblocks[i]=%p data_block[]=%p\n",
-                   s->mb_x,s->mb_y, s->pblocks[i],
-                   &render->data_blocks[(render->next_free_data_block_num)*64]);
-                }*/
-            }
-            render->next_free_data_block_num++;
-        }
-    }
-    render->filled_mv_blocks_num++;
-
-    assert(render->filled_mv_blocks_num <= render->total_number_of_mv_blocks);
-    assert(render->next_free_data_block_num <= render->total_number_of_data_blocks);
-
-
-    if(render->filled_mv_blocks_num >= render->total_number_of_mv_blocks)
-        ff_draw_horiz_band(s,0,0);
-
-// DumpRenderInfo(render);
-// DumpMBlockInfo(mv_block);
-
-}