diff --git a/app/packager_main.cc b/app/packager_main.cc index 7e36e3ac07..455f4c5f6b 100644 --- a/app/packager_main.cc +++ b/app/packager_main.cc @@ -35,9 +35,9 @@ const char kUsage[] = namespace media { void DumpStreamInfo(const std::vector& streams) { - std::cout << "Found " << streams.size() << " stream(s)." << std::endl; + printf("Found %d stream(s).\n", streams.size()); for (size_t i = 0; i < streams.size(); ++i) - std::cout << "Stream [" << i << "] " << streams[i]->ToString() << std::endl; + printf("Stream [%d] %s\n", i, streams[i]->info()->ToString().c_str()); } // Create and initialize encryptor source. @@ -47,15 +47,15 @@ scoped_ptr CreateEncryptorSource() { std::string rsa_private_key; if (!File::ReadFileToString(FLAGS_signing_key_path.c_str(), &rsa_private_key)) { - LOG(ERROR) << "Failed to read from rsa_key_file."; + LOG(ERROR) << "Failed to read from '" << FLAGS_signing_key_path << "'."; return scoped_ptr(); } scoped_ptr signer( RsaRequestSigner::CreateSigner(FLAGS_signer, rsa_private_key)); if (!signer) { - LOG(ERROR) << "Cannot create signer object from " - << FLAGS_signing_key_path; + LOG(ERROR) << "Cannot create signer object from '" + << FLAGS_signing_key_path << "'."; return scoped_ptr(); } @@ -222,7 +222,7 @@ bool RunPackager(const std::string& input) { return false; } - std::cout << "Packaging completed successfully." << std::endl; + printf("Packaging completed successfully.\n"); return true; } diff --git a/media/base/audio_stream_info.cc b/media/base/audio_stream_info.cc index 7d0b6350fc..38eb2e1bf3 100644 --- a/media/base/audio_stream_info.cc +++ b/media/base/audio_stream_info.cc @@ -6,14 +6,49 @@ #include "media/base/audio_stream_info.h" -#include - #include "base/logging.h" #include "base/strings/string_number_conversions.h" +#include "base/strings/stringprintf.h" #include "media/base/limits.h" namespace media { +namespace { +std::string AudioCodecToString(AudioCodec audio_codec) { + switch (audio_codec) { + case kCodecAAC: + return "AAC"; + case kCodecMP3: + return "MP3"; + case kCodecPCM: + return "PCM"; + case kCodecVorbis: + return "Vorbis"; + case kCodecFLAC: + return "FLAC"; + case kCodecAMR_NB: + return "AMR_NB"; + case kCodecAMR_WB: + return "AMR_WB"; + case kCodecPCM_MULAW: + return "PCM_MULAW"; + case kCodecGSM_MS: + return "GSM_MS"; + case kCodecPCM_S16BE: + return "PCM_S16BE"; + case kCodecPCM_S24BE: + return "PCM_S24BE"; + case kCodecOpus: + return "Opus"; + case kCodecEAC3: + return "EAC3"; + default: + NOTIMPLEMENTED() << "Unknown Audio Codec: " << audio_codec; + return "UnknownAudioCodec"; + } +} +} // namespace + AudioStreamInfo::AudioStreamInfo(int track_id, uint32 time_scale, uint64 duration, @@ -51,13 +86,14 @@ bool AudioStreamInfo::IsValidConfig() const { } std::string AudioStreamInfo::ToString() const { - std::ostringstream s; - s << "codec: " << codec_ - << " sample_bits: " << static_cast(sample_bits_) - << " num_channels: " << static_cast(num_channels_) - << " sampling_frequency: " << sampling_frequency_ - << " " << StreamInfo::ToString(); - return s.str(); + return base::StringPrintf( + "%s codec: %s\n sample_bits: %d\n num_channels: %d\n " + "sampling_frequency: %d\n", + StreamInfo::ToString().c_str(), + AudioCodecToString(codec_).c_str(), + sample_bits_, + num_channels_, + sampling_frequency_); } std::string AudioStreamInfo::GetCodecString(AudioCodec codec, diff --git a/media/base/status.cc b/media/base/status.cc index 05bdf7e3d6..d21059a779 100644 --- a/media/base/status.cc +++ b/media/base/status.cc @@ -6,10 +6,48 @@ #include "media/base/status.h" -#include +#include "base/strings/stringprintf.h" namespace media { +namespace error { +namespace { +std::string ErrorCodeToString(Code error_code) { + switch (error_code) { + case OK: + return "OK"; + case UNKNOWN: + return "UNKNOWN"; + case CANCELLED: + return "CANCELLED"; + case INVALID_ARGUMENT: + return "INVALID_ARGUMENT"; + case UNIMPLEMENTED: + return "UNIMPLEMENTED"; + case FILE_FAILURE: + return "FILE_FAILURE"; + case END_OF_STREAM: + return "END_OF_STREAM"; + case HTTP_FAILURE: + return "HTTP_FAILURE"; + case PARSER_FAILURE: + return "PARSER_FAILURE"; + case MUXER_FAILURE: + return "MUXER_FAILURE"; + case FRAGMENT_FINALIZED: + return "FRAGMENT_FINALIZED"; + case SERVER_ERROR: + return "SERVER_ERROR"; + case INTERNAL_ERROR: + return "INTERNAL_ERROR"; + default: + NOTIMPLEMENTED() << "Unknown Status Code: " << error_code; + return "UNKNOWN_STATUS"; + } +} +} // namespace +} // namespace error + const Status& Status::OK = Status(error::OK, ""); const Status& Status::UNKNOWN = Status(error::UNKNOWN, ""); @@ -17,9 +55,10 @@ std::string Status::ToString() const { if (error_code_ == error::OK) return "OK"; - std::ostringstream string_stream; - string_stream << error_code_ << ":" << error_message_; - return string_stream.str(); + return base::StringPrintf("%d (%s): %s", + error_code_, + error::ErrorCodeToString(error_code_).c_str(), + error_message_.c_str()); } std::ostream& operator<<(std::ostream& os, const Status& x) { diff --git a/media/base/status_unittest.cc b/media/base/status_unittest.cc index 480babdbf0..b22e3fea28 100644 --- a/media/base/status_unittest.cc +++ b/media/base/status_unittest.cc @@ -6,8 +6,7 @@ #include "media/base/status.h" -#include - +#include "base/strings/string_number_conversions.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -25,10 +24,7 @@ static void CheckStatus(const Status& s, } else { EXPECT_TRUE(!s.ok()); EXPECT_THAT(s.ToString(), testing::HasSubstr(message)); - - std::ostringstream string_stream; - string_stream << code << ":" << message; - EXPECT_EQ(string_stream.str(), s.ToString()); + EXPECT_THAT(s.ToString(), testing::HasSubstr(base::UintToString(code))); } } diff --git a/media/base/stream_info.cc b/media/base/stream_info.cc index ccba8543c2..f14fda23ae 100644 --- a/media/base/stream_info.cc +++ b/media/base/stream_info.cc @@ -7,6 +7,7 @@ #include "media/base/stream_info.h" #include "base/logging.h" +#include "base/strings/stringprintf.h" namespace media { @@ -34,15 +35,16 @@ StreamInfo::StreamInfo(StreamType stream_type, StreamInfo::~StreamInfo() {} std::string StreamInfo::ToString() const { - std::ostringstream s; - s << "type: " << (stream_type_ == kStreamAudio ? "Audio" : "Video") - << " track_id: " << track_id_ - << " time_scale: " << time_scale_ - << " duration: " << duration_ - << " codec_string: " << codec_string_ - << " language: " << language_ - << " is_encrypted: " << is_encrypted_; - return s.str(); + return base::StringPrintf( + "type: %s\n codec_string: %s\n time_scale: %d\n duration: %d " + "(%.1f seconds)\n language: %s\n is_encrypted: %s\n", + (stream_type_ == kStreamAudio ? "Audio" : "Video"), + codec_string_.c_str(), + time_scale_, + duration_, + static_cast(duration_) / time_scale_, + language_.c_str(), + is_encrypted_ ? "true" : "false"); } } // namespace media diff --git a/media/base/video_stream_info.cc b/media/base/video_stream_info.cc index 2e33885fdc..d7d05b4aa4 100644 --- a/media/base/video_stream_info.cc +++ b/media/base/video_stream_info.cc @@ -6,14 +6,37 @@ #include "media/base/video_stream_info.h" -#include - #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" +#include "base/strings/stringprintf.h" #include "media/base/limits.h" namespace media { +namespace { +std::string VideoCodecToString(VideoCodec video_codec) { + switch (video_codec) { + case kCodecH264: + return "H264"; + case kCodecVC1: + return "VC1"; + case kCodecMPEG2: + return "MPEG2"; + case kCodecMPEG4: + return "MPEG4"; + case kCodecTheora: + return "Theora"; + case kCodecVP8: + return "VP8"; + case kCodecVP9: + return "VP9"; + default: + NOTIMPLEMENTED() << "Unknown Video Codec: " << video_codec; + return "UnknownVideoCodec"; + } +} +} // namespace + VideoStreamInfo::VideoStreamInfo(int track_id, uint32 time_scale, uint64 duration, @@ -50,13 +73,13 @@ bool VideoStreamInfo::IsValidConfig() const { } std::string VideoStreamInfo::ToString() const { - std::ostringstream s; - s << "codec: " << codec_ - << " width: " << width_ - << " height: " << height_ - << " nalu_length_size_: " << static_cast(nalu_length_size_) - << " " << StreamInfo::ToString(); - return s.str(); + return base::StringPrintf( + "%s codec: %s\n width: %d\n height: %d\n nalu_length_size: %d\n", + StreamInfo::ToString().c_str(), + VideoCodecToString(codec_).c_str(), + width_, + height_, + nalu_length_size_); } std::string VideoStreamInfo::GetCodecString(VideoCodec codec, @@ -74,7 +97,7 @@ std::string VideoStreamInfo::GetCodecString(VideoCodec codec, StringToLowerASCII(base::HexEncode(bytes, arraysize(bytes))); } default: - NOTIMPLEMENTED() << "Codec: " << codec; + NOTIMPLEMENTED() << "Unknown Codec: " << codec; return "unknown"; } } diff --git a/media/mp4/mp4_media_parser.cc b/media/mp4/mp4_media_parser.cc index ca31fb19c7..25d9cf48fd 100644 --- a/media/mp4/mp4_media_parser.cc +++ b/media/mp4/mp4_media_parser.cc @@ -123,8 +123,8 @@ bool MP4MediaParser::ParseBox(bool* err) { // before the head of the 'moof', so keeping this box around is sufficient.) return !(*err); } else { - LOG(WARNING) << "Skipping unrecognized top-level box: " - << FourCCToString(reader->type()); + DLOG(WARNING) << "Skipping unrecognized top-level box: " + << FourCCToString(reader->type()); } queue_.Pop(reader->size()); diff --git a/media/mp4/track_run_iterator.cc b/media/mp4/track_run_iterator.cc index 182a8850aa..cecc953f24 100644 --- a/media/mp4/track_run_iterator.cc +++ b/media/mp4/track_run_iterator.cc @@ -148,8 +148,8 @@ bool TrackRunIterator::Init() { if (edits.size() > 1) DVLOG(1) << "Multi-entry edit box detected."; - LOG(INFO) << "Edit list with media time " << edits[0].media_time - << " ignored."; + DLOG(INFO) << "Edit list with media time " << edits[0].media_time + << " ignored."; } DecodingTimeIterator decoding_time( diff --git a/media/test/packager_test.cc b/media/test/packager_test.cc index 11a09976a7..16f81df502 100644 --- a/media/test/packager_test.cc +++ b/media/test/packager_test.cc @@ -296,9 +296,9 @@ TEST_P(PackagerTest, MP4MuxerMultipleSegmentsUnencrypted) { EXPECT_TRUE(ContentsEqual(kOutputVideo, kOutputVideo2)); } -INSTANTIATE_TEST_CASE_P(PackagerE2ETest, +INSTANTIATE_TEST_CASE_P(PackagerEndToEnd, PackagerTestBasic, ValuesIn(kMediaFiles)); -INSTANTIATE_TEST_CASE_P(PackagerE2ETest, PackagerTest, ValuesIn(kMediaFiles)); +INSTANTIATE_TEST_CASE_P(PackagerEndToEnd, PackagerTest, ValuesIn(kMediaFiles)); } // namespace media