2 * MJPEG 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
29 static int nvdec_mjpeg_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
31 MJpegDecodeContext *s = avctx->priv_data;
33 NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
34 CUVIDPICPARAMS *pp = &ctx->pic_params;
37 AVFrame *cur_frame = s->picture;
41 ret = ff_nvdec_start_frame(avctx, cur_frame);
45 fdd = (FrameDecodeData*)cur_frame->private_ref->data;
46 cf = (NVDECFrame*)fdd->hwaccel_priv;
48 *pp = (CUVIDPICPARAMS) {
49 .PicWidthInMbs = (cur_frame->width + 15) / 16,
50 .FrameHeightInMbs = (cur_frame->height + 15) / 16,
51 .CurrPicIdx = cf->idx,
57 return ff_nvdec_simple_decode_slice(avctx, buffer, size);
60 static int nvdec_mjpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
65 static int nvdec_mjpeg_frame_params(AVCodecContext *avctx,
66 AVBufferRef *hw_frames_ctx)
68 // Only need storage for the current frame
69 return ff_nvdec_frame_params(avctx, hw_frames_ctx, 1);
72 #if CONFIG_MJPEG_NVDEC_HWACCEL
73 AVHWAccel ff_mjpeg_nvdec_hwaccel = {
74 .name = "mjpeg_nvdec",
75 .type = AVMEDIA_TYPE_VIDEO,
76 .id = AV_CODEC_ID_MJPEG,
77 .pix_fmt = AV_PIX_FMT_CUDA,
78 .start_frame = nvdec_mjpeg_start_frame,
79 .end_frame = ff_nvdec_simple_end_frame,
80 .decode_slice = nvdec_mjpeg_decode_slice,
81 .frame_params = nvdec_mjpeg_frame_params,
82 .init = ff_nvdec_decode_init,
83 .uninit = ff_nvdec_decode_uninit,
84 .priv_data_size = sizeof(NVDECContext),