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>
30 #include "vdpau_internal.h"
32 static int vdpau_vc1_start_frame(AVCodecContext *avctx,
33 const uint8_t *buffer, uint32_t size)
35 VC1Context * const v = avctx->priv_data;
36 MpegEncContext * const s = &v->s;
37 Picture *pic = s->current_picture_ptr;
38 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
39 VdpPictureInfoVC1 *info = &pic_ctx->info.vc1;
42 /* fill LvPictureInfoVC1 struct */
43 info->forward_reference = VDP_INVALID_HANDLE;
44 info->backward_reference = VDP_INVALID_HANDLE;
46 switch (s->pict_type) {
47 case AV_PICTURE_TYPE_B:
48 ref = ff_vdpau_get_surface_id(s->next_picture.f);
49 assert(ref != VDP_INVALID_HANDLE);
50 info->backward_reference = ref;
52 case AV_PICTURE_TYPE_P:
53 ref = ff_vdpau_get_surface_id(s->last_picture.f);
54 assert(ref != VDP_INVALID_HANDLE);
55 info->forward_reference = ref;
58 info->slice_count = 0;
60 info->picture_type = 4;
62 info->picture_type = s->pict_type - 1 + s->pict_type / 3;
64 info->frame_coding_mode = v->fcm ? (v->fcm + 1) : 0;
65 info->postprocflag = v->postprocflag;
66 info->pulldown = v->broadcast;
67 info->interlace = v->interlace;
68 info->tfcntrflag = v->tfcntrflag;
69 info->finterpflag = v->finterpflag;
71 info->dquant = v->dquant;
72 info->panscan_flag = v->panscanflag;
73 info->refdist_flag = v->refdist_flag;
74 info->quantizer = v->quantizer_mode;
75 info->extended_mv = v->extended_mv;
76 info->extended_dmv = v->extended_dmv;
77 info->overlap = v->overlap;
78 info->vstransform = v->vstransform;
79 info->loopfilter = v->s.loop_filter;
80 info->fastuvmc = v->fastuvmc;
81 info->range_mapy_flag = v->range_mapy_flag;
82 info->range_mapy = v->range_mapy;
83 info->range_mapuv_flag = v->range_mapuv_flag;
84 info->range_mapuv = v->range_mapuv;
85 /* Specific to simple/main profile only */
86 info->multires = v->multires;
87 info->syncmarker = v->resync_marker;
88 info->rangered = v->rangered | (v->rangeredfrm << 1);
89 info->maxbframes = v->s.max_b_frames;
90 info->deblockEnable = v->postprocflag & 1;
93 return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
96 static int vdpau_vc1_decode_slice(AVCodecContext *avctx,
97 const uint8_t *buffer, uint32_t size)
99 VC1Context * const v = avctx->priv_data;
100 MpegEncContext * const s = &v->s;
101 Picture *pic = s->current_picture_ptr;
102 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
105 val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
109 pic_ctx->info.vc1.slice_count++;
113 static int vdpau_vc1_init(AVCodecContext *avctx)
115 VdpDecoderProfile profile;
117 switch (avctx->profile) {
118 case FF_PROFILE_VC1_SIMPLE:
119 profile = VDP_DECODER_PROFILE_VC1_SIMPLE;
121 case FF_PROFILE_VC1_MAIN:
122 profile = VDP_DECODER_PROFILE_VC1_MAIN;
124 case FF_PROFILE_VC1_ADVANCED:
125 profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
128 return AVERROR(ENOTSUP);
131 return ff_vdpau_common_init(avctx, profile, avctx->level);
134 #if CONFIG_WMV3_VDPAU_HWACCEL
135 AVHWAccel ff_wmv3_vdpau_hwaccel = {
137 .type = AVMEDIA_TYPE_VIDEO,
138 .id = AV_CODEC_ID_WMV3,
139 .pix_fmt = AV_PIX_FMT_VDPAU,
140 .start_frame = vdpau_vc1_start_frame,
141 .end_frame = ff_vdpau_mpeg_end_frame,
142 .decode_slice = vdpau_vc1_decode_slice,
143 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
144 .init = vdpau_vc1_init,
145 .uninit = ff_vdpau_common_uninit,
146 .priv_data_size = sizeof(VDPAUContext),
147 .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
151 AVHWAccel ff_vc1_vdpau_hwaccel = {
153 .type = AVMEDIA_TYPE_VIDEO,
154 .id = AV_CODEC_ID_VC1,
155 .pix_fmt = AV_PIX_FMT_VDPAU,
156 .start_frame = vdpau_vc1_start_frame,
157 .end_frame = ff_vdpau_mpeg_end_frame,
158 .decode_slice = vdpau_vc1_decode_slice,
159 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
160 .init = vdpau_vc1_init,
161 .uninit = ff_vdpau_common_uninit,
162 .priv_data_size = sizeof(VDPAUContext),
163 .caps_internal = HWACCEL_CAP_ASYNC_SAFE,