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

Commit 25ac507b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add a method to override a master"

parents b96c2eb1 0d0228de
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.hardware.automotive.evs@1.1;

import @1.0::IEvsCamera;
import @1.0::IEvsDisplay;
import @1.0::EvsResult;
import IEvsCameraStream;

@@ -71,6 +72,23 @@ interface IEvsCamera extends @1.0::IEvsCamera {
     */
    setMaster() generates (EvsResult result);

    /**
     * Sets to be a master client forcibly.
     *
     * The client, which owns the display, has a high priority and can take over
     * a master role from other clients without the display.
     *
     * @param  display IEvsDisplay handle.  If a given display is in either
     *                 NOT_VISIBLE, VISIBLE_ON_NEXT_FRAME, or VISIBLE state, the
     *                 calling client is considered as the high priority client
     *                 and therefore allowed to take over a master role from
     *                 existing master client.
     *
     * @return result  EvsResult::OK if a master role is granted.
     *                 EvsResult::INVALID_ARG if a given display handle is null
     *                 or in valid states.
     */
    forceMaster(IEvsDisplay display) generates (EvsResult result);

    /**
     * Retires from a master client role.
+6 −0
Original line number Diff line number Diff line
@@ -264,6 +264,12 @@ Return<EvsResult> EvsCamera::setMaster() {
    return EvsResult::OK;
}

Return<EvsResult> EvsCamera::forceMaster(const sp<IEvsDisplay>& ) {
    // Default implementation does not expect multiple subscribers and therefore
    // return a success code always.
    return EvsResult::OK;
}


Return<EvsResult> EvsCamera::unsetMaster() {
    // Default implementation does not expect multiple subscribers and therefore
+3 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <android/hardware/automotive/evs/1.1/types.h>
#include <android/hardware/automotive/evs/1.1/IEvsCamera.h>
#include <android/hardware/automotive/evs/1.1/IEvsCameraStream.h>
#include <android/hardware/automotive/evs/1.0/IEvsDisplay.h>
#include <ui/GraphicBuffer.h>

#include <thread>
@@ -30,6 +31,7 @@ using IEvsCameraStream_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsCam
using IEvsCameraStream_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsCameraStream;
using ::android::hardware::automotive::evs::V1_0::EvsResult;
using ::android::hardware::automotive::evs::V1_0::CameraDesc;
using ::android::hardware::automotive::evs::V1_0::IEvsDisplay;


namespace android {
@@ -61,6 +63,7 @@ public:
    Return<EvsResult> resumeVideoStream() override;
    Return<EvsResult> doneWithFrame_1_1(const BufferDesc_1_1& buffer) override;
    Return<EvsResult> setMaster() override;
    Return<EvsResult> forceMaster(const sp<IEvsDisplay>& display) override;
    Return<EvsResult> unsetMaster() override;
    Return<void>      setParameter(CameraParam id, int32_t value,
                                   setParameter_cb _hidl_cb) override;
+36 −10
Original line number Diff line number Diff line
@@ -21,11 +21,14 @@

#include <stdio.h>
#include <string.h>
#include <chrono>

#include <android/log.h>
#include <cutils/native_handle.h>
#include <ui/GraphicBuffer.h>

using namespace std::chrono_literals;

FrameHandler::FrameHandler(android::sp <IEvsCamera> pCamera, CameraDesc cameraInfo,
                           android::sp <IEvsDisplay> pDisplay,
                           BufferControlFlag mode) :
@@ -148,7 +151,7 @@ Return<void> FrameHandler::notifyEvent(const EvsEvent& event) {
            ALOGD("Camera parameter 0x%X is changed to 0x%X",
                  mLatestEventDesc.payload[0], mLatestEventDesc.payload[1]);
        } else {
            ALOGD("Received an event 0x%X", mLatestEventDesc.aType);
            ALOGD("Received an event %s", eventToString(mLatestEventDesc.aType));
        }
        mLock.unlock();
        mEventSignal.notify_all();
@@ -339,11 +342,13 @@ void FrameHandler::getFrameDimension(unsigned* width, unsigned* height) {
    }
}

void FrameHandler::waitForEvent(const InfoEventType aTargetEvent,
bool FrameHandler::waitForEvent(const InfoEventType aTargetEvent,
                                InfoEventDesc &eventDesc) {
    // Wait until we get an expected parameter change event.
    std::unique_lock<std::mutex> lock(mLock);
    mEventSignal.wait(lock, [this, aTargetEvent, &eventDesc](){
    auto now = std::chrono::system_clock::now();
    bool result = mEventSignal.wait_until(lock, now + 5s,
        [this, aTargetEvent, &eventDesc](){
            bool flag = mLatestEventDesc.aType == aTargetEvent;
            if (flag) {
                eventDesc.aType = mLatestEventDesc.aType;
@@ -352,6 +357,27 @@ void FrameHandler::waitForEvent(const InfoEventType aTargetEvent,
            }

            return flag;
    });
        }
    );

    return !result;
}

const char *FrameHandler::eventToString(const InfoEventType aType) {
    switch (aType) {
        case InfoEventType::STREAM_STARTED:
            return "STREAM_STARTED";
        case InfoEventType::STREAM_STOPPED:
            return "STREAM_STOPPED";
        case InfoEventType::FRAME_DROPPED:
            return "FRAME_DROPPED";
        case InfoEventType::TIMEOUT:
            return "TIMEOUT";
        case InfoEventType::PARAMETER_CHANGED:
            return "PARAMETER_CHANGED";
        case InfoEventType::MASTER_RELEASED:
            return "MASTER_RELEASED";
        default:
            return "Unknown";
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public:
    bool isRunning();

    void waitForFrameCount(unsigned frameCount);
    void waitForEvent(const InfoEventType aTargetEvent,
    bool waitForEvent(const InfoEventType aTargetEvent,
                            InfoEventDesc &eventDesc);
    void getFramesCounters(unsigned* received, unsigned* displayed);
    void getFrameDimension(unsigned* width, unsigned* height);
@@ -79,6 +79,7 @@ private:

    // Local implementation details
    bool copyBufferContents(const BufferDesc_1_0& tgtBuffer, const BufferDesc_1_1& srcBuffer);
    const char *eventToString(const InfoEventType aType);

    // Values initialized as startup
    android::sp <IEvsCamera>    mCamera;
Loading