]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/ffmpeg.cpp
Simplified thumbnail creation, making it less intrusive in the frame_producer design.
[casparcg] / modules / ffmpeg / ffmpeg.cpp
index 9a5d650f44245d0a6c0aa85a46781e5fd77bf5c6..7d8159238c8cc0ed9f386f4c231f41ef64c556ca 100644 (file)
 
 #include "StdAfx.h"
 
+#include "ffmpeg.h"
+
 #include "consumer/ffmpeg_consumer.h"
+#include "consumer/streaming_consumer.h"
 #include "producer/ffmpeg_producer.h"
 #include "producer/util/util.h"
 
 #include <common/log.h>
+#include <common/os/general_protection_fault.h>
 
 #include <core/consumer/frame_consumer.h>
+#include <core/frame/draw_frame.h>
 #include <core/producer/frame_producer.h>
 #include <core/producer/media_info/media_info.h>
 #include <core/producer/media_info/media_info_repository.h>
+#include <core/system_info_provider.h>
+
+#include <boost/property_tree/ptree.hpp>
+#include <boost/thread/tss.hpp>
+#include <boost/bind.hpp>
 
 #include <tbb/recursive_mutex.h>
 
@@ -198,48 +208,6 @@ void log_callback(void* ptr, int level, const char* fmt, va_list vl)
 //}
 //#pragma warning (pop)
 
-void init(const spl::shared_ptr<core::media_info_repository>& media_info_repo)
-{
-       av_lockmgr_register(ffmpeg_lock_callback);
-       av_log_set_callback(log_callback);
-
-    avfilter_register_all();
-       //fix_yadif_filter_format_query();
-       av_register_all();
-    avformat_network_init();
-    avcodec_register_all();
-       
-       core::register_consumer_factory([](const std::vector<std::wstring>& params){return create_consumer(params);});
-       core::register_producer_factory(create_producer);
-       
-       media_info_repo->register_extractor(
-                       [](const std::wstring& file, const std::wstring& extension, core::media_info& info) -> bool
-                       {
-                               // TODO: merge thumbnail generation from 2.0
-                               //auto disable_logging = temporary_disable_logging_for_thread(true);
-                               if (extension == L".WAV" || extension == L".MP3")
-                               {
-                                       info.clip_type = L"AUDIO";
-                                       return true;
-                               }
-
-                               if (!is_valid_file(file))
-                                       return false;
-
-                               info.clip_type = L"MOVIE";
-
-                               return try_get_duration(file, info.duration, info.time_base);
-                       });
-
-}
-
-void uninit()
-{
-       avfilter_uninit();
-    avformat_network_deinit();
-       av_lockmgr_register(nullptr);
-}
-
 std::wstring make_version(unsigned int ver)
 {
        std::wstringstream str;
@@ -271,5 +239,100 @@ std::wstring swscale_version()
 {
        return make_version(::swscale_version());
 }
+bool& get_quiet_logging_for_thread()
+{
+       static boost::thread_specific_ptr<bool> quiet_logging_for_thread;
+
+       auto local = quiet_logging_for_thread.get();
+
+       if (!local)
+       {
+               local = new bool(false);
+               quiet_logging_for_thread.reset(local);
+       }
+
+       return *local;
+}
+
+bool is_logging_quiet_for_thread()
+{
+       return get_quiet_logging_for_thread();
+}
+
+std::shared_ptr<void> temporary_enable_quiet_logging_for_thread(bool enable)
+{
+       if (!enable || is_logging_quiet_for_thread())
+               return std::shared_ptr<void>();
+
+       get_quiet_logging_for_thread() = true;
+
+       return std::shared_ptr<void>(nullptr, [](void*)
+       {
+               get_quiet_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");
+
+       int min_level = is_logging_quiet_for_thread() ? AV_LOG_DEBUG : AV_LOG_FATAL;
+
+       log_callback(ptr, std::max(level, min_level), fmt, vl);
+}
+
+void init(core::module_dependencies dependencies)
+{
+       av_lockmgr_register(ffmpeg_lock_callback);
+       av_log_set_callback(log_for_thread);
+
+    avfilter_register_all();
+       //fix_yadif_filter_format_query();
+       av_register_all();
+    avformat_network_init();
+    avcodec_register_all();
+
+       auto info_repo = dependencies.media_info_repo;
+       
+       dependencies.consumer_registry->register_consumer_factory(L"FFmpeg Consumer", create_consumer, describe_consumer);
+       dependencies.consumer_registry->register_consumer_factory(L"Streaming Consumer",  create_streaming_consumer, describe_streaming_consumer);
+       dependencies.consumer_registry->register_preconfigured_consumer_factory(L"file", create_preconfigured_consumer);
+       dependencies.consumer_registry->register_preconfigured_consumer_factory(L"stream", create_preconfigured_streaming_consumer);
+       dependencies.producer_registry->register_producer_factory(L"FFmpeg Producer", boost::bind(&create_producer, _1, _2, info_repo), describe_producer);
+       dependencies.producer_registry->register_thumbnail_producer(boost::bind(&create_thumbnail_frame, _1, _2, info_repo));
+
+       info_repo->register_extractor(
+                       [](const std::wstring& file, const std::wstring& extension, core::media_info& info) -> bool
+                       {
+                               auto quiet_logging = temporary_enable_quiet_logging_for_thread(true);
+                               if (extension == L".WAV" || extension == L".MP3")
+                               {
+                                       info.clip_type = L"AUDIO";
+                                       return true;
+                               }
+
+                               if (!is_valid_file(file, true))
+                                       return false;
+
+                               info.clip_type = L"MOVIE";
+
+                               return try_get_duration(file, info.duration, info.time_base);
+                       });
+       dependencies.system_info_provider_repo->register_system_info_provider([](boost::property_tree::wptree& info)
+       {
+               info.add(L"system.ffmpeg.avcodec", avcodec_version());
+               info.add(L"system.ffmpeg.avformat", avformat_version());
+               info.add(L"system.ffmpeg.avfilter", avfilter_version());
+               info.add(L"system.ffmpeg.avutil", avutil_version());
+               info.add(L"system.ffmpeg.swscale", swscale_version());
+       });
+}
+
+void uninit()
+{
+       avfilter_uninit();
+    avformat_network_deinit();
+       av_lockmgr_register(nullptr);
+}
 
-}}
\ No newline at end of file
+}}