I'm trying to get the video stream of a camera into an imagereader surface to be able to process these images. I found a lot of examples that deal with the camera2 API but I don't use that because my video stream comes from an external camera.
Ideally, I would have two surfaces: one as a preview and and one from the ImageReader to process the image. Similar to this. I understand that you combine the two surfaces with a CaptureRequest.Builder
and then .addTarget(surface)
. The problem is that I don't have a CamerDevice
to make the createCaptureRequest
.
The code I am using can be found here.
I tried to just create an ImageReader and its surface and pass it to the startDecoding
function. But this didn't work quite well as I got this error:
E/JNI: close+++++++
E/BufferQueueProducer: [ImageReader-1280x720f32315659m16-17834-0] dequeueBuffer: BufferQueue has been abandoned
E/ACodec: NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS query failed: No such device (19)
E/ACodec: Failed to allocate output port buffers after port reconfiguration: (-19)
E/ACodec: signalError(omxError 0x80001001, internalError -19)
E/MediaCodec: Codec reported err 0xffffffed, actionCode 0, while in state 6
E/AccessHeadCameraActivity: Error has occured.
java.lang.IllegalStateException
at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:2379)
Any hint into the right direction would be nice!
Update 1:
The error results from the return value of dequeueOutputBuffer
, as this has the value of -1
. According to the docs on the MediaCodec, this means that the call timed out. But why does that happen?
Update 2
I don't have the surfaceCreated
(because I don't have the SurfaceView anymore), so that code moved into the onCreate
. Everthing else is pretty much the same as in here
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_acess_headcamera);
mediaManager = (MediaManager) getUnitManager(FuncConstant.MEDIA_MANAGER);
setupImageReader();
StreamOption streamOption = new StreamOption();
streamOption.setChannel(StreamOption.MAIN_STREAM);
streamOption.setDecodType(StreamOption.HARDWARE_DECODE);
streamOption.setJustIframe(false);
mediaManager.openStream(streamOption);
surface = imageReader.getSurface();
startDecoding(surface);
initListener();
}
private void setupImageReader() {
imageReader = ImageReader.newInstance(width, height, ImageFormat.YV12,
IMAGE_READER_BUFFER_SIZE);
imageReader.setOnImageAvailableListener(onImageAvailableListener, backgroundHandler);
}