| 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 |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 | 757 |
| 758 void AVFoundationVideoCapturer::SetUseBackCamera(bool useBackCamera) { | 758 void AVFoundationVideoCapturer::SetUseBackCamera(bool useBackCamera) { |
| 759 _capturer.useBackCamera = useBackCamera; | 759 _capturer.useBackCamera = useBackCamera; |
| 760 } | 760 } |
| 761 | 761 |
| 762 bool AVFoundationVideoCapturer::GetUseBackCamera() const { | 762 bool AVFoundationVideoCapturer::GetUseBackCamera() const { |
| 763 return _capturer.useBackCamera; | 763 return _capturer.useBackCamera; |
| 764 } | 764 } |
| 765 | 765 |
| 766 void AVFoundationVideoCapturer::CaptureSampleBuffer( | 766 void AVFoundationVideoCapturer::CaptureSampleBuffer( |
| 767 CMSampleBufferRef sample_buffer, webrtc::VideoRotation rotation) { | 767 CMSampleBufferRef sample_buffer, VideoRotation rotation) { |
| 768 if (CMSampleBufferGetNumSamples(sample_buffer) != 1 || | 768 if (CMSampleBufferGetNumSamples(sample_buffer) != 1 || |
| 769 !CMSampleBufferIsValid(sample_buffer) || | 769 !CMSampleBufferIsValid(sample_buffer) || |
| 770 !CMSampleBufferDataIsReady(sample_buffer)) { | 770 !CMSampleBufferDataIsReady(sample_buffer)) { |
| 771 return; | 771 return; |
| 772 } | 772 } |
| 773 | 773 |
| 774 CVImageBufferRef image_buffer = CMSampleBufferGetImageBuffer(sample_buffer); | 774 CVImageBufferRef image_buffer = CMSampleBufferGetImageBuffer(sample_buffer); |
| 775 if (image_buffer == NULL) { | 775 if (image_buffer == NULL) { |
| 776 return; | 776 return; |
| 777 } | 777 } |
| 778 | 778 |
| 779 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer = | 779 const int captured_width = CVPixelBufferGetWidth(image_buffer); |
| 780 new rtc::RefCountedObject<webrtc::CoreVideoFrameBuffer>(image_buffer); | 780 const int captured_height = CVPixelBufferGetHeight(image_buffer); |
| 781 | |
| 782 const int captured_width = buffer->width(); | |
| 783 const int captured_height = buffer->height(); | |
| 784 | 781 |
| 785 int adapted_width; | 782 int adapted_width; |
| 786 int adapted_height; | 783 int adapted_height; |
| 787 int crop_width; | 784 int crop_width; |
| 788 int crop_height; | 785 int crop_height; |
| 789 int crop_x; | 786 int crop_x; |
| 790 int crop_y; | 787 int crop_y; |
| 791 int64_t translated_camera_time_us; | 788 int64_t translated_camera_time_us; |
| 792 | 789 |
| 793 if (!AdaptFrame(captured_width, captured_height, | 790 if (!AdaptFrame(captured_width, captured_height, |
| 794 rtc::TimeNanos() / rtc::kNumNanosecsPerMicrosec, | 791 rtc::TimeNanos() / rtc::kNumNanosecsPerMicrosec, |
| 795 rtc::TimeMicros(), &adapted_width, &adapted_height, | 792 rtc::TimeMicros(), &adapted_width, &adapted_height, |
| 796 &crop_width, &crop_height, &crop_x, &crop_y, | 793 &crop_width, &crop_height, &crop_x, &crop_y, |
| 797 &translated_camera_time_us)) { | 794 &translated_camera_time_us)) { |
| 798 return; | 795 return; |
| 799 } | 796 } |
| 800 | 797 |
| 801 if (adapted_width != captured_width || crop_width != captured_width || | 798 rtc::scoped_refptr<VideoFrameBuffer> buffer = |
| 802 adapted_height != captured_height || crop_height != captured_height || | 799 new rtc::RefCountedObject<CoreVideoFrameBuffer>( |
| 803 (apply_rotation() && rotation != webrtc::kVideoRotation_0)) { | 800 image_buffer, |
| 804 // TODO(magjed): Avoid converting to I420. | 801 adapted_width, adapted_height, |
| 805 rtc::scoped_refptr<webrtc::I420Buffer> scaled_buffer( | |
| 806 _buffer_pool.CreateBuffer(adapted_width, adapted_height)); | |
| 807 scaled_buffer->CropAndScaleFrom(buffer->NativeToI420Buffer(), crop_x, | |
| 808 crop_y, crop_width, crop_height); | |
| 809 if (!apply_rotation() || rotation == webrtc::kVideoRotation_0) { | |
| 810 buffer = scaled_buffer; | |
| 811 } else { | |
| 812 // Applying rotation is only supported for legacy reasons and performance | |
| 813 // is not critical here. | |
| 814 rtc::scoped_refptr<webrtc::I420Buffer> rotated_buffer( | |
| 815 (rotation == webrtc::kVideoRotation_180) | |
| 816 ? I420Buffer::Create(adapted_width, adapted_height) | |
| 817 : I420Buffer::Create(adapted_height, adapted_width)); | |
| 818 libyuv::I420Rotate( | |
| 819 scaled_buffer->DataY(), scaled_buffer->StrideY(), | |
| 820 scaled_buffer->DataU(), scaled_buffer->StrideU(), | |
| 821 scaled_buffer->DataV(), scaled_buffer->StrideV(), | |
| 822 rotated_buffer->MutableDataY(), rotated_buffer->StrideY(), | |
| 823 rotated_buffer->MutableDataU(), rotated_buffer->StrideU(), | |
| 824 rotated_buffer->MutableDataV(), rotated_buffer->StrideV(), | |
| 825 crop_width, crop_height, | 802 crop_width, crop_height, |
| 826 static_cast<libyuv::RotationMode>(rotation)); | 803 crop_x, crop_y); |
| 827 buffer = rotated_buffer; | 804 |
| 828 } | 805 // Applying rotation is only supported for legacy reasons and performance is |
| 806 // not critical here. |
| 807 if (apply_rotation() && rotation != kVideoRotation_0) { |
| 808 buffer = buffer->NativeToI420Buffer(); |
| 809 rtc::scoped_refptr<I420Buffer> rotated_buffer = |
| 810 (rotation == kVideoRotation_180) |
| 811 ? I420Buffer::Create(adapted_width, adapted_height) |
| 812 : I420Buffer::Create(adapted_height, adapted_width); |
| 813 libyuv::I420Rotate( |
| 814 buffer->DataY(), buffer->StrideY(), |
| 815 buffer->DataU(), buffer->StrideU(), |
| 816 buffer->DataV(), buffer->StrideV(), |
| 817 rotated_buffer->MutableDataY(), rotated_buffer->StrideY(), |
| 818 rotated_buffer->MutableDataU(), rotated_buffer->StrideU(), |
| 819 rotated_buffer->MutableDataV(), rotated_buffer->StrideV(), |
| 820 buffer->width(), buffer->height(), |
| 821 static_cast<libyuv::RotationMode>(rotation)); |
| 822 buffer = rotated_buffer; |
| 829 } | 823 } |
| 830 | 824 |
| 831 OnFrame(cricket::WebRtcVideoFrame(buffer, rotation, | 825 OnFrame(cricket::WebRtcVideoFrame(buffer, rotation, |
| 832 translated_camera_time_us, 0), | 826 translated_camera_time_us, 0), |
| 833 captured_width, captured_height); | 827 captured_width, captured_height); |
| 834 } | 828 } |
| 835 | 829 |
| 836 } // namespace webrtc | 830 } // namespace webrtc |
| OLD | NEW |