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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 EglBase.Context sharedContext) { | 352 EglBase.Context sharedContext) { |
353 Logging.d(TAG, "VideoCapturerAndroid"); | 353 Logging.d(TAG, "VideoCapturerAndroid"); |
354 this.id = cameraId; | 354 this.id = cameraId; |
355 this.eventsHandler = eventsHandler; | 355 this.eventsHandler = eventsHandler; |
356 cameraThread = new HandlerThread(TAG); | 356 cameraThread = new HandlerThread(TAG); |
357 cameraThread.start(); | 357 cameraThread.start(); |
358 cameraThreadHandler = new Handler(cameraThread.getLooper()); | 358 cameraThreadHandler = new Handler(cameraThread.getLooper()); |
359 videoBuffers = new FramePool(cameraThread); | 359 videoBuffers = new FramePool(cameraThread); |
360 isCapturingToTexture = (sharedContext != null); | 360 isCapturingToTexture = (sharedContext != null); |
361 cameraStatistics = | 361 cameraStatistics = |
362 new CameraStatistics(isCapturingToTexture ? 1 : videoBuffers.numCaptureB
uffers); | 362 new CameraStatistics(isCapturingToTexture ? 1 : FramePool.NUMBER_OF_CAPT
URE_BUFFERS); |
363 surfaceHelper = SurfaceTextureHelper.create(sharedContext, cameraThreadHandl
er); | 363 surfaceHelper = SurfaceTextureHelper.create(sharedContext, cameraThreadHandl
er); |
364 if (isCapturingToTexture) { | 364 if (isCapturingToTexture) { |
365 surfaceHelper.setListener(this); | 365 surfaceHelper.setListener(this); |
366 } | 366 } |
367 } | 367 } |
368 | 368 |
369 private void checkIsOnCameraThread() { | 369 private void checkIsOnCameraThread() { |
370 if (Thread.currentThread() != cameraThread) { | 370 if (Thread.currentThread() != cameraThread) { |
371 throw new IllegalStateException("Wrong thread"); | 371 throw new IllegalStateException("Wrong thread"); |
372 } | 372 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 final int[] range = CameraEnumerationAndroid.getFramerateRange(parameters, f
ramerate * 1000); | 528 final int[] range = CameraEnumerationAndroid.getFramerateRange(parameters, f
ramerate * 1000); |
529 final android.hardware.Camera.Size previewSize = | 529 final android.hardware.Camera.Size previewSize = |
530 CameraEnumerationAndroid.getClosestSupportedSize( | 530 CameraEnumerationAndroid.getClosestSupportedSize( |
531 parameters.getSupportedPreviewSizes(), width, height); | 531 parameters.getSupportedPreviewSizes(), width, height); |
532 final CaptureFormat captureFormat = new CaptureFormat( | 532 final CaptureFormat captureFormat = new CaptureFormat( |
533 previewSize.width, previewSize.height, | 533 previewSize.width, previewSize.height, |
534 range[android.hardware.Camera.Parameters.PREVIEW_FPS_MIN_INDEX], | 534 range[android.hardware.Camera.Parameters.PREVIEW_FPS_MIN_INDEX], |
535 range[android.hardware.Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); | 535 range[android.hardware.Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); |
536 | 536 |
537 // Check if we are already using this capture format, then we don't need to
do anything. | 537 // Check if we are already using this capture format, then we don't need to
do anything. |
538 if (captureFormat.equals(this.captureFormat)) { | 538 if (captureFormat.isSameFormat(this.captureFormat)) { |
539 return; | 539 return; |
540 } | 540 } |
541 | 541 |
542 // Update camera parameters. | 542 // Update camera parameters. |
543 Logging.d(TAG, "isVideoStabilizationSupported: " + | 543 Logging.d(TAG, "isVideoStabilizationSupported: " + |
544 parameters.isVideoStabilizationSupported()); | 544 parameters.isVideoStabilizationSupported()); |
545 if (parameters.isVideoStabilizationSupported()) { | 545 if (parameters.isVideoStabilizationSupported()) { |
546 parameters.setVideoStabilization(true); | 546 parameters.setVideoStabilization(true); |
547 } | 547 } |
548 // Note: setRecordingHint(true) actually decrease frame rate on N5. | 548 // Note: setRecordingHint(true) actually decrease frame rate on N5. |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 | 770 |
771 // Class used for allocating and bookkeeping video frames. All buffers are | 771 // Class used for allocating and bookkeeping video frames. All buffers are |
772 // 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 |
773 // not thread-safe, and enforces single thread use. | 773 // not thread-safe, and enforces single thread use. |
774 private static class FramePool { | 774 private static class FramePool { |
775 // Thread that all calls should be made on. | 775 // Thread that all calls should be made on. |
776 private final Thread thread; | 776 private final Thread thread; |
777 // Arbitrary queue depth. Higher number means more memory allocated & held, | 777 // Arbitrary queue depth. Higher number means more memory allocated & held, |
778 // 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 |
779 // potentially stalling the capturer if it runs out of buffers to write to). | 779 // potentially stalling the capturer if it runs out of buffers to write to). |
780 public static final int numCaptureBuffers = 3; | 780 public static final int NUMBER_OF_CAPTURE_BUFFERS = 3; |
781 // This container tracks the buffers added as camera callback buffers. It is
needed for finding | 781 // This container tracks the buffers added as camera callback buffers. It is
needed for finding |
782 // the corresponding ByteBuffer given a byte[]. | 782 // the corresponding ByteBuffer given a byte[]. |
783 private final Map<byte[], ByteBuffer> queuedBuffers = new IdentityHashMap<by
te[], ByteBuffer>(); | 783 private final Map<byte[], ByteBuffer> queuedBuffers = new IdentityHashMap<by
te[], ByteBuffer>(); |
784 // This container tracks the frames that have been sent but not returned. It
is needed for | 784 // This container tracks the frames that have been sent but not returned. It
is needed for |
785 // keeping the buffers alive and for finding the corresponding ByteBuffer gi
ven a timestamp. | 785 // keeping the buffers alive and for finding the corresponding ByteBuffer gi
ven a timestamp. |
786 private final Map<Long, ByteBuffer> pendingBuffers = new HashMap<Long, ByteB
uffer>(); | 786 private final Map<Long, ByteBuffer> pendingBuffers = new HashMap<Long, ByteB
uffer>(); |
787 private int frameSize = 0; | 787 private int frameSize = 0; |
788 private android.hardware.Camera camera; | 788 private android.hardware.Camera camera; |
789 | 789 |
790 public FramePool(Thread thread) { | 790 public FramePool(Thread thread) { |
791 this.thread = thread; | 791 this.thread = thread; |
792 } | 792 } |
793 | 793 |
794 private void checkIsOnValidThread() { | 794 private void checkIsOnValidThread() { |
795 if (Thread.currentThread() != thread) { | 795 if (Thread.currentThread() != thread) { |
796 throw new IllegalStateException("Wrong thread"); | 796 throw new IllegalStateException("Wrong thread"); |
797 } | 797 } |
798 } | 798 } |
799 | 799 |
800 // Discards previous queued buffers and adds new callback buffers to camera. | 800 // Discards previous queued buffers and adds new callback buffers to camera. |
801 public void queueCameraBuffers(int frameSize, android.hardware.Camera camera
) { | 801 public void queueCameraBuffers(int frameSize, android.hardware.Camera camera
) { |
802 checkIsOnValidThread(); | 802 checkIsOnValidThread(); |
803 this.camera = camera; | 803 this.camera = camera; |
804 this.frameSize = frameSize; | 804 this.frameSize = frameSize; |
805 | 805 |
806 queuedBuffers.clear(); | 806 queuedBuffers.clear(); |
807 for (int i = 0; i < numCaptureBuffers; ++i) { | 807 for (int i = 0; i < NUMBER_OF_CAPTURE_BUFFERS; ++i) { |
808 final ByteBuffer buffer = ByteBuffer.allocateDirect(frameSize); | 808 final ByteBuffer buffer = ByteBuffer.allocateDirect(frameSize); |
809 camera.addCallbackBuffer(buffer.array()); | 809 camera.addCallbackBuffer(buffer.array()); |
810 queuedBuffers.put(buffer.array(), buffer); | 810 queuedBuffers.put(buffer.array(), buffer); |
811 } | 811 } |
812 Logging.d(TAG, "queueCameraBuffers enqueued " + numCaptureBuffers | 812 Logging.d(TAG, "queueCameraBuffers enqueued " + NUMBER_OF_CAPTURE_BUFFERS |
813 + " buffers of size " + frameSize + "."); | 813 + " buffers of size " + frameSize + "."); |
814 } | 814 } |
815 | 815 |
816 public void stopReturnBuffersToCamera() { | 816 public void stopReturnBuffersToCamera() { |
817 checkIsOnValidThread(); | 817 checkIsOnValidThread(); |
818 this.camera = null; | 818 this.camera = null; |
819 queuedBuffers.clear(); | 819 queuedBuffers.clear(); |
820 // Frames in |pendingBuffers| need to be kept alive until they are returne
d. | 820 // Frames in |pendingBuffers| need to be kept alive until they are returne
d. |
821 } | 821 } |
822 | 822 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 private native void nativeOnTextureFrameCaptured(long nativeCapturer, int wi
dth, int height, | 941 private native void nativeOnTextureFrameCaptured(long nativeCapturer, int wi
dth, int height, |
942 int oesTextureId, float[] transformMatrix, int rotation, long timestamp)
; | 942 int oesTextureId, float[] transformMatrix, int rotation, long timestamp)
; |
943 private native void nativeOnOutputFormatRequest(long nativeCapturer, | 943 private native void nativeOnOutputFormatRequest(long nativeCapturer, |
944 int width, int height, int framerate); | 944 int width, int height, int framerate); |
945 } | 945 } |
946 | 946 |
947 private static native long nativeCreateVideoCapturer( | 947 private static native long nativeCreateVideoCapturer( |
948 VideoCapturerAndroid videoCapturer, | 948 VideoCapturerAndroid videoCapturer, |
949 SurfaceTextureHelper surfaceHelper); | 949 SurfaceTextureHelper surfaceHelper); |
950 } | 950 } |
OLD | NEW |