FFmpeg
Loading...
Searching...
No Matches
nvdec_mpeg12.c
Go to the documentation of this file.
1/*
2 * MPEG-1/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 "hwaccel_internal.h"
27#include "internal.h"
28#include "mpegutils.h"
29#include "mpegvideo.h"
30#include "nvdec.h"
31#include "decode.h"
32
34 const AVBufferRef *buffer_ref,
35 const uint8_t *buffer, uint32_t size)
36{
37 MpegEncContext *s = avctx->priv_data;
38
40 CUVIDPICPARAMS *pp = &ctx->pic_params;
41 CUVIDMPEG2PICPARAMS *ppc = &pp->CodecSpecific.mpeg2;
42 FrameDecodeData *fdd;
43 NVDECFrame *cf;
44 AVFrame *cur_frame = s->cur_pic.ptr->f;
45
46 int ret, i;
47
48 ret = ff_nvdec_start_frame(avctx, cur_frame);
49 if (ret < 0)
50 return ret;
51
52 fdd = cur_frame->private_ref;
53 cf = (NVDECFrame*)fdd->hwaccel_priv;
54
55 *pp = (CUVIDPICPARAMS) {
56 .PicWidthInMbs = (cur_frame->width + 15) / 16,
57 .FrameHeightInMbs = (cur_frame->height + 15) / 16,
58 .CurrPicIdx = cf->idx,
59
60 .field_pic_flag = s->picture_structure != PICT_FRAME,
61 .bottom_field_flag = s->picture_structure == PICT_BOTTOM_FIELD,
62 .second_field = s->picture_structure != PICT_FRAME && !s->first_field,
63
64 .intra_pic_flag = s->pict_type == AV_PICTURE_TYPE_I,
65 .ref_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
66 s->pict_type == AV_PICTURE_TYPE_P,
67
68 .CodecSpecific.mpeg2 = {
69 .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_pic.ptr ? s->last_pic.ptr->f : NULL),
70 .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_pic.ptr ? s->next_pic.ptr->f : NULL),
71
72 .picture_coding_type = s->pict_type,
73 .full_pel_forward_vector = s->full_pel[0],
74 .full_pel_backward_vector = s->full_pel[1],
75 .f_code = { { s->mpeg_f_code[0][0],
76 s->mpeg_f_code[0][1] },
77 { s->mpeg_f_code[1][0],
78 s->mpeg_f_code[1][1] } },
79 .intra_dc_precision = s->intra_dc_precision,
80 .frame_pred_frame_dct = s->frame_pred_frame_dct,
81 .concealment_motion_vectors = s->concealment_motion_vectors,
82 .q_scale_type = s->q_scale_type,
83 .intra_vlc_format = s->intra_vlc_format,
84 .alternate_scan = s->alternate_scan,
85 .top_field_first = s->top_field_first,
86 }
87 };
88
89 for (i = 0; i < 64; ++i) {
90 int n = s->idsp.idct_permutation[i];
91 ppc->QuantMatrixIntra[i] = s->intra_matrix[n];
92 ppc->QuantMatrixInter[i] = s->inter_matrix[n];
93 }
94
95 return 0;
96}
97
99 AVBufferRef *hw_frames_ctx,
100 enum AVPixelFormat hw_format)
101{
102 // Each frame can at most have one P and one B reference
103 return ff_nvdec_frame_params(avctx, hw_frames_ctx, hw_format, 2, 0);
104}
105
106#if CONFIG_MPEG1_NVDEC_HWACCEL || CONFIG_MPEG2_NVDEC_HWACCEL
107static int nvdec_mpeg12_cuda_frame_params(AVCodecContext *avctx,
108 AVBufferRef *hw_frames_ctx)
109{
110 return nvdec_mpeg12_frame_params(avctx, hw_frames_ctx, AV_PIX_FMT_CUDA);
111}
112#endif
113
114#if CONFIG_MPEG2_NVDEC_HWACCEL
116 .p.name = "mpeg2_nvdec",
117 .p.type = AVMEDIA_TYPE_VIDEO,
119 .p.pix_fmt = AV_PIX_FMT_CUDA,
120 .start_frame = nvdec_mpeg12_start_frame,
121 .end_frame = ff_nvdec_simple_end_frame,
122 .decode_slice = ff_nvdec_simple_decode_slice,
123 .frame_params = nvdec_mpeg12_cuda_frame_params,
124 .init = ff_nvdec_decode_init,
125 .uninit = ff_nvdec_decode_uninit,
126 .priv_data_size = sizeof(NVDECContext),
127};
128#endif
129
130#if CONFIG_MPEG1_NVDEC_CUARRAY_HWACCEL || CONFIG_MPEG2_NVDEC_CUARRAY_HWACCEL
131static int nvdec_mpeg12_cuarray_frame_params(AVCodecContext *avctx,
132 AVBufferRef *hw_frames_ctx)
133{
134 return nvdec_mpeg12_frame_params(avctx, hw_frames_ctx, AV_PIX_FMT_CUARRAY);
135}
136#endif
137
138#if CONFIG_MPEG2_NVDEC_CUARRAY_HWACCEL
140 .p.name = "mpeg2_nvdec_cuarray",
141 .p.type = AVMEDIA_TYPE_VIDEO,
143 .p.pix_fmt = AV_PIX_FMT_CUARRAY,
144 .start_frame = nvdec_mpeg12_start_frame,
145 .end_frame = ff_nvdec_simple_end_frame,
146 .decode_slice = ff_nvdec_simple_decode_slice,
147 .frame_params = nvdec_mpeg12_cuarray_frame_params,
148 .init = ff_nvdec_decode_init,
149 .uninit = ff_nvdec_decode_uninit,
150 .priv_data_size = sizeof(NVDECContext),
151};
152#endif
153
154#if CONFIG_MPEG1_NVDEC_HWACCEL
156 .p.name = "mpeg1_nvdec",
157 .p.type = AVMEDIA_TYPE_VIDEO,
159 .p.pix_fmt = AV_PIX_FMT_CUDA,
160 .start_frame = nvdec_mpeg12_start_frame,
161 .end_frame = ff_nvdec_simple_end_frame,
162 .decode_slice = ff_nvdec_simple_decode_slice,
163 .frame_params = nvdec_mpeg12_cuda_frame_params,
164 .init = ff_nvdec_decode_init,
165 .uninit = ff_nvdec_decode_uninit,
166 .priv_data_size = sizeof(NVDECContext),
167};
168#endif
169
170#if CONFIG_MPEG1_NVDEC_CUARRAY_HWACCEL
172 .p.name = "mpeg1_nvdec_cuarray",
173 .p.type = AVMEDIA_TYPE_VIDEO,
175 .p.pix_fmt = AV_PIX_FMT_CUARRAY,
176 .start_frame = nvdec_mpeg12_start_frame,
177 .end_frame = ff_nvdec_simple_end_frame,
178 .decode_slice = ff_nvdec_simple_decode_slice,
179 .frame_params = nvdec_mpeg12_cuarray_frame_params,
180 .init = ff_nvdec_decode_init,
181 .uninit = ff_nvdec_decode_uninit,
182 .priv_data_size = sizeof(NVDECContext),
183};
184#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_MPEG1VIDEO
Definition codec_id.h:51
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition codec_id.h:52
@ 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
const struct FFHWAccel ff_mpeg2_nvdec_cuarray_hwaccel
const struct FFHWAccel ff_mpeg1_nvdec_cuarray_hwaccel
const struct FFHWAccel ff_mpeg1_nvdec_hwaccel
const struct FFHWAccel ff_mpeg2_nvdec_hwaccel
common internal api header.
#define PICT_BOTTOM_FIELD
Definition mpegutils.h:32
#define PICT_FRAME
Definition mpegutils.h:33
mpegvideo header.
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_mpeg12_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, enum AVPixelFormat hw_format)
static int nvdec_mpeg12_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, 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
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
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
MpegEncContext.
Definition mpegvideo.h:67
unsigned int idx
Definition nvdec.h:55
static char buffer[20]
Definition seek.c:32
int size