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 "content/browser/renderer_host/media/audio_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/process.h" | 9 #include "base/process.h" |
10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 i != audio_entries_.end(); ++i) { | 322 i != audio_entries_.end(); ++i) { |
323 CloseAndDeleteStream(i->second); | 323 CloseAndDeleteStream(i->second); |
324 } | 324 } |
325 } | 325 } |
326 | 326 |
327 void AudioRendererHost::CloseAndDeleteStream(AudioEntry* entry) { | 327 void AudioRendererHost::CloseAndDeleteStream(AudioEntry* entry) { |
328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
329 | 329 |
330 if (!entry->pending_close) { | 330 if (!entry->pending_close) { |
331 entry->controller->Close( | 331 entry->controller->Close( |
332 base::Bind(&AudioRendererHost::OnStreamClosed, this, entry)); | 332 base::Bind(&AudioRendererHost::DeleteEntry, this, entry)); |
333 entry->pending_close = true; | 333 entry->pending_close = true; |
334 } | 334 } |
335 } | 335 } |
336 | 336 |
337 void AudioRendererHost::OnStreamClosed(AudioEntry* entry) { | |
338 // Delete the entry on the IO thread after we've closed the stream. | |
339 // (We're currently on the audio thread). | |
340 BrowserThread::PostTask( | |
341 BrowserThread::IO, FROM_HERE, | |
342 base::Bind(&AudioRendererHost::DeleteEntry, this, entry)); | |
343 } | |
344 | |
345 void AudioRendererHost::DeleteEntry(AudioEntry* entry) { | 337 void AudioRendererHost::DeleteEntry(AudioEntry* entry) { |
346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
347 | 339 |
348 // Delete the entry when this method goes out of scope. | 340 // Delete the entry when this method goes out of scope. |
349 scoped_ptr<AudioEntry> entry_deleter(entry); | 341 scoped_ptr<AudioEntry> entry_deleter(entry); |
350 | 342 |
351 // Erase the entry identified by |stream_id| from the map. | 343 // Erase the entry identified by |stream_id| from the map. |
352 audio_entries_.erase(entry->stream_id); | 344 audio_entries_.erase(entry->stream_id); |
353 | 345 |
354 // Notify the media observer. | 346 // Notify the media observer. |
(...skipping 28 matching lines...) Expand all Loading... |
383 | 375 |
384 // Iterate the map of entries. | 376 // Iterate the map of entries. |
385 // TODO(hclam): Implement a faster look up method. | 377 // TODO(hclam): Implement a faster look up method. |
386 for (AudioEntryMap::iterator i = audio_entries_.begin(); | 378 for (AudioEntryMap::iterator i = audio_entries_.begin(); |
387 i != audio_entries_.end(); ++i) { | 379 i != audio_entries_.end(); ++i) { |
388 if (!i->second->pending_close && controller == i->second->controller.get()) | 380 if (!i->second->pending_close && controller == i->second->controller.get()) |
389 return i->second; | 381 return i->second; |
390 } | 382 } |
391 return NULL; | 383 return NULL; |
392 } | 384 } |
OLD | NEW |