| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 void PpFrameWriter::FrameWriterDelegate::DeliverFrameOnIO( | 67 void PpFrameWriter::FrameWriterDelegate::DeliverFrameOnIO( |
| 68 const scoped_refptr<media::VideoFrame>& frame, | 68 const scoped_refptr<media::VideoFrame>& frame, |
| 69 const media::VideoCaptureFormat& format) { | 69 const media::VideoCaptureFormat& format) { |
| 70 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 70 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 71 // The local time when this frame is generated is unknown so give a null | 71 // The local time when this frame is generated is unknown so give a null |
| 72 // value to |estimated_capture_time|. | 72 // value to |estimated_capture_time|. |
| 73 new_frame_callback_.Run(frame, format, base::TimeTicks()); | 73 new_frame_callback_.Run(frame, format, base::TimeTicks()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 PpFrameWriter::PpFrameWriter() : endian_(UNKNOWN) { | 76 PpFrameWriter::PpFrameWriter() { |
| 77 DVLOG(3) << "PpFrameWriter ctor"; | 77 DVLOG(3) << "PpFrameWriter ctor"; |
| 78 } | 78 } |
| 79 | 79 |
| 80 PpFrameWriter::~PpFrameWriter() { | 80 PpFrameWriter::~PpFrameWriter() { |
| 81 DVLOG(3) << "PpFrameWriter dtor"; | 81 DVLOG(3) << "PpFrameWriter dtor"; |
| 82 } | 82 } |
| 83 | 83 |
| 84 void PpFrameWriter::GetCurrentSupportedFormats( | 84 void PpFrameWriter::GetCurrentSupportedFormats( |
| 85 int max_requested_width, | 85 int max_requested_width, |
| 86 int max_requested_height, | 86 int max_requested_height, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 time_stamp_ns / base::Time::kNanosecondsPerMicrosecond); | 150 time_stamp_ns / base::Time::kNanosecondsPerMicrosecond); |
| 151 | 151 |
| 152 scoped_refptr<media::VideoFrame> new_frame = | 152 scoped_refptr<media::VideoFrame> new_frame = |
| 153 frame_pool_.CreateFrame(media::VideoFrame::YV12, frame_size, | 153 frame_pool_.CreateFrame(media::VideoFrame::YV12, frame_size, |
| 154 gfx::Rect(frame_size), frame_size, timestamp); | 154 gfx::Rect(frame_size), frame_size, timestamp); |
| 155 media::VideoCaptureFormat format( | 155 media::VideoCaptureFormat format( |
| 156 frame_size, | 156 frame_size, |
| 157 MediaStreamVideoSource::kUnknownFrameRate, | 157 MediaStreamVideoSource::kUnknownFrameRate, |
| 158 media::PIXEL_FORMAT_YV12); | 158 media::PIXEL_FORMAT_YV12); |
| 159 | 159 |
| 160 // TODO(magjed): Remove this and always use libyuv::ARGBToI420 when | 160 libyuv::ARGBToI420(src_data, |
| 161 // crbug/426020 is fixed. | 161 src_stride, |
| 162 // Due to a change in endianness, we try to determine it from the data. | 162 new_frame->data(media::VideoFrame::kYPlane), |
| 163 // The alpha channel is always 255. It is unlikely for other color channels to | 163 new_frame->stride(media::VideoFrame::kYPlane), |
| 164 // be 255, so we will most likely break on the first few pixels in the first | 164 new_frame->data(media::VideoFrame::kUPlane), |
| 165 // frame. | 165 new_frame->stride(media::VideoFrame::kUPlane), |
| 166 const uint8* row_ptr = src_data; | 166 new_frame->data(media::VideoFrame::kVPlane), |
| 167 // Note that we only do this if endian_ is still UNKNOWN. | 167 new_frame->stride(media::VideoFrame::kVPlane), |
| 168 for (int y = 0; y < height && endian_ == UNKNOWN; ++y) { | 168 width, |
| 169 for (int x = 0; x < width; ++x) { | 169 height); |
| 170 if (row_ptr[x * 4 + 0] != 255) { // First byte is not Alpha => XXXA. | |
| 171 endian_ = XXXA; | |
| 172 break; | |
| 173 } | |
| 174 if (row_ptr[x * 4 + 3] != 255) { // Fourth byte is not Alpha => AXXX. | |
| 175 endian_ = AXXX; | |
| 176 break; | |
| 177 } | |
| 178 } | |
| 179 row_ptr += src_stride; | |
| 180 } | |
| 181 if (endian_ == UNKNOWN) { | |
| 182 LOG(WARNING) << "PpFrameWriter::FrameWriterDelegate::DeliverFrameOnIO - " | |
| 183 << "Could not determine endianness."; | |
| 184 } | |
| 185 // libyuv specifies fourcc/channel ordering the same as webrtc. That is why | |
| 186 // the naming is reversed compared to PixelEndian and PP_ImageDataFormat which | |
| 187 // describes the memory layout from the lowest address to the highest. | |
| 188 auto xxxxToI420 = | |
| 189 (endian_ == AXXX) ? &libyuv::BGRAToI420 : &libyuv::ARGBToI420; | |
| 190 xxxxToI420(src_data, | |
| 191 src_stride, | |
| 192 new_frame->data(media::VideoFrame::kYPlane), | |
| 193 new_frame->stride(media::VideoFrame::kYPlane), | |
| 194 new_frame->data(media::VideoFrame::kUPlane), | |
| 195 new_frame->stride(media::VideoFrame::kUPlane), | |
| 196 new_frame->data(media::VideoFrame::kVPlane), | |
| 197 new_frame->stride(media::VideoFrame::kVPlane), | |
| 198 width, | |
| 199 height); | |
| 200 | 170 |
| 201 delegate_->DeliverFrame(new_frame, format); | 171 delegate_->DeliverFrame(new_frame, format); |
| 202 } | 172 } |
| 203 | 173 |
| 204 // PpFrameWriterProxy is a helper class to make sure the user won't use | 174 // PpFrameWriterProxy is a helper class to make sure the user won't use |
| 205 // PpFrameWriter after it is released (IOW its owner - WebMediaStreamSource - | 175 // PpFrameWriter after it is released (IOW its owner - WebMediaStreamSource - |
| 206 // is released). | 176 // is released). |
| 207 class PpFrameWriterProxy : public FrameWriterInterface { | 177 class PpFrameWriterProxy : public FrameWriterInterface { |
| 208 public: | 178 public: |
| 209 explicit PpFrameWriterProxy(const base::WeakPtr<PpFrameWriter>& writer) | 179 explicit PpFrameWriterProxy(const base::WeakPtr<PpFrameWriter>& writer) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 236 |
| 267 stream.addTrack(MediaStreamVideoTrack::CreateVideoTrack( | 237 stream.addTrack(MediaStreamVideoTrack::CreateVideoTrack( |
| 268 writer, constraints, MediaStreamVideoSource::ConstraintsCallback(), | 238 writer, constraints, MediaStreamVideoSource::ConstraintsCallback(), |
| 269 track_enabled)); | 239 track_enabled)); |
| 270 | 240 |
| 271 *frame_writer = new PpFrameWriterProxy(writer->AsWeakPtr()); | 241 *frame_writer = new PpFrameWriterProxy(writer->AsWeakPtr()); |
| 272 return true; | 242 return true; |
| 273 } | 243 } |
| 274 | 244 |
| 275 } // namespace content | 245 } // namespace content |
| OLD | NEW |