From 7cac9da4211e7c3a4f4c6fd6f7457e67b5a864b7 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Fri, 20 Mar 2015 19:18:38 -0700 Subject: [PATCH] Fix various misc build issues in Windows This is part of the effort to get edash_packager builds on Windows. Change-Id: I1339f8f41a30ad3d5808ab19276d46ee902065e2 --- packager/media/base/bit_reader.cc | 2 + packager/media/file/file.gyp | 12 ++++- .../file/{udp_file.cc => udp_file_posix.cc} | 0 packager/media/file/udp_file_win.cc | 51 +++++++++++++++++++ packager/media/formats/mp2t/adts_header.cc | 2 +- .../mp2t/mp2t_media_parser_unittest.cc | 5 +- packager/media/formats/mp4/mp4_muxer.cc | 2 +- packager/media/formats/mp4/segmenter.cc | 4 +- .../formats/mp4/single_segment_segmenter.cc | 15 ++++-- 9 files changed, 81 insertions(+), 12 deletions(-) rename packager/media/file/{udp_file.cc => udp_file_posix.cc} (100%) create mode 100644 packager/media/file/udp_file_win.cc diff --git a/packager/media/base/bit_reader.cc b/packager/media/base/bit_reader.cc index 8682849a39..5b1824e519 100644 --- a/packager/media/base/bit_reader.cc +++ b/packager/media/base/bit_reader.cc @@ -4,6 +4,8 @@ #include "packager/media/base/bit_reader.h" +#include + namespace edash_packager { namespace media { diff --git a/packager/media/file/file.gyp b/packager/media/file/file.gyp index 44fe1b0398..0a40a92321 100644 --- a/packager/media/file/file.gyp +++ b/packager/media/file/file.gyp @@ -22,9 +22,19 @@ 'local_file.h', 'threaded_io_file.cc', 'threaded_io_file.h', - 'udp_file.cc', 'udp_file.h', ], + 'conditions': [ + ['OS == "win"', { + 'sources': [ + 'udp_file_win.cc', + ], + }, { + 'sources': [ + 'udp_file_posix.cc', + ], + }], + ], 'dependencies': [ '../../base/base.gyp:base', '../../third_party/gflags/gflags.gyp:gflags', diff --git a/packager/media/file/udp_file.cc b/packager/media/file/udp_file_posix.cc similarity index 100% rename from packager/media/file/udp_file.cc rename to packager/media/file/udp_file_posix.cc diff --git a/packager/media/file/udp_file_win.cc b/packager/media/file/udp_file_win.cc new file mode 100644 index 0000000000..49a48beec6 --- /dev/null +++ b/packager/media/file/udp_file_win.cc @@ -0,0 +1,51 @@ +// Copyright 2015 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// 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/base/logging.h" + +namespace edash_packager { +namespace media { + +UdpFile::UdpFile(const char* file_name) : File(file_name), socket_(0) { +} + +UdpFile::~UdpFile() {} + +bool UdpFile::Close() { + NOTIMPLEMENTED(); + delete this; + return false; +} + +int64_t UdpFile::Read(void* buffer, uint64_t length) { + NOTIMPLEMENTED(); + return -1; +} + +int64_t UdpFile::Write(const void* buffer, uint64_t length) { + NOTIMPLEMENTED(); + return -1; +} + +int64_t UdpFile::Size() { + NOTIMPLEMENTED(); + return -1; +} + +bool UdpFile::Flush() { + NOTIMPLEMENTED(); + return false; +} + +bool UdpFile::Open() { + NOTIMPLEMENTED(); + return false; +} + +} // namespace media +} // namespace edash_packager diff --git a/packager/media/formats/mp2t/adts_header.cc b/packager/media/formats/mp2t/adts_header.cc index 887893beab..80f634c0c6 100644 --- a/packager/media/formats/mp2t/adts_header.cc +++ b/packager/media/formats/mp2t/adts_header.cc @@ -49,7 +49,7 @@ bool AdtsHeader::Parse(const uint8_t* adts_frame, size_t adts_frame_size) { // Skip MPEG version and layer. RCHECK(frame.SkipBits(3)); // Get "protection absent" flag. - bool protection_absent; + uint8_t protection_absent; RCHECK(frame.ReadBits(1, &protection_absent)); // Get profile. RCHECK(frame.ReadBits(2, &profile_)); diff --git a/packager/media/formats/mp2t/mp2t_media_parser_unittest.cc b/packager/media/formats/mp2t/mp2t_media_parser_unittest.cc index 90b55769ef..32c0732d66 100644 --- a/packager/media/formats/mp2t/mp2t_media_parser_unittest.cc +++ b/packager/media/formats/mp2t/mp2t_media_parser_unittest.cc @@ -145,9 +145,8 @@ TEST_F(Mp2tMediaParserTest, TimestampWrapAround) { ParseMpeg2TsFile("bear-1280x720_ptswraparound.ts", 512); parser_->Flush(); EXPECT_EQ(video_frame_count_, 82); - EXPECT_GE(video_min_dts_, (95443 - 1) * kMpeg2Timescale); - EXPECT_LE(video_max_dts_, - static_cast((95443 + 4)) * kMpeg2Timescale); + EXPECT_GE(video_min_dts_, static_cast(95443 - 1) * kMpeg2Timescale); + EXPECT_LE(video_max_dts_, static_cast(95443 + 4) * kMpeg2Timescale); } } // namespace mp2t diff --git a/packager/media/formats/mp4/mp4_muxer.cc b/packager/media/formats/mp4/mp4_muxer.cc index ba6721c4c8..e9f0063a9d 100644 --- a/packager/media/formats/mp4/mp4_muxer.cc +++ b/packager/media/formats/mp4/mp4_muxer.cc @@ -248,7 +248,7 @@ void MP4Muxer::FireOnMediaStartEvent() { stream_info_vec, timescale, event::MuxerListener::kContainerMp4, - encryption_key_source()); + encryption_key_source() != NULL); } void MP4Muxer::FireOnMediaEndEvent() { diff --git a/packager/media/formats/mp4/segmenter.cc b/packager/media/formats/mp4/segmenter.cc index f4b479ffb0..1fb757cec4 100644 --- a/packager/media/formats/mp4/segmenter.cc +++ b/packager/media/formats/mp4/segmenter.cc @@ -336,7 +336,7 @@ Status Segmenter::FinalizeFragment(Fragmenter* fragmenter) { // Fill in data offsets. Data offset base is moof size + mdat box size. // (mdat is still empty, mdat size is the same as mdat box size). uint64_t base = moof_->ComputeSize() + mdat.ComputeSize(); - for (uint i = 0; i < moof_->tracks.size(); ++i) { + for (size_t i = 0; i < moof_->tracks.size(); ++i) { TrackFragment& traf = moof_->tracks[i]; Fragmenter* fragmenter = fragmenters_[i]; if (fragmenter->aux_data()->Size() > 0) { @@ -356,7 +356,7 @@ Status Segmenter::FinalizeFragment(Fragmenter* fragmenter) { // Write the fragment to buffer. moof_->Write(fragment_buffer_.get()); - for (uint i = 0; i < moof_->tracks.size(); ++i) { + for (size_t i = 0; i < moof_->tracks.size(); ++i) { Fragmenter* fragmenter = fragmenters_[i]; mdat.data_size = fragmenter->aux_data()->Size() + fragmenter->data()->Size(); diff --git a/packager/media/formats/mp4/single_segment_segmenter.cc b/packager/media/formats/mp4/single_segment_segmenter.cc index 74cf3218d9..f59706ec2d 100644 --- a/packager/media/formats/mp4/single_segment_segmenter.cc +++ b/packager/media/formats/mp4/single_segment_segmenter.cc @@ -7,9 +7,12 @@ #include "packager/media/formats/mp4/single_segment_segmenter.h" #include +#include +#include #include "packager/base/file_util.h" #include "packager/base/strings/stringprintf.h" +#include "packager/base/threading/platform_thread.h" #include "packager/base/time/time.h" #include "packager/media/base/buffer_writer.h" #include "packager/media/base/media_stream.h" @@ -24,10 +27,14 @@ namespace mp4 { namespace { // Create a temp file name using process/thread id and current time. std::string TempFileName() { - int32_t tid = static_cast(pthread_self()); - int32_t pid = static_cast(getpid()); - int64_t now = base::Time::Now().ToInternalValue(); - return base::StringPrintf("packager-tempfile-%x-%d-%" PRIx64, tid, pid, now); + int32_t tid = static_cast(base::PlatformThread::CurrentId()); + int64_t rand = 0; + if (RAND_bytes(reinterpret_cast(&rand), sizeof(rand)) != 1) { + LOG(WARNING) << "RAND_bytes failed with error: " + << ERR_error_string(ERR_get_error(), NULL); + rand = base::Time::Now().ToInternalValue(); + } + return base::StringPrintf("packager-tempfile-%x-%" PRIx64, tid, rand); } } // namespace