media: fix "prepend-sps-pps-to-idr-frames" behavior

- Add constant.
- ACodec: Check for support only for video encoders, ignore otherwise.
- codec2: fix C2PrependHeaderModeSetting definition.
- CCodec: fail configure if the feature is not supported.
- CCodec: fix mapping between SDK and codec2

Bug: 32746212
Test: atest CtsMediaTestCases:MediaCodecTest#testPrependHeadersToSyncFrames
Change-Id: I8b86b4c8c139d6addbafc1a3558c640b1add42c9
diff --git a/media/codec2/sfplugin/CCodec.cpp b/media/codec2/sfplugin/CCodec.cpp
index 8474ce8..8a2b3fe 100644
--- a/media/codec2/sfplugin/CCodec.cpp
+++ b/media/codec2/sfplugin/CCodec.cpp
@@ -859,11 +859,12 @@
         std::vector<std::unique_ptr<C2Param>> params;
         C2StreamUsageTuning::input usage(0u, 0u);
         C2StreamMaxBufferSizeInfo::input maxInputSize(0u, 0u);
+        C2PrependHeaderModeSetting prepend(PREPEND_HEADER_TO_NONE);
 
         std::initializer_list<C2Param::Index> indices {
         };
         c2_status_t c2err = comp->query(
-                { &usage, &maxInputSize },
+                { &usage, &maxInputSize, &prepend },
                 indices,
                 C2_DONT_BLOCK,
                 &params);
@@ -931,6 +932,16 @@
             }
         }
 
+        int32_t clientPrepend;
+        if ((config->mDomain & Config::IS_VIDEO)
+                && (config->mDomain & Config::IS_ENCODER)
+                && msg->findInt32(KEY_PREPEND_HEADERS_TO_SYNC_FRAMES, &clientPrepend)
+                && clientPrepend
+                && (!prepend || prepend.value != PREPEND_HEADER_TO_ALL_SYNC)) {
+            ALOGE("Failed to set KEY_PREPEND_HEADERS_TO_SYNC_FRAMES");
+            return BAD_VALUE;
+        }
+
         if ((config->mDomain & (Config::IS_VIDEO | Config::IS_IMAGE))) {
             // propagate HDR static info to output format for both encoders and decoders
             // if component supports this info, we will update from component, but only the raw port,
diff --git a/media/codec2/sfplugin/CCodecConfig.cpp b/media/codec2/sfplugin/CCodecConfig.cpp
index ef02e74..428f032 100644
--- a/media/codec2/sfplugin/CCodecConfig.cpp
+++ b/media/codec2/sfplugin/CCodecConfig.cpp
@@ -486,19 +486,31 @@
     add(ConfigMapper(std::string(KEY_FEATURE_) + FEATURE_SecurePlayback,
                      C2_PARAMKEY_SECURE_MODE, "value"));
 
-    add(ConfigMapper("prepend-sps-pps-to-idr-frames",
+    add(ConfigMapper(KEY_PREPEND_HEADERS_TO_SYNC_FRAMES,
                      C2_PARAMKEY_PREPEND_HEADER_MODE, "value")
         .limitTo(D::ENCODER & D::VIDEO)
-        .withMapper([](C2Value v) -> C2Value {
+        .withMappers([](C2Value v) -> C2Value {
             int32_t value;
-            if (v.get(&value) && value) {
-                return C2Value(C2Config::PREPEND_HEADER_TO_ALL_SYNC);
-            } else {
-                return C2Value(C2Config::PREPEND_HEADER_TO_NONE);
+            if (v.get(&value)) {
+                return value ? C2Value(C2Config::PREPEND_HEADER_TO_ALL_SYNC)
+                             : C2Value(C2Config::PREPEND_HEADER_TO_NONE);
             }
+            return C2Value();
+        }, [](C2Value v) -> C2Value {
+            C2Config::prepend_header_mode_t value;
+            using C2ValueType=typename _c2_reduce_enum_to_underlying_type<decltype(value)>::type;
+            if (v.get((C2ValueType *)&value)) {
+                switch (value) {
+                    case C2Config::PREPEND_HEADER_TO_NONE:      return 0;
+                    case C2Config::PREPEND_HEADER_TO_ALL_SYNC:  return 1;
+                    case C2Config::PREPEND_HEADER_ON_CHANGE:    [[fallthrough]];
+                    default:                                    return C2Value();
+                }
+            }
+            return C2Value();
         }));
     // remove when codecs switch to PARAMKEY
-    deprecated(ConfigMapper("prepend-sps-pps-to-idr-frames",
+    deprecated(ConfigMapper(KEY_PREPEND_HEADERS_TO_SYNC_FRAMES,
                             "coding.add-csd-to-sync-frames", "value")
                .limitTo(D::ENCODER & D::VIDEO));
     // convert to timestamp base