Libav
vdpau.c
Go to the documentation of this file.
1 /*
2  * Video Decode and Presentation API for UNIX (VDPAU) is used for
3  * HW decode acceleration for MPEG-1/2, MPEG-4 ASP, H.264 and VC-1.
4  *
5  * Copyright (c) 2008 NVIDIA
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
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <limits.h>
25 #include "avcodec.h"
26 #include "h264.h"
27 #include "vc1.h"
28 
29 #undef NDEBUG
30 #include <assert.h>
31 
32 #include "vdpau.h"
33 #include "vdpau_internal.h"
34 
42  av_unused const uint8_t *buffer,
43  av_unused uint32_t size)
44 {
45  pic_ctx->bitstream_buffers_allocated = 0;
46  pic_ctx->bitstream_buffers_used = 0;
47  pic_ctx->bitstream_buffers = NULL;
48  return 0;
49 }
50 
51 #if CONFIG_H263_VDPAU_HWACCEL || CONFIG_MPEG1_VDPAU_HWACCEL || \
52  CONFIG_MPEG2_VDPAU_HWACCEL || CONFIG_MPEG4_VDPAU_HWACCEL || \
53  CONFIG_VC1_VDPAU_HWACCEL || CONFIG_WMV3_VDPAU_HWACCEL
55 {
56  AVVDPAUContext *hwctx = avctx->hwaccel_context;
57  MpegEncContext *s = avctx->priv_data;
58  Picture *pic = s->current_picture_ptr;
59  struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
60  VdpVideoSurface surf = ff_vdpau_get_surface_id(pic->f);
61 
62  hwctx->render(hwctx->decoder, surf, (void *)&pic_ctx->info,
63  pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers);
64 
66  av_freep(&pic_ctx->bitstream_buffers);
67 
68  return 0;
69 }
70 #endif
71 
73  const uint8_t *buf, uint32_t size)
74 {
75  VdpBitstreamBuffer *buffers = pic_ctx->bitstream_buffers;
76 
77  buffers = av_fast_realloc(buffers, &pic_ctx->bitstream_buffers_allocated,
78  (pic_ctx->bitstream_buffers_used + 1) * sizeof(*buffers));
79  if (!buffers)
80  return AVERROR(ENOMEM);
81 
82  pic_ctx->bitstream_buffers = buffers;
83  buffers += pic_ctx->bitstream_buffers_used++;
84 
85  buffers->struct_version = VDP_BITSTREAM_BUFFER_VERSION;
86  buffers->bitstream = buf;
87  buffers->bitstream_bytes = size;
88  return 0;
89 }
90 
91 int av_vdpau_get_profile(AVCodecContext *avctx, VdpDecoderProfile *profile)
92 {
93 #define PROFILE(prof) \
94 do { \
95  *profile = prof; \
96  return 0; \
97 } while (0)
98 
99  switch (avctx->codec_id) {
100  case AV_CODEC_ID_MPEG1VIDEO: PROFILE(VDP_DECODER_PROFILE_MPEG1);
102  switch (avctx->profile) {
103  case FF_PROFILE_MPEG2_MAIN: PROFILE(VDP_DECODER_PROFILE_MPEG2_MAIN);
104  case FF_PROFILE_MPEG2_SIMPLE: PROFILE(VDP_DECODER_PROFILE_MPEG2_SIMPLE);
105  default: return AVERROR(EINVAL);
106  }
107  case AV_CODEC_ID_H263: PROFILE(VDP_DECODER_PROFILE_MPEG4_PART2_ASP);
108  case AV_CODEC_ID_MPEG4:
109  switch (avctx->profile) {
110  case FF_PROFILE_MPEG4_SIMPLE: PROFILE(VDP_DECODER_PROFILE_MPEG4_PART2_SP);
111  case FF_PROFILE_MPEG4_ADVANCED_SIMPLE: PROFILE(VDP_DECODER_PROFILE_MPEG4_PART2_ASP);
112  default: return AVERROR(EINVAL);
113  }
114  case AV_CODEC_ID_H264:
115  switch (avctx->profile & ~FF_PROFILE_H264_INTRA) {
117  case FF_PROFILE_H264_BASELINE: PROFILE(VDP_DECODER_PROFILE_H264_BASELINE);
118  case FF_PROFILE_H264_MAIN: PROFILE(VDP_DECODER_PROFILE_H264_MAIN);
119  case FF_PROFILE_H264_HIGH: PROFILE(VDP_DECODER_PROFILE_H264_HIGH);
120  default: return AVERROR(EINVAL);
121  }
122  case AV_CODEC_ID_WMV3:
123  case AV_CODEC_ID_VC1:
124  switch (avctx->profile) {
125  case FF_PROFILE_VC1_SIMPLE: PROFILE(VDP_DECODER_PROFILE_VC1_SIMPLE);
126  case FF_PROFILE_VC1_MAIN: PROFILE(VDP_DECODER_PROFILE_VC1_MAIN);
127  case FF_PROFILE_VC1_ADVANCED: PROFILE(VDP_DECODER_PROFILE_VC1_ADVANCED);
128  default: return AVERROR(EINVAL);
129  }
130  }
131  return AVERROR(EINVAL);
132 }
133 
135 {
136  return av_mallocz(sizeof(AVVDPAUContext));
137 }
138 
139 /* @}*/
#define FF_PROFILE_H264_MAIN
Definition: avcodec.h:2649
#define FF_PROFILE_MPEG4_SIMPLE
Definition: avcodec.h:2666
#define FF_PROFILE_MPEG2_MAIN
Definition: avcodec.h:2641
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
#define FF_PROFILE_H264_INTRA
Definition: avcodec.h:2645
int bitstream_buffers_used
Useful bitstream buffers in the bitstream buffers table.
Public libavcodec VDPAU header.
int profile
profile
Definition: avcodec.h:2616
AVVDPAUContext * av_vdpau_alloc_context(void)
Allocate an AVVDPAUContext.
Definition: vdpau.c:134
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
Definition: mpegvideo.c:2361
VdpBitstreamBuffer * bitstream_buffers
Table of bitstream buffers.
#define FF_PROFILE_H264_BASELINE
Definition: avcodec.h:2647
uint8_t
void * hwaccel_context
Hardware accelerator context.
Definition: avcodec.h:2438
VdpDecoder decoder
VDPAU decoder handle.
Definition: vdpau.h:88
int av_vdpau_get_profile(AVCodecContext *avctx, VdpDecoderProfile *profile)
Get a decoder profile that should be used for initializing a VDPAU decoder.
Definition: vdpau.c:91
H.264 / AVC / MPEG4 part10 codec.
#define PROFILE(prof)
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
Definition: mem.c:369
This structure is used to share data between the libavcodec library and the client video application...
Definition: vdpau.h:82
#define AVERROR(e)
Definition: error.h:43
#define FF_PROFILE_H264_HIGH
Definition: avcodec.h:2651
int bitstream_buffers_allocated
Allocated size of the bitstream_buffers table.
#define FF_PROFILE_VC1_MAIN
Definition: avcodec.h:2662
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:310
Picture.
Definition: mpegvideo.h:99
void * hwaccel_picture_private
hardware accelerator private data
Definition: mpegvideo.h:131
static char buffer[20]
Definition: seek-test.c:31
#define FF_PROFILE_VC1_SIMPLE
Definition: avcodec.h:2661
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:110
NULL
Definition: eval.c:55
Libavcodec external API header.
enum AVCodecID codec_id
Definition: avcodec.h:1061
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
main external API structure.
Definition: avcodec.h:1044
#define FF_PROFILE_MPEG4_ADVANCED_SIMPLE
Definition: avcodec.h:2681
struct AVFrame * f
Definition: mpegvideo.h:100
VdpDecoderRender * render
VDPAU decoder render callback.
Definition: vdpau.h:95
MpegEncContext.
Definition: mpegvideo.h:204
struct AVCodecContext * avctx
Definition: mpegvideo.h:221
int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx, const uint8_t *buf, uint32_t size)
Definition: vdpau.c:72
void * priv_data
Definition: avcodec.h:1086
#define FF_PROFILE_VC1_ADVANCED
Definition: avcodec.h:2664
#define FF_PROFILE_MPEG2_SIMPLE
Definition: avcodec.h:2642
#define FF_PROFILE_H264_CONSTRAINED_BASELINE
Definition: avcodec.h:2648
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
#define av_unused
Definition: attributes.h:86
static uintptr_t ff_vdpau_get_surface_id(AVFrame *pic)
Extract VdpVideoSurface from an AVFrame.