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

Commit 78a81db3 authored by Dave Sparks's avatar Dave Sparks Committed by Android Git Automerger
Browse files

am b9a22122: Merge change I0e09e56f into eclair

Merge commit 'b9a22122b08d749368f90128e29aff035031f8db' into eclair-mr2

* commit 'b9a22122b08d749368f90128e29aff035031f8db':
  Don't callback on NULL client. Bug 2180510.
parents 8995c00a 3f205ecf
Loading
Loading
Loading
Loading
+60 −27
Original line number Original line Diff line number Diff line
@@ -309,7 +309,7 @@ status_t CameraService::Client::connect(const sp<ICameraClient>& client)
            oldClient = mCameraClient;
            oldClient = mCameraClient;


            // did the client actually change?
            // did the client actually change?
            if (client->asBinder() == mCameraClient->asBinder()) {
            if ((mCameraClient != NULL) && (client->asBinder() == mCameraClient->asBinder())) {
                LOGD("Connect to the same client");
                LOGD("Connect to the same client");
                return NO_ERROR;
                return NO_ERROR;
            }
            }
@@ -878,7 +878,10 @@ void CameraService::Client::handleShutter()
        mSurface->unregisterBuffers();
        mSurface->unregisterBuffers();
    }
    }


    mCameraClient->notifyCallback(CAMERA_MSG_SHUTTER, 0, 0);
    sp<ICameraClient> c = mCameraClient;
    if (c != NULL) {
        c->notifyCallback(CAMERA_MSG_SHUTTER, 0, 0);
    }
    mHardware->disableMsgType(CAMERA_MSG_SHUTTER);
    mHardware->disableMsgType(CAMERA_MSG_SHUTTER);


    // It takes some time before yuvPicture callback to be called.
    // It takes some time before yuvPicture callback to be called.
@@ -932,31 +935,38 @@ void CameraService::Client::handlePreviewData(const sp<IMemory>& mem)
        }
        }
    }
    }


    // Is the callback enabled or not?
    // local copy of the callback flags
    if (!(mPreviewCallbackFlag & FRAME_CALLBACK_FLAG_ENABLE_MASK)) {
    int flags = mPreviewCallbackFlag;

    // is callback enabled?
    if (!(flags & FRAME_CALLBACK_FLAG_ENABLE_MASK)) {
        // If the enable bit is off, the copy-out and one-shot bits are ignored
        // If the enable bit is off, the copy-out and one-shot bits are ignored
        LOGV("frame callback is diabled");
        LOGV("frame callback is diabled");
        return;
        return;
    }
    }


    // Is the received frame copied out or not?
    // hold a strong pointer to the client
    if (mPreviewCallbackFlag & FRAME_CALLBACK_FLAG_COPY_OUT_MASK) {
    sp<ICameraClient> c = mCameraClient;
        LOGV("frame is copied out");
        copyFrameAndPostCopiedFrame(heap, offset, size);
    } else {
        LOGV("frame is directly sent out without copying");
        mCameraClient->dataCallback(CAMERA_MSG_PREVIEW_FRAME, mem);
    }


    // Is this is one-shot only?
    // clear callback flags if no client or one-shot mode
    if (mPreviewCallbackFlag & FRAME_CALLBACK_FLAG_ONE_SHOT_MASK) {
    if ((c == NULL) || (mPreviewCallbackFlag & FRAME_CALLBACK_FLAG_ONE_SHOT_MASK)) {
        LOGV("One-shot only, thus clear the bits and disable frame callback");
        LOGV("Disable preview callback");
        mPreviewCallbackFlag &= ~(FRAME_CALLBACK_FLAG_ONE_SHOT_MASK |
        mPreviewCallbackFlag &= ~(FRAME_CALLBACK_FLAG_ONE_SHOT_MASK |
                                FRAME_CALLBACK_FLAG_COPY_OUT_MASK |
                                FRAME_CALLBACK_FLAG_COPY_OUT_MASK |
                                FRAME_CALLBACK_FLAG_ENABLE_MASK);
                                FRAME_CALLBACK_FLAG_ENABLE_MASK);
        // TODO: Shouldn't we use this API for non-overlay hardware as well?
        if (mUseOverlay)
        if (mUseOverlay)
            mHardware->disableMsgType(CAMERA_MSG_PREVIEW_FRAME);
            mHardware->disableMsgType(CAMERA_MSG_PREVIEW_FRAME);
    }
    }

    // Is the received frame copied out or not?
    if (flags & FRAME_CALLBACK_FLAG_COPY_OUT_MASK) {
        LOGV("frame is copied");
        copyFrameAndPostCopiedFrame(c, heap, offset, size);
    } else {
        LOGV("frame is forwarded");
        c->dataCallback(CAMERA_MSG_PREVIEW_FRAME, mem);
    }
}
}


// picture callback - postview image ready
// picture callback - postview image ready
@@ -972,7 +982,10 @@ void CameraService::Client::handlePostview(const sp<IMemory>& mem)
    }
    }
#endif
#endif


    mCameraClient->dataCallback(CAMERA_MSG_POSTVIEW_FRAME, mem);
    sp<ICameraClient> c = mCameraClient;
    if (c != NULL) {
        c->dataCallback(CAMERA_MSG_POSTVIEW_FRAME, mem);
    }
    mHardware->disableMsgType(CAMERA_MSG_POSTVIEW_FRAME);
    mHardware->disableMsgType(CAMERA_MSG_POSTVIEW_FRAME);
}
}


@@ -997,7 +1010,10 @@ void CameraService::Client::handleRawPicture(const sp<IMemory>& mem)
        mSurface->postBuffer(offset);
        mSurface->postBuffer(offset);
    }
    }


    mCameraClient->dataCallback(CAMERA_MSG_RAW_IMAGE, mem);
    sp<ICameraClient> c = mCameraClient;
    if (c != NULL) {
        c->dataCallback(CAMERA_MSG_RAW_IMAGE, mem);
    }
    mHardware->disableMsgType(CAMERA_MSG_RAW_IMAGE);
    mHardware->disableMsgType(CAMERA_MSG_RAW_IMAGE);
}
}


@@ -1014,7 +1030,10 @@ void CameraService::Client::handleCompressedPicture(const sp<IMemory>& mem)
    }
    }
#endif
#endif


    mCameraClient->dataCallback(CAMERA_MSG_COMPRESSED_IMAGE, mem);
    sp<ICameraClient> c = mCameraClient;
    if (c != NULL) {
        c->dataCallback(CAMERA_MSG_COMPRESSED_IMAGE, mem);
    }
    mHardware->disableMsgType(CAMERA_MSG_COMPRESSED_IMAGE);
    mHardware->disableMsgType(CAMERA_MSG_COMPRESSED_IMAGE);
}
}


@@ -1032,7 +1051,10 @@ void CameraService::Client::notifyCallback(int32_t msgType, int32_t ext1, int32_
            client->handleShutter();
            client->handleShutter();
            break;
            break;
        default:
        default:
            client->mCameraClient->notifyCallback(msgType, ext1, ext2);
            sp<ICameraClient> c = client->mCameraClient;
            if (c != NULL) {
                c->notifyCallback(msgType, ext1, ext2);
            }
            break;
            break;
    }
    }


@@ -1053,10 +1075,13 @@ void CameraService::Client::dataCallback(int32_t msgType, const sp<IMemory>& dat
        return;
        return;
    }
    }


    sp<ICameraClient> c = client->mCameraClient;
    if (dataPtr == NULL) {
    if (dataPtr == NULL) {
        LOGE("Null data returned in data callback");
        LOGE("Null data returned in data callback");
        client->mCameraClient->notifyCallback(CAMERA_MSG_ERROR, UNKNOWN_ERROR, 0);
        if (c != NULL) {
        client->mCameraClient->dataCallback(msgType, NULL);
            c->notifyCallback(CAMERA_MSG_ERROR, UNKNOWN_ERROR, 0);
            c->dataCallback(msgType, NULL);
        }
        return;
        return;
    }
    }


@@ -1074,7 +1099,9 @@ void CameraService::Client::dataCallback(int32_t msgType, const sp<IMemory>& dat
            client->handleCompressedPicture(dataPtr);
            client->handleCompressedPicture(dataPtr);
            break;
            break;
        default:
        default:
            client->mCameraClient->dataCallback(msgType, dataPtr);
            if (c != NULL) {
                c->dataCallback(msgType, dataPtr);
            }
            break;
            break;
    }
    }


@@ -1095,15 +1122,20 @@ void CameraService::Client::dataCallbackTimestamp(nsecs_t timestamp, int32_t msg
    if (client == 0) {
    if (client == 0) {
        return;
        return;
    }
    }
    sp<ICameraClient> c = client->mCameraClient;


    if (dataPtr == NULL) {
    if (dataPtr == NULL) {
        LOGE("Null data returned in data with timestamp callback");
        LOGE("Null data returned in data with timestamp callback");
        client->mCameraClient->notifyCallback(CAMERA_MSG_ERROR, UNKNOWN_ERROR, 0);
        if (c != NULL) {
        client->mCameraClient->dataCallbackTimestamp(0, msgType, NULL);
            c->notifyCallback(CAMERA_MSG_ERROR, UNKNOWN_ERROR, 0);
            c->dataCallbackTimestamp(0, msgType, NULL);
        }
        return;
        return;
    }
    }


    client->mCameraClient->dataCallbackTimestamp(timestamp, msgType, dataPtr);
    if (c != NULL) {
        c->dataCallbackTimestamp(timestamp, msgType, dataPtr);
    }


#if DEBUG_CLIENT_REFERENCES
#if DEBUG_CLIENT_REFERENCES
    if (client->getStrongCount() == 1) {
    if (client->getStrongCount() == 1) {
@@ -1161,7 +1193,8 @@ status_t CameraService::Client::sendCommand(int32_t cmd, int32_t arg1, int32_t a
    return mHardware->sendCommand(cmd, arg1, arg2);
    return mHardware->sendCommand(cmd, arg1, arg2);
}
}


void CameraService::Client::copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, size_t offset, size_t size)
void CameraService::Client::copyFrameAndPostCopiedFrame(const sp<ICameraClient>& client,
        const sp<IMemoryHeap>& heap, size_t offset, size_t size)
{
{
    LOGV("copyFrameAndPostCopiedFrame");
    LOGV("copyFrameAndPostCopiedFrame");
    // It is necessary to copy out of pmem before sending this to
    // It is necessary to copy out of pmem before sending this to
@@ -1186,7 +1219,7 @@ void CameraService::Client::copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, si
        LOGE("failed to allocate space for frame callback");
        LOGE("failed to allocate space for frame callback");
        return;
        return;
    }
    }
    mCameraClient->dataCallback(CAMERA_MSG_PREVIEW_FRAME, frame);
    client->dataCallback(CAMERA_MSG_PREVIEW_FRAME, frame);
}
}


status_t CameraService::dump(int fd, const Vector<String16>& args)
status_t CameraService::dump(int fd, const Vector<String16>& args)
+3 −3
Original line number Original line Diff line number Diff line
@@ -23,10 +23,9 @@
#include <ui/CameraHardwareInterface.h>
#include <ui/CameraHardwareInterface.h>
#include <ui/Camera.h>
#include <ui/Camera.h>


class android::MemoryHeapBase;

namespace android {
namespace android {


class MemoryHeapBase;
class MediaPlayer;
class MediaPlayer;


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@@ -151,7 +150,8 @@ private:
                    void        handleRawPicture(const sp<IMemory>&);
                    void        handleRawPicture(const sp<IMemory>&);
                    void        handleCompressedPicture(const sp<IMemory>&);
                    void        handleCompressedPicture(const sp<IMemory>&);


                    void        copyFrameAndPostCopiedFrame(sp<IMemoryHeap> heap, size_t offset, size_t size);
                    void        copyFrameAndPostCopiedFrame(const sp<ICameraClient>& client,
                                    const sp<IMemoryHeap>& heap, size_t offset, size_t size);


        // camera operation mode
        // camera operation mode
        enum camera_mode {
        enum camera_mode {