Home | History | Annotate | Download | only in mediastream
      1 /*
      2  * Copyright (C) 2011 Ericsson AB. All rights reserved.
      3  * Copyright (C) 2012 Google Inc. All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *
      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
     14  *    distribution.
     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.
     18  *
     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.
     30  */
     31 
     32 #include "config.h"
     33 
     34 #include "core/platform/mediastream/MediaStreamCenter.h"
     35 
     36 #include "core/platform/mediastream/MediaStreamDescriptor.h"
     37 #include "modules/mediastream/MediaStreamTrackSourcesRequest.h"
     38 #include "public/platform/Platform.h"
     39 #include "public/platform/WebMediaStream.h"
     40 #include "public/platform/WebMediaStreamCenter.h"
     41 #include "public/platform/WebMediaStreamTrack.h"
     42 #include "public/platform/WebMediaStreamTrackSourcesRequest.h"
     43 #include "wtf/MainThread.h"
     44 #include "wtf/PassOwnPtr.h"
     45 
     46 namespace WebCore {
     47 
     48 MediaStreamCenter& MediaStreamCenter::instance()
     49 {
     50     ASSERT(isMainThread());
     51     DEFINE_STATIC_LOCAL(MediaStreamCenter, center, ());
     52     return center;
     53 }
     54 
     55 MediaStreamCenter::MediaStreamCenter()
     56     : m_private(adoptPtr(blink::Platform::current()->createMediaStreamCenter(this)))
     57 {
     58 }
     59 
     60 MediaStreamCenter::~MediaStreamCenter()
     61 {
     62 }
     63 
     64 bool MediaStreamCenter::getMediaStreamTrackSources(PassRefPtr<MediaStreamTrackSourcesRequest> request)
     65 {
     66     return m_private && m_private->getMediaStreamTrackSources(request);
     67 }
     68 
     69 void MediaStreamCenter::didSetMediaStreamTrackEnabled(MediaStreamDescriptor* stream,  MediaStreamComponent* component)
     70 {
     71     if (m_private) {
     72         if (component->enabled()) {
     73             m_private->didEnableMediaStreamTrack(stream, component);
     74             m_private->didEnableMediaStreamTrack(component);
     75         } else {
     76             m_private->didDisableMediaStreamTrack(stream, component);
     77             m_private->didDisableMediaStreamTrack(component);
     78         }
     79     }
     80 }
     81 
     82 bool MediaStreamCenter::didAddMediaStreamTrack(MediaStreamDescriptor* stream, MediaStreamComponent* component)
     83 {
     84     return m_private && m_private->didAddMediaStreamTrack(stream, component);
     85 }
     86 
     87 bool MediaStreamCenter::didRemoveMediaStreamTrack(MediaStreamDescriptor* stream, MediaStreamComponent* component)
     88 {
     89     return m_private && m_private->didRemoveMediaStreamTrack(stream, component);
     90 }
     91 
     92 void MediaStreamCenter::didStopLocalMediaStream(MediaStreamDescriptor* stream)
     93 {
     94     if (m_private)
     95         m_private->didStopLocalMediaStream(stream);
     96 }
     97 
     98 bool MediaStreamCenter::didStopMediaStreamTrack(MediaStreamComponent* track)
     99 {
    100     return m_private && m_private->didStopMediaStreamTrack(track);
    101 }
    102 
    103 void MediaStreamCenter::didCreateMediaStream(MediaStreamDescriptor* stream)
    104 {
    105     if (m_private) {
    106         blink::WebMediaStream webStream(stream);
    107         m_private->didCreateMediaStream(webStream);
    108     }
    109 }
    110 
    111 void MediaStreamCenter::didCreateMediaStreamTrack(MediaStreamComponent* track)
    112 {
    113     if (m_private)
    114         m_private->didCreateMediaStreamTrack(track);
    115 }
    116 
    117 void MediaStreamCenter::stopLocalMediaStream(const blink::WebMediaStream& webStream)
    118 {
    119     MediaStreamDescriptor* stream = webStream;
    120     MediaStreamDescriptorClient* client = stream->client();
    121     if (client)
    122         client->streamEnded();
    123     else
    124         stream->setEnded();
    125 }
    126 
    127 } // namespace WebCore
    128