Change output messages to make it more human readable

Also remove formatting using stream which is not recommended per Google
C++ style guide.

Change-Id: I3930f0a453acc0258876c08c4266dcbb13757ac8
This commit is contained in:
Kongqun Yang 2014-03-05 15:15:22 -08:00
parent 5f3c0f7181
commit c1a7fd9c4a
9 changed files with 146 additions and 50 deletions

View File

@ -35,9 +35,9 @@ const char kUsage[] =
namespace media { namespace media {
void DumpStreamInfo(const std::vector<MediaStream*>& streams) { void DumpStreamInfo(const std::vector<MediaStream*>& 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) 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. // Create and initialize encryptor source.
@ -47,15 +47,15 @@ scoped_ptr<EncryptorSource> CreateEncryptorSource() {
std::string rsa_private_key; std::string rsa_private_key;
if (!File::ReadFileToString(FLAGS_signing_key_path.c_str(), if (!File::ReadFileToString(FLAGS_signing_key_path.c_str(),
&rsa_private_key)) { &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<EncryptorSource>(); return scoped_ptr<EncryptorSource>();
} }
scoped_ptr<RequestSigner> signer( scoped_ptr<RequestSigner> signer(
RsaRequestSigner::CreateSigner(FLAGS_signer, rsa_private_key)); RsaRequestSigner::CreateSigner(FLAGS_signer, rsa_private_key));
if (!signer) { if (!signer) {
LOG(ERROR) << "Cannot create signer object from " LOG(ERROR) << "Cannot create signer object from '"
<< FLAGS_signing_key_path; << FLAGS_signing_key_path << "'.";
return scoped_ptr<EncryptorSource>(); return scoped_ptr<EncryptorSource>();
} }
@ -222,7 +222,7 @@ bool RunPackager(const std::string& input) {
return false; return false;
} }
std::cout << "Packaging completed successfully." << std::endl; printf("Packaging completed successfully.\n");
return true; return true;
} }

View File

@ -6,14 +6,49 @@
#include "media/base/audio_stream_info.h" #include "media/base/audio_stream_info.h"
#include <sstream>
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "media/base/limits.h" #include "media/base/limits.h"
namespace media { 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, AudioStreamInfo::AudioStreamInfo(int track_id,
uint32 time_scale, uint32 time_scale,
uint64 duration, uint64 duration,
@ -51,13 +86,14 @@ bool AudioStreamInfo::IsValidConfig() const {
} }
std::string AudioStreamInfo::ToString() const { std::string AudioStreamInfo::ToString() const {
std::ostringstream s; return base::StringPrintf(
s << "codec: " << codec_ "%s codec: %s\n sample_bits: %d\n num_channels: %d\n "
<< " sample_bits: " << static_cast<int>(sample_bits_) "sampling_frequency: %d\n",
<< " num_channels: " << static_cast<int>(num_channels_) StreamInfo::ToString().c_str(),
<< " sampling_frequency: " << sampling_frequency_ AudioCodecToString(codec_).c_str(),
<< " " << StreamInfo::ToString(); sample_bits_,
return s.str(); num_channels_,
sampling_frequency_);
} }
std::string AudioStreamInfo::GetCodecString(AudioCodec codec, std::string AudioStreamInfo::GetCodecString(AudioCodec codec,

View File

@ -6,10 +6,48 @@
#include "media/base/status.h" #include "media/base/status.h"
#include <sstream> #include "base/strings/stringprintf.h"
namespace media { 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::OK = Status(error::OK, "");
const Status& Status::UNKNOWN = Status(error::UNKNOWN, ""); const Status& Status::UNKNOWN = Status(error::UNKNOWN, "");
@ -17,9 +55,10 @@ std::string Status::ToString() const {
if (error_code_ == error::OK) if (error_code_ == error::OK)
return "OK"; return "OK";
std::ostringstream string_stream; return base::StringPrintf("%d (%s): %s",
string_stream << error_code_ << ":" << error_message_; error_code_,
return string_stream.str(); error::ErrorCodeToString(error_code_).c_str(),
error_message_.c_str());
} }
std::ostream& operator<<(std::ostream& os, const Status& x) { std::ostream& operator<<(std::ostream& os, const Status& x) {

View File

@ -6,8 +6,7 @@
#include "media/base/status.h" #include "media/base/status.h"
#include <sstream> #include "base/strings/string_number_conversions.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
@ -25,10 +24,7 @@ static void CheckStatus(const Status& s,
} else { } else {
EXPECT_TRUE(!s.ok()); EXPECT_TRUE(!s.ok());
EXPECT_THAT(s.ToString(), testing::HasSubstr(message)); EXPECT_THAT(s.ToString(), testing::HasSubstr(message));
EXPECT_THAT(s.ToString(), testing::HasSubstr(base::UintToString(code)));
std::ostringstream string_stream;
string_stream << code << ":" << message;
EXPECT_EQ(string_stream.str(), s.ToString());
} }
} }

View File

@ -7,6 +7,7 @@
#include "media/base/stream_info.h" #include "media/base/stream_info.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/stringprintf.h"
namespace media { namespace media {
@ -34,15 +35,16 @@ StreamInfo::StreamInfo(StreamType stream_type,
StreamInfo::~StreamInfo() {} StreamInfo::~StreamInfo() {}
std::string StreamInfo::ToString() const { std::string StreamInfo::ToString() const {
std::ostringstream s; return base::StringPrintf(
s << "type: " << (stream_type_ == kStreamAudio ? "Audio" : "Video") "type: %s\n codec_string: %s\n time_scale: %d\n duration: %d "
<< " track_id: " << track_id_ "(%.1f seconds)\n language: %s\n is_encrypted: %s\n",
<< " time_scale: " << time_scale_ (stream_type_ == kStreamAudio ? "Audio" : "Video"),
<< " duration: " << duration_ codec_string_.c_str(),
<< " codec_string: " << codec_string_ time_scale_,
<< " language: " << language_ duration_,
<< " is_encrypted: " << is_encrypted_; static_cast<double>(duration_) / time_scale_,
return s.str(); language_.c_str(),
is_encrypted_ ? "true" : "false");
} }
} // namespace media } // namespace media

View File

@ -6,14 +6,37 @@
#include "media/base/video_stream_info.h" #include "media/base/video_stream_info.h"
#include <sstream>
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "media/base/limits.h" #include "media/base/limits.h"
namespace media { 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, VideoStreamInfo::VideoStreamInfo(int track_id,
uint32 time_scale, uint32 time_scale,
uint64 duration, uint64 duration,
@ -50,13 +73,13 @@ bool VideoStreamInfo::IsValidConfig() const {
} }
std::string VideoStreamInfo::ToString() const { std::string VideoStreamInfo::ToString() const {
std::ostringstream s; return base::StringPrintf(
s << "codec: " << codec_ "%s codec: %s\n width: %d\n height: %d\n nalu_length_size: %d\n",
<< " width: " << width_ StreamInfo::ToString().c_str(),
<< " height: " << height_ VideoCodecToString(codec_).c_str(),
<< " nalu_length_size_: " << static_cast<int>(nalu_length_size_) width_,
<< " " << StreamInfo::ToString(); height_,
return s.str(); nalu_length_size_);
} }
std::string VideoStreamInfo::GetCodecString(VideoCodec codec, std::string VideoStreamInfo::GetCodecString(VideoCodec codec,
@ -74,7 +97,7 @@ std::string VideoStreamInfo::GetCodecString(VideoCodec codec,
StringToLowerASCII(base::HexEncode(bytes, arraysize(bytes))); StringToLowerASCII(base::HexEncode(bytes, arraysize(bytes)));
} }
default: default:
NOTIMPLEMENTED() << "Codec: " << codec; NOTIMPLEMENTED() << "Unknown Codec: " << codec;
return "unknown"; return "unknown";
} }
} }

View File

@ -123,8 +123,8 @@ bool MP4MediaParser::ParseBox(bool* err) {
// before the head of the 'moof', so keeping this box around is sufficient.) // before the head of the 'moof', so keeping this box around is sufficient.)
return !(*err); return !(*err);
} else { } else {
LOG(WARNING) << "Skipping unrecognized top-level box: " DLOG(WARNING) << "Skipping unrecognized top-level box: "
<< FourCCToString(reader->type()); << FourCCToString(reader->type());
} }
queue_.Pop(reader->size()); queue_.Pop(reader->size());

View File

@ -148,8 +148,8 @@ bool TrackRunIterator::Init() {
if (edits.size() > 1) if (edits.size() > 1)
DVLOG(1) << "Multi-entry edit box detected."; DVLOG(1) << "Multi-entry edit box detected.";
LOG(INFO) << "Edit list with media time " << edits[0].media_time DLOG(INFO) << "Edit list with media time " << edits[0].media_time
<< " ignored."; << " ignored.";
} }
DecodingTimeIterator decoding_time( DecodingTimeIterator decoding_time(

View File

@ -296,9 +296,9 @@ TEST_P(PackagerTest, MP4MuxerMultipleSegmentsUnencrypted) {
EXPECT_TRUE(ContentsEqual(kOutputVideo, kOutputVideo2)); EXPECT_TRUE(ContentsEqual(kOutputVideo, kOutputVideo2));
} }
INSTANTIATE_TEST_CASE_P(PackagerE2ETest, INSTANTIATE_TEST_CASE_P(PackagerEndToEnd,
PackagerTestBasic, PackagerTestBasic,
ValuesIn(kMediaFiles)); ValuesIn(kMediaFiles));
INSTANTIATE_TEST_CASE_P(PackagerE2ETest, PackagerTest, ValuesIn(kMediaFiles)); INSTANTIATE_TEST_CASE_P(PackagerEndToEnd, PackagerTest, ValuesIn(kMediaFiles));
} // namespace media } // namespace media