Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm

Issue 2611113003: AVFoundationVideoCapturer: Fix apply_rotation() logic (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 !CMSampleBufferIsValid(sample_buffer) || 124 !CMSampleBufferIsValid(sample_buffer) ||
125 !CMSampleBufferDataIsReady(sample_buffer)) { 125 !CMSampleBufferDataIsReady(sample_buffer)) {
126 return; 126 return;
127 } 127 }
128 128
129 CVImageBufferRef image_buffer = CMSampleBufferGetImageBuffer(sample_buffer); 129 CVImageBufferRef image_buffer = CMSampleBufferGetImageBuffer(sample_buffer);
130 if (image_buffer == NULL) { 130 if (image_buffer == NULL) {
131 return; 131 return;
132 } 132 }
133 133
134 const int captured_width = CVPixelBufferGetWidth(image_buffer); 134 int captured_width = CVPixelBufferGetWidth(image_buffer);
135 const int captured_height = CVPixelBufferGetHeight(image_buffer); 135 int captured_height = CVPixelBufferGetHeight(image_buffer);
136 136
137 int adapted_width; 137 int adapted_width;
138 int adapted_height; 138 int adapted_height;
139 int crop_width; 139 int crop_width;
140 int crop_height; 140 int crop_height;
141 int crop_x; 141 int crop_x;
142 int crop_y; 142 int crop_y;
143 int64_t translated_camera_time_us; 143 int64_t translated_camera_time_us;
144 144
145 if (!AdaptFrame(captured_width, captured_height, 145 if (!AdaptFrame(captured_width, captured_height,
146 rtc::TimeNanos() / rtc::kNumNanosecsPerMicrosec, 146 rtc::TimeNanos() / rtc::kNumNanosecsPerMicrosec,
147 rtc::TimeMicros(), &adapted_width, &adapted_height, 147 rtc::TimeMicros(), &adapted_width, &adapted_height,
148 &crop_width, &crop_height, &crop_x, &crop_y, 148 &crop_width, &crop_height, &crop_x, &crop_y,
149 &translated_camera_time_us)) { 149 &translated_camera_time_us)) {
150 return; 150 return;
151 } 151 }
152 152
153 rtc::scoped_refptr<VideoFrameBuffer> buffer = 153 rtc::scoped_refptr<VideoFrameBuffer> buffer =
154 new rtc::RefCountedObject<CoreVideoFrameBuffer>( 154 new rtc::RefCountedObject<CoreVideoFrameBuffer>(
155 image_buffer, 155 image_buffer,
156 adapted_width, adapted_height, 156 adapted_width, adapted_height,
157 crop_width, crop_height, 157 crop_width, crop_height,
158 crop_x, crop_y); 158 crop_x, crop_y);
159 159
160 // Applying rotation is only supported for legacy reasons and performance is 160 // Applying rotation is only supported for legacy reasons and performance is
161 // not critical here. 161 // not critical here.
162 if (apply_rotation() && rotation != kVideoRotation_0) { 162 if (apply_rotation() && rotation != kVideoRotation_0) {
163 buffer = buffer->NativeToI420Buffer(); 163 buffer = buffer->NativeToI420Buffer();
164 rtc::scoped_refptr<I420Buffer> rotated_buffer = 164 rtc::scoped_refptr<I420Buffer> rotated_buffer;
165 (rotation == kVideoRotation_180) 165 if (rotation == kVideoRotation_0 || rotation == kVideoRotation_180) {
kthelgason 2017/01/09 08:18:28 The first case can never happen due to the outer c
magjed_webrtc 2017/01/09 09:31:14 Right, and the previous code just did (rotation ==
166 ? I420Buffer::Create(adapted_width, adapted_height) 166 rotated_buffer = I420Buffer::Create(adapted_width, adapted_height);
167 : I420Buffer::Create(adapted_height, adapted_width); 167 } else {
168 // Swap width and height.
169 rotated_buffer = I420Buffer::Create(adapted_height, adapted_width);
170 std::swap(captured_width, captured_height);
171 }
168 libyuv::I420Rotate( 172 libyuv::I420Rotate(
169 buffer->DataY(), buffer->StrideY(), 173 buffer->DataY(), buffer->StrideY(),
170 buffer->DataU(), buffer->StrideU(), 174 buffer->DataU(), buffer->StrideU(),
171 buffer->DataV(), buffer->StrideV(), 175 buffer->DataV(), buffer->StrideV(),
172 rotated_buffer->MutableDataY(), rotated_buffer->StrideY(), 176 rotated_buffer->MutableDataY(), rotated_buffer->StrideY(),
173 rotated_buffer->MutableDataU(), rotated_buffer->StrideU(), 177 rotated_buffer->MutableDataU(), rotated_buffer->StrideU(),
174 rotated_buffer->MutableDataV(), rotated_buffer->StrideV(), 178 rotated_buffer->MutableDataV(), rotated_buffer->StrideV(),
175 buffer->width(), buffer->height(), 179 buffer->width(), buffer->height(),
176 static_cast<libyuv::RotationMode>(rotation)); 180 static_cast<libyuv::RotationMode>(rotation));
177 buffer = rotated_buffer; 181 buffer = rotated_buffer;
182 rotation = kVideoRotation_0;
178 } 183 }
179 184
180 OnFrame(webrtc::VideoFrame(buffer, rotation, translated_camera_time_us), 185 OnFrame(webrtc::VideoFrame(buffer, rotation, translated_camera_time_us),
181 captured_width, captured_height); 186 captured_width, captured_height);
182 } 187 }
183 188
184 } // namespace webrtc 189 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698