| 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 // FIXME: Oilpan: This disposer pattern is duplicated in a lot of places. |
| 38 // We should create a good abstraction class for this and remove the code duplic
ation. |
| 39 class MediaStreamSourceDisposer { |
| 40 public: |
| 41 explicit MediaStreamSourceDisposer(MediaStreamSource& source) : m_source(sou
rce) { } |
| 42 ~MediaStreamSourceDisposer() |
| 43 { |
| 44 m_source.dispose(); |
| 45 } |
| 46 |
| 47 private: |
| 48 MediaStreamSource& m_source; |
| 49 }; |
| 50 |
| 51 typedef HeapHashMap<WeakMember<MediaStreamSource>, OwnPtr<MediaStreamSourceDispo
ser> > SourceDisposers; |
| 52 |
| 53 static SourceDisposers& sourceDisposers() |
| 38 { | 54 { |
| 39 return adoptRef(new MediaStreamSource(id, type, name, readyState, requiresCo
nsumer)); | 55 DEFINE_STATIC_LOCAL(Persistent<SourceDisposers>, disposers, (new SourceDispo
sers)); |
| 56 return *disposers; |
| 57 } |
| 58 |
| 59 MediaStreamSource* MediaStreamSource::create(const String& id, Type type, const
String& name, ReadyState readyState, bool requiresConsumer) |
| 60 { |
| 61 return new MediaStreamSource(id, type, name, readyState, requiresConsumer); |
| 40 } | 62 } |
| 41 | 63 |
| 42 MediaStreamSource::MediaStreamSource(const String& id, Type type, const String&
name, ReadyState readyState, bool requiresConsumer) | 64 MediaStreamSource::MediaStreamSource(const String& id, Type type, const String&
name, ReadyState readyState, bool requiresConsumer) |
| 43 : m_id(id) | 65 : m_id(id) |
| 44 , m_type(type) | 66 , m_type(type) |
| 45 , m_name(name) | 67 , m_name(name) |
| 46 , m_readyState(readyState) | 68 , m_readyState(readyState) |
| 47 , m_requiresConsumer(requiresConsumer) | 69 , m_requiresConsumer(requiresConsumer) |
| 48 { | 70 { |
| 71 sourceDisposers().add(this, adoptPtr(new MediaStreamSourceDisposer(*this))); |
| 72 } |
| 73 |
| 74 void MediaStreamSource::dispose() |
| 75 { |
| 76 m_extraData = nullptr; |
| 49 } | 77 } |
| 50 | 78 |
| 51 void MediaStreamSource::setReadyState(ReadyState readyState) | 79 void MediaStreamSource::setReadyState(ReadyState readyState) |
| 52 { | 80 { |
| 53 if (m_readyState != ReadyStateEnded && m_readyState != readyState) { | 81 if (m_readyState != ReadyStateEnded && m_readyState != readyState) { |
| 54 m_readyState = readyState; | 82 m_readyState = readyState; |
| 55 for (Vector<Observer*>::iterator i = m_observers.begin(); i != m_observe
rs.end(); ++i) | 83 for (HeapHashSet<WeakMember<Observer> >::iterator i = m_observers.begin(
); i != m_observers.end(); ++i) |
| 56 (*i)->sourceChangedState(); | 84 (*i)->sourceChangedState(); |
| 57 } | 85 } |
| 58 } | 86 } |
| 59 | 87 |
| 60 void MediaStreamSource::addObserver(MediaStreamSource::Observer* observer) | 88 void MediaStreamSource::addObserver(MediaStreamSource::Observer* observer) |
| 61 { | 89 { |
| 62 m_observers.append(observer); | 90 ASSERT(!m_observers.contains(observer)); |
| 63 } | 91 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 } | 92 } |
| 71 | 93 |
| 72 void MediaStreamSource::addAudioConsumer(AudioDestinationConsumer* consumer) | 94 void MediaStreamSource::addAudioConsumer(AudioDestinationConsumer* consumer) |
| 73 { | 95 { |
| 74 ASSERT(m_requiresConsumer); | 96 ASSERT(m_requiresConsumer); |
| 75 MutexLocker locker(m_audioConsumersLock); | 97 MutexLocker locker(m_audioConsumersLock); |
| 76 m_audioConsumers.add(consumer); | 98 m_audioConsumers.add(consumer); |
| 77 } | 99 } |
| 78 | 100 |
| 79 bool MediaStreamSource::removeAudioConsumer(AudioDestinationConsumer* consumer) | 101 bool MediaStreamSource::removeAudioConsumer(AudioDestinationConsumer* consumer) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 96 } | 118 } |
| 97 | 119 |
| 98 void MediaStreamSource::consumeAudio(AudioBus* bus, size_t numberOfFrames) | 120 void MediaStreamSource::consumeAudio(AudioBus* bus, size_t numberOfFrames) |
| 99 { | 121 { |
| 100 ASSERT(m_requiresConsumer); | 122 ASSERT(m_requiresConsumer); |
| 101 MutexLocker locker(m_audioConsumersLock); | 123 MutexLocker locker(m_audioConsumersLock); |
| 102 for (HeapHashSet<Member<AudioDestinationConsumer> >::iterator it = m_audioCo
nsumers.begin(); it != m_audioConsumers.end(); ++it) | 124 for (HeapHashSet<Member<AudioDestinationConsumer> >::iterator it = m_audioCo
nsumers.begin(); it != m_audioConsumers.end(); ++it) |
| 103 (*it)->consumeAudio(bus, numberOfFrames); | 125 (*it)->consumeAudio(bus, numberOfFrames); |
| 104 } | 126 } |
| 105 | 127 |
| 128 void MediaStreamSource::trace(Visitor* visitor) |
| 129 { |
| 130 visitor->trace(m_observers); |
| 131 visitor->trace(m_audioConsumers); |
| 132 } |
| 133 |
| 106 } // namespace blink | 134 } // namespace blink |
| 135 |
| OLD | NEW |