• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/vda_h264.c

Go to the documentation of this file.
00001 /*
00002  * VDA H264 HW acceleration.
00003  *
00004  * copyright (c) 2011 Sebastien Zwickert
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #include "h264.h"
00024 #include "vda_internal.h"
00025 
00026 static int start_frame(AVCodecContext *avctx,
00027                        av_unused const uint8_t *buffer,
00028                        av_unused uint32_t size)
00029 {
00030     struct vda_context *vda_ctx = avctx->hwaccel_context;
00031 
00032     if (!vda_ctx->decoder)
00033         return -1;
00034 
00035     vda_ctx->bitstream_size = 0;
00036 
00037     return 0;
00038 }
00039 
00040 static int decode_slice(AVCodecContext *avctx,
00041                         const uint8_t *buffer,
00042                         uint32_t size)
00043 {
00044     struct vda_context *vda_ctx = avctx->hwaccel_context;
00045     void *tmp;
00046 
00047     if (!vda_ctx->decoder)
00048         return -1;
00049 
00050     tmp = av_fast_realloc(vda_ctx->bitstream, &vda_ctx->ref_size, vda_ctx->bitstream_size+size+4);
00051     if (!tmp)
00052         return AVERROR(ENOMEM);
00053 
00054     vda_ctx->bitstream = tmp;
00055 
00056     AV_WB32(vda_ctx->bitstream+vda_ctx->bitstream_size, size);
00057     memcpy(vda_ctx->bitstream+vda_ctx->bitstream_size+4, buffer, size);
00058 
00059     vda_ctx->bitstream_size += size + 4;
00060 
00061     return 0;
00062 }
00063 
00064 static int end_frame(AVCodecContext *avctx)
00065 {
00066     H264Context *h = avctx->priv_data;
00067     struct vda_context *vda_ctx = avctx->hwaccel_context;
00068     AVFrame *frame = &h->s.current_picture_ptr->f;
00069     int status;
00070 
00071     if (!vda_ctx->decoder || !vda_ctx->bitstream)
00072         return -1;
00073 
00074     status = ff_vda_decoder_decode(vda_ctx, vda_ctx->bitstream,
00075                                    vda_ctx->bitstream_size,
00076                                    frame->reordered_opaque);
00077 
00078     if (status)
00079         av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
00080 
00081     return status;
00082 }
00083 
00084 AVHWAccel ff_h264_vda_hwaccel = {
00085     .name           = "h264_vda",
00086     .type           = AVMEDIA_TYPE_VIDEO,
00087     .id             = CODEC_ID_H264,
00088     .pix_fmt        = PIX_FMT_VDA_VLD,
00089     .start_frame    = start_frame,
00090     .decode_slice   = decode_slice,
00091     .end_frame      = end_frame,
00092     .priv_data_size = 0,
00093 };
Generated on Fri Feb 1 2013 14:34:45 for FFmpeg by doxygen 1.7.1