diff mbox series

[FFmpeg-devel,01/19] lavc/avcodec: improve enc/dec API doxy

Message ID 20230125165537.5371-1-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/19] lavc/avcodec: improve enc/dec API doxy | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Jan. 25, 2023, 4:55 p.m. UTC
Change return value descriptions into proper lists.
---
 libavcodec/avcodec.h | 81 +++++++++++++++++++++++---------------------
 1 file changed, 42 insertions(+), 39 deletions(-)

Comments

Michael Niedermayer Jan. 25, 2023, 8:51 p.m. UTC | #1
On Wed, Jan 25, 2023 at 05:55:34PM +0100, Anton Khirnov wrote:
> ---
>  libavcodec/libwebpenc_animencoder.c | 35 +++++++++++++++++++++++++++--
>  1 file changed, 33 insertions(+), 2 deletions(-)

breaks:
ffmpeg  -i lena.pnm -bitexact -y /tmp/file.webp
...
[libwebp_anim @ 0x2d19bdc0] Using libwebp for RGB-to-YUV conversion. You may want to consider passing in YUV instead for lossy encoding.
==11922== Invalid read of size 8
==11922==    at 0x99F606: libwebp_anim_encode_frame (in ffmpeg_g)
==11922==    by 0x86EA44: ff_encode_encode_cb (in ffmpeg_g)
==11922==    by 0x86EE59: encode_receive_packet_internal (in ffmpeg_g)
==11922==    by 0x86F04F: avcodec_send_frame (in ffmpeg_g)
==11922==    by 0x30EDB2: encode_frame (in ffmpeg_g)
==11922==    by 0x3185A8: transcode (in ffmpeg_g)
==11922==    by 0x2EDD63: main (in ffmpeg_g)
==11922==  Address 0x88 is not stack'd, malloc'd or (recently) free'd


[...]
Anton Khirnov Jan. 28, 2023, 11:11 a.m. UTC | #2
Will push the set tomorrow if nobody has further comments.
Marvin Scholz Jan. 28, 2023, 11:37 a.m. UTC | #3
On 25 Jan 2023, at 17:55, Anton Khirnov wrote:

> Change return value descriptions into proper lists.
> ---
>  libavcodec/avcodec.h | 81 +++++++++++++++++++++++---------------------
>  1 file changed, 42 insertions(+), 39 deletions(-)
>
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 0ac581d660..f3ca41f126 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -2605,17 +2605,18 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
>   *                  still has frames buffered, it will return them after sending
>   *                  a flush packet.
>   *
> - * @return 0 on success, otherwise negative error code:
> - *      AVERROR(EAGAIN):   input is not accepted in the current state - user
> - *                         must read output with avcodec_receive_frame() (once
> - *                         all output is read, the packet should be resent, and
> - *                         the call will not fail with EAGAIN).
> - *      AVERROR_EOF:       the decoder has been flushed, and no new packets can
> - *                         be sent to it (also returned if more than 1 flush
> - *                         packet is sent)
> - *      AVERROR(EINVAL):   codec not opened, it is an encoder, or requires flush
> - *      AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
> - *      other errors: legitimate decoding errors
> + * @return
> + * - 0:                 success
> + * - AVERROR(EAGAIN):   input is not accepted in the current state - user must
> + *                      read output with avcodec_receive_frame() (once all
> + *                      output is read, the packet should be resent, and the
> + *                      call will not fail with EAGAIN).
> + * - AVERROR_EOF:       the decoder has been flushed, and no new packets can be
> + *                      sent to it (also returned if more than 1 flush packet is
> + *                      sent)
> + * - AVERROR(EINVAL):   codec not opened, it is an encoder, or requires flush
> + * - AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
> + * - other errors:      legitimate decoding errors
>   */

Wouldn't @retval work better for such return value documentation?

>  int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt);
>
> @@ -2630,17 +2631,17 @@ int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt);
>   *              av_frame_unref(frame) before doing anything else.
>   *
>   * @return
> - *      0:                 success, a frame was returned
> - *      AVERROR(EAGAIN):   output is not available in this state - user must try
> - *                         to send new input
> - *      AVERROR_EOF:       the codec has been fully flushed, and there will be
> - *                         no more output frames
> - *      AVERROR(EINVAL):   codec not opened, or it is an encoder without
> - *                         the AV_CODEC_FLAG_RECON_FRAME flag enabled
> - *      AVERROR_INPUT_CHANGED:   current decoded frame has changed parameters
> - *                               with respect to first decoded frame. Applicable
> - *                               when flag AV_CODEC_FLAG_DROPCHANGED is set.
> - *      other negative values: legitimate decoding errors
> + * - 0:                     success, a frame was returned
> + * - AVERROR(EAGAIN):       output is not available in this state - user must
> + *                          try to send new input
> + * - AVERROR_EOF:           the codec has been fully flushed, and there will be
> + *                          no more output frames
> + * - AVERROR(EINVAL):       codec not opened, or it is an encoder without the
> + *                          AV_CODEC_FLAG_RECON_FRAME flag enabled
> + * - AVERROR_INPUT_CHANGED: current decoded frame has changed parameters with
> + *                          respect to first decoded frame. Applicable when flag
> + *                          AV_CODEC_FLAG_DROPCHANGED is set.
> + * - other negative values: legitimate decoding errors
>   */
>  int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
>
> @@ -2667,16 +2668,17 @@ int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
>   *                  If it is not set, frame->nb_samples must be equal to
>   *                  avctx->frame_size for all frames except the last.
>   *                  The final frame may be smaller than avctx->frame_size.
> - * @return 0 on success, otherwise negative error code:
> - *      AVERROR(EAGAIN):   input is not accepted in the current state - user
> - *                         must read output with avcodec_receive_packet() (once
> - *                         all output is read, the packet should be resent, and
> - *                         the call will not fail with EAGAIN).
> - *      AVERROR_EOF:       the encoder has been flushed, and no new frames can
> - *                         be sent to it
> - *      AVERROR(EINVAL):   codec not opened, it is a decoder, or requires flush
> - *      AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
> - *      other errors: legitimate encoding errors
> + * @return
> + * - 0:                 success
> + * - AVERROR(EAGAIN):   input is not accepted in the current state - user must
> + *                      read output with avcodec_receive_packet() (once all
> + *                      output is read, the packet should be resent, and the
> + *                      call will not fail with EAGAIN).
> + * - AVERROR_EOF:       the encoder has been flushed, and no new frames can
> + *                      be sent to it
> + * - AVERROR(EINVAL):   codec not opened, it is a decoder, or requires flush
> + * - AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
> + * - other errors:      legitimate encoding errors
>   */
>  int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame);
>
> @@ -2687,13 +2689,14 @@ int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame);
>   * @param avpkt This will be set to a reference-counted packet allocated by the
>   *              encoder. Note that the function will always call
>   *              av_packet_unref(avpkt) before doing anything else.
> - * @return 0 on success, otherwise negative error code:
> - *      AVERROR(EAGAIN):   output is not available in the current state - user
> - *                         must try to send input
> - *      AVERROR_EOF:       the encoder has been fully flushed, and there will be
> - *                         no more output packets
> - *      AVERROR(EINVAL):   codec not opened, or it is a decoder
> - *      other errors: legitimate encoding errors
> + * @return
> + * - 0:                 success
> + * - AVERROR(EAGAIN):   output is not available in the current state - user must
> + *                      try to send input
> + * - AVERROR_EOF:       the encoder has been fully flushed, and there will be no
> + *                      more output packets
> + * - AVERROR(EINVAL):   codec not opened, or it is a decoder
> + * - other errors:      legitimate encoding errors
>   */
>  int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
>
> -- 
> 2.35.1
>
> _______________________________________________
> 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".
Anton Khirnov Jan. 28, 2023, 1:23 p.m. UTC | #4
Quoting Marvin Scholz (2023-01-28 12:37:42)
> 
> 
> On 25 Jan 2023, at 17:55, Anton Khirnov wrote:
> 
> > Change return value descriptions into proper lists.
> > ---
> >  libavcodec/avcodec.h | 81 +++++++++++++++++++++++---------------------
> >  1 file changed, 42 insertions(+), 39 deletions(-)
> >
> > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > index 0ac581d660..f3ca41f126 100644
> > --- a/libavcodec/avcodec.h
> > +++ b/libavcodec/avcodec.h
> > @@ -2605,17 +2605,18 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
> >   *                  still has frames buffered, it will return them after sending
> >   *                  a flush packet.
> >   *
> > - * @return 0 on success, otherwise negative error code:
> > - *      AVERROR(EAGAIN):   input is not accepted in the current state - user
> > - *                         must read output with avcodec_receive_frame() (once
> > - *                         all output is read, the packet should be resent, and
> > - *                         the call will not fail with EAGAIN).
> > - *      AVERROR_EOF:       the decoder has been flushed, and no new packets can
> > - *                         be sent to it (also returned if more than 1 flush
> > - *                         packet is sent)
> > - *      AVERROR(EINVAL):   codec not opened, it is an encoder, or requires flush
> > - *      AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
> > - *      other errors: legitimate decoding errors
> > + * @return
> > + * - 0:                 success
> > + * - AVERROR(EAGAIN):   input is not accepted in the current state - user must
> > + *                      read output with avcodec_receive_frame() (once all
> > + *                      output is read, the packet should be resent, and the
> > + *                      call will not fail with EAGAIN).
> > + * - AVERROR_EOF:       the decoder has been flushed, and no new packets can be
> > + *                      sent to it (also returned if more than 1 flush packet is
> > + *                      sent)
> > + * - AVERROR(EINVAL):   codec not opened, it is an encoder, or requires flush
> > + * - AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
> > + * - other errors:      legitimate decoding errors
> >   */
> 
> Wouldn't @retval work better for such return value documentation?

I don't know, how is it better?
Marvin Scholz Jan. 28, 2023, 2:47 p.m. UTC | #5
On 28 Jan 2023, at 14:23, Anton Khirnov wrote:

> Quoting Marvin Scholz (2023-01-28 12:37:42)
>>
>>
>> On 25 Jan 2023, at 17:55, Anton Khirnov wrote:
>>
>>> Change return value descriptions into proper lists.
>>> ---
>>>  libavcodec/avcodec.h | 81 +++++++++++++++++++++++---------------------
>>>  1 file changed, 42 insertions(+), 39 deletions(-)
>>>
>>> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
>>> index 0ac581d660..f3ca41f126 100644
>>> --- a/libavcodec/avcodec.h
>>> +++ b/libavcodec/avcodec.h
>>> @@ -2605,17 +2605,18 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
>>>   *                  still has frames buffered, it will return them after sending
>>>   *                  a flush packet.
>>>   *
>>> - * @return 0 on success, otherwise negative error code:
>>> - *      AVERROR(EAGAIN):   input is not accepted in the current state - user
>>> - *                         must read output with avcodec_receive_frame() (once
>>> - *                         all output is read, the packet should be resent, and
>>> - *                         the call will not fail with EAGAIN).
>>> - *      AVERROR_EOF:       the decoder has been flushed, and no new packets can
>>> - *                         be sent to it (also returned if more than 1 flush
>>> - *                         packet is sent)
>>> - *      AVERROR(EINVAL):   codec not opened, it is an encoder, or requires flush
>>> - *      AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
>>> - *      other errors: legitimate decoding errors
>>> + * @return
>>> + * - 0:                 success
>>> + * - AVERROR(EAGAIN):   input is not accepted in the current state - user must
>>> + *                      read output with avcodec_receive_frame() (once all
>>> + *                      output is read, the packet should be resent, and the
>>> + *                      call will not fail with EAGAIN).
>>> + * - AVERROR_EOF:       the decoder has been flushed, and no new packets can be
>>> + *                      sent to it (also returned if more than 1 flush packet is
>>> + *                      sent)
>>> + * - AVERROR(EINVAL):   codec not opened, it is an encoder, or requires flush
>>> + * - AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
>>> + * - other errors:      legitimate decoding errors
>>>   */
>>
>> Wouldn't @retval work better for such return value documentation?
>
> I don't know, how is it better?
>

It should produce a more consistent output like in other places that use retval and is
semantically the more correct choice here.

Currently the documentation of possible return values is a bit all over the place with
some using lists, others just explain the values in a sentence, other places use retval.

IMO we should consistently try to use retval where it makes sense.

> -- 
> 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".
diff mbox series

Patch

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 0ac581d660..f3ca41f126 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2605,17 +2605,18 @@  int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
  *                  still has frames buffered, it will return them after sending
  *                  a flush packet.
  *
- * @return 0 on success, otherwise negative error code:
- *      AVERROR(EAGAIN):   input is not accepted in the current state - user
- *                         must read output with avcodec_receive_frame() (once
- *                         all output is read, the packet should be resent, and
- *                         the call will not fail with EAGAIN).
- *      AVERROR_EOF:       the decoder has been flushed, and no new packets can
- *                         be sent to it (also returned if more than 1 flush
- *                         packet is sent)
- *      AVERROR(EINVAL):   codec not opened, it is an encoder, or requires flush
- *      AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
- *      other errors: legitimate decoding errors
+ * @return
+ * - 0:                 success
+ * - AVERROR(EAGAIN):   input is not accepted in the current state - user must
+ *                      read output with avcodec_receive_frame() (once all
+ *                      output is read, the packet should be resent, and the
+ *                      call will not fail with EAGAIN).
+ * - AVERROR_EOF:       the decoder has been flushed, and no new packets can be
+ *                      sent to it (also returned if more than 1 flush packet is
+ *                      sent)
+ * - AVERROR(EINVAL):   codec not opened, it is an encoder, or requires flush
+ * - AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
+ * - other errors:      legitimate decoding errors
  */
 int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt);
 
@@ -2630,17 +2631,17 @@  int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt);
  *              av_frame_unref(frame) before doing anything else.
  *
  * @return
- *      0:                 success, a frame was returned
- *      AVERROR(EAGAIN):   output is not available in this state - user must try
- *                         to send new input
- *      AVERROR_EOF:       the codec has been fully flushed, and there will be
- *                         no more output frames
- *      AVERROR(EINVAL):   codec not opened, or it is an encoder without
- *                         the AV_CODEC_FLAG_RECON_FRAME flag enabled
- *      AVERROR_INPUT_CHANGED:   current decoded frame has changed parameters
- *                               with respect to first decoded frame. Applicable
- *                               when flag AV_CODEC_FLAG_DROPCHANGED is set.
- *      other negative values: legitimate decoding errors
+ * - 0:                     success, a frame was returned
+ * - AVERROR(EAGAIN):       output is not available in this state - user must
+ *                          try to send new input
+ * - AVERROR_EOF:           the codec has been fully flushed, and there will be
+ *                          no more output frames
+ * - AVERROR(EINVAL):       codec not opened, or it is an encoder without the
+ *                          AV_CODEC_FLAG_RECON_FRAME flag enabled
+ * - AVERROR_INPUT_CHANGED: current decoded frame has changed parameters with
+ *                          respect to first decoded frame. Applicable when flag
+ *                          AV_CODEC_FLAG_DROPCHANGED is set.
+ * - other negative values: legitimate decoding errors
  */
 int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
 
@@ -2667,16 +2668,17 @@  int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
  *                  If it is not set, frame->nb_samples must be equal to
  *                  avctx->frame_size for all frames except the last.
  *                  The final frame may be smaller than avctx->frame_size.
- * @return 0 on success, otherwise negative error code:
- *      AVERROR(EAGAIN):   input is not accepted in the current state - user
- *                         must read output with avcodec_receive_packet() (once
- *                         all output is read, the packet should be resent, and
- *                         the call will not fail with EAGAIN).
- *      AVERROR_EOF:       the encoder has been flushed, and no new frames can
- *                         be sent to it
- *      AVERROR(EINVAL):   codec not opened, it is a decoder, or requires flush
- *      AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
- *      other errors: legitimate encoding errors
+ * @return
+ * - 0:                 success
+ * - AVERROR(EAGAIN):   input is not accepted in the current state - user must
+ *                      read output with avcodec_receive_packet() (once all
+ *                      output is read, the packet should be resent, and the
+ *                      call will not fail with EAGAIN).
+ * - AVERROR_EOF:       the encoder has been flushed, and no new frames can
+ *                      be sent to it
+ * - AVERROR(EINVAL):   codec not opened, it is a decoder, or requires flush
+ * - AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
+ * - other errors:      legitimate encoding errors
  */
 int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame);
 
@@ -2687,13 +2689,14 @@  int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame);
  * @param avpkt This will be set to a reference-counted packet allocated by the
  *              encoder. Note that the function will always call
  *              av_packet_unref(avpkt) before doing anything else.
- * @return 0 on success, otherwise negative error code:
- *      AVERROR(EAGAIN):   output is not available in the current state - user
- *                         must try to send input
- *      AVERROR_EOF:       the encoder has been fully flushed, and there will be
- *                         no more output packets
- *      AVERROR(EINVAL):   codec not opened, or it is a decoder
- *      other errors: legitimate encoding errors
+ * @return
+ * - 0:                 success
+ * - AVERROR(EAGAIN):   output is not available in the current state - user must
+ *                      try to send input
+ * - AVERROR_EOF:       the encoder has been fully flushed, and there will be no
+ *                      more output packets
+ * - AVERROR(EINVAL):   codec not opened, or it is a decoder
+ * - other errors:      legitimate encoding errors
  */
 int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);