00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 };