-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[camera_android] Support concurrently image capture and image streaming #4332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
dec3d69
Merge remote-tracking branch 'upstream/main' into camx_occ
camsim99 0e0333b
Merge remote-tracking branch 'upstream/main'
camsim99 bd7ac99
Merge remote-tracking branch 'upstream/main'
camsim99 5c3363b
Merge remote-tracking branch 'upstream/main'
camsim99 fed9621
Undo changes
camsim99 5aabe34
Merge remote-tracking branch 'upstream/main'
camsim99 2b9a352
Merge remote-tracking branch 'upstream/main'
camsim99 a1173da
Merge remote-tracking branch 'upstream/main'
camsim99 cbc3d6b
Merge remote-tracking branch 'upstream/main'
camsim99 cae5a4c
Merge remote-tracking branch 'upstream/main'
camsim99 72283db
Merge remote-tracking branch 'upstream/main'
camsim99 166a77c
Merge remote-tracking branch 'upstream/main'
camsim99 399780e
Merge remote-tracking branch 'upstream/main'
camsim99 8d5d0e7
Merge remote-tracking branch 'upstream/main'
camsim99 8de6de1
Make fixes
camsim99 f731d64
Merge remote-tracking branch 'upstream/main' into xi_debug
camsim99 0710eb8
Initial stab at tests
camsim99 72365fa
Test attmept 2
camsim99 4bb3601
some test fixes
camsim99 7a45621
Test changes, removed test for ease
camsim99 73168b5
Add fix for invalid use of matchers
camsim99 69d7ffe
add debug notes
camsim99 30a8880
Bump version
camsim99 3abad3b
Mock prepareMediaRecorder
camsim99 9e44f56
Change camera to spy for mock
camsim99 c493b9d
Merge remote-tracking branch 'upstream/main' into xi_debug
camsim99 22ebff0
Mock prepareRecording
camsim99 7d39d57
Bump times because createCaptureSession
camsim99 48177de
Bump times because createCaptureSession
camsim99 6f9e085
Uncomment other tests, add comments
camsim99 a0af9cc
Add back imports
camsim99 ce3c25c
Add one last comment
camsim99 ede8e88
format
camsim99 bcfa57c
Refactor and check if surface mock needed
camsim99 6c1ba5e
fix tests
camsim99 abf390f
Formatting
camsim99 00ce873
Add mock for test
camsim99 10331d6
Correct to 2
camsim99 c29896c
Merge remote-tracking branch 'upstream/main' into xi_debug
camsim99 d9347f9
Formatting
camsim99 020a5e2
I'm not sure why I'm getting so confused
camsim99 ea9c373
format
camsim99 f784750
Add periods
camsim99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import android.hardware.camera2.params.SessionConfiguration; | ||
import android.media.CamcorderProfile; | ||
import android.media.EncoderProfiles; | ||
import android.media.Image; | ||
import android.media.ImageReader; | ||
import android.media.MediaRecorder; | ||
import android.os.Build; | ||
|
@@ -414,8 +415,14 @@ private void createCaptureSession( | |
|
||
List<Surface> remainingSurfaces = Arrays.asList(surfaces); | ||
if (templateType != CameraDevice.TEMPLATE_PREVIEW) { | ||
// If it is not preview mode, add all surfaces as targets. | ||
// If it is not preview mode, add all surfaces as targets | ||
// except the surface used for still capture as this should | ||
// not be part of a repeating request. | ||
Surface pictureImageReaderSurface = pictureImageReader.getSurface(); | ||
for (Surface surface : remainingSurfaces) { | ||
if (surface == pictureImageReaderSurface) { | ||
continue; | ||
} | ||
previewRequestBuilder.addTarget(surface); | ||
} | ||
} | ||
|
@@ -539,6 +546,10 @@ private void startCapture(boolean record, boolean stream) throws CameraAccessExc | |
surfaces.add(imageStreamReader.getSurface()); | ||
} | ||
|
||
// Add pictureImageReader surface to allow for still capture | ||
// during recording/image streaming. | ||
surfaces.add(pictureImageReader.getSurface()); | ||
|
||
createCaptureSession( | ||
CameraDevice.TEMPLATE_RECORD, successCallback, surfaces.toArray(new Surface[0])); | ||
} | ||
|
@@ -659,7 +670,6 @@ public void onCaptureCompleted( | |
}; | ||
|
||
try { | ||
captureSession.stopRepeating(); | ||
Log.i(TAG, "sending capture request"); | ||
captureSession.capture(stillBuilder.build(), captureCallback, backgroundHandler); | ||
} catch (CameraAccessException e) { | ||
|
@@ -1140,10 +1150,15 @@ public void startPreviewWithImageStream(EventChannel imageStreamChannel) | |
public void onImageAvailable(ImageReader reader) { | ||
Log.i(TAG, "onImageAvailable"); | ||
|
||
// Use acquireNextImage since image reader is only for one image. | ||
Image image = reader.acquireNextImage(); | ||
if (image == null) { | ||
return; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated fix: |
||
backgroundHandler.post( | ||
new ImageSaver( | ||
// Use acquireNextImage since image reader is only for one image. | ||
reader.acquireNextImage(), | ||
image, | ||
captureFile, | ||
new ImageSaver.Callback() { | ||
@Override | ||
|
@@ -1159,7 +1174,8 @@ public void onError(String errorCode, String errorMessage) { | |
cameraCaptureCallback.setCameraState(CameraState.STATE_PREVIEW); | ||
} | ||
|
||
private void prepareRecording(@NonNull Result result) { | ||
@VisibleForTesting | ||
void prepareRecording(@NonNull Result result) { | ||
final File outputDir = applicationContext.getCacheDir(); | ||
try { | ||
captureFile = File.createTempFile("REC", ".mp4", outputDir); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated fix: This call should not be necessary for still capture to proceed.