APV Encoder: properly initialize frame holders and fix initializations

Bug: 378098743
Test: CodecEncoderTest

Change-Id: I9aad53b4346f5c06c00fee4b1ab758e2334a0bbb
diff --git a/media/codec2/components/apv/C2SoftApvDec.cpp b/media/codec2/components/apv/C2SoftApvDec.cpp
index 0617d06..0064cec 100644
--- a/media/codec2/components/apv/C2SoftApvDec.cpp
+++ b/media/codec2/components/apv/C2SoftApvDec.cpp
@@ -493,10 +493,13 @@
       mOutBufferFlush(nullptr),
       mIvColorformat(IV_YUV_420P),
       mOutputDelay(kDefaultOutputDelay),
+      mHeaderDecoded(false),
+      mOutIndex(0u),
+      mHalPixelFormat(HAL_PIXEL_FORMAT_YV12),
       mWidth(320),
       mHeight(240),
-      mHeaderDecoded(false),
-      mOutIndex(0u) {
+      mSignalledOutputEos(false),
+      mSignalledError(false) {
     oapvdHandle = NULL;
     oapvmHandle = NULL;
     outputCsp = OUTPUT_CSP_NATIVE;
diff --git a/media/codec2/components/apv/C2SoftApvDec.h b/media/codec2/components/apv/C2SoftApvDec.h
index 22bfcff..f5beb8f 100644
--- a/media/codec2/components/apv/C2SoftApvDec.h
+++ b/media/codec2/components/apv/C2SoftApvDec.h
@@ -66,7 +66,7 @@
 
 namespace android {
 
-struct C2SoftApvDec : public SimpleC2Component {
+struct C2SoftApvDec final : public SimpleC2Component {
     class IntfImpl;
 
     C2SoftApvDec(const char* name, c2_node_id_t id, const std::shared_ptr<IntfImpl>& intfImpl);
diff --git a/media/codec2/components/apv/C2SoftApvEnc.cpp b/media/codec2/components/apv/C2SoftApvEnc.cpp
index 999c08d..a61cfd6 100644
--- a/media/codec2/components/apv/C2SoftApvEnc.cpp
+++ b/media/codec2/components/apv/C2SoftApvEnc.cpp
@@ -505,6 +505,8 @@
     mReceivedFrames = 0;
     mReceivedFirstFrame = false;
     mColorFormat = OAPV_CF_PLANAR2;
+    memset(&mInputFrames, 0, sizeof(mInputFrames));
+    memset(&mReconFrames, 0, sizeof(mReconFrames));
     return C2_OK;
 }
 
@@ -512,6 +514,7 @@
     for (int32_t i = 0; i < MAX_NUM_FRMS; i++) {
         if (mInputFrames.frm[i].imgb != nullptr) {
             imgb_release(mInputFrames.frm[i].imgb);
+            mInputFrames.frm[i].imgb = nullptr;
         }
     }
 
diff --git a/media/codec2/components/apv/C2SoftApvEnc.h b/media/codec2/components/apv/C2SoftApvEnc.h
index 445b042..441c663 100644
--- a/media/codec2/components/apv/C2SoftApvEnc.h
+++ b/media/codec2/components/apv/C2SoftApvEnc.h
@@ -31,11 +31,11 @@
 #define APV_QP_MIN 1
 #define APV_QP_MAX 51
 
-struct C2SoftApvEnc : public SimpleC2Component {
+struct C2SoftApvEnc final : public SimpleC2Component {
     class IntfImpl;
 
     C2SoftApvEnc(const char* name, c2_node_id_t id, const std::shared_ptr<IntfImpl>& intfImpl);
-    ~C2SoftApvEnc();
+    virtual ~C2SoftApvEnc();
 
     // From SimpleC2Component
     c2_status_t onInit() override;