1*09537850SAkhilesh Sanikop // Copyright 2019 The libgav1 Authors 2*09537850SAkhilesh Sanikop // 3*09537850SAkhilesh Sanikop // Licensed under the Apache License, Version 2.0 (the "License"); 4*09537850SAkhilesh Sanikop // you may not use this file except in compliance with the License. 5*09537850SAkhilesh Sanikop // You may obtain a copy of the License at 6*09537850SAkhilesh Sanikop // 7*09537850SAkhilesh Sanikop // http://www.apache.org/licenses/LICENSE-2.0 8*09537850SAkhilesh Sanikop // 9*09537850SAkhilesh Sanikop // Unless required by applicable law or agreed to in writing, software 10*09537850SAkhilesh Sanikop // distributed under the License is distributed on an "AS IS" BASIS, 11*09537850SAkhilesh Sanikop // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*09537850SAkhilesh Sanikop // See the License for the specific language governing permissions and 13*09537850SAkhilesh Sanikop // limitations under the License. 14*09537850SAkhilesh Sanikop 15*09537850SAkhilesh Sanikop #include "examples/file_reader_factory.h" 16*09537850SAkhilesh Sanikop 17*09537850SAkhilesh Sanikop #include <new> 18*09537850SAkhilesh Sanikop 19*09537850SAkhilesh Sanikop #include "examples/logging.h" 20*09537850SAkhilesh Sanikop 21*09537850SAkhilesh Sanikop namespace libgav1 { 22*09537850SAkhilesh Sanikop namespace { 23*09537850SAkhilesh Sanikop GetFileReaderOpenFunctions()24*09537850SAkhilesh Sanikopstd::vector<FileReaderFactory::OpenFunction>* GetFileReaderOpenFunctions() { 25*09537850SAkhilesh Sanikop static auto* open_functions = 26*09537850SAkhilesh Sanikop new (std::nothrow) std::vector<FileReaderFactory::OpenFunction>(); 27*09537850SAkhilesh Sanikop return open_functions; 28*09537850SAkhilesh Sanikop } 29*09537850SAkhilesh Sanikop 30*09537850SAkhilesh Sanikop } // namespace 31*09537850SAkhilesh Sanikop RegisterReader(OpenFunction open_function)32*09537850SAkhilesh Sanikopbool FileReaderFactory::RegisterReader(OpenFunction open_function) { 33*09537850SAkhilesh Sanikop if (open_function == nullptr) return false; 34*09537850SAkhilesh Sanikop auto* open_functions = GetFileReaderOpenFunctions(); 35*09537850SAkhilesh Sanikop const size_t num_readers = open_functions->size(); 36*09537850SAkhilesh Sanikop open_functions->push_back(open_function); 37*09537850SAkhilesh Sanikop return open_functions->size() == num_readers + 1; 38*09537850SAkhilesh Sanikop } 39*09537850SAkhilesh Sanikop OpenReader(const std::string & file_name,const bool error_tolerant)40*09537850SAkhilesh Sanikopstd::unique_ptr<FileReaderInterface> FileReaderFactory::OpenReader( 41*09537850SAkhilesh Sanikop const std::string& file_name, const bool error_tolerant /*= false*/) { 42*09537850SAkhilesh Sanikop for (auto* open_function : *GetFileReaderOpenFunctions()) { 43*09537850SAkhilesh Sanikop auto reader = open_function(file_name, error_tolerant); 44*09537850SAkhilesh Sanikop if (reader == nullptr) continue; 45*09537850SAkhilesh Sanikop return reader; 46*09537850SAkhilesh Sanikop } 47*09537850SAkhilesh Sanikop LIBGAV1_EXAMPLES_LOG_ERROR("No file reader able to open input"); 48*09537850SAkhilesh Sanikop return nullptr; 49*09537850SAkhilesh Sanikop } 50*09537850SAkhilesh Sanikop 51*09537850SAkhilesh Sanikop } // namespace libgav1 52