2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
|
|
#include "media/base/media_sample.h"
|
|
|
|
|
2014-06-20 21:45:09 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
#include "base/logging.h"
|
2014-03-31 22:25:45 +00:00
|
|
|
#include "base/strings/stringprintf.h"
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2013-09-24 04:17:12 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
MediaSample::MediaSample(const uint8* data,
|
2014-03-31 22:25:45 +00:00
|
|
|
size_t size,
|
2013-09-24 04:17:12 +00:00
|
|
|
const uint8* side_data,
|
2014-03-31 22:25:45 +00:00
|
|
|
size_t side_data_size,
|
2013-09-24 04:17:12 +00:00
|
|
|
bool is_key_frame)
|
|
|
|
: dts_(0), pts_(0), duration_(0), is_key_frame_(is_key_frame) {
|
|
|
|
if (!data) {
|
2014-03-31 22:25:45 +00:00
|
|
|
CHECK_EQ(size, 0u);
|
2013-09-24 04:17:12 +00:00
|
|
|
CHECK(!side_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data_.assign(data, data + size);
|
|
|
|
if (side_data)
|
|
|
|
side_data_.assign(side_data, side_data + side_data_size);
|
|
|
|
}
|
|
|
|
|
2014-09-16 19:55:49 +00:00
|
|
|
MediaSample::MediaSample() : dts_(0), pts_(0),
|
|
|
|
duration_(0),
|
|
|
|
is_key_frame_(false) {}
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
MediaSample::~MediaSample() {}
|
|
|
|
|
|
|
|
// static
|
|
|
|
scoped_refptr<MediaSample> MediaSample::CopyFrom(const uint8* data,
|
2014-03-31 22:25:45 +00:00
|
|
|
size_t data_size,
|
2013-09-24 04:17:12 +00:00
|
|
|
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(
|
2014-03-31 22:25:45 +00:00
|
|
|
new MediaSample(data, data_size, NULL, 0u, is_key_frame));
|
2013-09-24 04:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
scoped_refptr<MediaSample> MediaSample::CopyFrom(const uint8* data,
|
2014-03-31 22:25:45 +00:00
|
|
|
size_t data_size,
|
2013-09-24 04:17:12 +00:00
|
|
|
const uint8* side_data,
|
2014-03-31 22:25:45 +00:00
|
|
|
size_t side_data_size,
|
2013-09-24 04:17:12 +00:00
|
|
|
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, side_data, side_data_size, is_key_frame));
|
|
|
|
}
|
|
|
|
|
2014-07-14 21:35:57 +00:00
|
|
|
// static
|
|
|
|
scoped_refptr<MediaSample> MediaSample::CreateEmptyMediaSample() {
|
|
|
|
MediaSample* media_sample = new MediaSample();
|
|
|
|
return make_scoped_refptr(media_sample);
|
|
|
|
}
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
// static
|
|
|
|
scoped_refptr<MediaSample> MediaSample::CreateEOSBuffer() {
|
|
|
|
return make_scoped_refptr(new MediaSample(NULL, 0, NULL, 0, false));
|
|
|
|
}
|
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
std::string MediaSample::ToString() const {
|
2014-03-31 22:25:45 +00:00
|
|
|
if (end_of_stream())
|
|
|
|
return "End of stream sample\n";
|
|
|
|
return base::StringPrintf(
|
2014-06-20 21:45:09 +00:00
|
|
|
"dts: %" PRId64 "\n pts: %" PRId64 "\n duration: %" PRId64 "\n "
|
2014-08-25 22:51:19 +00:00
|
|
|
"is_key_frame: %s\n size: %zu\n side_data_size: %zu\n",
|
2014-06-20 21:45:09 +00:00
|
|
|
dts_,
|
|
|
|
pts_,
|
|
|
|
duration_,
|
|
|
|
is_key_frame_ ? "true" : "false",
|
|
|
|
data_.size(),
|
2014-08-25 22:51:19 +00:00
|
|
|
side_data_.size());
|
2013-09-24 04:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|