~medibuntu-maintainers/mplayer/medibuntu.oneiric

« back to all changes in this revision

Viewing changes to libavcodec/dxva2_vc1.c

  • Committer: Gauvain Pocentek
  • Date: 2010-09-25 09:39:02 UTC
  • mfrom: (66.1.6 maverick)
  • Revision ID: gauvain@images-20100925093902-9q2akz3ls3qzhaaw
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* merge from debian, remaining changes:
  - build depend against, lame, x264, xvid
* debian/patches/60eval-api.patch, backport patch from upstream to
  unbreak compilation for eval.h move not yet in 0.6
* gmplayer is gone now, please see smplayer as alternative frontend.
  LP: #503537, #493088, #467534, #467524, #460326, #390399, #285570,
      #208680, #118709, #513065, #459595, #455913, #179918, #65165.
* enable the mencoder package
* sort build depends alphabetically
* enable dvdnav support, Closes: #582508, #488226, LP: #611749
* prepare new upload
* no longer build mplayer-gui, it doesn't build anymore with shared
  swscale
* merge from debian/experimental, remaining changes:
  - build depend against, lame, x264, xvid
  - enable mencoder and mplayer-gui
* ensure that quilt patches are actually applied
* New Upstream Version, LP: #539315
* Build (against) again the System FFmpeg 
* tighten dependency on FFmpeg 0.6
* remove patches merged upstream
* remove 22disable-xscreensaver.patch
* refresh patches
* readd x264, xvid and mp3lame support, LP: #606125
* remove old parallel building mechanism, fixes FTBFS
* New upstream version
* compile against internal ffmpeg for now, LP: #587203, #588097
* recompile for directfb transtion, LP: #587163
* remove patches that were merged upstream
* avoid removing DOCS/html directory. it is included in release
  tarball
* convert to source Format: 3.0 (quilt)
* refreshed patches
* remove files that are included in upstream tarball
* rework debian/rules file
  - support parallel building
  - merge build rules for mplayer and mencoder package
  - remove unreferenced COMMON_CONFIGURE_FLAGS macro
  - rename DEB_BUILD_CONFIGURE -> CONFIGURE_FLAGS
  - don't build documentation - release tarballs have them prebuilt
  - build HTML documentation only if not already avaiable in the build
    tree
  - remove remaining references to debian/strip.sh from debian/rules
* remove copied vdpau headers
* copy in mencoder.c from upstream
* enable mplayer-gui (Closes: #579925) and mencoder packages. 
  (Closes: #396954, #400940, #580168)
* Fix rtsp vulnerability. Patch applied by DSA. Closes: #581245
* Fix another integer overflow, Closes: #524805
* prepare new upload
* sync libao2/ao_pulse.c with svn r30062, Closes: #558196, #580113
* make configure use pkg-config for fribidi checks. Closes: #582784,
  LP: #556200
* document 23mplayer-debug-printf.patch
* avoid mentioning of GTK frontend in mplayer description
* improve package descriptions of mplayer-doc and mplayer-dbg
* medium urgency because of fixed security issue
* fix SVN_VERION regex in debian rules to unbreak get-orig-source
  target. Closes: #582369
* forcefully disable arts support. Closes: #581225
* Remove mencoder from Depends in mplayer-dbg package.
* new upstream snapshot from rc3 branch.
* remove patches applied upstream:
  
  - 24_enable_fontconfig_by_default.diff
  - 30_add_gmplayer_man_rules.diff
  - 40_improve_desktop_file.patch
  - 41_fix_forcedsubsonly.patch
  - 50_fix_crashes_with_invalid_SDPs.patch
  - 50_fix_initial_volume_setting_pulse_output.patch
  - 61-malloc-bsd.patch
  - 62-disable-vidix-on-kfreebsd-amd64.patch
  - 63-sys-kd-include.patch
* don't install apport hook
* gross hack to avoid building mplayer-nogui and mplayer-gui packages
* add md5sum to remove to avoid spurious conffile prompt, Closes: #568272
* Make mplayer build on kFreeBSD (backports from upstream), Closes: #578622
  - Revert obscure hack that disables the malloc.h check on certain BSD
    platforms. 
  - disable vidix on kFreeBSD-amd64
  - rename 'struct keypad' -> 'struct m_keypad' to avoid FTBFS on
    kFreeBSD/amd64
* enable fontconfig by default. (Closes: #573257)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DXVA2 WMV3/VC-1 HW acceleration.
 
3
 *
 
4
 * copyright (c) 2010 Laurent Aimar
 
5
 *
 
6
 * This file is part of FFmpeg.
 
7
 *
 
8
 * FFmpeg is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public
 
10
 * License as published by the Free Software Foundation; either
 
11
 * version 2.1 of the License, or (at your option) any later version.
 
12
 *
 
13
 * FFmpeg is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * Lesser General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public
 
19
 * License along with FFmpeg; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
21
 */
 
22
 
 
23
#include "dxva2_internal.h"
 
24
#include "vc1.h"
 
25
#include "vc1data.h"
 
26
 
 
27
struct dxva2_picture_context {
 
28
    DXVA_PictureParameters pp;
 
29
    DXVA_SliceInfo         si;
 
30
 
 
31
    const uint8_t          *bitstream;
 
32
    unsigned               bitstream_size;
 
33
};
 
34
 
 
35
static void fill_picture_parameters(AVCodecContext *avctx,
 
36
                                    struct dxva_context *ctx, const VC1Context *v,
 
37
                                    DXVA_PictureParameters *pp)
 
38
{
 
39
    const MpegEncContext *s = &v->s;
 
40
    const Picture *current_picture = s->current_picture_ptr;
 
41
 
 
42
    memset(pp, 0, sizeof(*pp));
 
43
    pp->wDecodedPictureIndex    =
 
44
    pp->wDeblockedPictureIndex  = ff_dxva2_get_surface_index(ctx, current_picture);
 
45
    if (s->pict_type != FF_I_TYPE)
 
46
        pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->last_picture);
 
47
    else
 
48
        pp->wForwardRefPictureIndex = 0xffff;
 
49
    if (s->pict_type == FF_B_TYPE)
 
50
        pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->next_picture);
 
51
    else
 
52
        pp->wBackwardRefPictureIndex = 0xffff;
 
53
    if (v->profile == PROFILE_ADVANCED) {
 
54
        /* It is the cropped width/height -1 of the frame */
 
55
        pp->wPicWidthInMBminus1 = avctx->width  - 1;
 
56
        pp->wPicHeightInMBminus1= avctx->height - 1;
 
57
    } else {
 
58
        /* It is the coded width/height in macroblock -1 of the frame */
 
59
        pp->wPicWidthInMBminus1 = s->mb_width  - 1;
 
60
        pp->wPicHeightInMBminus1= s->mb_height - 1;
 
61
    }
 
62
    pp->bMacroblockWidthMinus1  = 15;
 
63
    pp->bMacroblockHeightMinus1 = 15;
 
64
    pp->bBlockWidthMinus1       = 7;
 
65
    pp->bBlockHeightMinus1      = 7;
 
66
    pp->bBPPminus1              = 7;
 
67
    if (s->picture_structure & PICT_TOP_FIELD)
 
68
        pp->bPicStructure      |= 0x01;
 
69
    if (s->picture_structure & PICT_BOTTOM_FIELD)
 
70
        pp->bPicStructure      |= 0x02;
 
71
    pp->bSecondField            = v->interlace && v->fcm != 0x03 && !s->first_field;
 
72
    pp->bPicIntra               = s->pict_type == FF_I_TYPE;
 
73
    pp->bPicBackwardPrediction  = s->pict_type == FF_B_TYPE;
 
74
    pp->bBidirectionalAveragingMode = (1                                           << 7) |
 
75
                                      ((ctx->cfg->ConfigIntraResidUnsigned != 0)   << 6) |
 
76
                                      ((ctx->cfg->ConfigResidDiffAccelerator != 0) << 5) |
 
77
                                      ((v->lumscale != 32 || v->lumshift != 0)     << 4) |
 
78
                                      ((v->profile == PROFILE_ADVANCED)            << 3);
 
79
    pp->bMVprecisionAndChromaRelation = ((v->mv_mode == MV_PMODE_1MV_HPEL_BILIN) << 3) |
 
80
                                        (1                                       << 2) |
 
81
                                        (0                                       << 1) |
 
82
                                        (!s->quarter_sample                          );
 
83
    pp->bChromaFormat           = v->chromaformat;
 
84
    ctx->report_id++;
 
85
    if (ctx->report_id >= (1 << 16))
 
86
        ctx->report_id = 1;
 
87
    pp->bPicScanFixed           = ctx->report_id >> 8;
 
88
    pp->bPicScanMethod          = ctx->report_id & 0xff;
 
89
    pp->bPicReadbackRequests    = 0;
 
90
    pp->bRcontrol               = v->rnd;
 
91
    pp->bPicSpatialResid8       = (v->panscanflag  << 7) |
 
92
                                  (v->refdist_flag << 6) |
 
93
                                  (s->loop_filter  << 5) |
 
94
                                  (v->fastuvmc     << 4) |
 
95
                                  (v->extended_mv  << 3) |
 
96
                                  (v->dquant       << 1) |
 
97
                                  (v->vstransform      );
 
98
    pp->bPicOverflowBlocks      = (v->quantizer_mode << 6) |
 
99
                                  (v->multires       << 5) |
 
100
                                  (s->resync_marker  << 4) |
 
101
                                  (v->rangered       << 3) |
 
102
                                  (s->max_b_frames       );
 
103
    pp->bPicExtrapolation       = (!v->interlace || v->fcm == 0x00) ? 1 : 2;
 
104
    pp->bPicDeblocked           = ((v->profile != PROFILE_ADVANCED && v->rangeredfrm) << 5) |
 
105
                                  (s->loop_filter                                     << 1);
 
106
    pp->bPicDeblockConfined     = (v->postprocflag             << 7) |
 
107
                                  (v->broadcast                << 6) |
 
108
                                  (v->interlace                << 5) |
 
109
                                  (v->tfcntrflag               << 4) |
 
110
                                  (v->finterpflag              << 3) |
 
111
                                  ((s->pict_type != FF_B_TYPE) << 2) |
 
112
                                  (v->psf                      << 1) |
 
113
                                  (v->extended_dmv                 );
 
114
    if (s->pict_type != FF_I_TYPE)
 
115
        pp->bPic4MVallowed      = v->mv_mode == MV_PMODE_MIXED_MV ||
 
116
                                  (v->mv_mode == MV_PMODE_INTENSITY_COMP &&
 
117
                                   v->mv_mode2 == MV_PMODE_MIXED_MV);
 
118
    if (v->profile == PROFILE_ADVANCED)
 
119
        pp->bPicOBMC            = (v->range_mapy_flag  << 7) |
 
120
                                  (v->range_mapy       << 4) |
 
121
                                  (v->range_mapuv_flag << 3) |
 
122
                                  (v->range_mapuv          );
 
123
    pp->bPicBinPB               = 0;
 
124
    pp->bMV_RPS                 = 0;
 
125
    pp->bReservedBits           = 0;
 
126
    if (s->picture_structure == PICT_FRAME) {
 
127
        pp->wBitstreamFcodes        = v->lumscale;
 
128
        pp->wBitstreamPCEelements   = v->lumshift;
 
129
    } else {
 
130
        /* Syntax: (top_field_param << 8) | bottom_field_param */
 
131
        pp->wBitstreamFcodes        = (v->lumscale << 8) | v->lumscale;
 
132
        pp->wBitstreamPCEelements   = (v->lumshift << 8) | v->lumshift;
 
133
    }
 
134
    pp->bBitstreamConcealmentNeed   = 0;
 
135
    pp->bBitstreamConcealmentMethod = 0;
 
136
}
 
137
 
 
138
static void fill_slice(AVCodecContext *avctx, DXVA_SliceInfo *slice,
 
139
                       unsigned position, unsigned size)
 
140
{
 
141
    const VC1Context *v = avctx->priv_data;
 
142
    const MpegEncContext *s = &v->s;
 
143
 
 
144
    memset(slice, 0, sizeof(*slice));
 
145
    slice->wHorizontalPosition = 0;
 
146
    slice->wVerticalPosition   = s->mb_y;
 
147
    slice->dwSliceBitsInBuffer = 8 * size;
 
148
    slice->dwSliceDataLocation = position;
 
149
    slice->bStartCodeBitOffset = 0;
 
150
    slice->bReservedBits       = 0;
 
151
    slice->wMBbitOffset        = get_bits_count(&s->gb);
 
152
    slice->wNumberMBsInSlice   = s->mb_width * s->mb_height; /* XXX We assume 1 slice */
 
153
    slice->wQuantizerScaleCode = v->pq;
 
154
    slice->wBadSliceChopping   = 0;
 
155
}
 
156
 
 
157
static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
 
158
                                             DXVA2_DecodeBufferDesc *bs,
 
159
                                             DXVA2_DecodeBufferDesc *sc)
 
160
{
 
161
    const VC1Context *v = avctx->priv_data;
 
162
    struct dxva_context *ctx = avctx->hwaccel_context;
 
163
    const MpegEncContext *s = &v->s;
 
164
    struct dxva2_picture_context *ctx_pic = s->current_picture_ptr->hwaccel_picture_private;
 
165
 
 
166
    DXVA_SliceInfo *slice = &ctx_pic->si;
 
167
 
 
168
    static const uint8_t start_code[] = { 0, 0, 1, 0x0d };
 
169
    const unsigned start_code_size = avctx->codec_id == CODEC_ID_VC1 ? sizeof(start_code) : 0;
 
170
    const unsigned slice_size = slice->dwSliceBitsInBuffer / 8;
 
171
    const unsigned padding = 128 - ((start_code_size + slice_size) & 127);
 
172
    const unsigned data_size = start_code_size + slice_size + padding;
 
173
 
 
174
    uint8_t  *dxva_data;
 
175
    unsigned dxva_size;
 
176
    int result;
 
177
 
 
178
    if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder,
 
179
                                              DXVA2_BitStreamDateBufferType,
 
180
                                              &dxva_data, &dxva_size)))
 
181
        return -1;
 
182
 
 
183
    result = data_size <= dxva_size ? 0 : -1;
 
184
    if (!result) {
 
185
        if (start_code_size > 0)
 
186
            memcpy(dxva_data, start_code, start_code_size);
 
187
        memcpy(dxva_data + start_code_size,
 
188
               ctx_pic->bitstream + slice->dwSliceDataLocation, slice_size);
 
189
        if (padding > 0)
 
190
            memset(dxva_data + start_code_size + slice_size, 0, padding);
 
191
        slice->dwSliceBitsInBuffer = 8 * data_size;
 
192
    }
 
193
    if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder,
 
194
                                                  DXVA2_BitStreamDateBufferType)))
 
195
        return -1;
 
196
    if (result)
 
197
        return result;
 
198
 
 
199
    memset(bs, 0, sizeof(*bs));
 
200
    bs->CompressedBufferType = DXVA2_BitStreamDateBufferType;
 
201
    bs->DataSize             = data_size;
 
202
    bs->NumMBsInBuffer       = s->mb_width * s->mb_height;
 
203
    assert((bs->DataSize & 127) == 0);
 
204
 
 
205
    return ff_dxva2_commit_buffer(avctx, ctx, sc,
 
206
                                  DXVA2_SliceControlBufferType,
 
207
                                  slice, sizeof(*slice), bs->NumMBsInBuffer);
 
208
}
 
209
 
 
210
static int start_frame(AVCodecContext *avctx,
 
211
                       av_unused const uint8_t *buffer,
 
212
                       av_unused uint32_t size)
 
213
{
 
214
    const VC1Context *v = avctx->priv_data;
 
215
    struct dxva_context *ctx = avctx->hwaccel_context;
 
216
    struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->hwaccel_picture_private;
 
217
 
 
218
    if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0)
 
219
        return -1;
 
220
    assert(ctx_pic);
 
221
 
 
222
    fill_picture_parameters(avctx, ctx, v, &ctx_pic->pp);
 
223
 
 
224
    ctx_pic->bitstream_size = 0;
 
225
    ctx_pic->bitstream      = NULL;
 
226
    return 0;
 
227
}
 
228
 
 
229
static int decode_slice(AVCodecContext *avctx,
 
230
                        const uint8_t *buffer, uint32_t size)
 
231
{
 
232
    const VC1Context *v = avctx->priv_data;
 
233
    const Picture *current_picture = v->s.current_picture_ptr;
 
234
    struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
 
235
 
 
236
    if (ctx_pic->bitstream_size > 0)
 
237
        return -1;
 
238
 
 
239
    if (avctx->codec_id == CODEC_ID_VC1 &&
 
240
        size >= 4 && IS_MARKER(AV_RB32(buffer))) {
 
241
        buffer += 4;
 
242
        size   -= 4;
 
243
    }
 
244
 
 
245
    ctx_pic->bitstream_size = size;
 
246
    ctx_pic->bitstream      = buffer;
 
247
 
 
248
    fill_slice(avctx, &ctx_pic->si, 0, size);
 
249
    return 0;
 
250
}
 
251
 
 
252
static int end_frame(AVCodecContext *avctx)
 
253
{
 
254
    VC1Context *v = avctx->priv_data;
 
255
    struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->hwaccel_picture_private;
 
256
 
 
257
    if (ctx_pic->bitstream_size <= 0)
 
258
        return -1;
 
259
 
 
260
    return ff_dxva2_common_end_frame(avctx, &v->s,
 
261
                                     &ctx_pic->pp, sizeof(ctx_pic->pp),
 
262
                                     NULL, 0,
 
263
                                     commit_bitstream_and_slice_buffer);
 
264
}
 
265
 
 
266
#if CONFIG_WMV3_DXVA2_HWACCEL
 
267
AVHWAccel wmv3_dxva2_hwaccel = {
 
268
    .name           = "wmv3_dxva2",
 
269
    .type           = AVMEDIA_TYPE_VIDEO,
 
270
    .id             = CODEC_ID_WMV3,
 
271
    .pix_fmt        = PIX_FMT_DXVA2_VLD,
 
272
    .capabilities   = 0,
 
273
    .start_frame    = start_frame,
 
274
    .decode_slice   = decode_slice,
 
275
    .end_frame      = end_frame,
 
276
    .priv_data_size = sizeof(struct dxva2_picture_context),
 
277
};
 
278
#endif
 
279
 
 
280
AVHWAccel vc1_dxva2_hwaccel = {
 
281
    .name           = "vc1_dxva2",
 
282
    .type           = AVMEDIA_TYPE_VIDEO,
 
283
    .id             = CODEC_ID_VC1,
 
284
    .pix_fmt        = PIX_FMT_DXVA2_VLD,
 
285
    .capabilities   = 0,
 
286
    .start_frame    = start_frame,
 
287
    .decode_slice   = decode_slice,
 
288
    .end_frame      = end_frame,
 
289
    .priv_data_size = sizeof(struct dxva2_picture_context),
 
290
};
 
291