status_t PictureThread::waitForAndExecuteMessage()
{
    LOG2("@%s", __FUNCTION__);
    status_t status = NO_ERROR;
    Message msg;
    mMessageQueue.receive(&msg);

    switch (msg.id) {

        case MESSAGE_ID_EXIT:
            status = handleMessageExit();
            break;

        case MESSAGE_ID_ENCODE:
            status = handleMessageEncode(&msg.data.encode);
            break;

        case MESSAGE_ID_FLUSH:
            status = handleMessageFlush();
            break;

        default:
            status = BAD_VALUE;
            break;
    };
    return status;
}
status_t VideoThread::waitForAndExecuteMessage()
{
    LOG2("@%s", __FUNCTION__);
    status_t status = NO_ERROR;
    Message msg;
    mMessageQueue.receive(&msg);

    switch (msg.id) {

    case MESSAGE_ID_EXIT:
        status = handleMessageExit();
        break;

    case MESSAGE_ID_VIDEO:
        status = handleMessageVideo(&msg.data.video);
        break;

    case MESSAGE_ID_FLUSH:
        status = handleMessageFlush();
        break;

    case MESSAGE_ID_SET_SLOWMOTION_RATE:
        status = handleMessageSetSlowMotionRate(&msg.data.setSlowMotionRate);
        break;

    default:
        ALOGE("Invalid message");
        status = BAD_VALUE;
        break;
    };
    return status;
}
void ResultProcessor::messageThreadLoop(void)
{
    HAL_TRACE_CALL(CAMERA_DEBUG_LOG_LEVEL1);

    mThreadRunning = true;
    while (mThreadRunning) {
        status_t status = NO_ERROR;
        Message msg;
        mMessageQueue.receive(&msg);
        PERFORMANCE_HAL_ATRACE_PARAM1("msg", msg.id);
        Camera3Request* request = msg.request;
        switch (msg.id) {
        case MESSAGE_ID_EXIT:
            status = handleMessageExit();
            break;
       case MESSAGE_ID_SHUTTER_DONE:
           status = handleShutterDone(msg);
           break;
       case MESSAGE_ID_METADATA_DONE:
           status = handleMetadataDone(msg);
           break;
       case MESSAGE_ID_BUFFER_DONE:
           status = handleBufferDone(msg);
           break;
       case MESSAGE_ID_REGISTER_REQUEST:
           status = handleRegisterRequest(msg);
           break;
        default:
           status = BAD_VALUE;
           break;
        }
        mMessageQueue.reply(msg.id, status);
    }
}
status_t VideoThread::waitForAndExecuteMessage()
{
    LOG2("@%s", __FUNCTION__);
    status_t status = NO_ERROR;
    Message msg;
    mMessageQueue.receive(&msg);

    switch (msg.id) {

        case MESSAGE_ID_EXIT:
            status = handleMessageExit();
            break;

        case MESSAGE_ID_FLUSH:
            status = handleMessageFlush();
            break;

        case MESSAGE_ID_RELEASE_RECORDING_FRAME:
            status = handleMessageReleaseRecordingFrame(&msg.data.releaseRecordingFrame);
            break;

        case MESSAGE_ID_SET_SLOWMOTION_RATE:
            status = handleMessageSetSlowMotionRate(&msg.data.setSlowMotionRate);
            break;

        case MESSAGE_ID_DEQUEUE_RECORDING:
            status = handleMessageDequeueRecording(&msg.data.dequeueRecording);
            break;

        case MESSAGE_ID_START_RECORDING:
            status = handleMessageStartRecording();
            break;

        case MESSAGE_ID_PUSH_FRAME:
            status = handleMessagePushFrame(&msg.data.pushFrame);
            break;

        case MESSAGE_ID_STOP_RECORDING:
            status = handleMessageStopRecording();
            break;

        default:
            ALOGE("Invalid message");
            status = BAD_VALUE;
            break;
    };
    return status;
}
status_t AAAThread::waitForAndExecuteMessage()
{
    LOG2("@%s", __FUNCTION__);
    status_t status = NO_ERROR;
    Message msg;
    mMessageQueue.receive(&msg);

    if (msg.id != MESSAGE_ID_EXIT && PlatformData::isDisable3A(mCameraId)) {
        if (msg.id == MESSAGE_ID_AUTO_FOCUS)
            mCallbacksThread->autoFocusDone(true);
        mMessageQueue.reply(msg.id, status);
        return status;
    }

    switch (msg.id) {

    case MESSAGE_ID_EXIT:
        status = handleMessageExit();
        break;

    case MESSAGE_ID_NEW_STATS_READY:
        status = handleMessageNewStats(&msg.data.stats);
        break;

    case MESSAGE_ID_ENABLE_AAA:
        status = handleMessageEnable3A();
        break;

    case MESSAGE_ID_AUTO_FOCUS:
        status = handleMessageAutoFocus();
        break;

    case MESSAGE_ID_CANCEL_AUTO_FOCUS:
        status = handleMessageCancelAutoFocus();
        break;

    case MESSAGE_ID_NEW_FRAME:
        status = handleMessageNewFrame(&msg.data.frame);
        break;

    case MESSAGE_ID_ENABLE_AE_LOCK:
        status = handleMessageEnableAeLock(&msg.data.enable);
        break;

    case MESSAGE_ID_ENABLE_AWB_LOCK:
        status = handleMessageEnableAwbLock(&msg.data.enable);
        break;

    case MESSAGE_ID_FLASH_STAGE:
        status = handleMessageFlashStage(&msg.data.flashStage);
        break;

    case MESSAGE_ID_SWITCH_MODE_AND_RATE:
        status = handleMessageSwitchModeAndRate(&msg.data.switchInfo);
        break;

    case MESSAGE_ID_SET_ORIENTATION:
        status = handleMessageSetOrientation(&msg.data.orientation);
        break;

    default:
        status = BAD_VALUE;
        break;
    };
    return status;
}