Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 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 #include "avfoundationvideocapturer.h" | 11 #include "avfoundationvideocapturer.h" | 
| 12 | 12 | 
| 13 #import <AVFoundation/AVFoundation.h> | 13 #import <AVFoundation/AVFoundation.h> | 
| 14 | 14 | 
| 15 #import "RTCAVFoundationVideoCapturerInternal.h" | 15 #import "RTCAVFoundationVideoCapturerInternal.h" | 
| 16 #import "RTCDispatcher+Private.h" | 16 #import "RTCDispatcher+Private.h" | 
| 17 #import "WebRTC/RTCLogging.h" | 17 #import "WebRTC/RTCLogging.h" | 
| 18 | 18 | 
| 19 #include "avfoundationformatmapper.h" | 19 #include "avfoundationformatmapper.h" | 
| 20 #include "libyuv/rotate.h" | 20 #include "libyuv/rotate.h" | 
| 21 | |
| 22 #include "webrtc/api/video/video_rotation.h" | |
| 21 #include "webrtc/base/bind.h" | 23 #include "webrtc/base/bind.h" | 
| 22 #include "webrtc/base/checks.h" | 24 #include "webrtc/base/checks.h" | 
| 23 #include "webrtc/base/logging.h" | 25 #include "webrtc/base/logging.h" | 
| 24 #include "webrtc/base/thread.h" | 26 #include "webrtc/base/thread.h" | 
| 25 #include "webrtc/common_video/include/corevideo_frame_buffer.h" | 27 #include "webrtc/common_video/include/corevideo_frame_buffer.h" | 
| 26 #include "webrtc/common_video/rotation.h" | |
| 27 | 28 | 
| 28 namespace webrtc { | 29 namespace webrtc { | 
| 29 | 30 | 
| 30 enum AVFoundationVideoCapturerMessageType : uint32_t { | 31 enum AVFoundationVideoCapturerMessageType : uint32_t { | 
| 31 kMessageTypeFrame, | 32 kMessageTypeFrame, | 
| 32 }; | 33 }; | 
| 33 | 34 | 
| 34 AVFoundationVideoCapturer::AVFoundationVideoCapturer() : _capturer(nil) { | 35 AVFoundationVideoCapturer::AVFoundationVideoCapturer() : _capturer(nil) { | 
| 35 _capturer = | 36 _capturer = | 
| 36 [[RTCAVFoundationVideoCapturerInternal alloc] initWithCapturer:this]; | 37 [[RTCAVFoundationVideoCapturerInternal alloc] initWithCapturer:this]; | 
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 return; | 151 return; | 
| 151 } | 152 } | 
| 152 | 153 | 
| 153 rtc::scoped_refptr<VideoFrameBuffer> buffer = | 154 rtc::scoped_refptr<VideoFrameBuffer> buffer = | 
| 154 new rtc::RefCountedObject<CoreVideoFrameBuffer>( | 155 new rtc::RefCountedObject<CoreVideoFrameBuffer>( | 
| 155 image_buffer, | 156 image_buffer, | 
| 156 adapted_width, adapted_height, | 157 adapted_width, adapted_height, | 
| 157 crop_width, crop_height, | 158 crop_width, crop_height, | 
| 158 crop_x, crop_y); | 159 crop_x, crop_y); | 
| 159 | 160 | 
| 160 // Applying rotation is only supported for legacy reasons and performance is | 161 // Applying rotation is only supported for legacy reasons and performance is | 
| 
 
the sun
2016/12/05 22:36:29
Use I420Buffer::Rotate?
 
nisse-webrtc
2016/12/06 12:02:15
Good catch, will do.
 
nisse-webrtc
2016/12/13 15:08:02
Done.
 
 | |
| 161 // not critical here. | 162 // not critical here. | 
| 162 if (apply_rotation() && rotation != kVideoRotation_0) { | 163 if (apply_rotation() && rotation != kVideoRotation_0) { | 
| 163 buffer = buffer->NativeToI420Buffer(); | 164 buffer = buffer->NativeToI420Buffer(); | 
| 164 rtc::scoped_refptr<I420Buffer> rotated_buffer = | 165 rtc::scoped_refptr<I420Buffer> rotated_buffer = | 
| 165 (rotation == kVideoRotation_180) | 166 (rotation == kVideoRotation_180) | 
| 166 ? I420Buffer::Create(adapted_width, adapted_height) | 167 ? I420Buffer::Create(adapted_width, adapted_height) | 
| 167 : I420Buffer::Create(adapted_height, adapted_width); | 168 : I420Buffer::Create(adapted_height, adapted_width); | 
| 168 libyuv::I420Rotate( | 169 libyuv::I420Rotate( | 
| 169 buffer->DataY(), buffer->StrideY(), | 170 buffer->DataY(), buffer->StrideY(), | 
| 170 buffer->DataU(), buffer->StrideU(), | 171 buffer->DataU(), buffer->StrideU(), | 
| 171 buffer->DataV(), buffer->StrideV(), | 172 buffer->DataV(), buffer->StrideV(), | 
| 172 rotated_buffer->MutableDataY(), rotated_buffer->StrideY(), | 173 rotated_buffer->MutableDataY(), rotated_buffer->StrideY(), | 
| 173 rotated_buffer->MutableDataU(), rotated_buffer->StrideU(), | 174 rotated_buffer->MutableDataU(), rotated_buffer->StrideU(), | 
| 174 rotated_buffer->MutableDataV(), rotated_buffer->StrideV(), | 175 rotated_buffer->MutableDataV(), rotated_buffer->StrideV(), | 
| 175 buffer->width(), buffer->height(), | 176 buffer->width(), buffer->height(), | 
| 176 static_cast<libyuv::RotationMode>(rotation)); | 177 static_cast<libyuv::RotationMode>(rotation)); | 
| 177 buffer = rotated_buffer; | 178 buffer = rotated_buffer; | 
| 178 } | 179 } | 
| 179 | 180 | 
| 180 OnFrame(webrtc::VideoFrame(buffer, rotation, translated_camera_time_us), | 181 OnFrame(webrtc::VideoFrame(buffer, rotation, translated_camera_time_us), | 
| 181 captured_width, captured_height); | 182 captured_width, captured_height); | 
| 182 } | 183 } | 
| 183 | 184 | 
| 184 } // namespace webrtc | 185 } // namespace webrtc | 
| OLD | NEW |