From patchwork Sun Oct 9 17:50:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Langdale X-Patchwork-Id: 930 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp2126515vsd; Sun, 9 Oct 2016 11:01:13 -0700 (PDT) X-Received: by 10.194.22.103 with SMTP id c7mr11032312wjf.34.1476036073258; Sun, 09 Oct 2016 11:01:13 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ma1si10175102wjb.183.2016.10.09.11.01.12; Sun, 09 Oct 2016 11:01:13 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@overt.org; dkim=neutral (body hash did not verify) header.i=@overt.org; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C223F689B2D; Sun, 9 Oct 2016 21:00:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from rs224.mailgun.us (rs224.mailgun.us [209.61.151.224]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E4341689AD0 for ; Sun, 9 Oct 2016 21:00:43 +0300 (EEST) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=overt.org; q=dns/txt; s=k1; t=1476036060; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=yZXMax3sXUacyKsjNNyqXk6O8Mba7sSwjyutxQ5JbGk=; b=dueeqfNSEhlS3XPB1XyyC7264t5MGCVdQlnikmzcZfyAqV90TwuLzICDq7pk5bEpzGy8hCae 8hhHf9i7H1HvyxBnOTRjmpJcup04/aeaPYoQpoKzdl8BmJvUgNNig3Jdr9lIkg4qIgWMq2Um vMsPeMED487R8H5OwSXL0rGvcpQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=overt.org; s=k1; q=dns; h=Sender: From: To: Cc: Subject: Date: Message-Id: In-Reply-To: References; b=CaDa7Lo2Jx1V5aw2UvN96csg5+7lZ97Dna4bfOHWCKfRsBsuqDbT6cDduZBeoNlSCWB8o9 +3/pDltjBQcfJQtGeSoEMG7fwDVNM8ZFuidw6iIDiGg7y9+2wuQVKuI7QQBw6VbbVC32FjqI yhOAok2R4L9wVhgKYRXdliyBv61l8= X-Mailgun-Sending-Ip: 209.61.151.224 X-Mailgun-Sid: WyIyM2Q3MCIsICJmZm1wZWctZGV2ZWxAZmZtcGVnLm9yZyIsICI0YTg5NjEiXQ== Received: from mail.overt.org (155.208.178.107.bc.googleusercontent.com [107.178.208.155]) by mxa.mailgun.org with ESMTP id 57fa835c.7f745ed91068-in02; Sun, 09 Oct 2016 17:50:20 -0000 (UTC) Received: from authenticated-user (mail.overt.org [107.178.208.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.overt.org (Postfix) with ESMTPSA id 06C99607AE; Sun, 9 Oct 2016 17:50:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=overt.org; s=mail; t=1476035420; bh=NlqJ5hnQGmb9UD88/4/uYe+ilTtc2LW2oEXvbW7WBpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V/wpVBYeZr4JVJzFEapwTD0/e2ROOSvbs/CHQY7Tf9DIMiacAJtXtimKXwi86AuXn Ylw/sH/RHRVipMWQmzhkNopH1hM79XLGmOcWYQe55z2vs2b+9caeiXGHJzccEvuqbJ mSBAsSrDRlbv4UYdjaDn+K7I94TxnSI06vP2zw/r5jWCZGraASsFl2PLKyZBAf2ajF Y01jjSmDoAtd6sKg62qOm4j0y9o5DOpbe/G9oiBeHW1298KV2xxTGFMB7+aI4vRwEz D3VXnWCzX6UEBJUWdL8S3oI/8Y8MUMxyYBJ84SUSDlLB6MBj6twW3WOpwsVyZi78mo FgtizD1T0lnow== From: Philip Langdale To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Oct 2016 10:50:13 -0700 Message-Id: <1476035413-16516-3-git-send-email-philipl@overt.org> In-Reply-To: <1476035413-16516-1-git-send-email-philipl@overt.org> References: <1476035413-16516-1-git-send-email-philipl@overt.org> Subject: [FFmpeg-devel] [PATCH 2/2] crystalhd: Use mpeg4_unpack_bframes to avoid buggy crystalhd handling X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Philip Langdale MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The hardware handling of packed bframes was always questionable but it used to ok with my workaround. Today, not so much. But today we have a bsf to unpack the bframes, so let's just use that and be done with it. --- libavcodec/crystalhd.c | 127 ++++++++++++++++++++++++------------------------- 1 file changed, 63 insertions(+), 64 deletions(-) diff --git a/libavcodec/crystalhd.c b/libavcodec/crystalhd.c index 83be8e5..9120940 100644 --- a/libavcodec/crystalhd.c +++ b/libavcodec/crystalhd.c @@ -150,7 +150,6 @@ typedef struct { /* Options */ uint32_t sWidth; - uint8_t bframe_bug; } CHDContext; static const AVOption options[] = { @@ -379,9 +378,59 @@ static av_cold int uninit(AVCodecContext *avctx) } +static av_cold int init_bsf(AVCodecContext *avctx, const char *bsf_name) +{ + CHDContext *priv = avctx->priv_data; + const AVBitStreamFilter *bsf; + int avret; + void *extradata = NULL; + size_t size = 0; + + bsf = av_bsf_get_by_name(bsf_name); + if (!bsf) { + av_log(avctx, AV_LOG_ERROR, + "Cannot open the %s BSF!\n", bsf_name); + return AVERROR_BSF_NOT_FOUND; + } + + avret = av_bsf_alloc(bsf, &priv->bsfc); + if (avret != 0) { + return avret; + } + + avret = avcodec_parameters_from_context(priv->bsfc->par_in, avctx); + if (avret != 0) { + return avret; + } + + avret = av_bsf_init(priv->bsfc); + if (avret != 0) { + return avret; + } + + /* Back up the extradata so it can be restored at close time. */ + priv->orig_extradata = avctx->extradata; + priv->orig_extradata_size = avctx->extradata_size; + + size = priv->bsfc->par_out->extradata_size; + extradata = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!extradata) { + av_log(avctx, AV_LOG_ERROR, + "Failed to allocate copy of extradata\n"); + return AVERROR(ENOMEM); + } + memcpy(extradata, priv->bsfc->par_out->extradata, size); + + avctx->extradata = extradata; + avctx->extradata_size = size; + + return 0; +} + static av_cold int init(AVCodecContext *avctx) { CHDContext* priv; + int avret; BC_STATUS ret; BC_INFO_CRYSTAL version; BC_INPUT_FORMAT format = { @@ -417,46 +466,22 @@ static av_cold int init(AVCodecContext *avctx) subtype = id2subtype(priv, avctx->codec->id); switch (subtype) { case BC_MSUBTYPE_AVC1: - { - const AVBitStreamFilter *bsf; - int avret; - - bsf = av_bsf_get_by_name("h264_mp4toannexb"); - if (!bsf) { - av_log(avctx, AV_LOG_ERROR, - "Cannot open the h264_mp4toannexb BSF!\n"); - return AVERROR_BSF_NOT_FOUND; - } - avret = av_bsf_alloc(bsf, &priv->bsfc); - if (avret != 0) { - return AVERROR(ENOMEM); - } - avret = avcodec_parameters_from_context(priv->bsfc->par_in, avctx); - if (avret != 0) { - return AVERROR(ENOMEM); - } - avret = av_bsf_init(priv->bsfc); - if (avret != 0) { - return AVERROR(ENOMEM); - } - - format.metaDataSz = priv->bsfc->par_out->extradata_size; - format.pMetaData = av_malloc(format.metaDataSz + AV_INPUT_BUFFER_PADDING_SIZE); - if (!format.pMetaData) { - av_log(avctx, AV_LOG_ERROR, - "Failed to allocate copy of extradata\n"); - return AVERROR(ENOMEM); - } - memcpy(format.pMetaData, priv->bsfc->par_out->extradata, format.metaDataSz); - - /* Back up the extradata so it can be restored at close time. */ - priv->orig_extradata = avctx->extradata; - priv->orig_extradata_size = avctx->extradata_size; - avctx->extradata = format.pMetaData; - avctx->extradata_size = format.metaDataSz; + avret = init_bsf(avctx, "h264_mp4toannexb"); + if (avret != 0) { + return avret; } subtype = BC_MSUBTYPE_H264; format.startCodeSz = 4; + format.pMetaData = avctx->extradata; + format.metaDataSz = avctx->extradata_size; + break; + case BC_MSUBTYPE_DIVX: + avret = init_bsf(avctx, "mpeg4_unpack_bframes"); + if (avret != 0) { + return avret; + } + format.pMetaData = avctx->extradata; + format.metaDataSz = avctx->extradata_size; break; case BC_MSUBTYPE_H264: format.startCodeSz = 4; @@ -466,7 +491,6 @@ static av_cold int init(AVCodecContext *avctx) case BC_MSUBTYPE_WMV3: case BC_MSUBTYPE_WMVA: case BC_MSUBTYPE_MPEG2VIDEO: - case BC_MSUBTYPE_DIVX: case BC_MSUBTYPE_DIVX311: format.pMetaData = avctx->extradata; format.metaDataSz = avctx->extradata_size; @@ -839,15 +863,6 @@ static inline CopyRet receive_frame(AVCodecContext *avctx, priv->last_picture = output.PicInfo.picture_number - 1; } - if (avctx->codec->id == AV_CODEC_ID_MPEG4 && - output.PicInfo.timeStamp == 0 && priv->bframe_bug) { - av_log(avctx, AV_LOG_VERBOSE, - "CrystalHD: Not returning packed frame twice.\n"); - priv->last_picture++; - DtsReleaseOutputBuffs(dev, NULL, FALSE); - return RET_COPY_AGAIN; - } - print_frame_info(priv, &output); if (priv->last_picture + 1 < output.PicInfo.picture_number) { @@ -908,22 +923,6 @@ static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *a av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: decode_frame\n"); - if (avpkt->size == 7 && !priv->bframe_bug) { - /* - * The use of a drop frame triggers the bug - */ - av_log(avctx, AV_LOG_INFO, - "CrystalHD: Enabling work-around for packed b-frame bug\n"); - priv->bframe_bug = 1; - } else if (avpkt->size == 8 && priv->bframe_bug) { - /* - * Delay frames don't trigger the bug - */ - av_log(avctx, AV_LOG_INFO, - "CrystalHD: Disabling work-around for packed b-frame bug\n"); - priv->bframe_bug = 0; - } - if (len) { int32_t tx_free = (int32_t)DtsTxFreeSize(dev);