ইভেন্ট এবং ফ্রেম বিজ্ঞপ্তি প্রক্রিয়া

Exterior View System (EVS) এর পূর্ববর্তী রিলিজে, IEvsCameraStream ইন্টারফেস শুধুমাত্র ক্যাপচার করা ভিডিও ফ্রেমগুলি সরবরাহ করার জন্য একটি একক কলব্যাক পদ্ধতি সংজ্ঞায়িত করেছিল। যদিও এটি ইভিএস পরিষেবা ক্লায়েন্ট বাস্তবায়নকে সরলীকৃত করেছে, এটি ক্লায়েন্টদের জন্য কোনও স্ট্রিমিং ঘটনা সনাক্ত করা এবং সেইজন্য, সঠিকভাবে পরিচালনা করা কঠিন করে তুলেছে। EVS ডেভেলপমেন্ট অভিজ্ঞতা উন্নত করতে, AOSP-এ এখন স্ট্রিমিং ইভেন্টগুলি সরবরাহ করার জন্য একটি অতিরিক্ত কলব্যাক রয়েছে।

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;
};

এবং, ইভিএস এবং অন্যান্য অ্যান্ড্রয়েড গ্রাফিকাল উপাদানগুলির মধ্যে গ্রাফিক্স বাফারের বিবরণে কোনও ভিন্নতা এড়াতে, android.hardware.graphics.common@1.2 ইন্টারফেস থেকে আমদানি করা HardwareBuffer ব্যবহার করার জন্য BufferDesc পুনরায় সংজ্ঞায়িত করা হয়েছে৷ HardwareBufferHardwareBufferDescription রয়েছে, যা একটি বাফার হ্যান্ডেল সহ Android NDK-এর 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);
};

ফ্রেম কলব্যাক পদ্ধতির একটি নতুন সংস্করণ একাধিক বাফার বর্ণনাকারী প্রদান করার জন্য ডিজাইন করা হয়েছে। অতএব, EVS ক্যামেরা বাস্তবায়ন একক কল দ্বারা একাধিক ফ্রেম ফরোয়ার্ড করতে পারে যদি এটি একাধিক উত্স পরিচালনা করে।

এছাড়াও, স্ট্রীমের সমাপ্তির বিজ্ঞপ্তি দেওয়ার পূর্ববর্তী প্রোটোকল, যা নাল ফ্রেম পাঠাচ্ছিল, সেটিকে অবমূল্যায়ন করা হয়েছে এবং 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();
}

BufferDesc ব্যবহার করুন

AHardwareBuffer_Desc হল Android NDK-এর ডেটা টাইপ যা একটি নেটিভ হার্ডওয়্যার বাফারের প্রতিনিধিত্ব করে যা EGL/OpenGL এবং Vulkan প্রিমটিভের সাথে আবদ্ধ হতে পারে। এটি পূর্ববর্তী EVS BufferDesc থেকে বেশিরভাগ বাফার মেটাডেটা ধারণ করে এবং তাই, এটিকে নতুন BufferDesc সংজ্ঞায় প্রতিস্থাপন করে। যাইহোক, যেহেতু এটি 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;