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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 import java.util.ArrayList; | 44 import java.util.ArrayList; |
45 import java.util.HashMap; | 45 import java.util.HashMap; |
46 import java.util.HashSet; | 46 import java.util.HashSet; |
47 import java.util.IdentityHashMap; | 47 import java.util.IdentityHashMap; |
48 import java.util.List; | 48 import java.util.List; |
49 import java.util.Map; | 49 import java.util.Map; |
50 import java.util.Set; | 50 import java.util.Set; |
51 import java.util.concurrent.CountDownLatch; | 51 import java.util.concurrent.CountDownLatch; |
52 import java.util.concurrent.TimeUnit; | 52 import java.util.concurrent.TimeUnit; |
53 | 53 |
54 import javax.microedition.khronos.egl.EGLContext; | |
55 import javax.microedition.khronos.egl.EGL10; | |
56 | |
57 // Android specific implementation of VideoCapturer. | 54 // Android specific implementation of VideoCapturer. |
58 // An instance of this class can be created by an application using | 55 // An instance of this class can be created by an application using |
59 // VideoCapturerAndroid.create(); | 56 // VideoCapturerAndroid.create(); |
60 // This class extends VideoCapturer with a method to easily switch between the | 57 // This class extends VideoCapturer with a method to easily switch between the |
61 // front and back camera. It also provides methods for enumerating valid device | 58 // front and back camera. It also provides methods for enumerating valid device |
62 // names. | 59 // names. |
63 // | 60 // |
64 // Threading notes: this class is called from C++ code, Android Camera callbacks
, and possibly | 61 // Threading notes: this class is called from C++ code, Android Camera callbacks
, and possibly |
65 // arbitrary Java threads. All public entry points are thread safe, and delegate
the work to the | 62 // arbitrary Java threads. All public entry points are thread safe, and delegate
the work to the |
66 // camera thread. The internal *OnCameraThread() methods must check |camera| for
null to check if | 63 // camera thread. The internal *OnCameraThread() methods must check |camera| for
null to check if |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 // Invoked on failure, e.g. camera is stopped or only one camera available. | 223 // Invoked on failure, e.g. camera is stopped or only one camera available. |
227 void onCameraSwitchError(String errorDescription); | 224 void onCameraSwitchError(String errorDescription); |
228 } | 225 } |
229 | 226 |
230 public static VideoCapturerAndroid create(String name, | 227 public static VideoCapturerAndroid create(String name, |
231 CameraEventsHandler eventsHandler) { | 228 CameraEventsHandler eventsHandler) { |
232 return VideoCapturerAndroid.create(name, eventsHandler, null); | 229 return VideoCapturerAndroid.create(name, eventsHandler, null); |
233 } | 230 } |
234 | 231 |
235 public static VideoCapturerAndroid create(String name, | 232 public static VideoCapturerAndroid create(String name, |
236 CameraEventsHandler eventsHandler, EGLContext sharedEglContext) { | 233 CameraEventsHandler eventsHandler, EglBase.Context sharedEglContext) { |
237 final int cameraId = lookupDeviceName(name); | 234 final int cameraId = lookupDeviceName(name); |
238 if (cameraId == -1) { | 235 if (cameraId == -1) { |
239 return null; | 236 return null; |
240 } | 237 } |
241 | 238 |
242 final VideoCapturerAndroid capturer = new VideoCapturerAndroid(cameraId, eve
ntsHandler, | 239 final VideoCapturerAndroid capturer = new VideoCapturerAndroid(cameraId, eve
ntsHandler, |
243 sharedEglContext); | 240 sharedEglContext); |
244 capturer.setNativeCapturer(nativeCreateVideoCapturer(capturer)); | 241 capturer.setNativeCapturer(nativeCreateVideoCapturer(capturer)); |
245 return capturer; | 242 return capturer; |
246 } | 243 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 private String getSupportedFormatsAsJson() throws JSONException { | 339 private String getSupportedFormatsAsJson() throws JSONException { |
343 return CameraEnumerationAndroid.getSupportedFormatsAsJson(getCurrentCameraId
()); | 340 return CameraEnumerationAndroid.getSupportedFormatsAsJson(getCurrentCameraId
()); |
344 } | 341 } |
345 | 342 |
346 // Called from native VideoCapturer_nativeCreateVideoCapturer. | 343 // Called from native VideoCapturer_nativeCreateVideoCapturer. |
347 private VideoCapturerAndroid(int cameraId) { | 344 private VideoCapturerAndroid(int cameraId) { |
348 this(cameraId, null, null); | 345 this(cameraId, null, null); |
349 } | 346 } |
350 | 347 |
351 private VideoCapturerAndroid(int cameraId, CameraEventsHandler eventsHandler, | 348 private VideoCapturerAndroid(int cameraId, CameraEventsHandler eventsHandler, |
352 EGLContext sharedContext) { | 349 EglBase.Context sharedContext) { |
353 Logging.d(TAG, "VideoCapturerAndroid"); | 350 Logging.d(TAG, "VideoCapturerAndroid"); |
354 this.id = cameraId; | 351 this.id = cameraId; |
355 this.eventsHandler = eventsHandler; | 352 this.eventsHandler = eventsHandler; |
356 cameraThread = new HandlerThread(TAG); | 353 cameraThread = new HandlerThread(TAG); |
357 cameraThread.start(); | 354 cameraThread.start(); |
358 cameraThreadHandler = new Handler(cameraThread.getLooper()); | 355 cameraThreadHandler = new Handler(cameraThread.getLooper()); |
359 videoBuffers = new FramePool(cameraThread); | 356 videoBuffers = new FramePool(cameraThread); |
360 isCapturingToTexture = (sharedContext != null); | 357 isCapturingToTexture = (sharedContext != null); |
361 cameraStatistics = | 358 cameraStatistics = |
362 new CameraStatistics(isCapturingToTexture ? 1 : videoBuffers.numCaptureB
uffers); | 359 new CameraStatistics(isCapturingToTexture ? 1 : videoBuffers.numCaptureB
uffers); |
363 surfaceHelper = SurfaceTextureHelper.create( | 360 surfaceHelper = SurfaceTextureHelper.create(sharedContext, cameraThreadHandl
er); |
364 isCapturingToTexture ? sharedContext : EGL10.EGL_NO_CONTEXT, cameraThrea
dHandler); | |
365 if (isCapturingToTexture) { | 361 if (isCapturingToTexture) { |
366 surfaceHelper.setListener(this); | 362 surfaceHelper.setListener(this); |
367 } | 363 } |
368 } | 364 } |
369 | 365 |
370 private void checkIsOnCameraThread() { | 366 private void checkIsOnCameraThread() { |
371 if (Thread.currentThread() != cameraThread) { | 367 if (Thread.currentThread() != cameraThread) { |
372 throw new IllegalStateException("Wrong thread"); | 368 throw new IllegalStateException("Wrong thread"); |
373 } | 369 } |
374 } | 370 } |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 private native void nativeOnByteBufferFrameCaptured(long nativeCapturer, | 934 private native void nativeOnByteBufferFrameCaptured(long nativeCapturer, |
939 byte[] data, int length, int width, int height, int rotation, long timeS
tamp); | 935 byte[] data, int length, int width, int height, int rotation, long timeS
tamp); |
940 private native void nativeOnTextureFrameCaptured(long nativeCapturer, int wi
dth, int height, | 936 private native void nativeOnTextureFrameCaptured(long nativeCapturer, int wi
dth, int height, |
941 int oesTextureId, float[] transformMatrix, long timestamp); | 937 int oesTextureId, float[] transformMatrix, long timestamp); |
942 private native void nativeOnOutputFormatRequest(long nativeCapturer, | 938 private native void nativeOnOutputFormatRequest(long nativeCapturer, |
943 int width, int height, int framerate); | 939 int width, int height, int framerate); |
944 } | 940 } |
945 | 941 |
946 private static native long nativeCreateVideoCapturer(VideoCapturerAndroid vide
oCapturer); | 942 private static native long nativeCreateVideoCapturer(VideoCapturerAndroid vide
oCapturer); |
947 } | 943 } |
OLD | NEW |