OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sounds/sounds_manager.h" | 5 #include "media/audio/sounds/sounds_manager.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 LOG(WARNING) << "Can't initialize AudioStreamHandler for key=" << key; | 57 LOG(WARNING) << "Can't initialize AudioStreamHandler for key=" << key; |
58 return false; | 58 return false; |
59 } | 59 } |
60 handlers_[key] = new_handler; | 60 handlers_[key] = new_handler; |
61 return true; | 61 return true; |
62 } | 62 } |
63 | 63 |
64 bool SoundsManagerImpl::Play(SoundKey key) { | 64 bool SoundsManagerImpl::Play(SoundKey key) { |
65 DCHECK(CalledOnValidThread()); | 65 DCHECK(CalledOnValidThread()); |
66 linked_ptr<AudioStreamHandler> handler = GetHandler(key); | 66 linked_ptr<AudioStreamHandler> handler = GetHandler(key); |
67 if (!handler.get()) | 67 return handler.get() && handler->IsInitialized() && handler->Play(); |
68 return false; | |
69 if (!handler->IsInitialized()) | |
70 return false; | |
71 return handler->Play(); | |
72 } | 68 } |
73 | 69 |
74 bool SoundsManagerImpl::Stop(SoundKey key) { | 70 bool SoundsManagerImpl::Stop(SoundKey key) { |
75 DCHECK(CalledOnValidThread()); | 71 DCHECK(CalledOnValidThread()); |
76 linked_ptr<AudioStreamHandler> handler = GetHandler(key); | 72 linked_ptr<AudioStreamHandler> handler = GetHandler(key); |
77 if (!handler.get()) | 73 if (!handler.get() || !handler->IsInitialized()) |
78 return false; | |
79 if (!handler->IsInitialized()) | |
80 return false; | 74 return false; |
81 handler->Stop(); | 75 handler->Stop(); |
82 return true; | 76 return true; |
83 } | 77 } |
84 | 78 |
85 base::TimeDelta SoundsManagerImpl::GetDuration(SoundKey key) { | 79 base::TimeDelta SoundsManagerImpl::GetDuration(SoundKey key) { |
86 DCHECK(CalledOnValidThread()); | 80 DCHECK(CalledOnValidThread()); |
87 linked_ptr<AudioStreamHandler> handler = GetHandler(key); | 81 linked_ptr<AudioStreamHandler> handler = GetHandler(key); |
88 if (!handler.get()) | 82 if (!handler.get() || !handler->IsInitialized()) |
89 return base::TimeDelta(); | 83 return base::TimeDelta(); |
90 if (!handler->IsInitialized()) | 84 return handler->duration(); |
91 return base::TimeDelta(); | |
92 const WavAudioHandler& wav_audio = handler->wav_audio_handler(); | |
93 return wav_audio.GetDuration(); | |
94 } | 85 } |
95 | 86 |
96 linked_ptr<AudioStreamHandler> SoundsManagerImpl::GetHandler(SoundKey key) { | 87 linked_ptr<AudioStreamHandler> SoundsManagerImpl::GetHandler(SoundKey key) { |
97 auto key_handler_pair_iter = handlers_.find(key); | 88 auto key_handler_pair_iter = handlers_.find(key); |
98 return key_handler_pair_iter == handlers_.end() ? | 89 return key_handler_pair_iter == handlers_.end() ? |
99 linked_ptr<AudioStreamHandler>() : key_handler_pair_iter->second; | 90 linked_ptr<AudioStreamHandler>() : key_handler_pair_iter->second; |
100 } | 91 } |
101 | 92 |
102 } // namespace | 93 } // namespace |
103 | 94 |
(...skipping 26 matching lines...) Expand all Loading... |
130 | 121 |
131 // static | 122 // static |
132 void SoundsManager::InitializeForTesting(SoundsManager* manager) { | 123 void SoundsManager::InitializeForTesting(SoundsManager* manager) { |
133 CHECK(!g_instance) << "SoundsManager is already initialized."; | 124 CHECK(!g_instance) << "SoundsManager is already initialized."; |
134 CHECK(manager); | 125 CHECK(manager); |
135 g_instance = manager; | 126 g_instance = manager; |
136 g_initialized_for_testing = true; | 127 g_initialized_for_testing = true; |
137 } | 128 } |
138 | 129 |
139 } // namespace media | 130 } // namespace media |
OLD | NEW |