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

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

Issue 591313008: Add support for Rec709 color space videos in software YUV convert path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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 "media/filters/skcanvas_video_renderer.h" 5 #include "media/filters/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/libyuv/include/libyuv.h" 10 #include "third_party/libyuv/include/libyuv.h"
(...skipping 17 matching lines...) Expand all
28 28
29 namespace media { 29 namespace media {
30 30
31 static bool IsYUV(media::VideoFrame::Format format) { 31 static bool IsYUV(media::VideoFrame::Format format) {
32 switch (format) { 32 switch (format) {
33 case VideoFrame::YV12: 33 case VideoFrame::YV12:
34 case VideoFrame::YV16: 34 case VideoFrame::YV16:
35 case VideoFrame::I420: 35 case VideoFrame::I420:
36 case VideoFrame::YV12A: 36 case VideoFrame::YV12A:
37 case VideoFrame::YV12J: 37 case VideoFrame::YV12J:
38 case VideoFrame::YV12HD:
38 case VideoFrame::YV24: 39 case VideoFrame::YV24:
39 case VideoFrame::NV12: 40 case VideoFrame::NV12:
40 return true; 41 return true;
41 case VideoFrame::UNKNOWN: 42 case VideoFrame::UNKNOWN:
42 case VideoFrame::NATIVE_TEXTURE: 43 case VideoFrame::NATIVE_TEXTURE:
43 #if defined(VIDEO_HOLE) 44 #if defined(VIDEO_HOLE)
44 case VideoFrame::HOLE: 45 case VideoFrame::HOLE:
45 #endif // defined(VIDEO_HOLE) 46 #endif // defined(VIDEO_HOLE)
46 return false; 47 return false;
47 } 48 }
48 NOTREACHED() << "Invalid videoframe format provided: " << format; 49 NOTREACHED() << "Invalid videoframe format provided: " << format;
49 return false; 50 return false;
50 } 51 }
51 52
52 static bool IsJPEGColorSpace(media::VideoFrame::Format format) { 53 static bool IsJPEGColorSpace(media::VideoFrame::Format format) {
53 switch (format) { 54 switch (format) {
54 case VideoFrame::YV12J: 55 case VideoFrame::YV12J:
55 return true; 56 return true;
56 case VideoFrame::YV12: 57 case VideoFrame::YV12:
58 case VideoFrame::YV12HD:
57 case VideoFrame::YV16: 59 case VideoFrame::YV16:
58 case VideoFrame::I420: 60 case VideoFrame::I420:
59 case VideoFrame::YV12A: 61 case VideoFrame::YV12A:
60 case VideoFrame::YV24: 62 case VideoFrame::YV24:
61 case VideoFrame::NV12: 63 case VideoFrame::NV12:
62 case VideoFrame::UNKNOWN: 64 case VideoFrame::UNKNOWN:
63 case VideoFrame::NATIVE_TEXTURE: 65 case VideoFrame::NATIVE_TEXTURE:
64 #if defined(VIDEO_HOLE) 66 #if defined(VIDEO_HOLE)
65 case VideoFrame::HOLE: 67 case VideoFrame::HOLE:
66 #endif // defined(VIDEO_HOLE) 68 #endif // defined(VIDEO_HOLE)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, 127 video_frame->data(media::VideoFrame::kVPlane) + uv_offset,
126 static_cast<uint8*>(rgb_pixels), 128 static_cast<uint8*>(rgb_pixels),
127 video_frame->visible_rect().width(), 129 video_frame->visible_rect().width(),
128 video_frame->visible_rect().height(), 130 video_frame->visible_rect().height(),
129 video_frame->stride(media::VideoFrame::kYPlane), 131 video_frame->stride(media::VideoFrame::kYPlane),
130 video_frame->stride(media::VideoFrame::kUPlane), 132 video_frame->stride(media::VideoFrame::kUPlane),
131 row_bytes, 133 row_bytes,
132 media::YV12J); 134 media::YV12J);
133 break; 135 break;
134 136
137 case media::VideoFrame::YV12HD:
138 media::ConvertYUVToRGB32(
139 video_frame->data(media::VideoFrame::kYPlane) + y_offset,
140 video_frame->data(media::VideoFrame::kUPlane) + uv_offset,
141 video_frame->data(media::VideoFrame::kVPlane) + uv_offset,
142 static_cast<uint8*>(rgb_pixels),
143 video_frame->visible_rect().width(),
144 video_frame->visible_rect().height(),
145 video_frame->stride(media::VideoFrame::kYPlane),
146 video_frame->stride(media::VideoFrame::kUPlane),
147 row_bytes,
148 media::YV12HD);
149 break;
150
135 case media::VideoFrame::YV16: 151 case media::VideoFrame::YV16:
136 LIBYUV_I422_TO_ARGB( 152 LIBYUV_I422_TO_ARGB(
137 video_frame->data(media::VideoFrame::kYPlane) + y_offset, 153 video_frame->data(media::VideoFrame::kYPlane) + y_offset,
138 video_frame->stride(media::VideoFrame::kYPlane), 154 video_frame->stride(media::VideoFrame::kYPlane),
139 video_frame->data(media::VideoFrame::kUPlane) + uv_offset, 155 video_frame->data(media::VideoFrame::kUPlane) + uv_offset,
140 video_frame->stride(media::VideoFrame::kUPlane), 156 video_frame->stride(media::VideoFrame::kUPlane),
141 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, 157 video_frame->data(media::VideoFrame::kVPlane) + uv_offset,
142 video_frame->stride(media::VideoFrame::kVPlane), 158 video_frame->stride(media::VideoFrame::kVPlane),
143 static_cast<uint8*>(rgb_pixels), 159 static_cast<uint8*>(rgb_pixels),
144 row_bytes, 160 row_bytes,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 DCHECK_EQ(video_frame->format(), media::VideoFrame::NATIVE_TEXTURE); 208 DCHECK_EQ(video_frame->format(), media::VideoFrame::NATIVE_TEXTURE);
193 SkBitmap tmp; 209 SkBitmap tmp;
194 tmp.installPixels( 210 tmp.installPixels(
195 SkImageInfo::MakeN32Premul(video_frame->visible_rect().width(), 211 SkImageInfo::MakeN32Premul(video_frame->visible_rect().width(),
196 video_frame->visible_rect().height()), 212 video_frame->visible_rect().height()),
197 rgb_pixels, 213 rgb_pixels,
198 row_bytes); 214 row_bytes);
199 video_frame->ReadPixelsFromNativeTexture(tmp); 215 video_frame->ReadPixelsFromNativeTexture(tmp);
200 break; 216 break;
201 } 217 }
202 default: 218 case VideoFrame::UNKNOWN:
219 case VideoFrame::NV12:
203 NOTREACHED(); 220 NOTREACHED();
204 break;
205 } 221 }
206 } 222 }
207 223
208 // Generates an RGB image from a VideoFrame. 224 // Generates an RGB image from a VideoFrame.
209 class VideoImageGenerator : public SkImageGenerator { 225 class VideoImageGenerator : public SkImageGenerator {
210 public: 226 public:
211 VideoImageGenerator(const scoped_refptr<VideoFrame>& frame) : frame_(frame) {} 227 VideoImageGenerator(const scoped_refptr<VideoFrame>& frame) : frame_(frame) {}
212 virtual ~VideoImageGenerator() {} 228 virtual ~VideoImageGenerator() {}
213 229
214 void set_frame(const scoped_refptr<VideoFrame>& frame) { frame_ = frame; } 230 void set_frame(const scoped_refptr<VideoFrame>& frame) { frame_ = frame; }
(...skipping 19 matching lines...) Expand all
234 // If skia couldn't do the YUV conversion, we will. 250 // If skia couldn't do the YUV conversion, we will.
235 ConvertVideoFrameToRGBPixels(frame_, pixels, row_bytes); 251 ConvertVideoFrameToRGBPixels(frame_, pixels, row_bytes);
236 frame_ = NULL; 252 frame_ = NULL;
237 return true; 253 return true;
238 } 254 }
239 255
240 virtual bool onGetYUV8Planes(SkISize sizes[3], 256 virtual bool onGetYUV8Planes(SkISize sizes[3],
241 void* planes[3], 257 void* planes[3],
242 size_t row_bytes[3], 258 size_t row_bytes[3],
243 SkYUVColorSpace* color_space) OVERRIDE { 259 SkYUVColorSpace* color_space) OVERRIDE {
244 if (!frame_.get() || !IsYUV(frame_->format())) 260 if (!frame_.get() || !IsYUV(frame_->format()) ||
261 frame_->format() == VideoFrame::YV12HD) {
245 return false; 262 return false;
263 }
246 264
247 if (color_space) { 265 if (color_space) {
248 if (IsJPEGColorSpace(frame_->format())) 266 if (IsJPEGColorSpace(frame_->format()))
249 *color_space = kJPEG_SkYUVColorSpace; 267 *color_space = kJPEG_SkYUVColorSpace;
250 else 268 else
251 *color_space = kRec601_SkYUVColorSpace; 269 *color_space = kRec601_SkYUVColorSpace;
252 } 270 }
253 271
254 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; 272 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane;
255 ++plane) { 273 ++plane) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 SkCanvas* canvas) { 388 SkCanvas* canvas) {
371 Paint(video_frame, 389 Paint(video_frame,
372 canvas, 390 canvas,
373 video_frame->visible_rect(), 391 video_frame->visible_rect(),
374 0xff, 392 0xff,
375 SkXfermode::kSrc_Mode, 393 SkXfermode::kSrc_Mode,
376 media::VIDEO_ROTATION_0); 394 media::VIDEO_ROTATION_0);
377 } 395 }
378 396
379 } // namespace media 397 } // namespace media
OLDNEW
« media/base/video_frame.h ('K') | « media/filters/ffmpeg_video_decoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698