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

Unified Diff: content/renderer/media/webrtc/video_destination_handler.cc

Issue 663183002: ppapi: Change endianness in libyuv calls, from BGRA to ARGB (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add todo and remove PepperVideoSourceHost from this CL 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/webrtc/video_destination_handler.cc
diff --git a/content/renderer/media/webrtc/video_destination_handler.cc b/content/renderer/media/webrtc/video_destination_handler.cc
index 160537165d7912e4c514f6d49272f9dd60d0adde..2d088301f565c0fe808154f4f453bc64c21fed28 100644
--- a/content/renderer/media/webrtc/video_destination_handler.cc
+++ b/content/renderer/media/webrtc/video_destination_handler.cc
@@ -101,6 +101,8 @@ void PpFrameWriter::FrameWriterDelegate::DeliverFrame(
<< "The image_data's mapped bitmap is NULL.";
return;
}
+ // We only support PP_IMAGEDATAFORMAT_BGRA_PREMUL at the moment.
+ DCHECK(image_data->format() == PP_IMAGEDATAFORMAT_BGRA_PREMUL);
io_message_loop_->PostTaskAndReply(
FROM_HERE,
base::Bind(&FrameWriterDelegate::DeliverFrameOnIO, this,
@@ -153,15 +155,47 @@ void PpFrameWriter::FrameWriterDelegate::DeliverFrameOnIO(
MediaStreamVideoSource::kUnknownFrameRate,
media::PIXEL_FORMAT_YV12);
- libyuv::BGRAToI420(data,
- stride,
- new_frame->data(media::VideoFrame::kYPlane),
- new_frame->stride(media::VideoFrame::kYPlane),
- new_frame->data(media::VideoFrame::kUPlane),
- new_frame->stride(media::VideoFrame::kUPlane),
- new_frame->data(media::VideoFrame::kVPlane),
- new_frame->stride(media::VideoFrame::kVPlane),
- frame_size.width(), frame_size.height());
+ // TODO(magjed): Remove this and always use libyuv::ARGBToI420 when
+ // crbug/426020 is fixed.
+ // Due to confusion about endianness, we try to determine it from the data.
+ // The alpha channel is always 255. It is unlikely for other color channels to
+ // be 255, so we will most likely break on the first few pixels.
+ enum {
+ UNKNOWN,
+ AXXX,
+ XXXA,
+ } endian = UNKNOWN;
+
+ uint8* row_ptr = data;
+ for (int y = 0; y < height && endian == UNKNOWN; ++y) {
+ for (int x = 0; x < width; ++x) {
+ if (row_ptr[x * 4 + 0] != 255) {
+ endian = XXXA;
+ break;
+ }
+ if (row_ptr[x * 4 + 3] != 255) {
+ endian = AXXX;
+ break;
+ }
+ }
+ row_ptr += stride;
+ }
+ if (endian == UNKNOWN) {
+ LOG(WARNING) << "PpFrameWriter::FrameWriterDelegate::DeliverFrameOnIO - "
+ << "Could not determine endianness.";
+ }
+ const auto xxxxToI420 =
+ (endian == XXXA) ? libyuv::ARGBToI420 : libyuv::BGRAToI420;
thorcarpenter 2014/10/22 16:56:39 can we do xxxToI420 = (endian == XXXA || endian
magjed_chromium 2014/10/22 17:27:53 Done.
+ xxxxToI420(data,
+ stride,
+ new_frame->data(media::VideoFrame::kYPlane),
+ new_frame->stride(media::VideoFrame::kYPlane),
+ new_frame->data(media::VideoFrame::kUPlane),
+ new_frame->stride(media::VideoFrame::kUPlane),
+ new_frame->data(media::VideoFrame::kVPlane),
+ new_frame->stride(media::VideoFrame::kVPlane),
+ width,
+ height);
// The local time when this frame is generated is unknown so give a null
// value to |estimated_capture_time|.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698