Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: webkit/glue/media/video_renderer_impl.cc

Issue 5878007: Fix black video frames when seeking (which also fixes flashing poster issue). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/glue/media/video_renderer_impl.h" 5 #include "webkit/glue/media/video_renderer_impl.h"
6 6
7 #include "media/base/video_frame.h" 7 #include "media/base/video_frame.h"
8 #include "media/base/yuv_convert.h" 8 #include "media/base/yuv_convert.h"
9 #include "webkit/glue/webmediaplayer_impl.h" 9 #include "webkit/glue/webmediaplayer_impl.h"
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 void VideoRendererImpl::SetWebMediaPlayerImplProxy( 43 void VideoRendererImpl::SetWebMediaPlayerImplProxy(
44 WebMediaPlayerImpl::Proxy* proxy) { 44 WebMediaPlayerImpl::Proxy* proxy) {
45 proxy_ = proxy; 45 proxy_ = proxy;
46 } 46 }
47 47
48 void VideoRendererImpl::SetRect(const gfx::Rect& rect) { 48 void VideoRendererImpl::SetRect(const gfx::Rect& rect) {
49 } 49 }
50 50
51 // This method is always called on the renderer's thread. 51 // This method is always called on the renderer's thread.
52 bool VideoRendererImpl::GetCurrentBitmap(SkBitmap* bitmap) {
53 scoped_refptr<media::VideoFrame> video_frame;
54 GetCurrentFrame(&video_frame);
55
56 if (!video_frame) {
57 return false;
58 } else {
scherkus (not reviewing) 2010/12/17 18:50:40 nit: de-else/indent this block due to early return
59 if (bitmap->empty() ||
60 bitmap->config() != SkBitmap::kARGB_8888_Config ||
61 bitmap->width() != width() || bitmap->height() != height()) {
62 bitmap->reset();
63 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width(), height());
64 bitmap->allocPixels(NULL, NULL);
65 bitmap->eraseRGB(0xff, 0x00, 0x00);
66 }
67
68 SlowPaintToBitmap(video_frame, bitmap);
69 }
70
71 PutCurrentFrame(video_frame);
72
73 return true;
74 }
75
76 // This method is always called on the renderer's thread.
52 void VideoRendererImpl::Paint(skia::PlatformCanvas* canvas, 77 void VideoRendererImpl::Paint(skia::PlatformCanvas* canvas,
53 const gfx::Rect& dest_rect) { 78 const gfx::Rect& dest_rect) {
54 scoped_refptr<media::VideoFrame> video_frame; 79 scoped_refptr<media::VideoFrame> video_frame;
55 GetCurrentFrame(&video_frame); 80 GetCurrentFrame(&video_frame);
81
56 if (!video_frame) { 82 if (!video_frame) {
57 SkPaint paint; 83 SkPaint paint;
58 paint.setColor(SK_ColorBLACK); 84 paint.setColor(SK_ColorBLACK);
59 canvas->drawRectCoords( 85 canvas->drawRectCoords(
60 static_cast<float>(dest_rect.x()), 86 static_cast<float>(dest_rect.x()),
61 static_cast<float>(dest_rect.y()), 87 static_cast<float>(dest_rect.y()),
62 static_cast<float>(dest_rect.right()), 88 static_cast<float>(dest_rect.right()),
63 static_cast<float>(dest_rect.bottom()), 89 static_cast<float>(dest_rect.bottom()),
64 paint); 90 paint);
65 } else { 91 } else {
66 if (CanFastPaint(canvas, dest_rect)) { 92 if (CanFastPaint(canvas, dest_rect)) {
67 FastPaint(video_frame, canvas, dest_rect); 93 FastPaint(video_frame, canvas, dest_rect);
68 } else { 94 } else {
69 SlowPaint(video_frame, canvas, dest_rect); 95 SlowPaintToBitmap(video_frame, &bitmap_);
96 CopyBitmapToCanvas(bitmap_, canvas, dest_rect);
70 } 97 }
71 98
72 // Presentation timestamp logging is primarily used to measure performance 99 // Presentation timestamp logging is primarily used to measure performance
73 // on low-end devices. When profiled on an Intel Atom N280 @ 1.66GHz this 100 // on low-end devices. When profiled on an Intel Atom N280 @ 1.66GHz this
74 // code had a ~63 microsecond perf hit when logging to a file (not stdout), 101 // code had a ~63 microsecond perf hit when logging to a file (not stdout),
75 // which is neglible enough for measuring playback performance. 102 // which is neglible enough for measuring playback performance.
76 if (pts_logging_) 103 if (pts_logging_)
77 VLOG(1) << "pts=" << video_frame->GetTimestamp().InMicroseconds(); 104 VLOG(1) << "pts=" << video_frame->GetTimestamp().InMicroseconds();
78 } 105 }
79 106
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 171
145 if (config == SkBitmap::kARGB_8888_Config && device->isOpaque() && 172 if (config == SkBitmap::kARGB_8888_Config && device->isOpaque() &&
146 device_rect.contains(total_clip.getBounds())) { 173 device_rect.contains(total_clip.getBounds())) {
147 return true; 174 return true;
148 } 175 }
149 } 176 }
150 177
151 return false; 178 return false;
152 } 179 }
153 180
154 void VideoRendererImpl::SlowPaint(media::VideoFrame* video_frame, 181 void VideoRendererImpl::SlowPaintToBitmap(media::VideoFrame* video_frame,
155 skia::PlatformCanvas* canvas, 182 SkBitmap* bitmap) {
156 const gfx::Rect& dest_rect) {
157 // 1. Convert YUV frame to RGB. 183 // 1. Convert YUV frame to RGB.
scherkus (not reviewing) 2010/12/17 18:50:40 nit: remove the 1. (or the comment itself, your ca
158 base::TimeDelta timestamp = video_frame->GetTimestamp(); 184 base::TimeDelta timestamp = video_frame->GetTimestamp();
159 if (video_frame != last_converted_frame_ || 185 if (video_frame != last_converted_frame_ ||
160 timestamp != last_converted_timestamp_) { 186 timestamp != last_converted_timestamp_) {
161 last_converted_frame_ = video_frame; 187 last_converted_frame_ = video_frame;
162 last_converted_timestamp_ = timestamp; 188 last_converted_timestamp_ = timestamp;
163 DCHECK(video_frame->format() == media::VideoFrame::YV12 || 189 DCHECK(video_frame->format() == media::VideoFrame::YV12 ||
164 video_frame->format() == media::VideoFrame::YV16); 190 video_frame->format() == media::VideoFrame::YV16);
165 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == 191 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) ==
166 video_frame->stride(media::VideoFrame::kVPlane)); 192 video_frame->stride(media::VideoFrame::kVPlane));
167 DCHECK(video_frame->planes() == media::VideoFrame::kNumYUVPlanes); 193 DCHECK(video_frame->planes() == media::VideoFrame::kNumYUVPlanes);
168 bitmap_.lockPixels(); 194 bitmap->lockPixels();
169 media::YUVType yuv_type = 195 media::YUVType yuv_type =
170 (video_frame->format() == media::VideoFrame::YV12) ? 196 (video_frame->format() == media::VideoFrame::YV12) ?
171 media::YV12 : media::YV16; 197 media::YV12 : media::YV16;
172 media::ConvertYUVToRGB32(video_frame->data(media::VideoFrame::kYPlane), 198 media::ConvertYUVToRGB32(video_frame->data(media::VideoFrame::kYPlane),
173 video_frame->data(media::VideoFrame::kUPlane), 199 video_frame->data(media::VideoFrame::kUPlane),
174 video_frame->data(media::VideoFrame::kVPlane), 200 video_frame->data(media::VideoFrame::kVPlane),
175 static_cast<uint8*>(bitmap_.getPixels()), 201 static_cast<uint8*>(bitmap->getPixels()),
176 video_frame->width(), 202 video_frame->width(),
177 video_frame->height(), 203 video_frame->height(),
178 video_frame->stride(media::VideoFrame::kYPlane), 204 video_frame->stride(media::VideoFrame::kYPlane),
179 video_frame->stride(media::VideoFrame::kUPlane), 205 video_frame->stride(media::VideoFrame::kUPlane),
180 bitmap_.rowBytes(), 206 bitmap->rowBytes(),
181 yuv_type); 207 yuv_type);
182 bitmap_.unlockPixels(); 208 bitmap->unlockPixels();
183 } 209 }
210 }
184 211
212 void VideoRendererImpl::CopyBitmapToCanvas(const SkBitmap& bitmap,
213 skia::PlatformCanvas* canvas,
214 const gfx::Rect& dest_rect) {
185 // 2. Paint the bitmap to canvas. 215 // 2. Paint the bitmap to canvas.
scherkus (not reviewing) 2010/12/17 18:50:40 ditto
186 SkMatrix matrix; 216 SkMatrix matrix;
187 matrix.setTranslate(static_cast<SkScalar>(dest_rect.x()), 217 matrix.setTranslate(static_cast<SkScalar>(dest_rect.x()),
188 static_cast<SkScalar>(dest_rect.y())); 218 static_cast<SkScalar>(dest_rect.y()));
189 if (dest_rect.width() != video_size_.width() || 219 if (dest_rect.width() != bitmap_.width() ||
190 dest_rect.height() != video_size_.height()) { 220 dest_rect.height() != bitmap_.height()) {
191 matrix.preScale(SkIntToScalar(dest_rect.width()) / 221 matrix.preScale(SkIntToScalar(dest_rect.width()) /
192 SkIntToScalar(video_size_.width()), 222 SkIntToScalar(bitmap_.width()),
193 SkIntToScalar(dest_rect.height()) / 223 SkIntToScalar(dest_rect.height()) /
194 SkIntToScalar(video_size_.height())); 224 SkIntToScalar(bitmap_.height()));
195 } 225 }
196 SkPaint paint; 226 SkPaint paint;
197 paint.setFlags(SkPaint::kFilterBitmap_Flag); 227 paint.setFlags(SkPaint::kFilterBitmap_Flag);
198 canvas->drawBitmapMatrix(bitmap_, matrix, &paint); 228 canvas->drawBitmapMatrix(bitmap, matrix, &paint);
199 } 229 }
200 230
201 void VideoRendererImpl::FastPaint(media::VideoFrame* video_frame, 231 void VideoRendererImpl::FastPaint(media::VideoFrame* video_frame,
scherkus (not reviewing) 2010/12/17 18:50:40 nit: maybe rename this to FastPaintToCanvas ?
202 skia::PlatformCanvas* canvas, 232 skia::PlatformCanvas* canvas,
203 const gfx::Rect& dest_rect) { 233 const gfx::Rect& dest_rect) {
204 DCHECK(video_frame->format() == media::VideoFrame::YV12 || 234 DCHECK(video_frame->format() == media::VideoFrame::YV12 ||
205 video_frame->format() == media::VideoFrame::YV16); 235 video_frame->format() == media::VideoFrame::YV16);
206 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == 236 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) ==
207 video_frame->stride(media::VideoFrame::kVPlane)); 237 video_frame->stride(media::VideoFrame::kVPlane));
208 DCHECK(video_frame->planes() == media::VideoFrame::kNumYUVPlanes); 238 DCHECK(video_frame->planes() == media::VideoFrame::kNumYUVPlanes);
209 const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(true); 239 const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(true);
210 media::YUVType yuv_type = (video_frame->format() == media::VideoFrame::YV12) ? 240 media::YUVType yuv_type = (video_frame->format() == media::VideoFrame::YV12) ?
211 media::YV12 : media::YV16; 241 media::YV12 : media::YV16;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // Transform destination rect to local coordinates. 337 // Transform destination rect to local coordinates.
308 SkRect transformed_rect; 338 SkRect transformed_rect;
309 SkRect skia_dest_rect; 339 SkRect skia_dest_rect;
310 skia_dest_rect.iset(src_rect.x(), src_rect.y(), 340 skia_dest_rect.iset(src_rect.x(), src_rect.y(),
311 src_rect.right(), src_rect.bottom()); 341 src_rect.right(), src_rect.bottom());
312 matrix.mapRect(&transformed_rect, skia_dest_rect); 342 matrix.mapRect(&transformed_rect, skia_dest_rect);
313 transformed_rect.round(dest_rect); 343 transformed_rect.round(dest_rect);
314 } 344 }
315 345
316 } // namespace webkit_glue 346 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698