FFmpeg
Loading...
Searching...
No Matches
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"
29#include "mpeg4videodec.h"
30#include "vdpau.h"
31#include "vdpau_internal.h"
32
34 const AVBufferRef *buffer_ref,
35 const uint8_t *buffer, uint32_t size)
36{
38 MPVContext *const s = &ctx->h.c;
39 MPVPicture *pic = s->cur_pic.ptr;
41 VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4;
42 VdpVideoSurface ref;
43 int i;
44
45 /* fill VdpPictureInfoMPEG4Part2 struct */
46 info->forward_reference = VDP_INVALID_HANDLE;
47 info->backward_reference = VDP_INVALID_HANDLE;
48 info->vop_coding_type = 0;
49
50 switch (s->pict_type) {
52 ref = ff_vdpau_get_surface_id(s->next_pic.ptr->f);
53 assert(ref != VDP_INVALID_HANDLE);
54 info->backward_reference = ref;
55 info->vop_coding_type = 2;
58 ref = ff_vdpau_get_surface_id(s->last_pic.ptr->f);
59 assert(ref != VDP_INVALID_HANDLE);
60 info->forward_reference = ref;
61 }
62
63 info->trd[0] = s->pp_time;
64 info->trb[0] = s->pb_time;
65 info->trd[1] = s->pp_field_time >> 1;
66 info->trb[1] = s->pb_field_time >> 1;
67 info->vop_time_increment_resolution = s->avctx->framerate.num;
68 info->vop_fcode_forward = ctx->f_code;
69 info->vop_fcode_backward = ctx->b_code;
70 info->resync_marker_disable = !ctx->resync_marker;
71 info->interlaced = !s->progressive_sequence;
72 info->quant_type = ctx->mpeg_quant;
73 info->quarter_sample = s->quarter_sample;
74 info->short_video_header = avctx->codec->id == AV_CODEC_ID_H263;
75 info->rounding_control = s->no_rounding;
76 info->alternate_vertical_scan_flag = s->alternate_scan;
77 info->top_field_first = s->top_field_first;
78 for (i = 0; i < 64; ++i) {
79 int n = s->idsp.idct_permutation[i];
80 info->intra_quantizer_matrix[i] = s->intra_matrix[n];
81 info->non_intra_quantizer_matrix[i] = s->inter_matrix[n];
82 }
83
85 return ff_vdpau_add_buffer(pic_ctx, buffer, size);
86}
87
89 av_unused const uint8_t *buffer,
90 av_unused uint32_t size)
91{
92 return 0;
93}
94
96{
97 VdpDecoderProfile profile;
98
99 switch (avctx->profile) {
101 profile = VDP_DECODER_PROFILE_MPEG4_PART2_SP;
102 break;
103 // As any ASP decoder must be able to decode SP, this
104 // should be a safe fallback if profile is unknown/unspecified.
107 profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
108 break;
109 default:
110 return AVERROR(ENOTSUP);
111 }
112
113 return ff_vdpau_common_init(avctx, profile, avctx->level);
114}
115
117 .p.name = "mpeg4_vdpau",
118 .p.type = AVMEDIA_TYPE_VIDEO,
119 .p.id = AV_CODEC_ID_MPEG4,
120 .p.pix_fmt = AV_PIX_FMT_VDPAU,
121 .start_frame = vdpau_mpeg4_start_frame,
122 .end_frame = ff_vdpau_mpeg_end_frame,
123 .decode_slice = vdpau_mpeg4_decode_slice,
124 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
126 .uninit = ff_vdpau_common_uninit,
127 .frame_params = ff_vdpau_common_frame_params,
128 .priv_data_size = sizeof(VDPAUContext),
129 .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
130};
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 AV_PROFILE_MPEG4_ADVANCED_SIMPLE
Definition defs.h:146
#define AV_PROFILE_UNKNOWN
Definition defs.h:65
#define AV_PROFILE_MPEG4_SIMPLE
Definition defs.h:131
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
av_cold int ff_vdpau_common_uninit(AVCodecContext *avctx)
Definition vdpau.c:278
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:316
av_cold int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, int level)
Definition vdpau.c:127
int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, const uint8_t *buf, uint32_t size)
Definition vdpau.c:373
int ff_vdpau_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition vdpau.c:108
@ AV_CODEC_ID_H263
Definition codec_id.h:54
@ AV_CODEC_ID_MPEG4
Definition codec_id.h:62
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition avutil.h:280
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
const struct FFHWAccel ff_mpeg4_vdpau_hwaccel
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#define av_unused
Definition attributes.h:164
#define av_cold
Definition attributes.h:117
int profile
Definition mxfenc.c:2299
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition pixfmt.h:194
A reference to a data buffer.
Definition buffer.h:82
main external API structure.
Definition avcodec.h:443
int level
Encoding level descriptor.
Definition avcodec.h:1646
const struct AVCodec * codec
Definition avcodec.h:452
int profile
profile
Definition avcodec.h:1636
void * priv_data
Definition avcodec.h:470
enum AVCodecID id
Definition codec.h:189
MPVPicture.
Definition mpegpicture.h:58
void * hwaccel_picture_private
RefStruct reference for hardware accelerator private data.
Definition mpegpicture.h:75
union VDPAUPictureInfo info
VDPAU picture information.
static int ref[MAX_W *MAX_W]
static AVFormatContext * ctx
Definition movenc.c:49
static char buffer[20]
Definition seek.c:32
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:88
static av_cold int vdpau_mpeg4_init(AVCodecContext *avctx)
Definition vdpau_mpeg4.c:95
static int vdpau_mpeg4_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, const uint8_t *buffer, uint32_t size)
Definition vdpau_mpeg4.c:33