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 E098B45C68 for ; Sat, 29 Apr 2023 09:12:09 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7F12C68C03E; Sat, 29 Apr 2023 12:12:06 +0300 (EEST) Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3CF9F68BF62 for ; Sat, 29 Apr 2023 12:12:00 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 33T9BxsN030826 for ; Sat, 29 Apr 2023 11:11:59 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 7A2C5EB5BF; Sat, 29 Apr 2023 11:11:59 +0200 (CEST) Date: Sat, 29 Apr 2023 11:11:59 +0200 From: Nicolas George To: FFmpeg development discussions and patches Message-ID: References: <20230428095508.221826-1-george@nsup.org> <20230428095508.221826-5-george@nsup.org> MIME-Version: 1.0 In-Reply-To: <20230428095508.221826-5-george@nsup.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Sat, 29 Apr 2023 11:11:59 +0200 (CEST) Subject: Re: [FFmpeg-devel] [PATCH 5/8] lavu: add a JSON writer API (WIP) 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="===============1140897967098324190==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============1140897967098324190== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="QZo5Sf+QRyi48sZs" Content-Disposition: inline --QZo5Sf+QRyi48sZs Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Nicolas George (12023-04-28): > Signed-off-by: Nicolas George > --- > libavutil/Makefile | 1 + > libavutil/json.c | 368 +++++++++++++++++++++++++++++++++++ > libavutil/json.h | 470 +++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 839 insertions(+) > create mode 100644 libavutil/json.c > create mode 100644 libavutil/json.h I forgot to write: I wrote this code not only because we have half-baked JSON output in multiple places in the code, but also to show the kind of API AVWriter makes possible. Typical JSON APIs would have a function to write a string value or an object key, requiring the caller to build the string beforehand. Of course, this API can do that: > +void av_json_add_string(AVJson *jc, const char *str); including with a format string, which is less usual: > +void av_json_add_string_printf(AVJson *jc, const char *fmt, ...) av_prin= tf_format(2, 3); But these are just wrappers for convenience over the real API: > +AVWriter av_json_begin_string(AVJson *jc); It starts a string, i.e. outputs a quote, and then we get a writer to write into that string. It will be automatically escaped, no intermediate buffer will be used, and all the functions of the writer API are available, including all the av_something_write() to come to serialize our various types. Also note that this API as a whole can produce small JSON outputs without any dynamic allocation, making it suitable for once-per-frame calls, but is not limited to that. Do we *need* that: of course not, we still put =E2=80=9Clen +=3D snprintf()= =E2=80=9D and =E2=80=9Cav_realloc()=E2=80=9D and error checks all over the place. Now, while people maybe look at the code, there are a few things I can work on, and I wonder which one you would like to see first: - Finishing this JSON API. - A XML API: that would be useful for dashenc, movenc, ttmlenc, ffprobe and possibly others. - Add serialization functions for our various types, like I did for av_disposition_write(). - Go forward with the others API enhancements that I promised and that depend on AVWriter. Regards, --=20 Nicolas George --QZo5Sf+QRyi48sZs Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE6ooRQGBoNzw0KnwPcZVLI8pNxgwFAmRM310ACgkQcZVLI8pN xgxSPA/9ETsZWfnof63m7l7+9CV3c9juW+By1zNLVX9c3m3H0DvTdTfI+j9BJqcu MB4IEtTi0RwcMEcovmjXFCuUeSX2M5bILCbYbymZMMFkEo2qpiqz08zflSZH7GHU gYK/U7gMECXIZzpkFC6PHAuvJHu17gQxIKMeI9ZmLF5w3tFAj/TTj3OI+S3Wn78d hiT17rnHz9xnRz+WAyUPvYBzNRKErJ8pVOYzocc5SMniFSULiIoBkussQOPQ9McA RJbD7BZolf7hPQcX8qK6YbDsxqJn7m6+B8uTTJN9r+1ZljLzBu2f35KAKUjid3ig J7YN9+IN9SNB4WCHY31gETZImJuYSfPJf0MWXTxHGTDdHJCeeA8PhKl6dD/4XEa6 sJnVCvk9eI0VZ+q2iL59Vze9UsuK0B30L3u4UPDFUMTQ3P4GbTNS+nGl0R+DYLwK M+DSNzH9io7D2zaJTAIJTKCNU8wFwsvIzFSZbKKGYfmbxWczw1dh6cWToIunD6V7 nCHSO16BrTvsxm95fTD+5+2pyBpvj7hN/dnqlAm/diOhD29AMACnUS4H8hZpIhql 72JOqGeyL8HUpiVFEWA1QzxC8shTOYiRYMAK4iR2SSYIidSoqejb+/sM/UL7g4Nb uUC1zGfBvyXQ1a8aXoNvpNdL5Gj8UGdu999xA9Oowx/ajXUSGZs= =/Sqd -----END PGP SIGNATURE----- --QZo5Sf+QRyi48sZs-- --===============1140897967098324190== 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". --===============1140897967098324190==--