Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Stefano Sabatini <stefasab@gmail.com>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH v3 1/3] doc: Explain what "context" means
Date: Wed, 22 May 2024 12:37:37 +0200
Message-ID: <Zk3K8WEj9o/ZZH4n@mariano> (raw)
In-Reply-To: <Zjf0ZK2No4ir51iq@andrews-2024-laptop.sayers>

On date Sunday 2024-05-05 22:04:36 +0100, Andrew Sayers wrote:
> I'm still travelling, so the following thoughts might be a bit
> half-formed.  But I wanted to get some feedback before sitting down
> for a proper think.
[...]
> > > I've also gone through the code looking for edge cases we haven't covered.
> > > Here are some questions trying to prompt an "oh yeah I forgot to mention
> > > that"-type answer.  Anything where the answer is more like "that should
> > > probably be rewritten to be clearer", let me know and I'll avoid confusing
> > > newbies with it.
> > > 
> > 
> > > av_ambient_viewing_environment_create_side_data() takes an AVFrame as its
> > > first argument, and returns a new AVAmbientViewingEnvironment.  What is the
> > > context object for that function - AVFrame or AVAmbientViewingEnvironment?
> > 
> > But this should be clear from the doxy:
> > 
> > /**
> >  * Allocate and add an AVAmbientViewingEnvironment structure to an existing
> >  * AVFrame as side data.
> >  *
> >  * @return the newly allocated struct, or NULL on failure
> >  */
> > AVAmbientViewingEnvironment *av_ambient_viewing_environment_create_side_data(AVFrame *frame);
> 
> I'm afraid it's not clear, at least to me.  I think you're saying the
> AVFrame is the context because a "create" function can't have a
> context any more than a C++ "new" can be called as a member.  But the
> function's prefix points to the other conclusion, and neither signal
> is clear enough on its own.

No, what I'm saying is that in some cases you don't need to think in
terms of contexts, in this case there is no context at all, the
function takes a frame and modify it, and returns the ambient
environment to be used by the following functions. This should be very
clear by reading the doxy. There is no rule dictating the first param
of each FFmpeg function should be a "context".

> 
> My current thinking is to propose separate patches renaming arguments
> to `ctx` whenever I find functions I can't parse.  That's not as good
> as a simple rule like "the first argument is always the context", but
> better than adding a paragraph or two about how to read the docs.

There cannot be such rule, because it would be false in many cases.

> > Also, you are assuming that all the function should have a
> > context. That's not the case, as you don't always need to keep track
> > of a "context" when performing operations.
> 
[...]
> > > av_channel_description_bprint() takes a `struct AVBPrint *` as its first
> > > argument, then `enum AVChannel`.  Is the context AVBPrint, AVChannel,
> > > or both?  Does it make sense for a function to have two contexts?
> > 
> > Again, this should be clear from the doxy:
> > /**
> >  * Get a human readable string describing a given channel.
> >  *
> >  * @param buf pre-allocated buffer where to put the generated string
> >  * @param buf_size size in bytes of the buffer.
> >  * @param channel the AVChannel whose description to get
> >  * @return amount of bytes needed to hold the output string, or a negative AVERROR
> >  *         on failure. If the returned value is bigger than buf_size, then the
> >  *         string was truncated.
> >  */
> > int av_channel_description(char *buf, size_t buf_size, enum AVChannel channel);
> > 
> > /**
> >  * bprint variant of av_channel_description().
> >  *
> >  * @note the string will be appended to the bprint buffer.
> >  */
> > void av_channel_description_bprint(struct AVBPrint *bp, enum AVChannel channel_id);
> 

> I think you're saying that I should look at which word appears more
> often in the doxy ("channel") rather than which word appears first in
> the argument list ("buf")?  As above, the solution might be to rename
> the variable in a separate patch rather than teach people another
> special case.

This is more about the semantics described in English language by the
doxy (which is normative). Again, thinking in terms of "contexts" is
misleading in this case.

In this case you have two functions, av_channel_description writing a
string to a buffer with fixed size, the second modifying an "AVBPrint"
struct, which is a high-level buffer providing more flexibility (and
"bprint" is used as a verb in the doxy, which might be misleading).

Note that both signatures are mimicing the standard C library
convention:
memcpy(dst, dst_size, src)

which in turn is a mnemonics for:
dst = src

meaning that we are copying data from src to dst.

You might think that in fact you are operating on a context (the dst
buffer or the AVBPrint struct), but you don't need to introduce the
concept of context for these simple functions.
_______________________________________________
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".

  reply	other threads:[~2024-05-22 10:37 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18 15:06 [FFmpeg-devel] [PATCH " Andrew Sayers
2024-04-18 15:06 ` [FFmpeg-devel] [PATCH 2/3] lavu: Clarify relationship between AVClass, AVOption and context Andrew Sayers
2024-04-18 15:06 ` [FFmpeg-devel] [PATCH 3/3] all: Link to "context" from all contexts with documentation Andrew Sayers
2024-04-20  7:25 ` [FFmpeg-devel] [PATCH 1/3] doc: Explain what "context" means Stefano Sabatini
2024-04-20 12:18   ` Andrew Sayers
2024-04-20 16:13     ` Stefano Sabatini
2024-04-20 12:19   ` [FFmpeg-devel] [PATCH v2 " Andrew Sayers
2024-04-20 12:19     ` [FFmpeg-devel] [PATCH v2 2/3] lavu: Clarify relationship between AVClass, AVOption and context Andrew Sayers
2024-04-20 12:19     ` [FFmpeg-devel] [PATCH v2 3/3] all: Link to "context" from all contexts with documentation Andrew Sayers
2024-04-20 16:48     ` [FFmpeg-devel] [PATCH v2 1/3] doc: Explain what "context" means Stefano Sabatini
2024-04-20 22:17       ` Andrew Sayers
2024-04-22  8:02         ` Stefano Sabatini
2024-04-22 15:56           ` [FFmpeg-devel] [PATCH v3 0/3] all: Link to "context" from all contexts with documentation Andrew Sayers
2024-04-22 15:56             ` [FFmpeg-devel] [PATCH v3 1/3] doc: Explain what "context" means Andrew Sayers
2024-04-22 17:05               ` Stefano Sabatini
2024-04-29  9:10                 ` Andrew Sayers
2024-05-02 10:03                   ` Andrew Sayers
2024-05-05  7:29                   ` Stefano Sabatini
2024-05-05 21:04                     ` Andrew Sayers
2024-05-22 10:37                       ` Stefano Sabatini [this message]
2024-05-22 12:47                         ` Andrew Sayers
2024-05-25  9:00                           ` Stefano Sabatini
2024-04-29  9:24                 ` [FFmpeg-devel] [PATCH v4 1/4] " Andrew Sayers
2024-04-29  9:24                   ` [FFmpeg-devel] [PATCH v4 2/4] lavu: Clarify relationship between AVClass, AVOption and context Andrew Sayers
2024-04-29  9:24                   ` [FFmpeg-devel] [PATCH v4 3/4] all: Link to "context" from all contexts with documentation Andrew Sayers
2024-05-02 11:01                     ` Lynne
2024-05-02 11:14                       ` Andrew Sayers
2024-05-02 13:00                       ` Zhao Zhili
2024-05-02 13:27                         ` Andrew Sayers
2024-05-02 13:39                           ` Zhao Zhili
2024-04-29  9:24                   ` [FFmpeg-devel] [PATCH v4 4/4] lavf: Add documentation for private "Context" classes Andrew Sayers
2024-05-05  8:31                   ` [FFmpeg-devel] [PATCH v4 1/4] doc: Explain what "context" means Andreas Rheinhardt
2024-05-05 10:34                     ` Andrew Sayers
2024-04-22 15:56             ` [FFmpeg-devel] [PATCH v3 2/3] lavu: Clarify relationship between AVClass, AVOption and context Andrew Sayers
2024-04-22 15:56             ` [FFmpeg-devel] [PATCH v3 3/3] all: Link to "context" from all contexts with documentation Andrew Sayers
2024-05-15 15:54 ` [FFmpeg-devel] [PATCH v4 0/4] Explain what "context" means Andrew Sayers
2024-05-15 15:54   ` [FFmpeg-devel] [PATCH v4 1/4] doc: " Andrew Sayers
2024-05-22  9:31     ` Stefano Sabatini
2024-05-22 16:07       ` Andrew Sayers
2024-05-25  9:49         ` Stefano Sabatini
2024-05-26 12:06           ` Andrew Sayers
2024-05-28 17:24             ` Stefano Sabatini
2024-05-29 10:10               ` Andrew Sayers
2024-05-29 10:50               ` Andrew Sayers
2024-05-29 11:06                 ` Paul B Mahol
2024-05-29 14:18                   ` Andrew Sayers
2024-05-29 16:06                 ` Stefano Sabatini
2024-05-23 20:00       ` [FFmpeg-devel] [PATCH v5 0/4] " Andrew Sayers
2024-05-23 20:00         ` [FFmpeg-devel] [PATCH v5 1/4] doc: " Andrew Sayers
2024-05-25 11:00           ` Stefano Sabatini
2024-05-23 20:00         ` [FFmpeg-devel] [PATCH v5 2/4] lavu: Clarify relationship between AVClass, AVOption and context Andrew Sayers
2024-05-25  9:57           ` Stefano Sabatini
2024-05-23 20:00         ` [FFmpeg-devel] [PATCH v5 3/4] all: Link to "context" from all public contexts with documentation Andrew Sayers
2024-05-23 20:00         ` [FFmpeg-devel] [PATCH v5 4/4] all: Rewrite documentation for contexts Andrew Sayers
2024-05-24  1:50         ` [FFmpeg-devel] [PATCH v5 0/4] Explain what "context" means Michael Niedermayer
2024-05-24  9:43           ` Andrew Sayers
2024-05-15 15:54   ` [FFmpeg-devel] [PATCH v4 2/4] lavu: Clarify relationship between AVClass, AVOption and context Andrew Sayers
2024-05-22 10:04     ` Stefano Sabatini
2024-05-15 15:54   ` [FFmpeg-devel] [PATCH v4 3/4] all: Link to "context" from all contexts with documentation Andrew Sayers
2024-05-15 16:46     ` Lynne via ffmpeg-devel
2024-05-16 11:25       ` Andrew Sayers
2024-05-15 15:54   ` [FFmpeg-devel] [PATCH v4 4/4] lavf: Add documentation for private "Context" classes Andrew Sayers
2024-05-22 10:08     ` Stefano Sabatini
2024-05-22 14:47       ` Andrew Sayers
2024-05-22 15:24     ` Andreas Rheinhardt
2024-05-22 16:54       ` Andrew Sayers
2024-06-04 14:47 ` [FFmpeg-devel] [PATCH v6 0/4] doc: Explain what "context" means Andrew Sayers
2024-06-04 14:47   ` [FFmpeg-devel] [PATCH v6 1/4] " Andrew Sayers
2024-06-05  8:15     ` Anton Khirnov
2024-06-12 20:52     ` Stefano Sabatini
2024-06-13 14:20       ` Andrew Sayers
2024-06-15  9:17         ` Stefano Sabatini
2024-06-16 18:02           ` [FFmpeg-devel] Development process for explaining contexts (was Re: [PATCH v6 1/4] doc: Explain what "context" means) Andrew Sayers
2024-06-16 21:20             ` Paul B Mahol
2024-07-01 22:16             ` Stefano Sabatini
2024-07-02  9:56               ` Andrew Sayers
2024-07-06 11:33                 ` Stefano Sabatini
2024-06-04 14:47   ` [FFmpeg-devel] [PATCH v6 2/4] lavu: Clarify relationship between AVClass, AVOption and context Andrew Sayers
2024-06-05 10:34     ` Stefano Sabatini
2024-06-05 12:46       ` Andrew Sayers
2024-06-04 14:47   ` [FFmpeg-devel] [PATCH v6 3/4] all: Link to "context" from all public contexts with documentation Andrew Sayers
2024-06-05  8:12     ` Anton Khirnov
2024-06-05 12:51       ` Andrew Sayers
2024-06-04 14:47   ` [FFmpeg-devel] [PATCH v6 4/4] all: Rewrite documentation for contexts Andrew Sayers

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=Zk3K8WEj9o/ZZH4n@mariano \
    --to=stefasab@gmail.com \
    --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 http://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/ http://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