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 EDDDD47BB8 for ; Mon, 28 Apr 2025 06:44:38 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9615568B353; Mon, 28 Apr 2025 09:44:34 +0300 (EEST) Received: from mx.sdf.org (mx.sdf.org [205.166.94.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 34340687C32 for ; Mon, 28 Apr 2025 09:44:26 +0300 (EEST) Received: from 28828826f30850df2d2bb146bd869914 ([1.145.229.152]) (authenticated (0 bits)) by mx.sdf.org (8.18.1/8.14.3) with ESMTPSA id 53S6iFQp014430 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Mon, 28 Apr 2025 06:44:20 GMT Date: Mon, 28 Apr 2025 16:44:14 +1000 From: Peter Ross To: Amogh Kumar Sinha Message-ID: Mail-Followup-To: Amogh Kumar Sinha , ffmpeg-devel@ffmpeg.org References: MIME-Version: 1.0 In-Reply-To: Subject: Re: [FFmpeg-devel] Addition of encoder functionality in libavcodec/vpx_rac.h and corresponding commit in vpx_rac.c 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: ffmpeg-devel@ffmpeg.org Content-Type: multipart/mixed; boundary="===============2299292682629779752==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============2299292682629779752== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Xr9GMF7mpiQwtBxq" Content-Disposition: inline --Xr9GMF7mpiQwtBxq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Amogh, On Sun, Apr 27, 2025 at 10:38:57PM +0530, Amogh Kumar Sinha wrote: > Dear Sir, > I am sending this patch for adding encoder functionality, as the > Qualification Task for GSoC 2025. Kindly look into it: Ok, this "diff" comes at the last minute and its not quite ready for inclusion into FFmpeg. The deadline for GSoC student selection is in ~24hours, which makes this kind of difficult. I will give you some comments. Firstly, patches need to be sent to ffmpeg-devel. You must be subscribed to ffmpeg-devel before attempting to send to it. Instructions: https://ffmpeg.org/mailman/listinfo/ffmpeg-devel Secondly, patches needs to be presented in git-format-patch style. Instructions for setting up email/git here:=20 https://ffmpeg.org/developer.html#Submitting-patches-1 I have managed to apply your diffs and test your code with a simple program. Below is my test code. Something is not quite right with your encoder, as the range decoder output does not match the input the encoder. I don't have time tonight to dig deeper into why. ``` #include #include #include "libavcodec/vpx_rac.h" int main() { uint8_t buf[64] =3D {0}; VPXRangeCoder e; ff_vpx_init_range_encoder(&e, buf, sizeof(buf)); vpx_rac_put(&e, 1); vpx_rac_put(&e, 1); vpx_rac_put(&e, 1); vpx_rac_put(&e, 0); vpx_rac_put(&e, 1); vpx_rac_put(&e, 0); ff_vpx_range_encoder_flush(&e); printf("buf: %02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]); VPXRangeCoder d; ff_vpx_init_range_decoder(&d, buf, sizeof(buf)); printf("%d\n", vpx_rac_get(&d)); printf("%d\n", vpx_rac_get(&d)); printf("%d\n", vpx_rac_get(&d)); printf("%d\n", vpx_rac_get(&d)); printf("%d\n", vpx_rac_get(&d)); printf("%d\n", vpx_rac_get(&d)); return 0; } ``` The program is expected to output 111010, but currently gives 111000. > Commit to vpx_rac.h: > +++ vpx_rac.h 2025-04-27 21:34:45 > @@ -20,7 +20,7 @@ >=20 > /** > * @file > - * Common VP5-VP9 range decoder stuff > + * Common VP5-VP9 range decoder/encoder stuff > */ >=20 > #ifndef AVCODEC_VPX_RAC_H > \ No newline at end of file > @@ -40,10 +40,17 @@ > const uint8_t *end; > unsigned int code_word; > int end_reached; > + > + // For encoder > + unsigned int low; > + uint8_t *output_buffer; > + uint8_t *output_start; > + uint8_t *output_end; > } VPXRangeCoder; >=20 > extern const uint8_t ff_vpx_norm_shift[256]; > int ff_vpx_init_range_decoder(VPXRangeCoder *c, const uint8_t *buf, > int buf_size); > +int ff_vpx_init_range_encoder(VPXRangeCoder *c, uint8_t *buf, int > buf_size); >=20 > /** > * returns 1 if the end of the stream has been reached, 0 otherwise. > \ No newline at end of file > @@ -72,6 +79,42 @@ > return code_word; > } >=20 > +// Encoder related function > +static av_always_inline int vpx_rac_renorm_encoder(VPXRangeCoder *c) > +{ > + while (c->high < 128) { > + c->high <<=3D 1; > + > + if (c->low & 0x8000) { > + if (c->output_buffer > c->output_start) { > + uint8_t *p =3D c->output_buffer - 1; > + while (p > c->output_start && *p =3D=3D 0xFF) { > + *p =3D 0; > + p--; > + } > + (*p)++; > + } > + } > + > + c->low <<=3D 1; > + c->low &=3D 0xFFFF; > + > + c->bits++; > + if (c->bits >=3D 0) { > + if (c->output_buffer >=3D c->output_end) > + return AVERROR(ENOSPC); > + > + *c->output_buffer++ =3D (c->low >> 8) & 0xFF; > + c->bits -=3D 8; > + } > + } > + > + return 0; > +} > + > +// Encoder related function > +int ff_vpx_range_encoder_flush(VPXRangeCoder *c); > + > #if ARCH_ARM > #include "arm/vpx_arith.h" > #elif ARCH_X86 > \ No newline at end of file > @@ -132,4 +175,24 @@ > return bit; > } >=20 > -#endif /* AVCODEC_VPX_RAC_H */ > +// Encoder related function > +static av_always_inline int vpx_rac_put(VPXRangeCoder *c, int bit) > +{ > + int ret; > + unsigned int split =3D (c->high + 1) >> 1; > + > + if (bit) { > + c->low +=3D split; > + c->high -=3D split; > + } else { > + c->high =3D split; > + } > + > + ret =3D vpx_rac_renorm_encoder(c); > + if (ret < 0) > + return ret; > + > + return 0; > +} > + > +#endif /* AVCODEC_VPX_RAC_H */ > \ No newline at end of file > Commit to vpx_rac.c: > +++ vpx_rac.c 2025-04-27 22:31:48 > @@ -51,3 +51,52 @@ > c->code_word =3D bytestream_get_be24(&c->buffer); > return 0; > } > + > +//Encoder related > +int ff_vpx_init_range_encoder(VPXRangeCoder *c, uint8_t *buf, int > buf_size) > +{ > + if (!buf || buf_size < 2) > + return AVERROR(EINVAL); > + > + c->high =3D 255; // Start with full range > + c->low =3D 0; // Initialize low value > + c->bits =3D -8; // Initialize bits (negative as in > decoder) > + c->output_buffer =3D buf; > + c->output_start =3D buf; > + c->output_end =3D buf + buf_size; > + > + // Reserve first 2 bytes for initial code word in decoder > + c->output_buffer +=3D 2; > + > + if (c->output_buffer >=3D c->output_end) > + return AVERROR(EINVAL); > + > + return 0; > +} > + > +//Encoder related > +int ff_vpx_range_encoder_flush(VPXRangeCoder *c) > +{ > + int i, ret; > + > + for (i =3D 0; i < 16; i++) { > + ret =3D vpx_rac_put(c, 0); > + if (ret < 0) > + return ret; > + } > + > + if (c->output_start + 1 >=3D c->output_end) > + return AVERROR(ENOSPC); > + > + if (c->output_start + 3 < c->output_end) { > + uint16_t initial_code =3D (c->output_start[2] << 8) | > c->output_start[3]; > + c->output_start[0] =3D initial_code >> 8; > + c->output_start[1] =3D initial_code & 0xFF; > + } else { > + // Handle the case where we don't have enough encoded data > + c->output_start[0] =3D 0; > + c->output_start[1] =3D 0; > + } > + > + return c->output_buffer - c->output_start; > +} > \ No newline at end of file > Yours Sincerely, > Amogh Kumar Sinha -- Peter (A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B) --Xr9GMF7mpiQwtBxq Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQSpB+AvpuUM0jTNINJnYHnFrEDdawUCaA8juwAKCRBnYHnFrEDd a3ddAJ9Zz2Qc8wutlZm1CArGa3RJ3ZXwigCgmex7R4GBKkjEKXtMaQJzBn8Ch9s= =+m2y -----END PGP SIGNATURE----- --Xr9GMF7mpiQwtBxq-- --===============2299292682629779752== 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". --===============2299292682629779752==--