FFmpeg  4.1.11
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 <vdpau/vdpau.h>
25 
26 #include "avcodec.h"
27 #include "hwaccel.h"
28 #include "mpegvideo.h"
29 #include "vdpau.h"
30 #include "vdpau_internal.h"
31 
33  const uint8_t *buffer, uint32_t size)
34 {
35  MpegEncContext * const s = avctx->priv_data;
36  Picture *pic = s->current_picture_ptr;
37  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
38  VdpPictureInfoMPEG1Or2 *info = &pic_ctx->info.mpeg;
39  VdpVideoSurface ref;
40  int i;
41 
42  /* fill VdpPictureInfoMPEG1Or2 struct */
43  info->forward_reference = VDP_INVALID_HANDLE;
44  info->backward_reference = VDP_INVALID_HANDLE;
45 
46  switch (s->pict_type) {
47  case AV_PICTURE_TYPE_B:
49  assert(ref != VDP_INVALID_HANDLE);
50  info->backward_reference = ref;
51  /* fall through to forward prediction */
52  case AV_PICTURE_TYPE_P:
54  info->forward_reference = ref;
55  }
56 
57  info->slice_count = 0;
58  info->picture_structure = s->picture_structure;
59  info->picture_coding_type = s->pict_type;
60  info->intra_dc_precision = s->intra_dc_precision;
61  info->frame_pred_frame_dct = s->frame_pred_frame_dct;
62  info->concealment_motion_vectors = s->concealment_motion_vectors;
63  info->intra_vlc_format = s->intra_vlc_format;
64  info->alternate_scan = s->alternate_scan;
65  info->q_scale_type = s->q_scale_type;
66  info->top_field_first = s->top_field_first;
67  // Both for MPEG-1 only, zero for MPEG-2:
68  info->full_pel_forward_vector = s->full_pel[0];
69  info->full_pel_backward_vector = s->full_pel[1];
70  // For MPEG-1 fill both horizontal & vertical:
71  info->f_code[0][0] = s->mpeg_f_code[0][0];
72  info->f_code[0][1] = s->mpeg_f_code[0][1];
73  info->f_code[1][0] = s->mpeg_f_code[1][0];
74  info->f_code[1][1] = s->mpeg_f_code[1][1];
75  for (i = 0; i < 64; ++i) {
76  int n = s->idsp.idct_permutation[i];
77  info->intra_quantizer_matrix[i] = s->intra_matrix[n];
78  info->non_intra_quantizer_matrix[i] = s->inter_matrix[n];
79  }
80 
81  return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
82 }
83 
85  const uint8_t *buffer, uint32_t size)
86 {
87  MpegEncContext * const s = avctx->priv_data;
88  Picture *pic = s->current_picture_ptr;
89  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
90  int val;
91 
92  val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
93  if (val < 0)
94  return val;
95 
96  pic_ctx->info.mpeg.slice_count++;
97  return 0;
98 }
99 
100 #if CONFIG_MPEG1_VDPAU_HWACCEL
101 static int vdpau_mpeg1_init(AVCodecContext *avctx)
102 {
103  return ff_vdpau_common_init(avctx, VDP_DECODER_PROFILE_MPEG1,
104  VDP_DECODER_LEVEL_MPEG1_NA);
105 }
106 
108  .name = "mpeg1_vdpau",
109  .type = AVMEDIA_TYPE_VIDEO,
111  .pix_fmt = AV_PIX_FMT_VDPAU,
112  .start_frame = vdpau_mpeg_start_frame,
113  .end_frame = ff_vdpau_mpeg_end_frame,
114  .decode_slice = vdpau_mpeg_decode_slice,
115  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
116  .init = vdpau_mpeg1_init,
117  .uninit = ff_vdpau_common_uninit,
118  .priv_data_size = sizeof(VDPAUContext),
119  .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
120 };
121 #endif
122 
123 #if CONFIG_MPEG2_VDPAU_HWACCEL
124 static int vdpau_mpeg2_init(AVCodecContext *avctx)
125 {
126  VdpDecoderProfile profile;
127 
128  switch (avctx->profile) {
130  profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
131  break;
133  profile = VDP_DECODER_PROFILE_MPEG2_SIMPLE;
134  break;
135  default:
136  return AVERROR(EINVAL);
137  }
138 
139  return ff_vdpau_common_init(avctx, profile, VDP_DECODER_LEVEL_MPEG2_HL);
140 }
141 
143  .name = "mpeg2_vdpau",
144  .type = AVMEDIA_TYPE_VIDEO,
146  .pix_fmt = AV_PIX_FMT_VDPAU,
147  .start_frame = vdpau_mpeg_start_frame,
148  .end_frame = ff_vdpau_mpeg_end_frame,
149  .decode_slice = vdpau_mpeg_decode_slice,
150  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
151  .init = vdpau_mpeg2_init,
152  .uninit = ff_vdpau_common_uninit,
153  .frame_params = ff_vdpau_common_frame_params,
154  .priv_data_size = sizeof(VDPAUContext),
155  .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
156 };
157 #endif
IDCTDSPContext idsp
Definition: mpegvideo.h:230
const char const char void * val
Definition: avisynth_c.h:771
#define FF_PROFILE_MPEG2_MAIN
Definition: avcodec.h:2892
int size
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:322
static int vdpau_mpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg12.c:84
mpegvideo header.
Public libavcodec VDPAU header.
int profile
profile
Definition: avcodec.h:2859
static char buffer[20]
Definition: seek.c:32
int ff_vdpau_common_uninit(AVCodecContext *avctx)
Definition: vdpau.c:284
uint8_t
int full_pel[2]
Definition: mpegvideo.h:489
int intra_dc_precision
Definition: mpegvideo.h:463
int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, int level)
Definition: vdpau.c:133
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:258
#define AVERROR(e)
Definition: error.h:43
const AVHWAccel ff_mpeg1_vdpau_hwaccel
VdpPictureInfoMPEG1Or2 mpeg
int intra_vlc_format
Definition: mpegvideo.h:469
int top_field_first
Definition: mpegvideo.h:465
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:3598
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:184
Picture.
Definition: mpegpicture.h:45
int alternate_scan
Definition: mpegvideo.h:470
void * hwaccel_picture_private
Hardware accelerator private data.
Definition: mpegpicture.h:77
#define s(width, name)
Definition: cbs_vp9.c:257
int n
Definition: avisynth_c.h:684
int ff_vdpau_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: vdpau.c:114
uint8_t idct_permutation[64]
IDCT input permutation.
Definition: idctdsp.h:96
int mpeg_f_code[2][2]
Definition: mpegvideo.h:457
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:220
int frame_pred_frame_dct
Definition: mpegvideo.h:464
uint16_t inter_matrix[64]
Definition: mpegvideo.h:302
int concealment_motion_vectors
Definition: mpegvideo.h:466
Libavcodec external API header.
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
main external API structure.
Definition: avcodec.h:1533
struct AVFrame * f
Definition: mpegpicture.h:46
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:197
const AVHWAccel ff_mpeg2_vdpau_hwaccel
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:212
mfxU16 profile
Definition: qsvenc.c:44
MpegEncContext.
Definition: mpegvideo.h:81
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, const uint8_t *buf, uint32_t size)
Definition: vdpau.c:377
Picture last_picture
copy of the previous picture structure.
Definition: mpegvideo.h:162
Bi-dir predicted.
Definition: avutil.h:276
#define HWACCEL_CAP_ASYNC_SAFE
Definition: hwaccel.h:26
void * priv_data
Definition: avcodec.h:1560
int picture_structure
Definition: mpegvideo.h:460
union VDPAUPictureInfo info
VDPAU picture information.
#define FF_PROFILE_MPEG2_SIMPLE
Definition: avcodec.h:2893
Picture next_picture
copy of the next picture structure.
Definition: mpegvideo.h:168
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
Definition: mpegvideo.h:300
static int vdpau_mpeg_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg12.c:32
Predicted.
Definition: avutil.h:275
static uintptr_t ff_vdpau_get_surface_id(AVFrame *pic)
Extract VdpVideoSurface from an AVFrame.