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

Side by Side Diff: webkit/media/skcanvas_video_renderer.cc

Issue 10824141: Remove VideoDecoder::natural_size() & added VideoFrame::natural_size(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix copyright year. Created 8 years, 4 months 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) 2012 The Chromium Authors. All rights reserved. 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 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/media/skcanvas_video_renderer.h" 5 #include "webkit/media/skcanvas_video_renderer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/base/video_frame.h" 8 #include "media/base/video_frame.h"
9 #include "media/base/yuv_convert.h" 9 #include "media/base/yuv_convert.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 10 #include "third_party/skia/include/core/SkCanvas.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // Project the clip rect to the original video frame, obtains the 102 // Project the clip rect to the original video frame, obtains the
103 // dimensions of the projected clip rect, "left" and "top" of the rect. 103 // dimensions of the projected clip rect, "left" and "top" of the rect.
104 // The math here are all integer math so we won't have rounding error and 104 // The math here are all integer math so we won't have rounding error and
105 // write outside of the canvas. 105 // write outside of the canvas.
106 // We have the assumptions of dest_rect.width() and dest_rect.height() 106 // We have the assumptions of dest_rect.width() and dest_rect.height()
107 // being non-zero, these are valid assumptions since finding intersection 107 // being non-zero, these are valid assumptions since finding intersection
108 // above rejects empty rectangle so we just do a DCHECK here. 108 // above rejects empty rectangle so we just do a DCHECK here.
109 DCHECK_NE(0, dest_rect.width()); 109 DCHECK_NE(0, dest_rect.width());
110 DCHECK_NE(0, dest_rect.height()); 110 DCHECK_NE(0, dest_rect.height());
111 size_t frame_clip_width = local_dest_irect.width() * 111 size_t frame_clip_width = local_dest_irect.width() *
112 video_frame->width() / local_dest_irect_saved.width(); 112 video_frame->data_size().width() / local_dest_irect_saved.width();
113 size_t frame_clip_height = local_dest_irect.height() * 113 size_t frame_clip_height = local_dest_irect.height() *
114 video_frame->height() / local_dest_irect_saved.height(); 114 video_frame->data_size().height() / local_dest_irect_saved.height();
115 115
116 // Project the "left" and "top" of the final destination rect to local 116 // Project the "left" and "top" of the final destination rect to local
117 // coordinates of the video frame, use these values to find the offsets 117 // coordinates of the video frame, use these values to find the offsets
118 // in the video frame to start reading. 118 // in the video frame to start reading.
119 size_t frame_clip_left = 119 size_t frame_clip_left =
120 (local_dest_irect.fLeft - local_dest_irect_saved.fLeft) * 120 (local_dest_irect.fLeft - local_dest_irect_saved.fLeft) *
121 video_frame->width() / local_dest_irect_saved.width(); 121 video_frame->data_size().width() / local_dest_irect_saved.width();
122 size_t frame_clip_top = 122 size_t frame_clip_top =
123 (local_dest_irect.fTop - local_dest_irect_saved.fTop) * 123 (local_dest_irect.fTop - local_dest_irect_saved.fTop) *
124 video_frame->height() / local_dest_irect_saved.height(); 124 video_frame->data_size().height() / local_dest_irect_saved.height();
125 125
126 // Use the "left" and "top" of the destination rect to locate the offset 126 // Use the "left" and "top" of the destination rect to locate the offset
127 // in Y, U and V planes. 127 // in Y, U and V planes.
128 size_t y_offset = video_frame->stride(media::VideoFrame::kYPlane) * 128 size_t y_offset = video_frame->stride(media::VideoFrame::kYPlane) *
129 frame_clip_top + frame_clip_left; 129 frame_clip_top + frame_clip_left;
130 130
131 // For format YV12, there is one U, V value per 2x2 block. 131 // For format YV12, there is one U, V value per 2x2 block.
132 // For format YV16, there is one u, V value per 2x1 block. 132 // For format YV16, there is one u, V value per 2x1 block.
133 size_t uv_offset = (video_frame->stride(media::VideoFrame::kUPlane) * 133 size_t uv_offset = (video_frame->stride(media::VideoFrame::kUPlane) *
134 (frame_clip_top >> y_shift)) + (frame_clip_left >> 1); 134 (frame_clip_top >> y_shift)) + (frame_clip_left >> 1);
(...skipping 29 matching lines...) Expand all
164 // |bitmap| will be (re)allocated to match the dimensions of |video_frame|. 164 // |bitmap| will be (re)allocated to match the dimensions of |video_frame|.
165 static void ConvertVideoFrameToBitmap( 165 static void ConvertVideoFrameToBitmap(
166 const scoped_refptr<media::VideoFrame>& video_frame, 166 const scoped_refptr<media::VideoFrame>& video_frame,
167 SkBitmap* bitmap) { 167 SkBitmap* bitmap) {
168 DCHECK(IsEitherYV12OrYV16(video_frame->format())) << video_frame->format(); 168 DCHECK(IsEitherYV12OrYV16(video_frame->format())) << video_frame->format();
169 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) == 169 DCHECK(video_frame->stride(media::VideoFrame::kUPlane) ==
170 video_frame->stride(media::VideoFrame::kVPlane)); 170 video_frame->stride(media::VideoFrame::kVPlane));
171 171
172 // Check if |bitmap| needs to be (re)allocated. 172 // Check if |bitmap| needs to be (re)allocated.
173 if (bitmap->isNull() || 173 if (bitmap->isNull() ||
174 bitmap->width() != static_cast<int>(video_frame->width()) || 174 bitmap->width() != video_frame->data_size().width() ||
175 bitmap->height() != static_cast<int>(video_frame->height())) { 175 bitmap->height() != video_frame->data_size().height()) {
176 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 176 bitmap->setConfig(SkBitmap::kARGB_8888_Config,
177 video_frame->width(), 177 video_frame->data_size().width(),
178 video_frame->height()); 178 video_frame->data_size().height());
179 bitmap->allocPixels(); 179 bitmap->allocPixels();
180 bitmap->setIsVolatile(true); 180 bitmap->setIsVolatile(true);
181 } 181 }
182 182
183 bitmap->lockPixels(); 183 bitmap->lockPixels();
184 media::YUVType yuv_type = 184 media::YUVType yuv_type =
185 (video_frame->format() == media::VideoFrame::YV12) ? 185 (video_frame->format() == media::VideoFrame::YV12) ?
186 media::YV12 : media::YV16; 186 media::YV12 : media::YV16;
187 media::ConvertYUVToRGB32(video_frame->data(media::VideoFrame::kYPlane), 187 media::ConvertYUVToRGB32(video_frame->data(media::VideoFrame::kYPlane),
188 video_frame->data(media::VideoFrame::kUPlane), 188 video_frame->data(media::VideoFrame::kUPlane),
189 video_frame->data(media::VideoFrame::kVPlane), 189 video_frame->data(media::VideoFrame::kVPlane),
190 static_cast<uint8*>(bitmap->getPixels()), 190 static_cast<uint8*>(bitmap->getPixels()),
191 video_frame->width(), 191 video_frame->data_size().width(),
192 video_frame->height(), 192 video_frame->data_size().height(),
193 video_frame->stride(media::VideoFrame::kYPlane), 193 video_frame->stride(media::VideoFrame::kYPlane),
194 video_frame->stride(media::VideoFrame::kUPlane), 194 video_frame->stride(media::VideoFrame::kUPlane),
195 bitmap->rowBytes(), 195 bitmap->rowBytes(),
196 yuv_type); 196 yuv_type);
197 bitmap->notifyPixelsChanged(); 197 bitmap->notifyPixelsChanged();
198 bitmap->unlockPixels(); 198 bitmap->unlockPixels();
199 } 199 }
200 200
201 SkCanvasVideoRenderer::SkCanvasVideoRenderer() 201 SkCanvasVideoRenderer::SkCanvasVideoRenderer()
202 : last_frame_timestamp_(media::kNoTimestamp()) { 202 : last_frame_timestamp_(media::kNoTimestamp()) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 ConvertVideoFrameToBitmap(video_frame, &last_frame_); 239 ConvertVideoFrameToBitmap(video_frame, &last_frame_);
240 last_frame_timestamp_ = video_frame->GetTimestamp(); 240 last_frame_timestamp_ = video_frame->GetTimestamp();
241 } 241 }
242 242
243 // Do a slower paint using |last_frame_|. 243 // Do a slower paint using |last_frame_|.
244 paint.setFilterBitmap(true); 244 paint.setFilterBitmap(true);
245 canvas->drawBitmapRect(last_frame_, NULL, dest, &paint); 245 canvas->drawBitmapRect(last_frame_, NULL, dest, &paint);
246 } 246 }
247 247
248 } // namespace webkit_media 248 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/android/webmediaplayer_android.cc ('k') | webkit/media/skcanvas_video_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698