diff options
Diffstat (limited to 'src/modules/dcc/DccVoiceGsmCodec.cpp')
| -rw-r--r-- | src/modules/dcc/DccVoiceGsmCodec.cpp | 181 |
1 files changed, 92 insertions, 89 deletions
diff --git a/src/modules/dcc/DccVoiceGsmCodec.cpp b/src/modules/dcc/DccVoiceGsmCodec.cpp index 8f7fb6534..e2a23bb4e 100644 --- a/src/modules/dcc/DccVoiceGsmCodec.cpp +++ b/src/modules/dcc/DccVoiceGsmCodec.cpp @@ -27,122 +27,125 @@ #include "DccVoiceGsmCodec.h" #ifdef COMPILE_USE_GSM - #include <dlfcn.h> +#include <dlfcn.h> - #define GSM_PACKED_FRAME_SIZE_IN_BYTES 33 - #define GSM_UNPACKED_FRAME_SIZE_IN_BYTES 320 - #define GSM_UNPACKED_FRAME_SIZE_IN_SHORTS 160 +#define GSM_PACKED_FRAME_SIZE_IN_BYTES 33 +#define GSM_UNPACKED_FRAME_SIZE_IN_BYTES 320 +#define GSM_UNPACKED_FRAME_SIZE_IN_SHORTS 160 - void * (*gsm_session_create)() = 0; - void (*gsm_session_destroy)(void *) = 0; - void (*gsm_session_encode)(void *,short *,unsigned char *) = 0; - int (*gsm_session_decode)(void *,unsigned char *,short *) = 0; +void * (*gsm_session_create)() = 0; +void (*gsm_session_destroy)(void *) = 0; +void (*gsm_session_encode)(void *, short *, unsigned char *) = 0; +int (*gsm_session_decode)(void *, unsigned char *, short *) = 0; - void * g_pGSMCodecLibraryHandle = 0; +void * g_pGSMCodecLibraryHandle = 0; - bool kvi_gsm_codec_init() - { - if(g_pGSMCodecLibraryHandle)return true; // Already initialized - - g_pGSMCodecLibraryHandle = dlopen("libgsm.so",RTLD_NOW | RTLD_GLOBAL); - if(!g_pGSMCodecLibraryHandle)return false; // no way to open it +bool kvi_gsm_codec_init() +{ + if(g_pGSMCodecLibraryHandle) + return true; // Already initialized - gsm_session_create = (void * (*)()) dlsym(g_pGSMCodecLibraryHandle,"gsm_create"); - gsm_session_destroy = (void (*)(void *)) dlsym(g_pGSMCodecLibraryHandle,"gsm_destroy"); - gsm_session_encode = (void (*)(void *,short *,unsigned char *)) dlsym(g_pGSMCodecLibraryHandle,"gsm_encode"); - gsm_session_decode = (int (*)(void *,unsigned char *,short *)) dlsym(g_pGSMCodecLibraryHandle,"gsm_decode"); + g_pGSMCodecLibraryHandle = dlopen("libgsm.so", RTLD_NOW | RTLD_GLOBAL); + if(!g_pGSMCodecLibraryHandle) + return false; // no way to open it - if(! (gsm_session_create && gsm_session_destroy && gsm_session_encode && gsm_session_decode)) - { - dlclose(g_pGSMCodecLibraryHandle); - g_pGSMCodecLibraryHandle = 0; - return false; - } - return true; - } + gsm_session_create = (void * (*)())dlsym(g_pGSMCodecLibraryHandle, "gsm_create"); + gsm_session_destroy = (void (*)(void *))dlsym(g_pGSMCodecLibraryHandle, "gsm_destroy"); + gsm_session_encode = (void (*)(void *, short *, unsigned char *))dlsym(g_pGSMCodecLibraryHandle, "gsm_encode"); + gsm_session_decode = (int (*)(void *, unsigned char *, short *))dlsym(g_pGSMCodecLibraryHandle, "gsm_decode"); - void kvi_gsm_codec_done() + if(!(gsm_session_create && gsm_session_destroy && gsm_session_encode && gsm_session_decode)) { - if(g_pGSMCodecLibraryHandle) - { - dlclose(g_pGSMCodecLibraryHandle); - g_pGSMCodecLibraryHandle = 0; - } + dlclose(g_pGSMCodecLibraryHandle); + g_pGSMCodecLibraryHandle = 0; + return false; } + return true; +} - - DccVoiceGsmCodec::DccVoiceGsmCodec() - : DccVoiceCodec() +void kvi_gsm_codec_done() +{ + if(g_pGSMCodecLibraryHandle) { - m_pEncodeState = gsm_session_create(); - m_pDecodeState = gsm_session_create(); - m_szName = "gsm (compression 33:320)"; + dlclose(g_pGSMCodecLibraryHandle); + g_pGSMCodecLibraryHandle = 0; } +} - DccVoiceGsmCodec::~DccVoiceGsmCodec() - { - gsm_session_destroy(m_pEncodeState); - gsm_session_destroy(m_pDecodeState); - } +DccVoiceGsmCodec::DccVoiceGsmCodec() + : DccVoiceCodec() +{ + m_pEncodeState = gsm_session_create(); + m_pDecodeState = gsm_session_create(); + m_szName = "gsm (compression 33:320)"; +} - void DccVoiceGsmCodec::encode(KviDataBuffer * signal,KviDataBuffer * stream) - { - if(signal->size() < GSM_UNPACKED_FRAME_SIZE_IN_BYTES)return; // nothing to encode +DccVoiceGsmCodec::~DccVoiceGsmCodec() +{ + gsm_session_destroy(m_pEncodeState); + gsm_session_destroy(m_pDecodeState); +} - unsigned char * ptr = signal->data(); +void DccVoiceGsmCodec::encode(KviDataBuffer * signal, KviDataBuffer * stream) +{ + if(signal->size() < GSM_UNPACKED_FRAME_SIZE_IN_BYTES) + return; // nothing to encode - int uFrames = signal->size() / GSM_UNPACKED_FRAME_SIZE_IN_BYTES; - int uTotalDataCompressed = uFrames * GSM_UNPACKED_FRAME_SIZE_IN_BYTES; - int uFrameOffset = stream->size(); - unsigned char * endPtr = ptr + uTotalDataCompressed; + unsigned char * ptr = signal->data(); - stream->addSize(GSM_PACKED_FRAME_SIZE_IN_BYTES * uFrames); + int uFrames = signal->size() / GSM_UNPACKED_FRAME_SIZE_IN_BYTES; + int uTotalDataCompressed = uFrames * GSM_UNPACKED_FRAME_SIZE_IN_BYTES; + int uFrameOffset = stream->size(); + unsigned char * endPtr = ptr + uTotalDataCompressed; - while(ptr != endPtr) - { - gsm_session_encode(m_pEncodeState,(short *)ptr,stream->data() + uFrameOffset); - ptr += GSM_UNPACKED_FRAME_SIZE_IN_BYTES; - uFrameOffset += GSM_PACKED_FRAME_SIZE_IN_BYTES; - } - signal->remove(uTotalDataCompressed); - } + stream->addSize(GSM_PACKED_FRAME_SIZE_IN_BYTES * uFrames); - void DccVoiceGsmCodec::decode(KviDataBuffer * stream,KviDataBuffer * signal) + while(ptr != endPtr) { - if(stream->size() < GSM_PACKED_FRAME_SIZE_IN_BYTES)return; // nothing to decode + gsm_session_encode(m_pEncodeState, (short *)ptr, stream->data() + uFrameOffset); + ptr += GSM_UNPACKED_FRAME_SIZE_IN_BYTES; + uFrameOffset += GSM_PACKED_FRAME_SIZE_IN_BYTES; + } + signal->remove(uTotalDataCompressed); +} - unsigned char * ptr = stream->data(); +void DccVoiceGsmCodec::decode(KviDataBuffer * stream, KviDataBuffer * signal) +{ + if(stream->size() < GSM_PACKED_FRAME_SIZE_IN_BYTES) + return; // nothing to decode - // Gsm codec - int uFrames = stream->size() / GSM_PACKED_FRAME_SIZE_IN_BYTES; - int uTotalDataDecompressed = uFrames * GSM_PACKED_FRAME_SIZE_IN_BYTES; - int uSignalOffset = signal->size(); - unsigned char * endPtr = ptr + (uTotalDataDecompressed); + unsigned char * ptr = stream->data(); - signal->addSize(GSM_UNPACKED_FRAME_SIZE_IN_BYTES * uFrames); + // Gsm codec + int uFrames = stream->size() / GSM_PACKED_FRAME_SIZE_IN_BYTES; + int uTotalDataDecompressed = uFrames * GSM_PACKED_FRAME_SIZE_IN_BYTES; + int uSignalOffset = signal->size(); + unsigned char * endPtr = ptr + (uTotalDataDecompressed); - while(ptr != endPtr) - { - // We don't check the return value here - // Well..it is either an unrecoverable internal error - // or a broken frame... - // but if we receive broken frames over DCC...well....better - // check the hardware...or the remote codec as well... - gsm_session_decode(m_pDecodeState,ptr,(short *)(signal->data() + uSignalOffset)); - ptr += GSM_PACKED_FRAME_SIZE_IN_BYTES; - uSignalOffset += GSM_UNPACKED_FRAME_SIZE_IN_BYTES; - } - stream->remove(uTotalDataDecompressed); - } + signal->addSize(GSM_UNPACKED_FRAME_SIZE_IN_BYTES * uFrames); - int DccVoiceGsmCodec::encodedFrameSize() + while(ptr != endPtr) { - return GSM_PACKED_FRAME_SIZE_IN_BYTES; + // We don't check the return value here + // Well..it is either an unrecoverable internal error + // or a broken frame... + // but if we receive broken frames over DCC...well....better + // check the hardware...or the remote codec as well... + gsm_session_decode(m_pDecodeState, ptr, (short *)(signal->data() + uSignalOffset)); + ptr += GSM_PACKED_FRAME_SIZE_IN_BYTES; + uSignalOffset += GSM_UNPACKED_FRAME_SIZE_IN_BYTES; } + stream->remove(uTotalDataDecompressed); +} - int DccVoiceGsmCodec::decodedFrameSize() - { - return GSM_UNPACKED_FRAME_SIZE_IN_BYTES; - } +int DccVoiceGsmCodec::encodedFrameSize() +{ + return GSM_PACKED_FRAME_SIZE_IN_BYTES; +} + +int DccVoiceGsmCodec::decodedFrameSize() +{ + return GSM_UNPACKED_FRAME_SIZE_IN_BYTES; +} #endif // COMPILE_USE_GSM |
