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

Commit 63c0f36d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I72357031,I50253590

* changes:
  Remove unused code path in MediaExtractor(Factory|Service)
  Load media extractor plug-ins by using media namespace.
parents 4adca04f b52f0a0a
Loading
Loading
Loading
Loading
+20 −79
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@
#include <binder/PermissionCache.h>
#include <binder/IServiceManager.h>
#include <media/DataSource.h>
#include <media/MediaAnalyticsItem.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/InterfaceUtils.h>
#include <media/stagefright/MediaExtractor.h>
#include <media/stagefright/MediaExtractorFactory.h>
@@ -34,7 +32,6 @@
#include <private/android_filesystem_config.h>
#include <cutils/properties.h>
#include <utils/String8.h>
#include <ziparchive/zip_archive.h>

#include <dirent.h>
#include <dlfcn.h>
@@ -130,13 +127,6 @@ Mutex MediaExtractorFactory::gPluginMutex;
std::shared_ptr<std::list<sp<ExtractorPlugin>>> MediaExtractorFactory::gPlugins;
bool MediaExtractorFactory::gPluginsRegistered = false;
bool MediaExtractorFactory::gIgnoreVersion = false;
std::string MediaExtractorFactory::gLinkedLibraries;

// static
void MediaExtractorFactory::SetLinkedLibraries(const std::string& linkedLibraries) {
    Mutex::Autolock autoLock(gPluginMutex);
    gLinkedLibraries = linkedLibraries;
}

// static
void *MediaExtractorFactory::sniff(
@@ -235,71 +225,12 @@ void MediaExtractorFactory::RegisterExtractor(const sp<ExtractorPlugin> &plugin,
}

//static
void MediaExtractorFactory::RegisterExtractorsInSystem(
        const char *libDirPath, std::list<sp<ExtractorPlugin>> &pluginList) {
    ALOGV("search for plugins at %s", libDirPath);
    DIR *libDir = opendir(libDirPath);
    if (libDir) {
        struct dirent* libEntry;
        while ((libEntry = readdir(libDir))) {
            if (libEntry->d_name[0] == '.') {
                continue;
            }
            String8 libPath = String8(libDirPath) + "/" + libEntry->d_name;
            void *libHandle = dlopen(libPath.string(), RTLD_NOW | RTLD_LOCAL);
            if (libHandle) {
                GetExtractorDef getDef =
                    (GetExtractorDef) dlsym(libHandle, "GETEXTRACTORDEF");
                if (getDef) {
                    ALOGV("registering sniffer for %s", libPath.string());
                    RegisterExtractor(
                            new ExtractorPlugin(getDef(), libHandle, libPath), pluginList);
                } else {
                    ALOGW("%s does not contain sniffer", libPath.string());
                    dlclose(libHandle);
                }
            } else {
                ALOGW("couldn't dlopen(%s) %s", libPath.string(), strerror(errno));
            }
        }

        closedir(libDir);
    } else {
        ALOGE("couldn't opendir(%s)", libDirPath);
    }
}

//static
void MediaExtractorFactory::RegisterExtractorsInApex(
        const char *libDirPath, std::list<sp<ExtractorPlugin>> &pluginList) {
void MediaExtractorFactory::RegisterExtractors(
        const char *libDirPath, const android_dlextinfo* dlextinfo,
        std::list<sp<ExtractorPlugin>> &pluginList) {
    ALOGV("search for plugins at %s", libDirPath);
    ALOGV("linked libs %s", gLinkedLibraries.c_str());

    std::string libDirPathEx = libDirPath;
    libDirPathEx += "/extractors";
    android_namespace_t *extractorNs = android_create_namespace("extractor",
            nullptr,  // ld_library_path
            libDirPath,  // default_library_path
            ANDROID_NAMESPACE_TYPE_ISOLATED,
            libDirPathEx.c_str(),  // permitted_when_isolated_path
            nullptr); // parent
    if (!android_link_namespaces(extractorNs, nullptr, gLinkedLibraries.c_str())) {
        ALOGE("Failed to link namespace. Failed to load extractor plug-ins in apex.");
        return;
    }
    const android_dlextinfo dlextinfo = {
        .flags = ANDROID_DLEXT_USE_NAMESPACE,
        .library_namespace = extractorNs,
    };

    // try extractors subfolder first
    DIR *libDir = opendir(libDirPathEx.c_str());

    if (libDir) {
        libDirPath = libDirPathEx.c_str();
    } else {
        libDir = opendir(libDirPath);
    }
    DIR *libDir = opendir(libDirPath);
    if (libDir) {
        struct dirent* libEntry;
        while ((libEntry = readdir(libDir))) {
@@ -312,7 +243,7 @@ void MediaExtractorFactory::RegisterExtractorsInApex(
            }
            void *libHandle = android_dlopen_ext(
                    libPath.string(),
                    RTLD_NOW | RTLD_LOCAL, &dlextinfo);
                    RTLD_NOW | RTLD_LOCAL, dlextinfo);
            if (libHandle) {
                GetExtractorDef getDef =
                    (GetExtractorDef) dlsym(libHandle, "GETEXTRACTORDEF");
@@ -352,17 +283,27 @@ void MediaExtractorFactory::UpdateExtractors() {

    std::shared_ptr<std::list<sp<ExtractorPlugin>>> newList(new std::list<sp<ExtractorPlugin>>());

    RegisterExtractorsInApex("/apex/com.android.media/lib"
    android_namespace_t *mediaNs = android_get_exported_namespace("media");
    if (mediaNs != NULL) {
        const android_dlextinfo dlextinfo = {
            .flags = ANDROID_DLEXT_USE_NAMESPACE,
            .library_namespace = mediaNs,
        };
        RegisterExtractors("/apex/com.android.media/lib"
#ifdef __LP64__
                "64"
#endif
            , *newList);
                "/extractors", &dlextinfo, *newList);

    } else {
        ALOGE("couldn't find media namespace.");
    }

    RegisterExtractorsInSystem("/system/lib"
    RegisterExtractors("/system/lib"
#ifdef __LP64__
            "64"
#endif
            "/extractors", *newList);
            "/extractors", NULL, *newList);

    newList->sort(compareFunc);
    gPlugins = newList;
+4 −6
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <unordered_set>

#include <android/dlext.h>
#include <media/IMediaExtractor.h>

namespace android {
@@ -36,19 +37,16 @@ public:
            const sp<DataSource> &source, const char *mime = NULL);
    static status_t dump(int fd, const Vector<String16>& args);
    static std::unordered_set<std::string> getSupportedTypes();
    static void SetLinkedLibraries(const std::string& linkedLibraries);

private:
    static Mutex gPluginMutex;
    static std::shared_ptr<std::list<sp<ExtractorPlugin>>> gPlugins;
    static bool gPluginsRegistered;
    static bool gIgnoreVersion;
    static std::string gLinkedLibraries;

    static void RegisterExtractorsInSystem(
            const char *libDirPath, std::list<sp<ExtractorPlugin>> &pluginList);
    static void RegisterExtractorsInApex(
            const char *libDirPath, std::list<sp<ExtractorPlugin>> &pluginList);
    static void RegisterExtractors(
            const char *libDirPath, const android_dlextinfo* dlextinfo,
            std::list<sp<ExtractorPlugin>> &pluginList);
    static void RegisterExtractor(
            const sp<ExtractorPlugin> &plugin, std::list<sp<ExtractorPlugin>> &pluginList);

+0 −18
Original line number Diff line number Diff line
@@ -8,24 +8,6 @@ LOCAL_SRC_FILES := \

LOCAL_SHARED_LIBRARIES := libmedia libstagefright libbinder libutils liblog
LOCAL_MODULE:= libmediaextractorservice

sanitizer_runtime_libraries := $(call normalize-path-list,$(addsuffix .so,\
  $(ADDRESS_SANITIZER_RUNTIME_LIBRARY) \
  $(UBSAN_RUNTIME_LIBRARY) \
  $(TSAN_RUNTIME_LIBRARY)))

# $(info Sanitizer:  $(sanitizer_runtime_libraries))

ndk_libraries := $(call normalize-path-list,$(addprefix lib,$(addsuffix .so,\
  $(NDK_PREBUILT_SHARED_LIBRARIES))))

# $(info NDK:  $(ndk_libraries))

LOCAL_CFLAGS += -DLINKED_LIBRARIES='"$(sanitizer_runtime_libraries):$(ndk_libraries)"'

sanitizer_runtime_libraries :=
ndk_libraries :=

include $(BUILD_SHARED_LIBRARY)


+1 −3
Original line number Diff line number Diff line
@@ -30,9 +30,7 @@
namespace android {

MediaExtractorService::MediaExtractorService()
        : BnMediaExtractorService() {
    MediaExtractorFactory::SetLinkedLibraries(std::string(LINKED_LIBRARIES));
}
        : BnMediaExtractorService() { }

sp<IMediaExtractor> MediaExtractorService::makeExtractor(
        const sp<IDataSource> &remoteSource, const char *mime) {