FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vdpau_vc1.c
Date: 2025-04-25 22:50:00
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 "vc1.h"
31 #include "vdpau.h"
32 #include "vdpau_internal.h"
33
34 static int vdpau_vc1_start_frame(AVCodecContext *avctx,
35 const AVBufferRef *buffer_ref,
36 const uint8_t *buffer, uint32_t size)
37 {
38 VC1Context * const v = avctx->priv_data;
39 MpegEncContext * const s = &v->s;
40 MPVPicture *pic = s->cur_pic.ptr;
41 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
42 VdpPictureInfoVC1 *info = &pic_ctx->info.vc1;
43 VdpVideoSurface ref;
44
45 /* fill LvPictureInfoVC1 struct */
46 info->forward_reference = VDP_INVALID_HANDLE;
47 info->backward_reference = VDP_INVALID_HANDLE;
48
49 switch (s->pict_type) {
50 case AV_PICTURE_TYPE_B:
51 if (s->next_pic.ptr) {
52 ref = ff_vdpau_get_surface_id(s->next_pic.ptr->f);
53 assert(ref != VDP_INVALID_HANDLE);
54 info->backward_reference = ref;
55 }
56 /* fall-through */
57 case AV_PICTURE_TYPE_P:
58 if (s->last_pic.ptr) {
59 ref = ff_vdpau_get_surface_id(s->last_pic.ptr->f);
60 assert(ref != VDP_INVALID_HANDLE);
61 info->forward_reference = ref;
62 }
63 }
64
65 info->slice_count = 0;
66 if (v->bi_type)
67 info->picture_type = 4;
68 else
69 info->picture_type = s->pict_type - 1 + s->pict_type / 3;
70
71 info->frame_coding_mode = v->fcm ? (v->fcm + 1) : 0;
72 info->postprocflag = v->postprocflag;
73 info->pulldown = v->broadcast;
74 info->interlace = v->interlace;
75 info->tfcntrflag = v->tfcntrflag;
76 info->finterpflag = v->finterpflag;
77 info->psf = v->psf;
78 info->dquant = v->dquant;
79 info->panscan_flag = v->panscanflag;
80 info->refdist_flag = v->refdist_flag;
81 info->quantizer = v->quantizer_mode;
82 info->extended_mv = v->extended_mv;
83 info->extended_dmv = v->extended_dmv;
84 info->overlap = v->overlap;
85 info->vstransform = v->vstransform;
86 info->loopfilter = v->s.loop_filter;
87 info->fastuvmc = v->fastuvmc;
88 info->range_mapy_flag = v->range_mapy_flag;
89 info->range_mapy = v->range_mapy;
90 info->range_mapuv_flag = v->range_mapuv_flag;
91 info->range_mapuv = v->range_mapuv;
92 /* Specific to simple/main profile only */
93 info->multires = v->multires;
94 info->syncmarker = v->resync_marker;
95 info->rangered = v->rangered | (v->rangeredfrm << 1);
96 info->maxbframes = v->max_b_frames;
97 info->deblockEnable = v->postprocflag & 1;
98 info->pquant = v->pq;
99
100 return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
101 }
102
103 static int vdpau_vc1_decode_slice(AVCodecContext *avctx,
104 const uint8_t *buffer, uint32_t size)
105 {
106 VC1Context * const v = avctx->priv_data;
107 MpegEncContext * const s = &v->s;
108 MPVPicture *pic = s->cur_pic.ptr;
109 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
110 int val;
111
112 val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
113 if (val < 0)
114 return val;
115
116 pic_ctx->info.vc1.slice_count++;
117 return 0;
118 }
119
120 static av_cold int vdpau_vc1_init(AVCodecContext *avctx)
121 {
122 VdpDecoderProfile profile;
123
124 switch (avctx->profile) {
125 case AV_PROFILE_VC1_SIMPLE:
126 profile = VDP_DECODER_PROFILE_VC1_SIMPLE;
127 break;
128 case AV_PROFILE_VC1_MAIN:
129 profile = VDP_DECODER_PROFILE_VC1_MAIN;
130 break;
131 case AV_PROFILE_VC1_ADVANCED:
132 profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
133 break;
134 default:
135 return AVERROR(ENOTSUP);
136 }
137
138 return ff_vdpau_common_init(avctx, profile, avctx->level);
139 }
140
141 #if CONFIG_WMV3_VDPAU_HWACCEL
142 const FFHWAccel ff_wmv3_vdpau_hwaccel = {
143 .p.name = "wm3_vdpau",
144 .p.type = AVMEDIA_TYPE_VIDEO,
145 .p.id = AV_CODEC_ID_WMV3,
146 .p.pix_fmt = AV_PIX_FMT_VDPAU,
147 .start_frame = vdpau_vc1_start_frame,
148 .end_frame = ff_vdpau_mpeg_end_frame,
149 .decode_slice = vdpau_vc1_decode_slice,
150 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
151 .init = vdpau_vc1_init,
152 .uninit = ff_vdpau_common_uninit,
153 .frame_params = ff_vdpau_common_frame_params,
154 .priv_data_size = sizeof(VDPAUContext),
155 .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
156 };
157 #endif
158
159 const FFHWAccel ff_vc1_vdpau_hwaccel = {
160 .p.name = "vc1_vdpau",
161 .p.type = AVMEDIA_TYPE_VIDEO,
162 .p.id = AV_CODEC_ID_VC1,
163 .p.pix_fmt = AV_PIX_FMT_VDPAU,
164 .start_frame = vdpau_vc1_start_frame,
165 .end_frame = ff_vdpau_mpeg_end_frame,
166 .decode_slice = vdpau_vc1_decode_slice,
167 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
168 .init = vdpau_vc1_init,
169 .uninit = ff_vdpau_common_uninit,
170 .frame_params = ff_vdpau_common_frame_params,
171 .priv_data_size = sizeof(VDPAUContext),
172 .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
173 };
174