]> git.sesse.net Git - casparcg/commitdiff
* Ported thread local disabling of ffmpeg producer logging from 2.0 and move some...
authorHelge Norberg <helge.norberg@svt.se>
Wed, 28 Oct 2015 17:39:00 +0000 (18:39 +0100)
committerHelge Norberg <helge.norberg@svt.se>
Wed, 28 Oct 2015 17:39:00 +0000 (18:39 +0100)
modules/ffmpeg/audio_channel_remapper.cpp
modules/ffmpeg/ffmpeg.cpp
modules/ffmpeg/ffmpeg.h
modules/ffmpeg/producer/ffmpeg_producer.cpp
modules/ffmpeg/producer/filter/audio_filter.cpp
modules/ffmpeg/producer/filter/filter.cpp
modules/ffmpeg/producer/input/input.cpp
modules/ffmpeg/producer/muxer/frame_muxer.cpp

index f70f9c5581323ed9ca45777fc33840e08f3d7328..54de4386d5a336e808bd5e7569f6260c22f71f79 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "StdAfx.h"
 
+#include "ffmpeg.h"
+
 #include <core/frame/audio_channel_layout.h>
 
 #include <common/except.h>
@@ -77,13 +79,13 @@ std::wstring generate_pan_filter_str(
                        for (int i = 0; i < output.num_channels; ++i)
                                result << L"|c" << i << L"=c" << i;
 
-                       CASPAR_LOG(debug) << "[audio_channel_remapper] Passthru " << input.num_channels << " channels into " << output.num_channels;
+                       CASPAR_LOG(trace) << "[audio_channel_remapper] Passthru " << input.num_channels << " channels into " << output.num_channels;
 
                        return result.str();
                }
        }
 
-       CASPAR_LOG(debug) << L"[audio_channel_remapper] Using mix config: " << *mix_config;
+       CASPAR_LOG(trace) << L"[audio_channel_remapper] Using mix config: " << *mix_config;
 
        // Split on | to find the output sections
        std::vector<std::wstring> output_sections;
@@ -136,15 +138,16 @@ struct audio_channel_remapper::impl
                if (output_layout_ == audio_channel_layout::invalid())
                        CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info(L"Output audio channel layout is invalid"));
 
-               CASPAR_LOG(debug) << L"[audio_channel_remapper] Input:  " << input_layout_.print();
-               CASPAR_LOG(debug) << L"[audio_channel_remapper] Output: " << output_layout_.print();
+               CASPAR_LOG(trace) << L"[audio_channel_remapper] Input:  " << input_layout_.print();
+               CASPAR_LOG(trace) << L"[audio_channel_remapper] Output: " << output_layout_.print();
 
                if (!the_same_layouts_)
                {
                        auto mix_config = mix_repo->get_config(input_layout_.type, output_layout_.type);
                        auto pan_filter = u8(generate_pan_filter_str(input_layout_, output_layout_, mix_config));
 
-                       CASPAR_LOG(debug) << "[audio_channel_remapper] Using audio filter: " << pan_filter;
+                       CASPAR_LOG(trace) << "[audio_channel_remapper] Using audio filter: " << pan_filter;
+                       auto logging_disabled = ffmpeg::temporary_disable_logging_for_thread(true);
                        filter_.reset(new ffmpeg::audio_filter(
                                        boost::rational<int>(1, 1),
                                        48000,
@@ -156,7 +159,7 @@ struct audio_channel_remapper::impl
                                        pan_filter));
                }
                else
-                       CASPAR_LOG(debug) << "[audio_channel_remapper] No remapping/mixing needed because the input and output layout is equal.";
+                       CASPAR_LOG(trace) << "[audio_channel_remapper] No remapping/mixing needed because the input and output layout is equal.";
        }
 
        audio_buffer mix_and_rearrange(audio_buffer input)
index 7a151f05b62879d6754560a5e736c08c307f6e84..6a6946f1faa4084749a97dfab56ea3fe15f640af 100644 (file)
@@ -29,6 +29,7 @@
 #include "producer/util/util.h"
 
 #include <common/log.h>
+#include <common/os/general_protection_fault.h>
 
 #include <core/consumer/frame_consumer.h>
 #include <core/producer/frame_producer.h>
@@ -37,6 +38,7 @@
 #include <core/system_info_provider.h>
 
 #include <boost/property_tree/ptree.hpp>
+#include <boost/thread/tss.hpp>
 
 #include <tbb/recursive_mutex.h>
 
@@ -235,11 +237,55 @@ std::wstring swscale_version()
 {
        return make_version(::swscale_version());
 }
+bool& get_disable_logging_for_thread()
+{
+       static boost::thread_specific_ptr<bool> disable_logging_for_thread;
+
+       auto local = disable_logging_for_thread.get();
+
+       if (!local)
+       {
+               local = new bool(false);
+               disable_logging_for_thread.reset(local);
+       }
+
+       return *local;
+}
+
+void disable_logging_for_thread()
+{
+       get_disable_logging_for_thread() = true;
+}
+
+bool is_logging_disabled_for_thread()
+{
+       return get_disable_logging_for_thread();
+}
+
+std::shared_ptr<void> temporary_disable_logging_for_thread(bool disable)
+{
+       if (!disable || is_logging_disabled_for_thread())
+               return std::shared_ptr<void>();
+
+       disable_logging_for_thread();
+
+       return std::shared_ptr<void>(nullptr, [](void*)
+       {
+               get_disable_logging_for_thread() = false; // Only works correctly if destructed in same thread as original caller.
+       });
+}
+
+void log_for_thread(void* ptr, int level, const char* fmt, va_list vl)
+{
+       ensure_gpf_handler_installed_for_thread("ffmpeg-thread");
+       if (!get_disable_logging_for_thread()) // It does not matter what the value of the bool is
+               log_callback(ptr, level, fmt, vl);
+}
 
 void init(core::module_dependencies dependencies)
 {
        av_lockmgr_register(ffmpeg_lock_callback);
-       av_log_set_callback(log_callback);
+       av_log_set_callback(log_for_thread);
 
     avfilter_register_all();
        //fix_yadif_filter_format_query();
index e47e74cf44ba1fe90a097611f556a0a7b4c2150c..a20a882470acee4a2191930571a75422c993f0d9 100644 (file)
@@ -28,5 +28,8 @@ namespace caspar { namespace ffmpeg {
 
 void init(core::module_dependencies dependencies);
 void uninit();
+void disable_logging_for_thread();
+std::shared_ptr<void> temporary_disable_logging_for_thread(bool disable);
+bool is_logging_disabled_for_thread();
 
 }}
index 813c933302d26c32cc76a52a6fa39483d5d0cf9f..8dcf6fbd888b7f6806f45f2291d66e0b4e8c3d18 100644 (file)
@@ -24,6 +24,7 @@
 #include "ffmpeg_producer.h"
 
 #include "../ffmpeg_error.h"
+#include "../ffmpeg.h"
 
 #include "muxer/frame_muxer.h"
 #include "input/input.h"
@@ -144,7 +145,8 @@ public:
                        constraints_.width.set(video_decoder_->width());
                        constraints_.height.set(video_decoder_->height());
                        
-                       CASPAR_LOG(info) << print() << L" " << video_decoder_->print();
+                       if (!is_logging_disabled_for_thread())
+                               CASPAR_LOG(info) << print() << L" " << video_decoder_->print();
                }
                catch(averror_stream_not_found&)
                {
@@ -184,7 +186,8 @@ public:
                
                decode_next_frame();
 
-               CASPAR_LOG(info) << print() << L" Initialized";
+               if (!is_logging_disabled_for_thread())
+                       CASPAR_LOG(info) << print() << L" Initialized";
        }
 
        // frame_producer
index ce59992f5cfaa1e7878092f6cc3c9f7b024c94fb..de5b8fd34f079b9ad74fcb295602b374b9fcca41 100644 (file)
@@ -24,6 +24,7 @@
 #include "audio_filter.h"
 
 #include "../../ffmpeg_error.h"
+#include "../../ffmpeg.h"
 
 #include <common/assert.h>
 #include <common/except.h>
@@ -155,11 +156,12 @@ struct audio_filter::implementation
                audio_graph_in_  = filt_asrc;
                audio_graph_out_ = filt_asink;
                
-               CASPAR_LOG(info)
-                       <<      u16(std::string("\n") 
-                               + avfilter_graph_dump(
-                                               audio_graph_.get(), 
-                                               nullptr));
+               if (!is_logging_disabled_for_thread())
+                       CASPAR_LOG(info)
+                               <<      u16(std::string("\n") 
+                                       + avfilter_graph_dump(
+                                                       audio_graph_.get(), 
+                                                       nullptr));
        }
        
        void configure_filtergraph(
index 28816d20640165c9b20400e925d1614996a0fa1c..b47c6ef0a8d3b5fd3020588571bb7da82dd9d1e0 100644 (file)
@@ -24,6 +24,7 @@
 #include "filter.h"
 
 #include "../../ffmpeg_error.h"
+#include "../../ffmpeg.h"
 
 #include <common/assert.h>
 #include <common/except.h>
@@ -150,11 +151,12 @@ struct filter::implementation
                video_graph_in_  = filt_vsrc;
                video_graph_out_ = filt_vsink;
                
-               CASPAR_LOG(info)
-                       <<      u16(std::string("\n") 
-                               + avfilter_graph_dump(
-                                               video_graph_.get(), 
-                                               nullptr));
+               if (!is_logging_disabled_for_thread())
+                       CASPAR_LOG(info)
+                               <<      u16(std::string("\n") 
+                                       + avfilter_graph_dump(
+                                                       video_graph_.get(), 
+                                                       nullptr));
        }
        
        void configure_filtergraph(
index 5e170d2404d15ed22a3b54241d822925ebb1182d..68f33c7347995d814d00f2f84232fe2305de9cb8 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "../util/util.h"
 #include "../../ffmpeg_error.h"
+#include "../../ffmpeg.h"
 
 #include <common/diagnostics/graph.h>
 #include <common/executor.h>
@@ -218,7 +219,8 @@ private:
                eof_ = false;
                graph_->set_tag(diagnostics::tag_severity::INFO, "seek");
 
-               CASPAR_LOG(debug) << print() << " Seeking: " << target;
+               if (!is_logging_disabled_for_thread())
+                       CASPAR_LOG(debug) << print() << " Seeking: " << target;
 
                int flags = AVSEEK_FLAG_FRAME;
                if(target == 0)
index 7cb40f809ca76da73c952dac9422906b9833b464..4189326c0533df073603eb8fbc95a75bf216edf1 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "../filter/filter.h"
 #include "../util/util.h"
+#include "../../ffmpeg.h"
 
 #include <core/producer/frame_producer.h>
 #include <core/frame/draw_frame.h>
@@ -123,7 +124,8 @@ struct frame_muxer::impl : boost::noncopyable
                if (previous_frame_ && video->data[0] && is_frame_format_changed(*previous_frame_, *video))
                {
                        // Fixes bug where avfilter crashes server on some DV files (starts in YUV420p but changes to YUV411p after the first frame).
-                       CASPAR_LOG(info) << L"[frame_muxer] Frame format has changed. Resetting display mode.";
+                       if (!ffmpeg::is_logging_disabled_for_thread())
+                               CASPAR_LOG(info) << L"[frame_muxer] Frame format has changed. Resetting display mode.";
                        display_mode_ = display_mode::invalid;
                }
 
@@ -328,7 +330,8 @@ struct frame_muxer::impl : boost::noncopyable
 
                if(display_mode_ == display_mode::invalid)
                {
-                       CASPAR_LOG(warning) << L"[frame_muxer] Auto-transcode: Failed to detect display-mode.";
+                       if (!ffmpeg::is_logging_disabled_for_thread())
+                               CASPAR_LOG(warning) << L"[frame_muxer] Auto-transcode: Failed to detect display-mode.";
                        display_mode_ = display_mode::simple;
                }
 
@@ -348,7 +351,8 @@ struct frame_muxer::impl : boost::noncopyable
                        std::vector<AVPixelFormat>(),
                        u8(filter_str)));
 
-               CASPAR_LOG(info) << L"[frame_muxer] " << display_mode_ << L" " << print_mode(frame->width, frame->height, in_fps_, frame->interlaced_frame > 0);
+               if (!ffmpeg::is_logging_disabled_for_thread())
+                       CASPAR_LOG(info) << L"[frame_muxer] " << display_mode_ << L" " << print_mode(frame->width, frame->height, in_fps_, frame->interlaced_frame > 0);
        }
        
        uint32_t calc_nb_frames(uint32_t nb_frames) const