From patchwork Thu Aug 11 12:38:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sebechlebskyjan@gmail.com X-Patchwork-Id: 150 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.67 with SMTP id o64csp43706vsd; Thu, 11 Aug 2016 05:38:51 -0700 (PDT) X-Received: by 10.194.38.9 with SMTP id c9mr9137462wjk.78.1470919131295; Thu, 11 Aug 2016 05:38:51 -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 m71si12502678wmh.129.2016.08.11.05.38.50; Thu, 11 Aug 2016 05:38:51 -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=@gmail.com; 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; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4481068A638; Thu, 11 Aug 2016 15:38:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 11BB168A62A for ; Thu, 11 Aug 2016 15:38:40 +0300 (EEST) Received: by mail-wm0-f66.google.com with SMTP id i5so1142855wmg.2 for ; Thu, 11 Aug 2016 05:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ALNxSPye5Ob9AEN6NBS131OUSTU8T8M8zwhWt/UGgWs=; b=TMTHcoZFh9ndnoG+tyZA8MDgP5jR4Aw6nsH37B8SzjWPNWnH+fceboO3yd1yLcKENv CVaBPK4LEs57yVGpzRqqBeFi9I/MqBTaEN1VzP7MMEm2y3Uh6VlXvg0XEX//w/MP2YDI PBXJ8XCupJiapMsZwdxfhDzFhZawLx7uYywqnVlThFrFC7bAUaA1/aUF9zs2zF5Q2WbO b3qGixjSEsAnAOHi+KZ21LvHzTbQKlEEhEEYQ/tciRKIJD0xwWnezIvGxHsSTufElpgv yuNi9q/Gv+7cXSgS5jGmHfH/F8JR8ze72PEqZUJINbEvfWdT1My9GUnWh8reSHvSh0OE 7YeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ALNxSPye5Ob9AEN6NBS131OUSTU8T8M8zwhWt/UGgWs=; b=lLIbSvYdiGa8Dq4yORQNFBC3jDzaOHR9Qh1qJ5PK2YuCr88eBz5qGf5olVe4cKNwDM c3t/npTNu2dqdNMHDaDYmnE1dHP2dwpCn6tfVPai4RlpyCos+ahvVknT83HywLXbmaLw Q8hvbn7xfn9brbObuiDGEVsCSqWCluqsdpgCAEBRFUXfyVH56XSKB03j5R6xhKKMVrSJ gT2uVhIIisjNxgrLKrOscciNuBqBUvLsUWDZkI20J2WYFTeQ8nw5ob10zVi2PWktyfEz 1ZeMd/N1YFuMHFMUT6HqZ9kcjQhC4kMQ+TFxq/VeSXBAxiNU5GEZs4312AoN3D8CYftT YJcg== X-Gm-Message-State: AEkoouvMq0qSEGqvHm4hFW39bWSJneUGlOBCrqxQLBhq+Id7I5P3TBQ8lQU36gCT3KHAFg== X-Received: by 10.194.97.17 with SMTP id dw17mr9219348wjb.8.1470919120083; Thu, 11 Aug 2016 05:38:40 -0700 (PDT) Received: from localhost.localdomain (157.174.broadband3.iol.cz. [85.70.174.157]) by smtp.gmail.com with ESMTPSA id ko7sm2507062wjc.48.2016.08.11.05.38.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Aug 2016 05:38:39 -0700 (PDT) From: sebechlebskyjan@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 11 Aug 2016 14:38:29 +0200 Message-Id: <1470919109-3327-1-git-send-email-sebechlebskyjan@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <20160810170430.GC5460@nb4> References: <20160810170430.GC5460@nb4> Subject: [FFmpeg-devel] [PATCH v2 04/11] avformat/muxers: Add non-blocking mode support for av_write_trailer 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: Jan Sebechlebsky MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jan Sebechlebsky This makes av_write_trailer not to free the resources if write_trailer call returns AVERROR(EAGAIN) allowing repeated calls of write_trailer of non-blocking muxer. Signed-off-by: Jan Sebechlebsky --- Changes since the last version of the patch: - Added assert to the part of the code dealing with flushing interleaved packets which should not be entered if muxer in non-blocking mode is used. (also there is assert for the same condition added into av_interleaved_write_packet in one of the following patches). libavformat/avformat.h | 6 +++++- libavformat/mux.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index d8a6cf3..2cc3156 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -2510,8 +2510,12 @@ int av_write_uncoded_frame_query(AVFormatContext *s, int stream_index); * * May only be called after a successful call to avformat_write_header. * + * If AVFMT_FLAG_NONBLOCK is set, this call may return AVERROR(EAGAIN) + * meaning the operation is pending and the call should be repeated. + * * @param s media file handle - * @return 0 if OK, AVERROR_xxx on error + * @return 0 if OK, AVERROR(EAGAIN) in case call should be repeated, + * other AVERROR on error */ int av_write_trailer(AVFormatContext *s); diff --git a/libavformat/mux.c b/libavformat/mux.c index e9973ed..3ae924c 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -1204,11 +1204,14 @@ int av_write_trailer(AVFormatContext *s) for (;; ) { AVPacket pkt; ret = interleave_packet(s, &pkt, NULL, 1); - if (ret < 0) - goto fail; if (!ret) break; + av_assert0(!(s->flags & AVFMT_FLAG_NONBLOCK)); + + if (ret < 0) + goto fail; + ret = write_packet(s, &pkt); if (ret >= 0) s->streams[pkt.stream_index]->nb_frames++; @@ -1238,6 +1241,9 @@ fail: } } + if (ret == AVERROR(EAGAIN)) + return ret; + if (s->oformat->deinit) s->oformat->deinit(s);