• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef MediaSource_h
32 #define MediaSource_h
33 
34 #include "bindings/v8/ScriptWrappable.h"
35 #include "core/dom/ActiveDOMObject.h"
36 #include "core/events/EventTarget.h"
37 #include "core/html/HTMLMediaSource.h"
38 #include "core/html/URLRegistry.h"
39 #include "modules/mediasource/SourceBuffer.h"
40 #include "modules/mediasource/SourceBufferList.h"
41 #include "public/platform/WebMediaSource.h"
42 #include "wtf/PassOwnPtr.h"
43 #include "wtf/RefCounted.h"
44 #include "wtf/Vector.h"
45 
46 namespace blink {
47 class WebSourceBuffer;
48 }
49 
50 namespace WebCore {
51 
52 class ExceptionState;
53 class GenericEventQueue;
54 
55 class MediaSource FINAL
56     : public RefCountedWillBeRefCountedGarbageCollected<MediaSource>
57     , public HTMLMediaSource
58     , public ActiveDOMObject
59     , public EventTargetWithInlineData
60     , public ScriptWrappable {
61     REFCOUNTED_EVENT_TARGET(MediaSource);
62     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaSource);
63 public:
64     static const AtomicString& openKeyword();
65     static const AtomicString& closedKeyword();
66     static const AtomicString& endedKeyword();
67 
68     static PassRefPtrWillBeRawPtr<MediaSource> create(ExecutionContext*);
69     virtual ~MediaSource();
70 
71     // MediaSource.idl methods
sourceBuffers()72     SourceBufferList* sourceBuffers() { return m_sourceBuffers.get(); }
activeSourceBuffers()73     SourceBufferList* activeSourceBuffers() { return m_activeSourceBuffers.get(); }
74     SourceBuffer* addSourceBuffer(const String& type, ExceptionState&);
75     void removeSourceBuffer(SourceBuffer*, ExceptionState&);
76     void setDuration(double, ExceptionState&);
readyState()77     const AtomicString& readyState() const { return m_readyState; }
78     void endOfStream(const AtomicString& error, ExceptionState&);
79     void endOfStream(ExceptionState&);
80     static bool isTypeSupported(const String& type);
81 
82         // HTMLMediaSource
83     virtual bool attachToElement(HTMLMediaElement*) OVERRIDE;
84     virtual void setWebMediaSourceAndOpen(PassOwnPtr<blink::WebMediaSource>) OVERRIDE;
85     virtual void close() OVERRIDE;
86     virtual bool isClosed() const OVERRIDE;
87     virtual double duration() const OVERRIDE;
88     virtual PassRefPtr<TimeRanges> buffered() const OVERRIDE;
refHTMLMediaSource()89     virtual void refHTMLMediaSource() OVERRIDE { ref(); }
derefHTMLMediaSource()90     virtual void derefHTMLMediaSource() OVERRIDE { deref(); }
91 
92     // EventTarget interface
93     virtual const AtomicString& interfaceName() const OVERRIDE;
94     virtual ExecutionContext* executionContext() const OVERRIDE;
95 
96     // ActiveDOMObject interface
97     virtual bool hasPendingActivity() const OVERRIDE;
98     virtual void stop() OVERRIDE;
99 
100     // URLRegistrable interface
101     virtual URLRegistry& registry() const OVERRIDE;
102 
103     // Used by SourceBuffer.
104     void openIfInEndedState();
105     bool isOpen() const;
106 
107     // Used by MediaSourceRegistry.
108     void addedToRegistry();
109     void removedFromRegistry();
110 
111     void trace(Visitor*);
112 
113 private:
114     explicit MediaSource(ExecutionContext*);
115 
116     void setReadyState(const AtomicString&);
117     void onReadyStateChange(const AtomicString&, const AtomicString&);
118 
119     bool isUpdating() const;
120 
121     PassOwnPtr<blink::WebSourceBuffer> createWebSourceBuffer(const String& type, const Vector<String>& codecs, ExceptionState&);
122     void scheduleEvent(const AtomicString& eventName);
123     void endOfStreamInternal(const blink::WebMediaSource::EndOfStreamStatus, ExceptionState&);
124 
125     // Implements the duration change algorithm.
126     // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#duration-change-algorithm
127     void durationChangeAlgorithm(double newDuration);
128 
129     OwnPtr<blink::WebMediaSource> m_webMediaSource;
130     AtomicString m_readyState;
131     OwnPtrWillBeMember<GenericEventQueue> m_asyncEventQueue;
132     // FIXME: oilpan: This should become a Member. For now, m_attachedElement will be cleared by the HTMLMediaElement destructor.
133     HTMLMediaElement* m_attachedElement;
134 
135     RefPtrWillBeMember<SourceBufferList> m_sourceBuffers;
136     RefPtrWillBeMember<SourceBufferList> m_activeSourceBuffers;
137 };
138 
139 } // namespace WebCore
140 
141 #endif
142