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] lsws/swscale.h: introduce sws_get_gaussian_vec
Date: Sun, 3 Sep 2023 02:25:07 +0200
Message-ID: <ZPPSY6IGhj9tBUeg@mariano> (raw)
In-Reply-To: <20230902200753.GB8640@pb2>

On date Saturday 2023-09-02 22:07:53 +0200, Michael Niedermayer wrote:
> On Fri, Sep 01, 2023 at 08:38:26PM +0200, Stefano Sabatini wrote:
> > On date Friday 2023-09-01 18:54:40 +0200, Michael Niedermayer wrote:
> > > On Thu, Aug 31, 2023 at 07:16:20PM +0200, Stefano Sabatini wrote:
> > [...]
> > > > +/**
> > > > + * Compute and return a normalized Gaussian vector.
> > > > + *
> > > > + * @param vecp: pointer where the computed vector is put in case of
> > > > + *        success
> > > > + * @param standard_deviation the standard deviation used to generate
> > > > + *        the Gaussian vector, must be a non-negative value
> > > > + * @param quality the quality of the generated Gaussian vector, must
> > > > + *        be a non-negative value. It affects the lenght of the generated
> > > > + *        vector. A value equal to 3 corresponds to high quality.
> > > > + * @param log_ctx a pointer to an arbitrary struct of which the first
> > > > + *        field is a pointer to an AVClass struct (used for av_log)
> > > > + *        used for logging, can be NULL
> > > > + *
> > > > + * @return a negative error code on error, non negative otherwise
> > > > + */
> > > > +int sws_get_gaussian_vec(SwsVector **vecp,
> > > > +                         double standard_deviation, double quality,
> > > > +                         void *log_ctx);
> > > 
> > > which of the two do you consider better?
> > > 
> > > First, here the central part we return is the vector
> > > 
> > > SwsVector *gaus_vec = sws_getGaussianVec(NULL, 1, 2);
> > > SwsVector *temp_vec = sws_ConvolveVec(NULL, in_vec, gaus_vec);
> > > sws_averageVec(temp_vec, temp_vec, in_vec);
> > > 
> > > av_free(gaus_vec);
> > > return temp_vec; // Error checking here happens by temp_vec being NULL in all cases of error
> > > 
> > > vs.
> > > 
> > > Second, here the central part we return is the error code
> > > 
> > > SwsVector *gaus_vec = NULL;
> > > SwsVector *temp_vec = NULL;
> > > int err = sws_getGaussianVec(&gaus_vec, 1, 2);
> > > if (err<0)
> > >     goto fail;
> > > 
> > > err = sws_ConvolveVec(&temp_vec, in_vec, gaus_vec);
> > > if (err<0)
> > >     goto fail;
> > > 
> > > err = sws_averageVec(&temp_vec, temp_vec, in_vec);
> > > if (err<0)
> > >     goto fail;
> > 
> > The latter pattern enables differentiation between error codes (ENOMEM
> > or EINVAL) and provides feedback in the log message. With the former
> > you only know if it fails, but you don't know why (relevant in case
> > e.g. we make the parameter tunable by a filter and we don't want to
> > add additional validation and logging at the filter level).
> 

> can the API be designed so that optionally the user could choose to
> only check the error code after several steps ?
> (this would avoid the need for 1 check per call where the fine grained
>  information is not needed)
> I mean similar to the concept of NAN in floating point so that a failure
> can be propagated and only at the end checked.

Well, with the new approach you can do:

SwsVector *gaus_vec, *temp_vec, *avg_vec;

sws_get_gaussian_vec(&gaus_vec, 1, 2);
sws_get_convolution_vec(&temp_vec, in_vec, gaus_vec);
sws_get_average_vec(&avg_vec, temp_vec, in_vec);
 
av_free(gaus_vec);
av_free(temp_vec);
return avg_vec; // Error checking here happens by avg_vec being NULL in all cases of error

If you want to disable the log we could add a log_ctx_offset parameter.
_______________________________________________
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:[~2023-09-03  0:25 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-26 12:23 Stefano Sabatini
2023-08-26 15:15 ` Andreas Rheinhardt
2023-08-31 15:32   ` Stefano Sabatini
2023-08-31 16:51     ` Andreas Rheinhardt
2023-08-31 17:16       ` Stefano Sabatini
2023-09-01 16:54         ` Michael Niedermayer
2023-09-01 18:38           ` Stefano Sabatini
2023-09-02 20:07             ` Michael Niedermayer
2023-09-03  0:25               ` Stefano Sabatini [this message]
2023-09-03 16:34                 ` Michael Niedermayer
2023-08-26 15:15 ` Anton Khirnov
2023-08-31 15:06   ` Stefano Sabatini
2023-09-01 15:50     ` Anton Khirnov
2023-09-01 18:28       ` Stefano Sabatini
2023-09-05 11:19         ` Anton Khirnov
2023-09-05 22:59           ` Stefano Sabatini
2023-09-06 11:13             ` Anton Khirnov
2023-11-04 21:38               ` Stefano Sabatini

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=ZPPSY6IGhj9tBUeg@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 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