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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 RTC_DCHECK(rotation == 0 || rotation == 90 || rotation == 180 || | 172 RTC_DCHECK(rotation == 0 || rotation == 90 || rotation == 180 || |
173 rotation == 270); | 173 rotation == 270); |
174 rtc::CritScope cs(&capturer_lock_); | 174 rtc::CritScope cs(&capturer_lock_); |
175 | 175 |
176 int adapted_width; | 176 int adapted_width; |
177 int adapted_height; | 177 int adapted_height; |
178 int crop_width; | 178 int crop_width; |
179 int crop_height; | 179 int crop_height; |
180 int crop_x; | 180 int crop_x; |
181 int crop_y; | 181 int crop_y; |
| 182 int64_t translated_camera_time_us; |
182 | 183 |
183 if (!capturer_->AdaptFrame(width, height, timestamp_ns, | 184 if (!capturer_->AdaptFrame(width, height, |
| 185 timestamp_ns / rtc::kNumNanosecsPerMicrosec, |
| 186 rtc::TimeMicros(), |
184 &adapted_width, &adapted_height, | 187 &adapted_width, &adapted_height, |
185 &crop_width, &crop_height, &crop_x, &crop_y)) { | 188 &crop_width, &crop_height, &crop_x, &crop_y, |
| 189 &translated_camera_time_us)) { |
186 return; | 190 return; |
187 } | 191 } |
188 | 192 |
189 int rotated_width = crop_width; | 193 int rotated_width = crop_width; |
190 int rotated_height = crop_height; | 194 int rotated_height = crop_height; |
191 | 195 |
192 if (capturer_->apply_rotation() && (rotation == 90 || rotation == 270)) { | 196 if (capturer_->apply_rotation() && (rotation == 90 || rotation == 270)) { |
193 std::swap(adapted_width, adapted_height); | 197 std::swap(adapted_width, adapted_height); |
194 std::swap(rotated_width, rotated_height); | 198 std::swap(rotated_width, rotated_height); |
195 } | 199 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 scaled->MutableDataY(), scaled->StrideY(), | 232 scaled->MutableDataY(), scaled->StrideY(), |
229 scaled->MutableDataU(), scaled->StrideU(), | 233 scaled->MutableDataU(), scaled->StrideU(), |
230 scaled->MutableDataV(), scaled->StrideV(), | 234 scaled->MutableDataV(), scaled->StrideV(), |
231 adapted_width, adapted_height, | 235 adapted_width, adapted_height, |
232 libyuv::kFilterBox) < 0) { | 236 libyuv::kFilterBox) < 0) { |
233 LOG(LS_WARNING) << "I420Scale failed"; | 237 LOG(LS_WARNING) << "I420Scale failed"; |
234 return; | 238 return; |
235 } | 239 } |
236 buffer = scaled; | 240 buffer = scaled; |
237 } | 241 } |
238 // TODO(nisse): Use microsecond time instead. | |
239 capturer_->OnFrame(cricket::WebRtcVideoFrame( | 242 capturer_->OnFrame(cricket::WebRtcVideoFrame( |
240 buffer, timestamp_ns, | 243 buffer, |
241 capturer_->apply_rotation() | 244 capturer_->apply_rotation() |
242 ? webrtc::kVideoRotation_0 | 245 ? webrtc::kVideoRotation_0 |
243 : static_cast<webrtc::VideoRotation>(rotation)), | 246 : static_cast<webrtc::VideoRotation>(rotation), |
| 247 translated_camera_time_us), |
244 width, height); | 248 width, height); |
245 } | 249 } |
246 | 250 |
247 void AndroidVideoCapturerJni::OnTextureFrame(int width, | 251 void AndroidVideoCapturerJni::OnTextureFrame(int width, |
248 int height, | 252 int height, |
249 int rotation, | 253 int rotation, |
250 int64_t timestamp_ns, | 254 int64_t timestamp_ns, |
251 const NativeHandleImpl& handle) { | 255 const NativeHandleImpl& handle) { |
252 RTC_DCHECK(rotation == 0 || rotation == 90 || rotation == 180 || | 256 RTC_DCHECK(rotation == 0 || rotation == 90 || rotation == 180 || |
253 rotation == 270); | 257 rotation == 270); |
254 rtc::CritScope cs(&capturer_lock_); | 258 rtc::CritScope cs(&capturer_lock_); |
255 | 259 |
256 int adapted_width; | 260 int adapted_width; |
257 int adapted_height; | 261 int adapted_height; |
258 int crop_width; | 262 int crop_width; |
259 int crop_height; | 263 int crop_height; |
260 int crop_x; | 264 int crop_x; |
261 int crop_y; | 265 int crop_y; |
| 266 int64_t translated_camera_time_us; |
262 | 267 |
263 if (!capturer_->AdaptFrame(width, height, timestamp_ns, | 268 if (!capturer_->AdaptFrame(width, height, |
| 269 timestamp_ns / rtc::kNumNanosecsPerMicrosec, |
| 270 rtc::TimeMicros(), |
264 &adapted_width, &adapted_height, | 271 &adapted_width, &adapted_height, |
265 &crop_width, &crop_height, &crop_x, &crop_y)) { | 272 &crop_width, &crop_height, &crop_x, &crop_y, |
| 273 &translated_camera_time_us)) { |
266 surface_texture_helper_->ReturnTextureFrame(); | 274 surface_texture_helper_->ReturnTextureFrame(); |
267 return; | 275 return; |
268 } | 276 } |
269 | 277 |
270 Matrix matrix = handle.sampling_matrix; | 278 Matrix matrix = handle.sampling_matrix; |
271 | 279 |
272 matrix.Crop(crop_width / static_cast<float>(width), | 280 matrix.Crop(crop_width / static_cast<float>(width), |
273 crop_height / static_cast<float>(height), | 281 crop_height / static_cast<float>(height), |
274 crop_x / static_cast<float>(width), | 282 crop_x / static_cast<float>(width), |
275 crop_y / static_cast<float>(height)); | 283 crop_y / static_cast<float>(height)); |
276 | 284 |
277 if (capturer_->apply_rotation()) { | 285 if (capturer_->apply_rotation()) { |
278 if (rotation == webrtc::kVideoRotation_90 || | 286 if (rotation == webrtc::kVideoRotation_90 || |
279 rotation == webrtc::kVideoRotation_270) { | 287 rotation == webrtc::kVideoRotation_270) { |
280 std::swap(adapted_width, adapted_height); | 288 std::swap(adapted_width, adapted_height); |
281 } | 289 } |
282 matrix.Rotate(static_cast<webrtc::VideoRotation>(rotation)); | 290 matrix.Rotate(static_cast<webrtc::VideoRotation>(rotation)); |
283 } | 291 } |
284 | 292 |
285 // TODO(nisse): Use microsecond time instead. | |
286 capturer_->OnFrame( | 293 capturer_->OnFrame( |
287 cricket::WebRtcVideoFrame( | 294 cricket::WebRtcVideoFrame( |
288 surface_texture_helper_->CreateTextureFrame( | 295 surface_texture_helper_->CreateTextureFrame( |
289 adapted_width, adapted_height, | 296 adapted_width, adapted_height, |
290 NativeHandleImpl(handle.oes_texture_id, matrix)), | 297 NativeHandleImpl(handle.oes_texture_id, matrix)), |
291 timestamp_ns, capturer_->apply_rotation() | 298 capturer_->apply_rotation() |
292 ? webrtc::kVideoRotation_0 | 299 ? webrtc::kVideoRotation_0 |
293 : static_cast<webrtc::VideoRotation>(rotation)), | 300 : static_cast<webrtc::VideoRotation>(rotation), |
| 301 translated_camera_time_us), |
294 width, height); | 302 width, height); |
295 } | 303 } |
296 | 304 |
297 void AndroidVideoCapturerJni::OnOutputFormatRequest(int width, | 305 void AndroidVideoCapturerJni::OnOutputFormatRequest(int width, |
298 int height, | 306 int height, |
299 int fps) { | 307 int fps) { |
300 AsyncCapturerInvoke("OnOutputFormatRequest", | 308 AsyncCapturerInvoke("OnOutputFormatRequest", |
301 &webrtc::AndroidVideoCapturer::OnOutputFormatRequest, | 309 &webrtc::AndroidVideoCapturer::OnOutputFormatRequest, |
302 width, height, fps); | 310 width, height, fps); |
303 } | 311 } |
(...skipping 30 matching lines...) Expand all Loading... |
334 | 342 |
335 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) | 343 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) |
336 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, | 344 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, |
337 jint j_fps) { | 345 jint j_fps) { |
338 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; | 346 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; |
339 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( | 347 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( |
340 j_width, j_height, j_fps); | 348 j_width, j_height, j_fps); |
341 } | 349 } |
342 | 350 |
343 } // namespace webrtc_jni | 351 } // namespace webrtc_jni |
OLD | NEW |