Skip to content

Commit

Permalink
implementing video recording
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaji Khan committed Mar 14, 2024
1 parent f47171b commit 398230d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions app/src/main/java/com/shajikhan/ladspa/amprack/Camera2.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

public class Camera2 {
final String TAG = getClass().getSimpleName();
// parameters for the encoder
private static final String MIME_TYPE = "video/avc"; // H.264 Advanced Video Coding
private static final int FRAME_RATE = 30; // 15fps
private static final int IFRAME_INTERVAL = 3; // 10 seconds between I-frames
private static final int IFRAME_INTERVAL = 10; // 10 seconds between I-frames
private int mWidth = -1;
private int mHeight = -1;
// bit rate, in bits per second
Expand Down Expand Up @@ -108,6 +109,8 @@ public void openCamera() {
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
assert map != null;
imageDimension = map.getOutputSizes(SurfaceTexture.class)[0];
///| fixme: get this from somewhere else
imageDimension = new Size(720, 1280);
if (ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
Expand Down Expand Up @@ -177,15 +180,19 @@ public void createCameraPreview() {
SurfaceTexture texture = textureView.getSurfaceTexture();
assert texture != null;
texture.setDefaultBufferSize(imageDimension.getWidth(), imageDimension.getHeight());
Log.d(TAG, "createCameraPreview: created surface with dimensions".format (" %d x %d", imageDimension.getWidth(), imageDimension.getHeight()));
Surface surface = new Surface(texture);
captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
videoBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
captureRequestBuilder.addTarget(surface);

prepareEncoder();
videoBuilder.addTarget(mInputSurface);
List<Surface> surfaceList = new ArrayList<>();
surfaceList.add(surface);
surfaceList.add(mInputSurface);

cameraDevice.createCaptureSession(Arrays.asList(surface), new CameraCaptureSession.StateCallback() {
cameraDevice.createCaptureSession(surfaceList, new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
//The camera is already closed
Expand All @@ -199,7 +206,7 @@ public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {

@Override
public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
MainActivity.toast("Configuration change");
MainActivity.toast("Failed to start camera 😓");
}
}, null);
} catch (CameraAccessException e) {
Expand Down Expand Up @@ -234,8 +241,9 @@ public void closeCamera() {
private void prepareEncoder() {
mBufferInfo = new MediaCodec.BufferInfo();
///| Todo: fixme: get width and height from camera
mWidth = 900 ;
mHeight = 1600 ;
mWidth = imageDimension.getWidth() ;
mHeight = imageDimension.getHeight() ;
mBitRate = 1000000 ;
MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, mWidth, mHeight);

// Set some properties. Failing to specify some of these can cause the MediaCodec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3261,8 +3261,8 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface,
// resizeTextureView(width, height);
// surface.setDefaultBufferSize(cameraPreviewSize_.getWidth(),
// cameraPreviewSize_.getHeight());
surface_ = new Surface(surface);
surfaceTexture = surface;
// surface_ = new Surface(surface);
// surfaceTexture = surface;
// camera2.createCameraPreview();
// camera2.updatePreview();

Expand Down

0 comments on commit 398230d

Please sign in to comment.