Libav
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 Libav.
8  *
9  * Libav 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  * Libav 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 Libav; 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 "vdpau.h"
28 #include "vdpau_internal.h"
29 
31  const uint8_t *buffer, uint32_t size)
32 {
33  MpegEncContext * const s = avctx->priv_data;
34  Picture *pic = s->current_picture_ptr;
35  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
36  VdpPictureInfoMPEG1Or2 *info = &pic_ctx->info.mpeg;
37  VdpVideoSurface ref;
38  int i;
39 
40  /* fill VdpPictureInfoMPEG1Or2 struct */
41  info->forward_reference = VDP_INVALID_HANDLE;
42  info->backward_reference = VDP_INVALID_HANDLE;
43 
44  switch (s->pict_type) {
45  case AV_PICTURE_TYPE_B:
47  assert(ref != VDP_INVALID_HANDLE);
48  info->backward_reference = ref;
49  /* fall through to forward prediction */
50  case AV_PICTURE_TYPE_P:
52  info->forward_reference = ref;
53  }
54 
55  info->slice_count = 0;
56  info->picture_structure = s->picture_structure;
57  info->picture_coding_type = s->pict_type;
58  info->intra_dc_precision = s->intra_dc_precision;
59  info->frame_pred_frame_dct = s->frame_pred_frame_dct;
60  info->concealment_motion_vectors = s->concealment_motion_vectors;
61  info->intra_vlc_format = s->intra_vlc_format;
62  info->alternate_scan = s->alternate_scan;
63  info->q_scale_type = s->q_scale_type;
64  info->top_field_first = s->top_field_first;
65  // Both for MPEG-1 only, zero for MPEG-2:
66  info->full_pel_forward_vector = s->full_pel[0];
67  info->full_pel_backward_vector = s->full_pel[1];
68  // For MPEG-1 fill both horizontal & vertical:
69  info->f_code[0][0] = s->mpeg_f_code[0][0];
70  info->f_code[0][1] = s->mpeg_f_code[0][1];
71  info->f_code[1][0] = s->mpeg_f_code[1][0];
72  info->f_code[1][1] = s->mpeg_f_code[1][1];
73  for (i = 0; i < 64; ++i) {
74  info->intra_quantizer_matrix[i] = s->intra_matrix[i];
75  info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
76  }
77 
78  return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
79 }
80 
82  const uint8_t *buffer, uint32_t size)
83 {
84  MpegEncContext * const s = avctx->priv_data;
85  Picture *pic = s->current_picture_ptr;
86  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
87  int val;
88 
89  val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
90  if (val < 0)
91  return val;
92 
93  pic_ctx->info.mpeg.slice_count++;
94  return 0;
95 }
96 
97 #if CONFIG_MPEG1_VDPAU_HWACCEL
98 AVHWAccel ff_mpeg1_vdpau_hwaccel = {
99  .name = "mpeg1_vdpau",
100  .type = AVMEDIA_TYPE_VIDEO,
102  .pix_fmt = AV_PIX_FMT_VDPAU,
103  .start_frame = vdpau_mpeg_start_frame,
104  .end_frame = ff_vdpau_mpeg_end_frame,
105  .decode_slice = vdpau_mpeg_decode_slice,
106  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
107 };
108 #endif
109 
110 #if CONFIG_MPEG2_VDPAU_HWACCEL
111 AVHWAccel ff_mpeg2_vdpau_hwaccel = {
112  .name = "mpeg2_vdpau",
113  .type = AVMEDIA_TYPE_VIDEO,
115  .pix_fmt = AV_PIX_FMT_VDPAU,
116  .start_frame = vdpau_mpeg_start_frame,
117  .end_frame = ff_vdpau_mpeg_end_frame,
118  .decode_slice = vdpau_mpeg_decode_slice,
119  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
120 };
121 #endif
int size
union AVVDPAUPictureInfo info
VDPAU picture information.
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:41
static int vdpau_mpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg12.c:81
VdpPictureInfoMPEG1Or2 mpeg
Definition: vdpau.h:63
Public libavcodec VDPAU header.
uint8_t
int full_pel[2]
Definition: mpegvideo.h:588
int intra_dc_precision
Definition: mpegvideo.h:572
int intra_vlc_format
Definition: mpegvideo.h:577
int top_field_first
Definition: mpegvideo.h:574
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2915
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:310
Picture.
Definition: mpegvideo.h:99
int alternate_scan
Definition: mpegvideo.h:578
void * hwaccel_picture_private
hardware accelerator private data
Definition: mpegvideo.h:131
static char buffer[20]
Definition: seek-test.c:31
int mpeg_f_code[2][2]
Definition: mpegvideo.h:567
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:110
int frame_pred_frame_dct
Definition: mpegvideo.h:573
uint16_t inter_matrix[64]
Definition: mpegvideo.h:424
int concealment_motion_vectors
Definition: mpegvideo.h:575
Libavcodec external API header.
AVHWAccel.
Definition: avcodec.h:2909
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
main external API structure.
Definition: avcodec.h:1050
struct AVFrame * f
Definition: mpegvideo.h:100
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:190
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:339
MpegEncContext.
Definition: mpegvideo.h:204
int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, const uint8_t *buf, uint32_t size)
Definition: vdpau.c:72
Picture last_picture
copy of the previous picture structure.
Definition: mpegvideo.h:288
Bi-dir predicted.
Definition: avutil.h:255
void * priv_data
Definition: avcodec.h:1092
int picture_structure
Definition: mpegvideo.h:570
Picture next_picture
copy of the next picture structure.
Definition: mpegvideo.h:294
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
Definition: mpegvideo.h:422
static int vdpau_mpeg_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg12.c:30
Predicted.
Definition: avutil.h:254
static uintptr_t ff_vdpau_get_surface_id(AVFrame *pic)
Extract VdpVideoSurface from an AVFrame.