mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
完善Android工程
This commit is contained in:
parent
d30869d0c9
commit
a44b770d9d
@ -13,6 +13,7 @@ android {
|
|||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
cppFlags "-std=c++11 -frtti -fexceptions"
|
cppFlags "-std=c++11 -frtti -fexceptions"
|
||||||
|
arguments "-DENABLE_API=off", "-DENABLE_TESTS=off", "-DENABLE_PLAYER=off", "-DENABLE_SERVER_LIB=on"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ndk {
|
ndk {
|
||||||
|
@ -6,106 +6,30 @@ set(CMAKE_CXX_STANDARD 11)
|
|||||||
#设置生成的so动态库最后输出的路径
|
#设置生成的so动态库最后输出的路径
|
||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/libs_export/${ANDROID_ABI})
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/libs_export/${ANDROID_ABI})
|
||||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/libs_export/${ANDROID_ABI})
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/libs_export/${ANDROID_ABI})
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libs_export/${ANDROID_ABI}/binary)
|
||||||
LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH})
|
set(OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${ANDROID_ABI}/")
|
||||||
|
|
||||||
#设置工程源码根目录
|
#设置工程源码根目录
|
||||||
set(ZLMediaKit_Root ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../)
|
|
||||||
set(JNI_Root ${CMAKE_CURRENT_SOURCE_DIR})
|
set(JNI_Root ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
set(ToolKit_Root ${ZLMediaKit_Root}/3rdpart/ZLToolKit/src)
|
set(ZLMediaKit_Root ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../)
|
||||||
set(MediaKit_Root ${ZLMediaKit_Root}/src)
|
|
||||||
set(MediaServer_Root ${ZLMediaKit_Root}/3rdpart/media-server/)
|
|
||||||
|
|
||||||
#设置头文件目录
|
#添加主工程cmake
|
||||||
INCLUDE_DIRECTORIES(${ToolKit_Root})
|
add_subdirectory(${ZLMediaKit_Root} ${EXECUTABLE_OUTPUT_PATH})
|
||||||
INCLUDE_DIRECTORIES(${MediaKit_Root})
|
|
||||||
INCLUDE_DIRECTORIES(${JNI_Root})
|
|
||||||
|
|
||||||
#收集源代码
|
#设置include
|
||||||
file(GLOB ToolKit_src_list ${ToolKit_Root}/*/*.cpp ${ToolKit_Root}/*/*.h ${ToolKit_Root}/*/*.c)
|
include_directories(${JNI_Root})
|
||||||
file(GLOB MediaKit_src_list ${MediaKit_Root}/*/*.cpp ${MediaKit_Root}/*/*.h ${MediaKit_Root}/*/*.c)
|
include_directories(${ZLMediaKit_Root}/src)
|
||||||
|
include_directories(${ZLMediaKit_Root}/srt)
|
||||||
|
include_directories(${ZLMediaKit_Root}/webrtc)
|
||||||
|
include_directories(${ZLMediaKit_Root}/server)
|
||||||
|
include_directories(${ZLMediaKit_Root}/3rdpart)
|
||||||
|
include_directories(${ZLMediaKit_Root}/3rdpart/media-server)
|
||||||
|
include_directories(${ZLMediaKit_Root}/3rdpart/ZLToolKit/src)
|
||||||
|
|
||||||
|
#收集源代码添加动态库
|
||||||
file(GLOB JNI_src_list ${JNI_Root}/*.cpp ${JNI_Root}/*.h)
|
file(GLOB JNI_src_list ${JNI_Root}/*.cpp ${JNI_Root}/*.h)
|
||||||
|
|
||||||
#去除win32的适配代码
|
|
||||||
if (NOT WIN32)
|
|
||||||
list(REMOVE_ITEM ToolKit_src_list ${ToolKit_Root}/win32/getopt.c)
|
|
||||||
else()
|
|
||||||
#防止Windows.h包含Winsock.h
|
|
||||||
add_definitions(-DWIN32_LEAN_AND_MEAN -DMP4V2_NO_STDINT_DEFS)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
set(ENABLE_HLS true)
|
|
||||||
set(ENABLE_OPENSSL true)
|
|
||||||
set(ENABLE_MYSQL false)
|
|
||||||
set(ENABLE_FAAC false)
|
|
||||||
set(ENABLE_X264 false)
|
|
||||||
set(ENABLE_MP4 true)
|
|
||||||
|
|
||||||
#添加两个静态库
|
|
||||||
if(ENABLE_HLS)
|
|
||||||
message(STATUS "ENABLE_HLS defined")
|
|
||||||
add_definitions(-DENABLE_HLS)
|
|
||||||
set(LINK_LIB_LIST zlmediakit zltoolkit mpeg)
|
|
||||||
else()
|
|
||||||
set(LINK_LIB_LIST zlmediakit zltoolkit)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
if(ENABLE_MP4)
|
|
||||||
message(STATUS "ENABLE_MP4 defined")
|
|
||||||
add_definitions(-DENABLE_MP4)
|
|
||||||
list(APPEND LINK_LIB_LIST mov flv)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (ENABLE_OPENSSL)
|
|
||||||
#openssl
|
|
||||||
add_definitions(-DENABLE_OPENSSL)
|
|
||||||
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}/include)
|
|
||||||
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}/)
|
|
||||||
list(APPEND LINK_LIB_LIST ssl crypto)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
#libmpeg
|
|
||||||
if(ENABLE_HLS)
|
|
||||||
aux_source_directory(${MediaServer_Root}/libmpeg/include src_mpeg)
|
|
||||||
aux_source_directory(${MediaServer_Root}/libmpeg/source src_mpeg)
|
|
||||||
include_directories(${MediaServer_Root}/libmpeg/include)
|
|
||||||
add_library(mpeg STATIC ${src_mpeg})
|
|
||||||
if(MSVC)
|
|
||||||
set_target_properties(mpeg PROPERTIES COMPILE_FLAGS ${VS_FALGS} )
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(ENABLE_MP4)
|
|
||||||
aux_source_directory(${MediaServer_Root}/libmov/include src_mov)
|
|
||||||
aux_source_directory(${MediaServer_Root}/libmov/source src_mov)
|
|
||||||
include_directories(${MediaServer_Root}/libmov/include)
|
|
||||||
aux_source_directory(${MediaServer_Root}/libflv/include src_flv)
|
|
||||||
aux_source_directory(${MediaServer_Root}/libflv/source src_flv)
|
|
||||||
include_directories(${MediaServer_Root}/libflv/include)
|
|
||||||
add_library(mov STATIC ${src_mov})
|
|
||||||
add_library(flv STATIC ${src_flv})
|
|
||||||
if(MSVC)
|
|
||||||
set_target_properties(mov flv PROPERTIES COMPILE_FLAGS ${VS_FALGS} )
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
#添加库
|
|
||||||
add_library(zltoolkit STATIC ${ToolKit_src_list})
|
|
||||||
add_library(zlmediakit STATIC ${MediaKit_src_list})
|
|
||||||
add_library(zlmediakit_jni SHARED ${JNI_src_list})
|
add_library(zlmediakit_jni SHARED ${JNI_src_list})
|
||||||
|
|
||||||
add_definitions(-DDISABLE_MAIN)
|
|
||||||
#添加json以及MediaServer相关代码
|
|
||||||
include_directories(${ZLMediaKit_Root}/3rdpart)
|
|
||||||
include_directories(${ZLMediaKit_Root}/server)
|
|
||||||
file(GLOB jsoncpp_src_list ${ZLMediaKit_Root}/3rdpart/jsoncpp/*.cpp)
|
|
||||||
file(GLOB MediaServer_src_list ${ZLMediaKit_Root}/server/*.cpp)
|
|
||||||
add_library(jsoncpp STATIC ${jsoncpp_src_list})
|
|
||||||
add_library(MediaServer STATIC ${MediaServer_src_list})
|
|
||||||
|
|
||||||
#链接
|
#链接
|
||||||
target_link_libraries(zlmediakit_jni MediaServer jsoncpp ${LINK_LIB_LIST} log z)
|
target_link_libraries(zlmediakit_jni -Wl,--start-group log z ${LINK_LIB_LIST} -Wl,--end-group)
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "Common/config.h"
|
#include "Common/config.h"
|
||||||
#include "Player/MediaPlayer.h"
|
#include "Player/MediaPlayer.h"
|
||||||
#include "Extension/Frame.h"
|
#include "Extension/Frame.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
@ -23,7 +24,6 @@ using namespace mediakit;
|
|||||||
#define MediaPlayerCallBackSign "com/zlmediakit/jni/ZLMediaKit$MediaPlayerCallBack"
|
#define MediaPlayerCallBackSign "com/zlmediakit/jni/ZLMediaKit$MediaPlayerCallBack"
|
||||||
#define MediaFrameSign "com/zlmediakit/jni/ZLMediaKit$MediaFrame"
|
#define MediaFrameSign "com/zlmediakit/jni/ZLMediaKit$MediaFrame"
|
||||||
|
|
||||||
|
|
||||||
string stringFromJstring(JNIEnv *env, jstring jstr) {
|
string stringFromJstring(JNIEnv *env, jstring jstr) {
|
||||||
if (!env || !jstr) {
|
if (!env || !jstr) {
|
||||||
WarnL << "invalid args";
|
WarnL << "invalid args";
|
||||||
@ -34,6 +34,7 @@ string stringFromJstring(JNIEnv *env,jstring jstr){
|
|||||||
env->ReleaseStringUTFChars(jstr, field_char);
|
env->ReleaseStringUTFChars(jstr, field_char);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
string stringFromJbytes(JNIEnv *env, jbyteArray jbytes) {
|
string stringFromJbytes(JNIEnv *env, jbyteArray jbytes) {
|
||||||
if (!env || !jbytes) {
|
if (!env || !jbytes) {
|
||||||
WarnL << "invalid args";
|
WarnL << "invalid args";
|
||||||
@ -44,6 +45,7 @@ string stringFromJbytes(JNIEnv *env,jbyteArray jbytes){
|
|||||||
env->ReleaseByteArrayElements(jbytes, bytes, 0);
|
env->ReleaseByteArrayElements(jbytes, bytes, 0);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
string stringFieldFromJava(JNIEnv *env, jobject jdata, jfieldID jid) {
|
string stringFieldFromJava(JNIEnv *env, jobject jdata, jfieldID jid) {
|
||||||
if (!env || !jdata || !jid) {
|
if (!env || !jdata || !jid) {
|
||||||
WarnL << "invalid args";
|
WarnL << "invalid args";
|
||||||
@ -160,6 +162,7 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved){
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern int start_main(int argc,char *argv[]);
|
extern int start_main(int argc,char *argv[]);
|
||||||
|
|
||||||
JNI_API(jboolean, startDemo, jstring ini_dir){
|
JNI_API(jboolean, startDemo, jstring ini_dir){
|
||||||
string sd_path = stringFromJstring(env,ini_dir);
|
string sd_path = stringFromJstring(env,ini_dir);
|
||||||
string ini_file = sd_path + "/zlmediakit.ini";
|
string ini_file = sd_path + "/zlmediakit.ini";
|
||||||
@ -196,7 +199,6 @@ JNI_API(jboolean,startDemo,jstring ini_dir){
|
|||||||
|
|
||||||
int argc = 5;
|
int argc = 5;
|
||||||
const char *argv[] = {"", "-c", ini_file.data(), "-s", pem_file.data()};
|
const char *argv[] = {"", "-c", ini_file.data(), "-s", pem_file.data()};
|
||||||
|
|
||||||
start_main(argc, (char **) argv);
|
start_main(argc, (char **) argv);
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
WarnL << ex.what();
|
WarnL << ex.what();
|
||||||
@ -260,8 +262,6 @@ JNI_API(jlong,createMediaPlayer,jstring url,jobject callback){
|
|||||||
return (jlong)(ret);
|
return (jlong)(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JNI_API(void,releaseMediaPlayer,jlong ptr){
|
JNI_API(void,releaseMediaPlayer,jlong ptr){
|
||||||
MediaPlayer::Ptr *player = (MediaPlayer::Ptr *)ptr;
|
MediaPlayer::Ptr *player = (MediaPlayer::Ptr *)ptr;
|
||||||
delete player;
|
delete player;
|
||||||
|
@ -98,6 +98,7 @@ option(ENABLE_API "Enable C API SDK" true)
|
|||||||
option(ENABLE_CXX_API "Enable C++ API SDK" false)
|
option(ENABLE_CXX_API "Enable C++ API SDK" false)
|
||||||
option(ENABLE_TESTS "Enable Tests" true)
|
option(ENABLE_TESTS "Enable Tests" true)
|
||||||
option(ENABLE_SERVER "Enable Server" true)
|
option(ENABLE_SERVER "Enable Server" true)
|
||||||
|
option(ENABLE_SERVER_LIB "Enable server as android static library" false)
|
||||||
option(ENABLE_MEM_DEBUG "Enable Memory Debug" false)
|
option(ENABLE_MEM_DEBUG "Enable Memory Debug" false)
|
||||||
option(ENABLE_ASAN "Enable Address Sanitize" false)
|
option(ENABLE_ASAN "Enable Address Sanitize" false)
|
||||||
option(ENABLE_WEBRTC "Enable WebRTC" true)
|
option(ENABLE_WEBRTC "Enable WebRTC" true)
|
||||||
@ -307,7 +308,7 @@ if (JEMALLOC_FOUND)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
#查找openssl是否安装
|
#查找openssl是否安装
|
||||||
find_package(OpenSSL QUIET)
|
find_package(OPENSSL QUIET)
|
||||||
if (OPENSSL_FOUND AND ENABLE_OPENSSL)
|
if (OPENSSL_FOUND AND ENABLE_OPENSSL)
|
||||||
message(STATUS "found library:${OPENSSL_LIBRARIES},ENABLE_OPENSSL defined")
|
message(STATUS "found library:${OPENSSL_LIBRARIES},ENABLE_OPENSSL defined")
|
||||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||||
@ -521,3 +522,7 @@ endif ()
|
|||||||
if (ENABLE_PLAYER)
|
if (ENABLE_PLAYER)
|
||||||
add_subdirectory(player)
|
add_subdirectory(player)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (ENABLE_SERVER_LIB)
|
||||||
|
set(LINK_LIB_LIST ${LINK_LIB_LIST} PARENT_SCOPE)
|
||||||
|
endif ()
|
||||||
|
@ -3,6 +3,14 @@ file(GLOB jsoncpp_src_list ../3rdpart/jsoncpp/*.cpp ../3rdpart/jsoncpp/*.h )
|
|||||||
add_library(jsoncpp STATIC ${jsoncpp_src_list})
|
add_library(jsoncpp STATIC ${jsoncpp_src_list})
|
||||||
file(GLOB MediaServer_src_list ./*.cpp ./*.h)
|
file(GLOB MediaServer_src_list ./*.cpp ./*.h)
|
||||||
|
|
||||||
|
if (ENABLE_SERVER_LIB)
|
||||||
|
add_definitions(-DDISABLE_MAIN)
|
||||||
|
add_library(MediaServer STATIC ${MediaServer_src_list})
|
||||||
|
list(APPEND LINK_LIB_LIST MediaServer jsoncpp)
|
||||||
|
set(LINK_LIB_LIST ${LINK_LIB_LIST} PARENT_SCOPE)
|
||||||
|
return()
|
||||||
|
endif ()
|
||||||
|
|
||||||
add_executable(MediaServer ${MediaServer_src_list})
|
add_executable(MediaServer ${MediaServer_src_list})
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
|
Loading…
Reference in New Issue
Block a user