FFmpeg
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 "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 
35  const uint8_t *buffer, uint32_t size)
36 {
37  VC1Context * const v = avctx->priv_data;
38  MpegEncContext * const s = &v->s;
39  Picture *pic = s->current_picture_ptr;
40  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
41  VdpPictureInfoVC1 *info = &pic_ctx->info.vc1;
42  VdpVideoSurface ref;
43 
44  /* fill LvPictureInfoVC1 struct */
45  info->forward_reference = VDP_INVALID_HANDLE;
46  info->backward_reference = VDP_INVALID_HANDLE;
47 
48  switch (s->pict_type) {
49  case AV_PICTURE_TYPE_B:
50  if (s->next_picture_ptr) {
51  ref = ff_vdpau_get_surface_id(s->next_picture.f);
52  assert(ref != VDP_INVALID_HANDLE);
53  info->backward_reference = ref;
54  }
55  /* fall-through */
56  case AV_PICTURE_TYPE_P:
57  if (s->last_picture_ptr) {
58  ref = ff_vdpau_get_surface_id(s->last_picture.f);
59  assert(ref != VDP_INVALID_HANDLE);
60  info->forward_reference = ref;
61  }
62  }
63 
64  info->slice_count = 0;
65  if (v->bi_type)
66  info->picture_type = 4;
67  else
68  info->picture_type = s->pict_type - 1 + s->pict_type / 3;
69 
70  info->frame_coding_mode = v->fcm ? (v->fcm + 1) : 0;
71  info->postprocflag = v->postprocflag;
72  info->pulldown = v->broadcast;
73  info->interlace = v->interlace;
74  info->tfcntrflag = v->tfcntrflag;
75  info->finterpflag = v->finterpflag;
76  info->psf = v->psf;
77  info->dquant = v->dquant;
78  info->panscan_flag = v->panscanflag;
79  info->refdist_flag = v->refdist_flag;
80  info->quantizer = v->quantizer_mode;
81  info->extended_mv = v->extended_mv;
82  info->extended_dmv = v->extended_dmv;
83  info->overlap = v->overlap;
84  info->vstransform = v->vstransform;
85  info->loopfilter = v->s.loop_filter;
86  info->fastuvmc = v->fastuvmc;
87  info->range_mapy_flag = v->range_mapy_flag;
88  info->range_mapy = v->range_mapy;
89  info->range_mapuv_flag = v->range_mapuv_flag;
90  info->range_mapuv = v->range_mapuv;
91  /* Specific to simple/main profile only */
92  info->multires = v->multires;
93  info->syncmarker = v->resync_marker;
94  info->rangered = v->rangered | (v->rangeredfrm << 1);
95  info->maxbframes = v->s.max_b_frames;
96  info->deblockEnable = v->postprocflag & 1;
97  info->pquant = v->pq;
98 
99  return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
100 }
101 
103  const uint8_t *buffer, uint32_t size)
104 {
105  VC1Context * const v = avctx->priv_data;
106  MpegEncContext * const s = &v->s;
107  Picture *pic = s->current_picture_ptr;
108  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
109  int val;
110 
111  val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
112  if (val < 0)
113  return val;
114 
115  pic_ctx->info.vc1.slice_count++;
116  return 0;
117 }
118 
119 static int vdpau_vc1_init(AVCodecContext *avctx)
120 {
121  VdpDecoderProfile profile;
122 
123  switch (avctx->profile) {
125  profile = VDP_DECODER_PROFILE_VC1_SIMPLE;
126  break;
127  case AV_PROFILE_VC1_MAIN:
128  profile = VDP_DECODER_PROFILE_VC1_MAIN;
129  break;
131  profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
132  break;
133  default:
134  return AVERROR(ENOTSUP);
135  }
136 
137  return ff_vdpau_common_init(avctx, profile, avctx->level);
138 }
139 
140 #if CONFIG_WMV3_VDPAU_HWACCEL
142  .p.name = "wm3_vdpau",
143  .p.type = AVMEDIA_TYPE_VIDEO,
144  .p.id = AV_CODEC_ID_WMV3,
145  .p.pix_fmt = AV_PIX_FMT_VDPAU,
146  .start_frame = vdpau_vc1_start_frame,
147  .end_frame = ff_vdpau_mpeg_end_frame,
148  .decode_slice = vdpau_vc1_decode_slice,
149  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
150  .init = vdpau_vc1_init,
151  .uninit = ff_vdpau_common_uninit,
152  .frame_params = ff_vdpau_common_frame_params,
153  .priv_data_size = sizeof(VDPAUContext),
154  .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
155 };
156 #endif
157 
159  .p.name = "vc1_vdpau",
160  .p.type = AVMEDIA_TYPE_VIDEO,
161  .p.id = AV_CODEC_ID_VC1,
162  .p.pix_fmt = AV_PIX_FMT_VDPAU,
163  .start_frame = vdpau_vc1_start_frame,
164  .end_frame = ff_vdpau_mpeg_end_frame,
165  .decode_slice = vdpau_vc1_decode_slice,
166  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
167  .init = vdpau_vc1_init,
168  .uninit = ff_vdpau_common_uninit,
169  .frame_params = ff_vdpau_common_frame_params,
170  .priv_data_size = sizeof(VDPAUContext),
171  .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
172 };
AV_PROFILE_VC1_MAIN
#define AV_PROFILE_VC1_MAIN
Definition: defs.h:126
ff_vdpau_common_frame_params
int ff_vdpau_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: vdpau.c:125
VC1Context
The VC1 Context.
Definition: vc1.h:173
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
VC1Context::overlap
int overlap
overlapped transforms in use
Definition: vc1.h:224
VC1Context::interlace
int interlace
Progressive/interlaced (RPTFTM syntax element)
Definition: vc1.h:199
vc1.h
MpegEncContext::max_b_frames
int max_b_frames
max number of B-frames for encoding
Definition: mpegvideo.h:105
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
ff_vc1_vdpau_hwaccel
const FFHWAccel ff_vc1_vdpau_hwaccel
Definition: vdpau_vc1.c:158
VC1Context::fastuvmc
int fastuvmc
Rounding of qpel vector to hpel ? (not in Simple)
Definition: vc1.h:220
Picture
Picture.
Definition: mpegpicture.h:46
vdpau_internal.h
vdpau_picture_context
Definition: vdpau_internal.h:98
FFHWAccel
Definition: hwaccel_internal.h:34
VC1Context::multires
int multires
frame-level RESPIC syntax element present
Definition: vc1.h:184
val
static double val(void *priv, double ch)
Definition: aeval.c:78
ff_vdpau_add_buffer
int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, const uint8_t *buf, uint32_t size)
Definition: vdpau.c:388
VC1Context::dquant
int dquant
How qscale varies with MBs, 2 bits (not in Simple)
Definition: vc1.h:222
vdpau_vc1_decode_slice
static int vdpau_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_vc1.c:102
ff_vdpau_common_init
int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, int level)
Definition: vdpau.c:144
vdpau.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
VC1Context::range_mapuv_flag
uint8_t range_mapuv_flag
Definition: vc1.h:326
VC1Context::postprocflag
int postprocflag
Per-frame processing suggestion flag present.
Definition: vc1.h:197
info
MIPS optimizations info
Definition: mips.txt:2
VC1Context::rangered
int rangered
RANGEREDFRM (range reduction) syntax element present at frame level.
Definition: vc1.h:187
MpegEncContext::loop_filter
int loop_filter
Definition: mpegvideo.h:367
ff_vdpau_common_start_frame
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:333
ff_vdpau_get_surface_id
static uintptr_t ff_vdpau_get_surface_id(AVFrame *pic)
Extract VdpVideoSurface from an AVFrame.
Definition: vdpau_internal.h:38
Picture::hwaccel_picture_private
void * hwaccel_picture_private
RefStruct reference for hardware accelerator private data.
Definition: mpegpicture.h:70
VC1Context::pq
uint8_t pq
Definition: vc1.h:236
AV_CODEC_ID_WMV3
@ AV_CODEC_ID_WMV3
Definition: codec_id.h:123
HWACCEL_CAP_ASYNC_SAFE
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
Definition: hwaccel_internal.h:31
VC1Context::range_mapy_flag
uint8_t range_mapy_flag
Definition: vc1.h:325
hwaccel_internal.h
VC1Context::panscanflag
int panscanflag
NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} present.
Definition: vc1.h:201
VC1Context::range_mapuv
uint8_t range_mapuv
Definition: vc1.h:328
VC1Context::resync_marker
int resync_marker
could this stream contain resync markers
Definition: vc1.h:398
ff_wmv3_vdpau_hwaccel
const struct FFHWAccel ff_wmv3_vdpau_hwaccel
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1783
VC1Context::refdist_flag
int refdist_flag
REFDIST syntax element present in II, IP, PI or PP field picture headers.
Definition: vc1.h:202
AV_PROFILE_VC1_SIMPLE
#define AV_PROFILE_VC1_SIMPLE
Definition: defs.h:125
ff_vdpau_common_uninit
int ff_vdpau_common_uninit(AVCodecContext *avctx)
Definition: vdpau.c:295
VDPAUContext
Definition: vdpau_internal.h:73
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
size
int size
Definition: twinvq_data.h:10344
VDPAUPictureInfo::vc1
VdpPictureInfoVC1 vc1
Definition: vdpau_internal.h:46
VC1Context::rangeredfrm
uint8_t rangeredfrm
Frame decoding info for S/M profiles only.
Definition: vc1.h:301
ff_vdpau_mpeg_end_frame
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
VC1Context::tfcntrflag
int tfcntrflag
TFCNTR present.
Definition: vc1.h:200
AV_PIX_FMT_VDPAU
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:194
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2081
VC1Context::s
MpegEncContext s
Definition: vc1.h:174
VC1Context::extended_mv
int extended_mv
Ext MV in P/B (not in Simple)
Definition: vc1.h:221
AV_CODEC_ID_VC1
@ AV_CODEC_ID_VC1
Definition: codec_id.h:122
profile
int profile
Definition: mxfenc.c:2226
vdpau_vc1_init
static int vdpau_vc1_init(AVCodecContext *avctx)
Definition: vdpau_vc1.c:119
avcodec.h
AV_PROFILE_VC1_ADVANCED
#define AV_PROFILE_VC1_ADVANCED
Definition: defs.h:128
AVCodecContext
main external API structure.
Definition: avcodec.h:445
vdpau_picture_context::info
union VDPAUPictureInfo info
VDPAU picture information.
Definition: vdpau_internal.h:102
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:281
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1639
VC1Context::vstransform
int vstransform
variable-size [48]x[48] transform type + info
Definition: vc1.h:223
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
VC1Context::bi_type
int bi_type
Definition: vc1.h:383
VC1Context::fcm
enum FrameCodingMode fcm
Frame decoding info for Advanced profile.
Definition: vc1.h:307
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:280
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
VC1Context::psf
int psf
Progressive Segmented Frame.
Definition: vc1.h:209
VC1Context::broadcast
int broadcast
TFF/RFF present.
Definition: vc1.h:198
vdpau_vc1_start_frame
static int vdpau_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_vc1.c:34
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
VC1Context::finterpflag
int finterpflag
INTERPFRM present.
Definition: vc1.h:226
VC1Context::quantizer_mode
int quantizer_mode
2 bits, quantizer mode used for sequence, see QUANT_*
Definition: vc1.h:225
VC1Context::range_mapy
uint8_t range_mapy
Definition: vc1.h:327
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:67
VC1Context::extended_dmv
int extended_dmv
Additional extended dmv range at P/B-frame-level.
Definition: vc1.h:203