| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/stream_parser_buffer.h" | 5 #include "media/base/stream_parser_buffer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "media/base/buffers.h" | 8 #include "media/base/buffers.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| 11 | 11 |
| 12 static scoped_refptr<StreamParserBuffer> CopyBuffer( | 12 static scoped_refptr<StreamParserBuffer> CopyBuffer( |
| 13 const StreamParserBuffer& buffer) { | 13 const StreamParserBuffer& buffer) { |
| 14 if (buffer.end_of_stream()) | 14 if (buffer.end_of_stream()) |
| 15 return StreamParserBuffer::CreateEOSBuffer(); | 15 return StreamParserBuffer::CreateEOSBuffer(); |
| 16 | 16 |
| 17 scoped_refptr<StreamParserBuffer> copied_buffer = | 17 scoped_refptr<StreamParserBuffer> copied_buffer = |
| 18 StreamParserBuffer::CopyFrom(buffer.data(), | 18 StreamParserBuffer::CopyFrom(buffer.data(), |
| 19 buffer.data_size(), | 19 buffer.data_size(), |
| 20 buffer.side_data(), | 20 buffer.side_data(), |
| 21 buffer.side_data_size(), | 21 buffer.side_data_size(), |
| 22 buffer.is_key_frame(), | 22 buffer.is_key_frame(), |
| 23 buffer.type(), | 23 buffer.type(), |
| 24 buffer.track_id()); | 24 buffer.track_id()); |
| 25 copied_buffer->SetDecodeTimestamp(buffer.GetDecodeTimestamp()); | 25 copied_buffer->SetDecodeTimestamp(buffer.GetDecodeTimestamp()); |
| 26 copied_buffer->SetConfigId(buffer.GetConfigId()); | 26 copied_buffer->SetConfigId(buffer.GetConfigId()); |
| 27 copied_buffer->set_timestamp(buffer.timestamp()); | 27 copied_buffer->set_timestamp(buffer.timestamp()); |
| 28 copied_buffer->set_duration(buffer.duration()); | 28 copied_buffer->set_duration(buffer.duration()); |
| 29 copied_buffer->set_is_duration_estimated(buffer.is_duration_estimated()); |
| 29 copied_buffer->set_discard_padding(buffer.discard_padding()); | 30 copied_buffer->set_discard_padding(buffer.discard_padding()); |
| 30 copied_buffer->set_splice_timestamp(buffer.splice_timestamp()); | 31 copied_buffer->set_splice_timestamp(buffer.splice_timestamp()); |
| 31 const DecryptConfig* decrypt_config = buffer.decrypt_config(); | 32 const DecryptConfig* decrypt_config = buffer.decrypt_config(); |
| 32 if (decrypt_config) { | 33 if (decrypt_config) { |
| 33 copied_buffer->set_decrypt_config( | 34 copied_buffer->set_decrypt_config( |
| 34 make_scoped_ptr(new DecryptConfig(decrypt_config->key_id(), | 35 make_scoped_ptr(new DecryptConfig(decrypt_config->key_id(), |
| 35 decrypt_config->iv(), | 36 decrypt_config->iv(), |
| 36 decrypt_config->subsamples()))); | 37 decrypt_config->subsamples()))); |
| 37 } | 38 } |
| 38 | 39 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 66 return DecodeTimestamp::FromPresentationTime(timestamp()); | 67 return DecodeTimestamp::FromPresentationTime(timestamp()); |
| 67 return decode_timestamp_; | 68 return decode_timestamp_; |
| 68 } | 69 } |
| 69 | 70 |
| 70 void StreamParserBuffer::SetDecodeTimestamp(DecodeTimestamp timestamp) { | 71 void StreamParserBuffer::SetDecodeTimestamp(DecodeTimestamp timestamp) { |
| 71 decode_timestamp_ = timestamp; | 72 decode_timestamp_ = timestamp; |
| 72 if (preroll_buffer_.get()) | 73 if (preroll_buffer_.get()) |
| 73 preroll_buffer_->SetDecodeTimestamp(timestamp); | 74 preroll_buffer_->SetDecodeTimestamp(timestamp); |
| 74 } | 75 } |
| 75 | 76 |
| 76 StreamParserBuffer::StreamParserBuffer(const uint8* data, int data_size, | 77 StreamParserBuffer::StreamParserBuffer(const uint8* data, |
| 78 int data_size, |
| 77 const uint8* side_data, | 79 const uint8* side_data, |
| 78 int side_data_size, bool is_key_frame, | 80 int side_data_size, |
| 79 Type type, TrackId track_id) | 81 bool is_key_frame, |
| 82 Type type, |
| 83 TrackId track_id) |
| 80 : DecoderBuffer(data, data_size, side_data, side_data_size), | 84 : DecoderBuffer(data, data_size, side_data, side_data_size), |
| 81 decode_timestamp_(kNoDecodeTimestamp()), | 85 decode_timestamp_(kNoDecodeTimestamp()), |
| 82 config_id_(kInvalidConfigId), | 86 config_id_(kInvalidConfigId), |
| 83 type_(type), | 87 type_(type), |
| 84 track_id_(track_id) { | 88 track_id_(track_id), |
| 89 is_duration_estimated_(false) { |
| 85 // TODO(scherkus): Should DataBuffer constructor accept a timestamp and | 90 // TODO(scherkus): Should DataBuffer constructor accept a timestamp and |
| 86 // duration to force clients to set them? Today they end up being zero which | 91 // duration to force clients to set them? Today they end up being zero which |
| 87 // is both a common and valid value and could lead to bugs. | 92 // is both a common and valid value and could lead to bugs. |
| 88 if (data) { | 93 if (data) { |
| 89 set_duration(kNoTimestamp()); | 94 set_duration(kNoTimestamp()); |
| 90 } | 95 } |
| 91 | 96 |
| 92 if (is_key_frame) | 97 if (is_key_frame) |
| 93 set_is_key_frame(true); | 98 set_is_key_frame(true); |
| 94 } | 99 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 114 void StreamParserBuffer::ConvertToSpliceBuffer( | 119 void StreamParserBuffer::ConvertToSpliceBuffer( |
| 115 const BufferQueue& pre_splice_buffers) { | 120 const BufferQueue& pre_splice_buffers) { |
| 116 DCHECK(splice_buffers_.empty()); | 121 DCHECK(splice_buffers_.empty()); |
| 117 DCHECK(duration() > base::TimeDelta()) | 122 DCHECK(duration() > base::TimeDelta()) |
| 118 << "Only buffers with a valid duration can convert to a splice buffer." | 123 << "Only buffers with a valid duration can convert to a splice buffer." |
| 119 << " pts " << timestamp().InSecondsF() | 124 << " pts " << timestamp().InSecondsF() |
| 120 << " dts " << GetDecodeTimestamp().InSecondsF() | 125 << " dts " << GetDecodeTimestamp().InSecondsF() |
| 121 << " dur " << duration().InSecondsF(); | 126 << " dur " << duration().InSecondsF(); |
| 122 DCHECK(!end_of_stream()); | 127 DCHECK(!end_of_stream()); |
| 123 | 128 |
| 129 // Splicing requires non-estimated sample accurate durations to be confident |
| 130 // things will sound smooth. Also, we cannot be certain whether estimated |
| 131 // overlap is really a splice scenario, or just over estimation. |
| 132 DCHECK(!is_duration_estimated_); |
| 133 |
| 124 // Make a copy of this first, before making any changes. | 134 // Make a copy of this first, before making any changes. |
| 125 scoped_refptr<StreamParserBuffer> overlapping_buffer = CopyBuffer(*this); | 135 scoped_refptr<StreamParserBuffer> overlapping_buffer = CopyBuffer(*this); |
| 126 overlapping_buffer->set_splice_timestamp(kNoTimestamp()); | 136 overlapping_buffer->set_splice_timestamp(kNoTimestamp()); |
| 127 | 137 |
| 128 const scoped_refptr<StreamParserBuffer>& first_splice_buffer = | 138 const scoped_refptr<StreamParserBuffer>& first_splice_buffer = |
| 129 pre_splice_buffers.front(); | 139 pre_splice_buffers.front(); |
| 130 | 140 |
| 131 // Ensure the given buffers are actually before the splice point. | 141 // Ensure the given buffers are actually before the splice point. |
| 132 DCHECK(first_splice_buffer->timestamp() <= overlapping_buffer->timestamp()); | 142 DCHECK(first_splice_buffer->timestamp() <= overlapping_buffer->timestamp()); |
| 133 | 143 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 161 first_splice_buffer->timestamp()); | 171 first_splice_buffer->timestamp()); |
| 162 | 172 |
| 163 // Copy all pre splice buffers into our wrapper buffer. | 173 // Copy all pre splice buffers into our wrapper buffer. |
| 164 for (BufferQueue::const_iterator it = pre_splice_buffers.begin(); | 174 for (BufferQueue::const_iterator it = pre_splice_buffers.begin(); |
| 165 it != pre_splice_buffers.end(); | 175 it != pre_splice_buffers.end(); |
| 166 ++it) { | 176 ++it) { |
| 167 const scoped_refptr<StreamParserBuffer>& buffer = *it; | 177 const scoped_refptr<StreamParserBuffer>& buffer = *it; |
| 168 DCHECK(!buffer->end_of_stream()); | 178 DCHECK(!buffer->end_of_stream()); |
| 169 DCHECK(!buffer->preroll_buffer().get()); | 179 DCHECK(!buffer->preroll_buffer().get()); |
| 170 DCHECK(buffer->splice_buffers().empty()); | 180 DCHECK(buffer->splice_buffers().empty()); |
| 181 DCHECK(!buffer->is_duration_estimated()); |
| 171 splice_buffers_.push_back(CopyBuffer(*buffer.get())); | 182 splice_buffers_.push_back(CopyBuffer(*buffer.get())); |
| 172 splice_buffers_.back()->set_splice_timestamp(splice_timestamp()); | 183 splice_buffers_.back()->set_splice_timestamp(splice_timestamp()); |
| 173 } | 184 } |
| 174 | 185 |
| 175 splice_buffers_.push_back(overlapping_buffer); | 186 splice_buffers_.push_back(overlapping_buffer); |
| 176 } | 187 } |
| 177 | 188 |
| 178 void StreamParserBuffer::SetPrerollBuffer( | 189 void StreamParserBuffer::SetPrerollBuffer( |
| 179 const scoped_refptr<StreamParserBuffer>& preroll_buffer) { | 190 const scoped_refptr<StreamParserBuffer>& preroll_buffer) { |
| 180 DCHECK(!preroll_buffer_.get()); | 191 DCHECK(!preroll_buffer_.get()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 197 std::make_pair(kInfiniteDuration(), base::TimeDelta())); | 208 std::make_pair(kInfiniteDuration(), base::TimeDelta())); |
| 198 } | 209 } |
| 199 | 210 |
| 200 void StreamParserBuffer::set_timestamp(base::TimeDelta timestamp) { | 211 void StreamParserBuffer::set_timestamp(base::TimeDelta timestamp) { |
| 201 DecoderBuffer::set_timestamp(timestamp); | 212 DecoderBuffer::set_timestamp(timestamp); |
| 202 if (preroll_buffer_.get()) | 213 if (preroll_buffer_.get()) |
| 203 preroll_buffer_->set_timestamp(timestamp); | 214 preroll_buffer_->set_timestamp(timestamp); |
| 204 } | 215 } |
| 205 | 216 |
| 206 } // namespace media | 217 } // namespace media |
| OLD | NEW |