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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 } | 147 } |
143 | 148 |
144 // Rewrite |this| buffer as a splice buffer. | 149 // Rewrite |this| buffer as a splice buffer. |
145 SetDecodeTimestamp(first_splice_buffer->GetDecodeTimestamp()); | 150 SetDecodeTimestamp(first_splice_buffer->GetDecodeTimestamp()); |
146 SetConfigId(first_splice_buffer->GetConfigId()); | 151 SetConfigId(first_splice_buffer->GetConfigId()); |
147 set_timestamp(first_splice_buffer->timestamp()); | 152 set_timestamp(first_splice_buffer->timestamp()); |
148 set_is_key_frame(first_splice_buffer->is_key_frame()); | 153 set_is_key_frame(first_splice_buffer->is_key_frame()); |
149 type_ = first_splice_buffer->type(); | 154 type_ = first_splice_buffer->type(); |
150 track_id_ = first_splice_buffer->track_id(); | 155 track_id_ = first_splice_buffer->track_id(); |
151 set_splice_timestamp(overlapping_buffer->timestamp()); | 156 set_splice_timestamp(overlapping_buffer->timestamp()); |
152 | 157 |
DaleCurtis
2015/04/15 22:51:45
Forward this new flag? Or DCHECK it's not present?
chcunningham
2015/04/16 18:04:16
Done, added DCHECKs
| |
153 // The splice duration is the duration of all buffers before the splice plus | 158 // The splice duration is the duration of all buffers before the splice plus |
154 // the highest ending timestamp after the splice point. | 159 // the highest ending timestamp after the splice point. |
155 DCHECK(overlapping_buffer->duration() > base::TimeDelta()); | 160 DCHECK(overlapping_buffer->duration() > base::TimeDelta()); |
156 DCHECK(pre_splice_buffers.back()->duration() > base::TimeDelta()); | 161 DCHECK(pre_splice_buffers.back()->duration() > base::TimeDelta()); |
157 set_duration( | 162 set_duration( |
158 std::max(overlapping_buffer->timestamp() + overlapping_buffer->duration(), | 163 std::max(overlapping_buffer->timestamp() + overlapping_buffer->duration(), |
159 pre_splice_buffers.back()->timestamp() + | 164 pre_splice_buffers.back()->timestamp() + |
160 pre_splice_buffers.back()->duration()) - | 165 pre_splice_buffers.back()->duration()) - |
161 first_splice_buffer->timestamp()); | 166 first_splice_buffer->timestamp()); |
162 | 167 |
(...skipping 17 matching lines...) Expand all Loading... | |
180 DCHECK(!preroll_buffer_.get()); | 185 DCHECK(!preroll_buffer_.get()); |
181 DCHECK(!end_of_stream()); | 186 DCHECK(!end_of_stream()); |
182 DCHECK(!preroll_buffer->end_of_stream()); | 187 DCHECK(!preroll_buffer->end_of_stream()); |
183 DCHECK(!preroll_buffer->preroll_buffer_.get()); | 188 DCHECK(!preroll_buffer->preroll_buffer_.get()); |
184 DCHECK(preroll_buffer->splice_timestamp() == kNoTimestamp()); | 189 DCHECK(preroll_buffer->splice_timestamp() == kNoTimestamp()); |
185 DCHECK(preroll_buffer->splice_buffers().empty()); | 190 DCHECK(preroll_buffer->splice_buffers().empty()); |
186 DCHECK(preroll_buffer->timestamp() <= timestamp()); | 191 DCHECK(preroll_buffer->timestamp() <= timestamp()); |
187 DCHECK(preroll_buffer->discard_padding() == DecoderBuffer::DiscardPadding()); | 192 DCHECK(preroll_buffer->discard_padding() == DecoderBuffer::DiscardPadding()); |
188 DCHECK_EQ(preroll_buffer->type(), type()); | 193 DCHECK_EQ(preroll_buffer->type(), type()); |
189 DCHECK_EQ(preroll_buffer->track_id(), track_id()); | 194 DCHECK_EQ(preroll_buffer->track_id(), track_id()); |
190 | 195 |
DaleCurtis
2015/04/15 22:51:46
Any DCHECKS() you want to add here?
chcunningham
2015/04/16 18:04:16
I think estimation should be ok for pre-roll. Unli
| |
191 preroll_buffer_ = preroll_buffer; | 196 preroll_buffer_ = preroll_buffer; |
192 preroll_buffer_->set_timestamp(timestamp()); | 197 preroll_buffer_->set_timestamp(timestamp()); |
193 preroll_buffer_->SetDecodeTimestamp(GetDecodeTimestamp()); | 198 preroll_buffer_->SetDecodeTimestamp(GetDecodeTimestamp()); |
194 | 199 |
195 // Mark the entire buffer for discard. | 200 // Mark the entire buffer for discard. |
196 preroll_buffer_->set_discard_padding( | 201 preroll_buffer_->set_discard_padding( |
197 std::make_pair(kInfiniteDuration(), base::TimeDelta())); | 202 std::make_pair(kInfiniteDuration(), base::TimeDelta())); |
198 } | 203 } |
199 | 204 |
200 void StreamParserBuffer::set_timestamp(base::TimeDelta timestamp) { | 205 void StreamParserBuffer::set_timestamp(base::TimeDelta timestamp) { |
201 DecoderBuffer::set_timestamp(timestamp); | 206 DecoderBuffer::set_timestamp(timestamp); |
202 if (preroll_buffer_.get()) | 207 if (preroll_buffer_.get()) |
203 preroll_buffer_->set_timestamp(timestamp); | 208 preroll_buffer_->set_timestamp(timestamp); |
204 } | 209 } |
205 | 210 |
206 } // namespace media | 211 } // namespace media |
OLD | NEW |