Home | History | Annotate | Download | only in mediastream
      1 /*
      2  * Copyright (C) 2011 Ericsson AB. All rights reserved.
      3  * Copyright (C) 2013 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 #ifndef MediaStreamComponent_h
     33 #define MediaStreamComponent_h
     34 
     35 #include "platform/audio/AudioSourceProvider.h"
     36 #include "wtf/PassRefPtr.h"
     37 #include "wtf/RefCounted.h"
     38 #include "wtf/ThreadingPrimitives.h"
     39 #include "wtf/text/WTFString.h"
     40 
     41 namespace blink {
     42 class WebAudioSourceProvider;
     43 }
     44 
     45 namespace WebCore {
     46 
     47 class MediaStreamDescriptor;
     48 class MediaStreamSource;
     49 
     50 class PLATFORM_EXPORT MediaStreamComponent : public RefCounted<MediaStreamComponent> {
     51 public:
     52     class ExtraData : public RefCounted<ExtraData> {
     53     public:
     54         virtual ~ExtraData() { }
     55     };
     56 
     57     static PassRefPtr<MediaStreamComponent> create(PassRefPtr<MediaStreamSource>);
     58     static PassRefPtr<MediaStreamComponent> create(const String& id, PassRefPtr<MediaStreamSource>);
     59     static PassRefPtr<MediaStreamComponent> create(MediaStreamDescriptor*, PassRefPtr<MediaStreamSource>);
     60 
     61     MediaStreamDescriptor* stream() const { return m_stream; }
     62     void setStream(MediaStreamDescriptor* stream) { m_stream = stream; }
     63 
     64     MediaStreamSource* source() const { return m_source.get(); }
     65 
     66     String id() const { return m_id; }
     67     bool enabled() const { return m_enabled; }
     68     void setEnabled(bool enabled) { m_enabled = enabled; }
     69 
     70 #if ENABLE(WEB_AUDIO)
     71     AudioSourceProvider* audioSourceProvider() { return &m_sourceProvider; }
     72     void setSourceProvider(blink::WebAudioSourceProvider* provider) { m_sourceProvider.wrap(provider); }
     73 #endif // ENABLE(WEB_AUDIO)
     74 
     75     ExtraData* extraData() const { return m_extraData.get(); }
     76     void setExtraData(PassRefPtr<ExtraData> extraData) { m_extraData = extraData; }
     77 
     78 private:
     79     MediaStreamComponent(const String& id, MediaStreamDescriptor*, PassRefPtr<MediaStreamSource>);
     80 
     81 #if ENABLE(WEB_AUDIO)
     82     // AudioSourceProviderImpl wraps a WebAudioSourceProvider::provideInput()
     83     // calls into chromium to get a rendered audio stream.
     84 
     85     class AudioSourceProviderImpl : public AudioSourceProvider {
     86     public:
     87         AudioSourceProviderImpl()
     88             : m_webAudioSourceProvider(0)
     89         {
     90         }
     91 
     92         virtual ~AudioSourceProviderImpl() { }
     93 
     94         // Wraps the given blink::WebAudioSourceProvider to WebCore::AudioSourceProvider.
     95         void wrap(blink::WebAudioSourceProvider*);
     96 
     97         // WebCore::AudioSourceProvider
     98         virtual void provideInput(WebCore::AudioBus*, size_t framesToProcess);
     99 
    100     private:
    101         blink::WebAudioSourceProvider* m_webAudioSourceProvider;
    102         Mutex m_provideInputLock;
    103     };
    104 
    105     AudioSourceProviderImpl m_sourceProvider;
    106 #endif // ENABLE(WEB_AUDIO)
    107 
    108     MediaStreamDescriptor* m_stream;
    109     RefPtr<MediaStreamSource> m_source;
    110     String m_id;
    111     bool m_enabled;
    112     RefPtr<ExtraData> m_extraData;
    113 };
    114 
    115 typedef Vector<RefPtr<MediaStreamComponent> > MediaStreamComponentVector;
    116 
    117 } // namespace WebCore
    118 
    119 #endif // MediaStreamComponent_h
    120