Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/webrtc_video_capturer_adapter.h" | 5 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/memory/aligned_memory.h" | 9 #include "base/memory/aligned_memory.h" |
| 10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
| 11 #include "third_party/libyuv/include/libyuv/convert.h" | 11 #include "third_party/libyuv/include/libyuv/convert.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 WebRtcVideoCapturerAdapter::WebRtcVideoCapturerAdapter(bool is_screencast) | 15 WebRtcVideoCapturerAdapter::WebRtcVideoCapturerAdapter( |
| 16 bool is_screencast) | |
|
Ami GONE FROM CHROMIUM
2014/05/12 19:46:28
\n unnecessary now
perkj_chrome
2014/05/12 20:35:12
Done.
| |
| 16 : is_screencast_(is_screencast), | 17 : is_screencast_(is_screencast), |
| 17 running_(false), | 18 running_(false), |
| 18 buffer_(NULL), | 19 buffer_(NULL), |
| 19 buffer_size_(0) { | 20 buffer_size_(0) { |
| 21 thread_checker_.DetachFromThread(); | |
| 20 } | 22 } |
| 21 | 23 |
| 22 WebRtcVideoCapturerAdapter::~WebRtcVideoCapturerAdapter() { | 24 WebRtcVideoCapturerAdapter::~WebRtcVideoCapturerAdapter() { |
| 23 DVLOG(3) << " WebRtcVideoCapturerAdapter::dtor"; | 25 DVLOG(3) << " WebRtcVideoCapturerAdapter::dtor"; |
| 24 base::AlignedFree(buffer_); | 26 base::AlignedFree(buffer_); |
| 25 } | 27 } |
| 26 | 28 |
| 27 cricket::CaptureState WebRtcVideoCapturerAdapter::Start( | 29 cricket::CaptureState WebRtcVideoCapturerAdapter::Start( |
| 28 const cricket::VideoFormat& capture_format) { | 30 const cricket::VideoFormat& capture_format) { |
| 31 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 29 DCHECK(!running_); | 32 DCHECK(!running_); |
| 30 DVLOG(3) << " WebRtcVideoCapturerAdapter::Start w = " << capture_format.width | 33 DVLOG(3) << " WebRtcVideoCapturerAdapter::Start w = " << capture_format.width |
| 31 << " h = " << capture_format.height; | 34 << " h = " << capture_format.height; |
| 32 | 35 |
| 33 running_ = true; | 36 running_ = true; |
| 34 return cricket::CS_RUNNING; | 37 return cricket::CS_RUNNING; |
| 35 } | 38 } |
| 36 | 39 |
| 37 void WebRtcVideoCapturerAdapter::Stop() { | 40 void WebRtcVideoCapturerAdapter::Stop() { |
| 41 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 38 DVLOG(3) << " WebRtcVideoCapturerAdapter::Stop "; | 42 DVLOG(3) << " WebRtcVideoCapturerAdapter::Stop "; |
| 39 DCHECK(running_); | 43 DCHECK(running_); |
| 40 running_ = false; | 44 running_ = false; |
| 41 SetCaptureFormat(NULL); | 45 SetCaptureFormat(NULL); |
| 42 SignalStateChange(this, cricket::CS_STOPPED); | 46 SignalStateChange(this, cricket::CS_STOPPED); |
| 43 } | 47 } |
| 44 | 48 |
| 45 bool WebRtcVideoCapturerAdapter::IsRunning() { | 49 bool WebRtcVideoCapturerAdapter::IsRunning() { |
| 50 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 46 return running_; | 51 return running_; |
| 47 } | 52 } |
| 48 | 53 |
| 49 bool WebRtcVideoCapturerAdapter::GetPreferredFourccs( | 54 bool WebRtcVideoCapturerAdapter::GetPreferredFourccs( |
| 50 std::vector<uint32>* fourccs) { | 55 std::vector<uint32>* fourccs) { |
| 56 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 51 if (!fourccs) | 57 if (!fourccs) |
| 52 return false; | 58 return false; |
| 53 fourccs->push_back(cricket::FOURCC_I420); | 59 fourccs->push_back(cricket::FOURCC_I420); |
| 54 return true; | 60 return true; |
| 55 } | 61 } |
| 56 | 62 |
| 57 bool WebRtcVideoCapturerAdapter::IsScreencast() const { | 63 bool WebRtcVideoCapturerAdapter::IsScreencast() const { |
| 58 return is_screencast_; | 64 return is_screencast_; |
| 59 } | 65 } |
| 60 | 66 |
| 61 bool WebRtcVideoCapturerAdapter::GetBestCaptureFormat( | 67 bool WebRtcVideoCapturerAdapter::GetBestCaptureFormat( |
| 62 const cricket::VideoFormat& desired, | 68 const cricket::VideoFormat& desired, |
| 63 cricket::VideoFormat* best_format) { | 69 cricket::VideoFormat* best_format) { |
| 70 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 64 DVLOG(3) << " GetBestCaptureFormat:: " | 71 DVLOG(3) << " GetBestCaptureFormat:: " |
| 65 << " w = " << desired.width | 72 << " w = " << desired.width |
| 66 << " h = " << desired.height; | 73 << " h = " << desired.height; |
| 67 | 74 |
| 68 // Capability enumeration is done in MediaStreamVideoSource. The adapter can | 75 // Capability enumeration is done in MediaStreamVideoSource. The adapter can |
| 69 // just use what is provided. | 76 // just use what is provided. |
| 70 // Use the desired format as the best format. | 77 // Use the desired format as the best format. |
| 71 best_format->width = desired.width; | 78 best_format->width = desired.width; |
| 72 best_format->height = desired.height; | 79 best_format->height = desired.height; |
| 73 best_format->fourcc = cricket::FOURCC_I420; | 80 best_format->fourcc = cricket::FOURCC_I420; |
| 74 best_format->interval = desired.interval; | 81 best_format->interval = desired.interval; |
| 75 return true; | 82 return true; |
| 76 } | 83 } |
| 77 | 84 |
| 78 void WebRtcVideoCapturerAdapter::OnFrameCaptured( | 85 void WebRtcVideoCapturerAdapter::OnFrameCaptured( |
| 79 const scoped_refptr<media::VideoFrame>& frame) { | 86 const scoped_refptr<media::VideoFrame>& frame) { |
| 87 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 80 DCHECK(media::VideoFrame::I420 == frame->format() || | 88 DCHECK(media::VideoFrame::I420 == frame->format() || |
| 81 media::VideoFrame::YV12 == frame->format()); | 89 media::VideoFrame::YV12 == frame->format()); |
| 82 if (first_frame_timestamp_ == media::kNoTimestamp()) | 90 if (first_frame_timestamp_ == media::kNoTimestamp()) |
| 83 first_frame_timestamp_ = frame->timestamp(); | 91 first_frame_timestamp_ = frame->timestamp(); |
| 84 | 92 |
| 85 cricket::CapturedFrame captured_frame; | 93 cricket::CapturedFrame captured_frame; |
| 86 captured_frame.width = frame->visible_rect().width(); | 94 captured_frame.width = frame->visible_rect().width(); |
| 87 captured_frame.height = frame->visible_rect().height(); | 95 captured_frame.height = frame->visible_rect().height(); |
| 88 // cricket::CapturedFrame time is in nanoseconds. | 96 // cricket::CapturedFrame time is in nanoseconds. |
| 89 captured_frame.elapsed_time = | 97 captured_frame.elapsed_time = |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 113 media::VideoFrame::AllocationSize(frame->format(), frame->coded_size()); | 121 media::VideoFrame::AllocationSize(frame->format(), frame->coded_size()); |
| 114 } | 122 } |
| 115 | 123 |
| 116 // This signals to libJingle that a new VideoFrame is available. | 124 // This signals to libJingle that a new VideoFrame is available. |
| 117 // libJingle have no assumptions on what thread this signal come from. | 125 // libJingle have no assumptions on what thread this signal come from. |
| 118 SignalFrameCaptured(this, &captured_frame); | 126 SignalFrameCaptured(this, &captured_frame); |
| 119 } | 127 } |
| 120 | 128 |
| 121 void WebRtcVideoCapturerAdapter::UpdateI420Buffer( | 129 void WebRtcVideoCapturerAdapter::UpdateI420Buffer( |
| 122 const scoped_refptr<media::VideoFrame>& src) { | 130 const scoped_refptr<media::VideoFrame>& src) { |
| 131 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 123 const int src_width = src->coded_size().width(); | 132 const int src_width = src->coded_size().width(); |
| 124 const int src_height = src->coded_size().height(); | 133 const int src_height = src->coded_size().height(); |
| 125 const int dst_width = src->visible_rect().width(); | 134 const int dst_width = src->visible_rect().width(); |
| 126 const int dst_height = src->visible_rect().height(); | 135 const int dst_height = src->visible_rect().height(); |
| 127 DCHECK(src_width >= dst_width && src_height >= dst_height); | 136 DCHECK(src_width >= dst_width && src_height >= dst_height); |
| 128 | 137 |
| 129 const int horiz_crop = src->visible_rect().x(); | 138 const int horiz_crop = src->visible_rect().x(); |
| 130 const int vert_crop = src->visible_rect().y(); | 139 const int vert_crop = src->visible_rect().y(); |
| 131 | 140 |
| 132 const uint8* src_y = src->data(media::VideoFrame::kYPlane) + | 141 const uint8* src_y = src->data(media::VideoFrame::kYPlane) + |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 dst_stride_y, | 175 dst_stride_y, |
| 167 dst_u, | 176 dst_u, |
| 168 dst_halfwidth, | 177 dst_halfwidth, |
| 169 dst_v, | 178 dst_v, |
| 170 dst_halfwidth, | 179 dst_halfwidth, |
| 171 dst_width, | 180 dst_width, |
| 172 dst_height); | 181 dst_height); |
| 173 } | 182 } |
| 174 | 183 |
| 175 } // namespace content | 184 } // namespace content |
| OLD | NEW |