From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 81BF248232 for ; Thu, 14 Dec 2023 20:16:14 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C7D0668D2C8; Thu, 14 Dec 2023 22:15:28 +0200 (EET) Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7C9B968D29E for ; Thu, 14 Dec 2023 22:15:20 +0200 (EET) Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5c21e185df5so7374774a12.1 for ; Thu, 14 Dec 2023 12:15:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702584918; x=1703189718; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=mSE6cPNs1R3AaCBlo94VrNHgs5ToTsW0px4hqwFDXSQ=; b=kBMaTJCtLgxVdQd7TlgWOeVbKFfk3/Dq6y2G9nW5mncnFornxg/T16q0ZfeT8mIHfb wLGJ0hNj3hmsLI5QZrtMgW7+CmfahXAs3UTOSiWDEU60V1NYdFWOCophR7j8NzfI/4p1 IjNLtm1+bpHemdnL+IOgui0UiG6Haach8jJ/y1gSSUlz8uMZvsEe0bndqQi9l5Ib3LwO fuwhqxO51nWJCpeZayryrToBezTz3WBM2LzPgND7jMnmf3FJTDVDsFSEKyfYK4AEIvC8 /oGh/ip1Zidsx0eF3DeWdZD6mtInAqpMvUjtlBw6LrSNQC8GvDI+kyO7Avnz02Bvv98W 9bgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702584918; x=1703189718; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mSE6cPNs1R3AaCBlo94VrNHgs5ToTsW0px4hqwFDXSQ=; b=E1KFiGfMedM4guC8m1w02kbPAjeEju2uLDA6NhdfC+F0FU+dg5II6DspCcYkib5bMr PDY0HXW+NblfkLnsS/k994+orl0hEUwEgFaRcHYFeuS04ggJuFPRkxta+HB0+PEBwLJJ sqqGiuJO0XGq8/xN77/skvi2NMr7pUBCsNUTNXtNveAgW2VET+TZYpQdr31eLrAdv6r5 wkFcB8x8EoSRMIpz0o6MLH8SosW3t95Ex1kDpvJJNr3f5XTKKQxALss9DfhIX4iG2M1O HCPXcA/MLiFZzKmeWR7XnkMeb7USVp6wtygMfUypI6vCN2K0w4rbky5IMkbOvxCkRxiQ Rm+w== X-Gm-Message-State: AOJu0YygfmOe1Sb6jkExgMx1/t5VenM16ARtSY4NqbjIfUNuUKE8p39X Kdn3X1m261tzLOr60cWvWX7ATHcjUc4= X-Google-Smtp-Source: AGHT+IHCGN/46I/93b8/SLDaLuHJHyS1KFBZs+GrgUrr19Dcn06vRWrpaX37ZAoiNG9smMYWT1lJ+g== X-Received: by 2002:a05:6a21:18d:b0:190:8491:ac38 with SMTP id le13-20020a056a21018d00b001908491ac38mr14379559pzb.106.1702584918481; Thu, 14 Dec 2023 12:15:18 -0800 (PST) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id h12-20020a62b40c000000b006d0d4bafe31sm3352885pfn.6.2023.12.14.12.15.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:15:18 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 Dec 2023 17:14:31 -0300 Message-ID: <20231214201433.4608-7-jamrial@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231214201433.4608-1-jamrial@gmail.com> References: <20231214201433.4608-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/8] avformat/aviobuf: add ffio_read_leb() and ffio_write_leb() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: James Almer --- libavformat/avio_internal.h | 10 ++++++++++ libavformat/aviobuf.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h index bd58499b64..f2e4ff30cb 100644 --- a/libavformat/avio_internal.h +++ b/libavformat/avio_internal.h @@ -146,6 +146,16 @@ int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **buf, int buf_siz uint64_t ffio_read_varlen(AVIOContext *bc); +/** + * Read a unsigned integer coded as a variable number of up to eight + * little-endian bytes, where the MSB in a byte signals another byte + * must be read. + * All coded bytes are read, but values > UINT_MAX are truncated. + */ +unsigned int ffio_read_leb(AVIOContext *s); + +void ffio_write_leb(AVIOContext *s, unsigned val); + /** * Read size bytes from AVIOContext into buf. * Check that exactly size bytes have been read. diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 2899c75521..5a329ce465 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -971,6 +971,39 @@ uint64_t ffio_read_varlen(AVIOContext *bc){ return val; } +unsigned int ffio_read_leb(AVIOContext *s) { + int more, i = 0; + unsigned leb = 0; + + do { + int byte = avio_r8(s); + unsigned bits = byte & 0x7f; + more = byte & 0x80; + if (i <= 4) + leb |= bits << (i * 7); + if (++i == 8) + break; + } while (more); + + return leb; +} + +void ffio_write_leb(AVIOContext *s, unsigned val) +{ + int len; + uint8_t byte; + + len = (av_log2(val) + 7) / 7; + + for (int i = 0; i < len; i++) { + byte = val >> (7 * i) & 0x7f; + if (i < len - 1) + byte |= 0x80; + + avio_w8(s, byte); + } +} + int ffio_fdopen(AVIOContext **s, URLContext *h) { uint8_t *buffer = NULL; -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".