mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-26 19:01:44 +02:00
d404fe35b2
Using VDPAU correctly means checking for preemption and possibly regenerating the context all the time. With the current API there is no context or other user-defined pointer and thus this in not possible during decoding unless using some hack like global variables. The need to reinitialize both surfaces and even function pointers makes handling preemption even more difficult. This patch introduces a new render2 function that gets both the AVCodecContext and AVFrame in addition, in both the user can store additional opaque data. This allows even advanced approaches like keeping a "generation counter" for the surfaces so they can be regenerated on the fly and efficiently. In addition, the function has a return value that will be passed through all the way instead of being silently ignored as for the current render function. Unfortunately the HWAccel API has no way of providing API/ABI compatibility, so a currently disallowed state (render pointer being NULL) is used to extend it. Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
105 lines
3.3 KiB
C
105 lines
3.3 KiB
C
/*
|
|
* Video Decode and Presentation API for UNIX (VDPAU) is used for
|
|
* HW decode acceleration for MPEG-1/2, MPEG-4 ASP, H.264 and VC-1.
|
|
*
|
|
* Copyright (c) 2008 NVIDIA
|
|
*
|
|
* This file is part of FFmpeg.
|
|
*
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#include <limits.h>
|
|
#include "avcodec.h"
|
|
#include "h264.h"
|
|
#include "vc1.h"
|
|
|
|
#undef NDEBUG
|
|
#include <assert.h>
|
|
|
|
#include "vdpau.h"
|
|
#include "vdpau_internal.h"
|
|
|
|
/**
|
|
* @addtogroup VDPAU_Decoding
|
|
*
|
|
* @{
|
|
*/
|
|
|
|
AVVDPAUContext *av_alloc_vdpaucontext(void)
|
|
{
|
|
return av_mallocz(sizeof(AVVDPAUContext));
|
|
}
|
|
|
|
MAKE_ACCESSORS(AVVDPAUContext, vdpau_hwaccel, AVVDPAU_Render2, render2)
|
|
|
|
int ff_vdpau_common_start_frame(Picture *pic,
|
|
av_unused const uint8_t *buffer,
|
|
av_unused uint32_t size)
|
|
{
|
|
struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
|
|
|
|
pic_ctx->bitstream_buffers_allocated = 0;
|
|
pic_ctx->bitstream_buffers_used = 0;
|
|
pic_ctx->bitstream_buffers = NULL;
|
|
return 0;
|
|
}
|
|
|
|
#if CONFIG_H263_VDPAU_HWACCEL || CONFIG_MPEG1_VDPAU_HWACCEL || \
|
|
CONFIG_MPEG2_VDPAU_HWACCEL || CONFIG_MPEG4_VDPAU_HWACCEL || \
|
|
CONFIG_VC1_VDPAU_HWACCEL || CONFIG_WMV3_VDPAU_HWACCEL
|
|
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
|
|
{
|
|
int res = 0;
|
|
AVVDPAUContext *hwctx = avctx->hwaccel_context;
|
|
MpegEncContext *s = avctx->priv_data;
|
|
Picture *pic = s->current_picture_ptr;
|
|
struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
|
|
VdpVideoSurface surf = ff_vdpau_get_surface_id(pic);
|
|
|
|
if (!hwctx->render) {
|
|
res = hwctx->render2(avctx, &pic->f, (void *)&pic_ctx->info,
|
|
pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers);
|
|
} else
|
|
hwctx->render(hwctx->decoder, surf, (void *)&pic_ctx->info,
|
|
pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers);
|
|
|
|
ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
|
|
av_freep(&pic_ctx->bitstream_buffers);
|
|
|
|
return res;
|
|
}
|
|
#endif
|
|
|
|
int ff_vdpau_add_buffer(Picture *pic, const uint8_t *buf, uint32_t size)
|
|
{
|
|
struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
|
|
VdpBitstreamBuffer *buffers = pic_ctx->bitstream_buffers;
|
|
|
|
buffers = av_fast_realloc(buffers, &pic_ctx->bitstream_buffers_allocated,
|
|
(pic_ctx->bitstream_buffers_used + 1) * sizeof(*buffers));
|
|
if (!buffers)
|
|
return AVERROR(ENOMEM);
|
|
|
|
pic_ctx->bitstream_buffers = buffers;
|
|
buffers += pic_ctx->bitstream_buffers_used++;
|
|
|
|
buffers->struct_version = VDP_BITSTREAM_BUFFER_VERSION;
|
|
buffers->bitstream = buf;
|
|
buffers->bitstream_bytes = size;
|
|
return 0;
|
|
}
|
|
/* @}*/
|