| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | package org.webrtc; |
| 12 |
| 13 | import android.graphics.Matrix; |
| 14 |
| 15 | interface CameraSession { |
| 16 | enum FailureType { ERROR, DISCONNECTED } |
| 17 |
| 18 | // Callbacks are fired on the camera thread. |
| 19 | interface CreateSessionCallback { |
| 20 | void onDone(CameraSession session); |
| 21 | void onFailure(FailureType failureType, String error); |
| 22 | } |
| 23 |
| 24 | // Events are fired on the camera thread. |
| 25 | interface Events { |
| 26 | void onCameraOpening(); |
| 27 | void onCameraError(CameraSession session, String error); |
| 28 | void onCameraDisconnected(CameraSession session); |
| 29 | void onCameraClosed(CameraSession session); |
| 30 | void onFrameCaptured(CameraSession session, VideoFrame frame); |
| 31 | } |
| 32 |
| 33 | /** |
| 34 | * Stops the capture. Waits until no more calls to capture observer will be made. |
| 35 | * If waitCameraStop is true, also waits for the camera to stop. |
| 36 | */ |
| 37 | void stop(); |
| 38 |
| 39 | static VideoFrame.TextureBuffer createTextureBufferWithModifiedTransformMatrix( |
| 40 | TextureBufferImpl buffer, boolean mirror, int rotation) { |
| 41 | final Matrix transformMatrix = new Matrix(); |
| 42 | // Perform mirror and rotation around (0.5, 0.5) since that is the center of the texture. |
| 43 | transformMatrix.preTranslate(/* dx= */ 0.5f, /* dy= */ 0.5f); |
| 44 | if (mirror) { |
| 45 | transformMatrix.preScale(/* sx= */ -1f, /* sy= */ 1f); |
| 46 | } |
| 47 | transformMatrix.preRotate(rotation); |
| 48 | transformMatrix.preTranslate(/* dx= */ -0.5f, /* dy= */ -0.5f); |
| 49 |
| 50 | // The width and height are not affected by rotation since Camera2Session has set them to the |
| 51 | // value they should be after undoing the rotation. |
| 52 | return buffer.applyTransformMatrix(transformMatrix, buffer.getWidth(), buffer.getHeight()); |
| 53 | } |
| 54 | } |
| 55 |