avformat/mpeg: demux ivtv captions
[ffmpeg.git] / libavcodec / nvdec_vp8.c
blobff3b3f259c044fc7c710b220d53c0f899ff0c8f6
1 /*
2 * VP8 HW decode acceleration through NVDEC
4 * Copyright (c) 2017 Philip Langdale
6 * This file is part of FFmpeg.
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.
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.
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
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"
30 static unsigned char safe_get_ref_idx(VP8Frame *frame)
32 return frame ? ff_nvdec_get_ref_idx(frame->tf.f) : 255;
35 static int nvdec_vp8_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
37 VP8Context *h = avctx->priv_data;
39 NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
40 CUVIDPICPARAMS *pp = &ctx->pic_params;
41 FrameDecodeData *fdd;
42 NVDECFrame *cf;
43 AVFrame *cur_frame = h->framep[VP8_FRAME_CURRENT]->tf.f;
45 int ret;
47 ret = ff_nvdec_start_frame(avctx, cur_frame);
48 if (ret < 0)
49 return ret;
51 fdd = (FrameDecodeData*)cur_frame->private_ref->data;
52 cf = (NVDECFrame*)fdd->hwaccel_priv;
54 *pp = (CUVIDPICPARAMS) {
55 .PicWidthInMbs = (cur_frame->width + 15) / 16,
56 .FrameHeightInMbs = (cur_frame->height + 15) / 16,
57 .CurrPicIdx = cf->idx,
59 .CodecSpecific.vp8 = {
60 .width = cur_frame->width,
61 .height = cur_frame->height,
63 .first_partition_size = h->header_partition_size,
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]),
69 * Explicit braces for anonymous inners and unnamed fields
70 * to work around limitations in ancient versions of gcc.
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,
84 return 0;
87 static int nvdec_vp8_frame_params(AVCodecContext *avctx,
88 AVBufferRef *hw_frames_ctx)
90 // VP8 uses a fixed size pool of 3 possible reference frames
91 return ff_nvdec_frame_params(avctx, hw_frames_ctx, 3, 0);
94 const FFHWAccel ff_vp8_nvdec_hwaccel = {
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),