Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 442578ec authored by Ray Essick's avatar Ray Essick Committed by Android (Google) Code Review
Browse files

Merge "APV codec plugins refuse to initialize before sdk=36" into main

parents f2be6030 a0c7ca22
Loading
Loading
Loading
Loading
+18 −12
Original line number Diff line number Diff line
@@ -12,23 +12,26 @@ cc_library {
    name: "libcodec2_soft_apvenc",
    defaults: [
        "libcodec2_soft-defaults",
        "libcodec2_soft_sanitize_signed-defaults",
        "libcodec2_soft_sanitize_cfi-defaults",
        "libcodec2_soft_sanitize_signed-defaults",
    ],

    static_libs: [
        "libopenapv",
        "android.media.swcodec.flags-aconfig-cc",
        "libopenapv",
    ],

    srcs: ["C2SoftApvEnc.cpp"],
    srcs: [
        "C2SoftApvEnc.cpp",
        "isAtLeastRelease.cpp",
    ],

    cflags: [
        "-DOAPV_STATIC_DEFINE",
        "-Wno-unused-variable",
        "-Wno-unused-parameter",
        "-Wno-unused-function",
        "-Wno-reorder-ctor",
        "-Wno-unused-function",
        "-Wno-unused-parameter",
        "-Wno-unused-variable",
    ],
}

@@ -37,22 +40,25 @@ cc_library {
    name: "libcodec2_soft_apvdec",
    defaults: [
        "libcodec2_soft-defaults",
        "libcodec2_soft_sanitize_signed-defaults",
        "libcodec2_soft_sanitize_cfi-defaults",
        "libcodec2_soft_sanitize_signed-defaults",
    ],

    static_libs: [
        "libopenapv",
        "android.media.swcodec.flags-aconfig-cc",
        "libopenapv",
    ],

    srcs: ["C2SoftApvDec.cpp"],
    srcs: [
        "C2SoftApvDec.cpp",
        "isAtLeastRelease.cpp",
    ],

    cflags: [
        "-DOAPV_STATIC_DEFINE",
        "-Wno-unused-variable",
        "-Wno-unused-parameter",
        "-Wno-unused-function",
        "-Wno-reorder-ctor",
        "-Wno-unused-function",
        "-Wno-unused-parameter",
        "-Wno-unused-variable",
    ],
}
+8 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <Codec2Mapper.h>
#include <SimpleC2Interface.h>
#include "C2SoftApvDec.h"
#include "isAtLeastRelease.h"

#include <cutils/properties.h>

@@ -1515,6 +1516,13 @@ __attribute__((cfi_canonical_jump_table)) extern "C" ::C2ComponentFactory* Creat
        ALOGV("APV SW Codec is not enabled");
        return nullptr;
    }

    bool enabled = isAtLeastRelease(36, "Baklava");
    ALOGD("isAtLeastRelease(36, Baklava) says enable: %s", enabled ? "yes" : "no");
    if (!enabled) {
        return nullptr;
    }

    return new ::android::C2SoftApvDecFactory();
}

+8 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include <util/C2InterfaceHelper.h>
#include <cmath>
#include "C2SoftApvEnc.h"
#include "isAtLeastRelease.h"

namespace android {

@@ -1403,6 +1404,13 @@ __attribute__((cfi_canonical_jump_table)) extern "C" ::C2ComponentFactory* Creat
        ALOGV("APV SW Codec is not enabled");
        return nullptr;
    }

    bool enabled = isAtLeastRelease(36, "Baklava");
    ALOGD("isAtLeastRelease(36, Baklava) says enable: %s", enabled ? "yes" : "no");
    if (!enabled) {
        return nullptr;
    }

    return new ::android::C2SoftApvEncFactory();
}

+68 −0
Original line number Diff line number Diff line
/*
 * Copyright 2017, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "isAtLeastRelease"

#include <android/api-level.h>
#include <android-base/properties.h>
#include <utils/Log.h>

#include <mutex>
#include <string>

// current SDK for this device; filled in when initializing the parser.
static int mySdk = 0;
static std::string myCodeName;

// to help address b/388925029

/**
 * support code so a plugin (currently the APV codecs) can self-manage
 * whether it is running on a sufficiently new code base.
 *
 * this is here because the XMLparser for Media codec definitions has
 * an off-by-one error in how it handles <MediaCodec name=".." ... minsdk="" >
 *
 * we will want to fix that starting in Android B/16, but devices in Android V/15
 * still have issues [and we build the codecs into module code so that it goes back
 * to older releases].
 *
 */

bool isAtLeastRelease(int minsdk, const char *codename) {

    static std::once_flag sCheckOnce;
    std::call_once(sCheckOnce, [&](){
        mySdk = android_get_device_api_level();
        myCodeName  = android::base::GetProperty("ro.build.version.codename", "<none>");
    });

    bool satisfied = false;
    ALOGI("device sdk %d, minsdk %d", mySdk, minsdk);
    if (mySdk >= minsdk) {
        satisfied = true;
    }

    // allow the called to skip the codename.
    if (codename != nullptr) {
        ALOGI("active codename %s, to match %s", myCodeName.c_str(), codename);
        if (myCodeName == codename) {
            satisfied = true;
        }
    }

    return satisfied;
}
+17 −0
Original line number Diff line number Diff line
/*
 * Copyright 2017, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

bool isAtLeastRelease(int minsdk, const char *codename);