NdkCameraCaptureSession.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (C) 2015 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. //#define LOG_NDEBUG 0
  17. #define LOG_TAG "NdkCameraCaptureSession"
  18. #define ATRACE_TAG ATRACE_TAG_CAMERA
  19. #include <utils/Log.h>
  20. #include <utils/Mutex.h>
  21. #include <utils/StrongPointer.h>
  22. #include <utils/Trace.h>
  23. #include <camera/NdkCameraDevice.h>
  24. #include <camera/NdkCaptureRequest.h>
  25. #include <camera/NdkCameraCaptureSession.h>
  26. #include "impl/ACameraCaptureSession.h"
  27. #include "impl/ACameraCaptureSession.inc"
  28. using namespace android;
  29. EXPORT
  30. void ACameraCaptureSession_close(ACameraCaptureSession* session) {
  31. ATRACE_CALL();
  32. if (session != nullptr) {
  33. session->closeByApp();
  34. }
  35. return;
  36. }
  37. EXPORT
  38. camera_status_t ACameraCaptureSession_getDevice(
  39. ACameraCaptureSession* session, ACameraDevice **device) {
  40. ATRACE_CALL();
  41. if (session == nullptr || device == nullptr) {
  42. ALOGE("%s: Error: invalid input: session %p, device %p",
  43. __FUNCTION__, session, device);
  44. return ACAMERA_ERROR_INVALID_PARAMETER;
  45. }
  46. if (session->isClosed()) {
  47. ALOGE("%s: session %p is already closed", __FUNCTION__, session);
  48. *device = nullptr;
  49. return ACAMERA_ERROR_SESSION_CLOSED;
  50. }
  51. *device = session->getDevice();
  52. if (*device == nullptr) {
  53. // Should not reach here
  54. ALOGE("%s: unknown failure: device is null", __FUNCTION__);
  55. return ACAMERA_ERROR_UNKNOWN;
  56. }
  57. return ACAMERA_OK;
  58. }
  59. EXPORT
  60. camera_status_t ACameraCaptureSession_capture(
  61. ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
  62. int numRequests, ACaptureRequest** requests,
  63. /*optional*/int* captureSequenceId) {
  64. ATRACE_CALL();
  65. if (session == nullptr || requests == nullptr || numRequests < 1) {
  66. ALOGE("%s: Error: invalid input: session %p, numRequest %d, requests %p",
  67. __FUNCTION__, session, numRequests, requests);
  68. return ACAMERA_ERROR_INVALID_PARAMETER;
  69. }
  70. if (session->isClosed()) {
  71. ALOGE("%s: session %p is already closed", __FUNCTION__, session);
  72. if (captureSequenceId != nullptr) {
  73. *captureSequenceId = CAPTURE_SEQUENCE_ID_NONE;
  74. }
  75. return ACAMERA_ERROR_SESSION_CLOSED;
  76. }
  77. return session->capture(
  78. cbs, numRequests, requests, captureSequenceId);
  79. }
  80. EXPORT
  81. camera_status_t ACameraCaptureSession_logicalCamera_capture(
  82. ACameraCaptureSession* session,
  83. /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacks* lcbs,
  84. int numRequests, ACaptureRequest** requests,
  85. /*optional*/int* captureSequenceId) {
  86. ATRACE_CALL();
  87. if (session == nullptr || requests == nullptr || numRequests < 1) {
  88. ALOGE("%s: Error: invalid input: session %p, numRequest %d, requests %p",
  89. __FUNCTION__, session, numRequests, requests);
  90. return ACAMERA_ERROR_INVALID_PARAMETER;
  91. }
  92. if (session->isClosed()) {
  93. ALOGE("%s: session %p is already closed", __FUNCTION__, session);
  94. if (captureSequenceId) {
  95. *captureSequenceId = CAPTURE_SEQUENCE_ID_NONE;
  96. }
  97. return ACAMERA_ERROR_SESSION_CLOSED;
  98. }
  99. return session->capture(
  100. lcbs, numRequests, requests, captureSequenceId);
  101. }
  102. EXPORT
  103. camera_status_t ACameraCaptureSession_setRepeatingRequest(
  104. ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
  105. int numRequests, ACaptureRequest** requests,
  106. /*optional*/int* captureSequenceId) {
  107. ATRACE_CALL();
  108. if (session == nullptr || requests == nullptr || numRequests < 1) {
  109. ALOGE("%s: Error: invalid input: session %p, numRequest %d, requests %p",
  110. __FUNCTION__, session, numRequests, requests);
  111. return ACAMERA_ERROR_INVALID_PARAMETER;
  112. }
  113. if (session->isClosed()) {
  114. ALOGE("%s: session %p is already closed", __FUNCTION__, session);
  115. if (captureSequenceId) {
  116. *captureSequenceId = CAPTURE_SEQUENCE_ID_NONE;
  117. }
  118. return ACAMERA_ERROR_SESSION_CLOSED;
  119. }
  120. return session->setRepeatingRequest(cbs, numRequests, requests, captureSequenceId);
  121. }
  122. EXPORT
  123. camera_status_t ACameraCaptureSession_logicalCamera_setRepeatingRequest(
  124. ACameraCaptureSession* session,
  125. /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacks* lcbs,
  126. int numRequests, ACaptureRequest** requests,
  127. /*optional*/int* captureSequenceId) {
  128. ATRACE_CALL();
  129. if (session == nullptr || requests == nullptr || numRequests < 1) {
  130. ALOGE("%s: Error: invalid input: session %p, numRequest %d, requests %p",
  131. __FUNCTION__, session, numRequests, requests);
  132. return ACAMERA_ERROR_INVALID_PARAMETER;
  133. }
  134. if (session->isClosed()) {
  135. ALOGE("%s: session %p is already closed", __FUNCTION__, session);
  136. if (captureSequenceId) {
  137. *captureSequenceId = CAPTURE_SEQUENCE_ID_NONE;
  138. }
  139. return ACAMERA_ERROR_SESSION_CLOSED;
  140. }
  141. return session->setRepeatingRequest(lcbs, numRequests, requests, captureSequenceId);
  142. }
  143. EXPORT
  144. camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session) {
  145. ATRACE_CALL();
  146. if (session == nullptr) {
  147. ALOGE("%s: Error: session is null", __FUNCTION__);
  148. return ACAMERA_ERROR_INVALID_PARAMETER;
  149. }
  150. if (session->isClosed()) {
  151. ALOGE("%s: session %p is already closed", __FUNCTION__, session);
  152. return ACAMERA_ERROR_SESSION_CLOSED;
  153. }
  154. return session->stopRepeating();
  155. }
  156. EXPORT
  157. camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session) {
  158. ATRACE_CALL();
  159. if (session == nullptr) {
  160. ALOGE("%s: Error: session is null", __FUNCTION__);
  161. return ACAMERA_ERROR_INVALID_PARAMETER;
  162. }
  163. if (session->isClosed()) {
  164. ALOGE("%s: session %p is already closed", __FUNCTION__, session);
  165. return ACAMERA_ERROR_SESSION_CLOSED;
  166. }
  167. return session->abortCaptures();
  168. }
  169. EXPORT
  170. camera_status_t ACameraCaptureSession_updateSharedOutput(ACameraCaptureSession* session,
  171. ACaptureSessionOutput* output) {
  172. ATRACE_CALL();
  173. if (session == nullptr) {
  174. ALOGE("%s: Error: session is null", __FUNCTION__);
  175. return ACAMERA_ERROR_INVALID_PARAMETER;
  176. }
  177. if (session->isClosed()) {
  178. ALOGE("%s: session %p is already closed", __FUNCTION__, session);
  179. return ACAMERA_ERROR_SESSION_CLOSED;
  180. }
  181. return session->updateOutputConfiguration(output);
  182. }