2 * VC-1 decode acceleration through VDPAU
4 * Copyright (c) 2008 NVIDIA
5 * Copyright (c) 2013 RĂ©mi Denis-Courmont
7 * This file is part of Libav.
9 * Libav is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * Libav is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with Libav; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <vdpau/vdpau.h>
29 #include "vdpau_internal.h"
31 static int vdpau_vc1_start_frame(AVCodecContext *avctx,
32 const uint8_t *buffer, uint32_t size)
34 VC1Context * const v = avctx->priv_data;
35 MpegEncContext * const s = &v->s;
36 Picture *pic = s->current_picture_ptr;
37 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
38 VdpPictureInfoVC1 *info = &pic_ctx->info.vc1;
41 /* fill LvPictureInfoVC1 struct */
42 info->forward_reference = VDP_INVALID_HANDLE;
43 info->backward_reference = VDP_INVALID_HANDLE;
45 switch (s->pict_type) {
46 case AV_PICTURE_TYPE_B:
47 ref = ff_vdpau_get_surface_id(s->next_picture.f);
48 assert(ref != VDP_INVALID_HANDLE);
49 info->backward_reference = ref;
51 case AV_PICTURE_TYPE_P:
52 ref = ff_vdpau_get_surface_id(s->last_picture.f);
53 assert(ref != VDP_INVALID_HANDLE);
54 info->forward_reference = ref;
57 info->slice_count = 0;
59 info->picture_type = 4;
61 info->picture_type = s->pict_type - 1 + s->pict_type / 3;
63 info->frame_coding_mode = v->fcm ? (v->fcm + 1) : 0;
64 info->postprocflag = v->postprocflag;
65 info->pulldown = v->broadcast;
66 info->interlace = v->interlace;
67 info->tfcntrflag = v->tfcntrflag;
68 info->finterpflag = v->finterpflag;
70 info->dquant = v->dquant;
71 info->panscan_flag = v->panscanflag;
72 info->refdist_flag = v->refdist_flag;
73 info->quantizer = v->quantizer_mode;
74 info->extended_mv = v->extended_mv;
75 info->extended_dmv = v->extended_dmv;
76 info->overlap = v->overlap;
77 info->vstransform = v->vstransform;
78 info->loopfilter = v->s.loop_filter;
79 info->fastuvmc = v->fastuvmc;
80 info->range_mapy_flag = v->range_mapy_flag;
81 info->range_mapy = v->range_mapy;
82 info->range_mapuv_flag = v->range_mapuv_flag;
83 info->range_mapuv = v->range_mapuv;
84 /* Specific to simple/main profile only */
85 info->multires = v->multires;
86 info->syncmarker = v->resync_marker;
87 info->rangered = v->rangered | (v->rangeredfrm << 1);
88 info->maxbframes = v->s.max_b_frames;
89 info->deblockEnable = v->postprocflag & 1;
92 return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
95 static int vdpau_vc1_decode_slice(AVCodecContext *avctx,
96 const uint8_t *buffer, uint32_t size)
98 VC1Context * const v = avctx->priv_data;
99 MpegEncContext * const s = &v->s;
100 Picture *pic = s->current_picture_ptr;
101 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
104 val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
108 pic_ctx->info.vc1.slice_count++;
112 static int vdpau_vc1_init(AVCodecContext *avctx)
114 VdpDecoderProfile profile;
116 switch (avctx->profile) {
117 case FF_PROFILE_VC1_SIMPLE:
118 profile = VDP_DECODER_PROFILE_VC1_SIMPLE;
120 case FF_PROFILE_VC1_MAIN:
121 profile = VDP_DECODER_PROFILE_VC1_MAIN;
123 case FF_PROFILE_VC1_ADVANCED:
124 profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
127 return AVERROR(ENOTSUP);
130 return ff_vdpau_common_init(avctx, profile, avctx->level);
133 #if CONFIG_WMV3_VDPAU_HWACCEL
134 AVHWAccel ff_wmv3_vdpau_hwaccel = {
136 .type = AVMEDIA_TYPE_VIDEO,
137 .id = AV_CODEC_ID_WMV3,
138 .pix_fmt = AV_PIX_FMT_VDPAU,
139 .start_frame = vdpau_vc1_start_frame,
140 .end_frame = ff_vdpau_mpeg_end_frame,
141 .decode_slice = vdpau_vc1_decode_slice,
142 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
143 .init = vdpau_vc1_init,
144 .uninit = ff_vdpau_common_uninit,
145 .priv_data_size = sizeof(VDPAUContext),
149 AVHWAccel ff_vc1_vdpau_hwaccel = {
151 .type = AVMEDIA_TYPE_VIDEO,
152 .id = AV_CODEC_ID_VC1,
153 .pix_fmt = AV_PIX_FMT_VDPAU,
154 .start_frame = vdpau_vc1_start_frame,
155 .end_frame = ff_vdpau_mpeg_end_frame,
156 .decode_slice = vdpau_vc1_decode_slice,
157 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
158 .init = vdpau_vc1_init,
159 .uninit = ff_vdpau_common_uninit,
160 .priv_data_size = sizeof(VDPAUContext),