diff --git a/faad2/BUILD.gn b/faad2/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..580168a770366364f8b9ba5111b57b238e7fbeea --- /dev/null +++ b/faad2/BUILD.gn @@ -0,0 +1,117 @@ +import("//build/ohos.gni") + +declare_args() { + enable_faad2_test = false +} + +config("config") { + cflags = [ + "-fPIC", + "-Wall", + "-Wextra", + "-fexceptions", + "-Wno-error=unused-parameter", + "-Wno-error=int-conversion", + "-Wno-error=constant-conversion", + "-Wno-error=format", + "-Wno-incompatible-pointer-types", + "-Wno-parentheses", + "-Wno-unused-variable", + "-Wno-absolute-value", + "-Wno-unused-function", + "-Wno-unused-const-variable", + "-Wno-unused-label", + "-Wno-implicit-function-declaration", + "-DHAVE_CONFIG_H", + "-Wno-error=missing-field-initializers", + "-Wno-error=sign-compare", + "-Wno-error=misleading-indentation", + "-Wno-error=comment", + ] +} + +ohos_source_set("faad2_source") { + sources = [ + "//third_party/faad2/frontend/audio.c", + "//third_party/faad2/frontend/getopt.c", + "//third_party/faad2/frontend/mp4read.c", + "//third_party/faad2/frontend/unicode_support.c", + "//third_party/faad2/libfaad/bits.c", + "//third_party/faad2/libfaad/cfft.c", + "//third_party/faad2/libfaad/common.c", + "//third_party/faad2/libfaad/decoder.c", + "//third_party/faad2/libfaad/drc.c", + "//third_party/faad2/libfaad/drm_dec.c", + "//third_party/faad2/libfaad/error.c", + "//third_party/faad2/libfaad/filtbank.c", + "//third_party/faad2/libfaad/hcr.c", + "//third_party/faad2/libfaad/huffman.c", + "//third_party/faad2/libfaad/ic_predict.c", + "//third_party/faad2/libfaad/is.c", + "//third_party/faad2/libfaad/lt_predict.c", + "//third_party/faad2/libfaad/mdct.c", + "//third_party/faad2/libfaad/mp4.c", + "//third_party/faad2/libfaad/ms.c", + "//third_party/faad2/libfaad/output.c", + "//third_party/faad2/libfaad/pns.c", + "//third_party/faad2/libfaad/ps_dec.c", + "//third_party/faad2/libfaad/ps_syntax.c", + "//third_party/faad2/libfaad/pulse.c", + "//third_party/faad2/libfaad/rvlc.c", + "//third_party/faad2/libfaad/sbr_dct.c", + "//third_party/faad2/libfaad/sbr_dec.c", + "//third_party/faad2/libfaad/sbr_e_nf.c", + "//third_party/faad2/libfaad/sbr_fbt.c", + "//third_party/faad2/libfaad/sbr_hfadj.c", + "//third_party/faad2/libfaad/sbr_hfgen.c", + "//third_party/faad2/libfaad/sbr_huff.c", + "//third_party/faad2/libfaad/sbr_qmf.c", + "//third_party/faad2/libfaad/sbr_syntax.c", + "//third_party/faad2/libfaad/sbr_tf_grid.c", + "//third_party/faad2/libfaad/specrec.c", + "//third_party/faad2/libfaad/ssr.c", + "//third_party/faad2/libfaad/ssr_fb.c", + "//third_party/faad2/libfaad/ssr_ipqf.c", + "//third_party/faad2/libfaad/syntax.c", + "//third_party/faad2/libfaad/tns.c", + ] + include_dirs = [ + "//third_party/faad2/", + "//third_party/faad2/include", + "//third_party/faad2/libfaad", + "//third_party/faad2/libfaad/codebook", + "//third_party/faad2/frontend", + ] + configs = [ ":config" ] +} + +ohos_executable("faad2_test") { + sources = [ "//third_party/faad2/frontend/main.c" ] + include_dirs = [ + "//third_party/faad2/", + "//third_party/faad2/frontend", + "//third_party/faad2/include", + "//third_party/faad2/libfaad", + "//third_party/faad2/libfaad/codebook", + ] + + configs = [ ":config" ] + + deps = [ "//third_party/faad2:libfaad2" ] + subsystem_name = "thirdparty" + part_name = "faad2" + output_name = "faad2_test" +} + +ohos_shared_library("libfaad2") { + deps = [ ":faad2_source" ] + part_name = "faad2" + output_name = "faad2" +} + +group("faad2_targets") { + deps = [ ":libfaad2" ] + if (enable_faad2_test) { + deps += [ ":faad2_test" ] + } +} diff --git a/faad2/CHANGELOG.md b/faad2/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..4963dc7546e7cc84baf8e836c544ddf43f554025 --- /dev/null +++ b/faad2/CHANGELOG.md @@ -0,0 +1,3 @@ +# 1.0.0 + +添加BUILD.gn和cmake,适配在ohos上的编译 diff --git a/faad2/CMakeLists.txt b/faad2/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..89d8882dc85d331e25df66809b42776f9f94773b --- /dev/null +++ b/faad2/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(faad2) + +set(FAAD2_OPTION -DHAVE_CONFIG_H) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/libfaad + ${CMAKE_CURRENT_SOURCE_DIR}/libfaad/codebook) + +file(GLOB libfaad_source libfaad/*.c) +add_library(faad2 SHARED ${libfaad_source}) +target_compile_definitions(faad2 PRIVATE ${FAAD2_OPTION}) \ No newline at end of file diff --git a/faad2/README.OpenSource b/faad2/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..dfb08392777416ce2346ccd37bd3517e3ae13ab3 --- /dev/null +++ b/faad2/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "faad2", + "License": "GPL", + "License File": "COPYING", + "Version Number": "v2.10.1", + "Owner" : "wupingyuan@huawei.com", + "Upstream URL": "https://github.com/knik0/faad2", + "Description": "FAAD2 is a HE, LC, MAIN and LTP profile, MPEG2 and MPEG-4 AAC decoder." + } +] diff --git a/faad2/README_zh.md b/faad2/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..936ea10cce9e5d7f0686c82f972603039e056d2c --- /dev/null +++ b/faad2/README_zh.md @@ -0,0 +1,19 @@ +# faad2 三方库说明 + +## 功能简介 + +FAAD2 是一个音频解码的库。 + +## 使用约束 + +- Rom版本:OpenHarmony3.2 beta2 +- IDE版本:DevEco Studio 3.1 Beta1 +- API版本:9 +- 三方库版本:v2.10.1 +- 当前适配的功能:音频解码 +- License:[GPL](https://github.com/knik0/faad2/blob/master/COPYING) + +## 集成方式 + +- [系统Rom包集成](./docs/rom_integrate.md) ++ [应用hap包集成](docs/hap_integrate.md) diff --git a/faad2/adapted/config.h b/faad2/adapted/config.h new file mode 100644 index 0000000000000000000000000000000000000000..893bc1790a6da42dfecc15555e36640bf582d337 --- /dev/null +++ b/faad2/adapted/config.h @@ -0,0 +1,137 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +#undef AC_APPLE_UNIVERSAL_BUILD + +/* Define if you want to use libfaad together with Digital Radio Mondiale + (DRM) */ +#undef DRM + +/* Define if you want support for Digital Radio Mondiale (DRM) parametric + stereo */ +#undef DRM_PS + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_ERRNO_H + +/* Define if needed */ +#undef HAVE_FLOAT32_T + +/* Define to 1 if you have the header file. */ +#undef HAVE_FLOAT_H + +/* Define to 1 if you have the `getpwuid' function. */ +#undef HAVE_GETPWUID + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define if you have the IOKit API */ +#undef HAVE_IOKIT_IOKITLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_LIMITS_H + +/* Define if you have C99's lrintf function. */ +#undef HAVE_LRINTF + +/* Define to 1 if you have the header file. */ +#undef HAVE_MATHF_H + +/* Define to 1 if you have the `memcpy' function. */ +#define HAVE_MEMCPY 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strchr' function. */ +#undef HAVE_STRCHR + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strsep' function. */ +#undef HAVE_STRSEP + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYSFS_LIBSYSFS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TIME_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#undef LT_OBJDIR + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "2.10.1" + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to 1 if you can safely include both and . */ +#undef TIME_WITH_SYS_TIME + +/* Version number of package */ +#undef VERSION + +#define BUILD_DATE "NOW" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +# undef WORDS_BIGENDIAN +# endif +#endif + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif + +/* Define to `long int' if does not define. */ +#undef off_t diff --git a/faad2/bundle.json b/faad2/bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..2a762e749fb71e77b4c57fcaebe20f503dcf958f --- /dev/null +++ b/faad2/bundle.json @@ -0,0 +1,35 @@ +{ + "name": "@ohos/faad2", + "description": "FAAD2 is a HE, LC, MAIN and LTP profile, MPEG2 and MPEG-4 AAC decoder.", + "version": "2.10.1", + "license": "GPL", + "publishAs": "", + "segment": { + "destPath": "third_party/faad2" + }, + "dirs": {}, + "scripts": {}, + "readmePath": { + "en": "README" + }, + "component": { + "name": "faad2", + "subsystem": "thirdparty", + "syscap": [], + "features": [], + "adapted_system_type": ["standard"], + "rom": "", + "ram": "", + "deps": { + "components": [], + "third_party": [] + }, + "build": { + "sub_component": [ + "//third_party/faad2:faad2_targets" + ], + "inner_kits": [], + "test": [] + } + } +} \ No newline at end of file diff --git a/faad2/docs/hap_integrate.md b/faad2/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..66c66f1942168c8208591fd46ca72902b7b8e971 --- /dev/null +++ b/faad2/docs/hap_integrate.md @@ -0,0 +1,47 @@ +# faad2如何集成到应用hap +## 准备应用工程 +本库是基于DevEco Studio 3.1 Beta1版本,在RK3568开发板上验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 +### 准备应用开发环境 +开发环境的准备参考:[开发环境准备](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md#%E5%B7%A5%E7%A8%8B%E5%87%86%E5%A4%87) +### 增加构建脚本及配置文件 +- 下载本仓库,并解压 +- 三方库目录结构 + ``` + tpc_c_cplusplus/faad2 #三方库faad2的目录结构如下 + ├── adapted #存放三方库适配需要的代码文件 + ├── docs #存放三方库相关文档的文件夹 + ├── CmakeLists.txt #构建脚本,支持hap包集成 + ├── bundle.json #三方库组件定义文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` +- 将faad2拷贝至工程xxxx/entry/src/main/cpp/thirdparty目录下 +### 准备三方库源码 +- 三方库下载地址:[faad2](https://github.com/knik0/faad2), 版本:v2.10.1 + 解压后修改库文件名为faad2,拷贝至工程xxxx/entry/src/main/cpp/thirdparty/faad2目录下 +## 应用中使用三方库 +- 将三方库加入工程中,目录结构如下 + ``` + demo/entry/src/main/cpp + ├── thirdparty #三方库存放目录 + │ ├── faad2 #三方库faad2 + ├── CMakeLists.txt #工程目录的构建脚本 + ├── ..... #工程目录的其他文件 + ``` +- 在工程顶级CMakeLists.txt中引入三方库,增加如下代码 + ``` + add_subdirectory(thirdparty/faad2) #引入子目录下的CMakeLists.txt + target_link_libraries(工程库名 PUBLIC faad2) #工程依赖三方库faad2 + target_include_directories(工程库名 PRIVATE thirdparty/faad2/include) + ``` +## 编译工程 +编译工程,安装应用可以参考 [应用的安装和运行](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md#%E5%AE%89%E8%A3%85%E8%B0%83%E8%AF%95) +## 运行效果 +- 在 [faad2](https://gitee.com/openharmony-tpc/openharmony_tpc_samples/tree/master/faad2)中,运行效果如下图 +  ![演示](pic/hap.jpg) +## 参考资料 +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) + diff --git a/faad2/docs/pic/hap.jpg b/faad2/docs/pic/hap.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8caebcb0bb51b94b4beb509acfc66d0e1895aad0 Binary files /dev/null and b/faad2/docs/pic/hap.jpg differ diff --git a/faad2/docs/pic/result.png b/faad2/docs/pic/result.png new file mode 100644 index 0000000000000000000000000000000000000000..2ac1c198541f918a1eb6c4279b8bd6d3aa82529d Binary files /dev/null and b/faad2/docs/pic/result.png differ diff --git a/faad2/docs/rom_integrate.md b/faad2/docs/rom_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..d1c599a3170e8a1abbef75909e4fcee3c7efc200 --- /dev/null +++ b/faad2/docs/rom_integrate.md @@ -0,0 +1,141 @@ +# faad2如何集成到系统Rom + +## 准备源码工程 + +本库是基于OpenHarmony-v3.2-Beta2版本,在RK3568开发板上验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 + +### 准备系统Rom源码 + +系统源码获取请参考:[OpenHarmony源码下载](https://gitee.com/openharmony/docs/blob/OpenHarmony-v3.2-Beta3/zh-cn/release-notes/OpenHarmony-v3.2-beta2.md) + +### 增加构建脚本及配置文件 + +- 下载本仓库代码 + + ``` + cd ~ + git clone git@gitee.com:openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +- 三方库目录结构 + + ``` + tpc_c_cplusplus/faad2 #三方库faad2的目录结构如下 + ├── adapted #存放三方库适配需要的代码文件 + ├── docs #存放三方库相关文档的文件夹 + ├── BUILD.gn #构建脚本,支持rom包集成 + ├── bundle.json #三方库组件定义文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` + +- 将三方库拷贝到OpenHarmony源码的third_party目录下 + + ``` + cp ~/tpc_c_cplusplus/faad2 ~/openharmony/third_party -rf + ``` + +### 准备三方库源码 + +``` +cd ~/openharmony/third_party/faad2 #进入三方库目录 +git clone https://github.com/knik0/faad2.git #下载三方库源码 +``` + +## 系统Rom中引入三方库 + +准备完三方库代码后,我们需要将三方库加入到编译构建体系中。标准系统编译构建可以参考文档[标准系统编译构建指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/device-dev/subsystems/subsys-build-standard-large.md) 我们默认三方库是属于OpenHarmony的thirdparty子系统,如果需要自己定义子系统参考文档[如何为三方库组件中添加一个三方库](https://gitee.com/openharmony-sig/knowledge/blob/master/docs/openharmony_getstarted/port_thirdparty/README.md) 新增需要编译的组件,在OpenHarmony源码的vendor/hihope/rk3568/config.json文件中,新增需要编译的组件,如下代码段所示,在thirdparty子系统下面新增faad2组件 + +``` + { + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "faad2", + "features": [] + } + ] + } +``` + +## 系统Rom中引入三方库测试程序 + +faad2原生库提供了测试用例,如需要引入测试程序,在OpenHarmony源码的vendor/hihope/rk3568/config.json文件,对应组件的features中打开编译选项: + +``` +{ + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "faad2", + "features": [ "enable_faad2_test=true" ] + } + ] +} +``` + +## 编译工程 + +在OpenHarmony源码根目录下 + +``` +cd ~/openharmony +``` + +- 执行编译 + + ``` + ./build.sh --product-name rk3568 --ccache + ``` + +- 生成文件的路径 + + 可执行文件生成在out/rk3568/thirdparty/faad2/faad2_test,库文件生成在out/rk3568/obj/thirdparty/faad2目录下 + +## 运行效果 + +将编译生成的库和测试文件放到板子上运行,为避免每次将文件推入设备都烧录整个镜像,我们使用hdc_std工具将文件推到开发板上 + +- 首先将hdc_std工具编译出来 工具编译出来所在路径out/sdk/ohos-sdk/windows/toolchains/hdc_std.exe + + ``` + hb set #源码根目录下使用hb set 选择产品ohos-sdk + hb build #然后编译 + ``` + +- 将工具拷贝到Windows,可以为工具目录配置环境变量,也可以在工具所在目录打开windows命令行 + +- 将编译生成的faad2_test可执行文件及原生库下的测试文件test.aac准备好 + +- 将准备好的文件推送到开发板,在windows命令行进行如下操作 + + ``` + hdc_std shell mount -o remount,rw / #修改系统权限为可读写 + hdc_std file send faad2_test /data #将可执行文件推入开发板data目录 + hdc_std file send libfaad2.z.so /system/lib64 + hdc_std file send libfaad2.z.so /system/lib + hdc_std file send test.aac /data #将测试文件推入开发板data目录 + hdc_std shell #进入开发板 + chmod 777 faad2_test #添加权限 + ./faad2_test -w test.aac > out.wav #执行可执行文件解码生成wav文件 + ``` + +- 运行测试程序 效果如下图 + +- ![result](pic/result.png) + +## 参考资料 + +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [如何为三方库组件中添加一个三方库](https://gitee.com/openharmony-sig/knowledge/blob/master/docs/openharmony_getstarted/port_thirdparty/README.md) +- [标准系统编译构建指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/device-dev/subsystems/subsys-build-standard-large.md) \ No newline at end of file