FFmpeg  2.1.1
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 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  Picture *pic = s->current_picture_ptr;
35  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
36  VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4;
37  VdpVideoSurface ref;
38  int i;
39 
40  /* fill VdpPictureInfoMPEG4Part2 struct */
41  info->forward_reference = VDP_INVALID_HANDLE;
42  info->backward_reference = VDP_INVALID_HANDLE;
43  info->vop_coding_type = 0;
44 
45  switch (s->pict_type) {
46  case AV_PICTURE_TYPE_B:
48  assert(ref != VDP_INVALID_HANDLE);
49  info->backward_reference = ref;
50  info->vop_coding_type = 2;
51  /* fall-through */
52  case AV_PICTURE_TYPE_P:
54  assert(ref != VDP_INVALID_HANDLE);
55  info->forward_reference = ref;
56  }
57 
58  info->trd[0] = s->pp_time;
59  info->trb[0] = s->pb_time;
60  info->trd[1] = s->pp_field_time >> 1;
61  info->trb[1] = s->pb_field_time >> 1;
62  info->vop_time_increment_resolution = s->avctx->time_base.den;
63  info->vop_fcode_forward = s->f_code;
64  info->vop_fcode_backward = s->b_code;
65  info->resync_marker_disable = !s->resync_marker;
66  info->interlaced = !s->progressive_sequence;
67  info->quant_type = s->mpeg_quant;
68  info->quarter_sample = s->quarter_sample;
69  info->short_video_header = avctx->codec->id == AV_CODEC_ID_H263;
70  info->rounding_control = s->no_rounding;
71  info->alternate_vertical_scan_flag = s->alternate_scan;
72  info->top_field_first = s->top_field_first;
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  ff_vdpau_common_start_frame(pic, buffer, size);
79  return ff_vdpau_add_buffer(pic, buffer, size);
80 }
81 
83  av_unused const uint8_t *buffer,
84  av_unused uint32_t size)
85 {
86  return 0;
87 }
88 
89 #if CONFIG_H263_VDPAU_HWACCEL
90 AVHWAccel ff_h263_vdpau_hwaccel = {
91  .name = "h263_vdpau",
92  .type = AVMEDIA_TYPE_VIDEO,
93  .id = AV_CODEC_ID_H263,
94  .pix_fmt = AV_PIX_FMT_VDPAU,
95  .start_frame = vdpau_mpeg4_start_frame,
96  .end_frame = ff_vdpau_mpeg_end_frame,
97  .decode_slice = vdpau_mpeg4_decode_slice,
98  .priv_data_size = sizeof(struct vdpau_picture_context),
99 };
100 #endif
101 
102 #if CONFIG_MPEG4_VDPAU_HWACCEL
103 AVHWAccel ff_mpeg4_vdpau_hwaccel = {
104  .name = "mpeg4_vdpau",
105  .type = AVMEDIA_TYPE_VIDEO,
106  .id = AV_CODEC_ID_MPEG4,
107  .pix_fmt = AV_PIX_FMT_VDPAU,
108  .start_frame = vdpau_mpeg4_start_frame,
109  .end_frame = ff_vdpau_mpeg_end_frame,
110  .decode_slice = vdpau_mpeg4_decode_slice,
111  .priv_data_size = sizeof(struct vdpau_picture_context),
112 };
113 #endif
const char * s
Definition: avisynth_c.h:668
int size
Predicted.
Definition: avcodec.h:2305
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1265
uint8_t
int no_rounding
apply no rounding to motion compensation (MPEG4, msmpeg4, ...) for b-frames rounding mode is always 0...
Definition: mpegvideo.h:443
int resync_marker
could this stream contain resync markers
Definition: mpegvideo.h:596
uint16_t pp_time
time distance between the last 2 p,s,i frames
Definition: mpegvideo.h:565
int ff_vdpau_common_start_frame(Picture *pic, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition: vdpau.c:48
static uintptr_t ff_vdpau_get_surface_id(Picture *pic)
Extract VdpVideoSurface from a Picture.
enum AVCodecID id
Definition: avcodec.h:2936
struct AVCodec * codec
Definition: avcodec.h:1155
int quarter_sample
1-&gt;qpel, 0-&gt;half pel ME/MC
Definition: mpegvideo.h:584
Libavcodec external API header.
#define av_unused
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
Definition: avcodec.h:697
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:82
int top_field_first
Definition: mpegvideo.h:673
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:351
Picture.
Definition: mpegvideo.h:97
int alternate_scan
Definition: mpegvideo.h:677
void * hwaccel_picture_private
hardware accelerator private data
Definition: mpegvideo.h:132
static char buffer[20]
Definition: seek-test.c:31
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:3027
uint16_t inter_matrix[64]
Definition: mpegvideo.h:478
AVHWAccel.
Definition: avcodec.h:3021
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
main external API structure.
Definition: avcodec.h:1146
int progressive_sequence
Definition: mpegvideo.h:663
Bi-dir predicted.
Definition: avcodec.h:2306
int f_code
forward MV resolution
Definition: mpegvideo.h:399
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:381
Public libavcodec VDPAU header.
void * priv_data
Definition: avcodec.h:1182
uint16_t pb_field_time
like above, just for interlaced
Definition: mpegvideo.h:568
MpegEncContext.
Definition: mpegvideo.h:245
struct AVCodecContext * avctx
Definition: mpegvideo.h:247
uint16_t pp_field_time
Definition: mpegvideo.h:567
Picture last_picture
copy of the previous picture structure.
Definition: mpegvideo.h:329
int den
denominator
Definition: rational.h:45
static int vdpau_mpeg4_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: vdpau_mpeg4.c:30
int ff_vdpau_add_buffer(Picture *pic, const uint8_t *buf, uint32_t size)
Definition: vdpau.c:86
Picture next_picture
copy of the next picture structure.
Definition: mpegvideo.h:335
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: avcodec.h:4675
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
Definition: mpegvideo.h:476
int b_code
backward MV resolution for B Frames (mpeg4)
Definition: mpegvideo.h:400
uint16_t pb_time
time distance between the last b and p,s,i frame
Definition: mpegvideo.h:566