2 * Copyright (C) 2011 Ericsson AB. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * 3. Neither the name of Ericsson nor the names of its contributors
16 * may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "platform/mediastream/MediaStreamCenter.h"
35 #include "platform/mediastream/MediaStreamDescriptor.h"
36 #include "platform/mediastream/MediaStreamTrackSourcesRequest.h"
37 #include "platform/mediastream/MediaStreamWebAudioSource.h"
38 #include "public/platform/Platform.h"
39 #include "public/platform/WebAudioSourceProvider.h"
40 #include "public/platform/WebMediaStream.h"
41 #include "public/platform/WebMediaStreamCenter.h"
42 #include "public/platform/WebMediaStreamTrack.h"
43 #include "wtf/Assertions.h"
44 #include "wtf/MainThread.h"
45 #include "wtf/PassOwnPtr.h"
49 MediaStreamCenter
& MediaStreamCenter::instance()
51 ASSERT(isMainThread());
52 DEFINE_STATIC_LOCAL(MediaStreamCenter
, center
, ());
56 MediaStreamCenter::MediaStreamCenter()
57 : m_private(adoptPtr(Platform::current()->createMediaStreamCenter(this)))
61 MediaStreamCenter::~MediaStreamCenter()
65 void MediaStreamCenter::didSetMediaStreamTrackEnabled(MediaStreamComponent
* component
)
68 if (component
->enabled()) {
69 m_private
->didEnableMediaStreamTrack(component
);
71 m_private
->didDisableMediaStreamTrack(component
);
76 bool MediaStreamCenter::didAddMediaStreamTrack(MediaStreamDescriptor
* stream
, MediaStreamComponent
* component
)
78 return m_private
&& m_private
->didAddMediaStreamTrack(stream
, component
);
81 bool MediaStreamCenter::didRemoveMediaStreamTrack(MediaStreamDescriptor
* stream
, MediaStreamComponent
* component
)
83 return m_private
&& m_private
->didRemoveMediaStreamTrack(stream
, component
);
86 void MediaStreamCenter::didStopLocalMediaStream(MediaStreamDescriptor
* stream
)
89 m_private
->didStopLocalMediaStream(stream
);
92 bool MediaStreamCenter::didStopMediaStreamTrack(MediaStreamComponent
* track
)
94 return m_private
&& m_private
->didStopMediaStreamTrack(track
);
97 void MediaStreamCenter::didCreateMediaStreamAndTracks(MediaStreamDescriptor
* stream
)
102 for (size_t i
= 0; i
< stream
->numberOfAudioComponents(); ++i
)
103 didCreateMediaStreamTrack(stream
->audioComponent(i
));
105 for (size_t i
= 0; i
< stream
->numberOfVideoComponents(); ++i
)
106 didCreateMediaStreamTrack(stream
->videoComponent(i
));
108 WebMediaStream
webStream(stream
);
109 m_private
->didCreateMediaStream(webStream
);
112 void MediaStreamCenter::didCreateMediaStream(MediaStreamDescriptor
* stream
)
115 WebMediaStream
webStream(stream
);
116 m_private
->didCreateMediaStream(webStream
);
120 void MediaStreamCenter::didCreateMediaStreamTrack(MediaStreamComponent
* track
)
123 m_private
->didCreateMediaStreamTrack(track
);
126 PassOwnPtr
<AudioSourceProvider
> MediaStreamCenter::createWebAudioSourceFromMediaStreamTrack(MediaStreamComponent
* track
)
128 ASSERT_UNUSED(track
, track
);
129 #if ENABLE(WEB_AUDIO)
131 return MediaStreamWebAudioSource::create(adoptPtr(m_private
->createWebAudioSourceFromMediaStreamTrack(track
)));
137 void MediaStreamCenter::stopLocalMediaStream(const WebMediaStream
& webStream
)
139 MediaStreamDescriptor
* stream
= webStream
;
140 MediaStreamDescriptorClient
* client
= stream
->client();
142 client
->streamEnded();