| 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 #if defined(OS_ANDROID) |
| 83 frame->stride(media::VideoFrame::kYPlane), | 83 // See https://crbug.com/627983. |
| 84 frame->visible_data(media::VideoFrame::kUPlane), | 84 const uint32 destination_pixel_format = libyuv::FOURCC_ABGR; |
| 85 frame->stride(media::VideoFrame::kUPlane), | 85 #else |
| 86 frame->visible_data(media::VideoFrame::kVPlane), | 86 const uint32 destination_pixel_format = libyuv::FOURCC_ARGB; |
| 87 frame->stride(media::VideoFrame::kVPlane), | 87 #endif |
| 88 static_cast<uint8*>(pixmap.writable_addr()), | 88 |
| 89 pixmap.width() * 4, pixmap.width(), pixmap.height()); | 89 libyuv::ConvertFromI420(frame->visible_data(media::VideoFrame::kYPlane), |
| 90 frame->stride(media::VideoFrame::kYPlane), |
| 91 frame->visible_data(media::VideoFrame::kUPlane), |
| 92 frame->stride(media::VideoFrame::kUPlane), |
| 93 frame->visible_data(media::VideoFrame::kVPlane), |
| 94 frame->stride(media::VideoFrame::kVPlane), |
| 95 static_cast<uint8*>(pixmap.writable_addr()), |
| 96 pixmap.width() * 4, pixmap.width(), pixmap.height(), |
| 97 destination_pixel_format); |
| 90 | 98 |
| 91 if (frame->format() == media::PIXEL_FORMAT_YV12A) { | 99 if (frame->format() == media::PIXEL_FORMAT_YV12A) { |
| 92 DCHECK(!info.isOpaque()); | 100 DCHECK(!info.isOpaque()); |
| 93 // This function copies any plane into the alpha channel of an ARGB image. | 101 // This function copies any plane into the alpha channel of an ARGB image. |
| 94 libyuv::ARGBCopyYToAlpha(frame->visible_data(media::VideoFrame::kAPlane), | 102 libyuv::ARGBCopyYToAlpha(frame->visible_data(media::VideoFrame::kAPlane), |
| 95 frame->stride(media::VideoFrame::kAPlane), | 103 frame->stride(media::VideoFrame::kAPlane), |
| 96 static_cast<uint8*>(pixmap.writable_addr()), | 104 static_cast<uint8*>(pixmap.writable_addr()), |
| 97 pixmap.width() * 4, pixmap.width(), | 105 pixmap.width() * 4, pixmap.width(), |
| 98 pixmap.height()); | 106 pixmap.height()); |
| 99 } | 107 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 DCHECK(thread_checker_.CalledOnValidThread()); | 148 DCHECK(thread_checker_.CalledOnValidThread()); |
| 141 | 149 |
| 142 MediaStreamVideoSink::DisconnectFromTrack(); | 150 MediaStreamVideoSink::DisconnectFromTrack(); |
| 143 if (image) | 151 if (image) |
| 144 callbacks.PassCallbacks()->onSuccess(image); | 152 callbacks.PassCallbacks()->onSuccess(image); |
| 145 else | 153 else |
| 146 callbacks.PassCallbacks()->onError(); | 154 callbacks.PassCallbacks()->onError(); |
| 147 } | 155 } |
| 148 | 156 |
| 149 } // namespace content | 157 } // namespace content |
| OLD | NEW |