diff options
-rw-r--r-- | cmake/FindG729.cmake | 8 | ||||
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/audio/audio_codecs.cpp | 1 | ||||
-rw-r--r-- | src/audio/audio_decoder.cpp | 47 | ||||
-rw-r--r-- | src/audio/audio_decoder.h | 25 | ||||
-rw-r--r-- | src/audio/audio_encoder.cpp | 31 | ||||
-rw-r--r-- | src/audio/audio_encoder.h | 21 | ||||
-rw-r--r-- | src/gui/CMakeLists.txt | 2 |
8 files changed, 131 insertions, 6 deletions
diff --git a/cmake/FindG729.cmake b/cmake/FindG729.cmake index d11a27e..4a30ba0 100644 --- a/cmake/FindG729.cmake +++ b/cmake/FindG729.cmake @@ -1,14 +1,14 @@ FIND_PATH(G729_INCLUDE_DIR bcg729/decoder.h) -FIND_LIBRARY(G729_LIBRARIES NAMES bcg729) +FIND_LIBRARY(G729_LIBRARY NAMES bcg729) -IF(G729_INCLUDE_DIR AND G729_LIBRARIES) +IF(G729_INCLUDE_DIR AND G729_LIBRARY) SET(G729_FOUND TRUE) -ENDIF(G729_INCLUDE_DIR AND G729_LIBRARIES) +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_LIBRARIES}") + MESSAGE(STATUS "Found bcg729 library: ${G729_LIBRARY}") ENDIF (NOT G729_FIND_QUIETLY) ELSE(G729_FOUND) IF (G729_FIND_REQUIRED) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index abcc39d..ec3aa62 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -79,7 +79,7 @@ endif (WITH_QT4 OR WITH_QT5) target_link_libraries(twinkle-console -lpthread -lresolv ${LibMagic_LIBRARY} ${LIBXML2_LIBRARIES} ${Readline_LIBRARY} ${ILBC_LIBRARIES} ${SPEEX_LIBRARIES} ${ZRTPCPP_LIBRARIES} ${CCRTP_LIBRARIES} ${COMMONCPP_LIBRARIES} ${UCOMMON_LIBRARIES} ${LIBSNDFILE_LIBRARY} - ${Boost_LIBRARIES} ${ALSA_LIBRARY}) + ${Boost_LIBRARIES} ${ALSA_LIBRARY} ${G729_LIBRARY}) install(TARGETS twinkle-console DESTINATION bin) diff --git a/src/audio/audio_codecs.cpp b/src/audio/audio_codecs.cpp index 75a9262..849638d 100644 --- a/src/audio/audio_codecs.cpp +++ b/src/audio/audio_codecs.cpp @@ -26,6 +26,7 @@ unsigned short audio_sample_rate(t_audio_codec codec) { case CODEC_GSM: case CODEC_SPEEX_NB: case CODEC_ILBC: + case CODEC_G729A: case CODEC_G726_16: case CODEC_G726_24: case CODEC_G726_32: diff --git a/src/audio/audio_decoder.cpp b/src/audio/audio_decoder.cpp index e4c1d74..0f32214 100644 --- a/src/audio/audio_decoder.cpp +++ b/src/audio/audio_decoder.cpp @@ -521,3 +521,50 @@ bool t_g726_audio_decoder::valid_payload_size(uint16 payload_size, return (payload_size * 8 / _bits_per_sample ) <= sample_buf_size; } + +#ifdef HAVE_BCG729 + +t_g729a_audio_decoder::t_g729a_audio_decoder(uint16 default_ptime, t_user *user_config) + : t_audio_decoder(default_ptime, true, user_config) +{ + _context = initBcg729DecoderChannel(); +} + +t_g729a_audio_decoder::~t_g729a_audio_decoder() +{ + closeBcg729DecoderChannel(_context); +} + +uint16 t_g729a_audio_decoder::get_ptime(uint16 payload_size) const +{ + return (payload_size * 8) / (audio_sample_rate(_codec) / 1000); +} + +uint16 t_g729a_audio_decoder::decode(uint8 *payload, uint16 payload_size, + int16 *pcm_buf, uint16 pcm_buf_size) +{ + assert((payload_size % 10) == 0); + assert(pcm_buf_size >= payload_size*8); + + for (uint16 done = 0; done < payload_size; done += 10) + { + bcg729Decoder(_context, &payload[done], false, &pcm_buf[done * 8]); + } + + return payload_size * 8; +} + +bool t_g729a_audio_decoder::valid_payload_size(uint16 payload_size, uint16 sample_buf_size) const +{ + return payload_size > 0 && (payload_size % 10) == 0; +} + +uint16 t_g729a_audio_decoder::conceal(int16 *pcm_buf, uint16 pcm_buf_size) +{ + assert(pcm_buf_size >= 80); + + bcg729Decoder(_context, nullptr, true, pcm_buf); + return 80; +} + +#endif diff --git a/src/audio/audio_decoder.h b/src/audio/audio_decoder.h index cee198f..48ef29c 100644 --- a/src/audio/audio_decoder.h +++ b/src/audio/audio_decoder.h @@ -36,6 +36,12 @@ #include <speex/speex_preprocess.h> #endif +#ifdef HAVE_BCG729 +extern "C" { +# include <bcg729/decoder.h> +} +#endif + #ifdef HAVE_ILBC #ifndef HAVE_ILBC_CPP extern "C" { @@ -197,4 +203,23 @@ public: virtual bool valid_payload_size(uint16 payload_size, uint16 sample_buf_size) const; }; +#ifdef HAVE_BCG729 + +// G.729A +class t_g729a_audio_decoder : public t_audio_decoder { +public: + t_g729a_audio_decoder(uint16 default_ptime, t_user *user_config); + ~t_g729a_audio_decoder(); + + virtual uint16 get_ptime(uint16 payload_size) const override; + virtual uint16 decode(uint8 *payload, uint16 payload_size, + int16 *pcm_buf, uint16 pcm_buf_size) override; + virtual bool valid_payload_size(uint16 payload_size, uint16 sample_buf_size) const override; + virtual uint16 conceal(int16 *pcm_buf, uint16 pcm_buf_size) override; +private: + bcg729DecoderChannelContextStruct* _context; +}; + +#endif + #endif diff --git a/src/audio/audio_encoder.cpp b/src/audio/audio_encoder.cpp index 94e82b4..e77ab14 100644 --- a/src/audio/audio_encoder.cpp +++ b/src/audio/audio_encoder.cpp @@ -428,3 +428,34 @@ uint16 t_g726_audio_encoder::encode(int16 *sample_buf, uint16 nsamples, return 0; } + +#ifdef HAVE_BCG729 + +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) +{ + _context = initBcg729EncoderChannel(); +} + +t_g729a_audio_encoder::~t_g729a_audio_encoder() +{ + closeBcg729EncoderChannel(_context); +} + +uint16 t_g729a_audio_encoder::encode(int16 *sample_buf, uint16 nsamples, + uint8 *payload, uint16 payload_size, bool &silence) +{ + assert ((nsamples % 80) == 0); + assert (payload_size >= (nsamples/8)); + + silence = false; + + for (uint16 done = 0; done < nsamples; done += 80) + { + bcg729Encoder(_context, &sample_buf[done], &payload[done / 8]); + } + + return nsamples / 8; +} + +#endif diff --git a/src/audio/audio_encoder.h b/src/audio/audio_encoder.h index e2fb874..b900414 100644 --- a/src/audio/audio_encoder.h +++ b/src/audio/audio_encoder.h @@ -35,6 +35,12 @@ #include <speex/speex.h> #endif +#ifdef HAVE_BCG729 +extern "C" { +# include <bcg729/encoder.h> +} +#endif + #ifdef HAVE_ILBC #ifndef HAVE_ILBC_CPP extern "C" { @@ -179,4 +185,19 @@ public: uint8 *payload, uint16 payload_size, bool &silence); }; +#ifdef HAVE_BCG729 +class t_g729a_audio_encoder : public t_audio_encoder +{ +public: + t_g729a_audio_encoder(uint16 payload_id, uint16 ptime, t_user *user_config); + virtual ~t_g729a_audio_encoder(); + + virtual uint16 encode(int16 *sample_buf, uint16 nsamples, + uint8 *payload, uint16 payload_size, bool &silence); +private: + bcg729EncoderChannelContextStruct* _context; +}; + +#endif + #endif diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 624742d..57b8a19 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -134,7 +134,7 @@ add_executable(twinkle ${TWINKLE_GUI-SRCS}) target_link_libraries(twinkle -lpthread -lresolv ${LibMagic_LIBRARY} ${LIBXML2_LIBRARIES} ${Readline_LIBRARY} ${ILBC_LIBRARIES} ${SPEEX_LIBRARIES} ${ZRTPCPP_LIBRARIES} ${CCRTP_LIBRARIES} ${COMMONCPP_LIBRARIES} ${UCOMMON_LIBRARIES} ${LIBSNDFILE_LIBRARY} - ${Boost_LIBRARIES} ${ALSA_LIBRARY} ${qt_LIBS}) + ${Boost_LIBRARIES} ${ALSA_LIBRARY} ${qt_LIBS} ${G729_LIBRARY}) install(TARGETS twinkle DESTINATION bin) install(FILES ${twinkle_LANG} DESTINATION share/twinkle/lang) |