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 // TODO(magjed): Remove this and always use libyuv::ARGBToI420 when |
157 stride, | 159 // crbug/426020 is fixed. |
158 new_frame->data(media::VideoFrame::kYPlane), | 160 // Due to confusion about endianness, we try to determine it from the data. |
159 new_frame->stride(media::VideoFrame::kYPlane), | 161 // The alpha channel is always 255. It is unlikely for other color channels to |
160 new_frame->data(media::VideoFrame::kUPlane), | 162 // be 255, so we will most likely break on the first few pixels. |
161 new_frame->stride(media::VideoFrame::kUPlane), | 163 enum { |
162 new_frame->data(media::VideoFrame::kVPlane), | 164 UNKNOWN, |
163 new_frame->stride(media::VideoFrame::kVPlane), | 165 AXXX, |
164 frame_size.width(), frame_size.height()); | 166 XXXA, |
167 } endian = UNKNOWN; | |
168 | |
169 uint8* row_ptr = data; | |
170 for (int y = 0; y < height && endian == UNKNOWN; ++y) { | |
171 for (int x = 0; x < width; ++x) { | |
172 if (row_ptr[x * 4 + 0] != 255) { | |
173 endian = XXXA; | |
174 break; | |
175 } | |
176 if (row_ptr[x * 4 + 3] != 255) { | |
177 endian = AXXX; | |
178 break; | |
179 } | |
180 } | |
181 row_ptr += stride; | |
182 } | |
183 if (endian == UNKNOWN) { | |
184 LOG(WARNING) << "PpFrameWriter::FrameWriterDelegate::DeliverFrameOnIO - " | |
185 << "Could not determine endianness."; | |
186 } | |
187 const auto xxxxToI420 = | |
188 (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.
| |
189 xxxxToI420(data, | |
190 stride, | |
191 new_frame->data(media::VideoFrame::kYPlane), | |
192 new_frame->stride(media::VideoFrame::kYPlane), | |
193 new_frame->data(media::VideoFrame::kUPlane), | |
194 new_frame->stride(media::VideoFrame::kUPlane), | |
195 new_frame->data(media::VideoFrame::kVPlane), | |
196 new_frame->stride(media::VideoFrame::kVPlane), | |
197 width, | |
198 height); | |
165 | 199 |
166 // The local time when this frame is generated is unknown so give a null | 200 // The local time when this frame is generated is unknown so give a null |
167 // value to |estimated_capture_time|. | 201 // value to |estimated_capture_time|. |
168 new_frame_callback_.Run(new_frame, format, base::TimeTicks()); | 202 new_frame_callback_.Run(new_frame, format, base::TimeTicks()); |
169 } | 203 } |
170 | 204 |
171 PpFrameWriter::PpFrameWriter() { | 205 PpFrameWriter::PpFrameWriter() { |
172 DVLOG(3) << "PpFrameWriter ctor"; | 206 DVLOG(3) << "PpFrameWriter ctor"; |
173 delegate_ = new FrameWriterDelegate(io_message_loop()); | 207 delegate_ = new FrameWriterDelegate(io_message_loop()); |
174 } | 208 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 bool track_enabled = true; | 287 bool track_enabled = true; |
254 | 288 |
255 stream.addTrack(MediaStreamVideoTrack::CreateVideoTrack( | 289 stream.addTrack(MediaStreamVideoTrack::CreateVideoTrack( |
256 writer, constraints, MediaStreamVideoSource::ConstraintsCallback(), | 290 writer, constraints, MediaStreamVideoSource::ConstraintsCallback(), |
257 track_enabled)); | 291 track_enabled)); |
258 | 292 |
259 return true; | 293 return true; |
260 } | 294 } |
261 | 295 |
262 } // namespace content | 296 } // namespace content |
OLD | NEW |