Codec2: adjust for C2Params and C2Buffer API style fixups

Bug: 64121714
Change-Id: I5c57a3834ccc7ae935e8fde03f0fcf6ec94912f9
diff --git a/C2VDAComponent.cpp b/C2VDAComponent.cpp
index 0c05807..a67a07e 100644
--- a/C2VDAComponent.cpp
+++ b/C2VDAComponent.cpp
@@ -31,19 +31,12 @@
 
 namespace {
 
-// Get index from C2param object. Use index to identify the type of the parameter.
-// Currently there is no wise way to get index from a parameter because index is private.
-uint32_t restoreIndex(const C2Param* param) {
-    return (param->forStream() ? (0x02000000 | ((param->stream() << 17) & 0x01FE0000)) : 0) |
-           param->type();
-}
-
 // Helper function to allocate string type parameters.
 template <class T>
 std::unique_ptr<T> allocUniqueCstr(const char* cstr) {
     size_t len = strlen(cstr);
     std::unique_ptr<T> ptr = T::alloc_unique(len);
-    memcpy(ptr->m.mValue, cstr, len);
+    memcpy(ptr->m.value, cstr, len);
     return ptr;
 }
 
@@ -52,7 +45,7 @@
     T* param = (T*)c2Param;
     return std::unique_ptr<C2SettingResult>(
             new C2SettingResult{C2SettingResult::READ_ONLY,
-                                {C2ParamField(param, &T::mValue), nullptr /* supportedValues */},
+                                {C2ParamField(param, &T::value), nullptr /* supportedValues */},
                                 {} /* conflictedFields */});
 }
 
@@ -149,16 +142,16 @@
     }
 
     // Set default codec profile.
-    mInputCodecProfile.mValue = mSupportedProfiles[0].profile;
+    mInputCodecProfile.value = mSupportedProfiles[0].profile;
 
     auto minVideoSize = mSupportedProfiles[0].min_resolution;
     auto maxVideoSize = mSupportedProfiles[0].max_resolution;
     // Set default output video size.
-    mVideoSize.mWidth = minVideoSize.width();
-    mVideoSize.mHeight = minVideoSize.height();
+    mVideoSize.width = minVideoSize.width();
+    mVideoSize.height = minVideoSize.height();
     // Set default max video size.
-    mMaxVideoSizeHint.mWidth = maxVideoSize.width();
-    mMaxVideoSizeHint.mHeight = maxVideoSize.height();
+    mMaxVideoSizeHint.width = maxVideoSize.width();
+    mMaxVideoSizeHint.height = maxVideoSize.height();
 
     for (const auto& supportedProfile : mSupportedProfiles) {
         mSupportedCodecProfiles.push_back(supportedProfile.profile);
@@ -168,7 +161,7 @@
     }
 
     auto insertParam = [& params = mParams](C2Param* param) {
-        params[restoreIndex(param)] = param;
+        params[param->index()] = param;
     };
 
     insertParam(&mDomainInfo);
@@ -177,25 +170,25 @@
     insertParam(mOutputPortMime.get());
 
     insertParam(&mInputCodecProfile);
-    mSupportedValues.emplace(C2ParamField(&mInputCodecProfile, &C2StreamFormatConfig::mValue),
+    mSupportedValues.emplace(C2ParamField(&mInputCodecProfile, &C2StreamFormatConfig::value),
                              C2FieldSupportedValues(false, mSupportedCodecProfiles));
 
     // TODO(johnylin): min/max resolution may change by chosen profile, we should dynamically change
     // the supported values in the future.
     insertParam(&mVideoSize);
     mSupportedValues.emplace(
-            C2ParamField(&mVideoSize, &C2VideoSizeStreamInfo::mWidth),
+            C2ParamField(&mVideoSize, &C2VideoSizeStreamInfo::width),
             C2FieldSupportedValues(minVideoSize.width(), maxVideoSize.width(), 16));
     mSupportedValues.emplace(
-            C2ParamField(&mVideoSize, &C2VideoSizeStreamInfo::mHeight),
+            C2ParamField(&mVideoSize, &C2VideoSizeStreamInfo::height),
             C2FieldSupportedValues(minVideoSize.height(), maxVideoSize.height(), 16));
 
     insertParam(&mMaxVideoSizeHint);
     mSupportedValues.emplace(
-            C2ParamField(&mMaxVideoSizeHint, &C2MaxVideoSizeHintPortSetting::mWidth),
+            C2ParamField(&mMaxVideoSizeHint, &C2MaxVideoSizeHintPortSetting::width),
             C2FieldSupportedValues(minVideoSize.width(), maxVideoSize.width(), 16));
     mSupportedValues.emplace(
-            C2ParamField(&mMaxVideoSizeHint, &C2MaxVideoSizeHintPortSetting::mHeight),
+            C2ParamField(&mMaxVideoSizeHint, &C2MaxVideoSizeHintPortSetting::height),
             C2FieldSupportedValues(minVideoSize.height(), maxVideoSize.height(), 16));
 
     insertParam(mOutputBlockPools.get());
@@ -235,7 +228,7 @@
             continue;
         }
 
-        uint32_t index = restoreIndex(param);
+        uint32_t index = param->index();
         C2Param* myParam = getParamByIndex(index);
         if (!myParam || (myParam->size() != param->size())) {
             param->invalidate();
@@ -266,7 +259,7 @@
     UNUSED(mayBlock);
     c2_status_t err = C2_OK;
     for (C2Param* const param : params) {
-        uint32_t index = restoreIndex(param);
+        uint32_t index = param->index();
         C2Param* myParam = getParamByIndex(index);
         if (!myParam) {
             // C2_BAD_INDEX should be the lowest priority except for C2_OK.
@@ -274,25 +267,25 @@
             continue;
         }
 
-        if (index == restoreIndex(&mDomainInfo)) {  // read-only
+        if (index == mDomainInfo.index()) {  // read-only
             failures->push_back(reportReadOnlyFailure<decltype(mDomainInfo)>(param));
             err = C2_BAD_VALUE;
             continue;
-        } else if (index == restoreIndex(&mOutputColorFormat)) {  // read-only
+        } else if (index == mOutputColorFormat.index()) {  // read-only
             failures->push_back(reportReadOnlyFailure<decltype(mOutputColorFormat)>(param));
             err = C2_BAD_VALUE;
             continue;
-        } else if (index == restoreIndex(mInputPortMime.get())) {  // read-only
+        } else if (index == mInputPortMime->index()) {  // read-only
             failures->push_back(reportReadOnlyFlexFailure<
                                 std::remove_pointer<decltype(mInputPortMime.get())>::type>(param));
             err = C2_BAD_VALUE;
             continue;
-        } else if (index == restoreIndex(mOutputPortMime.get())) {  // read-only
+        } else if (index == mOutputPortMime->index()) {  // read-only
             failures->push_back(reportReadOnlyFlexFailure<
                                 std::remove_pointer<decltype(mOutputPortMime.get())>::type>(param));
             err = C2_BAD_VALUE;
             continue;
-        } else if (index == restoreIndex(&mInputCodecProfile)) {
+        } else if (index == mInputCodecProfile.index()) {
             std::unique_ptr<C2SettingResult> result =
                     validateUint32Config<decltype(mInputCodecProfile)>(param);
             if (result) {
@@ -300,7 +293,7 @@
                 err = C2_BAD_VALUE;
                 continue;
             }
-        } else if (index == restoreIndex(&mVideoSize)) {
+        } else if (index == mVideoSize.index()) {
             std::unique_ptr<C2SettingResult> result =
                     validateVideoSizeConfig<decltype(mVideoSize)>(param);
             if (result) {
@@ -308,7 +301,7 @@
                 err = C2_BAD_VALUE;
                 continue;
             }
-        } else if (index == restoreIndex(&mMaxVideoSizeHint)) {
+        } else if (index == mMaxVideoSizeHint.index()) {
             std::unique_ptr<C2SettingResult> result =
                     validateVideoSizeConfig<decltype(mMaxVideoSizeHint)>(param);
             if (result) {
@@ -316,7 +309,7 @@
                 err = C2_BAD_VALUE;
                 continue;
             }
-        } else if (index == restoreIndex(mOutputBlockPools.get())) {
+        } else if (index == mOutputBlockPools->index()) {
             // setting output block pools
             // TODO: add support for output-block-pools (this will be done when we move all
             // config to shared ptr)
@@ -376,10 +369,10 @@
         C2Param* c2Param) const {
     T* videoSize = (T*)c2Param;
 
-    C2ParamField fieldWidth(videoSize, &T::mWidth);
+    C2ParamField fieldWidth(videoSize, &T::width);
     const C2FieldSupportedValues& widths = mSupportedValues.at(fieldWidth);
     CHECK_EQ(widths.type, C2FieldSupportedValues::RANGE);
-    if (!findInt32FromPrimitiveValues(videoSize->mWidth, widths)) {
+    if (!findInt32FromPrimitiveValues(videoSize->width, widths)) {
         std::unique_ptr<C2SettingResult> result(new C2SettingResult{
                 C2SettingResult::BAD_VALUE,
                 {fieldWidth, std::make_unique<C2FieldSupportedValues>(
@@ -388,10 +381,10 @@
         return result;
     }
 
-    C2ParamField fieldHeight(videoSize, &T::mHeight);
+    C2ParamField fieldHeight(videoSize, &T::height);
     const C2FieldSupportedValues& heights = mSupportedValues.at(fieldHeight);
     CHECK_EQ(heights.type, C2FieldSupportedValues::RANGE);
-    if (!findInt32FromPrimitiveValues(videoSize->mHeight, heights)) {
+    if (!findInt32FromPrimitiveValues(videoSize->height, heights)) {
         std::unique_ptr<C2SettingResult> result(new C2SettingResult{
                 C2SettingResult::BAD_VALUE,
                 {fieldHeight, std::make_unique<C2FieldSupportedValues>(
@@ -407,9 +400,9 @@
 std::unique_ptr<C2SettingResult> C2VDAComponentIntf::validateUint32Config(C2Param* c2Param) const {
     T* config = (T*)c2Param;
 
-    C2ParamField field(config, &T::mValue);
+    C2ParamField field(config, &T::value);
     const C2FieldSupportedValues& configs = mSupportedValues.at(field);
-    if (!findUint32FromPrimitiveValues(config->mValue, configs)) {
+    if (!findUint32FromPrimitiveValues(config->value, configs)) {
         std::unique_ptr<C2SettingResult> result(new C2SettingResult{
                 C2SettingResult::BAD_VALUE, {field, nullptr}, {} /* conflicts */});
         if (configs.type == C2FieldSupportedValues::RANGE) {
@@ -507,7 +500,7 @@
     CHECK_EQ(mIntf->query_vb(stackParams, {}, C2_DONT_BLOCK, nullptr), C2_OK);
     // The value should be guaranteed to be within media::VideoCodecProfile enum range by component
     // interface.
-    mCodecProfile = static_cast<media::VideoCodecProfile>(codecProfile.mValue);
+    mCodecProfile = static_cast<media::VideoCodecProfile>(codecProfile.value);
     ALOGI("get parameter: mCodecProfile = %d", static_cast<int>(mCodecProfile));
 }
 
@@ -940,7 +933,7 @@
 
     // TODO: lock access to interface
     C2BlockPool::local_id_t poolId = mIntf->mOutputBlockPools->flexCount()
-                                             ? mIntf->mOutputBlockPools->m.mValues[0]
+                                             ? mIntf->mOutputBlockPools->m.values[0]
                                              : C2BlockPool::BASIC_GRAPHIC;
     ALOGI("Using C2BlockPool ID = %" PRIu64 " for allocating output buffers", poolId);
     c2_status_t err;
@@ -956,7 +949,7 @@
     mGraphicBlocks.clear();
     for (size_t i = 0; i < bufferCount; ++i) {
         std::shared_ptr<C2GraphicBlock> block;
-        C2MemoryUsage usage = {C2MemoryUsage::kSoftwareRead, 0};
+        C2MemoryUsage usage = {C2MemoryUsage::CPU_READ, 0};
         err = mOutputBlockPool->fetchGraphicBlock(size.width(), size.height(), pixelFormat, usage,
                                                   &block);
         if (err != C2_OK) {
@@ -979,21 +972,21 @@
     const C2GraphicView& view = info.mGraphicBlock->map().get();
     const uint8_t* const* data = view.data();
     CHECK_NE(data, nullptr);
-    const C2PlaneLayout& layout = view.layout();
+    const C2PlanarLayout& layout = view.layout();
 
     ALOGV("allocate graphic buffer: %p, id: %u, size: %dx%d", info.mGraphicBlock->handle(),
           info.mBlockId, info.mGraphicBlock->width(), info.mGraphicBlock->height());
 
     // get offset from data pointers
-    uint32_t offsets[C2PlaneLayout::MAX_NUM_PLANES];
+    uint32_t offsets[C2PlanarLayout::MAX_NUM_PLANES];
     auto baseAddress = reinterpret_cast<intptr_t>(data[0]);
-    for (uint32_t i = 0; i < layout.mNumPlanes; ++i) {
+    for (uint32_t i = 0; i < layout.numPlanes; ++i) {
         auto planeAddress = reinterpret_cast<intptr_t>(data[i]);
         offsets[i] = static_cast<uint32_t>(planeAddress - baseAddress);
     }
 
-    for (uint32_t i = 0; i < layout.mNumPlanes; ++i) {
-        ALOGV("plane %u: stride: %d, offset: %u", i, layout.mPlanes[i].mRowInc, offsets[i]);
+    for (uint32_t i = 0; i < layout.numPlanes; ++i) {
+        ALOGV("plane %u: stride: %d, offset: %u", i, layout.planes[i].rowInc, offsets[i]);
     }
 
     base::ScopedFD passedHandle(dup(info.mGraphicBlock->handle()->data[0]));
@@ -1003,9 +996,9 @@
         return;
     }
     std::vector<VideoFramePlane> passedPlanes;
-    for (uint32_t i = 0; i < layout.mNumPlanes; ++i) {
-        CHECK_GT(layout.mPlanes[i].mRowInc, 0);
-        passedPlanes.push_back({offsets[i], static_cast<uint32_t>(layout.mPlanes[i].mRowInc)});
+    for (uint32_t i = 0; i < layout.numPlanes; ++i) {
+        CHECK_GT(layout.planes[i].rowInc, 0);
+        passedPlanes.push_back({offsets[i], static_cast<uint32_t>(layout.planes[i].rowInc)});
     }
     info.mHandle = std::move(passedHandle);
     info.mPlanes = std::move(passedPlanes);
@@ -1275,15 +1268,15 @@
 ////////////////////////////////////////////////////////////////////////////////
 // Neglect flexible flag while matching parameter indices.
 #define CASE(paramType)                                                    \
-    case paramType::coreIndex:                                             \
+    case paramType::CORE_INDEX:                                            \
         return std::unique_ptr<C2StructDescriptor>(new C2StructDescriptor{ \
-                paramType::coreIndex,                                      \
-                paramType::fieldList,                                      \
+                paramType::CORE_INDEX,                                     \
+                paramType::FIELD_LIST,                                     \
         })
 
 class C2VDAComponentStore::ParamReflector : public C2ParamReflector {
 public:
-    virtual std::unique_ptr<C2StructDescriptor> describe(C2Param::BaseIndex coreIndex) override {
+    virtual std::unique_ptr<C2StructDescriptor> describe(C2Param::CoreIndex coreIndex) override {
         switch (coreIndex.coreIndex()) {
             //CASE(C2ComponentDomainInfo);  //TODO: known codec2 framework bug
             CASE(C2StreamFormatConfig);
diff --git a/tests/C2VDACompIntf_test.cpp b/tests/C2VDACompIntf_test.cpp
index d538103..2553bc4 100644
--- a/tests/C2VDACompIntf_test.cpp
+++ b/tests/C2VDACompIntf_test.cpp
@@ -24,7 +24,7 @@
 std::unique_ptr<T> alloc_unique_cstr(const char* cstr) {
     size_t len = strlen(cstr);
     std::unique_ptr<T> ptr = T::alloc_unique(len);
-    memcpy(ptr->m.mValue, cstr, len);
+    memcpy(ptr->m.value, cstr, len);
     return ptr;
 }
 
@@ -179,14 +179,14 @@
     T valid;
     for (int32_t h = heightMin; h <= heightMax; h += heightStep) {
         for (int32_t w = widthMin; w <= widthMax; w += widthStep) {
-            valid.mWidth = w;
-            valid.mHeight = h;
+            valid.width = w;
+            valid.height = h;
             {
                 SCOPED_TRACE("testWritableParam");
                 testWritableParam(&valid);
                 if (HasFailure()) {
-                    printf("Failed while config width = %d, height = %d\n", valid.mWidth,
-                           valid.mHeight);
+                    printf("Failed while config width = %d, height = %d\n", valid.width,
+                           valid.height);
                 }
                 if (HasFatalFailure()) return;
             }
@@ -197,37 +197,37 @@
     T invalid;
     // Width or height is smaller than min values
     if (!isUnderflowSubstract(widthMin, widthStep)) {
-        invalid.mWidth = widthMin - widthStep;
-        invalid.mHeight = heightMin;
+        invalid.width = widthMin - widthStep;
+        invalid.height = heightMin;
         testInvalidWritableParam(&invalid);
     }
     if (!isUnderflowSubstract(heightMin, heightStep)) {
-        invalid.mWidth = widthMin;
-        invalid.mHeight = heightMin - heightStep;
+        invalid.width = widthMin;
+        invalid.height = heightMin - heightStep;
         testInvalidWritableParam(&invalid);
     }
 
     // Width or height is bigger than max values
     if (!isOverflowAdd(widthMax, widthStep)) {
-        invalid.mWidth = widthMax + widthStep;
-        invalid.mHeight = heightMax;
+        invalid.width = widthMax + widthStep;
+        invalid.height = heightMax;
         testInvalidWritableParam(&invalid);
     }
     if (!isOverflowAdd(heightMax, heightStep)) {
-        invalid.mWidth = widthMax;
-        invalid.mHeight = heightMax + heightStep;
+        invalid.width = widthMax;
+        invalid.height = heightMax + heightStep;
         testInvalidWritableParam(&invalid);
     }
 
     // Invalid width/height within the range
     if (widthStep != 1) {
-        invalid.mWidth = widthMin + 1;
-        invalid.mHeight = heightMin;
+        invalid.width = widthMin + 1;
+        invalid.height = heightMin;
         testInvalidWritableParam(&invalid);
     }
     if (heightStep != 1) {
-        invalid.mWidth = widthMin;
-        invalid.mHeight = heightMin + 1;
+        invalid.width = widthMin;
+        invalid.height = heightMin + 1;
         testInvalidWritableParam(&invalid);
     }
 }
@@ -282,12 +282,12 @@
     C2VideoSizeStreamInfo::output videoSize;
     videoSize.setStream(0);  // only support single stream
     std::vector<C2FieldSupportedValuesQuery> widthC2FSV = {
-            {C2ParamField(&videoSize, &C2VideoSizeStreamInfo::mWidth),
+            {C2ParamField(&videoSize, &C2VideoSizeStreamInfo::width),
              C2FieldSupportedValuesQuery::CURRENT},
     };
     ASSERT_EQ(C2_OK, mIntf->querySupportedValues_vb(widthC2FSV, C2_DONT_BLOCK));
     std::vector<C2FieldSupportedValuesQuery> heightC2FSV = {
-            {C2ParamField(&videoSize, &C2VideoSizeStreamInfo::mHeight),
+            {C2ParamField(&videoSize, &C2VideoSizeStreamInfo::height),
              C2FieldSupportedValuesQuery::CURRENT},
     };
     ASSERT_EQ(C2_OK, mIntf->querySupportedValues_vb(heightC2FSV, C2_DONT_BLOCK));
@@ -315,12 +315,12 @@
 TEST_F(C2VDACompIntfTest, TestMaxVideoSizeHint) {
     C2MaxVideoSizeHintPortSetting::input maxVideoSizeHint;
     std::vector<C2FieldSupportedValuesQuery> widthC2FSV = {
-            {C2ParamField(&maxVideoSizeHint, &C2MaxVideoSizeHintPortSetting::mWidth),
+            {C2ParamField(&maxVideoSizeHint, &C2MaxVideoSizeHintPortSetting::width),
              C2FieldSupportedValuesQuery::CURRENT},
     };
     mIntf->querySupportedValues_vb(widthC2FSV, C2_DONT_BLOCK);
     std::vector<C2FieldSupportedValuesQuery> heightC2FSV = {
-            {C2ParamField(&maxVideoSizeHint, &C2MaxVideoSizeHintPortSetting::mHeight),
+            {C2ParamField(&maxVideoSizeHint, &C2MaxVideoSizeHintPortSetting::height),
              C2FieldSupportedValuesQuery::CURRENT},
     };
     mIntf->querySupportedValues_vb(heightC2FSV, C2_DONT_BLOCK);
@@ -349,7 +349,7 @@
     C2StreamFormatConfig::input codecProfile;
     codecProfile.setStream(0);  // only support single stream
     std::vector<C2FieldSupportedValuesQuery> profileValues = {
-            {C2ParamField(&codecProfile, &C2StreamFormatConfig::mValue),
+            {C2ParamField(&codecProfile, &C2StreamFormatConfig::value),
              C2FieldSupportedValuesQuery::CURRENT},
     };
     ASSERT_EQ(C2_OK, mIntf->querySupportedValues_vb(profileValues, C2_DONT_BLOCK));
@@ -357,10 +357,10 @@
     ASSERT_EQ(C2_OK, profileValues[0].status);
 
     for (const auto& profile : profileValues[0].values.values) {
-        codecProfile.mValue = profile.u32;
+        codecProfile.value = profile.u32;
         TRACED_FAILURE(testWritableParam(&codecProfile));
     }
-    codecProfile.mValue = 999;  // hard-coded invalid profile number
+    codecProfile.value = 999;  // hard-coded invalid profile number
     TRACED_FAILURE(testInvalidWritableParam(&codecProfile));
 }
 
diff --git a/vndk/C2AllocatorCrosGrallocNyc.cpp b/vndk/C2AllocatorCrosGrallocNyc.cpp
index 9ff26d3..b97aa98 100644
--- a/vndk/C2AllocatorCrosGrallocNyc.cpp
+++ b/vndk/C2AllocatorCrosGrallocNyc.cpp
@@ -25,7 +25,7 @@
     virtual ~C2AllocationCrosGralloc();
 
     virtual c2_status_t map(C2Rect rect, C2MemoryUsage usage, int* fenceFd,
-                            C2PlaneLayout* layout /* nonnull */,
+                            C2PlanarLayout* layout /* nonnull */,
                             uint8_t** addr /* nonnull */) override;
     virtual c2_status_t unmap(C2Fence* fenceFd /* nullable */) override;
     virtual bool isValid() const override;
@@ -63,7 +63,7 @@
     ~Impl() {}
 
     c2_status_t map(C2Rect rect, C2MemoryUsage usage, int* fenceFd,
-                    C2PlaneLayout* layout /* nonnull */, uint8_t** addr /* nonnull */) {
+                    C2PlanarLayout* layout /* nonnull */, uint8_t** addr /* nonnull */) {
         // TODO
         (void)fenceFd;
         if (mLocked) {
@@ -72,7 +72,7 @@
         if (!layout || !addr) {
             return C2_BAD_VALUE;
         }
-        if (usage.mConsumer != C2MemoryUsage::kSoftwareRead) {
+        if (usage.mConsumer != C2MemoryUsage::CPU_READ) {
             return C2_BAD_VALUE;  // always use GRALLOC_USAGE_SW_READ_OFTEN
         }
 
@@ -85,65 +85,74 @@
         // Resolve the format
         struct android_ycbcr ycbcr;
         memset(&ycbcr, 0, sizeof(ycbcr));
-        LOG_ALWAYS_FATAL_IF(mGraphicBuffer->lockYCbCr(C2MemoryUsage::kSoftwareRead, &ycbcr));
-        addr[C2PlaneLayout::Y] = (uint8_t*)ycbcr.y;
-        addr[C2PlaneLayout::U] = (uint8_t*)ycbcr.cb;
-        addr[C2PlaneLayout::V] = (uint8_t*)ycbcr.cr;
-        if (addr[C2PlaneLayout::U] > addr[C2PlaneLayout::V]) {
+        LOG_ALWAYS_FATAL_IF(mGraphicBuffer->lockYCbCr(C2MemoryUsage::CPU_READ, &ycbcr));
+        addr[C2PlanarLayout::PLANE_Y] = (uint8_t*)ycbcr.y;
+        addr[C2PlanarLayout::PLANE_U] = (uint8_t*)ycbcr.cb;
+        addr[C2PlanarLayout::PLANE_V] = (uint8_t*)ycbcr.cr;
+        if (addr[C2PlanarLayout::U] > addr[C2PlanarLayout::V]) {
             // YCrCb format
-            std::swap(addr[C2PlaneLayout::U], addr[C2PlaneLayout::V]);
+            std::swap(addr[C2PlanarLayout::U], addr[C2PlanarLayout::V]);
         }
         ALOGV("Mapped as addr y=%p cb=%p cr=%p, chrome_step=%zu, stride y=%zu c=%zu",
-              addr[C2PlaneLayout::Y], addr[C2PlaneLayout::U], addr[C2PlaneLayout::V],
+              addr[C2PlanarLayout::Y], addr[C2PlanarLayout::U], addr[C2PlanarLayout::V],
               ycbcr.chroma_step, ycbcr.ystride, ycbcr.cstride);
 
         LOG_ALWAYS_FATAL_IF(ycbcr.chroma_step != 1 && ycbcr.chroma_step != 2);
-        layout->mType = C2PlaneLayout::MEDIA_IMAGE_TYPE_YUV;
-        layout->mPlanes[C2PlaneLayout::Y] = {
-                C2PlaneInfo::Y,          // mChannel
-                1,                       // mColInc
-                (int32_t)ycbcr.ystride,  // mRowInc
-                1,                       // mHorizSubsampling
-                1,                       // mVertSubsampling
-                8,                       // mBitDepth
-                8,                       // mAllocatedDepth
+        layout->type = C2PlanarLayout::TYPE_YUV;
+        layout->planes[C2PlanarLayout::PLANE_Y] = {
+                C2PlaneInfo::CHANNEL_Y,  // channel
+                1,                       // colInc
+                (int32_t)ycbcr.ystride,  // rowInc
+                1,                       // colSampling
+                1,                       // rowSampling
+                8,                       // allocatedDepth
+                8,                       // bitDepth
+                0,                       // valueShift
+                C2PlaneInfo::NATIVE,     // endianness
         };
 
         if (ycbcr.chroma_step == 2) {
             // Semi-planar format
-            layout->mNumPlanes = 2;
-            layout->mPlanes[C2PlaneLayout::U] = {
-                    C2PlaneInfo::Cb,             // mChannel
-                    (int32_t)ycbcr.chroma_step,  // mColInc
-                    (int32_t)ycbcr.cstride,      // mRowInc
-                    1,                           // mHorizSubsampling
-                    2,                           // mVertSubsampling
-                    8,                           // mBitDepth
-                    8,                           // mAllocatedDepth
+            layout->numPlanes = 2;
+            layout->planes[C2PlanarLayout::PLANE_U] = {
+                    C2PlaneInfo::CHANNEL_Cb,     // channel
+                    (int32_t)ycbcr.chroma_step,  // colInc
+                    (int32_t)ycbcr.cstride,      // rowInc
+                    1,                           // colSampling
+                    2,                           // rowSampling
+                    8,                           // allocatedDepth
+                    8,                           // bitDepth
+                    0,                           // valueShift
+                    C2PlaneInfo::NATIVE,         // endianness
             };
-            addr[C2PlaneLayout::V] = nullptr;
+            // TODO: this must be a valid plan for TYPE_YUV
+            layout->planes[C2PlanarLayout::PLANE_V] = nullptr;
         } else {
-            layout->mNumPlanes = 3;
-            layout->mPlanes[C2PlaneLayout::U] = {
-                    C2PlaneInfo::Cb,             // mChannel
-                    (int32_t)ycbcr.chroma_step,  // mColInc
-                    (int32_t)ycbcr.cstride,      // mRowInc
-                    2,                           // mHorizSubsampling
-                    2,                           // mVertSubsampling
-                    8,                           // mBitDepth
-                    8,                           // mAllocatedDepth
+            layout->numPlanes = 3;
+            layout->planes[C2PlanarLayout::PLANE_U] = {
+                    C2PlaneInfo::CHANNEL_Cb,     // channel
+                    (int32_t)ycbcr.chroma_step,  // colInc
+                    (int32_t)ycbcr.cstride,      // rowInc
+                    2,                           // colSampling
+                    2,                           // rowSampling
+                    8,                           // allocatedDepth
+                    8,                           // bitDepth
+                    0,                           // valueShift
+                    C2PlaneInfo::NATIVE,         // endianness
             };
-            layout->mPlanes[C2PlaneLayout::V] = {
-                    C2PlaneInfo::Cr,             // mChannel
-                    (int32_t)ycbcr.chroma_step,  // mColInc
-                    (int32_t)ycbcr.cstride,      // mRowInc
-                    2,                           // mHorizSubsampling
-                    2,                           // mVertSubsampling
-                    8,                           // mBitDepth
-                    8,                           // mAllocatedDepth
+            layout->planes[C2PlanarLayout::PLANE_V] = {
+                    C2PlaneInfo::CHANNEL_Cr,     // channel
+                    (int32_t)ycbcr.chroma_step,  // colInc
+                    (int32_t)ycbcr.cstride,      // rowInc
+                    2,                           // colSampling
+                    2,                           // rowSampling
+                    8,                           // allocatedDepth
+                    8,                           // bitDepth
+                    0,                           // valueShift
+                    C2PlaneInfo::NATIVE,         // endianness
             };
         }
-        LOG_ALWAYS_FATAL_IF(layout->mNumPlanes > C2PlaneLayout::MAX_NUM_PLANES);
+        LOG_ALWAYS_FATAL_IF(layout->numPlanes > C2PlanarLayout::MAX_NUM_PLANES);
         mLocked = true;
         return C2_OK;
     }
@@ -175,7 +184,7 @@
 }
 
 c2_status_t C2AllocationCrosGralloc::map(C2Rect rect, C2MemoryUsage usage, int* fenceFd,
-                                         C2PlaneLayout* layout /* nonnull */,
+                                         C2PlanarLayout* layout /* nonnull */,
                                          uint8_t** addr /* nonnull */) {
     return mImpl->map(rect, usage, fenceFd, layout, addr);
 }
@@ -231,12 +240,12 @@
         uint32_t width, uint32_t height, uint32_t format, C2MemoryUsage usage,
         std::shared_ptr<C2GraphicAllocation>* allocation) {
     *allocation = nullptr;
-    if (usage.mConsumer != C2MemoryUsage::kSoftwareRead) {
+    if (usage.mConsumer != C2MemoryUsage::CPU_READ) {
         return C2_BAD_VALUE;  // always use GRALLOC_USAGE_SW_READ_OFTEN
     }
 
     auto alloc = std::make_shared<C2AllocationCrosGralloc>(mAllocator, width, height, format,
-                                                           C2MemoryUsage::kSoftwareRead);
+                                                           C2MemoryUsage::CPU_READ);
 
     c2_status_t ret = alloc->status();
     if (ret == C2_OK) {