FFmpeg
Loading...
Searching...
No Matches
nvdec_mpeg4.c
Go to the documentation of this file.
1/*
2 * MPEG-4 Part 2 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 "mpeg4videodec.h"
28#include "mpeg4videodefs.h"
29#include "nvdec.h"
30#include "decode.h"
31#include "hwaccel_internal.h"
32
34 const AVBufferRef *buffer_ref,
35 const uint8_t *buffer, uint32_t size)
36{
37 Mpeg4DecContext *m = avctx->priv_data;
38 MPVContext *const s = &m->h.c;
39
41 CUVIDPICPARAMS *pp = &ctx->pic_params;
42 CUVIDMPEG4PICPARAMS *ppc = &pp->CodecSpecific.mpeg4;
43 FrameDecodeData *fdd;
44 NVDECFrame *cf;
45 AVFrame *cur_frame = s->cur_pic.ptr->f;
46
47 int ret, i;
48
49 ret = ff_nvdec_start_frame(avctx, cur_frame);
50 if (ret < 0)
51 return ret;
52
53 fdd = cur_frame->private_ref;
54 cf = (NVDECFrame*)fdd->hwaccel_priv;
55
56 *pp = (CUVIDPICPARAMS) {
57 .PicWidthInMbs = (cur_frame->width + 15) / 16,
58 .FrameHeightInMbs = (cur_frame->height + 15) / 16,
59 .CurrPicIdx = cf->idx,
60
61 .intra_pic_flag = s->pict_type == AV_PICTURE_TYPE_I,
62 .ref_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
63 s->pict_type == AV_PICTURE_TYPE_P ||
64 s->pict_type == AV_PICTURE_TYPE_S,
65
66 .CodecSpecific.mpeg4 = {
67 .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_pic.ptr ? s->last_pic.ptr->f : NULL),
68 .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_pic.ptr ? s->next_pic.ptr->f : NULL),
69
70 .video_object_layer_width = s->width,
71 .video_object_layer_height = s->height,
72 .vop_time_increment_bitcount = m->time_increment_bits,
73 .top_field_first = s->top_field_first,
74 .resync_marker_disable = !m->resync_marker,
75 .quant_type = m->mpeg_quant,
76 .quarter_sample = s->quarter_sample,
77 .short_video_header = avctx->codec->id == AV_CODEC_ID_H263,
78 .divx_flags = m->h.divx_packed ? 5 : 0,
79
80 .vop_coding_type = s->pict_type - AV_PICTURE_TYPE_I,
81 .vop_coded = 1,
82 .vop_rounding_type = s->no_rounding,
83 .alternate_vertical_scan_flag = s->alternate_scan,
84 .interlaced = !s->progressive_sequence,
85 .vop_fcode_forward = m->f_code,
86 .vop_fcode_backward = m->b_code,
87 .trd = { s->pp_time, s->pp_field_time >> 1 },
88 .trb = { s->pb_time, s->pb_field_time >> 1 },
89
90 .gmc_enabled = s->pict_type == AV_PICTURE_TYPE_S &&
92 }
93 };
94
95 for (i = 0; i < 64; ++i) {
96 int n = s->idsp.idct_permutation[i];
97 ppc->QuantMatrixIntra[i] = s->intra_matrix[n];
98 ppc->QuantMatrixInter[i] = s->inter_matrix[n];
99 }
100
101 // We need to pass the full frame buffer and not just the slice
103}
104
105static int nvdec_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
106{
107 return 0;
108}
109
111 AVBufferRef *hw_frames_ctx,
112 enum AVPixelFormat hw_format)
113{
114 // Each frame can at most have one P and one B reference
115 return ff_nvdec_frame_params(avctx, hw_frames_ctx, hw_format, 2, 0);
116}
117
118#if CONFIG_MPEG4_NVDEC_HWACCEL
119static int nvdec_mpeg4_cuda_frame_params(AVCodecContext *avctx,
120 AVBufferRef *hw_frames_ctx)
121{
122 return nvdec_mpeg4_frame_params(avctx, hw_frames_ctx, AV_PIX_FMT_CUDA);
123}
124
126 .p.name = "mpeg4_nvdec",
127 .p.type = AVMEDIA_TYPE_VIDEO,
128 .p.id = AV_CODEC_ID_MPEG4,
129 .p.pix_fmt = AV_PIX_FMT_CUDA,
130 .start_frame = nvdec_mpeg4_start_frame,
131 .end_frame = ff_nvdec_simple_end_frame,
132 .decode_slice = nvdec_mpeg4_decode_slice,
133 .frame_params = nvdec_mpeg4_cuda_frame_params,
134 .init = ff_nvdec_decode_init,
135 .uninit = ff_nvdec_decode_uninit,
136 .priv_data_size = sizeof(NVDECContext),
137};
138#endif
139
140#if CONFIG_MPEG4_NVDEC_CUARRAY_HWACCEL
141static int nvdec_mpeg4_cuarray_frame_params(AVCodecContext *avctx,
142 AVBufferRef *hw_frames_ctx)
143{
144 return nvdec_mpeg4_frame_params(avctx, hw_frames_ctx, AV_PIX_FMT_CUARRAY);
145}
146
148 .p.name = "mpeg4_nvdec_cuarray",
149 .p.type = AVMEDIA_TYPE_VIDEO,
150 .p.id = AV_CODEC_ID_MPEG4,
151 .p.pix_fmt = AV_PIX_FMT_CUARRAY,
152 .start_frame = nvdec_mpeg4_start_frame,
153 .end_frame = ff_nvdec_simple_end_frame,
154 .decode_slice = nvdec_mpeg4_decode_slice,
155 .frame_params = nvdec_mpeg4_cuarray_frame_params,
156 .init = ff_nvdec_decode_init,
157 .uninit = ff_nvdec_decode_uninit,
158 .priv_data_size = sizeof(NVDECContext),
159};
160#endif
static AVFormatContext * ctx
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
@ AV_CODEC_ID_H263
Definition codec_id.h:54
@ AV_CODEC_ID_MPEG4
Definition codec_id.h:62
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
@ AV_PICTURE_TYPE_S
S(GMC)-VOP MPEG-4.
Definition avutil.h:281
const struct FFHWAccel ff_mpeg4_nvdec_hwaccel
const struct FFHWAccel ff_mpeg4_nvdec_cuarray_hwaccel
common internal api header.
#define GMC_SPRITE
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_mpeg4_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, enum AVPixelFormat hw_format)
static int nvdec_mpeg4_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, const uint8_t *buffer, uint32_t size)
Definition nvdec_mpeg4.c:33
static int nvdec_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
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
const struct AVCodec * codec
Definition avcodec.h:452
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
enum AVCodecID id
Definition codec.h:189
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
MPVContext c
Definition h263dec.h:44
int divx_packed
divx specific, used to workaround (many) bugs in divx5
Definition h263dec.h:75
int b_code
backward MV resolution for B-frames
int time_increment_bits
number of bits to represent the fractional part of time
H263DecContext h
int f_code
forward MV resolution
int resync_marker
could this stream contain resync markers
unsigned int idx
Definition nvdec.h:55
static char buffer[20]
Definition seek.c:32
int size