 Chromium Code Reviews
 Chromium Code Reviews Issue 663183002:
  ppapi: Change endianness in libyuv calls, from BGRA to ARGB  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 663183002:
  ppapi: Change endianness in libyuv calls, from BGRA to ARGB  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/webrtc/video_destination_handler.h" | 5 #include "content/renderer/media/webrtc/video_destination_handler.h" | 
| 6 | 6 | 
| 7 #include <string> | 7 #include <string> | 
| 8 | 8 | 
| 9 #include "base/base64.h" | 9 #include "base/base64.h" | 
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" | 
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 << "The image could not be mapped and is unusable."; | 94 << "The image could not be mapped and is unusable."; | 
| 95 return; | 95 return; | 
| 96 } | 96 } | 
| 97 | 97 | 
| 98 const SkBitmap* bitmap = image_data->GetMappedBitmap(); | 98 const SkBitmap* bitmap = image_data->GetMappedBitmap(); | 
| 99 if (!bitmap) { | 99 if (!bitmap) { | 
| 100 LOG(ERROR) << "PpFrameWriter::PutFrame - " | 100 LOG(ERROR) << "PpFrameWriter::PutFrame - " | 
| 101 << "The image_data's mapped bitmap is NULL."; | 101 << "The image_data's mapped bitmap is NULL."; | 
| 102 return; | 102 return; | 
| 103 } | 103 } | 
| 104 // We only support PP_IMAGEDATAFORMAT_BGRA_PREMUL at the moment. | |
| 105 DCHECK(image_data->format() == PP_IMAGEDATAFORMAT_BGRA_PREMUL); | |
| 104 io_message_loop_->PostTaskAndReply( | 106 io_message_loop_->PostTaskAndReply( | 
| 105 FROM_HERE, | 107 FROM_HERE, | 
| 106 base::Bind(&FrameWriterDelegate::DeliverFrameOnIO, this, | 108 base::Bind(&FrameWriterDelegate::DeliverFrameOnIO, this, | 
| 107 static_cast<uint8*>(bitmap->getPixels()), | 109 static_cast<uint8*>(bitmap->getPixels()), | 
| 108 bitmap->rowBytes(), | 110 bitmap->rowBytes(), | 
| 109 bitmap->width(), | 111 bitmap->width(), | 
| 110 bitmap->height(), | 112 bitmap->height(), | 
| 111 time_stamp_ns), | 113 time_stamp_ns), | 
| 112 base::Bind(&FrameWriterDelegate::FrameDelivered, this, | 114 base::Bind(&FrameWriterDelegate::FrameDelivered, this, | 
| 113 image_data)); | 115 image_data)); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 // WebRtcVideoCapturerAdapter before the frame is delivered to libJingle. | 148 // WebRtcVideoCapturerAdapter before the frame is delivered to libJingle. | 
| 147 // crbug/359587. | 149 // crbug/359587. | 
| 148 scoped_refptr<media::VideoFrame> new_frame = | 150 scoped_refptr<media::VideoFrame> new_frame = | 
| 149 frame_pool_.CreateFrame(media::VideoFrame::YV12, frame_size, | 151 frame_pool_.CreateFrame(media::VideoFrame::YV12, frame_size, | 
| 150 gfx::Rect(frame_size), frame_size, timestamp); | 152 gfx::Rect(frame_size), frame_size, timestamp); | 
| 151 media::VideoCaptureFormat format( | 153 media::VideoCaptureFormat format( | 
| 152 frame_size, | 154 frame_size, | 
| 153 MediaStreamVideoSource::kUnknownFrameRate, | 155 MediaStreamVideoSource::kUnknownFrameRate, | 
| 154 media::PIXEL_FORMAT_YV12); | 156 media::PIXEL_FORMAT_YV12); | 
| 155 | 157 | 
| 156 libyuv::BGRAToI420(data, | 158 // 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.
 | |
| 157 stride, | 159 // The alpha channel is always 255. It is unlikely for other color channels to | 
| 158 new_frame->data(media::VideoFrame::kYPlane), | 160 // be 255, so we will most likely break on the first few pixels. | 
| 159 new_frame->stride(media::VideoFrame::kYPlane), | 161 enum { | 
| 160 new_frame->data(media::VideoFrame::kUPlane), | 162 UNKNOWN, | 
| 161 new_frame->stride(media::VideoFrame::kUPlane), | 163 AXXX, | 
| 162 new_frame->data(media::VideoFrame::kVPlane), | 164 XXXA, | 
| 163 new_frame->stride(media::VideoFrame::kVPlane), | 165 } endian = UNKNOWN; | 
| 164 frame_size.width(), frame_size.height()); | 166 | 
| 167 uint8* row_ptr = data; | |
| 168 for (int y = 0; y < height && endian == UNKNOWN; ++y) { | |
| 169 for (int x = 0; x < width; ++x) { | |
| 170 if (row_ptr[x * 4 + 0] != 255) { | |
| 171 endian = XXXA; | |
| 172 break; | |
| 173 } | |
| 174 if (row_ptr[x * 4 + 3] != 255) { | |
| 175 endian = AXXX; | |
| 176 break; | |
| 177 } | |
| 178 } | |
| 179 row_ptr += stride; | |
| 180 } | |
| 181 if (endian == UNKNOWN) { | |
| 182 LOG(WARNING) << "PpFrameWriter::FrameWriterDelegate::DeliverFrameOnIO - " | |
| 183 << "Could not determine endianness."; | |
| 184 } | |
| 185 const auto xxxxToI420 = | |
| 186 (endian == AXXX) ? libyuv::BGRAToI420 : libyuv::ARGBToI420; | |
| 187 xxxxToI420(data, | |
| 188 stride, | |
| 189 new_frame->data(media::VideoFrame::kYPlane), | |
| 190 new_frame->stride(media::VideoFrame::kYPlane), | |
| 191 new_frame->data(media::VideoFrame::kUPlane), | |
| 192 new_frame->stride(media::VideoFrame::kUPlane), | |
| 193 new_frame->data(media::VideoFrame::kVPlane), | |
| 194 new_frame->stride(media::VideoFrame::kVPlane), | |
| 195 width, | |
| 196 height); | |
| 165 | 197 | 
| 166 // The local time when this frame is generated is unknown so give a null | 198 // The local time when this frame is generated is unknown so give a null | 
| 167 // value to |estimated_capture_time|. | 199 // value to |estimated_capture_time|. | 
| 168 new_frame_callback_.Run(new_frame, format, base::TimeTicks()); | 200 new_frame_callback_.Run(new_frame, format, base::TimeTicks()); | 
| 169 } | 201 } | 
| 170 | 202 | 
| 171 PpFrameWriter::PpFrameWriter() { | 203 PpFrameWriter::PpFrameWriter() { | 
| 172 DVLOG(3) << "PpFrameWriter ctor"; | 204 DVLOG(3) << "PpFrameWriter ctor"; | 
| 173 delegate_ = new FrameWriterDelegate(io_message_loop()); | 205 delegate_ = new FrameWriterDelegate(io_message_loop()); | 
| 174 } | 206 } | 
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 bool track_enabled = true; | 285 bool track_enabled = true; | 
| 254 | 286 | 
| 255 stream.addTrack(MediaStreamVideoTrack::CreateVideoTrack( | 287 stream.addTrack(MediaStreamVideoTrack::CreateVideoTrack( | 
| 256 writer, constraints, MediaStreamVideoSource::ConstraintsCallback(), | 288 writer, constraints, MediaStreamVideoSource::ConstraintsCallback(), | 
| 257 track_enabled)); | 289 track_enabled)); | 
| 258 | 290 | 
| 259 return true; | 291 return true; | 
| 260 } | 292 } | 
| 261 | 293 | 
| 262 } // namespace content | 294 } // namespace content | 
| OLD | NEW |