Setup ffmpeg log callback in dcpomatic_setup() instead of in FFmpeg.
authorCarl Hetherington <cth@carlh.net>
Thu, 23 Feb 2023 22:35:40 +0000 (23:35 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 3 Mar 2023 00:17:41 +0000 (01:17 +0100)
src/lib/ffmpeg.cc
src/lib/ffmpeg.h
src/lib/util.cc

index 39abfe2b84ce71679cd66af9ac20a7d59a34d199..4b8d7b8ab1d89ab7b14b67dbd8da739a52abc144 100644 (file)
@@ -96,30 +96,9 @@ avio_seek_wrapper (void* data, int64_t offset, int whence)
 }
 
 
-void
-FFmpeg::ffmpeg_log_callback (void* ptr, int level, const char* fmt, va_list vl)
-{
-       if (level > AV_LOG_WARNING) {
-               return;
-       }
-
-       char line[1024];
-       static int prefix = 0;
-       av_log_format_line (ptr, level, fmt, vl, line, sizeof (line), &prefix);
-       string str (line);
-       boost::algorithm::trim (str);
-       dcpomatic_log->log (String::compose ("FFmpeg: %1", str), LogEntry::TYPE_GENERAL);
-}
-
-
 void
 FFmpeg::setup_general ()
 {
-       /* This might not work too well in some cases of multiple FFmpeg decoders,
-          but it's probably good enough.
-       */
-       av_log_set_callback (FFmpeg::ffmpeg_log_callback);
-
        _file_group.set_paths (_ffmpeg_content->paths ());
        _avio_buffer = static_cast<uint8_t*> (wrapped_av_malloc(_avio_buffer_size));
        _avio_context = avio_alloc_context (_avio_buffer, _avio_buffer_size, 0, this, avio_read_wrapper, 0, avio_seek_wrapper);
index 55357d24b6a7d537770000e74ca8f3865a583362..834c8946c0e50679a6b4e8765ae30d3baa519ca1 100644 (file)
@@ -93,8 +93,6 @@ private:
        void setup_general ();
        void setup_decoders ();
 
-       static void ffmpeg_log_callback (void* ptr, int level, const char* fmt, va_list vl);
-
        /** AVFrames used for decoding audio streams; accessed with audio_frame() */
        std::map<std::shared_ptr<const FFmpegAudioStream>, AVFrame*> _audio_frame;
 };
index bab74583c52248d9cdd6fe569c3fba12468ba864..6ed66c40f27d14f3cc0dfd6c556b4a6f3c5b0d60 100644 (file)
@@ -388,6 +388,31 @@ capture_asdcp_logs ()
 }
 
 
+static
+void
+ffmpeg_log_callback(void* ptr, int level, const char* fmt, va_list vl)
+{
+       if (level > AV_LOG_WARNING) {
+               return;
+       }
+
+       char line[1024];
+       static int prefix = 0;
+       av_log_format_line(ptr, level, fmt, vl, line, sizeof (line), &prefix);
+       string str(line);
+       boost::algorithm::trim(str);
+       dcpomatic_log->log(String::compose("FFmpeg: %1", str), LogEntry::TYPE_GENERAL);
+}
+
+
+static
+void
+capture_ffmpeg_logs()
+{
+       av_log_set_callback(ffmpeg_log_callback);
+}
+
+
 /** Call the required functions to set up DCP-o-matic's static arrays, etc.
  *  Must be called from the UI thread, if there is one.
  */
@@ -455,6 +480,7 @@ LIBDCP_ENABLE_WARNINGS
        ui_thread = boost::this_thread::get_id ();
 
        capture_asdcp_logs ();
+       capture_ffmpeg_logs();
 }
 
 #ifdef DCPOMATIC_WINDOWS