Skip to content

Commit

Permalink
In apt-X stub library export symbols as weak
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Jan 17, 2021
1 parent ec1e08b commit 6648dfd
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 35 deletions.
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ endif()
if(WITH_SNDFILE)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SNDFile REQUIRED IMPORTED_TARGET sndfile)
add_definitions(-DWITH_SNDFILE=1)
endif()

include(GNUInstallDirs)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h
@ONLY)

add_definitions(-DPACKAGE_NAME="${PROJECT_NAME}")
add_definitions(-DPACKAGE_VERSION="${PROJECT_VERSION}")
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_definitions(-DHAVE_CONFIG_H=1)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

include(GNUInstallDirs)

if(ENABLE_DOC)
add_subdirectory(doc)
endif()
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ make && make install
- `WITH_FFMPEG` - use FFmpeg as a back-end (otherwise, stub library will be built)
- `WITH_SNDFILE` - read file formats supported by libsndfile (used by openaptx utils)

In the apt-X stub library (build without FFmpeg back-end), all symbols are exported as
[weak](https://en.wikipedia.org/wiki/Weak_symbol). As a consequence, it should be possible to
overwrite them during runtime with other library which exports strong symbols. However, it might
be required to define `LD_DYNAMIC_WEAK` environment variable - for more information consult
`ld.so` manual.

When reverse-engineered libraries were enabled, they will be automatically linked with the apt-X
stub library (build without FFmpeg back-end). See previous paragraph for the meaning of this.

## Benchmark

Below is the result of a small benchmark test performed with various apt-X encoding libraries.
Expand Down
10 changes: 10 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* config.h - Generated from config.h.in by CMake */

/* Define to 1 if FFmpeg is enabled. */
#cmakedefine WITH_FFMPEG 1

/* Define to 1 if SNDFile is enabled. */
#cmakedefine WITH_SNDFILE 1

#define PACKAGE_NAME "@PROJECT_NAME@"
#define PACKAGE_VERSION "@PROJECT_VERSION@"
66 changes: 38 additions & 28 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,34 @@ set_target_properties(aptxHD PROPERTIES
PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/../include/openaptx.h)
target_compile_definitions(aptxHD PRIVATE -DAPTXHD=1)

if(ENABLE_APTX422)
add_library(aptx-4.2.2 SHARED
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/encode.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/params.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/processor.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/qmf.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/quantizer.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/search.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/main.c)
set_target_properties(aptx-4.2.2 PROPERTIES
PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/../include/aptx422.h)
install(TARGETS aptx-4.2.2)
endif()

if(ENABLE_APTXHD100)
add_library(aptxHD-1.0.0 SHARED
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/encode.c
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/params.c
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/processor.c
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/qmf.c
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/quantizer.c
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/search.c
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/main.c)
set_target_properties(aptxHD-1.0.0 PROPERTIES
PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/../include/aptxHD100.h)
install(TARGETS aptxHD-1.0.0)
endif()

if(WITH_FFMPEG)

target_sources(aptx
Expand Down Expand Up @@ -37,6 +65,11 @@ else()
${CMAKE_CURRENT_BINARY_DIR}/sample-sonar.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx-stub.c)

if(ENABLE_APTX422)
# use reverse-engineered library as an encoding backend
target_link_libraries(aptx aptx-4.2.2)
endif()

add_custom_command(
DEPENDS bin2array ${SAMPLE_SONAR_APTX_HD}
COMMAND bin2array sample_sonar_aptx_hd ${SAMPLE_SONAR_APTX_HD} > sample-sonar-hd.c
Expand All @@ -46,35 +79,12 @@ else()
${CMAKE_CURRENT_BINARY_DIR}/sample-sonar-hd.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx-stub.c)

if(ENABLE_APTXHD100)
# use reverse-engineered library as an encoding backend
target_link_libraries(aptxHD PRIVATE aptxHD-1.0.0)
endif()

endif()

install(TARGETS aptx aptxHD
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

if(ENABLE_APTX422)
add_library(aptx422 SHARED
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/encode.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/params.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/processor.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/qmf.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/quantizer.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/search.c
${CMAKE_CURRENT_SOURCE_DIR}/aptx422/main.c)
set_target_properties(aptx422 PROPERTIES
PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/../include/aptx422.h)
install(TARGETS aptx422)
endif()

if(ENABLE_APTXHD100)
add_library(aptxHD100 SHARED
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/encode.c
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/params.c
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/processor.c
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/qmf.c
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/quantizer.c
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/search.c
${CMAKE_CURRENT_SOURCE_DIR}/aptxhd100/main.c)
set_target_properties(aptxHD100 PROPERTIES
PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/../include/aptxHD100.h)
install(TARGETS aptxHD100)
endif()
15 changes: 15 additions & 0 deletions src/aptx-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct internal_ctx {
bool swap;
};

__attribute__ ((weak))
int _aptxenc_init_(APTXENC enc, bool swap) {

static bool banner = true;
Expand All @@ -93,6 +94,7 @@ int _aptxenc_init_(APTXENC enc, bool swap) {
return 0;
}

__attribute__ ((weak))
int _aptxdec_init_(APTXDEC dec, bool swap) {

static bool banner = true;
Expand All @@ -113,17 +115,21 @@ int _aptxdec_init_(APTXDEC dec, bool swap) {
return 0;
}

__attribute__ ((weak))
void _aptxenc_destroy_(APTXENC enc) {
(void)enc;
}

__attribute__ ((weak))
void _aptxdec_destroy_(APTXDEC dec) {
(void)dec;
}

#if APTXHD
__attribute__ ((weak))
int _aptxenc_encode_(APTXENC enc, const int32_t pcmL[4], const int32_t pcmR[4], uint32_t code[2]) {
#else
__attribute__ ((weak))
int _aptxenc_encode_(APTXENC enc, const int32_t pcmL[4], const int32_t pcmR[4], uint16_t code[2]) {
#endif

Expand Down Expand Up @@ -155,8 +161,10 @@ int _aptxenc_encode_(APTXENC enc, const int32_t pcmL[4], const int32_t pcmR[4],
}

#if APTXHD
__attribute__ ((weak))
int _aptxdec_decode_(APTXDEC dec, int32_t pcmL[4], int32_t pcmR[4], const uint32_t code[2]) {
#else
__attribute__ ((weak))
int _aptxdec_decode_(APTXDEC dec, int32_t pcmL[4], int32_t pcmR[4], const uint16_t code[2]) {
#endif
(void)code;
Expand All @@ -172,30 +180,37 @@ int _aptxdec_decode_(APTXDEC dec, int32_t pcmL[4], int32_t pcmR[4], const uint16
return 0;
}

__attribute__ ((weak))
const char *_aptxenc_build_(void) {
return PACKAGE_NAME "-stub-" PACKAGE_VERSION;
}

__attribute__ ((weak))
const char *_aptxdec_build_(void) {
return PACKAGE_NAME "-stub-" PACKAGE_VERSION;
}

__attribute__ ((weak))
const char *_aptxenc_version_(void) {
return PACKAGE_VERSION;
}

__attribute__ ((weak))
const char *_aptxdec_version_(void) {
return PACKAGE_VERSION;
}

__attribute__ ((weak))
size_t _aptxenc_size_(void) {
return sizeof(struct internal_ctx);
}

__attribute__ ((weak))
size_t _aptxdec_size_(void) {
return sizeof(struct internal_ctx);
}

__attribute__ ((weak))
APTXENC _aptxenc_new_(bool swap) {
static struct internal_ctx ctx;
if (_aptxenc_init_(&ctx, swap) != 0)
Expand Down
6 changes: 3 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(ENABLE_APTX422)

add_library(qualcomm_libaptx SHARED IMPORTED)
set_target_properties(qualcomm_libaptx PROPERTIES
IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/3rdparty/libbt-aptX-ARM-4.2.2.so)
IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/archive/armv7/libbt-aptX-ARM-4.2.2.so)

add_executable(heval422 EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/src/aptx422/encode.c
Expand All @@ -25,7 +25,7 @@ if(ENABLE_APTXHD100)

add_library(qualcomm_libaptxHD SHARED IMPORTED)
set_target_properties(qualcomm_libaptxHD PROPERTIES
IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/3rdparty/libaptXHD_encoder.so)
IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/archive/armv7/libaptXHD-1.0.0-rel-Android21-ARMv7A.so)

add_executable(hevalhd100 EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/src/aptxhd100/encode.c
Expand All @@ -37,6 +37,6 @@ if(ENABLE_APTXHD100)
${CMAKE_CURRENT_SOURCE_DIR}/inspect-hd100.c
${CMAKE_CURRENT_SOURCE_DIR}/inspect-utils.c
${CMAKE_CURRENT_SOURCE_DIR}/heval-hd100.c)
target_link_libraries(heval422 qualcomm_libaptxHD)
target_link_libraries(hevalhd100 qualcomm_libaptxHD)

endif()

0 comments on commit 6648dfd

Please sign in to comment.