Merge changes from topic "c2-more-adjustments"

* changes:
  Codec2/AUtils: rename nom to num for 'numerator'
  Codec2: C2ParamDescriptor fixes
  Codec2: use std::list only for C2Work/C2Worklet
  Codec2: codec2_vndk is now a shared lib, plus, add internal headers
diff --git a/media/libstagefright/Android.bp b/media/libstagefright/Android.bp
index c5abe9b..106688a 100644
--- a/media/libstagefright/Android.bp
+++ b/media/libstagefright/Android.bp
@@ -126,6 +126,7 @@
         "libutils",
         "libmedia_helper",
         "libstagefright_codec2",
+        "libstagefright_codec2_vndk",
         "libstagefright_foundation",
         "libstagefright_gbs",
         "libstagefright_omx",
@@ -154,8 +155,6 @@
         "libstagefright_esds",
         "libstagefright_id3",
         "libFLAC",
-
-        "libstagefright_codec2_vndk",
     ],
 
     export_shared_lib_headers: [
diff --git a/media/libstagefright/CCodec.cpp b/media/libstagefright/CCodec.cpp
index b058f37..1e0a53f 100644
--- a/media/libstagefright/CCodec.cpp
+++ b/media/libstagefright/CCodec.cpp
@@ -117,7 +117,7 @@
 
     virtual void onWorkDone_nb(
             std::weak_ptr<C2Component> component,
-            std::vector<std::unique_ptr<C2Work>> workItems) override {
+            std::list<std::unique_ptr<C2Work>> workItems) override {
         (void)component;
         sp<CCodec> codec(mCodec.promote());
         if (!codec) {
@@ -601,7 +601,7 @@
     // TODO
 }
 
-void CCodec::onWorkDone(std::vector<std::unique_ptr<C2Work>> &workItems) {
+void CCodec::onWorkDone(std::list<std::unique_ptr<C2Work>> &workItems) {
     Mutexed<std::list<std::unique_ptr<C2Work>>>::Locked queue(mWorkDoneQueue);
     for (std::unique_ptr<C2Work> &item : workItems) {
         queue->push_back(std::move(item));
diff --git a/media/libstagefright/codec2/SimpleC2Component.cpp b/media/libstagefright/codec2/SimpleC2Component.cpp
index c3ae00e..01e9e43 100644
--- a/media/libstagefright/codec2/SimpleC2Component.cpp
+++ b/media/libstagefright/codec2/SimpleC2Component.cpp
@@ -237,8 +237,8 @@
 
 namespace {
 
-std::vector<std::unique_ptr<C2Work>> vec(std::unique_ptr<C2Work> &work) {
-    std::vector<std::unique_ptr<C2Work>> ret;
+std::list<std::unique_ptr<C2Work>> vec(std::unique_ptr<C2Work> &work) {
+    std::list<std::unique_ptr<C2Work>> ret;
     ret.push_back(std::move(work));
     return ret;
 }
diff --git a/media/libstagefright/codec2/include/C2Component.h b/media/libstagefright/codec2/include/C2Component.h
index e023db4..aa0974a 100644
--- a/media/libstagefright/codec2/include/C2Component.h
+++ b/media/libstagefright/codec2/include/C2Component.h
@@ -332,7 +332,7 @@
     class Listener {
     public:
         virtual void onWorkDone_nb(std::weak_ptr<C2Component> component,
-                                std::vector<std::unique_ptr<C2Work>> workItems) = 0;
+                                std::list<std::unique_ptr<C2Work>> workItems) = 0;
 
         virtual void onTripped_nb(std::weak_ptr<C2Component> component,
                                std::vector<std::shared_ptr<C2SettingResult>> settingResult) = 0;
diff --git a/media/libstagefright/codec2/include/C2Param.h b/media/libstagefright/codec2/include/C2Param.h
index e2df62d..4d9f707 100644
--- a/media/libstagefright/codec2/include/C2Param.h
+++ b/media/libstagefright/codec2/include/C2Param.h
@@ -1020,7 +1020,7 @@
      * For vendor-defined components, it can be true even for vendor-defined params,
      * but it is not recommended, in case the component becomes platform-defined.
      */
-    inline bool isRequired() const { return _mIsRequired; }
+    inline bool isRequired() const { return _mAttrib & IS_REQUIRED; }
 
     /**
      * Returns whether this parameter is persistent. This is always true for C2Tuning and C2Setting,
@@ -1029,35 +1029,43 @@
      * current frame and is not assumed to have the same value (or even be present) on subsequent
      * frames, unless it is specified for those frames.
      */
-    inline bool isPersistent() const { return _mIsPersistent; }
+    inline bool isPersistent() const { return _mAttrib & IS_PERSISTENT; }
 
     /// Returns the name of this param.
     /// This defaults to the underlying C2Struct's name, but could be altered for a component.
     inline C2String name() const { return _mName; }
 
-    /// Returns the parameter type
-    /// \todo fix this
-    inline C2Param::Type type() const { return _mType; }
+    /// Returns the parameter index
+    inline C2Param::Index index() const { return _mIndex; }
+
+    /// Returns the indices of parameters that this parameter has a dependency on
+    inline const std::vector<C2Param::Index> &dependencies() const { return mDependencies; }
+
+    // TODO: add more constructors that allow setting dependencies and attributes
 
     template<typename T>
     inline C2ParamDescriptor(bool isRequired, C2StringLiteral name, const T*)
-        : _mIsRequired(isRequired),
-          _mIsPersistent(true),
-          _mName(name),
-          _mType(T::PARAM_TYPE) { }
+        : _mIndex(T::PARAM_TYPE),
+          _mAttrib(IS_PERSISTENT | (isRequired ? IS_REQUIRED : 0)),
+          _mName(name) { }
 
     inline C2ParamDescriptor(
-            bool isRequired, C2StringLiteral name, C2Param::Type type)
-        : _mIsRequired(isRequired),
-          _mIsPersistent(true),
-          _mName(name),
-          _mType(type) { }
+            bool isRequired, C2StringLiteral name, C2Param::Index index)
+        : _mIndex(index),
+          _mAttrib(IS_PERSISTENT | (isRequired ? IS_REQUIRED : 0)),
+          _mName(name) { }
 
 private:
-    const bool _mIsRequired;
-    const bool _mIsPersistent;
+    enum attrib_t : uint32_t {
+        IS_REQUIRED   = 1u << 0,
+        IS_PERSISTENT = 1u << 1,
+    };
+    const C2Param::Index _mIndex;
+    const uint32_t _mAttrib;
     const C2String _mName;
-    const C2Param::Type _mType;
+    std::vector<C2Param::Index> mDependencies;
+
+    friend struct _C2ParamInspector;
 };
 
 /// \ingroup internal
@@ -1300,7 +1308,7 @@
         Primitive min;
         Primitive max;
         Primitive step;
-        Primitive nom;
+        Primitive num;
         Primitive denom;
     } range;
     std::vector<Primitive> values;
@@ -1315,9 +1323,9 @@
           range{min, max, step, (T)1, (T)1} { }
 
     template<typename T>
-    C2FieldSupportedValues(T min, T max, T nom, T den) :
+    C2FieldSupportedValues(T min, T max, T num, T den) :
         type(RANGE),
-        range{min, max, (T)0, nom, den} { }
+        range{min, max, (T)0, num, den} { }
 
     template<typename T>
     C2FieldSupportedValues(bool flags, std::initializer_list<T> list)
diff --git a/media/libstagefright/codec2/include/C2ParamDef.h b/media/libstagefright/codec2/include/C2ParamDef.h
index b5834f2..3691e01 100644
--- a/media/libstagefright/codec2/include/C2ParamDef.h
+++ b/media/libstagefright/codec2/include/C2ParamDef.h
@@ -225,7 +225,7 @@
 #define DEFINE_CAST_OPERATORS(_Type) \
     inline static _Type* From(C2Param *other) { \
         return (_Type*)C2Param::ifSuitable( \
-                other, sizeof(_Type),_Type::PARAM_TYPE, _Type::FLEX_SIZE, \
+                other, sizeof(_Type), _Type::PARAM_TYPE, _Type::FLEX_SIZE, \
                 (_Type::PARAM_TYPE & T::Index::DIR_UNDEFINED) != T::Index::DIR_UNDEFINED); \
     } \
     inline static const _Type* From(const C2Param *other) { \
diff --git a/media/libstagefright/codec2/include/C2Work.h b/media/libstagefright/codec2/include/C2Work.h
index 58a9174..b6c5814 100644
--- a/media/libstagefright/codec2/include/C2Work.h
+++ b/media/libstagefright/codec2/include/C2Work.h
@@ -68,7 +68,7 @@
 
     /// Conflicting parameters or fields with optional suggestions with (optional) suggested values
     /// for any conflicting fields to avoid the conflict.
-    std::list<C2ParamFieldValues> conflicts;
+    std::vector<C2ParamFieldValues> conflicts;
 };
 
 // ================================================================================================
@@ -206,7 +206,7 @@
 struct C2WorkOutline {
 //public:
     C2WorkOrdinalStruct ordinal;
-    std::list<c2_node_id_t> chain;
+    std::vector<c2_node_id_t> chain;
 };
 
 /// @}
diff --git a/media/libstagefright/codec2/tests/C2ComponentInterface_test.cpp b/media/libstagefright/codec2/tests/C2ComponentInterface_test.cpp
index f50af81..7da824b 100644
--- a/media/libstagefright/codec2/tests/C2ComponentInterface_test.cpp
+++ b/media/libstagefright/codec2/tests/C2ComponentInterface_test.cpp
@@ -410,17 +410,17 @@
             // 1. integer geometric case
             // 2. float geometric case
 
-            auto nom = prim2Value(range.nom);
+            auto num = prim2Value(range.num);
             auto denom = prim2Value(range.denom);
 
-            // If both range.nom and range.denom are 1 and step is 0, we should use
+            // If both range.num and range.denom are 1 and step is 0, we should use
             // VALUES, shouldn't we?
-            ASSERT_FALSE(nom == 1 && denom == 1);
+            ASSERT_FALSE(num == 1 && denom == 1);
 
-            // (nom / denom) is not less than 1.
+            // (num / denom) is not less than 1.
             ASSERT_FALSE(denom == 0);
-            ASSERT_LE(denom, nom);
-            for (auto v = rmin; v <= rmax; v = v * nom / denom) {
+            ASSERT_LE(denom, num);
+            for (auto v = rmin; v <= rmax; v = v * num / denom) {
                 validValues->emplace_back(v);
             }
 
@@ -529,7 +529,7 @@
         const C2Param &param,
         const std::vector<std::shared_ptr<C2ParamDescriptor>> &sParams) {
     for (const auto &pd : sParams) {
-        if (param.type() == pd->type().type()) {
+        if (param.type() == pd->index().type()) {
             return true;
         }
     }
diff --git a/media/libstagefright/codec2/tests/C2Param_test.cpp b/media/libstagefright/codec2/tests/C2Param_test.cpp
index d186292..1a29add 100644
--- a/media/libstagefright/codec2/tests/C2Param_test.cpp
+++ b/media/libstagefright/codec2/tests/C2Param_test.cpp
@@ -2622,8 +2622,8 @@
         if (get(sv.range.step, t) != std::is_integral<T>::value) {
             cout << ":" << get(sv.range.step, t);
         }
-        if (get(sv.range.nom, t) != 1 || get(sv.range.denom, t) != 1) {
-            cout << ":" << get(sv.range.nom, t) << "/" << get(sv.range.denom, t);
+        if (get(sv.range.num, t) != 1 || get(sv.range.denom, t) != 1) {
+            cout << ":" << get(sv.range.num, t) << "/" << get(sv.range.denom, t);
         }
         cout << get(sv.range.max, t) << ")";
     }
@@ -2736,7 +2736,7 @@
         cout << "persistent ";
     }
     cout << "struct ";
-    dumpType(pd.type());
+    dumpType(C2Param::Type(pd.index().type()));
     cout << " " << pd.name() << ";" << endl;
 }
 
@@ -2769,7 +2769,7 @@
     Uint32TestInfo t;
     std::vector<C2FieldSupportedValues> values;
     values.push_back(C2FieldSupportedValues(0, 10, 1));  // min, max, step
-    values.push_back(C2FieldSupportedValues(1, 64, 2, 1));  // min, max, nom, den
+    values.push_back(C2FieldSupportedValues(1, 64, 2, 1));  // min, max, num, den
     values.push_back(C2FieldSupportedValues(false, {1, 2, 3}));  // flags, std::initializer_list
     uint32_t val[] = {1, 3, 5, 7};
     std::vector<uint32_t> v(std::begin(val), std::end(val));
diff --git a/media/libstagefright/codec2/vndk/Android.bp b/media/libstagefright/codec2/vndk/Android.bp
index cc79dc0..cdd0488 100644
--- a/media/libstagefright/codec2/vndk/Android.bp
+++ b/media/libstagefright/codec2/vndk/Android.bp
@@ -1,4 +1,14 @@
-cc_library {
+cc_library_headers {
+    name: "libstagefright_codec2_internal",
+
+    export_include_dirs: [
+        "internal",
+    ],
+
+    vendor_available: false,
+}
+
+cc_library_shared {
     name: "libstagefright_codec2_vndk",
 
     srcs: [
@@ -13,6 +23,10 @@
         "include",
     ],
 
+    header_libs:[
+        "libstagefright_codec2_internal",
+    ],
+
     include_dirs: [
         "frameworks/av/media/libstagefright/codec2/include",
         "frameworks/native/include/media/hardware",
diff --git a/media/libstagefright/codec2/vndk/C2ParamInternal.h b/media/libstagefright/codec2/vndk/internal/C2ParamInternal.h
similarity index 88%
rename from media/libstagefright/codec2/vndk/C2ParamInternal.h
rename to media/libstagefright/codec2/vndk/internal/C2ParamInternal.h
index 0f3812a..5bf3009 100644
--- a/media/libstagefright/codec2/vndk/C2ParamInternal.h
+++ b/media/libstagefright/codec2/vndk/internal/C2ParamInternal.h
@@ -22,7 +22,7 @@
 namespace android {
 
 struct C2_HIDE _C2ParamInspector {
-   inline static uint32_t getIndex(const C2ParamField &pf) {
+    inline static uint32_t getIndex(const C2ParamField &pf) {
         return pf._mIndex;
     }
 
@@ -34,6 +34,10 @@
         return pf._mFieldId._mSize;
     }
 
+    inline static uint32_t getAttrib(const C2ParamDescriptor &pd) {
+        return pd._mAttrib;
+    }
+
     inline static
     C2ParamField CreateParamField(C2Param::Index index, uint32_t offset, uint32_t size) {
         return C2ParamField(index, offset, size);
diff --git a/media/libstagefright/codecs/aacdec/Android.bp b/media/libstagefright/codecs/aacdec/Android.bp
index f1ff11b..9931e2d 100644
--- a/media/libstagefright/codecs/aacdec/Android.bp
+++ b/media/libstagefright/codecs/aacdec/Android.bp
@@ -25,7 +25,6 @@
 
     static_libs: [
         "libFraunhoferAAC",
-        "libstagefright_codec2_vndk"
     ],
 
     shared_libs: [
@@ -33,6 +32,7 @@
         "libion",
         "liblog",
         "libstagefright_codec2",
+        "libstagefright_codec2_vndk",
         "libstagefright_foundation",
         "libstagefright_simple_c2component",
         "libutils",
diff --git a/media/libstagefright/codecs/aacenc/Android.bp b/media/libstagefright/codecs/aacenc/Android.bp
index 4caef92..9386c6e 100644
--- a/media/libstagefright/codecs/aacenc/Android.bp
+++ b/media/libstagefright/codecs/aacenc/Android.bp
@@ -22,7 +22,6 @@
 
     static_libs: [
         "libFraunhoferAAC",
-        "libstagefright_codec2_vndk"
     ],
 
     shared_libs: [
@@ -30,6 +29,7 @@
         "libion",
         "liblog",
         "libstagefright_codec2",
+        "libstagefright_codec2_vndk",
         "libstagefright_foundation",
         "libstagefright_simple_c2component",
         "libutils",
diff --git a/media/libstagefright/codecs/avcdec/C2SoftAvcDec.cpp b/media/libstagefright/codecs/avcdec/C2SoftAvcDec.cpp
index 4f64f6e..306d0a5 100644
--- a/media/libstagefright/codecs/avcdec/C2SoftAvcDec.cpp
+++ b/media/libstagefright/codecs/avcdec/C2SoftAvcDec.cpp
@@ -99,7 +99,7 @@
             }
         case C2FieldSupportedValues::RANGE:
             {
-                // TODO: handle step, nom, denom
+                // TODO: handle step, num, denom
                 return Getter<T>::get(supportedValues.range.min) <= value
                         && value <= Getter<T>::get(supportedValues.range.max);
             }
diff --git a/media/libstagefright/codecs/cmds/codec2.cpp b/media/libstagefright/codecs/cmds/codec2.cpp
index ec05d7a..d95bb07 100644
--- a/media/libstagefright/codecs/cmds/codec2.cpp
+++ b/media/libstagefright/codecs/cmds/codec2.cpp
@@ -83,7 +83,7 @@
     ~SimplePlayer();
 
     void onWorkDone(std::weak_ptr<C2Component> component,
-                    std::vector<std::unique_ptr<C2Work>> workItems);
+                    std::list<std::unique_ptr<C2Work>> workItems);
     void onTripped(std::weak_ptr<C2Component> component,
                    std::vector<std::shared_ptr<C2SettingResult>> settingResult);
     void onError(std::weak_ptr<C2Component> component, uint32_t errorCode);
@@ -120,7 +120,7 @@
     virtual ~Listener() = default;
 
     virtual void onWorkDone_nb(std::weak_ptr<C2Component> component,
-                            std::vector<std::unique_ptr<C2Work>> workItems) override {
+                            std::list<std::unique_ptr<C2Work>> workItems) override {
         mThis->onWorkDone(component, std::move(workItems));
     }
 
@@ -174,7 +174,7 @@
 }
 
 void SimplePlayer::onWorkDone(
-        std::weak_ptr<C2Component> component, std::vector<std::unique_ptr<C2Work>> workItems) {
+        std::weak_ptr<C2Component> component, std::list<std::unique_ptr<C2Work>> workItems) {
     ALOGV("SimplePlayer::onWorkDone");
     (void) component;
     ULock l(mProcessedLock);
diff --git a/media/libstagefright/foundation/include/media/stagefright/foundation/AUtils.h b/media/libstagefright/foundation/include/media/stagefright/foundation/AUtils.h
index 255a0f4..af6b357 100644
--- a/media/libstagefright/foundation/include/media/stagefright/foundation/AUtils.h
+++ b/media/libstagefright/foundation/include/media/stagefright/foundation/AUtils.h
@@ -22,28 +22,28 @@
 
 /* T must be integer type, den must not be 0 */
 template<class T>
-inline static const T divRound(const T &nom, const T &den) {
-    if ((nom >= 0) ^ (den >= 0)) {
-        return (nom - den / 2) / den;
+inline static const T divRound(const T &num, const T &den) {
+    if ((num >= 0) ^ (den >= 0)) {
+        return (num - den / 2) / den;
     } else {
-        return (nom + den / 2) / den;
+        return (num + den / 2) / den;
     }
 }
 
-/* == ceil(nom / den). T must be integer type, den must not be 0 */
+/* == ceil(num / den). T must be integer type, den must not be 0 */
 template<class T>
-inline static const T divUp(const T &nom, const T &den) {
+inline static const T divUp(const T &num, const T &den) {
     if (den < 0) {
-        return (nom < 0 ? nom + den + 1 : nom) / den;
+        return (num < 0 ? num + den + 1 : num) / den;
     } else {
-        return (nom < 0 ? nom : nom + den - 1) / den;
+        return (num < 0 ? num : num + den - 1) / den;
     }
 }
 
-/* == ceil(nom / den) * den. T must be integer type, alignment must be positive power of 2 */
+/* == ceil(num / den) * den. T must be integer type, alignment must be positive power of 2 */
 template<class T, class U>
-inline static const T align(const T &nom, const U &den) {
-    return (nom + (T)(den - 1)) & (T)~(den - 1);
+inline static const T align(const T &num, const U &den) {
+    return (num + (T)(den - 1)) & (T)~(den - 1);
 }
 
 template<class T>
diff --git a/media/libstagefright/include/media/stagefright/CCodec.h b/media/libstagefright/include/media/stagefright/CCodec.h
index c689761..fa19c6e 100644
--- a/media/libstagefright/include/media/stagefright/CCodec.h
+++ b/media/libstagefright/include/media/stagefright/CCodec.h
@@ -59,7 +59,7 @@
     virtual void signalRequestIDRFrame() override;
 
     void initiateReleaseIfStuck();
-    void onWorkDone(std::vector<std::unique_ptr<C2Work>> &workItems);
+    void onWorkDone(std::list<std::unique_ptr<C2Work>> &workItems);
 
 protected:
     virtual ~CCodec();