Go to the documentation of this file.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 "h264data.h"
00025
00026 #include "vda_internal.h"
00027
00028
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 };