From: Peter Lemenkov <lemenkov@gmail.com>
Date: Wed, 16 Nov 2016 18:47:17 +0300
Subject: [PATCH] Use mpg123 if available
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cf149782..c39eae75 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,7 +38,7 @@ OPTION(SEMS_USE_OPUS "Build with Opus" OFF)
OPTION(SEMS_USE_SPANDSP "Build with spandsp" OFF)
OPTION(SEMS_USE_LIBSAMPLERATE "Build with libsamplerate" OFF)
OPTION(SEMS_USE_ZRTP "Build with ZRTP" OFF)
-OPTION(SEMS_USE_MP3 "Build with Lame MP3" OFF)
+OPTION(SEMS_USE_MP3 "Build with MP3" OFF)
OPTION(SEMS_USE_ILBC "Build with iLBC library (fallback to bundled)" ON)
OPTION(SEMS_USE_G729 "Build with bcg729 library" OFF)
OPTION(SEMS_USE_TTS "Build with Text-to-speech support (requires Flite)" OFF)
@@ -134,9 +134,18 @@ ENDIF(SEMS_USE_ZRTP)
# Lame MP3 support
IF(SEMS_USE_MP3)
FIND_PACKAGE(Lame REQUIRED)
- MESSAGE(STATUS "Using lame mp3: YES")
+ IF(LAME_FOUND)
+ MESSAGE(STATUS "Using mp3 encoding (LAME library): YES")
+ FIND_PACKAGE(Mpg123)
+ IF(MPG123_FOUND)
+ ADD_DEFINITIONS(-DWITH_MPG123DECODER)
+ MESSAGE(STATUS "Using mp3 decoding (mpg123 library): YES")
+ ELSE(MPG123_FOUND)
+ MESSAGE(STATUS "Using mp3 decoding (mpg123 library): NO")
+ ENDIF(MPG123_FOUND)
+ ENDIF(LAME_FOUND)
ELSE(SEMS_USE_MP3)
- MESSAGE(STATUS "Using lame mp3: NO (default)")
+ MESSAGE(STATUS "Using mp3: NO (default)")
ENDIF(SEMS_USE_MP3)
IF(SEMS_USE_ILBC)
diff --git a/apps/mp3/CMakeLists.txt b/apps/mp3/CMakeLists.txt
index 5cda8a83..dbbced2d 100644
--- a/apps/mp3/CMakeLists.txt
+++ b/apps/mp3/CMakeLists.txt
@@ -7,5 +7,9 @@ mp3.c
# module_cflags += -DWITH_MPG123DECODER
SET(sems_module_name mp3)
-SET(sems_module_libs mp3lame)
+IF(MPG123_FOUND)
+ SET(sems_module_libs mp3lame mpg123)
+ELSE(MPG123_FOUND)
+ SET(sems_module_libs mp3lame)
+ENDIF(MPG123_FOUND)
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/module.rules.txt)
diff --git a/cmake/FindMpg123.cmake b/cmake/FindMpg123.cmake
new file mode 100644
index 00000000..9ffa2c1e
--- /dev/null
+++ b/cmake/FindMpg123.cmake
@@ -0,0 +1,17 @@
+FIND_PATH(MPG123_INCLUDE_DIR mpg123.h)
+FIND_LIBRARY(MPG123_LIBRARIES NAMES mpg123)
+
+IF(MPG123_INCLUDE_DIR AND MPG123_LIBRARIES)
+ SET(MPG123_FOUND TRUE)
+ENDIF(MPG123_INCLUDE_DIR AND MPG123_LIBRARIES)
+
+IF(MPG123_FOUND)
+ IF (NOT Mpg123_FIND_QUIETLY)
+ MESSAGE(STATUS "Found mpg123 includes: ${MPG123_INCLUDE_DIR}/mpg123.h")
+ MESSAGE(STATUS "Found mpg123 library: ${MPG123_LIBRARIES}")
+ ENDIF (NOT Mpg123_FIND_QUIETLY)
+ELSE(MPG123_FOUND)
+ IF (Mpg123_FIND_REQUIRED)
+ MESSAGE(FATAL_ERROR "Could NOT find mpg123 development files")
+ ENDIF (Mpg123_FIND_REQUIRED)
+ENDIF(MPG123_FOUND)