From b34b997bcbcf0a2b8c2a2cd164cadc57b4c55651 Mon Sep 17 00:00:00 2001 From: Kongqun Yang Date: Mon, 31 Mar 2014 15:25:45 -0700 Subject: [PATCH] Some more clean ups in media/base 1. Use size_t for MediaSample size; 2. Get rid of stringstream in media_sample.cc and media_stream.cc. Change-Id: I11fe650305a732ae6a18546ac68692e03ecedae4 --- media/base/media_sample.cc | 35 +++++++++++++++-------------------- media/base/media_sample.h | 14 +++++++------- media/base/media_stream.cc | 13 ++++++------- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/media/base/media_sample.cc b/media/base/media_sample.cc index 9448ddae9b..74e0cb023e 100644 --- a/media/base/media_sample.cc +++ b/media/base/media_sample.cc @@ -7,18 +7,19 @@ #include "media/base/media_sample.h" #include "base/logging.h" +#include "base/strings/stringprintf.h" #include "media/base/decrypt_config.h" namespace media { MediaSample::MediaSample(const uint8* data, - int size, + size_t size, const uint8* side_data, - int side_data_size, + size_t side_data_size, bool is_key_frame) : dts_(0), pts_(0), duration_(0), is_key_frame_(is_key_frame) { if (!data) { - CHECK_EQ(size, 0); + CHECK_EQ(size, 0u); CHECK(!side_data); return; } @@ -32,19 +33,19 @@ MediaSample::~MediaSample() {} // static scoped_refptr MediaSample::CopyFrom(const uint8* data, - int data_size, + size_t data_size, bool is_key_frame) { // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. CHECK(data); return make_scoped_refptr( - new MediaSample(data, data_size, NULL, 0, is_key_frame)); + new MediaSample(data, data_size, NULL, 0u, is_key_frame)); } // static scoped_refptr MediaSample::CopyFrom(const uint8* data, - int data_size, + size_t data_size, const uint8* side_data, - int side_data_size, + size_t side_data_size, bool is_key_frame) { // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. CHECK(data); @@ -58,19 +59,13 @@ scoped_refptr MediaSample::CreateEOSBuffer() { } std::string MediaSample::ToString() const { - if (end_of_stream()) { - return "end of stream"; - } - - std::ostringstream s; - s << "dts: " << dts_ - << " pts: " << pts_ - << " duration: " << duration_ - << " is_key_frame: " << is_key_frame_ - << " size: " << data_.size() - << " side_data_size: " << side_data_.size() - << " encrypted: " << (decrypt_config_ != NULL); - return s.str(); + if (end_of_stream()) + return "End of stream sample\n"; + return base::StringPrintf( + "dts: %ld\n pts: %ld\n duration: %ld\n is_key_frame: %s\n size: %zu\n " + "side_data_size: %zu\n is_encrypted: %s\n", + dts_, pts_, duration_, is_key_frame_ ? "true" : "false", data_.size(), + side_data_.size(), decrypt_config_ ? "true" : "false"); } } // namespace media diff --git a/media/base/media_sample.h b/media/base/media_sample.h index e17b011153..4047f2702d 100644 --- a/media/base/media_sample.h +++ b/media/base/media_sample.h @@ -29,7 +29,7 @@ class MediaSample : public base::RefCountedThreadSafe { /// @param size indicates sample size in bytes. Must not be negative. /// @param is_key_frame indicates whether the sample is a key frame. static scoped_refptr CopyFrom(const uint8* data, - int size, + size_t size, bool is_key_frame); /// Create a MediaSample object from input. @@ -43,9 +43,9 @@ class MediaSample : public base::RefCountedThreadSafe { /// Must not be negative. /// @param is_key_frame indicates whether the sample is a key frame. static scoped_refptr CopyFrom(const uint8* data, - int size, + size_t size, const uint8* side_data, - int side_data_size, + size_t side_data_size, bool is_key_frame); /// Create a MediaSample indicating we've reached end of stream. @@ -98,7 +98,7 @@ class MediaSample : public base::RefCountedThreadSafe { return &data_[0]; } - int data_size() const { + size_t data_size() const { DCHECK(!end_of_stream()); return data_.size(); } @@ -108,7 +108,7 @@ class MediaSample : public base::RefCountedThreadSafe { return &side_data_[0]; } - int side_data_size() const { + size_t side_data_size() const { DCHECK(!end_of_stream()); return side_data_.size(); } @@ -136,9 +136,9 @@ class MediaSample : public base::RefCountedThreadSafe { /// @param data,side_data can be NULL, which indicates an empty sample. /// @param size,side_data_size should not be negative. MediaSample(const uint8* data, - int size, + size_t size, const uint8* side_data, - int side_data_size, + size_t side_data_size, bool is_key_frame); virtual ~MediaSample(); diff --git a/media/base/media_stream.cc b/media/base/media_stream.cc index c9d2f6c5f1..5a1e2380dd 100644 --- a/media/base/media_stream.cc +++ b/media/base/media_stream.cc @@ -7,6 +7,7 @@ #include "media/base/media_stream.h" #include "base/logging.h" +#include "base/strings/stringprintf.h" #include "media/base/demuxer.h" #include "media/base/media_sample.h" #include "media/base/muxer.h" @@ -51,14 +52,14 @@ Status MediaStream::PushSample(const scoped_refptr& sample) { } void MediaStream::Connect(Muxer* muxer) { - DCHECK(muxer != NULL); - DCHECK(muxer_ == NULL); + DCHECK(muxer); + DCHECK(!muxer_); state_ = kConnected; muxer_ = muxer; } Status MediaStream::Start(MediaStreamOperation operation) { - DCHECK(demuxer_ != NULL); + DCHECK(demuxer_); DCHECK(operation == kPush || operation == kPull); switch (state_) { @@ -99,10 +100,8 @@ Status MediaStream::Start(MediaStreamOperation operation) { const scoped_refptr MediaStream::info() const { return info_; } std::string MediaStream::ToString() const { - std::ostringstream s; - s << "state: " << state_ << " samples in the queue: " << samples_.size() - << " " << info_->ToString(); - return s.str(); + return base::StringPrintf("state: %d\n samples in the queue: %zu\n %s", + state_, samples_.size(), info_->ToString().c_str()); } } // namespace media