Migrate libmediandk to ndk_library.

Test: make native
Bug: http://b/30465923
Change-Id: Id62eac2d5cc518465445d87ce204fa918f0ddb68
diff --git a/Android.bp b/Android.bp
index 0990db6..0d7c30d 100644
--- a/Android.bp
+++ b/Android.bp
@@ -5,6 +5,13 @@
     srcs: ["include/camera/ndk/**/*.h"],
 }
 
+ndk_headers {
+    name: "libmediandk_headers",
+    from: "include/ndk/",
+    to: "media",
+    srcs: ["include/ndk/**/*.h"],
+}
+
 subdirs = [
     "camera/ndk",
     "media/libmedia",
diff --git a/include/ndk/NdkImage.h b/include/ndk/NdkImage.h
index cd0b11e..9a99287 100644
--- a/include/ndk/NdkImage.h
+++ b/include/ndk/NdkImage.h
@@ -36,12 +36,16 @@
 #ifndef _NDK_IMAGE_H
 #define _NDK_IMAGE_H
 
+#include <sys/cdefs.h>
+
 #include "NdkMediaError.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 24
+
 /**
  * AImage is an opaque type that provides access to image generated by {@link AImageReader}.
  */
@@ -604,6 +608,8 @@
         const AImage* image, int planeIdx,
         /*out*/uint8_t** data, /*out*/int* dataLength);
 
+#endif /* __ANDROID_API__ >= 24 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/include/ndk/NdkImageReader.h b/include/ndk/NdkImageReader.h
index 7c7ec6a..8d72c28 100644
--- a/include/ndk/NdkImageReader.h
+++ b/include/ndk/NdkImageReader.h
@@ -36,6 +36,8 @@
 #ifndef _NDK_IMAGE_READER_H
 #define _NDK_IMAGE_READER_H
 
+#include <sys/cdefs.h>
+
 #include <android/native_window.h>
 #include "NdkMediaError.h"
 #include "NdkImage.h"
@@ -44,6 +46,8 @@
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 24
+
 /**
  * AImage is an opaque type that allows direct application access to image data rendered into a
  * {@link ANativeWindow}.
@@ -294,6 +298,8 @@
 media_status_t AImageReader_setImageListener(
         AImageReader* reader, AImageReader_ImageListener* listener);
 
+#endif /* __ANDROID_API__ >= 24 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/include/ndk/NdkMediaCodec.h b/include/ndk/NdkMediaCodec.h
index fcb3a99..ad17321 100644
--- a/include/ndk/NdkMediaCodec.h
+++ b/include/ndk/NdkMediaCodec.h
@@ -27,6 +27,8 @@
 #ifndef _NDK_MEDIA_CODEC_H
 #define _NDK_MEDIA_CODEC_H
 
+#include <sys/cdefs.h>
+
 #include <android/native_window.h>
 
 #include "NdkMediaCrypto.h"
@@ -37,6 +39,7 @@
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 21
 
 struct AMediaCodec;
 typedef struct AMediaCodec AMediaCodec;
@@ -254,6 +257,8 @@
  */
 media_status_t AMediaCodecCryptoInfo_getEncryptedBytes(AMediaCodecCryptoInfo*, size_t *dst);
 
+#endif /* __ANDROID_API__ >= 21 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/include/ndk/NdkMediaCrypto.h b/include/ndk/NdkMediaCrypto.h
index 90374c5..9236765 100644
--- a/include/ndk/NdkMediaCrypto.h
+++ b/include/ndk/NdkMediaCrypto.h
@@ -28,6 +28,7 @@
 #ifndef _NDK_MEDIA_CRYPTO_H
 #define _NDK_MEDIA_CRYPTO_H
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 #include <stdbool.h>
 
@@ -35,6 +36,8 @@
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 21
+
 struct AMediaCrypto;
 typedef struct AMediaCrypto AMediaCrypto;
 
@@ -48,6 +51,7 @@
 
 void AMediaCrypto_delete(AMediaCrypto* crypto);
 
+#endif /* __ANDROID_API__ >= 21 */
 
 #ifdef __cplusplus
 } // extern "C"
diff --git a/include/ndk/NdkMediaDrm.h b/include/ndk/NdkMediaDrm.h
index 3c312a9..9dd6283 100644
--- a/include/ndk/NdkMediaDrm.h
+++ b/include/ndk/NdkMediaDrm.h
@@ -27,14 +27,17 @@
 #ifndef _NDK_MEDIA_DRM_H
 #define _NDK_MEDIA_DRM_H
 
+#include <stdbool.h>
+#include <stdint.h>
+#include <sys/cdefs.h>
+
 #include "NdkMediaError.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include <stdint.h>
-#include <stdbool.h>
+#if __ANDROID_API__ >= 21
 
 struct AMediaDrm;
 typedef struct AMediaDrm AMediaDrm;
@@ -448,6 +451,8 @@
         const char *macAlgorithm, uint8_t *keyId, const uint8_t *message, size_t messageSize,
         const uint8_t *signature, size_t signatureSize);
 
+#endif /* __ANDROID_API__ >= 21 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/include/ndk/NdkMediaError.h b/include/ndk/NdkMediaError.h
index 60d401b..fb00b1d 100644
--- a/include/ndk/NdkMediaError.h
+++ b/include/ndk/NdkMediaError.h
@@ -28,10 +28,14 @@
 #ifndef _NDK_MEDIA_ERROR_H
 #define _NDK_MEDIA_ERROR_H
 
+#include <sys/cdefs.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 21
+
 typedef enum {
     AMEDIA_OK = 0,
 
@@ -59,6 +63,7 @@
 
 } media_status_t;
 
+#endif /* __ANDROID_API__ >= 21 */
 
 #ifdef __cplusplus
 } // extern "C"
diff --git a/include/ndk/NdkMediaExtractor.h b/include/ndk/NdkMediaExtractor.h
index 7324d31..c3180dc 100644
--- a/include/ndk/NdkMediaExtractor.h
+++ b/include/ndk/NdkMediaExtractor.h
@@ -28,6 +28,7 @@
 #ifndef _NDK_MEDIA_EXTRACTOR_H
 #define _NDK_MEDIA_EXTRACTOR_H
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include "NdkMediaCodec.h"
@@ -38,6 +39,8 @@
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 21
+
 struct AMediaExtractor;
 typedef struct AMediaExtractor AMediaExtractor;
 
@@ -158,6 +161,8 @@
     AMEDIAEXTRACTOR_SAMPLE_FLAG_ENCRYPTED = 2,
 };
 
+#endif /* __ANDROID_API__ >= 21 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/include/ndk/NdkMediaFormat.h b/include/ndk/NdkMediaFormat.h
index ab29791..a2a21d2 100644
--- a/include/ndk/NdkMediaFormat.h
+++ b/include/ndk/NdkMediaFormat.h
@@ -27,6 +27,7 @@
 #ifndef _NDK_MEDIA_FORMAT_H
 #define _NDK_MEDIA_FORMAT_H
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include "NdkMediaError.h"
@@ -35,6 +36,8 @@
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 21
+
 struct AMediaFormat;
 typedef struct AMediaFormat AMediaFormat;
 
@@ -104,6 +107,8 @@
 extern const char* AMEDIAFORMAT_KEY_WIDTH;
 extern const char* AMEDIAFORMAT_KEY_STRIDE;
 
+#endif /* __ANDROID_API__ >= 21 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/include/ndk/NdkMediaMuxer.h b/include/ndk/NdkMediaMuxer.h
index 90d946c..25987a2 100644
--- a/include/ndk/NdkMediaMuxer.h
+++ b/include/ndk/NdkMediaMuxer.h
@@ -28,6 +28,7 @@
 #ifndef _NDK_MEDIA_MUXER_H
 #define _NDK_MEDIA_MUXER_H
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include "NdkMediaCodec.h"
@@ -38,6 +39,8 @@
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 21
+
 struct AMediaMuxer;
 typedef struct AMediaMuxer AMediaMuxer;
 
@@ -112,6 +115,8 @@
 media_status_t AMediaMuxer_writeSampleData(AMediaMuxer *muxer,
         size_t trackIdx, const uint8_t *data, const AMediaCodecBufferInfo *info);
 
+#endif /* __ANDROID_API__ >= 21 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/media/ndk/Android.bp b/media/ndk/Android.bp
new file mode 100644
index 0000000..1ac1eeb
--- /dev/null
+++ b/media/ndk/Android.bp
@@ -0,0 +1,23 @@
+// Copyright (C) 2016 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.
+
+// Headers module is in frameworks/av/Android.bp because modules are not allowed
+// to refer to headers in parent directories and the headers live in
+// frameworks/av/include.
+
+ndk_library {
+    name: "libmediandk.ndk",
+    symbol_file: "libmediandk.map.txt",
+    first_version: "21",
+}
diff --git a/media/ndk/libmediandk.map.txt b/media/ndk/libmediandk.map.txt
new file mode 100644
index 0000000..7db4d06
--- /dev/null
+++ b/media/ndk/libmediandk.map.txt
@@ -0,0 +1,141 @@
+LIBMEDIANDK {
+  global:
+    AImageReader_acquireLatestImage; # introduced=24
+    AImageReader_acquireNextImage; # introduced=24
+    AImageReader_delete; # introduced=24
+    AImageReader_getFormat; # introduced=24
+    AImageReader_getHeight; # introduced=24
+    AImageReader_getMaxImages; # introduced=24
+    AImageReader_getWidth; # introduced=24
+    AImageReader_getWindow; # introduced=24
+    AImageReader_new; # introduced=24
+    AImageReader_setImageListener; # introduced=24
+    AImage_delete; # introduced=24
+    AImage_getCropRect; # introduced=24
+    AImage_getFormat; # introduced=24
+    AImage_getHeight; # introduced=24
+    AImage_getNumberOfPlanes; # introduced=24
+    AImage_getPlaneData; # introduced=24
+    AImage_getPlanePixelStride; # introduced=24
+    AImage_getPlaneRowStride; # introduced=24
+    AImage_getTimestamp; # introduced=24
+    AImage_getWidth; # introduced=24
+    AMEDIAFORMAT_KEY_AAC_PROFILE; # var
+    AMEDIAFORMAT_KEY_BIT_RATE; # var
+    AMEDIAFORMAT_KEY_CHANNEL_COUNT; # var
+    AMEDIAFORMAT_KEY_CHANNEL_MASK; # var
+    AMEDIAFORMAT_KEY_COLOR_FORMAT; # var
+    AMEDIAFORMAT_KEY_DURATION; # var
+    AMEDIAFORMAT_KEY_FLAC_COMPRESSION_LEVEL; # var
+    AMEDIAFORMAT_KEY_FRAME_RATE; # var
+    AMEDIAFORMAT_KEY_HEIGHT; # var
+    AMEDIAFORMAT_KEY_IS_ADTS; # var
+    AMEDIAFORMAT_KEY_IS_AUTOSELECT; # var
+    AMEDIAFORMAT_KEY_IS_DEFAULT; # var
+    AMEDIAFORMAT_KEY_IS_FORCED_SUBTITLE; # var
+    AMEDIAFORMAT_KEY_I_FRAME_INTERVAL; # var
+    AMEDIAFORMAT_KEY_LANGUAGE; # var
+    AMEDIAFORMAT_KEY_MAX_HEIGHT; # var
+    AMEDIAFORMAT_KEY_MAX_INPUT_SIZE; # var
+    AMEDIAFORMAT_KEY_MAX_WIDTH; # var
+    AMEDIAFORMAT_KEY_MIME; # var
+    AMEDIAFORMAT_KEY_PUSH_BLANK_BUFFERS_ON_STOP; # var
+    AMEDIAFORMAT_KEY_REPEAT_PREVIOUS_FRAME_AFTER; # var
+    AMEDIAFORMAT_KEY_SAMPLE_RATE; # var
+    AMEDIAFORMAT_KEY_STRIDE; # var
+    AMEDIAFORMAT_KEY_WIDTH; # var
+    AMediaCodecCryptoInfo_delete;
+    AMediaCodecCryptoInfo_getClearBytes;
+    AMediaCodecCryptoInfo_getEncryptedBytes;
+    AMediaCodecCryptoInfo_getIV;
+    AMediaCodecCryptoInfo_getKey;
+    AMediaCodecCryptoInfo_getMode;
+    AMediaCodecCryptoInfo_getNumSubSamples;
+    AMediaCodecCryptoInfo_new;
+    AMediaCodecCryptoInfo_setPattern; # introduced=24
+    AMediaCodec_configure;
+    AMediaCodec_createCodecByName;
+    AMediaCodec_createDecoderByType;
+    AMediaCodec_createEncoderByType;
+    AMediaCodec_delete;
+    AMediaCodec_dequeueInputBuffer;
+    AMediaCodec_dequeueOutputBuffer;
+    AMediaCodec_flush;
+    AMediaCodec_getInputBuffer;
+    AMediaCodec_getOutputBuffer;
+    AMediaCodec_getOutputFormat;
+    AMediaCodec_queueInputBuffer;
+    AMediaCodec_queueSecureInputBuffer;
+    AMediaCodec_releaseOutputBuffer;
+    AMediaCodec_releaseOutputBufferAtTime;
+    AMediaCodec_setOutputSurface; # introduced=24
+    AMediaCodec_start;
+    AMediaCodec_stop;
+    AMediaCrypto_delete;
+    AMediaCrypto_isCryptoSchemeSupported;
+    AMediaCrypto_new;
+    AMediaCrypto_requiresSecureDecoderComponent;
+    AMediaDrm_closeSession;
+    AMediaDrm_createByUUID;
+    AMediaDrm_decrypt;
+    AMediaDrm_encrypt;
+    AMediaDrm_getKeyRequest;
+    AMediaDrm_getPropertyByteArray;
+    AMediaDrm_getPropertyString;
+    AMediaDrm_getProvisionRequest;
+    AMediaDrm_getSecureStops;
+    AMediaDrm_isCryptoSchemeSupported;
+    AMediaDrm_openSession;
+    AMediaDrm_provideKeyResponse;
+    AMediaDrm_provideProvisionResponse;
+    AMediaDrm_queryKeyStatus;
+    AMediaDrm_release;
+    AMediaDrm_releaseSecureStops;
+    AMediaDrm_removeKeys;
+    AMediaDrm_restoreKeys;
+    AMediaDrm_setOnEventListener;
+    AMediaDrm_setPropertyByteArray;
+    AMediaDrm_setPropertyString;
+    AMediaDrm_sign;
+    AMediaDrm_verify;
+    AMediaExtractor_advance;
+    AMediaExtractor_delete;
+    AMediaExtractor_getPsshInfo;
+    AMediaExtractor_getSampleCryptoInfo;
+    AMediaExtractor_getSampleFlags;
+    AMediaExtractor_getSampleTime;
+    AMediaExtractor_getSampleTrackIndex;
+    AMediaExtractor_getTrackCount;
+    AMediaExtractor_getTrackFormat;
+    AMediaExtractor_new;
+    AMediaExtractor_readSampleData;
+    AMediaExtractor_seekTo;
+    AMediaExtractor_selectTrack;
+    AMediaExtractor_setDataSource;
+    AMediaExtractor_setDataSourceFd;
+    AMediaExtractor_unselectTrack;
+    AMediaFormat_delete;
+    AMediaFormat_getBuffer;
+    AMediaFormat_getFloat;
+    AMediaFormat_getInt32;
+    AMediaFormat_getInt64;
+    AMediaFormat_getSize;
+    AMediaFormat_getString;
+    AMediaFormat_new;
+    AMediaFormat_setBuffer;
+    AMediaFormat_setFloat;
+    AMediaFormat_setInt32;
+    AMediaFormat_setInt64;
+    AMediaFormat_setString;
+    AMediaFormat_toString;
+    AMediaMuxer_addTrack;
+    AMediaMuxer_delete;
+    AMediaMuxer_new;
+    AMediaMuxer_setLocation;
+    AMediaMuxer_setOrientationHint;
+    AMediaMuxer_start;
+    AMediaMuxer_stop;
+    AMediaMuxer_writeSampleData;
+  local:
+    *;
+};