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

Commit e419d7cd authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Unify error/status codes

Change-Id: Ib90cc2f2adc07ff146256931c92c0ec4becb86f5
parent 3425fd5a
Loading
Loading
Loading
Loading
+16 −14
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <android/native_window.h>

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

#ifdef __cplusplus
@@ -78,12 +79,12 @@ AMediaCodec* AMediaCodec_createEncoderByType(const char *mime_type);
/**
 * delete the codec and free its resources
 */
int AMediaCodec_delete(AMediaCodec*);
media_status_t AMediaCodec_delete(AMediaCodec*);

/**
 * Configure the codec. For decoding you would typically get the format from an extractor.
 */
int AMediaCodec_configure(
media_status_t AMediaCodec_configure(
        AMediaCodec*,
        const AMediaFormat* format,
        ANativeWindow* surface,
@@ -94,18 +95,18 @@ int AMediaCodec_configure(
 * Start the codec. A codec must be configured before it can be started, and must be started
 * before buffers can be sent to it.
 */
int AMediaCodec_start(AMediaCodec*);
media_status_t AMediaCodec_start(AMediaCodec*);

/**
 * Stop the codec.
 */
int AMediaCodec_stop(AMediaCodec*);
media_status_t AMediaCodec_stop(AMediaCodec*);

/*
 * Flush the codec's input and output. All indices previously returned from calls to
 * AMediaCodec_dequeueInputBuffer and AMediaCodec_dequeueOutputBuffer become invalid.
 */
int AMediaCodec_flush(AMediaCodec*);
media_status_t AMediaCodec_flush(AMediaCodec*);

/**
 * Get an input buffer. The specified buffer index must have been previously obtained from
@@ -129,13 +130,13 @@ ssize_t AMediaCodec_dequeueInputBuffer(AMediaCodec*, int64_t timeoutUs);
/**
 * Send the specified buffer to the codec for processing.
 */
int AMediaCodec_queueInputBuffer(AMediaCodec*,
media_status_t 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*,
media_status_t AMediaCodec_queueSecureInputBuffer(AMediaCodec*,
        size_t idx, off_t offset, AMediaCodecCryptoInfo*, uint64_t time, uint32_t flags);

/**
@@ -147,7 +148,7 @@ AMediaFormat* AMediaCodec_getOutputFormat(AMediaCodec*);
/**
 * Release and optionally render the specified buffer.
 */
int AMediaCodec_releaseOutputBuffer(AMediaCodec*, size_t idx, bool render);
media_status_t AMediaCodec_releaseOutputBuffer(AMediaCodec*, size_t idx, bool render);


typedef void (*OnCodecEvent)(AMediaCodec *codec, void *userdata);
@@ -158,7 +159,8 @@ typedef void (*OnCodecEvent)(AMediaCodec *codec, void *userdata);
 * Note that you cannot perform any operations on the mediacodec from within the callback.
 * If you need to perform mediacodec operations, you must do so on a different thread.
 */
int AMediaCodec_setNotificationCallback(AMediaCodec*, OnCodecEvent callback, void *userdata);
media_status_t AMediaCodec_setNotificationCallback(
        AMediaCodec*, OnCodecEvent callback, void *userdata);


enum {
@@ -182,14 +184,14 @@ AMediaCodecCryptoInfo *AMediaCodecCryptoInfo_new(
 * delete an AMediaCodecCryptoInfo created previously with AMediaCodecCryptoInfo_new, or
 * obtained from AMediaExtractor
 */
int AMediaCodecCryptoInfo_delete(AMediaCodecCryptoInfo*);
media_status_t AMediaCodecCryptoInfo_delete(AMediaCodecCryptoInfo*);

size_t AMediaCodecCryptoInfo_getNumSubSamples(AMediaCodecCryptoInfo*);
int AMediaCodecCryptoInfo_getKey(AMediaCodecCryptoInfo*, uint8_t *dst);
int AMediaCodecCryptoInfo_getIV(AMediaCodecCryptoInfo*, uint8_t *dst);
media_status_t AMediaCodecCryptoInfo_getKey(AMediaCodecCryptoInfo*, uint8_t *dst);
media_status_t 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);
media_status_t AMediaCodecCryptoInfo_getClearBytes(AMediaCodecCryptoInfo*, size_t *dst);
media_status_t AMediaCodecCryptoInfo_getEncryptedBytes(AMediaCodecCryptoInfo*, size_t *dst);

#ifdef __cplusplus
} // extern "C"
+21 −36
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@
#ifndef _NDK_MEDIA_DRM_H
#define _NDK_MEDIA_DRM_H

#include <NdkMediaError.h>

#ifdef __cplusplus
extern "C" {
#endif
@@ -47,23 +49,6 @@ typedef AMediaDrmByteArray AMediaDrmScope;
typedef AMediaDrmByteArray AMediaDrmKeySetId;
typedef AMediaDrmByteArray AMediaDrmSecureStop;

#define MEDIADRM_ERROR_BASE -2000

typedef enum {
    MEDIADRM_OK = 0,
    MEDIADRM_NOT_PROVISIONED_ERROR    = MEDIADRM_ERROR_BASE - 1,
    MEDIADRM_RESOURCE_BUSY_ERROR      = MEDIADRM_ERROR_BASE - 2,
    MEDIADRM_DEVICE_REVOKED_ERROR     = MEDIADRM_ERROR_BASE - 3,
    MEDIADRM_SHORT_BUFFER             = MEDIADRM_ERROR_BASE - 4,
    MEDIADRM_INVALID_OBJECT_ERROR     = MEDIADRM_ERROR_BASE - 5,
    MEDIADRM_INVALID_PARAMETER_ERROR  = MEDIADRM_ERROR_BASE - 6,
    MEDIADRM_SESSION_NOT_OPENED_ERROR = MEDIADRM_ERROR_BASE - 7,
    MEDIADRM_TAMPER_DETECTED_ERROR    = MEDIADRM_ERROR_BASE - 8,
    MEDIADRM_VERIFY_FAILED            = MEDIADRM_ERROR_BASE - 9,
    MEDIADRM_NEED_KEY_ERROR           = MEDIADRM_ERROR_BASE - 10,
    MEDIADRM_LICENSE_EXPIRED_ERROR    = MEDIADRM_ERROR_BASE - 11,
    MEDIADRM_UNKNOWN_ERROR            = MEDIADRM_ERROR_BASE - 12,
} mediadrm_status_t;

typedef enum AMediaDrmEventType {
    /**
@@ -130,13 +115,13 @@ void AMediaDrm_setOnEventListener(AMediaDrm *, AMediaDrmEventListener listener);
 * returns MEDIADRM_NOT_PROVISIONED_ERROR if provisioning is needed
 * returns MEDIADRM_RESOURCE_BUSY_ERROR if required resources are in use
 */
mediadrm_status_t AMediaDrm_openSession(AMediaDrm *, AMediaDrmSessionId &sessionId);
media_status_t AMediaDrm_openSession(AMediaDrm *, AMediaDrmSessionId &sessionId);

/**
 * Close a session on the MediaDrm object that was previously opened
 * with AMediaDrm_openSession.
 */
mediadrm_status_t AMediaDrm_closeSession(AMediaDrm *, const AMediaDrmSessionId &sessionId);
media_status_t AMediaDrm_closeSession(AMediaDrm *, const AMediaDrmSessionId &sessionId);

typedef enum AMediaDrmKeyType {
    /**
@@ -213,7 +198,7 @@ typedef struct AMediaDrmKeyValuePair {
 * returns MEDIADRM_NOT_PROVISIONED_ERROR if reprovisioning is needed, due to a
 * problem with the device certificate.
*/
mediadrm_status_t AMediaDrm_getKeyRequest(AMediaDrm *, const AMediaDrmScope &scope,
media_status_t AMediaDrm_getKeyRequest(AMediaDrm *, const AMediaDrmScope &scope,
        const uint8_t *init, size_t initSize, const char *mimeType, AMediaDrmKeyType keyType,
        const AMediaDrmKeyValue *optionalParameters, size_t numOptionalParameters,
        const uint8_t *&keyRequest, size_t &keyRequestSize);
@@ -235,7 +220,7 @@ mediadrm_status_t AMediaDrm_getKeyRequest(AMediaDrm *, const AMediaDrmScope &sco
 * responseSize should be set to the size of the response in bytes
 */

mediadrm_status_t AMediaDrm_provideKeyResponse(AMediaDrm *, const AMediaDrmScope &scope,
media_status_t AMediaDrm_provideKeyResponse(AMediaDrm *, const AMediaDrmScope &scope,
        const uint8_t *response, size_t responseSize, AMediaDrmKeySetId &keySetId);

/**
@@ -245,7 +230,7 @@ mediadrm_status_t AMediaDrm_provideKeyResponse(AMediaDrm *, const AMediaDrmScope
 * sessionId is the session ID for the DRM session
 * keySetId identifies the saved key set to restore
 */
mediadrm_status_t AMediaDrm_restoreKeys(AMediaDrm *, const AMediaDrmSessionId &sessionId,
media_status_t AMediaDrm_restoreKeys(AMediaDrm *, const AMediaDrmSessionId &sessionId,
        const AMediaDrmKeySetId &keySetId);

/**
@@ -253,7 +238,7 @@ mediadrm_status_t AMediaDrm_restoreKeys(AMediaDrm *, const AMediaDrmSessionId &s
 *
 * keySetId identifies keys to remove
 */
mediadrm_status_t AMediaDrm_removeKeys(AMediaDrm *, const AMediaDrmSessionId &keySetId);
media_status_t AMediaDrm_removeKeys(AMediaDrm *, const AMediaDrmSessionId &keySetId);

/**
 * Request an informative description of the key status for the session.  The status is
@@ -268,7 +253,7 @@ mediadrm_status_t AMediaDrm_removeKeys(AMediaDrm *, const AMediaDrmSessionId &ke
 * to be returned is greater than *numPairs, MEDIADRM_SHORT_BUFFER will be returned
 * and numPairs will be set to the number of pairs available.
 */
mediadrm_status_t AMediaDrm_queryKeyStatus(AMediaDrm *, const AMediaDrmSessionId &sessionId,
media_status_t AMediaDrm_queryKeyStatus(AMediaDrm *, const AMediaDrmSessionId &sessionId,
        AMediaDrmKeyValue *keyValuePairs, size_t &numPairs);


@@ -287,7 +272,7 @@ mediadrm_status_t AMediaDrm_queryKeyStatus(AMediaDrm *, const AMediaDrmSessionId
 *       the provisioning request should be sent to.  It will remain accessible until
 *       the next call to getProvisionRequest.
 */
mediadrm_status_t AMediaDrm_getProvisionRequest(AMediaDrm *, const uint8_t *&provisionRequest,
media_status_t AMediaDrm_getProvisionRequest(AMediaDrm *, const uint8_t *&provisionRequest,
        size_t &provisionRequestSize, const char *&serverUrl);


@@ -302,7 +287,7 @@ mediadrm_status_t AMediaDrm_getProvisionRequest(AMediaDrm *, const uint8_t *&pro
 * returns MEDIADRM_DEVICE_REVOKED_ERROR if the response indicates that the
 * server rejected the request
 */
mediadrm_status_t AMediaDrm_provideProvisionResponse(AMediaDrm *,
media_status_t AMediaDrm_provideProvisionResponse(AMediaDrm *,
        const uint8_t *response, size_t responseSize);


@@ -327,7 +312,7 @@ mediadrm_status_t AMediaDrm_provideProvisionResponse(AMediaDrm *,
 * MEDIADRM_SHORT_BUFFER will be returned and *numSecureStops will be set to the
 * number required.
 */
mediadrm_status_t AMediaDrm_getSecureStops(AMediaDrm *,
media_status_t AMediaDrm_getSecureStops(AMediaDrm *,
        AMediaDrmSecureStop *secureStops, size_t &numSecureStops);

/**
@@ -336,7 +321,7 @@ mediadrm_status_t AMediaDrm_getSecureStops(AMediaDrm *,
 *
 * ssRelease is the server response indicating which secure stops to release
 */
mediadrm_status_t AMediaDrm_releaseSecureStops(AMediaDrm *,
media_status_t AMediaDrm_releaseSecureStops(AMediaDrm *,
        const AMediaDrmSecureStop &ssRelease);

/**
@@ -369,7 +354,7 @@ const char *PROPERTY_ALGORITHMS = "algorithms";
 * memory that the value resides in is owned by the NDK MediaDrm API and
 * will remain valid until the next call to AMediaDrm_getPropertyString.
 */
mediadrm_status_t AMediaDrm_getPropertyString(AMediaDrm *, const char *propertyName,
media_status_t AMediaDrm_getPropertyString(AMediaDrm *, const char *propertyName,
        const char *&propertyValue);

/**
@@ -384,19 +369,19 @@ const char *PROPERTY_DEVICE_UNIQUE_ID = "deviceUniqueId";
 * memory that the value resides in is owned by the NDK MediaDrm API and
 * will remain valid until the next call to AMediaDrm_getPropertyByteArray.
 */
mediadrm_status_t AMediaDrm_getPropertyByteArray(AMediaDrm *, const char *propertyName,
media_status_t AMediaDrm_getPropertyByteArray(AMediaDrm *, const char *propertyName,
        AMediaDrmByteArray &propertyValue);

/**
 * Set a DRM engine plugin String property value.
 */
mediadrm_status_t AMediaDrm_setPropertyString(AMediaDrm *, const char *propertyName,
media_status_t AMediaDrm_setPropertyString(AMediaDrm *, const char *propertyName,
        const char *value);

/**
 * Set a DRM engine plugin byte array property value.
 */
mediadrm_status_t AMediaDrm_setPropertyByteArray(AMediaDrm *, const char *propertyName,
media_status_t AMediaDrm_setPropertyByteArray(AMediaDrm *, const char *propertyName,
        const uint8_t *value, size_t valueSize);

/**
@@ -424,7 +409,7 @@ mediadrm_status_t AMediaDrm_setPropertyByteArray(AMediaDrm *, const char *proper
 * to use is identified by the 16 byte keyId.  The key must have been loaded into
 * the session using provideKeyResponse.
 */
mediadrm_status_t AMediaDrm_encrypt(AMediaDrm *, const AMediaDrmSessionId &sessionId,
media_status_t AMediaDrm_encrypt(AMediaDrm *, const AMediaDrmSessionId &sessionId,
        const char *cipherAlgorithm, uint8_t *keyId, uint8_t *iv,
        const uint8_t *input, uint8_t *output, size_t dataSize);

@@ -435,7 +420,7 @@ mediadrm_status_t AMediaDrm_encrypt(AMediaDrm *, const AMediaDrmSessionId &sessi
 * to use is identified by the 16 byte keyId.  The key must have been loaded into
 * the session using provideKeyResponse.
 */
mediadrm_status_t AMediaDrm_decrypt(AMediaDrm *, const AMediaDrmSessionId &sessionId,
media_status_t AMediaDrm_decrypt(AMediaDrm *, const AMediaDrmSessionId &sessionId,
        const char *cipherAlgorithm, uint8_t *keyId, uint8_t *iv,
        const uint8_t *input, uint8_t *output, size_t dataSize);

@@ -448,7 +433,7 @@ mediadrm_status_t AMediaDrm_decrypt(AMediaDrm *, const AMediaDrmSessionId &sessi
 * by the 16 byte keyId.  The key must have been loaded into the session using
 * provideKeyResponse.
 */
mediadrm_status_t AMediaDrm_sign(AMediaDrm *, const AMediaDrmSessionId &sessionId,
media_status_t AMediaDrm_sign(AMediaDrm *, const AMediaDrmSessionId &sessionId,
        const char *macAlgorithm, uint8_t *keyId, uint8_t *message, size_t messageSize,
        uint8_t *signature, size_t *signatureSize);

@@ -459,7 +444,7 @@ mediadrm_status_t AMediaDrm_sign(AMediaDrm *, const AMediaDrmSessionId &sessionI
 * use is identified by the 16 byte keyId.  The key must have been loaded into the
 * session using provideKeyResponse.
 */
mediadrm_status_t AMediaDrm_verify(AMediaDrm *, const AMediaDrmSessionId &sessionId,
media_status_t AMediaDrm_verify(AMediaDrm *, const AMediaDrmSessionId &sessionId,
        const char *macAlgorithm, uint8_t *keyId, const uint8_t *message, size_t messageSize,
        const uint8_t *signature, size_t signatureSize);

+22 −7
Original line number Diff line number Diff line
@@ -32,13 +32,28 @@
extern "C" {
#endif

enum {
    AMEDIAERROR_BASE = -10000,

    AMEDIAERROR_GENERIC     = AMEDIAERROR_BASE,
    AMEDIAERROR_MALFORMED   = AMEDIAERROR_BASE - 1,
    AMEDIAERROR_UNSUPPORTED = AMEDIAERROR_BASE - 2
};
typedef enum {
    AMEDIA_OK = 0,

    AMEDIA_ERROR_BASE                  = -10000,
    AMEDIA_ERROR_UNKNOWN               = AMEDIA_ERROR_BASE,
    AMEDIA_ERROR_MALFORMED             = AMEDIA_ERROR_BASE - 1,
    AMEDIA_ERROR_UNSUPPORTED           = AMEDIA_ERROR_BASE - 2,
    AMEDIA_ERROR_INVALID_OBJECT        = AMEDIA_ERROR_BASE - 3,
    AMEDIA_ERROR_INVALID_PARAMETER     = AMEDIA_ERROR_BASE - 4,

    AMEDIA_DRM_ERROR_BASE              = -20000,
    AMEDIA_DRM_NOT_PROVISIONED         = AMEDIA_DRM_ERROR_BASE - 1,
    AMEDIA_DRM_RESOURCE_BUSY           = AMEDIA_DRM_ERROR_BASE - 2,
    AMEDIA_DRM_DEVICE_REVOKED          = AMEDIA_DRM_ERROR_BASE - 3,
    AMEDIA_DRM_SHORT_BUFFER            = AMEDIA_DRM_ERROR_BASE - 4,
    AMEDIA_DRM_SESSION_NOT_OPENED      = AMEDIA_DRM_ERROR_BASE - 5,
    AMEDIA_DRM_TAMPER_DETECTED         = AMEDIA_DRM_ERROR_BASE - 6,
    AMEDIA_DRM_VERIFY_FAILED           = AMEDIA_DRM_ERROR_BASE - 7,
    AMEDIA_DRM_NEED_KEY                = AMEDIA_DRM_ERROR_BASE - 8,
    AMEDIA_DRM_LICENSE_EXPIRED         = AMEDIA_DRM_ERROR_BASE - 9,

} media_status_t;


#ifdef __cplusplus
+8 −8
Original line number Diff line number Diff line
@@ -50,22 +50,22 @@ AMediaExtractor* AMediaExtractor_new();
/**
 * Delete a previously created media extractor
 */
int AMediaExtractor_delete(AMediaExtractor*);
media_status_t AMediaExtractor_delete(AMediaExtractor*);

/**
 *  Set the file descriptor from which the extractor will read.
 */
int AMediaExtractor_setDataSourceFd(AMediaExtractor*, int fd, off64_t offset, off64_t length);
media_status_t AMediaExtractor_setDataSourceFd(AMediaExtractor*, int fd, off64_t offset, off64_t length);

/**
 * Set the URI from which the extractor will read.
 */
int AMediaExtractor_setDataSource(AMediaExtractor*, const char *location); // TODO support headers
media_status_t AMediaExtractor_setDataSource(AMediaExtractor*, const char *location); // TODO support headers

/**
 * Return the number of tracks in the previously specified media file
 */
int AMediaExtractor_getTrackCount(AMediaExtractor*);
size_t AMediaExtractor_getTrackCount(AMediaExtractor*);

/**
 * Return the format of the specified track. The caller must free the returned format
@@ -78,23 +78,23 @@ AMediaFormat* AMediaExtractor_getTrackFormat(AMediaExtractor*, size_t idx);
 * Selecting the same track multiple times has no effect, the track is
 * only selected once.
 */
int AMediaExtractor_selectTrack(AMediaExtractor*, size_t idx);
media_status_t AMediaExtractor_selectTrack(AMediaExtractor*, size_t idx);

/**
 * Unselect the specified track. Subsequent calls to readSampleData, getSampleTrackIndex and
 * getSampleTime only retrieve information for the subset of tracks selected..
 */
int AMediaExtractor_unselectTrack(AMediaExtractor*, size_t idx);
media_status_t AMediaExtractor_unselectTrack(AMediaExtractor*, size_t idx);

/**
 * Read the current sample.
 */
int AMediaExtractor_readSampleData(AMediaExtractor*, uint8_t *buffer, size_t capacity);
ssize_t AMediaExtractor_readSampleData(AMediaExtractor*, uint8_t *buffer, size_t capacity);

/**
 * Read the current sample's flags.
 */
int AMediaExtractor_getSampleFlags(AMediaExtractor*); // see definitions below
uint32_t AMediaExtractor_getSampleFlags(AMediaExtractor*); // see definitions below

/**
 * Returns the track index the current sample originates from (or -1
+3 −1
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@

#include <sys/types.h>

#include "NdkMediaError.h"

#ifdef __cplusplus
extern "C" {
#endif
@@ -37,7 +39,7 @@ struct AMediaFormat;
typedef struct AMediaFormat AMediaFormat;

AMediaFormat *AMediaFormat_new();
int AMediaFormat_delete(AMediaFormat*);
media_status_t AMediaFormat_delete(AMediaFormat*);

/**
 * Human readable representation of the format. The returned string is owned by the format,
Loading