From facf4f4c7a8ed65d59baed9020d5fa061b952874 Mon Sep 17 00:00:00 2001 From: milla Date: Wed, 26 May 2021 13:32:55 +0200 Subject: FileReader pluggable at runtime --- src/AS_DCP_MXF.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/AS_DCP_MXF.cpp') diff --git a/src/AS_DCP_MXF.cpp b/src/AS_DCP_MXF.cpp index 9cb4c15..e63faa5 100755 --- a/src/AS_DCP_MXF.cpp +++ b/src/AS_DCP_MXF.cpp @@ -163,19 +163,19 @@ ASDCP::MD_to_CryptoInfo(CryptographicContext* InfoObj, WriterInfo& Info, const D // // ASDCP::Result_t -ASDCP::EssenceType(const std::string& filename, EssenceType_t& type) +ASDCP::EssenceType(const std::string& filename, EssenceType_t& type, const Kumu::IFileReaderFactory& fileReaderFactory) { const Dictionary* m_Dict = &DefaultCompositeDict(); InterchangeObject* md_object = 0; assert(m_Dict); - Kumu::FileReader Reader; + Kumu::IFileReader* Reader = fileReaderFactory.CreateFileReader(); OP1aHeader TestHeader(m_Dict); - Result_t result = Reader.OpenRead(filename); + Result_t result = Reader->OpenRead(filename); if ( ASDCP_SUCCESS(result) ) - result = TestHeader.InitFromFile(Reader); // test UL and OP + result = TestHeader.InitFromFile(*Reader); // test UL and OP if ( ASDCP_SUCCESS(result) ) { @@ -285,10 +285,11 @@ ASDCP::EssenceType(const std::string& filename, EssenceType_t& type) else { DefaultLogSink().Error("Unsupported MXF Operational Pattern.\n"); - return RESULT_FORMAT; + result = RESULT_FORMAT; } } + delete Reader; return result; } -- cgit v1.2.3 From 767bab5bb08fc4d43c8ca3fa24fa7713597cb9ca Mon Sep 17 00:00:00 2001 From: milla Date: Thu, 10 Jun 2021 14:10:31 +0200 Subject: Fix indentation Don't delete pointer manually, use smart pointer instead --- src/AS_DCP_MXF.cpp | 6 +++--- src/as-02-unwrap.cpp | 10 +++++----- src/asdcp-test.cpp | 14 +++++++------- src/klvwalk.cpp | 6 +++--- 4 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/AS_DCP_MXF.cpp') diff --git a/src/AS_DCP_MXF.cpp b/src/AS_DCP_MXF.cpp index e63faa5..9f6ca3f 100755 --- a/src/AS_DCP_MXF.cpp +++ b/src/AS_DCP_MXF.cpp @@ -169,7 +169,7 @@ ASDCP::EssenceType(const std::string& filename, EssenceType_t& type, const Kumu: InterchangeObject* md_object = 0; assert(m_Dict); - Kumu::IFileReader* Reader = fileReaderFactory.CreateFileReader(); + ASDCP::mem_ptr Reader(fileReaderFactory.CreateFileReader()); OP1aHeader TestHeader(m_Dict); Result_t result = Reader->OpenRead(filename); @@ -285,11 +285,11 @@ ASDCP::EssenceType(const std::string& filename, EssenceType_t& type, const Kumu: else { DefaultLogSink().Error("Unsupported MXF Operational Pattern.\n"); - result = RESULT_FORMAT; + return RESULT_FORMAT; } } - delete Reader; + return result; } diff --git a/src/as-02-unwrap.cpp b/src/as-02-unwrap.cpp index 5cc0cae..614a624 100755 --- a/src/as-02-unwrap.cpp +++ b/src/as-02-unwrap.cpp @@ -1131,24 +1131,24 @@ main(int argc, const char** argv) switch ( EssenceType ) { case ESS_AS02_JPEG_2000: - result = read_JP2K_file(Options, defaultFactory); + result = read_JP2K_file(Options, defaultFactory); break; //PB case ESS_AS02_ACES: - result = read_ACES_file(Options, defaultFactory); + result = read_ACES_file(Options, defaultFactory); break; //-- case ESS_AS02_PCM_24b_48k: case ESS_AS02_PCM_24b_96k: - result = read_PCM_file(Options, defaultFactory); + result = read_PCM_file(Options, defaultFactory); break; case ESS_AS02_TIMED_TEXT: - result = read_timed_text_file(Options, defaultFactory); + result = read_timed_text_file(Options, defaultFactory); break; case ESS_AS02_IAB: - result = read_iab_file(Options, defaultFactory); + result = read_iab_file(Options, defaultFactory); break; case ESS_AS02_ISXD: diff --git a/src/asdcp-test.cpp b/src/asdcp-test.cpp index 853c10a..838d259 100755 --- a/src/asdcp-test.cpp +++ b/src/asdcp-test.cpp @@ -2018,30 +2018,30 @@ main(int argc, const char** argv) switch ( EssenceType ) { case ESS_MPEG2_VES: - result = read_MPEG2_file(Options, defaultFactory); + result = read_MPEG2_file(Options, defaultFactory); break; case ESS_JPEG_2000: if ( Options.stereo_image_flag ) - result = read_JP2K_S_file(Options, defaultFactory); + result = read_JP2K_S_file(Options, defaultFactory); else - result = read_JP2K_file(Options, defaultFactory); + result = read_JP2K_file(Options, defaultFactory); break; case ESS_JPEG_2000_S: - result = read_JP2K_S_file(Options, defaultFactory); + result = read_JP2K_S_file(Options, defaultFactory); break; case ESS_PCM_24b_48k: case ESS_PCM_24b_96k: - result = read_PCM_file(Options, defaultFactory); + result = read_PCM_file(Options, defaultFactory); break; case ESS_TIMED_TEXT: - result = read_timed_text_file(Options, defaultFactory); + result = read_timed_text_file(Options, defaultFactory); break; - default: + default: fprintf(stderr, "%s: Unknown file type, not ASDCP essence.\n", Options.filenames[0]); return 5; } diff --git a/src/klvwalk.cpp b/src/klvwalk.cpp index 4f4af21..4e5194b 100755 --- a/src/klvwalk.cpp +++ b/src/klvwalk.cpp @@ -207,16 +207,16 @@ main(int argc, const char** argv) if ( ASDCP_SUCCESS(result) ) { - result = MXF::SeekToRIP(*Reader); + result = MXF::SeekToRIP(*Reader); if ( ASDCP_SUCCESS(result) ) { - result = RIP.InitFromFile(*Reader); + result = RIP.InitFromFile(*Reader); ui32_t test_s = RIP.PairArray.size(); if ( ASDCP_FAILURE(result) ) { - DefaultLogSink().Error("File contains no RIP\n"); + DefaultLogSink().Error("File contains no RIP\n"); result = RESULT_OK; } else if ( RIP.PairArray.empty() ) -- cgit v1.2.3 From 8df78decb4e01b579bbbd1f479d187adf34fc030 Mon Sep 17 00:00:00 2001 From: milla Date: Tue, 15 Jun 2021 13:12:01 +0200 Subject: Fix indentation Use smart pointer for Reader Don't define fileReader constructor and destructor twice (win and posix) but just once as their implementation is the same --- src/AS_DCP_MXF.cpp | 3 +-- src/KM_fileio.cpp | 33 ++++++++++----------------------- src/KM_fileio.h | 39 ++++++++++++++++++++------------------- src/as-02-info.cpp | 3 +-- src/asdcp-test.cpp | 3 +-- src/klvwalk.cpp | 4 +--- 6 files changed, 34 insertions(+), 51 deletions(-) (limited to 'src/AS_DCP_MXF.cpp') diff --git a/src/AS_DCP_MXF.cpp b/src/AS_DCP_MXF.cpp index 9f6ca3f..5e51613 100755 --- a/src/AS_DCP_MXF.cpp +++ b/src/AS_DCP_MXF.cpp @@ -285,11 +285,10 @@ ASDCP::EssenceType(const std::string& filename, EssenceType_t& type, const Kumu: else { DefaultLogSink().Error("Unsupported MXF Operational Pattern.\n"); - return RESULT_FORMAT; + return RESULT_FORMAT; } } - return result; } diff --git a/src/KM_fileio.cpp b/src/KM_fileio.cpp index c753012..03c3214 100644 --- a/src/KM_fileio.cpp +++ b/src/KM_fileio.cpp @@ -762,6 +762,16 @@ Kumu::FileWriter::Writev(const byte_t* buf, ui32_t buf_len) return RESULT_OK; } +Kumu::FileReader::FileReader() +{ + m_Handle = INVALID_HANDLE_VALUE; + assert(sizeof(off_t) <= sizeof(int64_t)); +} + +Kumu::FileReader::~FileReader() +{ + Kumu::FileReader::Close(); +} #ifdef KM_WIN32 #ifdef KM_WIN32_UTF8 @@ -816,18 +826,6 @@ Kumu::utf8_to_wbstr(const std::string& in, Kumu::ByteString& out) //------------------------------------------------------------------------------------------ // -Kumu::FileReader::FileReader() -{ - m_Handle = INVALID_HANDLE_VALUE; - assert(sizeof(off_t) <= sizeof(int64_t)); -} - -Kumu::FileReader::~FileReader() -{ - Kumu::FileReader::Close(); -} - -Kumu::Result_t Kumu::FileReader::OpenRead(const std::string& filename) const { const_cast(this)->m_Filename = filename; @@ -1077,17 +1075,6 @@ Kumu::FileWriter::Write(const byte_t* buf, ui32_t buf_len, ui32_t* bytes_written // POSIX // -Kumu::FileReader::FileReader() -{ - m_Handle = INVALID_HANDLE_VALUE; - assert(sizeof(off_t) <= sizeof(int64_t)); -} - -// -Kumu::FileReader::~FileReader() -{ - Kumu::FileReader::Close(); -} Kumu::Result_t Kumu::FileReader::OpenRead(const std::string& filename) const diff --git a/src/KM_fileio.h b/src/KM_fileio.h index f7713fc..1ef5e75 100755 --- a/src/KM_fileio.h +++ b/src/KM_fileio.h @@ -67,7 +67,7 @@ namespace Kumu }; - // + // enum DirectoryEntryType_t { DET_FILE, DET_DIR, @@ -84,7 +84,7 @@ namespace Kumu KM_NO_COPY_CONSTRUCT(DirScannerEx); public: - + DirScannerEx(); ~DirScannerEx() { Close(); } @@ -133,7 +133,7 @@ namespace Kumu // // error: 'void Kumu::compile_time_size_checker() [with bool sizecheck = false]' previously declared here // - // This is happening because the equality being tested below is false. The reason for this + // This is happening because the equality being tested below is false. The reason for this // will depend on your OS, but on Linux it is probably because you have not used -D_FILE_OFFSET_BITS=64 // Adding this magic macro to your CFLAGS will get you going again. If you are on a system that // does not support 64-bit files, you can disable this check by using -DKM_SMALL_FILES_OK. You @@ -190,7 +190,7 @@ namespace Kumu std::string PathJoin(const std::string& Path1, const std::string& Path2, char separator = '/'); std::string PathJoin(const std::string& Path1, const std::string& Path2, const std::string& Path3, char separator = '/'); std::string PathJoin(const std::string& Path1, const std::string& Path2, - const std::string& Path3, const std::string& Path4, char separator = '/'); + const std::string& Path3, const std::string& Path4, char separator = '/'); //------------------------------------------------------------------------------------------ @@ -247,10 +247,10 @@ namespace Kumu // Search all paths in SearchPaths for filenames matching Pattern (no directories are returned). // Put results in FoundPaths. Returns after first find if one_shot is true. PathList_t& FindInPath(const IPathMatch& Pattern, const std::string& SearchDir, - PathList_t& FoundPaths, bool one_shot = false, char separator = '/'); + PathList_t& FoundPaths, bool one_shot = false, char separator = '/'); PathList_t& FindInPaths(const IPathMatch& Pattern, const PathList_t& SearchPaths, - PathList_t& FoundPaths, bool one_shot = false, char separator = '/'); + PathList_t& FoundPaths, bool one_shot = false, char separator = '/'); std::string GetExecutablePath(const std::string& default_path); @@ -294,7 +294,7 @@ namespace Kumu // // Unarchives a file into a buffer Result_t ReadFileIntoBuffer(const std::string& Filename, Kumu::ByteString& Buffer, - ui32_t max_size = 8 * Kumu::Megabyte); + ui32_t max_size = 8 * Kumu::Megabyte); // Archives a buffer into a file Result_t WriteBufferIntoFile(const Kumu::ByteString& Buffer, const std::string& Filename); @@ -315,7 +315,7 @@ namespace Kumu //------------------------------------------------------------------------------------------ // class IFileReader - { + { public: virtual ~IFileReader(){} @@ -328,17 +328,17 @@ namespace Kumu virtual bool IsOpen() const = 0; // returns true if the file is open inline int64_t TellPosition() const // report the file pointer's location - { - int64_t tmp_pos; - Tell(&tmp_pos); - return tmp_pos; - } - }; + { + int64_t tmp_pos; + Tell(&tmp_pos); + return tmp_pos; + } + }; // class FileReader : public IFileReader - { - KM_NO_COPY_CONSTRUCT(FileReader); + { + KM_NO_COPY_CONSTRUCT(FileReader); public: FileReader(); @@ -350,14 +350,15 @@ namespace Kumu virtual Result_t Tell(Kumu::fpos_t* pos) const; // report the file pointer's location virtual Result_t Read(byte_t*, ui32_t, ui32_t* = 0) const; // read a buffer of data - inline virtual bool IsOpen() const { // returns true if the file is open - return (m_Handle != INVALID_HANDLE_VALUE); + inline virtual bool IsOpen() const // returns true if the file is open + { + return (m_Handle != INVALID_HANDLE_VALUE); } protected: std::string m_Filename; FileHandle m_Handle; - }; + }; // class IFileReaderFactory diff --git a/src/as-02-info.cpp b/src/as-02-info.cpp index d1b823c..79fe41b 100644 --- a/src/as-02-info.cpp +++ b/src/as-02-info.cpp @@ -930,7 +930,7 @@ show_file_info(CommandOptions& Options, const Kumu::IFileReaderFactory& fileRead else { fprintf(stderr, "Unknown/unsupported essence type: %s\n", Options.filenames.front().c_str()); - Kumu::IFileReader* Reader = fileReaderFactory.CreateFileReader(); + ASDCP::mem_ptr Reader(fileReaderFactory.CreateFileReader()); const Dictionary* Dict = &DefaultCompositeDict(); MXF::OP1aHeader TestHeader(Dict); @@ -957,7 +957,6 @@ show_file_info(CommandOptions& Options, const Kumu::IFileReaderFactory& fileRead { fputs("File is not MXF.\n", stdout); } - delete Reader; } return result; } diff --git a/src/asdcp-test.cpp b/src/asdcp-test.cpp index 838d259..3b25d88 100755 --- a/src/asdcp-test.cpp +++ b/src/asdcp-test.cpp @@ -1870,7 +1870,7 @@ show_file_info(CommandOptions& Options, const Kumu::IFileReaderFactory& fileRead else { fprintf(stderr, "File is not AS-DCP: %s\n", Options.filenames[0]); - Kumu::IFileReader* Reader = fileReaderFactory.CreateFileReader(); + ASDCP::mem_ptr Reader(fileReaderFactory.CreateFileReader()); const Dictionary* Dict = &DefaultCompositeDict(); MXF::OP1aHeader TestHeader(Dict); @@ -1897,7 +1897,6 @@ show_file_info(CommandOptions& Options, const Kumu::IFileReaderFactory& fileRead { fputs("File is not MXF.\n", stdout); } - delete Reader; } return result; diff --git a/src/klvwalk.cpp b/src/klvwalk.cpp index 4e5194b..1ba9908 100755 --- a/src/klvwalk.cpp +++ b/src/klvwalk.cpp @@ -192,8 +192,7 @@ main(int argc, const char** argv) for ( fi = Options.inFileList.begin(); ASDCP_SUCCESS(result) && fi != Options.inFileList.end(); fi++ ) { - Kumu::IFileReader* Reader = defaultFactory.CreateFileReader(); - + ASDCP::mem_ptr Reader(defaultFactory.CreateFileReader()); if (Options.verbose_flag) fprintf(stderr, "Opening file %s\n", ((*fi).c_str())); @@ -350,7 +349,6 @@ main(int argc, const char** argv) if( result == RESULT_ENDOFFILE ) result = RESULT_OK; } - delete Reader; } if ( ASDCP_FAILURE(result) ) -- cgit v1.2.3