]> git.sesse.net Git - casparcg/blobdiff - core/thumbnail_generator.cpp
Fix a few Clang warnings.
[casparcg] / core / thumbnail_generator.cpp
index aded7f7fe0b36659a5bc9e34248702455ab9ca6e..09b61de6cdb82b9fae38fc1bf6fd1ff775b6c0bf 100644 (file)
 #include <iterator>
 #include <set>
 #include <future>
+#include <thread>
 
-#include <boost/thread.hpp>
 #include <boost/algorithm/string/predicate.hpp>
 #include <boost/filesystem.hpp>
+#include <boost/thread.hpp>
 
 #include <tbb/atomic.h>
 
@@ -38,6 +39,7 @@
 #include <common/filesystem.h>
 
 #include "producer/frame_producer.h"
+#include "producer/cg_proxy.h"
 #include "consumer/frame_consumer.h"
 #include "mixer/mixer.h"
 #include "mixer/image/image_mixer.h"
@@ -66,7 +68,7 @@ struct thumbnail_output
                int current_sleep = sleep_millis;
 
                if (current_sleep > 0)
-                       boost::this_thread::sleep_for(boost::chrono::milliseconds(current_sleep));
+                       std::this_thread::sleep_for(std::chrono::milliseconds(current_sleep));
 
                on_send(std::move(frame));
                on_send = nullptr;
@@ -88,6 +90,7 @@ private:
        thumbnail_creator                                                               thumbnail_creator_;
        spl::shared_ptr<media_info_repository>                  media_info_repo_;
        spl::shared_ptr<const frame_producer_registry>  producer_registry_;
+       spl::shared_ptr<const cg_producer_registry>             cg_registry_;
        bool                                                                                    mipmap_;
        filesystem_monitor::ptr                                                 monitor_;
 public:
@@ -103,6 +106,7 @@ public:
                        const thumbnail_creator& thumbnail_creator,
                        spl::shared_ptr<media_info_repository> media_info_repo,
                        spl::shared_ptr<const frame_producer_registry> producer_registry,
+                       spl::shared_ptr<const cg_producer_registry> cg_registry,
                        bool mipmap)
                : media_path_(media_path)
                , thumbnails_path_(thumbnails_path)
@@ -115,6 +119,8 @@ public:
                , thumbnail_creator_(thumbnail_creator)
                , media_info_repo_(std::move(media_info_repo))
                , producer_registry_(std::move(producer_registry))
+               , cg_registry_(std::move(cg_registry))
+               , mipmap_(mipmap)
                , monitor_(monitor_factory.create(
                                media_path,
                                filesystem_event::ALL,
@@ -155,7 +161,7 @@ public:
                                continue;
 
                        auto relative_without_extension = get_relative_without_extension(path, thumbnails_path_);
-                       bool no_corresponding_media_file = relative_without_extensions.find(relative_without_extension.wstring()) 
+                       bool no_corresponding_media_file = relative_without_extensions.find(relative_without_extension.wstring())
                                        == relative_without_extensions.end();
 
                        if (no_corresponding_media_file)
@@ -166,16 +172,24 @@ public:
        void generate(const std::wstring& media_file)
        {
                using namespace boost::filesystem;
-               auto base_file = media_path_ / media_file;
-               auto folder = base_file.parent_path();
+
+               auto base_file  = media_path_ / media_file;
+               auto folder             = base_file.parent_path();
+               bool found              = false;
 
                for (boost::filesystem::directory_iterator iter(folder); iter != boost::filesystem::directory_iterator(); ++iter)
                {
                        auto stem = iter->path().stem();
 
                        if (boost::iequals(stem.wstring(), base_file.filename().wstring()))
+                       {
                                monitor_->reemmit(iter->path());
+                               found = true;
+                       }
                }
+
+               if (!found)
+                       CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(L"Media file " + media_file + L" not found"));
        }
 
        void generate_all()
@@ -245,31 +259,6 @@ public:
                std::promise<void> thumbnail_ready;
 
                {
-                       auto producer = frame_producer::empty();
-
-                       try
-                       {
-                               producer = producer_registry_->create_thumbnail_producer(
-                                               frame_producer_dependencies(image_mixer_, { }, format_desc_, producer_registry_),
-                                               media_file.wstring());
-                       }
-                       catch (const boost::thread_interrupted&)
-                       {
-                               throw;
-                       }
-                       catch (...)
-                       {
-                               CASPAR_LOG_CURRENT_EXCEPTION_AT_LEVEL(debug);
-                               CASPAR_LOG(info) << L"Thumbnail producer failed to initialize for " << media_file_with_extension << L". Turn on log level debug to see more information.";
-                               return;
-                       }
-
-                       if (producer == frame_producer::empty())
-                       {
-                               CASPAR_LOG(debug) << L"No appropriate thumbnail producer found for " << media_file_with_extension;
-                               return;
-                       }
-
                        boost::filesystem::create_directories(png_file.parent_path());
                        output_->on_send = [this, &png_file] (const_frame frame)
                        {
@@ -281,7 +270,7 @@ public:
 
                        try
                        {
-                               raw_frame = producer->create_thumbnail_frame();
+                               raw_frame = producer_registry_->create_thumbnail(frame_producer_dependencies(image_mixer_, {}, format_desc_, producer_registry_, cg_registry_), media_file.wstring());
                                media_info_repo_->remove(file.wstring());
                                media_info_repo_->get(file.wstring());
                        }
@@ -291,15 +280,15 @@ public:
                        }
                        catch (...)
                        {
-                               CASPAR_LOG_CURRENT_EXCEPTION_AT_LEVEL(debug);
-                               CASPAR_LOG(info) << L"Thumbnail producer failed to create thumbnail for " << media_file_with_extension << L". Turn on log level debug to see more information.";
+                               CASPAR_LOG_CURRENT_EXCEPTION_AT_LEVEL(trace);
+                               CASPAR_LOG(info) << L"Thumbnail producer failed to create thumbnail for " << media_file_with_extension << L". Turn on log level trace to see more information.";
                                return;
                        }
 
                        if (raw_frame == draw_frame::empty()
                                        || raw_frame == draw_frame::late())
                        {
-                               CASPAR_LOG(debug) << L"No thumbnail generated for " << media_file_with_extension;
+                               CASPAR_LOG(debug) << L"No thumbnail producer for " << media_file_with_extension;
                                return;
                        }
 
@@ -348,6 +337,7 @@ thumbnail_generator::thumbnail_generator(
                const thumbnail_creator& thumbnail_creator,
                spl::shared_ptr<media_info_repository> media_info_repo,
                spl::shared_ptr<const frame_producer_registry> producer_registry,
+               spl::shared_ptr<const cg_producer_registry> cg_registry,
                bool mipmap)
                : impl_(new impl(
                                monitor_factory,
@@ -360,6 +350,7 @@ thumbnail_generator::thumbnail_generator(
                                thumbnail_creator,
                                media_info_repo,
                                producer_registry,
+                               cg_registry,
                                mipmap))
 {
 }