Libav
vdpau_mpeg4.c
Go to the documentation of this file.
1 /*
2  * MPEG-4 Part 2 / H.263 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 "mpeg4video.h"
28 #include "vdpau.h"
29 #include "vdpau_internal.h"
30 
32  const uint8_t *buffer, uint32_t size)
33 {
34  Mpeg4DecContext *ctx = avctx->priv_data;
35  MpegEncContext * const s = &ctx->m;
36  Picture *pic = s->current_picture_ptr;
37  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
38  VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4;
39  VdpVideoSurface ref;
40  int i;
41 
42  /* fill VdpPictureInfoMPEG4Part2 struct */
43  info->forward_reference = VDP_INVALID_HANDLE;
44  info->backward_reference = VDP_INVALID_HANDLE;
45  info->vop_coding_type = 0;
46 
47  switch (s->pict_type) {
48  case AV_PICTURE_TYPE_B:
50  assert(ref != VDP_INVALID_HANDLE);
51  info->backward_reference = ref;
52  info->vop_coding_type = 2;
53  /* fall-through */
54  case AV_PICTURE_TYPE_P:
56  assert(ref != VDP_INVALID_HANDLE);
57  info->forward_reference = ref;
58  }
59 
60  info->trd[0] = s->pp_time;
61  info->trb[0] = s->pb_time;
62  info->trd[1] = s->pp_field_time >> 1;
63  info->trb[1] = s->pb_field_time >> 1;
64  info->vop_time_increment_resolution = s->avctx->time_base.den;
65  info->vop_fcode_forward = s->f_code;
66  info->vop_fcode_backward = s->b_code;
67  info->resync_marker_disable = !ctx->resync_marker;
68  info->interlaced = !s->progressive_sequence;
69  info->quant_type = s->mpeg_quant;
70  info->quarter_sample = s->quarter_sample;
71  info->short_video_header = avctx->codec->id == AV_CODEC_ID_H263;
72  info->rounding_control = s->no_rounding;
73  info->alternate_vertical_scan_flag = s->alternate_scan;
74  info->top_field_first = s->top_field_first;
75  for (i = 0; i < 64; ++i) {
76  info->intra_quantizer_matrix[i] = s->intra_matrix[i];
77  info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
78  }
79 
80  ff_vdpau_common_start_frame(pic_ctx, buffer, size);
81  return ff_vdpau_add_buffer(pic_ctx, buffer, size);
82 }
83 
85  av_unused const uint8_t *buffer,
86  av_unused uint32_t size)
87 {
88  return 0;
89 }
90 
91 #if CONFIG_H263_VDPAU_HWACCEL
92 AVHWAccel ff_h263_vdpau_hwaccel = {
93  .name = "h263_vdpau",
94  .type = AVMEDIA_TYPE_VIDEO,
95  .id = AV_CODEC_ID_H263,
96  .pix_fmt = AV_PIX_FMT_VDPAU,
97  .start_frame = vdpau_mpeg4_start_frame,
98  .end_frame = ff_vdpau_mpeg_end_frame,
99  .decode_slice = vdpau_mpeg4_decode_slice,
100  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
101 };
102 #endif
103 
104 #if CONFIG_MPEG4_VDPAU_HWACCEL
105 AVHWAccel ff_mpeg4_vdpau_hwaccel = {
106  .name = "mpeg4_vdpau",
107  .type = AVMEDIA_TYPE_VIDEO,
108  .id = AV_CODEC_ID_MPEG4,
109  .pix_fmt = AV_PIX_FMT_VDPAU,
110  .start_frame = vdpau_mpeg4_start_frame,
111  .end_frame = ff_vdpau_mpeg_end_frame,
112  .decode_slice = vdpau_mpeg4_decode_slice,
113  .frame_priv_data_size = sizeof(struct vdpau_picture_context),
114 };
115 #endif
const struct AVCodec * codec
Definition: avcodec.h:1059
int size
union AVVDPAUPictureInfo info
VDPAU picture information.
int resync_marker
could this stream contain resync markers
Definition: mpeg4video.h:79
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
Public libavcodec VDPAU header.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1175
uint8_t
int no_rounding
apply no rounding to motion compensation (MPEG4, msmpeg4, ...) for b-frames rounding mode is always 0...
Definition: mpegvideo.h:406
uint16_t pp_time
time distance between the last 2 p,s,i frames
Definition: mpegvideo.h:505
MpegEncContext m
Definition: mpeg4video.h:63
enum AVCodecID id
Definition: avcodec.h:2810
int quarter_sample
1->qpel, 0->half pel ME/MC
Definition: mpegvideo.h:514
static int vdpau_mpeg4_decode_slice(av_unused AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition: vdpau_mpeg4.c:84
int top_field_first
Definition: mpegvideo.h:574
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2899
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
VdpPictureInfoMPEG4Part2 mpeg4
Definition: vdpau.h:65
uint16_t inter_matrix[64]
Definition: mpegvideo.h:424
Libavcodec external API header.
AVHWAccel.
Definition: avcodec.h:2893
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
main external API structure.
Definition: avcodec.h:1050
int progressive_sequence
Definition: mpegvideo.h:566
struct AVFrame * f
Definition: mpegvideo.h:100
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:190
int f_code
forward MV resolution
Definition: mpegvideo.h:362
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:339
uint16_t pb_field_time
like above, just for interlaced
Definition: mpegvideo.h:508
MpegEncContext.
Definition: mpegvideo.h:204
struct AVCodecContext * avctx
Definition: mpegvideo.h:221
uint16_t pp_field_time
Definition: mpegvideo.h:507
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
int den
denominator
Definition: rational.h:45
void * priv_data
Definition: avcodec.h:1092
static int vdpau_mpeg4_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg4.c:31
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
int b_code
backward MV resolution for B Frames (mpeg4)
Definition: mpegvideo.h:363
Predicted.
Definition: avutil.h:254
#define av_unused
Definition: attributes.h:86
uint16_t pb_time
time distance between the last b and p,s,i frame
Definition: mpegvideo.h:506
static uintptr_t ff_vdpau_get_surface_id(AVFrame *pic)
Extract VdpVideoSurface from an AVFrame.