FFmpeg
nvdec_vp8.c
Go to the documentation of this file.
1 /*
2  * VP8 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 "hwaccel_internal.h"
27 #include "internal.h"
28 #include "vp8.h"
29 
30 static unsigned char safe_get_ref_idx(VP8Frame *frame)
31 {
32  return frame ? ff_nvdec_get_ref_idx(frame->tf.f) : 255;
33 }
34 
35 static int nvdec_vp8_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
36 {
37  VP8Context *h = avctx->priv_data;
38 
40  CUVIDPICPARAMS *pp = &ctx->pic_params;
41  FrameDecodeData *fdd;
42  NVDECFrame *cf;
43  AVFrame *cur_frame = h->framep[VP8_FRAME_CURRENT]->tf.f;
44 
45  int ret;
46 
47  ret = ff_nvdec_start_frame(avctx, cur_frame);
48  if (ret < 0)
49  return ret;
50 
51  fdd = (FrameDecodeData*)cur_frame->private_ref->data;
52  cf = (NVDECFrame*)fdd->hwaccel_priv;
53 
54  *pp = (CUVIDPICPARAMS) {
55  .PicWidthInMbs = (cur_frame->width + 15) / 16,
56  .FrameHeightInMbs = (cur_frame->height + 15) / 16,
57  .CurrPicIdx = cf->idx,
58 
59  .CodecSpecific.vp8 = {
60  .width = cur_frame->width,
61  .height = cur_frame->height,
62 
63  .first_partition_size = h->header_partition_size,
64 
65  .LastRefIdx = safe_get_ref_idx(h->framep[VP8_FRAME_PREVIOUS]),
66  .GoldenRefIdx = safe_get_ref_idx(h->framep[VP8_FRAME_GOLDEN]),
67  .AltRefIdx = safe_get_ref_idx(h->framep[VP8_FRAME_ALTREF]),
68  /*
69  * Explicit braces for anonymous inners and unnamed fields
70  * to work around limitations in ancient versions of gcc.
71  */
72  { // union
73  { // struct
74  !h->keyframe, // frame_type
75  h->profile, // version
76  !h->invisible, // show_frame
77  h->segmentation.enabled ? // update_mb_segmentation_data
78  h->segmentation.update_feature_data : 0,
79  }
80  }
81  }
82  };
83 
84  return 0;
85 }
86 
88  AVBufferRef *hw_frames_ctx)
89 {
90  // VP8 uses a fixed size pool of 3 possible reference frames
91  return ff_nvdec_frame_params(avctx, hw_frames_ctx, 3, 0);
92 }
93 
95  .p.name = "vp8_nvdec",
96  .p.type = AVMEDIA_TYPE_VIDEO,
97  .p.id = AV_CODEC_ID_VP8,
98  .p.pix_fmt = AV_PIX_FMT_CUDA,
99  .start_frame = nvdec_vp8_start_frame,
100  .end_frame = ff_nvdec_simple_end_frame,
101  .decode_slice = ff_nvdec_simple_decode_slice,
102  .frame_params = nvdec_vp8_frame_params,
103  .init = ff_nvdec_decode_init,
104  .uninit = ff_nvdec_decode_uninit,
105  .priv_data_size = sizeof(NVDECContext),
106 };
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
VP8_FRAME_CURRENT
@ VP8_FRAME_CURRENT
Definition: vp8.h:44
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
ff_nvdec_get_ref_idx
int ff_nvdec_get_ref_idx(AVFrame *frame)
Definition: nvdec.c:744
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:340
AVFrame::width
int width
Definition: frame.h:412
internal.h
VP8_FRAME_ALTREF
@ VP8_FRAME_ALTREF
Definition: vp8.h:47
FFHWAccel
Definition: hwaccel_internal.h:34
ff_nvdec_start_frame
int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: nvdec.c:560
NVDECFrame
Definition: nvdec.h:44
ctx
AVFormatContext * ctx
Definition: movenc.c:48
decode.h
nvdec_vp8_frame_params
static int nvdec_vp8_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: nvdec_vp8.c:87
frame
static AVFrame * frame
Definition: demux_decode.c:54
ff_nvdec_simple_end_frame
int ff_nvdec_simple_end_frame(AVCodecContext *avctx)
Definition: nvdec.c:662
hwaccel_internal.h
ff_nvdec_decode_init
int ff_nvdec_decode_init(AVCodecContext *avctx)
Definition: nvdec.c:326
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:480
VP8Frame
Definition: vp8.h:152
vp8.h
VP8_FRAME_GOLDEN
@ VP8_FRAME_GOLDEN
Definition: vp8.h:46
AVCodecInternal::hwaccel_priv_data
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:121
NVDECFrame::idx
unsigned int idx
Definition: nvdec.h:45
size
int size
Definition: twinvq_data.h:10344
nvdec.h
ff_nvdec_decode_uninit
int ff_nvdec_decode_uninit(AVCodecContext *avctx)
Definition: nvdec.c:258
AVFrame::private_ref
AVBufferRef * private_ref
AVBufferRef for internal use by a single libav* library.
Definition: frame.h:797
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2139
avcodec.h
ret
ret
Definition: filter_design.txt:187
safe_get_ref_idx
static unsigned char safe_get_ref_idx(VP8Frame *frame)
Definition: nvdec_vp8.c:30
AVCodecContext
main external API structure.
Definition: avcodec.h:445
AVFrame::height
int height
Definition: frame.h:412
ff_nvdec_simple_decode_slice
int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec.c:670
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:692
nvdec_vp8_start_frame
static int nvdec_vp8_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec_vp8.c:35
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
VP8Context
Definition: vp8.h:160
ff_vp8_nvdec_hwaccel
const FFHWAccel ff_vp8_nvdec_hwaccel
Definition: nvdec_vp8.c:94
FrameDecodeData::hwaccel_priv
void * hwaccel_priv
Per-frame private data for hwaccels.
Definition: decode.h:51
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
h
h
Definition: vp9dsp_template.c:2038
NVDECContext
Definition: nvdec.h:52
VP8_FRAME_PREVIOUS
@ VP8_FRAME_PREVIOUS
Definition: vp8.h:45