|
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Delegate calls from WebCore::MediaPlayerPrivate to Chrome's media player | |
scherkus (not reviewing)
2012/09/07 11:44:03
move to class definition instead of top of file
wjia(left Chromium)
2012/09/13 01:22:07
Done.
| |
6 // when "src" is from media stream. | |
7 // | |
8 // WebMediaPlayerMS works with multiple objects, the most important ones are: | |
9 // | |
10 // VideoFrameProvider | |
11 // provides video frames for rendering. | |
12 // | |
13 // TODO(wjia): add AudioPlayer. | |
14 // AudioPlayer | |
15 // plays audio streams. | |
16 // | |
17 // WebKit::WebMediaPlayerClient | |
18 // WebKit client of this media player object. | |
19 // | |
20 | |
21 #ifndef WEBKIT_MEDIA_WEBMEDIAPLAYER_MS_H_ | |
22 #define WEBKIT_MEDIA_WEBMEDIAPLAYER_MS_H_ | |
23 | |
24 #include "base/memory/ref_counted.h" | |
25 #include "base/memory/scoped_ptr.h" | |
26 #include "base/memory/weak_ptr.h" | |
27 #include "base/message_loop.h" | |
28 #include "googleurl/src/gurl.h" | |
29 #include "skia/ext/platform_canvas.h" | |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h" | |
31 #include "webkit/media/skcanvas_video_renderer.h" | |
32 | |
33 namespace WebKit { | |
34 class WebFrame; | |
35 class WebMediaPlayerClient; | |
36 } | |
37 | |
38 namespace media { | |
39 class MediaLog; | |
40 } | |
41 | |
42 namespace webkit_media { | |
43 | |
44 class MediaStreamClient; | |
45 class VideoFrameProvider; | |
46 class WebMediaPlayerDelegate; | |
47 | |
48 class WebMediaPlayerMS | |
49 : public WebKit::WebMediaPlayer, | |
50 public MessageLoop::DestructionObserver, | |
51 public base::SupportsWeakPtr<WebMediaPlayerMS> { | |
52 public: | |
53 // Construct a WebMediaPlayerMS with reference to the client, and | |
54 // a MediaStreamClient which provides VideoFrameProvider. | |
55 WebMediaPlayerMS(WebKit::WebFrame* frame, | |
56 WebKit::WebMediaPlayerClient* client, | |
57 base::WeakPtr<WebMediaPlayerDelegate> delegate, | |
58 MediaStreamClient* media_stream_client, | |
59 media::MediaLog* media_log); | |
60 virtual ~WebMediaPlayerMS(); | |
61 | |
62 virtual void load(const WebKit::WebURL& url, CORSMode cors_mode) OVERRIDE; | |
63 virtual void cancelLoad() OVERRIDE; | |
64 | |
65 // Playback controls. | |
66 virtual void play() OVERRIDE; | |
67 virtual void pause() OVERRIDE; | |
68 virtual bool supportsFullscreen() const OVERRIDE; | |
69 virtual bool supportsSave() const OVERRIDE; | |
70 virtual void seek(float seconds) OVERRIDE; | |
71 virtual void setEndTime(float seconds) OVERRIDE; | |
72 virtual void setRate(float rate) OVERRIDE; | |
73 virtual void setVolume(float volume) OVERRIDE; | |
74 virtual void setVisible(bool visible) OVERRIDE; | |
75 virtual void setPreload(WebKit::WebMediaPlayer::Preload preload) OVERRIDE; | |
76 virtual bool totalBytesKnown() OVERRIDE; | |
77 virtual const WebKit::WebTimeRanges& buffered() OVERRIDE; | |
78 virtual float maxTimeSeekable() const OVERRIDE; | |
79 | |
80 // Methods for painting. | |
81 virtual void setSize(const WebKit::WebSize& size) OVERRIDE; | |
82 | |
83 virtual void paint(WebKit::WebCanvas* canvas, | |
84 const WebKit::WebRect& rect, | |
85 uint8_t alpha) OVERRIDE; | |
86 | |
87 // True if the loaded media has a playable video/audio track. | |
88 virtual bool hasVideo() const OVERRIDE; | |
89 virtual bool hasAudio() const OVERRIDE; | |
90 | |
91 // Dimensions of the video. | |
92 virtual WebKit::WebSize naturalSize() const OVERRIDE; | |
93 | |
94 // Getters of playback state. | |
95 virtual bool paused() const OVERRIDE; | |
96 virtual bool seeking() const OVERRIDE; | |
97 virtual float duration() const OVERRIDE; | |
98 virtual float currentTime() const OVERRIDE; | |
99 | |
100 // Get rate of loading the resource. | |
101 virtual int32 dataRate() const OVERRIDE; | |
102 | |
103 // Internal states of loading and network. | |
104 virtual WebKit::WebMediaPlayer::NetworkState networkState() const OVERRIDE; | |
105 virtual WebKit::WebMediaPlayer::ReadyState readyState() const OVERRIDE; | |
106 | |
107 virtual bool didLoadingProgress() const OVERRIDE; | |
108 virtual unsigned long long totalBytes() const OVERRIDE; | |
109 | |
110 virtual bool hasSingleSecurityOrigin() const OVERRIDE; | |
111 virtual bool didPassCORSAccessCheck() const OVERRIDE; | |
112 virtual WebKit::WebMediaPlayer::MovieLoadType movieLoadType() const OVERRIDE; | |
113 | |
114 virtual float mediaTimeForTimeValue(float timeValue) const OVERRIDE; | |
115 | |
116 virtual unsigned decodedFrameCount() const OVERRIDE; | |
117 virtual unsigned droppedFrameCount() const OVERRIDE; | |
118 virtual unsigned audioDecodedByteCount() const OVERRIDE; | |
119 virtual unsigned videoDecodedByteCount() const OVERRIDE; | |
120 | |
121 virtual WebKit::WebVideoFrame* getCurrentFrame() OVERRIDE; | |
122 virtual void putCurrentFrame(WebKit::WebVideoFrame* web_video_frame) OVERRIDE; | |
123 | |
124 // As we are closing the tab or even the browser, |main_loop_| is destroyed | |
125 // even before this object gets destructed, so we need to know when | |
126 // |main_loop_| is being destroyed and we can stop posting repaint task | |
127 // to it. | |
128 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | |
129 | |
130 private: | |
131 // The callback for VideoFrameProvider to signal a new frame is available. | |
132 void Repaint(const scoped_refptr<media::VideoFrame>& frame); | |
scherkus (not reviewing)
2012/09/07 11:44:03
how about OnFrameAvailable()?
Repaint() is a bit
wjia(left Chromium)
2012/09/13 01:22:07
Done.
| |
133 // Need repaint due to state change. | |
134 void RepaintInternal(); | |
135 | |
136 // The callback for source to report error. | |
137 void OnSourceError(); | |
scherkus (not reviewing)
2012/09/07 11:44:03
this is a callback from VFP but the word "source"
wjia(left Chromium)
2012/09/13 01:22:07
The "source" means the real module which creates t
| |
138 | |
139 // Helpers that set the network/ready state and notifies the client if | |
140 // they've changed. | |
141 void SetNetworkState(WebKit::WebMediaPlayer::NetworkState state); | |
142 void SetReadyState(WebKit::WebMediaPlayer::ReadyState state); | |
143 | |
144 // Destroy resources held. | |
145 void Destroy(); | |
146 | |
147 // Getter method to |client_|. | |
148 WebKit::WebMediaPlayerClient* GetClient(); | |
149 | |
150 // Lets V8 know that player uses extra resources not managed by V8. | |
151 void IncrementExternallyAllocatedMemory(); | |
152 | |
153 WebKit::WebFrame* frame_; | |
154 | |
155 WebKit::WebMediaPlayer::NetworkState network_state_; | |
156 WebKit::WebMediaPlayer::ReadyState ready_state_; | |
157 | |
158 WebKit::WebTimeRanges buffered_; | |
159 | |
160 // Message loop for DCHECKs so methods calls executed in the correct thread. | |
161 MessageLoop* main_loop_; | |
162 | |
163 WebKit::WebMediaPlayerClient* client_; | |
164 | |
165 base::WeakPtr<WebMediaPlayerDelegate> delegate_; | |
166 | |
167 MediaStreamClient* media_stream_client_; | |
168 scoped_refptr<VideoFrameProvider> video_frame_provider_; | |
169 bool video_frame_provider_started_; | |
170 bool paused_; | |
171 scoped_refptr<media::VideoFrame> current_frame_; | |
172 bool pending_repaint_; | |
173 bool got_first_frame_; | |
174 base::TimeDelta start_time_; | |
175 unsigned total_frame_count_; | |
176 unsigned dropped_frame_count_; | |
177 SkCanvasVideoRenderer video_renderer_; | |
178 | |
179 scoped_refptr<media::MediaLog> media_log_; | |
180 | |
181 // Since accelerated compositing status is only known after the first layout, | |
182 // we delay reporting it to UMA until that time. | |
183 bool accelerated_compositing_reported_; | |
scherkus (not reviewing)
2012/09/07 11:44:03
It looks like you copied code from WebMediaPlayerI
wjia(left Chromium)
2012/09/13 01:22:07
yes, this one is copied from WMPImpl. Removing thi
| |
184 | |
185 bool incremented_externally_allocated_memory_; | |
186 | |
187 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMS); | |
188 }; | |
189 | |
190 } // namespace webkit_media | |
191 | |
192 #endif // WEBKIT_MEDIA_WEBMEDIAPLAYER_MS_H_ | |
OLD | NEW |