OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MediaRecorder_h | 5 #ifndef MediaRecorder_h |
6 #define MediaRecorder_h | 6 #define MediaRecorder_h |
7 | 7 |
8 #include "core/dom/ActiveDOMObject.h" | 8 #include "core/dom/ActiveDOMObject.h" |
9 #include "core/events/EventTarget.h" | 9 #include "core/events/EventTarget.h" |
10 #include "modules/EventTargetModules.h" | 10 #include "modules/EventTargetModules.h" |
11 #include "modules/ModulesExport.h" | 11 #include "modules/ModulesExport.h" |
| 12 #include "modules/mediarecorder/MediaRecorderOptions.h" |
12 #include "modules/mediastream/MediaStream.h" | 13 #include "modules/mediastream/MediaStream.h" |
13 #include "platform/AsyncMethodRunner.h" | 14 #include "platform/AsyncMethodRunner.h" |
14 #include "public/platform/WebMediaRecorderHandler.h" | 15 #include "public/platform/WebMediaRecorderHandler.h" |
15 #include "public/platform/WebMediaRecorderHandlerClient.h" | 16 #include "public/platform/WebMediaRecorderHandlerClient.h" |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 | 19 |
19 class Blob; | 20 class Blob; |
20 class BlobData; | 21 class BlobData; |
21 class ExceptionState; | 22 class ExceptionState; |
22 | 23 |
23 class MODULES_EXPORT MediaRecorder final | 24 class MODULES_EXPORT MediaRecorder final |
24 : public RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder> | 25 : public RefCountedGarbageCollectedEventTargetWithInlineData<MediaRecorder> |
25 , public WebMediaRecorderHandlerClient | 26 , public WebMediaRecorderHandlerClient |
26 , public ActiveDOMObject { | 27 , public ActiveDOMObject { |
27 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(MediaRecorder); | 28 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(MediaRecorder); |
28 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaRecorder); | 29 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaRecorder); |
29 DEFINE_WRAPPERTYPEINFO(); | 30 DEFINE_WRAPPERTYPEINFO(); |
30 public: | 31 public: |
31 enum class State { | 32 enum class State { |
32 Inactive = 0, | 33 Inactive = 0, |
33 Recording, | 34 Recording, |
34 Paused | 35 Paused |
35 }; | 36 }; |
36 | 37 |
37 static MediaRecorder* create(ExecutionContext*, MediaStream*, ExceptionState
&); | 38 static MediaRecorder* create(ExecutionContext*, MediaStream*, ExceptionState
&); |
38 static MediaRecorder* create(ExecutionContext*, MediaStream*, const String&
mimeType, ExceptionState&); | 39 static MediaRecorder* create(ExecutionContext*, MediaStream*, const MediaRec
orderOptions&, ExceptionState&); |
39 | 40 |
40 virtual ~MediaRecorder() {} | 41 virtual ~MediaRecorder() {} |
41 | 42 |
42 MediaStream* stream() const { return m_stream.get(); } | 43 MediaStream* stream() const { return m_stream.get(); } |
43 const String& mimeType() const { return m_mimeType; } | 44 const String& mimeType() const { return m_mimeType; } |
44 String state() const; | 45 String state() const; |
45 bool ignoreMutedMedia() const { return m_ignoreMutedMedia; } | 46 bool ignoreMutedMedia() const { return m_ignoreMutedMedia; } |
46 void setIgnoreMutedMedia(bool ignoreMutedMedia) { m_ignoreMutedMedia = ignor
eMutedMedia; } | 47 void setIgnoreMutedMedia(bool ignoreMutedMedia) { m_ignoreMutedMedia = ignor
eMutedMedia; } |
47 | 48 |
48 DEFINE_ATTRIBUTE_EVENT_LISTENER(start); | 49 DEFINE_ATTRIBUTE_EVENT_LISTENER(start); |
49 DEFINE_ATTRIBUTE_EVENT_LISTENER(stop); | 50 DEFINE_ATTRIBUTE_EVENT_LISTENER(stop); |
50 DEFINE_ATTRIBUTE_EVENT_LISTENER(dataavailable); | 51 DEFINE_ATTRIBUTE_EVENT_LISTENER(dataavailable); |
51 DEFINE_ATTRIBUTE_EVENT_LISTENER(pause); | 52 DEFINE_ATTRIBUTE_EVENT_LISTENER(pause); |
52 DEFINE_ATTRIBUTE_EVENT_LISTENER(resume); | 53 DEFINE_ATTRIBUTE_EVENT_LISTENER(resume); |
53 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 54 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
54 | 55 |
55 void start(ExceptionState&); | 56 void start(ExceptionState&); |
56 void start(int timeSlice, ExceptionState&); | 57 void start(int timeSlice, ExceptionState&); |
57 void stop(ExceptionState&); | 58 void stop(ExceptionState&); |
58 void pause(ExceptionState&); | 59 void pause(ExceptionState&); |
59 void resume(ExceptionState&); | 60 void resume(ExceptionState&); |
60 void requestData(ExceptionState&); | 61 void requestData(ExceptionState&); |
61 | 62 |
62 static String canRecordMimeType(const String& mimeType); | 63 static bool isTypeSupported(const String& type); |
63 | 64 |
64 // EventTarget | 65 // EventTarget |
65 virtual const AtomicString& interfaceName() const override; | 66 virtual const AtomicString& interfaceName() const override; |
66 virtual ExecutionContext* executionContext() const override; | 67 virtual ExecutionContext* executionContext() const override; |
67 | 68 |
68 // ActiveDOMObject | 69 // ActiveDOMObject |
69 virtual void suspend() override; | 70 virtual void suspend() override; |
70 virtual void resume() override; | 71 virtual void resume() override; |
71 virtual void stop() override; | 72 virtual void stop() override; |
72 virtual bool hasPendingActivity() const override { return !m_stopped; } | 73 virtual bool hasPendingActivity() const override { return !m_stopped; } |
73 | 74 |
74 // WebMediaRecorderHandlerClient | 75 // WebMediaRecorderHandlerClient |
75 virtual void writeData(const char* data, size_t length, bool lastInSlice) ov
erride; | 76 virtual void writeData(const char* data, size_t length, bool lastInSlice) ov
erride; |
76 virtual void failOutOfMemory(const WebString& message) override; | 77 virtual void failOutOfMemory(const WebString& message) override; |
77 virtual void failIllegalStreamModification(const WebString& message) overrid
e; | 78 virtual void failIllegalStreamModification(const WebString& message) overrid
e; |
78 virtual void failOtherRecordingError(const WebString& message) override; | 79 virtual void failOtherRecordingError(const WebString& message) override; |
79 | 80 |
80 DECLARE_VIRTUAL_TRACE(); | 81 DECLARE_VIRTUAL_TRACE(); |
81 | 82 |
82 private: | 83 private: |
83 MediaRecorder(ExecutionContext*, MediaStream*, const String& mimeType, Excep
tionState&); | 84 MediaRecorder(ExecutionContext*, MediaStream*, const MediaRecorderOptions&,
ExceptionState&); |
84 | 85 |
85 void createBlobEvent(Blob*); | 86 void createBlobEvent(Blob*); |
86 | 87 |
87 void stopRecording(); | 88 void stopRecording(); |
88 void scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event>); | 89 void scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event>); |
89 void dispatchScheduledEvent(); | 90 void dispatchScheduledEvent(); |
90 | 91 |
91 Member<MediaStream> m_stream; | 92 Member<MediaStream> m_stream; |
92 String m_mimeType; | 93 String m_mimeType; |
93 bool m_stopped; | 94 bool m_stopped; |
94 bool m_ignoreMutedMedia; | 95 bool m_ignoreMutedMedia; |
95 | 96 |
96 State m_state; | 97 State m_state; |
97 | 98 |
98 OwnPtr<BlobData> m_blobData; | 99 OwnPtr<BlobData> m_blobData; |
99 | 100 |
100 OwnPtr<WebMediaRecorderHandler> m_recorderHandler; | 101 OwnPtr<WebMediaRecorderHandler> m_recorderHandler; |
101 | 102 |
102 AsyncMethodRunner<MediaRecorder> m_dispatchScheduledEventRunner; | 103 AsyncMethodRunner<MediaRecorder> m_dispatchScheduledEventRunner; |
103 WillBeHeapVector<RefPtrWillBeMember<Event>> m_scheduledEvents; | 104 WillBeHeapVector<RefPtrWillBeMember<Event>> m_scheduledEvents; |
104 }; | 105 }; |
105 | 106 |
106 } // namespace blink | 107 } // namespace blink |
107 | 108 |
108 #endif // MediaRecorder_h | 109 #endif // MediaRecorder_h |
OLD | NEW |