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

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

Merge "Add methods for apex to create codec with uid/pid."

parents e697eccd efd1c5cd
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -116,7 +116,10 @@ cc_library_shared {

    export_header_lib_headers: ["jni_headers"],

    export_include_dirs: ["include"],
    export_include_dirs: [
        "include",
        "include_platform",
    ],

    export_shared_lib_headers: [
        "libgui",
+43 −7
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
//#define LOG_NDEBUG 0
#define LOG_TAG "NdkMediaCodec"

#include <media/NdkMediaCodec.h>
#include <media/NdkMediaCodecPlatform.h>
#include <media/NdkMediaError.h>
#include <media/NdkMediaFormatPriv.h>
#include "NdkMediaCryptoPriv.h"
@@ -312,7 +312,11 @@ static void requestActivityNotification(AMediaCodec *codec) {

extern "C" {

static AMediaCodec * createAMediaCodec(const char *name, bool name_is_type, bool encoder) {
static AMediaCodec * createAMediaCodec(const char *name,
                                       bool name_is_type,
                                       bool encoder,
                                       pid_t pid = android::MediaCodec::kNoPid,
                                       uid_t uid = android::MediaCodec::kNoUid) {
    AMediaCodec *mData = new AMediaCodec();
    mData->mLooper = new ALooper;
    mData->mLooper->setName("NDK MediaCodec_looper");
@@ -326,9 +330,20 @@ static AMediaCodec * createAMediaCodec(const char *name, bool name_is_type, bool
        return NULL;
    }
    if (name_is_type) {
        mData->mCodec = android::MediaCodec::CreateByType(mData->mLooper, name, encoder);
        mData->mCodec = android::MediaCodec::CreateByType(
                mData->mLooper,
                name,
                encoder,
                nullptr /* err */,
                pid,
                uid);
    } else {
        mData->mCodec = android::MediaCodec::CreateByComponentName(mData->mLooper, name);
        mData->mCodec = android::MediaCodec::CreateByComponentName(
                mData->mLooper,
                name,
                nullptr /* err */,
                pid,
                uid);
    }
    if (mData->mCodec == NULL) {  // failed to create codec
        AMediaCodec_delete(mData);
@@ -348,17 +363,38 @@ static AMediaCodec * createAMediaCodec(const char *name, bool name_is_type, bool

EXPORT
AMediaCodec* AMediaCodec_createCodecByName(const char *name) {
    return createAMediaCodec(name, false, false);
    return createAMediaCodec(name, false /* name_is_type */, false /* encoder */);
}

EXPORT
AMediaCodec* AMediaCodec_createDecoderByType(const char *mime_type) {
    return createAMediaCodec(mime_type, true, false);
    return createAMediaCodec(mime_type, true /* name_is_type */, false /* encoder */);
}

EXPORT
AMediaCodec* AMediaCodec_createEncoderByType(const char *name) {
    return createAMediaCodec(name, true, true);
    return createAMediaCodec(name, true /* name_is_type */, true /* encoder */);
}

EXPORT
AMediaCodec* AMediaCodec_createCodecByNameForClient(const char *name,
                                                    pid_t pid,
                                                    uid_t uid) {
    return createAMediaCodec(name, false /* name_is_type */, false /* encoder */, pid, uid);
}

EXPORT
AMediaCodec* AMediaCodec_createDecoderByTypeForClient(const char *mime_type,
                                                      pid_t pid,
                                                      uid_t uid) {
    return createAMediaCodec(mime_type, true /* name_is_type */, false /* encoder */, pid, uid);
}

EXPORT
AMediaCodec* AMediaCodec_createEncoderByTypeForClient(const char *name,
                                                      pid_t pid,
                                                      uid_t uid) {
    return createAMediaCodec(name, true /* name_is_type */, true /* encoder */, pid, uid);
}

EXPORT
+100 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */

#ifndef _NDK_MEDIA_CODEC_PLATFORM_H
#define _NDK_MEDIA_CODEC_PLATFORM_H

#include <stdint.h>
#include <sys/cdefs.h>

#include <media/NdkMediaCodec.h>

__BEGIN_DECLS

/**
 * Special uid and pid values used with AMediaCodec_createCodecByNameForClient,
 * AMediaCodec_createDecoderByTypeForClient and AMediaCodec_createEncoderByTypeForClient.
 *
 * Introduced in API 31.
 */
enum {
    /**
     * Uid value to indicate using calling uid.
     */
    AMEDIACODEC_CALLING_UID = -1,
    /**
     * Pid value to indicate using calling pid.
     */
    AMEDIACODEC_CALLING_PID = -1,
};

#if __ANDROID_API__ >= 31

/**
 * Create codec by name on behalf of a client.
 *
 * The usage is similar to AMediaCodec_createCodecByName(), except that the codec instance
 * will be attributed to the client of {uid, pid}, instead of the caller.
 *
 * Only certain privileged users are allowed to specify {uid, pid} that's different from the
 * caller's. Without the privilege, this API will behave the same as
 * AMediaCodec_createCodecByName().
 *
 * Available since API level 31.
 */
AMediaCodec* AMediaCodec_createCodecByNameForClient(const char *name,
                                                    pid_t pid,
                                                    uid_t uid) __INTRODUCED_IN(31);

/**
 * Create codec by mime type on behalf of a client.
 *
 * The usage is similar to AMediaCodec_createDecoderByType(), except that the codec instance
 * will be attributed to the client of {uid, pid}, instead of the caller.
 *
 * Only certain privileged users are allowed to specify {uid, pid} that's different from the
 * caller's. Without the privilege, this API will behave the same as
 * AMediaCodec_createDecoderByType().
 *
 * Available since API level 31.
 */
AMediaCodec* AMediaCodec_createDecoderByTypeForClient(const char *mime_type,
                                                      pid_t pid,
                                                      uid_t uid) __INTRODUCED_IN(31);

/**
 * Create encoder by name on behalf of a client.
 *
 * The usage is similar to AMediaCodec_createEncoderByType(), except that the codec instance
 * will be attributed to the client of {uid, pid}, instead of the caller.
 *
 * Only certain privileged users are allowed to specify {uid, pid} that's different from the
 * caller's. Without the privilege, this API will behave the same as
 * AMediaCodec_createEncoderByType().
 *
 * Available since API level 31.
 */
AMediaCodec* AMediaCodec_createEncoderByTypeForClient(const char *mime_type,
                                                      pid_t pid,
                                                      uid_t uid) __INTRODUCED_IN(31);

#endif // __ANDROID_API__ >= 31

__END_DECLS

#endif //_NDK_MEDIA_CODEC_PLATFORM_H

/** @} */
+3 −0
Original line number Diff line number Diff line
@@ -165,8 +165,11 @@ LIBMEDIANDK {
    AMediaCodecCryptoInfo_setPattern; # introduced=24
    AMediaCodec_configure;
    AMediaCodec_createCodecByName;
    AMediaCodec_createCodecByNameForClient; # apex #introduced = 31
    AMediaCodec_createDecoderByType;
    AMediaCodec_createDecoderByTypeForClient; # apex #introduced = 31
    AMediaCodec_createEncoderByType;
    AMediaCodec_createEncoderByTypeForClient; # apex #introduced = 31
    AMediaCodec_delete;
    AMediaCodec_dequeueInputBuffer;
    AMediaCodec_dequeueOutputBuffer;