OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 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 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 return; | 755 return; |
756 } | 756 } |
757 | 757 |
758 int rotation = getFrameOrientation(); | 758 int rotation = getFrameOrientation(); |
759 if (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT) { | 759 if (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT) { |
760 // Undo the mirror that the OS "helps" us with. | 760 // Undo the mirror that the OS "helps" us with. |
761 // http://developer.android.com/reference/android/hardware/Camera.html#set
DisplayOrientation(int) | 761 // http://developer.android.com/reference/android/hardware/Camera.html#set
DisplayOrientation(int) |
762 transformMatrix = | 762 transformMatrix = |
763 RendererCommon.multiplyMatrices(transformMatrix, RendererCommon.horizo
ntalFlipMatrix()); | 763 RendererCommon.multiplyMatrices(transformMatrix, RendererCommon.horizo
ntalFlipMatrix()); |
764 } | 764 } |
765 transformMatrix = RendererCommon.rotateTextureMatrix(transformMatrix, rotati
on); | 765 cameraStatistics.addPendingFrame(timestampNs); |
766 | 766 |
767 final int rotatedWidth = (rotation % 180 == 0) ? captureFormat.width : captu
reFormat.height; | 767 frameObserver.onTextureFrameCaptured(captureFormat.width, captureFormat.heig
ht, oesTextureId, |
768 final int rotatedHeight = (rotation % 180 == 0) ? captureFormat.height : cap
tureFormat.width; | 768 transformMatrix, rotation, timestampNs); |
769 cameraStatistics.addPendingFrame(timestampNs); | |
770 frameObserver.onTextureFrameCaptured(rotatedWidth, rotatedHeight, oesTexture
Id, | |
771 transformMatrix, timestampNs); | |
772 } | 769 } |
773 | 770 |
774 // Class used for allocating and bookkeeping video frames. All buffers are | 771 // Class used for allocating and bookkeeping video frames. All buffers are |
775 // direct allocated so that they can be directly used from native code. This c
lass is | 772 // direct allocated so that they can be directly used from native code. This c
lass is |
776 // not thread-safe, and enforces single thread use. | 773 // not thread-safe, and enforces single thread use. |
777 private static class FramePool { | 774 private static class FramePool { |
778 // Thread that all calls should be made on. | 775 // Thread that all calls should be made on. |
779 private final Thread thread; | 776 private final Thread thread; |
780 // Arbitrary queue depth. Higher number means more memory allocated & held, | 777 // Arbitrary queue depth. Higher number means more memory allocated & held, |
781 // lower number means more sensitivity to processing time in the client (and | 778 // lower number means more sensitivity to processing time in the client (and |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 abstract void onCapturerStarted(boolean success); | 884 abstract void onCapturerStarted(boolean success); |
888 | 885 |
889 // Delivers a captured frame. Called on a Java thread owned by | 886 // Delivers a captured frame. Called on a Java thread owned by |
890 // VideoCapturerAndroid. | 887 // VideoCapturerAndroid. |
891 abstract void onByteBufferFrameCaptured(byte[] data, int length, int width,
int height, | 888 abstract void onByteBufferFrameCaptured(byte[] data, int length, int width,
int height, |
892 int rotation, long timeStamp); | 889 int rotation, long timeStamp); |
893 | 890 |
894 // Delivers a captured frame in a texture with id |oesTextureId|. Called on
a Java thread | 891 // Delivers a captured frame in a texture with id |oesTextureId|. Called on
a Java thread |
895 // owned by VideoCapturerAndroid. | 892 // owned by VideoCapturerAndroid. |
896 abstract void onTextureFrameCaptured( | 893 abstract void onTextureFrameCaptured( |
897 int width, int height, int oesTextureId, float[] transformMatrix, long t
imestamp); | 894 int width, int height, int oesTextureId, float[] transformMatrix, int ro
tation, |
| 895 long timestamp); |
898 | 896 |
899 // Requests an output format from the video capturer. Captured frames | 897 // Requests an output format from the video capturer. Captured frames |
900 // by the camera will be scaled/or dropped by the video capturer. | 898 // by the camera will be scaled/or dropped by the video capturer. |
901 // Called on a Java thread owned by VideoCapturerAndroid. | 899 // Called on a Java thread owned by VideoCapturerAndroid. |
902 abstract void onOutputFormatRequest(int width, int height, int framerate); | 900 abstract void onOutputFormatRequest(int width, int height, int framerate); |
903 } | 901 } |
904 | 902 |
905 // An implementation of CapturerObserver that forwards all calls from | 903 // An implementation of CapturerObserver that forwards all calls from |
906 // Java to the C layer. | 904 // Java to the C layer. |
907 static class NativeObserver implements CapturerObserver { | 905 static class NativeObserver implements CapturerObserver { |
(...skipping 10 matching lines...) Expand all Loading... |
918 | 916 |
919 @Override | 917 @Override |
920 public void onByteBufferFrameCaptured(byte[] data, int length, int width, in
t height, | 918 public void onByteBufferFrameCaptured(byte[] data, int length, int width, in
t height, |
921 int rotation, long timeStamp) { | 919 int rotation, long timeStamp) { |
922 nativeOnByteBufferFrameCaptured(nativeCapturer, data, length, width, heigh
t, rotation, | 920 nativeOnByteBufferFrameCaptured(nativeCapturer, data, length, width, heigh
t, rotation, |
923 timeStamp); | 921 timeStamp); |
924 } | 922 } |
925 | 923 |
926 @Override | 924 @Override |
927 public void onTextureFrameCaptured( | 925 public void onTextureFrameCaptured( |
928 int width, int height, int oesTextureId, float[] transformMatrix, long t
imestamp) { | 926 int width, int height, int oesTextureId, float[] transformMatrix, int ro
tation, |
| 927 long timestamp) { |
929 nativeOnTextureFrameCaptured(nativeCapturer, width, height, oesTextureId,
transformMatrix, | 928 nativeOnTextureFrameCaptured(nativeCapturer, width, height, oesTextureId,
transformMatrix, |
930 timestamp); | 929 rotation, timestamp); |
931 } | 930 } |
932 | 931 |
933 @Override | 932 @Override |
934 public void onOutputFormatRequest(int width, int height, int framerate) { | 933 public void onOutputFormatRequest(int width, int height, int framerate) { |
935 nativeOnOutputFormatRequest(nativeCapturer, width, height, framerate); | 934 nativeOnOutputFormatRequest(nativeCapturer, width, height, framerate); |
936 } | 935 } |
937 | 936 |
938 private native void nativeCapturerStarted(long nativeCapturer, | 937 private native void nativeCapturerStarted(long nativeCapturer, |
939 boolean success); | 938 boolean success); |
940 private native void nativeOnByteBufferFrameCaptured(long nativeCapturer, | 939 private native void nativeOnByteBufferFrameCaptured(long nativeCapturer, |
941 byte[] data, int length, int width, int height, int rotation, long timeS
tamp); | 940 byte[] data, int length, int width, int height, int rotation, long timeS
tamp); |
942 private native void nativeOnTextureFrameCaptured(long nativeCapturer, int wi
dth, int height, | 941 private native void nativeOnTextureFrameCaptured(long nativeCapturer, int wi
dth, int height, |
943 int oesTextureId, float[] transformMatrix, long timestamp); | 942 int oesTextureId, float[] transformMatrix, int rotation, long timestamp)
; |
944 private native void nativeOnOutputFormatRequest(long nativeCapturer, | 943 private native void nativeOnOutputFormatRequest(long nativeCapturer, |
945 int width, int height, int framerate); | 944 int width, int height, int framerate); |
946 } | 945 } |
947 | 946 |
948 private static native long nativeCreateVideoCapturer( | 947 private static native long nativeCreateVideoCapturer( |
949 VideoCapturerAndroid videoCapturer, | 948 VideoCapturerAndroid videoCapturer, |
950 SurfaceTextureHelper surfaceHelper); | 949 SurfaceTextureHelper surfaceHelper); |
951 } | 950 } |
OLD | NEW |