FFmpeg  4.4.4
vdpau_mpeg4.c
Go to the documentation of this file.
1 /*
2  * MPEG-4 Part 2 / H.263 decode acceleration through VDPAU
3  *
4  * Copyright (c) 2008 NVIDIA
5  * Copyright (c) 2013 RĂ©mi Denis-Courmont
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <vdpau/vdpau.h>
25 
26 #include "avcodec.h"
27 #include "hwconfig.h"
28 #include "mpeg4video.h"
29 #include "vdpau.h"
30 #include "vdpau_internal.h"
31 
33  const uint8_t *buffer, uint32_t size)
34 {
35  Mpeg4DecContext *ctx = avctx->priv_data;
36  MpegEncContext * const s = &ctx->m;
37  Picture *pic = s->current_picture_ptr;
38  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
39  VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4;
40  VdpVideoSurface ref;
41  int i;
42 
43  /* fill VdpPictureInfoMPEG4Part2 struct */
44  info->forward_reference = VDP_INVALID_HANDLE;
45  info->backward_reference = VDP_INVALID_HANDLE;
46  info->vop_coding_type = 0;
47 
48  switch (s->pict_type) {
49  case AV_PICTURE_TYPE_B:
50  ref = ff_vdpau_get_surface_id(s->next_picture.f);
51  assert(ref != VDP_INVALID_HANDLE);
52  info->backward_reference = ref;
53  info->vop_coding_type = 2;
54  /* fall-through */
55  case AV_PICTURE_TYPE_P:
56  ref = ff_vdpau_get_surface_id(s->last_picture.f);
57  assert(ref != VDP_INVALID_HANDLE);
58  info->forward_reference = ref;
59  }
60 
61  info->trd[0] = s->pp_time;
62  info->trb[0] = s->pb_time;
63  info->trd[1] = s->pp_field_time >> 1;
64  info->trb[1] = s->pb_field_time >> 1;
65  info->vop_time_increment_resolution = s->avctx->framerate.num;
66  info->vop_fcode_forward = s->f_code;
67  info->vop_fcode_backward = s->b_code;
68  info->resync_marker_disable = !ctx->resync_marker;
69  info->interlaced = !s->progressive_sequence;
70  info->quant_type = s->mpeg_quant;
71  info->quarter_sample = s->quarter_sample;
72  info->short_video_header = avctx->codec->id == AV_CODEC_ID_H263;
73  info->rounding_control = s->no_rounding;
74  info->alternate_vertical_scan_flag = s->alternate_scan;
75  info->top_field_first = s->top_field_first;
76  for (i = 0; i < 64; ++i) {
77  info->intra_quantizer_matrix[i] = s->intra_matrix[i];
78  info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
79  }
80 
82  return ff_vdpau_add_buffer(pic_ctx, buffer, size);
83 }
84 
86  av_unused const uint8_t *buffer,
87  av_unused uint32_t size)
88 {
89  return 0;
90 }
91 
92 static int vdpau_mpeg4_init(AVCodecContext *avctx)
93 {
94  VdpDecoderProfile profile;
95 
96  switch (avctx->profile) {
98  profile = VDP_DECODER_PROFILE_MPEG4_PART2_SP;
99  break;
100  // As any ASP decoder must be able to decode SP, this
101  // should be a safe fallback if profile is unknown/unspecified.
102  case FF_PROFILE_UNKNOWN:
104  profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
105  break;
106  default:
107  return AVERROR(ENOTSUP);
108  }
109 
110  return ff_vdpau_common_init(avctx, profile, avctx->level);
111 }
112 
114  .name = "mpeg4_vdpau",
115  .type = AVMEDIA_TYPE_VIDEO,
116  .id = AV_CODEC_ID_MPEG4,
117  .pix_fmt = AV_PIX_FMT_VDPAU,
118  .start_frame = vdpau_mpeg4_start_frame,
119  .end_frame = ff_vdpau_mpeg_end_frame,
120  .decode_slice = vdpau_mpeg4_decode_slice,
121  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
123  .uninit = ff_vdpau_common_uninit,
124  .frame_params = ff_vdpau_common_frame_params,
125  .priv_data_size = sizeof(VDPAUContext),
126  .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
127 };
#define av_unused
Definition: attributes.h:131
uint8_t
Libavcodec external API header.
#define FF_PROFILE_MPEG4_SIMPLE
Definition: avcodec.h:1918
#define FF_PROFILE_MPEG4_ADVANCED_SIMPLE
Definition: avcodec.h:1933
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:1859
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
#define s(width, name)
Definition: cbs_vp9.c:257
int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, int level)
Definition: vdpau.c:137
int ff_vdpau_common_start_frame(struct vdpau_picture_context *pic_ctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition: vdpau.c:326
int ff_vdpau_common_uninit(AVCodecContext *avctx)
Definition: vdpau.c:288
int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, const uint8_t *buf, uint32_t size)
Definition: vdpau.c:381
int ff_vdpau_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: vdpau.c:118
@ AV_CODEC_ID_H263
Definition: codec_id.h:53
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:61
#define AVERROR(e)
Definition: error.h:43
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:276
#define HWACCEL_CAP_ASYNC_SAFE
Definition: hwconfig.h:26
int i
Definition: input.c:407
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:197
mfxU16 profile
Definition: qsvenc.c:45
static char buffer[20]
Definition: seek.c:32
main external API structure.
Definition: avcodec.h:536
int level
level
Definition: avcodec.h:1984
const struct AVCodec * codec
Definition: avcodec.h:545
int profile
profile
Definition: avcodec.h:1858
void * priv_data
Definition: avcodec.h:563
enum AVCodecID id
Definition: codec.h:211
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2444
MpegEncContext.
Definition: mpegvideo.h:81
Picture.
Definition: mpegpicture.h:45
void * hwaccel_picture_private
Hardware accelerator private data.
Definition: mpegpicture.h:78
union VDPAUPictureInfo info
VDPAU picture information.
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
AVFormatContext * ctx
Definition: movenc.c:48
int size
VdpPictureInfoMPEG4Part2 mpeg4
Public libavcodec VDPAU header.
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
static uintptr_t ff_vdpau_get_surface_id(AVFrame *pic)
Extract VdpVideoSurface from an AVFrame.
static int vdpau_mpeg4_decode_slice(av_unused AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition: vdpau_mpeg4.c:85
const AVHWAccel ff_mpeg4_vdpau_hwaccel
Definition: vdpau_mpeg4.c:113
static int vdpau_mpeg4_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg4.c:32
static int vdpau_mpeg4_init(AVCodecContext *avctx)
Definition: vdpau_mpeg4.c:92