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/logging.h" | 10 #include "base/logging.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 class PpFrameWriter::FrameWriterDelegate | 28 class PpFrameWriter::FrameWriterDelegate |
29 : public base::RefCountedThreadSafe<FrameWriterDelegate> { | 29 : public base::RefCountedThreadSafe<FrameWriterDelegate> { |
30 public: | 30 public: |
31 FrameWriterDelegate( | 31 FrameWriterDelegate( |
32 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy, | 32 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy, |
33 const VideoCaptureDeliverFrameCB& new_frame_callback); | 33 const VideoCaptureDeliverFrameCB& new_frame_callback); |
34 | 34 |
35 void DeliverFrame(const scoped_refptr<media::VideoFrame>& frame, | 35 void DeliverFrame(const scoped_refptr<media::VideoFrame>& frame); |
36 const media::VideoCaptureFormat& format); | |
37 private: | 36 private: |
38 friend class base::RefCountedThreadSafe<FrameWriterDelegate>; | 37 friend class base::RefCountedThreadSafe<FrameWriterDelegate>; |
39 virtual ~FrameWriterDelegate(); | 38 virtual ~FrameWriterDelegate(); |
40 | 39 |
41 void DeliverFrameOnIO(const scoped_refptr<media::VideoFrame>& frame, | 40 void DeliverFrameOnIO(const scoped_refptr<media::VideoFrame>& frame); |
42 const media::VideoCaptureFormat& format); | |
43 | 41 |
44 scoped_refptr<base::MessageLoopProxy> io_message_loop_; | 42 scoped_refptr<base::MessageLoopProxy> io_message_loop_; |
45 VideoCaptureDeliverFrameCB new_frame_callback_; | 43 VideoCaptureDeliverFrameCB new_frame_callback_; |
46 }; | 44 }; |
47 | 45 |
48 PpFrameWriter::FrameWriterDelegate::FrameWriterDelegate( | 46 PpFrameWriter::FrameWriterDelegate::FrameWriterDelegate( |
49 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy, | 47 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy, |
50 const VideoCaptureDeliverFrameCB& new_frame_callback) | 48 const VideoCaptureDeliverFrameCB& new_frame_callback) |
51 : io_message_loop_(io_message_loop_proxy), | 49 : io_message_loop_(io_message_loop_proxy), |
52 new_frame_callback_(new_frame_callback) { | 50 new_frame_callback_(new_frame_callback) { |
53 } | 51 } |
54 | 52 |
55 PpFrameWriter::FrameWriterDelegate::~FrameWriterDelegate() { | 53 PpFrameWriter::FrameWriterDelegate::~FrameWriterDelegate() { |
56 } | 54 } |
57 | 55 |
58 void PpFrameWriter::FrameWriterDelegate::DeliverFrame( | 56 void PpFrameWriter::FrameWriterDelegate::DeliverFrame( |
59 const scoped_refptr<media::VideoFrame>& frame, | 57 const scoped_refptr<media::VideoFrame>& frame) { |
60 const media::VideoCaptureFormat& format) { | |
61 io_message_loop_->PostTask( | 58 io_message_loop_->PostTask( |
62 FROM_HERE, | 59 FROM_HERE, |
63 base::Bind(&FrameWriterDelegate::DeliverFrameOnIO, | 60 base::Bind(&FrameWriterDelegate::DeliverFrameOnIO, this, frame)); |
64 this, frame, format)); | |
65 } | 61 } |
66 | 62 |
67 void PpFrameWriter::FrameWriterDelegate::DeliverFrameOnIO( | 63 void PpFrameWriter::FrameWriterDelegate::DeliverFrameOnIO( |
68 const scoped_refptr<media::VideoFrame>& frame, | 64 const scoped_refptr<media::VideoFrame>& frame) { |
69 const media::VideoCaptureFormat& format) { | |
70 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 65 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
71 // The local time when this frame is generated is unknown so give a null | 66 // The local time when this frame is generated is unknown so give a null |
72 // value to |estimated_capture_time|. | 67 // value to |estimated_capture_time|. |
73 new_frame_callback_.Run(frame, format, base::TimeTicks()); | 68 new_frame_callback_.Run(frame, base::TimeTicks()); |
74 } | 69 } |
75 | 70 |
76 PpFrameWriter::PpFrameWriter() { | 71 PpFrameWriter::PpFrameWriter() { |
77 DVLOG(3) << "PpFrameWriter ctor"; | 72 DVLOG(3) << "PpFrameWriter ctor"; |
78 } | 73 } |
79 | 74 |
80 PpFrameWriter::~PpFrameWriter() { | 75 PpFrameWriter::~PpFrameWriter() { |
81 DVLOG(3) << "PpFrameWriter dtor"; | 76 DVLOG(3) << "PpFrameWriter dtor"; |
82 } | 77 } |
83 | 78 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 140 |
146 if (state() != MediaStreamVideoSource::STARTED) | 141 if (state() != MediaStreamVideoSource::STARTED) |
147 return; | 142 return; |
148 | 143 |
149 const base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( | 144 const base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( |
150 time_stamp_ns / base::Time::kNanosecondsPerMicrosecond); | 145 time_stamp_ns / base::Time::kNanosecondsPerMicrosecond); |
151 | 146 |
152 scoped_refptr<media::VideoFrame> new_frame = | 147 scoped_refptr<media::VideoFrame> new_frame = |
153 frame_pool_.CreateFrame(media::VideoFrame::YV12, frame_size, | 148 frame_pool_.CreateFrame(media::VideoFrame::YV12, frame_size, |
154 gfx::Rect(frame_size), frame_size, timestamp); | 149 gfx::Rect(frame_size), frame_size, timestamp); |
155 media::VideoCaptureFormat format( | |
156 frame_size, | |
157 MediaStreamVideoSource::kUnknownFrameRate, | |
158 media::PIXEL_FORMAT_YV12); | |
159 | 150 |
160 // TODO(magjed): Chrome OS is not ready for switching from BGRA to ARGB. | 151 // TODO(magjed): Chrome OS is not ready for switching from BGRA to ARGB. |
161 // Remove this once http://crbug/434007 is fixed. We have a corresponding | 152 // Remove this once http://crbug/434007 is fixed. We have a corresponding |
162 // problem when we send frames to the effects plugin in PepperVideoSourceHost. | 153 // problem when we send frames to the effects plugin in PepperVideoSourceHost. |
163 #if defined(OS_CHROMEOS) | 154 #if defined(OS_CHROMEOS) |
164 auto libyuv_xxxx_to_i420 = &libyuv::BGRAToI420; | 155 auto libyuv_xxxx_to_i420 = &libyuv::BGRAToI420; |
165 #else | 156 #else |
166 auto libyuv_xxxx_to_i420 = &libyuv::ARGBToI420; | 157 auto libyuv_xxxx_to_i420 = &libyuv::ARGBToI420; |
167 #endif | 158 #endif |
168 libyuv_xxxx_to_i420(src_data, | 159 libyuv_xxxx_to_i420(src_data, |
169 src_stride, | 160 src_stride, |
170 new_frame->data(media::VideoFrame::kYPlane), | 161 new_frame->data(media::VideoFrame::kYPlane), |
171 new_frame->stride(media::VideoFrame::kYPlane), | 162 new_frame->stride(media::VideoFrame::kYPlane), |
172 new_frame->data(media::VideoFrame::kUPlane), | 163 new_frame->data(media::VideoFrame::kUPlane), |
173 new_frame->stride(media::VideoFrame::kUPlane), | 164 new_frame->stride(media::VideoFrame::kUPlane), |
174 new_frame->data(media::VideoFrame::kVPlane), | 165 new_frame->data(media::VideoFrame::kVPlane), |
175 new_frame->stride(media::VideoFrame::kVPlane), | 166 new_frame->stride(media::VideoFrame::kVPlane), |
176 width, | 167 width, |
177 height); | 168 height); |
178 | 169 |
179 delegate_->DeliverFrame(new_frame, format); | 170 delegate_->DeliverFrame(new_frame); |
180 } | 171 } |
181 | 172 |
182 // PpFrameWriterProxy is a helper class to make sure the user won't use | 173 // PpFrameWriterProxy is a helper class to make sure the user won't use |
183 // PpFrameWriter after it is released (IOW its owner - WebMediaStreamSource - | 174 // PpFrameWriter after it is released (IOW its owner - WebMediaStreamSource - |
184 // is released). | 175 // is released). |
185 class PpFrameWriterProxy : public FrameWriterInterface { | 176 class PpFrameWriterProxy : public FrameWriterInterface { |
186 public: | 177 public: |
187 explicit PpFrameWriterProxy(const base::WeakPtr<PpFrameWriter>& writer) | 178 explicit PpFrameWriterProxy(const base::WeakPtr<PpFrameWriter>& writer) |
188 : writer_(writer) { | 179 : writer_(writer) { |
189 DCHECK(writer_ != NULL); | 180 DCHECK(writer_ != NULL); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 235 |
245 stream.addTrack(MediaStreamVideoTrack::CreateVideoTrack( | 236 stream.addTrack(MediaStreamVideoTrack::CreateVideoTrack( |
246 writer, constraints, MediaStreamVideoSource::ConstraintsCallback(), | 237 writer, constraints, MediaStreamVideoSource::ConstraintsCallback(), |
247 track_enabled)); | 238 track_enabled)); |
248 | 239 |
249 *frame_writer = new PpFrameWriterProxy(writer->AsWeakPtr()); | 240 *frame_writer = new PpFrameWriterProxy(writer->AsWeakPtr()); |
250 return true; | 241 return true; |
251 } | 242 } |
252 | 243 |
253 } // namespace content | 244 } // namespace content |
OLD | NEW |