2 * Copyright 2013 Sveriges Television AB http://casparcg.com/
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Helge Norberg, helge.norberg@svt.se
22 #include "../../StdAfx.h"
24 #include "in_memory_media_info_repository.h"
29 #include <boost/thread/mutex.hpp>
30 #include <boost/foreach.hpp>
31 #include <boost/filesystem.hpp>
32 #include <boost/algorithm/string/case_conv.hpp>
34 #include "media_info.h"
35 #include "media_info_repository.h"
37 namespace caspar { namespace core {
39 class in_memory_media_info_repository : public media_info_repository
42 std::map<std::wstring, boost::optional<media_info>> info_by_file_;
43 std::vector<media_info_extractor> extractors_;
45 virtual void register_extractor(media_info_extractor extractor) override
47 boost::lock_guard<boost::mutex> lock(mutex_);
49 extractors_.push_back(extractor);
52 virtual boost::optional<media_info> get(const std::wstring& file) override
54 boost::lock_guard<boost::mutex> lock(mutex_);
56 auto iter = info_by_file_.find(file);
58 if (iter == info_by_file_.end())
61 auto extension = boost::to_upper_copy(boost::filesystem::path(file).extension().wstring());
64 BOOST_FOREACH(auto& extractor, extractors_)
66 success = extractor(file, extension, info);
72 boost::optional<media_info> result;
77 info_by_file_.insert(std::make_pair(file, result));
85 virtual void remove(const std::wstring& file) override
87 boost::lock_guard<boost::mutex> lock(mutex_);
89 info_by_file_.erase(file);
93 spl::shared_ptr<struct media_info_repository> create_in_memory_media_info_repository()
95 return spl::make_shared<in_memory_media_info_repository>();