FFmpeg
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 "hwaccel_internal.h"
28 #include "mpeg4videodec.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  MPVPicture *pic = s->cur_pic.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_pic.ptr->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_pic.ptr->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  int n = s->idsp.idct_permutation[i];
78  info->intra_quantizer_matrix[i] = s->intra_matrix[n];
79  info->non_intra_quantizer_matrix[i] = s->inter_matrix[n];
80  }
81 
83  return ff_vdpau_add_buffer(pic_ctx, buffer, size);
84 }
85 
87  av_unused const uint8_t *buffer,
88  av_unused uint32_t size)
89 {
90  return 0;
91 }
92 
93 static int vdpau_mpeg4_init(AVCodecContext *avctx)
94 {
95  VdpDecoderProfile profile;
96 
97  switch (avctx->profile) {
99  profile = VDP_DECODER_PROFILE_MPEG4_PART2_SP;
100  break;
101  // As any ASP decoder must be able to decode SP, this
102  // should be a safe fallback if profile is unknown/unspecified.
103  case AV_PROFILE_UNKNOWN:
105  profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
106  break;
107  default:
108  return AVERROR(ENOTSUP);
109  }
110 
111  return ff_vdpau_common_init(avctx, profile, avctx->level);
112 }
113 
115  .p.name = "mpeg4_vdpau",
116  .p.type = AVMEDIA_TYPE_VIDEO,
117  .p.id = AV_CODEC_ID_MPEG4,
118  .p.pix_fmt = AV_PIX_FMT_VDPAU,
119  .start_frame = vdpau_mpeg4_start_frame,
120  .end_frame = ff_vdpau_mpeg_end_frame,
121  .decode_slice = vdpau_mpeg4_decode_slice,
122  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
124  .uninit = ff_vdpau_common_uninit,
125  .frame_params = ff_vdpau_common_frame_params,
126  .priv_data_size = sizeof(VDPAUContext),
127  .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
128 };
ff_vdpau_common_frame_params
int ff_vdpau_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: vdpau.c:123
AV_PROFILE_MPEG4_ADVANCED_SIMPLE
#define AV_PROFILE_MPEG4_ADVANCED_SIMPLE
Definition: defs.h:146
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
mpeg4videodec.h
av_unused
#define av_unused
Definition: attributes.h:131
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
ff_mpeg4_vdpau_hwaccel
const FFHWAccel ff_mpeg4_vdpau_hwaccel
Definition: vdpau_mpeg4.c:114
vdpau_mpeg4_decode_slice
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:86
vdpau_internal.h
vdpau_picture_context
Definition: vdpau_internal.h:98
FFHWAccel
Definition: hwaccel_internal.h:34
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:460
ff_vdpau_add_buffer
int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, const uint8_t *buf, uint32_t size)
Definition: vdpau.c:386
ff_vdpau_common_init
int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, int level)
Definition: vdpau.c:142
vdpau.h
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
s
#define s(width, name)
Definition: cbs_vp9.c:198
info
MIPS optimizations info
Definition: mips.txt:2
ctx
AVFormatContext * ctx
Definition: movenc.c:49
ff_vdpau_common_start_frame
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:331
ff_vdpau_get_surface_id
static uintptr_t ff_vdpau_get_surface_id(AVFrame *pic)
Extract VdpVideoSurface from an AVFrame.
Definition: vdpau_internal.h:38
HWACCEL_CAP_ASYNC_SAFE
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
Definition: hwaccel_internal.h:31
hwaccel_internal.h
Mpeg4DecContext
Definition: mpeg4videodec.h:34
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1794
ff_vdpau_common_uninit
int ff_vdpau_common_uninit(AVCodecContext *avctx)
Definition: vdpau.c:293
VDPAUContext
Definition: vdpau_internal.h:73
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_ID_H263
@ AV_CODEC_ID_H263
Definition: codec_id.h:56
VDPAUPictureInfo::mpeg4
VdpPictureInfoMPEG4Part2 mpeg4
Definition: vdpau_internal.h:47
size
int size
Definition: twinvq_data.h:10344
vdpau_mpeg4_start_frame
static int vdpau_mpeg4_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg4.c:32
ff_vdpau_mpeg_end_frame
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
AVCodec::id
enum AVCodecID id
Definition: codec.h:201
AV_PIX_FMT_VDPAU
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:194
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2105
AV_PROFILE_MPEG4_SIMPLE
#define AV_PROFILE_MPEG4_SIMPLE
Definition: defs.h:131
MPVPicture::hwaccel_picture_private
void * hwaccel_picture_private
RefStruct reference for hardware accelerator private data.
Definition: mpegpicture.h:75
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
profile
int profile
Definition: mxfenc.c:2233
avcodec.h
AVCodecContext
main external API structure.
Definition: avcodec.h:451
vdpau_picture_context::info
union VDPAUPictureInfo info
VDPAU picture information.
Definition: vdpau_internal.h:102
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:281
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1650
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:280
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
MPVPicture
MPVPicture.
Definition: mpegpicture.h:58
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:73
vdpau_mpeg4_init
static int vdpau_mpeg4_init(AVCodecContext *avctx)
Definition: vdpau_mpeg4.c:93