| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // Implementation file of class VideoCapturer. | 11 // Implementation file of class VideoCapturer. |
| 12 | 12 |
| 13 #include "webrtc/media/base/videocapturer.h" | 13 #include "webrtc/media/base/videocapturer.h" |
| 14 | 14 |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 | 16 |
| 17 #include "libyuv/scale_argb.h" | 17 #include "libyuv/scale_argb.h" |
| 18 #include "webrtc/base/common.h" | 18 #include "webrtc/base/common.h" |
| 19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
| 20 #include "webrtc/base/systeminfo.h" | 20 #include "webrtc/base/systeminfo.h" |
| 21 #include "webrtc/video_frame.h" | 21 #include "webrtc/media/engine/webrtcvideoframe.h" |
| 22 | 22 |
| 23 namespace cricket { | 23 namespace cricket { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 static const int64_t kMaxDistance = ~(static_cast<int64_t>(1) << 63); | 27 static const int64_t kMaxDistance = ~(static_cast<int64_t>(1) << 63); |
| 28 #ifdef WEBRTC_LINUX | 28 #ifdef WEBRTC_LINUX |
| 29 static const int kYU12Penalty = 16; // Needs to be higher than MJPG index. | 29 static const int kYU12Penalty = 16; // Needs to be higher than MJPG index. |
| 30 #endif | 30 #endif |
| 31 | 31 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 if (!input_size_valid_) { | 125 if (!input_size_valid_) { |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 *width = input_width_; | 128 *width = input_width_; |
| 129 *height = input_height_; | 129 *height = input_height_; |
| 130 | 130 |
| 131 return true; | 131 return true; |
| 132 } | 132 } |
| 133 | 133 |
| 134 void VideoCapturer::RemoveSink( | 134 void VideoCapturer::RemoveSink( |
| 135 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) { | 135 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) { |
| 136 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 136 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 137 broadcaster_.RemoveSink(sink); | 137 broadcaster_.RemoveSink(sink); |
| 138 OnSinkWantsChanged(broadcaster_.wants()); | 138 OnSinkWantsChanged(broadcaster_.wants()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void VideoCapturer::AddOrUpdateSink( | 141 void VideoCapturer::AddOrUpdateSink( |
| 142 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink, | 142 rtc::VideoSinkInterface<cricket::VideoFrame>* sink, |
| 143 const rtc::VideoSinkWants& wants) { | 143 const rtc::VideoSinkWants& wants) { |
| 144 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 144 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 145 broadcaster_.AddOrUpdateSink(sink, wants); | 145 broadcaster_.AddOrUpdateSink(sink, wants); |
| 146 OnSinkWantsChanged(broadcaster_.wants()); | 146 OnSinkWantsChanged(broadcaster_.wants()); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void VideoCapturer::OnSinkWantsChanged(const rtc::VideoSinkWants& wants) { | 149 void VideoCapturer::OnSinkWantsChanged(const rtc::VideoSinkWants& wants) { |
| 150 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 150 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 151 apply_rotation_ = wants.rotation_applied; | 151 apply_rotation_ = wants.rotation_applied; |
| 152 | 152 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 *out_height = height; | 189 *out_height = height; |
| 190 *crop_width = width; | 190 *crop_width = width; |
| 191 *crop_height = height; | 191 *crop_height = height; |
| 192 *crop_x = 0; | 192 *crop_x = 0; |
| 193 *crop_y = 0; | 193 *crop_y = 0; |
| 194 } | 194 } |
| 195 | 195 |
| 196 return true; | 196 return true; |
| 197 } | 197 } |
| 198 | 198 |
| 199 void VideoCapturer::OnFrame(const webrtc::VideoFrame& frame, | 199 void VideoCapturer::OnFrame(const VideoFrame& frame, |
| 200 int orig_width, | 200 int orig_width, |
| 201 int orig_height) { | 201 int orig_height) { |
| 202 // For a child class which implements rotation itself, we should | 202 // For a child class which implements rotation itself, we should |
| 203 // always have apply_rotation_ == false or frame.rotation() == 0. | 203 // always have apply_rotation_ == false or frame.rotation() == 0. |
| 204 // Except possibly during races where apply_rotation_ is changed | 204 // Except possibly during races where apply_rotation_ is changed |
| 205 // mid-stream. | 205 // mid-stream. |
| 206 if (apply_rotation_ && frame.rotation() != webrtc::kVideoRotation_0) { | 206 if (apply_rotation_ && frame.rotation() != webrtc::kVideoRotation_0) { |
| 207 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer( | 207 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer( |
| 208 frame.video_frame_buffer()); | 208 frame.video_frame_buffer()); |
| 209 if (buffer->native_handle()) { | 209 if (buffer->native_handle()) { |
| 210 // Sources producing native frames must handle apply_rotation | 210 // Sources producing native frames must handle apply_rotation |
| 211 // themselves. But even if they do, we may occasionally end up | 211 // themselves. But even if they do, we may occasionally end up |
| 212 // in this case, for frames in flight at the time | 212 // in this case, for frames in flight at the time |
| 213 // applied_rotation is set to true. In that case, we just drop | 213 // applied_rotation is set to true. In that case, we just drop |
| 214 // the frame. | 214 // the frame. |
| 215 LOG(LS_WARNING) << "Native frame requiring rotation. Discarding."; | 215 LOG(LS_WARNING) << "Native frame requiring rotation. Discarding."; |
| 216 return; | 216 return; |
| 217 } | 217 } |
| 218 broadcaster_.OnFrame(webrtc::VideoFrame( | 218 broadcaster_.OnFrame(WebRtcVideoFrame( |
| 219 webrtc::I420Buffer::Rotate(buffer, frame.rotation()), | 219 webrtc::I420Buffer::Rotate(buffer, frame.rotation()), |
| 220 webrtc::kVideoRotation_0, frame.timestamp_us())); | 220 webrtc::kVideoRotation_0, frame.timestamp_us())); |
| 221 } else { | 221 } else { |
| 222 broadcaster_.OnFrame(frame); | 222 broadcaster_.OnFrame(frame); |
| 223 } | 223 } |
| 224 UpdateInputSize(orig_width, orig_height); | 224 UpdateInputSize(orig_width, orig_height); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void VideoCapturer::SetCaptureState(CaptureState state) { | 227 void VideoCapturer::SetCaptureState(CaptureState state) { |
| 228 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 228 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 void VideoCapturer::UpdateInputSize(int width, int height) { | 365 void VideoCapturer::UpdateInputSize(int width, int height) { |
| 366 // Update stats protected from fetches from different thread. | 366 // Update stats protected from fetches from different thread. |
| 367 rtc::CritScope cs(&frame_stats_crit_); | 367 rtc::CritScope cs(&frame_stats_crit_); |
| 368 | 368 |
| 369 input_size_valid_ = true; | 369 input_size_valid_ = true; |
| 370 input_width_ = width; | 370 input_width_ = width; |
| 371 input_height_ = height; | 371 input_height_ = height; |
| 372 } | 372 } |
| 373 | 373 |
| 374 } // namespace cricket | 374 } // namespace cricket |
| OLD | NEW |