Java Code Examples for android.graphics.SurfaceTexture.setDefaultBufferSize()

The following are Jave code examples for showing how to use setDefaultBufferSize() of the android.graphics.SurfaceTexture class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: BWS-Android   File: CameraHelper.java   Source Code and License Vote up 6 votes
/**
 * configures the ProportionalTextureView to respect the aspect ratio of the image and using an appropriate buffer size
 */
@VisibleForTesting
void configureTextureView(@NonNull ProportionalTextureView textureView, @ConfigurationOrientation int deviceOrientation,
                          @SurfaceRotation int relativeDisplayRotation, @NonNull Size previewSize) {
    switch (deviceOrientation) {
        case Configuration.ORIENTATION_PORTRAIT:
            // swap values because preview sizes are always landscape
            textureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth(), relativeDisplayRotation);
            break;
        case Configuration.ORIENTATION_LANDSCAPE:
            textureView.setAspectRatio(previewSize.getWidth(), previewSize.getHeight(), relativeDisplayRotation);
            break;
    }

    // working more memory efficient
    SurfaceTexture surface = textureView.getSurfaceTexture();
    if (surface != null) {
        surface.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
    } else {
        throw new CameraException("surface texture not attached to view");
    }
}
 
Example 2
Project: EasyScreenRecorder   File: MediaScreenEncoder.java   Source Code and License Vote up 6 votes
@Override
protected void onStart() {
    if (DEBUG) Log.d(TAG,"mScreenCaptureTask#onStart:");
	mDrawer = new GLDrawer2D(true);
	mTexId = mDrawer.initTex();
	mSourceTexture = new SurfaceTexture(mTexId);
	mSourceTexture.setDefaultBufferSize(mWidth, mHeight);	// これを入れないと映像が取れない
	mSourceSurface = new Surface(mSourceTexture);
	mSourceTexture.setOnFrameAvailableListener(mOnFrameAvailableListener, mHandler);
	mEncoderSurface = getEgl().createFromSurface(mSurface);

   	if (DEBUG) Log.d(TAG,"setup VirtualDisplay");
	intervals = (long)(1000f / fps);
    display = mMediaProjection.createVirtualDisplay(
    	"Capturing Display",
    	mWidth, mHeight, mDensity,
    	DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
    	mSourceSurface, mCallback, mHandler);
	if (DEBUG) Log.v(TAG,  "screen capture loop:display=" + display);
	// 録画タスクを起床
	queueEvent(mDrawTask);
}
 
Example 3
Project: AppRTC-Android   File: Camera2Session.java   Source Code and License Vote up 6 votes
@Override
public void onOpened(CameraDevice camera) {
  checkIsOnCameraThread();

  Logging.d(TAG, "Camera opened.");
  cameraDevice = camera;

  final SurfaceTexture surfaceTexture = surfaceTextureHelper.getSurfaceTexture();
  surfaceTexture.setDefaultBufferSize(captureFormat.width, captureFormat.height);
  surface = new Surface(surfaceTexture);
  List<Surface> surfaces = new ArrayList<Surface>();
  surfaces.add(surface);
  if (mediaRecorderSurface != null) {
    Logging.d(TAG, "Add MediaRecorder surface to capture session.");
    surfaces.add(mediaRecorderSurface);
  }
  try {
    camera.createCaptureSession(surfaces, new CaptureSessionCallback(), cameraThreadHandler);
  } catch (CameraAccessException e) {
    reportError("Failed to create capture session. " + e);
    return;
  }
}
 
Example 4
Project: AndroidRTC   File: Camera2Session.java   Source Code and License Vote up 6 votes
@Override
public void onOpened(CameraDevice camera) {
  checkIsOnCameraThread();

  Logging.d(TAG, "Camera opened.");
  cameraDevice = camera;

  final SurfaceTexture surfaceTexture = surfaceTextureHelper.getSurfaceTexture();
  surfaceTexture.setDefaultBufferSize(captureFormat.width, captureFormat.height);
  surface = new Surface(surfaceTexture);
  try {
    camera.createCaptureSession(
        Arrays.asList(surface), new CaptureSessionCallback(), cameraThreadHandler);
  } catch (CameraAccessException e) {
    reportError("Failed to create capture session. " + e);
    return;
  }
}
 
Example 5
Project: VideoCRE   File: Camera2Session.java   Source Code and License Vote up 6 votes
@Override
public void onOpened(CameraDevice camera) {
  checkIsOnCameraThread();

  Logging.d(TAG, "Camera opened.");
  cameraDevice = camera;

  final SurfaceTexture surfaceTexture = surfaceTextureHelper.getSurfaceTexture();
  surfaceTexture.setDefaultBufferSize(captureFormat.width, captureFormat.height);
  surface = new Surface(surfaceTexture);
  List<Surface> surfaces = new ArrayList<Surface>();
  surfaces.add(surface);
  if (mediaRecorderSurface != null) {
    Logging.d(TAG, "Add MediaRecorder surface to capture session.");
    surfaces.add(mediaRecorderSurface);
  }
  try {
    camera.createCaptureSession(surfaces, new CaptureSessionCallback(), cameraThreadHandler);
  } catch (CameraAccessException e) {
    reportError("Failed to create capture session. " + e);
    return;
  }
}
 
Example 6
Project: AndroidRTC   File: EglRendererTest.java   Source Code and License Vote up 5 votes
@Before
public void setUp() throws Exception {
  PeerConnectionFactory.initializeAndroidGlobals(InstrumentationRegistry.getTargetContext(),
      true /* initializeAudio */, true /* initializeVideo */, true /* videoHwAcceleration */);
  eglRenderer = new EglRenderer("TestRenderer: ");
  eglRenderer.init(null /* sharedContext */, EglBase.CONFIG_RGBA, new GlRectDrawer());
  oesTextureId = GlUtil.generateTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
  surfaceTexture = new SurfaceTexture(oesTextureId);
  surfaceTexture.setDefaultBufferSize(1 /* width */, 1 /* height */);
  eglRenderer.createEglSurface(surfaceTexture);
}
 
Example 7
Project: Croprotector   File: Shoot_fragment.java   Source Code and License Vote up 5 votes
@Override
public void onOpened(CameraDevice cameraDevice) {
    Log.d(TAG, "相机已经打开");
    try {
        mPreViewBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        SurfaceTexture texture = mTextureView.getSurfaceTexture();
        texture.setDefaultBufferSize(mPreViewSize.getWidth(), mPreViewSize.getHeight());
        surface = new Surface(texture);
        mPreViewBuilder.addTarget(surface);
        cameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface
                ()), mSessionStateCallBack, mHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 8
Project: KrGallery   File: CameraView.java   Source Code and License Vote up 4 votes
private void initCamera(boolean front) {
    CameraInfo info = null;
    ArrayList<CameraInfo> cameraInfos = CameraController.getInstance().getCameras();
    if (cameraInfos == null) {
        return;
    }
    for (int a = 0; a < cameraInfos.size(); a++) {
        CameraInfo cameraInfo = cameraInfos.get(a);
        if (isFrontface && cameraInfo.frontCamera != 0 || !isFrontface && cameraInfo.frontCamera == 0) {
            info = cameraInfo;
            break;
        }
    }
    if (info == null) {
        return;
    }
    float size4to3 = 4.0f / 3.0f;
    float size16to9 = 16.0f / 9.0f;
    float screenSize = (float) Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) / Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
    Size aspectRatio;
    int wantedWidth;
    int wantedHeight;
    if (Math.abs(screenSize - size4to3) < 0.1f) {
        aspectRatio = new Size(4, 3);
        wantedWidth = 1280;
        wantedHeight = 960;
    } else {
        aspectRatio = new Size(16, 9);
        wantedWidth = 1280;
        wantedHeight = 720;
    }
    if (textureView.getWidth() > 0 && textureView.getHeight() > 0) {
        int width = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
        int height = width * aspectRatio.getHeight() / aspectRatio.getWidth();
        previewSize = CameraController.chooseOptimalSize(info.getPreviewSizes(), width, height, aspectRatio);
    }
    Size pictureSize = CameraController.chooseOptimalSize(info.getPictureSizes(), wantedWidth, wantedHeight, aspectRatio);
    if (pictureSize.getWidth() >= 1280 && pictureSize.getHeight() >= 1280) {
        if (Math.abs(screenSize - size4to3) < 0.1f) {
            aspectRatio = new Size(3, 4);
        } else {
            aspectRatio = new Size(9, 16);
        }
        Size pictureSize2 = CameraController.chooseOptimalSize(info.getPictureSizes(), wantedHeight, wantedWidth, aspectRatio);
        if (pictureSize2.getWidth() < 1280 || pictureSize2.getHeight() < 1280) {
            pictureSize = pictureSize2;
        }
    }
    SurfaceTexture surfaceTexture = textureView.getSurfaceTexture();
    if (previewSize != null && surfaceTexture != null) {
        surfaceTexture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
        cameraSession = new CameraSession(info, previewSize, pictureSize, ImageFormat.JPEG);
        CameraController.getInstance().open(cameraSession, surfaceTexture, new Runnable() {
            @Override
            public void run() {
                if (cameraSession != null) {
                    cameraSession.setInitied();
                }
                checkPreviewMatrix();
            }
        }, new Runnable() {
            @Override
            public void run() {
                if (delegate != null) {
                    delegate.onCameraCreated(cameraSession.cameraInfo.camera);
                }
            }
        });
    }
}
 
Example 9
Project: rtmp-rtsp-stream-client-java   File: Camera2ApiManager.java   Source Code and License Vote up 4 votes
public void prepareCamera(SurfaceTexture surfaceTexture, int width, int height) {
  surfaceTexture.setDefaultBufferSize(width, height);
  this.surfaceEncoder = new Surface(surfaceTexture);
  prepared = true;
}