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