This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

The following commit(s) were added to refs/heads/master by this push:
     new b8c5376eb4 avcodec/vorbis_parser: Improve returned error codes
b8c5376eb4 is described below

commit b8c5376eb4e0a97c187aa51d7a5d8b0007ce1577
Author:     Andreas Rheinhardt <[email protected]>
AuthorDate: Thu Apr 15 03:56:36 2021 +0200
Commit:     Andreas Rheinhardt <[email protected]>
CommitDate: Sat May 30 13:10:07 2026 +0200

    avcodec/vorbis_parser: Improve returned error codes
    
    av_vorbis_parse_init() doesn't return an error code which is a slight
    problem in libvorbisenc.c. Fix this by making the internal
    initialization function behind av_vorbis_parse_init() available. This
    also avoids allocations and frees.
    
    Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/libvorbisenc.c           | 14 ++++++--------
 libavcodec/vorbis_parser.c          | 29 +++++++++--------------------
 libavcodec/vorbis_parser_internal.h |  8 ++++++--
 3 files changed, 21 insertions(+), 30 deletions(-)

diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c
index 06b234a7d8..352a5e1297 100644
--- a/libavcodec/libvorbisenc.c
+++ b/libavcodec/libvorbisenc.c
@@ -32,6 +32,7 @@
 #include "encode.h"
 #include "version.h"
 #include "vorbis_parser.h"
+#include "vorbis_parser_internal.h"
 
 
 /* Number of samples the user should send in each call.
@@ -53,7 +54,7 @@ typedef struct LibvorbisEncContext {
     int dsp_initialized;                /**< vd has been initialized        */
     vorbis_comment vc;                  /**< VorbisComment info             */
     double iblock;                      /**< impulse block bias option      */
-    AVVorbisParseContext *vp;           /**< parse context to get durations */
+    AVVorbisParseContext vp;            /**< parse context to get durations */
     AudioFrameQueue afq;                /**< frame queue for timestamps     */
 } LibvorbisEncContext;
 
@@ -224,7 +225,7 @@ static av_cold int 
libvorbis_get_priming_samples(vorbis_info *vi, AVCodecContext
             ret = vorbis_error_to_averror(ret);
             goto error;
         }
-        avctx->initial_padding = av_vorbis_parse_frame(s->vp, op.packet, 
op.bytes);
+        avctx->initial_padding = av_vorbis_parse_frame(&s->vp, op.packet, 
op.bytes);
     }
 
     ret = 0;
@@ -256,8 +257,6 @@ static av_cold int libvorbis_encode_close(AVCodecContext 
*avctx)
     av_fifo_freep2(&s->pkt_fifo);
     ff_af_queue_close(&s->afq);
 
-    av_vorbis_parse_free(&s->vp);
-
     return 0;
 }
 
@@ -319,10 +318,9 @@ static av_cold int libvorbis_encode_init(AVCodecContext 
*avctx)
     offset += header_code.bytes;
     av_assert0(offset == avctx->extradata_size);
 
-    s->vp = av_vorbis_parse_init(avctx->extradata, avctx->extradata_size);
-    if (!s->vp) {
+    ret = ff_vorbis_parse_init(&s->vp, avctx->extradata, 
avctx->extradata_size);
+    if (ret < 0) {
         av_log(avctx, AV_LOG_ERROR, "invalid extradata\n");
-        ret = AVERROR_UNKNOWN;
         goto error;
     }
 
@@ -415,7 +413,7 @@ static int libvorbis_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 
     avpkt->pts = ff_samples_to_time_base(avctx, op.granulepos);
 
-    duration = av_vorbis_parse_frame(s->vp, avpkt->data, avpkt->size);
+    duration = av_vorbis_parse_frame(&s->vp, avpkt->data, avpkt->size);
     if (duration > 0) {
         int discard_padding;
 
diff --git a/libavcodec/vorbis_parser.c b/libavcodec/vorbis_parser.c
index 88b81fcb53..8070004e61 100644
--- a/libavcodec/vorbis_parser.c
+++ b/libavcodec/vorbis_parser.c
@@ -184,8 +184,8 @@ bad_header:
     return ret;
 }
 
-static int vorbis_parse_init(AVVorbisParseContext *s,
-                             const uint8_t *extradata, int extradata_size)
+int ff_vorbis_parse_init(AVVorbisParseContext *s,
+                         const uint8_t *extradata, int extradata_size)
 {
     const uint8_t *header_start[3];
     int header_len[3];
@@ -291,7 +291,7 @@ AVVorbisParseContext *av_vorbis_parse_init(const uint8_t 
*extradata,
     if (!s)
         return NULL;
 
-    ret = vorbis_parse_init(s, extradata, extradata_size);
+    ret = ff_vorbis_parse_init(s, extradata, extradata_size);
     if (ret < 0) {
         av_vorbis_parse_free(&s);
         return NULL;
@@ -302,24 +302,20 @@ AVVorbisParseContext *av_vorbis_parse_init(const uint8_t 
*extradata,
 
 #if CONFIG_VORBIS_PARSER
 
-typedef struct VorbisParseContext {
-    AVVorbisParseContext *vp;
-} VorbisParseContext;
-
 static int vorbis_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
                         const uint8_t **poutbuf, int *poutbuf_size,
                         const uint8_t *buf, int buf_size)
 {
-    VorbisParseContext *s = s1->priv_data;
+    AVVorbisParseContext *s = s1->priv_data;
     int duration;
 
-    if (!s->vp && avctx->extradata && avctx->extradata_size) {
-        s->vp = av_vorbis_parse_init(avctx->extradata, avctx->extradata_size);
+    if (!s->valid_extradata && avctx->extradata && avctx->extradata_size) {
+        ff_vorbis_parse_init(s, avctx->extradata, avctx->extradata_size);
     }
-    if (!s->vp)
+    if (!s->valid_extradata)
         goto end;
 
-    if ((duration = av_vorbis_parse_frame(s->vp, buf, buf_size)) >= 0)
+    if ((duration = av_vorbis_parse_frame(s, buf, buf_size)) >= 0)
         s1->duration = duration;
 
 end:
@@ -330,16 +326,9 @@ end:
     return buf_size;
 }
 
-static av_cold void vorbis_parser_close(AVCodecParserContext *ctx)
-{
-    VorbisParseContext *s = ctx->priv_data;
-    av_vorbis_parse_free(&s->vp);
-}
-
 const FFCodecParser ff_vorbis_parser = {
     PARSER_CODEC_LIST(AV_CODEC_ID_VORBIS),
-    .priv_data_size = sizeof(VorbisParseContext),
+    .priv_data_size = sizeof(AVVorbisParseContext),
     .parse          = vorbis_parse,
-    .close          = vorbis_parser_close,
 };
 #endif /* CONFIG_VORBIS_PARSER */
diff --git a/libavcodec/vorbis_parser_internal.h 
b/libavcodec/vorbis_parser_internal.h
index 691a842385..556d8fdccb 100644
--- a/libavcodec/vorbis_parser_internal.h
+++ b/libavcodec/vorbis_parser_internal.h
@@ -28,11 +28,12 @@
 #ifndef AVCODEC_VORBIS_PARSER_INTERNAL_H
 #define AVCODEC_VORBIS_PARSER_INTERNAL_H
 
-#include "avcodec.h"
+#include <stdint.h>
+
 #include "vorbis_parser.h"
 
 struct AVVorbisParseContext {
-    const AVClass *class;
+    const struct AVClass *class;
     int extradata_parsed;       ///< we have attempted to parse extradata
     int valid_extradata;        ///< extradata is valid, so we can calculate 
duration
     int blocksize[2];           ///< short and long window sizes
@@ -43,4 +44,7 @@ struct AVVorbisParseContext {
     int prev_mask;              ///< bitmask used to get the previous mode 
flag in each packet
 };
 
+int ff_vorbis_parse_init(AVVorbisParseContext *s,
+                         const uint8_t *extradata, int extradata_size);
+
 #endif /* AVCODEC_VORBIS_PARSER_INTERNAL_H */

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to