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
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.
27 #include "public/platform/WebMediaStreamTrack.h"
29 #include "platform/mediastream/MediaStreamComponent.h"
30 #include "platform/mediastream/MediaStreamSource.h"
31 #include "public/platform/WebAudioSourceProvider.h"
32 #include "public/platform/WebMediaStream.h"
33 #include "public/platform/WebMediaStreamSource.h"
34 #include "public/platform/WebString.h"
40 class ExtraDataContainer
: public MediaStreamComponent::ExtraData
{
42 explicit ExtraDataContainer(PassOwnPtr
<WebMediaStreamTrack::ExtraData
> extraData
) : m_extraData(extraData
) { }
44 WebMediaStreamTrack::ExtraData
* extraData() { return m_extraData
.get(); }
47 OwnPtr
<WebMediaStreamTrack::ExtraData
> m_extraData
;
52 WebMediaStreamTrack
WebMediaStreamTrack::ExtraData::owner()
55 return WebMediaStreamTrack(m_owner
);
58 void WebMediaStreamTrack::ExtraData::setOwner(MediaStreamComponent
* owner
)
64 WebMediaStreamTrack::WebMediaStreamTrack(PassRefPtr
<MediaStreamComponent
> mediaStreamComponent
)
65 : m_private(mediaStreamComponent
)
69 WebMediaStreamTrack::WebMediaStreamTrack(MediaStreamComponent
* mediaStreamComponent
)
70 : m_private(mediaStreamComponent
)
74 WebMediaStreamTrack
& WebMediaStreamTrack::operator=(MediaStreamComponent
* mediaStreamComponent
)
76 m_private
= mediaStreamComponent
;
80 void WebMediaStreamTrack::initialize(const WebMediaStreamSource
& source
)
82 m_private
= MediaStreamComponent::create(source
);
85 void WebMediaStreamTrack::initialize(const WebString
& id
, const WebMediaStreamSource
& source
)
87 m_private
= MediaStreamComponent::create(id
, source
);
90 void WebMediaStreamTrack::reset()
95 WebMediaStreamTrack::operator PassRefPtr
<MediaStreamComponent
>() const
97 return m_private
.get();
100 WebMediaStreamTrack::operator MediaStreamComponent
*() const
102 return m_private
.get();
105 bool WebMediaStreamTrack::isEnabled() const
107 ASSERT(!m_private
.isNull());
108 return m_private
->enabled();
111 bool WebMediaStreamTrack::isMuted() const
113 ASSERT(!m_private
.isNull());
114 return m_private
->muted();
117 WebString
WebMediaStreamTrack::id() const
119 ASSERT(!m_private
.isNull());
120 return m_private
->id();
123 WebMediaStreamSource
WebMediaStreamTrack::source() const
125 ASSERT(!m_private
.isNull());
126 return WebMediaStreamSource(m_private
->source());
129 WebMediaStreamTrack::ExtraData
* WebMediaStreamTrack::extraData() const
131 MediaStreamComponent::ExtraData
* data
= m_private
->extraData();
134 return static_cast<ExtraDataContainer
*>(data
)->extraData();
137 void WebMediaStreamTrack::setExtraData(ExtraData
* extraData
)
139 ASSERT(!m_private
.isNull());
142 extraData
->setOwner(m_private
.get());
144 m_private
->setExtraData(adoptPtr(new ExtraDataContainer(adoptPtr(extraData
))));
147 void WebMediaStreamTrack::setSourceProvider(WebAudioSourceProvider
* provider
)
149 #if ENABLE(WEB_AUDIO)
150 ASSERT(!m_private
.isNull());
151 m_private
->setSourceProvider(provider
);
152 #endif // ENABLE(WEB_AUDIO)
155 void WebMediaStreamTrack::assign(const WebMediaStreamTrack
& other
)
157 m_private
= other
.m_private
;