Codec2: adjust to C2Work structure changes

Bug: 64121714
Change-Id: I1a4a80bc0def673933e2734497db0cefcd034f8b
diff --git a/C2VDAComponent.cpp b/C2VDAComponent.cpp
index ede61ba..ab7ff13 100644
--- a/C2VDAComponent.cpp
+++ b/C2VDAComponent.cpp
@@ -102,8 +102,8 @@
 }
 
 // Mask against 30 bits to avoid (undefined) wraparound on signed integer.
-int32_t frameIndexToBitstreamId(uint64_t frameIndex) {
-    return static_cast<int32_t>(frameIndex & 0x3FFFFFFF);
+int32_t frameIndexToBitstreamId(c2_cntr64_t frameIndex) {
+    return static_cast<int32_t>(frameIndex.peeku() & 0x3FFFFFFF);
 }
 
 const C2String kH264DecoderName = "v4l2.h264.decode";
@@ -578,15 +578,15 @@
     mQueue.pop();
 
     // Send input buffer to VDA for decode.
-    // Use frame_index as bitstreamId.
+    // Use frameIndex as bitstreamId.
     CHECK_EQ(work->input.buffers.size(), 1u);
     C2ConstLinearBlock linearBlock = work->input.buffers.front()->data().linearBlocks().front();
     if (linearBlock.size() > 0) {
-        int32_t bitstreamId = frameIndexToBitstreamId(work->input.ordinal.frame_index);
+        int32_t bitstreamId = frameIndexToBitstreamId(work->input.ordinal.frameIndex);
         sendInputBufferToAccelerator(linearBlock, bitstreamId);
     }
 
-    if (work->input.flags & C2BufferPack::FLAG_END_OF_STREAM) {
+    if (work->input.flags & C2FrameData::FLAG_END_OF_STREAM) {
         mVDAAdaptor->flush();
         mComponentState = ComponentState::DRAINING;
     }
@@ -670,9 +670,10 @@
             info->mGraphicBlock, base::Bind(&C2VDAComponent::returnOutputBuffer,
                                             mWeakThisFactory.GetWeakPtr(), pictureBufferId)));
     work->worklets.front()->output.ordinal = work->input.ordinal;
-    work->worklets_processed = 1u;
+    work->workletsProcessed = 1u;
 
-    int64_t currentTimestamp = base::checked_cast<int64_t>(work->input.ordinal.timestamp);
+    // TODO: this does not work for timestamps as they can wrap around
+    int64_t currentTimestamp = base::checked_cast<int64_t>(work->input.ordinal.timestamp.peek());
     CHECK_GE(currentTimestamp, mLastOutputTimestamp);
     mLastOutputTimestamp = currentTimestamp;
 
@@ -684,19 +685,19 @@
     ALOGV("onDrain");
     EXPECT_STATE_OR_RETURN_ON_ERROR(STARTED);
 
-    // Set input flag as C2BufferPack::FLAG_END_OF_STREAM to the last queued work. If mQueue is
+    // Set input flag as C2FrameData::FLAG_END_OF_STREAM to the last queued work. If mQueue is
     // empty, set to the last work in mPendingWorks and then signal flush immediately.
     if (!mQueue.empty()) {
-        mQueue.back()->input.flags = static_cast<C2BufferPack::flags_t>(
-                mQueue.back()->input.flags | C2BufferPack::FLAG_END_OF_STREAM);
+        mQueue.back()->input.flags = static_cast<C2FrameData::flags_t>(
+                mQueue.back()->input.flags | C2FrameData::FLAG_END_OF_STREAM);
     } else if (!mPendingWorks.empty()) {
         C2Work* work = getPendingWorkLastToFinish();
         if (!work) {
             reportError(C2_CORRUPTED);
             return;
         }
-        mPendingWorks.back()->input.flags = static_cast<C2BufferPack::flags_t>(
-                mPendingWorks.back()->input.flags | C2BufferPack::FLAG_END_OF_STREAM);
+        mPendingWorks.back()->input.flags = static_cast<C2FrameData::flags_t>(
+                mPendingWorks.back()->input.flags | C2FrameData::FLAG_END_OF_STREAM);
         mVDAAdaptor->flush();
         mComponentState = ComponentState::DRAINING;
     } else {
@@ -834,7 +835,7 @@
 C2Work* C2VDAComponent::getPendingWorkByBitstreamId(int32_t bitstreamId) {
     auto workIter = std::find_if(mPendingWorks.begin(), mPendingWorks.end(),
                                  [bitstreamId](const std::unique_ptr<C2Work>& w) {
-                                     return frameIndexToBitstreamId(w->input.ordinal.frame_index) ==
+                                     return frameIndexToBitstreamId(w->input.ordinal.frameIndex) ==
                                             bitstreamId;
                                  });
 
diff --git a/cmds/codec2.cpp b/cmds/codec2.cpp
index e0873b3..9d1e311 100644
--- a/cmds/codec2.cpp
+++ b/cmds/codec2.cpp
@@ -271,7 +271,7 @@
                 mProcessedWork.pop_front();
             }
 
-            if (work->worklets_processed > 0) {
+            if (work->workletsProcessed > 0) {
                 int slot;
                 sp<Fence> fence;
                 std::shared_ptr<C2Buffer> output = work->worklets.front()->output.buffers[0];
@@ -293,10 +293,10 @@
 
                 CHECK_EQ(igbp->attachBuffer(&slot, buffer), OK);
                 ALOGV("attachBuffer slot=%d ts=%lld", slot,
-                      work->worklets.front()->output.ordinal.timestamp * 1000ll);
+                      (work->worklets.front()->output.ordinal.timestamp * 1000ll).peekll());
 
                 IGraphicBufferProducer::QueueBufferInput qbi(
-                        work->worklets.front()->output.ordinal.timestamp * 1000ll, false,
+                        (work->worklets.front()->output.ordinal.timestamp * 1000ll).peekll(), false,
                         HAL_DATASPACE_UNKNOWN, Rect(graphic_block.width(), graphic_block.height()),
                         NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW, 0, Fence::NO_FENCE, 0);
                 IGraphicBufferProducer::QueueBufferOutput qbo;
@@ -316,9 +316,9 @@
             // input buffers should be cleared in component side.
             CHECK(work->input.buffers.empty());
             work->worklets.clear();
-            work->worklets_processed = 0;
+            work->workletsProcessed = 0;
 
-            if (work->input.flags & C2BufferPack::FLAG_END_OF_STREAM) {
+            if (work->input.flags & C2FrameData::FLAG_END_OF_STREAM) {
                 running.store(false);  // stop the thread
             }
 
@@ -371,9 +371,9 @@
                 mQueueCondition.wait_for(l, 100ms);
             }
         }
-        work->input.flags = static_cast<C2BufferPack::flags_t>(0);
+        work->input.flags = static_cast<C2FrameData::flags_t>(0);
         work->input.ordinal.timestamp = timestamp;
-        work->input.ordinal.frame_index = numFrames;
+        work->input.ordinal.frameIndex = numFrames;
 
         // Allocate input buffer.
         std::shared_ptr<C2LinearBlock> block;
diff --git a/tests/C2VDAComponent_test.cpp b/tests/C2VDAComponent_test.cpp
index 8f58c9e..44f6ab2 100644
--- a/tests/C2VDAComponent_test.cpp
+++ b/tests/C2VDAComponent_test.cpp
@@ -376,11 +376,11 @@
                 mProcessedWork.pop_front();
             }
             mFinishedWorkCounts[iteration]++;
-            ALOGV("Output: frame index: %" PRIu64 " result: %d outputs: %zu",
-                  work->input.ordinal.frame_index, work->result,
+            ALOGV("Output: frame index: %llu result: %d outputs: %zu",
+                  work->input.ordinal.frameIndex.peekull(), work->result,
                   work->worklets.front()->output.buffers.size());
 
-            if (work->worklets_processed == 1u) {
+            if (work->workletsProcessed == 1u) {
                 ASSERT_EQ(work->worklets.size(), 1u);
                 ASSERT_EQ(work->worklets.front()->output.buffers.size(), 1u);
                 std::shared_ptr<C2Buffer> output = work->worklets.front()->output.buffers[0];
@@ -394,11 +394,11 @@
             // input buffers should be cleared in component side.
             ASSERT_TRUE(work->input.buffers.empty());
             work->worklets.clear();
-            work->worklets_processed = 0;
+            work->workletsProcessed = 0;
 
-            bool iteration_end = work->input.flags & C2BufferPack::FLAG_END_OF_STREAM;
+            bool iteration_end = work->input.flags & C2FrameData::FLAG_END_OF_STREAM;
             if (iteration == 0 &&
-                work->input.ordinal.frame_index == static_cast<uint64_t>(mFlushAfterWorkIndex)) {
+                work->input.ordinal.frameIndex.peeku() == static_cast<uint64_t>(mFlushAfterWorkIndex)) {
                 ULock l(mFlushDoneLock);
                 mFlushDone = true;
                 mFlushDoneCondition.notify_all();
@@ -470,9 +470,9 @@
                     mQueueCondition.wait_for(l, 100ms);
                 }
             }
-            work->input.flags = static_cast<C2BufferPack::flags_t>(0);
+            work->input.flags = static_cast<C2FrameData::flags_t>(0);
             work->input.ordinal.timestamp = static_cast<uint64_t>(timestamp);
-            work->input.ordinal.frame_index = static_cast<uint64_t>(numWorks);
+            work->input.ordinal.frameIndex = static_cast<uint64_t>(numWorks);
 
             // Allocate input buffer.
             std::shared_ptr<C2LinearBlock> block;
@@ -486,8 +486,9 @@
             work->input.buffers.emplace_back(new C2VDALinearBuffer(std::move(block)));
             work->worklets.clear();
             work->worklets.emplace_back(new C2Worklet);
-            ALOGV("Input: bitstream id: %" PRIu64 " timestamp: %" PRIu64 " size: %zu",
-                  work->input.ordinal.frame_index, work->input.ordinal.timestamp, size);
+            ALOGV("Input: bitstream id: %llu timestamp: %llu size: %zu",
+                  work->input.ordinal.frameIndex.peekull(),
+                  work->input.ordinal.timestamp.peekull(), size);
 
             std::list<std::unique_ptr<C2Work>> items;
             items.push_back(std::move(work));