Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / exported / WebMediaStream.cpp
blob7ead4c231ef1bd1044035f8ec08ee482abbcfdee
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #include "config.h"
27 #include "public/platform/WebMediaStream.h"
29 #include "platform/UUID.h"
30 #include "platform/mediastream/MediaStreamComponent.h"
31 #include "platform/mediastream/MediaStreamDescriptor.h"
32 #include "platform/mediastream/MediaStreamSource.h"
33 #include "public/platform/WebMediaStreamSource.h"
34 #include "public/platform/WebMediaStreamTrack.h"
35 #include "public/platform/WebString.h"
36 #include "wtf/OwnPtr.h"
37 #include "wtf/PassOwnPtr.h"
38 #include "wtf/Vector.h"
40 namespace blink {
42 namespace {
44 class ExtraDataContainer : public MediaStreamDescriptor::ExtraData {
45 public:
46 ExtraDataContainer(PassOwnPtr<WebMediaStream::ExtraData> extraData) : m_extraData(extraData) { }
48 WebMediaStream::ExtraData* extraData() { return m_extraData.get(); }
50 private:
51 OwnPtr<WebMediaStream::ExtraData> m_extraData;
54 } // namespace
56 WebMediaStream::WebMediaStream(const PassRefPtr<MediaStreamDescriptor>& mediaStreamDescriptor)
57 : m_private(mediaStreamDescriptor)
61 WebMediaStream::WebMediaStream(MediaStreamDescriptor* mediaStreamDescriptor)
62 : m_private(mediaStreamDescriptor)
66 void WebMediaStream::reset()
68 m_private.reset();
71 WebString WebMediaStream::id() const
73 return m_private->id();
76 WebMediaStream::ExtraData* WebMediaStream::extraData() const
78 MediaStreamDescriptor::ExtraData* data = m_private->extraData();
79 if (!data)
80 return 0;
81 return static_cast<ExtraDataContainer*>(data)->extraData();
84 void WebMediaStream::setExtraData(ExtraData* extraData)
86 m_private->setExtraData(adoptPtr(new ExtraDataContainer(adoptPtr(extraData))));
89 void WebMediaStream::audioTracks(WebVector<WebMediaStreamTrack>& webTracks) const
91 size_t numberOfTracks = m_private->numberOfAudioComponents();
92 WebVector<WebMediaStreamTrack> result(numberOfTracks);
93 for (size_t i = 0; i < numberOfTracks; ++i)
94 result[i] = m_private->audioComponent(i);
95 webTracks.swap(result);
98 void WebMediaStream::videoTracks(WebVector<WebMediaStreamTrack>& webTracks) const
100 size_t numberOfTracks = m_private->numberOfVideoComponents();
101 WebVector<WebMediaStreamTrack> result(numberOfTracks);
102 for (size_t i = 0; i < numberOfTracks; ++i)
103 result[i] = m_private->videoComponent(i);
104 webTracks.swap(result);
107 void WebMediaStream::addTrack(const WebMediaStreamTrack& track)
109 ASSERT(!isNull());
110 m_private->addRemoteTrack(track);
113 void WebMediaStream::removeTrack(const WebMediaStreamTrack& track)
115 ASSERT(!isNull());
116 m_private->removeRemoteTrack(track);
119 WebMediaStream& WebMediaStream::operator=(const PassRefPtr<MediaStreamDescriptor>& mediaStreamDescriptor)
121 m_private = mediaStreamDescriptor;
122 return *this;
125 WebMediaStream::operator PassRefPtr<MediaStreamDescriptor>() const
127 return m_private.get();
130 WebMediaStream::operator MediaStreamDescriptor*() const
132 return m_private.get();
135 void WebMediaStream::initialize(const WebVector<WebMediaStreamTrack>& audioTracks, const WebVector<WebMediaStreamTrack>& videoTracks)
137 initialize(createCanonicalUUIDString(), audioTracks, videoTracks);
140 void WebMediaStream::initialize(const WebString& label, const WebVector<WebMediaStreamTrack>& audioTracks, const WebVector<WebMediaStreamTrack>& videoTracks)
142 MediaStreamComponentVector audio, video;
143 for (size_t i = 0; i < audioTracks.size(); ++i) {
144 MediaStreamComponent* component = audioTracks[i];
145 audio.append(component);
147 for (size_t i = 0; i < videoTracks.size(); ++i) {
148 MediaStreamComponent* component = videoTracks[i];
149 video.append(component);
151 m_private = MediaStreamDescriptor::create(label, audio, video);
154 void WebMediaStream::assign(const WebMediaStream& other)
156 m_private = other.m_private;
159 } // namespace blink