FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "mpegvideo.h"
28 #include "vdpau.h"
29 #include "vdpau_internal.h"
30 
32  const uint8_t *buffer, uint32_t size)
33 {
34  MpegEncContext * const s = avctx->priv_data;
35  Picture *pic = s->current_picture_ptr;
36  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
37  VdpPictureInfoMPEG1Or2 *info = &pic_ctx->info.mpeg;
38  VdpVideoSurface ref;
39  int i;
40 
41  /* fill VdpPictureInfoMPEG1Or2 struct */
42  info->forward_reference = VDP_INVALID_HANDLE;
43  info->backward_reference = VDP_INVALID_HANDLE;
44 
45  switch (s->pict_type) {
46  case AV_PICTURE_TYPE_B:
48  assert(ref != VDP_INVALID_HANDLE);
49  info->backward_reference = ref;
50  /* fall through to forward prediction */
51  case AV_PICTURE_TYPE_P:
53  info->forward_reference = ref;
54  }
55 
56  info->slice_count = 0;
57  info->picture_structure = s->picture_structure;
58  info->picture_coding_type = s->pict_type;
59  info->intra_dc_precision = s->intra_dc_precision;
60  info->frame_pred_frame_dct = s->frame_pred_frame_dct;
61  info->concealment_motion_vectors = s->concealment_motion_vectors;
62  info->intra_vlc_format = s->intra_vlc_format;
63  info->alternate_scan = s->alternate_scan;
64  info->q_scale_type = s->q_scale_type;
65  info->top_field_first = s->top_field_first;
66  // Both for MPEG-1 only, zero for MPEG-2:
67  info->full_pel_forward_vector = s->full_pel[0];
68  info->full_pel_backward_vector = s->full_pel[1];
69  // For MPEG-1 fill both horizontal & vertical:
70  info->f_code[0][0] = s->mpeg_f_code[0][0];
71  info->f_code[0][1] = s->mpeg_f_code[0][1];
72  info->f_code[1][0] = s->mpeg_f_code[1][0];
73  info->f_code[1][1] = s->mpeg_f_code[1][1];
74  for (i = 0; i < 64; ++i) {
75  info->intra_quantizer_matrix[i] = s->intra_matrix[i];
76  info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
77  }
78 
79  return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
80 }
81 
83  const uint8_t *buffer, uint32_t size)
84 {
85  MpegEncContext * const s = avctx->priv_data;
86  Picture *pic = s->current_picture_ptr;
87  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
88  int val;
89 
90  val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
91  if (val < 0)
92  return val;
93 
94  pic_ctx->info.mpeg.slice_count++;
95  return 0;
96 }
97 
98 #if CONFIG_MPEG1_VDPAU_HWACCEL
99 static int vdpau_mpeg1_init(AVCodecContext *avctx)
100 {
101  return ff_vdpau_common_init(avctx, VDP_DECODER_PROFILE_MPEG1,
102  VDP_DECODER_LEVEL_MPEG1_NA);
103 }
104 
105 AVHWAccel ff_mpeg1_vdpau_hwaccel = {
106  .name = "mpeg1_vdpau",
107  .type = AVMEDIA_TYPE_VIDEO,
109  .pix_fmt = AV_PIX_FMT_VDPAU,
110  .start_frame = vdpau_mpeg_start_frame,
111  .end_frame = ff_vdpau_mpeg_end_frame,
112  .decode_slice = vdpau_mpeg_decode_slice,
113  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
114  .init = vdpau_mpeg1_init,
115  .uninit = ff_vdpau_common_uninit,
116  .priv_data_size = sizeof(VDPAUContext),
117 };
118 #endif
119 
120 #if CONFIG_MPEG2_VDPAU_HWACCEL
121 static int vdpau_mpeg2_init(AVCodecContext *avctx)
122 {
123  VdpDecoderProfile profile;
124 
125  switch (avctx->profile) {
127  profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
128  break;
130  profile = VDP_DECODER_PROFILE_MPEG2_SIMPLE;
131  break;
132  default:
133  return AVERROR(EINVAL);
134  }
135 
136  return ff_vdpau_common_init(avctx, profile, VDP_DECODER_LEVEL_MPEG2_HL);
137 }
138 
139 AVHWAccel ff_mpeg2_vdpau_hwaccel = {
140  .name = "mpeg2_vdpau",
141  .type = AVMEDIA_TYPE_VIDEO,
143  .pix_fmt = AV_PIX_FMT_VDPAU,
144  .start_frame = vdpau_mpeg_start_frame,
145  .end_frame = ff_vdpau_mpeg_end_frame,
146  .decode_slice = vdpau_mpeg_decode_slice,
147  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
148  .init = vdpau_mpeg2_init,
149  .uninit = ff_vdpau_common_uninit,
150  .priv_data_size = sizeof(VDPAUContext),
151 };
152 #endif
const char const char void * val
Definition: avisynth_c.h:634
const char * s
Definition: avisynth_c.h:631
#define FF_PROFILE_MPEG2_MAIN
Definition: avcodec.h:3054
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
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:266
static int vdpau_mpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg12.c:82
mpegvideo header.
Public libavcodec VDPAU header.
int profile
profile
Definition: avcodec.h:3028
int ff_vdpau_common_uninit(AVCodecContext *avctx)
Definition: vdpau.c:228
uint8_t
int full_pel[2]
Definition: mpegvideo.h:479
int intra_dc_precision
Definition: mpegvideo.h:460
ptrdiff_t size
Definition: opengl_enc.c:101
int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, int level)
Definition: vdpau.c:115
#define AVERROR(e)
Definition: error.h:43
int intra_vlc_format
Definition: mpegvideo.h:466
int top_field_first
Definition: mpegvideo.h:462
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:3503
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:181
Picture.
Definition: mpegpicture.h:45
int alternate_scan
Definition: mpegvideo.h:467
void * hwaccel_picture_private
Hardware accelerator private data.
Definition: mpegpicture.h:77
int mpeg_f_code[2][2]
Definition: mpegvideo.h:454
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:106
int frame_pred_frame_dct
Definition: mpegvideo.h:461
uint16_t inter_matrix[64]
Definition: mpegvideo.h:302
int concealment_motion_vectors
Definition: mpegvideo.h:463
Libavcodec external API header.
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
main external API structure.
Definition: avcodec.h:1532
struct AVFrame * f
Definition: mpegpicture.h:46
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:209
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:209
mfxU16 profile
Definition: qsvenc.c:42
MpegEncContext.
Definition: mpegvideo.h:78
int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, const uint8_t *buf, uint32_t size)
Definition: vdpau.c:339
Picture last_picture
copy of the previous picture structure.
Definition: mpegvideo.h:159
Bi-dir predicted.
Definition: avutil.h:268
void * priv_data
Definition: avcodec.h:1574
int picture_structure
Definition: mpegvideo.h:457
#define FF_PROFILE_MPEG2_SIMPLE
Definition: avcodec.h:3055
Picture next_picture
copy of the next picture structure.
Definition: mpegvideo.h:165
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:31
Predicted.
Definition: avutil.h:267
GLuint buffer
Definition: opengl_enc.c:102
static uintptr_t ff_vdpau_get_surface_id(AVFrame *pic)
Extract VdpVideoSurface from an AVFrame.