| 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 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "platform/mediastream/MediaStreamSource.h" | 32 #include "platform/mediastream/MediaStreamSource.h" |
| 33 | 33 |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 PassRefPtr<MediaStreamSource> MediaStreamSource::create(const String& id, Type t
ype, const String& name, ReadyState readyState, bool requiresConsumer) | 37 MediaStreamSource* MediaStreamSource::create(const String& id, Type type, const
String& name, ReadyState readyState, bool requiresConsumer) |
| 38 { | 38 { |
| 39 return adoptRef(new MediaStreamSource(id, type, name, readyState, requiresCo
nsumer)); | 39 return new MediaStreamSource(id, type, name, readyState, requiresConsumer); |
| 40 } | 40 } |
| 41 | 41 |
| 42 MediaStreamSource::MediaStreamSource(const String& id, Type type, const String&
name, ReadyState readyState, bool requiresConsumer) | 42 MediaStreamSource::MediaStreamSource(const String& id, Type type, const String&
name, ReadyState readyState, bool requiresConsumer) |
| 43 : m_id(id) | 43 : m_id(id) |
| 44 , m_type(type) | 44 , m_type(type) |
| 45 , m_name(name) | 45 , m_name(name) |
| 46 , m_readyState(readyState) | 46 , m_readyState(readyState) |
| 47 , m_requiresConsumer(requiresConsumer) | 47 , m_requiresConsumer(requiresConsumer) |
| 48 { | 48 { |
| 49 } | 49 } |
| 50 | 50 |
| 51 void MediaStreamSource::setReadyState(ReadyState readyState) | 51 void MediaStreamSource::setReadyState(ReadyState readyState) |
| 52 { | 52 { |
| 53 if (m_readyState != ReadyStateEnded && m_readyState != readyState) { | 53 if (m_readyState != ReadyStateEnded && m_readyState != readyState) { |
| 54 m_readyState = readyState; | 54 m_readyState = readyState; |
| 55 for (Vector<Observer*>::iterator i = m_observers.begin(); i != m_observe
rs.end(); ++i) | 55 for (HeapHashSet<WeakMember<Observer> >::iterator i = m_observers.begin(
); i != m_observers.end(); ++i) |
| 56 (*i)->sourceChangedState(); | 56 (*i)->sourceChangedState(); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 void MediaStreamSource::addObserver(MediaStreamSource::Observer* observer) | 60 void MediaStreamSource::addObserver(MediaStreamSource::Observer* observer) |
| 61 { | 61 { |
| 62 m_observers.append(observer); | 62 ASSERT(!m_observers.contains(observer)); |
| 63 } | 63 m_observers.add(observer); |
| 64 | |
| 65 void MediaStreamSource::removeObserver(MediaStreamSource::Observer* observer) | |
| 66 { | |
| 67 size_t pos = m_observers.find(observer); | |
| 68 if (pos != kNotFound) | |
| 69 m_observers.remove(pos); | |
| 70 } | 64 } |
| 71 | 65 |
| 72 void MediaStreamSource::addAudioConsumer(AudioDestinationConsumer* consumer) | 66 void MediaStreamSource::addAudioConsumer(AudioDestinationConsumer* consumer) |
| 73 { | 67 { |
| 74 ASSERT(m_requiresConsumer); | 68 ASSERT(m_requiresConsumer); |
| 75 MutexLocker locker(m_audioConsumersLock); | 69 MutexLocker locker(m_audioConsumersLock); |
| 76 m_audioConsumers.add(consumer); | 70 m_audioConsumers.add(consumer); |
| 77 } | 71 } |
| 78 | 72 |
| 79 bool MediaStreamSource::removeAudioConsumer(AudioDestinationConsumer* consumer) | 73 bool MediaStreamSource::removeAudioConsumer(AudioDestinationConsumer* consumer) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 96 } | 90 } |
| 97 | 91 |
| 98 void MediaStreamSource::consumeAudio(AudioBus* bus, size_t numberOfFrames) | 92 void MediaStreamSource::consumeAudio(AudioBus* bus, size_t numberOfFrames) |
| 99 { | 93 { |
| 100 ASSERT(m_requiresConsumer); | 94 ASSERT(m_requiresConsumer); |
| 101 MutexLocker locker(m_audioConsumersLock); | 95 MutexLocker locker(m_audioConsumersLock); |
| 102 for (HeapHashSet<Member<AudioDestinationConsumer> >::iterator it = m_audioCo
nsumers.begin(); it != m_audioConsumers.end(); ++it) | 96 for (HeapHashSet<Member<AudioDestinationConsumer> >::iterator it = m_audioCo
nsumers.begin(); it != m_audioConsumers.end(); ++it) |
| 103 (*it)->consumeAudio(bus, numberOfFrames); | 97 (*it)->consumeAudio(bus, numberOfFrames); |
| 104 } | 98 } |
| 105 | 99 |
| 100 void MediaStreamSource::trace(Visitor* visitor) |
| 101 { |
| 102 visitor->trace(m_observers); |
| 103 visitor->trace(m_audioConsumers); |
| 104 } |
| 105 |
| 106 } // namespace blink | 106 } // namespace blink |
| 107 |
| OLD | NEW |