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

Commit 358538ce authored by Igor Murashkin's avatar Igor Murashkin Committed by Android (Google) Code Review
Browse files

Merge changes I25423a2b,I24680f1a into jb-mr2-dev

* changes:
  ProCamera: Add CpuConsumer asynchronous mode support
  Camera: Drop ProCamera connections when a Camera connection happens
parents 48c3f1f9 fb413768
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ LOCAL_SRC_FILES:= \
	ICamera.cpp \
	ICameraClient.cpp \
	ICameraService.cpp \
	ICameraServiceListener.cpp \
	ICameraRecordingProxy.cpp \
	ICameraRecordingProxyListener.cpp \
	IProCameraUser.cpp \
+16 −0
Original line number Diff line number Diff line
@@ -231,6 +231,22 @@ status_t CameraBase<TCam, TCamTraits>::getCameraInfo(int cameraId,
    return cs->getCameraInfo(cameraId, cameraInfo);
}

template <typename TCam, typename TCamTraits>
status_t CameraBase<TCam, TCamTraits>::addServiceListener(
                            const sp<ICameraServiceListener>& listener) {
    const sp<ICameraService>& cs = getCameraService();
    if (cs == 0) return UNKNOWN_ERROR;
    return cs->addListener(listener);
}

template <typename TCam, typename TCamTraits>
status_t CameraBase<TCam, TCamTraits>::removeServiceListener(
                            const sp<ICameraServiceListener>& listener) {
    const sp<ICameraService>& cs = getCameraService();
    if (cs == 0) return UNKNOWN_ERROR;
    return cs->removeListener(listener);
}

template class CameraBase<ProCamera>;
template class CameraBase<Camera>;

+33 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <binder/IServiceManager.h>

#include <camera/ICameraService.h>
#include <camera/ICameraServiceListener.h>
#include <camera/IProCameraUser.h>
#include <camera/IProCameraCallbacks.h>
#include <camera/ICamera.h>
@@ -86,6 +87,24 @@ public:
        remote()->transact(BnCameraService::CONNECT_PRO, data, &reply);
        return interface_cast<IProCameraUser>(reply.readStrongBinder());
    }

    virtual status_t addListener(const sp<ICameraServiceListener>& listener)
    {
        Parcel data, reply;
        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
        data.writeStrongBinder(listener->asBinder());
        remote()->transact(BnCameraService::ADD_LISTENER, data, &reply);
        return reply.readInt32();
    }

    virtual status_t removeListener(const sp<ICameraServiceListener>& listener)
    {
        Parcel data, reply;
        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
        data.writeStrongBinder(listener->asBinder());
        remote()->transact(BnCameraService::REMOVE_LISTENER, data, &reply);
        return reply.readInt32();
    }
};

IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService");
@@ -134,6 +153,20 @@ status_t BnCameraService::onTransact(
            reply->writeStrongBinder(camera->asBinder());
            return NO_ERROR;
        } break;
        case ADD_LISTENER: {
            CHECK_INTERFACE(ICameraService, data, reply);
            sp<ICameraServiceListener> listener =
                interface_cast<ICameraServiceListener>(data.readStrongBinder());
            reply->writeInt32(addListener(listener));
            return NO_ERROR;
        } break;
        case REMOVE_LISTENER: {
            CHECK_INTERFACE(ICameraService, data, reply);
            sp<ICameraServiceListener> listener =
                interface_cast<ICameraServiceListener>(data.readStrongBinder());
            reply->writeInt32(removeListener(listener));
            return NO_ERROR;
        } break;
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
+86 −0
Original line number Diff line number Diff line
/*
**
** Copyright 2013, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

#include <stdint.h>
#include <sys/types.h>

#include <binder/Parcel.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>

#include <camera/ICameraServiceListener.h>

namespace android {

namespace {
    enum {
        STATUS_CHANGED = IBinder::FIRST_CALL_TRANSACTION,
    };
}; // namespace anonymous

class BpCameraServiceListener: public BpInterface<ICameraServiceListener>
{

public:
    BpCameraServiceListener(const sp<IBinder>& impl)
        : BpInterface<ICameraServiceListener>(impl)
    {
    }

    virtual void onStatusChanged(Status status, int32_t cameraId)
    {
        Parcel data, reply;
        data.writeInterfaceToken(
                              ICameraServiceListener::getInterfaceDescriptor());

        data.writeInt32(static_cast<int32_t>(status));
        data.writeInt32(cameraId);

        remote()->transact(STATUS_CHANGED,
                           data,
                           &reply,
                           IBinder::FLAG_ONEWAY);
    }
};

IMPLEMENT_META_INTERFACE(CameraServiceListener,
                         "android.hardware.ICameraServiceListener");

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

status_t BnCameraServiceListener::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
    switch(code) {
        case STATUS_CHANGED: {
            CHECK_INTERFACE(ICameraServiceListener, data, reply);

            Status status = static_cast<Status>(data.readInt32());
            int32_t cameraId = data.readInt32();

            onStatusChanged(status, cameraId);

            return NO_ERROR;
        } break;
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
}

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

}; // namespace android
+20 −1
Original line number Diff line number Diff line
@@ -241,6 +241,17 @@ status_t ProCamera::createStreamCpu(int width, int height, int format,
                                    int heapCount,
                                    /*out*/
                                    sp<CpuConsumer>* cpuConsumer,
                                    int* streamId) {
    return createStreamCpu(width, height, format, heapCount,
                           /*synchronousMode*/true,
                           cpuConsumer, streamId);
}

status_t ProCamera::createStreamCpu(int width, int height, int format,
                                    int heapCount,
                                    bool synchronousMode,
                                    /*out*/
                                    sp<CpuConsumer>* cpuConsumer,
                                    int* streamId)
{
    ALOGV("%s: createStreamW %dx%d (fmt=0x%x)", __FUNCTION__, width, height,
@@ -251,7 +262,7 @@ status_t ProCamera::createStreamCpu(int width, int height, int format,
    sp <IProCameraUser> c = mCamera;
    if (c == 0) return NO_INIT;

    sp<CpuConsumer> cc = new CpuConsumer(heapCount);
    sp<CpuConsumer> cc = new CpuConsumer(heapCount, synchronousMode);
    cc->setName(String8("ProCamera::mCpuConsumer"));

    sp<Surface> stc = new Surface(
@@ -272,6 +283,7 @@ status_t ProCamera::createStreamCpu(int width, int height, int format,

    getStreamInfo(*streamId).cpuStream = true;
    getStreamInfo(*streamId).cpuConsumer = cc;
    getStreamInfo(*streamId).synchronousMode = synchronousMode;
    getStreamInfo(*streamId).stc = stc;
    // for lifetime management
    getStreamInfo(*streamId).frameAvailableListener = frameAvailableListener;
@@ -373,6 +385,13 @@ int ProCamera::dropFrameBuffer(int streamId, int count) {
        return BAD_VALUE;
    }

    if (!si.synchronousMode) {
        ALOGW("%s: No need to drop frames on asynchronous streams,"
              " as asynchronous mode only keeps 1 latest frame around.",
              __FUNCTION__);
        return BAD_VALUE;
    }

    int numDropped = 0;
    for (int i = 0; i < count; ++i) {
        CpuConsumer::LockedBuffer buffer;
Loading