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

Side by Side Diff: webrtc/api/java/jni/androidvideocapturer_jni.cc

Issue 2017443003: Implement timestamp translation/filter in VideoCapturer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add missing include of math.h. Created 4 years, 6 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 | « webrtc/BUILD.gn ('k') | webrtc/base/BUILD.gn » ('j') | 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 if (!capturer_) { 179 if (!capturer_) {
180 LOG(LS_WARNING) << "OnMemoryBufferFrame() called for closed capturer."; 180 LOG(LS_WARNING) << "OnMemoryBufferFrame() called for closed capturer.";
181 return; 181 return;
182 } 182 }
183 int adapted_width; 183 int adapted_width;
184 int adapted_height; 184 int adapted_height;
185 int crop_width; 185 int crop_width;
186 int crop_height; 186 int crop_height;
187 int crop_x; 187 int crop_x;
188 int crop_y; 188 int crop_y;
189 int64_t translated_camera_time_us;
189 190
190 if (!capturer_->AdaptFrame(width, height, timestamp_ns, 191 if (!capturer_->AdaptFrame(width, height,
192 timestamp_ns / rtc::kNumNanosecsPerMicrosec,
193 rtc::TimeMicros(),
191 &adapted_width, &adapted_height, 194 &adapted_width, &adapted_height,
192 &crop_width, &crop_height, &crop_x, &crop_y)) { 195 &crop_width, &crop_height, &crop_x, &crop_y,
196 &translated_camera_time_us)) {
193 return; 197 return;
194 } 198 }
195 199
196 int rotated_width = crop_width; 200 int rotated_width = crop_width;
197 int rotated_height = crop_height; 201 int rotated_height = crop_height;
198 202
199 if (capturer_->apply_rotation() && (rotation == 90 || rotation == 270)) { 203 if (capturer_->apply_rotation() && (rotation == 90 || rotation == 270)) {
200 std::swap(adapted_width, adapted_height); 204 std::swap(adapted_width, adapted_height);
201 std::swap(rotated_width, rotated_height); 205 std::swap(rotated_width, rotated_height);
202 } 206 }
(...skipping 18 matching lines...) Expand all
221 buffer->MutableDataU(), buffer->StrideU(), 225 buffer->MutableDataU(), buffer->StrideU(),
222 crop_width, crop_height, static_cast<libyuv::RotationMode>( 226 crop_width, crop_height, static_cast<libyuv::RotationMode>(
223 capturer_->apply_rotation() ? rotation : 0)); 227 capturer_->apply_rotation() ? rotation : 0));
224 228
225 if (adapted_width != buffer->width() || adapted_height != buffer->height()) { 229 if (adapted_width != buffer->width() || adapted_height != buffer->height()) {
226 rtc::scoped_refptr<webrtc::I420Buffer> scaled_buffer( 230 rtc::scoped_refptr<webrtc::I420Buffer> scaled_buffer(
227 post_scale_pool_.CreateBuffer(adapted_width, adapted_height)); 231 post_scale_pool_.CreateBuffer(adapted_width, adapted_height));
228 scaled_buffer->ScaleFrom(buffer); 232 scaled_buffer->ScaleFrom(buffer);
229 buffer = scaled_buffer; 233 buffer = scaled_buffer;
230 } 234 }
231 // TODO(nisse): Use microsecond time instead.
232 capturer_->OnFrame(cricket::WebRtcVideoFrame( 235 capturer_->OnFrame(cricket::WebRtcVideoFrame(
233 buffer, timestamp_ns, 236 buffer,
234 capturer_->apply_rotation() 237 capturer_->apply_rotation()
235 ? webrtc::kVideoRotation_0 238 ? webrtc::kVideoRotation_0
236 : static_cast<webrtc::VideoRotation>(rotation)), 239 : static_cast<webrtc::VideoRotation>(rotation),
240 translated_camera_time_us),
237 width, height); 241 width, height);
238 } 242 }
239 243
240 void AndroidVideoCapturerJni::OnTextureFrame(int width, 244 void AndroidVideoCapturerJni::OnTextureFrame(int width,
241 int height, 245 int height,
242 int rotation, 246 int rotation,
243 int64_t timestamp_ns, 247 int64_t timestamp_ns,
244 const NativeHandleImpl& handle) { 248 const NativeHandleImpl& handle) {
245 RTC_DCHECK(rotation == 0 || rotation == 90 || rotation == 180 || 249 RTC_DCHECK(rotation == 0 || rotation == 90 || rotation == 180 ||
246 rotation == 270); 250 rotation == 270);
247 rtc::CritScope cs(&capturer_lock_); 251 rtc::CritScope cs(&capturer_lock_);
248 if (!capturer_) { 252 if (!capturer_) {
249 LOG(LS_WARNING) << "OnTextureFrame() called for closed capturer."; 253 LOG(LS_WARNING) << "OnTextureFrame() called for closed capturer.";
250 surface_texture_helper_->ReturnTextureFrame(); 254 surface_texture_helper_->ReturnTextureFrame();
251 return; 255 return;
252 } 256 }
253 int adapted_width; 257 int adapted_width;
254 int adapted_height; 258 int adapted_height;
255 int crop_width; 259 int crop_width;
256 int crop_height; 260 int crop_height;
257 int crop_x; 261 int crop_x;
258 int crop_y; 262 int crop_y;
263 int64_t translated_camera_time_us;
259 264
260 if (!capturer_->AdaptFrame(width, height, timestamp_ns, 265 if (!capturer_->AdaptFrame(width, height,
266 timestamp_ns / rtc::kNumNanosecsPerMicrosec,
267 rtc::TimeMicros(),
261 &adapted_width, &adapted_height, 268 &adapted_width, &adapted_height,
262 &crop_width, &crop_height, &crop_x, &crop_y)) { 269 &crop_width, &crop_height, &crop_x, &crop_y,
270 &translated_camera_time_us)) {
263 surface_texture_helper_->ReturnTextureFrame(); 271 surface_texture_helper_->ReturnTextureFrame();
264 return; 272 return;
265 } 273 }
266 274
267 Matrix matrix = handle.sampling_matrix; 275 Matrix matrix = handle.sampling_matrix;
268 276
269 matrix.Crop(crop_width / static_cast<float>(width), 277 matrix.Crop(crop_width / static_cast<float>(width),
270 crop_height / static_cast<float>(height), 278 crop_height / static_cast<float>(height),
271 crop_x / static_cast<float>(width), 279 crop_x / static_cast<float>(width),
272 crop_y / static_cast<float>(height)); 280 crop_y / static_cast<float>(height));
273 281
274 if (capturer_->apply_rotation()) { 282 if (capturer_->apply_rotation()) {
275 if (rotation == webrtc::kVideoRotation_90 || 283 if (rotation == webrtc::kVideoRotation_90 ||
276 rotation == webrtc::kVideoRotation_270) { 284 rotation == webrtc::kVideoRotation_270) {
277 std::swap(adapted_width, adapted_height); 285 std::swap(adapted_width, adapted_height);
278 } 286 }
279 matrix.Rotate(static_cast<webrtc::VideoRotation>(rotation)); 287 matrix.Rotate(static_cast<webrtc::VideoRotation>(rotation));
280 } 288 }
281 289
282 // TODO(nisse): Use microsecond time instead.
283 capturer_->OnFrame( 290 capturer_->OnFrame(
284 cricket::WebRtcVideoFrame( 291 cricket::WebRtcVideoFrame(
285 surface_texture_helper_->CreateTextureFrame( 292 surface_texture_helper_->CreateTextureFrame(
286 adapted_width, adapted_height, 293 adapted_width, adapted_height,
287 NativeHandleImpl(handle.oes_texture_id, matrix)), 294 NativeHandleImpl(handle.oes_texture_id, matrix)),
288 timestamp_ns, capturer_->apply_rotation() 295 capturer_->apply_rotation()
289 ? webrtc::kVideoRotation_0 296 ? webrtc::kVideoRotation_0
290 : static_cast<webrtc::VideoRotation>(rotation)), 297 : static_cast<webrtc::VideoRotation>(rotation),
298 translated_camera_time_us),
291 width, height); 299 width, height);
292 } 300 }
293 301
294 void AndroidVideoCapturerJni::OnOutputFormatRequest(int width, 302 void AndroidVideoCapturerJni::OnOutputFormatRequest(int width,
295 int height, 303 int height,
296 int fps) { 304 int fps) {
297 AsyncCapturerInvoke(RTC_FROM_HERE, 305 AsyncCapturerInvoke(RTC_FROM_HERE,
298 &webrtc::AndroidVideoCapturer::OnOutputFormatRequest, 306 &webrtc::AndroidVideoCapturer::OnOutputFormatRequest,
299 width, height, fps); 307 width, height, fps);
300 } 308 }
(...skipping 30 matching lines...) Expand all
331 339
332 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) 340 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest)
333 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, 341 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height,
334 jint j_fps) { 342 jint j_fps) {
335 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; 343 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest";
336 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( 344 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest(
337 j_width, j_height, j_fps); 345 j_width, j_height, j_fps);
338 } 346 }
339 347
340 } // namespace webrtc_jni 348 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « webrtc/BUILD.gn ('k') | webrtc/base/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698