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(WebKit::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         else
     75             m_private->didDisableMediaStreamTrack(stream, component);
     76     }
     77 }
     78 
     79 bool MediaStreamCenter::didAddMediaStreamTrack(MediaStreamDescriptor* stream, MediaStreamComponent* component)
     80 {
     81     return m_private && m_private->didAddMediaStreamTrack(stream, component);
     82 }
     83 
     84 bool MediaStreamCenter::didRemoveMediaStreamTrack(MediaStreamDescriptor* stream, MediaStreamComponent* component)
     85 {
     86     return m_private && m_private->didRemoveMediaStreamTrack(stream, component);
     87 }
     88 
     89 void MediaStreamCenter::didStopLocalMediaStream(MediaStreamDescriptor* stream)
     90 {
     91     if (m_private) {
     92         m_private->didStopLocalMediaStream(stream);
     93         for (unsigned i = 0; i < stream->numberOfAudioComponents(); i++)
     94             stream->audioComponent(i)->source()->setReadyState(MediaStreamSource::ReadyStateEnded);
     95         for (unsigned i = 0; i < stream->numberOfVideoComponents(); i++)
     96             stream->videoComponent(i)->source()->setReadyState(MediaStreamSource::ReadyStateEnded);
     97     }
     98 }
     99 
    100 void MediaStreamCenter::didCreateMediaStream(MediaStreamDescriptor* stream)
    101 {
    102     if (m_private) {
    103         WebKit::WebMediaStream webStream(stream);
    104         m_private->didCreateMediaStream(webStream);
    105     }
    106 }
    107 
    108 void MediaStreamCenter::stopLocalMediaStream(const WebKit::WebMediaStream& webStream)
    109 {
    110     MediaStreamDescriptor* stream = webStream;
    111     MediaStreamDescriptorClient* client = stream->client();
    112     if (client)
    113         client->streamEnded();
    114     else
    115         stream->setEnded();
    116 }
    117 
    118 } // namespace WebCore
    119