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

Side by Side Diff: webrtc/sdk/android/src/jni/native_handle_impl.cc

Issue 3002553002: Add support for adding VideoSinks to VideoTracks. (Closed)
Patch Set: Add documentation, fix bug. Created 3 years, 4 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
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
11 #include "webrtc/sdk/android/src/jni/native_handle_impl.h" 11 #include "webrtc/sdk/android/src/jni/native_handle_impl.h"
12 12
13 #include <memory> 13 #include <memory>
14 14
15 #include "webrtc/common_video/include/video_frame_buffer.h" 15 #include "webrtc/common_video/include/video_frame_buffer.h"
16 #include "webrtc/rtc_base/bind.h" 16 #include "webrtc/rtc_base/bind.h"
17 #include "webrtc/rtc_base/checks.h" 17 #include "webrtc/rtc_base/checks.h"
18 #include "webrtc/rtc_base/keep_ref_until_done.h" 18 #include "webrtc/rtc_base/keep_ref_until_done.h"
19 #include "webrtc/rtc_base/logging.h" 19 #include "webrtc/rtc_base/logging.h"
20 #include "webrtc/rtc_base/scoped_ref_ptr.h" 20 #include "webrtc/rtc_base/scoped_ref_ptr.h"
21 #include "webrtc/rtc_base/timeutils.h" 21 #include "webrtc/rtc_base/timeutils.h"
22 #include "webrtc/sdk/android/src/jni/classreferenceholder.h" 22 #include "webrtc/sdk/android/src/jni/classreferenceholder.h"
23 #include "webrtc/sdk/android/src/jni/jni_helpers.h" 23 #include "webrtc/sdk/android/src/jni/jni_helpers.h"
24 #include "webrtc/sdk/android/src/jni/wrapped_native_i420_buffer.h"
24 #include "webrtc/system_wrappers/include/aligned_malloc.h" 25 #include "webrtc/system_wrappers/include/aligned_malloc.h"
25 26
26 namespace webrtc_jni { 27 namespace webrtc_jni {
27 28
28 namespace { 29 namespace {
29 30
30 class AndroidVideoI420Buffer : public webrtc::I420BufferInterface { 31 class AndroidVideoI420Buffer : public webrtc::I420BufferInterface {
31 public: 32 public:
32 // Wraps an existing reference to a Java VideoBuffer. Retain will not be 33 // Wraps an existing reference to a Java VideoBuffer. Retain will not be
33 // called but release will be called when the C++ object is destroyed. 34 // called but release will be called when the C++ object is destroyed.
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 jni, j_retain_id_, j_release_id_, width, height, j_video_frame_buffer); 468 jni, j_retain_id_, j_release_id_, width, height, j_video_frame_buffer);
468 } 469 }
469 470
470 JavaVideoFrameFactory::JavaVideoFrameFactory(JNIEnv* jni) 471 JavaVideoFrameFactory::JavaVideoFrameFactory(JNIEnv* jni)
471 : j_video_frame_class_(jni, FindClass(jni, "org/webrtc/VideoFrame")) { 472 : j_video_frame_class_(jni, FindClass(jni, "org/webrtc/VideoFrame")) {
472 j_video_frame_constructor_id_ = 473 j_video_frame_constructor_id_ =
473 GetMethodID(jni, *j_video_frame_class_, "<init>", 474 GetMethodID(jni, *j_video_frame_class_, "<init>",
474 "(Lorg/webrtc/VideoFrame$Buffer;IJ)V"); 475 "(Lorg/webrtc/VideoFrame$Buffer;IJ)V");
475 } 476 }
476 477
478 static bool IsJavaVideoBuffer(
479 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer) {
480 if (buffer->type() != webrtc::VideoFrameBuffer::Type::kNative) {
481 return false;
482 }
483 AndroidVideoFrameBuffer* android_buffer =
484 static_cast<AndroidVideoFrameBuffer*>(buffer.get());
485 return android_buffer->android_type() ==
486 AndroidVideoFrameBuffer::AndroidType::kJavaBuffer;
487 }
488
477 jobject JavaVideoFrameFactory::ToJavaFrame( 489 jobject JavaVideoFrameFactory::ToJavaFrame(
478 JNIEnv* jni, 490 JNIEnv* jni,
479 const webrtc::VideoFrame& frame) const { 491 const webrtc::VideoFrame& frame) const {
480 RTC_DCHECK(frame.video_frame_buffer()->type() == 492 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer =
481 webrtc::VideoFrameBuffer::Type::kNative); 493 frame.video_frame_buffer();
482 AndroidVideoFrameBuffer* android_buffer = 494 jobject j_buffer;
483 static_cast<AndroidVideoFrameBuffer*>(frame.video_frame_buffer().get()); 495 if (IsJavaVideoBuffer(buffer)) {
484 RTC_DCHECK(android_buffer->android_type() == 496 RTC_DCHECK(buffer->type() == webrtc::VideoFrameBuffer::Type::kNative);
485 AndroidVideoFrameBuffer::AndroidType::kJavaBuffer); 497 AndroidVideoFrameBuffer* android_buffer =
486 AndroidVideoBuffer* android_video_buffer = 498 static_cast<AndroidVideoFrameBuffer*>(buffer.get());
487 static_cast<AndroidVideoBuffer*>(android_buffer); 499 RTC_DCHECK(android_buffer->android_type() ==
488 jobject buffer = android_video_buffer->video_frame_buffer(); 500 AndroidVideoFrameBuffer::AndroidType::kJavaBuffer);
501 AndroidVideoBuffer* android_video_buffer =
502 static_cast<AndroidVideoBuffer*>(android_buffer);
503 j_buffer = android_video_buffer->video_frame_buffer();
504 } else {
505 j_buffer = WrapI420Buffer(jni, buffer->ToI420());
506 }
489 return jni->NewObject( 507 return jni->NewObject(
490 *j_video_frame_class_, j_video_frame_constructor_id_, buffer, 508 *j_video_frame_class_, j_video_frame_constructor_id_, j_buffer,
491 static_cast<jint>(frame.rotation()), 509 static_cast<jint>(frame.rotation()),
492 static_cast<jlong>(frame.timestamp_us() * rtc::kNumNanosecsPerMicrosec)); 510 static_cast<jlong>(frame.timestamp_us() * rtc::kNumNanosecsPerMicrosec));
493 } 511 }
494 512
495 } // namespace webrtc_jni 513 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « webrtc/sdk/android/src/jni/classreferenceholder.cc ('k') | webrtc/sdk/android/src/jni/videotrack_jni.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698