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 ESMTPS id EFF714DF2C for ; Wed, 5 Mar 2025 16:30:19 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9376D68EED9; Wed, 5 Mar 2025 18:30:17 +0200 (EET) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 21CDF68ED43 for ; Wed, 5 Mar 2025 18:30:11 +0200 (EET) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2232aead377so139683665ad.0 for ; Wed, 05 Mar 2025 08:30:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741192209; x=1741797009; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lEXfBvQz4ackPAc9v380Tc9Fr9hq2gH1W5XCwAKHZIs=; b=mZq8v5fBQ4wY+GxLKwAxq8i4X+UzThdYn7fyAc56taDtIQRXHJV/xcUHupW1ONvACn iB9ngoQlCe7P9LMiXU07K0JU9i11+CfFk6z2VwQ8rnxcofpJbAM0N+NL35oZkRCoqcwL TnR20mm9NfSnnx5kQS2CxZHj9UGBX47+KivsszDYVaCKStfwsiZVtQ6thgcyZz/VlTlp 3HxT8LqMLAdYIruw84DUPlN7o3oEurOkBwDP81Bq3DQl2DDS0jo8SEdOxxS6xqy84RoR iEFpPpQyEtl5euKW9Vyf5U41GJJ4OHE7yAsTwyatUm/nkEUqwm1maIG1ygj54G+SL+iz DSlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741192209; x=1741797009; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lEXfBvQz4ackPAc9v380Tc9Fr9hq2gH1W5XCwAKHZIs=; b=thI667f9gK5S+HVLVL82Xmsxl2Vv/DfpqS96wkubm6rHfVtYCWQWuo6amzTJoFAsaM XF7TbipuDJCpus5Ea26c4/GONAuFE4s6/CMW1HAvYY177qpL5liqD+52zMzrsCxP4CmH dGCfzKVaTqLzbKQa0sZYivq/dgowBVw0MV9IRW5bdMGl09V9+DNq8IN4XjyOHUpkqdz9 TnlWwPwO8fd4tHedRSJkPusZXXTwdS1tbG1AVSGHJgs6Tci8wgXyq2e+u4eEfEPG8OcJ a3CNCql+9zRokd/W18II8Ise1SAy/OUrCsoY8YVm22+QV3rYJVzN6PD7JXpBf7cq+YIW HvpA== X-Gm-Message-State: AOJu0YyXQ6Ro/PKQGHmbjDiroSigDYE8LUix2otQDHYVFGuaaVgKvk2d iGGwiy08+KRIGdCEsI38Sh1ZhhYC3rM+VsO+qJWhVTRPWVmFQYrz+QFyFjxXExk= X-Gm-Gg: ASbGncuy3YBw7nuqTRlhHiAcbJ+yyw/HQx+4zsY75JTD+lhWNfO/zaDt5GWdC9KcJcC aikCvFEr/PzXLj6Z/ZWVsVGfE86ElZ18CJGbOH8CrwS3IE0Rz1PNU9PqJ/5nHzf4kAZsdgyu9oZ XUd93u/ZFRKosYzVIYHFpj7grOmn4avfRgtPdnJBhdW6cJlgxFNpj+OHjDu4ghkIrURf1zMmzVQ lcQjTHAdnx9E/K/vi/72NiEfgXd/xw0y68uqv5NjVY44DV9pp6b7YeljRuLGfOVzg07a7TBN8m+ ArTrMbt+yT5NrLmd6fV2PmH9rzIkmDgsj25ubL7ieXs= X-Google-Smtp-Source: AGHT+IG0IXg+anIqQnu/LulQ+sWsXAB665x4bmGbVH4oIJTfLrKATMbW8qDwi4ucNUqMv/gEeISCow== X-Received: by 2002:a05:6a20:d80d:b0:1f3:3804:975a with SMTP id adf61e73a8af0-1f34949806bmr7820627637.24.1741192208931; Wed, 05 Mar 2025 08:30:08 -0800 (PST) Received: from mihir.. ([103.137.155.162]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-af021fb1581sm9848504a12.36.2025.03.05.08.30.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 08:30:08 -0800 (PST) From: MihirGore To: ffmpeg-devel@ffmpeg.org Date: Wed, 5 Mar 2025 21:59:34 +0530 Message-ID: <20250305162934.33784-2-mihirmvgore@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250305162934.33784-1-mihirmvgore@gmail.com> References: <20250305162934.33784-1-mihirmvgore@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/1] Add vpx range encoder support 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 Cc: MihirGore23 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: From: MihirGore23 --- libavcodec/vpx_rac.h | 75 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/libavcodec/vpx_rac.h b/libavcodec/vpx_rac.h index b158cc0754..f01358f71f 100644 --- a/libavcodec/vpx_rac.h +++ b/libavcodec/vpx_rac.h @@ -20,7 +20,7 @@ /** * @file - * Common VP5-VP9 range decoder stuff + * Common VP5-VP9 range encoder and decoder functions */ #ifndef AVCODEC_VPX_RAC_H @@ -34,24 +34,25 @@ typedef struct VPXRangeCoder { int high; - int bits; /* stored negated (i.e. negative "bits" is a positive number of - bits left) in order to eliminate a negate in cache refilling */ + int bits; const uint8_t *buffer; const uint8_t *end; unsigned int code_word; int end_reached; + uint8_t *output_buffer; // Added for encoding + uint8_t *output_end; // Added for encoding } VPXRangeCoder; extern const uint8_t ff_vpx_norm_shift[256]; + +/*Decoder Functions */ + int ff_vpx_init_range_decoder(VPXRangeCoder *c, const uint8_t *buf, int buf_size); -/** - * returns 1 if the end of the stream has been reached, 0 otherwise. - */ static av_always_inline int vpx_rac_is_end(VPXRangeCoder *c) { if (c->end <= c->buffer && c->bits >= 0) - c->end_reached ++; + c->end_reached++; return c->end_reached > 10; } @@ -64,7 +65,7 @@ static av_always_inline unsigned int vpx_rac_renorm(VPXRangeCoder *c) c->high <<= shift; code_word <<= shift; bits += shift; - if(bits >= 0 && c->buffer < c->end) { + if (bits >= 0 && c->buffer < c->end) { code_word |= bytestream_get_be16(&c->buffer) << bits; bits -= 16; } @@ -72,12 +73,6 @@ static av_always_inline unsigned int vpx_rac_renorm(VPXRangeCoder *c) return code_word; } -#if ARCH_ARM -#include "arm/vpx_arith.h" -#elif ARCH_X86 -#include "x86/vpx_arith.h" -#endif - #ifndef vpx_rac_get_prob #define vpx_rac_get_prob vpx_rac_get_prob static av_always_inline int vpx_rac_get_prob(VPXRangeCoder *c, uint8_t prob) @@ -95,7 +90,6 @@ static av_always_inline int vpx_rac_get_prob(VPXRangeCoder *c, uint8_t prob) #endif #ifndef vpx_rac_get_prob_branchy -// branchy variant, to be used where there's a branch based on the bit decoded static av_always_inline int vpx_rac_get_prob_branchy(VPXRangeCoder *c, int prob) { unsigned long code_word = vpx_rac_renorm(c); @@ -117,7 +111,6 @@ static av_always_inline int vpx_rac_get_prob_branchy(VPXRangeCoder *c, int prob) static av_always_inline int vpx_rac_get(VPXRangeCoder *c) { unsigned int code_word = vpx_rac_renorm(c); - /* equiprobable */ int low = (c->high + 1) >> 1; unsigned int low_shift = low << 16; int bit = code_word >= low_shift; @@ -132,4 +125,54 @@ static av_always_inline int vpx_rac_get(VPXRangeCoder *c) return bit; } +//Encoder Functions + +int ff_vpx_init_range_encoder(VPXRangeCoder *c, uint8_t *buf, int buf_size); + +static av_always_inline void vpx_rac_renorm_encoder(VPXRangeCoder *c) +{ + while (c->high < 0x10000) { + if (c->output_buffer < c->output_end) { + *c->output_buffer++ = c->code_word >> 24; + } + c->code_word <<= 8; + c->high <<= 8; + } +} + +static av_always_inline void vpx_rac_put_prob(VPXRangeCoder *c, int bit, uint8_t prob) +{ + unsigned int low = 1 + (((c->high - 1) * prob) >> 8); + if (bit) { + c->code_word += low << 16; + c->high -= low; + } else { + c->high = low; + } + vpx_rac_renorm_encoder(c); +} + +static av_always_inline void vpx_rac_put(VPXRangeCoder *c, int bit) +{ + unsigned int low = (c->high + 1) >> 1; + if (bit) { + c->code_word += low << 16; + c->high -= low; + } else { + c->high = low; + } + vpx_rac_renorm_encoder(c); +} + +static av_always_inline void vpx_rac_flush(VPXRangeCoder *c) +{ + for (int i = 0; i < 4; i++) { + if (c->output_buffer < c->output_end) { + *c->output_buffer++ = c->code_word >> 24; + } + c->code_word <<= 8; + } +} + #endif /* AVCODEC_VPX_RAC_H */ + -- 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".