From patchwork Sat Feb 10 17:12:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 7548 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp2169933jai; Sat, 10 Feb 2018 09:12:21 -0800 (PST) X-Google-Smtp-Source: AH8x224gZ94TS6nY64tD61xsnAp/VscIRe373BX47NXG4Qy7wBqBH9Zc7zefxB3I3JH5NDHAXWL9 X-Received: by 10.223.170.8 with SMTP id p8mr1384813wrd.81.1518282741265; Sat, 10 Feb 2018 09:12:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518282741; cv=none; d=google.com; s=arc-20160816; b=jgDzFFDVHF60BzxvmfgAvPESZzFhhbydqi6n9WDfpQdd2uTLd73pCyiPm3FETlAfoF IOi6yEh+7+VJIAupXa5EqhB0RNj8AcntRVyRJhZsZoGgYfWfQ9zC1B8hQwqu/Y1GczN/ N0YWVIHPmNtUd6JHVfmry7QO9NOgYTDoD9pP/9LEjjQ2mV+6I7YkVbt298MCSQFo8QJd H5O5JozL3tyE6PKHMAuFBn1vbslllIB2fWvwPG2bLv5BbIddi7n1nPpsuTzweQFsm5Uk F/wB8avfS/WI7kmpnnByQHurqu1KNJZedUXKEBnOl+9x0SOpLnRB9s6ctejM4l0vdFQ1 3jsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=gSOhjjVym1ZVvo8oHOCZ+p4L89I28mypF+7IkfohNLI=; b=DW93/501FKo5kyzXj2e7Pir63DgnIoMk2kTjxPThOSOdH8I6NlWWPL2s3GUF7RJDtA PYjQeX4ZLKUIJQwWobljOX4pYat13OHD28VzSDzCs/CxbDz597v2Br01opz7ie3wieF5 QqUuK+nkVqVi8DrPuBIRm6rmjz45m55YTC6aVFufc/1kTNggXTHOU52SwOjRjo00nWrJ I3NAVgqRgjyGhcevfJduK7oWZXpeKTTaprlIkc/e2NDB7QV3uJXDTBupOj+1x+l6xUMV jCFNkORTC3RfNRWnUP01/VpUZz+qEWuwETb+x5weNA7OfRz5/gHYJlvFQ7hc8Vd5eF3Z ulqw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s14si524385wrb.43.2018.02.10.09.12.20; Sat, 10 Feb 2018 09:12:21 -0800 (PST) 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; 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 18411680673; Sat, 10 Feb 2018 19:12:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 01B5968015B for ; Sat, 10 Feb 2018 19:12:02 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 5249FE17B7; Sat, 10 Feb 2018 18:12:12 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Gr2DGhfNRRca; Sat, 10 Feb 2018 18:12:11 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C8EF8E1132; Sat, 10 Feb 2018 18:12:10 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 10 Feb 2018 18:12:05 +0100 Message-Id: <20180210171206.29686-1-cus@passwd.hu> X-Mailer: git-send-email 2.13.6 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/aviobuf: add ff_read_line_to_bprint and ff_read_line_to_bprint_overwrite functions 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" To be able to read lines longer than a static buffer size. Signed-off-by: Marton Balint --- libavformat/aviobuf.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ libavformat/internal.h | 26 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 86eb6579f4..12cd73745d 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -821,6 +821,52 @@ int ff_get_line(AVIOContext *s, char *buf, int maxlen) return i; } +int64_t ff_read_line_to_bprint(AVIOContext *s, AVBPrint *bp) +{ + int len, end; + int64_t read = 0; + char tmp[1024]; + char c; + + do { + len = 0; + do { + c = avio_r8(s); + end = (c == '\r' || c == '\n' || c == '\0'); + if (!end) + tmp[len++] = c; + } while (!end && len < sizeof(tmp)); + av_bprint_append_data(bp, tmp, len); + read += len; + } while (!end); + + if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s)) + avio_skip(s, -1); + + if (!c && s->error) + return s->error; + + if (!c && !read && avio_feof(s)) + return AVERROR_EOF; + + return read; +} + +int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp) +{ + int64_t ret; + + av_bprint_clear(bp); + ret = ff_read_line_to_bprint(s, bp); + if (ret < 0) + return ret; + + if (!av_bprint_is_complete(bp)) + return AVERROR(ENOMEM); + + return bp->len; +} + int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen) { int i; diff --git a/libavformat/internal.h b/libavformat/internal.h index 0d08576c29..2ac7e2e1a0 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -299,6 +299,32 @@ void ff_put_v(AVIOContext *bc, uint64_t val); */ int ff_get_line(AVIOContext *s, char *buf, int maxlen); +/** + * Read a whole line of text from AVIOContext to an AVBPrint buffer. Stop + * reading after reaching a \\r, a \\n, a \\r\\n, a \\0 or EOF. The line + * ending characters are NOT included in the buffer, but they are skipped on + * the input. + * + * @param s the read-only AVIOContext + * @param bp the AVBPrint buffer + * @return the length of the read line, not including the line endings, + * negative on error. + */ +int64_t ff_read_line_to_bprint(AVIOContext *s, AVBPrint *bp); + +/** + * Read a whole line of text from AVIOContext to an AVBPrint buffer overwriting + * its contents. Stop reading after reaching a \\r, a \\n, a \\r\\n, a \\0 or + * EOF. The line ending characters are NOT included in the buffer, but they + * are skipped on the input. + * + * @param s the read-only AVIOContext + * @param bp the AVBPrint buffer + * @return the length of the read line not including the line endings, + * negative on error, or if the buffer becomes truncated. + */ +int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp); + #define SPACE_CHARS " \t\r\n" /**