| 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 { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 | 63 |
| 64 DecodeTimestamp StreamParserBuffer::GetDecodeTimestamp() const { | 64 DecodeTimestamp StreamParserBuffer::GetDecodeTimestamp() const { |
| 65 if (decode_timestamp_ == kNoDecodeTimestamp()) | 65 if (decode_timestamp_ == kNoDecodeTimestamp()) |
| 66 return DecodeTimestamp::FromPresentationTime(timestamp()); | 66 return DecodeTimestamp::FromPresentationTime(timestamp()); |
| 67 return decode_timestamp_; | 67 return decode_timestamp_; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void StreamParserBuffer::SetDecodeTimestamp(DecodeTimestamp timestamp) { | 70 void StreamParserBuffer::SetDecodeTimestamp(DecodeTimestamp timestamp) { |
| 71 decode_timestamp_ = timestamp; | 71 decode_timestamp_ = timestamp; |
| 72 if (preroll_buffer_) | 72 if (preroll_buffer_.get()) |
| 73 preroll_buffer_->SetDecodeTimestamp(timestamp); | 73 preroll_buffer_->SetDecodeTimestamp(timestamp); |
| 74 } | 74 } |
| 75 | 75 |
| 76 StreamParserBuffer::StreamParserBuffer(const uint8* data, int data_size, | 76 StreamParserBuffer::StreamParserBuffer(const uint8* data, int data_size, |
| 77 const uint8* side_data, | 77 const uint8* side_data, |
| 78 int side_data_size, bool is_keyframe, | 78 int side_data_size, bool is_keyframe, |
| 79 Type type, TrackId track_id) | 79 Type type, TrackId track_id) |
| 80 : DecoderBuffer(data, data_size, side_data, side_data_size), | 80 : DecoderBuffer(data, data_size, side_data, side_data_size), |
| 81 is_keyframe_(is_keyframe), | 81 is_keyframe_(is_keyframe), |
| 82 decode_timestamp_(kNoDecodeTimestamp()), | 82 decode_timestamp_(kNoDecodeTimestamp()), |
| 83 config_id_(kInvalidConfigId), | 83 config_id_(kInvalidConfigId), |
| 84 type_(type), | 84 type_(type), |
| 85 track_id_(track_id) { | 85 track_id_(track_id) { |
| 86 // TODO(scherkus): Should DataBuffer constructor accept a timestamp and | 86 // TODO(scherkus): Should DataBuffer constructor accept a timestamp and |
| 87 // duration to force clients to set them? Today they end up being zero which | 87 // duration to force clients to set them? Today they end up being zero which |
| 88 // is both a common and valid value and could lead to bugs. | 88 // is both a common and valid value and could lead to bugs. |
| 89 if (data) { | 89 if (data) { |
| 90 set_duration(kNoTimestamp()); | 90 set_duration(kNoTimestamp()); |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 StreamParserBuffer::~StreamParserBuffer() {} | 94 StreamParserBuffer::~StreamParserBuffer() {} |
| 95 | 95 |
| 96 int StreamParserBuffer::GetConfigId() const { | 96 int StreamParserBuffer::GetConfigId() const { |
| 97 return config_id_; | 97 return config_id_; |
| 98 } | 98 } |
| 99 | 99 |
| 100 void StreamParserBuffer::SetConfigId(int config_id) { | 100 void StreamParserBuffer::SetConfigId(int config_id) { |
| 101 config_id_ = config_id; | 101 config_id_ = config_id; |
| 102 if (preroll_buffer_) | 102 if (preroll_buffer_.get()) |
| 103 preroll_buffer_->SetConfigId(config_id); | 103 preroll_buffer_->SetConfigId(config_id); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void StreamParserBuffer::ConvertToSpliceBuffer( | 106 void StreamParserBuffer::ConvertToSpliceBuffer( |
| 107 const BufferQueue& pre_splice_buffers) { | 107 const BufferQueue& pre_splice_buffers) { |
| 108 DCHECK(splice_buffers_.empty()); | 108 DCHECK(splice_buffers_.empty()); |
| 109 DCHECK(duration() > base::TimeDelta()) | 109 DCHECK(duration() > base::TimeDelta()) |
| 110 << "Only buffers with a valid duration can convert to a splice buffer." | 110 << "Only buffers with a valid duration can convert to a splice buffer." |
| 111 << " pts " << timestamp().InSecondsF() | 111 << " pts " << timestamp().InSecondsF() |
| 112 << " dts " << GetDecodeTimestamp().InSecondsF() | 112 << " dts " << GetDecodeTimestamp().InSecondsF() |
| 113 << " dur " << duration().InSecondsF(); | 113 << " dur " << duration().InSecondsF(); |
| 114 DCHECK(!end_of_stream()); | 114 DCHECK(!end_of_stream()); |
| 115 | 115 |
| 116 // Make a copy of this first, before making any changes. | 116 // Make a copy of this first, before making any changes. |
| 117 scoped_refptr<StreamParserBuffer> overlapping_buffer = CopyBuffer(*this); | 117 scoped_refptr<StreamParserBuffer> overlapping_buffer = CopyBuffer(*this); |
| 118 overlapping_buffer->set_splice_timestamp(kNoTimestamp()); | 118 overlapping_buffer->set_splice_timestamp(kNoTimestamp()); |
| 119 | 119 |
| 120 const scoped_refptr<StreamParserBuffer>& first_splice_buffer = | 120 const scoped_refptr<StreamParserBuffer>& first_splice_buffer = |
| 121 pre_splice_buffers.front(); | 121 pre_splice_buffers.front(); |
| 122 | 122 |
| 123 // Ensure the given buffers are actually before the splice point. | 123 // Ensure the given buffers are actually before the splice point. |
| 124 DCHECK(first_splice_buffer->timestamp() <= overlapping_buffer->timestamp()); | 124 DCHECK(first_splice_buffer->timestamp() <= overlapping_buffer->timestamp()); |
| 125 | 125 |
| 126 // TODO(dalecurtis): We should also clear |data| and |side_data|, but since | 126 // TODO(dalecurtis): We should also clear |data| and |side_data|, but since |
| 127 // that implies EOS care must be taken to ensure there are no clients relying | 127 // that implies EOS care must be taken to ensure there are no clients relying |
| 128 // on that behavior. | 128 // on that behavior. |
| 129 | 129 |
| 130 // Move over any preroll from this buffer. | 130 // Move over any preroll from this buffer. |
| 131 if (preroll_buffer_) { | 131 if (preroll_buffer_.get()) { |
| 132 DCHECK(!overlapping_buffer->preroll_buffer_); | 132 DCHECK(!overlapping_buffer->preroll_buffer_.get()); |
| 133 overlapping_buffer->preroll_buffer_.swap(preroll_buffer_); | 133 overlapping_buffer->preroll_buffer_.swap(preroll_buffer_); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Rewrite |this| buffer as a splice buffer. | 136 // Rewrite |this| buffer as a splice buffer. |
| 137 SetDecodeTimestamp(first_splice_buffer->GetDecodeTimestamp()); | 137 SetDecodeTimestamp(first_splice_buffer->GetDecodeTimestamp()); |
| 138 SetConfigId(first_splice_buffer->GetConfigId()); | 138 SetConfigId(first_splice_buffer->GetConfigId()); |
| 139 set_timestamp(first_splice_buffer->timestamp()); | 139 set_timestamp(first_splice_buffer->timestamp()); |
| 140 is_keyframe_ = first_splice_buffer->IsKeyframe(); | 140 is_keyframe_ = first_splice_buffer->IsKeyframe(); |
| 141 type_ = first_splice_buffer->type(); | 141 type_ = first_splice_buffer->type(); |
| 142 track_id_ = first_splice_buffer->track_id(); | 142 track_id_ = first_splice_buffer->track_id(); |
| 143 set_splice_timestamp(overlapping_buffer->timestamp()); | 143 set_splice_timestamp(overlapping_buffer->timestamp()); |
| 144 | 144 |
| 145 // The splice duration is the duration of all buffers before the splice plus | 145 // The splice duration is the duration of all buffers before the splice plus |
| 146 // the highest ending timestamp after the splice point. | 146 // the highest ending timestamp after the splice point. |
| 147 DCHECK(overlapping_buffer->duration() > base::TimeDelta()); | 147 DCHECK(overlapping_buffer->duration() > base::TimeDelta()); |
| 148 DCHECK(pre_splice_buffers.back()->duration() > base::TimeDelta()); | 148 DCHECK(pre_splice_buffers.back()->duration() > base::TimeDelta()); |
| 149 set_duration( | 149 set_duration( |
| 150 std::max(overlapping_buffer->timestamp() + overlapping_buffer->duration(), | 150 std::max(overlapping_buffer->timestamp() + overlapping_buffer->duration(), |
| 151 pre_splice_buffers.back()->timestamp() + | 151 pre_splice_buffers.back()->timestamp() + |
| 152 pre_splice_buffers.back()->duration()) - | 152 pre_splice_buffers.back()->duration()) - |
| 153 first_splice_buffer->timestamp()); | 153 first_splice_buffer->timestamp()); |
| 154 | 154 |
| 155 // Copy all pre splice buffers into our wrapper buffer. | 155 // Copy all pre splice buffers into our wrapper buffer. |
| 156 for (BufferQueue::const_iterator it = pre_splice_buffers.begin(); | 156 for (BufferQueue::const_iterator it = pre_splice_buffers.begin(); |
| 157 it != pre_splice_buffers.end(); | 157 it != pre_splice_buffers.end(); |
| 158 ++it) { | 158 ++it) { |
| 159 const scoped_refptr<StreamParserBuffer>& buffer = *it; | 159 const scoped_refptr<StreamParserBuffer>& buffer = *it; |
| 160 DCHECK(!buffer->end_of_stream()); | 160 DCHECK(!buffer->end_of_stream()); |
| 161 DCHECK(!buffer->preroll_buffer()); | 161 DCHECK(!buffer->preroll_buffer().get()); |
| 162 DCHECK(buffer->splice_buffers().empty()); | 162 DCHECK(buffer->splice_buffers().empty()); |
| 163 splice_buffers_.push_back(CopyBuffer(*buffer)); | 163 splice_buffers_.push_back(CopyBuffer(*buffer.get())); |
| 164 splice_buffers_.back()->set_splice_timestamp(splice_timestamp()); | 164 splice_buffers_.back()->set_splice_timestamp(splice_timestamp()); |
| 165 } | 165 } |
| 166 | 166 |
| 167 splice_buffers_.push_back(overlapping_buffer); | 167 splice_buffers_.push_back(overlapping_buffer); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void StreamParserBuffer::SetPrerollBuffer( | 170 void StreamParserBuffer::SetPrerollBuffer( |
| 171 const scoped_refptr<StreamParserBuffer>& preroll_buffer) { | 171 const scoped_refptr<StreamParserBuffer>& preroll_buffer) { |
| 172 DCHECK(!preroll_buffer_); | 172 DCHECK(!preroll_buffer_.get()); |
| 173 DCHECK(!end_of_stream()); | 173 DCHECK(!end_of_stream()); |
| 174 DCHECK(!preroll_buffer->end_of_stream()); | 174 DCHECK(!preroll_buffer->end_of_stream()); |
| 175 DCHECK(!preroll_buffer->preroll_buffer_); | 175 DCHECK(!preroll_buffer->preroll_buffer_.get()); |
| 176 DCHECK(preroll_buffer->splice_timestamp() == kNoTimestamp()); | 176 DCHECK(preroll_buffer->splice_timestamp() == kNoTimestamp()); |
| 177 DCHECK(preroll_buffer->splice_buffers().empty()); | 177 DCHECK(preroll_buffer->splice_buffers().empty()); |
| 178 DCHECK(preroll_buffer->timestamp() <= timestamp()); | 178 DCHECK(preroll_buffer->timestamp() <= timestamp()); |
| 179 DCHECK(preroll_buffer->discard_padding() == DecoderBuffer::DiscardPadding()); | 179 DCHECK(preroll_buffer->discard_padding() == DecoderBuffer::DiscardPadding()); |
| 180 DCHECK_EQ(preroll_buffer->type(), type()); | 180 DCHECK_EQ(preroll_buffer->type(), type()); |
| 181 DCHECK_EQ(preroll_buffer->track_id(), track_id()); | 181 DCHECK_EQ(preroll_buffer->track_id(), track_id()); |
| 182 | 182 |
| 183 preroll_buffer_ = preroll_buffer; | 183 preroll_buffer_ = preroll_buffer; |
| 184 preroll_buffer_->set_timestamp(timestamp()); | 184 preroll_buffer_->set_timestamp(timestamp()); |
| 185 preroll_buffer_->SetDecodeTimestamp(GetDecodeTimestamp()); | 185 preroll_buffer_->SetDecodeTimestamp(GetDecodeTimestamp()); |
| 186 | 186 |
| 187 // Mark the entire buffer for discard. | 187 // Mark the entire buffer for discard. |
| 188 preroll_buffer_->set_discard_padding( | 188 preroll_buffer_->set_discard_padding( |
| 189 std::make_pair(kInfiniteDuration(), base::TimeDelta())); | 189 std::make_pair(kInfiniteDuration(), base::TimeDelta())); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void StreamParserBuffer::set_timestamp(base::TimeDelta timestamp) { | 192 void StreamParserBuffer::set_timestamp(base::TimeDelta timestamp) { |
| 193 DecoderBuffer::set_timestamp(timestamp); | 193 DecoderBuffer::set_timestamp(timestamp); |
| 194 if (preroll_buffer_) | 194 if (preroll_buffer_.get()) |
| 195 preroll_buffer_->set_timestamp(timestamp); | 195 preroll_buffer_->set_timestamp(timestamp); |
| 196 } | 196 } |
| 197 | 197 |
| 198 } // namespace media | 198 } // namespace media |
| OLD | NEW |