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

libavcodec/vda_h264.c

Go to the documentation of this file.
00001 /*
00002  * VDA H.264 hardware acceleration
00003  *
00004  * copyright (c) 2011 Sebastien Zwickert
00005  *
00006  * This file is part of Libav.
00007  *
00008  * Libav 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  * Libav 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 Libav; 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 "h264data.h"
00025 
00026 #include "vda_internal.h"
00027 
00028 /* This structure is used to store the bitstream of the current frame. */
00029 struct vda_picture_context {
00030     uint8_t *bitstream;
00031     int      bitstream_size;
00032 };
00033 
00034 static int start_frame(AVCodecContext *avctx,
00035                        av_unused const uint8_t *buffer,
00036                        av_unused uint32_t size)
00037 {
00038     const H264Context *h                = avctx->priv_data;
00039     struct vda_context *vda_ctx         = avctx->hwaccel_context;
00040     struct vda_picture_context *pic_ctx = h->s.current_picture_ptr->f.hwaccel_picture_private;
00041 
00042     if (!vda_ctx->decoder)
00043         return -1;
00044 
00045     pic_ctx->bitstream      = NULL;
00046     pic_ctx->bitstream_size = 0;
00047 
00048     return 0;
00049 }
00050 
00051 static int decode_slice(AVCodecContext *avctx,
00052                         const uint8_t *buffer,
00053                         uint32_t size)
00054 {
00055     H264Context *h                      = avctx->priv_data;
00056     struct vda_context *vda_ctx         = avctx->hwaccel_context;
00057     struct vda_picture_context *pic_ctx = h->s.current_picture_ptr->f.hwaccel_picture_private;
00058     void *tmp;
00059 
00060     if (!vda_ctx->decoder)
00061         return -1;
00062 
00063     tmp = av_realloc(pic_ctx->bitstream, pic_ctx->bitstream_size+size+4);
00064     if (!tmp)
00065         return AVERROR(ENOMEM);
00066 
00067     pic_ctx->bitstream = tmp;
00068 
00069     AV_WB32(pic_ctx->bitstream + pic_ctx->bitstream_size, size);
00070     memcpy(pic_ctx->bitstream + pic_ctx->bitstream_size + 4, buffer, size);
00071 
00072     pic_ctx->bitstream_size += size + 4;
00073 
00074     return 0;
00075 }
00076 
00077 static int end_frame(AVCodecContext *avctx)
00078 {
00079     H264Context *h                      = avctx->priv_data;
00080     struct vda_context *vda_ctx         = avctx->hwaccel_context;
00081     struct vda_picture_context *pic_ctx = h->s.current_picture_ptr->f.hwaccel_picture_private;
00082     AVFrame *frame                      = &h->s.current_picture_ptr->f;
00083     int status;
00084 
00085     if (!vda_ctx->decoder || !pic_ctx->bitstream)
00086         return -1;
00087 
00088     status = ff_vda_decoder_decode(vda_ctx, pic_ctx->bitstream,
00089                                    pic_ctx->bitstream_size,
00090                                    frame->reordered_opaque);
00091 
00092     if (status)
00093         av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
00094 
00095     av_freep(&pic_ctx->bitstream);
00096 
00097     return status;
00098 }
00099 
00100 AVHWAccel ff_h264_vda_hwaccel = {
00101     .name           = "h264_vda",
00102     .type           = AVMEDIA_TYPE_VIDEO,
00103     .id             = CODEC_ID_H264,
00104     .pix_fmt        = PIX_FMT_VDA_VLD,
00105     .start_frame    = start_frame,
00106     .decode_slice   = decode_slice,
00107     .end_frame      = end_frame,
00108     .priv_data_size = sizeof(struct vda_picture_context),
00109 };
Generated on Thu Jul 11 2013 15:38:22 for Libav by doxygen 1.7.1