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 MediaStreamSource* MediaStreamSource::create(const String& id, Type type, const
String& name, ReadyState readyState, bool requiresConsumer) | 37 PassRefPtr<MediaStreamSource> MediaStreamSource::create(const String& id, Type t
ype, const String& name, ReadyState readyState, bool requiresConsumer) |
38 { | 38 { |
39 return new MediaStreamSource(id, type, name, readyState, requiresConsumer); | 39 return adoptRef(new MediaStreamSource(id, type, name, readyState, requiresCo
nsumer)); |
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 (HeapHashSet<WeakMember<Observer> >::iterator i = m_observers.begin(
); i != m_observers.end(); ++i) | 55 for (Vector<Observer*>::iterator i = m_observers.begin(); i != m_observe
rs.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 ASSERT(!m_observers.contains(observer)); | 62 m_observers.append(observer); |
63 m_observers.add(observer); | 63 } |
| 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); |
64 } | 70 } |
65 | 71 |
66 void MediaStreamSource::addAudioConsumer(PassRefPtr<AudioDestinationConsumer> co
nsumer) | 72 void MediaStreamSource::addAudioConsumer(PassRefPtr<AudioDestinationConsumer> co
nsumer) |
67 { | 73 { |
68 ASSERT(m_requiresConsumer); | 74 ASSERT(m_requiresConsumer); |
69 MutexLocker locker(m_audioConsumersLock); | 75 MutexLocker locker(m_audioConsumersLock); |
70 m_audioConsumers.append(consumer); | 76 m_audioConsumers.append(consumer); |
71 } | 77 } |
72 | 78 |
73 bool MediaStreamSource::removeAudioConsumer(AudioDestinationConsumer* consumer) | 79 bool MediaStreamSource::removeAudioConsumer(AudioDestinationConsumer* consumer) |
(...skipping 17 matching lines...) Expand all Loading... |
91 } | 97 } |
92 | 98 |
93 void MediaStreamSource::consumeAudio(AudioBus* bus, size_t numberOfFrames) | 99 void MediaStreamSource::consumeAudio(AudioBus* bus, size_t numberOfFrames) |
94 { | 100 { |
95 ASSERT(m_requiresConsumer); | 101 ASSERT(m_requiresConsumer); |
96 MutexLocker locker(m_audioConsumersLock); | 102 MutexLocker locker(m_audioConsumersLock); |
97 for (Vector<RefPtr<AudioDestinationConsumer> >::iterator it = m_audioConsume
rs.begin(); it != m_audioConsumers.end(); ++it) | 103 for (Vector<RefPtr<AudioDestinationConsumer> >::iterator it = m_audioConsume
rs.begin(); it != m_audioConsumers.end(); ++it) |
98 (*it)->consumeAudio(bus, numberOfFrames); | 104 (*it)->consumeAudio(bus, numberOfFrames); |
99 } | 105 } |
100 | 106 |
101 void MediaStreamSource::trace(Visitor* visitor) | |
102 { | |
103 visitor->trace(m_observers); | |
104 } | |
105 | |
106 } // namespace blink | 107 } // namespace blink |
107 | |
OLD | NEW |