1/*
2 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19#ifndef MediaPlayerPrivateBlackBerry_h
20#define MediaPlayerPrivateBlackBerry_h
21
22#if ENABLE(VIDEO)
23#include "AuthenticationChallengeManager.h"
24#include "MediaPlayerPrivate.h"
25
26#include <BlackBerryPlatformPlayer.h>
27
28namespace BlackBerry {
29
30namespace Platform {
31class IntRect;
32
33namespace Graphics {
34class GLES2Program;
35}
36}
37
38namespace WebKit {
39class WebPageClient;
40}
41}
42
43namespace WebCore {
44
45class MediaPlayerPrivate : public MediaPlayerPrivateInterface, public AuthenticationChallengeClient, public BlackBerry::Platform::IPlatformPlayerListener {
46public:
47    virtual ~MediaPlayerPrivate();
48
49    static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*);
50    static void registerMediaEngine(MediaEngineRegistrar);
51    static void getSupportedTypes(HashSet<WTF::String>&);
52    static MediaPlayer::SupportsType supportsType(const WTF::String&, const WTF::String&, const KURL&);
53    static void notifyAppActivatedEvent(bool);
54    static void setCertificatePath(const WTF::String&);
55
56    virtual void load(const WTF::String& url);
57    virtual void cancelLoad();
58
59    virtual void prepareToPlay();
60#if USE(ACCELERATED_COMPOSITING)
61    virtual PlatformMedia platformMedia() const;
62    virtual PlatformLayer* platformLayer() const;
63    void drawBufferingAnimation(const TransformationMatrix&, const BlackBerry::Platform::Graphics::GLES2Program&);
64#endif
65
66    virtual void play();
67    virtual void pause();
68
69    virtual bool supportsFullscreen() const;
70
71    virtual IntSize naturalSize() const;
72
73    virtual bool hasVideo() const;
74    virtual bool hasAudio() const;
75
76    virtual void setVisible(bool);
77
78    virtual float duration() const;
79
80    virtual float currentTime() const;
81    virtual void seek(float time);
82    virtual bool seeking() const;
83
84    virtual void setRate(float);
85
86    virtual bool paused() const;
87    virtual bool muted() const;
88    virtual bool supportsMuting() const { return true; }
89
90    virtual void setVolume(float);
91    virtual void setMuted(bool);
92
93    virtual MediaPlayer::NetworkState networkState() const;
94    virtual MediaPlayer::ReadyState readyState() const;
95
96    virtual float maxTimeSeekable() const;
97    virtual PassRefPtr<TimeRanges> buffered() const;
98
99    virtual bool didLoadingProgress() const;
100
101    virtual void setSize(const IntSize&);
102
103    virtual void paint(GraphicsContext*, const IntRect&);
104
105    virtual void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
106
107    virtual bool hasAvailableVideoFrame() const;
108
109#if USE(ACCELERATED_COMPOSITING)
110    // Whether accelerated rendering is supported by the media engine for the current media.
111    virtual bool supportsAcceleratedRendering() const;
112    // Called when the rendering system flips the into or out of accelerated rendering mode.
113    virtual void acceleratedRenderingStateChanged() { }
114#endif
115
116    virtual bool hasSingleSecurityOrigin() const;
117
118    virtual MediaPlayer::MovieLoadType movieLoadType() const;
119
120    virtual void prepareForRendering();
121
122    void resizeSourceDimensions();
123    void setFullscreenWebPageClient(BlackBerry::WebKit::WebPageClient*);
124    BlackBerry::Platform::Graphics::Window* getWindow();
125    BlackBerry::Platform::Graphics::Window* getPeerWindow(const char*) const;
126    BlackBerry::Platform::IntRect getWindowScreenRect() const;
127    const char* mmrContextName();
128    float percentLoaded();
129    unsigned sourceWidth();
130    unsigned sourceHeight();
131    void setAllowPPSVolumeUpdates(bool);
132
133    // IPlatformPlayerListener implementation.
134    virtual void onStateChanged(BlackBerry::Platform::PlatformPlayer::MpState);
135    virtual void onMediaStatusChanged(BlackBerry::Platform::PlatformPlayer::MMRPlayState);
136    virtual void onError(BlackBerry::Platform::PlatformPlayer::Error);
137    virtual void onDurationChanged(float);
138    virtual void onTimeChanged(float);
139    virtual void onRateChanged(float);
140    virtual void onVolumeChanged(float);
141    virtual void onPauseStateChanged();
142    virtual void onRepaint();
143    virtual void onSizeChanged();
144    virtual void onPlayNotified();
145    virtual void onPauseNotified();
146    virtual void onWaitMetadataNotified(bool hasFinished, int timeWaited);
147#if USE(ACCELERATED_COMPOSITING)
148    virtual void onBuffering(bool);
149#endif
150    virtual void onAuthenticationNeeded(BlackBerry::Platform::MMRAuthChallenge&);
151    virtual void onAuthenticationAccepted(const BlackBerry::Platform::MMRAuthChallenge&) const;
152    virtual void onConditionallyEnterFullscreen();
153    virtual void onExitFullscreen();
154    virtual void onCreateHolePunchRect();
155    virtual void onDestroyHolePunchRect();
156
157    virtual void notifyChallengeResult(const KURL&, const ProtectionSpace&, AuthenticationChallengeResult, const Credential&);
158
159    virtual bool isProcessingUserGesture() const;
160    virtual bool isFullscreen() const;
161    virtual bool isElementPaused() const;
162    virtual bool isTabVisible() const;
163    virtual int onShowErrorDialog(BlackBerry::Platform::PlatformPlayer::Error);
164    virtual BlackBerry::Platform::Graphics::Window* platformWindow();
165    virtual BlackBerry::Platform::WebMediaStreamDescriptor lookupMediaStream(const BlackBerry::Platform::String& url);
166
167private:
168    MediaPlayerPrivate(MediaPlayer*);
169
170    void updateStates();
171    WTF::String userAgent(const WTF::String&) const;
172
173    virtual WTF::String engineDescription() const { return "BlackBerry"; }
174
175    MediaPlayer* m_webCorePlayer;
176    BlackBerry::Platform::PlatformPlayer* m_platformPlayer;
177
178    mutable MediaPlayer::NetworkState m_networkState;
179    MediaPlayer::ReadyState m_readyState;
180
181    BlackBerry::WebKit::WebPageClient* m_fullscreenWebPageClient;
182#if USE(ACCELERATED_COMPOSITING)
183    void bufferingTimerFired(Timer<MediaPlayerPrivate>*);
184    void setBuffering(bool);
185
186    Timer<MediaPlayerPrivate> m_bufferingTimer;
187    RefPtr<PlatformLayer> m_platformLayer;
188    bool m_showBufferingImage;
189#endif
190
191    void userDrivenSeekTimerFired(Timer<MediaPlayerPrivate>*);
192    Timer<MediaPlayerPrivate> m_userDrivenSeekTimer;
193    float m_lastSeekTime;
194    mutable float m_lastLoadingTime;
195    bool m_lastSeekTimePending;
196    bool m_isAuthenticationChallenging;
197    void waitMetadataTimerFired(Timer<MediaPlayerPrivate>*);
198    Timer<MediaPlayerPrivate> m_waitMetadataTimer;
199    int m_waitMetadataPopDialogCounter;
200};
201
202} // namespace WebCore
203
204#endif // ENABLE(VIDEO)
205#endif // MediaPlayerPrivateBlackBerry_h
206