|
|
|
#ifndef __PHONE_DEVICE_H__
|
|
|
|
#define __PHONE_DEVICE_H__
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
#include <camera/NdkCameraManager.h>
|
|
|
|
#include <camera/NdkCameraError.h>
|
|
|
|
#include <camera/NdkCameraDevice.h>
|
|
|
|
#include <camera/NdkCameraMetadataTags.h>
|
|
|
|
#include <media/NdkImageReader.h>
|
|
|
|
#include <android/log.h>
|
|
|
|
// #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 <Client/Device.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "Camera2Helper.h"
|
|
|
|
#include "camera2/ndkcamera.h"
|
|
|
|
|
|
|
|
|
|
|
|
class CPhoneDevice : public IDevice
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CPhoneDevice(JavaVM* vm, jobject service);
|
|
|
|
virtual ~CPhoneDevice();
|
|
|
|
|
|
|
|
virtual void SetListener(IListener* listener);
|
|
|
|
virtual bool UpdateTime(time_t ts);
|
|
|
|
virtual bool QuerySystemProperties(map<string, string>& properties);
|
|
|
|
virtual bool Reboot();
|
|
|
|
virtual timer_uid_t RegisterHeartbeat(unsigned int timerType, unsigned int timeout);
|
|
|
|
virtual bool TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<OSD_INFO>& osds, 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);
|
|
|
|
|
|
|
|
bool GetNextScheduleItem(uint32_t tsBasedZero, uint32_t scheduleTime, vector<uint32_t>& items);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
std::string GetFileName() const;
|
|
|
|
|
|
|
|
bool SendBroadcastMessage(std::string action, int value);
|
|
|
|
// bool MatchCaptureSizeRequest(ACameraManager *cameraManager, const char *selectedCameraId, unsigned int width, unsigned int height, uint32_t cameraOrientation_,
|
|
|
|
|
|
|
|
inline bool TakePhotoCb(bool res, const IDevice::PHOTO_INFO& photoInfo, const string& path, time_t photoTime) const
|
|
|
|
{
|
|
|
|
if (m_listener != NULL)
|
|
|
|
{
|
|
|
|
return m_listener->OnPhotoTaken(res, photoInfo, path, photoTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnImageReady(const cv::Mat& mat) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
JavaVM* m_vm;
|
|
|
|
jobject m_javaService;
|
|
|
|
|
|
|
|
jmethodID mRegisterTimerMid;
|
|
|
|
jmethodID mRegisterHeartbeatMid;
|
|
|
|
jmethodID mUnregisterTimerMid;
|
|
|
|
jmethodID mUpdateTimeMid;
|
|
|
|
|
|
|
|
std::string mPath;
|
|
|
|
IDevice::PHOTO_INFO mPhotoInfo;
|
|
|
|
vector<IDevice::OSD_INFO> mOsds;
|
|
|
|
IListener* m_listener;
|
|
|
|
|
|
|
|
atomic_ulong m_timerUidFeed;
|
|
|
|
std::map<IDevice::timer_uid_t, unsigned long> mTimers;
|
|
|
|
|
|
|
|
class CPhoneCamera : public NdkCamera {
|
|
|
|
public:
|
|
|
|
CPhoneCamera(CPhoneDevice* dev, int32_t width, int32_t height);
|
|
|
|
virtual void on_image(const cv::Mat& rgb) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
CPhoneDevice* m_dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
mutable CPhoneCamera* mCamera;
|
|
|
|
|
|
|
|
time_t mHeartbeatStartTime;
|
|
|
|
unsigned int mHeartbeatDuration;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // __PHONE_DEVICE_H__
|