diff options
Diffstat (limited to 'include/ui')
-rw-r--r-- | include/ui/Camera.h | 68 | ||||
-rw-r--r-- | include/ui/ICameraClient.h | 9 | ||||
-rw-r--r-- | include/ui/Point.h | 21 | ||||
-rw-r--r-- | include/ui/Rect.h | 40 |
4 files changed, 63 insertions, 75 deletions
diff --git a/include/ui/Camera.h b/include/ui/Camera.h index e593fea..e3544ab 100644 --- a/include/ui/Camera.h +++ b/include/ui/Camera.h @@ -63,23 +63,44 @@ namespace android { #define FRAME_CALLBACK_FLAG_CAMERA 0x05 #define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07 +// msgType in notifyCallback and dataCallback functions +enum { + CAMERA_MSG_ERROR = 0, + CAMERA_MSG_SHUTTER, + CAMERA_MSG_FOCUS, + CAMERA_MSG_ZOOM, + CAMERA_MSG_PREVIEW_FRAME, + CAMERA_MSG_VIDEO_FRAME, + CAMERA_MSG_POSTVIEW_FRAME, + CAMERA_MSG_RAW_IMAGE, + CAMERA_MSG_COMPRESSED_IMAGE +}; + +// camera fatal errors +enum { + CAMERA_ERROR_UKNOWN = 1, + CAMERA_ERROR_SERVER_DIED = 100 +}; + class ICameraService; class ICamera; class Surface; class Mutex; class String8; -typedef void (*shutter_callback)(void *cookie); -typedef void (*frame_callback)(const sp<IMemory>& mem, void *cookie); -typedef void (*autofocus_callback)(bool focused, void *cookie); -typedef void (*error_callback)(status_t err, void *cookie); +// ref-counted object for callbacks +class CameraListener: virtual public RefBase +{ +public: + virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0; + virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr) = 0; +}; class Camera : public BnCameraClient, public IBinder::DeathRecipient { public: // construct a camera client from an existing remote - Camera(const sp<ICamera>& camera); - + static sp<Camera> create(const sp<ICamera>& camera); static sp<Camera> connect(); ~Camera(); void init(); @@ -128,27 +149,19 @@ public: // get preview/capture parameters - key/value pairs String8 getParameters() const; - void setShutterCallback(shutter_callback cb, void *cookie); - void setRawCallback(frame_callback cb, void *cookie); - void setJpegCallback(frame_callback cb, void *cookie); - void setRecordingCallback(frame_callback cb, void *cookie); - void setPreviewCallback(frame_callback cb, void *cookie, int preview_callback_flag = FRAME_CALLBACK_FLAG_NOOP); - void setErrorCallback(error_callback cb, void *cookie); - void setAutoFocusCallback(autofocus_callback cb, void *cookie); + void setListener(const sp<CameraListener>& listener); + void setPreviewCallbackFlags(int preview_callback_flag); // ICameraClient interface - virtual void shutterCallback(); - virtual void rawCallback(const sp<IMemory>& picture); - virtual void jpegCallback(const sp<IMemory>& picture); - virtual void previewCallback(const sp<IMemory>& frame); - virtual void errorCallback(status_t error); - virtual void autoFocusCallback(bool focused); - virtual void recordingCallback(const sp<IMemory>& frame); + virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2); + virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr); sp<ICamera> remote(); private: Camera(); + Camera(const Camera&); + Camera& operator=(const Camera); virtual void binderDied(const wp<IBinder>& who); class DeathNotifier: public IBinder::DeathRecipient @@ -168,20 +181,7 @@ private: sp<ICamera> mCamera; status_t mStatus; - shutter_callback mShutterCallback; - void *mShutterCallbackCookie; - frame_callback mRawCallback; - void *mRawCallbackCookie; - frame_callback mJpegCallback; - void *mJpegCallbackCookie; - frame_callback mPreviewCallback; - void *mPreviewCallbackCookie; - frame_callback mRecordingCallback; - void *mRecordingCallbackCookie; - error_callback mErrorCallback; - void *mErrorCallbackCookie; - autofocus_callback mAutoFocusCallback; - void *mAutoFocusCallbackCookie; + sp<CameraListener> mListener; friend class DeathNotifier; diff --git a/include/ui/ICameraClient.h b/include/ui/ICameraClient.h index 73b951c..c4bdd07 100644 --- a/include/ui/ICameraClient.h +++ b/include/ui/ICameraClient.h @@ -29,13 +29,8 @@ class ICameraClient: public IInterface public: DECLARE_META_INTERFACE(CameraClient); - virtual void shutterCallback() = 0; - virtual void rawCallback(const sp<IMemory>& picture) = 0; - virtual void jpegCallback(const sp<IMemory>& picture) = 0; - virtual void previewCallback(const sp<IMemory>& frame) = 0; - virtual void errorCallback(status_t error) = 0; - virtual void autoFocusCallback(bool focused) = 0; - virtual void recordingCallback(const sp<IMemory>& frame) = 0; + virtual void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) = 0; + virtual void dataCallback(int32_t msgType, const sp<IMemory>& data) = 0; }; diff --git a/include/ui/Point.h b/include/ui/Point.h index dbbad1e..1653120 100644 --- a/include/ui/Point.h +++ b/include/ui/Point.h @@ -31,12 +31,9 @@ public: // because we want the compiler generated versions // Default constructor doesn't initialize the Point - inline Point() - { + inline Point() { } - - inline Point(int _x, int _y) : x(_x), y(_y) - { + inline Point(int x, int y) : x(x), y(y) { } inline bool operator == (const Point& rhs) const { @@ -57,8 +54,8 @@ public: } inline Point& operator - () { - x=-x; - y=-y; + x = -x; + y = -y; return *this; } @@ -73,11 +70,13 @@ public: return *this; } - Point operator + (const Point& rhs) const { - return Point(x+rhs.x, y+rhs.y); + const Point operator + (const Point& rhs) const { + const Point result(x+rhs.x, y+rhs.y); + return result; } - Point operator - (const Point& rhs) const { - return Point(x-rhs.x, y-rhs.y); + const Point operator - (const Point& rhs) const { + const Point result(x-rhs.x, y-rhs.y); + return result; } }; diff --git a/include/ui/Rect.h b/include/ui/Rect.h index d232847..da72944 100644 --- a/include/ui/Rect.h +++ b/include/ui/Rect.h @@ -33,23 +33,16 @@ public: // we don't provide copy-ctor and operator= on purpose // because we want the compiler generated versions - inline Rect() - { + inline Rect() { } - inline Rect(int w, int h) - : left(0), top(0), right(w), bottom(h) - { + : left(0), top(0), right(w), bottom(h) { } - inline Rect(int l, int t, int r, int b) - : left(l), top(t), right(r), bottom(b) - { + : left(l), top(t), right(r), bottom(b) { } - inline Rect(const Point& lt, const Point& rb) - : left(lt.x), top(lt.y), right(rb.x), bottom(rb.y) - { + : left(lt.x), top(lt.y), right(rb.x), bottom(rb.y) { } void makeInvalid(); @@ -78,21 +71,22 @@ public: return bottom-top; } - // returns left-top Point non-const reference, can be assigned - inline Point& leftTop() { - return reinterpret_cast<Point&>(left); + void setLeftTop(const Point& lt) { + left = lt.x; + top = lt.y; } - // returns right bottom non-const reference, can be assigned - inline Point& rightBottom() { - return reinterpret_cast<Point&>(right); + + void setRightBottom(const Point& rb) { + right = rb.x; + bottom = rb.y; } // the following 4 functions return the 4 corners of the rect as Point - inline const Point& leftTop() const { - return reinterpret_cast<const Point&>(left); + Point leftTop() const { + return Point(left, top); } - inline const Point& rightBottom() const { - return reinterpret_cast<const Point&>(right); + Point rightBottom() const { + return Point(right, bottom); } Point rightTop() const { return Point(right, top); @@ -133,8 +127,8 @@ public: Rect& operator -= (const Point& rhs) { return offsetBy(-rhs.x, -rhs.y); } - Rect operator + (const Point& rhs) const; - Rect operator - (const Point& rhs) const; + const Rect operator + (const Point& rhs) const; + const Rect operator - (const Point& rhs) const; void translate(int dx, int dy) { // legacy, don't use. offsetBy(dx, dy); |