H.264 On Sun, Aug 31, 2014 at 09:24:29PM +0200, Luca Barbato wrote: > Originally written by Luca Barbato <lu_z...@gentoo.org>. > Further contributions by Yukinori Yamazoe <droco...@gmail.com>. > --- > configure | 7 + > libavcodec/Makefile | 3 + > libavcodec/allcodecs.c | 1 + > libavcodec/qsv.c | 470 > ++++++++++++++++++++++++++++++++++++++++++++++ > libavcodec/qsv.h | 54 ++++++ > libavcodec/qsv_h264.c | 153 +++++++++++++++ > libavcodec/qsv_internal.h | 47 +++++ > 7 files changed, 735 insertions(+) > create mode 100644 libavcodec/qsv.c > create mode 100644 libavcodec/qsv.h > create mode 100644 libavcodec/qsv_h264.c > create mode 100644 libavcodec/qsv_internal.h
Changelog, version, docs. > --- /dev/null > +++ b/libavcodec/qsv.c > @@ -0,0 +1,470 @@ > + > +#include "libavutil/common.h" > +#include "libavutil/mem.h" > +#include "libavutil/log.h" > +#include "libavutil/time.h" > +#include "internal.h" > +#include "avcodec.h" > +#include "qsv.h" > +#include "qsv_internal.h" empty line between header groups > + switch (mfx_err) { > + case MFX_ERR_NONE: > + return 0; > + case MFX_ERR_MEMORY_ALLOC: > + case MFX_ERR_NOT_ENOUGH_BUFFER: > + return AVERROR(ENOMEM); > + case MFX_ERR_INVALID_HANDLE: > + return AVERROR(EINVAL); > + case MFX_ERR_DEVICE_FAILED: > + case MFX_ERR_DEVICE_LOST: > + case MFX_ERR_LOCK_MEMORY: > + return AVERROR(EIO); > + case MFX_ERR_NULL_PTR: > + case MFX_ERR_UNDEFINED_BEHAVIOR: > + case MFX_ERR_NOT_INITIALIZED: > + return AVERROR_BUG; > + case MFX_ERR_UNSUPPORTED: > + case MFX_ERR_NOT_FOUND: > + return AVERROR(ENOSYS); > + case MFX_ERR_MORE_DATA: > + case MFX_ERR_MORE_SURFACE: > + case MFX_ERR_MORE_BITSTREAM: > + return AVERROR(EAGAIN); > + case MFX_ERR_INCOMPATIBLE_VIDEO_PARAM: > + case MFX_ERR_INVALID_VIDEO_PARAM: > + return AVERROR(EINVAL); > + case MFX_ERR_ABORTED: > + case MFX_ERR_UNKNOWN: > + default: > + return AVERROR_UNKNOWN; Merge the EINVAL blocks. > +static int codec_id_to_mfx(enum AVCodecID codec_id) > +{ > + switch (codec_id) { > + case AV_CODEC_ID_H264: > + return MFX_CODEC_AVC; > + case AV_CODEC_ID_MPEG1VIDEO: > + case AV_CODEC_ID_MPEG2VIDEO: > + return MFX_CODEC_MPEG2; > + case AV_CODEC_ID_VC1: > + return MFX_CODEC_VC1; > + default: > + break; > + } > + > + return AVERROR(ENOSYS); > +} Directly return from the default label instead of breaking and then returning. > + q->surfaces[i].Data.U = q->surfaces[i].Data.Y + width * height; > + q->surfaces[i].Data.V = q->surfaces[i].Data.U + 1; > + q->surfaces[i].Data.Pitch = width; > + q->surfaces[i].Info = q->param.mfx.FrameInfo; > + q->pts[i] = q->dts[i] = AV_NOPTS_VALUE; align > +static int qsv_reinit(AVCodecContext *c, QSVContext *q) > +{ > + int ret; > + > + ret = ff_qsv_init(c, q); > + > + q->reinit = 0; > + > + return 0; You're ignoring the return value. > + } else if (!size && bs) { > + // Flush cached frames when EOF s/when/on/ > + if (q->reinit) { > + // We are done flushing the decoded frame queue > + av_log(avctx, AV_LOG_VERBOSE, "Calling reinit\n"); > + if ((ret = qsv_reinit(avctx, q)) < 0) > + return ret; Looks like a leftover debug av_log. > --- /dev/null > +++ b/libavcodec/qsv_h264.c > @@ -0,0 +1,153 @@ > + > +static int qsv_dec_frame(AVCodecContext *avctx, void *data, > + int *got_frame, AVPacket *avpkt) This is usually called decode_frame. > +static void qsv_dec_flush(AVCodecContext *avctx) same, either qsv_decode_flush or - even better - qsv_flush. > +av_cold int av_qsv_default_init(AVCodecContext *avctx) > +{ > + QSVH264Context *q = av_mallocz(sizeof(*q)); > + mfxBitstream *bs = &q->qsv.bs; > + int ret; > + > + if (avctx->codec_id != AV_CODEC_ID_H264) > + return AVERROR(ENOSYS); > + > + if (!q) > + return AVERROR(ENOMEM); I suspect that this might warn about mixed declarations and statements. You should malloc after checking the codec id, otherwise there is a potential memory leak I think. Maybe the allocation gets freed somewhere else, but it would still be cleaner to skip the allocation then. > + //FIXME feed it a fake IDR directly nit: space after // > + bs->Data = av_malloc(avctx->extradata_size + sizeof(fake_idr)); > + bs->DataLength = avctx->extradata_size; align The malloc is unchecked. > --- /dev/null > +++ b/libavcodec/qsv_internal.h > @@ -0,0 +1,47 @@ > + > +#ifndef AVCODEC_QSV_INTERNAL_H > +#define AVCODEC_QSV_INTERNAL_H > + > +#define QSV_VERSION_MAJOR 1 > +#define QSV_VERSION_MINOR 1 This is only used in one place, no need to have it in the header. Diego _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel