* [FFmpeg-devel] [PATCH] fftools/ffprobe: Switch to AVMutex
@ 2025-02-21 11:20 Andreas Rheinhardt
0 siblings, 0 replies; only message in thread
From: Andreas Rheinhardt @ 2025-02-21 11:20 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 14 bytes --]
Patch attached
[-- Attachment #2: 0001-fftools-ffprobe-Switch-to-AVMutex.patch --]
[-- Type: text/x-patch, Size: 3690 bytes --]
From 27090fa53a1adf8ea33fd8b223c352cf367bafe6 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 21 Feb 2025 11:24:53 +0100
Subject: [PATCH] fftools/ffprobe: Switch to AVMutex
This removes several #if checks. While just at it, also use
the correct mutex initializer (did this even work on all systems?)
and make the mutex static.
This commit does not enable -show_log for builds without threads
though.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
fftools/ffprobe.c | 38 +++++++++++---------------------------
1 file changed, 11 insertions(+), 27 deletions(-)
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 0270878ead..44138ab936 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -71,17 +71,6 @@
#include "libavutil/thread.h"
-#if !HAVE_THREADS
-# ifdef pthread_mutex_lock
-# undef pthread_mutex_lock
-# endif
-# define pthread_mutex_lock(a) do{}while(0)
-# ifdef pthread_mutex_unlock
-# undef pthread_mutex_unlock
-# endif
-# define pthread_mutex_unlock(a) do{}while(0)
-#endif
-
// attached as opaque_ref to packets/frames
typedef struct FrameData {
int64_t pkt_pos;
@@ -389,9 +378,8 @@ static int *selected_streams;
static int *streams_with_closed_captions;
static int *streams_with_film_grain;
-#if HAVE_THREADS
-pthread_mutex_t log_mutex;
-#endif
+static AVMutex log_mutex = AV_MUTEX_INITIALIZER;
+
typedef struct LogBuffer {
char *context_name;
int log_level;
@@ -418,7 +406,7 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
va_end(vl2);
#if HAVE_THREADS
- pthread_mutex_lock(&log_mutex);
+ ff_mutex_lock(&log_mutex);
new_log_buffer = av_realloc_array(log_buffer, log_buffer_size + 1, sizeof(*log_buffer));
if (new_log_buffer) {
@@ -449,7 +437,7 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
log_buffer_size ++;
}
- pthread_mutex_unlock(&log_mutex);
+ ff_mutex_unlock(&log_mutex);
#endif
}
@@ -2718,7 +2706,7 @@ static void clear_log(int need_lock)
int i;
if (need_lock)
- pthread_mutex_lock(&log_mutex);
+ ff_mutex_lock(&log_mutex);
for (i=0; i<log_buffer_size; i++) {
av_freep(&log_buffer[i].context_name);
av_freep(&log_buffer[i].parent_name);
@@ -2726,15 +2714,15 @@ static void clear_log(int need_lock)
}
log_buffer_size = 0;
if(need_lock)
- pthread_mutex_unlock(&log_mutex);
+ ff_mutex_unlock(&log_mutex);
}
static int show_log(WriterContext *w, int section_ids, int section_id, int log_level)
{
int i;
- pthread_mutex_lock(&log_mutex);
+ ff_mutex_lock(&log_mutex);
if (!log_buffer_size) {
- pthread_mutex_unlock(&log_mutex);
+ ff_mutex_unlock(&log_mutex);
return 0;
}
writer_print_section_header(w, NULL, section_ids);
@@ -2757,7 +2745,7 @@ static int show_log(WriterContext *w, int section_ids, int section_id, int log_l
}
}
clear_log(0);
- pthread_mutex_unlock(&log_mutex);
+ ff_mutex_unlock(&log_mutex);
writer_print_section_footer(w);
@@ -4663,12 +4651,10 @@ int main(int argc, char **argv)
init_dynload();
-#if HAVE_THREADS
- ret = pthread_mutex_init(&log_mutex, NULL);
+ ret = ff_mutex_init(&log_mutex, NULL);
if (ret != 0) {
goto end;
}
-#endif
av_log_set_flags(AV_LOG_SKIP_REPEATED);
options = real_options;
@@ -4816,9 +4802,7 @@ end:
avformat_network_deinit();
-#if HAVE_THREADS
- pthread_mutex_destroy(&log_mutex);
-#endif
+ ff_mutex_destroy(&log_mutex);
return ret < 0;
}
--
2.45.2
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] only message in thread
only message in thread, other threads:[~2025-02-21 11:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-21 11:20 [FFmpeg-devel] [PATCH] fftools/ffprobe: Switch to AVMutex Andreas Rheinhardt
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