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

Commit dec8ecd4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Support more input formats" into main

parents 52b7620a 43399105
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ typedef struct {
class ConfigManager final {
  public:
    static std::unique_ptr<ConfigManager> Create();
    static std::unique_ptr<ConfigManager> Create(const std::string path);
    ConfigManager(const ConfigManager&) = delete;
    ConfigManager& operator=(const ConfigManager&) = delete;

@@ -65,6 +66,15 @@ class ConfigManager final {
            UNKNOWN = std::numeric_limits<std::underlying_type_t<DeviceType>>::max(),
        };

        enum class PixelFormat : std::int32_t {
            NV12 = 0,
            NV21 = 1,
            YV12 = 2,
            I420 = 3,

            UNKNOWN = std::numeric_limits<std::underlying_type_t<DeviceType>>::max(),
        };

        CameraInfo() : characteristics(nullptr) {}

        virtual ~CameraInfo();
@@ -82,6 +92,8 @@ class ConfigManager final {

        static DeviceType deviceTypeFromSV(const std::string_view sv);

        static PixelFormat pixelFormatFromSV(const std::string_view sv);

        DeviceType deviceType{DeviceType::NONE};

        /*
@@ -105,6 +117,11 @@ class ConfigManager final {

        /* Camera module characteristics */
        camera_metadata_t* characteristics;

        /* Format of media in a given media container. This field is effective
         * only for DeviceType::VIDEO.
         */
        PixelFormat format;
    };

    class CameraGroupInfo : public CameraInfo {
@@ -272,7 +289,7 @@ class ConfigManager final {
     * @return bool
     *         True if it completes parsing a file successfully.
     */
    bool readConfigDataFromXML() noexcept;
    bool readConfigDataFromXML(const std::string path) noexcept;

    /*
     * read the information of the vehicle
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ class EvsCameraBase : public evs::BnEvsCamera {

    ~EvsCameraBase() override = default;

    virtual std::string getId() = 0;
    virtual void shutdown() = 0;

  protected:
+3 −1
Original line number Diff line number Diff line
@@ -65,7 +65,9 @@ class EvsMockCamera : public EvsCamera {
    ndk::ScopedAStatus setPrimaryClient() override;
    ndk::ScopedAStatus unsetPrimaryClient() override;

    const evs::CameraDesc& getDesc() { return mDescription; }
    std::string getId() override { return mDescription.id; }

    const CameraDesc& getDesc() { return mDescription; }

    static std::shared_ptr<EvsMockCamera> Create(const char* deviceName);
    static std::shared_ptr<EvsMockCamera> Create(
+10 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@
#include <aidl/android/hardware/automotive/evs/ParameterRange.h>
#include <aidl/android/hardware/automotive/evs/Stream.h>
#include <media/NdkMediaExtractor.h>

#include <ui/GraphicBuffer.h>

#include <cstdint>
@@ -70,6 +69,8 @@ class EvsVideoEmulatedCamera : public EvsCamera {
    // Methods from EvsCameraBase follow.
    void shutdown() override;

    std::string getId() override { return mDescription.id; }

    const evs::CameraDesc& getDesc() { return mDescription; }

    static std::shared_ptr<EvsVideoEmulatedCamera> Create(const char* deviceName);
@@ -117,6 +118,10 @@ class EvsVideoEmulatedCamera : public EvsCamera {
    bool postVideoStreamStop_locked(ndk::ScopedAStatus& status,
                                    std::unique_lock<std::mutex>& lck) override;

    int (*mFillBuffer)(const uint8_t* src_y, int src_stride_y, const uint8_t* src_u,
                       int src_stride_u, const uint8_t* src_v, int src_stride_v, uint8_t* dst_argb,
                       int dst_stride_argb, int width, int height);

    // The properties of this camera.
    CameraDesc mDescription = {};

@@ -149,6 +154,10 @@ class EvsVideoEmulatedCamera : public EvsCamera {
    uint64_t mUsage = 0;
    // Bytes per line in the buffers
    uint32_t mStride = 0;
    // Bytes per line in the output buffer
    uint32_t mDstStride = 0;
    // Bytes per line of U/V plane
    uint32_t mUvStride = 0;

    // Camera parameters.
    std::unordered_map<CameraParam, std::shared_ptr<CameraParameterDesc>> mParams;
+40 −12
Original line number Diff line number Diff line
@@ -52,6 +52,25 @@ ConfigManager::CameraInfo::DeviceType ConfigManager::CameraInfo::deviceTypeFromS
    return search == nameToType.end() ? DeviceType::UNKNOWN : search->second;
}

ConfigManager::CameraInfo::PixelFormat ConfigManager::CameraInfo::pixelFormatFromSV(
        const std::string_view sv) {
    using namespace std::string_view_literals;
    static const std::unordered_map<std::string_view, PixelFormat> nameToFormat = {
            // Full resolution Y plane followed by 2x2 subsampled U/V
            // interleaved plane.
            {"NV12"sv, PixelFormat::NV12},
            // Full resolution Y plane followed by 2x2 subsampled V/U
            // interleaved plane.
            {"NV21"sv, PixelFormat::NV21},
            // Full resolution Y plane followed by 2x2 subsampled V plane and then U plane.
            {"YV12"sv, PixelFormat::YV12},
            // Full resolution Y plane followed by 2x2 subsampled U plane and then V plane.
            {"I420"sv, PixelFormat::I420},
    };
    const auto search = nameToFormat.find(sv);
    return search == nameToFormat.end() ? PixelFormat::UNKNOWN : search->second;
}

void ConfigManager::printElementNames(const XMLElement* rootElem, const std::string& prefix) const {
    const XMLElement* curElem = rootElem;

@@ -144,6 +163,10 @@ bool ConfigManager::readCameraDeviceInfo(CameraInfo* aCamera, const XMLElement*
        aCamera->deviceType = CameraInfo::deviceTypeFromSV(typeAttr->Value());
    }

    if (const auto formatAttr = aDeviceElem->FindAttribute("format")) {
        aCamera->format = CameraInfo::pixelFormatFromSV(formatAttr->Value());
    }

    /* size information to allocate camera_metadata_t */
    size_t totalEntries = 0;
    size_t totalDataSize = 0;
@@ -474,20 +497,17 @@ void ConfigManager::readDisplayInfo(const XMLElement* const aDisplayElem) {
    return;
}

bool ConfigManager::readConfigDataFromXML() noexcept {
bool ConfigManager::readConfigDataFromXML(const std::string path) noexcept {
    XMLDocument xmlDoc;

    const int64_t parsingStart = android::elapsedRealtimeNano();

    /* load and parse a configuration file */
    xmlDoc.LoadFile(sConfigOverridePath.data());
    if (xmlDoc.ErrorID() != tinyxml2::XML_SUCCESS) {
        xmlDoc.LoadFile(sConfigDefaultPath.data());
    xmlDoc.LoadFile(path.c_str());
    if (xmlDoc.ErrorID() != tinyxml2::XML_SUCCESS) {
        LOG(ERROR) << "Failed to load and/or parse a configuration file, " << xmlDoc.ErrorStr();
        return false;
    }
    }

    /* retrieve the root element */
    const XMLElement* rootElem = xmlDoc.RootElement();
@@ -644,8 +664,7 @@ bool ConfigManager::readConfigDataFromBinary() {
                    p += count * sizeof(camera_metadata_rational_t);
                    break;
                default:
                    LOG(WARNING) << "Type " << type << " is unknown; "
                                 << "data may be corrupted.";
                    LOG(WARNING) << "Type " << type << " is unknown; " << "data may be corrupted.";
                    break;
            }
        }
@@ -746,8 +765,7 @@ bool ConfigManager::readConfigDataFromBinary() {
                    p += count * sizeof(camera_metadata_rational_t);
                    break;
                default:
                    LOG(WARNING) << "Type " << type << " is unknown; "
                                 << "data may be corrupted.";
                    LOG(WARNING) << "Type " << type << " is unknown; " << "data may be corrupted.";
                    break;
            }
        }
@@ -958,6 +976,16 @@ bool ConfigManager::writeConfigDataToBinary() {
}

std::unique_ptr<ConfigManager> ConfigManager::Create() {
    std::unique_ptr<ConfigManager> mgr = Create(std::string(sConfigOverridePath));
    if (!mgr) {
        LOG(DEBUG) << "A configuration override file does not exist. Use a default file instead.";
        mgr = Create(std::string((sConfigDefaultPath)));
    }

    return mgr;
}

std::unique_ptr<ConfigManager> ConfigManager::Create(const std::string path) {
    std::unique_ptr<ConfigManager> cfgMgr(new ConfigManager());

    /*
@@ -968,7 +996,7 @@ std::unique_ptr<ConfigManager> ConfigManager::Create() {
     * to the filesystem and construct CameraInfo instead; this was
     * evaluated as 10x faster.
     */
    if (!cfgMgr->readConfigDataFromXML()) {
    if (!cfgMgr->readConfigDataFromXML(path)) {
        return nullptr;
    } else {
        return cfgMgr;
Loading