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 "media/base/media_sample.h"
|
||||||
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
|
#include "base/strings/stringprintf.h"
|
||||||
#include "media/base/decrypt_config.h"
|
#include "media/base/decrypt_config.h"
|
||||||
|
|
||||||
namespace media {
|
namespace media {
|
||||||
|
|
||||||
MediaSample::MediaSample(const uint8* data,
|
MediaSample::MediaSample(const uint8* data,
|
||||||
int size,
|
size_t size,
|
||||||
const uint8* side_data,
|
const uint8* side_data,
|
||||||
int side_data_size,
|
size_t side_data_size,
|
||||||
bool is_key_frame)
|
bool is_key_frame)
|
||||||
: dts_(0), pts_(0), duration_(0), is_key_frame_(is_key_frame) {
|
: dts_(0), pts_(0), duration_(0), is_key_frame_(is_key_frame) {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
CHECK_EQ(size, 0);
|
CHECK_EQ(size, 0u);
|
||||||
CHECK(!side_data);
|
CHECK(!side_data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -32,19 +33,19 @@ MediaSample::~MediaSample() {}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
scoped_refptr<MediaSample> MediaSample::CopyFrom(const uint8* data,
|
scoped_refptr<MediaSample> MediaSample::CopyFrom(const uint8* data,
|
||||||
int data_size,
|
size_t data_size,
|
||||||
bool is_key_frame) {
|
bool is_key_frame) {
|
||||||
// If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
|
// If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
|
||||||
CHECK(data);
|
CHECK(data);
|
||||||
return make_scoped_refptr(
|
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
|
// static
|
||||||
scoped_refptr<MediaSample> MediaSample::CopyFrom(const uint8* data,
|
scoped_refptr<MediaSample> MediaSample::CopyFrom(const uint8* data,
|
||||||
int data_size,
|
size_t data_size,
|
||||||
const uint8* side_data,
|
const uint8* side_data,
|
||||||
int side_data_size,
|
size_t side_data_size,
|
||||||
bool is_key_frame) {
|
bool is_key_frame) {
|
||||||
// If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
|
// If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
|
||||||
CHECK(data);
|
CHECK(data);
|
||||||
|
@ -58,19 +59,13 @@ scoped_refptr<MediaSample> MediaSample::CreateEOSBuffer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MediaSample::ToString() const {
|
std::string MediaSample::ToString() const {
|
||||||
if (end_of_stream()) {
|
if (end_of_stream())
|
||||||
return "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 "
|
||||||
std::ostringstream s;
|
"side_data_size: %zu\n is_encrypted: %s\n",
|
||||||
s << "dts: " << dts_
|
dts_, pts_, duration_, is_key_frame_ ? "true" : "false", data_.size(),
|
||||||
<< " pts: " << pts_
|
side_data_.size(), decrypt_config_ ? "true" : "false");
|
||||||
<< " duration: " << duration_
|
|
||||||
<< " is_key_frame: " << is_key_frame_
|
|
||||||
<< " size: " << data_.size()
|
|
||||||
<< " side_data_size: " << side_data_.size()
|
|
||||||
<< " encrypted: " << (decrypt_config_ != NULL);
|
|
||||||
return s.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace media
|
} // namespace media
|
||||||
|
|
|
@ -29,7 +29,7 @@ class MediaSample : public base::RefCountedThreadSafe<MediaSample> {
|
||||||
/// @param size indicates sample size in bytes. Must not be negative.
|
/// @param size indicates sample size in bytes. Must not be negative.
|
||||||
/// @param is_key_frame indicates whether the sample is a key frame.
|
/// @param is_key_frame indicates whether the sample is a key frame.
|
||||||
static scoped_refptr<MediaSample> CopyFrom(const uint8* data,
|
static scoped_refptr<MediaSample> CopyFrom(const uint8* data,
|
||||||
int size,
|
size_t size,
|
||||||
bool is_key_frame);
|
bool is_key_frame);
|
||||||
|
|
||||||
/// Create a MediaSample object from input.
|
/// Create a MediaSample object from input.
|
||||||
|
@ -43,9 +43,9 @@ class MediaSample : public base::RefCountedThreadSafe<MediaSample> {
|
||||||
/// Must not be negative.
|
/// Must not be negative.
|
||||||
/// @param is_key_frame indicates whether the sample is a key frame.
|
/// @param is_key_frame indicates whether the sample is a key frame.
|
||||||
static scoped_refptr<MediaSample> CopyFrom(const uint8* data,
|
static scoped_refptr<MediaSample> CopyFrom(const uint8* data,
|
||||||
int size,
|
size_t size,
|
||||||
const uint8* side_data,
|
const uint8* side_data,
|
||||||
int side_data_size,
|
size_t side_data_size,
|
||||||
bool is_key_frame);
|
bool is_key_frame);
|
||||||
|
|
||||||
/// Create a MediaSample indicating we've reached end of stream.
|
/// Create a MediaSample indicating we've reached end of stream.
|
||||||
|
@ -98,7 +98,7 @@ class MediaSample : public base::RefCountedThreadSafe<MediaSample> {
|
||||||
return &data_[0];
|
return &data_[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
int data_size() const {
|
size_t data_size() const {
|
||||||
DCHECK(!end_of_stream());
|
DCHECK(!end_of_stream());
|
||||||
return data_.size();
|
return data_.size();
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ class MediaSample : public base::RefCountedThreadSafe<MediaSample> {
|
||||||
return &side_data_[0];
|
return &side_data_[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
int side_data_size() const {
|
size_t side_data_size() const {
|
||||||
DCHECK(!end_of_stream());
|
DCHECK(!end_of_stream());
|
||||||
return side_data_.size();
|
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 data,side_data can be NULL, which indicates an empty sample.
|
||||||
/// @param size,side_data_size should not be negative.
|
/// @param size,side_data_size should not be negative.
|
||||||
MediaSample(const uint8* data,
|
MediaSample(const uint8* data,
|
||||||
int size,
|
size_t size,
|
||||||
const uint8* side_data,
|
const uint8* side_data,
|
||||||
int side_data_size,
|
size_t side_data_size,
|
||||||
bool is_key_frame);
|
bool is_key_frame);
|
||||||
virtual ~MediaSample();
|
virtual ~MediaSample();
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "media/base/media_stream.h"
|
#include "media/base/media_stream.h"
|
||||||
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
|
#include "base/strings/stringprintf.h"
|
||||||
#include "media/base/demuxer.h"
|
#include "media/base/demuxer.h"
|
||||||
#include "media/base/media_sample.h"
|
#include "media/base/media_sample.h"
|
||||||
#include "media/base/muxer.h"
|
#include "media/base/muxer.h"
|
||||||
|
@ -51,14 +52,14 @@ Status MediaStream::PushSample(const scoped_refptr<MediaSample>& sample) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaStream::Connect(Muxer* muxer) {
|
void MediaStream::Connect(Muxer* muxer) {
|
||||||
DCHECK(muxer != NULL);
|
DCHECK(muxer);
|
||||||
DCHECK(muxer_ == NULL);
|
DCHECK(!muxer_);
|
||||||
state_ = kConnected;
|
state_ = kConnected;
|
||||||
muxer_ = muxer;
|
muxer_ = muxer;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status MediaStream::Start(MediaStreamOperation operation) {
|
Status MediaStream::Start(MediaStreamOperation operation) {
|
||||||
DCHECK(demuxer_ != NULL);
|
DCHECK(demuxer_);
|
||||||
DCHECK(operation == kPush || operation == kPull);
|
DCHECK(operation == kPush || operation == kPull);
|
||||||
|
|
||||||
switch (state_) {
|
switch (state_) {
|
||||||
|
@ -99,10 +100,8 @@ Status MediaStream::Start(MediaStreamOperation operation) {
|
||||||
const scoped_refptr<StreamInfo> MediaStream::info() const { return info_; }
|
const scoped_refptr<StreamInfo> MediaStream::info() const { return info_; }
|
||||||
|
|
||||||
std::string MediaStream::ToString() const {
|
std::string MediaStream::ToString() const {
|
||||||
std::ostringstream s;
|
return base::StringPrintf("state: %d\n samples in the queue: %zu\n %s",
|
||||||
s << "state: " << state_ << " samples in the queue: " << samples_.size()
|
state_, samples_.size(), info_->ToString().c_str());
|
||||||
<< " " << info_->ToString();
|
|
||||||
return s.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace media
|
} // namespace media
|
||||||
|
|
Loading…
Reference in New Issue