FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "vc1.h"
28 #include "vdpau.h"
29 #include "vdpau_internal.h"
30 
32  const uint8_t *buffer, uint32_t size)
33 {
34  VC1Context * const v = avctx->priv_data;
35  MpegEncContext * const s = &v->s;
36  Picture *pic = s->current_picture_ptr;
37  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
38  VdpPictureInfoVC1 *info = &pic_ctx->info.vc1;
39  VdpVideoSurface ref;
40 
41  /* fill LvPictureInfoVC1 struct */
42  info->forward_reference = VDP_INVALID_HANDLE;
43  info->backward_reference = VDP_INVALID_HANDLE;
44 
45  switch (s->pict_type) {
46  case AV_PICTURE_TYPE_B:
47  if (s->next_picture_ptr) {
49  assert(ref != VDP_INVALID_HANDLE);
50  info->backward_reference = ref;
51  }
52  /* fall-through */
53  case AV_PICTURE_TYPE_P:
54  if (s->last_picture_ptr) {
56  assert(ref != VDP_INVALID_HANDLE);
57  info->forward_reference = ref;
58  }
59  }
60 
61  info->slice_count = 0;
62  if (v->bi_type)
63  info->picture_type = 4;
64  else
65  info->picture_type = s->pict_type - 1 + s->pict_type / 3;
66 
67  info->frame_coding_mode = v->fcm ? (v->fcm + 1) : 0;
68  info->postprocflag = v->postprocflag;
69  info->pulldown = v->broadcast;
70  info->interlace = v->interlace;
71  info->tfcntrflag = v->tfcntrflag;
72  info->finterpflag = v->finterpflag;
73  info->psf = v->psf;
74  info->dquant = v->dquant;
75  info->panscan_flag = v->panscanflag;
76  info->refdist_flag = v->refdist_flag;
77  info->quantizer = v->quantizer_mode;
78  info->extended_mv = v->extended_mv;
79  info->extended_dmv = v->extended_dmv;
80  info->overlap = v->overlap;
81  info->vstransform = v->vstransform;
82  info->loopfilter = v->s.loop_filter;
83  info->fastuvmc = v->fastuvmc;
84  info->range_mapy_flag = v->range_mapy_flag;
85  info->range_mapy = v->range_mapy;
86  info->range_mapuv_flag = v->range_mapuv_flag;
87  info->range_mapuv = v->range_mapuv;
88  /* Specific to simple/main profile only */
89  info->multires = v->multires;
90  info->syncmarker = v->resync_marker;
91  info->rangered = v->rangered | (v->rangeredfrm << 1);
92  info->maxbframes = v->s.max_b_frames;
93  info->deblockEnable = v->postprocflag & 1;
94  info->pquant = v->pq;
95 
96  return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
97 }
98 
100  const uint8_t *buffer, uint32_t size)
101 {
102  VC1Context * const v = avctx->priv_data;
103  MpegEncContext * const s = &v->s;
104  Picture *pic = s->current_picture_ptr;
105  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
106  int val;
107 
108  val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
109  if (val < 0)
110  return val;
111 
112  pic_ctx->info.vc1.slice_count++;
113  return 0;
114 }
115 
116 static int vdpau_vc1_init(AVCodecContext *avctx)
117 {
118  VdpDecoderProfile profile;
119 
120  switch (avctx->profile) {
122  profile = VDP_DECODER_PROFILE_VC1_SIMPLE;
123  break;
124  case FF_PROFILE_VC1_MAIN:
125  profile = VDP_DECODER_PROFILE_VC1_MAIN;
126  break;
128  profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
129  break;
130  default:
131  return AVERROR(ENOTSUP);
132  }
133 
134  return ff_vdpau_common_init(avctx, profile, avctx->level);
135 }
136 
137 #if CONFIG_WMV3_VDPAU_HWACCEL
138 AVHWAccel ff_wmv3_vdpau_hwaccel = {
139  .name = "wm3_vdpau",
140  .type = AVMEDIA_TYPE_VIDEO,
141  .id = AV_CODEC_ID_WMV3,
142  .pix_fmt = AV_PIX_FMT_VDPAU,
143  .start_frame = vdpau_vc1_start_frame,
144  .end_frame = ff_vdpau_mpeg_end_frame,
145  .decode_slice = vdpau_vc1_decode_slice,
146  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
147  .init = vdpau_vc1_init,
148  .uninit = ff_vdpau_common_uninit,
149  .priv_data_size = sizeof(VDPAUContext),
150 };
151 #endif
152 
154  .name = "vc1_vdpau",
155  .type = AVMEDIA_TYPE_VIDEO,
156  .id = AV_CODEC_ID_VC1,
157  .pix_fmt = AV_PIX_FMT_VDPAU,
158  .start_frame = vdpau_vc1_start_frame,
159  .end_frame = ff_vdpau_mpeg_end_frame,
160  .decode_slice = vdpau_vc1_decode_slice,
161  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
162  .init = vdpau_vc1_init,
163  .uninit = ff_vdpau_common_uninit,
164  .priv_data_size = sizeof(VDPAUContext),
165 };
const char const char void * val
Definition: avisynth_c.h:634
const char * s
Definition: avisynth_c.h:631
The VC1 Context.
Definition: vc1.h:173
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
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:266
int extended_mv
Ext MV in P/B (not in Simple)
Definition: vc1.h:223
int broadcast
TFF/RFF present.
Definition: vc1.h:200
uint8_t rangeredfrm
Frame decoding info for S/M profiles only.
Definition: vc1.h:302
Public libavcodec VDPAU header.
int fastuvmc
Rounding of qpel vector to hpel ? (not in Simple)
Definition: vc1.h:222
int profile
profile
Definition: avcodec.h:3028
int bi_type
Definition: vc1.h:381
int ff_vdpau_common_uninit(AVCodecContext *avctx)
Definition: vdpau.c:228
uint8_t
int panscanflag
NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} present.
Definition: vc1.h:203
int interlace
Progressive/interlaced (RPTFTM syntax element)
Definition: vc1.h:201
int refdist_flag
REFDIST syntax element present in II, IP, PI or PP field picture headers.
Definition: vc1.h:204
ptrdiff_t size
Definition: opengl_enc.c:101
int psf
Progressive Segmented Frame.
Definition: vc1.h:211
int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, int level)
Definition: vdpau.c:115
int overlap
overlapped transforms in use
Definition: vc1.h:226
#define AVERROR(e)
Definition: error.h:43
int resync_marker
could this stream contain resync markers
Definition: vc1.h:396
int postprocflag
Per-frame processing suggestion flag present.
Definition: vc1.h:199
static int vdpau_vc1_init(AVCodecContext *avctx)
Definition: vdpau_vc1.c:116
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:3503
int tfcntrflag
TFCNTR present.
Definition: vc1.h:202
static int vdpau_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_vc1.c:31
#define FF_PROFILE_VC1_MAIN
Definition: avcodec.h:3075
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:181
Picture.
Definition: mpegpicture.h:45
void * hwaccel_picture_private
Hardware accelerator private data.
Definition: mpegpicture.h:77
int level
level
Definition: avcodec.h:3117
uint8_t range_mapuv_flag
Definition: vc1.h:329
#define FF_PROFILE_VC1_SIMPLE
Definition: avcodec.h:3074
int rangered
RANGEREDFRM (range reduction) syntax element present at frame level.
Definition: vc1.h:189
int finterpflag
INTERPFRM present.
Definition: vc1.h:228
AVHWAccel ff_vc1_vdpau_hwaccel
Definition: vdpau_vc1.c:153
Libavcodec external API header.
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
int multires
frame-level RESPIC syntax element present
Definition: vc1.h:186
main external API structure.
Definition: avcodec.h:1532
uint8_t range_mapy
Definition: vc1.h:330
int extended_dmv
Additional extended dmv range at P/B frame-level.
Definition: vc1.h:205
struct AVFrame * f
Definition: mpegpicture.h:46
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:209
int quantizer_mode
2bits, quantizer mode used for sequence, see QUANT_*
Definition: vc1.h:227
int max_b_frames
max number of b-frames for encoding
Definition: mpegvideo.h:112
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:209
mfxU16 profile
Definition: qsvenc.c:42
int vstransform
variable-size [48]x[48] transform type + info
Definition: vc1.h:225
uint8_t range_mapuv
Definition: vc1.h:331
static int vdpau_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_vc1.c:99
MpegEncContext s
Definition: vc1.h:174
MpegEncContext.
Definition: mpegvideo.h:78
Picture * next_picture_ptr
pointer to the next picture (for bidir pred)
Definition: mpegvideo.h:180
uint8_t pq
Definition: vc1.h:238
int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, const uint8_t *buf, uint32_t size)
Definition: vdpau.c:339
enum FrameCodingMode fcm
Frame decoding info for Advanced profile.
Definition: vc1.h:308
Picture last_picture
copy of the previous picture structure.
Definition: mpegvideo.h:159
Picture * last_picture_ptr
pointer to the previous picture.
Definition: mpegvideo.h:179
Bi-dir predicted.
Definition: avutil.h:268
void * priv_data
Definition: avcodec.h:1574
#define FF_PROFILE_VC1_ADVANCED
Definition: avcodec.h:3077
Picture next_picture
copy of the next picture structure.
Definition: mpegvideo.h:165
uint8_t range_mapy_flag
Definition: vc1.h:328
int dquant
How qscale varies with MBs, 2bits (not in Simple)
Definition: vc1.h:224
Predicted.
Definition: avutil.h:267
GLuint buffer
Definition: opengl_enc.c:102
static uintptr_t ff_vdpau_get_surface_id(AVFrame *pic)
Extract VdpVideoSurface from an AVFrame.