• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * MJPEG 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 "internal.h"
27 #include "mjpegdec.h"
28 #include "nvdec.h"
29 #include "decode.h"
30 
nvdec_mjpeg_start_frame(AVCodecContext * avctx,const uint8_t * buffer,uint32_t size)31 static int nvdec_mjpeg_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
32 {
33     MJpegDecodeContext *s = avctx->priv_data;
34 
35     NVDECContext      *ctx = avctx->internal->hwaccel_priv_data;
36     CUVIDPICPARAMS     *pp = &ctx->pic_params;
37     FrameDecodeData *fdd;
38     NVDECFrame *cf;
39     AVFrame *cur_frame = s->picture;
40 
41     int ret;
42 
43     ret = ff_nvdec_start_frame(avctx, cur_frame);
44     if (ret < 0)
45         return ret;
46 
47     fdd = (FrameDecodeData*)cur_frame->private_ref->data;
48     cf  = (NVDECFrame*)fdd->hwaccel_priv;
49 
50     *pp = (CUVIDPICPARAMS) {
51         .PicWidthInMbs     = (cur_frame->width  + 15) / 16,
52         .FrameHeightInMbs  = (cur_frame->height + 15) / 16,
53         .CurrPicIdx        = cf->idx,
54 
55         .intra_pic_flag    = 1,
56         .ref_pic_flag      = 0,
57     };
58 
59     return ff_nvdec_simple_decode_slice(avctx, buffer, size);
60 }
61 
nvdec_mjpeg_decode_slice(AVCodecContext * avctx,const uint8_t * buffer,uint32_t size)62 static int nvdec_mjpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
63 {
64     return 0;
65 }
66 
nvdec_mjpeg_frame_params(AVCodecContext * avctx,AVBufferRef * hw_frames_ctx)67 static int nvdec_mjpeg_frame_params(AVCodecContext *avctx,
68                                   AVBufferRef *hw_frames_ctx)
69 {
70     // Only need storage for the current frame
71     return ff_nvdec_frame_params(avctx, hw_frames_ctx, 1, 0);
72 }
73 
74 #if CONFIG_MJPEG_NVDEC_HWACCEL
75 AVHWAccel ff_mjpeg_nvdec_hwaccel = {
76     .name                 = "mjpeg_nvdec",
77     .type                 = AVMEDIA_TYPE_VIDEO,
78     .id                   = AV_CODEC_ID_MJPEG,
79     .pix_fmt              = AV_PIX_FMT_CUDA,
80     .start_frame          = nvdec_mjpeg_start_frame,
81     .end_frame            = ff_nvdec_simple_end_frame,
82     .decode_slice         = nvdec_mjpeg_decode_slice,
83     .frame_params         = nvdec_mjpeg_frame_params,
84     .init                 = ff_nvdec_decode_init,
85     .uninit               = ff_nvdec_decode_uninit,
86     .priv_data_size       = sizeof(NVDECContext),
87 };
88 #endif
89