FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vdpau_vc1.c
Date: 2026-04-30 18:27:06
Exec Total Coverage
Lines: 0 72 0.0%
Functions: 0 3 0.0%
Branches: 0 17 0.0%

Line Branch Exec Source
1 /*
2 * VC-1 decode acceleration through VDPAU
3 *
4 * Copyright (c) 2008 NVIDIA
5 * Copyright (c) 2013 Rémi Denis-Courmont
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg 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.
13 *
14 * FFmpeg 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.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include "config_components.h"
25
26 #include <vdpau/vdpau.h>
27
28 #include "avcodec.h"
29 #include "hwaccel_internal.h"
30 #include "libavutil/attributes.h"
31 #include "vc1.h"
32 #include "vdpau.h"
33 #include "vdpau_internal.h"
34
35 static int vdpau_vc1_start_frame(AVCodecContext *avctx,
36 const AVBufferRef *buffer_ref,
37 const uint8_t *buffer, uint32_t size)
38 {
39 VC1Context * const v = avctx->priv_data;
40 MpegEncContext * const s = &v->s;
41 MPVPicture *pic = s->cur_pic.ptr;
42 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
43 VdpPictureInfoVC1 *info = &pic_ctx->info.vc1;
44 VdpVideoSurface ref;
45
46 /* fill LvPictureInfoVC1 struct */
47 info->forward_reference = VDP_INVALID_HANDLE;
48 info->backward_reference = VDP_INVALID_HANDLE;
49
50 switch (s->pict_type) {
51 case AV_PICTURE_TYPE_B:
52 if (s->next_pic.ptr) {
53 ref = ff_vdpau_get_surface_id(s->next_pic.ptr->f);
54 assert(ref != VDP_INVALID_HANDLE);
55 info->backward_reference = ref;
56 }
57 av_fallthrough;
58 case AV_PICTURE_TYPE_P:
59 if (s->last_pic.ptr) {
60 ref = ff_vdpau_get_surface_id(s->last_pic.ptr->f);
61 assert(ref != VDP_INVALID_HANDLE);
62 info->forward_reference = ref;
63 }
64 }
65
66 info->slice_count = 0;
67 if (v->bi_type)
68 info->picture_type = 4;
69 else
70 info->picture_type = s->pict_type - 1 + s->pict_type / 3;
71
72 info->frame_coding_mode = v->fcm ? (v->fcm + 1) : 0;
73 info->postprocflag = v->postprocflag;
74 info->pulldown = v->broadcast;
75 info->interlace = v->interlace;
76 info->tfcntrflag = v->tfcntrflag;
77 info->finterpflag = v->finterpflag;
78 info->psf = v->psf;
79 info->dquant = v->dquant;
80 info->panscan_flag = v->panscanflag;
81 info->refdist_flag = v->refdist_flag;
82 info->quantizer = v->quantizer_mode;
83 info->extended_mv = v->extended_mv;
84 info->extended_dmv = v->extended_dmv;
85 info->overlap = v->overlap;
86 info->vstransform = v->vstransform;
87 info->loopfilter = v->loop_filter;
88 info->fastuvmc = v->fastuvmc;
89 info->range_mapy_flag = v->range_mapy_flag;
90 info->range_mapy = v->range_mapy;
91 info->range_mapuv_flag = v->range_mapuv_flag;
92 info->range_mapuv = v->range_mapuv;
93 /* Specific to simple/main profile only */
94 info->multires = v->multires;
95 info->syncmarker = v->resync_marker;
96 info->rangered = v->rangered | (v->rangeredfrm << 1);
97 info->maxbframes = v->max_b_frames;
98 info->deblockEnable = v->postprocflag & 1;
99 info->pquant = v->pq;
100
101 return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
102 }
103
104 static int vdpau_vc1_decode_slice(AVCodecContext *avctx,
105 const uint8_t *buffer, uint32_t size)
106 {
107 VC1Context * const v = avctx->priv_data;
108 MpegEncContext * const s = &v->s;
109 MPVPicture *pic = s->cur_pic.ptr;
110 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
111 int val;
112
113 val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
114 if (val < 0)
115 return val;
116
117 pic_ctx->info.vc1.slice_count++;
118 return 0;
119 }
120
121 static av_cold int vdpau_vc1_init(AVCodecContext *avctx)
122 {
123 VdpDecoderProfile profile;
124
125 switch (avctx->profile) {
126 case AV_PROFILE_VC1_SIMPLE:
127 profile = VDP_DECODER_PROFILE_VC1_SIMPLE;
128 break;
129 case AV_PROFILE_VC1_MAIN:
130 profile = VDP_DECODER_PROFILE_VC1_MAIN;
131 break;
132 case AV_PROFILE_VC1_ADVANCED:
133 profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
134 break;
135 default:
136 return AVERROR(ENOTSUP);
137 }
138
139 return ff_vdpau_common_init(avctx, profile, avctx->level);
140 }
141
142 #if CONFIG_WMV3_VDPAU_HWACCEL
143 const FFHWAccel ff_wmv3_vdpau_hwaccel = {
144 .p.name = "wm3_vdpau",
145 .p.type = AVMEDIA_TYPE_VIDEO,
146 .p.id = AV_CODEC_ID_WMV3,
147 .p.pix_fmt = AV_PIX_FMT_VDPAU,
148 .start_frame = vdpau_vc1_start_frame,
149 .end_frame = ff_vdpau_mpeg_end_frame,
150 .decode_slice = vdpau_vc1_decode_slice,
151 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
152 .init = vdpau_vc1_init,
153 .uninit = ff_vdpau_common_uninit,
154 .frame_params = ff_vdpau_common_frame_params,
155 .priv_data_size = sizeof(VDPAUContext),
156 .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
157 };
158 #endif
159
160 const FFHWAccel ff_vc1_vdpau_hwaccel = {
161 .p.name = "vc1_vdpau",
162 .p.type = AVMEDIA_TYPE_VIDEO,
163 .p.id = AV_CODEC_ID_VC1,
164 .p.pix_fmt = AV_PIX_FMT_VDPAU,
165 .start_frame = vdpau_vc1_start_frame,
166 .end_frame = ff_vdpau_mpeg_end_frame,
167 .decode_slice = vdpau_vc1_decode_slice,
168 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
169 .init = vdpau_vc1_init,
170 .uninit = ff_vdpau_common_uninit,
171 .frame_params = ff_vdpau_common_frame_params,
172 .priv_data_size = sizeof(VDPAUContext),
173 .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
174 };
175