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

Git pushed a commit to branch master
in repository ffmpeg.

commit f20ea3fb22ee9e8590604b8dfba6868ad1a9fd74
Author:     Marton Balint <[email protected]>
AuthorDate: Sun Mar 29 15:05:26 2026 +0200
Commit:     Marton Balint <[email protected]>
CommitDate: Wed May 13 22:41:23 2026 +0200

    avformat/hlsenc: dynamically allocate segment uris along with the segment 
struct
    
    As suggested by Andreas Rheinhardt.
    
    Supersedes: #22536.
    
    Signed-off-by: Marton Balint <[email protected]>
---
 libavformat/hlsenc.c | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index df24b17ab6..b342c85e90 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -74,8 +74,8 @@ typedef enum {
 #define POSTFIX_PATTERN "_%d"
 
 typedef struct HLSSegment {
-    char filename[MAX_URL_SIZE];
-    char sub_filename[MAX_URL_SIZE];
+    const char *filename;
+    const char *sub_filename;
     double duration; /* in seconds */
     int discont;
     int64_t pos;
@@ -84,11 +84,13 @@ typedef struct HLSSegment {
     int64_t keyframe_size;
     unsigned var_stream_idx;
 
-    char key_uri[LINE_BUFFER_SIZE + 1];
+    const char *key_uri;
     char iv_string[KEYSIZE*2 + 1];
 
     struct HLSSegment *next;
     double discont_program_date_time;
+
+    char buf[]; /* for filename, sub_filename and key_uri */
 } HLSSegment;
 
 typedef enum HLSFlags {
@@ -1041,13 +1043,12 @@ static int hls_append_segment(struct AVFormatContext 
*s, HLSContext *hls,
                               VariantStream *vs, double duration, int64_t pos,
                               int64_t size)
 {
-    HLSSegment *en = av_malloc(sizeof(*en));
+    HLSSegment en0 = {0};
+    HLSSegment *en = &en0;
     const char  *filename;
     int byterange_mode = (hls->flags & HLS_SINGLE_FILE) || (hls->max_seg_size 
> 0);
     int ret;
-
-    if (!en)
-        return AVERROR(ENOMEM);
+    AVBPrint bp;
 
     vs->total_size += size;
     vs->total_duration += duration;
@@ -1063,10 +1064,8 @@ static int hls_append_segment(struct AVFormatContext *s, 
HLSContext *hls,
 
     en->var_stream_idx = vs->var_stream_idx;
     ret = sls_flags_filename_process(s, hls, vs, en, duration, pos, size);
-    if (ret < 0) {
-        av_freep(&en);
+    if (ret < 0)
         return ret;
-    }
 
     filename = av_basename(vs->avf->url);
 
@@ -1077,21 +1076,16 @@ static int hls_append_segment(struct AVFormatContext 
*s, HLSContext *hls,
         && !byterange_mode) {
         av_log(hls, AV_LOG_WARNING, "Duplicated segment filename detected: 
%s\n", filename);
     }
-    av_strlcpy(en->filename, filename, sizeof(en->filename));
 
-    if (vs->has_subtitle)
-        av_strlcpy(en->sub_filename, av_basename(vs->vtt_avf->url), 
sizeof(en->sub_filename));
-    else
-        en->sub_filename[0] = '\0';
+    av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
+    av_bprintf(&bp, "%s%c", filename, 0);
+    av_bprintf(&bp, "%s%c", vs->has_subtitle ? av_basename(vs->vtt_avf->url) : 
"", 0);
 
     en->duration = duration;
     en->pos      = pos;
     en->size     = size;
     en->keyframe_pos      = vs->video_keyframe_pos;
     en->keyframe_size     = vs->video_keyframe_size;
-    en->next     = NULL;
-    en->discont  = 0;
-    en->discont_program_date_time = 0;
 
     if (vs->discontinuity) {
         en->discont = 1;
@@ -1099,10 +1093,21 @@ static int hls_append_segment(struct AVFormatContext 
*s, HLSContext *hls,
     }
 
     if (hls->key_info_file || hls->encrypt) {
-        av_strlcpy(en->key_uri, vs->key_uri, sizeof(en->key_uri));
+        av_bprintf(&bp, "%s%c", vs->key_uri, 0);
         av_strlcpy(en->iv_string, vs->iv_string, sizeof(en->iv_string));
+    } else {
+        av_bprint_chars(&bp, 0, 1);
     }
 
+    en = ff_bprint_finalize_as_fam(&bp, &en0, sizeof(en0), en0.buf);
+    if (!en)
+        return AVERROR(ENOMEM);
+#define NEXT(s) ((s) + strlen(s) + 1)
+    en->filename = en->buf;
+    en->sub_filename = NEXT(en->filename);
+    en->key_uri = NEXT(en->sub_filename);
+#undef NEXT
+
     if (!vs->segments)
         vs->segments = en;
     else
@@ -1536,7 +1541,7 @@ static int hls_window(AVFormatContext *s, int last, 
VariantStream *vs)
     int is_file_proto = proto && !strcmp(proto, "file");
     int use_temp_file = is_file_proto && ((hls->flags & HLS_TEMP_FILE) || 
!(hls->pl_type == PLAYLIST_TYPE_VOD));
     static unsigned warned_non_file;
-    char *key_uri = NULL;
+    const char *key_uri = NULL;
     char *iv_string = NULL;
     AVDictionary *options = NULL;
     double prog_date_time = vs->initial_prog_date_time;

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

Reply via email to