Change MediaSample::CopyFrom to MediaSample::Clone
Change-Id: Ibc8e6ba149496bb62179230e95aa6803a015b12b
This commit is contained in:
parent
92e1e39868
commit
9a60760815
|
@ -60,32 +60,6 @@ std::shared_ptr<MediaSample> MediaSample::CopyFrom(const uint8_t* data,
|
|||
data, data_size, side_data, side_data_size, is_key_frame));
|
||||
}
|
||||
|
||||
// static
|
||||
std::shared_ptr<MediaSample> MediaSample::CopyFrom(
|
||||
const MediaSample& media_sample) {
|
||||
std::shared_ptr<MediaSample> new_media_sample(new MediaSample);
|
||||
new_media_sample->dts_ = media_sample.dts_;
|
||||
new_media_sample->pts_ = media_sample.pts_;
|
||||
new_media_sample->duration_ = media_sample.duration_;
|
||||
new_media_sample->is_key_frame_ = media_sample.is_key_frame_;
|
||||
new_media_sample->is_encrypted_ = media_sample.is_encrypted_;
|
||||
new_media_sample->data_ = media_sample.data_;
|
||||
new_media_sample->data_size_ = media_sample.data_size_;
|
||||
new_media_sample->side_data_ = media_sample.side_data_;
|
||||
new_media_sample->side_data_size_ = media_sample.side_data_size_;
|
||||
new_media_sample->config_id_ = media_sample.config_id_;
|
||||
if (media_sample.decrypt_config_) {
|
||||
new_media_sample->decrypt_config_.reset(
|
||||
new DecryptConfig(media_sample.decrypt_config_->key_id(),
|
||||
media_sample.decrypt_config_->iv(),
|
||||
media_sample.decrypt_config_->subsamples(),
|
||||
media_sample.decrypt_config_->protection_scheme(),
|
||||
media_sample.decrypt_config_->crypt_byte_block(),
|
||||
media_sample.decrypt_config_->skip_byte_block()));
|
||||
}
|
||||
return new_media_sample;
|
||||
}
|
||||
|
||||
// static
|
||||
std::shared_ptr<MediaSample> MediaSample::FromMetadata(const uint8_t* metadata,
|
||||
size_t metadata_size) {
|
||||
|
@ -104,6 +78,28 @@ std::shared_ptr<MediaSample> MediaSample::CreateEOSBuffer() {
|
|||
new MediaSample(nullptr, 0, nullptr, 0, false));
|
||||
}
|
||||
|
||||
std::shared_ptr<MediaSample> MediaSample::Clone() const {
|
||||
std::shared_ptr<MediaSample> new_media_sample(new MediaSample);
|
||||
new_media_sample->dts_ = dts_;
|
||||
new_media_sample->pts_ = pts_;
|
||||
new_media_sample->duration_ = duration_;
|
||||
new_media_sample->is_key_frame_ = is_key_frame_;
|
||||
new_media_sample->is_encrypted_ = is_encrypted_;
|
||||
new_media_sample->data_ = data_;
|
||||
new_media_sample->data_size_ = data_size_;
|
||||
new_media_sample->side_data_ = side_data_;
|
||||
new_media_sample->side_data_size_ = side_data_size_;
|
||||
new_media_sample->config_id_ = config_id_;
|
||||
if (decrypt_config_) {
|
||||
new_media_sample->decrypt_config_.reset(new DecryptConfig(
|
||||
decrypt_config_->key_id(), decrypt_config_->iv(),
|
||||
decrypt_config_->subsamples(), decrypt_config_->protection_scheme(),
|
||||
decrypt_config_->crypt_byte_block(),
|
||||
decrypt_config_->skip_byte_block()));
|
||||
}
|
||||
return new_media_sample;
|
||||
}
|
||||
|
||||
void MediaSample::TransferData(std::shared_ptr<uint8_t> data,
|
||||
size_t data_size) {
|
||||
data_ = std::move(data);
|
||||
|
|
|
@ -45,10 +45,6 @@ class MediaSample {
|
|||
size_t side_data_size,
|
||||
bool is_key_frame);
|
||||
|
||||
/// Make a copy of MediaSample.
|
||||
/// @param media_sample is the source MediaSample to copy from.
|
||||
static std::shared_ptr<MediaSample> CopyFrom(const MediaSample& media_sample);
|
||||
|
||||
/// Create a MediaSample object from metadata.
|
||||
/// Unlike other factory methods, this cannot be a key frame. It must be only
|
||||
/// for metadata.
|
||||
|
@ -68,6 +64,9 @@ class MediaSample {
|
|||
|
||||
virtual ~MediaSample();
|
||||
|
||||
/// Clone the object and return a new MediaSample.
|
||||
std::shared_ptr<MediaSample> Clone() const;
|
||||
|
||||
/// Transfer data to this media sample. No data copying is involved.
|
||||
/// @param data points to the data to be transferred.
|
||||
/// @param data_size is the size of the data to be transferred.
|
||||
|
|
|
@ -258,8 +258,7 @@ Status EncryptionHandler::ProcessMediaSample(
|
|||
// Now that we know that this sample must be encrypted, make a copy of
|
||||
// the sample first so that all the encryption operations can be done
|
||||
// in-place.
|
||||
std::shared_ptr<MediaSample> cipher_sample =
|
||||
MediaSample::CopyFrom(*clear_sample);
|
||||
std::shared_ptr<MediaSample> cipher_sample(clear_sample->Clone());
|
||||
// |cipher_sample| above still contains the old clear sample data. We will
|
||||
// use |cipher_sample_data| to hold cipher sample data then transfer it to
|
||||
// |cipher_sample| after encryption.
|
||||
|
|
|
@ -157,7 +157,7 @@ Status Segmenter::Finalize() {
|
|||
}
|
||||
|
||||
Status Segmenter::AddSample(const MediaSample& source_sample) {
|
||||
std::shared_ptr<MediaSample> sample = MediaSample::CopyFrom(source_sample);
|
||||
std::shared_ptr<MediaSample> sample(source_sample.Clone());
|
||||
|
||||
if (sample_duration_ == 0) {
|
||||
first_timestamp_ = sample->pts();
|
||||
|
|
|
@ -164,7 +164,7 @@ Status TrickPlayHandler::OnTrickFrame(const MediaSample& sample) {
|
|||
total_trick_frames_++;
|
||||
|
||||
// Make a message we can store until later.
|
||||
previous_trick_frame_ = MediaSample::CopyFrom(sample);
|
||||
previous_trick_frame_ = sample.Clone();
|
||||
|
||||
// Add the message to our queue so that it will be ready to go out.
|
||||
delayed_messages_.push_back(
|
||||
|
|
Loading…
Reference in New Issue