FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nvdec_vc1.c
Go to the documentation of this file.
1 /*
2  * VC1 HW decode acceleration through NVDEC
3  *
4  * Copyright (c) 2017 Philip Langdale
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
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "avcodec.h"
24 #include "nvdec.h"
25 #include "decode.h"
26 #include "vc1.h"
27 
28 static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
29 {
30  VC1Context *v = avctx->priv_data;
31  MpegEncContext *s = &v->s;
32 
34  CUVIDPICPARAMS *pp = &ctx->pic_params;
35  FrameDecodeData *fdd;
36  NVDECFrame *cf;
37  AVFrame *cur_frame = s->current_picture.f;
38 
39  int ret;
40 
41  ret = ff_nvdec_start_frame(avctx, cur_frame);
42  if (ret < 0)
43  return ret;
44 
45  fdd = (FrameDecodeData*)cur_frame->private_ref->data;
46  cf = (NVDECFrame*)fdd->hwaccel_priv;
47 
48  *pp = (CUVIDPICPARAMS) {
49  .PicWidthInMbs = (cur_frame->width + 15) / 16,
50  .FrameHeightInMbs = (cur_frame->height + 15) / 16,
51  .CurrPicIdx = cf->idx,
52  .field_pic_flag = v->field_mode,
53  .bottom_field_flag = v->cur_field_type,
54  .second_field = v->second_field,
55 
56  .intra_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
58  .ref_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
60 
61  .CodecSpecific.vc1 = {
62  .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_picture.f),
63  .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_picture.f),
64  .FrameWidth = cur_frame->width,
65  .FrameHeight = cur_frame->height,
66 
67  .intra_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
69  .ref_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
71  .progressive_fcm = v->fcm == 0,
72 
73  .profile = v->profile,
74  .postprocflag = v->postprocflag,
75  .pulldown = v->broadcast,
76  .interlace = v->interlace,
77  .tfcntrflag = v->tfcntrflag,
78  .finterpflag = v->finterpflag,
79  .psf = v->psf,
80  .multires = v->multires,
81  .syncmarker = v->resync_marker,
82  .rangered = v->rangered,
83  .maxbframes = s->max_b_frames,
84 
85  .panscan_flag = v->panscanflag,
86  .refdist_flag = v->refdist_flag,
87  .extended_mv = v->extended_mv,
88  .dquant = v->dquant,
89  .vstransform = v->vstransform,
90  .loopfilter = v->s.loop_filter,
91  .fastuvmc = v->fastuvmc,
92  .overlap = v->overlap,
93  .quantizer = v->quantizer_mode,
94  .extended_dmv = v->extended_dmv,
95  .range_mapy_flag = v->range_mapy_flag,
96  .range_mapy = v->range_mapy,
97  .range_mapuv_flag = v->range_mapuv_flag,
98  .range_mapuv = v->range_mapuv,
99  .rangeredfrm = v->rangeredfrm,
100  }
101  };
102 
103  return 0;
104 }
105 
107  AVBufferRef *hw_frames_ctx)
108 {
109  // Each frame can at most have one P and one B reference
110  return ff_nvdec_frame_params(avctx, hw_frames_ctx, 2);
111 }
112 
114  .name = "vc1_nvdec",
115  .type = AVMEDIA_TYPE_VIDEO,
116  .id = AV_CODEC_ID_VC1,
117  .pix_fmt = AV_PIX_FMT_CUDA,
118  .start_frame = nvdec_vc1_start_frame,
119  .end_frame = ff_nvdec_simple_end_frame,
120  .decode_slice = ff_nvdec_simple_decode_slice,
121  .frame_params = nvdec_vc1_frame_params,
122  .init = ff_nvdec_decode_init,
123  .uninit = ff_nvdec_decode_uninit,
124  .priv_data_size = sizeof(NVDECContext),
125 };
126 
127 #if CONFIG_WMV3_NVDEC_HWACCEL
129  .name = "wmv3_nvdec",
130  .type = AVMEDIA_TYPE_VIDEO,
131  .id = AV_CODEC_ID_WMV3,
132  .pix_fmt = AV_PIX_FMT_CUDA,
133  .start_frame = nvdec_vc1_start_frame,
134  .end_frame = ff_nvdec_simple_end_frame,
135  .decode_slice = ff_nvdec_simple_decode_slice,
136  .frame_params = nvdec_vc1_frame_params,
137  .init = ff_nvdec_decode_init,
138  .uninit = ff_nvdec_decode_uninit,
139  .priv_data_size = sizeof(NVDECContext),
140 };
141 #endif
BI type.
Definition: avutil.h:280
const char * s
Definition: avisynth_c.h:768
The VC1 Context.
Definition: vc1.h:173
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
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:303
int ff_nvdec_simple_end_frame(AVCodecContext *avctx)
Definition: nvdec.c:494
int fastuvmc
Rounding of qpel vector to hpel ? (not in Simple)
Definition: vc1.h:222
static int nvdec_vc1_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: nvdec_vc1.c:106
const AVHWAccel ff_vc1_nvdec_hwaccel
Definition: nvdec_vc1.c:113
uint8_t
int panscanflag
NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} present.
Definition: vc1.h:203
CUVIDPICPARAMS pic_params
Definition: nvdec.h:51
int interlace
Progressive/interlaced (RPTFTM syntax element)
Definition: vc1.h:201
int second_field
Definition: vc1.h:355
AVBufferRef * private_ref
AVBufferRef for internal use by a single libav* library.
Definition: frame.h:596
int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec.c:502
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:180
int profile
Sequence header data for all Profiles TODO: choose between ints, uint8_ts and monobit flags...
Definition: vc1.h:218
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 width
Definition: frame.h:276
int overlap
overlapped transforms in use
Definition: vc1.h:226
int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: nvdec.c:418
const AVHWAccel ff_wmv3_nvdec_hwaccel
int resync_marker
could this stream contain resync markers
Definition: vc1.h:402
unsigned int idx
Definition: nvdec.h:45
int postprocflag
Per-frame processing suggestion flag present.
Definition: vc1.h:199
int ff_nvdec_decode_init(AVCodecContext *avctx)
Definition: nvdec.c:264
int cur_field_type
0: top, 1: bottom
Definition: vc1.h:363
int ff_nvdec_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, int dpb_size)
Definition: nvdec.c:524
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:3582
int tfcntrflag
TFCNTR present.
Definition: vc1.h:202
int field_mode
1 for interlaced field pictures
Definition: vc1.h:353
AVFormatContext * ctx
Definition: movenc.c:48
uint8_t range_mapuv_flag
Definition: vc1.h:330
HW acceleration through CUDA.
Definition: pixfmt.h:231
static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec_vc1.c:28
int rangered
RANGEREDFRM (range reduction) syntax element present at frame level.
Definition: vc1.h:189
int finterpflag
INTERPFRM present.
Definition: vc1.h:228
Libavcodec external API header.
int multires
frame-level RESPIC syntax element present
Definition: vc1.h:186
main external API structure.
Definition: avcodec.h:1518
int ff_nvdec_decode_uninit(AVCodecContext *avctx)
Definition: nvdec.c:246
uint8_t * data
The data buffer.
Definition: buffer.h:89
uint8_t range_mapy
Definition: vc1.h:331
int extended_dmv
Additional extended dmv range at P/B-frame-level.
Definition: vc1.h:205
struct AVFrame * f
Definition: mpegpicture.h:46
int quantizer_mode
2 bits, 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:115
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:212
int vstransform
variable-size [48]x[48] transform type + info
Definition: vc1.h:225
uint8_t range_mapuv
Definition: vc1.h:332
MpegEncContext s
Definition: vc1.h:174
MpegEncContext.
Definition: mpegvideo.h:81
A reference to a data buffer.
Definition: buffer.h:81
This struct stores per-frame lavc-internal data and is attached to it via private_ref.
Definition: decode.h:34
int ff_nvdec_get_ref_idx(AVFrame *frame)
Definition: nvdec.c:570
enum FrameCodingMode fcm
Frame decoding info for Advanced profile.
Definition: vc1.h:309
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:190
Picture last_picture
copy of the previous picture structure.
Definition: mpegvideo.h:162
void * priv_data
Definition: avcodec.h:1545
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1553
Picture next_picture
copy of the next picture structure.
Definition: mpegvideo.h:168
int height
Definition: frame.h:276
uint8_t range_mapy_flag
Definition: vc1.h:329
int dquant
How qscale varies with MBs, 2 bits (not in Simple)
Definition: vc1.h:224
void * hwaccel_priv
Per-frame private data for hwaccels.
Definition: decode.h:52
Predicted.
Definition: avutil.h:275
GLuint buffer
Definition: opengl_enc.c:102