diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 09910597..905d8232 100755 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -74,6 +74,9 @@ include_directories (include) aux_source_directory (dep_external/src/wav DIR_DEP_EXTERNAL_WAV) aux_source_directory (src/common DIR_IAMF_COMMON) aux_source_directory (src/iamf_dec DIR_IAMF_DEC) +aux_source_directory (src/iamf_dec/arch DIR_IAMF_DEC_ARCH) +aux_source_directory (src/iamf_dec/arch/arm DIR_IAMF_DEC_ARCH_ARM) +aux_source_directory (src/iamf_dec/arch/x86 DIR_IAMF_DEC_ARCH_X86) if(NOT ${find_opus} STREQUAL "find_opus-NOTFOUND") aux_source_directory (src/iamf_dec/opus DIR_IAMF_DEC_OPUS) endif() @@ -92,6 +95,9 @@ include_directories( ${EXTER_INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/src/common ${PROJECT_SOURCE_DIR}/src/iamf_dec + ${PROJECT_SOURCE_DIR}/src/iamf_dec/arch + ${PROJECT_SOURCE_DIR}/src/iamf_dec/arch/arm + ${PROJECT_SOURCE_DIR}/src/iamf_dec/arch/x86 ${PROJECT_SOURCE_DIR}/src/iamf_dec/opus ${PROJECT_SOURCE_DIR}/src/iamf_dec/aac ${PROJECT_SOURCE_DIR}/src/iamf_dec/flac @@ -108,7 +114,8 @@ endif() if(BUILD_SHARED_LIBS) add_library(${PROJECT_NAME} SHARED ${DIR_DEP_EXTERNAL_WAV} ${DIR_IAMF_COMMON} - ${DIR_IAMF_DEC_OPUS} ${DIR_IAMF_DEC_AAC} ${DIR_IAMF_DEC_FLAC} ${DIR_IAMF_DEC_PCM} ${DIR_IAMF_DEC}) + ${DIR_IAMF_DEC_OPUS} ${DIR_IAMF_DEC_AAC} ${DIR_IAMF_DEC_FLAC} ${DIR_IAMF_DEC_PCM} ${DIR_IAMF_DEC} + ${DIR_IAMF_DEC_ARCH} ${DIR_IAMF_DEC_ARCH_ARM} ${DIR_IAMF_DEC_ARCH_X86}) if(NOT ${find_opus} STREQUAL "find_opus-NOTFOUND") target_link_libraries (${PROJECT_NAME} opus) @@ -132,7 +139,8 @@ if(BUILD_SHARED_LIBS) else() add_library(${PROJECT_NAME} STATIC ${DIR_DEP_EXTERNAL_WAV} ${DIR_IAMF_COMMON} ${DIR_IAMF_DEC_OPUS} ${DIR_IAMF_DEC_AAC} ${DIR_IAMF_DEC_PCM} - ${DIR_IAMF_DEC_FLAC} ${DIR_IAMF_DEC}) + ${DIR_IAMF_DEC_FLAC} ${DIR_IAMF_DEC} ${DIR_IAMF_DEC_ARCH} ${DIR_IAMF_DEC_ARCH_ARM} + ${DIR_IAMF_DEC_ARCH_X86}) endif() diff --git a/code/src/iamf_dec/IAMF_decoder.c b/code/src/iamf_dec/IAMF_decoder.c old mode 100755 new mode 100644 index f9d8bb87..3e2e7ba9 --- a/code/src/iamf_dec/IAMF_decoder.c +++ b/code/src/iamf_dec/IAMF_decoder.c @@ -4157,6 +4157,7 @@ IAMF_DecoderHandle IAMF_decoder_open(void) { handle->ctx.status = IAMF_DECODER_STATUS_INIT; handle->ctx.mix_presentation_id = INVALID_ID; handle->limiter = audio_effect_peak_limiter_create(); + handle->arch = arch_create(); if (!handle->limiter || iamf_database_init(db) != IAMF_OK) { IAMF_decoder_close(handle); handle = 0; @@ -4169,6 +4170,7 @@ int IAMF_decoder_close(IAMF_DecoderHandle handle) { if (handle) { iamf_decoder_internal_reset(handle); if (handle->limiter) audio_effect_peak_limiter_destroy(handle->limiter); + if (handle->arch) arch_destroy(handle->arch); free(handle); } #if SR diff --git a/code/src/iamf_dec/IAMF_decoder_private.h b/code/src/iamf_dec/IAMF_decoder_private.h old mode 100755 new mode 100644 index c7253427..297abda3 --- a/code/src/iamf_dec/IAMF_decoder_private.h +++ b/code/src/iamf_dec/IAMF_decoder_private.h @@ -28,6 +28,7 @@ #include "IAMF_defines.h" #include "IAMF_types.h" #include "ae_rdr.h" +#include "arch.h" #include "audio_effect_peak_limiter.h" #include "demixer.h" #include "downmix_renderer.h" @@ -341,6 +342,7 @@ typedef struct IAMF_DecoderContext { struct IAMF_Decoder { IAMF_DecoderContext ctx; AudioEffectPeakLimiter *limiter; + Arch *arch; }; #endif /* IAMF_DECODER_PRIVATE_H */ diff --git a/code/src/iamf_dec/arch.c b/code/src/iamf_dec/arch.c new file mode 100644 index 00000000..6da24f2f --- /dev/null +++ b/code/src/iamf_dec/arch.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024, Alliance for Open Media. All rights reserved + * + * This source code is subject to the terms of the BSD 3-Clause Clear License + * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear + * License was not distributed with this source code in the LICENSE file, you + * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the + * Alliance for Open Media Patent License 1.0 was not distributed with this + * source code in the PATENTS file, you can obtain it at + * www.aomedia.org/license/patent. + */ + +/** + * @file arch.c + * @brief Collection of CPU-specific functions. + * @version 0.1 + * @date Created 10/24/2024 + **/ + +#include "arch.h" + +#include + +#include "IAMF_utils.h" +#include "arch/arch_init.h" + +Arch* arch_create() { + Arch* arch = IAMF_MALLOCZ(Arch, 1); + memset(arch, 0x0, sizeof(Arch)); + + arch_init(arch); + + return arch; +} + +void arch_destroy(Arch* arch) { IAMF_FREE(arch); } diff --git a/code/src/iamf_dec/arch.h b/code/src/iamf_dec/arch.h new file mode 100644 index 00000000..8a3b33e3 --- /dev/null +++ b/code/src/iamf_dec/arch.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, Alliance for Open Media. All rights reserved + * + * This source code is subject to the terms of the BSD 3-Clause Clear License + * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear + * License was not distributed with this source code in the LICENSE file, you + * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the + * Alliance for Open Media Patent License 1.0 was not distributed with this + * source code in the PATENTS file, you can obtain it at + * www.aomedia.org/license/patent. + */ + +/** + * @file arch.h + * @brief Collection of CPU-specific functions. + * @version 0.1 + * @date Created 10/24/2024 + **/ + +#ifndef ARCH_H_ +#define ARCH_H_ + +typedef struct ArchCallbacks { + // Functions with possible architecture-specific optimizations +} Arch; + +Arch *arch_create(); +void arch_destroy(Arch *arch); + +#endif /* ARCH_H_ */ diff --git a/code/src/iamf_dec/arch/arch_common.c b/code/src/iamf_dec/arch/arch_common.c new file mode 100644 index 00000000..ea501ea8 --- /dev/null +++ b/code/src/iamf_dec/arch/arch_common.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, Alliance for Open Media. All rights reserved + * + * This source code is subject to the terms of the BSD 3-Clause Clear License + * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear + * License was not distributed with this source code in the LICENSE file, you + * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the + * Alliance for Open Media Patent License 1.0 was not distributed with this + * source code in the PATENTS file, you can obtain it at + * www.aomedia.org/license/patent. + */ + +/** + * @file arch_common.c + * @brief C implementation for CPU-specific functions. + * @version 0.1 + * @date Created 10/24/2024 + **/ + +#include "arch_common.h" + +// TODO: Remove this line when first function added! diff --git a/code/src/iamf_dec/arch/arch_common.h b/code/src/iamf_dec/arch/arch_common.h new file mode 100644 index 00000000..4d13fee4 --- /dev/null +++ b/code/src/iamf_dec/arch/arch_common.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024, Alliance for Open Media. All rights reserved + * + * This source code is subject to the terms of the BSD 3-Clause Clear License + * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear + * License was not distributed with this source code in the LICENSE file, you + * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the + * Alliance for Open Media Patent License 1.0 was not distributed with this + * source code in the PATENTS file, you can obtain it at + * www.aomedia.org/license/patent. + */ + +/** + * @file arch_common.h + * @brief C implementation for CPU-specific functions. + * @version 0.1 + * @date Created 10/24/2024 + **/ + +#ifndef ARCH_COMMON_H_ +#define ARCH_COMMON_H_ + +// TODO: Remove this line when first function added! + +#endif /* ARCH_COMMON_H_ */ diff --git a/code/src/iamf_dec/arch/arch_init.c b/code/src/iamf_dec/arch/arch_init.c new file mode 100644 index 00000000..6e6a6b2c --- /dev/null +++ b/code/src/iamf_dec/arch/arch_init.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024, Alliance for Open Media. All rights reserved + * + * This source code is subject to the terms of the BSD 3-Clause Clear License + * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear + * License was not distributed with this source code in the LICENSE file, you + * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the + * Alliance for Open Media Patent License 1.0 was not distributed with this + * source code in the PATENTS file, you can obtain it at + * www.aomedia.org/license/patent. + */ + +/** + * @file arch_init.c + * @brief Init CPU-specific function callbacks. + * @version 0.1 + * @date Created 10/24/2024 + **/ + +#include "arch_init.h" + +#include + +#include "arch.h" +#include "arch_common.h" + +// To add new architecture 'ABC', follow the following pattern: +// * add arch/ABC subfolder, with detect_ABC.h +// * inside detect_ABC.h, if ABC target detected, define IAMF_ARCH_DETECTED_ABC, +// and implement arch_override(...) function +// * all files under arch/ABC must include detect_ABC.h, and be surrounded with +// #if defined(IAMF_ARCH_DETECTED_ABC) +#include "arm/detect_arm.h" +#include "x86/detect_x86.h" +#if defined(IAMF_ARCH_DETECTED_ARM) || defined(IAMF_ARCH_DETECTED_X86) +#define HAS_ARCH_OVERRIDE (1) +#endif + +#if defined(HAS_ARCH_OVERRIDE) +// Implemented in each architecture-specific subfolder, +// behind IAMF_ARCH_DETECTED_... ifdef +void arch_override(Arch* arch); +#endif + +void arch_init(Arch* arch) { + memset(arch, 0x0, sizeof(Arch)); + + // Fill with reference implementations + + // arch->myfn = &myfn_c; // myfn_c is in arch_common.h/.c + // TODO: Remove these lines when first function added! + +#if defined(HAS_ARCH_OVERRIDE) + // Override with platform-specific functions, if available + arch_override(arch); +#endif +} diff --git a/code/src/iamf_dec/arch/arch_init.h b/code/src/iamf_dec/arch/arch_init.h new file mode 100644 index 00000000..ee101d09 --- /dev/null +++ b/code/src/iamf_dec/arch/arch_init.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, Alliance for Open Media. All rights reserved + * + * This source code is subject to the terms of the BSD 3-Clause Clear License + * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear + * License was not distributed with this source code in the LICENSE file, you + * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the + * Alliance for Open Media Patent License 1.0 was not distributed with this + * source code in the PATENTS file, you can obtain it at + * www.aomedia.org/license/patent. + */ + +/** + * @file arch_init.h + * @brief Init CPU-specific function callbacks. + * @version 0.1 + * @date Created 10/24/2024 + **/ + +#ifndef ARCH_INIT_H_ +#define ARCH_INIT_H_ + +typedef struct ArchCallbacks Arch; + +void arch_init(Arch* arch); + +#endif /* ARCH_INIT_H_ */ diff --git a/code/src/iamf_dec/arch/arm/detect_arm.h b/code/src/iamf_dec/arch/arm/detect_arm.h new file mode 100644 index 00000000..e67cea12 --- /dev/null +++ b/code/src/iamf_dec/arch/arm/detect_arm.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, Alliance for Open Media. All rights reserved + * + * This source code is subject to the terms of the BSD 3-Clause Clear License + * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear + * License was not distributed with this source code in the LICENSE file, you + * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the + * Alliance for Open Media Patent License 1.0 was not distributed with this + * source code in the PATENTS file, you can obtain it at + * www.aomedia.org/license/patent. + */ + +/** + * @file detect_arm.h + * @brief Detect Arm architecture during compilation. + * @version 0.1 + * @date Created 10/24/2024 + **/ + +#ifndef DETECT_ARM_H_ +#define DETECT_ARM_H_ + +#if defined(__ARM_NEON) +#define IAMF_ARCH_DETECTED_ARM (1) +#endif + +#endif /* DETECT_ARM_H_ */ diff --git a/code/src/iamf_dec/arch/arm/override_arm.c b/code/src/iamf_dec/arch/arm/override_arm.c new file mode 100644 index 00000000..1c602f92 --- /dev/null +++ b/code/src/iamf_dec/arch/arm/override_arm.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024, Alliance for Open Media. All rights reserved + * + * This source code is subject to the terms of the BSD 3-Clause Clear License + * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear + * License was not distributed with this source code in the LICENSE file, you + * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the + * Alliance for Open Media Patent License 1.0 was not distributed with this + * source code in the PATENTS file, you can obtain it at + * www.aomedia.org/license/patent. + */ + +/** + * @file override_arm.c + * @brief Override with Arm function implementations. + * @version 0.1 + * @date Created 10/24/2024 + **/ + +#include "detect_arm.h" + +#if defined(IAMF_ARCH_DETECTED_ARM) + +#include + +#include "../../arch.h" + +void arch_override(Arch *arch) { + // Override functions with Arm implementations here + + // arch->myfn = &myfn_neon; + // TODO: Remove this line when first function added! +} + +#endif diff --git a/code/src/iamf_dec/arch/x86/detect_x86.h b/code/src/iamf_dec/arch/x86/detect_x86.h new file mode 100644 index 00000000..05eaa412 --- /dev/null +++ b/code/src/iamf_dec/arch/x86/detect_x86.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, Alliance for Open Media. All rights reserved + * + * This source code is subject to the terms of the BSD 3-Clause Clear License + * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear + * License was not distributed with this source code in the LICENSE file, you + * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the + * Alliance for Open Media Patent License 1.0 was not distributed with this + * source code in the PATENTS file, you can obtain it at + * www.aomedia.org/license/patent. + */ + +/** + * @file detect_x86.h + * @brief Detect x86 architecture during compilation. + * @version 0.1 + * @date Created 10/24/2024 + **/ + +#ifndef DETECT_X86_H_ +#define DETECT_X86_H_ + +#if defined(__x86_64__) || defined(__i386__) +#define IAMF_ARCH_DETECTED_X86 (1) +#endif + +#endif /* DETECT_X86_H_ */ diff --git a/code/src/iamf_dec/arch/x86/override_x86.c b/code/src/iamf_dec/arch/x86/override_x86.c new file mode 100644 index 00000000..9a44c2a4 --- /dev/null +++ b/code/src/iamf_dec/arch/x86/override_x86.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, Alliance for Open Media. All rights reserved + * + * This source code is subject to the terms of the BSD 3-Clause Clear License + * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear + * License was not distributed with this source code in the LICENSE file, you + * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the + * Alliance for Open Media Patent License 1.0 was not distributed with this + * source code in the PATENTS file, you can obtain it at + * www.aomedia.org/license/patent. + */ + +/** + * @file override_x86.c + * @brief Override with x86 function implementations. + * @version 0.1 + * @date Created 10/24/2024 + **/ + +#include "detect_x86.h" + +#if defined(IAMF_ARCH_DETECTED_X86) + +#include "../../arch.h" + +void arch_override(Arch* arch) { + // Override functions with x86 implementations here +} + +#endif /* IAMF_ARCH_DETECTED_X86 */ diff --git a/code/win64/VS2022/iamf/iamf.vcxproj b/code/win64/VS2022/iamf/iamf.vcxproj index cf60a0f7..89cd4d89 100755 --- a/code/win64/VS2022/iamf/iamf.vcxproj +++ b/code/win64/VS2022/iamf/iamf.vcxproj @@ -133,6 +133,11 @@ + + + + + @@ -167,6 +172,11 @@ + + + + + diff --git a/code/win64/VS2022/iamf/iamf.vcxproj.filters b/code/win64/VS2022/iamf/iamf.vcxproj.filters index 1dec2811..5e5993fc 100755 --- a/code/win64/VS2022/iamf/iamf.vcxproj.filters +++ b/code/win64/VS2022/iamf/iamf.vcxproj.filters @@ -15,6 +15,9 @@ + + Source Files + Source Files @@ -69,6 +72,18 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + Source Files @@ -116,6 +131,21 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + Header Files