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/6] avformat/utils: Use static mutexes instead of ff_lock_avformat()
@ 2024-05-17 15:23 Andreas Rheinhardt
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 2/6] avformat/tls_openssl: #if ff_openssl_init/deinit() away if possible Andreas Rheinhardt
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-05-17 15:23 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Its existence is a remnant of (libavcodec's) lock-manager API
which has been removed in a04c2c707de2ce850f79870e84ac9d7ec7aa9143.
There is no need to use the same lock for avisynth, chromaprint
or tls, so switch to ordinary static mutexes instead.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/avisynth.c    | 15 +++++++++------
 libavformat/chromaprint.c | 12 +++++++-----
 libavformat/internal.h    |  3 ---
 libavformat/tls_gnutls.c  | 16 +++++++---------
 libavformat/tls_openssl.c | 17 +++++++----------
 libavformat/utils.c       | 13 -------------
 6 files changed, 30 insertions(+), 46 deletions(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 1709bf4051..625bdf7e3a 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -23,6 +23,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
+#include "libavutil/thread.h"
 
 #include "avformat.h"
 #include "demux.h"
@@ -130,6 +131,8 @@ static const int avs_planes_yuva[4]   = { AVS_PLANAR_Y, AVS_PLANAR_U,
 static const int avs_planes_rgba[4]   = { AVS_PLANAR_G, AVS_PLANAR_B,
                                           AVS_PLANAR_R, AVS_PLANAR_A };
 
+static AVMutex avisynth_mutex = AV_MUTEX_INITIALIZER;
+
 /* A conflict between C++ global objects, atexit, and dynamic loading requires
  * us to register our own atexit handler to prevent double freeing. */
 static AviSynthLibrary avs_library;
@@ -1083,15 +1086,15 @@ static av_cold int avisynth_read_header(AVFormatContext *s)
     int ret;
 
     // Calling library must implement a lock for thread-safe opens.
-    if (ret = ff_lock_avformat())
-        return ret;
+    if (ff_mutex_lock(&avisynth_mutex))
+        return AVERROR_UNKNOWN;
 
     if (ret = avisynth_open_file(s)) {
-        ff_unlock_avformat();
+        ff_mutex_unlock(&avisynth_mutex);
         return ret;
     }
 
-    ff_unlock_avformat();
+    ff_mutex_unlock(&avisynth_mutex);
     return 0;
 }
 
@@ -1127,11 +1130,11 @@ static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
 
 static av_cold int avisynth_read_close(AVFormatContext *s)
 {
-    if (ff_lock_avformat())
+    if (ff_mutex_lock(&avisynth_mutex))
         return AVERROR_UNKNOWN;
 
     avisynth_context_destroy(s->priv_data);
-    ff_unlock_avformat();
+    ff_mutex_unlock(&avisynth_mutex);
     return 0;
 }
 
diff --git a/libavformat/chromaprint.c b/libavformat/chromaprint.c
index 1cdca47ea5..eae233a651 100644
--- a/libavformat/chromaprint.c
+++ b/libavformat/chromaprint.c
@@ -20,15 +20,17 @@
  */
 
 #include "avformat.h"
-#include "internal.h"
 #include "mux.h"
 #include "libavutil/opt.h"
+#include "libavutil/thread.h"
 #include <chromaprint.h>
 
 #define CPR_VERSION_INT AV_VERSION_INT(CHROMAPRINT_VERSION_MAJOR, \
                                        CHROMAPRINT_VERSION_MINOR, \
                                        CHROMAPRINT_VERSION_PATCH)
 
+static AVMutex chromaprint_mutex = AV_MUTEX_INITIALIZER;
+
 typedef enum FingerprintFormat {
     FINGERPRINT_RAW,
     FINGERPRINT_COMPRESSED,
@@ -52,9 +54,9 @@ static void deinit(AVFormatContext *s)
     ChromaprintMuxContext *const cpr = s->priv_data;
 
     if (cpr->ctx) {
-        ff_lock_avformat();
+        ff_mutex_lock(&chromaprint_mutex);
         chromaprint_free(cpr->ctx);
-        ff_unlock_avformat();
+        ff_mutex_unlock(&chromaprint_mutex);
     }
 }
 
@@ -63,9 +65,9 @@ static av_cold int init(AVFormatContext *s)
     ChromaprintMuxContext *cpr = s->priv_data;
     AVStream *st;
 
-    ff_lock_avformat();
+    ff_mutex_lock(&chromaprint_mutex);
     cpr->ctx = chromaprint_new(cpr->algorithm);
-    ff_unlock_avformat();
+    ff_mutex_unlock(&chromaprint_mutex);
 
     if (!cpr->ctx) {
         av_log(s, AV_LOG_ERROR, "Failed to create chromaprint context.\n");
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 7f3d1c0086..6bad4fd119 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -727,9 +727,6 @@ struct AVBPrint;
  */
 int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf);
 
-int ff_lock_avformat(void);
-int ff_unlock_avformat(void);
-
 /**
  * Set AVFormatContext url field to the provided pointer. The pointer must
  * point to a valid string. The existing url field is freed if necessary. Also
diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c
index 2ab38a199b..df251ad79c 100644
--- a/libavformat/tls_gnutls.c
+++ b/libavformat/tls_gnutls.c
@@ -25,15 +25,12 @@
 #include <gnutls/x509.h>
 
 #include "avformat.h"
-#include "internal.h"
 #include "network.h"
 #include "os_support.h"
 #include "url.h"
 #include "tls.h"
-#include "libavcodec/internal.h"
-#include "libavutil/avstring.h"
 #include "libavutil/opt.h"
-#include "libavutil/parseutils.h"
+#include "libavutil/thread.h"
 
 #ifndef GNUTLS_VERSION_NUMBER
 #define GNUTLS_VERSION_NUMBER LIBGNUTLS_VERSION_NUMBER
@@ -41,7 +38,6 @@
 
 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER <= 0x020b00
 #include <gcrypt.h>
-#include "libavutil/thread.h"
 GCRY_THREAD_OPTION_PTHREAD_IMPL;
 #endif
 
@@ -54,22 +50,24 @@ typedef struct TLSContext {
     int io_err;
 } TLSContext;
 
+static AVMutex gnutls_mutex = AV_MUTEX_INITIALIZER;
+
 void ff_gnutls_init(void)
 {
-    ff_lock_avformat();
+    ff_mutex_lock(&gnutls_mutex);
 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER < 0x020b00
     if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
         gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
 #endif
     gnutls_global_init();
-    ff_unlock_avformat();
+    ff_mutex_unlock(&gnutls_mutex);
 }
 
 void ff_gnutls_deinit(void)
 {
-    ff_lock_avformat();
+    ff_mutex_lock(&gnutls_mutex);
     gnutls_global_deinit();
-    ff_unlock_avformat();
+    ff_mutex_unlock(&gnutls_mutex);
 }
 
 static int print_tls_error(URLContext *h, int ret)
diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
index b875be32f0..89d7c6e1ea 100644
--- a/libavformat/tls_openssl.c
+++ b/libavformat/tls_openssl.c
@@ -19,17 +19,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "avformat.h"
-#include "internal.h"
 #include "network.h"
 #include "os_support.h"
 #include "url.h"
 #include "tls.h"
-#include "libavutil/avstring.h"
-#include "libavutil/avutil.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
-#include "libavutil/parseutils.h"
 #include "libavutil/thread.h"
 
 #include <openssl/bio.h>
@@ -49,6 +44,8 @@ typedef struct TLSContext {
     int io_err;
 } TLSContext;
 
+static AVMutex openssl_mutex = AV_MUTEX_INITIALIZER;
+
 #if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
 #include <openssl/crypto.h>
 pthread_mutex_t *openssl_mutexes;
@@ -69,7 +66,7 @@ static unsigned long openssl_thread_id(void)
 
 int ff_openssl_init(void)
 {
-    ff_lock_avformat();
+    ff_mutex_lock(&openssl_mutex);
     if (!openssl_init) {
         /* OpenSSL 1.0.2 or below, then you would use SSL_library_init. If you are
          * using OpenSSL 1.1.0 or above, then the library will initialize
@@ -85,7 +82,7 @@ int ff_openssl_init(void)
             int i;
             openssl_mutexes = av_malloc_array(sizeof(pthread_mutex_t), CRYPTO_num_locks());
             if (!openssl_mutexes) {
-                ff_unlock_avformat();
+                ff_mutex_unlock(&openssl_mutex);
                 return AVERROR(ENOMEM);
             }
 
@@ -99,14 +96,14 @@ int ff_openssl_init(void)
 #endif
     }
     openssl_init++;
-    ff_unlock_avformat();
+    ff_mutex_unlock(&openssl_mutex);
 
     return 0;
 }
 
 void ff_openssl_deinit(void)
 {
-    ff_lock_avformat();
+    ff_mutex_lock(&openssl_mutex);
     openssl_init--;
     if (!openssl_init) {
 #if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
@@ -119,7 +116,7 @@ void ff_openssl_deinit(void)
         }
 #endif
     }
-    ff_unlock_avformat();
+    ff_mutex_unlock(&openssl_mutex);
 }
 
 static int print_tls_error(URLContext *h, int ret)
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 4dded7aea4..e9ded627ad 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -27,7 +27,6 @@
 #include "libavutil/bprint.h"
 #include "libavutil/internal.h"
 #include "libavutil/mem.h"
-#include "libavutil/thread.h"
 #include "libavutil/time.h"
 
 #include "libavcodec/internal.h"
@@ -40,23 +39,11 @@
 #endif
 #include "os_support.h"
 
-static AVMutex avformat_mutex = AV_MUTEX_INITIALIZER;
-
 /**
  * @file
  * various utility functions for use within FFmpeg
  */
 
-int ff_lock_avformat(void)
-{
-    return ff_mutex_lock(&avformat_mutex) ? -1 : 0;
-}
-
-int ff_unlock_avformat(void)
-{
-    return ff_mutex_unlock(&avformat_mutex) ? -1 : 0;
-}
-
 /* an arbitrarily chosen "sane" max packet size -- 50M */
 #define SANE_CHUNK_SIZE (50000000)
 
-- 
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] 13+ messages in thread

* [FFmpeg-devel] [PATCH 2/6] avformat/tls_openssl: #if ff_openssl_init/deinit() away if possible
  2024-05-17 15:23 [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() Andreas Rheinhardt
@ 2024-05-17 15:25 ` Andreas Rheinhardt
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 3/6] avformat/tee: Constify AVDictionaryEntry* pointee where possible Andreas Rheinhardt
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-05-17 15:25 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

These functions do nothing useful when used with a non-ancient
version of openssl (namely 1.1.0 or above).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/network.c     |  9 +++++++--
 libavformat/tls_openssl.c | 34 ++++++++++++++++++++--------------
 2 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/libavformat/network.c b/libavformat/network.c
index f752efc411..6db82b6d26 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -18,8 +18,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
 #include "config_components.h"
 
+#if CONFIG_TLS_PROTOCOL && CONFIG_OPENSSL
+#include <openssl/opensslv.h>
+#endif
+
 #include <fcntl.h>
 #include "network.h"
 #include "tls.h"
@@ -31,7 +36,7 @@
 int ff_tls_init(void)
 {
 #if CONFIG_TLS_PROTOCOL
-#if CONFIG_OPENSSL
+#if CONFIG_OPENSSL && OPENSSL_VERSION_NUMBER < 0x10100000L
     int ret;
     if ((ret = ff_openssl_init()) < 0)
         return ret;
@@ -46,7 +51,7 @@ int ff_tls_init(void)
 void ff_tls_deinit(void)
 {
 #if CONFIG_TLS_PROTOCOL
-#if CONFIG_OPENSSL
+#if CONFIG_OPENSSL && OPENSSL_VERSION_NUMBER < 0x10100000L
     ff_openssl_deinit();
 #endif
 #if CONFIG_GNUTLS
diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
index 89d7c6e1ea..8b0cf9efb2 100644
--- a/libavformat/tls_openssl.c
+++ b/libavformat/tls_openssl.c
@@ -23,16 +23,12 @@
 #include "os_support.h"
 #include "url.h"
 #include "tls.h"
-#include "libavutil/mem.h"
 #include "libavutil/opt.h"
-#include "libavutil/thread.h"
 
 #include <openssl/bio.h>
 #include <openssl/ssl.h>
 #include <openssl/err.h>
 
-static int openssl_init;
-
 typedef struct TLSContext {
     const AVClass *class;
     TLSShared tls_shared;
@@ -44,10 +40,22 @@ typedef struct TLSContext {
     int io_err;
 } TLSContext;
 
+/* OpenSSL 1.0.2 or below, then you would use SSL_library_init. If you are
+ * using OpenSSL 1.1.0 or above, then the library will initialize
+ * itself automatically.
+ * https://wiki.openssl.org/index.php/Library_Initialization
+ */
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#include "libavutil/thread.h"
+
 static AVMutex openssl_mutex = AV_MUTEX_INITIALIZER;
 
-#if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
+static int openssl_init;
+
+#if HAVE_THREADS
 #include <openssl/crypto.h>
+#include "libavutil/mem.h"
+
 pthread_mutex_t *openssl_mutexes;
 static void openssl_lock(int mode, int type, const char *file, int line)
 {
@@ -68,16 +76,9 @@ int ff_openssl_init(void)
 {
     ff_mutex_lock(&openssl_mutex);
     if (!openssl_init) {
-        /* OpenSSL 1.0.2 or below, then you would use SSL_library_init. If you are
-         * using OpenSSL 1.1.0 or above, then the library will initialize
-         * itself automatically.
-         * https://wiki.openssl.org/index.php/Library_Initialization
-         */
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
         SSL_library_init();
         SSL_load_error_strings();
-#endif
-#if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
+#if HAVE_THREADS
         if (!CRYPTO_get_locking_callback()) {
             int i;
             openssl_mutexes = av_malloc_array(sizeof(pthread_mutex_t), CRYPTO_num_locks());
@@ -106,7 +107,7 @@ void ff_openssl_deinit(void)
     ff_mutex_lock(&openssl_mutex);
     openssl_init--;
     if (!openssl_init) {
-#if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
+#if HAVE_THREADS
         if (CRYPTO_get_locking_callback() == openssl_lock) {
             int i;
             CRYPTO_set_locking_callback(NULL);
@@ -118,6 +119,7 @@ void ff_openssl_deinit(void)
     }
     ff_mutex_unlock(&openssl_mutex);
 }
+#endif
 
 static int print_tls_error(URLContext *h, int ret)
 {
@@ -157,7 +159,9 @@ static int tls_close(URLContext *h)
     if (c->url_bio_method)
         BIO_meth_free(c->url_bio_method);
 #endif
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
     ff_openssl_deinit();
+#endif
     return 0;
 }
 
@@ -253,8 +257,10 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
     BIO *bio;
     int ret;
 
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
     if ((ret = ff_openssl_init()) < 0)
         return ret;
+#endif
 
     if ((ret = ff_tls_open_underlying(c, h, uri, options)) < 0)
         goto fail;
-- 
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] 13+ messages in thread

* [FFmpeg-devel] [PATCH 3/6] avformat/tee: Constify AVDictionaryEntry* pointee where possible
  2024-05-17 15:23 [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() Andreas Rheinhardt
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 2/6] avformat/tls_openssl: #if ff_openssl_init/deinit() away if possible Andreas Rheinhardt
@ 2024-05-17 15:25 ` Andreas Rheinhardt
  2024-05-17 15:42   ` epirat07
  2024-05-17 16:17   ` Andreas Rheinhardt
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 4/6] avformat/tee: Use smaller scope for variables Andreas Rheinhardt
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-05-17 15:25 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

This is in preparation for using av_dict_iterate().

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

diff --git a/libavformat/tee.c b/libavformat/tee.c
index 1cbbb80dbb..87159681ed 100644
--- a/libavformat/tee.c
+++ b/libavformat/tee.c
@@ -158,7 +158,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
 {
     int i, ret;
     AVDictionary *options = NULL, *bsf_options = NULL;
-    AVDictionaryEntry *entry;
+    const AVDictionaryEntry *entry;
     char *filename;
     char *format = NULL, *select = NULL, *on_fail = NULL;
     char *use_fifo = NULL, *fifo_options_str = NULL;
@@ -172,8 +172,9 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
         return ret;
 
 #define CONSUME_OPTION(option, field, action) do {                      \
-        if ((entry = av_dict_get(options, option, NULL, 0))) {          \
-            field = entry->value;                                       \
+        AVDictionaryEntry *en = av_dict_get(options, option, NULL, 0);  \
+        if (en) {                                                       \
+            field = en->value;                                          \
             { action }                                                  \
             av_dict_set(&options, option, NULL, 0);                     \
         }                                                               \
-- 
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] 13+ messages in thread

* [FFmpeg-devel] [PATCH 4/6] avformat/tee: Use smaller scope for variables
  2024-05-17 15:23 [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() Andreas Rheinhardt
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 2/6] avformat/tls_openssl: #if ff_openssl_init/deinit() away if possible Andreas Rheinhardt
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 3/6] avformat/tee: Constify AVDictionaryEntry* pointee where possible Andreas Rheinhardt
@ 2024-05-17 15:25 ` Andreas Rheinhardt
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 5/6] avcodec/lib*, avformat/tee: Simplify iterating over AVDictionary Andreas Rheinhardt
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-05-17 15:25 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/tee.c | 71 +++++++++++++++++++++++------------------------
 1 file changed, 35 insertions(+), 36 deletions(-)

diff --git a/libavformat/tee.c b/libavformat/tee.c
index 87159681ed..0c0543fa65 100644
--- a/libavformat/tee.c
+++ b/libavformat/tee.c
@@ -119,7 +119,6 @@ static int parse_slave_fifo_options(const char *fifo_options, TeeSlave *tee_slav
 static int close_slave(TeeSlave *tee_slave)
 {
     AVFormatContext *avf;
-    unsigned i;
     int ret = 0;
 
     av_dict_free(&tee_slave->fifo_options);
@@ -131,7 +130,7 @@ static int close_slave(TeeSlave *tee_slave)
         ret = av_write_trailer(avf);
 
     if (tee_slave->bsfs) {
-        for (i = 0; i < avf->nb_streams; ++i)
+        for (unsigned i = 0; i < avf->nb_streams; ++i)
             av_bsf_free(&tee_slave->bsfs[i]);
     }
     av_freep(&tee_slave->stream_map);
@@ -146,9 +145,8 @@ static int close_slave(TeeSlave *tee_slave)
 static void close_slaves(AVFormatContext *avf)
 {
     TeeContext *tee = avf->priv_data;
-    unsigned i;
 
-    for (i = 0; i < tee->nb_slaves; i++) {
+    for (unsigned i = 0; i < tee->nb_slaves; i++) {
         close_slave(&tee->slaves[i]);
     }
     av_freep(&tee->slaves);
@@ -156,14 +154,12 @@ static void close_slaves(AVFormatContext *avf)
 
 static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
 {
-    int i, ret;
+    int ret;
     AVDictionary *options = NULL, *bsf_options = NULL;
     const AVDictionaryEntry *entry;
     char *filename;
-    char *format = NULL, *select = NULL, *on_fail = NULL;
-    char *use_fifo = NULL, *fifo_options_str = NULL;
+    char *format = NULL, *select = NULL;
     AVFormatContext *avf2 = NULL;
-    AVStream *st, *st2;
     int stream_count;
     int fullret;
     char *subselect = NULL, *next_subselect = NULL, *first_subselect = NULL, *tmp_select = NULL;
@@ -181,22 +177,25 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
     } while (0)
 #define STEAL_OPTION(option, field)                                     \
     CONSUME_OPTION(option, field,                                       \
-                   entry->value = NULL; /* prevent it from being freed */)
-#define PROCESS_OPTION(option, field, function, on_error)               \
-    CONSUME_OPTION(option, field, if ((ret = function) < 0) { { on_error } goto end; })
+                   en->value = NULL; /* prevent it from being freed */)
+#define PROCESS_OPTION(option, function, on_error) do {                 \
+        const char *value;                                              \
+        CONSUME_OPTION(option, value, if ((ret = function) < 0)         \
+                                          { { on_error } goto end; });  \
+    } while (0)
 
     STEAL_OPTION("f", format);
     STEAL_OPTION("select", select);
-    PROCESS_OPTION("onfail", on_fail,
-                   parse_slave_failure_policy_option(on_fail, tee_slave),
+    PROCESS_OPTION("onfail",
+                   parse_slave_failure_policy_option(value, tee_slave),
                    av_log(avf, AV_LOG_ERROR, "Invalid onfail option value, "
                           "valid options are 'abort' and 'ignore'\n"););
-    PROCESS_OPTION("use_fifo", use_fifo,
-                   parse_slave_fifo_policy(use_fifo, tee_slave),
+    PROCESS_OPTION("use_fifo",
+                   parse_slave_fifo_policy(value, tee_slave),
                    av_log(avf, AV_LOG_ERROR, "Error parsing fifo options: %s\n",
                           av_err2str(ret)););
-    PROCESS_OPTION("fifo_options", fifo_options_str,
-                   parse_slave_fifo_options(fifo_options_str, tee_slave), ;);
+    PROCESS_OPTION("fifo_options",
+                   parse_slave_fifo_options(value, tee_slave), ;);
     entry = NULL;
     while ((entry = av_dict_get(options, "bsfs", entry, AV_DICT_IGNORE_SUFFIX))) {
         /* trim out strlen("bsfs") characters from key */
@@ -250,8 +249,9 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
     }
 
     stream_count = 0;
-    for (i = 0; i < avf->nb_streams; i++) {
-        st = avf->streams[i];
+    for (unsigned i = 0; i < avf->nb_streams; i++) {
+        const AVStream *st = avf->streams[i];
+        AVStream *st2;
         if (select) {
             tmp_select = av_strdup(select);  // av_strtok is destructive so we regenerate it in each loop
             if (!tmp_select) {
@@ -326,7 +326,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
             spec++; /* consume separator */
         }
 
-        for (i = 0; i < avf2->nb_streams; i++) {
+        for (unsigned i = 0; i < avf2->nb_streams; i++) {
             ret = avformat_match_stream_specifier(avf2, avf2->streams[i], spec);
             if (ret < 0) {
                 av_log(avf, AV_LOG_ERROR,
@@ -357,7 +357,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
         av_dict_set(&bsf_options, entry->key, NULL, 0);
     }
 
-    for (i = 0; i < avf->nb_streams; i++){
+    for (unsigned i = 0; i < avf->nb_streams; i++){
         int target_stream = tee_slave->stream_map[i];
         if (target_stream < 0)
             continue;
@@ -407,10 +407,9 @@ end:
 
 static void log_slave(TeeSlave *slave, void *log_ctx, int log_level)
 {
-    int i;
     av_log(log_ctx, log_level, "filename:'%s' format:%s\n",
            slave->avf->url, slave->avf->oformat->name);
-    for (i = 0; i < slave->avf->nb_streams; i++) {
+    for (unsigned i = 0; i < slave->avf->nb_streams; i++) {
         AVStream *st = slave->avf->streams[i];
         AVBSFContext *bsf = slave->bsfs[i];
         const char *bsf_name;
@@ -450,7 +449,7 @@ static int tee_process_slave_failure(AVFormatContext *avf, unsigned slave_idx, i
 static int tee_write_header(AVFormatContext *avf)
 {
     TeeContext *tee = avf->priv_data;
-    unsigned nb_slaves = 0, i;
+    unsigned nb_slaves = 0;
     const char *filename = avf->url;
     char **slaves = NULL;
     int ret;
@@ -476,7 +475,7 @@ static int tee_write_header(AVFormatContext *avf)
     }
     tee->nb_slaves = tee->nb_alive = nb_slaves;
 
-    for (i = 0; i < nb_slaves; i++) {
+    for (unsigned i = 0; i < nb_slaves; i++) {
 
         tee->slaves[i].use_fifo = tee->use_fifo;
         ret = av_dict_copy(&tee->slaves[i].fifo_options, tee->fifo_options, 0);
@@ -493,9 +492,9 @@ static int tee_write_header(AVFormatContext *avf)
         av_freep(&slaves[i]);
     }
 
-    for (i = 0; i < avf->nb_streams; i++) {
-        int j, mapped = 0;
-        for (j = 0; j < tee->nb_slaves; j++)
+    for (unsigned i = 0; i < avf->nb_streams; i++) {
+        int mapped = 0;
+        for (unsigned j = 0; j < tee->nb_slaves; j++)
             if (tee->slaves[j].avf)
                 mapped += tee->slaves[j].stream_map[i] >= 0;
         if (!mapped)
@@ -506,7 +505,7 @@ static int tee_write_header(AVFormatContext *avf)
     return 0;
 
 fail:
-    for (i = 0; i < nb_slaves; i++)
+    for (unsigned i = 0; i < nb_slaves; i++)
         av_freep(&slaves[i]);
     close_slaves(avf);
     av_free(slaves);
@@ -517,9 +516,8 @@ static int tee_write_trailer(AVFormatContext *avf)
 {
     TeeContext *tee = avf->priv_data;
     int ret_all = 0, ret;
-    unsigned i;
 
-    for (i = 0; i < tee->nb_slaves; i++) {
+    for (unsigned i = 0; i < tee->nb_slaves; i++) {
         if ((ret = close_slave(&tee->slaves[i])) < 0) {
             ret = tee_process_slave_failure(avf, i, ret);
             if (!ret_all && ret < 0)
@@ -533,15 +531,16 @@ static int tee_write_trailer(AVFormatContext *avf)
 static int tee_write_packet(AVFormatContext *avf, AVPacket *pkt)
 {
     TeeContext *tee = avf->priv_data;
-    AVFormatContext *avf2;
-    AVBSFContext *bsfs;
     AVPacket *const pkt2 = ffformatcontext(avf)->pkt;
     int ret_all = 0, ret;
-    unsigned i, s;
+    unsigned s;
     int s2;
 
-    for (i = 0; i < tee->nb_slaves; i++) {
-        if (!(avf2 = tee->slaves[i].avf))
+    for (unsigned i = 0; i < tee->nb_slaves; i++) {
+        AVFormatContext *avf2 = tee->slaves[i].avf;
+        AVBSFContext *bsfs;
+
+        if (!avf2)
             continue;
 
         /* Flush slave if pkt is NULL*/
-- 
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] 13+ messages in thread

* [FFmpeg-devel] [PATCH 5/6] avcodec/lib*, avformat/tee: Simplify iterating over AVDictionary
  2024-05-17 15:23 [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() Andreas Rheinhardt
                   ` (2 preceding siblings ...)
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 4/6] avformat/tee: Use smaller scope for variables Andreas Rheinhardt
@ 2024-05-17 15:25 ` Andreas Rheinhardt
  2024-05-17 15:41   ` epirat07
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 6/6] fftools, avfilter, avformat: Simplify check for "is dictionary empty?" Andreas Rheinhardt
  2024-05-19  9:57 ` [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() Andreas Rheinhardt
  5 siblings, 1 reply; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-05-17 15:25 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/libaomenc.c  | 4 ++--
 libavcodec/libkvazaar.c | 4 ++--
 libavcodec/libsvtav1.c  | 6 +++---
 libavcodec/libx264.c    | 4 ++--
 libavcodec/libx265.c    | 4 ++--
 libavformat/tee.c       | 4 ++--
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index c39853c20f..dec74ebecd 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -970,9 +970,9 @@ static av_cold int aom_init(AVCodecContext *avctx,
 
 #if AOM_ENCODER_ABI_VERSION >= 23
     {
-        AVDictionaryEntry *en = NULL;
+        const AVDictionaryEntry *en = NULL;
 
-        while ((en = av_dict_get(ctx->aom_params, "", en, AV_DICT_IGNORE_SUFFIX))) {
+        while ((en = av_dict_iterate(ctx->aom_params, en))) {
             int ret = aom_codec_set_option(&ctx->encoder, en->key, en->value);
             if (ret != AOM_CODEC_OK) {
                 log_encoder_error(avctx, en->key);
diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index 0711d9ab38..cd731ae9d0 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -111,8 +111,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
     if (ctx->kvz_params) {
         AVDictionary *dict = NULL;
         if (!av_dict_parse_string(&dict, ctx->kvz_params, "=", ",", 0)) {
-            AVDictionaryEntry *entry = NULL;
-            while ((entry = av_dict_get(dict, "", entry, AV_DICT_IGNORE_SUFFIX))) {
+            const AVDictionaryEntry *entry = NULL;
+            while ((entry = av_dict_iterate(dict, entry))) {
                 if (!api->config_parse(cfg, entry->key, entry->value)) {
                     av_log(avctx, AV_LOG_WARNING, "Invalid option: %s=%s.\n",
                            entry->key, entry->value);
diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index 9bc165f0cf..2fef8c8971 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -210,7 +210,7 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param,
 {
     SvtContext *svt_enc = avctx->priv_data;
     const AVPixFmtDescriptor *desc;
-    AVDictionaryEntry *en = NULL;
+    const AVDictionaryEntry av_unused *en = NULL;
 
     // Update param from options
     if (svt_enc->enc_mode >= -1)
@@ -326,7 +326,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
     handle_side_data(avctx, param);
 
 #if SVT_AV1_CHECK_VERSION(0, 9, 1)
-    while ((en = av_dict_get(svt_enc->svtav1_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
+    while ((en = av_dict_iterate(svt_enc->svtav1_opts, en))) {
         EbErrorType ret = svt_av1_enc_parse_parameter(param, en->key, en->value);
         if (ret != EB_ErrorNone) {
             int level = (avctx->err_recognition & AV_EF_EXPLODE) ? AV_LOG_ERROR : AV_LOG_WARNING;
@@ -336,7 +336,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         }
     }
 #else
-    if ((en = av_dict_get(svt_enc->svtav1_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
+    if (av_dict_count(svt_enc->svtav1_opts)) {
         int level = (avctx->err_recognition & AV_EF_EXPLODE) ? AV_LOG_ERROR : AV_LOG_WARNING;
         av_log(avctx, level, "svt-params needs libavcodec to be compiled with SVT-AV1 "
                              "headers >= 0.9.1.\n");
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 2715f277f1..29d1a7ccbc 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -1385,8 +1385,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
         x4->params.b_repeat_headers = 1;
 
     {
-        AVDictionaryEntry *en = NULL;
-        while (en = av_dict_get(x4->x264_params, "", en, AV_DICT_IGNORE_SUFFIX)) {
+        const AVDictionaryEntry *en = NULL;
+        while (en = av_dict_iterate(x4->x264_params, en)) {
            if ((ret = x264_param_parse(&x4->params, en->key, en->value)) < 0) {
                av_log(avctx, AV_LOG_WARNING,
                       "Error parsing option '%s = %s'.\n",
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index c4ceffff5d..ac1dbc4f97 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -495,8 +495,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
     }
 
     {
-        AVDictionaryEntry *en = NULL;
-        while ((en = av_dict_get(ctx->x265_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
+        const AVDictionaryEntry *en = NULL;
+        while ((en = av_dict_iterate(ctx->x265_opts, en))) {
             int parse_ret = ctx->api->param_parse(ctx->params, en->key, en->value);
 
             switch (parse_ret) {
diff --git a/libavformat/tee.c b/libavformat/tee.c
index 0c0543fa65..1a2a8ead82 100644
--- a/libavformat/tee.c
+++ b/libavformat/tee.c
@@ -313,7 +313,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
     }
 
     entry = NULL;
-    while (entry = av_dict_get(bsf_options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
+    while (entry = av_dict_iterate(bsf_options, NULL)) {
         const char *spec = entry->key;
         if (*spec) {
             if (strspn(spec, slave_bsfs_spec_sep) != 1) {
@@ -390,7 +390,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
 
     if (options) {
         entry = NULL;
-        while ((entry = av_dict_get(options, "", entry, AV_DICT_IGNORE_SUFFIX)))
+        while ((entry = av_dict_iterate(options, entry)))
             av_log(avf2, AV_LOG_ERROR, "Unknown option '%s'\n", entry->key);
         ret = AVERROR_OPTION_NOT_FOUND;
         goto end;
-- 
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] 13+ messages in thread

* [FFmpeg-devel] [PATCH 6/6] fftools, avfilter, avformat: Simplify check for "is dictionary empty?"
  2024-05-17 15:23 [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() Andreas Rheinhardt
                   ` (3 preceding siblings ...)
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 5/6] avcodec/lib*, avformat/tee: Simplify iterating over AVDictionary Andreas Rheinhardt
@ 2024-05-17 15:25 ` Andreas Rheinhardt
  2024-05-17 15:39   ` epirat07
  2024-05-19  9:57 ` [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() Andreas Rheinhardt
  5 siblings, 1 reply; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-05-17 15:25 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 fftools/ffmpeg.c       | 4 ++--
 fftools/ffplay.c       | 4 ++--
 fftools/ffprobe.c      | 2 +-
 libavfilter/avfilter.c | 4 ++--
 libavformat/aacdec.c   | 2 +-
 libavformat/http.c     | 8 ++++----
 libavformat/mpc.c      | 2 +-
 libavformat/oggenc.c   | 2 +-
 libavformat/wvdec.c    | 2 +-
 9 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1f50ed6805..c86fd5065e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -484,8 +484,8 @@ void remove_avoptions(AVDictionary **a, AVDictionary *b)
 
 int check_avoptions(AVDictionary *m)
 {
-    const AVDictionaryEntry *t;
-    if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
+    const AVDictionaryEntry *t = av_dict_iterate(m, NULL);
+    if (t) {
         av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key);
         return AVERROR_OPTION_NOT_FOUND;
     }
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index b9d11eecee..5a66bfa38d 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -2694,7 +2694,7 @@ static int stream_component_open(VideoState *is, int stream_index)
     if ((ret = avcodec_open2(avctx, codec, &opts)) < 0) {
         goto fail;
     }
-    if ((t = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
+    if ((t = av_dict_iterate(opts, NULL))) {
         av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
         ret =  AVERROR_OPTION_NOT_FOUND;
         goto fail;
@@ -2862,7 +2862,7 @@ static int read_thread(void *arg)
     if (scan_all_pmts_set)
         av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
 
-    if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
+    if ((t = av_dict_iterate(format_opts, NULL))) {
         av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
         ret = AVERROR_OPTION_NOT_FOUND;
         goto fail;
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 5b40dad527..2d38e5dfdc 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -3951,7 +3951,7 @@ static int open_input_file(InputFile *ifile, const char *filename,
                 exit(1);
             }
 
-            if ((t = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
+            if ((t = av_dict_iterate(opts, NULL))) {
                 av_log(NULL, AV_LOG_ERROR, "Option %s for input stream %d not found\n",
                        t->key, stream->index);
                 return AVERROR_OPTION_NOT_FOUND;
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 049e4f62ca..2dc8820184 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -941,7 +941,7 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
 int avfilter_init_str(AVFilterContext *filter, const char *args)
 {
     AVDictionary *options = NULL;
-    AVDictionaryEntry *e;
+    const AVDictionaryEntry *e;
     int ret = 0;
 
     if (args && *args) {
@@ -954,7 +954,7 @@ int avfilter_init_str(AVFilterContext *filter, const char *args)
     if (ret < 0)
         goto fail;
 
-    if ((e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
+    if ((e = av_dict_iterate(options, NULL))) {
         av_log(filter, AV_LOG_ERROR, "No such option: %s.\n", e->key);
         ret = AVERROR_OPTION_NOT_FOUND;
         goto fail;
diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c
index e267886e1a..a8be251815 100644
--- a/libavformat/aacdec.c
+++ b/libavformat/aacdec.c
@@ -119,7 +119,7 @@ static int adts_aac_read_header(AVFormatContext *s)
 
     ff_id3v1_read(s);
     if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
-        !av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
+        !av_dict_count(s->metadata)) {
         int64_t cur = avio_tell(s->pb);
         ff_ape_parse_tag(s);
         avio_seek(s->pb, cur, SEEK_SET);
diff --git a/libavformat/http.c b/libavformat/http.c
index 1a67068a44..ec60bc0b17 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -990,7 +990,7 @@ static int parse_set_cookie(const char *set_cookie, AVDictionary **dict)
 static int parse_cookie(HTTPContext *s, const char *p, AVDictionary **cookies)
 {
     AVDictionary *new_params = NULL;
-    AVDictionaryEntry *e, *cookie_entry;
+    const AVDictionaryEntry *e, *cookie_entry;
     char *eql, *name;
 
     // ensure the cookie is parsable
@@ -998,7 +998,7 @@ static int parse_cookie(HTTPContext *s, const char *p, AVDictionary **cookies)
         return -1;
 
     // if there is no cookie value there is nothing to parse
-    cookie_entry = av_dict_get(new_params, "", NULL, AV_DICT_IGNORE_SUFFIX);
+    cookie_entry = av_dict_iterate(new_params, NULL);
     if (!cookie_entry || !cookie_entry->value) {
         av_dict_free(&new_params);
         return -1;
@@ -1300,7 +1300,7 @@ static int get_cookies(HTTPContext *s, char **cookies, const char *path,
     *cookies = NULL;
     while ((cookie = av_strtok(next, "\n", &saveptr)) && !ret) {
         AVDictionary *cookie_params = NULL;
-        AVDictionaryEntry *cookie_entry, *e;
+        const AVDictionaryEntry *cookie_entry, *e;
 
         next = NULL;
         // store the cookie in a dict in case it is updated in the response
@@ -1312,7 +1312,7 @@ static int get_cookies(HTTPContext *s, char **cookies, const char *path,
             goto skip_cookie;
 
         // if the cookie has no value, skip it
-        cookie_entry = av_dict_get(cookie_params, "", NULL, AV_DICT_IGNORE_SUFFIX);
+        cookie_entry = av_dict_iterate(cookie_params, NULL);
         if (!cookie_entry || !cookie_entry->value)
             goto skip_cookie;
 
diff --git a/libavformat/mpc.c b/libavformat/mpc.c
index 60cb768ab6..1e0e170c7d 100644
--- a/libavformat/mpc.c
+++ b/libavformat/mpc.c
@@ -112,7 +112,7 @@ static int mpc_read_header(AVFormatContext *s)
     if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
         int64_t pos = avio_tell(s->pb);
         ff_ape_parse_tag(s);
-        if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX))
+        if (av_dict_count(s->metadata) == 0)
             ff_id3v1_read(s);
         avio_seek(s->pb, pos, SEEK_SET);
     }
diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
index f5782cb583..224519a4da 100644
--- a/libavformat/oggenc.c
+++ b/libavformat/oggenc.c
@@ -432,7 +432,7 @@ static int ogg_build_vp8_headers(AVFormatContext *s, AVStream *st,
     bytestream_put_be32(&p, st->time_base.num);
 
     /* optional second packet: VorbisComment */
-    if (av_dict_get(st->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
+    if (av_dict_count(st->metadata)) {
         p = ogg_write_vorbiscomment(7, bitexact, &oggstream->header_len[1], &st->metadata, 0, NULL, 0);
         if (!p)
             return AVERROR(ENOMEM);
diff --git a/libavformat/wvdec.c b/libavformat/wvdec.c
index b25c1eee83..e2a79957f7 100644
--- a/libavformat/wvdec.c
+++ b/libavformat/wvdec.c
@@ -268,7 +268,7 @@ static int wv_read_header(AVFormatContext *s)
     if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
         int64_t cur = avio_tell(s->pb);
         wc->apetag_start = ff_ape_parse_tag(s);
-        if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX))
+        if (av_dict_count(s->metadata) == 0)
             ff_id3v1_read(s);
         avio_seek(s->pb, cur, SEEK_SET);
     }
-- 
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] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 6/6] fftools, avfilter, avformat: Simplify check for "is dictionary empty?"
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 6/6] fftools, avfilter, avformat: Simplify check for "is dictionary empty?" Andreas Rheinhardt
@ 2024-05-17 15:39   ` epirat07
  0 siblings, 0 replies; 13+ messages in thread
From: epirat07 @ 2024-05-17 15:39 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On 17 May 2024, at 17:25, Andreas Rheinhardt wrote:

> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  fftools/ffmpeg.c       | 4 ++--
>  fftools/ffplay.c       | 4 ++--
>  fftools/ffprobe.c      | 2 +-
>  libavfilter/avfilter.c | 4 ++--
>  libavformat/aacdec.c   | 2 +-
>  libavformat/http.c     | 8 ++++----
>  libavformat/mpc.c      | 2 +-
>  libavformat/oggenc.c   | 2 +-
>  libavformat/wvdec.c    | 2 +-
>  9 files changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 1f50ed6805..c86fd5065e 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -484,8 +484,8 @@ void remove_avoptions(AVDictionary **a, AVDictionary *b)
>
>  int check_avoptions(AVDictionary *m)
>  {
> -    const AVDictionaryEntry *t;
> -    if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
> +    const AVDictionaryEntry *t = av_dict_iterate(m, NULL);
> +    if (t) {
>          av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key);
>          return AVERROR_OPTION_NOT_FOUND;
>      }
> diff --git a/fftools/ffplay.c b/fftools/ffplay.c
> index b9d11eecee..5a66bfa38d 100644
> --- a/fftools/ffplay.c
> +++ b/fftools/ffplay.c
> @@ -2694,7 +2694,7 @@ static int stream_component_open(VideoState *is, int stream_index)
>      if ((ret = avcodec_open2(avctx, codec, &opts)) < 0) {
>          goto fail;
>      }
> -    if ((t = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
> +    if ((t = av_dict_iterate(opts, NULL))) {
>          av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
>          ret =  AVERROR_OPTION_NOT_FOUND;
>          goto fail;
> @@ -2862,7 +2862,7 @@ static int read_thread(void *arg)
>      if (scan_all_pmts_set)
>          av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
>
> -    if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
> +    if ((t = av_dict_iterate(format_opts, NULL))) {
>          av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
>          ret = AVERROR_OPTION_NOT_FOUND;
>          goto fail;
> diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> index 5b40dad527..2d38e5dfdc 100644
> --- a/fftools/ffprobe.c
> +++ b/fftools/ffprobe.c
> @@ -3951,7 +3951,7 @@ static int open_input_file(InputFile *ifile, const char *filename,
>                  exit(1);
>              }
>
> -            if ((t = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
> +            if ((t = av_dict_iterate(opts, NULL))) {
>                  av_log(NULL, AV_LOG_ERROR, "Option %s for input stream %d not found\n",
>                         t->key, stream->index);
>                  return AVERROR_OPTION_NOT_FOUND;
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 049e4f62ca..2dc8820184 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -941,7 +941,7 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
>  int avfilter_init_str(AVFilterContext *filter, const char *args)
>  {
>      AVDictionary *options = NULL;
> -    AVDictionaryEntry *e;
> +    const AVDictionaryEntry *e;
>      int ret = 0;
>
>      if (args && *args) {
> @@ -954,7 +954,7 @@ int avfilter_init_str(AVFilterContext *filter, const char *args)
>      if (ret < 0)
>          goto fail;
>
> -    if ((e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
> +    if ((e = av_dict_iterate(options, NULL))) {
>          av_log(filter, AV_LOG_ERROR, "No such option: %s.\n", e->key);
>          ret = AVERROR_OPTION_NOT_FOUND;
>          goto fail;
> diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c
> index e267886e1a..a8be251815 100644
> --- a/libavformat/aacdec.c
> +++ b/libavformat/aacdec.c
> @@ -119,7 +119,7 @@ static int adts_aac_read_header(AVFormatContext *s)
>
>      ff_id3v1_read(s);
>      if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
> -        !av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
> +        !av_dict_count(s->metadata)) {
>          int64_t cur = avio_tell(s->pb);
>          ff_ape_parse_tag(s);
>          avio_seek(s->pb, cur, SEEK_SET);
> diff --git a/libavformat/http.c b/libavformat/http.c
> index 1a67068a44..ec60bc0b17 100644
> --- a/libavformat/http.c
> +++ b/libavformat/http.c
> @@ -990,7 +990,7 @@ static int parse_set_cookie(const char *set_cookie, AVDictionary **dict)
>  static int parse_cookie(HTTPContext *s, const char *p, AVDictionary **cookies)
>  {
>      AVDictionary *new_params = NULL;
> -    AVDictionaryEntry *e, *cookie_entry;
> +    const AVDictionaryEntry *e, *cookie_entry;
>      char *eql, *name;
>
>      // ensure the cookie is parsable
> @@ -998,7 +998,7 @@ static int parse_cookie(HTTPContext *s, const char *p, AVDictionary **cookies)
>          return -1;
>
>      // if there is no cookie value there is nothing to parse
> -    cookie_entry = av_dict_get(new_params, "", NULL, AV_DICT_IGNORE_SUFFIX);
> +    cookie_entry = av_dict_iterate(new_params, NULL);
>      if (!cookie_entry || !cookie_entry->value) {
>          av_dict_free(&new_params);
>          return -1;
> @@ -1300,7 +1300,7 @@ static int get_cookies(HTTPContext *s, char **cookies, const char *path,
>      *cookies = NULL;
>      while ((cookie = av_strtok(next, "\n", &saveptr)) && !ret) {
>          AVDictionary *cookie_params = NULL;
> -        AVDictionaryEntry *cookie_entry, *e;
> +        const AVDictionaryEntry *cookie_entry, *e;
>
>          next = NULL;
>          // store the cookie in a dict in case it is updated in the response
> @@ -1312,7 +1312,7 @@ static int get_cookies(HTTPContext *s, char **cookies, const char *path,
>              goto skip_cookie;
>
>          // if the cookie has no value, skip it
> -        cookie_entry = av_dict_get(cookie_params, "", NULL, AV_DICT_IGNORE_SUFFIX);
> +        cookie_entry = av_dict_iterate(cookie_params, NULL);
>          if (!cookie_entry || !cookie_entry->value)
>              goto skip_cookie;
>
> diff --git a/libavformat/mpc.c b/libavformat/mpc.c
> index 60cb768ab6..1e0e170c7d 100644
> --- a/libavformat/mpc.c
> +++ b/libavformat/mpc.c
> @@ -112,7 +112,7 @@ static int mpc_read_header(AVFormatContext *s)
>      if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
>          int64_t pos = avio_tell(s->pb);
>          ff_ape_parse_tag(s);
> -        if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX))
> +        if (av_dict_count(s->metadata) == 0)
>              ff_id3v1_read(s);
>          avio_seek(s->pb, pos, SEEK_SET);
>      }
> diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
> index f5782cb583..224519a4da 100644
> --- a/libavformat/oggenc.c
> +++ b/libavformat/oggenc.c
> @@ -432,7 +432,7 @@ static int ogg_build_vp8_headers(AVFormatContext *s, AVStream *st,
>      bytestream_put_be32(&p, st->time_base.num);
>
>      /* optional second packet: VorbisComment */
> -    if (av_dict_get(st->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
> +    if (av_dict_count(st->metadata)) {
>          p = ogg_write_vorbiscomment(7, bitexact, &oggstream->header_len[1], &st->metadata, 0, NULL, 0);
>          if (!p)
>              return AVERROR(ENOMEM);
> diff --git a/libavformat/wvdec.c b/libavformat/wvdec.c
> index b25c1eee83..e2a79957f7 100644
> --- a/libavformat/wvdec.c
> +++ b/libavformat/wvdec.c
> @@ -268,7 +268,7 @@ static int wv_read_header(AVFormatContext *s)
>      if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
>          int64_t cur = avio_tell(s->pb);
>          wc->apetag_start = ff_ape_parse_tag(s);
> -        if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX))
> +        if (av_dict_count(s->metadata) == 0)
>              ff_id3v1_read(s);
>          avio_seek(s->pb, cur, SEEK_SET);
>      }
> -- 
> 2.40.1


LGTM, thanks!

>
> _______________________________________________
> 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".
_______________________________________________
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] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 5/6] avcodec/lib*, avformat/tee: Simplify iterating over AVDictionary
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 5/6] avcodec/lib*, avformat/tee: Simplify iterating over AVDictionary Andreas Rheinhardt
@ 2024-05-17 15:41   ` epirat07
  2024-05-17 15:44     ` Andreas Rheinhardt
  0 siblings, 1 reply; 13+ messages in thread
From: epirat07 @ 2024-05-17 15:41 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On 17 May 2024, at 17:25, Andreas Rheinhardt wrote:

> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/libaomenc.c  | 4 ++--
>  libavcodec/libkvazaar.c | 4 ++--
>  libavcodec/libsvtav1.c  | 6 +++---
>  libavcodec/libx264.c    | 4 ++--
>  libavcodec/libx265.c    | 4 ++--
>  libavformat/tee.c       | 4 ++--
>  6 files changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> index c39853c20f..dec74ebecd 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -970,9 +970,9 @@ static av_cold int aom_init(AVCodecContext *avctx,
>
>  #if AOM_ENCODER_ABI_VERSION >= 23
>      {
> -        AVDictionaryEntry *en = NULL;
> +        const AVDictionaryEntry *en = NULL;
>
> -        while ((en = av_dict_get(ctx->aom_params, "", en, AV_DICT_IGNORE_SUFFIX))) {
> +        while ((en = av_dict_iterate(ctx->aom_params, en))) {
>              int ret = aom_codec_set_option(&ctx->encoder, en->key, en->value);
>              if (ret != AOM_CODEC_OK) {
>                  log_encoder_error(avctx, en->key);
> diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
> index 0711d9ab38..cd731ae9d0 100644
> --- a/libavcodec/libkvazaar.c
> +++ b/libavcodec/libkvazaar.c
> @@ -111,8 +111,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>      if (ctx->kvz_params) {
>          AVDictionary *dict = NULL;
>          if (!av_dict_parse_string(&dict, ctx->kvz_params, "=", ",", 0)) {
> -            AVDictionaryEntry *entry = NULL;
> -            while ((entry = av_dict_get(dict, "", entry, AV_DICT_IGNORE_SUFFIX))) {
> +            const AVDictionaryEntry *entry = NULL;
> +            while ((entry = av_dict_iterate(dict, entry))) {
>                  if (!api->config_parse(cfg, entry->key, entry->value)) {
>                      av_log(avctx, AV_LOG_WARNING, "Invalid option: %s=%s.\n",
>                             entry->key, entry->value);
> diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
> index 9bc165f0cf..2fef8c8971 100644
> --- a/libavcodec/libsvtav1.c
> +++ b/libavcodec/libsvtav1.c
> @@ -210,7 +210,7 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param,
>  {
>      SvtContext *svt_enc = avctx->priv_data;
>      const AVPixFmtDescriptor *desc;
> -    AVDictionaryEntry *en = NULL;
> +    const AVDictionaryEntry av_unused *en = NULL;
>
>      // Update param from options
>      if (svt_enc->enc_mode >= -1)
> @@ -326,7 +326,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>      handle_side_data(avctx, param);
>
>  #if SVT_AV1_CHECK_VERSION(0, 9, 1)
> -    while ((en = av_dict_get(svt_enc->svtav1_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
> +    while ((en = av_dict_iterate(svt_enc->svtav1_opts, en))) {
>          EbErrorType ret = svt_av1_enc_parse_parameter(param, en->key, en->value);
>          if (ret != EB_ErrorNone) {
>              int level = (avctx->err_recognition & AV_EF_EXPLODE) ? AV_LOG_ERROR : AV_LOG_WARNING;
> @@ -336,7 +336,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>          }
>      }
>  #else
> -    if ((en = av_dict_get(svt_enc->svtav1_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
> +    if (av_dict_count(svt_enc->svtav1_opts)) {
>          int level = (avctx->err_recognition & AV_EF_EXPLODE) ? AV_LOG_ERROR : AV_LOG_WARNING;
>          av_log(avctx, level, "svt-params needs libavcodec to be compiled with SVT-AV1 "
>                               "headers >= 0.9.1.\n");
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 2715f277f1..29d1a7ccbc 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -1385,8 +1385,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>          x4->params.b_repeat_headers = 1;
>
>      {
> -        AVDictionaryEntry *en = NULL;
> -        while (en = av_dict_get(x4->x264_params, "", en, AV_DICT_IGNORE_SUFFIX)) {
> +        const AVDictionaryEntry *en = NULL;
> +        while (en = av_dict_iterate(x4->x264_params, en)) {

Missing pair of braces to make the compiler not warn about assignment in check, no?

>             if ((ret = x264_param_parse(&x4->params, en->key, en->value)) < 0) {
>                 av_log(avctx, AV_LOG_WARNING,
>                        "Error parsing option '%s = %s'.\n",
> diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
> index c4ceffff5d..ac1dbc4f97 100644
> --- a/libavcodec/libx265.c
> +++ b/libavcodec/libx265.c
> @@ -495,8 +495,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>      }
>
>      {
> -        AVDictionaryEntry *en = NULL;
> -        while ((en = av_dict_get(ctx->x265_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
> +        const AVDictionaryEntry *en = NULL;
> +        while ((en = av_dict_iterate(ctx->x265_opts, en))) {
>              int parse_ret = ctx->api->param_parse(ctx->params, en->key, en->value);
>
>              switch (parse_ret) {
> diff --git a/libavformat/tee.c b/libavformat/tee.c
> index 0c0543fa65..1a2a8ead82 100644
> --- a/libavformat/tee.c
> +++ b/libavformat/tee.c
> @@ -313,7 +313,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
>      }
>
>      entry = NULL;
> -    while (entry = av_dict_get(bsf_options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
> +    while (entry = av_dict_iterate(bsf_options, NULL)) {

Same as above

>          const char *spec = entry->key;
>          if (*spec) {
>              if (strspn(spec, slave_bsfs_spec_sep) != 1) {
> @@ -390,7 +390,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
>
>      if (options) {
>          entry = NULL;
> -        while ((entry = av_dict_get(options, "", entry, AV_DICT_IGNORE_SUFFIX)))
> +        while ((entry = av_dict_iterate(options, entry)))
>              av_log(avf2, AV_LOG_ERROR, "Unknown option '%s'\n", entry->key);
>          ret = AVERROR_OPTION_NOT_FOUND;
>          goto end;
> -- 
> 2.40.1

Otherwise LGTM, thanks!

>
> _______________________________________________
> 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".
_______________________________________________
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] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 3/6] avformat/tee: Constify AVDictionaryEntry* pointee where possible
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 3/6] avformat/tee: Constify AVDictionaryEntry* pointee where possible Andreas Rheinhardt
@ 2024-05-17 15:42   ` epirat07
  2024-05-17 16:17   ` Andreas Rheinhardt
  1 sibling, 0 replies; 13+ messages in thread
From: epirat07 @ 2024-05-17 15:42 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On 17 May 2024, at 17:25, Andreas Rheinhardt wrote:

> This is in preparation for using av_dict_iterate().
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavformat/tee.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/libavformat/tee.c b/libavformat/tee.c
> index 1cbbb80dbb..87159681ed 100644
> --- a/libavformat/tee.c
> +++ b/libavformat/tee.c
> @@ -158,7 +158,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
>  {
>      int i, ret;
>      AVDictionary *options = NULL, *bsf_options = NULL;
> -    AVDictionaryEntry *entry;
> +    const AVDictionaryEntry *entry;
>      char *filename;
>      char *format = NULL, *select = NULL, *on_fail = NULL;
>      char *use_fifo = NULL, *fifo_options_str = NULL;
> @@ -172,8 +172,9 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
>          return ret;
>
>  #define CONSUME_OPTION(option, field, action) do {                      \
> -        if ((entry = av_dict_get(options, option, NULL, 0))) {          \
> -            field = entry->value;                                       \
> +        AVDictionaryEntry *en = av_dict_get(options, option, NULL, 0);  \
> +        if (en) {                                                       \
> +            field = en->value;                                          \
>              { action }                                                  \
>              av_dict_set(&options, option, NULL, 0);                     \
>          }                                                               \
> -- 
> 2.40.1
>

LGTM, thanks!

> _______________________________________________
> 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".
_______________________________________________
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] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 5/6] avcodec/lib*, avformat/tee: Simplify iterating over AVDictionary
  2024-05-17 15:41   ` epirat07
@ 2024-05-17 15:44     ` Andreas Rheinhardt
  2024-05-17 15:48       ` epirat07
  0 siblings, 1 reply; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-05-17 15:44 UTC (permalink / raw)
  To: ffmpeg-devel

epirat07@gmail.com:
> 
> 
> On 17 May 2024, at 17:25, Andreas Rheinhardt wrote:
> 
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  libavcodec/libaomenc.c  | 4 ++--
>>  libavcodec/libkvazaar.c | 4 ++--
>>  libavcodec/libsvtav1.c  | 6 +++---
>>  libavcodec/libx264.c    | 4 ++--
>>  libavcodec/libx265.c    | 4 ++--
>>  libavformat/tee.c       | 4 ++--
>>  6 files changed, 13 insertions(+), 13 deletions(-)
>>
>> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
>> index c39853c20f..dec74ebecd 100644
>> --- a/libavcodec/libaomenc.c
>> +++ b/libavcodec/libaomenc.c
>> @@ -970,9 +970,9 @@ static av_cold int aom_init(AVCodecContext *avctx,
>>
>>  #if AOM_ENCODER_ABI_VERSION >= 23
>>      {
>> -        AVDictionaryEntry *en = NULL;
>> +        const AVDictionaryEntry *en = NULL;
>>
>> -        while ((en = av_dict_get(ctx->aom_params, "", en, AV_DICT_IGNORE_SUFFIX))) {
>> +        while ((en = av_dict_iterate(ctx->aom_params, en))) {
>>              int ret = aom_codec_set_option(&ctx->encoder, en->key, en->value);
>>              if (ret != AOM_CODEC_OK) {
>>                  log_encoder_error(avctx, en->key);
>> diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
>> index 0711d9ab38..cd731ae9d0 100644
>> --- a/libavcodec/libkvazaar.c
>> +++ b/libavcodec/libkvazaar.c
>> @@ -111,8 +111,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>>      if (ctx->kvz_params) {
>>          AVDictionary *dict = NULL;
>>          if (!av_dict_parse_string(&dict, ctx->kvz_params, "=", ",", 0)) {
>> -            AVDictionaryEntry *entry = NULL;
>> -            while ((entry = av_dict_get(dict, "", entry, AV_DICT_IGNORE_SUFFIX))) {
>> +            const AVDictionaryEntry *entry = NULL;
>> +            while ((entry = av_dict_iterate(dict, entry))) {
>>                  if (!api->config_parse(cfg, entry->key, entry->value)) {
>>                      av_log(avctx, AV_LOG_WARNING, "Invalid option: %s=%s.\n",
>>                             entry->key, entry->value);
>> diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
>> index 9bc165f0cf..2fef8c8971 100644
>> --- a/libavcodec/libsvtav1.c
>> +++ b/libavcodec/libsvtav1.c
>> @@ -210,7 +210,7 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param,
>>  {
>>      SvtContext *svt_enc = avctx->priv_data;
>>      const AVPixFmtDescriptor *desc;
>> -    AVDictionaryEntry *en = NULL;
>> +    const AVDictionaryEntry av_unused *en = NULL;
>>
>>      // Update param from options
>>      if (svt_enc->enc_mode >= -1)
>> @@ -326,7 +326,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>>      handle_side_data(avctx, param);
>>
>>  #if SVT_AV1_CHECK_VERSION(0, 9, 1)
>> -    while ((en = av_dict_get(svt_enc->svtav1_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
>> +    while ((en = av_dict_iterate(svt_enc->svtav1_opts, en))) {
>>          EbErrorType ret = svt_av1_enc_parse_parameter(param, en->key, en->value);
>>          if (ret != EB_ErrorNone) {
>>              int level = (avctx->err_recognition & AV_EF_EXPLODE) ? AV_LOG_ERROR : AV_LOG_WARNING;
>> @@ -336,7 +336,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>>          }
>>      }
>>  #else
>> -    if ((en = av_dict_get(svt_enc->svtav1_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
>> +    if (av_dict_count(svt_enc->svtav1_opts)) {
>>          int level = (avctx->err_recognition & AV_EF_EXPLODE) ? AV_LOG_ERROR : AV_LOG_WARNING;
>>          av_log(avctx, level, "svt-params needs libavcodec to be compiled with SVT-AV1 "
>>                               "headers >= 0.9.1.\n");
>> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
>> index 2715f277f1..29d1a7ccbc 100644
>> --- a/libavcodec/libx264.c
>> +++ b/libavcodec/libx264.c
>> @@ -1385,8 +1385,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>>          x4->params.b_repeat_headers = 1;
>>
>>      {
>> -        AVDictionaryEntry *en = NULL;
>> -        while (en = av_dict_get(x4->x264_params, "", en, AV_DICT_IGNORE_SUFFIX)) {
>> +        const AVDictionaryEntry *en = NULL;
>> +        while (en = av_dict_iterate(x4->x264_params, en)) {
> 
> Missing pair of braces to make the compiler not warn about assignment in check, no?
> 

I did not change the parentheses in this patch at all as doing so would
be orthogonal to the patch. We use this style without the additional
pair of parentheses everywhere and actually add -Wno-parentheses in
configure (line 7429).

>>             if ((ret = x264_param_parse(&x4->params, en->key, en->value)) < 0) {
>>                 av_log(avctx, AV_LOG_WARNING,
>>                        "Error parsing option '%s = %s'.\n",
>> diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
>> index c4ceffff5d..ac1dbc4f97 100644
>> --- a/libavcodec/libx265.c
>> +++ b/libavcodec/libx265.c
>> @@ -495,8 +495,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>>      }
>>
>>      {
>> -        AVDictionaryEntry *en = NULL;
>> -        while ((en = av_dict_get(ctx->x265_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
>> +        const AVDictionaryEntry *en = NULL;
>> +        while ((en = av_dict_iterate(ctx->x265_opts, en))) {
>>              int parse_ret = ctx->api->param_parse(ctx->params, en->key, en->value);
>>
>>              switch (parse_ret) {
>> diff --git a/libavformat/tee.c b/libavformat/tee.c
>> index 0c0543fa65..1a2a8ead82 100644
>> --- a/libavformat/tee.c
>> +++ b/libavformat/tee.c
>> @@ -313,7 +313,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
>>      }
>>
>>      entry = NULL;
>> -    while (entry = av_dict_get(bsf_options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
>> +    while (entry = av_dict_iterate(bsf_options, NULL)) {
> 
> Same as above
> 
>>          const char *spec = entry->key;
>>          if (*spec) {
>>              if (strspn(spec, slave_bsfs_spec_sep) != 1) {
>> @@ -390,7 +390,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
>>
>>      if (options) {
>>          entry = NULL;
>> -        while ((entry = av_dict_get(options, "", entry, AV_DICT_IGNORE_SUFFIX)))
>> +        while ((entry = av_dict_iterate(options, entry)))
>>              av_log(avf2, AV_LOG_ERROR, "Unknown option '%s'\n", entry->key);
>>          ret = AVERROR_OPTION_NOT_FOUND;
>>          goto end;
>> -- 
>> 2.40.1
> 
> Otherwise LGTM, thanks!
> 

_______________________________________________
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] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 5/6] avcodec/lib*, avformat/tee: Simplify iterating over AVDictionary
  2024-05-17 15:44     ` Andreas Rheinhardt
@ 2024-05-17 15:48       ` epirat07
  0 siblings, 0 replies; 13+ messages in thread
From: epirat07 @ 2024-05-17 15:48 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On 17 May 2024, at 17:44, Andreas Rheinhardt wrote:

> epirat07@gmail.com:
>>
>>
>> On 17 May 2024, at 17:25, Andreas Rheinhardt wrote:
>>
>>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>>> ---
>>>  libavcodec/libaomenc.c  | 4 ++--
>>>  libavcodec/libkvazaar.c | 4 ++--
>>>  libavcodec/libsvtav1.c  | 6 +++---
>>>  libavcodec/libx264.c    | 4 ++--
>>>  libavcodec/libx265.c    | 4 ++--
>>>  libavformat/tee.c       | 4 ++--
>>>  6 files changed, 13 insertions(+), 13 deletions(-)
>>>
>>> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
>>> index c39853c20f..dec74ebecd 100644
>>> --- a/libavcodec/libaomenc.c
>>> +++ b/libavcodec/libaomenc.c
>>> @@ -970,9 +970,9 @@ static av_cold int aom_init(AVCodecContext *avctx,
>>>
>>>  #if AOM_ENCODER_ABI_VERSION >= 23
>>>      {
>>> -        AVDictionaryEntry *en = NULL;
>>> +        const AVDictionaryEntry *en = NULL;
>>>
>>> -        while ((en = av_dict_get(ctx->aom_params, "", en, AV_DICT_IGNORE_SUFFIX))) {
>>> +        while ((en = av_dict_iterate(ctx->aom_params, en))) {
>>>              int ret = aom_codec_set_option(&ctx->encoder, en->key, en->value);
>>>              if (ret != AOM_CODEC_OK) {
>>>                  log_encoder_error(avctx, en->key);
>>> diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
>>> index 0711d9ab38..cd731ae9d0 100644
>>> --- a/libavcodec/libkvazaar.c
>>> +++ b/libavcodec/libkvazaar.c
>>> @@ -111,8 +111,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>>>      if (ctx->kvz_params) {
>>>          AVDictionary *dict = NULL;
>>>          if (!av_dict_parse_string(&dict, ctx->kvz_params, "=", ",", 0)) {
>>> -            AVDictionaryEntry *entry = NULL;
>>> -            while ((entry = av_dict_get(dict, "", entry, AV_DICT_IGNORE_SUFFIX))) {
>>> +            const AVDictionaryEntry *entry = NULL;
>>> +            while ((entry = av_dict_iterate(dict, entry))) {
>>>                  if (!api->config_parse(cfg, entry->key, entry->value)) {
>>>                      av_log(avctx, AV_LOG_WARNING, "Invalid option: %s=%s.\n",
>>>                             entry->key, entry->value);
>>> diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
>>> index 9bc165f0cf..2fef8c8971 100644
>>> --- a/libavcodec/libsvtav1.c
>>> +++ b/libavcodec/libsvtav1.c
>>> @@ -210,7 +210,7 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param,
>>>  {
>>>      SvtContext *svt_enc = avctx->priv_data;
>>>      const AVPixFmtDescriptor *desc;
>>> -    AVDictionaryEntry *en = NULL;
>>> +    const AVDictionaryEntry av_unused *en = NULL;
>>>
>>>      // Update param from options
>>>      if (svt_enc->enc_mode >= -1)
>>> @@ -326,7 +326,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>>>      handle_side_data(avctx, param);
>>>
>>>  #if SVT_AV1_CHECK_VERSION(0, 9, 1)
>>> -    while ((en = av_dict_get(svt_enc->svtav1_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
>>> +    while ((en = av_dict_iterate(svt_enc->svtav1_opts, en))) {
>>>          EbErrorType ret = svt_av1_enc_parse_parameter(param, en->key, en->value);
>>>          if (ret != EB_ErrorNone) {
>>>              int level = (avctx->err_recognition & AV_EF_EXPLODE) ? AV_LOG_ERROR : AV_LOG_WARNING;
>>> @@ -336,7 +336,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>>>          }
>>>      }
>>>  #else
>>> -    if ((en = av_dict_get(svt_enc->svtav1_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
>>> +    if (av_dict_count(svt_enc->svtav1_opts)) {
>>>          int level = (avctx->err_recognition & AV_EF_EXPLODE) ? AV_LOG_ERROR : AV_LOG_WARNING;
>>>          av_log(avctx, level, "svt-params needs libavcodec to be compiled with SVT-AV1 "
>>>                               "headers >= 0.9.1.\n");
>>> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
>>> index 2715f277f1..29d1a7ccbc 100644
>>> --- a/libavcodec/libx264.c
>>> +++ b/libavcodec/libx264.c
>>> @@ -1385,8 +1385,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>>>          x4->params.b_repeat_headers = 1;
>>>
>>>      {
>>> -        AVDictionaryEntry *en = NULL;
>>> -        while (en = av_dict_get(x4->x264_params, "", en, AV_DICT_IGNORE_SUFFIX)) {
>>> +        const AVDictionaryEntry *en = NULL;
>>> +        while (en = av_dict_iterate(x4->x264_params, en)) {
>>
>> Missing pair of braces to make the compiler not warn about assignment in check, no?
>>
>
> I did not change the parentheses in this patch at all as doing so would
> be orthogonal to the patch. We use this style without the additional
> pair of parentheses everywhere and actually add -Wno-parentheses in
> configure (line 7429).

Indeed sorry, I had pulled parts of AVDict out of tree when I did a bunch of work
on it a while ago to easier test a lot of edge cases and debug things.

Any reason why we silence this, as just adding a pair of braces to make intent
clearer vs accidentally doing it wrong somewhere seems worth it…

Anyway, LGTM then for this patch, sorry for the noise.

>
>>>             if ((ret = x264_param_parse(&x4->params, en->key, en->value)) < 0) {
>>>                 av_log(avctx, AV_LOG_WARNING,
>>>                        "Error parsing option '%s = %s'.\n",
>>> diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
>>> index c4ceffff5d..ac1dbc4f97 100644
>>> --- a/libavcodec/libx265.c
>>> +++ b/libavcodec/libx265.c
>>> @@ -495,8 +495,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>>>      }
>>>
>>>      {
>>> -        AVDictionaryEntry *en = NULL;
>>> -        while ((en = av_dict_get(ctx->x265_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
>>> +        const AVDictionaryEntry *en = NULL;
>>> +        while ((en = av_dict_iterate(ctx->x265_opts, en))) {
>>>              int parse_ret = ctx->api->param_parse(ctx->params, en->key, en->value);
>>>
>>>              switch (parse_ret) {
>>> diff --git a/libavformat/tee.c b/libavformat/tee.c
>>> index 0c0543fa65..1a2a8ead82 100644
>>> --- a/libavformat/tee.c
>>> +++ b/libavformat/tee.c
>>> @@ -313,7 +313,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
>>>      }
>>>
>>>      entry = NULL;
>>> -    while (entry = av_dict_get(bsf_options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
>>> +    while (entry = av_dict_iterate(bsf_options, NULL)) {
>>
>> Same as above
>>
>>>          const char *spec = entry->key;
>>>          if (*spec) {
>>>              if (strspn(spec, slave_bsfs_spec_sep) != 1) {
>>> @@ -390,7 +390,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
>>>
>>>      if (options) {
>>>          entry = NULL;
>>> -        while ((entry = av_dict_get(options, "", entry, AV_DICT_IGNORE_SUFFIX)))
>>> +        while ((entry = av_dict_iterate(options, entry)))
>>>              av_log(avf2, AV_LOG_ERROR, "Unknown option '%s'\n", entry->key);
>>>          ret = AVERROR_OPTION_NOT_FOUND;
>>>          goto end;
>>> -- 
>>> 2.40.1
>>
>> Otherwise LGTM, thanks!
>>
>
> _______________________________________________
> 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".
_______________________________________________
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] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 3/6] avformat/tee: Constify AVDictionaryEntry* pointee where possible
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 3/6] avformat/tee: Constify AVDictionaryEntry* pointee where possible Andreas Rheinhardt
  2024-05-17 15:42   ` epirat07
@ 2024-05-17 16:17   ` Andreas Rheinhardt
  1 sibling, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-05-17 16:17 UTC (permalink / raw)
  To: ffmpeg-devel

Andreas Rheinhardt:
> This is in preparation for using av_dict_iterate().
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavformat/tee.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/tee.c b/libavformat/tee.c
> index 1cbbb80dbb..87159681ed 100644
> --- a/libavformat/tee.c
> +++ b/libavformat/tee.c
> @@ -158,7 +158,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
>  {
>      int i, ret;
>      AVDictionary *options = NULL, *bsf_options = NULL;
> -    AVDictionaryEntry *entry;
> +    const AVDictionaryEntry *entry;
>      char *filename;
>      char *format = NULL, *select = NULL, *on_fail = NULL;
>      char *use_fifo = NULL, *fifo_options_str = NULL;
> @@ -172,8 +172,9 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
>          return ret;
>  
>  #define CONSUME_OPTION(option, field, action) do {                      \
> -        if ((entry = av_dict_get(options, option, NULL, 0))) {          \
> -            field = entry->value;                                       \
> +        AVDictionaryEntry *en = av_dict_get(options, option, NULL, 0);  \
> +        if (en) {                                                       \
> +            field = en->value;                                          \
>              { action }                                                  \
>              av_dict_set(&options, option, NULL, 0);                     \
>          }                                                               \

Added the following necessary diff from the next patch locally:

-                   entry->value = NULL; /* prevent it from being freed */)
+                   en->value = NULL; /* prevent it from being freed */)

- Andreas

_______________________________________________
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] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat()
  2024-05-17 15:23 [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() Andreas Rheinhardt
                   ` (4 preceding siblings ...)
  2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 6/6] fftools, avfilter, avformat: Simplify check for "is dictionary empty?" Andreas Rheinhardt
@ 2024-05-19  9:57 ` Andreas Rheinhardt
  5 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2024-05-19  9:57 UTC (permalink / raw)
  To: ffmpeg-devel

Andreas Rheinhardt:
> Its existence is a remnant of (libavcodec's) lock-manager API
> which has been removed in a04c2c707de2ce850f79870e84ac9d7ec7aa9143.
> There is no need to use the same lock for avisynth, chromaprint
> or tls, so switch to ordinary static mutexes instead.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavformat/avisynth.c    | 15 +++++++++------
>  libavformat/chromaprint.c | 12 +++++++-----
>  libavformat/internal.h    |  3 ---
>  libavformat/tls_gnutls.c  | 16 +++++++---------
>  libavformat/tls_openssl.c | 17 +++++++----------
>  libavformat/utils.c       | 13 -------------
>  6 files changed, 30 insertions(+), 46 deletions(-)
> 
> diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
> index 1709bf4051..625bdf7e3a 100644
> --- a/libavformat/avisynth.c
> +++ b/libavformat/avisynth.c
> @@ -23,6 +23,7 @@
>  #include "libavutil/internal.h"
>  #include "libavutil/mem.h"
>  #include "libavutil/opt.h"
> +#include "libavutil/thread.h"
>  
>  #include "avformat.h"
>  #include "demux.h"
> @@ -130,6 +131,8 @@ static const int avs_planes_yuva[4]   = { AVS_PLANAR_Y, AVS_PLANAR_U,
>  static const int avs_planes_rgba[4]   = { AVS_PLANAR_G, AVS_PLANAR_B,
>                                            AVS_PLANAR_R, AVS_PLANAR_A };
>  
> +static AVMutex avisynth_mutex = AV_MUTEX_INITIALIZER;
> +
>  /* A conflict between C++ global objects, atexit, and dynamic loading requires
>   * us to register our own atexit handler to prevent double freeing. */
>  static AviSynthLibrary avs_library;
> @@ -1083,15 +1086,15 @@ static av_cold int avisynth_read_header(AVFormatContext *s)
>      int ret;
>  
>      // Calling library must implement a lock for thread-safe opens.
> -    if (ret = ff_lock_avformat())
> -        return ret;
> +    if (ff_mutex_lock(&avisynth_mutex))
> +        return AVERROR_UNKNOWN;
>  
>      if (ret = avisynth_open_file(s)) {
> -        ff_unlock_avformat();
> +        ff_mutex_unlock(&avisynth_mutex);
>          return ret;
>      }
>  
> -    ff_unlock_avformat();
> +    ff_mutex_unlock(&avisynth_mutex);
>      return 0;
>  }
>  
> @@ -1127,11 +1130,11 @@ static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
>  
>  static av_cold int avisynth_read_close(AVFormatContext *s)
>  {
> -    if (ff_lock_avformat())
> +    if (ff_mutex_lock(&avisynth_mutex))
>          return AVERROR_UNKNOWN;
>  
>      avisynth_context_destroy(s->priv_data);
> -    ff_unlock_avformat();
> +    ff_mutex_unlock(&avisynth_mutex);
>      return 0;
>  }
>  
> diff --git a/libavformat/chromaprint.c b/libavformat/chromaprint.c
> index 1cdca47ea5..eae233a651 100644
> --- a/libavformat/chromaprint.c
> +++ b/libavformat/chromaprint.c
> @@ -20,15 +20,17 @@
>   */
>  
>  #include "avformat.h"
> -#include "internal.h"
>  #include "mux.h"
>  #include "libavutil/opt.h"
> +#include "libavutil/thread.h"
>  #include <chromaprint.h>
>  
>  #define CPR_VERSION_INT AV_VERSION_INT(CHROMAPRINT_VERSION_MAJOR, \
>                                         CHROMAPRINT_VERSION_MINOR, \
>                                         CHROMAPRINT_VERSION_PATCH)
>  
> +static AVMutex chromaprint_mutex = AV_MUTEX_INITIALIZER;
> +
>  typedef enum FingerprintFormat {
>      FINGERPRINT_RAW,
>      FINGERPRINT_COMPRESSED,
> @@ -52,9 +54,9 @@ static void deinit(AVFormatContext *s)
>      ChromaprintMuxContext *const cpr = s->priv_data;
>  
>      if (cpr->ctx) {
> -        ff_lock_avformat();
> +        ff_mutex_lock(&chromaprint_mutex);
>          chromaprint_free(cpr->ctx);
> -        ff_unlock_avformat();
> +        ff_mutex_unlock(&chromaprint_mutex);
>      }
>  }
>  
> @@ -63,9 +65,9 @@ static av_cold int init(AVFormatContext *s)
>      ChromaprintMuxContext *cpr = s->priv_data;
>      AVStream *st;
>  
> -    ff_lock_avformat();
> +    ff_mutex_lock(&chromaprint_mutex);
>      cpr->ctx = chromaprint_new(cpr->algorithm);
> -    ff_unlock_avformat();
> +    ff_mutex_unlock(&chromaprint_mutex);
>  
>      if (!cpr->ctx) {
>          av_log(s, AV_LOG_ERROR, "Failed to create chromaprint context.\n");
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index 7f3d1c0086..6bad4fd119 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -727,9 +727,6 @@ struct AVBPrint;
>   */
>  int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf);
>  
> -int ff_lock_avformat(void);
> -int ff_unlock_avformat(void);
> -
>  /**
>   * Set AVFormatContext url field to the provided pointer. The pointer must
>   * point to a valid string. The existing url field is freed if necessary. Also
> diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c
> index 2ab38a199b..df251ad79c 100644
> --- a/libavformat/tls_gnutls.c
> +++ b/libavformat/tls_gnutls.c
> @@ -25,15 +25,12 @@
>  #include <gnutls/x509.h>
>  
>  #include "avformat.h"
> -#include "internal.h"
>  #include "network.h"
>  #include "os_support.h"
>  #include "url.h"
>  #include "tls.h"
> -#include "libavcodec/internal.h"
> -#include "libavutil/avstring.h"
>  #include "libavutil/opt.h"
> -#include "libavutil/parseutils.h"
> +#include "libavutil/thread.h"
>  
>  #ifndef GNUTLS_VERSION_NUMBER
>  #define GNUTLS_VERSION_NUMBER LIBGNUTLS_VERSION_NUMBER
> @@ -41,7 +38,6 @@
>  
>  #if HAVE_THREADS && GNUTLS_VERSION_NUMBER <= 0x020b00
>  #include <gcrypt.h>
> -#include "libavutil/thread.h"
>  GCRY_THREAD_OPTION_PTHREAD_IMPL;
>  #endif
>  
> @@ -54,22 +50,24 @@ typedef struct TLSContext {
>      int io_err;
>  } TLSContext;
>  
> +static AVMutex gnutls_mutex = AV_MUTEX_INITIALIZER;
> +
>  void ff_gnutls_init(void)
>  {
> -    ff_lock_avformat();
> +    ff_mutex_lock(&gnutls_mutex);
>  #if HAVE_THREADS && GNUTLS_VERSION_NUMBER < 0x020b00
>      if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
>          gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
>  #endif
>      gnutls_global_init();
> -    ff_unlock_avformat();
> +    ff_mutex_unlock(&gnutls_mutex);
>  }
>  
>  void ff_gnutls_deinit(void)
>  {
> -    ff_lock_avformat();
> +    ff_mutex_lock(&gnutls_mutex);
>      gnutls_global_deinit();
> -    ff_unlock_avformat();
> +    ff_mutex_unlock(&gnutls_mutex);
>  }
>  
>  static int print_tls_error(URLContext *h, int ret)
> diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
> index b875be32f0..89d7c6e1ea 100644
> --- a/libavformat/tls_openssl.c
> +++ b/libavformat/tls_openssl.c
> @@ -19,17 +19,12 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>   */
>  
> -#include "avformat.h"
> -#include "internal.h"
>  #include "network.h"
>  #include "os_support.h"
>  #include "url.h"
>  #include "tls.h"
> -#include "libavutil/avstring.h"
> -#include "libavutil/avutil.h"
>  #include "libavutil/mem.h"
>  #include "libavutil/opt.h"
> -#include "libavutil/parseutils.h"
>  #include "libavutil/thread.h"
>  
>  #include <openssl/bio.h>
> @@ -49,6 +44,8 @@ typedef struct TLSContext {
>      int io_err;
>  } TLSContext;
>  
> +static AVMutex openssl_mutex = AV_MUTEX_INITIALIZER;
> +
>  #if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
>  #include <openssl/crypto.h>
>  pthread_mutex_t *openssl_mutexes;
> @@ -69,7 +66,7 @@ static unsigned long openssl_thread_id(void)
>  
>  int ff_openssl_init(void)
>  {
> -    ff_lock_avformat();
> +    ff_mutex_lock(&openssl_mutex);
>      if (!openssl_init) {
>          /* OpenSSL 1.0.2 or below, then you would use SSL_library_init. If you are
>           * using OpenSSL 1.1.0 or above, then the library will initialize
> @@ -85,7 +82,7 @@ int ff_openssl_init(void)
>              int i;
>              openssl_mutexes = av_malloc_array(sizeof(pthread_mutex_t), CRYPTO_num_locks());
>              if (!openssl_mutexes) {
> -                ff_unlock_avformat();
> +                ff_mutex_unlock(&openssl_mutex);
>                  return AVERROR(ENOMEM);
>              }
>  
> @@ -99,14 +96,14 @@ int ff_openssl_init(void)
>  #endif
>      }
>      openssl_init++;
> -    ff_unlock_avformat();
> +    ff_mutex_unlock(&openssl_mutex);
>  
>      return 0;
>  }
>  
>  void ff_openssl_deinit(void)
>  {
> -    ff_lock_avformat();
> +    ff_mutex_lock(&openssl_mutex);
>      openssl_init--;
>      if (!openssl_init) {
>  #if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
> @@ -119,7 +116,7 @@ void ff_openssl_deinit(void)
>          }
>  #endif
>      }
> -    ff_unlock_avformat();
> +    ff_mutex_unlock(&openssl_mutex);
>  }
>  
>  static int print_tls_error(URLContext *h, int ret)
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 4dded7aea4..e9ded627ad 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -27,7 +27,6 @@
>  #include "libavutil/bprint.h"
>  #include "libavutil/internal.h"
>  #include "libavutil/mem.h"
> -#include "libavutil/thread.h"
>  #include "libavutil/time.h"
>  
>  #include "libavcodec/internal.h"
> @@ -40,23 +39,11 @@
>  #endif
>  #include "os_support.h"
>  
> -static AVMutex avformat_mutex = AV_MUTEX_INITIALIZER;
> -
>  /**
>   * @file
>   * various utility functions for use within FFmpeg
>   */
>  
> -int ff_lock_avformat(void)
> -{
> -    return ff_mutex_lock(&avformat_mutex) ? -1 : 0;
> -}
> -
> -int ff_unlock_avformat(void)
> -{
> -    return ff_mutex_unlock(&avformat_mutex) ? -1 : 0;
> -}
> -
>  /* an arbitrarily chosen "sane" max packet size -- 50M */
>  #define SANE_CHUNK_SIZE (50000000)
>  

Will apply this patchset tomorrow unless there are objections.

- Andreas

_______________________________________________
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] 13+ messages in thread

end of thread, other threads:[~2024-05-19  9:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-17 15:23 [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() Andreas Rheinhardt
2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 2/6] avformat/tls_openssl: #if ff_openssl_init/deinit() away if possible Andreas Rheinhardt
2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 3/6] avformat/tee: Constify AVDictionaryEntry* pointee where possible Andreas Rheinhardt
2024-05-17 15:42   ` epirat07
2024-05-17 16:17   ` Andreas Rheinhardt
2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 4/6] avformat/tee: Use smaller scope for variables Andreas Rheinhardt
2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 5/6] avcodec/lib*, avformat/tee: Simplify iterating over AVDictionary Andreas Rheinhardt
2024-05-17 15:41   ` epirat07
2024-05-17 15:44     ` Andreas Rheinhardt
2024-05-17 15:48       ` epirat07
2024-05-17 15:25 ` [FFmpeg-devel] [PATCH 6/6] fftools, avfilter, avformat: Simplify check for "is dictionary empty?" Andreas Rheinhardt
2024-05-17 15:39   ` epirat07
2024-05-19  9:57 ` [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() 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