From patchwork Wed Oct 26 19:40:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Langdale X-Patchwork-Id: 1185 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.133 with SMTP id o127csp220046vsd; Wed, 26 Oct 2016 12:51:52 -0700 (PDT) X-Received: by 10.28.207.129 with SMTP id f123mr4437998wmg.18.1477511512347; Wed, 26 Oct 2016 12:51:52 -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 a202si12432558wma.65.2016.10.26.12.51.51; Wed, 26 Oct 2016 12:51:52 -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 B2CAD689E5C; Wed, 26 Oct 2016 22:51:19 +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 923AA689E39 for ; Wed, 26 Oct 2016 22:51:11 +0300 (EEST) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=overt.org; q=dns/txt; s=k1; t=1477511473; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=sbmD7uPpnwTVKSVEWbsjSfcj3gjCstfn1uUWE4f/STg=; b=ymuHSsRqFF8vmxlKpjnrfePWlKubGLri57A9CiYIoeRDhbUz0brBk2eOUIMNCaLP72vTqi9b ZHR0Ch9TYbIWQsvpLX9hJ5MVJ9f4iGzfkDa/X3xVtCJCWQq4o7JdqlGEF69dBv+eenHfawDs KyddNCEA/mixqfgW+JcGc85/7XQ= 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=wj3ZMx1E0QD43dq47zz+M1FbjT62RmDInHABKeSXUlG1tOJly+gDc7921urXoEggBaY303 c7TCB/JnOphrLmNZ6TjwWvxmvX7wWbxqoQUqQElc8j/NN5vnW2PGboDnar8jitzjtCpw9E4I DvO2rViK2VINFagtycV+n+zSsTPd4= 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 581106b5.7fbadfd82420-in02; Wed, 26 Oct 2016 19:40:37 -0000 (UTC) Received: from authenticated-user (mail.overt.org [107.178.208.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.overt.org (Postfix) with ESMTPSA id 068EE605BB; Wed, 26 Oct 2016 19:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=overt.org; s=mail; t=1477510837; bh=6bC6is2+YNJRgNhXNrftU6Y7uw3TTPPGj4egzKihyUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U4lXUwy9i3vaNIbAe8i3fAiJcV45Du2Q5PSYQOVGF9tpXi0BU590fOrZrnLvyyUBg +5D+whdgrmokVA1isM1KyIhbhJ01b+D1A6zzuN4jn5QBOzB8NT87S4n4nMV7hf98e1 8pP1GEWEVs4yBS708gXmZpq9PiyMmJwf32MeE7CrVBxsCKy/1VHYNiczJ7Vfol0TFW QNE2mZEQ5S1crRKiBQ5CEJ1pmzupc1v/9w9NVv0j2uhize/RcHUgAuYvOQoAe3Rn9X XBV2X6Rf45S6KsxHyRAeewR9cjCoCs3nK5iUfs5m3Iju+c7XSPw2y9iSb9EYjajbBY DDd5WwKHjVm8Q== From: Philip Langdale To: ffmpeg-devel@ffmpeg.org Date: Wed, 26 Oct 2016 12:40:26 -0700 Message-Id: <20161026194028.26438-9-philipl@overt.org> In-Reply-To: <20161026194028.26438-1-philipl@overt.org> References: <20161026194028.26438-1-philipl@overt.org> Subject: [FFmpeg-devel] [PATCH 08/10] crystalhd: Loop for a frame internally where possible. 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" It's not possible to return EAGAIN when we've passed input EOF and are in draining mode. If do return EAGAIN, we're saying there's no way to get any more output - which isn't true in many cases. So let's handled these cases in an internal loop as best we can. Signed-off-by: Philip Langdale --- libavcodec/crystalhd.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/libavcodec/crystalhd.c b/libavcodec/crystalhd.c index 4ac138c..2d803ab 100644 --- a/libavcodec/crystalhd.c +++ b/libavcodec/crystalhd.c @@ -105,6 +105,7 @@ typedef enum { RET_ERROR = -1, RET_OK = 0, + RET_COPY_AGAIN = 1, } CopyRet; typedef struct OpaqueList { @@ -129,6 +130,7 @@ typedef struct { uint32_t sps_pps_size; uint8_t is_nal; uint8_t need_second_field; + uint8_t draining; OpaqueList *head; OpaqueList *tail; @@ -304,6 +306,7 @@ static void flush(AVCodecContext *avctx) CHDContext *priv = avctx->priv_data; priv->need_second_field = 0; + priv->draining = 0; av_frame_unref (priv->pic); @@ -438,6 +441,7 @@ static av_cold int init(AVCodecContext *avctx) priv->avctx = avctx; priv->is_nal = avctx->extradata_size > 0 && *(avctx->extradata) == 1; priv->pic = av_frame_alloc(); + priv->draining = 0; subtype = id2subtype(priv, avctx->codec->id); switch (subtype) { @@ -670,6 +674,8 @@ FF_ENABLE_DEPRECATION_WARNINGS if ((ret = av_frame_ref(data, priv->pic)) < 0) { return ret; } + } else { + return RET_COPY_AGAIN; } return RET_OK; @@ -745,7 +751,7 @@ static inline CopyRet receive_frame(AVCodecContext *avctx, avctx->sample_aspect_ratio = (AVRational) {221, 1}; break; } - return RET_OK; + return RET_COPY_AGAIN; } else if (ret == BC_STS_SUCCESS) { int copy_ret = -1; if (output.PoutFlags & BC_POUT_FLAGS_PIB_VALID) { @@ -768,13 +774,13 @@ static inline CopyRet receive_frame(AVCodecContext *avctx, */ av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput succeeded with " "invalid PIB\n"); - copy_ret = RET_OK; + copy_ret = RET_COPY_AGAIN; } DtsReleaseOutputBuffs(dev, NULL, FALSE); return copy_ret; } else if (ret == BC_STS_BUSY) { - return RET_OK; + return RET_COPY_AGAIN; } else { av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput failed %d\n", ret); return RET_ERROR; @@ -874,6 +880,7 @@ static int crystalhd_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt) } } else { av_log(avctx, AV_LOG_INFO, "CrystalHD: No more input data\n"); + priv->draining = 1; ret = AVERROR_EOF; goto exit; } @@ -893,22 +900,27 @@ static int crystalhd_receive_frame(AVCodecContext *avctx, AVFrame *frame) av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: receive_frame\n"); - bc_ret = DtsGetDriverStatus(dev, &decoder_status); - if (bc_ret != BC_STS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed\n"); - return -1; - } + do { + bc_ret = DtsGetDriverStatus(dev, &decoder_status); + if (bc_ret != BC_STS_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed\n"); + return -1; + } - if (decoder_status.ReadyListCount == 0) { - av_log(avctx, AV_LOG_INFO, "CrystalHD: Insufficient frames ready. Returning\n"); - return AVERROR(EAGAIN); - } + if (decoder_status.ReadyListCount == 0) { + av_log(avctx, AV_LOG_INFO, "CrystalHD: Insufficient frames ready. Returning\n"); + got_frame = 0; + rec_ret = RET_OK; + break; + } + + rec_ret = receive_frame(avctx, frame, &got_frame); + } while (rec_ret == RET_COPY_AGAIN); - rec_ret = receive_frame(avctx, frame, &got_frame); if (rec_ret == RET_ERROR) { return -1; } else if (got_frame == 0) { - return AVERROR(EAGAIN); + return priv->draining ? AVERROR_EOF : AVERROR(EAGAIN); } else { return 0; }