mirror of https://github.com/axmolengine/axmol.git
Merge pull request #1197 from mustime/bug1284
issue #1284: fix a compile error for missing android.so
This commit is contained in:
commit
c8808b5be2
|
@ -10,9 +10,6 @@ LOCAL_SRC_FILES := SimpleAudioEngine.cpp \
|
|||
opensl/OpenSLEngine.cpp \
|
||||
opensl/SimpleAudioEngineOpenSL.cpp
|
||||
|
||||
LOCAL_EXPORT_LDLIBS := -landroid
|
||||
|
||||
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include \
|
||||
|
|
|
@ -124,6 +124,7 @@ extern "C" {
|
|||
#define FILE_NOT_FOUND -1
|
||||
|
||||
#define ASSET_MANAGER_GETTER "getAssetManager"
|
||||
#define LIBANDROID "libandroid.so"
|
||||
|
||||
#define MIN_VOLUME_MILLIBEL -4000
|
||||
#define MAX_VOLUME_MILLIBEL 0
|
||||
|
@ -141,7 +142,8 @@ struct AudioPlayer
|
|||
typedef map<unsigned int, vector<AudioPlayer*>* > EffectList;
|
||||
typedef pair<unsigned int, vector<AudioPlayer*>* > Effect;
|
||||
|
||||
void* s_pHandle = NULL;
|
||||
void* s_pAndroidHandle = NULL;
|
||||
void* s_pOpenSLESHandle = NULL;
|
||||
|
||||
static EffectList& sharedList()
|
||||
{
|
||||
|
@ -167,7 +169,7 @@ SLInterfaceID getInterfaceID(const char *value)
|
|||
{
|
||||
// clear the error stack
|
||||
dlerror();
|
||||
SLInterfaceID* IID = (SLInterfaceID*)dlsym(s_pHandle, value);
|
||||
SLInterfaceID* IID = (SLInterfaceID*)dlsym(s_pOpenSLESHandle, value);
|
||||
const char* errorInfo = dlerror();
|
||||
if (errorInfo)
|
||||
{
|
||||
|
@ -181,7 +183,7 @@ void* getFuncPtr(const char *value)
|
|||
{
|
||||
// clear the error stack
|
||||
dlerror();
|
||||
void* funcPtr = dlsym(s_pHandle, value);
|
||||
void* funcPtr = dlsym(s_pOpenSLESHandle, value);
|
||||
const char* errorInfo = dlerror();
|
||||
if (errorInfo)
|
||||
{
|
||||
|
@ -202,9 +204,15 @@ int getFileDescriptor(const char * filename, off_t & start, off_t & length)
|
|||
jobject assetManager = methodInfo.env->CallStaticObjectMethod(methodInfo.classID, methodInfo.methodID);
|
||||
methodInfo.env->DeleteLocalRef(methodInfo.classID);
|
||||
|
||||
AAssetManager* (*AAssetManager_fromJava)(JNIEnv* env, jobject assetManager);
|
||||
AAssetManager_fromJava = (AAssetManager* (*)(JNIEnv* env, jobject assetManager))
|
||||
dlsym(s_pAndroidHandle, "AAssetManager_fromJava");
|
||||
AAssetManager* mgr = AAssetManager_fromJava(methodInfo.env, assetManager);
|
||||
assert(NULL != mgr);
|
||||
|
||||
AAsset* (*AAssetManager_open)(AAssetManager* mgr, const char* filename, int mode);
|
||||
AAssetManager_open = (AAsset* (*)(AAssetManager* mgr, const char* filename, int mode))
|
||||
dlsym(s_pAndroidHandle, "AAssetManager_open");
|
||||
AAsset* Asset = AAssetManager_open(mgr, filename, AASSET_MODE_UNKNOWN);
|
||||
if (NULL == Asset)
|
||||
{
|
||||
|
@ -213,8 +221,15 @@ int getFileDescriptor(const char * filename, off_t & start, off_t & length)
|
|||
}
|
||||
|
||||
// open asset as file descriptor
|
||||
int (*AAsset_openFileDescriptor)(AAsset* asset, off_t* outStart, off_t* outLength);
|
||||
AAsset_openFileDescriptor = (int (*)(AAsset* asset, off_t* outStart, off_t* outLength))
|
||||
dlsym(s_pAndroidHandle, "AAsset_openFileDescriptor");
|
||||
int fd = AAsset_openFileDescriptor(Asset, &start, &length);
|
||||
assert(0 <= fd);
|
||||
|
||||
void (*AAsset_close)(AAsset* asset);
|
||||
AAsset_close = (void (*)(AAsset* asset))
|
||||
dlsym(s_pAndroidHandle, "AAsset_close");
|
||||
AAsset_close(Asset);
|
||||
|
||||
return fd;
|
||||
|
@ -297,7 +312,19 @@ void destroyAudioPlayer(AudioPlayer * player)
|
|||
|
||||
void OpenSLEngine::createEngine(void* pHandle)
|
||||
{
|
||||
s_pHandle = pHandle;
|
||||
assert(pHandle != NULL);
|
||||
s_pOpenSLESHandle = pHandle;
|
||||
|
||||
// clear the error stack
|
||||
dlerror();
|
||||
s_pAndroidHandle = dlopen(LIBANDROID, RTLD_LAZY);
|
||||
const char* errorInfo = dlerror();
|
||||
if (errorInfo)
|
||||
{
|
||||
LOGD(errorInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
SLresult result;
|
||||
if (s_pEngineObject == NULL)
|
||||
{
|
||||
|
|
|
@ -12,10 +12,11 @@
|
|||
#include "SLES/OpenSLES.h"
|
||||
#include "SLES/OpenSLES_Android.h"
|
||||
#include <sys/types.h>
|
||||
#include <android/asset_manager.h>
|
||||
#include <android/asset_manager_jni.h>
|
||||
#include "android/asset_manager.h"
|
||||
#include "android/asset_manager_jni.h"
|
||||
#include <android/log.h>
|
||||
#include <jni/JniHelper.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
|
||||
class OpenSLEngine
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Copyright (C) 2010 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 ANDROID_ASSET_MANAGER_H
|
||||
#define ANDROID_ASSET_MANAGER_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct AAssetManager;
|
||||
typedef struct AAssetManager AAssetManager;
|
||||
|
||||
struct AAssetDir;
|
||||
typedef struct AAssetDir AAssetDir;
|
||||
|
||||
struct AAsset;
|
||||
typedef struct AAsset AAsset;
|
||||
|
||||
/* Available modes for opening assets */
|
||||
enum {
|
||||
AASSET_MODE_UNKNOWN = 0,
|
||||
AASSET_MODE_RANDOM = 1,
|
||||
AASSET_MODE_STREAMING = 2,
|
||||
AASSET_MODE_BUFFER = 3
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Open the named directory within the asset hierarchy. The directory can then
|
||||
* be inspected with the AAssetDir functions. To open the top-level directory,
|
||||
* pass in "" as the dirName.
|
||||
*
|
||||
* The object returned here should be freed by calling AAssetDir_close().
|
||||
*/
|
||||
AAssetDir* AAssetManager_openDir(AAssetManager* mgr, const char* dirName);
|
||||
|
||||
/**
|
||||
* Open an asset.
|
||||
*
|
||||
* The object returned here should be freed by calling AAsset_close().
|
||||
*/
|
||||
AAsset* AAssetManager_open(AAssetManager* mgr, const char* filename, int mode);
|
||||
|
||||
/**
|
||||
* Iterate over the files in an asset directory. A NULL string is returned
|
||||
* when all the file names have been returned.
|
||||
*
|
||||
* The returned file name is suitable for passing to AAssetManager_open().
|
||||
*
|
||||
* The string returned here is owned by the AssetDir implementation and is not
|
||||
* guaranteed to remain valid if any other calls are made on this AAssetDir
|
||||
* instance.
|
||||
*/
|
||||
const char* AAssetDir_getNextFileName(AAssetDir* assetDir);
|
||||
|
||||
/**
|
||||
* Reset the iteration state of AAssetDir_getNextFileName() to the beginning.
|
||||
*/
|
||||
void AAssetDir_rewind(AAssetDir* assetDir);
|
||||
|
||||
/**
|
||||
* Close an opened AAssetDir, freeing any related resources.
|
||||
*/
|
||||
void AAssetDir_close(AAssetDir* assetDir);
|
||||
|
||||
/**
|
||||
* Attempt to read 'count' bytes of data from the current offset.
|
||||
*
|
||||
* Returns the number of bytes read, zero on EOF, or < 0 on error.
|
||||
*/
|
||||
int AAsset_read(AAsset* asset, void* buf, size_t count);
|
||||
|
||||
/**
|
||||
* Seek to the specified offset within the asset data. 'whence' uses the
|
||||
* same constants as lseek()/fseek().
|
||||
*
|
||||
* Returns the new position on success, or (off_t) -1 on error.
|
||||
*/
|
||||
off_t AAsset_seek(AAsset* asset, off_t offset, int whence);
|
||||
|
||||
/**
|
||||
* Close the asset, freeing all associated resources.
|
||||
*/
|
||||
void AAsset_close(AAsset* asset);
|
||||
|
||||
/**
|
||||
* Get a pointer to a buffer holding the entire contents of the assset.
|
||||
*
|
||||
* Returns NULL on failure.
|
||||
*/
|
||||
const void* AAsset_getBuffer(AAsset* asset);
|
||||
|
||||
/**
|
||||
* Report the total size of the asset data.
|
||||
*/
|
||||
off_t AAsset_getLength(AAsset* asset);
|
||||
|
||||
/**
|
||||
* Report the total amount of asset data that can be read from the current position.
|
||||
*/
|
||||
off_t AAsset_getRemainingLength(AAsset* asset);
|
||||
|
||||
/**
|
||||
* Open a new file descriptor that can be used to read the asset data.
|
||||
*
|
||||
* Returns < 0 if direct fd access is not possible (for example, if the asset is
|
||||
* compressed).
|
||||
*/
|
||||
int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength);
|
||||
|
||||
/**
|
||||
* Returns whether this asset's internal buffer is allocated in ordinary RAM (i.e. not
|
||||
* mmapped).
|
||||
*/
|
||||
int AAsset_isAllocated(AAsset* asset);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // ANDROID_ASSET_MANAGER_H
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (C) 2010 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 ANDROID_ASSET_MANAGER_JNI_H
|
||||
#define ANDROID_ASSET_MANAGER_JNI_H
|
||||
|
||||
#include "asset_manager.h"
|
||||
#include <jni.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Given a Dalvik AssetManager object, obtain the corresponding native AAssetManager
|
||||
* object. Note that the caller is responsible for obtaining and holding a VM reference
|
||||
* to the jobject to prevent its being garbage collected while the native object is
|
||||
* in use.
|
||||
*/
|
||||
AAssetManager* AAssetManager_fromJava(JNIEnv* env, jobject assetManager);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // ANDROID_ASSET_MANAGER_JNI_H
|
Loading…
Reference in New Issue