From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id B5DE54FDB2 for ; Wed, 2 Jul 2025 14:44:07 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id F04AE68C178; Wed, 2 Jul 2025 17:44:03 +0300 (EEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 779C068CC5D for ; Wed, 2 Jul 2025 17:43:57 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id B93A81FD3D for ; Wed, 2 Jul 2025 14:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1751467436; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=WpNGI4ykAya6fN3Kq7KxaSsj4KaXHeVaCxXz+Y1JV9g=; b=MEvvJXS3t6tpbm2vYKvaD0G9SycH2zc2KzB9bJqlPbTe0jy1domWL8p8uCJdJw0N6bZZev YnWjFtzv+MZBlvl3e5I5P77j76KpwK100LpELEOP61vWcjEQSUGfOd7r1flU1RWWzi7Gm7 TKjuaoySm3J/ND7ucKfluFXFet2ZSPMJEN01PMYIZ1NfBZlfW71Iv9U/o6R3/uuTTMuh6c xvtOSyME01SSy+hdTmLNJAMNaZQ6jSKy65sgcrxAW6L88+9ynaSJyReXLG/VlgkFHAB+fX xTvsAShvmHWxBcqIeckXnRc/n80tYEodLLnna+4ZMrJfmh7lMmQ88OEFWvCt9g== Date: Wed, 2 Jul 2025 16:43:55 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20250702144355.GE29660@pb2> MIME-Version: 1.0 X-GND-State: clean X-GND-Score: -70 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddujeeijecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrhhlucfvnfffucdlfedtmdenucfjughrpeffhffvuffkgggtugesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcupfhivgguvghrmhgrhigvrhcuoehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgeqnecuggftrfgrthhtvghrnhepieefgeevgfdvgeeludegheelhfegffdvgefgtdegveegudelveeiueelieetveffnecukfhppeeguddrieeirdeiiedrvddvjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeguddrieeirdeiiedrvddvjedphhgvlhhopehlohgtrghlhhhoshhtpdhmrghilhhfrhhomhepmhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtpdhnsggprhgtphhtthhopedupdhrtghpthhtohepfhhfmhhpvghgqdguvghvvghlsehffhhmphgvghdrohhrgh X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [RFC] Advanced Error Codes 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="===============6357278062649508372==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============6357278062649508372== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="6Tx6JDZ2MNaN5Vow" Content-Disposition: inline --6Tx6JDZ2MNaN5Vow Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi People are asking for better error codes Heres a quick pseodocode design / implementation / brainstorming: I hope iam not re-doing some past one but i didnt quickly find a past discu= ssion Observations. Errors are for developers debuging or users resolving problems We rarely care about more then 2-3 independant errors but we care about= their history like from where they came and how and what arguments caused = them We also care about the error free case being fast, really fast We are lazy we dont want maintaince burden We also dont want to deal with maintaining matching cleanup for each ge= nerated error Idea 1 + very simple + fully compatible can be freely mixed with existing error codes - needs a global table + we never alloc, so we have no cleanup to do + zero overhead for passing around as its just integers Idea 2 (Alternatrive) This is exactly like Idea 1 but using thread local instead of a global = tabl + No mutex + no global table + no denial of service if a thread blasts errors out while another has = an occasional error - Thread local table - More complex and slow to move errors accross thread boundaries For both ideas: * New error codes are 64bit * if they are trunctaed to 32bit they are a valid 32bit error code like AVE= RROR(EIO) * That means the new error codes are 32bit (existing error code for compati= bility) and 32bit (a identifier into a fixed size table.) Pseudocode: #define MAX_CONCURRENT_ERRORS 256 // error 256 will use slot 0, 257 slot = 1 and so on #define MASK (MAX_CONCURRENT_ERRORS - 1) #define FREE_FORM_LEN 64 //probably we will need more, can just be bumped typedef struct AdvancedError { const char *error_name; ///< like "Timeout" or "Invalid= Bitstream" const char *operation_name; ///< like "Network Read" or "H.264 b= lock parsing" const char *source_filename; ///< like ffmpeg.c int source_line_number; ///< like line 123 in ffmpeg.c char free_form_description[FREE_FORM_LEN]; ///< anything extra that do= esnt fit in pointers to static const strings int64_t this_error; int64_t previous_error; ///< A previous related error, if any int64_t timestamp; ///< Timestamp at which the error occu= red int thread_id; } AdvancedError; struct AdvancedError advanced_error[MAX_CONCURRENT_ERRORS]; // the = whole is 32kb ATM int64_t av_adv_err_new(int error_code, const char *error_name, const char *operation_name, const char *source_filename, int source_line_number, int64_t previous_error, const char free_form_description[FREE_FORM_LEN], ) { pthread_mutex_lock() int64_t err =3D error_code + (counter++ << 32); AdvancedError *ae =3D &advanced_error[(err>>32) & MASK]; ae->error_name =3D error_name; ae->operation_name =3D operation_name; ae->source_filename =3D source_filename; ae->source_line_number =3D source_line_number; ae->this_error =3D err; ae->previous_error =3D previous_error; ae->timestamp =3D av_gettime(); memcpy(ae->free_form_description, free_form_description, FREE_FORM_= LEN); pthread_mutex_unlock() return err; } /** * Retrieve AdvancedError struct for a given error code or fail * @param adv_err [OUT] where to store the AdvancedError in * * @return 0 on success negative on failure */ int av_adv_err_retrieve(int64_t err, AdvancedError *adv_err) { int ret =3D -1; pthread_mutex_lock() int index =3D err >> 32; if (advanced_error[index & MASK].this_error =3D=3D err) { memcpy(adv_err, &advanced_error[index & MASK], sizeof(adv_err)); ret =3D 0; } pthread_mutex_unlock() return ret; } --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If you drop bombs on a foreign country and kill a hundred thousand innocent people, expect your government to call the consequence "unprovoked inhuman terrorist attacks" and use it to justify dropping more bombs and killing more people. The technology changed, the idea is old. --6Tx6JDZ2MNaN5Vow Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEKAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCaGVFqAAKCRBhHseHBAsP q6ZEAJ0a+4tBnx3ByRUcXgivYjZOTOU5OQCdFs37hv9hLpsBTqzSQDmTs4fpY5U= =2eNI -----END PGP SIGNATURE----- --6Tx6JDZ2MNaN5Vow-- --===============6357278062649508372== 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". --===============6357278062649508372==--