X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=core%2Fthumbnail_generator.cpp;h=a80702c8a9dcf62f765b0f1b415a9ae6d32bc3ae;hb=cde347942b00b54550497641786219e8a0862287;hp=fd3ccb1886cda53eb0d7d60995b88ba0fbfea789;hpb=a36f794e330f7a29ea4583868290817c483c10ae;p=casparcg diff --git a/core/thumbnail_generator.cpp b/core/thumbnail_generator.cpp index fd3ccb188..a80702c8a 100644 --- a/core/thumbnail_generator.cpp +++ b/core/thumbnail_generator.cpp @@ -35,6 +35,7 @@ #include #include +#include #include "producer/frame_producer.h" #include "consumer/frame_consumer.h" @@ -50,30 +51,6 @@ namespace caspar { namespace core { -std::wstring get_relative_without_extension( - const boost::filesystem::path& file, - const boost::filesystem::path& relative_to) -{ - auto result = file.stem(); - - boost::filesystem::path current_path = file; - - while (true) - { - current_path = current_path.parent_path(); - - if (boost::filesystem::equivalent(current_path, relative_to)) - break; - - if (current_path.empty()) - throw std::runtime_error("File not relative to folder"); - - result = current_path.filename() / result; - } - - return result.wstring(); -} - struct thumbnail_output { tbb::atomic sleep_millis; @@ -138,6 +115,7 @@ public: , thumbnail_creator_(thumbnail_creator) , media_info_repo_(std::move(media_info_repo)) , producer_registry_(std::move(producer_registry)) + , mipmap_(mipmap) , monitor_(monitor_factory.create( media_path, filesystem_event::ALL, @@ -168,7 +146,7 @@ public: std::insert_iterator>( relative_without_extensions, relative_without_extensions.end()), - boost::bind(&get_relative_without_extension, _1, media_path_)); + [&](const path& p) { return get_relative_without_extension(p, media_path_).wstring(); }); for (boost::filesystem::wrecursive_directory_iterator iter(thumbnails_path_); iter != boost::filesystem::wrecursive_directory_iterator(); ++iter) { @@ -178,11 +156,11 @@ 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) + bool no_corresponding_media_file = relative_without_extensions.find(relative_without_extension.wstring()) == relative_without_extensions.end(); if (no_corresponding_media_file) - remove(thumbnails_path_ / (relative_without_extension + L".png")); + remove(thumbnails_path_ / (relative_without_extension.wstring() + L".png")); } } @@ -221,7 +199,7 @@ public: break; case filesystem_event::REMOVED: auto relative_without_extension = get_relative_without_extension(file, media_path_); - boost::filesystem::remove(thumbnails_path_ / (relative_without_extension + L".png")); + boost::filesystem::remove(thumbnails_path_ / (relative_without_extension.wstring() + L".png")); media_info_repo_->remove(file.wstring()); break; @@ -232,7 +210,7 @@ public: { using namespace boost::filesystem; - auto png_file = thumbnails_path_ / (get_relative_without_extension(file, media_path_) + L".png"); + auto png_file = thumbnails_path_ / (get_relative_without_extension(file, media_path_).wstring() + L".png"); if (!exists(png_file)) return true; @@ -262,35 +240,12 @@ public: void generate_thumbnail(const boost::filesystem::path& file) { + auto media_file_with_extension = get_relative(file, media_path_); auto media_file = get_relative_without_extension(file, media_path_); - auto png_file = thumbnails_path_ / (media_file + L".png"); + auto png_file = thumbnails_path_ / (media_file.wstring() + L".png"); std::promise 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); - } - catch (const boost::thread_interrupted&) - { - throw; - } - catch (...) - { - CASPAR_LOG(debug) << L"Thumbnail producer failed to initialize for " << media_file; - return; - } - - if (producer == frame_producer::empty()) - { - CASPAR_LOG(trace) << L"No appropriate thumbnail producer found for " << media_file; - return; - } - boost::filesystem::create_directories(png_file.parent_path()); output_->on_send = [this, &png_file] (const_frame frame) { @@ -302,7 +257,7 @@ public: try { - raw_frame = producer->create_thumbnail_frame(); + raw_frame = producer_registry_->create_thumbnail(frame_producer_dependencies(image_mixer_, {}, format_desc_, producer_registry_), media_file.wstring()); media_info_repo_->remove(file.wstring()); media_info_repo_->get(file.wstring()); } @@ -312,14 +267,15 @@ public: } catch (...) { - CASPAR_LOG(debug) << L"Thumbnail producer failed to create thumbnail for " << media_file; + 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; + CASPAR_LOG(debug) << L"No thumbnail producer for " << media_file_with_extension; return; } @@ -344,7 +300,7 @@ public: try { boost::filesystem::last_write_time(png_file, boost::filesystem::last_write_time(file)); - CASPAR_LOG(debug) << L"Generated thumbnail for " << media_file; + CASPAR_LOG(info) << L"Generated thumbnail for " << media_file_with_extension; } catch (...) { @@ -352,7 +308,7 @@ public: } } else - CASPAR_LOG(debug) << L"No thumbnail generated for " << media_file; + CASPAR_LOG(debug) << L"No thumbnail generated for " << media_file_with_extension; } };