Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c8fb0a1 authored by Benny Wong's avatar Benny Wong Committed by James Dong
Browse files

Modified the camera HAL interface to use the same generic callback architecture as camera services

parent 1689746b
Loading
Loading
Loading
Loading
+51 −49
Original line number Original line Diff line number Diff line
@@ -33,13 +33,11 @@ CameraHardwareStub::CameraHardwareStub()
                    mRawHeap(0),
                    mRawHeap(0),
                    mFakeCamera(0),
                    mFakeCamera(0),
                    mPreviewFrameSize(0),
                    mPreviewFrameSize(0),
                    mRawPictureCallback(0),
                    mNotifyCb(0),
                    mJpegPictureCallback(0),
                    mDataCb(0),
                    mPictureCallbackCookie(0),
                    mDataCbTimestamp(0),
                    mPreviewCallback(0),
                    mCallbackCookie(0),
                    mPreviewCallbackCookie(0),
                    mMsgEnabled(0),
                    mAutoFocusCallback(0),
                    mAutoFocusCallbackCookie(0),
                    mCurrentPreviewFrame(0)
                    mCurrentPreviewFrame(0)
{
{
    initDefaultParameters();
    initDefaultParameters();
@@ -112,6 +110,36 @@ sp<IMemoryHeap> CameraHardwareStub::getRawHeap() const
    return mRawHeap;
    return mRawHeap;
}
}


void CameraHardwareStub::setCallbacks(notify_callback notify_cb,
                                      data_callback data_cb,
                                      data_callback_timestamp data_cb_timestamp,
                                      void* user)
{
    Mutex::Autolock lock(mLock);
    mNotifyCb = notify_cb;
    mDataCb = data_cb;
    mDataCbTimestamp = data_cb_timestamp;
    mCallbackCookie = user;
}

void CameraHardwareStub::enableMsgType(int32_t msgType)
{
    Mutex::Autolock lock(mLock);
    mMsgEnabled |= msgType;
}

void CameraHardwareStub::disableMsgType(int32_t msgType)
{
    Mutex::Autolock lock(mLock);
    mMsgEnabled &= ~msgType;
}

bool CameraHardwareStub::msgTypeEnabled(int32_t msgType)
{
    Mutex::Autolock lock(mLock);
    return (mMsgEnabled & msgType);
}

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


int CameraHardwareStub::previewThread()
int CameraHardwareStub::previewThread()
@@ -150,7 +178,8 @@ int CameraHardwareStub::previewThread()
        //LOGV("previewThread: generated frame to buffer %d", mCurrentPreviewFrame);
        //LOGV("previewThread: generated frame to buffer %d", mCurrentPreviewFrame);
        
        
        // Notify the client of a new frame.
        // Notify the client of a new frame.
        mPreviewCallback(buffer, mPreviewCallbackCookie);
        if (mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME)
            mDataCb(CAMERA_MSG_PREVIEW_FRAME, buffer, mCallbackCookie);
    
    
        // Advance the buffer pointer.
        // Advance the buffer pointer.
        mCurrentPreviewFrame = (mCurrentPreviewFrame + 1) % kBufferCount;
        mCurrentPreviewFrame = (mCurrentPreviewFrame + 1) % kBufferCount;
@@ -162,15 +191,13 @@ int CameraHardwareStub::previewThread()
    return NO_ERROR;
    return NO_ERROR;
}
}


status_t CameraHardwareStub::startPreview(preview_callback cb, void* user)
status_t CameraHardwareStub::startPreview()
{
{
    Mutex::Autolock lock(mLock);
    Mutex::Autolock lock(mLock);
    if (mPreviewThread != 0) {
    if (mPreviewThread != 0) {
        // already running
        // already running
        return INVALID_OPERATION;
        return INVALID_OPERATION;
    }
    }
    mPreviewCallback = cb;
    mPreviewCallbackCookie = user;
    mPreviewThread = new PreviewThread(this);
    mPreviewThread = new PreviewThread(this);
    return NO_ERROR;
    return NO_ERROR;
}
}
@@ -197,7 +224,7 @@ bool CameraHardwareStub::previewEnabled() {
    return mPreviewThread != 0;
    return mPreviewThread != 0;
}
}


status_t CameraHardwareStub::startRecording(recording_callback cb, void* user)
status_t CameraHardwareStub::startRecording()
{
{
    return UNKNOWN_ERROR;
    return UNKNOWN_ERROR;
}
}
@@ -225,25 +252,14 @@ int CameraHardwareStub::beginAutoFocusThread(void *cookie)


int CameraHardwareStub::autoFocusThread()
int CameraHardwareStub::autoFocusThread()
{
{
    if (mAutoFocusCallback != NULL) {
    if (mMsgEnabled & CAMERA_MSG_FOCUS)
        mAutoFocusCallback(true, mAutoFocusCallbackCookie);
        mNotifyCb(CAMERA_MSG_FOCUS, true, 0, mCallbackCookie);
        mAutoFocusCallback = NULL;
    return NO_ERROR;
    return NO_ERROR;
}
}
    return UNKNOWN_ERROR;
}


status_t CameraHardwareStub::autoFocus(autofocus_callback af_cb,
status_t CameraHardwareStub::autoFocus()
                                       void *user)
{
{
    Mutex::Autolock lock(mLock);
    Mutex::Autolock lock(mLock);

    if (mAutoFocusCallback != NULL) {
        return mAutoFocusCallback == af_cb ? NO_ERROR : INVALID_OPERATION;
    }

    mAutoFocusCallback = af_cb;
    mAutoFocusCallbackCookie = user;
    if (createThread(beginAutoFocusThread, this) == false)
    if (createThread(beginAutoFocusThread, this) == false)
        return UNKNOWN_ERROR;
        return UNKNOWN_ERROR;
    return NO_ERROR;
    return NO_ERROR;
@@ -257,10 +273,10 @@ status_t CameraHardwareStub::autoFocus(autofocus_callback af_cb,


int CameraHardwareStub::pictureThread()
int CameraHardwareStub::pictureThread()
{
{
    if (mShutterCallback)
    if (mMsgEnabled & CAMERA_MSG_SHUTTER)
        mShutterCallback(mPictureCallbackCookie);
        mNotifyCb(CAMERA_MSG_SHUTTER, 0, 0, mCallbackCookie);


    if (mRawPictureCallback) {
    if (mMsgEnabled & CAMERA_MSG_RAW_IMAGE) {
        //FIXME: use a canned YUV image!
        //FIXME: use a canned YUV image!
        // In the meantime just make another fake camera picture.
        // In the meantime just make another fake camera picture.
        int w, h;
        int w, h;
@@ -268,42 +284,28 @@ int CameraHardwareStub::pictureThread()
        sp<MemoryBase> mem = new MemoryBase(mRawHeap, 0, w * 2 * h);
        sp<MemoryBase> mem = new MemoryBase(mRawHeap, 0, w * 2 * h);
        FakeCamera cam(w, h);
        FakeCamera cam(w, h);
        cam.getNextFrameAsYuv422((uint8_t *)mRawHeap->base());
        cam.getNextFrameAsYuv422((uint8_t *)mRawHeap->base());
        if (mRawPictureCallback)
        mDataCb(CAMERA_MSG_RAW_IMAGE, mem, mCallbackCookie);
            mRawPictureCallback(mem, mPictureCallbackCookie);
    }
    }


    if (mJpegPictureCallback) {
    if (mMsgEnabled & CAMERA_MSG_COMPRESSED_IMAGE) {
        sp<MemoryHeapBase> heap = new MemoryHeapBase(kCannedJpegSize);
        sp<MemoryHeapBase> heap = new MemoryHeapBase(kCannedJpegSize);
        sp<MemoryBase> mem = new MemoryBase(heap, 0, kCannedJpegSize);
        sp<MemoryBase> mem = new MemoryBase(heap, 0, kCannedJpegSize);
        memcpy(heap->base(), kCannedJpeg, kCannedJpegSize);
        memcpy(heap->base(), kCannedJpeg, kCannedJpegSize);
        if (mJpegPictureCallback)
        mDataCb(CAMERA_MSG_COMPRESSED_IMAGE, mem, mCallbackCookie);
            mJpegPictureCallback(mem, mPictureCallbackCookie);
    }
    }
    return NO_ERROR;
    return NO_ERROR;
}
}


status_t CameraHardwareStub::takePicture(shutter_callback shutter_cb,
status_t CameraHardwareStub::takePicture()
                                         raw_callback raw_cb,
                                         jpeg_callback jpeg_cb,
                                         void* user)
{
{
    stopPreview();
    stopPreview();
    mShutterCallback = shutter_cb;
    mRawPictureCallback = raw_cb;
    mJpegPictureCallback = jpeg_cb;
    mPictureCallbackCookie = user;
    if (createThread(beginPictureThread, this) == false)
    if (createThread(beginPictureThread, this) == false)
        return -1;
        return -1;
    return NO_ERROR;
    return NO_ERROR;
}
}


status_t CameraHardwareStub::cancelPicture(bool cancel_shutter,
status_t CameraHardwareStub::cancelPicture()
                                           bool cancel_raw,
                                           bool cancel_jpeg)
{
{
    if (cancel_shutter) mShutterCallback = NULL;
    if (cancel_raw) mRawPictureCallback = NULL;
    if (cancel_jpeg) mJpegPictureCallback = NULL;
    return NO_ERROR;
    return NO_ERROR;
}
}


+20 −19
Original line number Original line Diff line number Diff line
@@ -32,23 +32,27 @@ public:
    virtual sp<IMemoryHeap> getPreviewHeap() const;
    virtual sp<IMemoryHeap> getPreviewHeap() const;
    virtual sp<IMemoryHeap> getRawHeap() const;
    virtual sp<IMemoryHeap> getRawHeap() const;


    virtual status_t    startPreview(preview_callback cb, void* user);
    virtual void        setCallbacks(notify_callback notify_cb,
                                     data_callback data_cb,
                                     data_callback_timestamp data_cb_timestamp,
                                     void* user);

    virtual void        enableMsgType(int32_t msgType);
    virtual void        disableMsgType(int32_t msgType);
    virtual bool        msgTypeEnabled(int32_t msgType);

    virtual status_t    startPreview();
    virtual void        stopPreview();
    virtual void        stopPreview();
    virtual bool        previewEnabled();
    virtual bool        previewEnabled();


    virtual status_t    startRecording(recording_callback cb, void* user);
    virtual status_t    startRecording();
    virtual void        stopRecording();
    virtual void        stopRecording();
    virtual bool        recordingEnabled();
    virtual bool        recordingEnabled();
    virtual void        releaseRecordingFrame(const sp<IMemory>& mem);
    virtual void        releaseRecordingFrame(const sp<IMemory>& mem);


    virtual status_t    autoFocus(autofocus_callback, void *user);
    virtual status_t    autoFocus();
    virtual status_t    takePicture(shutter_callback,
    virtual status_t    takePicture();
                                    raw_callback,
    virtual status_t    cancelPicture();
                                    jpeg_callback,
                                    void* user);
    virtual status_t    cancelPicture(bool cancel_shutter,
                                      bool cancel_raw,
                                      bool cancel_jpeg);
    virtual status_t    dump(int fd, const Vector<String16>& args) const;
    virtual status_t    dump(int fd, const Vector<String16>& args) const;
    virtual status_t    setParameters(const CameraParameters& params);
    virtual status_t    setParameters(const CameraParameters& params);
    virtual CameraParameters  getParameters() const;
    virtual CameraParameters  getParameters() const;
@@ -109,18 +113,15 @@ private:
    bool                mPreviewRunning;
    bool                mPreviewRunning;
    int                 mPreviewFrameSize;
    int                 mPreviewFrameSize;


    shutter_callback    mShutterCallback;
    raw_callback        mRawPictureCallback;
    jpeg_callback       mJpegPictureCallback;
    void                *mPictureCallbackCookie;

    // protected by mLock
    // protected by mLock
    sp<PreviewThread>   mPreviewThread;
    sp<PreviewThread>   mPreviewThread;
    preview_callback    mPreviewCallback;
    void                *mPreviewCallbackCookie;


    autofocus_callback  mAutoFocusCallback;
    notify_callback    mNotifyCb;
    void                *mAutoFocusCallbackCookie;
    data_callback      mDataCb;
    data_callback_timestamp mDataCbTimestamp;
    void               *mCallbackCookie;

    int32_t             mMsgEnabled;


    // only used from PreviewThread
    // only used from PreviewThread
    int                 mCurrentPreviewFrame;
    int                 mCurrentPreviewFrame;
+210 −210

File changed.

Preview size limit exceeded, changes collapsed.

+11 −13
Original line number Original line Diff line number Diff line
@@ -132,22 +132,20 @@ private:


                    status_t    checkPid();
                    status_t    checkPid();


        static      void        recordingCallback(nsecs_t timestamp, const sp<IMemory>& mem, void* user);
        static      void        notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2, void* user);
        static      void        previewCallback(const sp<IMemory>& mem, void* user);
        static      void        dataCallback(int32_t msgType, const sp<IMemory>& dataPtr, void* user);
        static      void        shutterCallback(void *user);
        static      void        dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType,
        static      void        yuvPictureCallback(const sp<IMemory>& mem, void* user);
                                                      const sp<IMemory>& dataPtr, void* user);
        static      void        jpegPictureCallback(const sp<IMemory>& mem, void* user);

        static      void        autoFocusCallback(bool focused, void* user);
        static      sp<Client>  getClientFromCookie(void* user);
        static      sp<Client>  getClientFromCookie(void* user);


                    void        postShutter();
                    void        handlePreviewData(const sp<IMemory>&);
                    void        postRaw(const sp<IMemory>& mem);
                    void        handleShutter();
                    void        postJpeg(const sp<IMemory>& mem);
                    void        handlePostview(const sp<IMemory>&);
                    void        postPreviewFrame(const sp<IMemory>& mem);
                    void        handleRawPicture(const sp<IMemory>&);
                    void        postRecordingFrame(nsecs_t timestamp, const sp<IMemory>& frame);
                    void        handleCompressedPicture(const sp<IMemory>&);

                    void        copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, size_t offset, size_t size);
                    void        copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, size_t offset, size_t size);
                    void        postError(status_t error);
                    void        postAutoFocus(bool focused);


        // camera operation mode
        // camera operation mode
        enum camera_mode {
        enum camera_mode {
+10 −9
Original line number Original line Diff line number Diff line
@@ -66,15 +66,16 @@ namespace android {


// msgType in notifyCallback and dataCallback functions
// msgType in notifyCallback and dataCallback functions
enum {
enum {
    CAMERA_MSG_ERROR = 0,
    CAMERA_MSG_ERROR            = 0x001,
    CAMERA_MSG_SHUTTER,
    CAMERA_MSG_SHUTTER          = 0x002,
    CAMERA_MSG_FOCUS,
    CAMERA_MSG_FOCUS            = 0x004,
    CAMERA_MSG_ZOOM,
    CAMERA_MSG_ZOOM             = 0x008,
    CAMERA_MSG_PREVIEW_FRAME,
    CAMERA_MSG_PREVIEW_FRAME    = 0x010,
    CAMERA_MSG_VIDEO_FRAME,
    CAMERA_MSG_VIDEO_FRAME      = 0x020,
    CAMERA_MSG_POSTVIEW_FRAME,
    CAMERA_MSG_POSTVIEW_FRAME   = 0x040,
    CAMERA_MSG_RAW_IMAGE,
    CAMERA_MSG_RAW_IMAGE        = 0x080,
    CAMERA_MSG_COMPRESSED_IMAGE
    CAMERA_MSG_COMPRESSED_IMAGE = 0x100,
    CAMERA_MSG_ALL_MSGS         = 0x1FF
};
};


// camera fatal errors
// camera fatal errors
Loading