diff --git a/packager/app/packager_main.cc b/packager/app/packager_main.cc index 330f6978eb..65466ac144 100644 --- a/packager/app/packager_main.cc +++ b/packager/app/packager_main.cc @@ -23,7 +23,7 @@ #include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/string_split.h" #include "packager/base/strings/stringprintf.h" -#include "packager/media/file/file.h" +#include "packager/file/file.h" #include "packager/packager.h" #if defined(OS_WIN) @@ -108,8 +108,8 @@ bool GetWidevineSigner(WidevineSigner* signer) { signer->aes.iv = FLAGS_aes_signing_iv_bytes; } else if (!FLAGS_rsa_signing_key_path.empty()) { signer->signing_key_type = WidevineSigner::SigningKeyType::kRsa; - if (!media::File::ReadFileToString(FLAGS_rsa_signing_key_path.c_str(), - &signer->rsa.key)) { + if (!File::ReadFileToString(FLAGS_rsa_signing_key_path.c_str(), + &signer->rsa.key)) { LOG(ERROR) << "Failed to read from '" << FLAGS_rsa_signing_key_path << "'."; return false; diff --git a/packager/app/packager_util.cc b/packager/app/packager_util.cc index d09c13607a..84adb2e6f4 100644 --- a/packager/app/packager_util.cc +++ b/packager/app/packager_util.cc @@ -9,6 +9,7 @@ #include "packager/base/logging.h" #include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/string_split.h" +#include "packager/file/file.h" #include "packager/media/base/fixed_key_source.h" #include "packager/media/base/media_handler.h" #include "packager/media/base/muxer_options.h" @@ -17,7 +18,6 @@ #include "packager/media/base/widevine_key_source.h" #include "packager/media/chunking/chunking_handler.h" #include "packager/media/crypto/encryption_handler.h" -#include "packager/media/file/file.h" #include "packager/mpd/base/mpd_options.h" #include "packager/packager.h" #include "packager/status.h" diff --git a/packager/media/file/file.cc b/packager/file/file.cc similarity index 91% rename from packager/media/file/file.cc rename to packager/file/file.cc index d81adece93..35273a4163 100644 --- a/packager/media/file/file.cc +++ b/packager/file/file.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "packager/media/file/file.h" +#include "packager/file/file.h" #include #include @@ -12,10 +12,10 @@ #include "packager/base/files/important_file_writer.h" #include "packager/base/logging.h" #include "packager/base/strings/string_piece.h" -#include "packager/media/file/local_file.h" -#include "packager/media/file/memory_file.h" -#include "packager/media/file/threaded_io_file.h" -#include "packager/media/file/udp_file.h" +#include "packager/file/local_file.h" +#include "packager/file/memory_file.h" +#include "packager/file/threaded_io_file.h" +#include "packager/file/udp_file.h" DEFINE_uint64(io_cache_size, 32ULL << 20, @@ -31,7 +31,6 @@ DEFINE_uint64(io_block_size, #endif // CopyFile namespace shaka { -namespace media { const char* kLocalFilePrefix = "file://"; const char* kUdpFilePrefix = "udp://"; @@ -84,27 +83,16 @@ bool DeleteMemoryFile(const char* file_name) { } static const FileTypeInfo kFileTypeInfo[] = { - { - kLocalFilePrefix, - strlen(kLocalFilePrefix), - &CreateLocalFile, - &DeleteLocalFile, - &WriteLocalFileAtomically, - }, - { - kUdpFilePrefix, - strlen(kUdpFilePrefix), - &CreateUdpFile, - nullptr, - nullptr - }, - { - kMemoryFilePrefix, - strlen(kMemoryFilePrefix), - &CreateMemoryFile, - &DeleteMemoryFile, - nullptr - }, + { + kLocalFilePrefix, + strlen(kLocalFilePrefix), + &CreateLocalFile, + &DeleteLocalFile, + &WriteLocalFileAtomically, + }, + {kUdpFilePrefix, strlen(kUdpFilePrefix), &CreateUdpFile, nullptr, nullptr}, + {kMemoryFilePrefix, strlen(kMemoryFilePrefix), &CreateMemoryFile, + &DeleteMemoryFile, nullptr}, }; const FileTypeInfo* GetFileTypeInfo(base::StringPiece file_name, @@ -214,7 +202,8 @@ bool File::ReadFileToString(const char* file_name, std::string* contents) { return len == 0; } -bool File::WriteFileAtomically(const char* file_name, const std::string& contents) { +bool File::WriteFileAtomically(const char* file_name, + const std::string& contents) { base::StringPiece real_file_name; const FileTypeInfo* file_type = GetFileTypeInfo(file_name, &real_file_name); DCHECK(file_type); @@ -230,7 +219,7 @@ bool File::WriteFileAtomically(const char* file_name, const std::string& content << " is not guaranteed to be atomic."; } - std::unique_ptr file(media::File::Open(file_name, "w")); + std::unique_ptr file(File::Open(file_name, "w")); if (!file) { LOG(ERROR) << "Failed to open file " << file_name; return false; @@ -317,5 +306,4 @@ int64_t File::CopyFile(File* source, File* destination, int64_t max_copy) { return bytes_copied; } -} // namespace media } // namespace shaka diff --git a/packager/media/file/file.gyp b/packager/file/file.gyp similarity index 78% rename from packager/media/file/file.gyp rename to packager/file/file.gyp index 355afe87bc..f1a20dec49 100644 --- a/packager/media/file/file.gyp +++ b/packager/file/file.gyp @@ -6,7 +6,7 @@ { 'includes': [ - '../../common.gypi', + '../common.gypi', ], 'targets': [ { @@ -32,9 +32,8 @@ 'udp_options.h', ], 'dependencies': [ - '../../base/base.gyp:base', - '../../third_party/gflags/gflags.gyp:gflags', - '../base/media_base.gyp:media_base', + '../base/base.gyp:base', + '../third_party/gflags/gflags.gyp:gflags', ], }, { @@ -48,9 +47,9 @@ 'udp_options_unittest.cc', ], 'dependencies': [ - '../../testing/gtest.gyp:gtest', - '../../third_party/gflags/gflags.gyp:gflags', - '../test/media_test.gyp:run_tests_with_atexit_manager', + '../media/test/media_test.gyp:run_tests_with_atexit_manager', + '../testing/gtest.gyp:gtest', + '../third_party/gflags/gflags.gyp:gflags', 'file', ], }, diff --git a/packager/media/file/file.h b/packager/file/file.h similarity index 99% rename from packager/media/file/file.h rename to packager/file/file.h index 67030157c4..28c5687850 100644 --- a/packager/media/file/file.h +++ b/packager/file/file.h @@ -14,7 +14,6 @@ #include "packager/base/macros.h" namespace shaka { -namespace media { extern const char* kLocalFilePrefix; extern const char* kMemoryFilePrefix; @@ -154,7 +153,6 @@ class File { DISALLOW_COPY_AND_ASSIGN(File); }; -} // namespace media } // namespace shaka #endif // PACKAGER_FILE_FILE_H_ diff --git a/packager/media/file/file_closer.h b/packager/file/file_closer.h similarity index 79% rename from packager/media/file/file_closer.h rename to packager/file/file_closer.h index 8b8531d781..72ed33af50 100644 --- a/packager/media/file/file_closer.h +++ b/packager/file/file_closer.h @@ -8,10 +8,9 @@ #define MEDIA_FILE_FILE_CLOSER_H_ #include "packager/base/logging.h" -#include "packager/media/file/file.h" +#include "packager/file/file.h" namespace shaka { -namespace media { /// Used by std::unique_ptr to automatically close the file when it goes out of /// scope. @@ -20,14 +19,12 @@ struct FileCloser { if (file != NULL) { const std::string filename = file->file_name(); if (!file->Close()) { - LOG(WARNING) << "Failed to close the file properly: " - << filename; + LOG(WARNING) << "Failed to close the file properly: " << filename; } } } }; -} // namespace media } // namespace shaka #endif // MEDIA_FILE_FILE_CLOSER_H_ diff --git a/packager/media/file/file_test_util.h b/packager/file/file_test_util.h similarity index 79% rename from packager/media/file/file_test_util.h rename to packager/file/file_test_util.h index 748646b144..5ab4fc9f98 100644 --- a/packager/media/file/file_test_util.h +++ b/packager/file/file_test_util.h @@ -12,36 +12,34 @@ #include -#include "packager/media/file/file.h" +#include "packager/file/file.h" namespace shaka { -namespace media { -#define ASSERT_FILE_EQ(file_name, array) \ - do { \ - std::string temp_data; \ - ASSERT_TRUE(media::File::ReadFileToString((file_name), &temp_data)); \ - const char* array_ptr = reinterpret_cast(array); \ - ASSERT_EQ(std::string(array_ptr, arraysize(array)), temp_data); \ +#define ASSERT_FILE_EQ(file_name, array) \ + do { \ + std::string temp_data; \ + ASSERT_TRUE(File::ReadFileToString((file_name), &temp_data)); \ + const char* array_ptr = reinterpret_cast(array); \ + ASSERT_EQ(std::string(array_ptr, arraysize(array)), temp_data); \ } while (false) -#define ASSERT_FILE_STREQ(file_name, str) \ - do { \ - std::string temp_data; \ - ASSERT_TRUE(media::File::ReadFileToString((file_name), &temp_data)); \ - ASSERT_EQ(str, temp_data); \ +#define ASSERT_FILE_STREQ(file_name, str) \ + do { \ + std::string temp_data; \ + ASSERT_TRUE(File::ReadFileToString((file_name), &temp_data)); \ + ASSERT_EQ(str, temp_data); \ } while (false) #define ASSERT_FILE_ENDS_WITH(file_name, array) \ do { \ std::string temp_data; \ - ASSERT_TRUE(media::File::ReadFileToString((file_name), &temp_data)); \ + ASSERT_TRUE(File::ReadFileToString((file_name), &temp_data)); \ EXPECT_THAT(temp_data, \ ::testing::EndsWith(std::string( \ reinterpret_cast(array), sizeof(array)))); \ } while (false) -} // namespace media } // namespace shaka #endif // MEDIA_FILE_FILE_TEST_UTIL_H_ diff --git a/packager/media/file/file_unittest.cc b/packager/file/file_unittest.cc similarity index 95% rename from packager/media/file/file_unittest.cc rename to packager/file/file_unittest.cc index 24d7a5fe21..460dd443fb 100644 --- a/packager/media/file/file_unittest.cc +++ b/packager/file/file_unittest.cc @@ -8,7 +8,7 @@ #include #include "packager/base/files/file_util.h" -#include "packager/media/file/file.h" +#include "packager/file/file.h" DECLARE_uint64(io_cache_size); DECLARE_uint64(io_block_size); @@ -18,7 +18,6 @@ const int kDataSize = 1024; } namespace shaka { -namespace media { using base::FilePath; @@ -41,7 +40,7 @@ class LocalFileTest : public testing::Test { void TearDown() override { // Remove test file if created. base::DeleteFile(FilePath::FromUTF8Unsafe(local_file_name_no_prefix_), - false); + false); } std::string data_; @@ -57,8 +56,7 @@ class LocalFileTest : public testing::Test { TEST_F(LocalFileTest, ReadNotExist) { // Remove test file if it exists. - base::DeleteFile(FilePath::FromUTF8Unsafe(local_file_name_no_prefix_), - false); + base::DeleteFile(FilePath::FromUTF8Unsafe(local_file_name_no_prefix_), false); ASSERT_TRUE(File::Open(local_file_name_.c_str(), "r") == NULL); } @@ -73,21 +71,18 @@ TEST_F(LocalFileTest, Copy) { base::WriteFile(test_file_path_, data_.data(), kDataSize)); FilePath temp_dir; - ASSERT_TRUE(base::CreateNewTempDirectory(FilePath::StringType(), - &temp_dir)); + ASSERT_TRUE(base::CreateNewTempDirectory(FilePath::StringType(), &temp_dir)); // Copy the test file to temp dir as filename "a". - FilePath destination = - temp_dir.Append(FilePath::FromUTF8Unsafe("a")); - ASSERT_TRUE( - File::Copy(FilePath::FromUTF8Unsafe(local_file_name_).AsUTF8Unsafe().c_str(), - destination.AsUTF8Unsafe().c_str())); + FilePath destination = temp_dir.Append(FilePath::FromUTF8Unsafe("a")); + ASSERT_TRUE(File::Copy( + FilePath::FromUTF8Unsafe(local_file_name_).AsUTF8Unsafe().c_str(), + destination.AsUTF8Unsafe().c_str())); // Make a buffer bigger than the expected file content size to make sure that // there isn't extra stuff appended. char copied_file_content_buffer[kDataSize * 2] = {}; - ASSERT_EQ(kDataSize, base::ReadFile(destination, - copied_file_content_buffer, + ASSERT_EQ(kDataSize, base::ReadFile(destination, copied_file_content_buffer, arraysize(copied_file_content_buffer))); ASSERT_EQ(data_, std::string(copied_file_content_buffer, kDataSize)); @@ -192,8 +187,7 @@ TEST_F(LocalFileTest, WriteFlushCheckSize) { } class ParamLocalFileTest : public LocalFileTest, - public ::testing::WithParamInterface { -}; + public ::testing::WithParamInterface {}; TEST_P(ParamLocalFileTest, SeekWriteAndSeekRead) { const uint32_t kBlockSize(10); @@ -297,5 +291,4 @@ TEST_F(LocalFileTest, DISABLED_ReadSeekOutOfBounds) { EXPECT_TRUE(file->Close()); } -} // namespace media } // namespace shaka diff --git a/packager/media/file/file_util.cc b/packager/file/file_util.cc similarity index 96% rename from packager/media/file/file_util.cc rename to packager/file/file_util.cc index a4e54e3c47..7e1ecca715 100644 --- a/packager/media/file/file_util.cc +++ b/packager/file/file_util.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "packager/media/file/file_util.h" +#include "packager/file/file_util.h" #include diff --git a/packager/media/file/file_util.h b/packager/file/file_util.h similarity index 100% rename from packager/media/file/file_util.h rename to packager/file/file_util.h diff --git a/packager/media/file/file_util_unittest.cc b/packager/file/file_util_unittest.cc similarity index 93% rename from packager/media/file/file_util_unittest.cc rename to packager/file/file_util_unittest.cc index f43d10825e..188ac21cc5 100644 --- a/packager/media/file/file_util_unittest.cc +++ b/packager/file/file_util_unittest.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "packager/media/file/file_util.h" +#include "packager/file/file_util.h" #include diff --git a/packager/media/file/io_cache.cc b/packager/file/io_cache.cc similarity index 93% rename from packager/media/file/io_cache.cc rename to packager/file/io_cache.cc index 956de4f5b6..34b3b8382e 100644 --- a/packager/media/file/io_cache.cc +++ b/packager/file/io_cache.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "packager/media/file/io_cache.h" +#include "packager/file/io_cache.h" #include @@ -17,8 +17,6 @@ namespace shaka { using base::AutoLock; using base::AutoUnlock; -namespace media { - IoCache::IoCache(uint64_t cache_size) : cache_size_(cache_size), read_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, @@ -47,8 +45,8 @@ uint64_t IoCache::Read(void* buffer, uint64_t size) { } size = std::min(size, BytesCachedInternal()); - uint64_t first_chunk_size(std::min(size, static_cast( - end_ptr_ - r_ptr_))); + uint64_t first_chunk_size( + std::min(size, static_cast(end_ptr_ - r_ptr_))); memcpy(buffer, r_ptr_, first_chunk_size); r_ptr_ += first_chunk_size; DCHECK_GE(end_ptr_, r_ptr_); @@ -80,8 +78,8 @@ uint64_t IoCache::Write(const void* buffer, uint64_t size) { return 0; uint64_t write_size(std::min(bytes_left, BytesFreeInternal())); - uint64_t first_chunk_size(std::min(write_size, static_cast( - end_ptr_ - w_ptr_))); + uint64_t first_chunk_size( + std::min(write_size, static_cast(end_ptr_ - w_ptr_))); memcpy(w_ptr_, r_ptr, first_chunk_size); w_ptr_ += first_chunk_size; DCHECK_GE(end_ptr_, w_ptr_); @@ -152,5 +150,4 @@ void IoCache::WaitUntilEmptyOrClosed() { } } -} // namespace media } // namespace shaka diff --git a/packager/media/file/io_cache.h b/packager/file/io_cache.h similarity index 98% rename from packager/media/file/io_cache.h rename to packager/file/io_cache.h index c43bba47b3..d986a6f13a 100644 --- a/packager/media/file/io_cache.h +++ b/packager/file/io_cache.h @@ -14,7 +14,6 @@ #include "packager/base/synchronization/waitable_event.h" namespace shaka { -namespace media { /// Declaration of class which implements a thread-safe circular buffer. class IoCache { @@ -80,7 +79,6 @@ class IoCache { DISALLOW_COPY_AND_ASSIGN(IoCache); }; -} // namespace media } // namespace shaka #endif // PACKAGER_FILE_IO_CACHE_H diff --git a/packager/media/file/io_cache_unittest.cc b/packager/file/io_cache_unittest.cc similarity index 87% rename from packager/media/file/io_cache_unittest.cc rename to packager/file/io_cache_unittest.cc index 4fce29bd04..db1f7d9157 100644 --- a/packager/media/file/io_cache_unittest.cc +++ b/packager/file/io_cache_unittest.cc @@ -4,22 +4,36 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd +#include "packager/file/io_cache.h" #include #include #include #include "packager/base/bind.h" #include "packager/base/bind_helpers.h" -#include "packager/base/threading/platform_thread.h" -#include "packager/media/base/closure_thread.h" -#include "packager/media/file/io_cache.h" +#include "packager/base/threading/simple_thread.h" namespace { const uint64_t kBlockSize = 256; const uint64_t kCacheSize = 16 * kBlockSize; -} +} // namespace namespace shaka { -namespace media { + +class ClosureThread : public base::SimpleThread { + public: + ClosureThread(const std::string& name_prefix, const base::Closure& task) + : base::SimpleThread(name_prefix), task_(task) {} + + ~ClosureThread() { + if (HasBeenStarted() && !HasBeenJoined()) + Join(); + } + + void Run() { task_.Run(); } + + private: + const base::Closure task_; +}; class IoCacheTest : public testing::Test { public: @@ -53,9 +67,7 @@ class IoCacheTest : public testing::Test { cache_closed_ = false; } - void TearDown() override { - WaitForWriterThread(); - } + void TearDown() override { WaitForWriterThread(); } void GenerateTestBuffer(uint64_t size, std::vector* test_buffer) { test_buffer->resize(size); @@ -63,8 +75,8 @@ class IoCacheTest : public testing::Test { while (size) { uint64_t copy_size(std::min(size, kBlockSize)); memcpy(w_ptr, reference_block_, copy_size); - w_ptr += copy_size; - size -= copy_size; + w_ptr += copy_size; + size -= copy_size; } } @@ -72,18 +84,14 @@ class IoCacheTest : public testing::Test { uint64_t num_writes, int sleep_between_writes, bool close_when_done) { - writer_thread_.reset(new ClosureThread("WriterThread", - base::Bind( - &IoCacheTest::WriteToCache, - base::Unretained(this), - test_buffer, - num_writes, - sleep_between_writes, - close_when_done))); + writer_thread_.reset(new ClosureThread( + "WriterThread", + base::Bind(&IoCacheTest::WriteToCache, base::Unretained(this), + test_buffer, num_writes, sleep_between_writes, + close_when_done))); writer_thread_->Start(); } - void WaitForWriterThread() { if (writer_thread_) { writer_thread_->Join(); @@ -140,8 +148,7 @@ TEST_F(IoCacheTest, LotsOfUnalignedBlocks) { EXPECT_EQ(write_buffer1, read_buffer1); std::vector verify_buffer; for (uint64_t idx = 0; idx < kNumWrites; ++idx) - verify_buffer.insert(verify_buffer.end(), - write_buffer2.begin(), + verify_buffer.insert(verify_buffer.end(), write_buffer2.begin(), write_buffer2.end()); uint64_t verify_index(0); while (verify_index < verify_buffer.size()) { @@ -191,8 +198,7 @@ TEST_F(IoCacheTest, CloseByReader) { GenerateTestBuffer(kBlockSize, &write_buffer); WriteToCacheThreaded(write_buffer, kNumWrites, 0, false); while (cache_->BytesCached() < kCacheSize) { - base::PlatformThread::Sleep( - base::TimeDelta::FromMilliseconds(10)); + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); } cache_->Close(); WaitForWriterThread(); @@ -254,13 +260,11 @@ TEST_F(IoCacheTest, LargeRead) { WriteToCacheThreaded(write_buffer, kNumWrites, 0, false); std::vector verify_buffer; while (verify_buffer.size() < kCacheSize) { - verify_buffer.insert(verify_buffer.end(), - write_buffer.begin(), + verify_buffer.insert(verify_buffer.end(), write_buffer.begin(), write_buffer.end()); } while (cache_->BytesCached() < kCacheSize) { - base::PlatformThread::Sleep( - base::TimeDelta::FromMilliseconds(10)); + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); } std::vector read_buffer(kCacheSize); EXPECT_EQ(kCacheSize, cache_->Read(read_buffer.data(), kCacheSize)); @@ -268,5 +272,4 @@ TEST_F(IoCacheTest, LargeRead) { cache_->Close(); } -} // namespace media } // namespace shaka diff --git a/packager/media/file/local_file.cc b/packager/file/local_file.cc similarity index 88% rename from packager/media/file/local_file.cc rename to packager/file/local_file.cc index e1cf375416..236f996e61 100644 --- a/packager/media/file/local_file.cc +++ b/packager/file/local_file.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "packager/media/file/local_file.h" +#include "packager/file/local_file.h" #include #if defined(OS_WIN) @@ -14,15 +14,12 @@ #include "packager/base/logging.h" namespace shaka { -namespace media { // Always open files in binary mode. const char kAdditionalFileMode[] = "b"; LocalFile::LocalFile(const char* file_name, const char* mode) - : File(file_name), - file_mode_(mode), - internal_file_(NULL) { + : File(file_name), file_mode_(mode), internal_file_(NULL) { if (file_mode_.find(kAdditionalFileMode) == std::string::npos) file_mode_ += kAdditionalFileMode; } @@ -60,7 +57,7 @@ int64_t LocalFile::Size() { int64_t file_size; if (!base::GetFileSize(base::FilePath::FromUTF8Unsafe(file_name()), - &file_size)) { + &file_size)) { LOG(ERROR) << "Cannot get file size."; return -1; } @@ -74,8 +71,8 @@ bool LocalFile::Flush() { bool LocalFile::Seek(uint64_t position) { #if defined(OS_WIN) - return _fseeki64(internal_file_, static_cast<__int64>(position), - SEEK_SET) == 0; + return _fseeki64(internal_file_, static_cast<__int64>(position), SEEK_SET) == + 0; #else return fseeko(internal_file_, position, SEEK_SET) >= 0; #endif // !defined(OS_WIN) @@ -96,8 +93,8 @@ bool LocalFile::Tell(uint64_t* position) { LocalFile::~LocalFile() {} bool LocalFile::Open() { - internal_file_ = - base::OpenFile(base::FilePath::FromUTF8Unsafe(file_name()), file_mode_.c_str()); + internal_file_ = base::OpenFile(base::FilePath::FromUTF8Unsafe(file_name()), + file_mode_.c_str()); return (internal_file_ != NULL); } @@ -105,5 +102,4 @@ bool LocalFile::Delete(const char* file_name) { return base::DeleteFile(base::FilePath::FromUTF8Unsafe(file_name), false); } -} // namespace media } // namespace shaka diff --git a/packager/media/file/local_file.h b/packager/file/local_file.h similarity index 95% rename from packager/media/file/local_file.h rename to packager/file/local_file.h index 924c04f9a6..ecc3c0b62c 100644 --- a/packager/media/file/local_file.h +++ b/packager/file/local_file.h @@ -12,10 +12,9 @@ #include #include "packager/base/compiler_specific.h" -#include "packager/media/file/file.h" +#include "packager/file/file.h" namespace shaka { -namespace media { /// Implement LocalFile which deals with local storage. class LocalFile : public File { @@ -53,7 +52,6 @@ class LocalFile : public File { DISALLOW_COPY_AND_ASSIGN(LocalFile); }; -} // namespace media } // namespace shaka #endif // PACKAGER_FILE_LOCAL_FILE_H_ diff --git a/packager/media/file/memory_file.cc b/packager/file/memory_file.cc similarity index 97% rename from packager/media/file/memory_file.cc rename to packager/file/memory_file.cc index e970f7ca65..92471d2d50 100644 --- a/packager/media/file/memory_file.cc +++ b/packager/file/memory_file.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "packager/media/file/memory_file.h" +#include "packager/file/memory_file.h" #include // for memcpy @@ -15,7 +15,6 @@ #include "packager/base/logging.h" namespace shaka { -namespace media { namespace { // A helper filesystem object. This holds the data for the memory files. @@ -136,6 +135,4 @@ void MemoryFile::Delete(const std::string& file_name) { FileSystem::Instance()->Delete(file_name); } -} // namespace media } // namespace shaka - diff --git a/packager/media/file/memory_file.h b/packager/file/memory_file.h similarity index 95% rename from packager/media/file/memory_file.h rename to packager/file/memory_file.h index 01807db31c..02f80199da 100644 --- a/packager/media/file/memory_file.h +++ b/packager/file/memory_file.h @@ -12,10 +12,9 @@ #include #include -#include "packager/media/file/file.h" +#include "packager/file/file.h" namespace shaka { -namespace media { /// Implements a File that is stored in memory. This should be only used for /// testing, since this does not support larger files. @@ -54,8 +53,6 @@ class MemoryFile : public File { DISALLOW_COPY_AND_ASSIGN(MemoryFile); }; -} // namespace media } // namespace shaka #endif // MEDIA_FILE_MEDIA_FILE_H_ - diff --git a/packager/media/file/memory_file_unittest.cc b/packager/file/memory_file_unittest.cc similarity index 93% rename from packager/media/file/memory_file_unittest.cc rename to packager/file/memory_file_unittest.cc index a930b8c2d2..bb44a7b5eb 100644 --- a/packager/media/file/memory_file_unittest.cc +++ b/packager/file/memory_file_unittest.cc @@ -2,26 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "packager/file/memory_file.h" #include #include -#include "packager/media/file/file.h" -#include "packager/media/file/file_closer.h" -#include "packager/media/file/memory_file.h" +#include "packager/file/file.h" +#include "packager/file/file_closer.h" namespace shaka { -namespace media { namespace { const uint8_t kWriteBuffer[] = {1, 2, 3, 4, 5, 6, 7, 8}; const int64_t kWriteBufferSize = sizeof(kWriteBuffer); -} +} // namespace class MemoryFileTest : public testing::Test { protected: - void TearDown() override { - MemoryFile::DeleteAll(); - } + void TearDown() override { MemoryFile::DeleteAll(); } }; TEST_F(MemoryFileTest, ModifiesSameFile) { @@ -110,5 +107,4 @@ TEST_F(MemoryFileTest, WriteExistingFileDeletes) { EXPECT_EQ(0, file2->Size()); } -} // namespace media } // namespace shaka diff --git a/packager/media/file/threaded_io_file.cc b/packager/file/threaded_io_file.cc similarity index 90% rename from packager/media/file/threaded_io_file.cc rename to packager/file/threaded_io_file.cc index bfef991280..7f668c4916 100644 --- a/packager/media/file/threaded_io_file.cc +++ b/packager/file/threaded_io_file.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "packager/media/file/threaded_io_file.h" +#include "packager/file/threaded_io_file.h" #include "packager/base/bind.h" #include "packager/base/bind_helpers.h" @@ -12,7 +12,6 @@ #include "packager/base/threading/worker_pool.h" namespace shaka { -namespace media { using base::subtle::NoBarrier_Load; using base::subtle::NoBarrier_Store; @@ -49,9 +48,10 @@ bool ThreadedIoFile::Open() { position_ = 0; size_ = internal_file_->Size(); - base::WorkerPool::PostTask(FROM_HERE, base::Bind(&ThreadedIoFile::TaskHandler, - base::Unretained(this)), - true /* task_is_slow */); + base::WorkerPool::PostTask( + FROM_HERE, + base::Bind(&ThreadedIoFile::TaskHandler, base::Unretained(this)), + true /* task_is_slow */); return true; } @@ -79,7 +79,6 @@ int64_t ThreadedIoFile::Read(void* buffer, uint64_t length) { if (NoBarrier_Load(&internal_file_error_)) return NoBarrier_Load(&internal_file_error_); - uint64_t bytes_read = cache_.Read(buffer, length); position_ += bytes_read; @@ -120,8 +119,10 @@ bool ThreadedIoFile::Flush() { bool ThreadedIoFile::Seek(uint64_t position) { if (mode_ == kOutputMode) { // Writing. Just flush the cache and seek. - if (!Flush()) return false; - if (!internal_file_->Seek(position)) return false; + if (!Flush()) + return false; + if (!internal_file_->Seek(position)) + return false; } else { // Reading. Close cache, wait for thread task to exit, seek, and re-post // the task. @@ -140,7 +141,8 @@ bool ThreadedIoFile::Seek(uint64_t position) { FROM_HERE, base::Bind(&ThreadedIoFile::TaskHandler, base::Unretained(this)), true /* task_is_slow */); - if (!result) return false; + if (!result) + return false; } position_ = position; return true; @@ -166,8 +168,8 @@ void ThreadedIoFile::RunInInputMode() { DCHECK_EQ(kInputMode, mode_); while (true) { - int64_t read_result = internal_file_->Read(&io_buffer_[0], - io_buffer_.size()); + int64_t read_result = + internal_file_->Read(&io_buffer_[0], io_buffer_.size()); if (read_result <= 0) { NoBarrier_Store(&eof_, read_result == 0); NoBarrier_Store(&internal_file_error_, read_result); @@ -210,5 +212,4 @@ void ThreadedIoFile::RunInOutputMode() { } } -} // namespace media } // namespace shaka diff --git a/packager/media/file/threaded_io_file.h b/packager/file/threaded_io_file.h similarity index 89% rename from packager/media/file/threaded_io_file.h rename to packager/file/threaded_io_file.h index 5b57a1bc02..91eb2fb4e4 100644 --- a/packager/media/file/threaded_io_file.h +++ b/packager/file/threaded_io_file.h @@ -10,20 +10,16 @@ #include #include "packager/base/atomicops.h" #include "packager/base/synchronization/waitable_event.h" -#include "packager/media/file/file.h" -#include "packager/media/file/file_closer.h" -#include "packager/media/file/io_cache.h" +#include "packager/file/file.h" +#include "packager/file/file_closer.h" +#include "packager/file/io_cache.h" namespace shaka { -namespace media { /// Declaration of class which implements a thread-safe circular buffer. class ThreadedIoFile : public File { public: - enum Mode { - kInputMode, - kOutputMode - }; + enum Mode { kInputMode, kOutputMode }; ThreadedIoFile(std::unique_ptr internal_file, Mode mode, @@ -69,7 +65,6 @@ class ThreadedIoFile : public File { DISALLOW_COPY_AND_ASSIGN(ThreadedIoFile); }; -} // namespace media } // namespace shaka #endif // PACKAGER_FILE_THREADED_IO_FILE_H diff --git a/packager/media/file/udp_file.cc b/packager/file/udp_file.cc similarity index 88% rename from packager/media/file/udp_file.cc rename to packager/file/udp_file.cc index e0bb970efd..ef1aa16157 100644 --- a/packager/media/file/udp_file.cc +++ b/packager/file/udp_file.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "packager/media/file/udp_file.h" +#include "packager/file/udp_file.h" #if defined(OS_WIN) #include @@ -22,10 +22,9 @@ #include #include "packager/base/logging.h" -#include "packager/media/file/udp_options.h" +#include "packager/file/udp_options.h" namespace shaka { -namespace media { namespace { @@ -35,9 +34,8 @@ bool IsIpv4MulticastAddress(const struct in_addr& addr) { } // anonymous namespace -UdpFile::UdpFile(const char* file_name) : - File(file_name), - socket_(INVALID_SOCKET) {} +UdpFile::UdpFile(const char* file_name) + : File(file_name), socket_(INVALID_SOCKET) {} UdpFile::~UdpFile() {} @@ -60,8 +58,8 @@ int64_t UdpFile::Read(void* buffer, uint64_t length) { int64_t result; do { - result = recvfrom(socket_, reinterpret_cast(buffer), - length, 0, NULL, 0); + result = + recvfrom(socket_, reinterpret_cast(buffer), length, 0, NULL, 0); } while ((result == -1) && (errno == EINTR)); return result; @@ -103,7 +101,8 @@ class LibWinsockInitializer { } ~LibWinsockInitializer() { - if (error_ == 0) WSACleanup(); + if (error_ == 0) + WSACleanup(); } int error() const { return error_; } @@ -115,8 +114,7 @@ class LibWinsockInitializer { class ScopedSocket { public: - explicit ScopedSocket(SOCKET sock_fd) - : sock_fd_(sock_fd) {} + explicit ScopedSocket(SOCKET sock_fd) : sock_fd_(sock_fd) {} ~ScopedSocket() { if (sock_fd_ != INVALID_SOCKET) @@ -161,8 +159,7 @@ bool UdpFile::Open() { } struct in_addr local_in_addr = {0}; - if (inet_pton(AF_INET, options->address().c_str(), - &local_in_addr) != 1) { + if (inet_pton(AF_INET, options->address().c_str(), &local_in_addr) != 1) { LOG(ERROR) << "Malformed IPv4 address " << options->address(); return false; } @@ -181,7 +178,7 @@ bool UdpFile::Open() { if (options->reuse()) { const int optval = 1; if (setsockopt(new_socket.get(), SOL_SOCKET, SO_REUSEADDR, - reinterpret_cast(&optval), + reinterpret_cast(&optval), sizeof(optval)) < 0) { LOG(ERROR) << "Could not apply the SO_REUSEADDR property to the UDP socket"; @@ -214,7 +211,7 @@ bool UdpFile::Open() { } if (setsockopt(new_socket.get(), IPPROTO_IP, IP_ADD_MEMBERSHIP, - reinterpret_cast(&multicast_group), + reinterpret_cast(&multicast_group), sizeof(multicast_group)) < 0) { LOG(ERROR) << "Failed to join multicast group."; return false; @@ -237,5 +234,4 @@ bool UdpFile::Open() { return true; } -} // namespace media } // namespace shaka diff --git a/packager/media/file/udp_file.h b/packager/file/udp_file.h similarity index 94% rename from packager/media/file/udp_file.h rename to packager/file/udp_file.h index 6d08df9e11..f8b5875b2a 100644 --- a/packager/media/file/udp_file.h +++ b/packager/file/udp_file.h @@ -12,7 +12,7 @@ #include #include "packager/base/compiler_specific.h" -#include "packager/media/file/file.h" +#include "packager/file/file.h" #if defined(OS_WIN) #include @@ -21,7 +21,6 @@ typedef int SOCKET; #endif // defined(OS_WIN) namespace shaka { -namespace media { /// Implements UdpFile, which receives UDP unicast and multicast streams. class UdpFile : public File { @@ -52,7 +51,6 @@ class UdpFile : public File { DISALLOW_COPY_AND_ASSIGN(UdpFile); }; -} // namespace media } // namespace shaka #endif // MEDIA_FILE_UDP_FILE_H_ diff --git a/packager/media/file/udp_options.cc b/packager/file/udp_options.cc similarity index 97% rename from packager/media/file/udp_options.cc rename to packager/file/udp_options.cc index affd6be034..b378c629f4 100644 --- a/packager/media/file/udp_options.cc +++ b/packager/file/udp_options.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "packager/media/file/udp_options.h" +#include "packager/file/udp_options.h" #include @@ -17,7 +17,6 @@ DEFINE_string(udp_interface_address, " or multicast streams"); namespace shaka { -namespace media { namespace { @@ -101,7 +100,8 @@ std::unique_ptr UdpOptions::ParseFromString( break; case kTimeoutField: if (!base::StringToUint(pair.second, &options->timeout_us_)) { - LOG(ERROR) << "Invalid udp option for timeout field " << pair.second; + LOG(ERROR) << "Invalid udp option for timeout field " + << pair.second; return nullptr; } break; @@ -128,5 +128,4 @@ std::unique_ptr UdpOptions::ParseFromString( return options; } -} // namespace media } // namespace shaka diff --git a/packager/media/file/udp_options.h b/packager/file/udp_options.h similarity index 97% rename from packager/media/file/udp_options.h rename to packager/file/udp_options.h index 7927a4cf4e..eb016ac6b0 100644 --- a/packager/media/file/udp_options.h +++ b/packager/file/udp_options.h @@ -10,7 +10,6 @@ #include "packager/base/strings/string_piece.h" namespace shaka { -namespace media { /// Options parsed from UDP url string of the form: udp://ip:port[?options] class UdpOptions { @@ -42,5 +41,4 @@ class UdpOptions { unsigned timeout_us_ = 0; }; -} // namespace media } // namespace shaka diff --git a/packager/media/file/udp_options_unittest.cc b/packager/file/udp_options_unittest.cc similarity index 97% rename from packager/media/file/udp_options_unittest.cc rename to packager/file/udp_options_unittest.cc index f5e0017063..c422c51b62 100644 --- a/packager/media/file/udp_options_unittest.cc +++ b/packager/file/udp_options_unittest.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "packager/media/file/udp_options.h" +#include "packager/file/udp_options.h" #include #include @@ -12,7 +12,6 @@ DECLARE_string(udp_interface_address); namespace shaka { -namespace media { class UdpOptionsTest : public testing::Test { public: @@ -96,5 +95,4 @@ TEST_F(UdpOptionsTest, InvalidTimeout) { "224.1.2.30:88?source=10.11.12.13&timeout=1a9")); } -} // namespace media } // namespace shaka diff --git a/packager/hls/base/master_playlist.cc b/packager/hls/base/master_playlist.cc index fd7294d461..b0bf8cff1b 100644 --- a/packager/hls/base/master_playlist.cc +++ b/packager/hls/base/master_playlist.cc @@ -11,8 +11,8 @@ #include "packager/base/files/file_path.h" #include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/stringprintf.h" +#include "packager/file/file.h" #include "packager/hls/base/media_playlist.h" -#include "packager/media/file/file.h" #include "packager/version/version.h" namespace shaka { @@ -161,7 +161,7 @@ bool MasterPlaylist::WriteMasterPlaylist(const std::string& base_url, base::FilePath::FromUTF8Unsafe(output_dir) .Append(base::FilePath::FromUTF8Unsafe(file_name_)) .AsUTF8Unsafe(); - if (!media::File::WriteFileAtomically(file_path.c_str(), content)) { + if (!File::WriteFileAtomically(file_path.c_str(), content)) { LOG(ERROR) << "Failed to write master playlist to: " << file_path; return false; } diff --git a/packager/hls/base/master_playlist_unittest.cc b/packager/hls/base/master_playlist_unittest.cc index ece19acb4b..8e899243f2 100644 --- a/packager/hls/base/master_playlist_unittest.cc +++ b/packager/hls/base/master_playlist_unittest.cc @@ -8,10 +8,10 @@ #include #include "packager/base/files/file_path.h" +#include "packager/file/file.h" #include "packager/hls/base/master_playlist.h" #include "packager/hls/base/media_playlist.h" #include "packager/hls/base/mock_media_playlist.h" -#include "packager/media/file/file.h" #include "packager/version/version.h" namespace shaka { @@ -77,8 +77,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistOneVideo) { EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(kBaseUrl, test_output_dir_)); std::string actual; - ASSERT_TRUE( - media::File::ReadFileToString(master_playlist_path_.c_str(), &actual)); + ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual)); const std::string expected = "#EXTM3U\n" @@ -158,8 +157,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudio) { EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(kBaseUrl, test_output_dir_)); std::string actual; - ASSERT_TRUE( - media::File::ReadFileToString(master_playlist_path_.c_str(), &actual)); + ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual)); const std::string expected = "#EXTM3U\n" @@ -229,8 +227,7 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistMultipleAudioGroups) { EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(kBaseUrl, test_output_dir_)); std::string actual; - ASSERT_TRUE( - media::File::ReadFileToString(master_playlist_path_.c_str(), &actual)); + ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual)); const std::string expected = "#EXTM3U\n" diff --git a/packager/hls/base/media_playlist.cc b/packager/hls/base/media_playlist.cc index a131b91f81..b86992eb31 100644 --- a/packager/hls/base/media_playlist.cc +++ b/packager/hls/base/media_playlist.cc @@ -15,8 +15,8 @@ #include "packager/base/logging.h" #include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/stringprintf.h" +#include "packager/file/file.h" #include "packager/media/base/language_utils.h" -#include "packager/media/file/file.h" #include "packager/version/version.h" namespace shaka { @@ -392,7 +392,7 @@ bool MediaPlaylist::WriteToFile(const std::string& file_path) { content += "#EXT-X-ENDLIST\n"; } - if (!media::File::WriteFileAtomically(file_path.c_str(), content)) { + if (!File::WriteFileAtomically(file_path.c_str(), content)) { LOG(ERROR) << "Failed to write playlist to: " << file_path; return false; } diff --git a/packager/hls/base/media_playlist.h b/packager/hls/base/media_playlist.h index 4b306aaca5..0dc60d77c0 100644 --- a/packager/hls/base/media_playlist.h +++ b/packager/hls/base/media_playlist.h @@ -16,9 +16,7 @@ namespace shaka { -namespace media { class File; -} // namespace media namespace hls { diff --git a/packager/hls/base/media_playlist_unittest.cc b/packager/hls/base/media_playlist_unittest.cc index 8f6b731a50..8f1496feab 100644 --- a/packager/hls/base/media_playlist_unittest.cc +++ b/packager/hls/base/media_playlist_unittest.cc @@ -7,8 +7,8 @@ #include #include +#include "packager/file/file_test_util.h" #include "packager/hls/base/media_playlist.h" -#include "packager/media/file/file_test_util.h" #include "packager/version/version.h" namespace shaka { diff --git a/packager/hls/hls.gyp b/packager/hls/hls.gyp index 54dc6af115..58e3ec463d 100644 --- a/packager/hls/hls.gyp +++ b/packager/hls/hls.gyp @@ -23,9 +23,9 @@ ], 'dependencies': [ '../base/base.gyp:base', + '../file/file.gyp:file', '../media/base/media_base.gyp:media_base', '../media/base/media_base.gyp:widevine_pssh_data_proto', - '../media/file/file.gyp:file', '../mpd/mpd.gyp:media_info_proto', ], }, diff --git a/packager/media/base/buffer_writer.cc b/packager/media/base/buffer_writer.cc index d5ad554ca2..e5527d9983 100644 --- a/packager/media/base/buffer_writer.cc +++ b/packager/media/base/buffer_writer.cc @@ -8,7 +8,7 @@ #include "packager/base/logging.h" #include "packager/base/sys_byteorder.h" -#include "packager/media/file/file.h" +#include "packager/file/file.h" namespace shaka { namespace media { diff --git a/packager/media/base/buffer_writer.h b/packager/media/base/buffer_writer.h index 7713875553..39667c7794 100644 --- a/packager/media/base/buffer_writer.h +++ b/packager/media/base/buffer_writer.h @@ -13,10 +13,11 @@ #include "packager/status.h" namespace shaka { -namespace media { class File; +namespace media { + /// A simple buffer writer implementation which appends various data types to /// buffer. class BufferWriter { diff --git a/packager/media/base/buffer_writer_unittest.cc b/packager/media/base/buffer_writer_unittest.cc index 9bc6c6bad5..f6403eb22e 100644 --- a/packager/media/base/buffer_writer_unittest.cc +++ b/packager/media/base/buffer_writer_unittest.cc @@ -10,8 +10,8 @@ #include #include "packager/base/files/file_util.h" +#include "packager/file/file.h" #include "packager/media/base/buffer_reader.h" -#include "packager/media/file/file.h" #include "packager/status_test_util.h" namespace { diff --git a/packager/media/base/media_base.gyp b/packager/media/base/media_base.gyp index 113f35ac8c..a5eb0ce1ea 100644 --- a/packager/media/base/media_base.gyp +++ b/packager/media/base/media_base.gyp @@ -157,10 +157,10 @@ 'widevine_key_source_unittest.cc', ], 'dependencies': [ + '../../file/file.gyp:file', '../../testing/gmock.gyp:gmock', '../../testing/gtest.gyp:gtest', '../../third_party/boringssl/boringssl.gyp:boringssl', - '../file/file.gyp:file', '../test/media_test.gyp:media_test_support', 'media_base', ], diff --git a/packager/media/demuxer/demuxer.cc b/packager/media/demuxer/demuxer.cc index b8aec2d359..cefd48f4d8 100644 --- a/packager/media/demuxer/demuxer.cc +++ b/packager/media/demuxer/demuxer.cc @@ -11,11 +11,11 @@ #include "packager/base/bind.h" #include "packager/base/logging.h" #include "packager/base/strings/string_number_conversions.h" +#include "packager/file/file.h" #include "packager/media/base/decryptor_source.h" #include "packager/media/base/key_source.h" #include "packager/media/base/media_sample.h" #include "packager/media/base/stream_info.h" -#include "packager/media/file/file.h" #include "packager/media/formats/mp2t/mp2t_media_parser.h" #include "packager/media/formats/mp4/mp4_media_parser.h" #include "packager/media/formats/webm/webm_media_parser.h" diff --git a/packager/media/demuxer/demuxer.h b/packager/media/demuxer/demuxer.h index a9a45864b0..6f93ed44d3 100644 --- a/packager/media/demuxer/demuxer.h +++ b/packager/media/demuxer/demuxer.h @@ -17,10 +17,12 @@ #include "packager/status.h" namespace shaka { + +class File; + namespace media { class Decryptor; -class File; class KeySource; class MediaParser; class MediaSample; diff --git a/packager/media/event/media_event.gyp b/packager/media/event/media_event.gyp index 3e3131afbc..9c8f1da7a6 100644 --- a/packager/media/event/media_event.gyp +++ b/packager/media/event/media_event.gyp @@ -24,12 +24,12 @@ 'vod_media_info_dump_muxer_listener.h', ], 'dependencies': [ + '../../file/file.gyp:file', '../../mpd/mpd.gyp:media_info_proto', # Depends on full protobuf to read/write with TextFormat. '../../third_party/protobuf/protobuf.gyp:protobuf_full_do_not_use', '../base/media_base.gyp:media_base', '../codecs/codecs.gyp:codecs', - '../file/file.gyp:file', ], }, { diff --git a/packager/media/event/vod_media_info_dump_muxer_listener.cc b/packager/media/event/vod_media_info_dump_muxer_listener.cc index a05c704aa2..ceb5e25244 100644 --- a/packager/media/event/vod_media_info_dump_muxer_listener.cc +++ b/packager/media/event/vod_media_info_dump_muxer_listener.cc @@ -9,11 +9,11 @@ #include #include "packager/base/logging.h" +#include "packager/file/file.h" #include "packager/media/base/muxer_options.h" -#include "packager/media/base/stream_info.h" #include "packager/media/base/protection_system_specific_info.h" +#include "packager/media/base/stream_info.h" #include "packager/media/event/muxer_listener_internal.h" -#include "packager/media/file/file.h" #include "packager/mpd/base/media_info.pb.h" namespace shaka { @@ -100,7 +100,7 @@ bool VodMediaInfoDumpMuxerListener::WriteMediaInfoToFile( return false; } - media::File* file = File::Open(output_file_path.c_str(), "w"); + File* file = File::Open(output_file_path.c_str(), "w"); if (!file) { LOG(ERROR) << "Failed to open " << output_file_path; return false; diff --git a/packager/media/event/vod_media_info_dump_muxer_listener_unittest.cc b/packager/media/event/vod_media_info_dump_muxer_listener_unittest.cc index 055ac8bc46..df78bc00a1 100644 --- a/packager/media/event/vod_media_info_dump_muxer_listener_unittest.cc +++ b/packager/media/event/vod_media_info_dump_muxer_listener_unittest.cc @@ -11,12 +11,12 @@ #include "packager/base/files/file_path.h" #include "packager/base/files/file_util.h" +#include "packager/file/file.h" #include "packager/media/base/fourccs.h" #include "packager/media/base/muxer_options.h" #include "packager/media/base/video_stream_info.h" #include "packager/media/event/muxer_listener_test_helper.h" #include "packager/media/event/vod_media_info_dump_muxer_listener.h" -#include "packager/media/file/file.h" #include "packager/mpd/base/media_info.pb.h" namespace { diff --git a/packager/media/formats/mp2t/ts_segmenter.h b/packager/media/formats/mp2t/ts_segmenter.h index 87b270b21f..89d0aa7a26 100644 --- a/packager/media/formats/mp2t/ts_segmenter.h +++ b/packager/media/formats/mp2t/ts_segmenter.h @@ -8,8 +8,8 @@ #define PACKAGER_MEDIA_FORMATS_MP2T_TS_SEGMENTER_H_ #include +#include "packager/file/file.h" #include "packager/media/base/muxer_options.h" -#include "packager/media/file/file.h" #include "packager/media/formats/mp2t/pes_packet_generator.h" #include "packager/media/formats/mp2t/ts_writer.h" #include "packager/status.h" diff --git a/packager/media/formats/mp2t/ts_writer.h b/packager/media/formats/mp2t/ts_writer.h index 66f96039fa..c4d6e105af 100644 --- a/packager/media/formats/mp2t/ts_writer.h +++ b/packager/media/formats/mp2t/ts_writer.h @@ -12,8 +12,8 @@ #include #include -#include "packager/media/file/file.h" -#include "packager/media/file/file_closer.h" +#include "packager/file/file.h" +#include "packager/file/file_closer.h" #include "packager/media/formats/mp2t/continuity_counter.h" #include "packager/media/formats/mp2t/pes_packet.h" #include "packager/media/formats/mp2t/program_map_table_writer.h" diff --git a/packager/media/formats/mp4/mp4.gyp b/packager/media/formats/mp4/mp4.gyp index d8d2ab32b8..f8003d592f 100644 --- a/packager/media/formats/mp4/mp4.gyp +++ b/packager/media/formats/mp4/mp4.gyp @@ -64,9 +64,9 @@ 'track_run_iterator_unittest.cc', ], 'dependencies': [ + '../../../file/file.gyp:file', '../../../testing/gtest.gyp:gtest', '../../../testing/gmock.gyp:gmock', - '../../file/file.gyp:file', '../../test/media_test.gyp:media_test_support', 'mp4', ] diff --git a/packager/media/formats/mp4/mp4_media_parser.cc b/packager/media/formats/mp4/mp4_media_parser.cc index c3a2f08182..f51feaafc1 100644 --- a/packager/media/formats/mp4/mp4_media_parser.cc +++ b/packager/media/formats/mp4/mp4_media_parser.cc @@ -11,6 +11,8 @@ #include "packager/base/callback_helpers.h" #include "packager/base/logging.h" #include "packager/base/strings/string_number_conversions.h" +#include "packager/file/file.h" +#include "packager/file/file_closer.h" #include "packager/media/base/audio_stream_info.h" #include "packager/media/base/buffer_reader.h" #include "packager/media/base/decrypt_config.h" @@ -23,8 +25,6 @@ #include "packager/media/codecs/es_descriptor.h" #include "packager/media/codecs/hevc_decoder_configuration_record.h" #include "packager/media/codecs/vp_codec_configuration_record.h" -#include "packager/media/file/file.h" -#include "packager/media/file/file_closer.h" #include "packager/media/formats/mp4/box_definitions.h" #include "packager/media/formats/mp4/box_reader.h" #include "packager/media/formats/mp4/track_run_iterator.h" diff --git a/packager/media/formats/mp4/mp4_muxer.cc b/packager/media/formats/mp4/mp4_muxer.cc index e6c7c0f728..8fe9d2188c 100644 --- a/packager/media/formats/mp4/mp4_muxer.cc +++ b/packager/media/formats/mp4/mp4_muxer.cc @@ -8,6 +8,7 @@ #include "packager/base/time/clock.h" #include "packager/base/time/time.h" +#include "packager/file/file.h" #include "packager/media/base/aes_encryptor.h" #include "packager/media/base/audio_stream_info.h" #include "packager/media/base/fourccs.h" @@ -17,7 +18,6 @@ #include "packager/media/base/video_stream_info.h" #include "packager/media/codecs/es_descriptor.h" #include "packager/media/event/muxer_listener.h" -#include "packager/media/file/file.h" #include "packager/media/formats/mp4/box_definitions.h" #include "packager/media/formats/mp4/multi_segment_segmenter.h" #include "packager/media/formats/mp4/single_segment_segmenter.h" diff --git a/packager/media/formats/mp4/multi_segment_segmenter.cc b/packager/media/formats/mp4/multi_segment_segmenter.cc index 9cc1f3a14c..abd08d79ba 100644 --- a/packager/media/formats/mp4/multi_segment_segmenter.cc +++ b/packager/media/formats/mp4/multi_segment_segmenter.cc @@ -10,11 +10,11 @@ #include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/string_util.h" +#include "packager/file/file.h" #include "packager/media/base/buffer_writer.h" #include "packager/media/base/muxer_options.h" #include "packager/media/base/muxer_util.h" #include "packager/media/event/muxer_listener.h" -#include "packager/media/file/file.h" #include "packager/media/formats/mp4/box_definitions.h" namespace shaka { diff --git a/packager/media/formats/mp4/single_segment_segmenter.cc b/packager/media/formats/mp4/single_segment_segmenter.cc index 77df75e462..d4be794201 100644 --- a/packager/media/formats/mp4/single_segment_segmenter.cc +++ b/packager/media/formats/mp4/single_segment_segmenter.cc @@ -8,11 +8,11 @@ #include +#include "packager/file/file.h" +#include "packager/file/file_util.h" #include "packager/media/base/buffer_writer.h" #include "packager/media/base/muxer_options.h" #include "packager/media/event/progress_listener.h" -#include "packager/media/file/file.h" -#include "packager/media/file/file_util.h" #include "packager/media/formats/mp4/box_definitions.h" namespace shaka { diff --git a/packager/media/formats/mp4/single_segment_segmenter.h b/packager/media/formats/mp4/single_segment_segmenter.h index 2e72a1b5bb..616a1ca560 100644 --- a/packager/media/formats/mp4/single_segment_segmenter.h +++ b/packager/media/formats/mp4/single_segment_segmenter.h @@ -7,8 +7,8 @@ #ifndef MEDIA_FORMATS_MP4_SINGLE_SEGMENT_SEGMENTER_H_ #define MEDIA_FORMATS_MP4_SINGLE_SEGMENT_SEGMENTER_H_ +#include "packager/file/file_closer.h" #include "packager/media/event/muxer_listener.h" -#include "packager/media/file/file_closer.h" #include "packager/media/formats/mp4/segmenter.h" namespace shaka { diff --git a/packager/media/formats/webm/mkv_writer.h b/packager/media/formats/webm/mkv_writer.h index 4ce4b7432a..2f17d1348f 100644 --- a/packager/media/formats/webm/mkv_writer.h +++ b/packager/media/formats/webm/mkv_writer.h @@ -10,7 +10,7 @@ #include #include -#include "packager/media/file/file_closer.h" +#include "packager/file/file_closer.h" #include "packager/status.h" #include "packager/third_party/libwebm/src/mkvmuxer.hpp" diff --git a/packager/media/formats/webm/segmenter_test_base.cc b/packager/media/formats/webm/segmenter_test_base.cc index fe3514b146..643b0b0fc0 100644 --- a/packager/media/formats/webm/segmenter_test_base.cc +++ b/packager/media/formats/webm/segmenter_test_base.cc @@ -6,7 +6,7 @@ #include "packager/media/formats/webm/segmenter_test_base.h" -#include "packager/media/file/memory_file.h" +#include "packager/file/memory_file.h" #include "packager/media/formats/webm/webm_constants.h" #include "packager/version/version.h" diff --git a/packager/media/formats/webm/segmenter_test_base.h b/packager/media/formats/webm/segmenter_test_base.h index 0e70610a6d..e7c05c426e 100644 --- a/packager/media/formats/webm/segmenter_test_base.h +++ b/packager/media/formats/webm/segmenter_test_base.h @@ -9,13 +9,13 @@ #include +#include "packager/file/file_closer.h" +#include "packager/file/file_test_util.h" +#include "packager/file/memory_file.h" #include "packager/media/base/media_sample.h" #include "packager/media/base/muxer_options.h" #include "packager/media/base/stream_info.h" #include "packager/media/base/video_stream_info.h" -#include "packager/media/file/file_closer.h" -#include "packager/media/file/file_test_util.h" -#include "packager/media/file/memory_file.h" #include "packager/media/formats/webm/mkv_writer.h" #include "packager/media/formats/webm/segmenter.h" #include "packager/media/formats/webm/webm_parser.h" diff --git a/packager/media/formats/webm/two_pass_single_segment_segmenter.cc b/packager/media/formats/webm/two_pass_single_segment_segmenter.cc index 09ac5b9e84..5e1f710157 100644 --- a/packager/media/formats/webm/two_pass_single_segment_segmenter.cc +++ b/packager/media/formats/webm/two_pass_single_segment_segmenter.cc @@ -8,10 +8,10 @@ #include +#include "packager/file/file_util.h" #include "packager/media/base/media_sample.h" #include "packager/media/base/muxer_options.h" #include "packager/media/base/stream_info.h" -#include "packager/media/file/file_util.h" #include "packager/third_party/libwebm/src/mkvmuxer.hpp" #include "packager/third_party/libwebm/src/mkvmuxerutil.hpp" #include "packager/third_party/libwebm/src/webmids.hpp" diff --git a/packager/media/formats/webm/webm.gyp b/packager/media/formats/webm/webm.gyp index db7989099d..cd4f1698cb 100644 --- a/packager/media/formats/webm/webm.gyp +++ b/packager/media/formats/webm/webm.gyp @@ -83,10 +83,10 @@ 'webm_webvtt_parser_unittest.cc', ], 'dependencies': [ + '../../../file/file.gyp:file', '../../../testing/gtest.gyp:gtest', '../../../testing/gmock.gyp:gmock', '../../../third_party/libwebm/libwebm.gyp:mkvmuxer', - '../../file/file.gyp:file', '../../test/media_test.gyp:media_test_support', 'webm', ] diff --git a/packager/mpd/base/mpd_builder.cc b/packager/mpd/base/mpd_builder.cc index 9fc86e3e9d..2d7b005803 100644 --- a/packager/mpd/base/mpd_builder.cc +++ b/packager/mpd/base/mpd_builder.cc @@ -24,8 +24,8 @@ #include "packager/base/synchronization/lock.h" #include "packager/base/time/default_clock.h" #include "packager/base/time/time.h" +#include "packager/file/file.h" #include "packager/media/base/language_utils.h" -#include "packager/media/file/file.h" #include "packager/mpd/base/content_protection_element.h" #include "packager/mpd/base/mpd_utils.h" #include "packager/mpd/base/xml/xml_node.h" diff --git a/packager/mpd/base/mpd_builder.h b/packager/mpd/base/mpd_builder.h index 1665309f4c..1c2a8ae540 100644 --- a/packager/mpd/base/mpd_builder.h +++ b/packager/mpd/base/mpd_builder.h @@ -39,11 +39,8 @@ // element. namespace shaka { -namespace media { -class File; -} // namespace media - class AdaptationSet; +class File; class Representation; namespace xml { diff --git a/packager/mpd/base/mpd_notifier_util.cc b/packager/mpd/base/mpd_notifier_util.cc index e07e9aa380..4a10603f88 100644 --- a/packager/mpd/base/mpd_notifier_util.cc +++ b/packager/mpd/base/mpd_notifier_util.cc @@ -8,7 +8,7 @@ #include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/string_util.h" -#include "packager/media/file/file.h" +#include "packager/file/file.h" #include "packager/mpd/base/mpd_utils.h" namespace shaka { @@ -22,7 +22,7 @@ bool WriteMpdToFile(const std::string& output_path, MpdBuilder* mpd_builder) { return false; } - if (!media::File::WriteFileAtomically(output_path.c_str(), mpd)) { + if (!File::WriteFileAtomically(output_path.c_str(), mpd)) { LOG(ERROR) << "Failed to write mpd to: " << output_path; return false; } diff --git a/packager/mpd/mpd.gyp b/packager/mpd/mpd.gyp index 9cd37892b1..af1256f1ae 100644 --- a/packager/mpd/mpd.gyp +++ b/packager/mpd/mpd.gyp @@ -50,7 +50,8 @@ ], 'dependencies': [ '../base/base.gyp:base', - '../media/file/file.gyp:file', + '../file/file.gyp:file', + '../media/base/media_base.gyp:media_base', '../third_party/libxml/libxml.gyp:libxml', '../version/version.gyp:version', 'media_info_proto', @@ -91,7 +92,7 @@ ], 'dependencies': [ '../base/base.gyp:base', - '../media/file/file.gyp:file', + '../file/file.gyp:file', '../media/test/media_test.gyp:run_tests_with_atexit_manager', '../testing/gmock.gyp:gmock', '../testing/gtest.gyp:gtest', @@ -108,7 +109,7 @@ 'util/mpd_writer.h', ], 'dependencies': [ - '../media/file/file.gyp:file', + '../file/file.gyp:file', '../third_party/gflags/gflags.gyp:gflags', 'mpd_builder', 'mpd_mocks', diff --git a/packager/mpd/util/mpd_writer.cc b/packager/mpd/util/mpd_writer.cc index a04cb3f7b5..159070b936 100644 --- a/packager/mpd/util/mpd_writer.cc +++ b/packager/mpd/util/mpd_writer.cc @@ -12,7 +12,7 @@ #include "packager/base/files/file_path.h" #include "packager/base/files/file_util.h" -#include "packager/media/file/file.h" +#include "packager/file/file.h" #include "packager/mpd/base/dash_iop_mpd_notifier.h" #include "packager/mpd/base/mpd_builder.h" #include "packager/mpd/base/mpd_notifier.h" @@ -70,8 +70,7 @@ MpdWriter::~MpdWriter() {} bool MpdWriter::AddFile(const std::string& media_info_path, const std::string& mpd_path) { std::string file_content; - if (!media::File::ReadFileToString(media_info_path.c_str(), - &file_content)) { + if (!File::ReadFileToString(media_info_path.c_str(), &file_content)) { LOG(ERROR) << "Failed to read " << media_info_path << " to string."; return false; } diff --git a/packager/packager.cc b/packager/packager.cc index 2fbfb837fc..96ed040d8d 100644 --- a/packager/packager.cc +++ b/packager/packager.cc @@ -16,6 +16,7 @@ #include "packager/base/strings/stringprintf.h" #include "packager/base/threading/simple_thread.h" #include "packager/base/time/clock.h" +#include "packager/file/file.h" #include "packager/hls/base/hls_notifier.h" #include "packager/hls/base/simple_hls_notifier.h" #include "packager/media/base/container_names.h" @@ -29,7 +30,6 @@ #include "packager/media/event/hls_notify_muxer_listener.h" #include "packager/media/event/mpd_notify_muxer_listener.h" #include "packager/media/event/vod_media_info_dump_muxer_listener.h" -#include "packager/media/file/file.h" #include "packager/media/formats/mp2t/ts_muxer.h" #include "packager/media/formats/mp4/mp4_muxer.h" #include "packager/media/formats/webm/webm_muxer.h" diff --git a/packager/packager.gyp b/packager/packager.gyp index cdc86d60fa..83a2f0b64e 100644 --- a/packager/packager.gyp +++ b/packager/packager.gyp @@ -22,12 +22,12 @@ 'app/packager_util.h', ], 'dependencies': [ + 'file/file.gyp:file', 'hls/hls.gyp:hls_builder', 'media/codecs/codecs.gyp:codecs', 'media/chunking/chunking.gyp:chunking', 'media/demuxer/demuxer.gyp:demuxer', 'media/event/media_event.gyp:media_event', - 'media/file/file.gyp:file', 'media/formats/mp2t/mp2t.gyp:mp2t', 'media/formats/mp4/mp4.gyp:mp4', 'media/formats/mpeg/mpeg.gyp:mpeg', @@ -83,8 +83,8 @@ ], 'dependencies': [ 'base/base.gyp:base', + 'file/file.gyp:file', 'libpackager', - 'media/file/file.gyp:file', 'third_party/gflags/gflags.gyp:gflags', ], 'conditions': [ @@ -172,6 +172,7 @@ 'target_name': 'packager_builder_tests', 'type': 'none', 'dependencies': [ + 'file/file.gyp:file_unittest', 'hls/hls.gyp:hls_unittest', 'media/base/media_base.gyp:media_base_unittest', 'media/chunking/chunking.gyp:chunking_unittest', @@ -179,7 +180,6 @@ 'media/crypto/crypto.gyp:crypto_unittest', 'media/demuxer/demuxer.gyp:demuxer_unittest', 'media/event/media_event.gyp:media_event_unittest', - 'media/file/file.gyp:file_unittest', 'media/formats/mp2t/mp2t.gyp:mp2t_unittest', 'media/formats/mp4/mp4.gyp:mp4_unittest', 'media/formats/webm/webm.gyp:webm_unittest',