FFmpeg
vdpau_mpeg12.c
Go to the documentation of this file.
1 /*
2  * MPEG-1/2 HW 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 "config_components.h"
25 
26 #include <vdpau/vdpau.h>
27 
28 #include "avcodec.h"
29 #include "hwaccel_internal.h"
30 #include "mpegvideo.h"
31 #include "vdpau.h"
32 #include "vdpau_internal.h"
33 
35  const uint8_t *buffer, uint32_t size)
36 {
37  MpegEncContext * const s = avctx->priv_data;
38  MPVPicture *pic = s->cur_pic.ptr;
39  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
40  VdpPictureInfoMPEG1Or2 *info = &pic_ctx->info.mpeg;
41  VdpVideoSurface ref;
42  int i;
43 
44  /* fill VdpPictureInfoMPEG1Or2 struct */
45  info->forward_reference = VDP_INVALID_HANDLE;
46  info->backward_reference = VDP_INVALID_HANDLE;
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  /* fall through to forward prediction */
54  case AV_PICTURE_TYPE_P:
55  ref = ff_vdpau_get_surface_id(s->last_pic.ptr->f);
56  info->forward_reference = ref;
57  }
58 
59  info->slice_count = 0;
60  info->picture_structure = s->picture_structure;
61  info->picture_coding_type = s->pict_type;
62  info->intra_dc_precision = s->intra_dc_precision;
63  info->frame_pred_frame_dct = s->frame_pred_frame_dct;
64  info->concealment_motion_vectors = s->concealment_motion_vectors;
65  info->intra_vlc_format = s->intra_vlc_format;
66  info->alternate_scan = s->alternate_scan;
67  info->q_scale_type = s->q_scale_type;
68  info->top_field_first = s->top_field_first;
69  // Both for MPEG-1 only, zero for MPEG-2:
70  info->full_pel_forward_vector = s->full_pel[0];
71  info->full_pel_backward_vector = s->full_pel[1];
72  // For MPEG-1 fill both horizontal & vertical:
73  info->f_code[0][0] = s->mpeg_f_code[0][0];
74  info->f_code[0][1] = s->mpeg_f_code[0][1];
75  info->f_code[1][0] = s->mpeg_f_code[1][0];
76  info->f_code[1][1] = s->mpeg_f_code[1][1];
77  for (i = 0; i < 64; ++i) {
78  int n = s->idsp.idct_permutation[i];
79  info->intra_quantizer_matrix[i] = s->intra_matrix[n];
80  info->non_intra_quantizer_matrix[i] = s->inter_matrix[n];
81  }
82 
83  return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
84 }
85 
87  const uint8_t *buffer, uint32_t size)
88 {
89  MpegEncContext * const s = avctx->priv_data;
90  MPVPicture *pic = s->cur_pic.ptr;
91  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
92  int val;
93 
94  val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
95  if (val < 0)
96  return val;
97 
98  pic_ctx->info.mpeg.slice_count++;
99  return 0;
100 }
101 
102 #if CONFIG_MPEG1_VDPAU_HWACCEL
103 static int vdpau_mpeg1_init(AVCodecContext *avctx)
104 {
105  return ff_vdpau_common_init(avctx, VDP_DECODER_PROFILE_MPEG1,
106  VDP_DECODER_LEVEL_MPEG1_NA);
107 }
108 
110  .p.name = "mpeg1_vdpau",
111  .p.type = AVMEDIA_TYPE_VIDEO,
112  .p.id = AV_CODEC_ID_MPEG1VIDEO,
113  .p.pix_fmt = AV_PIX_FMT_VDPAU,
114  .start_frame = vdpau_mpeg_start_frame,
115  .end_frame = ff_vdpau_mpeg_end_frame,
116  .decode_slice = vdpau_mpeg_decode_slice,
117  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
118  .init = vdpau_mpeg1_init,
119  .uninit = ff_vdpau_common_uninit,
120  .priv_data_size = sizeof(VDPAUContext),
121  .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
122 };
123 #endif
124 
125 #if CONFIG_MPEG2_VDPAU_HWACCEL
126 static int vdpau_mpeg2_init(AVCodecContext *avctx)
127 {
128  VdpDecoderProfile profile;
129 
130  switch (avctx->profile) {
132  profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
133  break;
135  profile = VDP_DECODER_PROFILE_MPEG2_SIMPLE;
136  break;
137  default:
138  return AVERROR(EINVAL);
139  }
140 
141  return ff_vdpau_common_init(avctx, profile, VDP_DECODER_LEVEL_MPEG2_HL);
142 }
143 
145  .p.name = "mpeg2_vdpau",
146  .p.type = AVMEDIA_TYPE_VIDEO,
147  .p.id = AV_CODEC_ID_MPEG2VIDEO,
148  .p.pix_fmt = AV_PIX_FMT_VDPAU,
149  .start_frame = vdpau_mpeg_start_frame,
150  .end_frame = ff_vdpau_mpeg_end_frame,
151  .decode_slice = vdpau_mpeg_decode_slice,
152  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
153  .init = vdpau_mpeg2_init,
154  .uninit = ff_vdpau_common_uninit,
155  .frame_params = ff_vdpau_common_frame_params,
156  .priv_data_size = sizeof(VDPAUContext),
157  .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
158 };
159 #endif
ff_vdpau_common_frame_params
int ff_vdpau_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: vdpau.c:123
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
ff_mpeg2_vdpau_hwaccel
const struct FFHWAccel ff_mpeg2_vdpau_hwaccel
AV_PROFILE_MPEG2_SIMPLE
#define AV_PROFILE_MPEG2_SIMPLE
Definition: defs.h:105
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
vdpau_mpeg_start_frame
static int vdpau_mpeg_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg12.c:34
mpegvideo.h
VDPAUPictureInfo::mpeg
VdpPictureInfoMPEG1Or2 mpeg
Definition: vdpau_internal.h:45
vdpau_internal.h
ff_mpeg1_vdpau_hwaccel
const struct FFHWAccel ff_mpeg1_vdpau_hwaccel
vdpau_picture_context
Definition: vdpau_internal.h:98
FFHWAccel
Definition: hwaccel_internal.h:34
val
static double val(void *priv, double ch)
Definition: aeval.c:77
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
s
#define s(width, name)
Definition: cbs_vp9.c:198
info
MIPS optimizations info
Definition: mips.txt:2
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
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: codec_id.h:53
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
size
int size
Definition: twinvq_data.h:10344
ff_vdpau_mpeg_end_frame
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
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
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
AV_PROFILE_MPEG2_MAIN
#define AV_PROFILE_MPEG2_MAIN
Definition: defs.h:104
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
vdpau_mpeg_decode_slice
static int vdpau_mpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg12.c:86
MPVPicture
MPVPicture.
Definition: mpegpicture.h:58
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:54
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:73