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/audio/audio_manager.h" | 5 #include "media/audio/audio_manager.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 // because the destructor runs on the audio thread. We want to always change | 247 // because the destructor runs on the audio thread. We want to always change |
248 // g_last_created from the main thread. | 248 // g_last_created from the main thread. |
249 if (g_last_created == instance) { | 249 if (g_last_created == instance) { |
250 g_last_created = nullptr; | 250 g_last_created = nullptr; |
251 } else { | 251 } else { |
252 // We create multiple instances of AudioManager only when testing. | 252 // We create multiple instances of AudioManager only when testing. |
253 // We should not encounter this case in production. | 253 // We should not encounter this case in production. |
254 LOG(WARNING) << "Multiple instances of AudioManager detected"; | 254 LOG(WARNING) << "Multiple instances of AudioManager detected"; |
255 } | 255 } |
256 | 256 |
257 #if defined(OS_MACOSX) | 257 // The deleter runs on the main thread, and AudioManager must be destroyed on |
258 // If we are on Mac, tasks after this point are not executed, hence this is | 258 // the audio thread. If the audio thread is the same as the main one, tasks |
259 // the only chance to delete the audio manager (which on Mac lives on the | 259 // after this point are not executed, hence this is the only chance to delete |
260 // main browser thread instead of a dedicated audio thread). If we don't | 260 // AudioManager. See http://crbug.com/623703 for more details. |
261 // delete here, the CoreAudio thread can keep providing callbacks, which | 261 if (instance->GetTaskRunner()->BelongsToCurrentThread()) { |
262 // uses a state that is destroyed in ~BrowserMainLoop(). | 262 delete instance; |
263 // See http://crbug.com/623703 for more details. | 263 return; |
264 DCHECK(instance->GetTaskRunner()->BelongsToCurrentThread()); | 264 } |
265 delete instance; | 265 |
266 #else | 266 // AudioManager must be destroyed on the audio thread. See |
267 // AudioManager must be destroyed on the audio thread. | 267 // http://crbug.com/705455 for an existing AudioManager lifetime issue. |
268 if (!instance->GetTaskRunner()->DeleteSoon(FROM_HERE, instance)) { | 268 if (!instance->GetTaskRunner()->DeleteSoon(FROM_HERE, instance)) |
269 LOG(WARNING) << "Failed to delete AudioManager instance."; | 269 LOG(WARNING) << "Failed to delete AudioManager instance."; |
270 } | |
271 #endif | |
272 } | 270 } |
273 | 271 |
274 // Forward declaration of the platform specific AudioManager factory function. | 272 // Forward declaration of the platform specific AudioManager factory function. |
275 ScopedAudioManagerPtr CreateAudioManager( | 273 ScopedAudioManagerPtr CreateAudioManager( |
276 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 274 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
277 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 275 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
278 AudioLogFactory* audio_log_factory); | 276 AudioLogFactory* audio_log_factory); |
279 | 277 |
280 void AudioManager::SetMaxStreamCountForTesting(int max_input, int max_output) { | 278 void AudioManager::SetMaxStreamCountForTesting(int max_input, int max_output) { |
281 NOTREACHED(); | 279 NOTREACHED(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 return GetHelper()->app_name(); | 351 return GetHelper()->app_name(); |
354 } | 352 } |
355 #endif | 353 #endif |
356 | 354 |
357 // static | 355 // static |
358 AudioManager* AudioManager::Get() { | 356 AudioManager* AudioManager::Get() { |
359 return g_last_created; | 357 return g_last_created; |
360 } | 358 } |
361 | 359 |
362 } // namespace media | 360 } // namespace media |
OLD | NEW |