OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 void MediaStreamSource::addAudioConsumer(AudioDestinationConsumer* consumer) { | 78 void MediaStreamSource::addAudioConsumer(AudioDestinationConsumer* consumer) { |
79 ASSERT(m_requiresConsumer); | 79 ASSERT(m_requiresConsumer); |
80 MutexLocker locker(m_audioConsumersLock); | 80 MutexLocker locker(m_audioConsumersLock); |
81 m_audioConsumers.insert(consumer); | 81 m_audioConsumers.insert(consumer); |
82 } | 82 } |
83 | 83 |
84 bool MediaStreamSource::removeAudioConsumer( | 84 bool MediaStreamSource::removeAudioConsumer( |
85 AudioDestinationConsumer* consumer) { | 85 AudioDestinationConsumer* consumer) { |
86 ASSERT(m_requiresConsumer); | 86 ASSERT(m_requiresConsumer); |
87 MutexLocker locker(m_audioConsumersLock); | 87 MutexLocker locker(m_audioConsumersLock); |
88 auto it = m_audioConsumers.find(consumer); | 88 HeapHashSet<Member<AudioDestinationConsumer>>::iterator it = |
| 89 m_audioConsumers.find(consumer); |
89 if (it == m_audioConsumers.end()) | 90 if (it == m_audioConsumers.end()) |
90 return false; | 91 return false; |
91 m_audioConsumers.erase(it); | 92 m_audioConsumers.erase(it); |
92 return true; | 93 return true; |
93 } | 94 } |
94 | 95 |
95 void MediaStreamSource::getSettings(WebMediaStreamTrack::Settings& settings) { | 96 void MediaStreamSource::getSettings(WebMediaStreamTrack::Settings& settings) { |
96 settings.deviceId = id(); | 97 settings.deviceId = id(); |
97 } | 98 } |
98 | 99 |
99 void MediaStreamSource::setAudioFormat(size_t numberOfChannels, | 100 void MediaStreamSource::setAudioFormat(size_t numberOfChannels, |
100 float sampleRate) { | 101 float sampleRate) { |
101 ASSERT(m_requiresConsumer); | 102 ASSERT(m_requiresConsumer); |
102 MutexLocker locker(m_audioConsumersLock); | 103 MutexLocker locker(m_audioConsumersLock); |
103 for (AudioDestinationConsumer* consumer : m_audioConsumers) | 104 for (HeapHashSet<Member<AudioDestinationConsumer>>::iterator it = |
104 consumer->setFormat(numberOfChannels, sampleRate); | 105 m_audioConsumers.begin(); |
| 106 it != m_audioConsumers.end(); ++it) |
| 107 (*it)->setFormat(numberOfChannels, sampleRate); |
105 } | 108 } |
106 | 109 |
107 void MediaStreamSource::consumeAudio(AudioBus* bus, size_t numberOfFrames) { | 110 void MediaStreamSource::consumeAudio(AudioBus* bus, size_t numberOfFrames) { |
108 ASSERT(m_requiresConsumer); | 111 ASSERT(m_requiresConsumer); |
109 MutexLocker locker(m_audioConsumersLock); | 112 MutexLocker locker(m_audioConsumersLock); |
110 // Prevent GCs from going ahead while this iteration runs, attempting to | 113 // Prevent GCs from going ahead while this iteration runs, attempting to |
111 // pinpoint crbug.com/682945 failures. | 114 // pinpoint crbug.com/682945 failures. |
112 ThreadState::MainThreadGCForbiddenScope scope; | 115 ThreadState::MainThreadGCForbiddenScope scope; |
113 for (AudioDestinationConsumer* consumer : m_audioConsumers) | 116 for (HeapHashSet<Member<AudioDestinationConsumer>>::iterator it = |
114 consumer->consumeAudio(bus, numberOfFrames); | 117 m_audioConsumers.begin(); |
| 118 it != m_audioConsumers.end(); ++it) |
| 119 (*it)->consumeAudio(bus, numberOfFrames); |
115 } | 120 } |
116 | 121 |
117 DEFINE_TRACE(MediaStreamSource) { | 122 DEFINE_TRACE(MediaStreamSource) { |
118 visitor->trace(m_observers); | 123 visitor->trace(m_observers); |
| 124 visitor->trace(m_audioConsumers); |
119 } | 125 } |
120 | 126 |
121 } // namespace blink | 127 } // namespace blink |
OLD | NEW |