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