FFmpeg: libavcodec/nvdec_mpeg4.c Source File

FFmpeg
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 "avcodec.h"
24 #include "mpeg4video.h"
25 #include "nvdec.h"
26 #include "decode.h"
27 
28  static int nvdec_mpeg4_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
29 {
30  Mpeg4DecContext *m = avctx->priv_data;
31  MpegEncContext *s = &m->m;
32 
33  NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
34  CUVIDPICPARAMS *pp = &ctx->pic_params;
35  CUVIDMPEG4PICPARAMS *ppc = &pp->CodecSpecific.mpeg4;
36  FrameDecodeData *fdd;
37  NVDECFrame *cf;
38  AVFrame *cur_frame = s->current_picture.f;
39 
40  int ret, i;
41 
42  ret = ff_nvdec_start_frame(avctx, cur_frame);
43  if (ret < 0)
44  return ret;
45 
46  fdd = (FrameDecodeData*)cur_frame->private_ref->data;
47  cf = (NVDECFrame*)fdd->hwaccel_priv;
48 
49  *pp = (CUVIDPICPARAMS) {
50  .PicWidthInMbs = (cur_frame->width + 15) / 16,
51  .FrameHeightInMbs = (cur_frame->height + 15) / 16,
52  .CurrPicIdx = cf->idx,
53 
54  .intra_pic_flag = s->pict_type == AV_PICTURE_TYPE_I,
55  .ref_pic_flag = s->pict_type == AV_PICTURE_TYPE_I ||
56  s->pict_type == AV_PICTURE_TYPE_P ||
57  s->pict_type == AV_PICTURE_TYPE_S,
58 
59  .CodecSpecific.mpeg4 = {
60  .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_picture.f),
61  .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_picture.f),
62 
63  .video_object_layer_width = s->width,
64  .video_object_layer_height = s->height,
65  .vop_time_increment_bitcount = m->time_increment_bits,
66  .top_field_first = s->top_field_first,
67  .resync_marker_disable = !m->resync_marker,
68  .quant_type = s->mpeg_quant,
69  .quarter_sample = s->quarter_sample,
70  .short_video_header = avctx->codec->id == AV_CODEC_ID_H263,
71  .divx_flags = s->divx_packed ? 5 : 0,
72 
73  .vop_coding_type = s->pict_type - AV_PICTURE_TYPE_I,
74  .vop_coded = 1,
75  .vop_rounding_type = s->no_rounding,
76  .alternate_vertical_scan_flag = s->alternate_scan,
77  .interlaced = !s->progressive_sequence,
78  .vop_fcode_forward = s->f_code,
79  .vop_fcode_backward = s->b_code,
80  .trd = { s->pp_time, s->pp_field_time >> 1 },
81  .trb = { s->pb_time, s->pb_field_time >> 1 },
82 
83  .gmc_enabled = s->pict_type == AV_PICTURE_TYPE_S &&
84  m->vol_sprite_usage == GMC_SPRITE,
85  }
86  };
87 
88  for (i = 0; i < 64; ++i) {
89  ppc->QuantMatrixIntra[i] = s->intra_matrix[i];
90  ppc->QuantMatrixInter[i] = s->inter_matrix[i];
91  }
92 
93  // We need to pass the full frame buffer and not just the slice
94  return ff_nvdec_simple_decode_slice(avctx, buffer, size);
95 }
96 
97  static int nvdec_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
98 {
99  return 0;
100 }
101 
102  static int nvdec_mpeg4_frame_params(AVCodecContext *avctx,
103  AVBufferRef *hw_frames_ctx)
104 {
105  // Each frame can at most have one P and one B reference
106  return ff_nvdec_frame_params(avctx, hw_frames_ctx, 2);
107 }
108 
109  const AVHWAccel ff_mpeg4_nvdec_hwaccel = {
110  .name = "mpeg4_nvdec",
111  .type = AVMEDIA_TYPE_VIDEO,
112  .id = AV_CODEC_ID_MPEG4,
113  .pix_fmt = AV_PIX_FMT_CUDA,
114  .start_frame = nvdec_mpeg4_start_frame,
115  .end_frame = ff_nvdec_simple_end_frame,
116  .decode_slice = nvdec_mpeg4_decode_slice,
117  .frame_params = nvdec_mpeg4_frame_params,
118  .init = ff_nvdec_decode_init,
119  .uninit = ff_nvdec_decode_uninit,
120  .priv_data_size = sizeof(NVDECContext),
121 };
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:1527
s
const char * s
Definition: avisynth_c.h:768
AV_PICTURE_TYPE_S
S(GMC)-VOP MPEG-4.
Definition: avutil.h:277
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
Mpeg4DecContext::resync_marker
int resync_marker
could this stream contain resync markers
Definition: mpeg4video.h:89
MpegEncContext::mpeg_quant
int mpeg_quant
Definition: mpegvideo.h:410
ff_nvdec_simple_end_frame
int ff_nvdec_simple_end_frame(AVCodecContext *avctx)
Definition: nvdec.c:494
nvdec_mpeg4_frame_params
static int nvdec_mpeg4_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: nvdec_mpeg4.c:102
Mpeg4DecContext::vol_sprite_usage
int vol_sprite_usage
Definition: mpeg4video.h:78
NVDECFrame
Definition: nvdec.h:44
uint8_t
uint8_t
Definition: audio_convert.c:194
NVDECContext::pic_params
CUVIDPICPARAMS pic_params
Definition: nvdec.h:51
AVFrame::private_ref
AVBufferRef * private_ref
AVBufferRef for internal use by a single libav* library.
Definition: frame.h:596
ff_nvdec_simple_decode_slice
int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec.c:502
MpegEncContext::no_rounding
int no_rounding
apply no rounding to motion compensation (MPEG-4, msmpeg4, ...) for B-frames rounding mode is always ...
Definition: mpegvideo.h:284
MpegEncContext::current_picture
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:180
MpegEncContext::pp_time
uint16_t pp_time
time distance between the last 2 p,s,i frames
Definition: mpegvideo.h:392
size
ptrdiff_t size
Definition: opengl_enc.c:101
Mpeg4DecContext::m
MpegEncContext m
Definition: mpeg4video.h:73
AVCodec::id
enum AVCodecID id
Definition: avcodec.h:3422
AVFrame::width
int width
Definition: frame.h:276
nvdec_mpeg4_start_frame
static int nvdec_mpeg4_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec_mpeg4.c:28
ff_nvdec_start_frame
int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: nvdec.c:418
MpegEncContext::quarter_sample
int quarter_sample
1->qpel, 0->half pel ME/MC
Definition: mpegvideo.h:401
ff_mpeg4_nvdec_hwaccel
const AVHWAccel ff_mpeg4_nvdec_hwaccel
Definition: nvdec_mpeg4.c:109
NVDECFrame::idx
unsigned int idx
Definition: nvdec.h:45
ff_nvdec_decode_init
int ff_nvdec_decode_init(AVCodecContext *avctx)
Definition: nvdec.c:264
ff_nvdec_frame_params
int ff_nvdec_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, int dpb_size)
Definition: nvdec.c:524
AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
MpegEncContext::top_field_first
int top_field_first
Definition: mpegvideo.h:465
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:3582
MpegEncContext::alternate_scan
int alternate_scan
Definition: mpegvideo.h:470
ctx
AVFormatContext * ctx
Definition: movenc.c:48
nvdec_mpeg4_decode_slice
static int nvdec_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec_mpeg4.c:97
AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:231
MpegEncContext::inter_matrix
uint16_t inter_matrix[64]
Definition: mpegvideo.h:302
avcodec.h
Libavcodec external API header.
AVCodecContext
main external API structure.
Definition: avcodec.h:1518
ff_nvdec_decode_uninit
int ff_nvdec_decode_uninit(AVCodecContext *avctx)
Definition: nvdec.c:246
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:89
MpegEncContext::height
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:100
MpegEncContext::progressive_sequence
int progressive_sequence
Definition: mpegvideo.h:456
Picture::f
struct AVFrame * f
Definition: mpegpicture.h:46
MpegEncContext::f_code
int f_code
forward MV resolution
Definition: mpegvideo.h:238
MpegEncContext::pict_type
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:212
MpegEncContext::pb_field_time
uint16_t pb_field_time
like above, just for interlaced
Definition: mpegvideo.h:395
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:81
MpegEncContext::pp_field_time
uint16_t pp_field_time
Definition: mpegvideo.h:394
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:81
FrameDecodeData
This struct stores per-frame lavc-internal data and is attached to it via private_ref.
Definition: decode.h:34
ff_nvdec_get_ref_idx
int ff_nvdec_get_ref_idx(AVFrame *frame)
Definition: nvdec.c:570
MpegEncContext::divx_packed
int divx_packed
Definition: mpegvideo.h:414
AVCodecInternal::hwaccel_priv_data
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:190
MpegEncContext::last_picture
Picture last_picture
copy of the previous picture structure.
Definition: mpegvideo.h:162
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:1545
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1553
MpegEncContext::next_picture
Picture next_picture
copy of the next picture structure.
Definition: mpegvideo.h:168
AVFrame::height
int height
Definition: frame.h:276
MpegEncContext::intra_matrix
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
Definition: mpegvideo.h:300
Mpeg4DecContext::time_increment_bits
int time_increment_bits
number of bits to represent the fractional part of time
Definition: mpeg4video.h:76
FrameDecodeData::hwaccel_priv
void * hwaccel_priv
Per-frame private data for hwaccels.
Definition: decode.h:52
MpegEncContext::b_code
int b_code
backward MV resolution for B-frames (MPEG-4)
Definition: mpegvideo.h:239
AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
buffer
GLuint buffer
Definition: opengl_enc.c:102
MpegEncContext::pb_time
uint16_t pb_time
time distance between the last b and p,s,i frame
Definition: mpegvideo.h:393
GMC_SPRITE
#define GMC_SPRITE
Definition: mpeg4video.h:54

Generated on Sun May 13 2018 02:03:53 for FFmpeg by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /