FFmpeg
Loading...
Searching...
No Matches
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 "config_components.h"
24
25#include "avcodec.h"
26#include "nvdec.h"
27#include "decode.h"
28#include "hwaccel_internal.h"
29#include "internal.h"
30#include "vp8.h"
31
32static unsigned char safe_get_ref_idx(VP8Frame *frame)
33{
34 return frame ? ff_nvdec_get_ref_idx(frame->tf.f) : 255;
35}
36
38 const AVBufferRef *buffer_ref,
39 const uint8_t *buffer, uint32_t size)
40{
41 VP8Context *h = avctx->priv_data;
42
44 CUVIDPICPARAMS *pp = &ctx->pic_params;
45 FrameDecodeData *fdd;
46 NVDECFrame *cf;
47 AVFrame *cur_frame = h->framep[VP8_FRAME_CURRENT]->tf.f;
48
49 int ret;
50
51 ret = ff_nvdec_start_frame(avctx, cur_frame);
52 if (ret < 0)
53 return ret;
54
55 fdd = cur_frame->private_ref;
56 cf = (NVDECFrame*)fdd->hwaccel_priv;
57
58 *pp = (CUVIDPICPARAMS) {
59 .PicWidthInMbs = (cur_frame->width + 15) / 16,
60 .FrameHeightInMbs = (cur_frame->height + 15) / 16,
61 .CurrPicIdx = cf->idx,
62
63 .CodecSpecific.vp8 = {
64 .width = cur_frame->width,
65 .height = cur_frame->height,
66
67 .first_partition_size = h->header_partition_size,
68
69 .LastRefIdx = safe_get_ref_idx(h->framep[VP8_FRAME_PREVIOUS]),
70 .GoldenRefIdx = safe_get_ref_idx(h->framep[VP8_FRAME_GOLDEN]),
71 .AltRefIdx = safe_get_ref_idx(h->framep[VP8_FRAME_ALTREF]),
72 /*
73 * Explicit braces for anonymous inners and unnamed fields
74 * to work around limitations in ancient versions of gcc.
75 */
76 { // union
77 { // struct
78 !h->keyframe, // frame_type
79 h->profile, // version
80 !h->invisible, // show_frame
81 h->segmentation.enabled ? // update_mb_segmentation_data
82 h->segmentation.update_feature_data : 0,
83 }
84 }
85 }
86 };
87
88 return 0;
89}
90
92 AVBufferRef *hw_frames_ctx,
93 enum AVPixelFormat hw_format)
94{
95 // VP8 uses a fixed size pool of 3 possible reference frames
96 return ff_nvdec_frame_params(avctx, hw_frames_ctx, hw_format, 3, 0);
97}
98
99#if CONFIG_VP8_NVDEC_HWACCEL
100static int nvdec_vp8_cuda_frame_params(AVCodecContext *avctx,
101 AVBufferRef *hw_frames_ctx)
102{
103 return nvdec_vp8_frame_params(avctx, hw_frames_ctx, AV_PIX_FMT_CUDA);
104}
105
107 .p.name = "vp8_nvdec",
108 .p.type = AVMEDIA_TYPE_VIDEO,
109 .p.id = AV_CODEC_ID_VP8,
110 .p.pix_fmt = AV_PIX_FMT_CUDA,
111 .start_frame = nvdec_vp8_start_frame,
112 .end_frame = ff_nvdec_simple_end_frame,
113 .decode_slice = ff_nvdec_simple_decode_slice,
114 .frame_params = nvdec_vp8_cuda_frame_params,
115 .init = ff_nvdec_decode_init,
116 .uninit = ff_nvdec_decode_uninit,
117 .priv_data_size = sizeof(NVDECContext),
118};
119#endif
120
121#if CONFIG_VP8_NVDEC_CUARRAY_HWACCEL
122static int nvdec_vp8_cuarray_frame_params(AVCodecContext *avctx,
123 AVBufferRef *hw_frames_ctx)
124{
125 return nvdec_vp8_frame_params(avctx, hw_frames_ctx, AV_PIX_FMT_CUARRAY);
126}
127
129 .p.name = "vp8_nvdec_cuarray",
130 .p.type = AVMEDIA_TYPE_VIDEO,
131 .p.id = AV_CODEC_ID_VP8,
132 .p.pix_fmt = AV_PIX_FMT_CUARRAY,
133 .start_frame = nvdec_vp8_start_frame,
134 .end_frame = ff_nvdec_simple_end_frame,
135 .decode_slice = ff_nvdec_simple_decode_slice,
136 .frame_params = nvdec_vp8_cuarray_frame_params,
137 .init = ff_nvdec_decode_init,
138 .uninit = ff_nvdec_decode_uninit,
139 .priv_data_size = sizeof(NVDECContext),
140};
141#endif
Libavcodec external API header.
static AVFrame * frame
@ AV_CODEC_ID_VP8
Definition codec_id.h:190
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
const struct FFHWAccel ff_vp8_nvdec_cuarray_hwaccel
const struct FFHWAccel ff_vp8_nvdec_hwaccel
common internal api header.
int ff_nvdec_simple_end_frame(AVCodecContext *avctx)
Definition nvdec.c:1051
int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition nvdec.c:1061
int ff_nvdec_decode_init(AVCodecContext *avctx)
Definition nvdec.c:404
int ff_nvdec_get_ref_idx(AVFrame *frame)
Definition nvdec.c:1180
int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
Definition nvdec.c:946
int ff_nvdec_decode_uninit(AVCodecContext *avctx)
Definition nvdec.c:297
int ff_nvdec_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, enum AVPixelFormat hw_format, int dpb_size, int supports_444)
Definition nvdec.c:1083
static int nvdec_vp8_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, enum AVPixelFormat hw_format)
Definition nvdec_vp8.c:91
static unsigned char safe_get_ref_idx(VP8Frame *frame)
Definition nvdec_vp8.c:32
static int nvdec_vp8_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, const uint8_t *buffer, uint32_t size)
Definition nvdec_vp8.c:37
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition pixfmt.h:260
@ AV_PIX_FMT_CUARRAY
hardware decoding through openharmony
Definition pixfmt.h:506
A reference to a data buffer.
Definition buffer.h:82
main external API structure.
Definition avcodec.h:443
struct AVCodecInternal * internal
Private context used for internal data.
Definition avcodec.h:478
void * priv_data
Definition avcodec.h:470
void * hwaccel_priv_data
hwaccel-specific private data
Definition internal.h:130
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
int width
Definition frame.h:544
int height
Definition frame.h:544
void * private_ref
RefStruct reference for internal use by a single libav* library.
Definition frame.h:810
This struct stores per-frame lavc-internal data and is attached to it via private_ref.
Definition decode.h:33
void * hwaccel_priv
Definition decode.h:54
unsigned int idx
Definition nvdec.h:55
static AVFormatContext * ctx
Definition movenc.c:49
static char buffer[20]
Definition seek.c:32
int size
@ VP8_FRAME_CURRENT
Definition vp8.h:45
@ VP8_FRAME_GOLDEN
Definition vp8.h:47
@ VP8_FRAME_ALTREF
Definition vp8.h:48
@ VP8_FRAME_PREVIOUS
Definition vp8.h:46