I have got custom view that extends SurfaceView and implements Camera.PreviewCallback. I am using this view as a camera preview. There is also implemented functionality captureing video frames to buffer and streaming them.
When orientation of device is changed, I call setRotation() with appropriate argument.
Camera.Parameters parameters = svVideo.getCamera().getParameters();
parameters.setRotation(rotation);
svVideo.getCamera().setParameters(parameters);
But sadly, there is no change in orientation of frames captured in onPreviewFrame() callback. What I am trying to achieve is that if I rotate streaming device, video stream sent to other device will be rotated accordingly.
I also tried to take some photos with changed rotation as described. setRotation() affects only rotation of pictures taken with front-facing camera (which is weird), photos from back facing camera are not affected at all.
My question is: How could I get properly rotated frames usable for streaming or rotate them in callback by myself?
Here is my onPreviewFrame method:
@Override
public void onPreviewFrame(final byte[] frame, final Camera camera) {
final long now = System.nanoTime();
if (outq.remainingCapacity() >= 2 && (now - this.frame) >= 1000000000 / fps) { //Don't encode more then we can handle, and also not more then FPS.
queueFrameForEncoding(frame, now);
}
getEncodedFrames();
camera.addCallbackBuffer(frame); //Recycle buffer
}