Skip to content

Commit

Permalink
Add support for new bcg729 API introduced in 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
fbriere committed Feb 7, 2018
1 parent a00e899 commit 42ec560
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ if (WITH_G729)
if (G729_FOUND)
message(STATUS "bcg729 OK")
set(HAVE_BCG729 TRUE)

if (NOT G729_OLD_API)
set(HAVE_BCG729_API_1_0_2 TRUE)
endif (NOT G729_OLD_API)

include_directories(${G729_INCLUDE_DIR})
else (G729_FOUND)
Expand Down
28 changes: 28 additions & 0 deletions cmake/FindG729.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
INCLUDE(CMakePushCheckState)
INCLUDE(CheckCSourceCompiles)

FIND_PATH(G729_INCLUDE_DIR bcg729/decoder.h)
FIND_LIBRARY(G729_LIBRARY NAMES bcg729)

IF(G729_INCLUDE_DIR AND G729_LIBRARY)
SET(G729_FOUND TRUE)

# The bcg729 API was changed in 1.0.2 (see #104); since there is no
# apparent way to determine the actual installed version, this checks
# whether we are dealing with the old or new API.
CMAKE_PUSH_CHECK_STATE()
SET(CMAKE_REQUIRED_INCLUDES "${INCLUDE_DIRECTORIES};${G729_INCLUDE_DIR}")
SET(CMAKE_REQUIRED_LIBRARIES "${G729_LIBRARY}")
SET(CMAKE_REQUIRED_QUIET TRUE)
# Try to compile something using the old (pre-1.0.2) API
CHECK_C_SOURCE_COMPILES("
#include <bcg729/encoder.h>
#include <bcg729/decoder.h>
int main() {
/* This function requires an argument since 1.0.2 */
initBcg729EncoderChannel();
return(0);
}
" G729_OLD_API)
CMAKE_POP_CHECK_STATE()
ENDIF(G729_INCLUDE_DIR AND G729_LIBRARY)

IF(G729_FOUND)
IF (NOT G729_FIND_QUIETLY)
MESSAGE(STATUS "Found bcg729 includes: ${G729_INCLUDE_DIR}/bcg729/decoder.h")
MESSAGE(STATUS "Found bcg729 library: ${G729_LIBRARY}")
IF (G729_OLD_API)
MESSAGE(STATUS "Using the old (pre-1.0.2) bcg729 API")
ELSE (G729_OLD_API)
MESSAGE(STATUS "Using the new (post-1.0.2) bcg729 API")
ENDIF (G729_OLD_API)
ENDIF (NOT G729_FIND_QUIETLY)
ELSE(G729_FOUND)
IF (G729_FIND_REQUIRED)
Expand Down
8 changes: 8 additions & 0 deletions src/audio/audio_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,11 @@ uint16 t_g729a_audio_decoder::decode(uint8 *payload, uint16 payload_size,

for (uint16 done = 0; done < payload_size; done += 10)
{
#ifdef HAVE_BCG729_API_1_0_2
bcg729Decoder(_context, &payload[done], 0, false, false, false, &pcm_buf[done * 8]);
#else
bcg729Decoder(_context, &payload[done], false, &pcm_buf[done * 8]);
#endif
}

return payload_size * 8;
Expand All @@ -562,7 +566,11 @@ uint16 t_g729a_audio_decoder::conceal(int16 *pcm_buf, uint16 pcm_buf_size)
{
assert(pcm_buf_size >= 80);

#ifdef HAVE_BCG729_API_1_0_2
bcg729Decoder(_context, nullptr, false, true, false, false, pcm_buf);
#else
bcg729Decoder(_context, nullptr, true, pcm_buf);
#endif
return 80;
}

Expand Down
8 changes: 8 additions & 0 deletions src/audio/audio_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,11 @@ uint16 t_g726_audio_encoder::encode(int16 *sample_buf, uint16 nsamples,
t_g729a_audio_encoder::t_g729a_audio_encoder(uint16 payload_id, uint16 ptime, t_user *user_config)
: t_audio_encoder(payload_id, ptime, user_config)
{
#ifdef HAVE_BCG729_API_1_0_2
_context = initBcg729EncoderChannel(false);
#else
_context = initBcg729EncoderChannel();
#endif
}

t_g729a_audio_encoder::~t_g729a_audio_encoder()
Expand All @@ -451,7 +455,11 @@ uint16 t_g729a_audio_encoder::encode(int16 *sample_buf, uint16 nsamples,

for (uint16 done = 0; done < nsamples; done += 80)
{
#ifdef HAVE_BCG729_API_1_0_2
bcg729Encoder(_context, &sample_buf[done], &payload[done / 8], 0);
#else
bcg729Encoder(_context, &sample_buf[done], &payload[done / 8]);
#endif
}

return nsamples / 8;
Expand Down
1 change: 1 addition & 0 deletions twinkle_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#cmakedefine HAVE_ILBC
#cmakedefine HAVE_ZRTP
#cmakedefine HAVE_BCG729
#cmakedefine HAVE_BCG729_API_1_0_2
#cmakedefine HAVE_GSM

#cmakedefine HAVE_UNISTD_H
Expand Down

0 comments on commit 42ec560

Please sign in to comment.