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
24 #include "vda_internal.h"
26 static int start_frame(AVCodecContext *avctx,
27 av_unused const uint8_t *buffer,
28 av_unused uint32_t size)
30 struct vda_context *vda_ctx = avctx->hwaccel_context;
32 if (!vda_ctx->decoder)
35 vda_ctx->bitstream_size = 0;
40 static int decode_slice(AVCodecContext *avctx,
41 const uint8_t *buffer,
44 struct vda_context *vda_ctx = avctx->hwaccel_context;
47 if (!vda_ctx->decoder)
50 tmp = av_fast_realloc(vda_ctx->bitstream, &vda_ctx->ref_size, vda_ctx->bitstream_size+size+4);
52 return AVERROR(ENOMEM);
54 vda_ctx->bitstream = tmp;
56 AV_WB32(vda_ctx->bitstream+vda_ctx->bitstream_size, size);
57 memcpy(vda_ctx->bitstream+vda_ctx->bitstream_size+4, buffer, size);
59 vda_ctx->bitstream_size += size + 4;
64 static int end_frame(AVCodecContext *avctx)
66 H264Context *h = avctx->priv_data;
67 struct vda_context *vda_ctx = avctx->hwaccel_context;
68 AVFrame *frame = &h->s.current_picture_ptr->f;
71 if (!vda_ctx->decoder || !vda_ctx->bitstream)
74 status = ff_vda_decoder_decode(vda_ctx, vda_ctx->bitstream,
75 vda_ctx->bitstream_size,
76 frame->reordered_opaque);
79 av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
84 AVHWAccel ff_h264_vda_hwaccel = {
86 .type = AVMEDIA_TYPE_VIDEO,
88 .pix_fmt = PIX_FMT_VDA_VLD,
89 .start_frame = start_frame,
90 .decode_slice = decode_slice,
91 .end_frame = end_frame,