2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2011 Ericsson AB. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 #include "core/dom/ContextLifecycleObserver.h"
30 #include "core/html/URLRegistry.h"
31 #include "modules/EventTargetModules.h"
32 #include "modules/mediastream/MediaStreamTrack.h"
33 #include "platform/Timer.h"
34 #include "platform/mediastream/MediaStreamDescriptor.h"
40 class MediaStream FINAL
41 : public RefCountedGarbageCollectedWillBeGarbageCollectedFinalized<MediaStream>
42 , public URLRegistrable
43 , public MediaStreamDescriptorClient
44 , public EventTargetWithInlineData
45 , public ContextLifecycleObserver {
46 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollectedWillBeGarbageCollectedFinalized<MediaStream>);
47 DEFINE_WRAPPERTYPEINFO();
48 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaStream);
50 static MediaStream* create(ExecutionContext*);
51 static MediaStream* create(ExecutionContext*, MediaStream*);
52 static MediaStream* create(ExecutionContext*, const MediaStreamTrackVector&);
53 static MediaStream* create(ExecutionContext*, PassRefPtr<MediaStreamDescriptor>);
54 virtual ~MediaStream();
57 String label() const { return m_descriptor->id(); }
59 String id() const { return m_descriptor->id(); }
61 void addTrack(MediaStreamTrack*, ExceptionState&);
62 void removeTrack(MediaStreamTrack*, ExceptionState&);
63 MediaStreamTrack* getTrackById(String);
64 MediaStream* clone(ExecutionContext*);
66 MediaStreamTrackVector getAudioTracks() const { return m_audioTracks; }
67 MediaStreamTrackVector getVideoTracks() const { return m_videoTracks; }
68 MediaStreamTrackVector getTracks();
73 DEFINE_ATTRIBUTE_EVENT_LISTENER(ended);
74 DEFINE_ATTRIBUTE_EVENT_LISTENER(addtrack);
75 DEFINE_ATTRIBUTE_EVENT_LISTENER(removetrack);
79 // MediaStreamDescriptorClient
80 virtual void streamEnded() OVERRIDE;
82 MediaStreamDescriptor* descriptor() const { return m_descriptor.get(); }
85 virtual const AtomicString& interfaceName() const OVERRIDE;
86 virtual ExecutionContext* executionContext() const OVERRIDE;
89 virtual URLRegistry& registry() const OVERRIDE;
91 virtual void trace(Visitor*) OVERRIDE;
94 MediaStream(ExecutionContext*, PassRefPtr<MediaStreamDescriptor>);
95 MediaStream(ExecutionContext*, const MediaStreamTrackVector& audioTracks, const MediaStreamTrackVector& videoTracks);
97 // ContextLifecycleObserver
98 virtual void contextDestroyed() OVERRIDE;
100 // MediaStreamDescriptorClient
101 virtual void addRemoteTrack(MediaStreamComponent*) OVERRIDE;
102 virtual void removeRemoteTrack(MediaStreamComponent*) OVERRIDE;
104 void scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event>);
105 void scheduledEventTimerFired(Timer<MediaStream>*);
109 MediaStreamTrackVector m_audioTracks;
110 MediaStreamTrackVector m_videoTracks;
111 RefPtr<MediaStreamDescriptor> m_descriptor;
113 Timer<MediaStream> m_scheduledEventTimer;
114 WillBeHeapVector<RefPtrWillBeMember<Event> > m_scheduledEvents;
117 typedef HeapVector<Member<MediaStream> > MediaStreamVector;
121 #endif // MediaStream_h