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