From e1020d5371ca17e21da494608108dcb87cea3d23 Mon Sep 17 00:00:00 2001 From: Shaji Khan Date: Thu, 14 Mar 2024 11:41:37 +0530 Subject: [PATCH] milestone: going to implement camera --- app/src/main/cpp/camera_engine.cpp | 9 +++++++-- app/src/main/cpp/camera_manager.cpp | 6 ++++++ app/src/main/cpp/camera_manager.h | 2 +- app/src/main/java/com/shajikhan/ladspa/amprack/Rack.java | 6 ++++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/cpp/camera_engine.cpp b/app/src/main/cpp/camera_engine.cpp index 40a802f9..8df69eb5 100644 --- a/app/src/main/cpp/camera_engine.cpp +++ b/app/src/main/cpp/camera_engine.cpp @@ -235,6 +235,8 @@ void CameraAppEngine::releaseEncoder() { bool CameraAppEngine::writeFrame(AImage * image){ // Feed any pending encoder output into the muxer. IN + OUT + return true; // if (mEncoder == nullptr) { // LOGD("first time running, trying to create encoder ..."); // createEncoder(filename); @@ -299,6 +301,8 @@ bool CameraAppEngine::writeFrame(AImage * image){ void CameraAppEngine::drainEncoder(bool endOfStream) { IN + OUT + return; LOGD("end of stream: %d", endOfStream); if (endOfStream) { LOGD( "Draining encoder to EOS"); @@ -313,7 +317,7 @@ void CameraAppEngine::drainEncoder(bool endOfStream) { while (true) { LOGD("dequeue output buffer..."); - if (mEncoder != nullptr) LOGE("mEncoder is NULL"); + if (mEncoder == nullptr) LOGE("mEncoder is NULL"); ssize_t encoderStatus = AMediaCodec_dequeueOutputBuffer(mEncoder, &mBufferInfo, TIMEOUT_USEC); LOGD("encoder status: %d", encoderStatus); @@ -487,10 +491,11 @@ void ImageReader::ImageCallback(AImageReader *reader) { // if (format == AIMAGE_FORMAT_JPEG) // { AImage *image = nullptr; - status = AImageReader_acquireNextImage(reader, &image); + status = AImageReader_acquireLatestImage(reader, &image); ASSERT(status == AMEDIA_OK && image, "Image is not available"); CameraAppEngine * _app = (CameraAppEngine *) app ; _app -> writeFrame (image); + AImage_delete(image); /* size_t bufferSize = 0; int inputBufferIdx = AMediaCodec_dequeueInputBuffer(mediaCodec, -1); diff --git a/app/src/main/cpp/camera_manager.cpp b/app/src/main/cpp/camera_manager.cpp index cd2fb389..9728d8bd 100644 --- a/app/src/main/cpp/camera_manager.cpp +++ b/app/src/main/cpp/camera_manager.cpp @@ -290,6 +290,9 @@ void NDKCamera::CreateSession(ANativeWindow* previewWindow, CALL_DEV(createCaptureSession(cameras_[activeCameraId_].device_, outputContainer_, GetSessionListener(), &captureSession_)); + CALL_DEV(createCaptureSession(cameras_[activeCameraId_].device_, + outputContainer_, GetSessionListener(), + &captureSessionV)); if (jpgWindow) { ACaptureRequest_setEntry_i32(requests_[JPG_CAPTURE_REQUEST_IDX].request_, @@ -444,6 +447,9 @@ void NDKCamera::StartPreview(bool start) { CALL_SESSION(setRepeatingRequest(captureSession_, nullptr, 1, &requests_[PREVIEW_REQUEST_IDX].request_, nullptr)); + CALL_SESSION(setRepeatingRequest(captureSessionV, nullptr, 1, + &requests_[VIDEO_CAPTURE_REQUEST_IDX].request_, + nullptr)); } else if (!start && captureSessionState_ == CaptureSessionState::ACTIVE) { ACameraCaptureSession_stopRepeating(captureSession_); } diff --git a/app/src/main/cpp/camera_manager.h b/app/src/main/cpp/camera_manager.h index a5531481..e24ebf7d 100644 --- a/app/src/main/cpp/camera_manager.h +++ b/app/src/main/cpp/camera_manager.h @@ -89,7 +89,7 @@ class NDKCamera { std::vector requests_; ACaptureSessionOutputContainer* outputContainer_; - ACameraCaptureSession* captureSession_; + ACameraCaptureSession* captureSession_, *captureSessionV; CaptureSessionState captureSessionState_; // set up exposure control diff --git a/app/src/main/java/com/shajikhan/ladspa/amprack/Rack.java b/app/src/main/java/com/shajikhan/ladspa/amprack/Rack.java index 88c95718..53cb5317 100644 --- a/app/src/main/java/com/shajikhan/ladspa/amprack/Rack.java +++ b/app/src/main/java/com/shajikhan/ladspa/amprack/Rack.java @@ -662,8 +662,10 @@ public boolean onLongClick(View view) { @Override public void onClick(View v) { // mainActivity.drummer (); -// mainActivity.cameraPreview(); - MainActivity.setAudioDevice(); + if (BuildConfig.DEBUG) + mainActivity.cameraPreview(); + else + MainActivity.setAudioDevice(); return; } });