FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nvdec_mjpeg.c
Go to the documentation of this file.
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 "avcodec.h"
24 #include "internal.h"
25 #include "mjpegdec.h"
26 #include "nvdec.h"
27 #include "decode.h"
28 
29 static int nvdec_mjpeg_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
30 {
31  MJpegDecodeContext *s = avctx->priv_data;
32 
34  CUVIDPICPARAMS *pp = &ctx->pic_params;
35  FrameDecodeData *fdd;
36  NVDECFrame *cf;
37  AVFrame *cur_frame = s->picture;
38 
39  int ret;
40 
41  ret = ff_nvdec_start_frame(avctx, cur_frame);
42  if (ret < 0)
43  return ret;
44 
45  fdd = (FrameDecodeData*)cur_frame->private_ref->data;
46  cf = (NVDECFrame*)fdd->hwaccel_priv;
47 
48  *pp = (CUVIDPICPARAMS) {
49  .PicWidthInMbs = (cur_frame->width + 15) / 16,
50  .FrameHeightInMbs = (cur_frame->height + 15) / 16,
51  .CurrPicIdx = cf->idx,
52 
53  .intra_pic_flag = 1,
54  .ref_pic_flag = 0,
55  };
56 
57  return ff_nvdec_simple_decode_slice(avctx, buffer, size);
58 }
59 
60 static int nvdec_mjpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
61 {
62  return 0;
63 }
64 
66  AVBufferRef *hw_frames_ctx)
67 {
68  // Only need storage for the current frame
69  return ff_nvdec_frame_params(avctx, hw_frames_ctx, 1);
70 }
71 
72 #if CONFIG_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),
85 };
86 #endif
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
int ff_nvdec_simple_end_frame(AVCodecContext *avctx)
Definition: nvdec.c:537
static int nvdec_mjpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec_mjpeg.c:60
uint8_t
CUVIDPICPARAMS pic_params
Definition: nvdec.h:51
AVBufferRef * private_ref
AVBufferRef for internal use by a single libav* library.
Definition: frame.h:604
int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec.c:545
ptrdiff_t size
Definition: opengl_enc.c:101
int width
Definition: frame.h:284
int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: nvdec.c:461
unsigned int idx
Definition: nvdec.h:45
const AVHWAccel ff_mjpeg_nvdec_hwaccel
static int nvdec_mjpeg_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: nvdec_mjpeg.c:65
int ff_nvdec_decode_init(AVCodecContext *avctx)
Definition: nvdec.c:270
int ff_nvdec_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, int dpb_size)
Definition: nvdec.c:577
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:3598
AVFormatContext * ctx
Definition: movenc.c:48
#define s(width, name)
Definition: cbs_vp9.c:257
HW acceleration through CUDA.
Definition: pixfmt.h:235
Libavcodec external API header.
main external API structure.
Definition: avcodec.h:1533
int ff_nvdec_decode_uninit(AVCodecContext *avctx)
Definition: nvdec.c:252
uint8_t * data
The data buffer.
Definition: buffer.h:89
A reference to a data buffer.
Definition: buffer.h:81
This struct stores per-frame lavc-internal data and is attached to it via private_ref.
Definition: decode.h:34
common internal api header.
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:190
void * priv_data
Definition: avcodec.h:1560
AVFrame * picture
Definition: mjpegdec.h:99
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1568
int height
Definition: frame.h:284
void * hwaccel_priv
Per-frame private data for hwaccels.
Definition: decode.h:52
MJPEG decoder.
static int nvdec_mjpeg_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec_mjpeg.c:29
GLuint buffer
Definition: opengl_enc.c:102