FFmpeg
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 "config_components.h"
24 
25 #include "avcodec.h"
26 #include "hwaccel_internal.h"
27 #include "internal.h"
28 #include "nvdec.h"
29 #include "decode.h"
30 #include "vc1.h"
31 
32 static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
33 {
34  VC1Context *v = avctx->priv_data;
35  MpegEncContext *s = &v->s;
36 
38  CUVIDPICPARAMS *pp = &ctx->pic_params;
39  FrameDecodeData *fdd;
40  NVDECFrame *cf;
41  AVFrame *cur_frame = s->cur_pic.ptr->f;
42 
43  int ret;
44 
45  ret = ff_nvdec_start_frame(avctx, cur_frame);
46  if (ret < 0)
47  return ret;
48 
49  fdd = (FrameDecodeData*)cur_frame->private_ref->data;
50  cf = (NVDECFrame*)fdd->hwaccel_priv;
51 
52  *pp = (CUVIDPICPARAMS) {
53  .PicWidthInMbs = (cur_frame->width + 15) / 16,
54  .FrameHeightInMbs = (cur_frame->height + 15) / 16,
55  .CurrPicIdx = cf->idx,
56  .field_pic_flag = v->field_mode,
57  .bottom_field_flag = v->cur_field_type,
58  .second_field = v->second_field,
59 
60  .intra_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
61  s->pict_type == AV_PICTURE_TYPE_BI,
62  .ref_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
63  s->pict_type == AV_PICTURE_TYPE_P,
64 
65  .CodecSpecific.vc1 = {
66  .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_pic.ptr ? s->last_pic.ptr->f : NULL),
67  .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_pic.ptr ? s->next_pic.ptr->f : NULL),
68  .FrameWidth = cur_frame->width,
69  .FrameHeight = cur_frame->height,
70 
71  .intra_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
72  s->pict_type == AV_PICTURE_TYPE_BI,
73  .ref_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
74  s->pict_type == AV_PICTURE_TYPE_P,
75  .progressive_fcm = v->fcm == 0,
76 
77  .profile = v->profile,
78  .postprocflag = v->postprocflag,
79  .pulldown = v->broadcast,
80  .interlace = v->interlace,
81  .tfcntrflag = v->tfcntrflag,
82  .finterpflag = v->finterpflag,
83  .psf = v->psf,
84  .multires = v->multires,
85  .syncmarker = v->resync_marker,
86  .rangered = v->rangered,
87  .maxbframes = s->max_b_frames,
88 
89  .panscan_flag = v->panscanflag,
90  .refdist_flag = v->refdist_flag,
91  .extended_mv = v->extended_mv,
92  .dquant = v->dquant,
93  .vstransform = v->vstransform,
94  .loopfilter = v->s.loop_filter,
95  .fastuvmc = v->fastuvmc,
96  .overlap = v->overlap,
97  .quantizer = v->quantizer_mode,
98  .extended_dmv = v->extended_dmv,
99  .range_mapy_flag = v->range_mapy_flag,
100  .range_mapy = v->range_mapy,
101  .range_mapuv_flag = v->range_mapuv_flag,
102  .range_mapuv = v->range_mapuv,
103  .rangeredfrm = v->rangeredfrm,
104  }
105  };
106 
107  return 0;
108 }
109 
111  AVBufferRef *hw_frames_ctx)
112 {
113  // Each frame can at most have one P and one B reference
114  return ff_nvdec_frame_params(avctx, hw_frames_ctx, 2, 0);
115 }
116 
118  .p.name = "vc1_nvdec",
119  .p.type = AVMEDIA_TYPE_VIDEO,
120  .p.id = AV_CODEC_ID_VC1,
121  .p.pix_fmt = AV_PIX_FMT_CUDA,
122  .start_frame = nvdec_vc1_start_frame,
123  .end_frame = ff_nvdec_simple_end_frame,
124  .decode_slice = ff_nvdec_simple_decode_slice,
125  .frame_params = nvdec_vc1_frame_params,
126  .init = ff_nvdec_decode_init,
127  .uninit = ff_nvdec_decode_uninit,
128  .priv_data_size = sizeof(NVDECContext),
129 };
130 
131 #if CONFIG_WMV3_NVDEC_HWACCEL
133  .p.name = "wmv3_nvdec",
134  .p.type = AVMEDIA_TYPE_VIDEO,
135  .p.id = AV_CODEC_ID_WMV3,
136  .p.pix_fmt = AV_PIX_FMT_CUDA,
137  .start_frame = nvdec_vc1_start_frame,
138  .end_frame = ff_nvdec_simple_end_frame,
139  .decode_slice = ff_nvdec_simple_decode_slice,
140  .frame_params = nvdec_vc1_frame_params,
141  .init = ff_nvdec_decode_init,
142  .uninit = ff_nvdec_decode_uninit,
143  .priv_data_size = sizeof(NVDECContext),
144 };
145 #endif
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
VC1Context
The VC1 Context.
Definition: vc1.h:173
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
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
ff_wmv3_nvdec_hwaccel
const struct FFHWAccel ff_wmv3_nvdec_hwaccel
vc1.h
ff_nvdec_get_ref_idx
int ff_nvdec_get_ref_idx(AVFrame *frame)
Definition: nvdec.c:747
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
FrameDecodeData
This struct stores per-frame lavc-internal data and is attached to it via private_ref.
Definition: decode.h:33
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:403
AVFrame::width
int width
Definition: frame.h:475
internal.h
nvdec_vc1_frame_params
static int nvdec_vc1_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: nvdec_vc1.c:110
VC1Context::fastuvmc
int fastuvmc
Rounding of qpel vector to hpel ? (not in Simple)
Definition: vc1.h:220
FFHWAccel
Definition: hwaccel_internal.h:34
ff_nvdec_start_frame
int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: nvdec.c:561
VC1Context::multires
int multires
frame-level RESPIC syntax element present
Definition: vc1.h:184
VC1Context::dquant
int dquant
How qscale varies with MBs, 2 bits (not in Simple)
Definition: vc1.h:222
s
#define s(width, name)
Definition: cbs_vp9.c:198
VC1Context::range_mapuv_flag
uint8_t range_mapuv_flag
Definition: vc1.h:327
VC1Context::postprocflag
int postprocflag
Per-frame processing suggestion flag present.
Definition: vc1.h:197
VC1Context::rangered
int rangered
RANGEREDFRM (range reduction) syntax element present at frame level.
Definition: vc1.h:187
NVDECFrame
Definition: nvdec.h:44
MpegEncContext::loop_filter
int loop_filter
Definition: mpegvideo.h:370
ctx
AVFormatContext * ctx
Definition: movenc.c:49
decode.h
nvdec_vc1_start_frame
static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec_vc1.c:32
AV_CODEC_ID_WMV3
@ AV_CODEC_ID_WMV3
Definition: codec_id.h:123
ff_nvdec_simple_end_frame
int ff_nvdec_simple_end_frame(AVCodecContext *avctx)
Definition: nvdec.c:663
NULL
#define NULL
Definition: coverity.c:32
VC1Context::range_mapy_flag
uint8_t range_mapy_flag
Definition: vc1.h:326
hwaccel_internal.h
VC1Context::field_mode
int field_mode
1 for interlaced field pictures
Definition: vc1.h:350
VC1Context::panscanflag
int panscanflag
NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} present.
Definition: vc1.h:201
ff_nvdec_decode_init
int ff_nvdec_decode_init(AVCodecContext *avctx)
Definition: nvdec.c:327
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:486
VC1Context::range_mapuv
uint8_t range_mapuv
Definition: vc1.h:329
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
VC1Context::resync_marker
int resync_marker
could this stream contain resync markers
Definition: vc1.h:399
VC1Context::refdist_flag
int refdist_flag
REFDIST syntax element present in II, IP, PI or PP field picture headers.
Definition: vc1.h:202
AVCodecInternal::hwaccel_priv_data
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:130
NVDECFrame::idx
unsigned int idx
Definition: nvdec.h:45
size
int size
Definition: twinvq_data.h:10344
VC1Context::rangeredfrm
uint8_t rangeredfrm
Frame decoding info for S/M profiles only.
Definition: vc1.h:302
nvdec.h
VC1Context::tfcntrflag
int tfcntrflag
TFCNTR present.
Definition: vc1.h:200
ff_nvdec_decode_uninit
int ff_nvdec_decode_uninit(AVCodecContext *avctx)
Definition: nvdec.c:259
AVFrame::private_ref
AVBufferRef * private_ref
AVBufferRef for internal use by a single libav* library.
Definition: frame.h:799
VC1Context::cur_field_type
int cur_field_type
0: top, 1: bottom
Definition: vc1.h:360
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2121
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
avcodec.h
VC1Context::second_field
int second_field
Definition: vc1.h:352
ret
ret
Definition: filter_design.txt:187
ff_vc1_nvdec_hwaccel
const FFHWAccel ff_vc1_nvdec_hwaccel
Definition: nvdec_vc1.c:117
AVCodecContext
main external API structure.
Definition: avcodec.h:451
AVFrame::height
int height
Definition: frame.h:475
ff_nvdec_simple_decode_slice
int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec.c:673
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
ff_nvdec_frame_params
int ff_nvdec_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, int dpb_size, int supports_444)
Definition: nvdec.c:695
VC1Context::profile
int profile
Sequence header data for all Profiles TODO: choose between ints, uint8_ts and monobit flags.
Definition: vc1.h:216
VC1Context::vstransform
int vstransform
variable-size [48]x[48] transform type + info
Definition: vc1.h:223
VC1Context::fcm
enum FrameCodingMode fcm
Frame decoding info for Advanced profile.
Definition: vc1.h:308
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
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
VC1Context::broadcast
int broadcast
TFF/RFF present.
Definition: vc1.h:198
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
AV_PICTURE_TYPE_BI
@ AV_PICTURE_TYPE_BI
BI type.
Definition: avutil.h:285
VC1Context::finterpflag
int finterpflag
INTERPFRM present.
Definition: vc1.h:226
FrameDecodeData::hwaccel_priv
void * hwaccel_priv
Per-frame private data for hwaccels.
Definition: decode.h:51
VC1Context::quantizer_mode
int quantizer_mode
2 bits, quantizer mode used for sequence, see QUANT_*
Definition: vc1.h:225
NVDECContext
Definition: nvdec.h:52
VC1Context::range_mapy
uint8_t range_mapy
Definition: vc1.h:328
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:73
VC1Context::extended_dmv
int extended_dmv
Additional extended dmv range at P/B-frame-level.
Definition: vc1.h:203