2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
32 #include "MediaPlayerProxy.h"
36 #include "StringHash.h"
37 #include <wtf/HashSet.h>
38 #include <wtf/OwnPtr.h>
39 #include <wtf/Noncopyable.h>
45 class GraphicsContext
;
49 class MediaPlayerPrivateInterface
;
52 class MediaPlayerClient
{
54 virtual ~MediaPlayerClient() { }
56 // the network state has changed
57 virtual void mediaPlayerNetworkStateChanged(MediaPlayer
*) { }
59 // the ready state has changed
60 virtual void mediaPlayerReadyStateChanged(MediaPlayer
*) { }
62 // the volume or muted state has changed
63 virtual void mediaPlayerVolumeChanged(MediaPlayer
*) { }
65 // time has jumped, eg. not as a result of normal playback
66 virtual void mediaPlayerTimeChanged(MediaPlayer
*) { }
68 // a new frame of video is available
69 virtual void mediaPlayerRepaint(MediaPlayer
*) { }
71 // the media file duration has changed, or is now known
72 virtual void mediaPlayerDurationChanged(MediaPlayer
*) { }
74 // the playback rate has changed
75 virtual void mediaPlayerRateChanged(MediaPlayer
*) { }
77 // the movie size has changed
78 virtual void mediaPlayerSizeChanged(MediaPlayer
*) { }
81 class MediaPlayer
: Noncopyable
{
83 MediaPlayer(MediaPlayerClient
*);
84 virtual ~MediaPlayer();
86 // media engine support
87 enum SupportsType
{ IsNotSupported
, IsSupported
, MayBeSupported
};
88 static MediaPlayer::SupportsType
supportsType(ContentType contentType
);
89 static void getSupportedTypes(HashSet
<String
>&);
90 static bool isAvailable();
92 IntSize
naturalSize();
95 void setFrameView(FrameView
* frameView
) { m_frameView
= frameView
; }
96 FrameView
* frameView() { return m_frameView
; }
97 bool inMediaDocument();
99 IntSize
size() const { return m_size
; }
100 void setSize(const IntSize
& size
);
102 void load(const String
& url
, const ContentType
& contentType
);
105 bool visible() const;
106 void setVisible(bool);
112 bool seeking() const;
114 float duration() const;
115 float currentTime() const;
116 void seek(float time
);
118 void setEndTime(float time
);
123 float maxTimeBuffered();
124 float maxTimeSeekable();
126 unsigned bytesLoaded();
127 bool totalBytesKnown();
128 unsigned totalBytes();
130 float volume() const;
131 void setVolume(float);
133 int dataRate() const;
135 bool autobuffer() const;
136 void setAutobuffer(bool);
138 void paint(GraphicsContext
*, const IntRect
&);
140 enum NetworkState
{ Empty
, Idle
, Loading
, Loaded
, FormatError
, NetworkError
, DecodeError
};
141 NetworkState
networkState();
143 enum ReadyState
{ HaveNothing
, HaveMetadata
, HaveCurrentData
, HaveFutureData
, HaveEnoughData
};
144 ReadyState
readyState();
146 void networkStateChanged();
147 void readyStateChanged();
148 void volumeChanged();
152 void durationChanged();
156 MediaPlayerClient
* mediaPlayerClient() const { return m_mediaPlayerClient
; }
158 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
159 void setPoster(const String
& url
);
160 void deliverNotification(MediaPlayerProxyNotificationType notification
);
161 void setMediaPlayerProxy(WebMediaPlayerProxy
* proxy
);
165 static void initializeMediaEngines();
167 MediaPlayerClient
* m_mediaPlayerClient
;
168 OwnPtr
<MediaPlayerPrivateInterface
*> m_private
;
169 void* m_currentMediaEngine
;
170 FrameView
* m_frameView
;
176 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
177 WebMediaPlayerProxy
* m_playerProxy
; // not owned or used, passed to m_private
181 typedef MediaPlayerPrivateInterface
* (*CreateMediaEnginePlayer
)(MediaPlayer
*);
182 typedef void (*MediaEngineSupportedTypes
)(HashSet
<String
>& types
);
183 typedef MediaPlayer::SupportsType (*MediaEngineSupportsType
)(const String
& type
, const String
& codecs
);
185 typedef void (*MediaEngineRegistrar
)(CreateMediaEnginePlayer
, MediaEngineSupportedTypes
, MediaEngineSupportsType
);
190 #endif // ENABLE(VIDEO)