#ifndef __PHONE_DEVICE_H__ #define __PHONE_DEVICE_H__ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // #define LOG_TAG "native-camera2-jni" #define PD_LOG_TAG "PhoneDev" #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,PD_LOG_TAG,__VA_ARGS__) #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,PD_LOG_TAG,__VA_ARGS__) #include #include class CPhoneDevice : public IDevice { public: CPhoneDevice(JavaVM* vm, jobject service); virtual ~CPhoneDevice(); virtual void SetListener(IListener* listener); virtual bool Reboot(); virtual timer_uid_t RegisterHeartbeat(unsigned int timerType, unsigned int timeout); virtual bool TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const string& path); virtual timer_uid_t registerTimer(unsigned int timerType, unsigned int timeout); virtual bool unregisterTimer(timer_uid_t uid); virtual bool FireTimer(timer_uid_t uid); protected: ACameraCaptureSession_stateCallbacks *GetSessionListener(); std::string GetFileName() const; bool SendBroadcastMessage(std::string action, int value); bool DisplayImage(ANativeWindow_Buffer* buf, AImage* image); void PresentImage(ANativeWindow_Buffer* buf, AImage* image); void PresentImage90(ANativeWindow_Buffer* buf, AImage* image); void PresentImage180(ANativeWindow_Buffer* buf, AImage* image); void PresentImage270(ANativeWindow_Buffer* buf, AImage* image); static void camera_device_on_disconnected(void *context, ACameraDevice *device); static void camera_device_on_error(void *context, ACameraDevice *device, int error); static void capture_session_on_ready(void *context, ACameraCaptureSession *session); static void capture_session_on_active(void *context, ACameraCaptureSession *session); static void capture_session_on_closed(void *context, ACameraCaptureSession *session); void ImageCallback(AImageReader *reader); static void OnImageCallback(void *ctx, AImageReader *reader); bool WriteFile(AImage *image); static bool WriteFile(CPhoneDevice* pThis, AImage *image); inline bool TakePhotoCb(bool res, const IDevice::PHOTO_INFO& photoInfo, const string& path, time_t photoTime) { if (m_listener != NULL) { return m_listener->OnPhotoTaken(res, photoInfo, path, photoTime); } return false; } protected: JavaVM* m_vm; jobject m_javaService; jmethodID mRegisterTimerMid; jmethodID mRegisterHeartbeatMid; jmethodID mUnregisterTimerMid; std::string mPath; IDevice::PHOTO_INFO mPhotoInfo; IListener* m_listener; atomic_ulong m_timerUidFeed; std::map mTimers; AImageReader *mAImageReader; ANativeWindow *theNativeWindow; ACameraDevice *cameraDevice; ACaptureRequest *captureRequest; ACameraOutputTarget *cameraOutputTarget; ACaptureSessionOutput *sessionOutput; ACaptureSessionOutputContainer *captureSessionOutputContainer; ACameraCaptureSession *captureSession; ACameraDevice_StateCallbacks deviceStateCallbacks; ACameraCaptureSession_stateCallbacks captureSessionStateCallbacks; int32_t presentRotation_; int32_t imageHeight_; int32_t imageWidth_; uint8_t* imageBuffer_; int32_t yStride, uvStride; uint8_t *yPixel, *uPixel, *vPixel; int32_t yLen, uLen, vLen; int32_t uvPixelStride; }; #endif // __PHONE_DEVICE_H__