• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  * Copyright (C) 2011 Ericsson AB. 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  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef MediaStream_h
27 #define MediaStream_h
28 
29 #include "bindings/v8/ScriptWrappable.h"
30 #include "core/dom/ContextLifecycleObserver.h"
31 #include "core/html/URLRegistry.h"
32 #include "modules/EventTargetModules.h"
33 #include "modules/mediastream/MediaStreamTrack.h"
34 #include "platform/Timer.h"
35 #include "platform/mediastream/MediaStreamDescriptor.h"
36 #include "wtf/RefCounted.h"
37 #include "wtf/RefPtr.h"
38 
39 namespace WebCore {
40 
41 class ExceptionState;
42 
43 class MediaStream FINAL : public RefCountedWillBeRefCountedGarbageCollected<MediaStream>, public ScriptWrappable,
44     public URLRegistrable, public MediaStreamDescriptorClient, public EventTargetWithInlineData, public ContextLifecycleObserver {
45     REFCOUNTED_EVENT_TARGET(MediaStream);
46     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaStream);
47 public:
48     static PassRefPtrWillBeRawPtr<MediaStream> create(ExecutionContext*);
49     static PassRefPtrWillBeRawPtr<MediaStream> create(ExecutionContext*, PassRefPtrWillBeRawPtr<MediaStream>);
50     static PassRefPtrWillBeRawPtr<MediaStream> create(ExecutionContext*, const MediaStreamTrackVector&);
51     static PassRefPtrWillBeRawPtr<MediaStream> create(ExecutionContext*, PassRefPtr<MediaStreamDescriptor>);
52     virtual ~MediaStream();
53 
54     // DEPRECATED
label()55     String label() const { return m_descriptor->id(); }
56 
id()57     String id() const { return m_descriptor->id(); }
58 
59     void addTrack(PassRefPtrWillBeRawPtr<MediaStreamTrack>, ExceptionState&);
60     void removeTrack(PassRefPtrWillBeRawPtr<MediaStreamTrack>, ExceptionState&);
61     MediaStreamTrack* getTrackById(String);
62     PassRefPtrWillBeRawPtr<MediaStream> clone(ExecutionContext*);
63 
getAudioTracks()64     MediaStreamTrackVector getAudioTracks() const { return m_audioTracks; }
getVideoTracks()65     MediaStreamTrackVector getVideoTracks() const { return m_videoTracks; }
66 
67     bool ended() const;
68     void stop();
69 
70     DEFINE_ATTRIBUTE_EVENT_LISTENER(ended);
71     DEFINE_ATTRIBUTE_EVENT_LISTENER(addtrack);
72     DEFINE_ATTRIBUTE_EVENT_LISTENER(removetrack);
73 
74     void trackEnded();
75 
76     // MediaStreamDescriptorClient
77     virtual void streamEnded() OVERRIDE;
78 
descriptor()79     MediaStreamDescriptor* descriptor() const { return m_descriptor.get(); }
80 
81     // EventTarget
82     virtual const AtomicString& interfaceName() const OVERRIDE;
83     virtual ExecutionContext* executionContext() const OVERRIDE;
84 
85     // URLRegistrable
86     virtual URLRegistry& registry() const OVERRIDE;
87 
88     virtual void trace(Visitor*) OVERRIDE;
89 
90 private:
91     MediaStream(ExecutionContext*, PassRefPtr<MediaStreamDescriptor>);
92     MediaStream(ExecutionContext*, const MediaStreamTrackVector& audioTracks, const MediaStreamTrackVector& videoTracks);
93 
94     // ContextLifecycleObserver
95     virtual void contextDestroyed() OVERRIDE;
96 
97     // MediaStreamDescriptorClient
98     virtual void addRemoteTrack(MediaStreamComponent*) OVERRIDE;
99     virtual void removeRemoteTrack(MediaStreamComponent*) OVERRIDE;
100 
101     void scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event>);
102     void scheduledEventTimerFired(Timer<MediaStream>*);
103 
104     bool m_stopped;
105 
106     MediaStreamTrackVector m_audioTracks;
107     MediaStreamTrackVector m_videoTracks;
108     RefPtr<MediaStreamDescriptor> m_descriptor;
109 
110     Timer<MediaStream> m_scheduledEventTimer;
111     WillBeHeapVector<RefPtrWillBeMember<Event> > m_scheduledEvents;
112 };
113 
114 typedef WillBeHeapVector<RefPtrWillBeMember<MediaStream> > MediaStreamVector;
115 
116 } // namespace WebCore
117 
118 #endif // MediaStream_h
119