FFmpeg
Loading...
Searching...
No Matches
vdpau_vp9.c
Go to the documentation of this file.
1/*
2 * VP9 HW decode acceleration through VDPAU
3 *
4 * Copyright (c) 2019 Manoj Gupta Bonda
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 Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <vdpau/vdpau.h>
24#include "libavutil/pixdesc.h"
25#include "avcodec.h"
26#include "hwaccel_internal.h"
27#include "vp9dec.h"
28#include "vdpau.h"
29#include "vdpau_internal.h"
30
32 const AVBufferRef *buffer_ref,
33 const uint8_t *buffer, uint32_t size)
34{
35 VP9Context *s = avctx->priv_data;
36 VP9SharedContext *h = &(s->s);
37 VP9Frame pic = h->frames[CUR_FRAME];
39 int i;
40
41 VdpPictureInfoVP9 *info = &pic_ctx->info.vp9;
42 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
43 if (!pixdesc) {
44 return AV_PIX_FMT_NONE;
45 }
46
47 info->width = avctx->width;
48 info->height = avctx->height;
49 /* fill LvPictureInfoVP9 struct */
50 info->lastReference = VDP_INVALID_HANDLE;
51 info->goldenReference = VDP_INVALID_HANDLE;
52 info->altReference = VDP_INVALID_HANDLE;
53
54 if (h->refs[h->h.refidx[0]].f && h->refs[h->h.refidx[0]].f->private_ref) {
55 info->lastReference = ff_vdpau_get_surface_id(h->refs[h->h.refidx[0]].f);
56 }
57 if (h->refs[h->h.refidx[1]].f && h->refs[h->h.refidx[1]].f->private_ref) {
58 info->goldenReference = ff_vdpau_get_surface_id(h->refs[h->h.refidx[1]].f);
59 }
60 if (h->refs[h->h.refidx[2]].f && h->refs[h->h.refidx[2]].f->private_ref) {
61 info->altReference = ff_vdpau_get_surface_id(h->refs[h->h.refidx[2]].f);
62 }
63
64 info->profile = h->h.profile;
65 info->frameContextIdx = h->h.framectxid;
66 info->keyFrame = h->h.keyframe;
67 info->showFrame = !h->h.invisible;
68 info->errorResilient = h->h.errorres;
69 info->frameParallelDecoding = h->h.parallelmode;
70
71 info->subSamplingX = pixdesc->log2_chroma_w;
72 info->subSamplingY = pixdesc->log2_chroma_h;
73
74 info->intraOnly = h->h.intraonly;
75 info->allowHighPrecisionMv = h->h.keyframe ? 0 : h->h.highprecisionmvs;
76 info->refreshEntropyProbs = h->h.refreshctx;
77
78 info->bitDepthMinus8Luma = pixdesc->comp[0].depth - 8;
79 info->bitDepthMinus8Chroma = pixdesc->comp[1].depth - 8;
80
81 info->loopFilterLevel = h->h.filter.level;
82 info->loopFilterSharpness = h->h.filter.sharpness;
83 info->modeRefLfEnabled = h->h.lf_delta.enabled;
84
85 info->log2TileColumns = h->h.tiling.log2_tile_cols;
86 info->log2TileRows = h->h.tiling.log2_tile_rows;
87
88 info->segmentEnabled = h->h.segmentation.enabled;
89 info->segmentMapUpdate = h->h.segmentation.update_map;
90 info->segmentMapTemporalUpdate = h->h.segmentation.temporal;
91 info->segmentFeatureMode = h->h.segmentation.absolute_vals;
92
93 info->qpYAc = h->h.yac_qi;
94 info->qpYDc = h->h.ydc_qdelta;
95 info->qpChDc = h->h.uvdc_qdelta;
96 info->qpChAc = h->h.uvac_qdelta;
97
98 info->resetFrameContext = h->h.resetctx;
99 info->mcompFilterType = h->h.filtermode ^ (h->h.filtermode <= 1);
100 info->uncompressedHeaderSize = h->h.uncompressed_header_size;
101 info->compressedHeaderSize = h->h.compressed_header_size;
102 info->refFrameSignBias[0] = 0;
103
104
105 for (i = 0; i < FF_ARRAY_ELEMS(info->mbModeLfDelta); i++)
106 info->mbModeLfDelta[i] = h->h.lf_delta.mode[i];
107
108 for (i = 0; i < FF_ARRAY_ELEMS(info->mbRefLfDelta); i++)
109 info->mbRefLfDelta[i] = h->h.lf_delta.ref[i];
110
111 for (i = 0; i < FF_ARRAY_ELEMS(info->mbSegmentTreeProbs); i++)
112 info->mbSegmentTreeProbs[i] = h->h.segmentation.prob[i];
113
114 for (i = 0; i < FF_ARRAY_ELEMS(info->activeRefIdx); i++) {
115 info->activeRefIdx[i] = h->h.refidx[i];
116 info->segmentPredProbs[i] = h->h.segmentation.pred_prob[i];
117 info->refFrameSignBias[i + 1] = h->h.signbias[i];
118 }
119
120 for (i = 0; i < FF_ARRAY_ELEMS(info->segmentFeatureEnable); i++) {
121 info->segmentFeatureEnable[i][0] = h->h.segmentation.feat[i].q_enabled;
122 info->segmentFeatureEnable[i][1] = h->h.segmentation.feat[i].lf_enabled;
123 info->segmentFeatureEnable[i][2] = h->h.segmentation.feat[i].ref_enabled;
124 info->segmentFeatureEnable[i][3] = h->h.segmentation.feat[i].skip_enabled;
125
126 info->segmentFeatureData[i][0] = h->h.segmentation.feat[i].q_val;
127 info->segmentFeatureData[i][1] = h->h.segmentation.feat[i].lf_val;
128 info->segmentFeatureData[i][2] = h->h.segmentation.feat[i].ref_val;
129 info->segmentFeatureData[i][3] = 0;
130 }
131
132 switch (avctx->colorspace) {
133 default:
135 info->colorSpace = 0;
136 break;
138 info->colorSpace = 1;
139 break;
140 case AVCOL_SPC_BT709:
141 info->colorSpace = 2;
142 break;
144 info->colorSpace = 3;
145 break;
147 info->colorSpace = 4;
148 break;
150 info->colorSpace = 5;
151 break;
153 info->colorSpace = 6;
154 break;
155 case AVCOL_SPC_RGB:
156 info->colorSpace = 7;
157 break;
158 }
159
160 return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
161
162}
163
164static const uint8_t start_code_prefix[3] = { 0x00, 0x00, 0x01 };
165
167 const uint8_t *buffer, uint32_t size)
168{
169 VP9SharedContext *h = avctx->priv_data;
170 VP9Frame pic = h->frames[CUR_FRAME];
172
173 int val;
174
176 if (val)
177 return val;
178
179 val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
180 if (val)
181 return val;
182
183 return 0;
184}
185
187{
188 VP9SharedContext *h = avctx->priv_data;
189 VP9Frame pic = h->frames[CUR_FRAME];
191
192 int val;
193
194 val = ff_vdpau_common_end_frame(avctx, pic.tf.f, pic_ctx);
195 if (val < 0)
196 return val;
197
198 return 0;
199}
200
202{
203 VdpDecoderProfile profile;
204 uint32_t level = avctx->level;
205
206 switch (avctx->profile) {
207 case AV_PROFILE_VP9_0:
208 profile = VDP_DECODER_PROFILE_VP9_PROFILE_0;
209 break;
210 case AV_PROFILE_VP9_1:
211 profile = VDP_DECODER_PROFILE_VP9_PROFILE_1;
212 break;
213 case AV_PROFILE_VP9_2:
214 profile = VDP_DECODER_PROFILE_VP9_PROFILE_2;
215 break;
216 case AV_PROFILE_VP9_3:
217 profile = VDP_DECODER_PROFILE_VP9_PROFILE_3;
218 break;
219 default:
220 return AVERROR(ENOTSUP);
221 }
222
223 return ff_vdpau_common_init(avctx, profile, level);
224}
225
227 .p.name = "vp9_vdpau",
228 .p.type = AVMEDIA_TYPE_VIDEO,
229 .p.id = AV_CODEC_ID_VP9,
230 .p.pix_fmt = AV_PIX_FMT_VDPAU,
231 .start_frame = vdpau_vp9_start_frame,
232 .end_frame = vdpau_vp9_end_frame,
233 .decode_slice = vdpau_vp9_decode_slice,
234 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
236 .uninit = ff_vdpau_common_uninit,
237 .frame_params = ff_vdpau_common_frame_params,
238 .priv_data_size = sizeof(VDPAUContext),
239 .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
240};
static double val(void *priv, double ch)
Definition aeval.c:77
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define AV_PROFILE_VP9_3
Definition defs.h:157
#define AV_PROFILE_VP9_1
Definition defs.h:155
#define AV_PROFILE_VP9_0
Definition defs.h:154
#define AV_PROFILE_VP9_2
Definition defs.h:156
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
av_cold int ff_vdpau_common_uninit(AVCodecContext *avctx)
Definition vdpau.c:278
int ff_vdpau_common_start_frame(struct vdpau_picture_context *pic_ctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition vdpau.c:316
av_cold int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, int level)
Definition vdpau.c:127
int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, const uint8_t *buf, uint32_t size)
Definition vdpau.c:373
int ff_vdpau_common_end_frame(AVCodecContext *avctx, AVFrame *frame, struct vdpau_picture_context *pic_ctx)
Definition vdpau.c:326
int ff_vdpau_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition vdpau.c:108
@ AV_CODEC_ID_VP9
Definition codec_id.h:217
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
const struct FFHWAccel ff_vp9_vdpau_hwaccel
Definition vdpau_vp9.c:226
#define av_cold
Definition attributes.h:117
int profile
Definition mxfenc.c:2299
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition pixfmt.h:194
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition pixfmt.h:708
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition pixfmt.h:712
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition pixfmt.h:707
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition pixfmt.h:717
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:709
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition pixfmt.h:713
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
Definition pixfmt.h:714
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
Definition pixfmt.h:710
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Definition buffer.h:82
main external API structure.
Definition avcodec.h:443
int width
picture width / height.
Definition avcodec.h:604
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:650
int level
Encoding level descriptor.
Definition avcodec.h:1646
int profile
profile
Definition avcodec.h:1636
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:671
void * priv_data
Definition avcodec.h:470
int depth
Number of bits in the component.
Definition pixdesc.h:57
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition pixdesc.h:80
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition pixdesc.h:89
struct AVFrame * f
void * hwaccel_picture_private
RefStruct reference.
Definition vp9shared.h:76
ProgressFrame tf
Definition vp9shared.h:70
union VDPAUPictureInfo info
VDPAU picture information.
uint8_t level
Definition svq3.c:208
static char buffer[20]
Definition seek.c:32
int size
Public libavcodec VDPAU header.
static const uint8_t start_code_prefix[3]
Definition vdpau_h264.c:180
static uintptr_t ff_vdpau_get_surface_id(AVFrame *pic)
Extract VdpVideoSurface from an AVFrame.
static int vdpau_vp9_end_frame(AVCodecContext *avctx)
Definition vdpau_vp9.c:186
static int vdpau_vp9_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition vdpau_vp9.c:166
static int vdpau_vp9_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, const uint8_t *buffer, uint32_t size)
Definition vdpau_vp9.c:31
static av_cold int vdpau_vp9_init(AVCodecContext *avctx)
Definition vdpau_vp9.c:201
#define CUR_FRAME
Definition vp9shared.h:172