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 "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  AVVDPAUContext *hwctx = avctx->hwaccel_context;
35  VdpPictureInfoMPEG1Or2 *info = &hwctx->info.mpeg;
36  VdpVideoSurface ref;
37  int i;
38 
39  /* fill VdpPictureInfoMPEG1Or2 struct */
40  info->forward_reference = VDP_INVALID_HANDLE;
41  info->backward_reference = VDP_INVALID_HANDLE;
42 
43  switch (s->pict_type) {
44  case AV_PICTURE_TYPE_B:
46  assert(ref != VDP_INVALID_HANDLE);
47  hwctx->info.mpeg.backward_reference = ref;
48  /* fall through to forward prediction */
49  case AV_PICTURE_TYPE_P:
51  hwctx->info.mpeg.forward_reference = ref;
52  }
53 
54  info->slice_count = 0;
55  info->picture_structure = s->picture_structure;
56  info->picture_coding_type = s->pict_type;
57  info->intra_dc_precision = s->intra_dc_precision;
58  info->frame_pred_frame_dct = s->frame_pred_frame_dct;
59  info->concealment_motion_vectors = s->concealment_motion_vectors;
60  info->intra_vlc_format = s->intra_vlc_format;
61  info->alternate_scan = s->alternate_scan;
62  info->q_scale_type = s->q_scale_type;
63  info->top_field_first = s->top_field_first;
64  // Both for MPEG-1 only, zero for MPEG-2:
65  info->full_pel_forward_vector = s->full_pel[0];
66  info->full_pel_backward_vector = s->full_pel[1];
67  // For MPEG-1 fill both horizontal & vertical:
68  info->f_code[0][0] = s->mpeg_f_code[0][0];
69  info->f_code[0][1] = s->mpeg_f_code[0][1];
70  info->f_code[1][0] = s->mpeg_f_code[1][0];
71  info->f_code[1][1] = s->mpeg_f_code[1][1];
72  for (i = 0; i < 64; ++i) {
73  info->intra_quantizer_matrix[i] = s->intra_matrix[i];
74  info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
75  }
76 
77  return ff_vdpau_common_start_frame(avctx, buffer, size);
78 }
79 
81  const uint8_t *buffer, uint32_t size)
82 {
83  AVVDPAUContext *hwctx = avctx->hwaccel_context;
84  int val;
85 
86  val = ff_vdpau_add_buffer(avctx, buffer, size);
87  if (val < 0)
88  return val;
89 
90  hwctx->info.mpeg.slice_count++;
91  return 0;
92 }
93 
94 #if CONFIG_MPEG1_VDPAU_HWACCEL
95 AVHWAccel ff_mpeg1_vdpau_hwaccel = {
96  .name = "mpeg1_vdpau",
97  .type = AVMEDIA_TYPE_VIDEO,
99  .pix_fmt = AV_PIX_FMT_VDPAU,
100  .start_frame = vdpau_mpeg_start_frame,
101  .end_frame = ff_vdpau_mpeg_end_frame,
102  .decode_slice = vdpau_mpeg_decode_slice,
103 };
104 #endif
105 
106 #if CONFIG_MPEG2_VDPAU_HWACCEL
107 AVHWAccel ff_mpeg2_vdpau_hwaccel = {
108  .name = "mpeg2_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 };
116 #endif
const char * s
Definition: avisynth_c.h:668
FIXME Range Coding of cr are ref
Definition: snow.txt:367
static int vdpau_mpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg12.c:80
Public libavcodec VDPAU header.
uint8_t
union FFVdpPictureInfo info
VDPAU picture information.
Definition: vdpau.h:92
void * hwaccel_context
Hardware accelerator context.
int full_pel[2]
Definition: mpegvideo.h:683
int intra_dc_precision
Definition: mpegvideo.h:666
static uintptr_t ff_vdpau_get_surface_id(Picture *pic)
Extract VdpVideoSurface from a Picture.
This structure is used to share data between the libavcodec library and the client video application...
Definition: vdpau.h:72
external API header
int size
int intra_vlc_format
Definition: mpegvideo.h:671
MIPS optimizations info
Definition: mips.txt:2
int top_field_first
Definition: mpegvideo.h:668
const char * name
Name of the hardware accelerated codec.
int alternate_scan
Definition: mpegvideo.h:672
int mpeg_f_code[2][2]
Definition: mpegvideo.h:659
preferred ID for MPEG-1/2 video decoding
int frame_pred_frame_dct
Definition: mpegvideo.h:667
uint16_t inter_matrix[64]
Definition: mpegvideo.h:474
int concealment_motion_vectors
Definition: mpegvideo.h:669
AVHWAccel.
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
main external API structure.
int ff_vdpau_add_buffer(AVCodecContext *avctx, const uint8_t *buf, uint32_t size)
Definition: vdpau.c:70
synthesis window for stochastic i
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:203
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:377
int ff_vdpau_common_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition: vdpau.c:41
MpegEncContext.
Definition: mpegvideo.h:241
Picture last_picture
copy of the previous picture structure.
Definition: mpegvideo.h:325
Bi-dir predicted.
Definition: avutil.h:218
the buffer and buffer 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 AVFilterBuffer structures They must not be accessed but through references stored in AVFilterBufferRef structures Several references can point to the same buffer
int picture_structure
Definition: mpegvideo.h:660
Picture next_picture
copy of the next picture structure.
Definition: mpegvideo.h:331
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
Definition: mpegvideo.h:472
static int vdpau_mpeg_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg12.c:30
Predicted.
Definition: avutil.h:217
VdpPictureInfoMPEG1Or2 mpeg
Definition: vdpau.h:58