Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: Redo checking for strftime %s support to avoid warnings
@ 2024-03-05 10:27 Andreas Rheinhardt
  2024-03-05 10:28 ` [FFmpeg-devel] [PATCH 2/2] avformat/dashenc, hlsenc: Return 0 on succes from write_header Andreas Rheinhardt
  2024-03-05 12:54 ` [FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: Redo checking for strftime %s support to avoid warnings Liu Steven
  0 siblings, 2 replies; 3+ messages in thread
From: Andreas Rheinhardt @ 2024-03-05 10:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

This is intended to avoid -Wformat= warnings on systems
where %s might not be supported (and also generally emitted
by GCC with -pedantic).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/hlsenc.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index a19b9bb3d1..d5cd627e59 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1878,18 +1878,23 @@ fail:
 
 static const char * get_default_pattern_localtime_fmt(AVFormatContext *s)
 {
+    HLSContext *hls = s->priv_data;
+#if HAVE_LIBC_MSVCRT
+    // no %s support on MSVC, which invokes the invalid parameter handler
+    // on unsupported format strings, instead of returning an error
+    int strftime_s_supported = 0;
+#else
     char b[21];
     time_t t = time(NULL);
-    struct tm *p, tmbuf;
-    HLSContext *hls = s->priv_data;
-
-    p = localtime_r(&t, &tmbuf);
+    struct tm tmbuf, *p = localtime_r(&t, &tmbuf);
     // no %s support when strftime returned error or left format string unchanged
-    // also no %s support on MSVC, which invokes the invalid parameter handler on unsupported format strings, instead of returning an error
+    int strftime_s_supported = strftime(b, sizeof(b), "%s", p) && strcmp(b, "%s");
+#endif
+
     if (hls->segment_type == SEGMENT_TYPE_FMP4) {
-        return (HAVE_LIBC_MSVCRT || !strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ? "-%Y%m%d%H%M%S.m4s" : "-%s.m4s";
+        return strftime_s_supported ? "-%s.m4s" : "-%Y%m%d%H%M%S.m4s";
     }
-    return (HAVE_LIBC_MSVCRT || !strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ? "-%Y%m%d%H%M%S.ts" : "-%s.ts";
+    return strftime_s_supported ? "-%s.ts" : "-%Y%m%d%H%M%S.ts";
 }
 
 static int append_postfix(char *name, int name_buf_len, int i)
-- 
2.40.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".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] avformat/dashenc, hlsenc: Return 0 on succes from write_header
  2024-03-05 10:27 [FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: Redo checking for strftime %s support to avoid warnings Andreas Rheinhardt
@ 2024-03-05 10:28 ` Andreas Rheinhardt
  2024-03-05 12:54 ` [FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: Redo checking for strftime %s support to avoid warnings Liu Steven
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Rheinhardt @ 2024-03-05 10:28 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Do not propagate the return value of avformat_write_header(),
as it contains the information whether the output had
already been initialized in avformat_init_output(),
but this is set generically; the return value of
FFOutputFormat.write_header is not documented at all
(and is currently ignored if >= 0), but it is more future-proof
to simply return 0 on success.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/dashenc.c | 2 +-
 libavformat/hlsenc.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 435a5e8afe..5e31b09486 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -1747,7 +1747,7 @@ static int dash_write_header(AVFormatContext *s)
             (ret = flush_init_segment(s, os)) < 0)
             return ret;
     }
-    return ret;
+    return 0;
 }
 
 static int add_segment(OutputStream *os, const char *file,
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index d5cd627e59..e560aa6a20 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2372,7 +2372,7 @@ static int hls_write_header(AVFormatContext *s)
         }
     }
 
-    return ret;
+    return 0;
 }
 
 static int hls_init_file_resend(AVFormatContext *s, VariantStream *vs)
-- 
2.40.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".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: Redo checking for strftime %s support to avoid warnings
  2024-03-05 10:27 [FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: Redo checking for strftime %s support to avoid warnings Andreas Rheinhardt
  2024-03-05 10:28 ` [FFmpeg-devel] [PATCH 2/2] avformat/dashenc, hlsenc: Return 0 on succes from write_header Andreas Rheinhardt
@ 2024-03-05 12:54 ` Liu Steven
  1 sibling, 0 replies; 3+ messages in thread
From: Liu Steven @ 2024-03-05 12:54 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Liu Steven



> On Mar 5, 2024, at 18:27, Andreas Rheinhardt <andreas.rheinhardt@outlook.com> wrote:
> 
> This is intended to avoid -Wformat= warnings on systems
> where %s might not be supported (and also generally emitted
> by GCC with -pedantic).
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavformat/hlsenc.c | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index a19b9bb3d1..d5cd627e59 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1878,18 +1878,23 @@ fail:
> 
> static const char * get_default_pattern_localtime_fmt(AVFormatContext *s)
> {
> +    HLSContext *hls = s->priv_data;
> +#if HAVE_LIBC_MSVCRT
> +    // no %s support on MSVC, which invokes the invalid parameter handler
> +    // on unsupported format strings, instead of returning an error
> +    int strftime_s_supported = 0;
> +#else
>     char b[21];
>     time_t t = time(NULL);
> -    struct tm *p, tmbuf;
> -    HLSContext *hls = s->priv_data;
> -
> -    p = localtime_r(&t, &tmbuf);
> +    struct tm tmbuf, *p = localtime_r(&t, &tmbuf);
>     // no %s support when strftime returned error or left format string unchanged
> -    // also no %s support on MSVC, which invokes the invalid parameter handler on unsupported format strings, instead of returning an error
> +    int strftime_s_supported = strftime(b, sizeof(b), "%s", p) && strcmp(b, "%s");
> +#endif
> +
>     if (hls->segment_type == SEGMENT_TYPE_FMP4) {
> -        return (HAVE_LIBC_MSVCRT || !strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ? "-%Y%m%d%H%M%S.m4s" : "-%s.m4s";
> +        return strftime_s_supported ? "-%s.m4s" : "-%Y%m%d%H%M%S.m4s";
>     }
> -    return (HAVE_LIBC_MSVCRT || !strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ? "-%Y%m%d%H%M%S.ts" : "-%s.ts";
> +    return strftime_s_supported ? "-%s.ts" : "-%Y%m%d%H%M%S.ts";
> }
> 
> static int append_postfix(char *name, int name_buf_len, int i)
> -- 
> 2.40.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”.
patchset looks good to me


Thanks
Steven


_______________________________________________
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".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-05 12:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-05 10:27 [FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: Redo checking for strftime %s support to avoid warnings Andreas Rheinhardt
2024-03-05 10:28 ` [FFmpeg-devel] [PATCH 2/2] avformat/dashenc, hlsenc: Return 0 on succes from write_header Andreas Rheinhardt
2024-03-05 12:54 ` [FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: Redo checking for strftime %s support to avoid warnings Liu Steven

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