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

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: automatically detect endianness 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 | content/renderer/pepper/pepper_video_source_host.cc » ('j') | 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..2ac3c0e4e4aa1ad0108d0c1ec5665d23f5363812 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,45 @@ 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());
+ // Due to confusion about endianness, we try to determine it from the data.
thorcarpenter 2014/10/21 21:14:48 I like this, but consider adding TODO and referenc
magjed_chromium 2014/10/22 17:27:53 Done.
+ // 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 == AXXX) ? libyuv::BGRAToI420 : libyuv::ARGBToI420;
+ 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 | content/renderer/pepper/pepper_video_source_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698