1 /* 2 * Copyright 2019 The libgav1 Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef LIBGAV1_EXAMPLES_FILE_READER_FACTORY_H_ 18 #define LIBGAV1_EXAMPLES_FILE_READER_FACTORY_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include "examples/file_reader_interface.h" 24 25 namespace libgav1 { 26 27 class FileReaderFactory { 28 public: 29 using OpenFunction = std::unique_ptr<FileReaderInterface> (*)( 30 const std::string& file_name, bool error_tolerant); 31 32 FileReaderFactory() = delete; 33 FileReaderFactory(const FileReaderFactory&) = delete; 34 FileReaderFactory& operator=(const FileReaderFactory&) = delete; 35 ~FileReaderFactory() = default; 36 37 // Registers the OpenFunction for a FileReaderInterface and returns true when 38 // registration succeeds. 39 static bool RegisterReader(OpenFunction open_function); 40 41 // Passes |file_name| to each OpenFunction until one succeeds. Returns nullptr 42 // when no reader is found for |file_name|. Otherwise a FileReaderInterface is 43 // returned. If |error_tolerant| is true and the reader supports it, some 44 // format and read errors may be ignored and partial data returned. 45 static std::unique_ptr<FileReaderInterface> OpenReader( 46 const std::string& file_name, bool error_tolerant = false); 47 }; 48 49 } // namespace libgav1 50 51 #endif // LIBGAV1_EXAMPLES_FILE_READER_FACTORY_H_ 52