• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef MediaStreamSource_h
33 #define MediaStreamSource_h
34 
35 #include "platform/PlatformExport.h"
36 #include "platform/audio/AudioDestinationConsumer.h"
37 #include "public/platform/WebMediaConstraints.h"
38 #include "wtf/OwnPtr.h"
39 #include "wtf/PassOwnPtr.h"
40 #include "wtf/RefCounted.h"
41 #include "wtf/ThreadingPrimitives.h"
42 #include "wtf/Vector.h"
43 #include "wtf/text/WTFString.h"
44 
45 namespace blink {
46 
47 class PLATFORM_EXPORT MediaStreamSource FINAL : public RefCounted<MediaStreamSource> {
48 public:
49     class Observer {
50     public:
~Observer()51         virtual ~Observer() { }
52         virtual void sourceChangedState() = 0;
53     };
54 
55     class ExtraData {
56     public:
~ExtraData()57         virtual ~ExtraData() { }
58     };
59 
60     enum Type {
61         TypeAudio,
62         TypeVideo
63     };
64 
65     enum ReadyState {
66         ReadyStateLive = 0,
67         ReadyStateMuted = 1,
68         ReadyStateEnded = 2
69     };
70 
71     static PassRefPtr<MediaStreamSource> create(const String& id, Type, const String& name, ReadyState = ReadyStateLive, bool requiresConsumer = false);
72 
id()73     const String& id() const { return m_id; }
type()74     Type type() const { return m_type; }
name()75     const String& name() const { return m_name; }
76 
77     void setReadyState(ReadyState);
readyState()78     ReadyState readyState() const { return m_readyState; }
79 
80     void addObserver(Observer*);
81     void removeObserver(Observer*);
82 
extraData()83     ExtraData* extraData() const { return m_extraData.get(); }
setExtraData(PassOwnPtr<ExtraData> extraData)84     void setExtraData(PassOwnPtr<ExtraData> extraData) { m_extraData = extraData; }
85 
setConstraints(blink::WebMediaConstraints constraints)86     void setConstraints(blink::WebMediaConstraints constraints) { m_constraints = constraints; }
constraints()87     blink::WebMediaConstraints constraints() { return m_constraints; }
88 
89     void setAudioFormat(size_t numberOfChannels, float sampleRate);
90     void consumeAudio(AudioBus*, size_t numberOfFrames);
91 
requiresAudioConsumer()92     bool requiresAudioConsumer() const { return m_requiresConsumer; }
93     void addAudioConsumer(AudioDestinationConsumer*);
94     bool removeAudioConsumer(AudioDestinationConsumer*);
audioConsumers()95     const HeapHashSet<Member<AudioDestinationConsumer> >& audioConsumers() { return m_audioConsumers; }
96 
97 private:
98     MediaStreamSource(const String& id, Type, const String& name, ReadyState, bool requiresConsumer);
99 
100     String m_id;
101     Type m_type;
102     String m_name;
103     ReadyState m_readyState;
104     bool m_requiresConsumer;
105     Vector<Observer*> m_observers;
106     Mutex m_audioConsumersLock;
107     PersistentHeapHashSet<Member<AudioDestinationConsumer> > m_audioConsumers;
108     OwnPtr<ExtraData> m_extraData;
109     blink::WebMediaConstraints m_constraints;
110 };
111 
112 typedef Vector<RefPtr<MediaStreamSource> > MediaStreamSourceVector;
113 
114 } // namespace blink
115 
116 #endif // MediaStreamSource_h
117