diff --git a/DEPS b/DEPS index e7d0738aed..80b03d4e9d 100644 --- a/DEPS +++ b/DEPS @@ -55,7 +55,7 @@ deps = { Var("chromium_git") + "/chromium/src/third_party/tcmalloc/chromium@fa1492f75861094061043a17c0f779c3d35780bf", "src/packager/third_party/zlib": - Var("chromium_git") + "/chromium/src/third_party/zlib@bcf81d2e5f3a62b698d179c1fadba94604c5dad3", + Var("chromium_git") + "/chromium/src/third_party/zlib@830b5c25b5fbe37e032ea09dd011d57042dd94df", "src/packager/tools/clang": Var("chromium_git") + "/chromium/src/tools/clang@0de8f3bb6af64e13876273c601704795d5e00faf", diff --git a/packager/app/mpd_generator.cc b/packager/app/mpd_generator.cc index b0e080b304..3aa0e40b41 100644 --- a/packager/app/mpd_generator.cc +++ b/packager/app/mpd_generator.cc @@ -14,6 +14,12 @@ #include "packager/mpd/util/mpd_writer.h" #include "packager/version/version.h" +#if defined(OS_WIN) +#include +#include +#include +#endif // defined(OS_WIN) + namespace shaka { namespace { const char kUsage[] = @@ -103,6 +109,29 @@ int MpdMain(int argc, char** argv) { } // namespace } // namespace shaka +#if defined(OS_WIN) +// Windows wmain, which converts wide character arguments to UTF-8. +int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) { + std::unique_ptr> utf8_argv( + new char*[argc], [argc](char** utf8_args) { + // TODO(tinskip): This leaks, but if this code is enabled, it crashes. + // Figure out why. I suspect gflags does something funny with the + // argument array. + // for (int idx = 0; idx < argc; ++idx) + // delete[] utf8_args[idx]; + delete[] utf8_args; + }); + std::wstring_convert> converter; + for (int idx = 0; idx < argc; ++idx) { + std::string utf8_arg(converter.to_bytes(argv[idx])); + utf8_arg += '\0'; + utf8_argv[idx] = new char[utf8_arg.size()]; + memcpy(utf8_argv[idx], &utf8_arg[0], utf8_arg.size()); + } + return shaka::MpdMain(argc, utf8_argv.get()); +} +#else int main(int argc, char** argv) { return shaka::MpdMain(argc, argv); } +#endif // !defined(OS_WIN) diff --git a/packager/app/packager_main.cc b/packager/app/packager_main.cc index 882f31acfe..edc3d6ed77 100644 --- a/packager/app/packager_main.cc +++ b/packager/app/packager_main.cc @@ -20,6 +20,7 @@ #include "packager/base/command_line.h" #include "packager/base/files/file_path.h" #include "packager/base/logging.h" +#include "packager/base/path_service.h" #include "packager/base/stl_util.h" #include "packager/base/strings/string_split.h" #include "packager/base/strings/stringprintf.h" @@ -46,6 +47,12 @@ #include "packager/mpd/base/simple_mpd_notifier.h" #include "packager/version/version.h" +#if defined(OS_WIN) +#include +#include +#include +#endif // defined(OS_WIN) + DEFINE_bool(use_fake_clock_for_muxer, false, "Set to true to use a fake clock for muxer. With this flag set, " @@ -480,13 +487,14 @@ bool RunPackager(const StreamDescriptorList& stream_descriptors) { scoped_ptr hls_notifier; if (!FLAGS_hls_master_playlist_output.empty()) { - base::FilePath master_playlist_path(FLAGS_hls_master_playlist_output); + base::FilePath master_playlist_path( + base::FilePath::FromUTF8Unsafe(FLAGS_hls_master_playlist_output)); base::FilePath master_playlist_name = master_playlist_path.BaseName(); hls_notifier.reset(new hls::SimpleHlsNotifier( hls::HlsNotifier::HlsProfile::kOnDemandProfile, FLAGS_hls_base_url, - master_playlist_path.DirName().AsEndingWithSeparator().value(), - master_playlist_name.value())); + master_playlist_path.DirName().AsEndingWithSeparator().AsUTF8Unsafe(), + master_playlist_name.AsUTF8Unsafe())); } std::vector remux_jobs; @@ -521,7 +529,16 @@ int PackagerMain(int argc, char** argv) { base::AtExitManager exit; // Needed to enable VLOG/DVLOG through --vmodule or --v. base::CommandLine::Init(argc, argv); - CHECK(logging::InitLogging(logging::LoggingSettings())); + + // Set up logging. + logging::LoggingSettings log_settings; + base::FilePath log_filename; + PathService::Get(base::DIR_EXE, &log_filename); + log_filename = log_filename.AppendASCII("packager.log"); + log_settings.logging_dest = logging::LOG_TO_ALL; + log_settings.log_file = log_filename.value().c_str(); + log_settings.delete_old = logging::DELETE_OLD_LOG_FILE; + CHECK(logging::InitLogging(log_settings)); google::SetUsageMessage(base::StringPrintf(kUsage, argv[0])); google::ParseCommandLineFlags(&argc, &argv, true); @@ -552,6 +569,29 @@ int PackagerMain(int argc, char** argv) { } // namespace media } // namespace shaka +#if defined(OS_WIN) +// Windows wmain, which converts wide character arguments to UTF-8. +int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) { + std::unique_ptr> utf8_argv( + new char*[argc], [argc](char** utf8_args) { + // TODO(tinskip): This leaks, but if this code is enabled, it crashes. + // Figure out why. I suspect gflags does something funny with the + // argument array. + // for (int idx = 0; idx < argc; ++idx) + // delete[] utf8_args[idx]; + delete[] utf8_args; + }); + std::wstring_convert> converter; + for (int idx = 0; idx < argc; ++idx) { + std::string utf8_arg(converter.to_bytes(argv[idx])); + utf8_arg += '\0'; + utf8_argv[idx] = new char[utf8_arg.size()]; + memcpy(utf8_argv[idx], &utf8_arg[0], utf8_arg.size()); + } + return shaka::media::PackagerMain(argc, utf8_argv.get()); +} +#else int main(int argc, char** argv) { return shaka::media::PackagerMain(argc, argv); } +#endif // defined(OS_WIN) diff --git a/packager/app/test/packager_app.py b/packager/app/test/packager_app.py index f07d40ed04..9f3c3f285d 100644 --- a/packager/app/test/packager_app.py +++ b/packager/app/test/packager_app.py @@ -8,6 +8,7 @@ """Test wrapper for the sample packager binary.""" import os +import platform import subprocess import test_env @@ -17,7 +18,10 @@ class PackagerApp(object): """Main integration class for testing the packager binary.""" def __init__(self): - self.binary = os.path.join(test_env.SCRIPT_DIR, 'packager') + packager_name = 'packager' + if platform.system() == 'Windows': + packager_name += '.exe' + self.binary = os.path.join(test_env.SCRIPT_DIR, packager_name) assert os.path.exists(self.binary), ('Please run from output directory, ' 'e.g. out/Debug/packager_test.py') diff --git a/packager/app/test/packager_test.py b/packager/app/test/packager_test.py index 65a0426b14..2c73889fa3 100755 --- a/packager/app/test/packager_test.py +++ b/packager/app/test/packager_test.py @@ -9,6 +9,7 @@ import filecmp import os +import platform import re import shutil import subprocess @@ -66,6 +67,7 @@ class PackagerAppTest(unittest.TestCase): ' num_channels: 2\n' ' sampling_frequency: 44100\n' ' language: und\n') + stream_info = stream_info.replace('\r\n', '\n') self.assertIn(expected_stream_info, stream_info, '\nExpecting: \n %s\n\nBut seeing: \n%s' % (expected_stream_info, stream_info)) @@ -527,7 +529,10 @@ class PackagerAppTest(unittest.TestCase): else: match = filecmp.cmp(test_output, golden_file) if not match: - p = subprocess.Popen(['git', '--no-pager', 'diff', '--color=auto', + git = 'git' + if platform.system() == 'Windows': + git += '.bat' + p = subprocess.Popen([git, '--no-pager', 'diff', '--color=auto', '--no-ext-diff', '--no-index', golden_file, test_output], stdout=subprocess.PIPE, @@ -538,11 +543,13 @@ class PackagerAppTest(unittest.TestCase): # '*.media_info' outputs contain media file names, which is changing for # every test run. These needs to be replaced for comparison. def _DiffMediaInfoGold(self, test_output, golden_file_name): + if platform.system() == 'Windows': + test_output = test_output.replace('\\', '\\\\') media_info_output = test_output + '.media_info' # Replaces filename, which is changing for every test run. - with open(media_info_output, 'r') as f: + with open(media_info_output, 'rb') as f: content = f.read() - with open(media_info_output, 'w') as f: + with open(media_info_output, 'wb') as f: f.write(content.replace(test_output, 'place_holder')) self._DiffGold(media_info_output, golden_file_name + '.media_info') @@ -565,7 +572,7 @@ class PackagerAppTest(unittest.TestCase): # Live mpd contains current availabilityStartTime and publishTime, which # needs to be replaced for comparison. def _DiffLiveMpdGold(self, test_output, golden_file_name): - with open(test_output, 'r') as f: + with open(test_output, 'rb') as f: content = f.read() # Extract availabilityStartTime. @@ -579,7 +586,7 @@ class PackagerAppTest(unittest.TestCase): self.assertIsNotNone(m) publish_time = m.group(0) print publish_time - with open(test_output, 'w') as f: + with open(test_output, 'wb') as f: f.write(content.replace( availability_start_time, 'availabilityStartTime="some_availability_start_time"').replace( diff --git a/packager/common.gypi b/packager/common.gypi index eebcee0948..f089e5aeaa 100644 --- a/packager/common.gypi +++ b/packager/common.gypi @@ -32,6 +32,14 @@ '-Wno-reserved-user-defined-literal', ], }], + ['OS == "win"', { + 'msvs_settings': { + 'VCCLCompilerTool': { + 'WarnAsError': 'true', + 'DisableSpecificWarnings': ['4125'] + }, + }, + }], ], }, } diff --git a/packager/hls/base/master_playlist_unittest.cc b/packager/hls/base/master_playlist_unittest.cc index 72835a8b8d..7daa4d5282 100644 --- a/packager/hls/base/master_playlist_unittest.cc +++ b/packager/hls/base/master_playlist_unittest.cc @@ -22,6 +22,7 @@ using ::testing::AtLeast; using ::testing::Return; using ::testing::ReturnRef; using ::testing::_; +using base::FilePath; namespace { const char kDefaultMasterPlaylistName[] = "playlist.m3u8"; @@ -39,7 +40,7 @@ class MasterPlaylistTest : public ::testing::Test { } MasterPlaylist master_playlist_; - base::FilePath test_output_dir_path_; + FilePath test_output_dir_path_; std::string test_output_dir_; private: @@ -48,12 +49,13 @@ class MasterPlaylistTest : public ::testing::Test { // using base::File* related API. // |output_dir| is set to an equivalent value to |temp_dir_path| but formatted // so that media::File interface can Open it. - void GetOutputDir(base::FilePath* temp_dir_path, std::string* output_dir) { + void GetOutputDir(FilePath* temp_dir_path, std::string* output_dir) { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir_.IsValid()); *temp_dir_path = temp_dir_.path(); // TODO(rkuroiwa): Use memory file sys once prefix is exposed. - *output_dir = media::kLocalFilePrefix + temp_dir_.path().value() + "/"; + *output_dir = media::kLocalFilePrefix + temp_dir_.path().AsUTF8Unsafe() + + "/"; } base::ScopedTempDir temp_dir_; @@ -78,8 +80,9 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistOneVideo) { const char kBaseUrl[] = "http://myplaylistdomain.com/"; EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(kBaseUrl, test_output_dir_)); - base::FilePath master_playlist_path = - test_output_dir_path_.Append(kDefaultMasterPlaylistName); + FilePath master_playlist_path = + test_output_dir_path_.Append(FilePath::FromUTF8Unsafe( + kDefaultMasterPlaylistName)); ASSERT_TRUE(base::PathExists(master_playlist_path)) << "Cannot find " << master_playlist_path.value(); @@ -149,8 +152,9 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudio) { const char kBaseUrl[] = "http://playlists.org/"; EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(kBaseUrl, test_output_dir_)); - base::FilePath master_playlist_path = - test_output_dir_path_.Append(kDefaultMasterPlaylistName); + FilePath master_playlist_path = + test_output_dir_path_.Append(FilePath::FromUTF8Unsafe( + kDefaultMasterPlaylistName)); ASSERT_TRUE(base::PathExists(master_playlist_path)) << "Cannot find " << master_playlist_path.value(); @@ -216,8 +220,8 @@ TEST_F(MasterPlaylistTest, WriteMasterPlaylistMultipleAudioGroups) { const char kBaseUrl[] = "http://anydomain.com/"; EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(kBaseUrl, test_output_dir_)); - base::FilePath master_playlist_path = - test_output_dir_path_.Append(kDefaultMasterPlaylistName); + FilePath master_playlist_path = test_output_dir_path_.Append( + FilePath::FromUTF8Unsafe(kDefaultMasterPlaylistName)); ASSERT_TRUE(base::PathExists(master_playlist_path)) << "Cannot find " << master_playlist_path.value(); @@ -266,15 +270,17 @@ TEST_F(MasterPlaylistTest, WriteAllPlaylists) { EXPECT_CALL(mock_playlist, SetTargetDuration(10)).WillOnce(Return(true)); master_playlist_.AddMediaPlaylist(&mock_playlist); - EXPECT_CALL(mock_playlist, - WriteToFile(FileNameMatches( - test_output_dir_path_.Append("media1.m3u8").value()))) + EXPECT_CALL( + mock_playlist, + WriteToFile(FileNameMatches( + test_output_dir_path_.Append(FilePath::FromUTF8Unsafe("media1.m3u8")) + .AsUTF8Unsafe()))) .WillOnce(Return(true)); const char kBaseUrl[] = "http://domain.com/"; EXPECT_TRUE(master_playlist_.WriteAllPlaylists(kBaseUrl, test_output_dir_)); - base::FilePath master_playlist_path = - test_output_dir_path_.Append(kDefaultMasterPlaylistName); + FilePath master_playlist_path = test_output_dir_path_.Append( + FilePath::FromUTF8Unsafe(kDefaultMasterPlaylistName)); ASSERT_TRUE(base::PathExists(master_playlist_path)) << "Cannot find master playlist at " << master_playlist_path.value(); } diff --git a/packager/hls/base/simple_hls_notifier.cc b/packager/hls/base/simple_hls_notifier.cc index 03e63b0cd3..287a877e87 100644 --- a/packager/hls/base/simple_hls_notifier.cc +++ b/packager/hls/base/simple_hls_notifier.cc @@ -53,9 +53,9 @@ void MakePathsRelativeToOutputDirectory(const std::string& output_dir, return; std::string directory_with_separator( - base::FilePath(prefix_stripped_output_dir) - .AsEndingWithSeparator() - .value()); + base::FilePath::FromUTF8Unsafe(prefix_stripped_output_dir) + .AsEndingWithSeparator() + .AsUTF8Unsafe()); if (directory_with_separator.empty()) return; diff --git a/packager/media/base/bit_reader.h b/packager/media/base/bit_reader.h index 33ad8fa623..b907c6a0be 100644 --- a/packager/media/base/bit_reader.h +++ b/packager/media/base/bit_reader.h @@ -40,6 +40,15 @@ class BitReader { return ret; } + // Explicit T=bool overload to make MSVC happy. + bool ReadBits(int num_bits, bool* out) { + DCHECK_EQ(num_bits, 1); + uint64_t temp; + bool ret = ReadBitsInternal(num_bits, &temp); + *out = temp != 0; + return ret; + } + /// Skip a number of bits from stream. /// @param num_bits specifies the number of bits to be skipped. /// @return false if the given number of bits cannot be skipped (not enough diff --git a/packager/media/base/buffer_writer_unittest.cc b/packager/media/base/buffer_writer_unittest.cc index b13528a83a..bbed3f7402 100644 --- a/packager/media/base/buffer_writer_unittest.cc +++ b/packager/media/base/buffer_writer_unittest.cc @@ -164,7 +164,7 @@ TEST_F(BufferWriterTest, WriteToFile) { LOG(INFO) << "Created temporary file: " << path.value(); // Append an array to buffer and then write to the temporary file. - File* const output_file = File::Open(path.value().c_str(), "w"); + File* const output_file = File::Open(path.AsUTF8Unsafe().c_str(), "w"); writer_->AppendArray(kuint8Array, sizeof(kuint8Array)); ASSERT_EQ(sizeof(kuint8Array), writer_->Size()); ASSERT_OK(writer_->WriteToFile(output_file)); @@ -172,12 +172,11 @@ TEST_F(BufferWriterTest, WriteToFile) { ASSERT_TRUE(output_file->Close()); // Read the file and verify. - File* const input_file = File::Open(path.value().c_str(), "r"); + File* const input_file = File::Open(path.AsUTF8Unsafe().c_str(), "r"); ASSERT_TRUE(input_file != NULL); std::vector data_read(sizeof(kuint8Array), 0); - EXPECT_EQ( - sizeof(kuint8Array), - static_cast(input_file->Read(&data_read[0], data_read.size()))); + EXPECT_EQ(sizeof(kuint8Array), static_cast(input_file->Read( + &data_read[0], data_read.size()))); ASSERT_TRUE(input_file->Close()); for (size_t i = 0; i < sizeof(kuint8Array); ++i) diff --git a/packager/media/codecs/aac_audio_specific_config.cc b/packager/media/codecs/aac_audio_specific_config.cc index 9ca9d14b5b..128b1c4bbd 100644 --- a/packager/media/codecs/aac_audio_specific_config.cc +++ b/packager/media/codecs/aac_audio_specific_config.cc @@ -142,9 +142,9 @@ bool AACAudioSpecificConfig::ConvertToADTS(std::vector* buffer) const { adts[1] = 0xf1; adts[2] = ((audio_object_type_ - 1) << 6) + (frequency_index_ << 2) + (channel_config_ >> 2); - adts[3] = ((channel_config_ & 0x3) << 6) + (size >> 11); - adts[4] = (size & 0x7ff) >> 3; - adts[5] = ((size & 7) << 5) + 0x1f; + adts[3] = ((channel_config_ & 0x3) << 6) + static_cast(size >> 11); + adts[4] = static_cast((size & 0x7ff) >> 3); + adts[5] = static_cast(((size & 7) << 5) + 0x1f); adts[6] = 0xfc; return true; diff --git a/packager/media/codecs/es_descriptor.cc b/packager/media/codecs/es_descriptor.cc index 12a5f5c4b4..b49dc36639 100644 --- a/packager/media/codecs/es_descriptor.cc +++ b/packager/media/codecs/es_descriptor.cc @@ -140,15 +140,17 @@ void ESDescriptor::Write(BufferWriter* writer) const { const std::vector kEmptyDecodingBufferSize(3, 0); const uint8_t kNoEsFlags = 0; - const uint8_t decoder_specific_info_size = decoder_specific_info_.size(); + const uint8_t decoder_specific_info_size = + static_cast(decoder_specific_info_.size()); // 6 bit stream type. The last bit is reserved with 1. const uint8_t stream_type = (kAudioStreamType << 2) | 1; - const uint8_t decoder_config_size = decoder_specific_info_size + kHeaderSize + - sizeof(uint8_t) + // object_type_. - sizeof(stream_type) + - kEmptyDecodingBufferSize.size() + - sizeof(kUnknownBitrate) * 2; + const uint8_t decoder_config_size = + static_cast(decoder_specific_info_size + kHeaderSize + + sizeof(uint8_t) + // object_type_. + sizeof(stream_type) + + kEmptyDecodingBufferSize.size() + + sizeof(kUnknownBitrate) * 2); const uint8_t sl_config_size = sizeof(uint8_t); // predefined. const uint8_t es_size = decoder_config_size + kHeaderSize + sl_config_size + @@ -178,7 +180,8 @@ void ESDescriptor::Write(BufferWriter* writer) const { size_t ESDescriptor::ComputeSize() const { // A bit magical. Refer to ESDescriptor::Write for details. - const uint8_t decoder_specific_info_size = decoder_specific_info_.size(); + const uint8_t decoder_specific_info_size = + static_cast(decoder_specific_info_.size()); const uint8_t decoder_config_size = decoder_specific_info_size + kHeaderSize + sizeof(uint8_t) * 5 + sizeof(uint32_t) * 2; diff --git a/packager/media/codecs/vp_codec_configuration_record.cc b/packager/media/codecs/vp_codec_configuration_record.cc index c76f32f851..71d616f825 100644 --- a/packager/media/codecs/vp_codec_configuration_record.cc +++ b/packager/media/codecs/vp_codec_configuration_record.cc @@ -161,7 +161,8 @@ void VPCodecConfigurationRecord::WriteMP4(std::vector* data) const { uint8_t chroma = (chroma_subsampling_ << 4) | (transfer_function_ << 1) | (video_full_range_flag_ ? 1 : 0); writer.AppendInt(chroma); - uint16_t codec_initialization_data_size = codec_initialization_data_.size(); + uint16_t codec_initialization_data_size = + static_cast(codec_initialization_data_.size()); writer.AppendInt(codec_initialization_data_size); writer.AppendVector(codec_initialization_data_); writer.SwapBuffer(data); 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 6067a57467..b6cd4deca4 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 @@ -65,7 +65,8 @@ class VodMediaInfoDumpMuxerListenerTest : public ::testing::Test { ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path_)); DLOG(INFO) << "Created temp file: " << temp_file_path_.value(); - listener_.reset(new VodMediaInfoDumpMuxerListener(temp_file_path_.value())); + listener_.reset(new VodMediaInfoDumpMuxerListener(temp_file_path_ + .AsUTF8Unsafe())); } void TearDown() override { @@ -106,7 +107,7 @@ class VodMediaInfoDumpMuxerListenerTest : public ::testing::Test { void ExpectTempFileToEqual(const std::string& expected_protobuf) { std::string temp_file_media_info_str; - ASSERT_TRUE(File::ReadFileToString(temp_file_path_.value().c_str(), + ASSERT_TRUE(File::ReadFileToString(temp_file_path_.AsUTF8Unsafe().c_str(), &temp_file_media_info_str)); ASSERT_TRUE(!temp_file_media_info_str.empty()); diff --git a/packager/media/file/file.cc b/packager/media/file/file.cc index 0934c2ab7b..16b70454d2 100644 --- a/packager/media/file/file.cc +++ b/packager/media/file/file.cc @@ -25,6 +25,11 @@ DEFINE_uint64(io_block_size, 2ULL << 20, "Size of the block size used for threaded I/O, in bytes."); +// Needed for Windows weirdness which somewhere defines CopyFile as CopyFileW. +#ifdef CopyFile +#undef CopyFile +#endif // CopyFile + namespace shaka { namespace media { diff --git a/packager/media/file/file_unittest.cc b/packager/media/file/file_unittest.cc index 6e6fb02bc4..72a4a1e58c 100644 --- a/packager/media/file/file_unittest.cc +++ b/packager/media/file/file_unittest.cc @@ -20,6 +20,8 @@ const int kDataSize = 1024; namespace shaka { namespace media { +using base::FilePath; + class LocalFileTest : public testing::Test { protected: void SetUp() override { @@ -29,7 +31,7 @@ class LocalFileTest : public testing::Test { // Test file path for file_util API. ASSERT_TRUE(base::CreateTemporaryFile(&test_file_path_)); - local_file_name_no_prefix_ = test_file_path_.value(); + local_file_name_no_prefix_ = test_file_path_.AsUTF8Unsafe(); // Local file name with prefix for File API. local_file_name_ = kLocalFilePrefix; @@ -38,13 +40,14 @@ class LocalFileTest : public testing::Test { void TearDown() override { // Remove test file if created. - base::DeleteFile(base::FilePath(local_file_name_no_prefix_), false); + base::DeleteFile(FilePath::FromUTF8Unsafe(local_file_name_no_prefix_), + false); } std::string data_; // Path to the temporary file for this test. - base::FilePath test_file_path_; + FilePath test_file_path_; // Same as |test_file_path_| but in string form. std::string local_file_name_no_prefix_; @@ -54,7 +57,8 @@ class LocalFileTest : public testing::Test { TEST_F(LocalFileTest, ReadNotExist) { // Remove test file if it exists. - base::DeleteFile(base::FilePath(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); } @@ -68,13 +72,16 @@ TEST_F(LocalFileTest, Copy) { ASSERT_EQ(kDataSize, base::WriteFile(test_file_path_, data_.data(), kDataSize)); - base::FilePath temp_dir; - ASSERT_TRUE(base::CreateNewTempDirectory("", &temp_dir)); + FilePath temp_dir; + ASSERT_TRUE(base::CreateNewTempDirectory(FilePath::StringType(), + &temp_dir)); // Copy the test file to temp dir as filename "a". - base::FilePath destination = temp_dir.Append("a"); + FilePath destination = + temp_dir.Append(FilePath::FromUTF8Unsafe("a")); ASSERT_TRUE( - File::Copy(local_file_name_.c_str(), destination.value().c_str())); + 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. diff --git a/packager/media/file/local_file.cc b/packager/media/file/local_file.cc index e59d7e0810..e1cf375416 100644 --- a/packager/media/file/local_file.cc +++ b/packager/media/file/local_file.cc @@ -7,15 +7,25 @@ #include "packager/media/file/local_file.h" #include - +#if defined(OS_WIN) +#include +#endif // defined(OS_WIN) #include "packager/base/files/file_util.h" #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; +} bool LocalFile::Close() { bool result = true; @@ -49,7 +59,8 @@ int64_t LocalFile::Size() { } int64_t file_size; - if (!base::GetFileSize(base::FilePath(file_name()), &file_size)) { + if (!base::GetFileSize(base::FilePath::FromUTF8Unsafe(file_name()), + &file_size)) { LOG(ERROR) << "Cannot get file size."; return -1; } @@ -62,14 +73,23 @@ bool LocalFile::Flush() { } bool LocalFile::Seek(uint64_t position) { +#if defined(OS_WIN) + return _fseeki64(internal_file_, static_cast<__int64>(position), + SEEK_SET) == 0; +#else return fseeko(internal_file_, position, SEEK_SET) >= 0; +#endif // !defined(OS_WIN) } bool LocalFile::Tell(uint64_t* position) { +#if defined(OS_WIN) + __int64 offset = _ftelli64(internal_file_); +#else off_t offset = ftello(internal_file_); +#endif // !defined(OS_WIN) if (offset < 0) return false; - *position = offset; + *position = static_cast(offset); return true; } @@ -77,12 +97,12 @@ LocalFile::~LocalFile() {} bool LocalFile::Open() { internal_file_ = - base::OpenFile(base::FilePath(file_name()), file_mode_.c_str()); + base::OpenFile(base::FilePath::FromUTF8Unsafe(file_name()), file_mode_.c_str()); return (internal_file_ != NULL); } bool LocalFile::Delete(const char* file_name) { - return base::DeleteFile(base::FilePath(file_name), false); + return base::DeleteFile(base::FilePath::FromUTF8Unsafe(file_name), false); } } // namespace media diff --git a/packager/media/formats/mp2t/es_parser_h26x_unittest.cc b/packager/media/formats/mp2t/es_parser_h26x_unittest.cc index 9a2f3aaaf9..06c1130d48 100644 --- a/packager/media/formats/mp2t/es_parser_h26x_unittest.cc +++ b/packager/media/formats/mp2t/es_parser_h26x_unittest.cc @@ -171,7 +171,7 @@ void EsParserH26xTest::RunTest(const H265NaluType* types, cur_sample_data.push_back(0); cur_sample_data.push_back(0); cur_sample_data.push_back(0); - cur_sample_data.push_back(es_data.size()); + cur_sample_data.push_back(static_cast(es_data.size())); cur_sample_data.insert(cur_sample_data.end(), es_data.begin(), es_data.end()); es_data.insert(es_data.begin(), kStartCode, diff --git a/packager/media/formats/mp2t/program_map_table_writer.cc b/packager/media/formats/mp2t/program_map_table_writer.cc index b5c56e264e..08649d4aed 100644 --- a/packager/media/formats/mp2t/program_map_table_writer.cc +++ b/packager/media/formats/mp2t/program_map_table_writer.cc @@ -378,7 +378,7 @@ bool AacProgramMapTableWriter::EncryptedSegmentPmtWithParameters( // -12 because there are 12 bytes between 'descriptor_length' in // registration_descriptor and 'setup_data_length' in audio_setup_information. if (aac_audio_specific_config_.size() > - std::numeric_limits::max() - 12) { + std::numeric_limits::max() - 12U) { LOG(ERROR) << "AACAudioSpecificConfig of size: " << aac_audio_specific_config_.size() << " will not fit in the descriptor."; diff --git a/packager/media/formats/mp2t/ts_writer_unittest.cc b/packager/media/formats/mp2t/ts_writer_unittest.cc index f5c7e83811..231993fb3a 100644 --- a/packager/media/formats/mp2t/ts_writer_unittest.cc +++ b/packager/media/formats/mp2t/ts_writer_unittest.cc @@ -108,7 +108,8 @@ class TsWriterTest : public ::testing::Test { void SetUp() override { base::CreateTemporaryFile(&test_file_path_); // TODO(rkuroiwa): Use memory file prefix once its exposed. - test_file_name_ = kLocalFilePrefix + test_file_path_.value(); + test_file_name_ = + std::string(kLocalFilePrefix) + test_file_path_.AsUTF8Unsafe(); } void TearDown() override { diff --git a/packager/media/formats/mp4/box_definitions.cc b/packager/media/formats/mp4/box_definitions.cc index 55b45cc226..8cc762c40c 100644 --- a/packager/media/formats/mp4/box_definitions.cc +++ b/packager/media/formats/mp4/box_definitions.cc @@ -46,7 +46,7 @@ const size_t kInvalidIvSize = 1; // According to ISO/IEC FDIS 23001-7: CENC spec, IV should be either // 64-bit (8-byte) or 128-bit (16-byte). // |per_sample_iv_size| of 0 means constant_iv is used. -bool IsIvSizeValid(size_t per_sample_iv_size) { +bool IsIvSizeValid(uint8_t per_sample_iv_size) { return per_sample_iv_size == 0 || per_sample_iv_size == 8 || per_sample_iv_size == 16; } @@ -251,7 +251,7 @@ bool SampleEncryptionEntry::ReadWrite(uint8_t iv_size, return true; } - uint16_t subsample_count = subsamples.size(); + uint16_t subsample_count = static_cast(subsamples.size()); RCHECK(buffer->ReadWriteUInt16(&subsample_count)); RCHECK(subsample_count > 0); subsamples.resize(subsample_count); @@ -289,7 +289,7 @@ bool SampleEncryptionEntry::ParseFromBuffer(uint8_t iv_size, uint32_t SampleEncryptionEntry::ComputeSize() const { const uint32_t subsample_entry_size = sizeof(uint16_t) + sizeof(uint32_t); - const uint16_t subsample_count = subsamples.size(); + const uint16_t subsample_count = static_cast(subsamples.size()); return initialization_vector.size() + (subsample_count > 0 ? (sizeof(subsample_count) + subsample_entry_size * subsample_count) @@ -331,7 +331,7 @@ bool SampleEncryption::ReadWriteInternal(BoxBuffer* buffer) { sample_encryption_entries.resize(sample_count); for (auto& sample_encryption_entry : sample_encryption_entries) { RCHECK(sample_encryption_entry.ReadWrite( - iv_size, flags & kUseSubsampleEncryption, buffer)); + iv_size, (flags & kUseSubsampleEncryption) != 0, buffer) != 0); } return true; } @@ -357,7 +357,7 @@ uint32_t SampleEncryption::ComputeSizeInternal() { } bool SampleEncryption::ParseFromSampleEncryptionData( - size_t iv_size, + uint8_t iv_size, std::vector* sample_encryption_entries) const { DCHECK(IsIvSizeValid(iv_size)); @@ -369,7 +369,7 @@ bool SampleEncryption::ParseFromSampleEncryptionData( sample_encryption_entries->resize(sample_count); for (auto& sample_encryption_entry : *sample_encryption_entries) { RCHECK(sample_encryption_entry.ParseFromBuffer( - iv_size, flags & kUseSubsampleEncryption, &reader)); + iv_size, (flags & kUseSubsampleEncryption) != 0, &reader) != 0); } return true; } @@ -439,7 +439,8 @@ bool TrackEncryption::ReadWriteInternal(BoxBuffer* buffer) { if (default_is_protected == 1) { if (default_per_sample_iv_size == 0) { // For constant iv. - uint8_t default_constant_iv_size = default_constant_iv.size(); + uint8_t default_constant_iv_size = + static_cast(default_constant_iv.size()); RCHECK(buffer->ReadWriteUInt8(&default_constant_iv_size)); RCHECK(default_constant_iv_size == 8 || default_constant_iv_size == 16); RCHECK(buffer->ReadWriteVector(&default_constant_iv, @@ -960,7 +961,7 @@ bool CencSampleEncryptionInfoEntry::ReadWrite(BoxBuffer* buffer) { if (is_protected == 1) { if (per_sample_iv_size == 0) { // For constant iv. - uint8_t constant_iv_size = constant_iv.size(); + uint8_t constant_iv_size = static_cast(constant_iv.size()); RCHECK(buffer->ReadWriteUInt8(&constant_iv_size)); RCHECK(constant_iv_size == 8 || constant_iv_size == 16); RCHECK(buffer->ReadWriteVector(&constant_iv, constant_iv_size)); @@ -2369,7 +2370,7 @@ bool TrackFragmentRun::ReadWriteInternal(BoxBuffer* buffer) { NOTIMPLEMENTED(); } - uint32_t first_sample_flags; + uint32_t first_sample_flags(0); if (buffer->Reading()) { if (first_sample_flags_present) @@ -2541,7 +2542,7 @@ bool SegmentIndex::ReadWriteInternal(BoxBuffer* buffer) { buffer->ReadWriteUInt64NBytes(&earliest_presentation_time, num_bytes) && buffer->ReadWriteUInt64NBytes(&first_offset, num_bytes)); - uint16_t reference_count = references.size(); + uint16_t reference_count = static_cast(references.size()); RCHECK(buffer->IgnoreBytes(2) && // reserved. buffer->ReadWriteUInt16(&reference_count)); references.resize(reference_count); diff --git a/packager/media/formats/mp4/box_definitions.h b/packager/media/formats/mp4/box_definitions.h index 7d3802827c..12b1b8f372 100644 --- a/packager/media/formats/mp4/box_definitions.h +++ b/packager/media/formats/mp4/box_definitions.h @@ -117,14 +117,14 @@ struct SampleEncryption : FullBox { /// entries. /// @return true on success, false otherwise. bool ParseFromSampleEncryptionData( - size_t iv_size, + uint8_t iv_size, std::vector* sample_encryption_entries) const; /// We may not know @a iv_size before reading this box. In this case, we will /// store sample encryption data for parsing later when @a iv_size is known. std::vector sample_encryption_data; - size_t iv_size; + uint8_t iv_size; std::vector sample_encryption_entries; }; diff --git a/packager/media/formats/mp4/box_definitions_unittest.cc b/packager/media/formats/mp4/box_definitions_unittest.cc index eb8328f956..2384f63641 100644 --- a/packager/media/formats/mp4/box_definitions_unittest.cc +++ b/packager/media/formats/mp4/box_definitions_unittest.cc @@ -452,7 +452,7 @@ class BoxDefinitionsTestGeneral : public testing::Test { void Modify(WebVTTConfigurationBox* vttc) { vttc->config = "WEBVTT\n" - "Region: id=someting width=40\% lines=3"; + "Region: id=someting width=40% lines=3"; } void Fill(WebVTTSourceLabelBox* vlab) { diff --git a/packager/media/formats/mp4/encrypting_fragmenter.cc b/packager/media/formats/mp4/encrypting_fragmenter.cc index 610d511316..6767f19c8b 100644 --- a/packager/media/formats/mp4/encrypting_fragmenter.cc +++ b/packager/media/formats/mp4/encrypting_fragmenter.cc @@ -173,8 +173,9 @@ void EncryptingFragmenter::FinalizeFragmentForEncryption() { traf()->auxiliary_offset.offsets.push_back(0); // For 'cbcs' scheme, Constant IVs SHALL be used. - const size_t per_sample_iv_size = - (protection_scheme_ == FOURCC_cbcs) ? 0 : encryptor_->iv().size(); + const uint8_t per_sample_iv_size = + (protection_scheme_ == FOURCC_cbcs) ? 0 : + static_cast(encryptor_->iv().size()); traf()->sample_encryption.iv_size = per_sample_iv_size; // Optimize saiz box. @@ -189,7 +190,7 @@ void EncryptingFragmenter::FinalizeFragmentForEncryption() { // |sample_info_sizes| table is filled in only for subsample encryption, // otherwise |sample_info_size| is just the IV size. DCHECK(!IsSubsampleEncryptionRequired()); - saiz.default_sample_info_size = per_sample_iv_size; + saiz.default_sample_info_size = static_cast(per_sample_iv_size); } // It should only happen with full sample encryption + constant iv, i.e. @@ -266,7 +267,8 @@ Status EncryptingFragmenter::EncryptSample(scoped_refptr sample) { const bool is_superframe = vpx_frames.size() > 1; for (const VPxFrameInfo& frame : vpx_frames) { SubsampleEntry subsample; - subsample.clear_bytes = frame.uncompressed_header_size; + subsample.clear_bytes = + static_cast(frame.uncompressed_header_size); subsample.cipher_bytes = frame.frame_size - frame.uncompressed_header_size; @@ -296,7 +298,7 @@ Status EncryptingFragmenter::EncryptSample(scoped_refptr sample) { DCHECK_LE(index_size, 2 + vpx_frames.size() * 4); DCHECK_GE(index_size, 2 + vpx_frames.size() * 1); SubsampleEntry subsample; - subsample.clear_bytes = index_size; + subsample.clear_bytes = static_cast(index_size); subsample.cipher_bytes = 0; sample_encryption_entry.subsamples.push_back(subsample); } diff --git a/packager/media/formats/mp4/key_rotation_fragmenter.cc b/packager/media/formats/mp4/key_rotation_fragmenter.cc index c5be9d778a..0249a2bfbf 100644 --- a/packager/media/formats/mp4/key_rotation_fragmenter.cc +++ b/packager/media/formats/mp4/key_rotation_fragmenter.cc @@ -52,7 +52,7 @@ Status KeyRotationFragmenter::PrepareFragmentForEncryption( bool enable_encryption) { bool need_to_refresh_encryptor = !encryptor(); - size_t current_crypto_period_index = + int64_t current_crypto_period_index = traf()->decode_time.decode_time / crypto_period_duration_; if (current_crypto_period_index != prev_crypto_period_index_) { scoped_ptr encryption_key(new EncryptionKey()); @@ -123,7 +123,8 @@ Status KeyRotationFragmenter::PrepareFragmentForEncryption( sample_group_entry.per_sample_iv_size = 0; sample_group_entry.constant_iv = encryptor()->iv(); } else { - sample_group_entry.per_sample_iv_size = encryptor()->iv().size(); + sample_group_entry.per_sample_iv_size = + static_cast(encryptor()->iv().size()); } sample_group_entry.crypt_byte_block = crypt_byte_block(); sample_group_entry.skip_byte_block = skip_byte_block(); diff --git a/packager/media/formats/mp4/key_rotation_fragmenter.h b/packager/media/formats/mp4/key_rotation_fragmenter.h index 00731c6c24..e496a8659c 100644 --- a/packager/media/formats/mp4/key_rotation_fragmenter.h +++ b/packager/media/formats/mp4/key_rotation_fragmenter.h @@ -66,7 +66,7 @@ class KeyRotationFragmenter : public EncryptingFragmenter { KeySource* encryption_key_source_; KeySource::TrackType track_type_; const int64_t crypto_period_duration_; - size_t prev_crypto_period_index_; + int64_t prev_crypto_period_index_; // For notifying new pssh boxes to the event handler. MuxerListener* const muxer_listener_; diff --git a/packager/media/formats/mp4/mp4_media_parser_unittest.cc b/packager/media/formats/mp4/mp4_media_parser_unittest.cc index f9963910e8..552ba67d85 100644 --- a/packager/media/formats/mp4/mp4_media_parser_unittest.cc +++ b/packager/media/formats/mp4/mp4_media_parser_unittest.cc @@ -99,7 +99,7 @@ class MP4MediaParserTest : public testing::Test { bool ParseMP4File(const std::string& filename, int append_bytes) { InitializeParser(NULL); - if (!parser_->LoadMoov(GetTestDataFilePath(filename).value())) + if (!parser_->LoadMoov(GetTestDataFilePath(filename).AsUTF8Unsafe())) return false; std::vector buffer = ReadTestDataFile(filename); return AppendDataInPieces(buffer.data(), buffer.size(), append_bytes); diff --git a/packager/media/formats/mp4/mp4_muxer.cc b/packager/media/formats/mp4/mp4_muxer.cc index 18ab3aacd9..3de6640c23 100644 --- a/packager/media/formats/mp4/mp4_muxer.cc +++ b/packager/media/formats/mp4/mp4_muxer.cc @@ -304,8 +304,8 @@ void MP4Muxer::GenerateAudioTrak(const AudioStreamInfo* audio_info, // values. const uint64_t kNanosecondsPerSecond = 1000000000ull; sample_group_description.audio_roll_recovery_entries[0].roll_distance = - -(audio_info->seek_preroll_ns() * audio.samplerate + - kNanosecondsPerSecond / 2) / + (0 - (audio_info->seek_preroll_ns() * audio.samplerate + + kNanosecondsPerSecond / 2)) / kNanosecondsPerSecond; sample_table.sample_to_groups.resize(1); diff --git a/packager/media/formats/mp4/segmenter.cc b/packager/media/formats/mp4/segmenter.cc index 5c0007e977..ec8cff6506 100644 --- a/packager/media/formats/mp4/segmenter.cc +++ b/packager/media/formats/mp4/segmenter.cc @@ -102,7 +102,8 @@ void GenerateSinf(const EncryptionKey& encryption_key, track_encryption.default_per_sample_iv_size = 0; track_encryption.default_constant_iv = encryption_key.iv; } else { - track_encryption.default_per_sample_iv_size = encryption_key.iv.size(); + track_encryption.default_per_sample_iv_size = + static_cast(encryption_key.iv.size()); } track_encryption.default_crypt_byte_block = pattern.crypt_byte_block; track_encryption.default_skip_byte_block = pattern.skip_byte_block; diff --git a/packager/media/formats/mp4/single_segment_segmenter.cc b/packager/media/formats/mp4/single_segment_segmenter.cc index 0d166ed322..25b8dd7ae7 100644 --- a/packager/media/formats/mp4/single_segment_segmenter.cc +++ b/packager/media/formats/mp4/single_segment_segmenter.cc @@ -83,10 +83,11 @@ Status SingleSegmentSegmenter::DoInitialize() { LOG(ERROR) << "Failed to create temporary file."; return Status(error::FILE_FAILURE, "Unable to create temporary file."); } - temp_file_name_ = temp_file_path.value(); + temp_file_name_ = temp_file_path.AsUTF8Unsafe(); } else { temp_file_name_ = - base::FilePath(options().temp_dir).Append(TempFileName()).value(); + base::FilePath::FromUTF8Unsafe(options().temp_dir) + .Append(base::FilePath::FromUTF8Unsafe(TempFileName())).AsUTF8Unsafe(); } temp_file_.reset(File::Open(temp_file_name_.c_str(), "w")); return temp_file_ diff --git a/packager/media/formats/webm/mkv_writer.cc b/packager/media/formats/webm/mkv_writer.cc index 256284d236..d77bcf74c5 100644 --- a/packager/media/formats/webm/mkv_writer.cc +++ b/packager/media/formats/webm/mkv_writer.cc @@ -57,7 +57,7 @@ int64_t MkvWriter::WriteFromFile(File* source) { return WriteFromFile(source, kWholeFile); } -int64_t MkvWriter::WriteFromFile(File* source, uint64_t max_copy) { +int64_t MkvWriter::WriteFromFile(File* source, int64_t max_copy) { DCHECK(file_); const int64_t size = File::CopyFile(source, file_.get(), max_copy); diff --git a/packager/media/formats/webm/mkv_writer.h b/packager/media/formats/webm/mkv_writer.h index aaaae56c0e..1b1a9cb9e6 100644 --- a/packager/media/formats/webm/mkv_writer.h +++ b/packager/media/formats/webm/mkv_writer.h @@ -56,7 +56,7 @@ class MkvWriter : public mkvmuxer::IMkvWriter { /// Writes the contents of the given file to this file, up to a maximum /// number of bytes. If @a max_copy is negative, will copy to EOF. /// @return The number of bytes written; or < 0 on error. - int64_t WriteFromFile(File* source, uint64_t max_copy); + int64_t WriteFromFile(File* source, int64_t max_copy); File* file() { return file_.get(); } 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 88036b3070..1b77bbf075 100644 --- a/packager/media/formats/webm/two_pass_single_segment_segmenter.cc +++ b/packager/media/formats/webm/two_pass_single_segment_segmenter.cc @@ -40,7 +40,8 @@ std::string TempFileName(const MuxerOptions& options) { } std::string file_prefix = base::StringPrintf("packager-tempfile-%x-%" PRIx64 ".tmp", tid, rand); - return base::FilePath(options.temp_dir).Append(file_prefix).value(); + return base::FilePath::FromUTF8Unsafe(options.temp_dir).Append( + base::FilePath::FromUTF8Unsafe(file_prefix)).AsUTF8Unsafe(); } // Skips a given number of bytes in a file by reading. This allows diff --git a/packager/media/formats/wvm/wvm_media_parser_unittest.cc b/packager/media/formats/wvm/wvm_media_parser_unittest.cc index 81ffcf318f..8cf1f66ba2 100644 --- a/packager/media/formats/wvm/wvm_media_parser_unittest.cc +++ b/packager/media/formats/wvm/wvm_media_parser_unittest.cc @@ -88,7 +88,7 @@ class WvmMediaParserTest : public testing::Test { int video_frame_count_; int encrypted_sample_count_; int64_t video_max_dts_; - uint32_t current_track_id_; + int32_t current_track_id_; EncryptionKey encryption_key_; void OnInit(const std::vector >& stream_infos) { @@ -103,7 +103,7 @@ class WvmMediaParserTest : public testing::Test { bool OnNewSample(uint32_t track_id, const scoped_refptr& sample) { std::string stream_type; - if (track_id != current_track_id_) { + if (static_cast(track_id) != current_track_id_) { // onto next track. video_max_dts_ = kNoTimestamp; current_track_id_ = track_id; diff --git a/packager/media/test/packager_test.cc b/packager/media/test/packager_test.cc index 1f0c840cb3..23112aa055 100644 --- a/packager/media/test/packager_test.cc +++ b/packager/media/test/packager_test.cc @@ -87,7 +87,8 @@ class PackagerTestBasic : public ::testing::TestWithParam { void SetUp() override { // Create a test directory for testing, will be deleted after test. - ASSERT_TRUE(base::CreateNewTempDirectory("packager_", &test_directory_)); + ASSERT_TRUE(base::CreateNewTempDirectory( + base::FilePath::FromUTF8Unsafe("packager_").value(), &test_directory_)); // Copy the input to test directory for easy reference. ASSERT_TRUE(base::CopyFile(GetTestDataFilePath(GetParam()), @@ -118,7 +119,8 @@ class PackagerTestBasic : public ::testing::TestWithParam { }; std::string PackagerTestBasic::GetFullPath(const std::string& file_name) { - return test_directory_.AppendASCII(file_name).value(); + return test_directory_.Append( + base::FilePath::FromUTF8Unsafe(file_name)).AsUTF8Unsafe(); } bool PackagerTestBasic::ContentsEqual(const std::string& file1, @@ -140,7 +142,7 @@ MuxerOptions PackagerTestBasic::SetupOptions(const std::string& output, options.output_file_name = GetFullPath(output); options.segment_template = GetFullPath(kSegmentTemplate); - options.temp_dir = test_directory_.value(); + options.temp_dir = test_directory_.AsUTF8Unsafe(); return options; } diff --git a/packager/media/test/run_tests_with_atexit_manager.cc b/packager/media/test/run_tests_with_atexit_manager.cc index 97b8f5a4ac..49d4424695 100644 --- a/packager/media/test/run_tests_with_atexit_manager.cc +++ b/packager/media/test/run_tests_with_atexit_manager.cc @@ -8,15 +8,27 @@ #include "packager/base/at_exit.h" #include "packager/base/command_line.h" +#include "packager/base/files/file_path.h" #include "packager/base/logging.h" +#include "packager/base/path_service.h" int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); + base::AtExitManager exit; // Needed to enable VLOG/DVLOG through --vmodule or --v. base::CommandLine::Init(argc, argv); - CHECK(logging::InitLogging(logging::LoggingSettings())); - base::AtExitManager exit; + // Set up logging. + logging::LoggingSettings log_settings; + base::FilePath log_filename; + PathService::Get(base::DIR_EXE, &log_filename); + log_filename = log_filename.AppendASCII("test.log"); + log_settings.logging_dest = logging::LOG_TO_ALL; + log_settings.log_file = log_filename.value().c_str(); + log_settings.delete_old = logging::DELETE_OLD_LOG_FILE; + CHECK(logging::InitLogging(log_settings)); + + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/packager/mpd/base/dash_iop_mpd_notifier_unittest.cc b/packager/mpd/base/dash_iop_mpd_notifier_unittest.cc index 54bae084b4..4c42a98bb9 100644 --- a/packager/mpd/base/dash_iop_mpd_notifier_unittest.cc +++ b/packager/mpd/base/dash_iop_mpd_notifier_unittest.cc @@ -101,7 +101,7 @@ class DashIopMpdNotifierTest void SetUp() override { ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path_)); - output_path_ = temp_file_path_.value(); + output_path_ = temp_file_path_.AsUTF8Unsafe(); ON_CALL(*default_mock_adaptation_set_, Group()) .WillByDefault(Return(kDefaultGroupId)); } diff --git a/packager/mpd/base/mpd_builder.cc b/packager/mpd/base/mpd_builder.cc index 8339084d0b..c783482548 100644 --- a/packager/mpd/base/mpd_builder.cc +++ b/packager/mpd/base/mpd_builder.cc @@ -332,8 +332,7 @@ std::string RoleToText(AdaptationSet::Role role) { case AdaptationSet::kRoleDub: return "dub"; default: - NOTREACHED(); - return ""; + break; } NOTREACHED(); @@ -653,8 +652,8 @@ void MpdBuilder::MakePathsRelativeToMpd(const std::string& mpd_path, : mpd_path; if (!mpd_file_path.empty()) { - std::string mpd_dir( - FilePath(mpd_file_path).DirName().AsEndingWithSeparator().value()); + std::string mpd_dir(FilePath::FromUTF8Unsafe(mpd_file_path) + .DirName().AsEndingWithSeparator().AsUTF8Unsafe()); if (!mpd_dir.empty()) { if (media_info->has_media_file_name()) { media_info->set_media_file_name( diff --git a/packager/mpd/base/mpd_builder_unittest.cc b/packager/mpd/base/mpd_builder_unittest.cc index e72e6ccb8d..52f4195f5b 100644 --- a/packager/mpd/base/mpd_builder_unittest.cc +++ b/packager/mpd/base/mpd_builder_unittest.cc @@ -194,14 +194,14 @@ class DynamicMpdBuilderTest : public MpdBuilderTest { // Injects a clock that always returns 2016 Jan 11 15:10:24 in UTC. void InjectTestClock() { - base::Time::Exploded test_time = {.year = 2016, - .month = 1, - .day_of_week = 1, // Monday. - .day_of_month = 11, - .hour = 15, - .minute = 10, - .second = 24, - .millisecond = 0}; + base::Time::Exploded test_time = { 2016, // year. + 1, // month + 1, // day_of_week = Monday. + 11, // day_of_month + 15, // hour. + 10, // minute. + 24, // second. + 0 }; // millisecond. ASSERT_TRUE(test_time.HasValidValues()); mpd_.InjectClockForTesting(scoped_ptr( new TestClock(base::Time::FromUTCExploded(test_time)))); @@ -1975,7 +1975,7 @@ TEST_F(StaticMpdBuilderTest, WriteToFile) { base::FilePath file_path; ASSERT_TRUE(base::CreateTemporaryFile(&file_path)); - media::File* file = media::File::Open(file_path.value().data(), "w"); + media::File* file = media::File::Open(file_path.AsUTF8Unsafe().c_str(), "w"); ASSERT_TRUE(file); ASSERT_TRUE(mpd_.WriteMpdToFile(file)); ASSERT_TRUE(file->Close()); @@ -2472,17 +2472,22 @@ TEST_F(TimeShiftBufferDepthTest, ManySegments) { } TEST(RelativePaths, PathsModified) { - const std::string kCommonPath(FilePath("foo").Append("bar").value()); + const FilePath kCommonPath( + FilePath::FromUTF8Unsafe("foo").Append(FilePath::FromUTF8Unsafe("bar"))); const std::string kMediaFileBase("media.mp4"); const std::string kInitSegmentBase("init.mp4"); const std::string kSegmentTemplateBase("segment-$Number$.mp4"); const std::string kMediaFile( - FilePath(kCommonPath).Append(kMediaFileBase).value()); + kCommonPath.Append(FilePath::FromUTF8Unsafe(kMediaFileBase)) + .AsUTF8Unsafe()); const std::string kInitSegment( - FilePath(kCommonPath).Append(kInitSegmentBase).value()); + kCommonPath.Append(FilePath::FromUTF8Unsafe(kInitSegmentBase)) + .AsUTF8Unsafe()); const std::string kSegmentTemplate( - FilePath(kCommonPath).Append(kSegmentTemplateBase).value()); - const std::string kMpd(FilePath(kCommonPath).Append("media.mpd").value()); + kCommonPath.Append(FilePath::FromUTF8Unsafe(kSegmentTemplateBase)) + .AsUTF8Unsafe()); + const std::string kMpd( + kCommonPath.Append(FilePath::FromUTF8Unsafe("media.mpd")).AsUTF8Unsafe()); MediaInfo media_info; media_info.set_media_file_name(kMediaFile); @@ -2495,18 +2500,24 @@ TEST(RelativePaths, PathsModified) { } TEST(RelativePaths, PathsNotModified) { - const std::string kMediaCommon(FilePath("foo").Append("bar").value()); + const FilePath kMediaCommon( + FilePath::FromUTF8Unsafe("foo").Append(FilePath::FromUTF8Unsafe("bar"))); const std::string kMediaFileBase("media.mp4"); const std::string kInitSegmentBase("init.mp4"); const std::string kSegmentTemplateBase("segment-$Number$.mp4"); const std::string kMediaFile( - FilePath(kMediaCommon).Append(kMediaFileBase).value()); + kMediaCommon.Append(FilePath::FromUTF8Unsafe(kMediaFileBase)) + .AsUTF8Unsafe()); const std::string kInitSegment( - FilePath(kMediaCommon).Append(kInitSegmentBase).value()); + kMediaCommon.Append(FilePath::FromUTF8Unsafe(kInitSegmentBase)) + .AsUTF8Unsafe()); const std::string kSegmentTemplate( - FilePath(kMediaCommon).Append(kSegmentTemplateBase).value()); - const std::string kMpd( - FilePath("foo").Append("baz").Append("media.mpd").value()); + kMediaCommon.Append(FilePath::FromUTF8Unsafe(kSegmentTemplateBase)) + .AsUTF8Unsafe()); + const std::string kMpd(FilePath::FromUTF8Unsafe("foo") + .Append(FilePath::FromUTF8Unsafe("baz")) + .Append(FilePath::FromUTF8Unsafe("media.mpd")) + .AsUTF8Unsafe()); MediaInfo media_info; media_info.set_media_file_name(kMediaFile); diff --git a/packager/mpd/base/simple_mpd_notifier_unittest.cc b/packager/mpd/base/simple_mpd_notifier_unittest.cc index 646fa445b3..4225e3dfb3 100644 --- a/packager/mpd/base/simple_mpd_notifier_unittest.cc +++ b/packager/mpd/base/simple_mpd_notifier_unittest.cc @@ -44,7 +44,7 @@ class SimpleMpdNotifierTest void SetUp() override { ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path_)); - output_path_ = temp_file_path_.value(); + output_path_ = temp_file_path_.AsUTF8Unsafe(); } void TearDown() override { diff --git a/packager/mpd/test/mpd_builder_test_helper.cc b/packager/mpd/test/mpd_builder_test_helper.cc index b66cd61b81..5dc25aeaee 100644 --- a/packager/mpd/test/mpd_builder_test_helper.cc +++ b/packager/mpd/test/mpd_builder_test_helper.cc @@ -78,7 +78,7 @@ bool ValidateMpdSchema(const std::string& mpd) { xml::scoped_xml_ptr schema_as_doc( xmlReadMemory(schema_str.data(), schema_str.size(), - schema_path.value().c_str(), + schema_path.AsUTF8Unsafe().c_str(), NULL, 0)); DCHECK(schema_as_doc); diff --git a/packager/mpd/util/mpd_writer_unittest.cc b/packager/mpd/util/mpd_writer_unittest.cc index 81389ddd82..a0ad5f3eef 100644 --- a/packager/mpd/util/mpd_writer_unittest.cc +++ b/packager/mpd/util/mpd_writer_unittest.cc @@ -92,14 +92,14 @@ TEST_F(MpdWriterTest, WriteMpdToFile) { GetTestDataFilePath(kFileNameVideoMediaInfo2); SetMpdNotifierFactoryForTest(); - EXPECT_TRUE(mpd_writer_.AddFile(media_info_file1.value(), "")); - EXPECT_TRUE(mpd_writer_.AddFile(media_info_file2.value(), "")); + EXPECT_TRUE(mpd_writer_.AddFile(media_info_file1.AsUTF8Unsafe(), "")); + EXPECT_TRUE(mpd_writer_.AddFile(media_info_file2.AsUTF8Unsafe(), "")); mpd_writer_.AddBaseUrl(kBaseUrl1); mpd_writer_.AddBaseUrl(kBaseUrl2); base::FilePath mpd_file_path; ASSERT_TRUE(base::CreateTemporaryFile(&mpd_file_path)); - EXPECT_TRUE(mpd_writer_.WriteMpdToFile(mpd_file_path.value().c_str())); + EXPECT_TRUE(mpd_writer_.WriteMpdToFile(mpd_file_path.AsUTF8Unsafe().c_str())); } } // namespace shaka diff --git a/packager/version/generate_version_string.py b/packager/version/generate_version_string.py index 214a7e36ee..b35caf403a 100755 --- a/packager/version/generate_version_string.py +++ b/packager/version/generate_version_string.py @@ -7,6 +7,7 @@ # https://developers.google.com/open-source/licenses/bsd """This script is used to generate version string for packager.""" +import platform import subprocess # To support python version before 2.7, which does not have @@ -30,9 +31,13 @@ if 'check_output' not in dir(subprocess): subprocess.check_output = check_output_implementation if __name__ == '__main__': + git = 'git' + if platform.system() == 'Windows': + git += '.bat' + try: version_tag = subprocess.check_output( - ['git', 'tag', '--points-at', 'HEAD'], + [git, 'tag', '--points-at', 'HEAD'], stderr=subprocess.STDOUT).rstrip() except subprocess.CalledProcessError as e: # git tag --points-at is not supported in old versions of git. Just ignore @@ -41,7 +46,7 @@ if __name__ == '__main__': try: version_hash = subprocess.check_output( - ['git', 'rev-parse', '--short', 'HEAD'], + [git, 'rev-parse', '--short', 'HEAD'], stderr=subprocess.STDOUT).rstrip() except subprocess.CalledProcessError as e: version_hash = 'unknown-version'