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 "internal.h"
27 #include "vp8.h"
28 
29 static unsigned char safe_get_ref_idx(VP8Frame *frame)
30 {
31  return frame ? ff_nvdec_get_ref_idx(frame->tf.f) : 255;
32 }
33 
34 static int nvdec_vp8_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
35 {
36  VP8Context *h = avctx->priv_data;
37 
39  CUVIDPICPARAMS *pp = &ctx->pic_params;
40  FrameDecodeData *fdd;
41  NVDECFrame *cf;
42  AVFrame *cur_frame = h->framep[VP56_FRAME_CURRENT]->tf.f;
43 
44  int ret;
45 
46  ret = ff_nvdec_start_frame(avctx, cur_frame);
47  if (ret < 0)
48  return ret;
49 
50  fdd = (FrameDecodeData*)cur_frame->private_ref->data;
51  cf = (NVDECFrame*)fdd->hwaccel_priv;
52 
53  *pp = (CUVIDPICPARAMS) {
54  .PicWidthInMbs = (cur_frame->width + 15) / 16,
55  .FrameHeightInMbs = (cur_frame->height + 15) / 16,
56  .CurrPicIdx = cf->idx,
57 
58  .CodecSpecific.vp8 = {
59  .width = cur_frame->width,
60  .height = cur_frame->height,
61 
62  .first_partition_size = h->header_partition_size,
63 
64  .LastRefIdx = safe_get_ref_idx(h->framep[VP56_FRAME_PREVIOUS]),
65  .GoldenRefIdx = safe_get_ref_idx(h->framep[VP56_FRAME_GOLDEN]),
66  .AltRefIdx = safe_get_ref_idx(h->framep[VP56_FRAME_GOLDEN2]),
67  /*
68  * Explicit braces for anonymous inners and unnamed fields
69  * to work around limitations in ancient versions of gcc.
70  */
71  { // union
72  { // struct
73  !h->keyframe, // frame_type
74  h->profile, // version
75  !h->invisible, // show_frame
76  h->segmentation.enabled ? // update_mb_segmentation_data
77  h->segmentation.update_feature_data : 0,
78  }
79  }
80  }
81  };
82 
83  return 0;
84 }
85 
87  AVBufferRef *hw_frames_ctx)
88 {
89  // VP8 uses a fixed size pool of 3 possible reference frames
90  return ff_nvdec_frame_params(avctx, hw_frames_ctx, 3, 0);
91 }
92 
94  .name = "vp8_nvdec",
95  .type = AVMEDIA_TYPE_VIDEO,
96  .id = AV_CODEC_ID_VP8,
97  .pix_fmt = AV_PIX_FMT_CUDA,
98  .start_frame = nvdec_vp8_start_frame,
99  .end_frame = ff_nvdec_simple_end_frame,
100  .decode_slice = ff_nvdec_simple_decode_slice,
101  .frame_params = nvdec_vp8_frame_params,
102  .init = ff_nvdec_decode_init,
103  .uninit = ff_nvdec_decode_uninit,
104  .priv_data_size = sizeof(NVDECContext),
105 };
VP56_FRAME_GOLDEN2
@ VP56_FRAME_GOLDEN2
Definition: vp56.h:47
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:225
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:747
FrameDecodeData
This struct stores per-frame lavc-internal data and is attached to it via private_ref.
Definition: decode.h:34
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
AVFrame::width
int width
Definition: frame.h:361
internal.h
AVHWAccel
Definition: avcodec.h:2039
ff_nvdec_start_frame
int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: nvdec.c:559
ff_vp8_nvdec_hwaccel
AVHWAccel ff_vp8_nvdec_hwaccel
Definition: nvdec_vp8.c:93
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:86
ff_nvdec_simple_end_frame
int ff_nvdec_simple_end_frame(AVCodecContext *avctx)
Definition: nvdec.c:665
ff_nvdec_decode_init
int ff_nvdec_decode_init(AVCodecContext *avctx)
Definition: nvdec.c:330
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:418
VP8Frame
Definition: vp8.h:139
vp8.h
AVCodecInternal::hwaccel_priv_data
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:176
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:262
AVFrame::private_ref
AVBufferRef * private_ref
AVBufferRef for internal use by a single libav* library.
Definition: frame.h:647
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2045
VP56_FRAME_GOLDEN
@ VP56_FRAME_GOLDEN
Definition: vp56.h:46
avcodec.h
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
safe_get_ref_idx
static unsigned char safe_get_ref_idx(VP8Frame *frame)
Definition: nvdec_vp8.c:29
VP56_FRAME_CURRENT
@ VP56_FRAME_CURRENT
Definition: vp56.h:44
AVCodecContext
main external API structure.
Definition: avcodec.h:383
AVFrame::height
int height
Definition: frame.h:361
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
VP56_FRAME_PREVIOUS
@ VP56_FRAME_PREVIOUS
Definition: vp56.h:45
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
nvdec_vp8_start_frame
static int nvdec_vp8_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec_vp8.c:34
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:410
VP8Context
Definition: vp8.h:148
FrameDecodeData::hwaccel_priv
void * hwaccel_priv
Per-frame private data for hwaccels.
Definition: decode.h:52
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:190
h
h
Definition: vp9dsp_template.c:2038
NVDECContext
Definition: nvdec.h:52