OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 | 733 |
734 // Wrapper dispatching webrtc::VideoRendererInterface to a Java VideoRenderer | 734 // Wrapper dispatching webrtc::VideoRendererInterface to a Java VideoRenderer |
735 // instance. | 735 // instance. |
736 class JavaVideoRendererWrapper : public VideoRendererInterface { | 736 class JavaVideoRendererWrapper : public VideoRendererInterface { |
737 public: | 737 public: |
738 JavaVideoRendererWrapper(JNIEnv* jni, jobject j_callbacks) | 738 JavaVideoRendererWrapper(JNIEnv* jni, jobject j_callbacks) |
739 : j_callbacks_(jni, j_callbacks), | 739 : j_callbacks_(jni, j_callbacks), |
740 j_render_frame_id_(GetMethodID( | 740 j_render_frame_id_(GetMethodID( |
741 jni, GetObjectClass(jni, j_callbacks), "renderFrame", | 741 jni, GetObjectClass(jni, j_callbacks), "renderFrame", |
742 "(Lorg/webrtc/VideoRenderer$I420Frame;)V")), | 742 "(Lorg/webrtc/VideoRenderer$I420Frame;)V")), |
743 j_can_apply_rotation_id_(GetMethodID( | |
744 jni, GetObjectClass(jni, j_callbacks), | |
745 "canApplyRotation", "()Z")), | |
746 j_frame_class_(jni, | 743 j_frame_class_(jni, |
747 FindClass(jni, "org/webrtc/VideoRenderer$I420Frame")), | 744 FindClass(jni, "org/webrtc/VideoRenderer$I420Frame")), |
748 j_i420_frame_ctor_id_(GetMethodID( | 745 j_i420_frame_ctor_id_(GetMethodID( |
749 jni, *j_frame_class_, "<init>", "(III[I[Ljava/nio/ByteBuffer;)V")), | 746 jni, *j_frame_class_, "<init>", "(III[I[Ljava/nio/ByteBuffer;)V")), |
750 j_texture_frame_ctor_id_(GetMethodID( | 747 j_texture_frame_ctor_id_(GetMethodID( |
751 jni, *j_frame_class_, "<init>", | 748 jni, *j_frame_class_, "<init>", |
752 "(IIILjava/lang/Object;I)V")), | 749 "(IIILjava/lang/Object;I)V")), |
753 j_byte_buffer_class_(jni, FindClass(jni, "java/nio/ByteBuffer")), | 750 j_byte_buffer_class_(jni, FindClass(jni, "java/nio/ByteBuffer")) { |
754 can_apply_rotation_set_(false), | |
755 can_apply_rotation_(false) { | |
756 CHECK_EXCEPTION(jni); | 751 CHECK_EXCEPTION(jni); |
757 } | 752 } |
758 | 753 |
759 virtual ~JavaVideoRendererWrapper() {} | 754 virtual ~JavaVideoRendererWrapper() {} |
760 | 755 |
761 void RenderFrame(const cricket::VideoFrame* video_frame) override { | 756 void RenderFrame(const cricket::VideoFrame* video_frame) override { |
762 ScopedLocalRefFrame local_ref_frame(jni()); | 757 ScopedLocalRefFrame local_ref_frame(jni()); |
763 | 758 jobject j_frame = (video_frame->GetNativeHandle() != nullptr) |
764 // Calling CanApplyRotation here to ensure can_apply_rotation_ is set. | 759 ? CricketToJavaTextureFrame(video_frame) |
765 CanApplyRotation(); | 760 : CricketToJavaI420Frame(video_frame); |
766 | 761 jni()->CallVoidMethod(*j_callbacks_, j_render_frame_id_, j_frame); |
767 const cricket::VideoFrame* frame = | 762 CHECK_EXCEPTION(jni()); |
768 can_apply_rotation_ ? video_frame | |
769 : video_frame->GetCopyWithRotationApplied(); | |
770 if (frame->GetNativeHandle() != NULL) { | |
771 jobject j_frame = CricketToJavaTextureFrame(frame); | |
772 jni()->CallVoidMethod(*j_callbacks_, j_render_frame_id_, j_frame); | |
773 CHECK_EXCEPTION(jni()); | |
774 } else { | |
775 jobject j_frame = CricketToJavaI420Frame(frame); | |
776 jni()->CallVoidMethod(*j_callbacks_, j_render_frame_id_, j_frame); | |
777 CHECK_EXCEPTION(jni()); | |
778 } | |
779 } | 763 } |
780 | 764 |
781 // TODO(guoweis): Report that rotation is supported as RenderFrame calls | 765 // TODO(guoweis): Report that rotation is supported as RenderFrame calls |
782 // GetCopyWithRotationApplied. | 766 // GetCopyWithRotationApplied. |
783 virtual bool CanApplyRotation() override { | 767 virtual bool CanApplyRotation() override { return true; } |
784 if (can_apply_rotation_set_) { | |
785 return can_apply_rotation_; | |
786 } | |
787 ScopedLocalRefFrame local_ref_frame(jni()); | |
788 jboolean ret = | |
789 jni()->CallBooleanMethod(*j_callbacks_, j_can_apply_rotation_id_); | |
790 CHECK_EXCEPTION(jni()); | |
791 can_apply_rotation_ = ret; | |
792 can_apply_rotation_set_ = true; | |
793 return ret; | |
794 } | |
795 | 768 |
796 private: | 769 private: |
797 // Return a VideoRenderer.I420Frame referring to the data in |frame|. | 770 // Return a VideoRenderer.I420Frame referring to the data in |frame|. |
798 jobject CricketToJavaI420Frame(const cricket::VideoFrame* frame) { | 771 jobject CricketToJavaI420Frame(const cricket::VideoFrame* frame) { |
799 jintArray strides = jni()->NewIntArray(3); | 772 jintArray strides = jni()->NewIntArray(3); |
800 jint* strides_array = jni()->GetIntArrayElements(strides, NULL); | 773 jint* strides_array = jni()->GetIntArrayElements(strides, NULL); |
801 strides_array[0] = frame->GetYPitch(); | 774 strides_array[0] = frame->GetYPitch(); |
802 strides_array[1] = frame->GetUPitch(); | 775 strides_array[1] = frame->GetUPitch(); |
803 strides_array[2] = frame->GetVPitch(); | 776 strides_array[2] = frame->GetVPitch(); |
804 jni()->ReleaseIntArrayElements(strides, strides_array, 0); | 777 jni()->ReleaseIntArrayElements(strides, strides_array, 0); |
(...skipping 27 matching lines...) Expand all Loading... |
832 static_cast<int>(frame->GetVideoRotation()), | 805 static_cast<int>(frame->GetVideoRotation()), |
833 texture_object, texture_id); | 806 texture_object, texture_id); |
834 } | 807 } |
835 | 808 |
836 JNIEnv* jni() { | 809 JNIEnv* jni() { |
837 return AttachCurrentThreadIfNeeded(); | 810 return AttachCurrentThreadIfNeeded(); |
838 } | 811 } |
839 | 812 |
840 ScopedGlobalRef<jobject> j_callbacks_; | 813 ScopedGlobalRef<jobject> j_callbacks_; |
841 jmethodID j_render_frame_id_; | 814 jmethodID j_render_frame_id_; |
842 jmethodID j_can_apply_rotation_id_; | |
843 ScopedGlobalRef<jclass> j_frame_class_; | 815 ScopedGlobalRef<jclass> j_frame_class_; |
844 jmethodID j_i420_frame_ctor_id_; | 816 jmethodID j_i420_frame_ctor_id_; |
845 jmethodID j_texture_frame_ctor_id_; | 817 jmethodID j_texture_frame_ctor_id_; |
846 ScopedGlobalRef<jclass> j_byte_buffer_class_; | 818 ScopedGlobalRef<jclass> j_byte_buffer_class_; |
847 bool can_apply_rotation_set_; | |
848 bool can_apply_rotation_; | |
849 }; | 819 }; |
850 | 820 |
851 | 821 |
852 static DataChannelInterface* ExtractNativeDC(JNIEnv* jni, jobject j_dc) { | 822 static DataChannelInterface* ExtractNativeDC(JNIEnv* jni, jobject j_dc) { |
853 jfieldID native_dc_id = GetFieldID(jni, | 823 jfieldID native_dc_id = GetFieldID(jni, |
854 GetObjectClass(jni, j_dc), "nativeDataChannel", "J"); | 824 GetObjectClass(jni, j_dc), "nativeDataChannel", "J"); |
855 jlong j_d = GetLongField(jni, j_dc, native_dc_id); | 825 jlong j_d = GetLongField(jni, j_dc, native_dc_id); |
856 return reinterpret_cast<DataChannelInterface*>(j_d); | 826 return reinterpret_cast<DataChannelInterface*>(j_d); |
857 } | 827 } |
858 | 828 |
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 } | 1677 } |
1708 | 1678 |
1709 JOW(void, VideoTrack_nativeRemoveRenderer)( | 1679 JOW(void, VideoTrack_nativeRemoveRenderer)( |
1710 JNIEnv* jni, jclass, | 1680 JNIEnv* jni, jclass, |
1711 jlong j_video_track_pointer, jlong j_renderer_pointer) { | 1681 jlong j_video_track_pointer, jlong j_renderer_pointer) { |
1712 reinterpret_cast<VideoTrackInterface*>(j_video_track_pointer)->RemoveRenderer( | 1682 reinterpret_cast<VideoTrackInterface*>(j_video_track_pointer)->RemoveRenderer( |
1713 reinterpret_cast<VideoRendererInterface*>(j_renderer_pointer)); | 1683 reinterpret_cast<VideoRendererInterface*>(j_renderer_pointer)); |
1714 } | 1684 } |
1715 | 1685 |
1716 } // namespace webrtc_jni | 1686 } // namespace webrtc_jni |
OLD | NEW |