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
This commit is contained in:
parent
f9ae38f717
commit
b34b997bcb
|
@ -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> 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> 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> 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
|
||||
|
|
|
@ -29,7 +29,7 @@ class MediaSample : public base::RefCountedThreadSafe<MediaSample> {
|
|||
/// @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<MediaSample> 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<MediaSample> {
|
|||
/// Must not be negative.
|
||||
/// @param is_key_frame indicates whether the sample is a key frame.
|
||||
static scoped_refptr<MediaSample> 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<MediaSample> {
|
|||
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<MediaSample> {
|
|||
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<MediaSample> {
|
|||
/// @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();
|
||||
|
||||
|
|
|
@ -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<MediaSample>& 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<StreamInfo> 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
|
||||
|
|
Loading…
Reference in New Issue