FFmpeg  4.4.4
vdpau_vc1.c
Go to the documentation of this file.
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 <vdpau/vdpau.h>
25 
26 #include "avcodec.h"
27 #include "hwconfig.h"
28 #include "vc1.h"
29 #include "vdpau.h"
30 #include "vdpau_internal.h"
31 
33  const uint8_t *buffer, uint32_t size)
34 {
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;
40  VdpVideoSurface ref;
41 
42  /* fill LvPictureInfoVC1 struct */
43  info->forward_reference = VDP_INVALID_HANDLE;
44  info->backward_reference = VDP_INVALID_HANDLE;
45 
46  switch (s->pict_type) {
47  case AV_PICTURE_TYPE_B:
48  if (s->next_picture_ptr) {
49  ref = ff_vdpau_get_surface_id(s->next_picture.f);
50  assert(ref != VDP_INVALID_HANDLE);
51  info->backward_reference = ref;
52  }
53  /* fall-through */
54  case AV_PICTURE_TYPE_P:
55  if (s->last_picture_ptr) {
56  ref = ff_vdpau_get_surface_id(s->last_picture.f);
57  assert(ref != VDP_INVALID_HANDLE);
58  info->forward_reference = ref;
59  }
60  }
61 
62  info->slice_count = 0;
63  if (v->bi_type)
64  info->picture_type = 4;
65  else
66  info->picture_type = s->pict_type - 1 + s->pict_type / 3;
67 
68  info->frame_coding_mode = v->fcm ? (v->fcm + 1) : 0;
69  info->postprocflag = v->postprocflag;
70  info->pulldown = v->broadcast;
71  info->interlace = v->interlace;
72  info->tfcntrflag = v->tfcntrflag;
73  info->finterpflag = v->finterpflag;
74  info->psf = v->psf;
75  info->dquant = v->dquant;
76  info->panscan_flag = v->panscanflag;
77  info->refdist_flag = v->refdist_flag;
78  info->quantizer = v->quantizer_mode;
79  info->extended_mv = v->extended_mv;
80  info->extended_dmv = v->extended_dmv;
81  info->overlap = v->overlap;
82  info->vstransform = v->vstransform;
83  info->loopfilter = v->s.loop_filter;
84  info->fastuvmc = v->fastuvmc;
85  info->range_mapy_flag = v->range_mapy_flag;
86  info->range_mapy = v->range_mapy;
87  info->range_mapuv_flag = v->range_mapuv_flag;
88  info->range_mapuv = v->range_mapuv;
89  /* Specific to simple/main profile only */
90  info->multires = v->multires;
91  info->syncmarker = v->resync_marker;
92  info->rangered = v->rangered | (v->rangeredfrm << 1);
93  info->maxbframes = v->s.max_b_frames;
94  info->deblockEnable = v->postprocflag & 1;
95  info->pquant = v->pq;
96 
97  return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
98 }
99 
101  const uint8_t *buffer, uint32_t size)
102 {
103  VC1Context * const v = avctx->priv_data;
104  MpegEncContext * const s = &v->s;
105  Picture *pic = s->current_picture_ptr;
106  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
107  int val;
108 
109  val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
110  if (val < 0)
111  return val;
112 
113  pic_ctx->info.vc1.slice_count++;
114  return 0;
115 }
116 
117 static int vdpau_vc1_init(AVCodecContext *avctx)
118 {
119  VdpDecoderProfile profile;
120 
121  switch (avctx->profile) {
123  profile = VDP_DECODER_PROFILE_VC1_SIMPLE;
124  break;
125  case FF_PROFILE_VC1_MAIN:
126  profile = VDP_DECODER_PROFILE_VC1_MAIN;
127  break;
129  profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
130  break;
131  default:
132  return AVERROR(ENOTSUP);
133  }
134 
135  return ff_vdpau_common_init(avctx, profile, avctx->level);
136 }
137 
138 #if CONFIG_WMV3_VDPAU_HWACCEL
140  .name = "wm3_vdpau",
141  .type = AVMEDIA_TYPE_VIDEO,
142  .id = AV_CODEC_ID_WMV3,
143  .pix_fmt = AV_PIX_FMT_VDPAU,
144  .start_frame = vdpau_vc1_start_frame,
145  .end_frame = ff_vdpau_mpeg_end_frame,
146  .decode_slice = vdpau_vc1_decode_slice,
147  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
148  .init = vdpau_vc1_init,
149  .uninit = ff_vdpau_common_uninit,
150  .frame_params = ff_vdpau_common_frame_params,
151  .priv_data_size = sizeof(VDPAUContext),
152  .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
153 };
154 #endif
155 
157  .name = "vc1_vdpau",
158  .type = AVMEDIA_TYPE_VIDEO,
159  .id = AV_CODEC_ID_VC1,
160  .pix_fmt = AV_PIX_FMT_VDPAU,
161  .start_frame = vdpau_vc1_start_frame,
162  .end_frame = ff_vdpau_mpeg_end_frame,
163  .decode_slice = vdpau_vc1_decode_slice,
164  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
165  .init = vdpau_vc1_init,
166  .uninit = ff_vdpau_common_uninit,
167  .frame_params = ff_vdpau_common_frame_params,
168  .priv_data_size = sizeof(VDPAUContext),
169  .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
170 };
static double val(void *priv, double ch)
Definition: aeval.c:76
uint8_t
Libavcodec external API header.
#define FF_PROFILE_VC1_MAIN
Definition: avcodec.h:1914
#define FF_PROFILE_VC1_SIMPLE
Definition: avcodec.h:1913
#define FF_PROFILE_VC1_ADVANCED
Definition: avcodec.h:1916
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
#define s(width, name)
Definition: cbs_vp9.c:257
int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, int level)
Definition: vdpau.c:137
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:326
int ff_vdpau_common_uninit(AVCodecContext *avctx)
Definition: vdpau.c:288
int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, const uint8_t *buf, uint32_t size)
Definition: vdpau.c:381
int ff_vdpau_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: vdpau.c:118
@ AV_CODEC_ID_VC1
Definition: codec_id.h:119
@ AV_CODEC_ID_WMV3
Definition: codec_id.h:120
#define AVERROR(e)
Definition: error.h:43
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:276
const AVHWAccel ff_wmv3_vdpau_hwaccel
#define HWACCEL_CAP_ASYNC_SAFE
Definition: hwconfig.h:26
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:197
mfxU16 profile
Definition: qsvenc.c:45
static char buffer[20]
Definition: seek.c:32
main external API structure.
Definition: avcodec.h:536
int level
level
Definition: avcodec.h:1984
int profile
profile
Definition: avcodec.h:1858
void * priv_data
Definition: avcodec.h:563
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2444
MpegEncContext.
Definition: mpegvideo.h:81
int max_b_frames
max number of B-frames for encoding
Definition: mpegvideo.h:115
Picture.
Definition: mpegpicture.h:45
void * hwaccel_picture_private
Hardware accelerator private data.
Definition: mpegpicture.h:78
The VC1 Context.
Definition: vc1.h:173
int tfcntrflag
TFCNTR present.
Definition: vc1.h:200
int dquant
How qscale varies with MBs, 2 bits (not in Simple)
Definition: vc1.h:222
int multires
frame-level RESPIC syntax element present
Definition: vc1.h:184
int finterpflag
INTERPFRM present.
Definition: vc1.h:226
uint8_t range_mapuv_flag
Definition: vc1.h:328
int extended_mv
Ext MV in P/B (not in Simple)
Definition: vc1.h:221
uint8_t range_mapy_flag
Definition: vc1.h:327
int bi_type
Definition: vc1.h:385
uint8_t range_mapy
Definition: vc1.h:329
uint8_t pq
Definition: vc1.h:236
int extended_dmv
Additional extended dmv range at P/B-frame-level.
Definition: vc1.h:203
int panscanflag
NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} present.
Definition: vc1.h:201
int psf
Progressive Segmented Frame.
Definition: vc1.h:209
uint8_t rangeredfrm
Frame decoding info for S/M profiles only.
Definition: vc1.h:301
int quantizer_mode
2 bits, quantizer mode used for sequence, see QUANT_*
Definition: vc1.h:225
int broadcast
TFF/RFF present.
Definition: vc1.h:198
int refdist_flag
REFDIST syntax element present in II, IP, PI or PP field picture headers.
Definition: vc1.h:202
MpegEncContext s
Definition: vc1.h:174
int overlap
overlapped transforms in use
Definition: vc1.h:224
uint8_t range_mapuv
Definition: vc1.h:330
int postprocflag
Per-frame processing suggestion flag present.
Definition: vc1.h:197
enum FrameCodingMode fcm
Frame decoding info for Advanced profile.
Definition: vc1.h:307
int interlace
Progressive/interlaced (RPTFTM syntax element)
Definition: vc1.h:199
int resync_marker
could this stream contain resync markers
Definition: vc1.h:400
int fastuvmc
Rounding of qpel vector to hpel ? (not in Simple)
Definition: vc1.h:220
int rangered
RANGEREDFRM (range reduction) syntax element present at frame level.
Definition: vc1.h:187
int vstransform
variable-size [48]x[48] transform type + info
Definition: vc1.h:223
union VDPAUPictureInfo info
VDPAU picture information.
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
int size
VdpPictureInfoVC1 vc1
Public libavcodec VDPAU header.
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
static uintptr_t ff_vdpau_get_surface_id(AVFrame *pic)
Extract VdpVideoSurface from an AVFrame.
static int vdpau_vc1_init(AVCodecContext *avctx)
Definition: vdpau_vc1.c:117
static int vdpau_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_vc1.c:100
const AVHWAccel ff_vc1_vdpau_hwaccel
Definition: vdpau_vc1.c:156
static int vdpau_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_vc1.c:32