From f43b9f41b5fb835a1ea193b34d8c14c3fb783ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= Date: Sat, 10 Feb 2018 15:06:50 -0500 Subject: [PATCH 1/4] Test building with bcg729 on Travis CI (The master build is currently commented out due to #104; it can be enabled after that issue is fixed.) --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index de77d411..1ec2f77f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ env: - FLAGS="-DWITH_QT5=ON -DWITH_ALSA=ON -DWITH_GSM=ON -DWITH_SPEEX=ON -DWITH_ZRTP=ON" # (qttools5-dev-tools is explicitly included because of Debian bug #835295) - PACKAGES="libasound2-dev libgsm1-dev libspeex-dev libspeexdsp-dev libzrtpcpp-dev qtdeclarative5-dev qttools5-dev qttools5-dev-tools" + matrix: # Test various compiler versions - PACKAGES_ADD="g++-4.9" MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9" @@ -15,9 +16,16 @@ env: # The version of uCommon available on trusty (6.0.7) will cause a build # failure when compiling with GCC 7 or Clang. #- PACKAGES_ADD="g++-7" MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" + # Test with all options disabled - FLAGS="-DWITH_QT5=OFF -DWITH_ALSA=OFF -DWITH_GSM=OFF -DWITH_SPEEX=OFF -DWITH_ZRTP=OFF" PACKAGES="" + # Test building with bcg729 + # (Twinkle does not currently build with the master branch, see issue #104) + #- BUILD_BCG729="master" FLAGS="-DWITH_QT5=OFF -DWITH_ALSA=OFF -DWITH_G729=ON" PACKAGES="git ca-certificates pkg-config libtool automake autoconf" + # Also test the old pre-1.0.2 API (issue #104) + - BUILD_BCG729="1.0.1" FLAGS="-DWITH_QT5=OFF -DWITH_ALSA=OFF -DWITH_G729=ON" PACKAGES="git ca-certificates pkg-config libtool automake autoconf" + # See https://docs.travis-ci.com/user/languages/cpp/#C11-C%2B%2B11-%28and-Beyond%29-and-Toolchain-Versioning before_install: - eval "${MATRIX_EVAL}" @@ -28,6 +36,8 @@ install: - sudo apt-get -y install bison cmake flex libccrtp-dev libmagic-dev libreadline-dev libsndfile1-dev libucommon-dev libxml2-dev linux-libc-dev $PACKAGES $PACKAGES_ADD script: + # Download and build bcg729 if necessary + - if [ "$BUILD_BCG729" ]; then git clone git://git.linphone.org/bcg729.git && (cd bcg729 && git checkout "$BUILD_BCG729" && ./autogen.sh && ./configure && make && sudo make install); fi - mkdir _build - cd _build - cmake -DCMAKE_INSTALL_PREFIX=../_install $FLAGS .. From 6fa1755c2c3321de0b2dd986bbeddfa12a3550f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= Date: Tue, 6 Feb 2018 18:02:25 -0500 Subject: [PATCH 2/4] Add support for new bcg729 API introduced in 1.0.2 [incomplete] ** This commit only provides dummy values for all new arguments. ** --- CMakeLists.txt | 4 ++++ cmake/FindG729.cmake | 28 ++++++++++++++++++++++++++++ src/audio/audio_decoder.cpp | 8 ++++++++ src/audio/audio_encoder.cpp | 8 ++++++++ twinkle_config.h.in | 1 + 5 files changed, 49 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 53153831..dc9aa382 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/FindG729.cmake b/cmake/FindG729.cmake index 4a30ba07..62e4219d 100644 --- a/cmake/FindG729.cmake +++ b/cmake/FindG729.cmake @@ -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 + #include + + 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) diff --git a/src/audio/audio_decoder.cpp b/src/audio/audio_decoder.cpp index 65935dd5..4e0be77f 100644 --- a/src/audio/audio_decoder.cpp +++ b/src/audio/audio_decoder.cpp @@ -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; @@ -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; } diff --git a/src/audio/audio_encoder.cpp b/src/audio/audio_encoder.cpp index d6ff3564..98095b31 100644 --- a/src/audio/audio_encoder.cpp +++ b/src/audio/audio_encoder.cpp @@ -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() @@ -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; diff --git a/twinkle_config.h.in b/twinkle_config.h.in index 39285650..e924aa5f 100644 --- a/twinkle_config.h.in +++ b/twinkle_config.h.in @@ -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 From 0b0f972ca4c63e1d90ca86f6e6900c86869b3913 Mon Sep 17 00:00:00 2001 From: Anton Schur Date: Fri, 29 Mar 2019 10:26:57 +0300 Subject: [PATCH 3/4] Implemented new api (1.0.2+) for bcg729 codec --- src/audio/audio_decoder.cpp | 23 +++++++++++++++++------ src/audio/audio_encoder.cpp | 22 ++++++++++++++++------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/audio/audio_decoder.cpp b/src/audio/audio_decoder.cpp index 4e0be77f..be3bc12c 100644 --- a/src/audio/audio_decoder.cpp +++ b/src/audio/audio_decoder.cpp @@ -542,19 +542,30 @@ uint16 t_g729a_audio_decoder::get_ptime(uint16 payload_size) const uint16 t_g729a_audio_decoder::decode(uint8 *payload, uint16 payload_size, int16 *pcm_buf, uint16 pcm_buf_size) { +#ifdef HAVE_BCG729_API_1_0_2 + int frame_size; + uint8 *encoded_data_ptr = payload; + int16 *decoded_data_ptr = pcm_buf; + uint32 new_len = 0; + for (uint16 done = 0; done < payload_size && new_len < pcm_buf_size; done += frame_size) + { + uint8 is_sid = (payload_size - done < 8) ? 1 : 0; + frame_size = (is_sid == 1) ? 2 : 10; + bcg729Decoder(_context, encoded_data_ptr, payload_size, false, is_sid, false, decoded_data_ptr); + encoded_data_ptr += frame_size; + decoded_data_ptr += 80; + new_len += 80; + } + return new_len; +#else assert((payload_size % 10) == 0); assert(pcm_buf_size >= payload_size*8); - 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; +#endif } bool t_g729a_audio_decoder::valid_payload_size(uint16 payload_size, uint16 sample_buf_size) const diff --git a/src/audio/audio_encoder.cpp b/src/audio/audio_encoder.cpp index 98095b31..5a72852c 100644 --- a/src/audio/audio_encoder.cpp +++ b/src/audio/audio_encoder.cpp @@ -452,17 +452,27 @@ uint16 t_g729a_audio_encoder::encode(int16 *sample_buf, uint16 nsamples, assert (payload_size >= (nsamples/8)); silence = false; - - for (uint16 done = 0; done < nsamples; done += 80) - { #ifdef HAVE_BCG729_API_1_0_2 - bcg729Encoder(_context, &sample_buf[done], &payload[done / 8], 0); + uint16 new_len = 0; + int16 *decoded_data_ptr = sample_buf; + uint8 *encoded_data_ptr = payload; + uint8 frame_size; + int loops = (int)nsamples / 80; + for (uint16 done = 0; done < loops; done ++) + { + bcg729Encoder(_context, decoded_data_ptr, encoded_data_ptr, &frame_size); + encoded_data_ptr += frame_size; + decoded_data_ptr += frame_size * 8; + new_len += frame_size; + } + return new_len; #else + for (uint16 done = 0; done < nsamples; done += 80) + { bcg729Encoder(_context, &sample_buf[done], &payload[done / 8]); -#endif } - return nsamples / 8; +#endif } #endif From 53868471f580ac72958f1641867c7c246dea2ace Mon Sep 17 00:00:00 2001 From: Anton Schur Date: Fri, 29 Mar 2019 11:09:16 +0300 Subject: [PATCH 4/4] Enabled bcg729-master tests --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1ec2f77f..5dc78640 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,8 +21,7 @@ env: - FLAGS="-DWITH_QT5=OFF -DWITH_ALSA=OFF -DWITH_GSM=OFF -DWITH_SPEEX=OFF -DWITH_ZRTP=OFF" PACKAGES="" # Test building with bcg729 - # (Twinkle does not currently build with the master branch, see issue #104) - #- BUILD_BCG729="master" FLAGS="-DWITH_QT5=OFF -DWITH_ALSA=OFF -DWITH_G729=ON" PACKAGES="git ca-certificates pkg-config libtool automake autoconf" + - BUILD_BCG729="master" FLAGS="-DWITH_QT5=OFF -DWITH_ALSA=OFF -DWITH_G729=ON" PACKAGES="git ca-certificates pkg-config libtool automake autoconf" # Also test the old pre-1.0.2 API (issue #104) - BUILD_BCG729="1.0.1" FLAGS="-DWITH_QT5=OFF -DWITH_ALSA=OFF -DWITH_G729=ON" PACKAGES="git ca-certificates pkg-config libtool automake autoconf"