2 * VDA H.264 hardware acceleration
4 * copyright (c) 2011 Sebastien Zwickert
6 * This file is part of Libav.
8 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "vda_internal.h"
28 /* This structure is used to store the bitstream of the current frame. */
29 struct vda_picture_context {
34 static int start_frame(AVCodecContext *avctx,
35 av_unused const uint8_t *buffer,
36 av_unused uint32_t size)
38 const H264Context *h = avctx->priv_data;
39 struct vda_context *vda_ctx = avctx->hwaccel_context;
40 struct vda_picture_context *pic_ctx = h->s.current_picture_ptr->f.hwaccel_picture_private;
42 if (!vda_ctx->decoder)
45 pic_ctx->bitstream = NULL;
46 pic_ctx->bitstream_size = 0;
51 static int decode_slice(AVCodecContext *avctx,
52 const uint8_t *buffer,
55 H264Context *h = avctx->priv_data;
56 struct vda_context *vda_ctx = avctx->hwaccel_context;
57 struct vda_picture_context *pic_ctx = h->s.current_picture_ptr->f.hwaccel_picture_private;
60 if (!vda_ctx->decoder)
63 tmp = av_realloc(pic_ctx->bitstream, pic_ctx->bitstream_size+size+4);
65 return AVERROR(ENOMEM);
67 pic_ctx->bitstream = tmp;
69 AV_WB32(pic_ctx->bitstream + pic_ctx->bitstream_size, size);
70 memcpy(pic_ctx->bitstream + pic_ctx->bitstream_size + 4, buffer, size);
72 pic_ctx->bitstream_size += size + 4;
77 static int end_frame(AVCodecContext *avctx)
79 H264Context *h = avctx->priv_data;
80 struct vda_context *vda_ctx = avctx->hwaccel_context;
81 struct vda_picture_context *pic_ctx = h->s.current_picture_ptr->f.hwaccel_picture_private;
82 AVFrame *frame = &h->s.current_picture_ptr->f;
85 if (!vda_ctx->decoder || !pic_ctx->bitstream)
88 status = ff_vda_decoder_decode(vda_ctx, pic_ctx->bitstream,
89 pic_ctx->bitstream_size,
90 frame->reordered_opaque);
93 av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
95 av_freep(&pic_ctx->bitstream);
100 AVHWAccel ff_h264_vda_hwaccel = {
102 .type = AVMEDIA_TYPE_VIDEO,
104 .pix_fmt = PIX_FMT_VDA_VLD,
105 .start_frame = start_frame,
106 .decode_slice = decode_slice,
107 .end_frame = end_frame,
108 .priv_data_size = sizeof(struct vda_picture_context),