Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/blink/multibuffer.h" | 5 #include "media/blink/multibuffer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 | 8 |
| 9 namespace media { | 9 namespace media { |
| 10 | 10 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 // Make sure that there are no present blocks between the writer and | 155 // Make sure that there are no present blocks between the writer and |
| 156 // the requested position, as that will cause the writer to quit. | 156 // the requested position, as that will cause the writer to quit. |
| 157 if (closest_writer > closest_block) { | 157 if (closest_writer > closest_block) { |
| 158 provider = writer_index_[closest_writer]; | 158 provider = writer_index_[closest_writer]; |
| 159 DCHECK(provider); | 159 DCHECK(provider); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 if (!provider) { | 162 if (!provider) { |
| 163 DCHECK(writer_index_.find(pos) == writer_index_.end()); | 163 DCHECK(writer_index_.find(pos) == writer_index_.end()); |
| 164 provider = writer_index_[pos] = CreateWriter(pos); | 164 provider = writer_index_[pos] = CreateWriter(pos); |
| 165 provider->SetAvailableCallback(base::Bind( | |
| 166 &MultiBuffer::DataProviderEvent, base::Unretained(this), provider)); | |
| 167 } | 165 } |
| 168 provider->SetDeferred(false); | 166 provider->SetDeferred(false); |
| 169 } | 167 } |
| 170 | 168 |
| 171 void MultiBuffer::RemoveReader(const BlockId& pos, Reader* reader) { | 169 void MultiBuffer::RemoveReader(const BlockId& pos, Reader* reader) { |
| 172 auto i = readers_.find(pos); | 170 auto i = readers_.find(pos); |
| 173 if (i == readers_.end()) | 171 if (i == readers_.end()) |
| 174 return; | 172 return; |
| 175 i->second.erase(reader); | 173 i->second.erase(reader); |
| 176 if (i->second.empty()) { | 174 if (i->second.empty()) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 } | 249 } |
| 252 if (i.interval_end() == freed_range.first.end) { | 250 if (i.interval_end() == freed_range.first.end) { |
| 253 // Notify the following range that it contains fewer blocks. | 251 // Notify the following range that it contains fewer blocks. |
| 254 auto j = i; | 252 auto j = i; |
| 255 ++j; | 253 ++j; |
| 256 DCHECK_EQ(j.value(), 1); | 254 DCHECK_EQ(j.value(), 1); |
| 257 NotifyAvailableRange(j.interval(), j.interval()); | 255 NotifyAvailableRange(j.interval(), j.interval()); |
| 258 } | 256 } |
| 259 } | 257 } |
| 260 } | 258 } |
| 259 if (data_.empty()) { | |
| 260 OnEmpty(); | |
| 261 } | |
|
xhwang
2015/11/19 23:34:17
tiny nit: braces can be omitted here. I actually s
hubbe
2015/11/20 23:24:22
No, unfortunately I'm still all mixed up since I u
| |
| 261 } | 262 } |
| 262 | 263 |
| 264 void MultiBuffer::OnEmpty() {} | |
|
xhwang
2015/11/19 23:34:17
What's the purpose of this? Will some test class o
hubbe
2015/11/20 23:24:22
Comment added in multibuffer.h
See ResourceMultiBu
| |
| 265 | |
| 263 void MultiBuffer::AddProvider(scoped_ptr<DataProvider> provider) { | 266 void MultiBuffer::AddProvider(scoped_ptr<DataProvider> provider) { |
| 264 // If there is already a provider in the same location, we delete it. | 267 // If there is already a provider in the same location, we delete it. |
| 265 DCHECK(!provider->Available()); | 268 DCHECK(!provider->Available()); |
| 266 BlockId pos = provider->Tell(); | 269 BlockId pos = provider->Tell(); |
| 267 DataProvider** place = &writer_index_[pos]; | 270 DataProvider** place = &writer_index_[pos]; |
| 268 DCHECK_NE(*place, provider.get()); | 271 DCHECK_NE(*place, provider.get()); |
| 269 if (*place) | 272 if (*place) |
| 270 delete *place; | 273 delete *place; |
| 271 *place = provider.release(); | 274 *place = provider.release(); |
| 272 } | 275 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 } | 474 } |
| 472 | 475 |
| 473 void MultiBuffer::IncrementMaxSize(int32_t size) { | 476 void MultiBuffer::IncrementMaxSize(int32_t size) { |
| 474 max_size_ += size; | 477 max_size_ += size; |
| 475 lru_->IncrementMaxSize(size); | 478 lru_->IncrementMaxSize(size); |
| 476 DCHECK_GE(max_size_, 0); | 479 DCHECK_GE(max_size_, 0); |
| 477 // Pruning only happens when blocks are added. | 480 // Pruning only happens when blocks are added. |
| 478 } | 481 } |
| 479 | 482 |
| 480 } // namespace media | 483 } // namespace media |
| OLD | NEW |