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 AA4894E01E for ; Thu, 6 Mar 2025 22:59:00 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 54CB768F3F2; Fri, 7 Mar 2025 00:58:56 +0200 (EET) Received: from mx.sdf.org (mx.sdf.org [205.166.94.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4C1F268EEDD for ; Fri, 7 Mar 2025 00:58:49 +0200 (EET) Received: from b23210acc22a312b5f9efa84d03776bb ([1.145.197.71]) (authenticated (0 bits)) by mx.sdf.org (8.18.1/8.14.3) with ESMTPSA id 526MweUf010735 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO) for ; Thu, 6 Mar 2025 22:58:45 GMT Date: Fri, 7 Mar 2025 09:58:38 +1100 From: Peter Ross To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches References: <20250305162934.33784-1-mihirmvgore@gmail.com> <20250305162934.33784-2-mihirmvgore@gmail.com> MIME-Version: 1.0 In-Reply-To: <20250305162934.33784-2-mihirmvgore@gmail.com> Subject: Re: [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 Content-Type: multipart/mixed; boundary="===============8200112147182007098==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============8200112147182007098== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="KYosVm3e4qID6xf3" Content-Disposition: inline --KYosVm3e4qID6xf3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Mar 05, 2025 at 09:59:34PM +0530, MihirGore wrote: > From: MihirGore23 > Hi, comments below. =20 > --- > libavcodec/vpx_rac.h | 75 ++++++++++++++++++++++++++++++++++---------- > 1 file changed, 59 insertions(+), 16 deletions(-) >=20 > 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 @@ > =20 > /** > * @file > - * Common VP5-VP9 range decoder stuff > + * Common VP5-VP9 range encoder and decoder functions > */ > =20 > #ifndef AVCODEC_VPX_RAC_H > @@ -34,24 +34,25 @@ > =20 > typedef struct VPXRangeCoder { > int high; > - int bits; /* stored negated (i.e. negative "bits" is a positive numb= er of > - bits left) in order to eliminate a negate in cache refi= lling */ > + int bits;=20 ^^^^^ there is some some unnecessary whitespace after 'bits;' also why did you delete the original comment? > 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; > =20 > 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); > =20 > -/** > - * 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 <=3D c->buffer && c->bits >=3D 0) > - c->end_reached ++; > + c->end_reached++; > return c->end_reached > 10; > } > =20 > @@ -64,7 +65,7 @@ static av_always_inline unsigned int vpx_rac_renorm(VPX= RangeCoder *c) > c->high <<=3D shift; > code_word <<=3D shift; > bits +=3D shift; > - if(bits >=3D 0 && c->buffer < c->end) { > + if (bits >=3D 0 && c->buffer < c->end) { > code_word |=3D bytestream_get_be16(&c->buffer) << bits; > bits -=3D 16; > } > @@ -72,12 +73,6 @@ static av_always_inline unsigned int vpx_rac_renorm(VP= XRangeCoder *c) > return code_word; > } > =20 > -#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 p= rob) > @@ -95,7 +90,6 @@ static av_always_inline int vpx_rac_get_prob(VPXRangeCo= der *c, uint8_t prob) > #endif > =20 > #ifndef vpx_rac_get_prob_branchy > -// branchy variant, to be used where there's a branch based on the bit d= ecoded > static av_always_inline int vpx_rac_get_prob_branchy(VPXRangeCoder *c, i= nt prob) > { > unsigned long code_word =3D 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 =3D vpx_rac_renorm(c); > - /* equiprobable */ > int low =3D (c->high + 1) >> 1; > unsigned int low_shift =3D low << 16; > int bit =3D code_word >=3D low_shift; > @@ -132,4 +125,54 @@ static av_always_inline int vpx_rac_get(VPXRangeCode= r *c) > return bit; > } > =20 > +//Encoder Functions > + > +int ff_vpx_init_range_encoder(VPXRangeCoder *c, uint8_t *buf, int buf_si= ze); > + ff_vpx_init_range_encoder function is not defined anywhere. did you forget to commit vpx_rac.c changes? > +static av_always_inline void vpx_rac_flush(VPXRangeCoder *c) > +{ > + for (int i =3D 0; i < 4; i++) { > + if (c->output_buffer < c->output_end) { > + *c->output_buffer++ =3D c->code_word >> 24; > + } > + c->code_word <<=3D 8; > + } > +} after calling vpx_rac_flush() how does the caller determine the final size of the output buffer? finally, does the output of your encoder work with the existing decoder? simple test case: ``` VPXRangeCoder e; uint8_t buf[1024] =3D {0}; ff_vpx_init_range_encoder(&e, buf, sizeof(buf)); vpx_rac_put(&e, 1); vpx_rac_put(&e, 0); vpx_rac_put(&e, 1); vpx_rac_flush(&e); VPXRangeCoder d; ff_vpx_init_range_decoder(&d, buf, e.output_buffer - buf); printf("%d\n", vpx_rac_get(&d)); printf("%d\n", vpx_rac_get(&d)); printf("%d\n", vpx_rac_get(&d)); ``` -- Peter (A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B) --KYosVm3e4qID6xf3 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQSpB+AvpuUM0jTNINJnYHnFrEDdawUCZ8oomwAKCRBnYHnFrEDd a/nXAJ9MA3NOinWLywuLFcSTowCs9uAPcwCgoL/bl/2WM8PX7tKunJ46vpmfGPo= =esn/ -----END PGP SIGNATURE----- --KYosVm3e4qID6xf3-- --===============8200112147182007098== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============8200112147182007098==--