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

Commit 050eb328 authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Some crypto stuff, error codes

Add crypto/drm related functions, define some media errors
instead of using magic numbers in the code.

Change-Id: I5924cba0bfcdb3623073c9182a646b70f4ead5a5
parent 021cf963
Loading
Loading
Loading
Loading
+44 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@

#include <android/native_window.h>

#include "NdkMediaCrypto.h"
#include "NdkMediaFormat.h"

#ifdef __cplusplus
@@ -46,6 +47,7 @@ struct AMediaCodecBufferInfo {
    uint32_t flags;
};
typedef struct AMediaCodecBufferInfo AMediaCodecBufferInfo;
typedef struct AMediaCodecCryptoInfo AMediaCodecCryptoInfo;

enum {
    AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM = 4,
@@ -81,8 +83,12 @@ int AMediaCodec_delete(AMediaCodec*);
/**
 * Configure the codec. For decoding you would typically get the format from an extractor.
 */
int AMediaCodec_configure(AMediaCodec*, const AMediaFormat* format,
        ANativeWindow* surface, uint32_t flags);  // TODO: other args
int AMediaCodec_configure(
        AMediaCodec*,
        const AMediaFormat* format,
        ANativeWindow* surface,
        AMediaCrypto *crypto,
        uint32_t flags);

/**
 * Start the codec. A codec must be configured before it can be started, and must be started
@@ -126,6 +132,12 @@ ssize_t AMediaCodec_dequeueInputBuffer(AMediaCodec*, int64_t timeoutUs);
int AMediaCodec_queueInputBuffer(AMediaCodec*,
        size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);

/**
 * Send the specified buffer to the codec for processing.
 */
int AMediaCodec_queueSecureInputBuffer(AMediaCodec*,
        size_t idx, off_t offset, AMediaCodecCryptoInfo*, uint64_t time, uint32_t flags);

/**
 * Get the index of the next available buffer of processed data.
 */
@@ -138,7 +150,6 @@ AMediaFormat* AMediaCodec_getOutputFormat(AMediaCodec*);
int AMediaCodec_releaseOutputBuffer(AMediaCodec*, size_t idx, bool render);



typedef void (*OnCodecEvent)(AMediaCodec *codec, void *userdata);

/**
@@ -150,6 +161,36 @@ typedef void (*OnCodecEvent)(AMediaCodec *codec, void *userdata);
int AMediaCodec_setNotificationCallback(AMediaCodec*, OnCodecEvent callback, void *userdata);


enum {
    AMEDIACODECRYPTOINFO_MODE_CLEAR = 0,
    AMEDIACODECRYPTOINFO_MODE_AES_CTR = 1
};

/**
 * create an AMediaCodecCryptoInfo from scratch. Use this if you need to use custom
 * crypto info, rather than one obtained from AMediaExtractor.
 */
AMediaCodecCryptoInfo *AMediaCodecCryptoInfo_new(
        int numsubsamples,
        uint8_t key[16],
        uint8_t iv[16],
        uint32_t mode,
        size_t *clearbytes,
        size_t *encryptedbytes);

/**
 * delete an AMediaCodecCryptoInfo create previously with AMediaCodecCryptoInfo_new, or
 * obtained from AMediaExtractor
 */
int AMediaCodecCryptoInfo_delete(AMediaCodecCryptoInfo*);

size_t AMediaCodecCryptoInfo_getNumSubSamples(AMediaCodecCryptoInfo*);
int AMediaCodecCryptoInfo_getKey(AMediaCodecCryptoInfo*, uint8_t *dst);
int AMediaCodecCryptoInfo_getIV(AMediaCodecCryptoInfo*, uint8_t *dst);
uint32_t AMediaCodecCryptoInfo_getMode(AMediaCodecCryptoInfo*);
int AMediaCodecCryptoInfo_getClearBytes(AMediaCodecCryptoInfo*, size_t *dst);
int AMediaCodecCryptoInfo_getEncryptedBytes(AMediaCodecCryptoInfo*, size_t *dst);

#ifdef __cplusplus
} // extern "C"
#endif
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.
 */


/*
 * This file defines an NDK API.
 * Do not remove methods.
 * Do not change method signatures.
 * Do not change the value of constants.
 * Do not change the size of any of the classes defined in here.
 * Do not reference types that are not part of the NDK.
 * Do not #include files that aren't part of the NDK.
 */

#ifndef _NDK_MEDIA_CRYPTO_H
#define _NDK_MEDIA_CRYPTO_H

#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

struct AMediaCrypto;
typedef struct AMediaCrypto AMediaCrypto;

typedef uint8_t AMediaUUID[16];

bool AMediaCrypto_isCryptoSchemeSupport(const AMediaUUID uuid);

bool AMediaCrypto_requiresSecureDecoderComponent(const char *mime);

AMediaCrypto* AMediaCrypto_new(const AMediaUUID uuid, const void *initData, size_t initDataSize);

void AMediaCrypto_delete(AMediaCrypto* crypto);


#ifdef __cplusplus
} // extern "C"
#endif

#endif // _NDK_MEDIA_CRYPTO_H
+48 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.
 */


/*
 * This file defines an NDK API.
 * Do not remove methods.
 * Do not change method signatures.
 * Do not change the value of constants.
 * Do not change the size of any of the classes defined in here.
 * Do not reference types that are not part of the NDK.
 * Do not #include files that aren't part of the NDK.
 */

#ifndef _NDK_MEDIA_ERROR_H
#define _NDK_MEDIA_ERROR_H

#ifdef __cplusplus
extern "C" {
#endif

enum {
    AMEDIAERROR_BASE = -10000,

    AMEDIAERROR_GENERIC     = AMEDIAERROR_BASE,
    AMEDIAERROR_MALFORMED   = AMEDIAERROR_BASE - 1,
    AMEDIAERROR_UNSUPPORTED = AMEDIAERROR_BASE - 2
};


#ifdef __cplusplus
} // extern "C"
#endif

#endif // _NDK_MEDIA_ERROR_H
+29 −0
Original line number Diff line number Diff line
@@ -30,7 +30,9 @@

#include <sys/types.h>

#include "NdkMediaCodec.h"
#include "NdkMediaFormat.h"
#include "NdkMediaCrypto.h"

#ifdef __cplusplus
extern "C" {
@@ -112,6 +114,33 @@ int64_t AMediaExtractor_getSampletime(AMediaExtractor*);
 */
bool AMediaExtractor_advance(AMediaExtractor*);


/**
 * mapping of crypto scheme uuid to the scheme specific data for that scheme
 */
typedef struct PsshEntry {
    AMediaUUID uuid;
    size_t datalen;
    void *data;
} PsshEntry;

/**
 * list of crypto schemes and their data
 */
typedef struct PsshInfo {
    size_t numentries;
    PsshEntry entries[0];
} PsshInfo;

/**
 * Get the PSSH info if present.
 */
PsshInfo* AMediaExtractor_getPsshInfo(AMediaExtractor*);


AMediaCodecCryptoInfo *AMediaExtractor_getSampleCryptoInfo(AMediaExtractor *);


enum {
    AMEDIAEXTRACTOR_SAMPLE_FLAG_SYNC = 1,
    AMEDIAEXTRACTOR_SAMPLE_FLAG_ENCRYPTED = 2,
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ include $(CLEAR_VARS)

LOCAL_SRC_FILES:=                                       \
                  NdkMediaCodec.cpp                     \
                  NdkMediaCrypto.cpp                    \
                  NdkMediaExtractor.cpp                 \
                  NdkMediaFormat.cpp                    \
                  NdkMediaMuxer.cpp                     \
@@ -34,6 +35,7 @@ LOCAL_C_INCLUDES := \
    frameworks/av/include/ndk

LOCAL_SHARED_LIBRARIES := \
    libbinder \
    libmedia \
    libstagefright \
    libstagefright_foundation \
Loading