OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2009 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 WebMediaPlayerClientImpl_h | |
32 #define WebMediaPlayerClientImpl_h | |
33 | |
34 #include "platform/audio/AudioSourceProvider.h" | |
35 #include "platform/graphics/media/MediaPlayer.h" | |
36 #include "public/platform/WebAudioSourceProviderClient.h" | |
37 #include "public/platform/WebEncryptedMediaTypes.h" | |
38 #include "public/platform/WebMediaPlayerClient.h" | |
39 #include "platform/weborigin/KURL.h" | |
40 #include "wtf/OwnPtr.h" | |
41 #include "wtf/PassOwnPtr.h" | |
42 #include "wtf/ThreadingPrimitives.h" | |
43 | |
44 namespace blink { | |
45 | |
46 class AudioSourceProviderClient; | |
47 class HTMLMediaElement; | |
48 class WebAudioSourceProvider; | |
49 class WebMediaPlayer; | |
50 | |
51 // This class serves as a bridge between MediaPlayer and | |
52 // WebMediaPlayer. | |
53 class WebMediaPlayerClientImpl final : public MediaPlayer, public WebMediaPlayer
Client { | |
54 | |
55 public: | |
56 static PassOwnPtr<MediaPlayer> create(MediaPlayerClient*); | |
57 | |
58 ~WebMediaPlayerClientImpl() override; | |
59 | |
60 // WebMediaPlayerClient methods: | |
61 void networkStateChanged() override; | |
62 void readyStateChanged() override; | |
63 void timeChanged() override; | |
64 void repaint() override; | |
65 void durationChanged() override; | |
66 void sizeChanged() override; | |
67 void playbackStateChanged() override; | |
68 | |
69 // WebEncryptedMediaPlayerClient methods: | |
70 void keyAdded(const WebString& keySystem, const WebString& sessionId) overri
de; | |
71 void keyError(const WebString& keySystem, const WebString& sessionId, MediaK
eyErrorCode, unsigned short systemCode) override; | |
72 void keyMessage(const WebString& keySystem, const WebString& sessionId, cons
t unsigned char* message, unsigned messageLength, const WebURL& defaultURL) over
ride; | |
73 void encrypted(WebEncryptedMediaInitDataType, const unsigned char* initData,
unsigned initDataLength) override; | |
74 void didBlockPlaybackWaitingForKey() override; | |
75 void didResumePlaybackBlockedForKey() override; | |
76 | |
77 void setWebLayer(WebLayer*) override; | |
78 WebMediaPlayer::TrackId addAudioTrack(const WebString& id, AudioTrackKind, c
onst WebString& label, const WebString& language, bool enabled) override; | |
79 void removeAudioTrack(WebMediaPlayer::TrackId) override; | |
80 WebMediaPlayer::TrackId addVideoTrack(const WebString& id, VideoTrackKind, c
onst WebString& label, const WebString& language, bool selected) override; | |
81 void removeVideoTrack(WebMediaPlayer::TrackId) override; | |
82 void addTextTrack(WebInbandTextTrack*) override; | |
83 void removeTextTrack(WebInbandTextTrack*) override; | |
84 void mediaSourceOpened(WebMediaSource*) override; | |
85 void requestSeek(double) override; | |
86 void remoteRouteAvailabilityChanged(bool) override; | |
87 void connectedToRemoteDevice() override; | |
88 void disconnectedFromRemoteDevice() override; | |
89 | |
90 // MediaPlayer methods: | |
91 WebMediaPlayer* webMediaPlayer() const override; | |
92 void load(WebMediaPlayer::LoadType, const WTF::String& url, WebMediaPlayer::
CORSMode) override; | |
93 void setPreload(MediaPlayer::Preload) override; | |
94 | |
95 #if ENABLE(WEB_AUDIO) | |
96 AudioSourceProvider* audioSourceProvider() override; | |
97 #endif | |
98 | |
99 private: | |
100 explicit WebMediaPlayerClientImpl(MediaPlayerClient*); | |
101 | |
102 HTMLMediaElement& mediaElement() const; | |
103 | |
104 MediaPlayerClient* m_client; | |
105 OwnPtr<WebMediaPlayer> m_webMediaPlayer; | |
106 | |
107 #if ENABLE(WEB_AUDIO) | |
108 // AudioClientImpl wraps an AudioSourceProviderClient. | |
109 // When the audio format is known, Chromium calls setFormat() which then dis
patches into WebCore. | |
110 | |
111 class AudioClientImpl final : public GarbageCollectedFinalized<AudioClientIm
pl>, public WebAudioSourceProviderClient { | |
112 public: | |
113 explicit AudioClientImpl(AudioSourceProviderClient* client) | |
114 : m_client(client) | |
115 { | |
116 } | |
117 | |
118 ~AudioClientImpl() override { } | |
119 | |
120 // WebAudioSourceProviderClient | |
121 void setFormat(size_t numberOfChannels, float sampleRate) override; | |
122 | |
123 DECLARE_TRACE(); | |
124 | |
125 private: | |
126 Member<AudioSourceProviderClient> m_client; | |
127 }; | |
128 | |
129 // AudioSourceProviderImpl wraps a WebAudioSourceProvider. | |
130 // provideInput() calls into Chromium to get a rendered audio stream. | |
131 | |
132 class AudioSourceProviderImpl final : public AudioSourceProvider { | |
133 public: | |
134 AudioSourceProviderImpl() | |
135 : m_webAudioSourceProvider(0) | |
136 { | |
137 } | |
138 | |
139 ~AudioSourceProviderImpl() override { } | |
140 | |
141 // Wraps the given WebAudioSourceProvider. | |
142 void wrap(WebAudioSourceProvider*); | |
143 | |
144 // AudioSourceProvider | |
145 void setClient(AudioSourceProviderClient*) override; | |
146 void provideInput(AudioBus*, size_t framesToProcess) override; | |
147 | |
148 private: | |
149 WebAudioSourceProvider* m_webAudioSourceProvider; | |
150 Persistent<AudioClientImpl> m_client; | |
151 Mutex provideInputLock; | |
152 }; | |
153 | |
154 AudioSourceProviderImpl m_audioSourceProvider; | |
155 #endif | |
156 }; | |
157 | |
158 } // namespace blink | |
159 | |
160 #endif | |
OLD | NEW |