Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: trunk/Source/platform/mediastream/MediaStreamSource.cpp

Issue 562663002: Revert 181702 "Oilpan: Move MediaStreamSource, MediaStreamCompon..." (Closed) Base URL: svn://svn.chromium.org/blink/
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // The disposer pattern actually makes the deletion of the extra data happen 37 PassRefPtr<MediaStreamSource> MediaStreamSource::create(const String& id, Type t ype, const String& name, ReadyState readyState, bool requiresConsumer)
38 // earlier and not later. The disposer makes sure that the extra data is
39 // destructed in weak processing which is run before sweeping and therefore
40 // all the objects are still alive and can be touched.
41 //
42 // FIXME: Oilpan: This disposer pattern is duplicated in a lot of places.
43 // We should create a good abstraction class for this and remove the code duplic ation.
44 class MediaStreamSourceDisposer {
45 public:
46 explicit MediaStreamSourceDisposer(MediaStreamSource& source) : m_source(sou rce) { }
47 ~MediaStreamSourceDisposer()
48 {
49 m_source.dispose();
50 }
51
52 private:
53 MediaStreamSource& m_source;
54 };
55
56 typedef HeapHashMap<WeakMember<MediaStreamSource>, OwnPtr<MediaStreamSourceDispo ser> > SourceDisposers;
57
58 static SourceDisposers& sourceDisposers()
59 { 38 {
60 DEFINE_STATIC_LOCAL(Persistent<SourceDisposers>, disposers, (new SourceDispo sers)); 39 return adoptRef(new MediaStreamSource(id, type, name, readyState, requiresCo nsumer));
61 return *disposers;
62 }
63
64 MediaStreamSource* MediaStreamSource::create(const String& id, Type type, const String& name, ReadyState readyState, bool requiresConsumer)
65 {
66 return new MediaStreamSource(id, type, name, readyState, requiresConsumer);
67 } 40 }
68 41
69 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)
70 : m_id(id) 43 : m_id(id)
71 , m_type(type) 44 , m_type(type)
72 , m_name(name) 45 , m_name(name)
73 , m_readyState(readyState) 46 , m_readyState(readyState)
74 , m_requiresConsumer(requiresConsumer) 47 , m_requiresConsumer(requiresConsumer)
75 { 48 {
76 sourceDisposers().add(this, adoptPtr(new MediaStreamSourceDisposer(*this)));
77 }
78
79 void MediaStreamSource::dispose()
80 {
81 m_extraData = nullptr;
82 } 49 }
83 50
84 void MediaStreamSource::setReadyState(ReadyState readyState) 51 void MediaStreamSource::setReadyState(ReadyState readyState)
85 { 52 {
86 if (m_readyState != ReadyStateEnded && m_readyState != readyState) { 53 if (m_readyState != ReadyStateEnded && m_readyState != readyState) {
87 m_readyState = readyState; 54 m_readyState = readyState;
88 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)
89 (*i)->sourceChangedState(); 56 (*i)->sourceChangedState();
90 } 57 }
91 } 58 }
92 59
93 void MediaStreamSource::addObserver(MediaStreamSource::Observer* observer) 60 void MediaStreamSource::addObserver(MediaStreamSource::Observer* observer)
94 { 61 {
95 ASSERT(!m_observers.contains(observer)); 62 m_observers.append(observer);
96 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);
97 } 70 }
98 71
99 void MediaStreamSource::addAudioConsumer(AudioDestinationConsumer* consumer) 72 void MediaStreamSource::addAudioConsumer(AudioDestinationConsumer* consumer)
100 { 73 {
101 ASSERT(m_requiresConsumer); 74 ASSERT(m_requiresConsumer);
102 MutexLocker locker(m_audioConsumersLock); 75 MutexLocker locker(m_audioConsumersLock);
103 m_audioConsumers.add(consumer); 76 m_audioConsumers.add(consumer);
104 } 77 }
105 78
106 bool MediaStreamSource::removeAudioConsumer(AudioDestinationConsumer* consumer) 79 bool MediaStreamSource::removeAudioConsumer(AudioDestinationConsumer* consumer)
(...skipping 16 matching lines...) Expand all
123 } 96 }
124 97
125 void MediaStreamSource::consumeAudio(AudioBus* bus, size_t numberOfFrames) 98 void MediaStreamSource::consumeAudio(AudioBus* bus, size_t numberOfFrames)
126 { 99 {
127 ASSERT(m_requiresConsumer); 100 ASSERT(m_requiresConsumer);
128 MutexLocker locker(m_audioConsumersLock); 101 MutexLocker locker(m_audioConsumersLock);
129 for (HeapHashSet<Member<AudioDestinationConsumer> >::iterator it = m_audioCo nsumers.begin(); it != m_audioConsumers.end(); ++it) 102 for (HeapHashSet<Member<AudioDestinationConsumer> >::iterator it = m_audioCo nsumers.begin(); it != m_audioConsumers.end(); ++it)
130 (*it)->consumeAudio(bus, numberOfFrames); 103 (*it)->consumeAudio(bus, numberOfFrames);
131 } 104 }
132 105
133 void MediaStreamSource::trace(Visitor* visitor)
134 {
135 visitor->trace(m_observers);
136 visitor->trace(m_audioConsumers);
137 }
138
139 } // namespace blink 106 } // namespace blink
140
OLDNEW
« no previous file with comments | « trunk/Source/platform/mediastream/MediaStreamSource.h ('k') | trunk/public/platform/WebMediaStream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698