घटना और फ़्रेम अधिसूचना तंत्र

एक्सटीरियर व्यू सिस्टम (ईवीएस) की पिछली रिलीज़ में, IEvsCameraStream इंटरफ़ेस ने केवल कैप्चर किए गए वीडियो फ़्रेम वितरित करने के लिए एकल कॉलबैक विधि को परिभाषित किया था। हालांकि इसने ईवीएस सेवा क्लाइंट कार्यान्वयन को सरल बना दिया, लेकिन इसने ग्राहकों के लिए किसी भी स्ट्रीमिंग घटनाओं की पहचान करना और इसलिए, उन्हें ठीक से संभालना भी मुश्किल बना दिया। ईवीएस विकास अनुभव को बढ़ाने के लिए, एओएसपी में अब स्ट्रीमिंग इवेंट वितरित करने के लिए एक अतिरिक्त कॉलबैक शामिल है।

package android.hardware.automotive.evs@1.1;

import @1.0::IEvsCameraStream;

/**
 * Implemented on client side to receive asynchronous video frame deliveries.
 */
interface IEvsCameraStream extends @1.0::IEvsCameraStream {
    /**
     * Receives calls from the HAL each time a video frame is ready for inspection.
     * Buffer handles received by this method must be returned via calls to
     * IEvsCamera::doneWithFrame_1_1(). When the video stream is stopped via a call
     * to IEvsCamera::stopVideoStream(), this callback may continue to happen for
     * some time as the pipeline drains. Each frame must still be returned.
     * When the last frame in the stream has been delivered, STREAM_STOPPED
     * event must be delivered. No further frame deliveries may happen
     * thereafter.
     *
     * @param buffer a buffer descriptor of a delivered image frame.
     */
    oneway deliverFrame_1_1(BufferDesc buffer);

    /**
     * Receives calls from the HAL each time an event happens.
     *
     * @param  event EVS event with possible event information.
     */
    oneway notify(EvsEvent event);
};

यह विधि EvsEventDesc डिलीवर करती है जिसमें तीन फ़ील्ड शामिल हैं:

  • घटना का प्रकार.
  • घटना की उत्पत्ति की पहचान करने के लिए स्ट्रिंग।
  • संभावित घटना की जानकारी रखने के लिए 4x 32-बिट शब्द डेटा।
/**
 * Structure that describes informative events occurred during EVS is streaming
 */
struct EvsEvent {
    /**
     * Type of an informative event
     */
    EvsEventType aType;
    /**
     * Device identifier
     */
    string deviceId;
    /**
     * Possible additional information
     */
    uint32_t[4] payload;
};

और, ईवीएस और अन्य एंड्रॉइड ग्राफिकल घटकों के बीच ग्राफिक्स बफर विवरण में किसी भी विचलन से बचने के लिए, BufferDesc android.hardware.graphics.common@1.2 इंटरफ़ेस से आयातित HardwareBuffer का उपयोग करने के लिए फिर से परिभाषित किया गया है। HardwareBuffer में HardwareBufferDescription शामिल है, जो एक बफर हैंडल के साथ एंड्रॉइड एनडीके के AHardwareBuffer_Desc का HIDL समकक्ष है।

/**
 * HIDL counterpart of AHardwareBuffer_Desc.
 *
 * An AHardwareBuffer_Desc object can be converted to and from a
 * HardwareBufferDescription object by memcpy().
 *
 * @sa +ndk libnativewindow#AHardwareBuffer_Desc.
 */
typedef uint32_t[10] HardwareBufferDescription;

/**
 * HIDL counterpart of AHardwareBuffer.
 *
 * AHardwareBuffer_createFromHandle() can be used to convert a HardwareBuffer
 * object to an AHardwareBuffer object.
 *
 * Conversely, AHardwareBuffer_getNativeHandle() can be used to extract a native
 * handle from an AHardwareBuffer object. Paired with AHardwareBuffer_Desc,
 * AHardwareBuffer_getNativeHandle() can be used to convert between
 * HardwareBuffer and AHardwareBuffer.
 *
 * @sa +ndk libnativewindow#AHardwareBuffer".
 */
struct HardwareBuffer {
    HardwareBufferDescription description;
    handle nativeHandle;
}

/**
 * Structure representing an image buffer through our APIs
 *
 * In addition to the handle to the graphics memory, need to retain
 * the properties of the buffer for easy reference and reconstruction of
 * an ANativeWindowBuffer object on the remote side of API calls.
 * Not least because OpenGL expect an ANativeWindowBuffer* for us as a
 * texture via eglCreateImageKHR().
 */
struct BufferDesc {
    /**
     * HIDL counterpart of AHardwareBuffer_Desc. Please see
     * hardware/interfaces/graphics/common/1.2/types.hal for more details.
     */
    HardwareBuffer buffer;
    /**
     * The size of a pixel in the units of bytes
     */
    uint32_t pixelSize;
    /**
     * Opaque value from driver
     */
    uint32_t bufferId;
    /**
     * Unique identifier of the physical camera device that produces this buffer.
     */
    string deviceId;
    /**
     * Time that this buffer is being filled
     */
    int64_t timestamp;
    /**
     * Frame metadata. This is opaque to EVS manager
     */
    vec<uint8_t> metadata
};

नोट: HardwareBufferDescription दस 32-बिट शब्दों की एक सरणी के रूप में परिभाषित किया गया है। आप इसे AHardwareBuffer_Desc प्रकार के रूप में डालना और सामग्री भरना चाह सकते हैं।

EvsEventDesc enum EvsEventType की एक संरचना है, जो कई स्ट्रीमिंग इवेंट और एक 32-बिट शब्द पेलोड को सूचीबद्ध करता है, जिसमें डेवलपर संभावित अतिरिक्त जानकारी रख सकता है। उदाहरण के लिए, डेवलपर स्ट्रीमिंग त्रुटि ईवेंट के लिए एक त्रुटि कोड डाल सकता है।

/**
 * Types of informative streaming events
 */
enum EvsEventType : uint32_t {
    /**
     * Video stream is started
     */
    STREAM_STARTED = 0,
    /**
     * Video stream is stopped
     */
    STREAM_STOPPED,
    /**
     * Video frame is dropped
     */
    FRAME_DROPPED,
    /**
     * Timeout happens
     */
    TIMEOUT,
    /**
     * Camera parameter is changed; payload contains a changed parameter ID and
     * its value
     */
    PARAMETER_CHANGED,
    /**
     * Master role has become available
     */
    MASTER_RELEASED,
};

फ़्रेम डिलीवरी

एक नए BufferDesc के साथ, IEvsCameraStream सेवा कार्यान्वयन से फ़्रेम और स्ट्रीमिंग ईवेंट प्राप्त करने के लिए नई कॉलबैक विधियां भी पेश करता है।

/**
 * Implemented on client side to receive asynchronous streaming event deliveries.
 */
interface IEvsCameraStream extends @1.0::IEvsCameraStream {
   /**
    * Receives calls from the HAL each time video frames are ready for inspection.
    * Buffer handles received by this method must be returned via calls to
    * IEvsCamera::doneWithFrame_1_1(). When the video stream is stopped via a call
    * to IEvsCamera::stopVideoStream(), this callback may continue to happen for
    * some time as the pipeline drains. Each frame must still be returned.
    * When the last frame in the stream has been delivered, STREAM_STOPPED
    * event must be delivered. No further frame deliveries may happen
    * thereafter.
    *
    * A camera device delivers the same number of frames as number of
    * backing physical camera devices; it means, a physical camera device
    * sends always a single frame and a logical camera device sends multiple
    * frames as many as the number of backing physical camera devices.
    *
    * @param buffer Buffer descriptors of delivered image frames.
    */
   oneway deliverFrame_1_1(vec<BufferDesc> buffer);

   /**
    * Receives calls from the HAL each time an event happens.
    *
    * @param  event EVS event with possible event information.
    */
   oneway notify(EvsEventDesc event);
};

फ़्रेम कॉलबैक पद्धति का एक नया संस्करण एकाधिक बफ़र डिस्क्रिप्टर वितरित करने के लिए डिज़ाइन किया गया है। इसलिए, यदि ईवीएस कैमरा कार्यान्वयन एकाधिक स्रोतों का प्रबंधन करता है तो यह एक ही कॉल द्वारा कई फ़्रेमों को अग्रेषित कर सकता है।

साथ ही, स्ट्रीम के अंत की सूचना देने वाला पिछला प्रोटोकॉल, जो शून्य फ्रेम भेज रहा था, को हटा दिया गया है और STREAM_STOPPED ईवेंट से बदल दिया गया है।

घटना अधिसूचना अनुक्रम आरेख

चित्र 1. घटना अधिसूचना अनुक्रम आरेख

ईवेंट और फ़्रेम अधिसूचना तंत्र का उपयोग करें

क्लाइंट द्वारा कार्यान्वित IEvsCameraStream के संस्करण की पहचान करें

सेवा डाउनकास्ट का प्रयास करके क्लाइंट द्वारा कार्यान्वित आने वाले IEvsCameraStream इंटरफ़ेस के संस्करण की पहचान कर सकती है:

using IEvsCameraStream_1_0 =
    ::android::hardware::automotive::evs::V1_0::IEvsCameraStream;
using IEvsCameraStream_1_1 =
    ::android::hardware::automotive::evs::V1_1::IEvsCameraStream;

Return<EvsResult> EvsV4lCamera::startVideoStream(
    const sp<IEvsCameraStream_1_0>& stream)  {

    IEvsCameraStream_1_0 aStream = stream;
    // Try to downcast. This succeeds if the client implements
    // IEvsCameraStream v1.1.
    IEvsCameraStream_1_1 aStream_1_1 =
        IEvsCameraStream_1_1::castFrom(aStream).withDefault(nullptr);
    if (aStream_1_1 == nullptr) {
        ALOGI("Start a stream for v1.0 client.");
    } else {
        ALOGI("Start a stream for v1.1 client.");
    }

    // Start a video stream
    ...
}

सूचित करें() कॉलबैक

EvsEvent notify() कॉलबैक के माध्यम से पारित किया जाता है और क्लाइंट फिर विवेचक के आधार पर इसके प्रकार की पहचान कर सकता है, जैसा कि नीचे दिखाया गया है:

Return<void> StreamHandler::notify(const EvsEvent& event) {
    ALOGD("Received an event id: %u", event.aType);
    // Handle each received event.
    switch(event.aType) {
        case EvsEventType::ERROR:
            // Do something to handle an error
            ...
            break;
        [More cases]
    }
    return Void();
}

बफ़रडेस्क का प्रयोग करें

AHardwareBuffer_Desc एक देशी हार्डवेयर बफर का प्रतिनिधित्व करने के लिए एंड्रॉइड NDK का डेटा प्रकार है जिसे ईजीएल/ओपनजीएल और वल्कन प्रिमिटिव से जोड़ा जा सकता है। इसमें पिछले EVS बफ़रडेस्क के अधिकांश बफ़र मेटाडेटा शामिल हैं और इसलिए, इसे नई बफ़रडेस्क परिभाषा में प्रतिस्थापित करता है। हालाँकि, चूंकि इसे HIDL इंटरफ़ेस में एक सरणी के रूप में परिभाषित किया गया है, इसलिए सदस्य चर को सीधे अनुक्रमित करना संभव नहीं है। इसके बजाय, आप सरणी को AHardwareBuffer_Desc के प्रकार के रूप में डाल सकते हैं, जैसा कि नीचे दिखाया गया है:

BufferDesc bufDesc = {};
AHardwareBuffer_Desc* pDesc =
    reinterpret_cast<AHardwareBuffer_Desc *>(&bufDesc.buffer.description);
pDesc->width  = mVideo.getWidth();
pDesc->height = mVideo.getHeight();
pDesc->layers = 1;
pDesc->format = mFormat;
pDesc->usage  = mUsage;
pDesc->stride = mStride;
bufDesc_1_1.buffer.nativeHandle = mBuffers[idx].handle;
bufDesc_1_1.bufferId = idx;