[FFmpeg-cvslog] avutil/mem: use GCC builtins to check for overflow in av_size_mult()

2021-05-31 Thread James Almer
ffmpeg | branch: master | James Almer  | Thu May 27 11:58:57 
2021 -0300| [baf5cc5b7a016efaa0d9bf3dfe62ad74ef4ffafe] | committer: James Almer

avutil/mem: use GCC builtins to check for overflow in av_size_mult()

Signed-off-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=baf5cc5b7a016efaa0d9bf3dfe62ad74ef4ffafe
---

 libavutil/mem.h | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavutil/mem.h b/libavutil/mem.h
index e21a1feaae..c876111afb 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -674,11 +674,18 @@ void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, 
size_t elem_size,
  */
 static inline int av_size_mult(size_t a, size_t b, size_t *r)
 {
-size_t t = a * b;
+size_t t;
+
+#if (!defined(__INTEL_COMPILER) && AV_GCC_VERSION_AT_LEAST(5,1)) || 
AV_HAS_BUILTIN(__builtin_mul_overflow)
+if (__builtin_mul_overflow(a, b, &t))
+return AVERROR(EINVAL);
+#else
+t = a * b;
 /* Hack inspired from glibc: don't try the division if nelem and elsize
  * are both less than sqrt(SIZE_MAX). */
 if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
 return AVERROR(EINVAL);
+#endif
 *r = t;
 return 0;
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavf/dashenc.c: Fix creating audio-only HLS playlists

2021-05-31 Thread Przemysław Sobala
ffmpeg | branch: master | Przemysław Sobala  | Thu 
May 20 11:50:27 2021 +0200| [575e52272d42f4278c6620f1a999c41425db2094] | 
committer: Karthick J

lavf/dashenc.c: Fix creating audio-only HLS playlists

With audio/video HLS playlists, audio chunklists are treated as
alternative renditions for video chunklists. This is wrong for
audio-only HLS playlists.

fixes: 9252

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=575e52272d42f4278c6620f1a999c41425db2094
---

 libavformat/dashenc.c | 139 ++
 1 file changed, 85 insertions(+), 54 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index ebbdfd627c..810ab22416 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -1256,14 +1256,10 @@ static int write_manifest(AVFormatContext *s, int final)
 
 if (c->hls_playlist) {
 char filename_hls[1024];
-const char *audio_group = "A1";
-char audio_codec_str[128] = "\0";
-int is_default = 1;
-int max_audio_bitrate = 0;
 
 // Publish master playlist only the configured rate
 if (c->master_playlist_created && (!c->master_publish_rate ||
- c->streams[0].segment_index % c->master_publish_rate))
+c->streams[0].segment_index % c->master_publish_rate))
 return 0;
 
 if (*c->dirname)
@@ -1282,60 +1278,95 @@ static int write_manifest(AVFormatContext *s, int final)
 
 ff_hls_write_playlist_version(c->m3u8_out, 7);
 
-for (i = 0; i < s->nb_streams; i++) {
-char playlist_file[64];
-AVStream *st = s->streams[i];
-OutputStream *os = &c->streams[i];
-if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO)
-continue;
-if (os->segment_type != SEGMENT_TYPE_MP4)
-continue;
-get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, 
i);
-ff_hls_write_audio_rendition(c->m3u8_out, (char *)audio_group,
- playlist_file, NULL, i, is_default);
-max_audio_bitrate = FFMAX(st->codecpar->bit_rate +
-  os->muxer_overhead, max_audio_bitrate);
-if (!av_strnstr(audio_codec_str, os->codec_str, 
sizeof(audio_codec_str))) {
-if (strlen(audio_codec_str))
-av_strlcat(audio_codec_str, ",", sizeof(audio_codec_str));
-av_strlcat(audio_codec_str, os->codec_str, 
sizeof(audio_codec_str));
+if (c->has_video) {
+// treat audio streams as alternative renditions for video streams
+const char *audio_group = "A1";
+char audio_codec_str[128] = "\0";
+int is_default = 1;
+int max_audio_bitrate = 0;
+
+for (i = 0; i < s->nb_streams; i++) {
+char playlist_file[64];
+AVStream *st = s->streams[i];
+OutputStream *os = &c->streams[i];
+if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO)
+continue;
+if (os->segment_type != SEGMENT_TYPE_MP4)
+continue;
+get_hls_playlist_name(playlist_file, sizeof(playlist_file), 
NULL, i);
+ff_hls_write_audio_rendition(c->m3u8_out, (char *)audio_group,
+ playlist_file, NULL, i, 
is_default);
+max_audio_bitrate = FFMAX(st->codecpar->bit_rate +
+  os->muxer_overhead, 
max_audio_bitrate);
+if (!av_strnstr(audio_codec_str, os->codec_str, 
sizeof(audio_codec_str))) {
+if (strlen(audio_codec_str))
+av_strlcat(audio_codec_str, ",", 
sizeof(audio_codec_str));
+av_strlcat(audio_codec_str, os->codec_str, 
sizeof(audio_codec_str));
+}
+is_default = 0;
 }
-is_default = 0;
-}
 
-for (i = 0; i < s->nb_streams; i++) {
-char playlist_file[64];
-char codec_str[128];
-AVStream *st = s->streams[i];
-OutputStream *os = &c->streams[i];
-char *agroup = NULL;
-char *codec_str_ptr = NULL;
-int stream_bitrate = os->muxer_overhead;
-if (os->bit_rate > 0)
-stream_bitrate += os->bit_rate;
-else if (final)
-stream_bitrate += os->pos * 8 * AV_TIME_BASE / 
c->total_duration;
-else if (os->first_segment_bit_rate > 0)
-stream_bitrate += os->first_segment_bit_rate;
-if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
-continue;
-if (os->segment_type != SEGMENT_TYPE_MP4)
-continue;
-av_strlcpy(codec_str, os->codec_str, sizeof(codec_str));
-if (max_audio_bitrate) {
-agroup