Initial NativeCamera support for Android 4.4 KitKat.

This commit is contained in:
Alexander Smorkalov 2013-11-17 11:42:13 +04:00
parent e3f450cffb
commit 04d293d2c4
2 changed files with 41 additions and 6 deletions

View File

@ -1,6 +1,6 @@
#if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1) && \
!defined(ANDROID_r4_0_0) && !defined(ANDROID_r4_0_3) && !defined(ANDROID_r4_1_1) && \
!defined(ANDROID_r4_2_0) && !defined(ANDROID_r4_3_0)
!defined(ANDROID_r4_2_0) && !defined(ANDROID_r4_3_0) && !defined(ANDROID_r4_4_0)
# error Building camera wrapper for your version of Android is not supported by OpenCV.\
You need to modify OpenCV sources in order to compile camera wrapper for your version of Android.
#endif
@ -22,7 +22,7 @@
#elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0)
# include <gui/ISurface.h>
# include <gui/BufferQueue.h>
#elif defined(ANDROID_r4_3_0)
#elif defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0)
# include <gui/IGraphicBufferProducer.h>
# include <gui/BufferQueue.h>
#else
@ -74,6 +74,20 @@ public:
{
}
};
#elif defined(ANDROID_r4_4_0)
class ConsumerListenerStub: public android::BnConsumerListener
{
public:
virtual void onFrameAvailable()
{
}
virtual void onBuffersReleased()
{
}
virtual ~ConsumerListenerStub()
{
}
};
#endif
std::string getProcessName()
@ -306,7 +320,8 @@ public:
}
virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr
#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) \
|| defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0)
,camera_frame_metadata_t*
#endif
)
@ -623,7 +638,14 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
bufferStatus = camera->setPreviewTexture(bufferQueue);
if (bufferStatus != 0)
LOGE("initCameraConnect: failed setPreviewTexture call; camera might not work correctly");
#endif
# elif defined(ANDROID_r4_4_0)
sp<BufferQueue> bufferQueue = new BufferQueue();
sp<IConsumerListener> queueListener = new ConsumerListenerStub();
bufferQueue->consumerConnect(queueListener, true);
bufferStatus = handler->camera->setPreviewTarget(bufferQueue);
if (bufferStatus != 0)
LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly");
# endif
#if (defined(ANDROID_r2_2_0) || defined(ANDROID_r2_3_3) || defined(ANDROID_r3_0_1))
# if 1
@ -663,7 +685,8 @@ void CameraHandler::closeCameraConnect()
}
camera->stopPreview();
#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) \
|| defined(ANDROID_r4_3_0) || defined(ANDROID_r4_3_0)
camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
#endif
camera->disconnect();
@ -914,7 +937,8 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
CameraParameters curCameraParameters((*ppcameraHandler)->params.flatten());
#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) \
|| defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0)
CameraHandler* handler=*ppcameraHandler;
handler->camera->stopPreview();
@ -943,6 +967,13 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
bufferStatus = handler->camera->setPreviewTexture(bufferQueue);
if (bufferStatus != 0)
LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly");
# elif defined(ANDROID_r4_4_0)
sp<BufferQueue> bufferQueue = new BufferQueue();
sp<IConsumerListener> queueListener = new ConsumerListenerStub();
bufferQueue->consumerConnect(queueListener, true);
bufferStatus = handler->camera->setPreviewTarget(bufferQueue);
if (bufferStatus != 0)
LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly");
# endif
handler->camera->setPreviewCallbackFlags( CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK | CAMERA_FRAME_CALLBACK_FLAG_COPY_OUT_MASK);//with copy

View File

@ -25,3 +25,7 @@ native_camera_r4.3.0; armeabi; 14; $ANDROID_STUB_ROOT/4.3.0
native_camera_r4.3.0; armeabi-v7a; 14; $ANDROID_STUB_ROOT/4.3.0
native_camera_r4.3.0; x86; 14; $ANDROID_STUB_ROOT/4.3.0
native_camera_r4.3.0; mips; 14; $ANDROID_STUB_ROOT/4.3.0
native_camera_r4.4.0; armeabi; 14; $ANDROID_STUB_ROOT/4.4.0
native_camera_r4.4.0; armeabi-v7a; 14; $ANDROID_STUB_ROOT/4.4.0
native_camera_r4.4.0; x86; 14; $ANDROID_STUB_ROOT/4.4.0
native_camera_r4.4.0; mips; 14; $ANDROID_STUB_ROOT/4.4.0