2 * VDA H264 HW acceleration.
4 * copyright (c) 2011 Sebastien Zwickert
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "vda_internal.h"
25 /* This structure is used to store the bitstream of the current frame. */
26 struct vda_picture_context {
31 static int start_frame(AVCodecContext *avctx,
32 av_unused const uint8_t *buffer,
33 av_unused uint32_t size)
35 const H264Context *h = avctx->priv_data;
36 struct vda_context *vda_ctx = avctx->hwaccel_context;
37 struct vda_picture_context *pic_ctx = h->s.current_picture_ptr->f.hwaccel_picture_private;
39 if (!vda_ctx->decoder)
42 pic_ctx->bitstream = NULL;
43 pic_ctx->bitstream_size = 0;
48 static int decode_slice(AVCodecContext *avctx,
49 const uint8_t *buffer,
52 H264Context *h = avctx->priv_data;
53 struct vda_context *vda_ctx = avctx->hwaccel_context;
54 struct vda_picture_context *pic_ctx = h->s.current_picture_ptr->f.hwaccel_picture_private;
57 if (!vda_ctx->decoder)
60 tmp = av_realloc(pic_ctx->bitstream, pic_ctx->bitstream_size+size+4);
62 return AVERROR(ENOMEM);
64 pic_ctx->bitstream = tmp;
66 AV_WB32(pic_ctx->bitstream+pic_ctx->bitstream_size, size);
67 memcpy(pic_ctx->bitstream+pic_ctx->bitstream_size+4, buffer, size);
69 pic_ctx->bitstream_size += size + 4;
74 static int end_frame(AVCodecContext *avctx)
76 H264Context *h = avctx->priv_data;
77 struct vda_context *vda_ctx = avctx->hwaccel_context;
78 struct vda_picture_context *pic_ctx = h->s.current_picture_ptr->f.hwaccel_picture_private;
79 AVFrame *frame = (AVFrame*)h->s.current_picture_ptr;
82 if (!vda_ctx->decoder || !pic_ctx->bitstream)
85 status = ff_vda_decoder_decode(vda_ctx, pic_ctx->bitstream,
86 pic_ctx->bitstream_size,
87 frame->reordered_opaque);
90 av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
92 av_freep(&pic_ctx->bitstream);
97 AVHWAccel ff_h264_vda_hwaccel = {
99 .type = AVMEDIA_TYPE_VIDEO,
101 .pix_fmt = PIX_FMT_VDA_VLD,
103 .start_frame = start_frame,
104 .decode_slice = decode_slice,
105 .end_frame = end_frame,
106 .priv_data_size = sizeof(struct vda_picture_context),