From: Anton Khirnov <anton@khirnov.net> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH 05/29] lavu/opt: distinguish between native and foreign access for AVOption fields Date: Tue, 05 Mar 2024 10:48:03 +0100 Message-ID: <170963208351.29002.10012269504779997538@lain.khirnov.net> (raw) In-Reply-To: <fc4b221f-ff76-978a-f5c8-7690545adfb7@passwd.hu> Quoting Marton Balint (2024-03-04 23:39:19) > On Mon, 4 Mar 2024, Anton Khirnov wrote: > > Native access is from the code that declared the options, foreign access > > is from code that is using the options. Forbid foreign access to > > AVOption.offset/default_val, for which there is no good reason, and > > which should allow us more freedom in extending their semantics in a > > compatible way. > > --- > > libavutil/opt.h | 14 ++++++++++++++ > > 1 file changed, 14 insertions(+) > > > > diff --git a/libavutil/opt.h b/libavutil/opt.h > > index e34b8506f8..e402f6a0a0 100644 > > --- a/libavutil/opt.h > > +++ b/libavutil/opt.h > > @@ -43,6 +43,16 @@ > > * ("objects"). An option can have a help text, a type and a range of possible > > * values. Options may then be enumerated, read and written to. > > * > > + * There are two modes of access to members of AVOption and its child structs. > > + * One is called 'native access', and refers to access from the code that > > + * declares the AVOption in question. The other is 'foreign access', and refers > > + * to access from other code. > > + * > > + * Certain struct members in this header are documented as 'native access only' > > + * or similar - it means that only the code that declared the AVOption in > > + * question is allowed to access the field. This allows us to extend the > > + * semantics of those fields without breaking API compatibility. > > + * > > Changing private/public status of existing fields retrospecitvely can be > considered an API break. I see this more as establishing/clarifying the status of those fields rather than changing it. While the idea that everything not explicitly forbidden is allowed is nice in theory, I don't think it's viable for us, because so many (especially older) APIs are barely documented, if at all. If we adhered to it strictly, almost any extension of existing APIs could be considered a break. E.g. consider that it is not publicly documented what C type does any AVOption type map to, or even that we can add new ones. > > * @section avoptions_implement Implementing AVOptions > > * This section describes how to add AVOptions capabilities to a struct. > > * > > @@ -301,6 +311,8 @@ typedef struct AVOption { > > const char *help; > > > > /** > > + * Native access only. > > + * > > * The offset relative to the context structure where the option > > * value is stored. It should be 0 for named constants. > > I don't quite see the reason hiding this. I think it is pretty safe to > say that its semantics won't change, and getting the offset, adding it to > the object pointer and directly reading or writing the value is the most > efficient way to get or set the values. This is precisely what the callers have no business doing IMO, and what the AVOption API is supposed to abstract away. AVOptions are not supposed to be especially efficient currently, but if some use case requires that we should add new API to make access more efficient - e.g. that accepts AVOptions rather than string option names, and flags that make setters take ownership rather than copy. > Also there is av_opt_ptr() which implicitly returns this anyway. Or > you want to fully disallow pointer based member access? Yes I do, at least in this generic type-unsafe form. av_opt_ptr() has a single caller in our codebase that I'd like to get rid of, and then deprecate+remove the function itself. Also note that the fact av_opt_ptr() exists at all supports my interpretation that option users are not supposed to access offset. > Some issues would be: > 1) for a dictionary type you don't have a getter which does not copy > 2) some types simply don't have a native typed getter/setter function > 3) if you have multiple object of the same class, when using getters > there will always be a linear search for the attribute name each time you > get/set. All of these can and should be solved with better getter/setter API. > > > */ > > @@ -308,6 +320,8 @@ typedef struct AVOption { > > enum AVOptionType type; > > > > /** > > + * Native access only. > > + * > > * the default value for scalar options > > */ > > One could argue that it will be more difficult to get the default value of > an option (you'd have to create an object, call av_opt_set_defaults() and > finally do av_opt_get), but what I find more problematic is the > inconsistency. You are not allowed to access default_val, unless it is an > array type, in which case you might access it to get array settings, but - > oh well - not the default value. I consistently forbid users to read the default value directly, they have to read it from the object. The only inconsistency is that default_val stores far more than just the default value for array options, but that follows from the constraints we are operating under. Recall the previous version of this patch where I put those values elsewhere and you objected to it. > In general, we should avoid having public API fields which are in fact > private. We have existing techniques to really hide those. For instance? The problem is those fields are not purely private, they are public in some contexts (what I call 'native access'), and private in others. That means they have to appear in the public header. > Considering we can always add new option types to define new > semantics, I don't really think that keeping the existing public API > fields public is such a blow. I would much prefer not to be forced to add gazillions of option types for every minor semantics difference we might want to introduce. -- Anton Khirnov _______________________________________________ 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".
next prev parent reply other threads:[~2024-03-05 9:48 UTC|newest] Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-03-04 13:06 [FFmpeg-devel] [PATCH 01/29] lavu/opt: factor per-type dispatch out of av_opt_get() Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 02/29] lavu/opt: factor per-type dispatch out of av_opt_set() Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 03/29] libavutil/opt: rework figuring out option sizes Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 04/29] lavu/opt: factor per-type dispatch out of av_opt_copy() Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 05/29] lavu/opt: distinguish between native and foreign access for AVOption fields Anton Khirnov 2024-03-04 22:39 ` Marton Balint 2024-03-05 9:48 ` Anton Khirnov [this message] 2024-03-05 10:17 ` Diederick C. Niehorster 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 06/29] lavu/opt: add array options Anton Khirnov 2024-03-04 13:29 ` Andreas Rheinhardt 2024-03-04 21:00 ` Anton Khirnov 2024-03-05 8:52 ` Andreas Rheinhardt 2024-03-07 14:50 ` Andreas Rheinhardt 2024-03-07 15:24 ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov 2024-03-04 21:32 ` [FFmpeg-devel] [PATCH " Marton Balint 2024-03-05 9:50 ` Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 07/29] lavc: add a decoder option for configuring side data preference Anton Khirnov 2024-03-04 14:05 ` Derek Buitenhuis 2024-03-05 9:57 ` Anton Khirnov 2024-03-05 12:30 ` James Almer 2024-03-05 14:29 ` Anton Khirnov 2024-03-05 14:35 ` James Almer 2024-03-05 14:54 ` Anton Khirnov 2024-03-05 15:07 ` James Almer 2024-03-05 15:19 ` Anton Khirnov 2024-03-06 13:58 ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 08/29] avcodec: add internal side data wrappers Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 09/29] lavc: add content light/mastering display " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 10/29] avcodec/av1dec: respect side data preference Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 11/29] avcodec/cri: " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 12/29] avcodec/h264_slice: " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 13/29] lavc/hevcdec: pass an actual codec context to ff_h2645_sei_to_frame() Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 14/29] avcodec/hevcdec: respect side data preference Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 15/29] avcodec/libjxldec: " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 16/29] avcodec/mjpegdec: " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 17/29] avcodec/mpeg12dec: " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 18/29] avcodec/pngdec: " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 19/29] avcodec/tiff: " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 20/29] avcodec/webp: " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 21/29] avcodec/libdav1d: " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 22/29] avcodec/dpx: " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 23/29] avcodec/mpeg12dec: use ff_frame_new_side_data Anton Khirnov 2024-03-04 13:36 ` Andreas Rheinhardt 2024-03-05 10:00 ` Anton Khirnov 2024-03-07 11:19 ` Andreas Rheinhardt 2024-03-07 12:18 ` Anton Khirnov 2024-03-07 12:25 ` James Almer 2024-03-07 12:37 ` Anton Khirnov 2024-03-07 20:05 ` Niklas Haas 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 24/29] avcodec/h2645_sei: use ff_frame_new_side_data_from_buf Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 25/29] avcodec/snowdec: use ff_frame_new_side_data Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 26/29] avcodec/mjpegdec: " Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 27/29] avcodec/hevcdec: switch to ff_frame_new_side_data_from_buf Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 28/29] lavc/*dec: use side data preference for mastering display/content light metadata Anton Khirnov 2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 29/29] tests/fate/matroska: add tests for side data preference Anton Khirnov 2024-03-07 23:42 ` Andreas Rheinhardt 2024-03-07 9:30 ` [FFmpeg-devel] [PATCH 01/29] lavu/opt: factor per-type dispatch out of av_opt_get() Anton Khirnov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=170963208351.29002.10012269504779997538@lain.khirnov.net \ --to=anton@khirnov.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git