OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/renderer/media/image_capture_frame_grabber.h" | 5 #include "content/renderer/media/image_capture_frame_grabber.h" |
6 | 6 |
7 #include "media/base/bind_to_current_loop.h" | 7 #include "media/base/bind_to_current_loop.h" |
8 #include "media/base/video_frame.h" | 8 #include "media/base/video_frame.h" |
9 #include "media/base/video_util.h" | 9 #include "media/base/video_util.h" |
10 #include "skia/ext/platform_canvas.h" | 10 #include "skia/ext/platform_canvas.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 sk_sp<SkSurface> surface = SkSurface::MakeRaster(info); | 72 sk_sp<SkSurface> surface = SkSurface::MakeRaster(info); |
73 DCHECK(surface); | 73 DCHECK(surface); |
74 | 74 |
75 SkPixmap pixmap; | 75 SkPixmap pixmap; |
76 if (!skia::GetWritablePixels(surface->getCanvas(), &pixmap)) { | 76 if (!skia::GetWritablePixels(surface->getCanvas(), &pixmap)) { |
77 DLOG(ERROR) << "Error trying to map SkSurface's pixels"; | 77 DLOG(ERROR) << "Error trying to map SkSurface's pixels"; |
78 callback.Run(sk_sp<SkImage>()); | 78 callback.Run(sk_sp<SkImage>()); |
79 return; | 79 return; |
80 } | 80 } |
81 | 81 |
82 libyuv::I420ToARGB(frame->visible_data(media::VideoFrame::kYPlane), | 82 const uint32 destination_pixel_format = |
83 frame->stride(media::VideoFrame::kYPlane), | 83 (kN32_SkColorType == kRGBA_8888_SkColorType) ? libyuv::FOURCC_ABGR |
84 frame->visible_data(media::VideoFrame::kUPlane), | 84 : libyuv::FOURCC_ARGB; |
85 frame->stride(media::VideoFrame::kUPlane), | 85 |
86 frame->visible_data(media::VideoFrame::kVPlane), | 86 libyuv::ConvertFromI420(frame->visible_data(media::VideoFrame::kYPlane), |
87 frame->stride(media::VideoFrame::kVPlane), | 87 frame->stride(media::VideoFrame::kYPlane), |
88 static_cast<uint8*>(pixmap.writable_addr()), | 88 frame->visible_data(media::VideoFrame::kUPlane), |
89 pixmap.width() * 4, pixmap.width(), pixmap.height()); | 89 frame->stride(media::VideoFrame::kUPlane), |
| 90 frame->visible_data(media::VideoFrame::kVPlane), |
| 91 frame->stride(media::VideoFrame::kVPlane), |
| 92 static_cast<uint8*>(pixmap.writable_addr()), |
| 93 pixmap.width() * 4, pixmap.width(), pixmap.height(), |
| 94 destination_pixel_format); |
90 | 95 |
91 if (frame->format() == media::PIXEL_FORMAT_YV12A) { | 96 if (frame->format() == media::PIXEL_FORMAT_YV12A) { |
92 DCHECK(!info.isOpaque()); | 97 DCHECK(!info.isOpaque()); |
93 // This function copies any plane into the alpha channel of an ARGB image. | 98 // This function copies any plane into the alpha channel of an ARGB image. |
94 libyuv::ARGBCopyYToAlpha(frame->visible_data(media::VideoFrame::kAPlane), | 99 libyuv::ARGBCopyYToAlpha(frame->visible_data(media::VideoFrame::kAPlane), |
95 frame->stride(media::VideoFrame::kAPlane), | 100 frame->stride(media::VideoFrame::kAPlane), |
96 static_cast<uint8*>(pixmap.writable_addr()), | 101 static_cast<uint8*>(pixmap.writable_addr()), |
97 pixmap.width() * 4, pixmap.width(), | 102 pixmap.width() * 4, pixmap.width(), |
98 pixmap.height()); | 103 pixmap.height()); |
99 } | 104 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 DCHECK(thread_checker_.CalledOnValidThread()); | 145 DCHECK(thread_checker_.CalledOnValidThread()); |
141 | 146 |
142 MediaStreamVideoSink::DisconnectFromTrack(); | 147 MediaStreamVideoSink::DisconnectFromTrack(); |
143 if (image) | 148 if (image) |
144 callbacks.PassCallbacks()->onSuccess(image); | 149 callbacks.PassCallbacks()->onSuccess(image); |
145 else | 150 else |
146 callbacks.PassCallbacks()->onError(); | 151 callbacks.PassCallbacks()->onError(); |
147 } | 152 } |
148 | 153 |
149 } // namespace content | 154 } // namespace content |
OLD | NEW |