diff options
58 files changed, 9818 insertions, 9814 deletions
diff --git a/.gitignore b/.gitignore index 97fa6ca..97fa6ca 100644..100755 --- a/.gitignore +++ b/.gitignore diff --git a/AStyle.sh b/AStyle.sh index 560791a..560791a 100644..100755 --- a/AStyle.sh +++ b/AStyle.sh diff --git a/bindings/_common/ActionConfig.cxx b/bindings/_common/ActionConfig.cxx index 35628ed..15028a7 100755 --- a/bindings/_common/ActionConfig.cxx +++ b/bindings/_common/ActionConfig.cxx @@ -1,88 +1,88 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -*/ - -#include "ActionConfig.h" - -ActionConfig::ActionConfig() -{ - m_pHandle = tsip_action_create(tsip_atype_config, - TSIP_ACTION_SET_NULL()); -} - -ActionConfig::~ActionConfig() -{ - TSK_OBJECT_SAFE_FREE(m_pHandle); -} - -bool ActionConfig::addHeader(const char* name, const char* value) -{ - return (tsip_action_set(m_pHandle, - TSIP_ACTION_SET_HEADER(name, value), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool ActionConfig::addPayload(const void* payload, unsigned len) -{ - return (tsip_action_set(m_pHandle, - TSIP_ACTION_SET_PAYLOAD(payload, len), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool ActionConfig::setActiveMedia(twrap_media_type_t type) -{ - tmedia_type_t media_type = twrap_get_native_media_type(type); - return (tsip_action_set(m_pHandle, - TSIP_ACTION_SET_MEDIA_TYPE(media_type), - TSIP_ACTION_SET_NULL()) == 0); -} - -ActionConfig* ActionConfig::setResponseLine(short code, const char* phrase) -{ - int32_t _code = code; - tsip_action_set(m_pHandle, - TSIP_ACTION_SET_RESP_LINE(_code, phrase), - TSIP_ACTION_SET_NULL()); - return this; -} - -ActionConfig* ActionConfig::setMediaString(twrap_media_type_t type, const char* key, const char* value) -{ - tmedia_type_t media_type = twrap_get_native_media_type(type); - tsip_action_set(m_pHandle, - TSIP_ACTION_SET_MEDIA( - TMEDIA_SESSION_SET_STR(media_type, key, value), - TMEDIA_SESSION_SET_NULL()), - TSIP_ACTION_SET_NULL()); - - return this; -} - -ActionConfig* ActionConfig::setMediaInt(twrap_media_type_t type, const char* key, int value) -{ - tmedia_type_t media_type = twrap_get_native_media_type(type); - tsip_action_set(m_pHandle, - TSIP_ACTION_SET_MEDIA( - TMEDIA_SESSION_SET_INT32(media_type, key, value), - TMEDIA_SESSION_SET_NULL()), - TSIP_ACTION_SET_NULL()); - - return this; +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*/
+
+#include "ActionConfig.h"
+
+ActionConfig::ActionConfig()
+{
+ m_pHandle = tsip_action_create(tsip_atype_config,
+ TSIP_ACTION_SET_NULL());
+}
+
+ActionConfig::~ActionConfig()
+{
+ TSK_OBJECT_SAFE_FREE(m_pHandle);
+}
+
+bool ActionConfig::addHeader(const char* name, const char* value)
+{
+ return (tsip_action_set(m_pHandle,
+ TSIP_ACTION_SET_HEADER(name, value),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool ActionConfig::addPayload(const void* payload, unsigned len)
+{
+ return (tsip_action_set(m_pHandle,
+ TSIP_ACTION_SET_PAYLOAD(payload, len),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool ActionConfig::setActiveMedia(twrap_media_type_t type)
+{
+ tmedia_type_t media_type = twrap_get_native_media_type(type);
+ return (tsip_action_set(m_pHandle,
+ TSIP_ACTION_SET_MEDIA_TYPE(media_type),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+ActionConfig* ActionConfig::setResponseLine(short code, const char* phrase)
+{
+ int32_t _code = code;
+ tsip_action_set(m_pHandle,
+ TSIP_ACTION_SET_RESP_LINE(_code, phrase),
+ TSIP_ACTION_SET_NULL());
+ return this;
+}
+
+ActionConfig* ActionConfig::setMediaString(twrap_media_type_t type, const char* key, const char* value)
+{
+ tmedia_type_t media_type = twrap_get_native_media_type(type);
+ tsip_action_set(m_pHandle,
+ TSIP_ACTION_SET_MEDIA(
+ TMEDIA_SESSION_SET_STR(media_type, key, value),
+ TMEDIA_SESSION_SET_NULL()),
+ TSIP_ACTION_SET_NULL());
+
+ return this;
+}
+
+ActionConfig* ActionConfig::setMediaInt(twrap_media_type_t type, const char* key, int value)
+{
+ tmedia_type_t media_type = twrap_get_native_media_type(type);
+ tsip_action_set(m_pHandle,
+ TSIP_ACTION_SET_MEDIA(
+ TMEDIA_SESSION_SET_INT32(media_type, key, value),
+ TMEDIA_SESSION_SET_NULL()),
+ TSIP_ACTION_SET_NULL());
+
+ return this;
}
\ No newline at end of file diff --git a/bindings/_common/ActionConfig.h b/bindings/_common/ActionConfig.h index 2cc43bd..c7be961 100755 --- a/bindings/_common/ActionConfig.h +++ b/bindings/_common/ActionConfig.h @@ -1,52 +1,52 @@ -/* Copyright (C) 2010-2011 Mamadou Diop. -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -*/ -#ifndef TINYWRAP_ACTIONCONFIG_H -#define TINYWRAP_ACTIONCONFIG_H - -#include "tinyWRAP_config.h" - -#include "tinysip.h" -#include "Common.h" - -class TINYWRAP_API ActionConfig -{ -public: - ActionConfig(); - virtual ~ActionConfig(); - - bool addHeader(const char* name, const char* value); - bool addPayload(const void* payload, unsigned len); - bool setActiveMedia(twrap_media_type_t type); - - ActionConfig* setResponseLine(short code, const char* phrase); - ActionConfig* setMediaString(twrap_media_type_t type, const char* key, const char* value); - ActionConfig* setMediaInt(twrap_media_type_t type, const char* key, int value); - -private: - tsip_action_handle_t* m_pHandle; - -#if !defined(SWIG) -public: - const inline tsip_action_handle_t* getHandle()const { - return m_pHandle; - } -#endif -}; - - -#endif /* TINYWRAP_ACTIONCONFIG_H */ +/* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*/
+#ifndef TINYWRAP_ACTIONCONFIG_H
+#define TINYWRAP_ACTIONCONFIG_H
+
+#include "tinyWRAP_config.h"
+
+#include "tinysip.h"
+#include "Common.h"
+
+class TINYWRAP_API ActionConfig
+{
+public:
+ ActionConfig();
+ virtual ~ActionConfig();
+
+ bool addHeader(const char* name, const char* value);
+ bool addPayload(const void* payload, unsigned len);
+ bool setActiveMedia(twrap_media_type_t type);
+
+ ActionConfig* setResponseLine(short code, const char* phrase);
+ ActionConfig* setMediaString(twrap_media_type_t type, const char* key, const char* value);
+ ActionConfig* setMediaInt(twrap_media_type_t type, const char* key, int value);
+
+private:
+ tsip_action_handle_t* m_pHandle;
+
+#if !defined(SWIG)
+public:
+ const inline tsip_action_handle_t* getHandle()const {
+ return m_pHandle;
+ }
+#endif
+};
+
+
+#endif /* TINYWRAP_ACTIONCONFIG_H */
diff --git a/bindings/_common/AudioResampler.cxx b/bindings/_common/AudioResampler.cxx index 850fdc8..f492252 100755 --- a/bindings/_common/AudioResampler.cxx +++ b/bindings/_common/AudioResampler.cxx @@ -1,73 +1,73 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ - -/**@file AudioResampler.cxx - * @brief Audio resampler - * - * @author Mamadou Diop <diopmamadou(at)doubango.org> - */ -#include "AudioResampler.h" - -#include "tinymedia/tmedia_resampler.h" - -#include "tsk_debug.h" - -AudioResampler::AudioResampler(uint32_t nInFreq, uint32_t nOutFreq, uint32_t nFrameDuration, uint32_t nChannels, uint32_t nQuality): - m_nOutFreq(nOutFreq), - m_nInFreq(nInFreq), - m_nFrameDuration(nFrameDuration), - m_nChannels(nChannels), - m_nQuality(nQuality) -{ - if ((m_pWrappedResampler = tmedia_resampler_create())) { - int ret; - if ((ret = tmedia_resampler_open(m_pWrappedResampler, nInFreq, nOutFreq, nFrameDuration, nChannels, nChannels, m_nQuality, 16))) { - TSK_DEBUG_ERROR("Failed to open audio resampler (%d)", ret); - TSK_OBJECT_SAFE_FREE(m_pWrappedResampler); - } - } - else { - TSK_DEBUG_ERROR("No audio resampler could be found. Did you forget to call tdav_init()?"); - } -} - -AudioResampler::~AudioResampler() -{ - TSK_OBJECT_SAFE_FREE(m_pWrappedResampler); -} - -uint32_t AudioResampler::process(const void* pInData, uint32_t nInSizeInBytes, void* pOutData, uint32_t nOutSizeInBytes) -{ - if(!m_pWrappedResampler) { - TSK_DEBUG_ERROR("Embedded resampler is invalid"); - return 0; - } - if(nInSizeInBytes < getInputRequiredSizeInShort()/2) { - TSK_DEBUG_ERROR("Input buffer is too short"); - return 0; - } - if(nOutSizeInBytes < getOutputRequiredSizeInShort()/2) { - TSK_DEBUG_ERROR("Output buffer is too short"); - return 0; - } - return 2*tmedia_resampler_process(m_pWrappedResampler, (uint16_t*)pInData, nInSizeInBytes/2, (uint16_t*)pOutData, nOutSizeInBytes/2); -} +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+/**@file AudioResampler.cxx
+ * @brief Audio resampler
+ *
+ * @author Mamadou Diop <diopmamadou(at)doubango.org>
+ */
+#include "AudioResampler.h"
+
+#include "tinymedia/tmedia_resampler.h"
+
+#include "tsk_debug.h"
+
+AudioResampler::AudioResampler(uint32_t nInFreq, uint32_t nOutFreq, uint32_t nFrameDuration, uint32_t nChannels, uint32_t nQuality):
+ m_nOutFreq(nOutFreq),
+ m_nInFreq(nInFreq),
+ m_nFrameDuration(nFrameDuration),
+ m_nChannels(nChannels),
+ m_nQuality(nQuality)
+{
+ if ((m_pWrappedResampler = tmedia_resampler_create())) {
+ int ret;
+ if ((ret = tmedia_resampler_open(m_pWrappedResampler, nInFreq, nOutFreq, nFrameDuration, nChannels, nChannels, m_nQuality, 16))) {
+ TSK_DEBUG_ERROR("Failed to open audio resampler (%d)", ret);
+ TSK_OBJECT_SAFE_FREE(m_pWrappedResampler);
+ }
+ }
+ else {
+ TSK_DEBUG_ERROR("No audio resampler could be found. Did you forget to call tdav_init()?");
+ }
+}
+
+AudioResampler::~AudioResampler()
+{
+ TSK_OBJECT_SAFE_FREE(m_pWrappedResampler);
+}
+
+uint32_t AudioResampler::process(const void* pInData, uint32_t nInSizeInBytes, void* pOutData, uint32_t nOutSizeInBytes)
+{
+ if(!m_pWrappedResampler) {
+ TSK_DEBUG_ERROR("Embedded resampler is invalid");
+ return 0;
+ }
+ if(nInSizeInBytes < getInputRequiredSizeInShort()/2) {
+ TSK_DEBUG_ERROR("Input buffer is too short");
+ return 0;
+ }
+ if(nOutSizeInBytes < getOutputRequiredSizeInShort()/2) {
+ TSK_DEBUG_ERROR("Output buffer is too short");
+ return 0;
+ }
+ return 2*tmedia_resampler_process(m_pWrappedResampler, (uint16_t*)pInData, nInSizeInBytes/2, (uint16_t*)pOutData, nOutSizeInBytes/2);
+}
diff --git a/bindings/_common/AudioResampler.h b/bindings/_common/AudioResampler.h index 87c7995..09dd2c1 100755 --- a/bindings/_common/AudioResampler.h +++ b/bindings/_common/AudioResampler.h @@ -1,62 +1,62 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ - -/**@file AudioResampler.h - * @brief Audio resampler - * - * @author Mamadou Diop <diopmamadou(at)doubango.org> - */ -#ifndef TINYWRAP_AUDIO_RESAMPLER_H -#define TINYWRAP_AUDIO_RESAMPLER_H - -#include "tinyWRAP_config.h" -#include "tsk_common.h" - -class AudioResampler -{ -public: - AudioResampler(uint32_t nInFreq, uint32_t nOutFreq, uint32_t nFrameDuration, uint32_t nChannels, uint32_t nQuality); - ~AudioResampler(); - -public: - inline bool isValid() { - return (m_pWrappedResampler != tsk_null); - } - inline uint32_t getOutputRequiredSizeInShort() { - return (m_nOutFreq * m_nFrameDuration)/1000; - } - inline uint32_t getInputRequiredSizeInShort() { - return (m_nInFreq * m_nFrameDuration)/1000; - } - uint32_t process(const void* pInData, uint32_t nInSizeInBytes, void* pOutData, uint32_t nOutSizeInBytes); - -private: - struct tmedia_resampler_s* m_pWrappedResampler; - uint32_t m_nOutFreq; - uint32_t m_nInFreq; - uint32_t m_nFrameDuration; - uint32_t m_nChannels; - uint32_t m_nQuality; -}; - - -#endif /* TINYWRAP_AUDIO_RESAMPLER_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+/**@file AudioResampler.h
+ * @brief Audio resampler
+ *
+ * @author Mamadou Diop <diopmamadou(at)doubango.org>
+ */
+#ifndef TINYWRAP_AUDIO_RESAMPLER_H
+#define TINYWRAP_AUDIO_RESAMPLER_H
+
+#include "tinyWRAP_config.h"
+#include "tsk_common.h"
+
+class AudioResampler
+{
+public:
+ AudioResampler(uint32_t nInFreq, uint32_t nOutFreq, uint32_t nFrameDuration, uint32_t nChannels, uint32_t nQuality);
+ ~AudioResampler();
+
+public:
+ inline bool isValid() {
+ return (m_pWrappedResampler != tsk_null);
+ }
+ inline uint32_t getOutputRequiredSizeInShort() {
+ return (m_nOutFreq * m_nFrameDuration)/1000;
+ }
+ inline uint32_t getInputRequiredSizeInShort() {
+ return (m_nInFreq * m_nFrameDuration)/1000;
+ }
+ uint32_t process(const void* pInData, uint32_t nInSizeInBytes, void* pOutData, uint32_t nOutSizeInBytes);
+
+private:
+ struct tmedia_resampler_s* m_pWrappedResampler;
+ uint32_t m_nOutFreq;
+ uint32_t m_nInFreq;
+ uint32_t m_nFrameDuration;
+ uint32_t m_nChannels;
+ uint32_t m_nQuality;
+};
+
+
+#endif /* TINYWRAP_AUDIO_RESAMPLER_H */
diff --git a/bindings/_common/Common.h b/bindings/_common/Common.h index eb206b6..67c2987 100755 --- a/bindings/_common/Common.h +++ b/bindings/_common/Common.h @@ -1,95 +1,95 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_COMMON_H -#define TINYWRAP_COMMON_H - -#include "tinyWRAP_config.h" - -#if ANDROID -# define dyn_cast static_cast -# define __JNIENV JNIEnv -#else -# define dyn_cast dynamic_cast -# define __JNIENV void -#endif - -typedef enum twrap_media_type_e { - // because of Java don't use OR - twrap_media_none = 0x00, - - twrap_media_audio = 0x01, // (0x01 << 0) - twrap_media_video = 0x02, // (0x01 << 1) - twrap_media_msrp = 0x04, // (0x01 << 2) - twrap_media_t140 = 0x08, // (0x01 << 3) - twrap_media_bfcp = 0x10, // (0x01 << 4) - twrap_media_bfcp_audio = 0x30, // (0x01 << 5) | twrap_media_bfcp; - twrap_media_bfcp_video = 0x50, // (0x01 << 6) | twrap_media_bfcp; - - twrap_media_audiovideo = 0x03, /* @deprecated */ - twrap_media_audio_video = twrap_media_audiovideo, -} -twrap_media_type_t; - -#if !defined(SWIG) -#include "tinymedia/tmedia_common.h" - -struct media_type_bind_s { - twrap_media_type_t twrap; - tmedia_type_t tnative; -}; -static const struct media_type_bind_s __media_type_binds[] = { - { twrap_media_msrp, tmedia_msrp }, - { twrap_media_audio , tmedia_audio }, - { twrap_media_video, tmedia_video }, - { twrap_media_audio_video, (tmedia_type_t)(tmedia_audio | tmedia_video) }, - { twrap_media_t140, tmedia_t140 }, - { twrap_media_bfcp, tmedia_bfcp }, - { twrap_media_bfcp_audio, tmedia_bfcp_audio }, - { twrap_media_bfcp_video, tmedia_bfcp_video }, -}; -static const tsk_size_t __media_type_binds_count = sizeof(__media_type_binds)/sizeof(__media_type_binds[0]); -static tmedia_type_t twrap_get_native_media_type(twrap_media_type_t type) -{ - tsk_size_t u; - tmedia_type_t t = tmedia_none; - for (u = 0; u < __media_type_binds_count; ++u) { - if ((__media_type_binds[u].twrap & type) == __media_type_binds[u].twrap) { - t = (tmedia_type_t)(t | __media_type_binds[u].tnative); - } - } - return t; -} -static twrap_media_type_t twrap_get_wrapped_media_type(tmedia_type_t type) -{ - twrap_media_type_t t = twrap_media_none; - tsk_size_t u; - for (u = 0; u < __media_type_binds_count; ++u) { - if ((__media_type_binds[u].tnative & type) == __media_type_binds[u].tnative) { - t = (twrap_media_type_t)(t | __media_type_binds[u].twrap); - } - } - return t; -} -#endif - -#endif /* TINYWRAP_COMMON_H */ - +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_COMMON_H
+#define TINYWRAP_COMMON_H
+
+#include "tinyWRAP_config.h"
+
+#if ANDROID
+# define dyn_cast static_cast
+# define __JNIENV JNIEnv
+#else
+# define dyn_cast dynamic_cast
+# define __JNIENV void
+#endif
+
+typedef enum twrap_media_type_e {
+ // because of Java don't use OR
+ twrap_media_none = 0x00,
+
+ twrap_media_audio = 0x01, // (0x01 << 0)
+ twrap_media_video = 0x02, // (0x01 << 1)
+ twrap_media_msrp = 0x04, // (0x01 << 2)
+ twrap_media_t140 = 0x08, // (0x01 << 3)
+ twrap_media_bfcp = 0x10, // (0x01 << 4)
+ twrap_media_bfcp_audio = 0x30, // (0x01 << 5) | twrap_media_bfcp;
+ twrap_media_bfcp_video = 0x50, // (0x01 << 6) | twrap_media_bfcp;
+
+ twrap_media_audiovideo = 0x03, /* @deprecated */
+ twrap_media_audio_video = twrap_media_audiovideo,
+}
+twrap_media_type_t;
+
+#if !defined(SWIG)
+#include "tinymedia/tmedia_common.h"
+
+struct media_type_bind_s {
+ twrap_media_type_t twrap;
+ tmedia_type_t tnative;
+};
+static const struct media_type_bind_s __media_type_binds[] = {
+ { twrap_media_msrp, tmedia_msrp },
+ { twrap_media_audio , tmedia_audio },
+ { twrap_media_video, tmedia_video },
+ { twrap_media_audio_video, (tmedia_type_t)(tmedia_audio | tmedia_video) },
+ { twrap_media_t140, tmedia_t140 },
+ { twrap_media_bfcp, tmedia_bfcp },
+ { twrap_media_bfcp_audio, tmedia_bfcp_audio },
+ { twrap_media_bfcp_video, tmedia_bfcp_video },
+};
+static const tsk_size_t __media_type_binds_count = sizeof(__media_type_binds)/sizeof(__media_type_binds[0]);
+static tmedia_type_t twrap_get_native_media_type(twrap_media_type_t type)
+{
+ tsk_size_t u;
+ tmedia_type_t t = tmedia_none;
+ for (u = 0; u < __media_type_binds_count; ++u) {
+ if ((__media_type_binds[u].twrap & type) == __media_type_binds[u].twrap) {
+ t = (tmedia_type_t)(t | __media_type_binds[u].tnative);
+ }
+ }
+ return t;
+}
+static twrap_media_type_t twrap_get_wrapped_media_type(tmedia_type_t type)
+{
+ twrap_media_type_t t = twrap_media_none;
+ tsk_size_t u;
+ for (u = 0; u < __media_type_binds_count; ++u) {
+ if ((__media_type_binds[u].tnative & type) == __media_type_binds[u].tnative) {
+ t = (twrap_media_type_t)(t | __media_type_binds[u].twrap);
+ }
+ }
+ return t;
+}
+#endif
+
+#endif /* TINYWRAP_COMMON_H */
+
diff --git a/bindings/_common/DDebug.cxx b/bindings/_common/DDebug.cxx index a1b77b3..e317f2c 100755 --- a/bindings/_common/DDebug.cxx +++ b/bindings/_common/DDebug.cxx @@ -1,145 +1,145 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "DDebug.h" - -#include "SipStack.h" - -#include "Common.h" - -#if ANDROID /* callbacks will fail with jni */ -# include <android/log.h> -# define ANDROID_DEBUG_TAG "tinyWRAP" -#endif - -/* Very Important ==> never call functions which could raise debug callbacks into callback functions -* Callbacks should not be used with Android (JNI). -*/ - -enum cb_type { - cb_info, - cb_warn, - cb_error, - cb_fatal -}; - -int debug_xxx_cb(const void* arg, const char* fmt, enum cb_type type, va_list *app) -{ - int ret = -1; - if(!arg) { - return -1; - } - - const SipStack* stack = dyn_cast<const SipStack*>((const SipStack*)arg); - - if(stack && stack->getDebugCallback()) { - char* message = tsk_null; - tsk_sprintf_2(&message, fmt, app); - - switch(type) { - case cb_info: - ret= -#if ANDROID - __android_log_write(ANDROID_LOG_INFO, ANDROID_DEBUG_TAG, message); -#else - stack->getDebugCallback()-> OnDebugInfo(message); -#endif - break; - case cb_warn: - ret= -#if ANDROID - __android_log_write(ANDROID_LOG_WARN, ANDROID_DEBUG_TAG, message); -#else - stack->getDebugCallback()-> OnDebugWarn(message); -#endif - break; - case cb_error: - ret= -#if ANDROID - __android_log_write(ANDROID_LOG_ERROR, ANDROID_DEBUG_TAG, message); -#else - stack->getDebugCallback()-> OnDebugError(message); -#endif - break; - case cb_fatal: - ret= -#if ANDROID - __android_log_write(ANDROID_LOG_FATAL, ANDROID_DEBUG_TAG, message); -#else - stack->getDebugCallback()-> OnDebugFatal(message); -#endif - break; - } - - TSK_FREE(message); - } - - return ret; -} - -int DDebugCallback::debug_info_cb(const void* arg, const char* fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = debug_xxx_cb(arg, fmt, cb_info, &ap); - va_end(ap); - - return ret; -} - -int DDebugCallback::debug_warn_cb(const void* arg, const char* fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = debug_xxx_cb(arg, fmt, cb_warn, &ap); - va_end(ap); - - return ret; -} - -int DDebugCallback::debug_error_cb(const void* arg, const char* fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = debug_xxx_cb(arg, fmt, cb_error, &ap); - va_end(ap); - - return ret; -} - -int DDebugCallback::debug_fatal_cb(const void* arg, const char* fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = debug_xxx_cb(arg, fmt, cb_fatal, &ap); - va_end(ap); - - return ret; -} - +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "DDebug.h"
+
+#include "SipStack.h"
+
+#include "Common.h"
+
+#if ANDROID /* callbacks will fail with jni */
+# include <android/log.h>
+# define ANDROID_DEBUG_TAG "tinyWRAP"
+#endif
+
+/* Very Important ==> never call functions which could raise debug callbacks into callback functions
+* Callbacks should not be used with Android (JNI).
+*/
+
+enum cb_type {
+ cb_info,
+ cb_warn,
+ cb_error,
+ cb_fatal
+};
+
+int debug_xxx_cb(const void* arg, const char* fmt, enum cb_type type, va_list *app)
+{
+ int ret = -1;
+ if(!arg) {
+ return -1;
+ }
+
+ const SipStack* stack = dyn_cast<const SipStack*>((const SipStack*)arg);
+
+ if(stack && stack->getDebugCallback()) {
+ char* message = tsk_null;
+ tsk_sprintf_2(&message, fmt, app);
+
+ switch(type) {
+ case cb_info:
+ ret=
+#if ANDROID
+ __android_log_write(ANDROID_LOG_INFO, ANDROID_DEBUG_TAG, message);
+#else
+ stack->getDebugCallback()-> OnDebugInfo(message);
+#endif
+ break;
+ case cb_warn:
+ ret=
+#if ANDROID
+ __android_log_write(ANDROID_LOG_WARN, ANDROID_DEBUG_TAG, message);
+#else
+ stack->getDebugCallback()-> OnDebugWarn(message);
+#endif
+ break;
+ case cb_error:
+ ret=
+#if ANDROID
+ __android_log_write(ANDROID_LOG_ERROR, ANDROID_DEBUG_TAG, message);
+#else
+ stack->getDebugCallback()-> OnDebugError(message);
+#endif
+ break;
+ case cb_fatal:
+ ret=
+#if ANDROID
+ __android_log_write(ANDROID_LOG_FATAL, ANDROID_DEBUG_TAG, message);
+#else
+ stack->getDebugCallback()-> OnDebugFatal(message);
+#endif
+ break;
+ }
+
+ TSK_FREE(message);
+ }
+
+ return ret;
+}
+
+int DDebugCallback::debug_info_cb(const void* arg, const char* fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = debug_xxx_cb(arg, fmt, cb_info, &ap);
+ va_end(ap);
+
+ return ret;
+}
+
+int DDebugCallback::debug_warn_cb(const void* arg, const char* fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = debug_xxx_cb(arg, fmt, cb_warn, &ap);
+ va_end(ap);
+
+ return ret;
+}
+
+int DDebugCallback::debug_error_cb(const void* arg, const char* fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = debug_xxx_cb(arg, fmt, cb_error, &ap);
+ va_end(ap);
+
+ return ret;
+}
+
+int DDebugCallback::debug_fatal_cb(const void* arg, const char* fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = debug_xxx_cb(arg, fmt, cb_fatal, &ap);
+ va_end(ap);
+
+ return ret;
+}
+
diff --git a/bindings/_common/DDebug.h b/bindings/_common/DDebug.h index 67b6340..4cfe9bd 100755 --- a/bindings/_common/DDebug.h +++ b/bindings/_common/DDebug.h @@ -1,57 +1,57 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_SIP_DEBUG_H -#define TINYWRAP_SIP_DEBUG_H - -class DDebugCallback -{ -public: - DDebugCallback() { } - virtual ~DDebugCallback() {} - - - virtual int OnDebugInfo(const char* message) { - return -1; - } - virtual int OnDebugWarn(const char* message) { - return -1; - } - virtual int OnDebugError(const char* message) { - return -1; - } - virtual int OnDebugFatal(const char* message) { - return -1; - } - -#if !defined(SWIG) -public: - static int debug_info_cb(const void* arg, const char* fmt, ...); - static int debug_warn_cb(const void* arg, const char* fmt, ...); - static int debug_error_cb(const void* arg, const char* fmt, ...); - static int debug_fatal_cb(const void* arg, const char* fmt, ...); -#endif - -private: - -}; - -#endif /* TINYWRAP_SIP_DEBUG_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_SIP_DEBUG_H
+#define TINYWRAP_SIP_DEBUG_H
+
+class DDebugCallback
+{
+public:
+ DDebugCallback() { }
+ virtual ~DDebugCallback() {}
+
+
+ virtual int OnDebugInfo(const char* message) {
+ return -1;
+ }
+ virtual int OnDebugWarn(const char* message) {
+ return -1;
+ }
+ virtual int OnDebugError(const char* message) {
+ return -1;
+ }
+ virtual int OnDebugFatal(const char* message) {
+ return -1;
+ }
+
+#if !defined(SWIG)
+public:
+ static int debug_info_cb(const void* arg, const char* fmt, ...);
+ static int debug_warn_cb(const void* arg, const char* fmt, ...);
+ static int debug_error_cb(const void* arg, const char* fmt, ...);
+ static int debug_fatal_cb(const void* arg, const char* fmt, ...);
+#endif
+
+private:
+
+};
+
+#endif /* TINYWRAP_SIP_DEBUG_H */
diff --git a/bindings/_common/MediaContent.cxx b/bindings/_common/MediaContent.cxx index b039bd2..eb78dea 100755 --- a/bindings/_common/MediaContent.cxx +++ b/bindings/_common/MediaContent.cxx @@ -1,179 +1,179 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "MediaContent.h" - - - -MediaContent::MediaContent(tmedia_content_t* pContent) - : m_pData(tsk_null) -{ - m_pContent = (tmedia_content_t*)tsk_object_ref(pContent); -} - -MediaContent::~MediaContent() -{ - TSK_OBJECT_SAFE_FREE(m_pContent); - TSK_OBJECT_SAFE_FREE(m_pData); -} - -const char* MediaContent::getType() -{ - if(m_pContent) { - return m_pContent->type; - } - return tsk_null; -} - -unsigned MediaContent::getDataLength() -{ - if(!m_pContent) { - TSK_DEBUG_ERROR("Invalid internal object"); - return 0; - } - - if(!m_pData) { - m_pData = tmedia_content_get_data(m_pContent); - } - - return (m_pData ? m_pData->size : 0); -} - -unsigned MediaContent::getData(void* pOutput, unsigned nMaxsize) -{ - unsigned nRetsize = 0; - - if(!m_pContent) { - TSK_DEBUG_ERROR("Invalid internal object"); - return 0; - } - - if(!m_pData) { - m_pData = tmedia_content_get_data(m_pContent); - } - - if(pOutput && nMaxsize && m_pData) { - nRetsize = (m_pData->size > nMaxsize) ? nMaxsize : m_pData->size; - memcpy(pOutput, m_pData->data, nRetsize); - } - - return nRetsize; -} - -MediaContent* MediaContent::parse(const void* pData, unsigned nSize, const char* pType) -{ - MediaContent* pMediaContent = tsk_null; - - tmedia_content_t* pContent = tmedia_content_parse(pData, (tsk_size_t)nSize, pType); - if(pContent) { - if(TMEDIA_CONTENT_IS_CPIM(pContent)) { - pMediaContent = new MediaContentCPIM(pContent); - } - else if(TMEDIA_CONTENT_IS_DUMMY(pContent)) { - // Todo - } - TSK_OBJECT_SAFE_FREE(pContent); - } - - return pMediaContent; -} - -MediaContentCPIM* MediaContent::parse(const void* pData, unsigned nSize) -{ - MediaContent* pMediaContent; - if((pMediaContent = MediaContent::parse(pData, nSize, TMEDIA_CONTENT_CPIM_TYPE))) { - return dyn_cast<MediaContentCPIM*>(pMediaContent); - } - return tsk_null; -} - -/* ============ message/CPIM ================= */ - -MediaContentCPIM::MediaContentCPIM(tmedia_content_t* pContent) - : MediaContent(pContent) -{ -} - -MediaContentCPIM::~MediaContentCPIM() -{ -} - -unsigned MediaContentCPIM::getPayloadLength() -{ - if(!m_pContent || !TMEDIA_CONTENT_IS_CPIM(m_pContent)) { - TSK_DEBUG_ERROR("Invalid internal object"); - return 0; - } - - return (TMEDIA_CONTENT_CPIM(m_pContent)->e ? TMEDIA_CONTENT_CPIM(m_pContent)->e->size : 0); -} - -unsigned MediaContentCPIM::getPayload(void* pOutput, unsigned nMaxsize) -{ - unsigned nRetsize = 0; - - if(!m_pContent || !TMEDIA_CONTENT_IS_CPIM(m_pContent)) { - TSK_DEBUG_ERROR("Invalid internal object"); - return 0; - } - - if(pOutput && nMaxsize && TMEDIA_CONTENT_CPIM(m_pContent)->e) { - nRetsize = (TMEDIA_CONTENT_CPIM(m_pContent)->e->size > nMaxsize) ? nMaxsize : TMEDIA_CONTENT_CPIM(m_pContent)->e->size; - memcpy(pOutput, TMEDIA_CONTENT_CPIM(m_pContent)->e->data, nRetsize); - } - - return nRetsize; -} - -const void* MediaContentCPIM::getPayloadPtr() -{ - if(!m_pContent || !TMEDIA_CONTENT_IS_CPIM(m_pContent)) { - TSK_DEBUG_ERROR("Invalid internal object"); - return tsk_null; - } - - return TMEDIA_CONTENT_CPIM(m_pContent)->e ? TMEDIA_CONTENT_CPIM(m_pContent)->e->data : tsk_null; -} - -const char* MediaContentCPIM::getHeaderValue(const char* name) -{ - const tmedia_content_cpim_t* cpim; - const tsk_list_item_t* item; - - if(!m_pContent || !TMEDIA_CONTENT_IS_CPIM(m_pContent)) { - TSK_DEBUG_ERROR("Invalid internal object"); - return tsk_null; - } - - cpim = TMEDIA_CONTENT_CPIM(m_pContent); - tsk_list_foreach(item, cpim->h_headers) { - if(tsk_striequals(name, TMEDIA_CONTENT_HEADER(item->data)->name)) { - return TMEDIA_CONTENT_HEADER(item->data)->value; - } - } - tsk_list_foreach(item, cpim->m_headers) { - if(tsk_striequals(name, TMEDIA_CONTENT_HEADER(item->data)->name)) { - return TMEDIA_CONTENT_HEADER(item->data)->value; - } - } - - return tsk_null; +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "MediaContent.h"
+
+
+
+MediaContent::MediaContent(tmedia_content_t* pContent)
+ : m_pData(tsk_null)
+{
+ m_pContent = (tmedia_content_t*)tsk_object_ref(pContent);
+}
+
+MediaContent::~MediaContent()
+{
+ TSK_OBJECT_SAFE_FREE(m_pContent);
+ TSK_OBJECT_SAFE_FREE(m_pData);
+}
+
+const char* MediaContent::getType()
+{
+ if(m_pContent) {
+ return m_pContent->type;
+ }
+ return tsk_null;
+}
+
+unsigned MediaContent::getDataLength()
+{
+ if(!m_pContent) {
+ TSK_DEBUG_ERROR("Invalid internal object");
+ return 0;
+ }
+
+ if(!m_pData) {
+ m_pData = tmedia_content_get_data(m_pContent);
+ }
+
+ return (m_pData ? m_pData->size : 0);
+}
+
+unsigned MediaContent::getData(void* pOutput, unsigned nMaxsize)
+{
+ unsigned nRetsize = 0;
+
+ if(!m_pContent) {
+ TSK_DEBUG_ERROR("Invalid internal object");
+ return 0;
+ }
+
+ if(!m_pData) {
+ m_pData = tmedia_content_get_data(m_pContent);
+ }
+
+ if(pOutput && nMaxsize && m_pData) {
+ nRetsize = (m_pData->size > nMaxsize) ? nMaxsize : m_pData->size;
+ memcpy(pOutput, m_pData->data, nRetsize);
+ }
+
+ return nRetsize;
+}
+
+MediaContent* MediaContent::parse(const void* pData, unsigned nSize, const char* pType)
+{
+ MediaContent* pMediaContent = tsk_null;
+
+ tmedia_content_t* pContent = tmedia_content_parse(pData, (tsk_size_t)nSize, pType);
+ if(pContent) {
+ if(TMEDIA_CONTENT_IS_CPIM(pContent)) {
+ pMediaContent = new MediaContentCPIM(pContent);
+ }
+ else if(TMEDIA_CONTENT_IS_DUMMY(pContent)) {
+ // Todo
+ }
+ TSK_OBJECT_SAFE_FREE(pContent);
+ }
+
+ return pMediaContent;
+}
+
+MediaContentCPIM* MediaContent::parse(const void* pData, unsigned nSize)
+{
+ MediaContent* pMediaContent;
+ if((pMediaContent = MediaContent::parse(pData, nSize, TMEDIA_CONTENT_CPIM_TYPE))) {
+ return dyn_cast<MediaContentCPIM*>(pMediaContent);
+ }
+ return tsk_null;
+}
+
+/* ============ message/CPIM ================= */
+
+MediaContentCPIM::MediaContentCPIM(tmedia_content_t* pContent)
+ : MediaContent(pContent)
+{
+}
+
+MediaContentCPIM::~MediaContentCPIM()
+{
+}
+
+unsigned MediaContentCPIM::getPayloadLength()
+{
+ if(!m_pContent || !TMEDIA_CONTENT_IS_CPIM(m_pContent)) {
+ TSK_DEBUG_ERROR("Invalid internal object");
+ return 0;
+ }
+
+ return (TMEDIA_CONTENT_CPIM(m_pContent)->e ? TMEDIA_CONTENT_CPIM(m_pContent)->e->size : 0);
+}
+
+unsigned MediaContentCPIM::getPayload(void* pOutput, unsigned nMaxsize)
+{
+ unsigned nRetsize = 0;
+
+ if(!m_pContent || !TMEDIA_CONTENT_IS_CPIM(m_pContent)) {
+ TSK_DEBUG_ERROR("Invalid internal object");
+ return 0;
+ }
+
+ if(pOutput && nMaxsize && TMEDIA_CONTENT_CPIM(m_pContent)->e) {
+ nRetsize = (TMEDIA_CONTENT_CPIM(m_pContent)->e->size > nMaxsize) ? nMaxsize : TMEDIA_CONTENT_CPIM(m_pContent)->e->size;
+ memcpy(pOutput, TMEDIA_CONTENT_CPIM(m_pContent)->e->data, nRetsize);
+ }
+
+ return nRetsize;
+}
+
+const void* MediaContentCPIM::getPayloadPtr()
+{
+ if(!m_pContent || !TMEDIA_CONTENT_IS_CPIM(m_pContent)) {
+ TSK_DEBUG_ERROR("Invalid internal object");
+ return tsk_null;
+ }
+
+ return TMEDIA_CONTENT_CPIM(m_pContent)->e ? TMEDIA_CONTENT_CPIM(m_pContent)->e->data : tsk_null;
+}
+
+const char* MediaContentCPIM::getHeaderValue(const char* name)
+{
+ const tmedia_content_cpim_t* cpim;
+ const tsk_list_item_t* item;
+
+ if(!m_pContent || !TMEDIA_CONTENT_IS_CPIM(m_pContent)) {
+ TSK_DEBUG_ERROR("Invalid internal object");
+ return tsk_null;
+ }
+
+ cpim = TMEDIA_CONTENT_CPIM(m_pContent);
+ tsk_list_foreach(item, cpim->h_headers) {
+ if(tsk_striequals(name, TMEDIA_CONTENT_HEADER(item->data)->name)) {
+ return TMEDIA_CONTENT_HEADER(item->data)->value;
+ }
+ }
+ tsk_list_foreach(item, cpim->m_headers) {
+ if(tsk_striequals(name, TMEDIA_CONTENT_HEADER(item->data)->name)) {
+ return TMEDIA_CONTENT_HEADER(item->data)->value;
+ }
+ }
+
+ return tsk_null;
}
\ No newline at end of file diff --git a/bindings/_common/MediaContent.h b/bindings/_common/MediaContent.h index 204b8ec..12bff3d 100755 --- a/bindings/_common/MediaContent.h +++ b/bindings/_common/MediaContent.h @@ -1,76 +1,76 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_MEDIA_CONTENT_H -#define TINYWRAP_MEDIA_CONTENT_H - -#include "tinymedia.h" -#include "Common.h" - -class MediaContentCPIM; - -class MediaContent -{ -public: -#if !defined(SWIG) - MediaContent(tmedia_content_t* content); -#endif - virtual ~MediaContent(); - -public: - const char* getType(); - virtual unsigned getDataLength(); - virtual unsigned getData(void* pOutput, unsigned nMaxsize); - - // SWIG %newobject() - static MediaContent* parse(const void* pData, unsigned nSize, const char* pType); - static MediaContentCPIM* parse(const void* pData, unsigned nSize); - - virtual unsigned getPayloadLength() = 0; - virtual unsigned getPayload(void* pOutput, unsigned nMaxsize) = 0; - -protected: - tmedia_content_t* m_pContent; - -private: - tsk_buffer_t* m_pData; -}; - - -/* ============ message/CPIM ================= */ -class MediaContentCPIM : public MediaContent -{ -public: -#if !defined(SWIG) - MediaContentCPIM(tmedia_content_t* pContent); -#endif - virtual ~MediaContentCPIM(); - -public: - virtual unsigned getPayloadLength(); - virtual unsigned getPayload(void* pOutput, unsigned nMaxsize); -#if !defined(SWIG) - const void* getPayloadPtr(); -#endif - const char* getHeaderValue(const char* pName); -}; - -#endif /*TINYWRAP_MEDIA_CONTENT_H*/ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_MEDIA_CONTENT_H
+#define TINYWRAP_MEDIA_CONTENT_H
+
+#include "tinymedia.h"
+#include "Common.h"
+
+class MediaContentCPIM;
+
+class MediaContent
+{
+public:
+#if !defined(SWIG)
+ MediaContent(tmedia_content_t* content);
+#endif
+ virtual ~MediaContent();
+
+public:
+ const char* getType();
+ virtual unsigned getDataLength();
+ virtual unsigned getData(void* pOutput, unsigned nMaxsize);
+
+ // SWIG %newobject()
+ static MediaContent* parse(const void* pData, unsigned nSize, const char* pType);
+ static MediaContentCPIM* parse(const void* pData, unsigned nSize);
+
+ virtual unsigned getPayloadLength() = 0;
+ virtual unsigned getPayload(void* pOutput, unsigned nMaxsize) = 0;
+
+protected:
+ tmedia_content_t* m_pContent;
+
+private:
+ tsk_buffer_t* m_pData;
+};
+
+
+/* ============ message/CPIM ================= */
+class MediaContentCPIM : public MediaContent
+{
+public:
+#if !defined(SWIG)
+ MediaContentCPIM(tmedia_content_t* pContent);
+#endif
+ virtual ~MediaContentCPIM();
+
+public:
+ virtual unsigned getPayloadLength();
+ virtual unsigned getPayload(void* pOutput, unsigned nMaxsize);
+#if !defined(SWIG)
+ const void* getPayloadPtr();
+#endif
+ const char* getHeaderValue(const char* pName);
+};
+
+#endif /*TINYWRAP_MEDIA_CONTENT_H*/
diff --git a/bindings/_common/MediaSessionMgr.cxx b/bindings/_common/MediaSessionMgr.cxx index 6bfb333..d844e4e 100755 --- a/bindings/_common/MediaSessionMgr.cxx +++ b/bindings/_common/MediaSessionMgr.cxx @@ -1,665 +1,665 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "MediaSessionMgr.h" - -// -// QoS -// -QoS::QoS(float qavg, float q1 /*= -1.f*/, float q2 /*= -1.f*/, float q3 /*= -1.f*/, float q4 /*= -1.f*/, float q5 /*= -1.f*/) - : m_Qqvg(qavg) - , m_VideoInWidth(0) - , m_VideoOutWidth(0) - , m_VideoInHeight(0) - , m_VideoOutHeight(0) - , m_BandwidthDownKbps(0) - , m_BandwidthUpKbps(0) - , m_VideoInAvgFps(0) - , m_VideoDecAvgTime(0) - , m_VideoEncAvgTime(0) -{ - m_Qn[0] = q1; - m_Qn[1] = q2; - m_Qn[2] = q3; - m_Qn[3] = q4; - m_Qn[4] = q5; -} - -QoS::~QoS() -{ -} - -// -// Codec -// -Codec::Codec(const struct tmedia_codec_s* pWrappedCodec) -{ - m_pWrappedCodec = (struct tmedia_codec_s*)tsk_object_ref(TSK_OBJECT(pWrappedCodec)); -} - -Codec::~Codec() -{ - TSK_OBJECT_SAFE_FREE(m_pWrappedCodec); -} - -twrap_media_type_t Codec::getMediaType() -{ - if(m_pWrappedCodec) { - switch(m_pWrappedCodec->type) { - case tmedia_audio: - return twrap_media_audio; - case tmedia_video: - return twrap_media_video; - case tmedia_msrp: - return twrap_media_msrp; - default: - break; - } - } - return twrap_media_none; -} - -const char* Codec::getName() -{ - if(m_pWrappedCodec) { - return m_pWrappedCodec->name; - } - return tsk_null; -} - -const char* Codec::getDescription() -{ - if(m_pWrappedCodec) { - return m_pWrappedCodec->desc; - } - return tsk_null; -} - -const char* Codec::getNegFormat() -{ - if(m_pWrappedCodec) { - return m_pWrappedCodec->neg_format ? m_pWrappedCodec->neg_format : m_pWrappedCodec->format; - } - return tsk_null; -} - -int Codec::getAudioSamplingRate() -{ - if(m_pWrappedCodec && m_pWrappedCodec->plugin) { - return m_pWrappedCodec->plugin->rate; - } - return 0; -} - -int Codec::getAudioChannels() -{ - if(m_pWrappedCodec && (m_pWrappedCodec->type & tmedia_audio) && m_pWrappedCodec->plugin) { - return m_pWrappedCodec->plugin->audio.channels; - } - return 0; -} - -int Codec::getAudioPTime() -{ - if(m_pWrappedCodec && (m_pWrappedCodec->type & tmedia_audio) && m_pWrappedCodec->plugin) { - return m_pWrappedCodec->plugin->audio.ptime; - } - return 0; -} - -// -// MediaSessionMgr -// -MediaSessionMgr::MediaSessionMgr(tmedia_session_mgr_t* pWrappedMgr) -{ - m_pWrappedMgr = (tmedia_session_mgr_t*)tsk_object_ref(pWrappedMgr); -} - -MediaSessionMgr::~MediaSessionMgr() -{ - TSK_OBJECT_SAFE_FREE(m_pWrappedMgr); -} - -bool MediaSessionMgr::sessionSetInt32(twrap_media_type_t media, const char* key, int32_t value) -{ - tmedia_type_t _media = twrap_get_native_media_type(media); - return (tmedia_session_mgr_set(m_pWrappedMgr, - TMEDIA_SESSION_SET_INT32(_media, key, value), - TMEDIA_SESSION_SET_NULL()) == 0); -} - -int32_t MediaSessionMgr::sessionGetInt32(twrap_media_type_t media, const char* key) -{ - int32_t value = 0; - tmedia_type_t _media = twrap_get_native_media_type(media); - (tmedia_session_mgr_get(m_pWrappedMgr, - TMEDIA_SESSION_GET_INT32(_media, key, &value), - TMEDIA_SESSION_GET_NULL())); - return value; -} - -QoS* MediaSessionMgr::sessionGetQoS(twrap_media_type_t media) -{ - tmedia_type_t _media = twrap_get_native_media_type(media); - tmedia_session_t* session = tmedia_session_mgr_find(m_pWrappedMgr, _media); - if (session) { - QoS* pQoS = new QoS( - session->qos_metrics.qvag, - session->qos_metrics.q1, - session->qos_metrics.q2, - session->qos_metrics.q3, - session->qos_metrics.q4, - session->qos_metrics.q5); - if (pQoS && ((_media & tmedia_video) || (_media & tmedia_bfcp_video))) { - pQoS->m_VideoInWidth = session->qos_metrics.video_in_width; - pQoS->m_VideoInHeight = session->qos_metrics.video_in_height; - pQoS->m_VideoOutWidth = session->qos_metrics.video_out_width; - pQoS->m_VideoOutHeight = session->qos_metrics.video_out_height; - pQoS->m_BandwidthDownKbps = session->qos_metrics.bw_down_est_kbps; - pQoS->m_BandwidthUpKbps = session->qos_metrics.bw_up_est_kbps; - pQoS->m_VideoInAvgFps = session->qos_metrics.video_in_avg_fps; - pQoS->m_VideoDecAvgTime = session->qos_metrics.video_dec_avg_time; - pQoS->m_VideoEncAvgTime = session->qos_metrics.video_enc_avg_time; - } - TSK_OBJECT_SAFE_FREE(session); - return pQoS; - } - return NULL; -} - -bool MediaSessionMgr::consumerSetInt32(twrap_media_type_t media, const char* key, int32_t value) -{ - tmedia_type_t _media = twrap_get_native_media_type(media); - return (tmedia_session_mgr_set(m_pWrappedMgr, - TMEDIA_SESSION_CONSUMER_SET_INT32(_media, key, value), - TMEDIA_SESSION_SET_NULL()) == 0); -} - -bool MediaSessionMgr::consumerSetInt64(twrap_media_type_t media, const char* key, int64_t value) -{ - tmedia_type_t _media = twrap_get_native_media_type(media); - return (tmedia_session_mgr_set(m_pWrappedMgr, - TMEDIA_SESSION_CONSUMER_SET_INT64(_media, key, value), - TMEDIA_SESSION_SET_NULL()) == 0); -} - -bool MediaSessionMgr::producerSetInt32(twrap_media_type_t media, const char* key, int32_t value) -{ - tmedia_type_t _media = twrap_get_native_media_type(media); - return (tmedia_session_mgr_set(m_pWrappedMgr, - TMEDIA_SESSION_PRODUCER_SET_INT32(_media, key, value), - TMEDIA_SESSION_SET_NULL()) == 0); -} - -bool MediaSessionMgr::producerSetInt64(twrap_media_type_t media, const char* key, int64_t value) -{ - tmedia_type_t _media = twrap_get_native_media_type(media); - return (tmedia_session_mgr_set(m_pWrappedMgr, - TMEDIA_SESSION_PRODUCER_SET_INT64(_media, key, value), - TMEDIA_SESSION_SET_NULL()) == 0); -} - -Codec* MediaSessionMgr::producerGetCodec(twrap_media_type_t media) -{ - tmedia_codec_t* _codec = tsk_null; - tmedia_type_t _media = twrap_get_native_media_type(media); - (tmedia_session_mgr_get(m_pWrappedMgr, - TMEDIA_SESSION_PRODUCER_GET_POBJECT(_media, "codec", &_codec), - TMEDIA_SESSION_GET_NULL())); - - if(_codec) { - Codec* pCodec = new Codec(_codec); - TSK_OBJECT_SAFE_FREE(_codec); - return pCodec; - } - return NULL; -} - -#include "tinydav/audio/tdav_session_audio.h" -#include "tinydav/video/tdav_session_video.h" -#include "ProxyPluginMgr.h" - - -const ProxyPlugin* MediaSessionMgr::findProxyPlugin(twrap_media_type_t media, bool consumer)const -{ - const ProxyPlugin* plugin = tsk_null; - ProxyPluginMgr* manager = ProxyPluginMgr::getInstance(); - - if(media != twrap_media_audio && media != twrap_media_video) { - TSK_DEBUG_ERROR("Invalid media type"); - return tsk_null; - } - - if(manager && m_pWrappedMgr) { - tmedia_type_t _media = twrap_get_native_media_type(media); - tmedia_session_t* session = tmedia_session_mgr_find(m_pWrappedMgr, _media); - if(session) { - if(session->plugin == tdav_session_audio_plugin_def_t) { - if(consumer) { - plugin = manager->findPlugin(TDAV_SESSION_AV(session)->consumer); - } - else { - plugin = manager->findPlugin(TDAV_SESSION_AV(session)->producer); - } - } - else if(session->plugin == tdav_session_video_plugin_def_t) { - if(consumer) { - plugin = manager->findPlugin(TDAV_SESSION_AV(session)->consumer); - } - else { - plugin = manager->findPlugin(TDAV_SESSION_AV(session)->producer); - } - } - else { - TSK_DEBUG_ERROR("Unknown session with media type = %d", _media); - } - tsk_object_unref(session); - } - } - else { - TSK_DEBUG_ERROR("Invalid state"); - } - - return plugin; -} - -// FIXME: create generic function to register any kind and number of plugin from a file -unsigned int MediaSessionMgr::registerAudioPluginFromFile(const char* path) -{ - static struct tsk_plugin_s* __plugin = tsk_null; - if(__plugin) { - TSK_DEBUG_ERROR("Audio plugin already registered"); - return 0; - } - if((__plugin = tsk_plugin_create(path))) { - unsigned int count = 0; - tsk_plugin_def_ptr_const_t plugin_def_ptr_const; - if((plugin_def_ptr_const = tsk_plugin_get_def(__plugin, tsk_plugin_def_type_consumer, tsk_plugin_def_media_type_audio))) { - if(tmedia_consumer_plugin_register((const tmedia_consumer_plugin_def_t*)plugin_def_ptr_const) == 0) { - ++count; - } - } - if((plugin_def_ptr_const = tsk_plugin_get_def(__plugin, tsk_plugin_def_type_producer, tsk_plugin_def_media_type_audio))) { - if(tmedia_producer_plugin_register((const tmedia_producer_plugin_def_t*)plugin_def_ptr_const) == 0) { - ++count; - } - } - return count; - } - TSK_DEBUG_ERROR("Failed to create plugin with path=%s", path); - return 0; -} - -uint64_t MediaSessionMgr::getSessionId(twrap_media_type_t media)const -{ - //const ProxyPlugin* plugin = tsk_null; - ProxyPluginMgr* manager = ProxyPluginMgr::getInstance(); - uint64_t id = 0; - - if (media != twrap_media_audio && media != twrap_media_video) { - TSK_DEBUG_ERROR("Invalid media type"); - return 0; - } - - if (manager && m_pWrappedMgr) { - tmedia_type_t _media = twrap_get_native_media_type(media); - tmedia_session_t* session = tmedia_session_mgr_find(m_pWrappedMgr, _media); - if (session) { - id = session->id; - } - tsk_object_unref(session); - } - else { - TSK_DEBUG_ERROR("Invalid state"); - } - - return id; -} - -bool MediaSessionMgr::defaultsSetProfile(tmedia_profile_t profile) -{ - return (tmedia_defaults_set_profile(profile) == 0); -} - -tmedia_profile_t MediaSessionMgr::defaultsGetProfile() -{ - return tmedia_defaults_get_profile(); -} - -bool MediaSessionMgr::defaultsSetBandwidthLevel(tmedia_bandwidth_level_t bl) // @deprecated -{ - return tmedia_defaults_set_bl(bl) == 0; -} -tmedia_bandwidth_level_t MediaSessionMgr::defaultsGetBandwidthLevel() // @deprecated -{ - return tmedia_defaults_get_bl(); -} -bool MediaSessionMgr::defaultsSetCongestionCtrlEnabled(bool enabled) -{ - return tmedia_defaults_set_congestion_ctrl_enabled(enabled ? tsk_true : tsk_false) == 0; -} -bool MediaSessionMgr::defaultsSetVideoMotionRank(int32_t video_motion_rank) -{ - return (tmedia_defaults_set_video_motion_rank(video_motion_rank) == 0); -} -bool MediaSessionMgr::defaultsSetVideoFps(int32_t video_fps) -{ - return (tmedia_defaults_set_video_fps(video_fps) == 0); -} -bool MediaSessionMgr::defaultsSetBandwidthVideoUploadMax(int32_t bw_video_up_max_kbps) -{ - return (tmedia_defaults_set_bandwidth_video_upload_max(bw_video_up_max_kbps) == 0); -} -bool MediaSessionMgr::defaultsSetBandwidthVideoDownloadMax(int32_t bw_video_down_max_kbps) -{ - return (tmedia_defaults_set_bandwidth_video_download_max(bw_video_down_max_kbps) == 0); -} - -bool MediaSessionMgr::defaultsSetPrefVideoSize(tmedia_pref_video_size_t pref_video_size) -{ - return tmedia_defaults_set_pref_video_size(pref_video_size) == 0; -} - -bool MediaSessionMgr::defaultsSetPrefVideoSizeOutRange(tmedia_pref_video_size_t min, tmedia_pref_video_size_t max) -{ - return tmedia_defaults_set_pref_video_size_range(min, max) == 0; -} - -bool MediaSessionMgr::defaultsSetAdaptativeVideoSizeOutEnabled(bool enabled) -{ - return tmedia_defaults_set_adapt_video_size_range_enabled(enabled ? tsk_true : tsk_false) == 0; -} - -bool MediaSessionMgr::defaultsSetJbMargin(uint32_t jb_margin_ms) -{ - return tmedia_defaults_set_jb_margin(jb_margin_ms) == 0; -} - -bool MediaSessionMgr::defaultsSetJbMaxLateRate(uint32_t jb_late_rate_percent) -{ - return tmedia_defaults_set_jb_max_late_rate(jb_late_rate_percent) == 0; -} - -bool MediaSessionMgr::defaultsSetEchoTail(uint32_t echo_tail) -{ - return tmedia_defaults_set_echo_tail(echo_tail) == 0; -} - -uint32_t MediaSessionMgr::defaultsGetEchoTail() -{ - return tmedia_defaults_get_echo_tail(); -} - -bool MediaSessionMgr::defaultsSetEchoSkew(uint32_t echo_skew) -{ - return tmedia_defaults_set_echo_skew(echo_skew) == 0; -} - -bool MediaSessionMgr::defaultsSetEchoSuppEnabled(bool echo_supp_enabled) -{ - return tmedia_defaults_set_echo_supp_enabled(echo_supp_enabled ? tsk_true : tsk_false) == 0; -} - -bool MediaSessionMgr::defaultsGetEchoSuppEnabled() -{ - return tmedia_defaults_get_echo_supp_enabled() ? true : false; -} - -bool MediaSessionMgr::defaultsSetAgcEnabled(bool agc_enabled) -{ - return tmedia_defaults_set_agc_enabled(agc_enabled ? tsk_true : tsk_false) == 0; -} - -bool MediaSessionMgr::defaultsGetAgcEnabled() -{ - return tmedia_defaults_get_agc_enabled() ? true : false; -} - -bool MediaSessionMgr::defaultsSetAgcLevel(float agc_level) -{ - return tmedia_defaults_set_agc_level(agc_level) == 0; -} - -float MediaSessionMgr::defaultsGetAgcLevel() -{ - return tmedia_defaults_get_agc_level(); -} - -bool MediaSessionMgr::defaultsSetVadEnabled(bool vad_enabled) -{ - return tmedia_defaults_set_vad_enabled(vad_enabled ? tsk_true : tsk_false) == 0; -} - -bool MediaSessionMgr::defaultsGetGetVadEnabled() -{ - return tmedia_defaults_get_vad_enabled() ? true : false; -} - -bool MediaSessionMgr::defaultsSetNoiseSuppEnabled(bool noise_supp_enabled) -{ - return tmedia_defaults_set_noise_supp_enabled(noise_supp_enabled ? tsk_true : tsk_false) == 0; -} - -bool MediaSessionMgr::defaultsGetNoiseSuppEnabled() -{ - return tmedia_defaults_get_noise_supp_enabled() ? true : false; -} - -bool MediaSessionMgr::defaultsSetNoiseSuppLevel(int32_t noise_supp_level) -{ - return tmedia_defaults_set_noise_supp_level(noise_supp_level) == 0; -} - -int32_t MediaSessionMgr::defaultsGetNoiseSuppLevel() -{ - return tmedia_defaults_get_noise_supp_level(); -} - -bool MediaSessionMgr::defaultsSet100relEnabled(bool _100rel_enabled) -{ - return tmedia_defaults_set_100rel_enabled(_100rel_enabled ? tsk_true : tsk_false) == 0; -} - -bool MediaSessionMgr::defaultsGet100relEnabled() -{ - return tmedia_defaults_get_100rel_enabled() == 0; -} - -bool MediaSessionMgr::defaultsSetScreenSize(int32_t sx, int32_t sy) -{ - return tmedia_defaults_set_screen_size(sx, sy) == 0; -} - -bool MediaSessionMgr::defaultsSetAudioGain(int32_t producer_gain, int32_t consumer_gain) -{ - return tmedia_defaults_set_audio_gain(producer_gain, consumer_gain) == 0; -} - -bool MediaSessionMgr::defaultsSetAudioPtime(int32_t ptime) -{ - return tmedia_defaults_set_audio_ptime(ptime) == 0; -} -bool MediaSessionMgr::defaultsSetAudioChannels(int32_t channel_playback, int32_t channel_record) -{ - return tmedia_defaults_set_audio_channels(channel_playback, channel_record) == 0; -} - -bool MediaSessionMgr::defaultsSetRtpPortRange(uint16_t range_start, uint16_t range_stop) -{ - return tmedia_defaults_set_rtp_port_range(range_start, range_stop) == 0; -} - -bool MediaSessionMgr::defaultsSetRtpSymetricEnabled(bool enabled) -{ - return tmedia_defaults_set_rtp_symetric_enabled(enabled ? tsk_true : tsk_false) == 0; -} - -bool MediaSessionMgr::defaultsSetMediaType(twrap_media_type_t media_type) -{ - return (tmedia_defaults_set_media_type(twrap_get_native_media_type(media_type)) == 0); -} - -bool MediaSessionMgr::defaultsSetVolume(int32_t volume) -{ - return (tmedia_defaults_set_volume(volume) == 0); -} - -int32_t MediaSessionMgr::defaultsGetVolume() -{ - return tmedia_defaults_get_volume(); -} - -bool MediaSessionMgr::defaultsSetInviteSessionTimers(int32_t timeout, const char* refresher) -{ - int ret = tmedia_defaults_set_inv_session_expires(timeout); - ret &= tmedia_defaults_set_inv_session_refresher(refresher); - return (ret == 0); -} - -bool MediaSessionMgr::defaultsSetSRtpMode(tmedia_srtp_mode_t mode) -{ - return (tmedia_defaults_set_srtp_mode(mode) == 0); -} -tmedia_srtp_mode_t MediaSessionMgr::defaultsGetSRtpMode() -{ - return tmedia_defaults_get_srtp_mode(); -} - -bool MediaSessionMgr::defaultsSetSRtpType(tmedia_srtp_type_t srtp_type) -{ - return (tmedia_defaults_set_srtp_type(srtp_type) == 0); -} -tmedia_srtp_type_t MediaSessionMgr::defaultsGetSRtpType() -{ - return tmedia_defaults_get_srtp_type(); -} - -bool MediaSessionMgr::defaultsSetRtcpEnabled(bool enabled) -{ - return (tmedia_defaults_set_rtcp_enabled(enabled ? tsk_true : tsk_false) == 0); -} -bool MediaSessionMgr::defaultsGetRtcpEnabled() -{ - return (tmedia_defaults_get_rtcp_enabled() == tsk_true); -} - -bool MediaSessionMgr::defaultsSetRtcpMuxEnabled(bool enabled) -{ - return (tmedia_defaults_set_rtcpmux_enabled(enabled ? tsk_true : tsk_false) == 0); -} -bool MediaSessionMgr::defaultsGetRtcpMuxEnabled() -{ - return (tmedia_defaults_get_rtcpmux_enabled() == tsk_true); -} - - -bool MediaSessionMgr::defaultsSetStunEnabled(bool stun_enabled) -{ - return (tmedia_defaults_set_stun_enabled(stun_enabled ? tsk_true : tsk_false) == 0); -} -bool MediaSessionMgr::defaultsSetIceStunEnabled(bool icestun_enabled) -{ - return (tmedia_defaults_set_icestun_enabled(icestun_enabled ? tsk_true : tsk_false) == 0); -} -bool MediaSessionMgr::defaultsSetIceTurnEnabled(bool iceturn_enabled) -{ - return (tmedia_defaults_set_iceturn_enabled(iceturn_enabled ? tsk_true : tsk_false) == 0); -} -bool MediaSessionMgr::defaultsSetStunServer(const char* server_ip, uint16_t server_port) -{ - return (tmedia_defaults_set_stun_server(server_ip, server_port) == 0); -} -bool MediaSessionMgr::defaultsSetStunCred(const char* username, const char* password) -{ - return (tmedia_defaults_set_stun_cred(username, password) == 0); -} -bool MediaSessionMgr::defaultsSetIceEnabled(bool ice_enabled) -{ - return (tmedia_defaults_set_ice_enabled(ice_enabled ? tsk_true : tsk_false) == 0); -} - -bool MediaSessionMgr::defaultsSetByPassEncoding(bool enabled) -{ - return (tmedia_defaults_set_bypass_encoding(enabled ? tsk_true : tsk_false) == 0); -} -bool MediaSessionMgr::defaultsGetByPassEncoding() -{ - return (tmedia_defaults_get_bypass_encoding() == tsk_true); -} -bool MediaSessionMgr::defaultsSetByPassDecoding(bool enabled) -{ - return (tmedia_defaults_set_bypass_decoding(enabled ? tsk_true : tsk_false) == 0); -} -bool MediaSessionMgr::defaultsGetByPassDecoding() -{ - return (tmedia_defaults_get_bypass_decoding() == tsk_true); -} - -bool MediaSessionMgr::defaultsSetVideoJbEnabled(bool enabled) -{ - return (tmedia_defaults_set_videojb_enabled(enabled ? tsk_true : tsk_false) == 0); -} -bool MediaSessionMgr::defaultsGetVideoJbEnabled() -{ - return (tmedia_defaults_get_videojb_enabled() == tsk_true); -} - -bool MediaSessionMgr::defaultsSetVideoZeroArtifactsEnabled(bool enabled) -{ - return (tmedia_defaults_set_video_zeroartifacts_enabled(enabled ? tsk_true : tsk_false) == 0); -} -bool MediaSessionMgr::defaultsGetVideoZeroArtifactsEnabled() -{ - return (tmedia_defaults_get_video_zeroartifacts_enabled() == tsk_true); -} - -bool MediaSessionMgr::defaultsSetRtpBuffSize(unsigned buffSize) -{ - return (tmedia_defaults_set_rtpbuff_size(buffSize) == 0); -} -unsigned MediaSessionMgr::defaultsGetRtpBuffSize() -{ - return tmedia_defaults_get_rtpbuff_size(); -} - -bool MediaSessionMgr::defaultsSetAvpfTail(unsigned tail_min, unsigned tail_max) -{ - return (tmedia_defaults_set_avpf_tail(tail_min, tail_max) == 0); -} - -bool MediaSessionMgr::defaultsSetAvpfMode(enum tmedia_mode_e mode) -{ - return (tmedia_defaults_set_avpf_mode(mode) == 0); -} - -bool MediaSessionMgr::defaultsSetOpusMaxCaptureRate(uint32_t opus_maxcapturerate) -{ - return (tmedia_defaults_set_opus_maxcapturerate(opus_maxcapturerate) == 0); -} -bool MediaSessionMgr::defaultsSetOpusMaxPlaybackRate(uint32_t opus_maxplaybackrate) -{ - return (tmedia_defaults_set_opus_maxplaybackrate(opus_maxplaybackrate) == 0); -} - -bool MediaSessionMgr::defaultsSetMaxFds(int32_t max_fds) -{ - return (tmedia_defaults_set_max_fds(max_fds) == 0); +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "MediaSessionMgr.h"
+
+//
+// QoS
+//
+QoS::QoS(float qavg, float q1 /*= -1.f*/, float q2 /*= -1.f*/, float q3 /*= -1.f*/, float q4 /*= -1.f*/, float q5 /*= -1.f*/)
+ : m_Qqvg(qavg)
+ , m_VideoInWidth(0)
+ , m_VideoOutWidth(0)
+ , m_VideoInHeight(0)
+ , m_VideoOutHeight(0)
+ , m_BandwidthDownKbps(0)
+ , m_BandwidthUpKbps(0)
+ , m_VideoInAvgFps(0)
+ , m_VideoDecAvgTime(0)
+ , m_VideoEncAvgTime(0)
+{
+ m_Qn[0] = q1;
+ m_Qn[1] = q2;
+ m_Qn[2] = q3;
+ m_Qn[3] = q4;
+ m_Qn[4] = q5;
+}
+
+QoS::~QoS()
+{
+}
+
+//
+// Codec
+//
+Codec::Codec(const struct tmedia_codec_s* pWrappedCodec)
+{
+ m_pWrappedCodec = (struct tmedia_codec_s*)tsk_object_ref(TSK_OBJECT(pWrappedCodec));
+}
+
+Codec::~Codec()
+{
+ TSK_OBJECT_SAFE_FREE(m_pWrappedCodec);
+}
+
+twrap_media_type_t Codec::getMediaType()
+{
+ if(m_pWrappedCodec) {
+ switch(m_pWrappedCodec->type) {
+ case tmedia_audio:
+ return twrap_media_audio;
+ case tmedia_video:
+ return twrap_media_video;
+ case tmedia_msrp:
+ return twrap_media_msrp;
+ default:
+ break;
+ }
+ }
+ return twrap_media_none;
+}
+
+const char* Codec::getName()
+{
+ if(m_pWrappedCodec) {
+ return m_pWrappedCodec->name;
+ }
+ return tsk_null;
+}
+
+const char* Codec::getDescription()
+{
+ if(m_pWrappedCodec) {
+ return m_pWrappedCodec->desc;
+ }
+ return tsk_null;
+}
+
+const char* Codec::getNegFormat()
+{
+ if(m_pWrappedCodec) {
+ return m_pWrappedCodec->neg_format ? m_pWrappedCodec->neg_format : m_pWrappedCodec->format;
+ }
+ return tsk_null;
+}
+
+int Codec::getAudioSamplingRate()
+{
+ if(m_pWrappedCodec && m_pWrappedCodec->plugin) {
+ return m_pWrappedCodec->plugin->rate;
+ }
+ return 0;
+}
+
+int Codec::getAudioChannels()
+{
+ if(m_pWrappedCodec && (m_pWrappedCodec->type & tmedia_audio) && m_pWrappedCodec->plugin) {
+ return m_pWrappedCodec->plugin->audio.channels;
+ }
+ return 0;
+}
+
+int Codec::getAudioPTime()
+{
+ if(m_pWrappedCodec && (m_pWrappedCodec->type & tmedia_audio) && m_pWrappedCodec->plugin) {
+ return m_pWrappedCodec->plugin->audio.ptime;
+ }
+ return 0;
+}
+
+//
+// MediaSessionMgr
+//
+MediaSessionMgr::MediaSessionMgr(tmedia_session_mgr_t* pWrappedMgr)
+{
+ m_pWrappedMgr = (tmedia_session_mgr_t*)tsk_object_ref(pWrappedMgr);
+}
+
+MediaSessionMgr::~MediaSessionMgr()
+{
+ TSK_OBJECT_SAFE_FREE(m_pWrappedMgr);
+}
+
+bool MediaSessionMgr::sessionSetInt32(twrap_media_type_t media, const char* key, int32_t value)
+{
+ tmedia_type_t _media = twrap_get_native_media_type(media);
+ return (tmedia_session_mgr_set(m_pWrappedMgr,
+ TMEDIA_SESSION_SET_INT32(_media, key, value),
+ TMEDIA_SESSION_SET_NULL()) == 0);
+}
+
+int32_t MediaSessionMgr::sessionGetInt32(twrap_media_type_t media, const char* key)
+{
+ int32_t value = 0;
+ tmedia_type_t _media = twrap_get_native_media_type(media);
+ (tmedia_session_mgr_get(m_pWrappedMgr,
+ TMEDIA_SESSION_GET_INT32(_media, key, &value),
+ TMEDIA_SESSION_GET_NULL()));
+ return value;
+}
+
+QoS* MediaSessionMgr::sessionGetQoS(twrap_media_type_t media)
+{
+ tmedia_type_t _media = twrap_get_native_media_type(media);
+ tmedia_session_t* session = tmedia_session_mgr_find(m_pWrappedMgr, _media);
+ if (session) {
+ QoS* pQoS = new QoS(
+ session->qos_metrics.qvag,
+ session->qos_metrics.q1,
+ session->qos_metrics.q2,
+ session->qos_metrics.q3,
+ session->qos_metrics.q4,
+ session->qos_metrics.q5);
+ if (pQoS && ((_media & tmedia_video) || (_media & tmedia_bfcp_video))) {
+ pQoS->m_VideoInWidth = session->qos_metrics.video_in_width;
+ pQoS->m_VideoInHeight = session->qos_metrics.video_in_height;
+ pQoS->m_VideoOutWidth = session->qos_metrics.video_out_width;
+ pQoS->m_VideoOutHeight = session->qos_metrics.video_out_height;
+ pQoS->m_BandwidthDownKbps = session->qos_metrics.bw_down_est_kbps;
+ pQoS->m_BandwidthUpKbps = session->qos_metrics.bw_up_est_kbps;
+ pQoS->m_VideoInAvgFps = session->qos_metrics.video_in_avg_fps;
+ pQoS->m_VideoDecAvgTime = session->qos_metrics.video_dec_avg_time;
+ pQoS->m_VideoEncAvgTime = session->qos_metrics.video_enc_avg_time;
+ }
+ TSK_OBJECT_SAFE_FREE(session);
+ return pQoS;
+ }
+ return NULL;
+}
+
+bool MediaSessionMgr::consumerSetInt32(twrap_media_type_t media, const char* key, int32_t value)
+{
+ tmedia_type_t _media = twrap_get_native_media_type(media);
+ return (tmedia_session_mgr_set(m_pWrappedMgr,
+ TMEDIA_SESSION_CONSUMER_SET_INT32(_media, key, value),
+ TMEDIA_SESSION_SET_NULL()) == 0);
+}
+
+bool MediaSessionMgr::consumerSetInt64(twrap_media_type_t media, const char* key, int64_t value)
+{
+ tmedia_type_t _media = twrap_get_native_media_type(media);
+ return (tmedia_session_mgr_set(m_pWrappedMgr,
+ TMEDIA_SESSION_CONSUMER_SET_INT64(_media, key, value),
+ TMEDIA_SESSION_SET_NULL()) == 0);
+}
+
+bool MediaSessionMgr::producerSetInt32(twrap_media_type_t media, const char* key, int32_t value)
+{
+ tmedia_type_t _media = twrap_get_native_media_type(media);
+ return (tmedia_session_mgr_set(m_pWrappedMgr,
+ TMEDIA_SESSION_PRODUCER_SET_INT32(_media, key, value),
+ TMEDIA_SESSION_SET_NULL()) == 0);
+}
+
+bool MediaSessionMgr::producerSetInt64(twrap_media_type_t media, const char* key, int64_t value)
+{
+ tmedia_type_t _media = twrap_get_native_media_type(media);
+ return (tmedia_session_mgr_set(m_pWrappedMgr,
+ TMEDIA_SESSION_PRODUCER_SET_INT64(_media, key, value),
+ TMEDIA_SESSION_SET_NULL()) == 0);
+}
+
+Codec* MediaSessionMgr::producerGetCodec(twrap_media_type_t media)
+{
+ tmedia_codec_t* _codec = tsk_null;
+ tmedia_type_t _media = twrap_get_native_media_type(media);
+ (tmedia_session_mgr_get(m_pWrappedMgr,
+ TMEDIA_SESSION_PRODUCER_GET_POBJECT(_media, "codec", &_codec),
+ TMEDIA_SESSION_GET_NULL()));
+
+ if(_codec) {
+ Codec* pCodec = new Codec(_codec);
+ TSK_OBJECT_SAFE_FREE(_codec);
+ return pCodec;
+ }
+ return NULL;
+}
+
+#include "tinydav/audio/tdav_session_audio.h"
+#include "tinydav/video/tdav_session_video.h"
+#include "ProxyPluginMgr.h"
+
+
+const ProxyPlugin* MediaSessionMgr::findProxyPlugin(twrap_media_type_t media, bool consumer)const
+{
+ const ProxyPlugin* plugin = tsk_null;
+ ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
+
+ if(media != twrap_media_audio && media != twrap_media_video) {
+ TSK_DEBUG_ERROR("Invalid media type");
+ return tsk_null;
+ }
+
+ if(manager && m_pWrappedMgr) {
+ tmedia_type_t _media = twrap_get_native_media_type(media);
+ tmedia_session_t* session = tmedia_session_mgr_find(m_pWrappedMgr, _media);
+ if(session) {
+ if(session->plugin == tdav_session_audio_plugin_def_t) {
+ if(consumer) {
+ plugin = manager->findPlugin(TDAV_SESSION_AV(session)->consumer);
+ }
+ else {
+ plugin = manager->findPlugin(TDAV_SESSION_AV(session)->producer);
+ }
+ }
+ else if(session->plugin == tdav_session_video_plugin_def_t) {
+ if(consumer) {
+ plugin = manager->findPlugin(TDAV_SESSION_AV(session)->consumer);
+ }
+ else {
+ plugin = manager->findPlugin(TDAV_SESSION_AV(session)->producer);
+ }
+ }
+ else {
+ TSK_DEBUG_ERROR("Unknown session with media type = %d", _media);
+ }
+ tsk_object_unref(session);
+ }
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid state");
+ }
+
+ return plugin;
+}
+
+// FIXME: create generic function to register any kind and number of plugin from a file
+unsigned int MediaSessionMgr::registerAudioPluginFromFile(const char* path)
+{
+ static struct tsk_plugin_s* __plugin = tsk_null;
+ if(__plugin) {
+ TSK_DEBUG_ERROR("Audio plugin already registered");
+ return 0;
+ }
+ if((__plugin = tsk_plugin_create(path))) {
+ unsigned int count = 0;
+ tsk_plugin_def_ptr_const_t plugin_def_ptr_const;
+ if((plugin_def_ptr_const = tsk_plugin_get_def(__plugin, tsk_plugin_def_type_consumer, tsk_plugin_def_media_type_audio))) {
+ if(tmedia_consumer_plugin_register((const tmedia_consumer_plugin_def_t*)plugin_def_ptr_const) == 0) {
+ ++count;
+ }
+ }
+ if((plugin_def_ptr_const = tsk_plugin_get_def(__plugin, tsk_plugin_def_type_producer, tsk_plugin_def_media_type_audio))) {
+ if(tmedia_producer_plugin_register((const tmedia_producer_plugin_def_t*)plugin_def_ptr_const) == 0) {
+ ++count;
+ }
+ }
+ return count;
+ }
+ TSK_DEBUG_ERROR("Failed to create plugin with path=%s", path);
+ return 0;
+}
+
+uint64_t MediaSessionMgr::getSessionId(twrap_media_type_t media)const
+{
+ //const ProxyPlugin* plugin = tsk_null;
+ ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
+ uint64_t id = 0;
+
+ if (media != twrap_media_audio && media != twrap_media_video) {
+ TSK_DEBUG_ERROR("Invalid media type");
+ return 0;
+ }
+
+ if (manager && m_pWrappedMgr) {
+ tmedia_type_t _media = twrap_get_native_media_type(media);
+ tmedia_session_t* session = tmedia_session_mgr_find(m_pWrappedMgr, _media);
+ if (session) {
+ id = session->id;
+ }
+ tsk_object_unref(session);
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid state");
+ }
+
+ return id;
+}
+
+bool MediaSessionMgr::defaultsSetProfile(tmedia_profile_t profile)
+{
+ return (tmedia_defaults_set_profile(profile) == 0);
+}
+
+tmedia_profile_t MediaSessionMgr::defaultsGetProfile()
+{
+ return tmedia_defaults_get_profile();
+}
+
+bool MediaSessionMgr::defaultsSetBandwidthLevel(tmedia_bandwidth_level_t bl) // @deprecated
+{
+ return tmedia_defaults_set_bl(bl) == 0;
+}
+tmedia_bandwidth_level_t MediaSessionMgr::defaultsGetBandwidthLevel() // @deprecated
+{
+ return tmedia_defaults_get_bl();
+}
+bool MediaSessionMgr::defaultsSetCongestionCtrlEnabled(bool enabled)
+{
+ return tmedia_defaults_set_congestion_ctrl_enabled(enabled ? tsk_true : tsk_false) == 0;
+}
+bool MediaSessionMgr::defaultsSetVideoMotionRank(int32_t video_motion_rank)
+{
+ return (tmedia_defaults_set_video_motion_rank(video_motion_rank) == 0);
+}
+bool MediaSessionMgr::defaultsSetVideoFps(int32_t video_fps)
+{
+ return (tmedia_defaults_set_video_fps(video_fps) == 0);
+}
+bool MediaSessionMgr::defaultsSetBandwidthVideoUploadMax(int32_t bw_video_up_max_kbps)
+{
+ return (tmedia_defaults_set_bandwidth_video_upload_max(bw_video_up_max_kbps) == 0);
+}
+bool MediaSessionMgr::defaultsSetBandwidthVideoDownloadMax(int32_t bw_video_down_max_kbps)
+{
+ return (tmedia_defaults_set_bandwidth_video_download_max(bw_video_down_max_kbps) == 0);
+}
+
+bool MediaSessionMgr::defaultsSetPrefVideoSize(tmedia_pref_video_size_t pref_video_size)
+{
+ return tmedia_defaults_set_pref_video_size(pref_video_size) == 0;
+}
+
+bool MediaSessionMgr::defaultsSetPrefVideoSizeOutRange(tmedia_pref_video_size_t min, tmedia_pref_video_size_t max)
+{
+ return tmedia_defaults_set_pref_video_size_range(min, max) == 0;
+}
+
+bool MediaSessionMgr::defaultsSetAdaptativeVideoSizeOutEnabled(bool enabled)
+{
+ return tmedia_defaults_set_adapt_video_size_range_enabled(enabled ? tsk_true : tsk_false) == 0;
+}
+
+bool MediaSessionMgr::defaultsSetJbMargin(uint32_t jb_margin_ms)
+{
+ return tmedia_defaults_set_jb_margin(jb_margin_ms) == 0;
+}
+
+bool MediaSessionMgr::defaultsSetJbMaxLateRate(uint32_t jb_late_rate_percent)
+{
+ return tmedia_defaults_set_jb_max_late_rate(jb_late_rate_percent) == 0;
+}
+
+bool MediaSessionMgr::defaultsSetEchoTail(uint32_t echo_tail)
+{
+ return tmedia_defaults_set_echo_tail(echo_tail) == 0;
+}
+
+uint32_t MediaSessionMgr::defaultsGetEchoTail()
+{
+ return tmedia_defaults_get_echo_tail();
+}
+
+bool MediaSessionMgr::defaultsSetEchoSkew(uint32_t echo_skew)
+{
+ return tmedia_defaults_set_echo_skew(echo_skew) == 0;
+}
+
+bool MediaSessionMgr::defaultsSetEchoSuppEnabled(bool echo_supp_enabled)
+{
+ return tmedia_defaults_set_echo_supp_enabled(echo_supp_enabled ? tsk_true : tsk_false) == 0;
+}
+
+bool MediaSessionMgr::defaultsGetEchoSuppEnabled()
+{
+ return tmedia_defaults_get_echo_supp_enabled() ? true : false;
+}
+
+bool MediaSessionMgr::defaultsSetAgcEnabled(bool agc_enabled)
+{
+ return tmedia_defaults_set_agc_enabled(agc_enabled ? tsk_true : tsk_false) == 0;
+}
+
+bool MediaSessionMgr::defaultsGetAgcEnabled()
+{
+ return tmedia_defaults_get_agc_enabled() ? true : false;
+}
+
+bool MediaSessionMgr::defaultsSetAgcLevel(float agc_level)
+{
+ return tmedia_defaults_set_agc_level(agc_level) == 0;
+}
+
+float MediaSessionMgr::defaultsGetAgcLevel()
+{
+ return tmedia_defaults_get_agc_level();
+}
+
+bool MediaSessionMgr::defaultsSetVadEnabled(bool vad_enabled)
+{
+ return tmedia_defaults_set_vad_enabled(vad_enabled ? tsk_true : tsk_false) == 0;
+}
+
+bool MediaSessionMgr::defaultsGetGetVadEnabled()
+{
+ return tmedia_defaults_get_vad_enabled() ? true : false;
+}
+
+bool MediaSessionMgr::defaultsSetNoiseSuppEnabled(bool noise_supp_enabled)
+{
+ return tmedia_defaults_set_noise_supp_enabled(noise_supp_enabled ? tsk_true : tsk_false) == 0;
+}
+
+bool MediaSessionMgr::defaultsGetNoiseSuppEnabled()
+{
+ return tmedia_defaults_get_noise_supp_enabled() ? true : false;
+}
+
+bool MediaSessionMgr::defaultsSetNoiseSuppLevel(int32_t noise_supp_level)
+{
+ return tmedia_defaults_set_noise_supp_level(noise_supp_level) == 0;
+}
+
+int32_t MediaSessionMgr::defaultsGetNoiseSuppLevel()
+{
+ return tmedia_defaults_get_noise_supp_level();
+}
+
+bool MediaSessionMgr::defaultsSet100relEnabled(bool _100rel_enabled)
+{
+ return tmedia_defaults_set_100rel_enabled(_100rel_enabled ? tsk_true : tsk_false) == 0;
+}
+
+bool MediaSessionMgr::defaultsGet100relEnabled()
+{
+ return tmedia_defaults_get_100rel_enabled() == 0;
+}
+
+bool MediaSessionMgr::defaultsSetScreenSize(int32_t sx, int32_t sy)
+{
+ return tmedia_defaults_set_screen_size(sx, sy) == 0;
+}
+
+bool MediaSessionMgr::defaultsSetAudioGain(int32_t producer_gain, int32_t consumer_gain)
+{
+ return tmedia_defaults_set_audio_gain(producer_gain, consumer_gain) == 0;
+}
+
+bool MediaSessionMgr::defaultsSetAudioPtime(int32_t ptime)
+{
+ return tmedia_defaults_set_audio_ptime(ptime) == 0;
+}
+bool MediaSessionMgr::defaultsSetAudioChannels(int32_t channel_playback, int32_t channel_record)
+{
+ return tmedia_defaults_set_audio_channels(channel_playback, channel_record) == 0;
+}
+
+bool MediaSessionMgr::defaultsSetRtpPortRange(uint16_t range_start, uint16_t range_stop)
+{
+ return tmedia_defaults_set_rtp_port_range(range_start, range_stop) == 0;
+}
+
+bool MediaSessionMgr::defaultsSetRtpSymetricEnabled(bool enabled)
+{
+ return tmedia_defaults_set_rtp_symetric_enabled(enabled ? tsk_true : tsk_false) == 0;
+}
+
+bool MediaSessionMgr::defaultsSetMediaType(twrap_media_type_t media_type)
+{
+ return (tmedia_defaults_set_media_type(twrap_get_native_media_type(media_type)) == 0);
+}
+
+bool MediaSessionMgr::defaultsSetVolume(int32_t volume)
+{
+ return (tmedia_defaults_set_volume(volume) == 0);
+}
+
+int32_t MediaSessionMgr::defaultsGetVolume()
+{
+ return tmedia_defaults_get_volume();
+}
+
+bool MediaSessionMgr::defaultsSetInviteSessionTimers(int32_t timeout, const char* refresher)
+{
+ int ret = tmedia_defaults_set_inv_session_expires(timeout);
+ ret &= tmedia_defaults_set_inv_session_refresher(refresher);
+ return (ret == 0);
+}
+
+bool MediaSessionMgr::defaultsSetSRtpMode(tmedia_srtp_mode_t mode)
+{
+ return (tmedia_defaults_set_srtp_mode(mode) == 0);
+}
+tmedia_srtp_mode_t MediaSessionMgr::defaultsGetSRtpMode()
+{
+ return tmedia_defaults_get_srtp_mode();
+}
+
+bool MediaSessionMgr::defaultsSetSRtpType(tmedia_srtp_type_t srtp_type)
+{
+ return (tmedia_defaults_set_srtp_type(srtp_type) == 0);
+}
+tmedia_srtp_type_t MediaSessionMgr::defaultsGetSRtpType()
+{
+ return tmedia_defaults_get_srtp_type();
+}
+
+bool MediaSessionMgr::defaultsSetRtcpEnabled(bool enabled)
+{
+ return (tmedia_defaults_set_rtcp_enabled(enabled ? tsk_true : tsk_false) == 0);
+}
+bool MediaSessionMgr::defaultsGetRtcpEnabled()
+{
+ return (tmedia_defaults_get_rtcp_enabled() == tsk_true);
+}
+
+bool MediaSessionMgr::defaultsSetRtcpMuxEnabled(bool enabled)
+{
+ return (tmedia_defaults_set_rtcpmux_enabled(enabled ? tsk_true : tsk_false) == 0);
+}
+bool MediaSessionMgr::defaultsGetRtcpMuxEnabled()
+{
+ return (tmedia_defaults_get_rtcpmux_enabled() == tsk_true);
+}
+
+
+bool MediaSessionMgr::defaultsSetStunEnabled(bool stun_enabled)
+{
+ return (tmedia_defaults_set_stun_enabled(stun_enabled ? tsk_true : tsk_false) == 0);
+}
+bool MediaSessionMgr::defaultsSetIceStunEnabled(bool icestun_enabled)
+{
+ return (tmedia_defaults_set_icestun_enabled(icestun_enabled ? tsk_true : tsk_false) == 0);
+}
+bool MediaSessionMgr::defaultsSetIceTurnEnabled(bool iceturn_enabled)
+{
+ return (tmedia_defaults_set_iceturn_enabled(iceturn_enabled ? tsk_true : tsk_false) == 0);
+}
+bool MediaSessionMgr::defaultsSetStunServer(const char* server_ip, uint16_t server_port)
+{
+ return (tmedia_defaults_set_stun_server(server_ip, server_port) == 0);
+}
+bool MediaSessionMgr::defaultsSetStunCred(const char* username, const char* password)
+{
+ return (tmedia_defaults_set_stun_cred(username, password) == 0);
+}
+bool MediaSessionMgr::defaultsSetIceEnabled(bool ice_enabled)
+{
+ return (tmedia_defaults_set_ice_enabled(ice_enabled ? tsk_true : tsk_false) == 0);
+}
+
+bool MediaSessionMgr::defaultsSetByPassEncoding(bool enabled)
+{
+ return (tmedia_defaults_set_bypass_encoding(enabled ? tsk_true : tsk_false) == 0);
+}
+bool MediaSessionMgr::defaultsGetByPassEncoding()
+{
+ return (tmedia_defaults_get_bypass_encoding() == tsk_true);
+}
+bool MediaSessionMgr::defaultsSetByPassDecoding(bool enabled)
+{
+ return (tmedia_defaults_set_bypass_decoding(enabled ? tsk_true : tsk_false) == 0);
+}
+bool MediaSessionMgr::defaultsGetByPassDecoding()
+{
+ return (tmedia_defaults_get_bypass_decoding() == tsk_true);
+}
+
+bool MediaSessionMgr::defaultsSetVideoJbEnabled(bool enabled)
+{
+ return (tmedia_defaults_set_videojb_enabled(enabled ? tsk_true : tsk_false) == 0);
+}
+bool MediaSessionMgr::defaultsGetVideoJbEnabled()
+{
+ return (tmedia_defaults_get_videojb_enabled() == tsk_true);
+}
+
+bool MediaSessionMgr::defaultsSetVideoZeroArtifactsEnabled(bool enabled)
+{
+ return (tmedia_defaults_set_video_zeroartifacts_enabled(enabled ? tsk_true : tsk_false) == 0);
+}
+bool MediaSessionMgr::defaultsGetVideoZeroArtifactsEnabled()
+{
+ return (tmedia_defaults_get_video_zeroartifacts_enabled() == tsk_true);
+}
+
+bool MediaSessionMgr::defaultsSetRtpBuffSize(unsigned buffSize)
+{
+ return (tmedia_defaults_set_rtpbuff_size(buffSize) == 0);
+}
+unsigned MediaSessionMgr::defaultsGetRtpBuffSize()
+{
+ return tmedia_defaults_get_rtpbuff_size();
+}
+
+bool MediaSessionMgr::defaultsSetAvpfTail(unsigned tail_min, unsigned tail_max)
+{
+ return (tmedia_defaults_set_avpf_tail(tail_min, tail_max) == 0);
+}
+
+bool MediaSessionMgr::defaultsSetAvpfMode(enum tmedia_mode_e mode)
+{
+ return (tmedia_defaults_set_avpf_mode(mode) == 0);
+}
+
+bool MediaSessionMgr::defaultsSetOpusMaxCaptureRate(uint32_t opus_maxcapturerate)
+{
+ return (tmedia_defaults_set_opus_maxcapturerate(opus_maxcapturerate) == 0);
+}
+bool MediaSessionMgr::defaultsSetOpusMaxPlaybackRate(uint32_t opus_maxplaybackrate)
+{
+ return (tmedia_defaults_set_opus_maxplaybackrate(opus_maxplaybackrate) == 0);
+}
+
+bool MediaSessionMgr::defaultsSetMaxFds(int32_t max_fds)
+{
+ return (tmedia_defaults_set_max_fds(max_fds) == 0);
}
\ No newline at end of file diff --git a/bindings/_common/MediaSessionMgr.h b/bindings/_common/MediaSessionMgr.h index c4f52be..ee7869b 100755 --- a/bindings/_common/MediaSessionMgr.h +++ b/bindings/_common/MediaSessionMgr.h @@ -1,246 +1,246 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_MEDIA_SESSIONMGR_H -#define TINYWRAP_MEDIA_SESSIONMGR_H - -#include "tinyWRAP_config.h" - -#include "tinymedia.h" -#include "Common.h" - -class ProxyPlugin; -class MediaSessionMgr; - -class TINYWRAP_API QoS -{ - friend class MediaSessionMgr; -public: -#if !defined(SWIG) - QoS(float qavg, float q1 = -1.f, float q2 = -1.f, float q3 = -1.f, float q4 = -1.f, float q5 = -1.f); -#endif - virtual ~QoS(); - float getQavg() { - return m_Qqvg; - } - float getQ1() { - return m_Qn[0]; - } - float getQ2() { - return m_Qn[1]; - } - float getQ3() { - return m_Qn[2]; - } - float getQ4() { - return m_Qn[3]; - } - float getQ5() { - return m_Qn[4]; - } - unsigned getVideoInWidth() { - return m_VideoInWidth; - } - unsigned getVideoOutWidth() { - return m_VideoOutWidth; - } - unsigned getVideoInHeight() { - return m_VideoInHeight; - } - unsigned getVideoOutHeight() { - return m_VideoOutHeight; - } - unsigned getBandwidthDownKbps() { - return m_BandwidthDownKbps; - } - unsigned getBandwidthUpKbps() { - return m_BandwidthUpKbps; - } - unsigned getVideoInAvgFps() { - return m_VideoInAvgFps; - } - unsigned getVideoDecAvgTime() { // In millis - return m_VideoDecAvgTime; - } - unsigned getVideoEncAvgTime() { // In millis - return m_VideoEncAvgTime; - } -private: - float m_Qqvg; - float m_Qn[5]; - unsigned m_VideoInWidth; - unsigned m_VideoOutWidth; - unsigned m_VideoInHeight; - unsigned m_VideoOutHeight; - unsigned m_BandwidthDownKbps; - unsigned m_BandwidthUpKbps; - unsigned m_VideoInAvgFps; - unsigned m_VideoDecAvgTime; - unsigned m_VideoEncAvgTime; -}; - -class TINYWRAP_API Codec -{ -public: -#if !defined(SWIG) - Codec(const struct tmedia_codec_s* pWrappedCodec); -#endif - virtual ~Codec(); - -public: -#if !defined(SWIG) - const struct tmedia_codec_s* getWrappedCodec() { - return m_pWrappedCodec; - } - inline bool isOpened() { - return (m_pWrappedCodec && (m_pWrappedCodec->opened == tsk_true)); - } -#endif - twrap_media_type_t getMediaType(); - const char* getName(); - const char* getDescription(); - const char* getNegFormat(); - int getAudioSamplingRate(); - int getAudioChannels(); - int getAudioPTime(); - -private: - struct tmedia_codec_s* m_pWrappedCodec; -}; - -class TINYWRAP_API MediaSessionMgr -{ -public: -#if !defined(SWIG) - MediaSessionMgr(tmedia_session_mgr_t* pWrappedMgr); -#endif - virtual ~MediaSessionMgr(); - -public: - bool sessionSetInt32(twrap_media_type_t media, const char* key, int32_t value); - int32_t sessionGetInt32(twrap_media_type_t media, const char* key); - QoS* sessionGetQoS(twrap_media_type_t media); - - bool consumerSetInt32(twrap_media_type_t media, const char* key, int32_t value); - bool consumerSetInt64(twrap_media_type_t media, const char* key, int64_t value); - - bool producerSetInt32(twrap_media_type_t media, const char* key, int32_t value); - bool producerSetInt64(twrap_media_type_t media, const char* key, int64_t value); - Codec* producerGetCodec(twrap_media_type_t media); - -#if !defined(SWIG) - const ProxyPlugin* findProxyPlugin(twrap_media_type_t media, bool consumer)const; -#endif - - const ProxyPlugin* findProxyPluginConsumer(twrap_media_type_t media)const { - return this->findProxyPlugin(media, true); - } - const ProxyPlugin* findProxyPluginProducer(twrap_media_type_t media)const { - return this->findProxyPlugin(media, false); - } - - static unsigned int registerAudioPluginFromFile(const char* path); - - uint64_t getSessionId(twrap_media_type_t media)const; - -#if !defined(SWIG) - inline const tmedia_session_mgr_t* getWrappedMgr()const { - return m_pWrappedMgr; - } -#endif - - // Defaults - static bool defaultsSetProfile(tmedia_profile_t profile); - static tmedia_profile_t defaultsGetProfile(); - static bool defaultsSetBandwidthLevel(tmedia_bandwidth_level_t bl); // @deprecated - static tmedia_bandwidth_level_t defaultsGetBandwidthLevel(); // @deprecated - static bool defaultsSetCongestionCtrlEnabled(bool enabled); - static bool defaultsSetVideoMotionRank(int32_t video_motion_rank); - static bool defaultsSetVideoFps(int32_t video_fps); - static bool defaultsSetBandwidthVideoUploadMax(int32_t bw_video_up_max_kbps); - static bool defaultsSetBandwidthVideoDownloadMax(int32_t bw_video_down_max_kbps); - static bool defaultsSetPrefVideoSize(tmedia_pref_video_size_t pref_video_size); - static bool defaultsSetPrefVideoSizeOutRange(tmedia_pref_video_size_t min, tmedia_pref_video_size_t max); - static bool defaultsSetAdaptativeVideoSizeOutEnabled(bool enabled); - static bool defaultsSetJbMargin(uint32_t jb_margin_ms); - static bool defaultsSetJbMaxLateRate(uint32_t jb_late_rate_percent); - static bool defaultsSetEchoTail(uint32_t echo_tail); - static uint32_t defaultsGetEchoTail(); - static bool defaultsSetEchoSkew(uint32_t echo_skew); - static bool defaultsSetEchoSuppEnabled(bool echo_supp_enabled); - static bool defaultsGetEchoSuppEnabled(); - static bool defaultsSetAgcEnabled(bool agc_enabled); - static bool defaultsGetAgcEnabled(); - static bool defaultsSetAgcLevel(float agc_level); - static float defaultsGetAgcLevel(); - static bool defaultsSetVadEnabled(bool vad_enabled); - static bool defaultsGetGetVadEnabled(); - static bool defaultsSetNoiseSuppEnabled(bool noise_supp_enabled); - static bool defaultsGetNoiseSuppEnabled(); - static bool defaultsSetNoiseSuppLevel(int32_t noise_supp_level); - static int32_t defaultsGetNoiseSuppLevel(); - static bool defaultsSet100relEnabled(bool _100rel_enabled); - static bool defaultsGet100relEnabled(); - static bool defaultsSetScreenSize(int32_t sx, int32_t sy); - static bool defaultsSetAudioGain(int32_t producer_gain, int32_t consumer_gain); - static bool defaultsSetAudioPtime(int32_t ptime); - static bool defaultsSetAudioChannels(int32_t channel_playback, int32_t channel_record); - static bool defaultsSetRtpPortRange(uint16_t range_start, uint16_t range_stop); - static bool defaultsSetRtpSymetricEnabled(bool enabled); - static bool defaultsSetMediaType(twrap_media_type_t media_type); - static bool defaultsSetVolume(int32_t volume); - static int32_t defaultsGetVolume(); - static bool defaultsSetInviteSessionTimers(int32_t timeout, const char* refresher); - static bool defaultsSetSRtpMode(tmedia_srtp_mode_t mode); - static tmedia_srtp_mode_t defaultsGetSRtpMode(); - static bool defaultsSetSRtpType(tmedia_srtp_type_t srtp_type); - static tmedia_srtp_type_t defaultsGetSRtpType(); - static bool defaultsSetRtcpEnabled(bool enabled); - static bool defaultsGetRtcpEnabled(); - static bool defaultsSetRtcpMuxEnabled(bool enabled); - static bool defaultsGetRtcpMuxEnabled(); - static bool defaultsSetStunEnabled(bool stun_enabled); - static bool defaultsSetIceStunEnabled(bool icestun_enabled); - static bool defaultsSetIceTurnEnabled(bool iceturn_enabled); - static bool defaultsSetStunServer(const char* server_ip, uint16_t server_port); - static bool defaultsSetStunCred(const char* username, const char* password); - static bool defaultsSetIceEnabled(bool ice_enabled); - static bool defaultsSetByPassEncoding(bool enabled); - static bool defaultsGetByPassEncoding(); - static bool defaultsSetByPassDecoding(bool enabled); - static bool defaultsGetByPassDecoding(); - static bool defaultsSetVideoJbEnabled(bool enabled); - static bool defaultsGetVideoJbEnabled(); - static bool defaultsSetVideoZeroArtifactsEnabled(bool enabled); - static bool defaultsGetVideoZeroArtifactsEnabled(); - static bool defaultsSetRtpBuffSize(unsigned buffSize); - static unsigned defaultsGetRtpBuffSize(); - static bool defaultsSetAvpfTail(unsigned tail_min, unsigned tail_max); - static bool defaultsSetAvpfMode(enum tmedia_mode_e mode); - static bool defaultsSetOpusMaxCaptureRate(uint32_t opus_maxcapturerate); - static bool defaultsSetOpusMaxPlaybackRate(uint32_t opus_maxplaybackrate); - static bool defaultsSetMaxFds(int32_t max_fds); - -private: - tmedia_session_mgr_t* m_pWrappedMgr; -}; - -#endif /* TINYWRAP_MEDIA_SESSIONMGR_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_MEDIA_SESSIONMGR_H
+#define TINYWRAP_MEDIA_SESSIONMGR_H
+
+#include "tinyWRAP_config.h"
+
+#include "tinymedia.h"
+#include "Common.h"
+
+class ProxyPlugin;
+class MediaSessionMgr;
+
+class TINYWRAP_API QoS
+{
+ friend class MediaSessionMgr;
+public:
+#if !defined(SWIG)
+ QoS(float qavg, float q1 = -1.f, float q2 = -1.f, float q3 = -1.f, float q4 = -1.f, float q5 = -1.f);
+#endif
+ virtual ~QoS();
+ float getQavg() {
+ return m_Qqvg;
+ }
+ float getQ1() {
+ return m_Qn[0];
+ }
+ float getQ2() {
+ return m_Qn[1];
+ }
+ float getQ3() {
+ return m_Qn[2];
+ }
+ float getQ4() {
+ return m_Qn[3];
+ }
+ float getQ5() {
+ return m_Qn[4];
+ }
+ unsigned getVideoInWidth() {
+ return m_VideoInWidth;
+ }
+ unsigned getVideoOutWidth() {
+ return m_VideoOutWidth;
+ }
+ unsigned getVideoInHeight() {
+ return m_VideoInHeight;
+ }
+ unsigned getVideoOutHeight() {
+ return m_VideoOutHeight;
+ }
+ unsigned getBandwidthDownKbps() {
+ return m_BandwidthDownKbps;
+ }
+ unsigned getBandwidthUpKbps() {
+ return m_BandwidthUpKbps;
+ }
+ unsigned getVideoInAvgFps() {
+ return m_VideoInAvgFps;
+ }
+ unsigned getVideoDecAvgTime() { // In millis
+ return m_VideoDecAvgTime;
+ }
+ unsigned getVideoEncAvgTime() { // In millis
+ return m_VideoEncAvgTime;
+ }
+private:
+ float m_Qqvg;
+ float m_Qn[5];
+ unsigned m_VideoInWidth;
+ unsigned m_VideoOutWidth;
+ unsigned m_VideoInHeight;
+ unsigned m_VideoOutHeight;
+ unsigned m_BandwidthDownKbps;
+ unsigned m_BandwidthUpKbps;
+ unsigned m_VideoInAvgFps;
+ unsigned m_VideoDecAvgTime;
+ unsigned m_VideoEncAvgTime;
+};
+
+class TINYWRAP_API Codec
+{
+public:
+#if !defined(SWIG)
+ Codec(const struct tmedia_codec_s* pWrappedCodec);
+#endif
+ virtual ~Codec();
+
+public:
+#if !defined(SWIG)
+ const struct tmedia_codec_s* getWrappedCodec() {
+ return m_pWrappedCodec;
+ }
+ inline bool isOpened() {
+ return (m_pWrappedCodec && (m_pWrappedCodec->opened == tsk_true));
+ }
+#endif
+ twrap_media_type_t getMediaType();
+ const char* getName();
+ const char* getDescription();
+ const char* getNegFormat();
+ int getAudioSamplingRate();
+ int getAudioChannels();
+ int getAudioPTime();
+
+private:
+ struct tmedia_codec_s* m_pWrappedCodec;
+};
+
+class TINYWRAP_API MediaSessionMgr
+{
+public:
+#if !defined(SWIG)
+ MediaSessionMgr(tmedia_session_mgr_t* pWrappedMgr);
+#endif
+ virtual ~MediaSessionMgr();
+
+public:
+ bool sessionSetInt32(twrap_media_type_t media, const char* key, int32_t value);
+ int32_t sessionGetInt32(twrap_media_type_t media, const char* key);
+ QoS* sessionGetQoS(twrap_media_type_t media);
+
+ bool consumerSetInt32(twrap_media_type_t media, const char* key, int32_t value);
+ bool consumerSetInt64(twrap_media_type_t media, const char* key, int64_t value);
+
+ bool producerSetInt32(twrap_media_type_t media, const char* key, int32_t value);
+ bool producerSetInt64(twrap_media_type_t media, const char* key, int64_t value);
+ Codec* producerGetCodec(twrap_media_type_t media);
+
+#if !defined(SWIG)
+ const ProxyPlugin* findProxyPlugin(twrap_media_type_t media, bool consumer)const;
+#endif
+
+ const ProxyPlugin* findProxyPluginConsumer(twrap_media_type_t media)const {
+ return this->findProxyPlugin(media, true);
+ }
+ const ProxyPlugin* findProxyPluginProducer(twrap_media_type_t media)const {
+ return this->findProxyPlugin(media, false);
+ }
+
+ static unsigned int registerAudioPluginFromFile(const char* path);
+
+ uint64_t getSessionId(twrap_media_type_t media)const;
+
+#if !defined(SWIG)
+ inline const tmedia_session_mgr_t* getWrappedMgr()const {
+ return m_pWrappedMgr;
+ }
+#endif
+
+ // Defaults
+ static bool defaultsSetProfile(tmedia_profile_t profile);
+ static tmedia_profile_t defaultsGetProfile();
+ static bool defaultsSetBandwidthLevel(tmedia_bandwidth_level_t bl); // @deprecated
+ static tmedia_bandwidth_level_t defaultsGetBandwidthLevel(); // @deprecated
+ static bool defaultsSetCongestionCtrlEnabled(bool enabled);
+ static bool defaultsSetVideoMotionRank(int32_t video_motion_rank);
+ static bool defaultsSetVideoFps(int32_t video_fps);
+ static bool defaultsSetBandwidthVideoUploadMax(int32_t bw_video_up_max_kbps);
+ static bool defaultsSetBandwidthVideoDownloadMax(int32_t bw_video_down_max_kbps);
+ static bool defaultsSetPrefVideoSize(tmedia_pref_video_size_t pref_video_size);
+ static bool defaultsSetPrefVideoSizeOutRange(tmedia_pref_video_size_t min, tmedia_pref_video_size_t max);
+ static bool defaultsSetAdaptativeVideoSizeOutEnabled(bool enabled);
+ static bool defaultsSetJbMargin(uint32_t jb_margin_ms);
+ static bool defaultsSetJbMaxLateRate(uint32_t jb_late_rate_percent);
+ static bool defaultsSetEchoTail(uint32_t echo_tail);
+ static uint32_t defaultsGetEchoTail();
+ static bool defaultsSetEchoSkew(uint32_t echo_skew);
+ static bool defaultsSetEchoSuppEnabled(bool echo_supp_enabled);
+ static bool defaultsGetEchoSuppEnabled();
+ static bool defaultsSetAgcEnabled(bool agc_enabled);
+ static bool defaultsGetAgcEnabled();
+ static bool defaultsSetAgcLevel(float agc_level);
+ static float defaultsGetAgcLevel();
+ static bool defaultsSetVadEnabled(bool vad_enabled);
+ static bool defaultsGetGetVadEnabled();
+ static bool defaultsSetNoiseSuppEnabled(bool noise_supp_enabled);
+ static bool defaultsGetNoiseSuppEnabled();
+ static bool defaultsSetNoiseSuppLevel(int32_t noise_supp_level);
+ static int32_t defaultsGetNoiseSuppLevel();
+ static bool defaultsSet100relEnabled(bool _100rel_enabled);
+ static bool defaultsGet100relEnabled();
+ static bool defaultsSetScreenSize(int32_t sx, int32_t sy);
+ static bool defaultsSetAudioGain(int32_t producer_gain, int32_t consumer_gain);
+ static bool defaultsSetAudioPtime(int32_t ptime);
+ static bool defaultsSetAudioChannels(int32_t channel_playback, int32_t channel_record);
+ static bool defaultsSetRtpPortRange(uint16_t range_start, uint16_t range_stop);
+ static bool defaultsSetRtpSymetricEnabled(bool enabled);
+ static bool defaultsSetMediaType(twrap_media_type_t media_type);
+ static bool defaultsSetVolume(int32_t volume);
+ static int32_t defaultsGetVolume();
+ static bool defaultsSetInviteSessionTimers(int32_t timeout, const char* refresher);
+ static bool defaultsSetSRtpMode(tmedia_srtp_mode_t mode);
+ static tmedia_srtp_mode_t defaultsGetSRtpMode();
+ static bool defaultsSetSRtpType(tmedia_srtp_type_t srtp_type);
+ static tmedia_srtp_type_t defaultsGetSRtpType();
+ static bool defaultsSetRtcpEnabled(bool enabled);
+ static bool defaultsGetRtcpEnabled();
+ static bool defaultsSetRtcpMuxEnabled(bool enabled);
+ static bool defaultsGetRtcpMuxEnabled();
+ static bool defaultsSetStunEnabled(bool stun_enabled);
+ static bool defaultsSetIceStunEnabled(bool icestun_enabled);
+ static bool defaultsSetIceTurnEnabled(bool iceturn_enabled);
+ static bool defaultsSetStunServer(const char* server_ip, uint16_t server_port);
+ static bool defaultsSetStunCred(const char* username, const char* password);
+ static bool defaultsSetIceEnabled(bool ice_enabled);
+ static bool defaultsSetByPassEncoding(bool enabled);
+ static bool defaultsGetByPassEncoding();
+ static bool defaultsSetByPassDecoding(bool enabled);
+ static bool defaultsGetByPassDecoding();
+ static bool defaultsSetVideoJbEnabled(bool enabled);
+ static bool defaultsGetVideoJbEnabled();
+ static bool defaultsSetVideoZeroArtifactsEnabled(bool enabled);
+ static bool defaultsGetVideoZeroArtifactsEnabled();
+ static bool defaultsSetRtpBuffSize(unsigned buffSize);
+ static unsigned defaultsGetRtpBuffSize();
+ static bool defaultsSetAvpfTail(unsigned tail_min, unsigned tail_max);
+ static bool defaultsSetAvpfMode(enum tmedia_mode_e mode);
+ static bool defaultsSetOpusMaxCaptureRate(uint32_t opus_maxcapturerate);
+ static bool defaultsSetOpusMaxPlaybackRate(uint32_t opus_maxplaybackrate);
+ static bool defaultsSetMaxFds(int32_t max_fds);
+
+private:
+ tmedia_session_mgr_t* m_pWrappedMgr;
+};
+
+#endif /* TINYWRAP_MEDIA_SESSIONMGR_H */
diff --git a/bindings/_common/Msrp.cxx b/bindings/_common/Msrp.cxx index edb25d3..743be04 100755 --- a/bindings/_common/Msrp.cxx +++ b/bindings/_common/Msrp.cxx @@ -1,315 +1,315 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "Msrp.h" - -#include "SipSession.h" -#include "Common.h" - -/* ======================== MsrpMessage ========================*/ -MsrpMessage::MsrpMessage() - :m_pMessage(tsk_null) -{ -} - -MsrpMessage::MsrpMessage(tmsrp_message_t *_message) -{ - m_pMessage = (tmsrp_message_t *)tsk_object_ref(_message); -} - -MsrpMessage::~MsrpMessage() -{ - TSK_OBJECT_SAFE_FREE(m_pMessage); -} - -bool MsrpMessage::isRequest() -{ - return (m_pMessage->type == tmsrp_request); -} - -short MsrpMessage::getCode() -{ - return TMSRP_RESPONSE_CODE(m_pMessage); -} - -const char* MsrpMessage::getPhrase() -{ - return TMSRP_RESPONSE_PHRASE(m_pMessage); -} - -tmsrp_request_type_t MsrpMessage::getRequestType() -{ - if(TMSRP_MESSAGE_IS_REQUEST(m_pMessage)) { - return m_pMessage->line.request.type; - } - return tmsrp_NONE; -} - -void MsrpMessage::getByteRange(int64_t* start, int64_t* end, int64_t* total) -{ - if(m_pMessage->ByteRange) { - *start = m_pMessage->ByteRange->start; - *end = m_pMessage->ByteRange->end; - *total = m_pMessage->ByteRange->total; - } - else { - *start = *end = *total = -1; - } -} - -bool MsrpMessage::isLastChunck() -{ - if(TMSRP_MESSAGE_IS_REQUEST(m_pMessage)) { - return (m_pMessage->end_line.cflag == '$'); - } - else { - if(m_pMessage->ByteRange) { - return (m_pMessage->ByteRange->end >= m_pMessage->ByteRange->total); - } - } - return false; -} - -bool MsrpMessage::isSuccessReport() -{ - if(TMSRP_REQUEST_IS_REPORT(m_pMessage)) { - if(m_pMessage->Status) { - return m_pMessage->Status->code >= 200 && m_pMessage->Status->code <= 299; - } - } - return false; -} - -bool MsrpMessage::isFirstChunck() -{ - return (m_pMessage && m_pMessage->ByteRange->start == 1); -} - -char* MsrpMessage::getMsrpHeaderValue(const char* name) -{ - const tmsrp_header_t* header = this->getMsrpHeader(name, 0); - if(header) { - return tmsrp_header_tostring(header); - } - return tsk_null; -} - -char* MsrpMessage::getMsrpHeaderParamValue(const char* name, const char* param) -{ - return tsk_null; -} - -unsigned MsrpMessage::getMsrpContentLength() -{ - if(m_pMessage && - m_pMessage->Content && - m_pMessage->Content->data && - m_pMessage->Content->size) { - return m_pMessage->Content->size; - } - return 0; -} - -unsigned MsrpMessage::getMsrpContent(void* output, unsigned maxsize) -{ - unsigned retsize = 0; - if(!output || - !m_pMessage || - !m_pMessage->Content || - !m_pMessage->Content->data || - !m_pMessage->Content->size) { - return 0; - } - - - retsize = (m_pMessage->Content->size > maxsize) ? maxsize : m_pMessage->Content->size; - memcpy(output, m_pMessage->Content->data, retsize); - return retsize; -} - -const tmsrp_header_t* MsrpMessage::getMsrpHeader(const char* name, unsigned index /*= 0*/) -{ - tsk_size_t pos = 0; - const tmsrp_header_t* hdr = tsk_null; - const tsk_list_item_t *item; - - /* From tmsrp_message_get_headerAt() */ - if(!m_pMessage || !name) { - return tsk_null; - } - - if(tsk_striequals(name, "To-Path")) { - if(index == 0) { - hdr = (const tmsrp_header_t*)m_pMessage->To; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "From-Path")) { - if(index == 0) { - hdr = (const tmsrp_header_t*)m_pMessage->From; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "Message-ID")) { - if(index == 0) { - hdr = (const tmsrp_header_t*)m_pMessage->MessageID; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "Byte-Range")) { - if(index == 0) { - hdr = (const tmsrp_header_t*)m_pMessage->ByteRange; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "Failure-Report")) { - if(index == 0) { - hdr = (const tmsrp_header_t*)m_pMessage->FailureReport; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "Success-Report")) { - if(index == 0) { - hdr = (const tmsrp_header_t*)m_pMessage->SuccessReport; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "Status")) { - if(index == 0) { - hdr = (const tmsrp_header_t*)m_pMessage->Status; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "Content-Type")) { - if(index == 0) { - hdr = (const tmsrp_header_t*)m_pMessage->ContentType; - goto bail; - } - else { - pos++; - } - } - - - /* All other headers */ - tsk_list_foreach(item, m_pMessage->headers) { - if(tsk_striequals(tmsrp_header_get_nameex(TMSRP_HEADER(item->data)), name)) { - if(pos++ >= index) { - hdr = (const tmsrp_header_t*)item->data; - break; - } - } - } - - -bail: - return hdr; - -} - - - -/* ======================== MsrpEvent ========================*/ -MsrpEvent::MsrpEvent(const tmsrp_event_t *_msrpevent) -{ - this->_event = _msrpevent; - if(this->_event && this->_event->message) { - m_pMessage = new MsrpMessage((tmsrp_message_t *)this->_event->message); - } - else { - m_pMessage = tsk_null; - } -} - -MsrpEvent::~MsrpEvent() -{ - if(m_pMessage) { - delete m_pMessage; - } -} - -tmsrp_event_type_t MsrpEvent::getType() -{ - if(this->_event) { - return this->_event->type; - } - return tmsrp_event_type_none; -} - -const MsrpSession* MsrpEvent::getSipSession() -{ - if(this->_event && this->_event->callback_data) { - return dyn_cast<const MsrpSession*>((const MsrpSession*)this->_event->callback_data); - } - return tsk_null; -} - -const MsrpMessage* MsrpEvent::getMessage() const -{ - return m_pMessage; -} - - - - -int twrap_msrp_cb(const tmsrp_event_t* _event) -{ - const MsrpSession* session = (const MsrpSession*)_event->callback_data; - MsrpCallback* callback; - int ret = -1; - - if(session) { - if((callback = session->getCallback())) { - MsrpEvent* e = new MsrpEvent(_event); - ret = callback->OnEvent(e); - delete e; - } - else { - return 0; - } - } - else { - TSK_DEBUG_ERROR("Invalid parameter"); - } - - return ret; +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "Msrp.h"
+
+#include "SipSession.h"
+#include "Common.h"
+
+/* ======================== MsrpMessage ========================*/
+MsrpMessage::MsrpMessage()
+ :m_pMessage(tsk_null)
+{
+}
+
+MsrpMessage::MsrpMessage(tmsrp_message_t *_message)
+{
+ m_pMessage = (tmsrp_message_t *)tsk_object_ref(_message);
+}
+
+MsrpMessage::~MsrpMessage()
+{
+ TSK_OBJECT_SAFE_FREE(m_pMessage);
+}
+
+bool MsrpMessage::isRequest()
+{
+ return (m_pMessage->type == tmsrp_request);
+}
+
+short MsrpMessage::getCode()
+{
+ return TMSRP_RESPONSE_CODE(m_pMessage);
+}
+
+const char* MsrpMessage::getPhrase()
+{
+ return TMSRP_RESPONSE_PHRASE(m_pMessage);
+}
+
+tmsrp_request_type_t MsrpMessage::getRequestType()
+{
+ if(TMSRP_MESSAGE_IS_REQUEST(m_pMessage)) {
+ return m_pMessage->line.request.type;
+ }
+ return tmsrp_NONE;
+}
+
+void MsrpMessage::getByteRange(int64_t* start, int64_t* end, int64_t* total)
+{
+ if(m_pMessage->ByteRange) {
+ *start = m_pMessage->ByteRange->start;
+ *end = m_pMessage->ByteRange->end;
+ *total = m_pMessage->ByteRange->total;
+ }
+ else {
+ *start = *end = *total = -1;
+ }
+}
+
+bool MsrpMessage::isLastChunck()
+{
+ if(TMSRP_MESSAGE_IS_REQUEST(m_pMessage)) {
+ return (m_pMessage->end_line.cflag == '$');
+ }
+ else {
+ if(m_pMessage->ByteRange) {
+ return (m_pMessage->ByteRange->end >= m_pMessage->ByteRange->total);
+ }
+ }
+ return false;
+}
+
+bool MsrpMessage::isSuccessReport()
+{
+ if(TMSRP_REQUEST_IS_REPORT(m_pMessage)) {
+ if(m_pMessage->Status) {
+ return m_pMessage->Status->code >= 200 && m_pMessage->Status->code <= 299;
+ }
+ }
+ return false;
+}
+
+bool MsrpMessage::isFirstChunck()
+{
+ return (m_pMessage && m_pMessage->ByteRange->start == 1);
+}
+
+char* MsrpMessage::getMsrpHeaderValue(const char* name)
+{
+ const tmsrp_header_t* header = this->getMsrpHeader(name, 0);
+ if(header) {
+ return tmsrp_header_tostring(header);
+ }
+ return tsk_null;
+}
+
+char* MsrpMessage::getMsrpHeaderParamValue(const char* name, const char* param)
+{
+ return tsk_null;
+}
+
+unsigned MsrpMessage::getMsrpContentLength()
+{
+ if(m_pMessage &&
+ m_pMessage->Content &&
+ m_pMessage->Content->data &&
+ m_pMessage->Content->size) {
+ return m_pMessage->Content->size;
+ }
+ return 0;
+}
+
+unsigned MsrpMessage::getMsrpContent(void* output, unsigned maxsize)
+{
+ unsigned retsize = 0;
+ if(!output ||
+ !m_pMessage ||
+ !m_pMessage->Content ||
+ !m_pMessage->Content->data ||
+ !m_pMessage->Content->size) {
+ return 0;
+ }
+
+
+ retsize = (m_pMessage->Content->size > maxsize) ? maxsize : m_pMessage->Content->size;
+ memcpy(output, m_pMessage->Content->data, retsize);
+ return retsize;
+}
+
+const tmsrp_header_t* MsrpMessage::getMsrpHeader(const char* name, unsigned index /*= 0*/)
+{
+ tsk_size_t pos = 0;
+ const tmsrp_header_t* hdr = tsk_null;
+ const tsk_list_item_t *item;
+
+ /* From tmsrp_message_get_headerAt() */
+ if(!m_pMessage || !name) {
+ return tsk_null;
+ }
+
+ if(tsk_striequals(name, "To-Path")) {
+ if(index == 0) {
+ hdr = (const tmsrp_header_t*)m_pMessage->To;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "From-Path")) {
+ if(index == 0) {
+ hdr = (const tmsrp_header_t*)m_pMessage->From;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "Message-ID")) {
+ if(index == 0) {
+ hdr = (const tmsrp_header_t*)m_pMessage->MessageID;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "Byte-Range")) {
+ if(index == 0) {
+ hdr = (const tmsrp_header_t*)m_pMessage->ByteRange;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "Failure-Report")) {
+ if(index == 0) {
+ hdr = (const tmsrp_header_t*)m_pMessage->FailureReport;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "Success-Report")) {
+ if(index == 0) {
+ hdr = (const tmsrp_header_t*)m_pMessage->SuccessReport;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "Status")) {
+ if(index == 0) {
+ hdr = (const tmsrp_header_t*)m_pMessage->Status;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "Content-Type")) {
+ if(index == 0) {
+ hdr = (const tmsrp_header_t*)m_pMessage->ContentType;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+
+
+ /* All other headers */
+ tsk_list_foreach(item, m_pMessage->headers) {
+ if(tsk_striequals(tmsrp_header_get_nameex(TMSRP_HEADER(item->data)), name)) {
+ if(pos++ >= index) {
+ hdr = (const tmsrp_header_t*)item->data;
+ break;
+ }
+ }
+ }
+
+
+bail:
+ return hdr;
+
+}
+
+
+
+/* ======================== MsrpEvent ========================*/
+MsrpEvent::MsrpEvent(const tmsrp_event_t *_msrpevent)
+{
+ this->_event = _msrpevent;
+ if(this->_event && this->_event->message) {
+ m_pMessage = new MsrpMessage((tmsrp_message_t *)this->_event->message);
+ }
+ else {
+ m_pMessage = tsk_null;
+ }
+}
+
+MsrpEvent::~MsrpEvent()
+{
+ if(m_pMessage) {
+ delete m_pMessage;
+ }
+}
+
+tmsrp_event_type_t MsrpEvent::getType()
+{
+ if(this->_event) {
+ return this->_event->type;
+ }
+ return tmsrp_event_type_none;
+}
+
+const MsrpSession* MsrpEvent::getSipSession()
+{
+ if(this->_event && this->_event->callback_data) {
+ return dyn_cast<const MsrpSession*>((const MsrpSession*)this->_event->callback_data);
+ }
+ return tsk_null;
+}
+
+const MsrpMessage* MsrpEvent::getMessage() const
+{
+ return m_pMessage;
+}
+
+
+
+
+int twrap_msrp_cb(const tmsrp_event_t* _event)
+{
+ const MsrpSession* session = (const MsrpSession*)_event->callback_data;
+ MsrpCallback* callback;
+ int ret = -1;
+
+ if(session) {
+ if((callback = session->getCallback())) {
+ MsrpEvent* e = new MsrpEvent(_event);
+ ret = callback->OnEvent(e);
+ delete e;
+ }
+ else {
+ return 0;
+ }
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ }
+
+ return ret;
}
\ No newline at end of file diff --git a/bindings/_common/Msrp.h b/bindings/_common/Msrp.h index 330860b..cd6f808 100755 --- a/bindings/_common/Msrp.h +++ b/bindings/_common/Msrp.h @@ -1,101 +1,101 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_MSRP_H -#define TINYWRAP_MSRP_H - -#include "tinyWRAP_config.h" - -#include "tinymsrp.h" - -class MsrpSession; - -class TINYWRAP_API MsrpMessage -{ -public: - MsrpMessage(); -#if !defined(SWIG) - MsrpMessage(tmsrp_message_t *message); -#endif - virtual ~MsrpMessage(); - - bool isRequest(); - short getCode(); - const char* getPhrase(); - tmsrp_request_type_t getRequestType(); -#if defined(SWIG) - void getByteRange(int64_t* OUTPUT, int64_t* OUTPUT, int64_t* OUTPUT); -#else - void getByteRange(int64_t* start, int64_t* end, int64_t* total); -#endif - bool isLastChunck(); - bool isFirstChunck(); - bool isSuccessReport(); - char* getMsrpHeaderValue(const char* name); - char* getMsrpHeaderParamValue(const char* name, const char* param); - unsigned getMsrpContentLength(); - unsigned getMsrpContent(void* output, unsigned maxsize); -#if !defined(SWIG) - const tmsrp_message_t* getWrappedMsrpMessage() { - return m_pMessage; - } -#endif - -private: - const tmsrp_header_t* getMsrpHeader(const char* name, unsigned index = 0); - -private: - tmsrp_message_t *m_pMessage; -}; - -class TINYWRAP_API MsrpEvent -{ -public: -#if !defined(SWIG) - MsrpEvent(const tmsrp_event_t *_event); -#endif - virtual ~MsrpEvent(); - - tmsrp_event_type_t getType(); - const MsrpSession* getSipSession(); - const MsrpMessage* getMessage() const; - -protected: - const tmsrp_event_t *_event; - MsrpMessage* m_pMessage; -}; - -class TINYWRAP_API MsrpCallback -{ -public: - MsrpCallback() { } - virtual ~MsrpCallback() {} - virtual int OnEvent(const MsrpEvent* e) { - return -1; - } -}; - - -#if !defined(SWIG) -int twrap_msrp_cb(const tmsrp_event_t* _event); -#endif - -#endif /* TINYWRAP_MSRP_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_MSRP_H
+#define TINYWRAP_MSRP_H
+
+#include "tinyWRAP_config.h"
+
+#include "tinymsrp.h"
+
+class MsrpSession;
+
+class TINYWRAP_API MsrpMessage
+{
+public:
+ MsrpMessage();
+#if !defined(SWIG)
+ MsrpMessage(tmsrp_message_t *message);
+#endif
+ virtual ~MsrpMessage();
+
+ bool isRequest();
+ short getCode();
+ const char* getPhrase();
+ tmsrp_request_type_t getRequestType();
+#if defined(SWIG)
+ void getByteRange(int64_t* OUTPUT, int64_t* OUTPUT, int64_t* OUTPUT);
+#else
+ void getByteRange(int64_t* start, int64_t* end, int64_t* total);
+#endif
+ bool isLastChunck();
+ bool isFirstChunck();
+ bool isSuccessReport();
+ char* getMsrpHeaderValue(const char* name);
+ char* getMsrpHeaderParamValue(const char* name, const char* param);
+ unsigned getMsrpContentLength();
+ unsigned getMsrpContent(void* output, unsigned maxsize);
+#if !defined(SWIG)
+ const tmsrp_message_t* getWrappedMsrpMessage() {
+ return m_pMessage;
+ }
+#endif
+
+private:
+ const tmsrp_header_t* getMsrpHeader(const char* name, unsigned index = 0);
+
+private:
+ tmsrp_message_t *m_pMessage;
+};
+
+class TINYWRAP_API MsrpEvent
+{
+public:
+#if !defined(SWIG)
+ MsrpEvent(const tmsrp_event_t *_event);
+#endif
+ virtual ~MsrpEvent();
+
+ tmsrp_event_type_t getType();
+ const MsrpSession* getSipSession();
+ const MsrpMessage* getMessage() const;
+
+protected:
+ const tmsrp_event_t *_event;
+ MsrpMessage* m_pMessage;
+};
+
+class TINYWRAP_API MsrpCallback
+{
+public:
+ MsrpCallback() { }
+ virtual ~MsrpCallback() {}
+ virtual int OnEvent(const MsrpEvent* e) {
+ return -1;
+ }
+};
+
+
+#if !defined(SWIG)
+int twrap_msrp_cb(const tmsrp_event_t* _event);
+#endif
+
+#endif /* TINYWRAP_MSRP_H */
diff --git a/bindings/_common/Msrp.i b/bindings/_common/Msrp.i index 7924073..9d32cc4 100755 --- a/bindings/_common/Msrp.i +++ b/bindings/_common/Msrp.i @@ -1,34 +1,34 @@ -%{ -#include "Msrp.h" -%} - -/* Callbacks */ -%feature("director") MsrpCallback; - - -%nodefaultctor; -%include "Msrp.h" -%clearnodefaultctor; - -/* From tinyMSRP/tmsrp_message.h */ -typedef enum tmsrp_request_type_e -{ - tmsrp_NONE = 0, - - tmsrp_SEND, - tmsrp_REPORT, - tmsrp_AUTH - //... -} -tmsrp_request_type_t; - - -/* From tinyMSRP/tmsrp_event.h */ -typedef enum tmsrp_event_type_e -{ - tmsrp_event_type_none, - tmsrp_event_type_connected, - tmsrp_event_type_disconnected, - tmsrp_event_type_message, -} +%{
+#include "Msrp.h"
+%}
+
+/* Callbacks */
+%feature("director") MsrpCallback;
+
+
+%nodefaultctor;
+%include "Msrp.h"
+%clearnodefaultctor;
+
+/* From tinyMSRP/tmsrp_message.h */
+typedef enum tmsrp_request_type_e
+{
+ tmsrp_NONE = 0,
+
+ tmsrp_SEND,
+ tmsrp_REPORT,
+ tmsrp_AUTH
+ //...
+}
+tmsrp_request_type_t;
+
+
+/* From tinyMSRP/tmsrp_event.h */
+typedef enum tmsrp_event_type_e
+{
+ tmsrp_event_type_none,
+ tmsrp_event_type_connected,
+ tmsrp_event_type_disconnected,
+ tmsrp_event_type_message,
+}
tmsrp_event_type_t;
\ No newline at end of file diff --git a/bindings/_common/ProxyConsumer.cxx b/bindings/_common/ProxyConsumer.cxx index 9aa4b2f..cb95105 100755 --- a/bindings/_common/ProxyConsumer.cxx +++ b/bindings/_common/ProxyConsumer.cxx @@ -1,810 +1,810 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ - -/**@file ProxyConsumer.c - * @brief Audio/Video proxy consumers. - * - * @author Mamadou Diop <diopmamadou(at)doubango.org> - * - - */ -#include "ProxyConsumer.h" - -#include "AudioResampler.h" - -#include "tsk_memory.h" -#include "tsk_debug.h" - -#include "tinydav/audio/tdav_consumer_audio.h" -#include "tinydav/video/tdav_consumer_video.h" - - -/* ============ Audio Consumer Interface ================= */ - -typedef struct twrap_consumer_proxy_audio_s { - TDAV_DECLARE_CONSUMER_AUDIO; - - uint64_t id; - tsk_bool_t started; - const ProxyAudioConsumer* pcConsumer; // thread-safe and will be destroyed at the time as the "struct" -} -twrap_consumer_proxy_audio_t; -#define TWRAP_CONSUMER_PROXY_AUDIO(self) ((twrap_consumer_proxy_audio_t*)(self)) - -int twrap_consumer_proxy_audio_set(tmedia_consumer_t* _self, const tmedia_param_t* param) -{ - twrap_consumer_proxy_audio_t* self = (twrap_consumer_proxy_audio_t*)_self; - if(param->plugin_type == tmedia_ppt_consumer) { - // specific proxy consumer - } - return tdav_consumer_audio_set(TDAV_CONSUMER_AUDIO(self), param); -} - -int twrap_consumer_proxy_audio_prepare(tmedia_consumer_t* self, const tmedia_codec_t* codec) -{ - twrap_consumer_proxy_audio_t* audio = TWRAP_CONSUMER_PROXY_AUDIO(self); - ProxyPluginMgr* manager = NULL; - int ret = -1; - if(codec && (manager = ProxyPluginMgr::getInstance())) { - if((audio->pcConsumer = manager->findAudioConsumer(audio->id)) && audio->pcConsumer->getCallback()) { - self->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_DECODING(codec); - self->audio.in.channels = TMEDIA_CODEC_CHANNELS_AUDIO_DECODING(codec); - self->audio.in.rate = TMEDIA_CODEC_RATE_DECODING(codec); - - ret = audio->pcConsumer->getCallback()->prepare((int)self->audio.ptime, self->audio.in.rate, self->audio.in.channels); - if(ret == 0 && !audio->pcConsumer->getCallback()->isPivotSettings()) { - // say consumer can output these params - // Out "rate" and "channels" must be defined regardless previous values (already the case in other back-ends) to avoid issues on reINVITE with rate change (e.g. Opus -> PCMA). - /*if(!self->audio.out.rate)*/ self->audio.out.rate = self->audio.in.rate; - /*if(!self->audio.out.channels)*/ self->audio.out.channels = self->audio.in.channels; - } - } - } - else { - TSK_DEBUG_ERROR("Invalid parameter/state: codec=%d, manager=%s", codec, manager ? "no-null" : "null"); - } - - return ret; -} - -int twrap_consumer_proxy_audio_start(tmedia_consumer_t* self) -{ - ProxyPluginMgr* manager; - int ret = -1; - if((manager = ProxyPluginMgr::getInstance())) { - const ProxyAudioConsumer* audioConsumer; - if((audioConsumer = manager->findAudioConsumer(TWRAP_CONSUMER_PROXY_AUDIO(self)->id)) && audioConsumer->getCallback()) { - ret = audioConsumer->getCallback()->start(); - } - } - - TWRAP_CONSUMER_PROXY_AUDIO(self)->started = (ret == 0); - return ret; -} - -int twrap_consumer_proxy_audio_consume(tmedia_consumer_t* self, const void* buffer, tsk_size_t size, const tsk_object_t* proto_hdr) -{ - twrap_consumer_proxy_audio_t* audio = TWRAP_CONSUMER_PROXY_AUDIO(self); - - if(!audio->pcConsumer) { - ProxyPluginMgr* manager; - if((manager = ProxyPluginMgr::getInstance())) { - audio->pcConsumer = manager->findAudioConsumer(audio->id); - } - } - - ProxyAudioConsumerCallback* callback; - int ret = -1; - if(audio->pcConsumer && (callback = audio->pcConsumer->getCallback())) { - if(callback->putInJitterBuffer()) { - ret = tdav_consumer_audio_put(TDAV_CONSUMER_AUDIO(self), buffer, size, proto_hdr); - } - else { - ret = callback->consume(buffer, size, proto_hdr); - } - } - - return ret; -} - -int twrap_consumer_proxy_audio_pause(tmedia_consumer_t* self) -{ - ProxyPluginMgr* manager; - int ret = -1; - if((manager = ProxyPluginMgr::getInstance())) { - const ProxyAudioConsumer* audioConsumer; - if((audioConsumer = manager->findAudioConsumer(TWRAP_CONSUMER_PROXY_AUDIO(self)->id)) && audioConsumer->getCallback()) { - ret = audioConsumer->getCallback()->pause(); - } - } - - return ret; -} - -int twrap_consumer_proxy_audio_stop(tmedia_consumer_t* self) -{ - ProxyPluginMgr* manager; - int ret = -1; - if((manager = ProxyPluginMgr::getInstance())) { - const ProxyAudioConsumer* audioConsumer; - if((audioConsumer = manager->findAudioConsumer(TWRAP_CONSUMER_PROXY_AUDIO(self)->id)) && audioConsumer->getCallback()) { - ret = audioConsumer->getCallback()->stop(); - } - } - - TWRAP_CONSUMER_PROXY_AUDIO(self)->started = (ret == 0) ? tsk_false : tsk_true; - return ret; -} - - -// -// Audio consumer object definition -// -/* constructor */ -static tsk_object_t* twrap_consumer_proxy_audio_ctor(tsk_object_t * self, va_list * app) -{ - twrap_consumer_proxy_audio_t *consumer = (twrap_consumer_proxy_audio_t *)self; - if(consumer) { - /* init base */ - tdav_consumer_audio_init(TDAV_CONSUMER_AUDIO(consumer)); - /* init self */ - - /* Add the plugin to the manager */ - ProxyPluginMgr* manager = ProxyPluginMgr::getInstance(); - if(manager) { - ProxyPlugin* proxyConsumer = new ProxyAudioConsumer(consumer); - uint64_t id = proxyConsumer->getId(); - manager->addPlugin(&proxyConsumer); - manager->getCallback()->OnPluginCreated(id, twrap_proxy_plugin_audio_consumer); - } - } - return self; -} -/* destructor */ -static tsk_object_t* twrap_consumer_proxy_audio_dtor(tsk_object_t * self) -{ - twrap_consumer_proxy_audio_t *consumer = (twrap_consumer_proxy_audio_t *)self; - if(consumer) { - /* stop */ - if(consumer->started) { - twrap_consumer_proxy_audio_stop(TMEDIA_CONSUMER(consumer)); - } - - /* deinit base */ - tdav_consumer_audio_deinit(TDAV_CONSUMER_AUDIO(consumer)); - /* deinit self */ - - - /* Remove plugin from the manager */ - ProxyPluginMgr* manager = ProxyPluginMgr::getInstance(); - if(manager) { - manager->getCallback()->OnPluginDestroyed(consumer->id, twrap_proxy_plugin_audio_consumer); - manager->removePlugin(consumer->id); - } - } - - return self; -} -/* object definition */ -static const tsk_object_def_t twrap_consumer_proxy_audio_def_s = { - sizeof(twrap_consumer_proxy_audio_t), - twrap_consumer_proxy_audio_ctor, - twrap_consumer_proxy_audio_dtor, - tdav_consumer_audio_cmp, -}; -/* plugin definition*/ -static const tmedia_consumer_plugin_def_t twrap_consumer_proxy_audio_plugin_def_s = { - &twrap_consumer_proxy_audio_def_s, - - tmedia_audio, - "Audio Proxy Consumer", - - twrap_consumer_proxy_audio_set, - twrap_consumer_proxy_audio_prepare, - twrap_consumer_proxy_audio_start, - twrap_consumer_proxy_audio_consume, - twrap_consumer_proxy_audio_pause, - twrap_consumer_proxy_audio_stop -}; - -/*TINYWRAP_GEXTERN*/ const tmedia_consumer_plugin_def_t *twrap_consumer_proxy_audio_plugin_def_t = &twrap_consumer_proxy_audio_plugin_def_s; - - - -/* ============ ProxyAudioConsumer Class ================= */ -ProxyAudioConsumer::ProxyAudioConsumer(twrap_consumer_proxy_audio_t* pConsumer) - :ProxyPlugin(twrap_proxy_plugin_audio_consumer), - m_pWrappedPlugin(pConsumer), - m_pCallback(tsk_null) -{ - memset(&m_PullBuffer, 0, sizeof(m_PullBuffer)); - memset(&m_Resampler, 0, sizeof(m_Resampler)); - - if(m_pWrappedPlugin) { - m_pWrappedPlugin->id = this->getId(); - } -} - -ProxyAudioConsumer::~ProxyAudioConsumer() -{ - TSK_FREE(m_Resampler.pInBufferPtr); - m_Resampler.nInBufferSizeInByte = 0; - if(m_Resampler.pResampler) { - delete m_Resampler.pResampler, m_Resampler.pResampler = tsk_null; - } -} - -// Use this function to request resampling when your sound card can't honor negotaited record parameters -bool ProxyAudioConsumer::setActualSndCardPlaybackParams(int nPtime, int nRate, int nChannels) -{ - if(m_pWrappedPlugin) { - TSK_DEBUG_INFO("ProxyAudioConsumer::setActualSndCardRecordParams(ptime=%d, rate=%d, channels=%d)", nPtime, nRate, nChannels); - TMEDIA_CONSUMER(m_pWrappedPlugin)->audio.ptime = nPtime; - TMEDIA_CONSUMER(m_pWrappedPlugin)->audio.out.rate = nRate; - TMEDIA_CONSUMER(m_pWrappedPlugin)->audio.out.channels = nChannels; - return true; - } - else { - TSK_DEBUG_ERROR("Invalid state"); - return false; - } -} - -bool ProxyAudioConsumer::queryForResampler(uint16_t nInFreq, uint16_t nOutFreq, uint16_t nFrameDuration, uint16_t nChannels, uint16_t nResamplerQuality) -{ - TSK_DEBUG_INFO("queryForResampler(%hu,%hu,%hu,%hu,%hu)", nInFreq, nOutFreq, nFrameDuration, nChannels, nResamplerQuality); - if(nResamplerQuality > 10) { - TSK_DEBUG_WARN("%d is invalid value for quality", nResamplerQuality); - } - m_Resampler.pResampler = new AudioResampler(nInFreq, nOutFreq, nFrameDuration, nChannels, nResamplerQuality); - if(!m_Resampler.pResampler) { - TSK_DEBUG_ERROR("Failed to create new 'AudioResampler' object"); - return false; - } - bool bOK = m_Resampler.pResampler->isValid(); - if(!bOK) { - goto bail; - } - m_Resampler.nInBufferSizeInByte = m_Resampler.pResampler->getInputRequiredSizeInShort() * 2; - m_Resampler.pInBufferPtr = tsk_calloc(m_Resampler.nInBufferSizeInByte, 1); - bOK = (m_Resampler.pInBufferPtr != tsk_null); - -bail: - if(!bOK) { - if(m_Resampler.pResampler) { - delete m_Resampler.pResampler, m_Resampler.pResampler = tsk_null; - } - TSK_FREE(m_Resampler.pInBufferPtr); - m_Resampler.nInBufferSizeInByte = 0; - } - return bOK; -} - -bool ProxyAudioConsumer::setPullBuffer(const void* pPullBufferPtr, unsigned nPullBufferSize) -{ - m_PullBuffer.pPullBufferPtr = pPullBufferPtr; - m_PullBuffer.nPullBufferSize = nPullBufferSize; - return true; -} - -unsigned ProxyAudioConsumer::pull(void* _pOutput/*=tsk_null*/, unsigned _nSize/*=0*/) -{ - if((m_pWrappedPlugin = (twrap_consumer_proxy_audio_t*)tsk_object_ref(m_pWrappedPlugin))) { - void* pOutput; - unsigned nSize; - if(_pOutput && _nSize) { - pOutput = _pOutput, nSize = _nSize; - } - else { - pOutput = (void*)m_PullBuffer.pPullBufferPtr, nSize = m_PullBuffer.nPullBufferSize; - } - - tsk_size_t nRetSize = 0; - - if(m_Resampler.pResampler && m_Resampler.pInBufferPtr) { - nRetSize = tdav_consumer_audio_get(TDAV_CONSUMER_AUDIO(m_pWrappedPlugin), m_Resampler.pInBufferPtr, m_Resampler.nInBufferSizeInByte); - if(nRetSize) { - nRetSize = m_Resampler.pResampler->process(m_Resampler.pInBufferPtr, nRetSize, pOutput, nSize); - } - } - else { - nRetSize = tdav_consumer_audio_get(TDAV_CONSUMER_AUDIO(m_pWrappedPlugin), pOutput, nSize); - } - - tdav_consumer_audio_tick(TDAV_CONSUMER_AUDIO(m_pWrappedPlugin)); - - m_pWrappedPlugin = (twrap_consumer_proxy_audio_t*)tsk_object_unref(m_pWrappedPlugin); - return nRetSize; - } - return 0; -} - -bool ProxyAudioConsumer::setGain(unsigned nGain) -{ - if(m_pWrappedPlugin) { - // see also: MediaSessionMgr.consumerSetInt32(org.doubango.tinyWRAP.twrap_media_type_t.twrap_media_audio, "gain", nGain); - TMEDIA_CONSUMER(m_pWrappedPlugin)->audio.gain = TSK_MIN(nGain,14); - return true; - } - return false; -} - -unsigned ProxyAudioConsumer::getGain() -{ - if(m_pWrappedPlugin) { - return TMEDIA_CONSUMER(m_pWrappedPlugin)->audio.gain; - } - return 0; -} - -bool ProxyAudioConsumer::reset() -{ - if(m_pWrappedPlugin) { - return (tdav_consumer_audio_reset(TDAV_CONSUMER_AUDIO(m_pWrappedPlugin)) == 0); - } - return false; -} - -bool ProxyAudioConsumer::registerPlugin() -{ - /* HACK: Unregister all other audio plugins */ - tmedia_consumer_plugin_unregister_by_type(tmedia_audio); - /* Register our proxy plugin */ - return (tmedia_consumer_plugin_register(twrap_consumer_proxy_audio_plugin_def_t) == 0); -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/* ============ Video Consumer Interface ================= */ - -typedef struct twrap_consumer_proxy_video_s { - TDAV_DECLARE_CONSUMER_VIDEO; - - uint64_t id; - tsk_bool_t started; - const ProxyVideoConsumer* pcConsumer; // thread-safe and will be destroyed at the time as the "struct" -} -twrap_consumer_proxy_video_t; -#define TWRAP_CONSUMER_PROXY_VIDEO(self) ((twrap_consumer_proxy_video_t*)(self)) - -int twrap_consumer_proxy_video_set(tmedia_consumer_t* self, const tmedia_param_t* params) -{ - return 0; -} - -int twrap_consumer_proxy_video_prepare(tmedia_consumer_t* self, const tmedia_codec_t* codec) -{ - ProxyPluginMgr* manager; - twrap_consumer_proxy_video_t* video = TWRAP_CONSUMER_PROXY_VIDEO(self); - int ret = -1; - if(codec && (manager = ProxyPluginMgr::getInstance())) { - if((video->pcConsumer = manager->findVideoConsumer(video->id)) && video->pcConsumer->getCallback()) { - self->video.fps = TMEDIA_CODEC_VIDEO(codec)->in.fps; - // in - self->video.in.chroma = tmedia_chroma_yuv420p; - self->video.in.width = TMEDIA_CODEC_VIDEO(codec)->in.width; - self->video.in.height = TMEDIA_CODEC_VIDEO(codec)->in.height; - // display (out) - self->video.display.chroma = video->pcConsumer->getChroma(); - self->video.display.auto_resize = video->pcConsumer->getAutoResizeDisplay(); - if(!self->video.display.width) { - self->video.display.width = self->video.in.width; - } - if(!self->video.display.height) { - self->video.display.height = self->video.in.height; - } - ret = video->pcConsumer->getCallback()->prepare(TMEDIA_CODEC_VIDEO(codec)->in.width, TMEDIA_CODEC_VIDEO(codec)->in.height, TMEDIA_CODEC_VIDEO(codec)->in.fps); - } - } - - return ret; -} - -int twrap_consumer_proxy_video_start(tmedia_consumer_t* self) -{ - ProxyPluginMgr* manager; - int ret = -1; - if((manager = ProxyPluginMgr::getInstance())) { - const ProxyVideoConsumer* videoConsumer; - if((videoConsumer = manager->findVideoConsumer(TWRAP_CONSUMER_PROXY_VIDEO(self)->id)) && videoConsumer->getCallback()) { - ret = videoConsumer->getCallback()->start(); - } - } - - TWRAP_CONSUMER_PROXY_VIDEO(self)->started = (ret == 0); - return ret; -} - -int twrap_consumer_proxy_video_consume(tmedia_consumer_t* self, const void* buffer, tsk_size_t size, const tsk_object_t* proto_hdr) -{ - if(!self || !buffer || !size) { - TSK_DEBUG_ERROR("Invalid parameter"); - return -1; - } - - twrap_consumer_proxy_video_t* video = TWRAP_CONSUMER_PROXY_VIDEO(self); - - if(!video->pcConsumer) { - ProxyPluginMgr* manager; - if((manager = ProxyPluginMgr::getInstance())) { - video->pcConsumer = manager->findVideoConsumer(video->id); - } - } - - int ret = -1; - ProxyVideoConsumerCallback* callback; - - if(video->pcConsumer && (callback = video->pcConsumer->getCallback())) { - if(tdav_consumer_video_has_jb(TDAV_CONSUMER_VIDEO(self))) { - ret = tdav_consumer_video_put(TDAV_CONSUMER_VIDEO(self), buffer, size, proto_hdr); - } - else { - if(video->pcConsumer->hasConsumeBuffer()) { - unsigned nCopiedSize = video->pcConsumer->copyBuffer(buffer, size); - ret = callback->bufferCopied(nCopiedSize, size); - } - else { - ProxyVideoFrame* frame = new ProxyVideoFrame(buffer, size, const_cast<ProxyVideoConsumer*>(video->pcConsumer)->getDecodedWidth(), const_cast<ProxyVideoConsumer*>(video->pcConsumer)->getDecodedHeight(), proto_hdr); - ret = callback->consume(frame); - delete frame, frame = tsk_null; - } - } - } - else if(!video->pcConsumer) { - TSK_DEBUG_ERROR("Cannot find consumer with id=%lld", TWRAP_CONSUMER_PROXY_VIDEO(self)->id); - } - - - return ret; -} - -int twrap_consumer_proxy_video_pause(tmedia_consumer_t* self) -{ - ProxyPluginMgr* manager; - int ret = -1; - if((manager = ProxyPluginMgr::getInstance())) { - const ProxyVideoConsumer* videoConsumer; - if((videoConsumer = manager->findVideoConsumer(TWRAP_CONSUMER_PROXY_VIDEO(self)->id)) && videoConsumer->getCallback()) { - ret = videoConsumer->getCallback()->pause(); - } - } - - return ret; -} - -int twrap_consumer_proxy_video_stop(tmedia_consumer_t* self) -{ - ProxyPluginMgr* manager; - int ret = -1; - if((manager = ProxyPluginMgr::getInstance())) { - const ProxyVideoConsumer* videoConsumer; - if((videoConsumer = manager->findVideoConsumer(TWRAP_CONSUMER_PROXY_VIDEO(self)->id)) && videoConsumer->getCallback()) { - ret = videoConsumer->getCallback()->stop(); - } - } - - TWRAP_CONSUMER_PROXY_VIDEO(self)->started = (ret == 0) ? tsk_false : tsk_true; - return ret; -} - - -// -// Video consumer object definition -// -/* constructor */ -static tsk_object_t* twrap_consumer_proxy_video_ctor(tsk_object_t * self, va_list * app) -{ - twrap_consumer_proxy_video_t *consumer = (twrap_consumer_proxy_video_t *)self; - if(consumer) { - /* init base */ - tdav_consumer_video_init(TDAV_CONSUMER_VIDEO(consumer)); - /* init self */ - - /* Add the plugin to the manager */ - ProxyPluginMgr* manager = ProxyPluginMgr::getInstance(); - if(manager) { - ProxyPlugin* proxyConsumer = new ProxyVideoConsumer(ProxyVideoConsumer::getDefaultChroma(), consumer); - uint64_t id = proxyConsumer->getId(); - manager->addPlugin(&proxyConsumer); - manager->getCallback()->OnPluginCreated(id, twrap_proxy_plugin_video_consumer); - } - } - return self; -} -/* destructor */ -static tsk_object_t* twrap_consumer_proxy_video_dtor(tsk_object_t * self) -{ - twrap_consumer_proxy_video_t *consumer = (twrap_consumer_proxy_video_t *)self; - if(consumer) { - - /* stop */ - if(consumer->started) { - twrap_consumer_proxy_video_stop(TMEDIA_CONSUMER(consumer)); - } - - /* deinit base */ - tdav_consumer_video_deinit(TDAV_CONSUMER_VIDEO(consumer)); - /* deinit self */ - - /* Remove plugin from the manager */ - ProxyPluginMgr* manager = ProxyPluginMgr::getInstance(); - if(manager) { - manager->getCallback()->OnPluginDestroyed(consumer->id, twrap_proxy_plugin_video_consumer); - manager->removePlugin(consumer->id); - } - } - - return self; -} -/* object definition */ -static const tsk_object_def_t twrap_consumer_proxy_video_def_s = { - sizeof(twrap_consumer_proxy_video_t), - twrap_consumer_proxy_video_ctor, - twrap_consumer_proxy_video_dtor, - tsk_null, -}; -/* plugin definition*/ -static const tmedia_consumer_plugin_def_t twrap_consumer_proxy_video_plugin_def_s = { - &twrap_consumer_proxy_video_def_s, - - tmedia_video, - "Video Proxy Consumer", - - twrap_consumer_proxy_video_set, - twrap_consumer_proxy_video_prepare, - twrap_consumer_proxy_video_start, - twrap_consumer_proxy_video_consume, - twrap_consumer_proxy_video_pause, - twrap_consumer_proxy_video_stop -}; - -/*TINYWRAP_GEXTERN*/ const tmedia_consumer_plugin_def_t *twrap_consumer_proxy_video_plugin_def_t = &twrap_consumer_proxy_video_plugin_def_s; - - - -/* ============ ProxyVideoConsumer Class ================= */ -tmedia_chroma_t ProxyVideoConsumer::s_eDefaultChroma = tmedia_chroma_rgb565le; -bool ProxyVideoConsumer::s_bAutoResizeDisplay = false; - -ProxyVideoConsumer::ProxyVideoConsumer(tmedia_chroma_t eChroma, struct twrap_consumer_proxy_video_s* pConsumer) - : m_eChroma(eChroma), - m_bAutoResizeDisplay(ProxyVideoConsumer::getDefaultAutoResizeDisplay()), - m_pWrappedPlugin(pConsumer), - m_pCallback(tsk_null), - ProxyPlugin(twrap_proxy_plugin_video_consumer) -{ - m_pWrappedPlugin->id = this->getId(); - m_ConsumeBuffer.pConsumeBufferPtr = tsk_null; - m_ConsumeBuffer.nConsumeBufferSize = 0; -} - -ProxyVideoConsumer::~ProxyVideoConsumer() -{ -} - -bool ProxyVideoConsumer::setDisplaySize(unsigned nWidth, unsigned nHeight) -{ - if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) { - TMEDIA_CONSUMER(m_pWrappedPlugin)->video.display.width = nWidth; - TMEDIA_CONSUMER(m_pWrappedPlugin)->video.display.height = nHeight; - m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin); - return true; - } - TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin"); - return false; -} - -unsigned ProxyVideoConsumer::getDisplayWidth() -{ - unsigned displayWidth = 0; - if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) { - displayWidth = TMEDIA_CONSUMER(m_pWrappedPlugin)->video.display.width; - m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin); - } - else { - TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin"); - } - return displayWidth; -} - -unsigned ProxyVideoConsumer::getDisplayHeight() -{ - unsigned displayHeight = 0; - if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) { - displayHeight = TMEDIA_CONSUMER(m_pWrappedPlugin)->video.display.height; - m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin); - } - else { - TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin"); - } - return displayHeight; -} - -unsigned ProxyVideoConsumer::getDecodedWidth() -{ - unsigned width = 0; - if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) { - width = TMEDIA_CONSUMER(m_pWrappedPlugin)->video.in.width; - m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin); - } - else { - TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin"); - } - return width; -} - -unsigned ProxyVideoConsumer::getDecodedHeight() -{ - unsigned height = 0; - if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) { - height = TMEDIA_CONSUMER(m_pWrappedPlugin)->video.in.height; - m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin); - } - else { - TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin"); - } - return height; -} - -tmedia_chroma_t ProxyVideoConsumer::getChroma()const -{ - return m_eChroma; -} - -bool ProxyVideoConsumer::setAutoResizeDisplay(bool bAutoResizeDisplay) -{ - if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) { - TMEDIA_CONSUMER(m_pWrappedPlugin)->video.display.auto_resize = bAutoResizeDisplay ? tsk_true : tsk_false; - m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin); - m_bAutoResizeDisplay = bAutoResizeDisplay; - return true; - } - TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin"); - return false; -} - -bool ProxyVideoConsumer::getAutoResizeDisplay()const -{ - return m_bAutoResizeDisplay; -} - -bool ProxyVideoConsumer::setConsumeBuffer(const void* pConsumeBufferPtr, unsigned nConsumeBufferSize) -{ - m_ConsumeBuffer.pConsumeBufferPtr = pConsumeBufferPtr; - m_ConsumeBuffer.nConsumeBufferSize = nConsumeBufferSize; - return true; -} - -unsigned ProxyVideoConsumer::copyBuffer(const void* pBuffer, unsigned nSize)const -{ - unsigned nRetsize = 0; - if(pBuffer && nSize && m_ConsumeBuffer.pConsumeBufferPtr && m_ConsumeBuffer.nConsumeBufferSize) { - nRetsize = (nSize > m_ConsumeBuffer.nConsumeBufferSize) ? m_ConsumeBuffer.nConsumeBufferSize : nSize; - memcpy((void*)m_ConsumeBuffer.pConsumeBufferPtr, pBuffer, nRetsize); - } - return nRetsize; -} - -unsigned ProxyVideoConsumer::pull(void* pOutput, unsigned nSize) -{ - if(pOutput && nSize && (m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) { - tsk_size_t nRetSize = 0; - - if(!tdav_consumer_video_has_jb(TDAV_CONSUMER_VIDEO(m_pWrappedPlugin))) { - TSK_DEBUG_ERROR("This consumer doesn't hold any jitter buffer.\n\nTo pull a buffer you must register a callback ('class ProxyVideoConsumerCallback') and listen for either 'consume' or 'bufferCopied' functions"); - goto done; - } - - nRetSize = tdav_consumer_video_get(TDAV_CONSUMER_VIDEO(m_pWrappedPlugin), pOutput, nSize); - - tdav_consumer_video_tick(TDAV_CONSUMER_VIDEO(m_pWrappedPlugin)); - -done: - m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin); - return nRetSize; - } - return 0; -} - -bool ProxyVideoConsumer::reset() -{ - bool ret = false; - if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) { - if(tdav_consumer_video_has_jb(TDAV_CONSUMER_VIDEO(m_pWrappedPlugin))) { - ret = (tdav_consumer_video_reset(TDAV_CONSUMER_VIDEO(m_pWrappedPlugin)) == 0); - } - else { - TSK_DEBUG_ERROR("This consumer doesn't hold any jitter buffer"); - } - m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin); - } - - TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin"); - return ret; -} - -bool ProxyVideoConsumer::registerPlugin() -{ - /* HACK: Unregister all other video plugins */ - tmedia_consumer_plugin_unregister_by_type(tmedia_video); - /* Register our proxy plugin */ - return (tmedia_consumer_plugin_register(twrap_consumer_proxy_video_plugin_def_t) == 0); -} - - - -ProxyVideoFrame::ProxyVideoFrame(const void* pBufferPtr, unsigned nSize, unsigned nFrameWidth, unsigned nFrameHeight, const tsk_object_t* pProtoHdr) -{ - m_pBufferPtr = pBufferPtr; - m_nBufferSize = nSize; - m_nFrameWidth = nFrameWidth; - m_nFrameHeight = nFrameHeight; - m_pProtoHdr = pProtoHdr; -} - -ProxyVideoFrame::~ProxyVideoFrame() -{ -} - -unsigned ProxyVideoFrame::getSize() -{ - return m_nBufferSize; -} - -unsigned ProxyVideoFrame::getContent(void* pOutput, unsigned nMaxsize) -{ - unsigned nRetsize = 0; - if(pOutput && nMaxsize && m_pBufferPtr) { - nRetsize = (m_nBufferSize > nMaxsize) ? nMaxsize : m_nBufferSize; - memcpy(pOutput, m_pBufferPtr, nRetsize); - } - return nRetsize; -} +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+/**@file ProxyConsumer.c
+ * @brief Audio/Video proxy consumers.
+ *
+ * @author Mamadou Diop <diopmamadou(at)doubango.org>
+ *
+
+ */
+#include "ProxyConsumer.h"
+
+#include "AudioResampler.h"
+
+#include "tsk_memory.h"
+#include "tsk_debug.h"
+
+#include "tinydav/audio/tdav_consumer_audio.h"
+#include "tinydav/video/tdav_consumer_video.h"
+
+
+/* ============ Audio Consumer Interface ================= */
+
+typedef struct twrap_consumer_proxy_audio_s {
+ TDAV_DECLARE_CONSUMER_AUDIO;
+
+ uint64_t id;
+ tsk_bool_t started;
+ const ProxyAudioConsumer* pcConsumer; // thread-safe and will be destroyed at the time as the "struct"
+}
+twrap_consumer_proxy_audio_t;
+#define TWRAP_CONSUMER_PROXY_AUDIO(self) ((twrap_consumer_proxy_audio_t*)(self))
+
+int twrap_consumer_proxy_audio_set(tmedia_consumer_t* _self, const tmedia_param_t* param)
+{
+ twrap_consumer_proxy_audio_t* self = (twrap_consumer_proxy_audio_t*)_self;
+ if(param->plugin_type == tmedia_ppt_consumer) {
+ // specific proxy consumer
+ }
+ return tdav_consumer_audio_set(TDAV_CONSUMER_AUDIO(self), param);
+}
+
+int twrap_consumer_proxy_audio_prepare(tmedia_consumer_t* self, const tmedia_codec_t* codec)
+{
+ twrap_consumer_proxy_audio_t* audio = TWRAP_CONSUMER_PROXY_AUDIO(self);
+ ProxyPluginMgr* manager = NULL;
+ int ret = -1;
+ if(codec && (manager = ProxyPluginMgr::getInstance())) {
+ if((audio->pcConsumer = manager->findAudioConsumer(audio->id)) && audio->pcConsumer->getCallback()) {
+ self->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_DECODING(codec);
+ self->audio.in.channels = TMEDIA_CODEC_CHANNELS_AUDIO_DECODING(codec);
+ self->audio.in.rate = TMEDIA_CODEC_RATE_DECODING(codec);
+
+ ret = audio->pcConsumer->getCallback()->prepare((int)self->audio.ptime, self->audio.in.rate, self->audio.in.channels);
+ if(ret == 0 && !audio->pcConsumer->getCallback()->isPivotSettings()) {
+ // say consumer can output these params
+ // Out "rate" and "channels" must be defined regardless previous values (already the case in other back-ends) to avoid issues on reINVITE with rate change (e.g. Opus -> PCMA).
+ /*if(!self->audio.out.rate)*/ self->audio.out.rate = self->audio.in.rate;
+ /*if(!self->audio.out.channels)*/ self->audio.out.channels = self->audio.in.channels;
+ }
+ }
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid parameter/state: codec=%d, manager=%s", codec, manager ? "no-null" : "null");
+ }
+
+ return ret;
+}
+
+int twrap_consumer_proxy_audio_start(tmedia_consumer_t* self)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ const ProxyAudioConsumer* audioConsumer;
+ if((audioConsumer = manager->findAudioConsumer(TWRAP_CONSUMER_PROXY_AUDIO(self)->id)) && audioConsumer->getCallback()) {
+ ret = audioConsumer->getCallback()->start();
+ }
+ }
+
+ TWRAP_CONSUMER_PROXY_AUDIO(self)->started = (ret == 0);
+ return ret;
+}
+
+int twrap_consumer_proxy_audio_consume(tmedia_consumer_t* self, const void* buffer, tsk_size_t size, const tsk_object_t* proto_hdr)
+{
+ twrap_consumer_proxy_audio_t* audio = TWRAP_CONSUMER_PROXY_AUDIO(self);
+
+ if(!audio->pcConsumer) {
+ ProxyPluginMgr* manager;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ audio->pcConsumer = manager->findAudioConsumer(audio->id);
+ }
+ }
+
+ ProxyAudioConsumerCallback* callback;
+ int ret = -1;
+ if(audio->pcConsumer && (callback = audio->pcConsumer->getCallback())) {
+ if(callback->putInJitterBuffer()) {
+ ret = tdav_consumer_audio_put(TDAV_CONSUMER_AUDIO(self), buffer, size, proto_hdr);
+ }
+ else {
+ ret = callback->consume(buffer, size, proto_hdr);
+ }
+ }
+
+ return ret;
+}
+
+int twrap_consumer_proxy_audio_pause(tmedia_consumer_t* self)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ const ProxyAudioConsumer* audioConsumer;
+ if((audioConsumer = manager->findAudioConsumer(TWRAP_CONSUMER_PROXY_AUDIO(self)->id)) && audioConsumer->getCallback()) {
+ ret = audioConsumer->getCallback()->pause();
+ }
+ }
+
+ return ret;
+}
+
+int twrap_consumer_proxy_audio_stop(tmedia_consumer_t* self)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ const ProxyAudioConsumer* audioConsumer;
+ if((audioConsumer = manager->findAudioConsumer(TWRAP_CONSUMER_PROXY_AUDIO(self)->id)) && audioConsumer->getCallback()) {
+ ret = audioConsumer->getCallback()->stop();
+ }
+ }
+
+ TWRAP_CONSUMER_PROXY_AUDIO(self)->started = (ret == 0) ? tsk_false : tsk_true;
+ return ret;
+}
+
+
+//
+// Audio consumer object definition
+//
+/* constructor */
+static tsk_object_t* twrap_consumer_proxy_audio_ctor(tsk_object_t * self, va_list * app)
+{
+ twrap_consumer_proxy_audio_t *consumer = (twrap_consumer_proxy_audio_t *)self;
+ if(consumer) {
+ /* init base */
+ tdav_consumer_audio_init(TDAV_CONSUMER_AUDIO(consumer));
+ /* init self */
+
+ /* Add the plugin to the manager */
+ ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
+ if(manager) {
+ ProxyPlugin* proxyConsumer = new ProxyAudioConsumer(consumer);
+ uint64_t id = proxyConsumer->getId();
+ manager->addPlugin(&proxyConsumer);
+ manager->getCallback()->OnPluginCreated(id, twrap_proxy_plugin_audio_consumer);
+ }
+ }
+ return self;
+}
+/* destructor */
+static tsk_object_t* twrap_consumer_proxy_audio_dtor(tsk_object_t * self)
+{
+ twrap_consumer_proxy_audio_t *consumer = (twrap_consumer_proxy_audio_t *)self;
+ if(consumer) {
+ /* stop */
+ if(consumer->started) {
+ twrap_consumer_proxy_audio_stop(TMEDIA_CONSUMER(consumer));
+ }
+
+ /* deinit base */
+ tdav_consumer_audio_deinit(TDAV_CONSUMER_AUDIO(consumer));
+ /* deinit self */
+
+
+ /* Remove plugin from the manager */
+ ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
+ if(manager) {
+ manager->getCallback()->OnPluginDestroyed(consumer->id, twrap_proxy_plugin_audio_consumer);
+ manager->removePlugin(consumer->id);
+ }
+ }
+
+ return self;
+}
+/* object definition */
+static const tsk_object_def_t twrap_consumer_proxy_audio_def_s = {
+ sizeof(twrap_consumer_proxy_audio_t),
+ twrap_consumer_proxy_audio_ctor,
+ twrap_consumer_proxy_audio_dtor,
+ tdav_consumer_audio_cmp,
+};
+/* plugin definition*/
+static const tmedia_consumer_plugin_def_t twrap_consumer_proxy_audio_plugin_def_s = {
+ &twrap_consumer_proxy_audio_def_s,
+
+ tmedia_audio,
+ "Audio Proxy Consumer",
+
+ twrap_consumer_proxy_audio_set,
+ twrap_consumer_proxy_audio_prepare,
+ twrap_consumer_proxy_audio_start,
+ twrap_consumer_proxy_audio_consume,
+ twrap_consumer_proxy_audio_pause,
+ twrap_consumer_proxy_audio_stop
+};
+
+/*TINYWRAP_GEXTERN*/ const tmedia_consumer_plugin_def_t *twrap_consumer_proxy_audio_plugin_def_t = &twrap_consumer_proxy_audio_plugin_def_s;
+
+
+
+/* ============ ProxyAudioConsumer Class ================= */
+ProxyAudioConsumer::ProxyAudioConsumer(twrap_consumer_proxy_audio_t* pConsumer)
+ :ProxyPlugin(twrap_proxy_plugin_audio_consumer),
+ m_pWrappedPlugin(pConsumer),
+ m_pCallback(tsk_null)
+{
+ memset(&m_PullBuffer, 0, sizeof(m_PullBuffer));
+ memset(&m_Resampler, 0, sizeof(m_Resampler));
+
+ if(m_pWrappedPlugin) {
+ m_pWrappedPlugin->id = this->getId();
+ }
+}
+
+ProxyAudioConsumer::~ProxyAudioConsumer()
+{
+ TSK_FREE(m_Resampler.pInBufferPtr);
+ m_Resampler.nInBufferSizeInByte = 0;
+ if(m_Resampler.pResampler) {
+ delete m_Resampler.pResampler, m_Resampler.pResampler = tsk_null;
+ }
+}
+
+// Use this function to request resampling when your sound card can't honor negotaited record parameters
+bool ProxyAudioConsumer::setActualSndCardPlaybackParams(int nPtime, int nRate, int nChannels)
+{
+ if(m_pWrappedPlugin) {
+ TSK_DEBUG_INFO("ProxyAudioConsumer::setActualSndCardRecordParams(ptime=%d, rate=%d, channels=%d)", nPtime, nRate, nChannels);
+ TMEDIA_CONSUMER(m_pWrappedPlugin)->audio.ptime = nPtime;
+ TMEDIA_CONSUMER(m_pWrappedPlugin)->audio.out.rate = nRate;
+ TMEDIA_CONSUMER(m_pWrappedPlugin)->audio.out.channels = nChannels;
+ return true;
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid state");
+ return false;
+ }
+}
+
+bool ProxyAudioConsumer::queryForResampler(uint16_t nInFreq, uint16_t nOutFreq, uint16_t nFrameDuration, uint16_t nChannels, uint16_t nResamplerQuality)
+{
+ TSK_DEBUG_INFO("queryForResampler(%hu,%hu,%hu,%hu,%hu)", nInFreq, nOutFreq, nFrameDuration, nChannels, nResamplerQuality);
+ if(nResamplerQuality > 10) {
+ TSK_DEBUG_WARN("%d is invalid value for quality", nResamplerQuality);
+ }
+ m_Resampler.pResampler = new AudioResampler(nInFreq, nOutFreq, nFrameDuration, nChannels, nResamplerQuality);
+ if(!m_Resampler.pResampler) {
+ TSK_DEBUG_ERROR("Failed to create new 'AudioResampler' object");
+ return false;
+ }
+ bool bOK = m_Resampler.pResampler->isValid();
+ if(!bOK) {
+ goto bail;
+ }
+ m_Resampler.nInBufferSizeInByte = m_Resampler.pResampler->getInputRequiredSizeInShort() * 2;
+ m_Resampler.pInBufferPtr = tsk_calloc(m_Resampler.nInBufferSizeInByte, 1);
+ bOK = (m_Resampler.pInBufferPtr != tsk_null);
+
+bail:
+ if(!bOK) {
+ if(m_Resampler.pResampler) {
+ delete m_Resampler.pResampler, m_Resampler.pResampler = tsk_null;
+ }
+ TSK_FREE(m_Resampler.pInBufferPtr);
+ m_Resampler.nInBufferSizeInByte = 0;
+ }
+ return bOK;
+}
+
+bool ProxyAudioConsumer::setPullBuffer(const void* pPullBufferPtr, unsigned nPullBufferSize)
+{
+ m_PullBuffer.pPullBufferPtr = pPullBufferPtr;
+ m_PullBuffer.nPullBufferSize = nPullBufferSize;
+ return true;
+}
+
+unsigned ProxyAudioConsumer::pull(void* _pOutput/*=tsk_null*/, unsigned _nSize/*=0*/)
+{
+ if((m_pWrappedPlugin = (twrap_consumer_proxy_audio_t*)tsk_object_ref(m_pWrappedPlugin))) {
+ void* pOutput;
+ unsigned nSize;
+ if(_pOutput && _nSize) {
+ pOutput = _pOutput, nSize = _nSize;
+ }
+ else {
+ pOutput = (void*)m_PullBuffer.pPullBufferPtr, nSize = m_PullBuffer.nPullBufferSize;
+ }
+
+ tsk_size_t nRetSize = 0;
+
+ if(m_Resampler.pResampler && m_Resampler.pInBufferPtr) {
+ nRetSize = tdav_consumer_audio_get(TDAV_CONSUMER_AUDIO(m_pWrappedPlugin), m_Resampler.pInBufferPtr, m_Resampler.nInBufferSizeInByte);
+ if(nRetSize) {
+ nRetSize = m_Resampler.pResampler->process(m_Resampler.pInBufferPtr, nRetSize, pOutput, nSize);
+ }
+ }
+ else {
+ nRetSize = tdav_consumer_audio_get(TDAV_CONSUMER_AUDIO(m_pWrappedPlugin), pOutput, nSize);
+ }
+
+ tdav_consumer_audio_tick(TDAV_CONSUMER_AUDIO(m_pWrappedPlugin));
+
+ m_pWrappedPlugin = (twrap_consumer_proxy_audio_t*)tsk_object_unref(m_pWrappedPlugin);
+ return nRetSize;
+ }
+ return 0;
+}
+
+bool ProxyAudioConsumer::setGain(unsigned nGain)
+{
+ if(m_pWrappedPlugin) {
+ // see also: MediaSessionMgr.consumerSetInt32(org.doubango.tinyWRAP.twrap_media_type_t.twrap_media_audio, "gain", nGain);
+ TMEDIA_CONSUMER(m_pWrappedPlugin)->audio.gain = TSK_MIN(nGain,14);
+ return true;
+ }
+ return false;
+}
+
+unsigned ProxyAudioConsumer::getGain()
+{
+ if(m_pWrappedPlugin) {
+ return TMEDIA_CONSUMER(m_pWrappedPlugin)->audio.gain;
+ }
+ return 0;
+}
+
+bool ProxyAudioConsumer::reset()
+{
+ if(m_pWrappedPlugin) {
+ return (tdav_consumer_audio_reset(TDAV_CONSUMER_AUDIO(m_pWrappedPlugin)) == 0);
+ }
+ return false;
+}
+
+bool ProxyAudioConsumer::registerPlugin()
+{
+ /* HACK: Unregister all other audio plugins */
+ tmedia_consumer_plugin_unregister_by_type(tmedia_audio);
+ /* Register our proxy plugin */
+ return (tmedia_consumer_plugin_register(twrap_consumer_proxy_audio_plugin_def_t) == 0);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/* ============ Video Consumer Interface ================= */
+
+typedef struct twrap_consumer_proxy_video_s {
+ TDAV_DECLARE_CONSUMER_VIDEO;
+
+ uint64_t id;
+ tsk_bool_t started;
+ const ProxyVideoConsumer* pcConsumer; // thread-safe and will be destroyed at the time as the "struct"
+}
+twrap_consumer_proxy_video_t;
+#define TWRAP_CONSUMER_PROXY_VIDEO(self) ((twrap_consumer_proxy_video_t*)(self))
+
+int twrap_consumer_proxy_video_set(tmedia_consumer_t* self, const tmedia_param_t* params)
+{
+ return 0;
+}
+
+int twrap_consumer_proxy_video_prepare(tmedia_consumer_t* self, const tmedia_codec_t* codec)
+{
+ ProxyPluginMgr* manager;
+ twrap_consumer_proxy_video_t* video = TWRAP_CONSUMER_PROXY_VIDEO(self);
+ int ret = -1;
+ if(codec && (manager = ProxyPluginMgr::getInstance())) {
+ if((video->pcConsumer = manager->findVideoConsumer(video->id)) && video->pcConsumer->getCallback()) {
+ self->video.fps = TMEDIA_CODEC_VIDEO(codec)->in.fps;
+ // in
+ self->video.in.chroma = tmedia_chroma_yuv420p;
+ self->video.in.width = TMEDIA_CODEC_VIDEO(codec)->in.width;
+ self->video.in.height = TMEDIA_CODEC_VIDEO(codec)->in.height;
+ // display (out)
+ self->video.display.chroma = video->pcConsumer->getChroma();
+ self->video.display.auto_resize = video->pcConsumer->getAutoResizeDisplay();
+ if(!self->video.display.width) {
+ self->video.display.width = self->video.in.width;
+ }
+ if(!self->video.display.height) {
+ self->video.display.height = self->video.in.height;
+ }
+ ret = video->pcConsumer->getCallback()->prepare(TMEDIA_CODEC_VIDEO(codec)->in.width, TMEDIA_CODEC_VIDEO(codec)->in.height, TMEDIA_CODEC_VIDEO(codec)->in.fps);
+ }
+ }
+
+ return ret;
+}
+
+int twrap_consumer_proxy_video_start(tmedia_consumer_t* self)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ const ProxyVideoConsumer* videoConsumer;
+ if((videoConsumer = manager->findVideoConsumer(TWRAP_CONSUMER_PROXY_VIDEO(self)->id)) && videoConsumer->getCallback()) {
+ ret = videoConsumer->getCallback()->start();
+ }
+ }
+
+ TWRAP_CONSUMER_PROXY_VIDEO(self)->started = (ret == 0);
+ return ret;
+}
+
+int twrap_consumer_proxy_video_consume(tmedia_consumer_t* self, const void* buffer, tsk_size_t size, const tsk_object_t* proto_hdr)
+{
+ if(!self || !buffer || !size) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ twrap_consumer_proxy_video_t* video = TWRAP_CONSUMER_PROXY_VIDEO(self);
+
+ if(!video->pcConsumer) {
+ ProxyPluginMgr* manager;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ video->pcConsumer = manager->findVideoConsumer(video->id);
+ }
+ }
+
+ int ret = -1;
+ ProxyVideoConsumerCallback* callback;
+
+ if(video->pcConsumer && (callback = video->pcConsumer->getCallback())) {
+ if(tdav_consumer_video_has_jb(TDAV_CONSUMER_VIDEO(self))) {
+ ret = tdav_consumer_video_put(TDAV_CONSUMER_VIDEO(self), buffer, size, proto_hdr);
+ }
+ else {
+ if(video->pcConsumer->hasConsumeBuffer()) {
+ unsigned nCopiedSize = video->pcConsumer->copyBuffer(buffer, size);
+ ret = callback->bufferCopied(nCopiedSize, size);
+ }
+ else {
+ ProxyVideoFrame* frame = new ProxyVideoFrame(buffer, size, const_cast<ProxyVideoConsumer*>(video->pcConsumer)->getDecodedWidth(), const_cast<ProxyVideoConsumer*>(video->pcConsumer)->getDecodedHeight(), proto_hdr);
+ ret = callback->consume(frame);
+ delete frame, frame = tsk_null;
+ }
+ }
+ }
+ else if(!video->pcConsumer) {
+ TSK_DEBUG_ERROR("Cannot find consumer with id=%lld", TWRAP_CONSUMER_PROXY_VIDEO(self)->id);
+ }
+
+
+ return ret;
+}
+
+int twrap_consumer_proxy_video_pause(tmedia_consumer_t* self)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ const ProxyVideoConsumer* videoConsumer;
+ if((videoConsumer = manager->findVideoConsumer(TWRAP_CONSUMER_PROXY_VIDEO(self)->id)) && videoConsumer->getCallback()) {
+ ret = videoConsumer->getCallback()->pause();
+ }
+ }
+
+ return ret;
+}
+
+int twrap_consumer_proxy_video_stop(tmedia_consumer_t* self)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ const ProxyVideoConsumer* videoConsumer;
+ if((videoConsumer = manager->findVideoConsumer(TWRAP_CONSUMER_PROXY_VIDEO(self)->id)) && videoConsumer->getCallback()) {
+ ret = videoConsumer->getCallback()->stop();
+ }
+ }
+
+ TWRAP_CONSUMER_PROXY_VIDEO(self)->started = (ret == 0) ? tsk_false : tsk_true;
+ return ret;
+}
+
+
+//
+// Video consumer object definition
+//
+/* constructor */
+static tsk_object_t* twrap_consumer_proxy_video_ctor(tsk_object_t * self, va_list * app)
+{
+ twrap_consumer_proxy_video_t *consumer = (twrap_consumer_proxy_video_t *)self;
+ if(consumer) {
+ /* init base */
+ tdav_consumer_video_init(TDAV_CONSUMER_VIDEO(consumer));
+ /* init self */
+
+ /* Add the plugin to the manager */
+ ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
+ if(manager) {
+ ProxyPlugin* proxyConsumer = new ProxyVideoConsumer(ProxyVideoConsumer::getDefaultChroma(), consumer);
+ uint64_t id = proxyConsumer->getId();
+ manager->addPlugin(&proxyConsumer);
+ manager->getCallback()->OnPluginCreated(id, twrap_proxy_plugin_video_consumer);
+ }
+ }
+ return self;
+}
+/* destructor */
+static tsk_object_t* twrap_consumer_proxy_video_dtor(tsk_object_t * self)
+{
+ twrap_consumer_proxy_video_t *consumer = (twrap_consumer_proxy_video_t *)self;
+ if(consumer) {
+
+ /* stop */
+ if(consumer->started) {
+ twrap_consumer_proxy_video_stop(TMEDIA_CONSUMER(consumer));
+ }
+
+ /* deinit base */
+ tdav_consumer_video_deinit(TDAV_CONSUMER_VIDEO(consumer));
+ /* deinit self */
+
+ /* Remove plugin from the manager */
+ ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
+ if(manager) {
+ manager->getCallback()->OnPluginDestroyed(consumer->id, twrap_proxy_plugin_video_consumer);
+ manager->removePlugin(consumer->id);
+ }
+ }
+
+ return self;
+}
+/* object definition */
+static const tsk_object_def_t twrap_consumer_proxy_video_def_s = {
+ sizeof(twrap_consumer_proxy_video_t),
+ twrap_consumer_proxy_video_ctor,
+ twrap_consumer_proxy_video_dtor,
+ tsk_null,
+};
+/* plugin definition*/
+static const tmedia_consumer_plugin_def_t twrap_consumer_proxy_video_plugin_def_s = {
+ &twrap_consumer_proxy_video_def_s,
+
+ tmedia_video,
+ "Video Proxy Consumer",
+
+ twrap_consumer_proxy_video_set,
+ twrap_consumer_proxy_video_prepare,
+ twrap_consumer_proxy_video_start,
+ twrap_consumer_proxy_video_consume,
+ twrap_consumer_proxy_video_pause,
+ twrap_consumer_proxy_video_stop
+};
+
+/*TINYWRAP_GEXTERN*/ const tmedia_consumer_plugin_def_t *twrap_consumer_proxy_video_plugin_def_t = &twrap_consumer_proxy_video_plugin_def_s;
+
+
+
+/* ============ ProxyVideoConsumer Class ================= */
+tmedia_chroma_t ProxyVideoConsumer::s_eDefaultChroma = tmedia_chroma_rgb565le;
+bool ProxyVideoConsumer::s_bAutoResizeDisplay = false;
+
+ProxyVideoConsumer::ProxyVideoConsumer(tmedia_chroma_t eChroma, struct twrap_consumer_proxy_video_s* pConsumer)
+ : m_eChroma(eChroma),
+ m_bAutoResizeDisplay(ProxyVideoConsumer::getDefaultAutoResizeDisplay()),
+ m_pWrappedPlugin(pConsumer),
+ m_pCallback(tsk_null),
+ ProxyPlugin(twrap_proxy_plugin_video_consumer)
+{
+ m_pWrappedPlugin->id = this->getId();
+ m_ConsumeBuffer.pConsumeBufferPtr = tsk_null;
+ m_ConsumeBuffer.nConsumeBufferSize = 0;
+}
+
+ProxyVideoConsumer::~ProxyVideoConsumer()
+{
+}
+
+bool ProxyVideoConsumer::setDisplaySize(unsigned nWidth, unsigned nHeight)
+{
+ if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) {
+ TMEDIA_CONSUMER(m_pWrappedPlugin)->video.display.width = nWidth;
+ TMEDIA_CONSUMER(m_pWrappedPlugin)->video.display.height = nHeight;
+ m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin);
+ return true;
+ }
+ TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin");
+ return false;
+}
+
+unsigned ProxyVideoConsumer::getDisplayWidth()
+{
+ unsigned displayWidth = 0;
+ if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) {
+ displayWidth = TMEDIA_CONSUMER(m_pWrappedPlugin)->video.display.width;
+ m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin);
+ }
+ else {
+ TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin");
+ }
+ return displayWidth;
+}
+
+unsigned ProxyVideoConsumer::getDisplayHeight()
+{
+ unsigned displayHeight = 0;
+ if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) {
+ displayHeight = TMEDIA_CONSUMER(m_pWrappedPlugin)->video.display.height;
+ m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin);
+ }
+ else {
+ TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin");
+ }
+ return displayHeight;
+}
+
+unsigned ProxyVideoConsumer::getDecodedWidth()
+{
+ unsigned width = 0;
+ if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) {
+ width = TMEDIA_CONSUMER(m_pWrappedPlugin)->video.in.width;
+ m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin);
+ }
+ else {
+ TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin");
+ }
+ return width;
+}
+
+unsigned ProxyVideoConsumer::getDecodedHeight()
+{
+ unsigned height = 0;
+ if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) {
+ height = TMEDIA_CONSUMER(m_pWrappedPlugin)->video.in.height;
+ m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin);
+ }
+ else {
+ TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin");
+ }
+ return height;
+}
+
+tmedia_chroma_t ProxyVideoConsumer::getChroma()const
+{
+ return m_eChroma;
+}
+
+bool ProxyVideoConsumer::setAutoResizeDisplay(bool bAutoResizeDisplay)
+{
+ if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) {
+ TMEDIA_CONSUMER(m_pWrappedPlugin)->video.display.auto_resize = bAutoResizeDisplay ? tsk_true : tsk_false;
+ m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin);
+ m_bAutoResizeDisplay = bAutoResizeDisplay;
+ return true;
+ }
+ TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin");
+ return false;
+}
+
+bool ProxyVideoConsumer::getAutoResizeDisplay()const
+{
+ return m_bAutoResizeDisplay;
+}
+
+bool ProxyVideoConsumer::setConsumeBuffer(const void* pConsumeBufferPtr, unsigned nConsumeBufferSize)
+{
+ m_ConsumeBuffer.pConsumeBufferPtr = pConsumeBufferPtr;
+ m_ConsumeBuffer.nConsumeBufferSize = nConsumeBufferSize;
+ return true;
+}
+
+unsigned ProxyVideoConsumer::copyBuffer(const void* pBuffer, unsigned nSize)const
+{
+ unsigned nRetsize = 0;
+ if(pBuffer && nSize && m_ConsumeBuffer.pConsumeBufferPtr && m_ConsumeBuffer.nConsumeBufferSize) {
+ nRetsize = (nSize > m_ConsumeBuffer.nConsumeBufferSize) ? m_ConsumeBuffer.nConsumeBufferSize : nSize;
+ memcpy((void*)m_ConsumeBuffer.pConsumeBufferPtr, pBuffer, nRetsize);
+ }
+ return nRetsize;
+}
+
+unsigned ProxyVideoConsumer::pull(void* pOutput, unsigned nSize)
+{
+ if(pOutput && nSize && (m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) {
+ tsk_size_t nRetSize = 0;
+
+ if(!tdav_consumer_video_has_jb(TDAV_CONSUMER_VIDEO(m_pWrappedPlugin))) {
+ TSK_DEBUG_ERROR("This consumer doesn't hold any jitter buffer.\n\nTo pull a buffer you must register a callback ('class ProxyVideoConsumerCallback') and listen for either 'consume' or 'bufferCopied' functions");
+ goto done;
+ }
+
+ nRetSize = tdav_consumer_video_get(TDAV_CONSUMER_VIDEO(m_pWrappedPlugin), pOutput, nSize);
+
+ tdav_consumer_video_tick(TDAV_CONSUMER_VIDEO(m_pWrappedPlugin));
+
+done:
+ m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin);
+ return nRetSize;
+ }
+ return 0;
+}
+
+bool ProxyVideoConsumer::reset()
+{
+ bool ret = false;
+ if((m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_ref(m_pWrappedPlugin))) {
+ if(tdav_consumer_video_has_jb(TDAV_CONSUMER_VIDEO(m_pWrappedPlugin))) {
+ ret = (tdav_consumer_video_reset(TDAV_CONSUMER_VIDEO(m_pWrappedPlugin)) == 0);
+ }
+ else {
+ TSK_DEBUG_ERROR("This consumer doesn't hold any jitter buffer");
+ }
+ m_pWrappedPlugin = (twrap_consumer_proxy_video_t*)tsk_object_unref(m_pWrappedPlugin);
+ }
+
+ TSK_DEBUG_ERROR("This consumer doesn't wrap any plugin");
+ return ret;
+}
+
+bool ProxyVideoConsumer::registerPlugin()
+{
+ /* HACK: Unregister all other video plugins */
+ tmedia_consumer_plugin_unregister_by_type(tmedia_video);
+ /* Register our proxy plugin */
+ return (tmedia_consumer_plugin_register(twrap_consumer_proxy_video_plugin_def_t) == 0);
+}
+
+
+
+ProxyVideoFrame::ProxyVideoFrame(const void* pBufferPtr, unsigned nSize, unsigned nFrameWidth, unsigned nFrameHeight, const tsk_object_t* pProtoHdr)
+{
+ m_pBufferPtr = pBufferPtr;
+ m_nBufferSize = nSize;
+ m_nFrameWidth = nFrameWidth;
+ m_nFrameHeight = nFrameHeight;
+ m_pProtoHdr = pProtoHdr;
+}
+
+ProxyVideoFrame::~ProxyVideoFrame()
+{
+}
+
+unsigned ProxyVideoFrame::getSize()
+{
+ return m_nBufferSize;
+}
+
+unsigned ProxyVideoFrame::getContent(void* pOutput, unsigned nMaxsize)
+{
+ unsigned nRetsize = 0;
+ if(pOutput && nMaxsize && m_pBufferPtr) {
+ nRetsize = (m_nBufferSize > nMaxsize) ? nMaxsize : m_nBufferSize;
+ memcpy(pOutput, m_pBufferPtr, nRetsize);
+ }
+ return nRetsize;
+}
diff --git a/bindings/_common/ProxyConsumer.h b/bindings/_common/ProxyConsumer.h index 76258b6..f8d1325 100755 --- a/bindings/_common/ProxyConsumer.h +++ b/bindings/_common/ProxyConsumer.h @@ -1,265 +1,265 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ - -/**@file ProxyConsumer.h - * @brief Audio/Video proxy consumers. - * - * @author Mamadou Diop <diopmamadou(at)doubango.org> - */ -#ifndef TINYWRAP_CONSUMER_PROXY_H -#define TINYWRAP_CONSUMER_PROXY_H - -#include "tinyWRAP_config.h" - -#include "ProxyPluginMgr.h" - -#include "tinymedia/tmedia_common.h" -#include "tinymedia/tmedia_consumer.h" - -class AudioResampler; - -/* ============ ProxyAudioConsumerCallback Class ================= */ -class ProxyAudioConsumerCallback -{ -public: - ProxyAudioConsumerCallback() { } - virtual ~ProxyAudioConsumerCallback() { } - - virtual int prepare(int ptime, int rate, int channels) { - return -1; - } - virtual int start() { - return -1; - } - virtual int pause() { - return -1; - } - virtual int stop() { - return -1; - } -#if !defined(SWIG) - // whether the audio buffer have to be stored in the JB then pulled using "ProxyAudioConsumer::pull()" or not - virtual bool putInJitterBuffer() { - return true; - } - // whether we are using the "telepresence" system (PIVOT audio settings must not be changed) - virtual bool isPivotSettings() { - return false; - } - // only called if "putInJitterBuffer()" return "true" - virtual int consume(const void* buffer_ptr, tsk_size_t buffer_size, const tsk_object_t* proto_hdr) { - return -1; - } -#endif -}; - -/* ============ ProxyAudioConsumer Class ================= */ -class ProxyAudioConsumer : public ProxyPlugin -{ -public: -#if !defined(SWIG) - ProxyAudioConsumer(struct twrap_consumer_proxy_audio_s* pConsumer); -#endif - virtual ~ProxyAudioConsumer(); - bool setActualSndCardPlaybackParams(int nPtime, int nRate, int nChannels); - bool queryForResampler(uint16_t nInFreq, uint16_t nOutFreq, uint16_t nFrameDuration, uint16_t nChannels, uint16_t nResamplerQuality); - bool setPullBuffer(const void* pPullBufferPtr, unsigned nPullBufferSize); - unsigned pull(void* pOutput=tsk_null, unsigned nSize=0); - bool setGain(unsigned nGain); - unsigned getGain(); - bool reset(); - void setCallback(ProxyAudioConsumerCallback* pCallback) { - m_pCallback = pCallback; - } -#if !defined(SWIG) - inline ProxyAudioConsumerCallback* getCallback()const { - return m_pCallback; - } - virtual inline bool isWrapping(tsk_object_t* pWrappedPlugin) { - return m_pWrappedPlugin == pWrappedPlugin; - } -#endif - virtual inline uint64_t getMediaSessionId() { - return m_pWrappedPlugin ? TMEDIA_CONSUMER(m_pWrappedPlugin)->session_id : 0; - } - -public: - static bool registerPlugin(); - -private: - struct twrap_consumer_proxy_audio_s* m_pWrappedPlugin; - ProxyAudioConsumerCallback* m_pCallback; - struct { - const void* pPullBufferPtr; - unsigned nPullBufferSize; - } m_PullBuffer; - - struct { - void* pInBufferPtr; - unsigned nInBufferSizeInByte; - AudioResampler* pResampler; - } m_Resampler; -}; - -class ProxyVideoFrame; - -/* ============ ProxyVideoConsumerCallback Class ================= */ -class ProxyVideoConsumerCallback -{ -public: - ProxyVideoConsumerCallback() {} - virtual ~ProxyVideoConsumerCallback() {} - - virtual int prepare(int nWidth, int nHeight, int nFps) { - return -1; - } - virtual int consume(const ProxyVideoFrame* frame) { - return -1; - } - // only called if a buffer is registered using setPullBuffer(). Otherwise, consume() will be called - virtual int bufferCopied(unsigned nCopiedSize, unsigned nAvailableSize) { - return -1; - } - virtual int start() { - return -1; - } - virtual int pause() { - return -1; - } - virtual int stop() { - return -1; - } -}; - -/* ============ ProxyVideoConsumer Class ================= */ -class ProxyVideoConsumer : public ProxyPlugin -{ -public: -#if !defined(SWIG) - ProxyVideoConsumer(tmedia_chroma_t eChroma, struct twrap_consumer_proxy_video_s* pConsumer); -#endif - virtual ~ProxyVideoConsumer(); - - bool setDisplaySize(unsigned nWidth, unsigned nHeight); - unsigned getDisplayWidth(); - unsigned getDisplayHeight(); - unsigned getDecodedWidth(); - unsigned getDecodedHeight(); - - void setCallback(ProxyVideoConsumerCallback* pCallback) { - m_pCallback = pCallback; - } - bool setAutoResizeDisplay(bool bAutoResizeDisplay); - bool getAutoResizeDisplay()const; - bool setConsumeBuffer(const void* pConsumeBufferPtr, unsigned nConsumeBufferSize); - unsigned pull(void* pOutput, unsigned nSize); - bool reset(); - -#if !defined(SWIG) - bool hasConsumeBuffer()const { - return m_ConsumeBuffer.pConsumeBufferPtr && m_ConsumeBuffer.nConsumeBufferSize; - } - unsigned copyBuffer(const void* pBuffer, unsigned nSize)const; - inline ProxyVideoConsumerCallback* getCallback()const { - return m_pCallback; - } - virtual inline bool isWrapping(tsk_object_t* wrapped_plugin) { - return m_pWrappedPlugin == wrapped_plugin; - } -#endif - virtual inline uint64_t getMediaSessionId() { - return m_pWrappedPlugin ? TMEDIA_CONSUMER(m_pWrappedPlugin)->session_id : 0; - } - -public: - static bool registerPlugin(); - static void setDefaultChroma(tmedia_chroma_t eChroma) { - s_eDefaultChroma = eChroma; - } - static void setDefaultAutoResizeDisplay(bool bAutoResizeDisplay) { - s_bAutoResizeDisplay = bAutoResizeDisplay; - } - -#if !defined(SWIG) - tmedia_chroma_t getChroma()const; - static tmedia_chroma_t getDefaultChroma() { - return s_eDefaultChroma; - } - static bool getDefaultAutoResizeDisplay() { - return s_bAutoResizeDisplay; - } -#endif - -private: - struct twrap_consumer_proxy_video_s* m_pWrappedPlugin; - tmedia_chroma_t m_eChroma; - ProxyVideoConsumerCallback* m_pCallback; - struct { - const void* pConsumeBufferPtr; - unsigned nConsumeBufferSize; - } m_ConsumeBuffer; - bool m_bAutoResizeDisplay; - - static tmedia_chroma_t s_eDefaultChroma; - static bool s_bAutoResizeDisplay; -}; - -/* ============ ProxyVideoFrame Class ================= */ -class ProxyVideoFrame -{ -public: -#if !defined(SWIG) - ProxyVideoFrame(const void* pBufferPtr, unsigned nBufferSize, unsigned nFrameWidth, unsigned nFrameHeight, const tsk_object_t* pProtoHdr); -#endif - virtual ~ProxyVideoFrame(); - -public: /* For Java/C# applications */ - unsigned getSize(); - unsigned getContent(void* pOutput, unsigned nMaxsize); - inline unsigned getFrameWidth()const { - return m_nFrameWidth; - } - inline unsigned getFrameHeight()const { - return m_nFrameHeight; - } - -#if !defined(SWIG) /* For C/C++ applications */ -public: - inline unsigned getBufferSize()const { - return m_nBufferSize; - } - inline const void* getBufferPtr()const { - return m_pBufferPtr; - } - inline const tsk_object_t* getProtoHdr()const { - return m_pProtoHdr; - } -#endif - -private: - const void* m_pBufferPtr; - unsigned m_nBufferSize, m_nFrameWidth, m_nFrameHeight; - const tsk_object_t* m_pProtoHdr; -}; - - -#endif /* TINYWRAP_CONSUMER_PROXY_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+/**@file ProxyConsumer.h
+ * @brief Audio/Video proxy consumers.
+ *
+ * @author Mamadou Diop <diopmamadou(at)doubango.org>
+ */
+#ifndef TINYWRAP_CONSUMER_PROXY_H
+#define TINYWRAP_CONSUMER_PROXY_H
+
+#include "tinyWRAP_config.h"
+
+#include "ProxyPluginMgr.h"
+
+#include "tinymedia/tmedia_common.h"
+#include "tinymedia/tmedia_consumer.h"
+
+class AudioResampler;
+
+/* ============ ProxyAudioConsumerCallback Class ================= */
+class ProxyAudioConsumerCallback
+{
+public:
+ ProxyAudioConsumerCallback() { }
+ virtual ~ProxyAudioConsumerCallback() { }
+
+ virtual int prepare(int ptime, int rate, int channels) {
+ return -1;
+ }
+ virtual int start() {
+ return -1;
+ }
+ virtual int pause() {
+ return -1;
+ }
+ virtual int stop() {
+ return -1;
+ }
+#if !defined(SWIG)
+ // whether the audio buffer have to be stored in the JB then pulled using "ProxyAudioConsumer::pull()" or not
+ virtual bool putInJitterBuffer() {
+ return true;
+ }
+ // whether we are using the "telepresence" system (PIVOT audio settings must not be changed)
+ virtual bool isPivotSettings() {
+ return false;
+ }
+ // only called if "putInJitterBuffer()" return "true"
+ virtual int consume(const void* buffer_ptr, tsk_size_t buffer_size, const tsk_object_t* proto_hdr) {
+ return -1;
+ }
+#endif
+};
+
+/* ============ ProxyAudioConsumer Class ================= */
+class ProxyAudioConsumer : public ProxyPlugin
+{
+public:
+#if !defined(SWIG)
+ ProxyAudioConsumer(struct twrap_consumer_proxy_audio_s* pConsumer);
+#endif
+ virtual ~ProxyAudioConsumer();
+ bool setActualSndCardPlaybackParams(int nPtime, int nRate, int nChannels);
+ bool queryForResampler(uint16_t nInFreq, uint16_t nOutFreq, uint16_t nFrameDuration, uint16_t nChannels, uint16_t nResamplerQuality);
+ bool setPullBuffer(const void* pPullBufferPtr, unsigned nPullBufferSize);
+ unsigned pull(void* pOutput=tsk_null, unsigned nSize=0);
+ bool setGain(unsigned nGain);
+ unsigned getGain();
+ bool reset();
+ void setCallback(ProxyAudioConsumerCallback* pCallback) {
+ m_pCallback = pCallback;
+ }
+#if !defined(SWIG)
+ inline ProxyAudioConsumerCallback* getCallback()const {
+ return m_pCallback;
+ }
+ virtual inline bool isWrapping(tsk_object_t* pWrappedPlugin) {
+ return m_pWrappedPlugin == pWrappedPlugin;
+ }
+#endif
+ virtual inline uint64_t getMediaSessionId() {
+ return m_pWrappedPlugin ? TMEDIA_CONSUMER(m_pWrappedPlugin)->session_id : 0;
+ }
+
+public:
+ static bool registerPlugin();
+
+private:
+ struct twrap_consumer_proxy_audio_s* m_pWrappedPlugin;
+ ProxyAudioConsumerCallback* m_pCallback;
+ struct {
+ const void* pPullBufferPtr;
+ unsigned nPullBufferSize;
+ } m_PullBuffer;
+
+ struct {
+ void* pInBufferPtr;
+ unsigned nInBufferSizeInByte;
+ AudioResampler* pResampler;
+ } m_Resampler;
+};
+
+class ProxyVideoFrame;
+
+/* ============ ProxyVideoConsumerCallback Class ================= */
+class ProxyVideoConsumerCallback
+{
+public:
+ ProxyVideoConsumerCallback() {}
+ virtual ~ProxyVideoConsumerCallback() {}
+
+ virtual int prepare(int nWidth, int nHeight, int nFps) {
+ return -1;
+ }
+ virtual int consume(const ProxyVideoFrame* frame) {
+ return -1;
+ }
+ // only called if a buffer is registered using setPullBuffer(). Otherwise, consume() will be called
+ virtual int bufferCopied(unsigned nCopiedSize, unsigned nAvailableSize) {
+ return -1;
+ }
+ virtual int start() {
+ return -1;
+ }
+ virtual int pause() {
+ return -1;
+ }
+ virtual int stop() {
+ return -1;
+ }
+};
+
+/* ============ ProxyVideoConsumer Class ================= */
+class ProxyVideoConsumer : public ProxyPlugin
+{
+public:
+#if !defined(SWIG)
+ ProxyVideoConsumer(tmedia_chroma_t eChroma, struct twrap_consumer_proxy_video_s* pConsumer);
+#endif
+ virtual ~ProxyVideoConsumer();
+
+ bool setDisplaySize(unsigned nWidth, unsigned nHeight);
+ unsigned getDisplayWidth();
+ unsigned getDisplayHeight();
+ unsigned getDecodedWidth();
+ unsigned getDecodedHeight();
+
+ void setCallback(ProxyVideoConsumerCallback* pCallback) {
+ m_pCallback = pCallback;
+ }
+ bool setAutoResizeDisplay(bool bAutoResizeDisplay);
+ bool getAutoResizeDisplay()const;
+ bool setConsumeBuffer(const void* pConsumeBufferPtr, unsigned nConsumeBufferSize);
+ unsigned pull(void* pOutput, unsigned nSize);
+ bool reset();
+
+#if !defined(SWIG)
+ bool hasConsumeBuffer()const {
+ return m_ConsumeBuffer.pConsumeBufferPtr && m_ConsumeBuffer.nConsumeBufferSize;
+ }
+ unsigned copyBuffer(const void* pBuffer, unsigned nSize)const;
+ inline ProxyVideoConsumerCallback* getCallback()const {
+ return m_pCallback;
+ }
+ virtual inline bool isWrapping(tsk_object_t* wrapped_plugin) {
+ return m_pWrappedPlugin == wrapped_plugin;
+ }
+#endif
+ virtual inline uint64_t getMediaSessionId() {
+ return m_pWrappedPlugin ? TMEDIA_CONSUMER(m_pWrappedPlugin)->session_id : 0;
+ }
+
+public:
+ static bool registerPlugin();
+ static void setDefaultChroma(tmedia_chroma_t eChroma) {
+ s_eDefaultChroma = eChroma;
+ }
+ static void setDefaultAutoResizeDisplay(bool bAutoResizeDisplay) {
+ s_bAutoResizeDisplay = bAutoResizeDisplay;
+ }
+
+#if !defined(SWIG)
+ tmedia_chroma_t getChroma()const;
+ static tmedia_chroma_t getDefaultChroma() {
+ return s_eDefaultChroma;
+ }
+ static bool getDefaultAutoResizeDisplay() {
+ return s_bAutoResizeDisplay;
+ }
+#endif
+
+private:
+ struct twrap_consumer_proxy_video_s* m_pWrappedPlugin;
+ tmedia_chroma_t m_eChroma;
+ ProxyVideoConsumerCallback* m_pCallback;
+ struct {
+ const void* pConsumeBufferPtr;
+ unsigned nConsumeBufferSize;
+ } m_ConsumeBuffer;
+ bool m_bAutoResizeDisplay;
+
+ static tmedia_chroma_t s_eDefaultChroma;
+ static bool s_bAutoResizeDisplay;
+};
+
+/* ============ ProxyVideoFrame Class ================= */
+class ProxyVideoFrame
+{
+public:
+#if !defined(SWIG)
+ ProxyVideoFrame(const void* pBufferPtr, unsigned nBufferSize, unsigned nFrameWidth, unsigned nFrameHeight, const tsk_object_t* pProtoHdr);
+#endif
+ virtual ~ProxyVideoFrame();
+
+public: /* For Java/C# applications */
+ unsigned getSize();
+ unsigned getContent(void* pOutput, unsigned nMaxsize);
+ inline unsigned getFrameWidth()const {
+ return m_nFrameWidth;
+ }
+ inline unsigned getFrameHeight()const {
+ return m_nFrameHeight;
+ }
+
+#if !defined(SWIG) /* For C/C++ applications */
+public:
+ inline unsigned getBufferSize()const {
+ return m_nBufferSize;
+ }
+ inline const void* getBufferPtr()const {
+ return m_pBufferPtr;
+ }
+ inline const tsk_object_t* getProtoHdr()const {
+ return m_pProtoHdr;
+ }
+#endif
+
+private:
+ const void* m_pBufferPtr;
+ unsigned m_nBufferSize, m_nFrameWidth, m_nFrameHeight;
+ const tsk_object_t* m_pProtoHdr;
+};
+
+
+#endif /* TINYWRAP_CONSUMER_PROXY_H */
diff --git a/bindings/_common/ProxyPluginMgr.cxx b/bindings/_common/ProxyPluginMgr.cxx index 2191b98..b35597e 100755 --- a/bindings/_common/ProxyPluginMgr.cxx +++ b/bindings/_common/ProxyPluginMgr.cxx @@ -1,308 +1,308 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "ProxyPluginMgr.h" - -#include "ProxyConsumer.h" -#include "ProxyProducer.h" - -// -// "twrap_proxy_plugin_t" Declarations -// -typedef struct twrap_proxy_plugin_s { - TSK_DECLARE_OBJECT; - ProxyPlugin* plugin; -} -twrap_proxy_plugin_t; -#define TWRAP_PROXY_PLUGIN(self) ((twrap_proxy_plugin_t*)(self)) -static int pred_find_plugin_by_value(const tsk_list_item_t *item, const void *proxyPlugin); -static twrap_proxy_plugin_t* twrap_proxy_plugin_create(ProxyPlugin** plugin); - - -// -// "ProxyPluginMgr" Class Implementation -// -ProxyPluginMgr* ProxyPluginMgr::instance = tsk_null; -static uint64_t __uniqueId = 0; - -ProxyPluginMgr::ProxyPluginMgr(ProxyPluginMgrCallback* _callback) - :callback(_callback) -{ - this->plugins = tsk_list_create(); - if(!this->callback) { - TSK_DEBUG_WARN("Callback function is Null => You will have big problems as we won't check it before call"); - } -} - -ProxyPluginMgr::~ProxyPluginMgr() -{ - if(this == ProxyPluginMgr::instance) { - ProxyPluginMgr::instance = tsk_null; - } - TSK_OBJECT_SAFE_FREE(this->plugins); -} - -ProxyPluginMgr* ProxyPluginMgr::createInstance(ProxyPluginMgrCallback* pCallback) -{ - if(!ProxyPluginMgr::instance) { - ProxyPluginMgr::instance = new ProxyPluginMgr(pCallback); - } - else { - TSK_DEBUG_WARN("Plugin instance already exist"); - ProxyPluginMgr::instance->callback = pCallback; - } - return ProxyPluginMgr::instance; -} - -void ProxyPluginMgr::destroyInstance(ProxyPluginMgr** ppInstance) -{ - if(ppInstance && *ppInstance) { - bool bMatch = ProxyPluginMgr::instance && (*ppInstance == ProxyPluginMgr::instance); - delete *ppInstance, *ppInstance = tsk_null; - if(bMatch) { - ProxyPluginMgr::instance = tsk_null; - } - } -} - -ProxyPluginMgr* ProxyPluginMgr::getInstance() -{ - if(!ProxyPluginMgr::instance) { - TSK_DEBUG_ERROR("No instance of the manager could be found"); - } - return ProxyPluginMgr::instance; -} - -uint64_t ProxyPluginMgr::getUniqueId() -{ - return ++__uniqueId; -} - -int ProxyPluginMgr::addPlugin(ProxyPlugin** plugin) -{ - twrap_proxy_plugin_t* twrap_plugin; - int ret = -1; - - tsk_list_lock(this->plugins); - - if(!plugin || !*plugin) { - TSK_DEBUG_ERROR("Invalid parameter"); - goto bail; - } - - if(tsk_list_find_item_by_pred(this->plugins, pred_find_plugin_by_value, *plugin)) { - TSK_DEBUG_ERROR("Plugin already exist"); - goto bail; - } - - if((twrap_plugin = twrap_proxy_plugin_create(plugin))) { - tsk_list_push_back_data(this->plugins, (void**)&twrap_plugin); - ret = 0; - } - else { - TSK_DEBUG_ERROR("Failed to create plugin"); - goto bail; - } - -bail: - tsk_list_unlock(this->plugins); - - return ret; -} - -int ProxyPluginMgr::removePlugin(ProxyPlugin** plugin) -{ - if(!plugin || !*plugin) { - TSK_DEBUG_ERROR("Invalid parameter"); - return -1; - } - return this->removePlugin((*plugin)->getId()); -} - -const ProxyPlugin* ProxyPluginMgr::findPlugin(uint64_t id) -{ - ProxyPlugin* ret = tsk_null; - - tsk_list_item_t* item; - - tsk_list_lock(this->plugins); - tsk_list_foreach(item, this->plugins) { - if(TWRAP_PROXY_PLUGIN(item->data)->plugin->getId() == id) { - ret = TWRAP_PROXY_PLUGIN(item->data)->plugin; - break; - } - } - tsk_list_unlock(this->plugins); - - return ret; -} - -const ProxyPlugin* ProxyPluginMgr::findPlugin(tsk_object_t* wrapped_plugin) -{ - ProxyPlugin* ret = tsk_null; - - tsk_list_item_t* item; - - if(!wrapped_plugin) { - TSK_DEBUG_ERROR("Invalid parameter"); - return tsk_null; - } - - tsk_list_lock(this->plugins); - tsk_list_foreach(item, this->plugins) { - if(TWRAP_PROXY_PLUGIN(item->data)->plugin->isWrapping(wrapped_plugin)) { - ret = TWRAP_PROXY_PLUGIN(item->data)->plugin; - break; - } - } - tsk_list_unlock(this->plugins); - - return ret; -} - -int ProxyPluginMgr::removePlugin(uint64_t id) -{ - tsk_list_item_t* item; - - tsk_list_lock(this->plugins); - - tsk_list_foreach(item, this->plugins) { - if(TWRAP_PROXY_PLUGIN(item->data)->plugin->getId() == id) { - tsk_list_remove_item(this->plugins, item); - break; - } - } - - tsk_list_unlock(this->plugins); - return 0; -} - -const ProxyAudioConsumer* ProxyPluginMgr::findAudioConsumer(uint64_t id) -{ - const ProxyPlugin* audioConsumer = this->findPlugin(id); - if(audioConsumer && audioConsumer->getType() == twrap_proxy_plugin_audio_consumer) { - return dyn_cast<const ProxyAudioConsumer*>(audioConsumer); - } - return tsk_null; -} - -const ProxyVideoConsumer* ProxyPluginMgr::findVideoConsumer(uint64_t id) -{ - const ProxyPlugin* videoConsumer = this->findPlugin(id); - if(videoConsumer && videoConsumer->getType() == twrap_proxy_plugin_video_consumer) { - return dyn_cast<const ProxyVideoConsumer*>(videoConsumer); - } - return tsk_null; -} - -const ProxyAudioProducer* ProxyPluginMgr::findAudioProducer(uint64_t id) -{ - const ProxyPlugin* audioProducer = this->findPlugin(id); - if(audioProducer && audioProducer->getType() == twrap_proxy_plugin_audio_producer) { - return dyn_cast<const ProxyAudioProducer*>(audioProducer); - } - return tsk_null; -} - -const ProxyVideoProducer* ProxyPluginMgr::findVideoProducer(uint64_t id) -{ - const ProxyPlugin* videoProducer = this->findPlugin(id); - if(videoProducer && videoProducer->getType() == twrap_proxy_plugin_video_producer) { - return dyn_cast<const ProxyVideoProducer*>(videoProducer); - } - return tsk_null; -} - - -// -// "twrap_proxy_plugin_t" Implementations -// -static tsk_object_t* twrap_proxy_plugin_ctor(tsk_object_t * self, va_list * app) -{ - twrap_proxy_plugin_t *_self = dyn_cast<twrap_proxy_plugin_t *>(TWRAP_PROXY_PLUGIN(self)); - if(_self) { - } - return self; -} - -static tsk_object_t* twrap_proxy_plugin_dtor(tsk_object_t * self) -{ - twrap_proxy_plugin_t *_self = dyn_cast<twrap_proxy_plugin_t *>(TWRAP_PROXY_PLUGIN(self)); - if(_self) { - if(_self->plugin) { - delete _self->plugin, _self->plugin = tsk_null; - } - } - - return self; -} - -static int twrap_proxy_plugin_cmp(const tsk_object_t *_c1, const tsk_object_t *_c2) -{ - const twrap_proxy_plugin_t *c1 = dyn_cast<const twrap_proxy_plugin_t *>(TWRAP_PROXY_PLUGIN(_c1)); - const twrap_proxy_plugin_t *c2 = dyn_cast<const twrap_proxy_plugin_t *>(TWRAP_PROXY_PLUGIN(_c2)); - - if(c1 && c2) { - return (c1->plugin == c2->plugin); // See "ProxyPlugin::operator ==" - } - else if(!c1 && !c2) { - return 0; - } - else { - return -1; - } -} - -static const tsk_object_def_t twrap_proxy_plugin_def_s = { - sizeof(twrap_proxy_plugin_t), - twrap_proxy_plugin_ctor, - twrap_proxy_plugin_dtor, - twrap_proxy_plugin_cmp, -}; -const tsk_object_def_t *twrap_proxy_plugin_def_t = &twrap_proxy_plugin_def_s; - -static int pred_find_plugin_by_value(const tsk_list_item_t *item, const void *proxyPlugin) -{ - if(item && item->data) { - const twrap_proxy_plugin_t *twrap_plugin = dyn_cast<const twrap_proxy_plugin_t *>(TWRAP_PROXY_PLUGIN(item->data)); - return (twrap_plugin->plugin == dyn_cast<const ProxyPlugin *>((const ProxyPlugin*)proxyPlugin)) ? 0 : -1; - } - return -1; -} - -static twrap_proxy_plugin_t* twrap_proxy_plugin_create(ProxyPlugin** plugin) -{ - if(!plugin || !*plugin) { - TSK_DEBUG_ERROR("Invalid parameter"); - return tsk_null; - } - - twrap_proxy_plugin_t* twrap_plugin = (twrap_proxy_plugin_t*)tsk_object_new(twrap_proxy_plugin_def_t); - if(!twrap_plugin) { - TSK_DEBUG_ERROR("Failed to create new instance of 'twrap_proxy_plugin_t'"); - return tsk_null; - } - - twrap_plugin->plugin = *plugin, - *plugin = tsk_null; - return twrap_plugin; -} - +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "ProxyPluginMgr.h"
+
+#include "ProxyConsumer.h"
+#include "ProxyProducer.h"
+
+//
+// "twrap_proxy_plugin_t" Declarations
+//
+typedef struct twrap_proxy_plugin_s {
+ TSK_DECLARE_OBJECT;
+ ProxyPlugin* plugin;
+}
+twrap_proxy_plugin_t;
+#define TWRAP_PROXY_PLUGIN(self) ((twrap_proxy_plugin_t*)(self))
+static int pred_find_plugin_by_value(const tsk_list_item_t *item, const void *proxyPlugin);
+static twrap_proxy_plugin_t* twrap_proxy_plugin_create(ProxyPlugin** plugin);
+
+
+//
+// "ProxyPluginMgr" Class Implementation
+//
+ProxyPluginMgr* ProxyPluginMgr::instance = tsk_null;
+static uint64_t __uniqueId = 0;
+
+ProxyPluginMgr::ProxyPluginMgr(ProxyPluginMgrCallback* _callback)
+ :callback(_callback)
+{
+ this->plugins = tsk_list_create();
+ if(!this->callback) {
+ TSK_DEBUG_WARN("Callback function is Null => You will have big problems as we won't check it before call");
+ }
+}
+
+ProxyPluginMgr::~ProxyPluginMgr()
+{
+ if(this == ProxyPluginMgr::instance) {
+ ProxyPluginMgr::instance = tsk_null;
+ }
+ TSK_OBJECT_SAFE_FREE(this->plugins);
+}
+
+ProxyPluginMgr* ProxyPluginMgr::createInstance(ProxyPluginMgrCallback* pCallback)
+{
+ if(!ProxyPluginMgr::instance) {
+ ProxyPluginMgr::instance = new ProxyPluginMgr(pCallback);
+ }
+ else {
+ TSK_DEBUG_WARN("Plugin instance already exist");
+ ProxyPluginMgr::instance->callback = pCallback;
+ }
+ return ProxyPluginMgr::instance;
+}
+
+void ProxyPluginMgr::destroyInstance(ProxyPluginMgr** ppInstance)
+{
+ if(ppInstance && *ppInstance) {
+ bool bMatch = ProxyPluginMgr::instance && (*ppInstance == ProxyPluginMgr::instance);
+ delete *ppInstance, *ppInstance = tsk_null;
+ if(bMatch) {
+ ProxyPluginMgr::instance = tsk_null;
+ }
+ }
+}
+
+ProxyPluginMgr* ProxyPluginMgr::getInstance()
+{
+ if(!ProxyPluginMgr::instance) {
+ TSK_DEBUG_ERROR("No instance of the manager could be found");
+ }
+ return ProxyPluginMgr::instance;
+}
+
+uint64_t ProxyPluginMgr::getUniqueId()
+{
+ return ++__uniqueId;
+}
+
+int ProxyPluginMgr::addPlugin(ProxyPlugin** plugin)
+{
+ twrap_proxy_plugin_t* twrap_plugin;
+ int ret = -1;
+
+ tsk_list_lock(this->plugins);
+
+ if(!plugin || !*plugin) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ goto bail;
+ }
+
+ if(tsk_list_find_item_by_pred(this->plugins, pred_find_plugin_by_value, *plugin)) {
+ TSK_DEBUG_ERROR("Plugin already exist");
+ goto bail;
+ }
+
+ if((twrap_plugin = twrap_proxy_plugin_create(plugin))) {
+ tsk_list_push_back_data(this->plugins, (void**)&twrap_plugin);
+ ret = 0;
+ }
+ else {
+ TSK_DEBUG_ERROR("Failed to create plugin");
+ goto bail;
+ }
+
+bail:
+ tsk_list_unlock(this->plugins);
+
+ return ret;
+}
+
+int ProxyPluginMgr::removePlugin(ProxyPlugin** plugin)
+{
+ if(!plugin || !*plugin) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+ return this->removePlugin((*plugin)->getId());
+}
+
+const ProxyPlugin* ProxyPluginMgr::findPlugin(uint64_t id)
+{
+ ProxyPlugin* ret = tsk_null;
+
+ tsk_list_item_t* item;
+
+ tsk_list_lock(this->plugins);
+ tsk_list_foreach(item, this->plugins) {
+ if(TWRAP_PROXY_PLUGIN(item->data)->plugin->getId() == id) {
+ ret = TWRAP_PROXY_PLUGIN(item->data)->plugin;
+ break;
+ }
+ }
+ tsk_list_unlock(this->plugins);
+
+ return ret;
+}
+
+const ProxyPlugin* ProxyPluginMgr::findPlugin(tsk_object_t* wrapped_plugin)
+{
+ ProxyPlugin* ret = tsk_null;
+
+ tsk_list_item_t* item;
+
+ if(!wrapped_plugin) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return tsk_null;
+ }
+
+ tsk_list_lock(this->plugins);
+ tsk_list_foreach(item, this->plugins) {
+ if(TWRAP_PROXY_PLUGIN(item->data)->plugin->isWrapping(wrapped_plugin)) {
+ ret = TWRAP_PROXY_PLUGIN(item->data)->plugin;
+ break;
+ }
+ }
+ tsk_list_unlock(this->plugins);
+
+ return ret;
+}
+
+int ProxyPluginMgr::removePlugin(uint64_t id)
+{
+ tsk_list_item_t* item;
+
+ tsk_list_lock(this->plugins);
+
+ tsk_list_foreach(item, this->plugins) {
+ if(TWRAP_PROXY_PLUGIN(item->data)->plugin->getId() == id) {
+ tsk_list_remove_item(this->plugins, item);
+ break;
+ }
+ }
+
+ tsk_list_unlock(this->plugins);
+ return 0;
+}
+
+const ProxyAudioConsumer* ProxyPluginMgr::findAudioConsumer(uint64_t id)
+{
+ const ProxyPlugin* audioConsumer = this->findPlugin(id);
+ if(audioConsumer && audioConsumer->getType() == twrap_proxy_plugin_audio_consumer) {
+ return dyn_cast<const ProxyAudioConsumer*>(audioConsumer);
+ }
+ return tsk_null;
+}
+
+const ProxyVideoConsumer* ProxyPluginMgr::findVideoConsumer(uint64_t id)
+{
+ const ProxyPlugin* videoConsumer = this->findPlugin(id);
+ if(videoConsumer && videoConsumer->getType() == twrap_proxy_plugin_video_consumer) {
+ return dyn_cast<const ProxyVideoConsumer*>(videoConsumer);
+ }
+ return tsk_null;
+}
+
+const ProxyAudioProducer* ProxyPluginMgr::findAudioProducer(uint64_t id)
+{
+ const ProxyPlugin* audioProducer = this->findPlugin(id);
+ if(audioProducer && audioProducer->getType() == twrap_proxy_plugin_audio_producer) {
+ return dyn_cast<const ProxyAudioProducer*>(audioProducer);
+ }
+ return tsk_null;
+}
+
+const ProxyVideoProducer* ProxyPluginMgr::findVideoProducer(uint64_t id)
+{
+ const ProxyPlugin* videoProducer = this->findPlugin(id);
+ if(videoProducer && videoProducer->getType() == twrap_proxy_plugin_video_producer) {
+ return dyn_cast<const ProxyVideoProducer*>(videoProducer);
+ }
+ return tsk_null;
+}
+
+
+//
+// "twrap_proxy_plugin_t" Implementations
+//
+static tsk_object_t* twrap_proxy_plugin_ctor(tsk_object_t * self, va_list * app)
+{
+ twrap_proxy_plugin_t *_self = dyn_cast<twrap_proxy_plugin_t *>(TWRAP_PROXY_PLUGIN(self));
+ if(_self) {
+ }
+ return self;
+}
+
+static tsk_object_t* twrap_proxy_plugin_dtor(tsk_object_t * self)
+{
+ twrap_proxy_plugin_t *_self = dyn_cast<twrap_proxy_plugin_t *>(TWRAP_PROXY_PLUGIN(self));
+ if(_self) {
+ if(_self->plugin) {
+ delete _self->plugin, _self->plugin = tsk_null;
+ }
+ }
+
+ return self;
+}
+
+static int twrap_proxy_plugin_cmp(const tsk_object_t *_c1, const tsk_object_t *_c2)
+{
+ const twrap_proxy_plugin_t *c1 = dyn_cast<const twrap_proxy_plugin_t *>(TWRAP_PROXY_PLUGIN(_c1));
+ const twrap_proxy_plugin_t *c2 = dyn_cast<const twrap_proxy_plugin_t *>(TWRAP_PROXY_PLUGIN(_c2));
+
+ if(c1 && c2) {
+ return (c1->plugin == c2->plugin); // See "ProxyPlugin::operator =="
+ }
+ else if(!c1 && !c2) {
+ return 0;
+ }
+ else {
+ return -1;
+ }
+}
+
+static const tsk_object_def_t twrap_proxy_plugin_def_s = {
+ sizeof(twrap_proxy_plugin_t),
+ twrap_proxy_plugin_ctor,
+ twrap_proxy_plugin_dtor,
+ twrap_proxy_plugin_cmp,
+};
+const tsk_object_def_t *twrap_proxy_plugin_def_t = &twrap_proxy_plugin_def_s;
+
+static int pred_find_plugin_by_value(const tsk_list_item_t *item, const void *proxyPlugin)
+{
+ if(item && item->data) {
+ const twrap_proxy_plugin_t *twrap_plugin = dyn_cast<const twrap_proxy_plugin_t *>(TWRAP_PROXY_PLUGIN(item->data));
+ return (twrap_plugin->plugin == dyn_cast<const ProxyPlugin *>((const ProxyPlugin*)proxyPlugin)) ? 0 : -1;
+ }
+ return -1;
+}
+
+static twrap_proxy_plugin_t* twrap_proxy_plugin_create(ProxyPlugin** plugin)
+{
+ if(!plugin || !*plugin) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return tsk_null;
+ }
+
+ twrap_proxy_plugin_t* twrap_plugin = (twrap_proxy_plugin_t*)tsk_object_new(twrap_proxy_plugin_def_t);
+ if(!twrap_plugin) {
+ TSK_DEBUG_ERROR("Failed to create new instance of 'twrap_proxy_plugin_t'");
+ return tsk_null;
+ }
+
+ twrap_plugin->plugin = *plugin,
+ *plugin = tsk_null;
+ return twrap_plugin;
+}
+
diff --git a/bindings/_common/ProxyPluginMgr.h b/bindings/_common/ProxyPluginMgr.h index 1bfd117..f8cdb43 100755 --- a/bindings/_common/ProxyPluginMgr.h +++ b/bindings/_common/ProxyPluginMgr.h @@ -1,137 +1,137 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_PROXY_PLUGIN_MGR_H -#define TINYWRAP_PROXY_PLUGIN_MGR_H - -#include "tinymedia.h" -#include "Common.h" - -class ProxyPlugin; -class ProxyConsumer; -class ProxyAudioConsumer; -class ProxyVideoConsumer; -class ProxyAudioProducer; -class ProxyVideoProducer; -class ProxyPluginMgrCallback; - -typedef enum twrap_proxy_plugin_type_e { - twrap_proxy_plugin_audio_producer, - twrap_proxy_plugin_video_producer, - twrap_proxy_plugin_audio_consumer, - twrap_proxy_plugin_video_consumer, -} -twrap_proxy_plugin_type_t; - -/* ============ ProxyPluginMgr Class ================= */ - -typedef tsk_list_t twrap_proxy_plungins_L_t; // contains "twrap_proxy_plungin_t" elements - -class ProxyPluginMgr -{ -private: - ProxyPluginMgr(ProxyPluginMgrCallback* callback); -public: - virtual ~ProxyPluginMgr(); - - // SWIG %newobject - static ProxyPluginMgr* createInstance(ProxyPluginMgrCallback* pCallback); -#if !defined(SWIG) - static void destroyInstance(ProxyPluginMgr** ppInstance); -#endif - static ProxyPluginMgr* getInstance(); - -#if !defined(SWIG) - static uint64_t getUniqueId(); - - int addPlugin(ProxyPlugin**); - const ProxyPlugin* findPlugin(tsk_object_t* wrapped_plugin); - int removePlugin(uint64_t id); - int removePlugin(ProxyPlugin**); - - inline ProxyPluginMgrCallback* getCallback() { - return this->callback; - } -#endif - - const ProxyPlugin* findPlugin(uint64_t id); - - const ProxyAudioConsumer* findAudioConsumer(uint64_t id); - const ProxyVideoConsumer* findVideoConsumer(uint64_t id); - const ProxyAudioProducer* findAudioProducer(uint64_t id); - const ProxyVideoProducer* findVideoProducer(uint64_t id); - -private: - static ProxyPluginMgr* instance; - ProxyPluginMgrCallback* callback; - - twrap_proxy_plungins_L_t* plugins; -}; - - -/* ============ ProxyPluginMgrCallback Class ================= */ -class ProxyPluginMgrCallback -{ -public: - ProxyPluginMgrCallback() { } - virtual ~ProxyPluginMgrCallback() { } - - virtual int OnPluginCreated(uint64_t id, enum twrap_proxy_plugin_type_e type) { - return -1; - } - virtual int OnPluginDestroyed(uint64_t id, enum twrap_proxy_plugin_type_e type) { - return -1; - } -}; - -/* ============ ProxyPlugin Class ================= */ -class ProxyPlugin -{ -public: -#if !defined SWIG - ProxyPlugin(twrap_proxy_plugin_type_t _type) { - this->type=_type; - this->id = ProxyPluginMgr::getUniqueId(); - } -#endif - virtual ~ProxyPlugin() {} - -#if !defined(SWIG) - virtual bool operator ==(const ProxyPlugin &plugin)const { - return this->getId() == plugin.getId(); - } - virtual inline bool isWrapping(tsk_object_t* wrapped_plugin) = 0; - virtual inline uint64_t getMediaSessionId() = 0; -#endif - - inline twrap_proxy_plugin_type_t getType()const { - return this->type; - } - inline uint64_t getId()const { - return this->id; - } - -protected: - uint64_t id; - twrap_proxy_plugin_type_t type; -}; - -#endif /* TINYWRAP_PROXY_PLUGIN_MGR_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_PROXY_PLUGIN_MGR_H
+#define TINYWRAP_PROXY_PLUGIN_MGR_H
+
+#include "tinymedia.h"
+#include "Common.h"
+
+class ProxyPlugin;
+class ProxyConsumer;
+class ProxyAudioConsumer;
+class ProxyVideoConsumer;
+class ProxyAudioProducer;
+class ProxyVideoProducer;
+class ProxyPluginMgrCallback;
+
+typedef enum twrap_proxy_plugin_type_e {
+ twrap_proxy_plugin_audio_producer,
+ twrap_proxy_plugin_video_producer,
+ twrap_proxy_plugin_audio_consumer,
+ twrap_proxy_plugin_video_consumer,
+}
+twrap_proxy_plugin_type_t;
+
+/* ============ ProxyPluginMgr Class ================= */
+
+typedef tsk_list_t twrap_proxy_plungins_L_t; // contains "twrap_proxy_plungin_t" elements
+
+class ProxyPluginMgr
+{
+private:
+ ProxyPluginMgr(ProxyPluginMgrCallback* callback);
+public:
+ virtual ~ProxyPluginMgr();
+
+ // SWIG %newobject
+ static ProxyPluginMgr* createInstance(ProxyPluginMgrCallback* pCallback);
+#if !defined(SWIG)
+ static void destroyInstance(ProxyPluginMgr** ppInstance);
+#endif
+ static ProxyPluginMgr* getInstance();
+
+#if !defined(SWIG)
+ static uint64_t getUniqueId();
+
+ int addPlugin(ProxyPlugin**);
+ const ProxyPlugin* findPlugin(tsk_object_t* wrapped_plugin);
+ int removePlugin(uint64_t id);
+ int removePlugin(ProxyPlugin**);
+
+ inline ProxyPluginMgrCallback* getCallback() {
+ return this->callback;
+ }
+#endif
+
+ const ProxyPlugin* findPlugin(uint64_t id);
+
+ const ProxyAudioConsumer* findAudioConsumer(uint64_t id);
+ const ProxyVideoConsumer* findVideoConsumer(uint64_t id);
+ const ProxyAudioProducer* findAudioProducer(uint64_t id);
+ const ProxyVideoProducer* findVideoProducer(uint64_t id);
+
+private:
+ static ProxyPluginMgr* instance;
+ ProxyPluginMgrCallback* callback;
+
+ twrap_proxy_plungins_L_t* plugins;
+};
+
+
+/* ============ ProxyPluginMgrCallback Class ================= */
+class ProxyPluginMgrCallback
+{
+public:
+ ProxyPluginMgrCallback() { }
+ virtual ~ProxyPluginMgrCallback() { }
+
+ virtual int OnPluginCreated(uint64_t id, enum twrap_proxy_plugin_type_e type) {
+ return -1;
+ }
+ virtual int OnPluginDestroyed(uint64_t id, enum twrap_proxy_plugin_type_e type) {
+ return -1;
+ }
+};
+
+/* ============ ProxyPlugin Class ================= */
+class ProxyPlugin
+{
+public:
+#if !defined SWIG
+ ProxyPlugin(twrap_proxy_plugin_type_t _type) {
+ this->type=_type;
+ this->id = ProxyPluginMgr::getUniqueId();
+ }
+#endif
+ virtual ~ProxyPlugin() {}
+
+#if !defined(SWIG)
+ virtual bool operator ==(const ProxyPlugin &plugin)const {
+ return this->getId() == plugin.getId();
+ }
+ virtual inline bool isWrapping(tsk_object_t* wrapped_plugin) = 0;
+ virtual inline uint64_t getMediaSessionId() = 0;
+#endif
+
+ inline twrap_proxy_plugin_type_t getType()const {
+ return this->type;
+ }
+ inline uint64_t getId()const {
+ return this->id;
+ }
+
+protected:
+ uint64_t id;
+ twrap_proxy_plugin_type_t type;
+};
+
+#endif /* TINYWRAP_PROXY_PLUGIN_MGR_H */
diff --git a/bindings/_common/ProxyProducer.cxx b/bindings/_common/ProxyProducer.cxx index 087a2d2..1fe7a5d 100755 --- a/bindings/_common/ProxyProducer.cxx +++ b/bindings/_common/ProxyProducer.cxx @@ -1,620 +1,620 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ - -/**@file ProxyProducer.c - * @brief Audio/Video proxy producers. - * - * @author Mamadou Diop <diopmamadou(at)doubango.org> - * - - */ -#include "ProxyProducer.h" - -#include "tsk_timer.h" -#include "tsk_memory.h" -#include "tsk_debug.h" - -#include "tinydav/audio/tdav_producer_audio.h" - - -/* ============ Audio Media Producer Interface ================= */ -typedef struct twrap_producer_proxy_audio_s { - TDAV_DECLARE_PRODUCER_AUDIO; - - uint64_t id; - tsk_bool_t started; -} -twrap_producer_proxy_audio_t; -#define TWRAP_PRODUCER_PROXY_AUDIO(self) ((twrap_producer_proxy_audio_t*)(self)) - -static int twrap_producer_proxy_audio_set(tmedia_producer_t* _self, const tmedia_param_t* param) -{ - twrap_producer_proxy_audio_t* self = (twrap_producer_proxy_audio_t*)_self; - if(param->plugin_type == tmedia_ppt_producer) { - // specific proxy producer - } - return tdav_producer_audio_set(TDAV_PRODUCER_AUDIO(self), param); -} - -static int twrap_producer_proxy_audio_prepare(tmedia_producer_t* self, const tmedia_codec_t* codec) -{ - ProxyPluginMgr* manager; - int ret = -1; - if(codec && (manager = ProxyPluginMgr::getInstance())) { - const ProxyAudioProducer* audioProducer; - if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()) { - self->audio.channels = TMEDIA_CODEC_CHANNELS_AUDIO_ENCODING(codec); - self->audio.rate = TMEDIA_CODEC_RATE_ENCODING(codec); - self->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_ENCODING(codec); - ret = audioProducer->getCallback()->prepare((int)self->audio.ptime, self->audio.rate, self->audio.channels); - } - } - return ret; -} - -static int twrap_producer_proxy_audio_start(tmedia_producer_t* self) -{ - ProxyPluginMgr* manager; - int ret = -1; - if((manager = ProxyPluginMgr::getInstance())) { - const ProxyAudioProducer* audioProducer; - if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()) { - const_cast<ProxyAudioProducer*>(audioProducer)->startPushCallback(); - ret = audioProducer->getCallback()->start(); - } - } - - TWRAP_PRODUCER_PROXY_AUDIO(self)->started = (ret == 0); - return ret; -} - -static int twrap_producer_proxy_audio_pause(tmedia_producer_t* self) -{ - ProxyPluginMgr* manager; - int ret = -1; - if((manager = ProxyPluginMgr::getInstance())) { - const ProxyAudioProducer* audioProducer; - if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()) { - ret = audioProducer->getCallback()->pause(); - } - } - return ret; -} - -static int twrap_producer_proxy_audio_stop(tmedia_producer_t* self) -{ - ProxyPluginMgr* manager; - int ret = -1; - if((manager = ProxyPluginMgr::getInstance())) { - const ProxyAudioProducer* audioProducer; - if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()) { - const_cast<ProxyAudioProducer*>(audioProducer)->stopPushCallback(); - ret = audioProducer->getCallback()->stop(); - } - } - TWRAP_PRODUCER_PROXY_AUDIO(self)->started = (ret == 0) ? tsk_false : tsk_true; - return ret; -} - - -// -// Audio producer object definition -// -/* constructor */ -static tsk_object_t* twrap_producer_proxy_audio_ctor(tsk_object_t * self, va_list * app) -{ - twrap_producer_proxy_audio_t *producer = (twrap_producer_proxy_audio_t *)self; - if(producer) { - /* init base */ - tdav_producer_audio_init(TDAV_PRODUCER_AUDIO(producer)); - /* init self */ - - /* Add the plugin to the manager */ - ProxyPluginMgr* manager = ProxyPluginMgr::getInstance(); - if(manager) { - ProxyPlugin* proxyProducer = new ProxyAudioProducer(producer); - uint64_t id = proxyProducer->getId(); - manager->addPlugin(&proxyProducer); - manager->getCallback()->OnPluginCreated(id, twrap_proxy_plugin_audio_producer); - } - } - return self; -} -/* destructor */ -static tsk_object_t* twrap_producer_proxy_audio_dtor(tsk_object_t * self) -{ - twrap_producer_proxy_audio_t *producer = (twrap_producer_proxy_audio_t *)self; - if(producer) { - - /* stop */ - if(producer->started) { - twrap_producer_proxy_audio_stop(TMEDIA_PRODUCER(producer)); - } - - /* deinit base */ - tdav_producer_audio_deinit(TDAV_PRODUCER_AUDIO(producer)); - /* deinit self */ - - /* Remove plugin from the manager */ - ProxyPluginMgr* manager = ProxyPluginMgr::getInstance(); - if(manager) { - manager->getCallback()->OnPluginDestroyed(producer->id, twrap_proxy_plugin_audio_producer); - manager->removePlugin(producer->id); - } - } - - return self; -} -/* object definition */ -static const tsk_object_def_t twrap_producer_proxy_audio_def_s = { - sizeof(twrap_producer_proxy_audio_t), - twrap_producer_proxy_audio_ctor, - twrap_producer_proxy_audio_dtor, - tdav_producer_audio_cmp, -}; -/* plugin definition*/ -static const tmedia_producer_plugin_def_t twrap_producer_proxy_audio_plugin_def_s = { - &twrap_producer_proxy_audio_def_s, - - tmedia_audio, - "Audio Proxy Producer", - - twrap_producer_proxy_audio_set, - twrap_producer_proxy_audio_prepare, - twrap_producer_proxy_audio_start, - twrap_producer_proxy_audio_pause, - twrap_producer_proxy_audio_stop -}; - -/*TINYWRAP_GEXTERN*/ const tmedia_producer_plugin_def_t *twrap_producer_proxy_audio_plugin_def_t = &twrap_producer_proxy_audio_plugin_def_s; - - - -/* ============ ProxyAudioProducer Class ================= */ -ProxyAudioProducer::ProxyAudioProducer(twrap_producer_proxy_audio_t* pProducer) - :m_pCallback(tsk_null), m_pWrappedPlugin(pProducer), m_bUsePushCallback(false), m_hPushTimerMgr(tsk_null), ProxyPlugin(twrap_proxy_plugin_audio_producer) -{ - m_pWrappedPlugin->id = this->getId(); - m_PushBuffer.pPushBufferPtr = tsk_null; - m_PushBuffer.nPushBufferSize = 0; -} - -ProxyAudioProducer::~ProxyAudioProducer() -{ - stopPushCallback(); -} - -// Use this function to request resampling when your sound card can't honor negotaited record parameters -bool ProxyAudioProducer::setActualSndCardRecordParams(int nPtime, int nRate, int nChannels) -{ - if(m_pWrappedPlugin) { - TSK_DEBUG_INFO("setActualSndCardRecordParams(ptime=%d, rate=%d, channels=%d)", nPtime, nRate, nChannels); - TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.ptime = nPtime; - TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.rate = nRate; - TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.channels = nChannels; - return true; - } - else { - TSK_DEBUG_ERROR("Invalid state"); - return false; - } -} - -bool ProxyAudioProducer::setPushBuffer(const void* pPushBufferPtr, unsigned nPushBufferSize, bool bUsePushCallback/*=false*/) -{ - m_PushBuffer.pPushBufferPtr = pPushBufferPtr; - m_PushBuffer.nPushBufferSize = nPushBufferSize; - m_bUsePushCallback = bUsePushCallback; - - if(!pPushBufferPtr || !nPushBufferSize || !bUsePushCallback) { - return stopPushCallback(); - } - else if(m_bUsePushCallback && m_pWrappedPlugin && m_pWrappedPlugin->started) { - return startPushCallback(); - } - return true; -} - -int ProxyAudioProducer::push(const void* _pBuffer/*=tsk_null*/, unsigned _nSize/*=0*/) -{ - if(m_pWrappedPlugin && TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback) { - const void* pBuffer; - unsigned nSize; - if(_pBuffer && _nSize) { - pBuffer = _pBuffer, nSize = _nSize; - } - else { - pBuffer = m_PushBuffer.pPushBufferPtr, nSize = m_PushBuffer.nPushBufferSize; - } - return TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback(TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback_data, pBuffer, nSize); - } - return 0; -} - -bool ProxyAudioProducer::setGain(unsigned nGain) -{ - if(m_pWrappedPlugin) { - // see also: MediaSessionMgr.producerSetInt32(org.doubango.tinyWRAP.twrap_media_type_t.twrap_media_audio, "gain", nGain); - TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.gain = TSK_MIN(nGain,14); - return true; - } - return false; -} - -unsigned ProxyAudioProducer::getGain() -{ - if(m_pWrappedPlugin) { - return TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.gain; - } - return 0; -} - -bool ProxyAudioProducer::startPushCallback() -{ - if(!m_bUsePushCallback) { - return true; - } - - if(!m_pWrappedPlugin) { - TSK_DEBUG_ERROR("Not wrapping plugin"); - return false; - } - - if(!m_hPushTimerMgr) { - if(!(m_hPushTimerMgr = tsk_timer_manager_create())) { - TSK_DEBUG_ERROR("Failed to create timer manager"); - return false; - } - } - - if(!TSK_RUNNABLE(m_hPushTimerMgr)->started) { - if((tsk_timer_manager_start(m_hPushTimerMgr)) == 0) { - m_uPushTimer = tsk_timer_manager_schedule(m_hPushTimerMgr, TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.ptime, &ProxyAudioProducer::pushTimerCallback, this); - } - else { - TSK_DEBUG_ERROR("Failed to start timer"); - return false; - } - } - return true; -} - -bool ProxyAudioProducer::stopPushCallback() -{ - if(m_hPushTimerMgr) { - tsk_timer_manager_destroy(&m_hPushTimerMgr); - } - return true; -} - -int ProxyAudioProducer::pushTimerCallback(const void* arg, tsk_timer_id_t timer_id) -{ - ProxyAudioProducer* This = (ProxyAudioProducer*)arg; - - This->m_uPushTimer = tsk_timer_manager_schedule(This->m_hPushTimerMgr, TMEDIA_PRODUCER(This->m_pWrappedPlugin)->audio.ptime, &ProxyAudioProducer::pushTimerCallback, This); - - if(This->m_pCallback) { - if(This->m_pCallback->fillPushBuffer() == 0) { - return This->push(); - } - } - return 0; -} - -bool ProxyAudioProducer::registerPlugin() -{ - /* HACK: Unregister all other audio plugins */ - tmedia_producer_plugin_unregister_by_type(tmedia_audio); - /* Register our proxy plugin */ - return (tmedia_producer_plugin_register(twrap_producer_proxy_audio_plugin_def_t) == 0); -} - - - - - - - - - - - - - - - - - - - - - - - -/* ============ Video Media Producer Interface ================= */ -typedef struct twrap_producer_proxy_video_s { - TMEDIA_DECLARE_PRODUCER; - - int rotation; - uint64_t id; - tsk_bool_t started; -#if 0 - // https://code.google.com/p/doubango/issues/detail?id=416 - // The lock on the producer is useless because all tinyDAV proxied functions (push(), stop(), prepare()...) are already thread safe. - // Locking the push method while tinDAV locks the stop() function produce a deadlock on Android devices with slow video producer implementations (e.g. Hovis Box v1) - TSK_DECLARE_SAFEOBJ; -#endif -} -twrap_producer_proxy_video_t; -#define TWRAP_PRODUCER_PROXY_VIDEO(self) ((twrap_producer_proxy_video_t*)(self)) - -int twrap_producer_proxy_video_set(tmedia_producer_t* self, const tmedia_param_t* params) -{ - return 0; -} - -int twrap_producer_proxy_video_prepare(tmedia_producer_t* self, const tmedia_codec_t* codec) -{ - ProxyPluginMgr* manager; - int ret = -1; - if(codec && (manager = ProxyPluginMgr::getInstance())) { - const ProxyVideoProducer* videoProducer; - if((videoProducer = manager->findVideoProducer(TWRAP_PRODUCER_PROXY_VIDEO(self)->id)) && videoProducer->getCallback()) { - self->video.chroma = videoProducer->getChroma(); - self->video.rotation = videoProducer->getRotation(); - ret = videoProducer->getCallback()->prepare(TMEDIA_CODEC_VIDEO(codec)->out.width, TMEDIA_CODEC_VIDEO(codec)->out.height, TMEDIA_CODEC_VIDEO(codec)->out.fps); - } - } - - return ret; -} - -int twrap_producer_proxy_video_start(tmedia_producer_t* self) -{ - ProxyPluginMgr* manager; - int ret = -1; - if((manager = ProxyPluginMgr::getInstance())) { - const ProxyVideoProducer* videoProducer; - if((videoProducer = manager->findVideoProducer(TWRAP_PRODUCER_PROXY_VIDEO(self)->id)) && videoProducer->getCallback()) { - ret = videoProducer->getCallback()->start(); - TWRAP_PRODUCER_PROXY_VIDEO(self)->started = (ret == 0); - } - } - - return ret; -} - -int twrap_producer_proxy_video_pause(tmedia_producer_t* self) -{ - ProxyPluginMgr* manager; - int ret = -1; - if((manager = ProxyPluginMgr::getInstance())) { - const ProxyVideoProducer* videoProducer; - if((videoProducer = manager->findVideoProducer(TWRAP_PRODUCER_PROXY_VIDEO(self)->id)) && videoProducer->getCallback()) { - ret = videoProducer->getCallback()->pause(); - } - } - - return ret; -} - -int twrap_producer_proxy_video_stop(tmedia_producer_t* self) -{ - ProxyPluginMgr* manager; - int ret = -1; - if((manager = ProxyPluginMgr::getInstance())) { - const ProxyVideoProducer* videoProducer; - if((videoProducer = manager->findVideoProducer(TWRAP_PRODUCER_PROXY_VIDEO(self)->id)) && videoProducer->getCallback()) { - ret = videoProducer->getCallback()->stop(); - TWRAP_PRODUCER_PROXY_VIDEO(self)->started = ((ret == 0) ? tsk_false : tsk_true); - } - } - - return ret; -} - - -// -// Video producer object definition -// -/* constructor */ -static tsk_object_t* twrap_producer_proxy_video_ctor(tsk_object_t * self, va_list * app) -{ - twrap_producer_proxy_video_t *producer = (twrap_producer_proxy_video_t *)self; - if(producer) { - /* init base */ - tmedia_producer_init(TMEDIA_PRODUCER(producer)); - /* init self */ - - /* Add the plugin to the manager */ - ProxyPluginMgr* manager = ProxyPluginMgr::getInstance(); - if(manager) { - ProxyPlugin* proxyProducer = new ProxyVideoProducer(ProxyVideoProducer::getDefaultChroma(), producer); - uint64_t id = proxyProducer->getId(); - manager->addPlugin(&proxyProducer); - manager->getCallback()->OnPluginCreated(id, twrap_proxy_plugin_video_producer); - } - } - return self; -} -/* destructor */ -static tsk_object_t* twrap_producer_proxy_video_dtor(tsk_object_t * self) -{ - twrap_producer_proxy_video_t *producer = (twrap_producer_proxy_video_t *)self; - if(producer) { - TSK_DEBUG_INFO("twrap_producer_proxy_video_dtor()"); - /* stop */ - if(producer->started) { - twrap_producer_proxy_video_stop(TMEDIA_PRODUCER(producer)); - } - - /* deinit base */ - tmedia_producer_deinit(TMEDIA_PRODUCER(producer)); - /* deinit self */ - - /* Remove plugin from the manager */ - ProxyPluginMgr* manager = ProxyPluginMgr::getInstance(); - if(manager) { - manager->getCallback()->OnPluginDestroyed(producer->id, twrap_proxy_plugin_video_producer); - manager->removePlugin(producer->id); - } - } - - return self; -} -/* object definition */ -static const tsk_object_def_t twrap_producer_proxy_video_def_s = { - sizeof(twrap_producer_proxy_video_t), - twrap_producer_proxy_video_ctor, - twrap_producer_proxy_video_dtor, - tsk_null, -}; -/* plugin definition*/ -static const tmedia_producer_plugin_def_t twrap_producer_proxy_video_plugin_def_s = { - &twrap_producer_proxy_video_def_s, - - tmedia_video, - "Video Proxy Producer", - - twrap_producer_proxy_video_set, - twrap_producer_proxy_video_prepare, - twrap_producer_proxy_video_start, - twrap_producer_proxy_video_pause, - twrap_producer_proxy_video_stop -}; - -/*TINYWRAP_GEXTERN*/ const tmedia_producer_plugin_def_t *twrap_producer_proxy_video_plugin_def_t = &twrap_producer_proxy_video_plugin_def_s; - - - -/* ============ ProxyVideoProducer Class ================= */ -tmedia_chroma_t ProxyVideoProducer::s_eDefaultChroma = tmedia_chroma_nv21; - -ProxyVideoProducer::ProxyVideoProducer(tmedia_chroma_t eChroma, struct twrap_producer_proxy_video_s* pProducer) - :m_pCallback(tsk_null), m_eChroma(eChroma), m_nRotation(0), m_bMirror(false), m_pWrappedPlugin(pProducer), ProxyPlugin(twrap_proxy_plugin_video_producer) -{ - if(m_pWrappedPlugin) { - m_pWrappedPlugin->id = this->getId(); - } -} - -ProxyVideoProducer::~ProxyVideoProducer() -{ - TSK_DEBUG_INFO("~ProxyVideoProducer"); -} - -int ProxyVideoProducer::getRotation()const -{ - return m_nRotation; -} - -bool ProxyVideoProducer::setRotation(int nRot) -{ - m_nRotation = nRot; - if (m_pWrappedPlugin) { - TMEDIA_PRODUCER(m_pWrappedPlugin)->video.rotation = m_nRotation; - return true; - } - return false; -} - -bool ProxyVideoProducer::getMirror()const -{ - return m_bMirror; -} - -bool ProxyVideoProducer::setMirror(bool bMirror) -{ - m_bMirror = bMirror; - if (m_pWrappedPlugin) { - TMEDIA_PRODUCER(m_pWrappedPlugin)->video.mirror = m_bMirror ? tsk_true : tsk_false; - return true; - } - return false; -} - -// alert the encoder which size your camera is using because it's very hard to retrieve it from send(buffer, size) function -// this function is only needed if the actual size (output from your camera) is different than the negociated one -bool ProxyVideoProducer::setActualCameraOutputSize(unsigned nWidth, unsigned nHeight) -{ - if(m_pWrappedPlugin) { - TMEDIA_PRODUCER(m_pWrappedPlugin)->video.width = nWidth; - TMEDIA_PRODUCER(m_pWrappedPlugin)->video.height = nHeight; - return true; - } - return false; -} - -// encode() then send() -int ProxyVideoProducer::push(const void* pBuffer, unsigned nSize) -{ - if (m_pWrappedPlugin && TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback) { - int ret = -1; - if (m_pWrappedPlugin->started) { - ret = TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback(TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback_data, pBuffer, nSize); - } - return ret; - } - return 0; -} - -// send() "as is" -// only used by telepresence system with a H.264 SVC hardaware encoder -int ProxyVideoProducer::sendRaw(const void* pBuffer, unsigned nSize, unsigned nDuration, bool bMarker) -{ - if(m_pWrappedPlugin && TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.callback) { - //tmedia_video_encode_result_reset(&TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr); - - TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.buffer.ptr = pBuffer; - TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.buffer.size = nSize; - TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.duration = nDuration; - TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.last_chunck = (bMarker == true); - return TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.callback(&TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr); - } - return 0; -} - -int ProxyVideoProducer::sendRaw(const void* pBuffer, unsigned nSize, const void* proto_hdr) -{ - if(m_pWrappedPlugin && TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.callback) { - //tmedia_video_encode_result_reset(&TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr); - - TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.buffer.ptr = pBuffer; - TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.buffer.size = nSize; - TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.proto_hdr = proto_hdr; - return TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.callback(&TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr); - } - return 0; -} - -tmedia_chroma_t ProxyVideoProducer::getChroma()const -{ - return m_eChroma; -} - -bool ProxyVideoProducer::registerPlugin() -{ - /* HACK: Unregister all other video plugins */ - tmedia_producer_plugin_unregister_by_type(tmedia_video); - /* Register our proxy plugin */ - return (tmedia_producer_plugin_register(twrap_producer_proxy_video_plugin_def_t) == 0); -} +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+/**@file ProxyProducer.c
+ * @brief Audio/Video proxy producers.
+ *
+ * @author Mamadou Diop <diopmamadou(at)doubango.org>
+ *
+
+ */
+#include "ProxyProducer.h"
+
+#include "tsk_timer.h"
+#include "tsk_memory.h"
+#include "tsk_debug.h"
+
+#include "tinydav/audio/tdav_producer_audio.h"
+
+
+/* ============ Audio Media Producer Interface ================= */
+typedef struct twrap_producer_proxy_audio_s {
+ TDAV_DECLARE_PRODUCER_AUDIO;
+
+ uint64_t id;
+ tsk_bool_t started;
+}
+twrap_producer_proxy_audio_t;
+#define TWRAP_PRODUCER_PROXY_AUDIO(self) ((twrap_producer_proxy_audio_t*)(self))
+
+static int twrap_producer_proxy_audio_set(tmedia_producer_t* _self, const tmedia_param_t* param)
+{
+ twrap_producer_proxy_audio_t* self = (twrap_producer_proxy_audio_t*)_self;
+ if(param->plugin_type == tmedia_ppt_producer) {
+ // specific proxy producer
+ }
+ return tdav_producer_audio_set(TDAV_PRODUCER_AUDIO(self), param);
+}
+
+static int twrap_producer_proxy_audio_prepare(tmedia_producer_t* self, const tmedia_codec_t* codec)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if(codec && (manager = ProxyPluginMgr::getInstance())) {
+ const ProxyAudioProducer* audioProducer;
+ if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()) {
+ self->audio.channels = TMEDIA_CODEC_CHANNELS_AUDIO_ENCODING(codec);
+ self->audio.rate = TMEDIA_CODEC_RATE_ENCODING(codec);
+ self->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_ENCODING(codec);
+ ret = audioProducer->getCallback()->prepare((int)self->audio.ptime, self->audio.rate, self->audio.channels);
+ }
+ }
+ return ret;
+}
+
+static int twrap_producer_proxy_audio_start(tmedia_producer_t* self)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ const ProxyAudioProducer* audioProducer;
+ if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()) {
+ const_cast<ProxyAudioProducer*>(audioProducer)->startPushCallback();
+ ret = audioProducer->getCallback()->start();
+ }
+ }
+
+ TWRAP_PRODUCER_PROXY_AUDIO(self)->started = (ret == 0);
+ return ret;
+}
+
+static int twrap_producer_proxy_audio_pause(tmedia_producer_t* self)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ const ProxyAudioProducer* audioProducer;
+ if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()) {
+ ret = audioProducer->getCallback()->pause();
+ }
+ }
+ return ret;
+}
+
+static int twrap_producer_proxy_audio_stop(tmedia_producer_t* self)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ const ProxyAudioProducer* audioProducer;
+ if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()) {
+ const_cast<ProxyAudioProducer*>(audioProducer)->stopPushCallback();
+ ret = audioProducer->getCallback()->stop();
+ }
+ }
+ TWRAP_PRODUCER_PROXY_AUDIO(self)->started = (ret == 0) ? tsk_false : tsk_true;
+ return ret;
+}
+
+
+//
+// Audio producer object definition
+//
+/* constructor */
+static tsk_object_t* twrap_producer_proxy_audio_ctor(tsk_object_t * self, va_list * app)
+{
+ twrap_producer_proxy_audio_t *producer = (twrap_producer_proxy_audio_t *)self;
+ if(producer) {
+ /* init base */
+ tdav_producer_audio_init(TDAV_PRODUCER_AUDIO(producer));
+ /* init self */
+
+ /* Add the plugin to the manager */
+ ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
+ if(manager) {
+ ProxyPlugin* proxyProducer = new ProxyAudioProducer(producer);
+ uint64_t id = proxyProducer->getId();
+ manager->addPlugin(&proxyProducer);
+ manager->getCallback()->OnPluginCreated(id, twrap_proxy_plugin_audio_producer);
+ }
+ }
+ return self;
+}
+/* destructor */
+static tsk_object_t* twrap_producer_proxy_audio_dtor(tsk_object_t * self)
+{
+ twrap_producer_proxy_audio_t *producer = (twrap_producer_proxy_audio_t *)self;
+ if(producer) {
+
+ /* stop */
+ if(producer->started) {
+ twrap_producer_proxy_audio_stop(TMEDIA_PRODUCER(producer));
+ }
+
+ /* deinit base */
+ tdav_producer_audio_deinit(TDAV_PRODUCER_AUDIO(producer));
+ /* deinit self */
+
+ /* Remove plugin from the manager */
+ ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
+ if(manager) {
+ manager->getCallback()->OnPluginDestroyed(producer->id, twrap_proxy_plugin_audio_producer);
+ manager->removePlugin(producer->id);
+ }
+ }
+
+ return self;
+}
+/* object definition */
+static const tsk_object_def_t twrap_producer_proxy_audio_def_s = {
+ sizeof(twrap_producer_proxy_audio_t),
+ twrap_producer_proxy_audio_ctor,
+ twrap_producer_proxy_audio_dtor,
+ tdav_producer_audio_cmp,
+};
+/* plugin definition*/
+static const tmedia_producer_plugin_def_t twrap_producer_proxy_audio_plugin_def_s = {
+ &twrap_producer_proxy_audio_def_s,
+
+ tmedia_audio,
+ "Audio Proxy Producer",
+
+ twrap_producer_proxy_audio_set,
+ twrap_producer_proxy_audio_prepare,
+ twrap_producer_proxy_audio_start,
+ twrap_producer_proxy_audio_pause,
+ twrap_producer_proxy_audio_stop
+};
+
+/*TINYWRAP_GEXTERN*/ const tmedia_producer_plugin_def_t *twrap_producer_proxy_audio_plugin_def_t = &twrap_producer_proxy_audio_plugin_def_s;
+
+
+
+/* ============ ProxyAudioProducer Class ================= */
+ProxyAudioProducer::ProxyAudioProducer(twrap_producer_proxy_audio_t* pProducer)
+ :m_pCallback(tsk_null), m_pWrappedPlugin(pProducer), m_bUsePushCallback(false), m_hPushTimerMgr(tsk_null), ProxyPlugin(twrap_proxy_plugin_audio_producer)
+{
+ m_pWrappedPlugin->id = this->getId();
+ m_PushBuffer.pPushBufferPtr = tsk_null;
+ m_PushBuffer.nPushBufferSize = 0;
+}
+
+ProxyAudioProducer::~ProxyAudioProducer()
+{
+ stopPushCallback();
+}
+
+// Use this function to request resampling when your sound card can't honor negotaited record parameters
+bool ProxyAudioProducer::setActualSndCardRecordParams(int nPtime, int nRate, int nChannels)
+{
+ if(m_pWrappedPlugin) {
+ TSK_DEBUG_INFO("setActualSndCardRecordParams(ptime=%d, rate=%d, channels=%d)", nPtime, nRate, nChannels);
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.ptime = nPtime;
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.rate = nRate;
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.channels = nChannels;
+ return true;
+ }
+ else {
+ TSK_DEBUG_ERROR("Invalid state");
+ return false;
+ }
+}
+
+bool ProxyAudioProducer::setPushBuffer(const void* pPushBufferPtr, unsigned nPushBufferSize, bool bUsePushCallback/*=false*/)
+{
+ m_PushBuffer.pPushBufferPtr = pPushBufferPtr;
+ m_PushBuffer.nPushBufferSize = nPushBufferSize;
+ m_bUsePushCallback = bUsePushCallback;
+
+ if(!pPushBufferPtr || !nPushBufferSize || !bUsePushCallback) {
+ return stopPushCallback();
+ }
+ else if(m_bUsePushCallback && m_pWrappedPlugin && m_pWrappedPlugin->started) {
+ return startPushCallback();
+ }
+ return true;
+}
+
+int ProxyAudioProducer::push(const void* _pBuffer/*=tsk_null*/, unsigned _nSize/*=0*/)
+{
+ if(m_pWrappedPlugin && TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback) {
+ const void* pBuffer;
+ unsigned nSize;
+ if(_pBuffer && _nSize) {
+ pBuffer = _pBuffer, nSize = _nSize;
+ }
+ else {
+ pBuffer = m_PushBuffer.pPushBufferPtr, nSize = m_PushBuffer.nPushBufferSize;
+ }
+ return TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback(TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback_data, pBuffer, nSize);
+ }
+ return 0;
+}
+
+bool ProxyAudioProducer::setGain(unsigned nGain)
+{
+ if(m_pWrappedPlugin) {
+ // see also: MediaSessionMgr.producerSetInt32(org.doubango.tinyWRAP.twrap_media_type_t.twrap_media_audio, "gain", nGain);
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.gain = TSK_MIN(nGain,14);
+ return true;
+ }
+ return false;
+}
+
+unsigned ProxyAudioProducer::getGain()
+{
+ if(m_pWrappedPlugin) {
+ return TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.gain;
+ }
+ return 0;
+}
+
+bool ProxyAudioProducer::startPushCallback()
+{
+ if(!m_bUsePushCallback) {
+ return true;
+ }
+
+ if(!m_pWrappedPlugin) {
+ TSK_DEBUG_ERROR("Not wrapping plugin");
+ return false;
+ }
+
+ if(!m_hPushTimerMgr) {
+ if(!(m_hPushTimerMgr = tsk_timer_manager_create())) {
+ TSK_DEBUG_ERROR("Failed to create timer manager");
+ return false;
+ }
+ }
+
+ if(!TSK_RUNNABLE(m_hPushTimerMgr)->started) {
+ if((tsk_timer_manager_start(m_hPushTimerMgr)) == 0) {
+ m_uPushTimer = tsk_timer_manager_schedule(m_hPushTimerMgr, TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.ptime, &ProxyAudioProducer::pushTimerCallback, this);
+ }
+ else {
+ TSK_DEBUG_ERROR("Failed to start timer");
+ return false;
+ }
+ }
+ return true;
+}
+
+bool ProxyAudioProducer::stopPushCallback()
+{
+ if(m_hPushTimerMgr) {
+ tsk_timer_manager_destroy(&m_hPushTimerMgr);
+ }
+ return true;
+}
+
+int ProxyAudioProducer::pushTimerCallback(const void* arg, tsk_timer_id_t timer_id)
+{
+ ProxyAudioProducer* This = (ProxyAudioProducer*)arg;
+
+ This->m_uPushTimer = tsk_timer_manager_schedule(This->m_hPushTimerMgr, TMEDIA_PRODUCER(This->m_pWrappedPlugin)->audio.ptime, &ProxyAudioProducer::pushTimerCallback, This);
+
+ if(This->m_pCallback) {
+ if(This->m_pCallback->fillPushBuffer() == 0) {
+ return This->push();
+ }
+ }
+ return 0;
+}
+
+bool ProxyAudioProducer::registerPlugin()
+{
+ /* HACK: Unregister all other audio plugins */
+ tmedia_producer_plugin_unregister_by_type(tmedia_audio);
+ /* Register our proxy plugin */
+ return (tmedia_producer_plugin_register(twrap_producer_proxy_audio_plugin_def_t) == 0);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/* ============ Video Media Producer Interface ================= */
+typedef struct twrap_producer_proxy_video_s {
+ TMEDIA_DECLARE_PRODUCER;
+
+ int rotation;
+ uint64_t id;
+ tsk_bool_t started;
+#if 0
+ // https://code.google.com/p/doubango/issues/detail?id=416
+ // The lock on the producer is useless because all tinyDAV proxied functions (push(), stop(), prepare()...) are already thread safe.
+ // Locking the push method while tinDAV locks the stop() function produce a deadlock on Android devices with slow video producer implementations (e.g. Hovis Box v1)
+ TSK_DECLARE_SAFEOBJ;
+#endif
+}
+twrap_producer_proxy_video_t;
+#define TWRAP_PRODUCER_PROXY_VIDEO(self) ((twrap_producer_proxy_video_t*)(self))
+
+int twrap_producer_proxy_video_set(tmedia_producer_t* self, const tmedia_param_t* params)
+{
+ return 0;
+}
+
+int twrap_producer_proxy_video_prepare(tmedia_producer_t* self, const tmedia_codec_t* codec)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if(codec && (manager = ProxyPluginMgr::getInstance())) {
+ const ProxyVideoProducer* videoProducer;
+ if((videoProducer = manager->findVideoProducer(TWRAP_PRODUCER_PROXY_VIDEO(self)->id)) && videoProducer->getCallback()) {
+ self->video.chroma = videoProducer->getChroma();
+ self->video.rotation = videoProducer->getRotation();
+ ret = videoProducer->getCallback()->prepare(TMEDIA_CODEC_VIDEO(codec)->out.width, TMEDIA_CODEC_VIDEO(codec)->out.height, TMEDIA_CODEC_VIDEO(codec)->out.fps);
+ }
+ }
+
+ return ret;
+}
+
+int twrap_producer_proxy_video_start(tmedia_producer_t* self)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ const ProxyVideoProducer* videoProducer;
+ if((videoProducer = manager->findVideoProducer(TWRAP_PRODUCER_PROXY_VIDEO(self)->id)) && videoProducer->getCallback()) {
+ ret = videoProducer->getCallback()->start();
+ TWRAP_PRODUCER_PROXY_VIDEO(self)->started = (ret == 0);
+ }
+ }
+
+ return ret;
+}
+
+int twrap_producer_proxy_video_pause(tmedia_producer_t* self)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ const ProxyVideoProducer* videoProducer;
+ if((videoProducer = manager->findVideoProducer(TWRAP_PRODUCER_PROXY_VIDEO(self)->id)) && videoProducer->getCallback()) {
+ ret = videoProducer->getCallback()->pause();
+ }
+ }
+
+ return ret;
+}
+
+int twrap_producer_proxy_video_stop(tmedia_producer_t* self)
+{
+ ProxyPluginMgr* manager;
+ int ret = -1;
+ if((manager = ProxyPluginMgr::getInstance())) {
+ const ProxyVideoProducer* videoProducer;
+ if((videoProducer = manager->findVideoProducer(TWRAP_PRODUCER_PROXY_VIDEO(self)->id)) && videoProducer->getCallback()) {
+ ret = videoProducer->getCallback()->stop();
+ TWRAP_PRODUCER_PROXY_VIDEO(self)->started = ((ret == 0) ? tsk_false : tsk_true);
+ }
+ }
+
+ return ret;
+}
+
+
+//
+// Video producer object definition
+//
+/* constructor */
+static tsk_object_t* twrap_producer_proxy_video_ctor(tsk_object_t * self, va_list * app)
+{
+ twrap_producer_proxy_video_t *producer = (twrap_producer_proxy_video_t *)self;
+ if(producer) {
+ /* init base */
+ tmedia_producer_init(TMEDIA_PRODUCER(producer));
+ /* init self */
+
+ /* Add the plugin to the manager */
+ ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
+ if(manager) {
+ ProxyPlugin* proxyProducer = new ProxyVideoProducer(ProxyVideoProducer::getDefaultChroma(), producer);
+ uint64_t id = proxyProducer->getId();
+ manager->addPlugin(&proxyProducer);
+ manager->getCallback()->OnPluginCreated(id, twrap_proxy_plugin_video_producer);
+ }
+ }
+ return self;
+}
+/* destructor */
+static tsk_object_t* twrap_producer_proxy_video_dtor(tsk_object_t * self)
+{
+ twrap_producer_proxy_video_t *producer = (twrap_producer_proxy_video_t *)self;
+ if(producer) {
+ TSK_DEBUG_INFO("twrap_producer_proxy_video_dtor()");
+ /* stop */
+ if(producer->started) {
+ twrap_producer_proxy_video_stop(TMEDIA_PRODUCER(producer));
+ }
+
+ /* deinit base */
+ tmedia_producer_deinit(TMEDIA_PRODUCER(producer));
+ /* deinit self */
+
+ /* Remove plugin from the manager */
+ ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
+ if(manager) {
+ manager->getCallback()->OnPluginDestroyed(producer->id, twrap_proxy_plugin_video_producer);
+ manager->removePlugin(producer->id);
+ }
+ }
+
+ return self;
+}
+/* object definition */
+static const tsk_object_def_t twrap_producer_proxy_video_def_s = {
+ sizeof(twrap_producer_proxy_video_t),
+ twrap_producer_proxy_video_ctor,
+ twrap_producer_proxy_video_dtor,
+ tsk_null,
+};
+/* plugin definition*/
+static const tmedia_producer_plugin_def_t twrap_producer_proxy_video_plugin_def_s = {
+ &twrap_producer_proxy_video_def_s,
+
+ tmedia_video,
+ "Video Proxy Producer",
+
+ twrap_producer_proxy_video_set,
+ twrap_producer_proxy_video_prepare,
+ twrap_producer_proxy_video_start,
+ twrap_producer_proxy_video_pause,
+ twrap_producer_proxy_video_stop
+};
+
+/*TINYWRAP_GEXTERN*/ const tmedia_producer_plugin_def_t *twrap_producer_proxy_video_plugin_def_t = &twrap_producer_proxy_video_plugin_def_s;
+
+
+
+/* ============ ProxyVideoProducer Class ================= */
+tmedia_chroma_t ProxyVideoProducer::s_eDefaultChroma = tmedia_chroma_nv21;
+
+ProxyVideoProducer::ProxyVideoProducer(tmedia_chroma_t eChroma, struct twrap_producer_proxy_video_s* pProducer)
+ :m_pCallback(tsk_null), m_eChroma(eChroma), m_nRotation(0), m_bMirror(false), m_pWrappedPlugin(pProducer), ProxyPlugin(twrap_proxy_plugin_video_producer)
+{
+ if(m_pWrappedPlugin) {
+ m_pWrappedPlugin->id = this->getId();
+ }
+}
+
+ProxyVideoProducer::~ProxyVideoProducer()
+{
+ TSK_DEBUG_INFO("~ProxyVideoProducer");
+}
+
+int ProxyVideoProducer::getRotation()const
+{
+ return m_nRotation;
+}
+
+bool ProxyVideoProducer::setRotation(int nRot)
+{
+ m_nRotation = nRot;
+ if (m_pWrappedPlugin) {
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->video.rotation = m_nRotation;
+ return true;
+ }
+ return false;
+}
+
+bool ProxyVideoProducer::getMirror()const
+{
+ return m_bMirror;
+}
+
+bool ProxyVideoProducer::setMirror(bool bMirror)
+{
+ m_bMirror = bMirror;
+ if (m_pWrappedPlugin) {
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->video.mirror = m_bMirror ? tsk_true : tsk_false;
+ return true;
+ }
+ return false;
+}
+
+// alert the encoder which size your camera is using because it's very hard to retrieve it from send(buffer, size) function
+// this function is only needed if the actual size (output from your camera) is different than the negociated one
+bool ProxyVideoProducer::setActualCameraOutputSize(unsigned nWidth, unsigned nHeight)
+{
+ if(m_pWrappedPlugin) {
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->video.width = nWidth;
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->video.height = nHeight;
+ return true;
+ }
+ return false;
+}
+
+// encode() then send()
+int ProxyVideoProducer::push(const void* pBuffer, unsigned nSize)
+{
+ if (m_pWrappedPlugin && TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback) {
+ int ret = -1;
+ if (m_pWrappedPlugin->started) {
+ ret = TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback(TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback_data, pBuffer, nSize);
+ }
+ return ret;
+ }
+ return 0;
+}
+
+// send() "as is"
+// only used by telepresence system with a H.264 SVC hardaware encoder
+int ProxyVideoProducer::sendRaw(const void* pBuffer, unsigned nSize, unsigned nDuration, bool bMarker)
+{
+ if(m_pWrappedPlugin && TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.callback) {
+ //tmedia_video_encode_result_reset(&TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr);
+
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.buffer.ptr = pBuffer;
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.buffer.size = nSize;
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.duration = nDuration;
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.last_chunck = (bMarker == true);
+ return TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.callback(&TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr);
+ }
+ return 0;
+}
+
+int ProxyVideoProducer::sendRaw(const void* pBuffer, unsigned nSize, const void* proto_hdr)
+{
+ if(m_pWrappedPlugin && TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.callback) {
+ //tmedia_video_encode_result_reset(&TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr);
+
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.buffer.ptr = pBuffer;
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.buffer.size = nSize;
+ TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.proto_hdr = proto_hdr;
+ return TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.callback(&TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr);
+ }
+ return 0;
+}
+
+tmedia_chroma_t ProxyVideoProducer::getChroma()const
+{
+ return m_eChroma;
+}
+
+bool ProxyVideoProducer::registerPlugin()
+{
+ /* HACK: Unregister all other video plugins */
+ tmedia_producer_plugin_unregister_by_type(tmedia_video);
+ /* Register our proxy plugin */
+ return (tmedia_producer_plugin_register(twrap_producer_proxy_video_plugin_def_t) == 0);
+}
diff --git a/bindings/_common/ProxyProducer.h b/bindings/_common/ProxyProducer.h index 4a4ea66..14c2a9f 100755 --- a/bindings/_common/ProxyProducer.h +++ b/bindings/_common/ProxyProducer.h @@ -1,200 +1,200 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ - -/**@file ProxyProducer.h - * @brief Audio/Video proxy consumers. - * - * @author Mamadou Diop <diopmamadou(at)doubango.org> - * - - */ -#ifndef TINYWRAP_PRODUCER_PROXY_H -#define TINYWRAP_PRODUCER_PROXY_H - -#include "tinyWRAP_config.h" - -#include "ProxyPluginMgr.h" - -#include "tinymedia/tmedia_common.h" -#include "tinymedia/tmedia_producer.h" - -/* ============ ProxyAudioProducerCallback Class ================= */ -class ProxyAudioProducerCallback -{ -public: - ProxyAudioProducerCallback() { } - virtual ~ProxyAudioProducerCallback() { } - - virtual int prepare(int ptime, int rate, int channels) { - return -1; - } - virtual int start() { - return -1; - } - virtual int pause() { - return -1; - } - virtual int stop() { - return -1; - } - // this function is called to signal that it's time to copy push data - virtual int fillPushBuffer() { - return -1; - } -}; - - -/* ============ ProxyAudioProducer Class ================= */ -class ProxyAudioProducer : public ProxyPlugin -{ -public: -#if !defined(SWIG) - ProxyAudioProducer(struct twrap_producer_proxy_audio_s* pProducer); -#endif - virtual ~ProxyAudioProducer(); - - bool setActualSndCardRecordParams(int nPtime, int nRate, int nChannels); - bool setPushBuffer(const void* pPushBufferPtr, unsigned nPushBufferSize, bool bUsePushCallback=false); - int push(const void* pBuffer=tsk_null, unsigned nSize=0); - bool setGain(unsigned nGain); - unsigned getGain(); - void setCallback(ProxyAudioProducerCallback* pCallback) { - m_pCallback = pCallback; - } -#if !defined(SWIG) - inline bool usePushCallback() { - return m_bUsePushCallback; - } - inline ProxyAudioProducerCallback* getCallback()const { - return m_pCallback; - } - virtual inline bool isWrapping(tsk_object_t* pWrappedPlugin) { - return m_pWrappedPlugin == pWrappedPlugin; - } -#endif - virtual inline uint64_t getMediaSessionId() { - return m_pWrappedPlugin ? TMEDIA_PRODUCER(m_pWrappedPlugin)->session_id : 0; - } - -#if !defined(SWIG) -public: - bool startPushCallback(); - bool stopPushCallback(); -private: - static int pushTimerCallback(const void* arg, tsk_timer_id_t timer_id); -#endif - -public: - static bool registerPlugin(); - -private: - struct twrap_producer_proxy_audio_s* m_pWrappedPlugin; - ProxyAudioProducerCallback* m_pCallback; - struct { - const void* pPushBufferPtr; - unsigned nPushBufferSize; - } m_PushBuffer; - bool m_bUsePushCallback; - void* m_hPushTimerMgr; - uint64_t m_uPushTimer; -}; - -/* ============ ProxyVideoProducerCallback Class ================= */ -class ProxyVideoProducerCallback -{ -public: - ProxyVideoProducerCallback() { } - virtual ~ProxyVideoProducerCallback() { } - - virtual int prepare(int width, int height, int fps) { - return -1; - } - virtual int start() { - return -1; - } - virtual int pause() { - return -1; - } - virtual int stop() { - return -1; - } -}; - -/* ============ ProxyVideoProducer Class ================= */ -class ProxyVideoProducer : public ProxyPlugin -{ -public: -#if !defined(SWIG) - ProxyVideoProducer(tmedia_chroma_t eChroma, struct twrap_producer_proxy_video_s* pProducer); -#endif - virtual ~ProxyVideoProducer(); - - int getRotation()const; - bool setRotation(int nRot); - bool getMirror()const; - bool setMirror(bool bMirror); - bool setActualCameraOutputSize(unsigned nWidth, unsigned nHeight); - int push(const void* pBuffer, unsigned nSize); - void setCallback(ProxyVideoProducerCallback* pCallback) { - m_pCallback = pCallback; - } -#if !defined(SWIG) - int sendRaw(const void* pBuffer, unsigned nSize, unsigned nDuration, bool bMarker); - int sendRaw(const void* pBuffer, unsigned nSize, const void* proto_hdr); - inline ProxyVideoProducerCallback* getCallback()const { - return m_pCallback; - } - virtual inline bool isWrapping(tsk_object_t* wrapped_plugin) { - return m_pWrappedPlugin == wrapped_plugin; - } - virtual inline const tmedia_producer_t* getWrappedPlugin()const { - return (tmedia_producer_t*)m_pWrappedPlugin; - } -#endif - virtual inline uint64_t getMediaSessionId() { - return m_pWrappedPlugin ? TMEDIA_PRODUCER(m_pWrappedPlugin)->session_id : 0; - } - -public: - static bool registerPlugin(); - static void setDefaultChroma(tmedia_chroma_t eChroma) { - s_eDefaultChroma = eChroma; - } - -#if !defined(SWIG) - tmedia_chroma_t getChroma()const; - static tmedia_chroma_t getDefaultChroma() { - return s_eDefaultChroma; - } -#endif - -private: - struct twrap_producer_proxy_video_s* m_pWrappedPlugin; - ProxyVideoProducerCallback* m_pCallback; - tmedia_chroma_t m_eChroma; - int m_nRotation; - bool m_bMirror; - - static tmedia_chroma_t s_eDefaultChroma; -}; - -#endif /* TINYWRAP_PRODUCER_PROXY_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+/**@file ProxyProducer.h
+ * @brief Audio/Video proxy consumers.
+ *
+ * @author Mamadou Diop <diopmamadou(at)doubango.org>
+ *
+
+ */
+#ifndef TINYWRAP_PRODUCER_PROXY_H
+#define TINYWRAP_PRODUCER_PROXY_H
+
+#include "tinyWRAP_config.h"
+
+#include "ProxyPluginMgr.h"
+
+#include "tinymedia/tmedia_common.h"
+#include "tinymedia/tmedia_producer.h"
+
+/* ============ ProxyAudioProducerCallback Class ================= */
+class ProxyAudioProducerCallback
+{
+public:
+ ProxyAudioProducerCallback() { }
+ virtual ~ProxyAudioProducerCallback() { }
+
+ virtual int prepare(int ptime, int rate, int channels) {
+ return -1;
+ }
+ virtual int start() {
+ return -1;
+ }
+ virtual int pause() {
+ return -1;
+ }
+ virtual int stop() {
+ return -1;
+ }
+ // this function is called to signal that it's time to copy push data
+ virtual int fillPushBuffer() {
+ return -1;
+ }
+};
+
+
+/* ============ ProxyAudioProducer Class ================= */
+class ProxyAudioProducer : public ProxyPlugin
+{
+public:
+#if !defined(SWIG)
+ ProxyAudioProducer(struct twrap_producer_proxy_audio_s* pProducer);
+#endif
+ virtual ~ProxyAudioProducer();
+
+ bool setActualSndCardRecordParams(int nPtime, int nRate, int nChannels);
+ bool setPushBuffer(const void* pPushBufferPtr, unsigned nPushBufferSize, bool bUsePushCallback=false);
+ int push(const void* pBuffer=tsk_null, unsigned nSize=0);
+ bool setGain(unsigned nGain);
+ unsigned getGain();
+ void setCallback(ProxyAudioProducerCallback* pCallback) {
+ m_pCallback = pCallback;
+ }
+#if !defined(SWIG)
+ inline bool usePushCallback() {
+ return m_bUsePushCallback;
+ }
+ inline ProxyAudioProducerCallback* getCallback()const {
+ return m_pCallback;
+ }
+ virtual inline bool isWrapping(tsk_object_t* pWrappedPlugin) {
+ return m_pWrappedPlugin == pWrappedPlugin;
+ }
+#endif
+ virtual inline uint64_t getMediaSessionId() {
+ return m_pWrappedPlugin ? TMEDIA_PRODUCER(m_pWrappedPlugin)->session_id : 0;
+ }
+
+#if !defined(SWIG)
+public:
+ bool startPushCallback();
+ bool stopPushCallback();
+private:
+ static int pushTimerCallback(const void* arg, tsk_timer_id_t timer_id);
+#endif
+
+public:
+ static bool registerPlugin();
+
+private:
+ struct twrap_producer_proxy_audio_s* m_pWrappedPlugin;
+ ProxyAudioProducerCallback* m_pCallback;
+ struct {
+ const void* pPushBufferPtr;
+ unsigned nPushBufferSize;
+ } m_PushBuffer;
+ bool m_bUsePushCallback;
+ void* m_hPushTimerMgr;
+ uint64_t m_uPushTimer;
+};
+
+/* ============ ProxyVideoProducerCallback Class ================= */
+class ProxyVideoProducerCallback
+{
+public:
+ ProxyVideoProducerCallback() { }
+ virtual ~ProxyVideoProducerCallback() { }
+
+ virtual int prepare(int width, int height, int fps) {
+ return -1;
+ }
+ virtual int start() {
+ return -1;
+ }
+ virtual int pause() {
+ return -1;
+ }
+ virtual int stop() {
+ return -1;
+ }
+};
+
+/* ============ ProxyVideoProducer Class ================= */
+class ProxyVideoProducer : public ProxyPlugin
+{
+public:
+#if !defined(SWIG)
+ ProxyVideoProducer(tmedia_chroma_t eChroma, struct twrap_producer_proxy_video_s* pProducer);
+#endif
+ virtual ~ProxyVideoProducer();
+
+ int getRotation()const;
+ bool setRotation(int nRot);
+ bool getMirror()const;
+ bool setMirror(bool bMirror);
+ bool setActualCameraOutputSize(unsigned nWidth, unsigned nHeight);
+ int push(const void* pBuffer, unsigned nSize);
+ void setCallback(ProxyVideoProducerCallback* pCallback) {
+ m_pCallback = pCallback;
+ }
+#if !defined(SWIG)
+ int sendRaw(const void* pBuffer, unsigned nSize, unsigned nDuration, bool bMarker);
+ int sendRaw(const void* pBuffer, unsigned nSize, const void* proto_hdr);
+ inline ProxyVideoProducerCallback* getCallback()const {
+ return m_pCallback;
+ }
+ virtual inline bool isWrapping(tsk_object_t* wrapped_plugin) {
+ return m_pWrappedPlugin == wrapped_plugin;
+ }
+ virtual inline const tmedia_producer_t* getWrappedPlugin()const {
+ return (tmedia_producer_t*)m_pWrappedPlugin;
+ }
+#endif
+ virtual inline uint64_t getMediaSessionId() {
+ return m_pWrappedPlugin ? TMEDIA_PRODUCER(m_pWrappedPlugin)->session_id : 0;
+ }
+
+public:
+ static bool registerPlugin();
+ static void setDefaultChroma(tmedia_chroma_t eChroma) {
+ s_eDefaultChroma = eChroma;
+ }
+
+#if !defined(SWIG)
+ tmedia_chroma_t getChroma()const;
+ static tmedia_chroma_t getDefaultChroma() {
+ return s_eDefaultChroma;
+ }
+#endif
+
+private:
+ struct twrap_producer_proxy_video_s* m_pWrappedPlugin;
+ ProxyVideoProducerCallback* m_pCallback;
+ tmedia_chroma_t m_eChroma;
+ int m_nRotation;
+ bool m_bMirror;
+
+ static tmedia_chroma_t s_eDefaultChroma;
+};
+
+#endif /* TINYWRAP_PRODUCER_PROXY_H */
diff --git a/bindings/_common/SMS.i b/bindings/_common/SMS.i index 82e8709..d25744d 100755 --- a/bindings/_common/SMS.i +++ b/bindings/_common/SMS.i @@ -1,7 +1,7 @@ -%{ -#include "SMSEncoder.h" -%} - -%nodefaultctor; -%include "SMSEncoder.h" +%{
+#include "SMSEncoder.h"
+%}
+
+%nodefaultctor;
+%include "SMSEncoder.h"
%clearnodefaultctor;
\ No newline at end of file diff --git a/bindings/_common/SMSEncoder.cxx b/bindings/_common/SMSEncoder.cxx index d07ab2b..e4cb0e5 100755 --- a/bindings/_common/SMSEncoder.cxx +++ b/bindings/_common/SMSEncoder.cxx @@ -1,371 +1,371 @@ -/* -* Copyright (C) 2009 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou@doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "SMSEncoder.h" - -// Short description: http://betelco.blogspot.com/2009/10/sms-over-3gpp-ims-network.html - - -RPMessage::RPMessage(twrap_rpmessage_type_t _type, tsms_rpdu_message_t* _rp_message) -{ - this->rp_message = (tsms_rpdu_message_t*)tsk_object_ref(_rp_message); - this->type = _type; - this->tmpBuffer = tsk_null; -} - -RPMessage::RPMessage() : - rp_message(tsk_null), - type(twrap_rpmessage_type_sms_none), - tmpBuffer(tsk_null) -{ -} - -twrap_rpmessage_type_t RPMessage::getType() -{ - return this->type; -} - -unsigned RPMessage::getPayloadLength() -{ - if(!this->tmpBuffer) { - if((this->tmpBuffer = tsk_buffer_create_null())) { - tsms_rpdu_data_serialize(this->rp_message, this->tmpBuffer); - } - } - return this->tmpBuffer ? this->tmpBuffer->size : 0; -} - -unsigned RPMessage::getPayload(void* output, unsigned maxsize) -{ - unsigned retsize = 0; - - if(!this->tmpBuffer) { - if((this->tmpBuffer = tsk_buffer_create_null())) { - tsms_rpdu_message_serialize(this->rp_message, this->tmpBuffer); - } - } - - if(output && maxsize && this->tmpBuffer && this->tmpBuffer->data) { - retsize = (this->tmpBuffer->size > maxsize) ? maxsize : this->tmpBuffer->size; - memcpy(output, this->tmpBuffer->data, retsize); - } - return retsize; -} - -RPMessage::~RPMessage() -{ - TSK_OBJECT_SAFE_FREE(this->rp_message); - TSK_OBJECT_SAFE_FREE(this->tmpBuffer); -} - - -SMSData::SMSData(twrap_sms_type_t _type, int _mr, const void* _ascii, tsk_size_t _size): oa(tsk_null), da(tsk_null) -{ - this->type = _type; - this->mr = _mr; - if((this->size = _size)) { - if((this->ascii = tsk_calloc(size+1, 1))) { - memcpy(this->ascii, _ascii, _size); - } - } - else { - this->ascii = tsk_null; - } -} - -SMSData::SMSData(): oa(tsk_null), da(tsk_null) -{ - this->type = twrap_sms_type_none; - this->mr = 0; - this->size = 0; - this->ascii = tsk_null; -} - -SMSData::~SMSData() -{ - TSK_FREE(this->ascii); - TSK_FREE(this->oa); - TSK_FREE(this->da); -} - -twrap_sms_type_t SMSData::getType() -{ - return this->type; -} - -int SMSData::getMR() -{ - return this->mr; -} - -unsigned SMSData::getPayloadLength() -{ - return this->size; -} - -unsigned SMSData::getPayload(void* output, unsigned maxsize) -{ - unsigned retsize = 0; - - if(output && maxsize && this->ascii) { - retsize = (this->size > maxsize) ? maxsize : this->size; - memcpy(output, this->ascii, retsize); - } - return retsize; -} - -const char* SMSData::getOA() -{ - return this->oa; -} - -const char* SMSData::getDA() -{ - return this->da; -} - -void SMSData::setOA(const char* _oa) -{ - TSK_FREE(this->oa); - this->oa = tsk_strdup(_oa); -} - -void SMSData::setDA(const char* _da) -{ - TSK_FREE(this->da); - this->da = tsk_strdup(_da); -} - - -// More information about RP-DATA: http://www.doubango.org/API/tinySMS/group__tsms__rpdu__group.html#tsms_rpdu_group_DATA -RPMessage* SMSEncoder::encodeSubmit(int mr, const char *smsc, const char *destination, const char *ascii) -{ - int ret; - tsk_buffer_t* buffer = tsk_null; - tsms_tpdu_submit_t* sms_submit = tsk_null; - tsms_rpdu_data_t* rp_data = tsk_null; - - RPMessage* encodedData = tsk_null; - - if(!smsc || ! destination || !ascii) { - TSK_DEBUG_ERROR("Invalid parameter"); - return tsk_null; - } - - if(mr<0 || mr>0xFF) { - TSK_DEBUG_WARN("Invalid Message Reference"); - mr &= 0xFF; - } - - // create SMS-SUBMIT message - if(!(sms_submit = tsms_tpdu_submit_create(mr, (const uint8_t*)smsc, (const uint8_t*)destination))) { - TSK_DEBUG_ERROR("Failed to create the TPDU SMS-SUBMIT message"); - goto bail; - } - // Set content for SMS-SUBMIT - if((buffer = tsms_pack_to_7bit(ascii))) { - ret = tsms_tpdu_submit_set_userdata(sms_submit, buffer, tsms_alpha_7bit); - TSK_OBJECT_SAFE_FREE(buffer); - } - else { - TSK_DEBUG_ERROR("Failed to encode the TPDU SMS-SUBMIT message"); - goto bail; - } - - // create RP-DATA(SMS-SUBMIT) - if((rp_data = tsms_rpdu_data_create_mo(mr, (const uint8_t*)smsc, TSMS_TPDU_MESSAGE(sms_submit)))) { - encodedData = new RPMessage(twrap_rpmessage_type_sms_submit, TSMS_RPDU_MESSAGE(rp_data)); - } - else { - TSK_DEBUG_ERROR("Failed to create the RP-DATA(SMS-SUBMIT) message"); - goto bail; - } - -bail: - TSK_OBJECT_SAFE_FREE(buffer); - TSK_OBJECT_SAFE_FREE(sms_submit); - TSK_OBJECT_SAFE_FREE(rp_data); - - return encodedData; -} - -// More information about RP-DATA: http://www.doubango.org/API/tinySMS/group__tsms__rpdu__group.html#tsms_rpdu_group_DATA -RPMessage* SMSEncoder::encodeDeliver(int mr, const char* smsc, const char* originator, const char* ascii) -{ - int ret; - tsk_buffer_t* buffer = tsk_null; - tsms_tpdu_deliver_t* sms_deliver = tsk_null; - tsms_rpdu_data_t* rp_data = tsk_null; - - RPMessage* encodedData = tsk_null; - - if(!smsc || ! originator || !ascii) { - TSK_DEBUG_ERROR("Invalid parameter"); - return tsk_null; - } - - if(mr<0 || mr>0xFF) { - TSK_DEBUG_WARN("Invalid Message Reference"); - mr &= 0xFF; - } - - // create SMS-DELIVER message - sms_deliver = tsms_tpdu_deliver_create((const uint8_t*)smsc, (const uint8_t*)originator); - // Set content for SMS-DELIVER - if((buffer = tsms_pack_to_7bit(ascii))) { - ret = tsms_tpdu_deliver_set_userdata(sms_deliver, buffer, tsms_alpha_7bit); - TSK_OBJECT_SAFE_FREE(buffer); - } - // create RP-DATA message - if((rp_data = tsms_rpdu_data_create_mt(mr, (const uint8_t*)smsc, TSMS_TPDU_MESSAGE(sms_deliver)))) { - encodedData = new RPMessage(twrap_rpmessage_type_sms_deliver, TSMS_RPDU_MESSAGE(rp_data)); - } - else { - TSK_DEBUG_ERROR("Failed to create the RP-DATA(SMS-DELIVER) message"); - goto bail; - } - -bail: - TSK_OBJECT_SAFE_FREE(buffer); - TSK_OBJECT_SAFE_FREE(sms_deliver); - TSK_OBJECT_SAFE_FREE(rp_data); - - return encodedData; -} - -RPMessage* SMSEncoder::encodeACK(int mr, const char* smsc, const char* destination, bool forSUBMIT) -{ - tsms_tpdu_report_t* sms_report = tsk_null; - tsms_rpdu_ack_t* rp_ack = tsk_null; - tsk_bool_t isSUBMIT = forSUBMIT ? tsk_true : tsk_false; - tsk_bool_t isERROR = tsk_false; - - RPMessage* encodedData = tsk_null; - - // create SMS-DELIVER(or SUBMIT)-REPORT message - sms_report = tsms_tpdu_report_create((const uint8_t*)smsc, isSUBMIT, isERROR); - // create RP-ACK message (From MS to SC) - if((rp_ack = tsms_rpdu_ack_create_mo(mr, TSMS_TPDU_MESSAGE(sms_report)))) { - encodedData = new RPMessage(twrap_rpmessage_type_sms_ack, TSMS_RPDU_MESSAGE(rp_ack)); - } - - TSK_OBJECT_SAFE_FREE(sms_report); - TSK_OBJECT_SAFE_FREE(rp_ack); - - return encodedData; -} - -RPMessage* SMSEncoder::encodeError(int mr, const char* smsc, const char* destination, bool forSUBMIT) -{ - tsms_tpdu_report_t* sms_report = tsk_null; - tsms_rpdu_error_t* rp_error= tsk_null; - tsk_bool_t isSUBMIT = forSUBMIT ? tsk_true : tsk_false; - tsk_bool_t isERROR = tsk_true; - - RPMessage* encodedData = tsk_null; - - // create SMS-DELIVER-REPORT message - sms_report = tsms_tpdu_report_create((const uint8_t*)smsc, isSUBMIT, isERROR); - // create RP-ERROR message - if((rp_error = tsms_rpdu_error_create_mo(mr, TSMS_TPDU_MESSAGE(sms_report), 0x0A/*call barred*/))) { - encodedData = new RPMessage(twrap_rpmessage_type_sms_error, TSMS_RPDU_MESSAGE(rp_error)); - } - - TSK_OBJECT_SAFE_FREE(sms_report); - TSK_OBJECT_SAFE_FREE(rp_error); - - return encodedData; -} - -SMSData* SMSEncoder::decode(const void* data, unsigned size, bool MobOrig) -{ - tsms_rpdu_message_t* rp_message = tsk_null; - tsms_tpdu_message_t* tpdu = tsk_null; - - SMSData* decodedData = tsk_null; - - if(!(rp_message = tsms_rpdu_message_deserialize(data, size))) { - TSK_DEBUG_ERROR("Failed to deserialize the RP-MESSAGE"); - goto bail; - } - - switch(rp_message->mti) { - case tsms_rpdu_type_data_mo: - case tsms_rpdu_type_data_mt: { - char* ascii = tsk_null; - tsms_rpdu_data_t* rp_data = TSMS_RPDU_DATA(rp_message); - if((tpdu = tsms_tpdu_message_deserialize(rp_data->udata->data, rp_data->udata->size, MobOrig))) { - if(tpdu->mti == tsms_tpdu_mti_deliver_mt || tpdu->mti == tsms_tpdu_mti_submit_mo) { /* SMS-SUBMIT or SMS-DELIVER? */ - ascii = tsms_tpdu_message_get_payload(tpdu); - decodedData = new SMSData(twrap_sms_type_rpdata, rp_message->mr, ascii, (tsk_size_t)tsk_strlen(ascii)); - - if(tpdu->mti == tsms_tpdu_mti_deliver_mt) { - tsms_tpdu_deliver_t* tpdu_deliver = (tsms_tpdu_deliver_t*)tpdu; - decodedData->setOA(tpdu_deliver->oa ? tpdu_deliver->oa->digits : tsk_null); - } - /* IMPORTANT: to not uncomment - else if(TSK_OBJECT_DEF(tpdu) == tsms_tpdu_submit_def_t){ - tsms_tpdu_submit_t* tpdu_submit = (tsms_tpdu_submit_t*)tpdu; - decodedData->setDA(tpdu_submit->da ? tpdu_submit->da->digits : tsk_null); - }*/ - TSK_FREE(ascii); - } - } - break; - } - case tsms_rpdu_type_ack_mo: - case tsms_rpdu_type_ack_mt: { - tsms_rpdu_ack_t* rp_ack = TSMS_RPDU_ACK(rp_message); - // ...do whatever you want - if(rp_ack->udata && (tpdu = tsms_tpdu_message_deserialize(rp_ack->udata->data, rp_ack->udata->size, MobOrig))) { - // ...do whatever you want - } - decodedData = new SMSData(twrap_sms_type_ack, rp_message->mr, tsk_null, 0); - break; - } - case tsms_rpdu_type_error_mo: - case tsms_rpdu_type_error_mt: { - tsms_rpdu_error_t* rp_error = TSMS_RPDU_ERROR(rp_message); - // ...do whatever you want - if(rp_error->udata && (tpdu = tsms_tpdu_message_deserialize(rp_error->udata->data, rp_error->udata->size, MobOrig))) { - // ...do whatever you want - } - decodedData = new SMSData(twrap_sms_type_error, rp_message->mr, tsk_null, 0); - break; - } - case tsms_rpdu_type_smma_mo: { - // tsms_rpdu_smma_t* rp_smma = TSMS_RPDU_SMMA(rp_message); - // ...do whatever you want - decodedData = new SMSData(twrap_sms_type_smma, rp_message->mr, tsk_null, 0); - break; - } - default: { - TSK_DEBUG_INFO("Unknown RP-Message type (%u).", rp_message->mti); - break; - } - } - -bail: - TSK_OBJECT_SAFE_FREE(rp_message); - TSK_OBJECT_SAFE_FREE(tpdu); - - return decodedData; +/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou@doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "SMSEncoder.h"
+
+// Short description: http://betelco.blogspot.com/2009/10/sms-over-3gpp-ims-network.html
+
+
+RPMessage::RPMessage(twrap_rpmessage_type_t _type, tsms_rpdu_message_t* _rp_message)
+{
+ this->rp_message = (tsms_rpdu_message_t*)tsk_object_ref(_rp_message);
+ this->type = _type;
+ this->tmpBuffer = tsk_null;
+}
+
+RPMessage::RPMessage() :
+ rp_message(tsk_null),
+ type(twrap_rpmessage_type_sms_none),
+ tmpBuffer(tsk_null)
+{
+}
+
+twrap_rpmessage_type_t RPMessage::getType()
+{
+ return this->type;
+}
+
+unsigned RPMessage::getPayloadLength()
+{
+ if(!this->tmpBuffer) {
+ if((this->tmpBuffer = tsk_buffer_create_null())) {
+ tsms_rpdu_data_serialize(this->rp_message, this->tmpBuffer);
+ }
+ }
+ return this->tmpBuffer ? this->tmpBuffer->size : 0;
+}
+
+unsigned RPMessage::getPayload(void* output, unsigned maxsize)
+{
+ unsigned retsize = 0;
+
+ if(!this->tmpBuffer) {
+ if((this->tmpBuffer = tsk_buffer_create_null())) {
+ tsms_rpdu_message_serialize(this->rp_message, this->tmpBuffer);
+ }
+ }
+
+ if(output && maxsize && this->tmpBuffer && this->tmpBuffer->data) {
+ retsize = (this->tmpBuffer->size > maxsize) ? maxsize : this->tmpBuffer->size;
+ memcpy(output, this->tmpBuffer->data, retsize);
+ }
+ return retsize;
+}
+
+RPMessage::~RPMessage()
+{
+ TSK_OBJECT_SAFE_FREE(this->rp_message);
+ TSK_OBJECT_SAFE_FREE(this->tmpBuffer);
+}
+
+
+SMSData::SMSData(twrap_sms_type_t _type, int _mr, const void* _ascii, tsk_size_t _size): oa(tsk_null), da(tsk_null)
+{
+ this->type = _type;
+ this->mr = _mr;
+ if((this->size = _size)) {
+ if((this->ascii = tsk_calloc(size+1, 1))) {
+ memcpy(this->ascii, _ascii, _size);
+ }
+ }
+ else {
+ this->ascii = tsk_null;
+ }
+}
+
+SMSData::SMSData(): oa(tsk_null), da(tsk_null)
+{
+ this->type = twrap_sms_type_none;
+ this->mr = 0;
+ this->size = 0;
+ this->ascii = tsk_null;
+}
+
+SMSData::~SMSData()
+{
+ TSK_FREE(this->ascii);
+ TSK_FREE(this->oa);
+ TSK_FREE(this->da);
+}
+
+twrap_sms_type_t SMSData::getType()
+{
+ return this->type;
+}
+
+int SMSData::getMR()
+{
+ return this->mr;
+}
+
+unsigned SMSData::getPayloadLength()
+{
+ return this->size;
+}
+
+unsigned SMSData::getPayload(void* output, unsigned maxsize)
+{
+ unsigned retsize = 0;
+
+ if(output && maxsize && this->ascii) {
+ retsize = (this->size > maxsize) ? maxsize : this->size;
+ memcpy(output, this->ascii, retsize);
+ }
+ return retsize;
+}
+
+const char* SMSData::getOA()
+{
+ return this->oa;
+}
+
+const char* SMSData::getDA()
+{
+ return this->da;
+}
+
+void SMSData::setOA(const char* _oa)
+{
+ TSK_FREE(this->oa);
+ this->oa = tsk_strdup(_oa);
+}
+
+void SMSData::setDA(const char* _da)
+{
+ TSK_FREE(this->da);
+ this->da = tsk_strdup(_da);
+}
+
+
+// More information about RP-DATA: http://www.doubango.org/API/tinySMS/group__tsms__rpdu__group.html#tsms_rpdu_group_DATA
+RPMessage* SMSEncoder::encodeSubmit(int mr, const char *smsc, const char *destination, const char *ascii)
+{
+ int ret;
+ tsk_buffer_t* buffer = tsk_null;
+ tsms_tpdu_submit_t* sms_submit = tsk_null;
+ tsms_rpdu_data_t* rp_data = tsk_null;
+
+ RPMessage* encodedData = tsk_null;
+
+ if(!smsc || ! destination || !ascii) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return tsk_null;
+ }
+
+ if(mr<0 || mr>0xFF) {
+ TSK_DEBUG_WARN("Invalid Message Reference");
+ mr &= 0xFF;
+ }
+
+ // create SMS-SUBMIT message
+ if(!(sms_submit = tsms_tpdu_submit_create(mr, (const uint8_t*)smsc, (const uint8_t*)destination))) {
+ TSK_DEBUG_ERROR("Failed to create the TPDU SMS-SUBMIT message");
+ goto bail;
+ }
+ // Set content for SMS-SUBMIT
+ if((buffer = tsms_pack_to_7bit(ascii))) {
+ ret = tsms_tpdu_submit_set_userdata(sms_submit, buffer, tsms_alpha_7bit);
+ TSK_OBJECT_SAFE_FREE(buffer);
+ }
+ else {
+ TSK_DEBUG_ERROR("Failed to encode the TPDU SMS-SUBMIT message");
+ goto bail;
+ }
+
+ // create RP-DATA(SMS-SUBMIT)
+ if((rp_data = tsms_rpdu_data_create_mo(mr, (const uint8_t*)smsc, TSMS_TPDU_MESSAGE(sms_submit)))) {
+ encodedData = new RPMessage(twrap_rpmessage_type_sms_submit, TSMS_RPDU_MESSAGE(rp_data));
+ }
+ else {
+ TSK_DEBUG_ERROR("Failed to create the RP-DATA(SMS-SUBMIT) message");
+ goto bail;
+ }
+
+bail:
+ TSK_OBJECT_SAFE_FREE(buffer);
+ TSK_OBJECT_SAFE_FREE(sms_submit);
+ TSK_OBJECT_SAFE_FREE(rp_data);
+
+ return encodedData;
+}
+
+// More information about RP-DATA: http://www.doubango.org/API/tinySMS/group__tsms__rpdu__group.html#tsms_rpdu_group_DATA
+RPMessage* SMSEncoder::encodeDeliver(int mr, const char* smsc, const char* originator, const char* ascii)
+{
+ int ret;
+ tsk_buffer_t* buffer = tsk_null;
+ tsms_tpdu_deliver_t* sms_deliver = tsk_null;
+ tsms_rpdu_data_t* rp_data = tsk_null;
+
+ RPMessage* encodedData = tsk_null;
+
+ if(!smsc || ! originator || !ascii) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return tsk_null;
+ }
+
+ if(mr<0 || mr>0xFF) {
+ TSK_DEBUG_WARN("Invalid Message Reference");
+ mr &= 0xFF;
+ }
+
+ // create SMS-DELIVER message
+ sms_deliver = tsms_tpdu_deliver_create((const uint8_t*)smsc, (const uint8_t*)originator);
+ // Set content for SMS-DELIVER
+ if((buffer = tsms_pack_to_7bit(ascii))) {
+ ret = tsms_tpdu_deliver_set_userdata(sms_deliver, buffer, tsms_alpha_7bit);
+ TSK_OBJECT_SAFE_FREE(buffer);
+ }
+ // create RP-DATA message
+ if((rp_data = tsms_rpdu_data_create_mt(mr, (const uint8_t*)smsc, TSMS_TPDU_MESSAGE(sms_deliver)))) {
+ encodedData = new RPMessage(twrap_rpmessage_type_sms_deliver, TSMS_RPDU_MESSAGE(rp_data));
+ }
+ else {
+ TSK_DEBUG_ERROR("Failed to create the RP-DATA(SMS-DELIVER) message");
+ goto bail;
+ }
+
+bail:
+ TSK_OBJECT_SAFE_FREE(buffer);
+ TSK_OBJECT_SAFE_FREE(sms_deliver);
+ TSK_OBJECT_SAFE_FREE(rp_data);
+
+ return encodedData;
+}
+
+RPMessage* SMSEncoder::encodeACK(int mr, const char* smsc, const char* destination, bool forSUBMIT)
+{
+ tsms_tpdu_report_t* sms_report = tsk_null;
+ tsms_rpdu_ack_t* rp_ack = tsk_null;
+ tsk_bool_t isSUBMIT = forSUBMIT ? tsk_true : tsk_false;
+ tsk_bool_t isERROR = tsk_false;
+
+ RPMessage* encodedData = tsk_null;
+
+ // create SMS-DELIVER(or SUBMIT)-REPORT message
+ sms_report = tsms_tpdu_report_create((const uint8_t*)smsc, isSUBMIT, isERROR);
+ // create RP-ACK message (From MS to SC)
+ if((rp_ack = tsms_rpdu_ack_create_mo(mr, TSMS_TPDU_MESSAGE(sms_report)))) {
+ encodedData = new RPMessage(twrap_rpmessage_type_sms_ack, TSMS_RPDU_MESSAGE(rp_ack));
+ }
+
+ TSK_OBJECT_SAFE_FREE(sms_report);
+ TSK_OBJECT_SAFE_FREE(rp_ack);
+
+ return encodedData;
+}
+
+RPMessage* SMSEncoder::encodeError(int mr, const char* smsc, const char* destination, bool forSUBMIT)
+{
+ tsms_tpdu_report_t* sms_report = tsk_null;
+ tsms_rpdu_error_t* rp_error= tsk_null;
+ tsk_bool_t isSUBMIT = forSUBMIT ? tsk_true : tsk_false;
+ tsk_bool_t isERROR = tsk_true;
+
+ RPMessage* encodedData = tsk_null;
+
+ // create SMS-DELIVER-REPORT message
+ sms_report = tsms_tpdu_report_create((const uint8_t*)smsc, isSUBMIT, isERROR);
+ // create RP-ERROR message
+ if((rp_error = tsms_rpdu_error_create_mo(mr, TSMS_TPDU_MESSAGE(sms_report), 0x0A/*call barred*/))) {
+ encodedData = new RPMessage(twrap_rpmessage_type_sms_error, TSMS_RPDU_MESSAGE(rp_error));
+ }
+
+ TSK_OBJECT_SAFE_FREE(sms_report);
+ TSK_OBJECT_SAFE_FREE(rp_error);
+
+ return encodedData;
+}
+
+SMSData* SMSEncoder::decode(const void* data, unsigned size, bool MobOrig)
+{
+ tsms_rpdu_message_t* rp_message = tsk_null;
+ tsms_tpdu_message_t* tpdu = tsk_null;
+
+ SMSData* decodedData = tsk_null;
+
+ if(!(rp_message = tsms_rpdu_message_deserialize(data, size))) {
+ TSK_DEBUG_ERROR("Failed to deserialize the RP-MESSAGE");
+ goto bail;
+ }
+
+ switch(rp_message->mti) {
+ case tsms_rpdu_type_data_mo:
+ case tsms_rpdu_type_data_mt: {
+ char* ascii = tsk_null;
+ tsms_rpdu_data_t* rp_data = TSMS_RPDU_DATA(rp_message);
+ if((tpdu = tsms_tpdu_message_deserialize(rp_data->udata->data, rp_data->udata->size, MobOrig))) {
+ if(tpdu->mti == tsms_tpdu_mti_deliver_mt || tpdu->mti == tsms_tpdu_mti_submit_mo) { /* SMS-SUBMIT or SMS-DELIVER? */
+ ascii = tsms_tpdu_message_get_payload(tpdu);
+ decodedData = new SMSData(twrap_sms_type_rpdata, rp_message->mr, ascii, (tsk_size_t)tsk_strlen(ascii));
+
+ if(tpdu->mti == tsms_tpdu_mti_deliver_mt) {
+ tsms_tpdu_deliver_t* tpdu_deliver = (tsms_tpdu_deliver_t*)tpdu;
+ decodedData->setOA(tpdu_deliver->oa ? tpdu_deliver->oa->digits : tsk_null);
+ }
+ /* IMPORTANT: to not uncomment
+ else if(TSK_OBJECT_DEF(tpdu) == tsms_tpdu_submit_def_t){
+ tsms_tpdu_submit_t* tpdu_submit = (tsms_tpdu_submit_t*)tpdu;
+ decodedData->setDA(tpdu_submit->da ? tpdu_submit->da->digits : tsk_null);
+ }*/
+ TSK_FREE(ascii);
+ }
+ }
+ break;
+ }
+ case tsms_rpdu_type_ack_mo:
+ case tsms_rpdu_type_ack_mt: {
+ tsms_rpdu_ack_t* rp_ack = TSMS_RPDU_ACK(rp_message);
+ // ...do whatever you want
+ if(rp_ack->udata && (tpdu = tsms_tpdu_message_deserialize(rp_ack->udata->data, rp_ack->udata->size, MobOrig))) {
+ // ...do whatever you want
+ }
+ decodedData = new SMSData(twrap_sms_type_ack, rp_message->mr, tsk_null, 0);
+ break;
+ }
+ case tsms_rpdu_type_error_mo:
+ case tsms_rpdu_type_error_mt: {
+ tsms_rpdu_error_t* rp_error = TSMS_RPDU_ERROR(rp_message);
+ // ...do whatever you want
+ if(rp_error->udata && (tpdu = tsms_tpdu_message_deserialize(rp_error->udata->data, rp_error->udata->size, MobOrig))) {
+ // ...do whatever you want
+ }
+ decodedData = new SMSData(twrap_sms_type_error, rp_message->mr, tsk_null, 0);
+ break;
+ }
+ case tsms_rpdu_type_smma_mo: {
+ // tsms_rpdu_smma_t* rp_smma = TSMS_RPDU_SMMA(rp_message);
+ // ...do whatever you want
+ decodedData = new SMSData(twrap_sms_type_smma, rp_message->mr, tsk_null, 0);
+ break;
+ }
+ default: {
+ TSK_DEBUG_INFO("Unknown RP-Message type (%u).", rp_message->mti);
+ break;
+ }
+ }
+
+bail:
+ TSK_OBJECT_SAFE_FREE(rp_message);
+ TSK_OBJECT_SAFE_FREE(tpdu);
+
+ return decodedData;
}
\ No newline at end of file diff --git a/bindings/_common/SMSEncoder.h b/bindings/_common/SMSEncoder.h index f38c9d4..674e3ae 100755 --- a/bindings/_common/SMSEncoder.h +++ b/bindings/_common/SMSEncoder.h @@ -1,113 +1,113 @@ -/* -* Copyright (C) 2009 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou@doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_SMSENCODER_H -#define TINYWRAP_SMSENCODER_H - -#include "tinyWRAP_config.h" - -#include "tinysip.h" /* SIP/IMS */ -#include "tinysms.h" /* Binary SMS API*/ - -typedef enum twrap_rpmessage_type_e { - twrap_rpmessage_type_sms_none, - twrap_rpmessage_type_sms_submit, - twrap_rpmessage_type_sms_deliver, - twrap_rpmessage_type_sms_ack, - twrap_rpmessage_type_sms_error, -} -twrap_rpmessage_type_t; - -typedef enum twrap_sms_type_e { - twrap_sms_type_none, - twrap_sms_type_rpdata, - twrap_sms_type_smma, - twrap_sms_type_ack, - twrap_sms_type_error, -} -twrap_sms_type_t; - -class RPMessage -{ -public: -#if !defined(SWIG) - RPMessage(twrap_rpmessage_type_t type, tsms_rpdu_message_t* rp_message); -#endif - RPMessage(); - - virtual ~RPMessage(); - -public: - /* Public API functions */ - twrap_rpmessage_type_t getType(); - unsigned getPayloadLength(); - unsigned getPayload(void* output, unsigned maxsize); - -private: - twrap_rpmessage_type_t type; - tsms_rpdu_message_t* rp_message; - - tsk_buffer_t* tmpBuffer; -}; - -class SMSData -{ -public: -#if !defined(SWIG) - SMSData(twrap_sms_type_t type, int mr, const void* ascii, tsk_size_t size); -#endif - SMSData(); - - virtual ~SMSData(); - -public: - /* Public API functions */ - twrap_sms_type_t getType(); - int getMR(); - unsigned getPayloadLength(); - unsigned getPayload(void* output, unsigned maxsize); - const char* getOA(); - const char* getDA(); -#if !defined(SWIG) - void setOA(const char* oa); - void setDA(const char* da); -#endif - -private: - twrap_sms_type_t type; - int mr; - void* ascii; - char* oa; - char* da; - tsk_size_t size; -}; - -class SMSEncoder -{ -public: - static RPMessage* encodeSubmit(int mr, const char* smsc, const char* destination, const char* ascii); - static RPMessage* encodeDeliver(int mr, const char* smsc, const char* originator, const char* ascii); - static RPMessage* encodeACK(int mr, const char* smsc, const char* destination, bool forSUBMIT); - static RPMessage* encodeError(int mr, const char* smsc, const char* destination, bool forSUBMIT); - static SMSData* decode(const void* data, unsigned size, bool MobOrig); -}; - -#endif /* TINYWRAP_SMSENCODER_H */ +/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou@doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_SMSENCODER_H
+#define TINYWRAP_SMSENCODER_H
+
+#include "tinyWRAP_config.h"
+
+#include "tinysip.h" /* SIP/IMS */
+#include "tinysms.h" /* Binary SMS API*/
+
+typedef enum twrap_rpmessage_type_e {
+ twrap_rpmessage_type_sms_none,
+ twrap_rpmessage_type_sms_submit,
+ twrap_rpmessage_type_sms_deliver,
+ twrap_rpmessage_type_sms_ack,
+ twrap_rpmessage_type_sms_error,
+}
+twrap_rpmessage_type_t;
+
+typedef enum twrap_sms_type_e {
+ twrap_sms_type_none,
+ twrap_sms_type_rpdata,
+ twrap_sms_type_smma,
+ twrap_sms_type_ack,
+ twrap_sms_type_error,
+}
+twrap_sms_type_t;
+
+class RPMessage
+{
+public:
+#if !defined(SWIG)
+ RPMessage(twrap_rpmessage_type_t type, tsms_rpdu_message_t* rp_message);
+#endif
+ RPMessage();
+
+ virtual ~RPMessage();
+
+public:
+ /* Public API functions */
+ twrap_rpmessage_type_t getType();
+ unsigned getPayloadLength();
+ unsigned getPayload(void* output, unsigned maxsize);
+
+private:
+ twrap_rpmessage_type_t type;
+ tsms_rpdu_message_t* rp_message;
+
+ tsk_buffer_t* tmpBuffer;
+};
+
+class SMSData
+{
+public:
+#if !defined(SWIG)
+ SMSData(twrap_sms_type_t type, int mr, const void* ascii, tsk_size_t size);
+#endif
+ SMSData();
+
+ virtual ~SMSData();
+
+public:
+ /* Public API functions */
+ twrap_sms_type_t getType();
+ int getMR();
+ unsigned getPayloadLength();
+ unsigned getPayload(void* output, unsigned maxsize);
+ const char* getOA();
+ const char* getDA();
+#if !defined(SWIG)
+ void setOA(const char* oa);
+ void setDA(const char* da);
+#endif
+
+private:
+ twrap_sms_type_t type;
+ int mr;
+ void* ascii;
+ char* oa;
+ char* da;
+ tsk_size_t size;
+};
+
+class SMSEncoder
+{
+public:
+ static RPMessage* encodeSubmit(int mr, const char* smsc, const char* destination, const char* ascii);
+ static RPMessage* encodeDeliver(int mr, const char* smsc, const char* originator, const char* ascii);
+ static RPMessage* encodeACK(int mr, const char* smsc, const char* destination, bool forSUBMIT);
+ static RPMessage* encodeError(int mr, const char* smsc, const char* destination, bool forSUBMIT);
+ static SMSData* decode(const void* data, unsigned size, bool MobOrig);
+};
+
+#endif /* TINYWRAP_SMSENCODER_H */
diff --git a/bindings/_common/SafeObject.cxx b/bindings/_common/SafeObject.cxx index b0dfc01..c077f94 100755 --- a/bindings/_common/SafeObject.cxx +++ b/bindings/_common/SafeObject.cxx @@ -1,42 +1,42 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "SafeObject.h" - -SafeObject::SafeObject() -{ - this->mutex = tsk_mutex_create(); -} - -int SafeObject::Lock()const -{ - return tsk_mutex_lock(this->mutex); -} - -int SafeObject::UnLock()const -{ - return tsk_mutex_unlock(this->mutex); -} - -SafeObject::~SafeObject() -{ - tsk_mutex_destroy(&this->mutex); -} +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "SafeObject.h"
+
+SafeObject::SafeObject()
+{
+ this->mutex = tsk_mutex_create();
+}
+
+int SafeObject::Lock()const
+{
+ return tsk_mutex_lock(this->mutex);
+}
+
+int SafeObject::UnLock()const
+{
+ return tsk_mutex_unlock(this->mutex);
+}
+
+SafeObject::~SafeObject()
+{
+ tsk_mutex_destroy(&this->mutex);
+}
diff --git a/bindings/_common/SafeObject.h b/bindings/_common/SafeObject.h index bb290b7..2540a9e 100755 --- a/bindings/_common/SafeObject.h +++ b/bindings/_common/SafeObject.h @@ -1,43 +1,43 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_SAFEOBJECT_H -#define TINYWRAP_SAFEOBJECT_H - -#include "tinyWRAP_config.h" - -#include "tsk_mutex.h" - -class TINYWRAP_API SafeObject -{ -public: - SafeObject(); - virtual ~SafeObject(); - - /* protected: */ - int Lock()const; - int UnLock()const; - -private: - tsk_mutex_handle_t *mutex; -}; - -#endif /* TINYWRAP_SAFEOBJECT_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_SAFEOBJECT_H
+#define TINYWRAP_SAFEOBJECT_H
+
+#include "tinyWRAP_config.h"
+
+#include "tsk_mutex.h"
+
+class TINYWRAP_API SafeObject
+{
+public:
+ SafeObject();
+ virtual ~SafeObject();
+
+ /* protected: */
+ int Lock()const;
+ int UnLock()const;
+
+private:
+ tsk_mutex_handle_t *mutex;
+};
+
+#endif /* TINYWRAP_SAFEOBJECT_H */
diff --git a/bindings/_common/SipCallback.cxx b/bindings/_common/SipCallback.cxx index 5785bd9..a7e4875 100755 --- a/bindings/_common/SipCallback.cxx +++ b/bindings/_common/SipCallback.cxx @@ -1,31 +1,31 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "SipCallback.h" - - - - - - - - - +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "SipCallback.h"
+
+
+
+
+
+
+
+
+
diff --git a/bindings/_common/SipCallback.h b/bindings/_common/SipCallback.h index c402628..54fc3e6 100755 --- a/bindings/_common/SipCallback.h +++ b/bindings/_common/SipCallback.h @@ -1,74 +1,74 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_SIPCALLBACK_H -#define TINYWRAP_SIPCALLBACK_H - -class DialogEvent; -class StackEvent; - -class InviteEvent; -class MessagingEvent; -class InfoEvent; -class OptionsEvent; -class PublicationEvent; -class RegistrationEvent; -class SubscriptionEvent; - -class SipCallback -{ -public: - SipCallback() { } - virtual ~SipCallback() {} - virtual int OnDialogEvent(const DialogEvent* e) { - return -1; - } - virtual int OnStackEvent(const StackEvent* e) { - return -1; - } - - virtual int OnInviteEvent(const InviteEvent* e) { - return -1; - } - virtual int OnMessagingEvent(const MessagingEvent* e) { - return -1; - } - virtual int OnInfoEvent(const InfoEvent* e) { - return -1; - } - virtual int OnOptionsEvent(const OptionsEvent* e) { - return -1; - } - virtual int OnPublicationEvent(const PublicationEvent* e) { - return -1; - } - virtual int OnRegistrationEvent(const RegistrationEvent* e) { - return -1; - } - virtual int OnSubscriptionEvent(const SubscriptionEvent* e) { - return -1; - } - -private: - -}; - -#endif /* TINYWRAP_SIPCALLBACK_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_SIPCALLBACK_H
+#define TINYWRAP_SIPCALLBACK_H
+
+class DialogEvent;
+class StackEvent;
+
+class InviteEvent;
+class MessagingEvent;
+class InfoEvent;
+class OptionsEvent;
+class PublicationEvent;
+class RegistrationEvent;
+class SubscriptionEvent;
+
+class SipCallback
+{
+public:
+ SipCallback() { }
+ virtual ~SipCallback() {}
+ virtual int OnDialogEvent(const DialogEvent* e) {
+ return -1;
+ }
+ virtual int OnStackEvent(const StackEvent* e) {
+ return -1;
+ }
+
+ virtual int OnInviteEvent(const InviteEvent* e) {
+ return -1;
+ }
+ virtual int OnMessagingEvent(const MessagingEvent* e) {
+ return -1;
+ }
+ virtual int OnInfoEvent(const InfoEvent* e) {
+ return -1;
+ }
+ virtual int OnOptionsEvent(const OptionsEvent* e) {
+ return -1;
+ }
+ virtual int OnPublicationEvent(const PublicationEvent* e) {
+ return -1;
+ }
+ virtual int OnRegistrationEvent(const RegistrationEvent* e) {
+ return -1;
+ }
+ virtual int OnSubscriptionEvent(const SubscriptionEvent* e) {
+ return -1;
+ }
+
+private:
+
+};
+
+#endif /* TINYWRAP_SIPCALLBACK_H */
diff --git a/bindings/_common/SipEvent.cxx b/bindings/_common/SipEvent.cxx index cc8a8eb..32ffb9cb 100755 --- a/bindings/_common/SipEvent.cxx +++ b/bindings/_common/SipEvent.cxx @@ -1,284 +1,284 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "SipEvent.h" -#include "SipSession.h" -#include "SipMessage.h" - -#include "SipStack.h" - - -#define takeOwnership_Implement(cls, name, session) \ -name##Session* cls##Event::take##session##Ownership() const \ -{ \ - if(this->sipevent && this->sipevent->ss /*&& !tsip_ssession_have_ownership(this->sipevent->ss)*/){ \ - SipStack* stack = this->getStack(); \ - if(stack){ \ - /* The constructor will call take_ownerhip() */ \ - return new name##Session(stack, this->sipevent->ss); \ - } \ - } \ - return tsk_null; \ -} \ - -/* ======================== SipEvent ========================*/ -SipEvent::SipEvent(const tsip_event_t *_sipevent) -{ - this->sipevent = _sipevent; - if(_sipevent) { - this->sipmessage = new SipMessage(_sipevent->sipmessage); - } - else { - this->sipmessage = tsk_null; - } -} - -SipEvent::~SipEvent() -{ - if(this->sipmessage) { - delete this->sipmessage; - } -} - -short SipEvent::getCode() const -{ - return this->sipevent->code; -} - -const char* SipEvent::getPhrase() const -{ - return this->sipevent->phrase; -} - -const SipSession* SipEvent::getBaseSession() const -{ - const void* userdata = tsip_ssession_get_userdata(this->sipevent->ss); - if(userdata) { - return dyn_cast<const SipSession*>((const SipSession*)userdata); - } - return tsk_null; -} - -const SipMessage* SipEvent::getSipMessage() const -{ - return this->sipmessage; -} - -SipStack* SipEvent::getStack()const -{ - const tsip_stack_handle_t* stack_handle = tsip_ssession_get_stack(sipevent->ss); - const void* userdata; - if(stack_handle && (userdata = tsip_stack_get_userdata(stack_handle))) { - return dyn_cast<SipStack*>((SipStack*)userdata); - } - return tsk_null; -} - - -/* ======================== DialogEvent ========================*/ -DialogEvent::DialogEvent(const tsip_event_t *_sipevent) - :SipEvent(_sipevent) { } - -DialogEvent::~DialogEvent() { } - - -/* ======================== DialogEvent ========================*/ -StackEvent::StackEvent(const tsip_event_t *_sipevent) - :SipEvent(_sipevent) { } - -StackEvent::~StackEvent() { } - - -/* ======================== InviteEvent ========================*/ -InviteEvent::InviteEvent(const tsip_event_t *_sipevent) - :SipEvent(_sipevent) -{ -} - -InviteEvent::~InviteEvent() -{ -} - -tsip_invite_event_type_t InviteEvent::getType() const -{ - return TSIP_INVITE_EVENT(this->sipevent)->type; -} - -twrap_media_type_t InviteEvent::getMediaType() const -{ - // Ignore Mixed session (both audio/video and MSRP) as specified by GSMA RCS. - if (this->sipevent && this->sipevent->ss) { - tmedia_type_t type = tsip_ssession_get_mediatype(this->sipevent->ss); - if ((type & tmedia_msrp) == tmedia_msrp) { - return twrap_media_msrp; - } - else { - return twrap_get_wrapped_media_type(type); - } - } - return twrap_media_none; -} - -const InviteSession* InviteEvent::getSession() const -{ - return dyn_cast<const InviteSession*>(this->getBaseSession()); -} - -takeOwnership_Implement(Invite, Call, CallSession); -takeOwnership_Implement(Invite, Msrp, MsrpSession); - -/* ======================== MessagingEvent ========================*/ -MessagingEvent::MessagingEvent(const tsip_event_t *_sipevent) - :SipEvent(_sipevent) -{ -} - -MessagingEvent::~MessagingEvent() -{ -} - -tsip_message_event_type_t MessagingEvent::getType() const -{ - return TSIP_MESSAGE_EVENT(this->sipevent)->type; -} - -const MessagingSession* MessagingEvent::getSession() const -{ - return dyn_cast<const MessagingSession*>(this->getBaseSession()); -} - -takeOwnership_Implement(Messaging, Messaging, Session); - - -/* ======================== InfoEvent ========================*/ -InfoEvent::InfoEvent(const tsip_event_t *_sipevent) - :SipEvent(_sipevent) -{ -} - -InfoEvent::~InfoEvent() -{ -} - -tsip_info_event_type_t InfoEvent::getType() const -{ - return TSIP_INFO_EVENT(this->sipevent)->type; -} - -const InfoSession* InfoEvent::getSession() const -{ - return dyn_cast<const InfoSession*>(this->getBaseSession()); -} - -takeOwnership_Implement(Info, Info, Session); - - - -/* ======================== OptionsEvent ========================*/ -OptionsEvent::OptionsEvent(const tsip_event_t *_sipevent) - :SipEvent(_sipevent) -{ -} - -OptionsEvent::~OptionsEvent() -{ -} - -tsip_options_event_type_t OptionsEvent::getType() const -{ - return TSIP_OPTIONS_EVENT(this->sipevent)->type; -} - -const OptionsSession* OptionsEvent::getSession() const -{ - return dyn_cast<const OptionsSession*>(this->getBaseSession()); -} - -takeOwnership_Implement(Options, Options, Session); - - -/* ======================== PublicationEvent ========================*/ -PublicationEvent::PublicationEvent(const tsip_event_t *_sipevent) - :SipEvent(_sipevent) -{ -} - -PublicationEvent::~PublicationEvent() -{ -} - -tsip_publish_event_type_t PublicationEvent::getType() const -{ - return TSIP_PUBLISH_EVENT(this->sipevent)->type; -} - -const PublicationSession* PublicationEvent::getSession() const -{ - return dyn_cast<const PublicationSession*>(this->getBaseSession()); -} - -takeOwnership_Implement(Publication, Publication, Session); - - -/* ======================== RegistrationEvent ========================*/ -RegistrationEvent::RegistrationEvent(const tsip_event_t *_sipevent) - :SipEvent(_sipevent) -{ -} - -RegistrationEvent::~RegistrationEvent() -{ -} - -tsip_register_event_type_t RegistrationEvent::getType() const -{ - return TSIP_REGISTER_EVENT(this->sipevent)->type; -} - -const RegistrationSession* RegistrationEvent::getSession() const -{ - return dyn_cast<const RegistrationSession*>(this->getBaseSession()); -} - -takeOwnership_Implement(Registration, Registration, Session); - - -/* ======================== SubscriptionEvent ========================*/ -SubscriptionEvent::SubscriptionEvent(const tsip_event_t *sipevent) - :SipEvent(sipevent) -{ -} - -SubscriptionEvent::~SubscriptionEvent() -{ -} - -tsip_subscribe_event_type_t SubscriptionEvent::getType() const -{ - return TSIP_SUBSCRIBE_EVENT(this->sipevent)->type; -} - -const SubscriptionSession* SubscriptionEvent::getSession() const -{ - return dyn_cast<const SubscriptionSession*>(this->getBaseSession()); -} - +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "SipEvent.h"
+#include "SipSession.h"
+#include "SipMessage.h"
+
+#include "SipStack.h"
+
+
+#define takeOwnership_Implement(cls, name, session) \
+name##Session* cls##Event::take##session##Ownership() const \
+{ \
+ if(this->sipevent && this->sipevent->ss /*&& !tsip_ssession_have_ownership(this->sipevent->ss)*/){ \
+ SipStack* stack = this->getStack(); \
+ if(stack){ \
+ /* The constructor will call take_ownerhip() */ \
+ return new name##Session(stack, this->sipevent->ss); \
+ } \
+ } \
+ return tsk_null; \
+} \
+
+/* ======================== SipEvent ========================*/
+SipEvent::SipEvent(const tsip_event_t *_sipevent)
+{
+ this->sipevent = _sipevent;
+ if(_sipevent) {
+ this->sipmessage = new SipMessage(_sipevent->sipmessage);
+ }
+ else {
+ this->sipmessage = tsk_null;
+ }
+}
+
+SipEvent::~SipEvent()
+{
+ if(this->sipmessage) {
+ delete this->sipmessage;
+ }
+}
+
+short SipEvent::getCode() const
+{
+ return this->sipevent->code;
+}
+
+const char* SipEvent::getPhrase() const
+{
+ return this->sipevent->phrase;
+}
+
+const SipSession* SipEvent::getBaseSession() const
+{
+ const void* userdata = tsip_ssession_get_userdata(this->sipevent->ss);
+ if(userdata) {
+ return dyn_cast<const SipSession*>((const SipSession*)userdata);
+ }
+ return tsk_null;
+}
+
+const SipMessage* SipEvent::getSipMessage() const
+{
+ return this->sipmessage;
+}
+
+SipStack* SipEvent::getStack()const
+{
+ const tsip_stack_handle_t* stack_handle = tsip_ssession_get_stack(sipevent->ss);
+ const void* userdata;
+ if(stack_handle && (userdata = tsip_stack_get_userdata(stack_handle))) {
+ return dyn_cast<SipStack*>((SipStack*)userdata);
+ }
+ return tsk_null;
+}
+
+
+/* ======================== DialogEvent ========================*/
+DialogEvent::DialogEvent(const tsip_event_t *_sipevent)
+ :SipEvent(_sipevent) { }
+
+DialogEvent::~DialogEvent() { }
+
+
+/* ======================== DialogEvent ========================*/
+StackEvent::StackEvent(const tsip_event_t *_sipevent)
+ :SipEvent(_sipevent) { }
+
+StackEvent::~StackEvent() { }
+
+
+/* ======================== InviteEvent ========================*/
+InviteEvent::InviteEvent(const tsip_event_t *_sipevent)
+ :SipEvent(_sipevent)
+{
+}
+
+InviteEvent::~InviteEvent()
+{
+}
+
+tsip_invite_event_type_t InviteEvent::getType() const
+{
+ return TSIP_INVITE_EVENT(this->sipevent)->type;
+}
+
+twrap_media_type_t InviteEvent::getMediaType() const
+{
+ // Ignore Mixed session (both audio/video and MSRP) as specified by GSMA RCS.
+ if (this->sipevent && this->sipevent->ss) {
+ tmedia_type_t type = tsip_ssession_get_mediatype(this->sipevent->ss);
+ if ((type & tmedia_msrp) == tmedia_msrp) {
+ return twrap_media_msrp;
+ }
+ else {
+ return twrap_get_wrapped_media_type(type);
+ }
+ }
+ return twrap_media_none;
+}
+
+const InviteSession* InviteEvent::getSession() const
+{
+ return dyn_cast<const InviteSession*>(this->getBaseSession());
+}
+
+takeOwnership_Implement(Invite, Call, CallSession);
+takeOwnership_Implement(Invite, Msrp, MsrpSession);
+
+/* ======================== MessagingEvent ========================*/
+MessagingEvent::MessagingEvent(const tsip_event_t *_sipevent)
+ :SipEvent(_sipevent)
+{
+}
+
+MessagingEvent::~MessagingEvent()
+{
+}
+
+tsip_message_event_type_t MessagingEvent::getType() const
+{
+ return TSIP_MESSAGE_EVENT(this->sipevent)->type;
+}
+
+const MessagingSession* MessagingEvent::getSession() const
+{
+ return dyn_cast<const MessagingSession*>(this->getBaseSession());
+}
+
+takeOwnership_Implement(Messaging, Messaging, Session);
+
+
+/* ======================== InfoEvent ========================*/
+InfoEvent::InfoEvent(const tsip_event_t *_sipevent)
+ :SipEvent(_sipevent)
+{
+}
+
+InfoEvent::~InfoEvent()
+{
+}
+
+tsip_info_event_type_t InfoEvent::getType() const
+{
+ return TSIP_INFO_EVENT(this->sipevent)->type;
+}
+
+const InfoSession* InfoEvent::getSession() const
+{
+ return dyn_cast<const InfoSession*>(this->getBaseSession());
+}
+
+takeOwnership_Implement(Info, Info, Session);
+
+
+
+/* ======================== OptionsEvent ========================*/
+OptionsEvent::OptionsEvent(const tsip_event_t *_sipevent)
+ :SipEvent(_sipevent)
+{
+}
+
+OptionsEvent::~OptionsEvent()
+{
+}
+
+tsip_options_event_type_t OptionsEvent::getType() const
+{
+ return TSIP_OPTIONS_EVENT(this->sipevent)->type;
+}
+
+const OptionsSession* OptionsEvent::getSession() const
+{
+ return dyn_cast<const OptionsSession*>(this->getBaseSession());
+}
+
+takeOwnership_Implement(Options, Options, Session);
+
+
+/* ======================== PublicationEvent ========================*/
+PublicationEvent::PublicationEvent(const tsip_event_t *_sipevent)
+ :SipEvent(_sipevent)
+{
+}
+
+PublicationEvent::~PublicationEvent()
+{
+}
+
+tsip_publish_event_type_t PublicationEvent::getType() const
+{
+ return TSIP_PUBLISH_EVENT(this->sipevent)->type;
+}
+
+const PublicationSession* PublicationEvent::getSession() const
+{
+ return dyn_cast<const PublicationSession*>(this->getBaseSession());
+}
+
+takeOwnership_Implement(Publication, Publication, Session);
+
+
+/* ======================== RegistrationEvent ========================*/
+RegistrationEvent::RegistrationEvent(const tsip_event_t *_sipevent)
+ :SipEvent(_sipevent)
+{
+}
+
+RegistrationEvent::~RegistrationEvent()
+{
+}
+
+tsip_register_event_type_t RegistrationEvent::getType() const
+{
+ return TSIP_REGISTER_EVENT(this->sipevent)->type;
+}
+
+const RegistrationSession* RegistrationEvent::getSession() const
+{
+ return dyn_cast<const RegistrationSession*>(this->getBaseSession());
+}
+
+takeOwnership_Implement(Registration, Registration, Session);
+
+
+/* ======================== SubscriptionEvent ========================*/
+SubscriptionEvent::SubscriptionEvent(const tsip_event_t *sipevent)
+ :SipEvent(sipevent)
+{
+}
+
+SubscriptionEvent::~SubscriptionEvent()
+{
+}
+
+tsip_subscribe_event_type_t SubscriptionEvent::getType() const
+{
+ return TSIP_SUBSCRIBE_EVENT(this->sipevent)->type;
+}
+
+const SubscriptionSession* SubscriptionEvent::getSession() const
+{
+ return dyn_cast<const SubscriptionSession*>(this->getBaseSession());
+}
+
takeOwnership_Implement(Subscription, Subscription, Session);
\ No newline at end of file diff --git a/bindings/_common/SipEvent.h b/bindings/_common/SipEvent.h index c8b67a8..3627845 100755 --- a/bindings/_common/SipEvent.h +++ b/bindings/_common/SipEvent.h @@ -1,218 +1,218 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_SIPEVENT_H -#define TINYWRAP_SIPEVENT_H - -#include "tinyWRAP_config.h" - -#include "tinysip.h" -#include "Common.h" - -class SipStack; - -class SipSession; -class InviteSession; -class CallSession; -class MsrpSession; -class MessagingSession; -class InfoSession; -class OptionsSession; -class PublicationSession; -class RegistrationSession; -class SubscriptionSession; - -class SipMessage; - - -/* ======================== SipEvent ========================*/ -class TINYWRAP_API SipEvent -{ -public: -#if !defined(SWIG) - SipEvent(const tsip_event_t *sipevent); -#endif - virtual ~SipEvent(); - -public: - short getCode() const; - const char* getPhrase() const; - const SipSession* getBaseSession() const; - const SipMessage* getSipMessage() const; -#if !defined(SWIG) - const tsip_event_t * getWrappedEvent() { - return sipevent; - } -#endif -#if !defined(SWIG) - SipStack* getStack()const; -#endif - -protected: - const tsip_event_t *sipevent; - SipMessage* sipmessage; -}; - - -/* ======================== DialogEvent ========================*/ -class TINYWRAP_API DialogEvent: public SipEvent -{ -public: -#if !defined(SWIG) - DialogEvent(const tsip_event_t *sipevent); -#endif - virtual ~DialogEvent(); - -public: /* Public API functions */ -}; - -/* ======================== StackEvent ========================*/ -class TINYWRAP_API StackEvent: public SipEvent -{ -public: -#if !defined(SWIG) - StackEvent(const tsip_event_t *sipevent); -#endif - virtual ~StackEvent(); - -public: /* Public API functions */ -}; - - - -/* ======================== InviteEvent ========================*/ -class TINYWRAP_API InviteEvent: public SipEvent -{ -public: -#if !defined(SWIG) - InviteEvent(const tsip_event_t *sipevent); -#endif - virtual ~InviteEvent(); - -public: /* Public API functions */ - tsip_invite_event_type_t getType() const; - twrap_media_type_t getMediaType() const; - const InviteSession* getSession() const; - CallSession* takeCallSessionOwnership() const; - MsrpSession* takeMsrpSessionOwnership() const; -}; - - - -/* ======================== MessagingEvent ========================*/ -class TINYWRAP_API MessagingEvent: public SipEvent -{ -public: -#if !defined(SWIG) - MessagingEvent(const tsip_event_t *sipevent); -#endif - virtual ~MessagingEvent(); - -public: /* Public API functions */ - tsip_message_event_type_t getType() const; - const MessagingSession* getSession() const; - MessagingSession* takeSessionOwnership() const; -}; - -/* ======================== InfoEvent ========================*/ -class TINYWRAP_API InfoEvent: public SipEvent -{ -public: -#if !defined(SWIG) - InfoEvent(const tsip_event_t *sipevent); -#endif - virtual ~InfoEvent(); - -public: /* Public API functions */ - tsip_info_event_type_t getType() const; - const InfoSession* getSession() const; - InfoSession* takeSessionOwnership() const; -}; - - - -/* ======================== OptionsEvent ========================*/ -class TINYWRAP_API OptionsEvent: public SipEvent -{ -public: -#if !defined(SWIG) - OptionsEvent(const tsip_event_t *sipevent); -#endif - virtual ~OptionsEvent(); - -public: /* Public API functions */ - tsip_options_event_type_t getType() const; - const OptionsSession* getSession() const; - OptionsSession* takeSessionOwnership() const; -}; - - - -/* ======================== PublicationEvent ========================*/ -class TINYWRAP_API PublicationEvent: public SipEvent -{ -public: -#if !defined(SWIG) - PublicationEvent(const tsip_event_t *sipevent); -#endif - virtual ~PublicationEvent(); - -public: /* Public API functions */ - tsip_publish_event_type_t getType() const; - const PublicationSession* getSession() const; - PublicationSession* takeSessionOwnership() const; -}; - - - -/* ======================== RegistrationEvent ========================*/ -class TINYWRAP_API RegistrationEvent: public SipEvent -{ -public: -#if !defined(SWIG) - RegistrationEvent(const tsip_event_t *sipevent); -#endif - virtual ~RegistrationEvent(); - -public: /* Public API functions */ - tsip_register_event_type_t getType() const; - const RegistrationSession* getSession() const; - RegistrationSession* takeSessionOwnership() const; - -}; - - -/* ======================== SubscriptionEvent ========================*/ -class TINYWRAP_API SubscriptionEvent: public SipEvent -{ -public: -#if !defined(SWIG) - SubscriptionEvent(const tsip_event_t *sipevent); -#endif - virtual ~SubscriptionEvent(); - -public: /* Public API functions */ - tsip_subscribe_event_type_t getType() const; - const SubscriptionSession* getSession() const; - SubscriptionSession* takeSessionOwnership() const; -}; - -#endif /* TINYWRAP_SIPEVENT_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_SIPEVENT_H
+#define TINYWRAP_SIPEVENT_H
+
+#include "tinyWRAP_config.h"
+
+#include "tinysip.h"
+#include "Common.h"
+
+class SipStack;
+
+class SipSession;
+class InviteSession;
+class CallSession;
+class MsrpSession;
+class MessagingSession;
+class InfoSession;
+class OptionsSession;
+class PublicationSession;
+class RegistrationSession;
+class SubscriptionSession;
+
+class SipMessage;
+
+
+/* ======================== SipEvent ========================*/
+class TINYWRAP_API SipEvent
+{
+public:
+#if !defined(SWIG)
+ SipEvent(const tsip_event_t *sipevent);
+#endif
+ virtual ~SipEvent();
+
+public:
+ short getCode() const;
+ const char* getPhrase() const;
+ const SipSession* getBaseSession() const;
+ const SipMessage* getSipMessage() const;
+#if !defined(SWIG)
+ const tsip_event_t * getWrappedEvent() {
+ return sipevent;
+ }
+#endif
+#if !defined(SWIG)
+ SipStack* getStack()const;
+#endif
+
+protected:
+ const tsip_event_t *sipevent;
+ SipMessage* sipmessage;
+};
+
+
+/* ======================== DialogEvent ========================*/
+class TINYWRAP_API DialogEvent: public SipEvent
+{
+public:
+#if !defined(SWIG)
+ DialogEvent(const tsip_event_t *sipevent);
+#endif
+ virtual ~DialogEvent();
+
+public: /* Public API functions */
+};
+
+/* ======================== StackEvent ========================*/
+class TINYWRAP_API StackEvent: public SipEvent
+{
+public:
+#if !defined(SWIG)
+ StackEvent(const tsip_event_t *sipevent);
+#endif
+ virtual ~StackEvent();
+
+public: /* Public API functions */
+};
+
+
+
+/* ======================== InviteEvent ========================*/
+class TINYWRAP_API InviteEvent: public SipEvent
+{
+public:
+#if !defined(SWIG)
+ InviteEvent(const tsip_event_t *sipevent);
+#endif
+ virtual ~InviteEvent();
+
+public: /* Public API functions */
+ tsip_invite_event_type_t getType() const;
+ twrap_media_type_t getMediaType() const;
+ const InviteSession* getSession() const;
+ CallSession* takeCallSessionOwnership() const;
+ MsrpSession* takeMsrpSessionOwnership() const;
+};
+
+
+
+/* ======================== MessagingEvent ========================*/
+class TINYWRAP_API MessagingEvent: public SipEvent
+{
+public:
+#if !defined(SWIG)
+ MessagingEvent(const tsip_event_t *sipevent);
+#endif
+ virtual ~MessagingEvent();
+
+public: /* Public API functions */
+ tsip_message_event_type_t getType() const;
+ const MessagingSession* getSession() const;
+ MessagingSession* takeSessionOwnership() const;
+};
+
+/* ======================== InfoEvent ========================*/
+class TINYWRAP_API InfoEvent: public SipEvent
+{
+public:
+#if !defined(SWIG)
+ InfoEvent(const tsip_event_t *sipevent);
+#endif
+ virtual ~InfoEvent();
+
+public: /* Public API functions */
+ tsip_info_event_type_t getType() const;
+ const InfoSession* getSession() const;
+ InfoSession* takeSessionOwnership() const;
+};
+
+
+
+/* ======================== OptionsEvent ========================*/
+class TINYWRAP_API OptionsEvent: public SipEvent
+{
+public:
+#if !defined(SWIG)
+ OptionsEvent(const tsip_event_t *sipevent);
+#endif
+ virtual ~OptionsEvent();
+
+public: /* Public API functions */
+ tsip_options_event_type_t getType() const;
+ const OptionsSession* getSession() const;
+ OptionsSession* takeSessionOwnership() const;
+};
+
+
+
+/* ======================== PublicationEvent ========================*/
+class TINYWRAP_API PublicationEvent: public SipEvent
+{
+public:
+#if !defined(SWIG)
+ PublicationEvent(const tsip_event_t *sipevent);
+#endif
+ virtual ~PublicationEvent();
+
+public: /* Public API functions */
+ tsip_publish_event_type_t getType() const;
+ const PublicationSession* getSession() const;
+ PublicationSession* takeSessionOwnership() const;
+};
+
+
+
+/* ======================== RegistrationEvent ========================*/
+class TINYWRAP_API RegistrationEvent: public SipEvent
+{
+public:
+#if !defined(SWIG)
+ RegistrationEvent(const tsip_event_t *sipevent);
+#endif
+ virtual ~RegistrationEvent();
+
+public: /* Public API functions */
+ tsip_register_event_type_t getType() const;
+ const RegistrationSession* getSession() const;
+ RegistrationSession* takeSessionOwnership() const;
+
+};
+
+
+/* ======================== SubscriptionEvent ========================*/
+class TINYWRAP_API SubscriptionEvent: public SipEvent
+{
+public:
+#if !defined(SWIG)
+ SubscriptionEvent(const tsip_event_t *sipevent);
+#endif
+ virtual ~SubscriptionEvent();
+
+public: /* Public API functions */
+ tsip_subscribe_event_type_t getType() const;
+ const SubscriptionSession* getSession() const;
+ SubscriptionSession* takeSessionOwnership() const;
+};
+
+#endif /* TINYWRAP_SIPEVENT_H */
diff --git a/bindings/_common/SipMessage.cxx b/bindings/_common/SipMessage.cxx index 2f0000b..2516234 100755 --- a/bindings/_common/SipMessage.cxx +++ b/bindings/_common/SipMessage.cxx @@ -1,355 +1,355 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "SipMessage.h" - - -SdpMessage::SdpMessage() - :m_pSdpMessage(tsk_null) -{ -} - -SdpMessage::SdpMessage(tsdp_message_t *_sdpmessage) -{ - m_pSdpMessage = (tsdp_message_t *)tsk_object_ref(_sdpmessage); -} - -SdpMessage::~SdpMessage() -{ - TSK_OBJECT_SAFE_FREE(m_pSdpMessage); -} - -char* SdpMessage::getSdpHeaderValue(const char* media, char name, unsigned index /*= 0*/) -{ - const tsdp_header_M_t* M; - - if((M = (const tsdp_header_M_t*)tsdp_message_get_header(m_pSdpMessage, tsdp_htype_M))) { - tsdp_header_type_t type = tsdp_htype_Dummy; - const tsdp_header_t* header; - switch(name) { - case 'a': - type = tsdp_htype_A; - break; - case 'b': - type = tsdp_htype_B; - break; - case 'c': - type = tsdp_htype_C; - break; - case 'e': - type = tsdp_htype_E; - break; - case 'i': - type = tsdp_htype_I; - break; - case 'k': - type = tsdp_htype_K; - break; - case 'm': - type = tsdp_htype_M; - break; - case 'o': - type = tsdp_htype_O; - break; - - - case 'p': - type = tsdp_htype_P; - break; - case 'r': - type = tsdp_htype_R; - break; - case 's': - type = tsdp_htype_S; - break; - case 't': - type = tsdp_htype_T; - break; - case 'u': - type = tsdp_htype_U; - break; - case 'v': - type = tsdp_htype_V; - break; - case 'z': - type = tsdp_htype_Z; - break; - } - - if((header = tsdp_message_get_headerAt(m_pSdpMessage, type, index))) { - return tsdp_header_tostring(header); - } - } - - return tsk_null; -} - -char* SdpMessage::getSdpHeaderAValue(const char* media, const char* attributeName) -{ - const tsdp_header_M_t* M; - tsk_size_t i; - - for(i = 0; (M = (const tsdp_header_M_t*)tsdp_message_get_headerAt(m_pSdpMessage, tsdp_htype_M, i)); i++) { - if(tsk_striequals(M->media, media)) { - const tsdp_header_A_t* A; - if((A = tsdp_header_M_findA(M, attributeName))) { - return tsk_strdup(A->value); - } - } - } - - return tsk_null; -} - - -SipMessage::SipMessage() - :m_pSipMessage(tsk_null), m_pSdpMessage(tsk_null) -{ -} - -SipMessage::SipMessage(tsip_message_t *_sipmessage) - : m_pSdpMessage(tsk_null) -{ - m_pSipMessage = (tsip_message_t *)tsk_object_ref(_sipmessage); -} - -SipMessage::~SipMessage() -{ - TSK_OBJECT_SAFE_FREE(m_pSipMessage); - if(m_pSdpMessage) { - delete m_pSdpMessage; - } -} - -bool SipMessage::isResponse() -{ - return TSIP_MESSAGE_IS_RESPONSE(m_pSipMessage); -} - -tsip_request_type_t SipMessage::getRequestType() -{ - if(TSIP_MESSAGE_IS_REQUEST(m_pSipMessage)) { - return (m_pSipMessage)->line.request.request_type; - } - return tsip_NONE; -} - -short SipMessage::getResponseCode() -{ - return TSIP_RESPONSE_CODE(m_pSipMessage); -} - -const char* SipMessage::getResponsePhrase() -{ - return TSIP_RESPONSE_PHRASE(m_pSipMessage); -} - -const tsip_header_t* SipMessage::getSipHeader(const char* name, unsigned index /* =0 */) -{ - /* Do not worry about calling tsk_striequals() several times because the function - * is fully optimized. - */ - /* Code below comes from tsip_message_get_headerAt() */ - tsk_size_t pos = 0; - const tsk_list_item_t *item; - const tsip_header_t* hdr = tsk_null; - if(!m_pSipMessage || !name) { - return tsk_null; - } - - if(tsk_striequals(name, "v") || tsk_striequals(name, "via")) { - if(index == 0) { - hdr = (const tsip_header_t*)m_pSipMessage->firstVia; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "f") || tsk_striequals(name, "from")) { - if(index == 0) { - hdr = (const tsip_header_t*)m_pSipMessage->From; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "t") || tsk_striequals(name, "to")) { - if(index == 0) { - hdr = (const tsip_header_t*)m_pSipMessage->To; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "m") || tsk_striequals(name, "contact")) { - if(index == 0) { - hdr = (const tsip_header_t*)m_pSipMessage->Contact; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "i") || tsk_striequals(name, "call-id")) { - if(index == 0) { - hdr = (const tsip_header_t*)m_pSipMessage->Call_ID; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "cseq")) { - if(index == 0) { - hdr = (const tsip_header_t*)m_pSipMessage->CSeq; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "expires")) { - if(index == 0) { - hdr = (const tsip_header_t*)m_pSipMessage->Expires; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "c") || tsk_striequals(name, "content-type")) { - if(index == 0) { - hdr = (const tsip_header_t*)m_pSipMessage->Content_Type; - goto bail; - } - else { - pos++; - } - } - if(tsk_striequals(name, "l") || tsk_striequals(name, "content-length")) { - if(index == 0) { - hdr = (const tsip_header_t*)m_pSipMessage->Content_Length; - goto bail; - } - else { - pos++; - } - } - - - tsk_list_foreach(item, m_pSipMessage->headers) { - if(tsk_striequals(tsip_header_get_name_2(TSIP_HEADER(item->data)), name)) { - if(pos++ >= index) { - hdr = (const tsip_header_t*)item->data; - break; - } - } - } - - -bail: - return hdr; -} - -// e.g. getHeaderParamValue("content-type"); -char* SipMessage::getSipHeaderValue(const char* name, unsigned index /* = 0*/) -{ - const tsip_header_t* header; - if((header = this->getSipHeader(name, index))) { - - switch(header->type) { - case tsip_htype_From: - return tsip_uri_tostring(((const tsip_header_From_t*)header)->uri, tsk_false, tsk_false); - case tsip_htype_To: - return tsip_uri_tostring(((const tsip_header_To_t*)header)->uri, tsk_false, tsk_false); - break; - case tsip_htype_P_Asserted_Identity: - return tsip_uri_tostring(((const tsip_header_P_Asserted_Identity_t*)header)->uri, tsk_false, tsk_false); - break; - - default: - return tsip_header_value_tostring(header); - } - } - // SWIG: %newobject getHeaderValueAt; - return tsk_null; -} - -// e.g. getHeaderParamValue("content-type", "charset"); -char* SipMessage::getSipHeaderParamValue(const char* name, const char* param, unsigned index /*=0*/) -{ - const tsip_header_t* header; - - if((header = this->getSipHeader(name, index))) { - return tsip_header_get_param_value(header, param); - } - - // SWIG: %newobject getSipHeaderParamValue; - return tsk_null; -} - -/** Returns the content length. -*/ -unsigned SipMessage::getSipContentLength() -{ - return TSIP_MESSAGE_CONTENT_DATA_LENGTH(m_pSipMessage); -} - -/** Gets the message content -* @param output A pointer to the output buffer where to copy the data. MUST -* be allocated by the caller. -* @param maxsize The maximum number of octets to copy. Should be less than the size of the -* @a output buffer. You can use @a getSipContentLength() to get the right value to use. -* @retval The number of octet copied in the @a output buffer. -*/ -unsigned SipMessage::getSipContent(void* output, unsigned maxsize) -{ - unsigned retsize = 0; - if(output && maxsize && TSIP_MESSAGE_HAS_CONTENT(m_pSipMessage)) { - retsize = (m_pSipMessage->Content->size > maxsize) ? maxsize : m_pSipMessage->Content->size; - memcpy(output, m_pSipMessage->Content->data, retsize); - } - return retsize; -} - -const void* SipMessage::getSipContentPtr() -{ - if(m_pSipMessage && m_pSipMessage->Content) { - return m_pSipMessage->Content->data; - } - return tsk_null; -} - -const SdpMessage* SipMessage::getSdpMessage() -{ - if(!m_pSdpMessage && TSIP_MESSAGE_HAS_CONTENT(m_pSipMessage)) { - tsdp_message_t* sdp = tsdp_message_parse(m_pSipMessage->Content->data, m_pSipMessage->Content->size); - if(sdp) { - m_pSdpMessage = new SdpMessage(sdp); - TSK_OBJECT_SAFE_FREE(sdp); - } - } - - return m_pSdpMessage; -} +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "SipMessage.h"
+
+
+SdpMessage::SdpMessage()
+ :m_pSdpMessage(tsk_null)
+{
+}
+
+SdpMessage::SdpMessage(tsdp_message_t *_sdpmessage)
+{
+ m_pSdpMessage = (tsdp_message_t *)tsk_object_ref(_sdpmessage);
+}
+
+SdpMessage::~SdpMessage()
+{
+ TSK_OBJECT_SAFE_FREE(m_pSdpMessage);
+}
+
+char* SdpMessage::getSdpHeaderValue(const char* media, char name, unsigned index /*= 0*/)
+{
+ const tsdp_header_M_t* M;
+
+ if((M = (const tsdp_header_M_t*)tsdp_message_get_header(m_pSdpMessage, tsdp_htype_M))) {
+ tsdp_header_type_t type = tsdp_htype_Dummy;
+ const tsdp_header_t* header;
+ switch(name) {
+ case 'a':
+ type = tsdp_htype_A;
+ break;
+ case 'b':
+ type = tsdp_htype_B;
+ break;
+ case 'c':
+ type = tsdp_htype_C;
+ break;
+ case 'e':
+ type = tsdp_htype_E;
+ break;
+ case 'i':
+ type = tsdp_htype_I;
+ break;
+ case 'k':
+ type = tsdp_htype_K;
+ break;
+ case 'm':
+ type = tsdp_htype_M;
+ break;
+ case 'o':
+ type = tsdp_htype_O;
+ break;
+
+
+ case 'p':
+ type = tsdp_htype_P;
+ break;
+ case 'r':
+ type = tsdp_htype_R;
+ break;
+ case 's':
+ type = tsdp_htype_S;
+ break;
+ case 't':
+ type = tsdp_htype_T;
+ break;
+ case 'u':
+ type = tsdp_htype_U;
+ break;
+ case 'v':
+ type = tsdp_htype_V;
+ break;
+ case 'z':
+ type = tsdp_htype_Z;
+ break;
+ }
+
+ if((header = tsdp_message_get_headerAt(m_pSdpMessage, type, index))) {
+ return tsdp_header_tostring(header);
+ }
+ }
+
+ return tsk_null;
+}
+
+char* SdpMessage::getSdpHeaderAValue(const char* media, const char* attributeName)
+{
+ const tsdp_header_M_t* M;
+ tsk_size_t i;
+
+ for(i = 0; (M = (const tsdp_header_M_t*)tsdp_message_get_headerAt(m_pSdpMessage, tsdp_htype_M, i)); i++) {
+ if(tsk_striequals(M->media, media)) {
+ const tsdp_header_A_t* A;
+ if((A = tsdp_header_M_findA(M, attributeName))) {
+ return tsk_strdup(A->value);
+ }
+ }
+ }
+
+ return tsk_null;
+}
+
+
+SipMessage::SipMessage()
+ :m_pSipMessage(tsk_null), m_pSdpMessage(tsk_null)
+{
+}
+
+SipMessage::SipMessage(tsip_message_t *_sipmessage)
+ : m_pSdpMessage(tsk_null)
+{
+ m_pSipMessage = (tsip_message_t *)tsk_object_ref(_sipmessage);
+}
+
+SipMessage::~SipMessage()
+{
+ TSK_OBJECT_SAFE_FREE(m_pSipMessage);
+ if(m_pSdpMessage) {
+ delete m_pSdpMessage;
+ }
+}
+
+bool SipMessage::isResponse()
+{
+ return TSIP_MESSAGE_IS_RESPONSE(m_pSipMessage);
+}
+
+tsip_request_type_t SipMessage::getRequestType()
+{
+ if(TSIP_MESSAGE_IS_REQUEST(m_pSipMessage)) {
+ return (m_pSipMessage)->line.request.request_type;
+ }
+ return tsip_NONE;
+}
+
+short SipMessage::getResponseCode()
+{
+ return TSIP_RESPONSE_CODE(m_pSipMessage);
+}
+
+const char* SipMessage::getResponsePhrase()
+{
+ return TSIP_RESPONSE_PHRASE(m_pSipMessage);
+}
+
+const tsip_header_t* SipMessage::getSipHeader(const char* name, unsigned index /* =0 */)
+{
+ /* Do not worry about calling tsk_striequals() several times because the function
+ * is fully optimized.
+ */
+ /* Code below comes from tsip_message_get_headerAt() */
+ tsk_size_t pos = 0;
+ const tsk_list_item_t *item;
+ const tsip_header_t* hdr = tsk_null;
+ if(!m_pSipMessage || !name) {
+ return tsk_null;
+ }
+
+ if(tsk_striequals(name, "v") || tsk_striequals(name, "via")) {
+ if(index == 0) {
+ hdr = (const tsip_header_t*)m_pSipMessage->firstVia;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "f") || tsk_striequals(name, "from")) {
+ if(index == 0) {
+ hdr = (const tsip_header_t*)m_pSipMessage->From;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "t") || tsk_striequals(name, "to")) {
+ if(index == 0) {
+ hdr = (const tsip_header_t*)m_pSipMessage->To;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "m") || tsk_striequals(name, "contact")) {
+ if(index == 0) {
+ hdr = (const tsip_header_t*)m_pSipMessage->Contact;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "i") || tsk_striequals(name, "call-id")) {
+ if(index == 0) {
+ hdr = (const tsip_header_t*)m_pSipMessage->Call_ID;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "cseq")) {
+ if(index == 0) {
+ hdr = (const tsip_header_t*)m_pSipMessage->CSeq;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "expires")) {
+ if(index == 0) {
+ hdr = (const tsip_header_t*)m_pSipMessage->Expires;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "c") || tsk_striequals(name, "content-type")) {
+ if(index == 0) {
+ hdr = (const tsip_header_t*)m_pSipMessage->Content_Type;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+ if(tsk_striequals(name, "l") || tsk_striequals(name, "content-length")) {
+ if(index == 0) {
+ hdr = (const tsip_header_t*)m_pSipMessage->Content_Length;
+ goto bail;
+ }
+ else {
+ pos++;
+ }
+ }
+
+
+ tsk_list_foreach(item, m_pSipMessage->headers) {
+ if(tsk_striequals(tsip_header_get_name_2(TSIP_HEADER(item->data)), name)) {
+ if(pos++ >= index) {
+ hdr = (const tsip_header_t*)item->data;
+ break;
+ }
+ }
+ }
+
+
+bail:
+ return hdr;
+}
+
+// e.g. getHeaderParamValue("content-type");
+char* SipMessage::getSipHeaderValue(const char* name, unsigned index /* = 0*/)
+{
+ const tsip_header_t* header;
+ if((header = this->getSipHeader(name, index))) {
+
+ switch(header->type) {
+ case tsip_htype_From:
+ return tsip_uri_tostring(((const tsip_header_From_t*)header)->uri, tsk_false, tsk_false);
+ case tsip_htype_To:
+ return tsip_uri_tostring(((const tsip_header_To_t*)header)->uri, tsk_false, tsk_false);
+ break;
+ case tsip_htype_P_Asserted_Identity:
+ return tsip_uri_tostring(((const tsip_header_P_Asserted_Identity_t*)header)->uri, tsk_false, tsk_false);
+ break;
+
+ default:
+ return tsip_header_value_tostring(header);
+ }
+ }
+ // SWIG: %newobject getHeaderValueAt;
+ return tsk_null;
+}
+
+// e.g. getHeaderParamValue("content-type", "charset");
+char* SipMessage::getSipHeaderParamValue(const char* name, const char* param, unsigned index /*=0*/)
+{
+ const tsip_header_t* header;
+
+ if((header = this->getSipHeader(name, index))) {
+ return tsip_header_get_param_value(header, param);
+ }
+
+ // SWIG: %newobject getSipHeaderParamValue;
+ return tsk_null;
+}
+
+/** Returns the content length.
+*/
+unsigned SipMessage::getSipContentLength()
+{
+ return TSIP_MESSAGE_CONTENT_DATA_LENGTH(m_pSipMessage);
+}
+
+/** Gets the message content
+* @param output A pointer to the output buffer where to copy the data. MUST
+* be allocated by the caller.
+* @param maxsize The maximum number of octets to copy. Should be less than the size of the
+* @a output buffer. You can use @a getSipContentLength() to get the right value to use.
+* @retval The number of octet copied in the @a output buffer.
+*/
+unsigned SipMessage::getSipContent(void* output, unsigned maxsize)
+{
+ unsigned retsize = 0;
+ if(output && maxsize && TSIP_MESSAGE_HAS_CONTENT(m_pSipMessage)) {
+ retsize = (m_pSipMessage->Content->size > maxsize) ? maxsize : m_pSipMessage->Content->size;
+ memcpy(output, m_pSipMessage->Content->data, retsize);
+ }
+ return retsize;
+}
+
+const void* SipMessage::getSipContentPtr()
+{
+ if(m_pSipMessage && m_pSipMessage->Content) {
+ return m_pSipMessage->Content->data;
+ }
+ return tsk_null;
+}
+
+const SdpMessage* SipMessage::getSdpMessage()
+{
+ if(!m_pSdpMessage && TSIP_MESSAGE_HAS_CONTENT(m_pSipMessage)) {
+ tsdp_message_t* sdp = tsdp_message_parse(m_pSipMessage->Content->data, m_pSipMessage->Content->size);
+ if(sdp) {
+ m_pSdpMessage = new SdpMessage(sdp);
+ TSK_OBJECT_SAFE_FREE(sdp);
+ }
+ }
+
+ return m_pSdpMessage;
+}
diff --git a/bindings/_common/SipMessage.h b/bindings/_common/SipMessage.h index e63a4a1..6c02d6f 100755 --- a/bindings/_common/SipMessage.h +++ b/bindings/_common/SipMessage.h @@ -1,82 +1,82 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_SIPMESSAGE_H -#define TINYWRAP_SIPMESSAGE_H - -#include "tinyWRAP_config.h" -#include "tinysip.h" - -class TINYWRAP_API SdpMessage -{ -public: - SdpMessage(); -#if !defined(SWIG) - SdpMessage(tsdp_message_t *sdpmessage); -#endif - virtual ~SdpMessage(); - - char* getSdpHeaderValue(const char* media, char name, unsigned index = 0); - char* getSdpHeaderAValue(const char* media, const char* attributeName); -#if !defined(SWIG) - const tsdp_message_t * getWrappedSdpMessage() { - return m_pSdpMessage; - } -#endif - -private: - tsdp_message_t *m_pSdpMessage; -}; - -class TINYWRAP_API SipMessage -{ -public: - SipMessage(); -#if !defined(SWIG) - SipMessage(tsip_message_t *sipmessage); -#endif - virtual ~SipMessage(); - - bool isResponse(); - tsip_request_type_t getRequestType(); - short getResponseCode(); - const char* getResponsePhrase(); - char* getSipHeaderValue(const char* name, unsigned index = 0); - char* getSipHeaderParamValue(const char* name, const char* param, unsigned index = 0); - unsigned getSipContentLength(); - unsigned getSipContent(void* output, unsigned maxsize); -#if !defined(SWIG) - const void* getSipContentPtr(); - const tsip_message_t* getWrappedSipMessage()const { - return m_pSipMessage; - } -#endif - const SdpMessage* getSdpMessage(); - -private: - const tsip_header_t* getSipHeader(const char* name, unsigned index = 0); - -private: - tsip_message_t *m_pSipMessage; - SdpMessage *m_pSdpMessage; -}; - -#endif /* TINYWRAP_SIPMESSAGE_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_SIPMESSAGE_H
+#define TINYWRAP_SIPMESSAGE_H
+
+#include "tinyWRAP_config.h"
+#include "tinysip.h"
+
+class TINYWRAP_API SdpMessage
+{
+public:
+ SdpMessage();
+#if !defined(SWIG)
+ SdpMessage(tsdp_message_t *sdpmessage);
+#endif
+ virtual ~SdpMessage();
+
+ char* getSdpHeaderValue(const char* media, char name, unsigned index = 0);
+ char* getSdpHeaderAValue(const char* media, const char* attributeName);
+#if !defined(SWIG)
+ const tsdp_message_t * getWrappedSdpMessage() {
+ return m_pSdpMessage;
+ }
+#endif
+
+private:
+ tsdp_message_t *m_pSdpMessage;
+};
+
+class TINYWRAP_API SipMessage
+{
+public:
+ SipMessage();
+#if !defined(SWIG)
+ SipMessage(tsip_message_t *sipmessage);
+#endif
+ virtual ~SipMessage();
+
+ bool isResponse();
+ tsip_request_type_t getRequestType();
+ short getResponseCode();
+ const char* getResponsePhrase();
+ char* getSipHeaderValue(const char* name, unsigned index = 0);
+ char* getSipHeaderParamValue(const char* name, const char* param, unsigned index = 0);
+ unsigned getSipContentLength();
+ unsigned getSipContent(void* output, unsigned maxsize);
+#if !defined(SWIG)
+ const void* getSipContentPtr();
+ const tsip_message_t* getWrappedSipMessage()const {
+ return m_pSipMessage;
+ }
+#endif
+ const SdpMessage* getSdpMessage();
+
+private:
+ const tsip_header_t* getSipHeader(const char* name, unsigned index = 0);
+
+private:
+ tsip_message_t *m_pSipMessage;
+ SdpMessage *m_pSdpMessage;
+};
+
+#endif /* TINYWRAP_SIPMESSAGE_H */
diff --git a/bindings/_common/SipSession.cxx b/bindings/_common/SipSession.cxx index 2de0fc8..66aaf02 100755 --- a/bindings/_common/SipSession.cxx +++ b/bindings/_common/SipSession.cxx @@ -1,1043 +1,1043 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "SipSession.h" -#include "SipStack.h" -#include "MediaSessionMgr.h" -#include "SipUri.h" -#include "Msrp.h" - -/* ======================== AsyncAction ========================*/ -typedef struct twrap_async_action_s { - const tsip_ssession_handle_t *session; - const ActionConfig* config; -} -twrap_async_action_t; - - - -/* ======================== SipSession ========================*/ -SipSession::SipSession(SipStack* stack) -{ - init(stack); -} - -SipSession::SipSession(SipStack* stack, tsip_ssession_handle_t* pHandle) -{ - init(stack, pHandle); -} - -SipSession::~SipSession() -{ - tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_USERDATA(tsk_null), - TSIP_SSESSION_SET_NULL()); - - TSK_OBJECT_SAFE_FREE(m_pHandle); -} - -void SipSession::init(SipStack* pStack, tsip_ssession_handle_t* pHandle/*=tsk_null*/) -{ - if(pHandle) { - /* "server-side-session" */ - if(tsip_ssession_have_ownership(pHandle)) { - tsk_object_ref(pHandle); - } - else if(tsip_ssession_take_ownership(pHandle) != 0) { /* should never happen */ - TSK_DEBUG_ERROR("Failed to take ownership"); - return; - } - m_pHandle = pHandle; - } - else { - /* "client-side-session" */ - m_pHandle = tsip_ssession_create(pStack->getHandle(), - TSIP_SSESSION_SET_USERDATA(this), - TSIP_SSESSION_SET_NULL()); - } - - /* set userdata (context) and ref. the stack handle */ - tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_USERDATA(this), - TSIP_SSESSION_SET_NULL()); - m_pStack = pStack; -} - -bool SipSession::addHeader(const char* name, const char* value) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_HEADER(name, value), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::haveOwnership() -{ - return (tsip_ssession_have_ownership(m_pHandle) == tsk_true); -} - -bool SipSession::removeHeader(const char* name) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_UNSET_HEADER(name), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::addCaps(const char* name, const char* value) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_CAPS(name, value), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::addCaps(const char* name) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_CAPS(name, tsk_null), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::removeCaps(const char* name) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_UNSET_CAPS(name), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::setExpires(unsigned expires) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_EXPIRES(expires), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::setFromUri(const char* fromUriString) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_FROM_STR(fromUriString), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::setFromUri(const SipUri* fromUri) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_FROM_OBJ(fromUri->getWrappedUri()), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::setToUri(const char* toUriString) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_TO_STR(toUriString), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::setToUri(const SipUri* toUri) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_TO_OBJ(toUri->getWrappedUri()), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::setSilentHangup(bool silent) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_SILENT_HANGUP(silent ? tsk_true : tsk_false), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::addSigCompCompartment(const char* compId) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_SIGCOMP_COMPARTMENT(compId), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::setAuth(const char* authHa1, const char* authIMPI) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_AUTH_HA1(authHa1), - TSIP_SSESSION_SET_AUTH_IMPI(authIMPI), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool SipSession::removeSigCompCompartment() -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_UNSET_SIGCOMP_COMPARTMENT(), - TSIP_SSESSION_SET_NULL()) == 0); -} - -// FIXME: should be "uint64_t" instead of "unsigned" -unsigned SipSession::getId()const -{ - return (unsigned)tsip_ssession_get_id(m_pHandle); -} - -bool SipSession::setWebSocketSrc(const char* host, int32_t port, const char* proto) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_WEBSOCKET_SRC(host, port, proto), - TSIP_SSESSION_SET_NULL()) == 0); -} - -const SipStack* SipSession::getStack()const -{ - return m_pStack; -} - - -/* ======================== InviteSession ========================*/ - -InviteSession::InviteSession(SipStack* pStack) - : SipSession(pStack), m_pMediaMgr(tsk_null) -{ -} - -InviteSession::InviteSession(SipStack* pStack, tsip_ssession_handle_t* pHandle) - : SipSession(pStack, pHandle), m_pMediaMgr(tsk_null) -{ - -} - -InviteSession::~InviteSession() -{ - if(m_pMediaMgr) { - delete m_pMediaMgr, m_pMediaMgr = tsk_null; - } -} - -bool InviteSession::hangup(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - - return (tsip_api_invite_send_bye(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool InviteSession::reject(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - - return (tsip_api_common_reject(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool InviteSession::accept(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - - return (tsip_api_common_accept(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool InviteSession::sendInfo(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/) -{ - int ret; - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - if(payload && len) { - ret = tsip_api_invite_send_info(m_pHandle, - TSIP_ACTION_SET_PAYLOAD(payload, len), - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()); - } - else { - ret = tsip_api_invite_send_info(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()); - } - return (ret == 0); -} - -const MediaSessionMgr* InviteSession::getMediaMgr() -{ - if(!m_pMediaMgr && m_pHandle) { - tmedia_session_mgr_t* mgr = tsip_session_get_mediamgr(m_pHandle); - if(mgr) { - m_pMediaMgr = new MediaSessionMgr(mgr); // new() it's not yours: see "m_pMediaMgr" which is destroy in the destructor() - tsk_object_unref(mgr); - } - else { - TSK_DEBUG_WARN("No media session associated to this session"); - } - } - return m_pMediaMgr; -} - - -/* ======================== CallSession ========================*/ -CallSession::CallSession(SipStack* Stack) - : InviteSession(Stack) -{ -} - -CallSession::CallSession(SipStack* Stack, tsip_ssession_handle_t* handle) - : InviteSession(Stack, handle) - , m_pT140Callback(tsk_null) - , m_pRtcpCallback(tsk_null) -{ -} - -CallSession::~CallSession() -{ -} - -/* @deprecated */ -bool CallSession::callAudio(const SipUri* remoteUri, ActionConfig* config/*=tsk_null*/) -{ - return call(remoteUri, twrap_media_audio, config); -} - -/* @deprecated */ -bool CallSession::callAudio(const char* remoteUriString, ActionConfig* config/*=tsk_null*/) -{ - return call(remoteUriString, twrap_media_audio, config); -} - -/* @deprecated */ -bool CallSession::callAudioVideo(const SipUri* remoteUri, ActionConfig* config/*=tsk_null*/) -{ - return call(remoteUri, twrap_media_audio_video, config); -} - -/* @deprecated */ -bool CallSession::callAudioVideo(const char* remoteUriString, ActionConfig* config/*=tsk_null*/) -{ - return call(remoteUriString, twrap_media_audio_video, config); -} - -/* @deprecated */ -bool CallSession::callVideo(const SipUri* remoteUri, ActionConfig* config/*=tsk_null*/) -{ - return call(remoteUri, twrap_media_video, config); -} - -/* @deprecated */ -bool CallSession::callVideo(const char* remoteUriString, ActionConfig* config/*=tsk_null*/) -{ - return call(remoteUriString, twrap_media_video, config); -} - -bool CallSession::call(const char* remoteUriString, twrap_media_type_t media, ActionConfig* config/*=tsk_null*/) -{ - - SipUri sipUri(remoteUriString); - if(sipUri.isValid()) { - return call(&sipUri, media, config); - } - TSK_DEBUG_ERROR("Failed to parse sip uri=%s", remoteUriString); - return false; -} - -bool CallSession::call(const SipUri* remoteUri, twrap_media_type_t media, ActionConfig* config/*=tsk_null*/) -{ - if(!remoteUri) { - TSK_DEBUG_ERROR("Invalid parameter"); - return false; - } - tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_TO_OBJ(remoteUri->getWrappedUri()), - TSIP_SSESSION_SET_NULL()); - - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_invite_send_invite(m_pHandle, twrap_get_native_media_type(media), - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool CallSession::setSupportedCodecs(int32_t codecs) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_CODECS(codecs), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - - -int32_t CallSession::getNegotiatedCodecs() -{ - return (int32_t) tsip_ssession_get_codecs_neg(m_pHandle); -} - -bool CallSession::setMediaSSRC(twrap_media_type_t media, uint32_t ssrc) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_RTP_SSRC(twrap_get_native_media_type(media), ssrc), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setSessionTimer(unsigned timeout, const char* refresher) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_TIMERS(timeout, refresher), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::set100rel(bool enabled) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_100rel(enabled ? tsk_true : tsk_false), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setRtcp(bool enabled) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_RTCP(enabled ? tsk_true : tsk_false), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); - -} - -bool CallSession::setRtcpMux(bool enabled) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_RTCPMUX(enabled ? tsk_true : tsk_false), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setSRtpMode(enum tmedia_srtp_mode_e mode) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_SRTP_MODE(mode), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setAvpfMode(enum tmedia_mode_e mode) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_AVPF_MODE(mode), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setICE(bool enabled) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_ICE(enabled ? tsk_true : tsk_false), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setICEStun(bool enabled) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_ICE_STUN(enabled ? tsk_true : tsk_false), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setICETurn(bool enabled) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_ICE_TURN(enabled ? tsk_true : tsk_false), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setSTUNServer(const char* hostname, uint16_t port) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_STUN_SERVER(hostname, port), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setSTUNCred(const char* username, const char* password) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_STUN_CRED(username, password), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setVideoFps(int32_t fps) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_VIDEO_FPS(fps), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setVideoBandwidthUploadMax(int32_t max) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_VIDEO_BW_UP(max), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setVideoBandwidthDownloadMax(int32_t max) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_VIDEO_BW_DOWN(max), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setVideoPrefSize(tmedia_pref_video_size_t pref_video_size) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_VIDEO_PREFSIZE(pref_video_size), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::setQoS(tmedia_qos_stype_t type, tmedia_qos_strength_t strength) -{ - return (tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_QOS(type, strength), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()) == 0); -} - -bool CallSession::hold(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - - return (tsip_api_invite_send_hold(m_pHandle, tmedia_all, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) ==0 ); -} - -bool CallSession::resume(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - - return (tsip_api_invite_send_resume(m_pHandle, tmedia_all, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool CallSession::transfer(const char* referToUriString, ActionConfig* config/*=tsk_null*/) -{ - if(tsk_strnullORempty(referToUriString)) { - TSK_DEBUG_ERROR("Invalid parameter"); - return false; - } - - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_invite_send_ect(m_pHandle, referToUriString, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool CallSession::acceptTransfer(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_invite_send_ect_accept(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool CallSession::rejectTransfer(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_invite_send_ect_reject(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool CallSession::sendDTMF(int number) -{ - return (tsip_api_invite_send_dtmf(m_pHandle, number, - TSIP_ACTION_SET_NULL()) == 0); -} - -unsigned CallSession::getSessionTransferId() -{ - return (unsigned)tsip_ssession_get_id_parent(m_pHandle); -} - -bool CallSession::sendT140Data(enum tmedia_t140_data_type_e data_type, const void* data_ptr /*= NULL*/, unsigned data_size /*= 0*/) -{ - const tmedia_session_mgr_t* pWrappedMgr; - const MediaSessionMgr* pMgr; - if((pMgr = getMediaMgr()) && (pWrappedMgr = pMgr->getWrappedMgr())) { - return (tmedia_session_mgr_send_t140_data((tmedia_session_mgr_t*)pWrappedMgr, data_type, data_ptr, data_size) == 0); - } - return false; -} - -bool CallSession::setT140Callback(const T140Callback* pT140Callback) -{ - const tmedia_session_mgr_t* pWrappedMgr; - const MediaSessionMgr* pMgr; - if((pMgr = getMediaMgr()) && (pWrappedMgr = pMgr->getWrappedMgr())) { - if((m_pT140Callback = pT140Callback)) { - return (tmedia_session_mgr_set_t140_ondata_cbfn((tmedia_session_mgr_t*)pWrappedMgr, this, &CallSession::t140OnDataCallback) == 0); - } - else { - return (tmedia_session_mgr_set_t140_ondata_cbfn((tmedia_session_mgr_t*)pWrappedMgr, this, tsk_null) == 0); - } - } - return false; -} - -bool CallSession::sendRtcpEvent(enum tmedia_rtcp_event_type_e event_type, twrap_media_type_t media_type, uint32_t ssrc_media /*= 0*/) -{ - const tmedia_session_mgr_t* pWrappedMgr; - const MediaSessionMgr* pMgr; - if((pMgr = getMediaMgr()) && (pWrappedMgr = pMgr->getWrappedMgr())) { - return (tmedia_session_mgr_send_rtcp_event((tmedia_session_mgr_t*)pWrappedMgr, twrap_get_native_media_type(media_type), event_type, ssrc_media) == 0); - } - TSK_DEBUG_ERROR("No media manager"); - return false; -} - -bool CallSession::setRtcpCallback(const RtcpCallback* pRtcpCallback, twrap_media_type_t media_type) -{ - const tmedia_session_mgr_t* pWrappedMgr; - const MediaSessionMgr* pMgr; - if((pMgr = getMediaMgr()) && (pWrappedMgr = pMgr->getWrappedMgr())) { - if((m_pRtcpCallback = pRtcpCallback)) { - return (tmedia_session_mgr_set_onrtcp_cbfn((tmedia_session_mgr_t*)pWrappedMgr, twrap_get_native_media_type(media_type), this, &CallSession::rtcpOnCallback) == 0); - } - else { - return (tmedia_session_mgr_set_onrtcp_cbfn((tmedia_session_mgr_t*)pWrappedMgr, twrap_get_native_media_type(media_type), this, tsk_null) == 0); - } - } - return false; -} - -const T140Callback* CallSession::getT140Callback() const -{ - return m_pT140Callback; -} - -int CallSession::t140OnDataCallback(const void* context, enum tmedia_t140_data_type_e data_type, const void* data_ptr, unsigned data_size) -{ - const CallSession* session = dyn_cast<const CallSession*>((const CallSession*)context); - if(session && session->getT140Callback()) { - T140CallbackData* dataObj = new T140CallbackData(data_type, data_ptr, data_size); - if(dataObj) { - int ret = const_cast<T140Callback*>(session->getT140Callback())->ondata(dataObj); - delete dataObj; - return ret; - } - } - return 0; -} - -const RtcpCallback* CallSession::getRtcpCallback() const -{ - return m_pRtcpCallback; -} - -int CallSession::rtcpOnCallback(const void* context, enum tmedia_rtcp_event_type_e event_type, uint32_t ssrc_media) -{ - const CallSession* session = dyn_cast<const CallSession*>((const CallSession*)context); - if(session && session->getRtcpCallback()) { - RtcpCallbackData* dataObj = new RtcpCallbackData(event_type, ssrc_media); - if(dataObj) { - int ret = const_cast<RtcpCallback*>(session->getRtcpCallback())->onevent(dataObj); - delete dataObj; - return ret; - } - } - TSK_DEBUG_INFO("Not Sending RTCP packet (no callback)"); - return 0; -} - -/* ======================== MsrpSession ========================*/ - -MsrpSession::MsrpSession(SipStack* pStack, MsrpCallback* pCallback) - : InviteSession(pStack), m_pCallback(pCallback) -{ - tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_MSRP_CB(twrap_msrp_cb), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()); -} - -MsrpSession::MsrpSession(SipStack* pStack, tsip_ssession_handle_t* pHandle) - : InviteSession(pStack, pHandle), m_pCallback(tsk_null) -{ - tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_MEDIA( - TSIP_MSESSION_SET_MSRP_CB(twrap_msrp_cb), - TSIP_MSESSION_SET_NULL() - ), - TSIP_SSESSION_SET_NULL()); -} - -MsrpSession::~MsrpSession() -{ -} - -bool MsrpSession::setCallback(MsrpCallback* pCallback) -{ - m_pCallback = pCallback; - return true; -} - -bool MsrpSession::callMsrp(const SipUri* remoteUri, ActionConfig* config/*=tsk_null*/) -{ - if(!remoteUri) { - TSK_DEBUG_ERROR("Invalid parameter"); - return false; - } - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - - tsip_ssession_set(m_pHandle, - TSIP_SSESSION_SET_TO_OBJ(remoteUri->getWrappedUri()), - TSIP_SSESSION_SET_NULL()); - - return (tsip_api_invite_send_invite(m_pHandle, tmedia_msrp, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool MsrpSession::callMsrp(const char* remoteUriString, ActionConfig* config/*=tsk_null*/) -{ - SipUri sipUri(remoteUriString); - if(sipUri.isValid()) { - return callMsrp(&sipUri, config); - } - TSK_DEBUG_ERROR("Failed to parse sip uri=%s", remoteUriString); - return false; -} - -bool MsrpSession::sendMessage(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - - return (tsip_api_invite_send_large_message(m_pHandle, - TSIP_ACTION_SET_PAYLOAD(payload, len), - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool MsrpSession::sendFile(ActionConfig* config/*=tsk_null*/) -{ - return false; -} - -/* ======================== MessagingSession ========================*/ -MessagingSession::MessagingSession(SipStack* pStack) - : SipSession(pStack) -{ -} - -MessagingSession::MessagingSession(SipStack* pStack, tsip_ssession_handle_t* pHandle) - : SipSession(pStack, pHandle) -{ -} - -MessagingSession::~MessagingSession() -{ -} - -bool MessagingSession::send(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/) -{ - int ret; - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - if(payload && len) { - ret = tsip_api_message_send_message(m_pHandle, - TSIP_ACTION_SET_PAYLOAD(payload, len), - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()); - } - else { - ret = tsip_api_message_send_message(m_pHandle, - TSIP_ACTION_SET_NULL()); - } - return (ret == 0); -} - -bool MessagingSession::accept(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_common_accept(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool MessagingSession::reject(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_common_reject(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - - - -/* ======================== InfoSession ========================*/ -InfoSession::InfoSession(SipStack* pStack) - : SipSession(pStack) -{ -} - -InfoSession::InfoSession(SipStack* pStack, tsip_ssession_handle_t* pHandle) - : SipSession(pStack, pHandle) -{ -} - -InfoSession::~InfoSession() -{ -} - -bool InfoSession::send(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/) -{ - int ret; - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - if(payload && len) { - ret = tsip_api_info_send_info(m_pHandle, - TSIP_ACTION_SET_PAYLOAD(payload, len), - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()); - } - else { - ret = tsip_api_info_send_info(m_pHandle, - TSIP_ACTION_SET_NULL()); - } - return (ret == 0); -} - -bool InfoSession::accept(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_common_accept(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool InfoSession::reject(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_common_reject(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - - - - -/* ======================== OptionsSession ========================*/ -OptionsSession::OptionsSession(SipStack* pStack) - : SipSession(pStack) -{ -} - -OptionsSession::OptionsSession(SipStack* pStack, tsip_ssession_handle_t* pHandle) - : SipSession(pStack, pHandle) -{ -} - -OptionsSession::~OptionsSession() -{ -} - -bool OptionsSession::send(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_options_send_options(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool OptionsSession::accept(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_common_accept(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool OptionsSession::reject(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_common_reject(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - - - - -/* ======================== PublicationSession ========================*/ -PublicationSession::PublicationSession(SipStack* Stack) - : SipSession(Stack) -{ -} - -PublicationSession::PublicationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle) - : SipSession(pStack, pHandle) -{ - -} - -PublicationSession::~PublicationSession() -{ -} - -bool PublicationSession::publish(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/) -{ - int ret; - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - if(payload && len) { - ret = tsip_api_publish_send_publish(m_pHandle, - TSIP_ACTION_SET_PAYLOAD(payload, len), - TSIP_ACTION_SET_NULL()); - } - else { - ret = tsip_api_publish_send_publish(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()); - } - return (ret == 0); -} - -bool PublicationSession::unPublish(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_publish_send_unpublish(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - - - -/* ======================== RegistrationSession ========================*/ -RegistrationSession::RegistrationSession(SipStack* pStack) - : SipSession(pStack) -{ -} - -RegistrationSession::RegistrationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle) - : SipSession(pStack, pHandle) -{ - -} - -RegistrationSession::~RegistrationSession() -{ -} - -bool RegistrationSession::register_(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_register_send_register(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool RegistrationSession::unRegister(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - return (tsip_api_register_send_unregister(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool RegistrationSession::accept(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - - return (tsip_api_common_accept(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - -bool RegistrationSession::reject(ActionConfig* config/*=tsk_null*/) -{ - const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null; - - return (tsip_api_common_reject(m_pHandle, - TSIP_ACTION_SET_CONFIG(action_cfg), - TSIP_ACTION_SET_NULL()) == 0); -} - - -/* ======================== SubscriptionSession ========================*/ -SubscriptionSession::SubscriptionSession(SipStack* pStack) - : SipSession(pStack) -{ -} - -SubscriptionSession::SubscriptionSession(SipStack* pStack, tsip_ssession_handle_t* pHandle) - : SipSession(pStack, pHandle) -{ - -} - - -SubscriptionSession::~SubscriptionSession() -{ -} - -bool SubscriptionSession::subscribe() -{ - return (tsip_api_subscribe_send_subscribe(m_pHandle, - TSIP_ACTION_SET_NULL()) == 0); -} - -bool SubscriptionSession::unSubscribe() -{ - return (tsip_api_subscribe_send_unsubscribe(m_pHandle, - TSIP_ACTION_SET_NULL()) == 0); -} +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "SipSession.h"
+#include "SipStack.h"
+#include "MediaSessionMgr.h"
+#include "SipUri.h"
+#include "Msrp.h"
+
+/* ======================== AsyncAction ========================*/
+typedef struct twrap_async_action_s {
+ const tsip_ssession_handle_t *session;
+ const ActionConfig* config;
+}
+twrap_async_action_t;
+
+
+
+/* ======================== SipSession ========================*/
+SipSession::SipSession(SipStack* stack)
+{
+ init(stack);
+}
+
+SipSession::SipSession(SipStack* stack, tsip_ssession_handle_t* pHandle)
+{
+ init(stack, pHandle);
+}
+
+SipSession::~SipSession()
+{
+ tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_USERDATA(tsk_null),
+ TSIP_SSESSION_SET_NULL());
+
+ TSK_OBJECT_SAFE_FREE(m_pHandle);
+}
+
+void SipSession::init(SipStack* pStack, tsip_ssession_handle_t* pHandle/*=tsk_null*/)
+{
+ if(pHandle) {
+ /* "server-side-session" */
+ if(tsip_ssession_have_ownership(pHandle)) {
+ tsk_object_ref(pHandle);
+ }
+ else if(tsip_ssession_take_ownership(pHandle) != 0) { /* should never happen */
+ TSK_DEBUG_ERROR("Failed to take ownership");
+ return;
+ }
+ m_pHandle = pHandle;
+ }
+ else {
+ /* "client-side-session" */
+ m_pHandle = tsip_ssession_create(pStack->getHandle(),
+ TSIP_SSESSION_SET_USERDATA(this),
+ TSIP_SSESSION_SET_NULL());
+ }
+
+ /* set userdata (context) and ref. the stack handle */
+ tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_USERDATA(this),
+ TSIP_SSESSION_SET_NULL());
+ m_pStack = pStack;
+}
+
+bool SipSession::addHeader(const char* name, const char* value)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_HEADER(name, value),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::haveOwnership()
+{
+ return (tsip_ssession_have_ownership(m_pHandle) == tsk_true);
+}
+
+bool SipSession::removeHeader(const char* name)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_UNSET_HEADER(name),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::addCaps(const char* name, const char* value)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_CAPS(name, value),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::addCaps(const char* name)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_CAPS(name, tsk_null),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::removeCaps(const char* name)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_UNSET_CAPS(name),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::setExpires(unsigned expires)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_EXPIRES(expires),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::setFromUri(const char* fromUriString)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_FROM_STR(fromUriString),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::setFromUri(const SipUri* fromUri)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_FROM_OBJ(fromUri->getWrappedUri()),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::setToUri(const char* toUriString)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_TO_STR(toUriString),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::setToUri(const SipUri* toUri)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_TO_OBJ(toUri->getWrappedUri()),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::setSilentHangup(bool silent)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_SILENT_HANGUP(silent ? tsk_true : tsk_false),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::addSigCompCompartment(const char* compId)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_SIGCOMP_COMPARTMENT(compId),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::setAuth(const char* authHa1, const char* authIMPI)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_AUTH_HA1(authHa1),
+ TSIP_SSESSION_SET_AUTH_IMPI(authIMPI),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool SipSession::removeSigCompCompartment()
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_UNSET_SIGCOMP_COMPARTMENT(),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+// FIXME: should be "uint64_t" instead of "unsigned"
+unsigned SipSession::getId()const
+{
+ return (unsigned)tsip_ssession_get_id(m_pHandle);
+}
+
+bool SipSession::setWebSocketSrc(const char* host, int32_t port, const char* proto)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_WEBSOCKET_SRC(host, port, proto),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+const SipStack* SipSession::getStack()const
+{
+ return m_pStack;
+}
+
+
+/* ======================== InviteSession ========================*/
+
+InviteSession::InviteSession(SipStack* pStack)
+ : SipSession(pStack), m_pMediaMgr(tsk_null)
+{
+}
+
+InviteSession::InviteSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
+ : SipSession(pStack, pHandle), m_pMediaMgr(tsk_null)
+{
+
+}
+
+InviteSession::~InviteSession()
+{
+ if(m_pMediaMgr) {
+ delete m_pMediaMgr, m_pMediaMgr = tsk_null;
+ }
+}
+
+bool InviteSession::hangup(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+
+ return (tsip_api_invite_send_bye(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool InviteSession::reject(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+
+ return (tsip_api_common_reject(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool InviteSession::accept(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+
+ return (tsip_api_common_accept(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool InviteSession::sendInfo(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/)
+{
+ int ret;
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ if(payload && len) {
+ ret = tsip_api_invite_send_info(m_pHandle,
+ TSIP_ACTION_SET_PAYLOAD(payload, len),
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL());
+ }
+ else {
+ ret = tsip_api_invite_send_info(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL());
+ }
+ return (ret == 0);
+}
+
+const MediaSessionMgr* InviteSession::getMediaMgr()
+{
+ if(!m_pMediaMgr && m_pHandle) {
+ tmedia_session_mgr_t* mgr = tsip_session_get_mediamgr(m_pHandle);
+ if(mgr) {
+ m_pMediaMgr = new MediaSessionMgr(mgr); // new() it's not yours: see "m_pMediaMgr" which is destroy in the destructor()
+ tsk_object_unref(mgr);
+ }
+ else {
+ TSK_DEBUG_WARN("No media session associated to this session");
+ }
+ }
+ return m_pMediaMgr;
+}
+
+
+/* ======================== CallSession ========================*/
+CallSession::CallSession(SipStack* Stack)
+ : InviteSession(Stack)
+{
+}
+
+CallSession::CallSession(SipStack* Stack, tsip_ssession_handle_t* handle)
+ : InviteSession(Stack, handle)
+ , m_pT140Callback(tsk_null)
+ , m_pRtcpCallback(tsk_null)
+{
+}
+
+CallSession::~CallSession()
+{
+}
+
+/* @deprecated */
+bool CallSession::callAudio(const SipUri* remoteUri, ActionConfig* config/*=tsk_null*/)
+{
+ return call(remoteUri, twrap_media_audio, config);
+}
+
+/* @deprecated */
+bool CallSession::callAudio(const char* remoteUriString, ActionConfig* config/*=tsk_null*/)
+{
+ return call(remoteUriString, twrap_media_audio, config);
+}
+
+/* @deprecated */
+bool CallSession::callAudioVideo(const SipUri* remoteUri, ActionConfig* config/*=tsk_null*/)
+{
+ return call(remoteUri, twrap_media_audio_video, config);
+}
+
+/* @deprecated */
+bool CallSession::callAudioVideo(const char* remoteUriString, ActionConfig* config/*=tsk_null*/)
+{
+ return call(remoteUriString, twrap_media_audio_video, config);
+}
+
+/* @deprecated */
+bool CallSession::callVideo(const SipUri* remoteUri, ActionConfig* config/*=tsk_null*/)
+{
+ return call(remoteUri, twrap_media_video, config);
+}
+
+/* @deprecated */
+bool CallSession::callVideo(const char* remoteUriString, ActionConfig* config/*=tsk_null*/)
+{
+ return call(remoteUriString, twrap_media_video, config);
+}
+
+bool CallSession::call(const char* remoteUriString, twrap_media_type_t media, ActionConfig* config/*=tsk_null*/)
+{
+
+ SipUri sipUri(remoteUriString);
+ if(sipUri.isValid()) {
+ return call(&sipUri, media, config);
+ }
+ TSK_DEBUG_ERROR("Failed to parse sip uri=%s", remoteUriString);
+ return false;
+}
+
+bool CallSession::call(const SipUri* remoteUri, twrap_media_type_t media, ActionConfig* config/*=tsk_null*/)
+{
+ if(!remoteUri) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return false;
+ }
+ tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_TO_OBJ(remoteUri->getWrappedUri()),
+ TSIP_SSESSION_SET_NULL());
+
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_invite_send_invite(m_pHandle, twrap_get_native_media_type(media),
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool CallSession::setSupportedCodecs(int32_t codecs)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_CODECS(codecs),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+
+int32_t CallSession::getNegotiatedCodecs()
+{
+ return (int32_t) tsip_ssession_get_codecs_neg(m_pHandle);
+}
+
+bool CallSession::setMediaSSRC(twrap_media_type_t media, uint32_t ssrc)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_RTP_SSRC(twrap_get_native_media_type(media), ssrc),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setSessionTimer(unsigned timeout, const char* refresher)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_TIMERS(timeout, refresher),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::set100rel(bool enabled)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_100rel(enabled ? tsk_true : tsk_false),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setRtcp(bool enabled)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_RTCP(enabled ? tsk_true : tsk_false),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+
+}
+
+bool CallSession::setRtcpMux(bool enabled)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_RTCPMUX(enabled ? tsk_true : tsk_false),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setSRtpMode(enum tmedia_srtp_mode_e mode)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_SRTP_MODE(mode),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setAvpfMode(enum tmedia_mode_e mode)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_AVPF_MODE(mode),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setICE(bool enabled)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_ICE(enabled ? tsk_true : tsk_false),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setICEStun(bool enabled)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_ICE_STUN(enabled ? tsk_true : tsk_false),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setICETurn(bool enabled)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_ICE_TURN(enabled ? tsk_true : tsk_false),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setSTUNServer(const char* hostname, uint16_t port)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_STUN_SERVER(hostname, port),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setSTUNCred(const char* username, const char* password)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_STUN_CRED(username, password),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setVideoFps(int32_t fps)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_VIDEO_FPS(fps),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setVideoBandwidthUploadMax(int32_t max)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_VIDEO_BW_UP(max),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setVideoBandwidthDownloadMax(int32_t max)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_VIDEO_BW_DOWN(max),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setVideoPrefSize(tmedia_pref_video_size_t pref_video_size)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_VIDEO_PREFSIZE(pref_video_size),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::setQoS(tmedia_qos_stype_t type, tmedia_qos_strength_t strength)
+{
+ return (tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_QOS(type, strength),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL()) == 0);
+}
+
+bool CallSession::hold(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+
+ return (tsip_api_invite_send_hold(m_pHandle, tmedia_all,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) ==0 );
+}
+
+bool CallSession::resume(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+
+ return (tsip_api_invite_send_resume(m_pHandle, tmedia_all,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool CallSession::transfer(const char* referToUriString, ActionConfig* config/*=tsk_null*/)
+{
+ if(tsk_strnullORempty(referToUriString)) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return false;
+ }
+
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_invite_send_ect(m_pHandle, referToUriString,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool CallSession::acceptTransfer(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_invite_send_ect_accept(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool CallSession::rejectTransfer(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_invite_send_ect_reject(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool CallSession::sendDTMF(int number)
+{
+ return (tsip_api_invite_send_dtmf(m_pHandle, number,
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+unsigned CallSession::getSessionTransferId()
+{
+ return (unsigned)tsip_ssession_get_id_parent(m_pHandle);
+}
+
+bool CallSession::sendT140Data(enum tmedia_t140_data_type_e data_type, const void* data_ptr /*= NULL*/, unsigned data_size /*= 0*/)
+{
+ const tmedia_session_mgr_t* pWrappedMgr;
+ const MediaSessionMgr* pMgr;
+ if((pMgr = getMediaMgr()) && (pWrappedMgr = pMgr->getWrappedMgr())) {
+ return (tmedia_session_mgr_send_t140_data((tmedia_session_mgr_t*)pWrappedMgr, data_type, data_ptr, data_size) == 0);
+ }
+ return false;
+}
+
+bool CallSession::setT140Callback(const T140Callback* pT140Callback)
+{
+ const tmedia_session_mgr_t* pWrappedMgr;
+ const MediaSessionMgr* pMgr;
+ if((pMgr = getMediaMgr()) && (pWrappedMgr = pMgr->getWrappedMgr())) {
+ if((m_pT140Callback = pT140Callback)) {
+ return (tmedia_session_mgr_set_t140_ondata_cbfn((tmedia_session_mgr_t*)pWrappedMgr, this, &CallSession::t140OnDataCallback) == 0);
+ }
+ else {
+ return (tmedia_session_mgr_set_t140_ondata_cbfn((tmedia_session_mgr_t*)pWrappedMgr, this, tsk_null) == 0);
+ }
+ }
+ return false;
+}
+
+bool CallSession::sendRtcpEvent(enum tmedia_rtcp_event_type_e event_type, twrap_media_type_t media_type, uint32_t ssrc_media /*= 0*/)
+{
+ const tmedia_session_mgr_t* pWrappedMgr;
+ const MediaSessionMgr* pMgr;
+ if((pMgr = getMediaMgr()) && (pWrappedMgr = pMgr->getWrappedMgr())) {
+ return (tmedia_session_mgr_send_rtcp_event((tmedia_session_mgr_t*)pWrappedMgr, twrap_get_native_media_type(media_type), event_type, ssrc_media) == 0);
+ }
+ TSK_DEBUG_ERROR("No media manager");
+ return false;
+}
+
+bool CallSession::setRtcpCallback(const RtcpCallback* pRtcpCallback, twrap_media_type_t media_type)
+{
+ const tmedia_session_mgr_t* pWrappedMgr;
+ const MediaSessionMgr* pMgr;
+ if((pMgr = getMediaMgr()) && (pWrappedMgr = pMgr->getWrappedMgr())) {
+ if((m_pRtcpCallback = pRtcpCallback)) {
+ return (tmedia_session_mgr_set_onrtcp_cbfn((tmedia_session_mgr_t*)pWrappedMgr, twrap_get_native_media_type(media_type), this, &CallSession::rtcpOnCallback) == 0);
+ }
+ else {
+ return (tmedia_session_mgr_set_onrtcp_cbfn((tmedia_session_mgr_t*)pWrappedMgr, twrap_get_native_media_type(media_type), this, tsk_null) == 0);
+ }
+ }
+ return false;
+}
+
+const T140Callback* CallSession::getT140Callback() const
+{
+ return m_pT140Callback;
+}
+
+int CallSession::t140OnDataCallback(const void* context, enum tmedia_t140_data_type_e data_type, const void* data_ptr, unsigned data_size)
+{
+ const CallSession* session = dyn_cast<const CallSession*>((const CallSession*)context);
+ if(session && session->getT140Callback()) {
+ T140CallbackData* dataObj = new T140CallbackData(data_type, data_ptr, data_size);
+ if(dataObj) {
+ int ret = const_cast<T140Callback*>(session->getT140Callback())->ondata(dataObj);
+ delete dataObj;
+ return ret;
+ }
+ }
+ return 0;
+}
+
+const RtcpCallback* CallSession::getRtcpCallback() const
+{
+ return m_pRtcpCallback;
+}
+
+int CallSession::rtcpOnCallback(const void* context, enum tmedia_rtcp_event_type_e event_type, uint32_t ssrc_media)
+{
+ const CallSession* session = dyn_cast<const CallSession*>((const CallSession*)context);
+ if(session && session->getRtcpCallback()) {
+ RtcpCallbackData* dataObj = new RtcpCallbackData(event_type, ssrc_media);
+ if(dataObj) {
+ int ret = const_cast<RtcpCallback*>(session->getRtcpCallback())->onevent(dataObj);
+ delete dataObj;
+ return ret;
+ }
+ }
+ TSK_DEBUG_INFO("Not Sending RTCP packet (no callback)");
+ return 0;
+}
+
+/* ======================== MsrpSession ========================*/
+
+MsrpSession::MsrpSession(SipStack* pStack, MsrpCallback* pCallback)
+ : InviteSession(pStack), m_pCallback(pCallback)
+{
+ tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_MSRP_CB(twrap_msrp_cb),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL());
+}
+
+MsrpSession::MsrpSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
+ : InviteSession(pStack, pHandle), m_pCallback(tsk_null)
+{
+ tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_MEDIA(
+ TSIP_MSESSION_SET_MSRP_CB(twrap_msrp_cb),
+ TSIP_MSESSION_SET_NULL()
+ ),
+ TSIP_SSESSION_SET_NULL());
+}
+
+MsrpSession::~MsrpSession()
+{
+}
+
+bool MsrpSession::setCallback(MsrpCallback* pCallback)
+{
+ m_pCallback = pCallback;
+ return true;
+}
+
+bool MsrpSession::callMsrp(const SipUri* remoteUri, ActionConfig* config/*=tsk_null*/)
+{
+ if(!remoteUri) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return false;
+ }
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+
+ tsip_ssession_set(m_pHandle,
+ TSIP_SSESSION_SET_TO_OBJ(remoteUri->getWrappedUri()),
+ TSIP_SSESSION_SET_NULL());
+
+ return (tsip_api_invite_send_invite(m_pHandle, tmedia_msrp,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool MsrpSession::callMsrp(const char* remoteUriString, ActionConfig* config/*=tsk_null*/)
+{
+ SipUri sipUri(remoteUriString);
+ if(sipUri.isValid()) {
+ return callMsrp(&sipUri, config);
+ }
+ TSK_DEBUG_ERROR("Failed to parse sip uri=%s", remoteUriString);
+ return false;
+}
+
+bool MsrpSession::sendMessage(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+
+ return (tsip_api_invite_send_large_message(m_pHandle,
+ TSIP_ACTION_SET_PAYLOAD(payload, len),
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool MsrpSession::sendFile(ActionConfig* config/*=tsk_null*/)
+{
+ return false;
+}
+
+/* ======================== MessagingSession ========================*/
+MessagingSession::MessagingSession(SipStack* pStack)
+ : SipSession(pStack)
+{
+}
+
+MessagingSession::MessagingSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
+ : SipSession(pStack, pHandle)
+{
+}
+
+MessagingSession::~MessagingSession()
+{
+}
+
+bool MessagingSession::send(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/)
+{
+ int ret;
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ if(payload && len) {
+ ret = tsip_api_message_send_message(m_pHandle,
+ TSIP_ACTION_SET_PAYLOAD(payload, len),
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL());
+ }
+ else {
+ ret = tsip_api_message_send_message(m_pHandle,
+ TSIP_ACTION_SET_NULL());
+ }
+ return (ret == 0);
+}
+
+bool MessagingSession::accept(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_common_accept(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool MessagingSession::reject(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_common_reject(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+
+
+/* ======================== InfoSession ========================*/
+InfoSession::InfoSession(SipStack* pStack)
+ : SipSession(pStack)
+{
+}
+
+InfoSession::InfoSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
+ : SipSession(pStack, pHandle)
+{
+}
+
+InfoSession::~InfoSession()
+{
+}
+
+bool InfoSession::send(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/)
+{
+ int ret;
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ if(payload && len) {
+ ret = tsip_api_info_send_info(m_pHandle,
+ TSIP_ACTION_SET_PAYLOAD(payload, len),
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL());
+ }
+ else {
+ ret = tsip_api_info_send_info(m_pHandle,
+ TSIP_ACTION_SET_NULL());
+ }
+ return (ret == 0);
+}
+
+bool InfoSession::accept(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_common_accept(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool InfoSession::reject(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_common_reject(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+
+
+
+/* ======================== OptionsSession ========================*/
+OptionsSession::OptionsSession(SipStack* pStack)
+ : SipSession(pStack)
+{
+}
+
+OptionsSession::OptionsSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
+ : SipSession(pStack, pHandle)
+{
+}
+
+OptionsSession::~OptionsSession()
+{
+}
+
+bool OptionsSession::send(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_options_send_options(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool OptionsSession::accept(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_common_accept(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool OptionsSession::reject(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_common_reject(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+
+
+
+/* ======================== PublicationSession ========================*/
+PublicationSession::PublicationSession(SipStack* Stack)
+ : SipSession(Stack)
+{
+}
+
+PublicationSession::PublicationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
+ : SipSession(pStack, pHandle)
+{
+
+}
+
+PublicationSession::~PublicationSession()
+{
+}
+
+bool PublicationSession::publish(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/)
+{
+ int ret;
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ if(payload && len) {
+ ret = tsip_api_publish_send_publish(m_pHandle,
+ TSIP_ACTION_SET_PAYLOAD(payload, len),
+ TSIP_ACTION_SET_NULL());
+ }
+ else {
+ ret = tsip_api_publish_send_publish(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL());
+ }
+ return (ret == 0);
+}
+
+bool PublicationSession::unPublish(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_publish_send_unpublish(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+
+
+/* ======================== RegistrationSession ========================*/
+RegistrationSession::RegistrationSession(SipStack* pStack)
+ : SipSession(pStack)
+{
+}
+
+RegistrationSession::RegistrationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
+ : SipSession(pStack, pHandle)
+{
+
+}
+
+RegistrationSession::~RegistrationSession()
+{
+}
+
+bool RegistrationSession::register_(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_register_send_register(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool RegistrationSession::unRegister(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+ return (tsip_api_register_send_unregister(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool RegistrationSession::accept(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+
+ return (tsip_api_common_accept(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool RegistrationSession::reject(ActionConfig* config/*=tsk_null*/)
+{
+ const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
+
+ return (tsip_api_common_reject(m_pHandle,
+ TSIP_ACTION_SET_CONFIG(action_cfg),
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+
+/* ======================== SubscriptionSession ========================*/
+SubscriptionSession::SubscriptionSession(SipStack* pStack)
+ : SipSession(pStack)
+{
+}
+
+SubscriptionSession::SubscriptionSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
+ : SipSession(pStack, pHandle)
+{
+
+}
+
+
+SubscriptionSession::~SubscriptionSession()
+{
+}
+
+bool SubscriptionSession::subscribe()
+{
+ return (tsip_api_subscribe_send_subscribe(m_pHandle,
+ TSIP_ACTION_SET_NULL()) == 0);
+}
+
+bool SubscriptionSession::unSubscribe()
+{
+ return (tsip_api_subscribe_send_unsubscribe(m_pHandle,
+ TSIP_ACTION_SET_NULL()) == 0);
+}
diff --git a/bindings/_common/SipSession.h b/bindings/_common/SipSession.h index a77418d..ebe5285 100755 --- a/bindings/_common/SipSession.h +++ b/bindings/_common/SipSession.h @@ -1,374 +1,374 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_SIPSESSION_H -#define TINYWRAP_SIPSESSION_H - -#include "tinyWRAP_config.h" - -#include "tinysip.h" -#include "tinymedia/tmedia_qos.h" -#include "ActionConfig.h" - -class SipUri; -class SipStack; -class MsrpCallback; -class MediaSessionMgr; - -/* ======================== T140Callback ========================*/ -class TINYWRAP_API T140CallbackData -{ -public: -#if !defined(SWIG) - T140CallbackData(enum tmedia_t140_data_type_e data_type, const void* data_ptr, unsigned data_size) { - m_eType = data_type; - m_pPtr = data_ptr; - m_nSize = data_size; - } -#endif - virtual ~T140CallbackData() {} - - inline enum tmedia_t140_data_type_e getType()const { - return m_eType; - } - inline unsigned getSize()const { - return m_nSize; - } - inline unsigned getData(void* pOutput, unsigned nMaxsize)const { - unsigned nRetsize = 0; - if(pOutput && nMaxsize && m_pPtr) { - nRetsize = (m_nSize > nMaxsize) ? nMaxsize : m_nSize; - memcpy(pOutput, m_pPtr, nRetsize); - } - return nRetsize; - } - -private: - enum tmedia_t140_data_type_e m_eType; - const void* m_pPtr; - unsigned m_nSize; -}; - -class TINYWRAP_API T140Callback -{ -public: - T140Callback() {} - virtual ~T140Callback() {} - virtual int ondata(const T140CallbackData* pData) { - return 0; - } -}; - -#if !defined(SWIG) -class RtcpCallbackData -{ -public: - RtcpCallbackData(enum tmedia_rtcp_event_type_e event_type, uint32_t ssrc_media) { - m_eType = event_type; - m_nSSRC = ssrc_media; - } - virtual ~RtcpCallbackData() {} - inline enum tmedia_rtcp_event_type_e getType()const { - return m_eType; - } - inline uint32_t getSSRC()const { - return m_nSSRC; - } -private: - enum tmedia_rtcp_event_type_e m_eType; - uint32_t m_nSSRC; -}; - -class TINYWRAP_API RtcpCallback -{ -public: - RtcpCallback() {} - virtual ~RtcpCallback() {} - virtual int onevent(const RtcpCallbackData* e) { - return 0; - } -}; -#endif /* #if !defined(SWIG) */ - - - -/* ======================== SipSession ========================*/ -class TINYWRAP_API SipSession -{ -public: - SipSession(SipStack* stack); -#if !defined(SWIG) - SipSession(SipStack* stack, tsip_ssession_handle_t* pHandle); -#endif - virtual ~SipSession(); - -public: - bool haveOwnership(); - bool addHeader(const char* name, const char* value); - bool removeHeader(const char* name); - bool addCaps(const char* name, const char* value); - bool addCaps(const char* name); - bool removeCaps(const char* name); - bool setExpires(unsigned expires); - bool setFromUri(const char* fromUriString); - bool setFromUri(const SipUri* fromUri); - bool setToUri(const char* toUriString); - bool setToUri(const SipUri* toUri); - bool setSilentHangup(bool silent); - bool addSigCompCompartment(const char* compId); - bool removeSigCompCompartment(); -#if !defined(SWIG) - bool setAuth(const char* authHa1, const char* authIMPI); -#endif - unsigned getId()const; - -#if !defined(SWIG) - bool setWebSocketSrc(const char* host, int32_t port, const char* proto); - const SipStack* getStack() const; - const tsip_ssession_handle_t* getWrappedSession() { - return m_pHandle; - } -#endif - -private: - void init(SipStack* stack, tsip_ssession_handle_t* pHandle=tsk_null); - -protected: - tsip_ssession_handle_t* m_pHandle; - const SipStack* m_pStack; -}; - -/* ======================== InviteSession ========================*/ -class TINYWRAP_API InviteSession : public SipSession -{ -public: /* ctor() and dtor() */ - InviteSession(SipStack* Stack); -#if !defined(SWIG) - InviteSession(SipStack* pStack, tsip_ssession_handle_t* pHandle); -#endif - virtual ~InviteSession(); - -public: /* Public functions */ - bool accept(ActionConfig* config=tsk_null); - bool hangup(ActionConfig* config=tsk_null); - bool reject(ActionConfig* config=tsk_null); - bool sendInfo(const void* payload, unsigned len, ActionConfig* config=tsk_null); - const MediaSessionMgr* getMediaMgr(); - -private: - MediaSessionMgr* m_pMediaMgr; -}; - - -/* ======================== CallSession ========================*/ -class TINYWRAP_API CallSession : public InviteSession -{ -public: /* ctor() and dtor() */ - CallSession(SipStack* pStack); -#if !defined(SWIG) - CallSession(SipStack* pStack, tsip_ssession_handle_t* pHandle); -#endif - virtual ~CallSession(); - -public: /* Public functions */ - bool callAudio(const char* remoteUriString, ActionConfig* config=tsk_null); /* @deprecated */ - bool callAudio(const SipUri* remoteUri, ActionConfig* config=tsk_null); /* @deprecated */ - bool callAudioVideo(const char* remoteUriString, ActionConfig* config=tsk_null); /* @deprecated */ - bool callAudioVideo(const SipUri* remoteUri, ActionConfig* config=tsk_null); /* @deprecated */ - bool callVideo(const char* remoteUriString, ActionConfig* config=tsk_null); /* @deprecated */ - bool callVideo(const SipUri* remoteUri, ActionConfig* config=tsk_null); /* @deprecated */ - - bool call(const char* remoteUriString, twrap_media_type_t media, ActionConfig* config=tsk_null); - bool call(const SipUri* remoteUri, twrap_media_type_t media, ActionConfig* config=tsk_null); -#if !defined(SWIG) - bool setSupportedCodecs(int32_t codecs); - int32_t getNegotiatedCodecs(); - bool setMediaSSRC(twrap_media_type_t media, uint32_t ssrc); -#endif - bool setSessionTimer(unsigned timeout, const char* refresher); - bool set100rel(bool enabled); - bool setRtcp(bool enabled); - bool setRtcpMux(bool enabled); - bool setSRtpMode(enum tmedia_srtp_mode_e mode); - bool setAvpfMode(enum tmedia_mode_e mode); - bool setICE(bool enabled); - bool setICEStun(bool enabled); - bool setICETurn(bool enabled); - bool setSTUNServer(const char* hostname, uint16_t port); - bool setSTUNCred(const char* username, const char* password); - bool setVideoFps(int32_t fps); - bool setVideoBandwidthUploadMax(int32_t max); - bool setVideoBandwidthDownloadMax(int32_t max); - bool setVideoPrefSize(tmedia_pref_video_size_t pref_video_size); - bool setQoS(tmedia_qos_stype_t type, tmedia_qos_strength_t strength); - bool hold(ActionConfig* config=tsk_null); - bool resume(ActionConfig* config=tsk_null); - bool transfer(const char* referToUriString, ActionConfig* config=tsk_null); - bool acceptTransfer(ActionConfig* config=tsk_null); - bool rejectTransfer(ActionConfig* config=tsk_null); - bool sendDTMF(int number); - unsigned getSessionTransferId(); - bool sendT140Data(enum tmedia_t140_data_type_e data_type, const void* data_ptr = NULL, unsigned data_size = 0); - bool setT140Callback(const T140Callback* pT140Callback); -#if !defined(SWIG) - bool sendRtcpEvent(enum tmedia_rtcp_event_type_e event_type, twrap_media_type_t media_type, uint32_t ssrc_media = 0); - bool setRtcpCallback(const RtcpCallback* pRtcpCallback, twrap_media_type_t media_type); - const T140Callback* getT140Callback() const; - static int t140OnDataCallback(const void* context, enum tmedia_t140_data_type_e data_type, const void* data_ptr, unsigned data_size); - const RtcpCallback* getRtcpCallback() const; - static int rtcpOnCallback(const void* context, enum tmedia_rtcp_event_type_e event_type, uint32_t ssrc_media); -#endif /* #if !defined(SWIG) */ - -private: - const T140Callback* m_pT140Callback; - const RtcpCallback* m_pRtcpCallback; -}; - -/* ======================== MsrpSession ========================*/ -class TINYWRAP_API MsrpSession : public InviteSession -{ -public: /* ctor() and dtor() */ - MsrpSession(SipStack* pStack, MsrpCallback* pCallback); -#if !defined(SWIG) - MsrpSession(SipStack* pStack, tsip_ssession_handle_t* pHandle); -#endif - virtual ~MsrpSession(); - -public: /* Public functions */ - bool setCallback(MsrpCallback* pCallback); - bool callMsrp(const char* remoteUriString, ActionConfig* config=tsk_null); - bool callMsrp(const SipUri* remoteUri, ActionConfig* config=tsk_null); - bool sendMessage(const void* payload, unsigned len, ActionConfig* config=tsk_null); - bool sendFile(ActionConfig* config=tsk_null); - -public: /* Public helper function */ -#if !defined(SWIG) - inline MsrpCallback* getCallback()const { - return m_pCallback; - } -#endif - -private: - MsrpCallback* m_pCallback; -}; - - - -/* ======================== MessagingSession ========================*/ -class TINYWRAP_API MessagingSession : public SipSession -{ -public: /* ctor() and dtor() */ - MessagingSession(SipStack* pStack); -#if !defined(SWIG) - MessagingSession(SipStack* pStack, tsip_ssession_handle_t* pHandle); -#endif - virtual ~MessagingSession(); - -public: /* Public functions */ - bool send(const void* payload, unsigned len, ActionConfig* config=tsk_null); - bool accept(ActionConfig* config=tsk_null); - bool reject(ActionConfig* config=tsk_null); -}; - -/* ======================== InfoSession ========================*/ -class TINYWRAP_API InfoSession : public SipSession -{ -public: /* ctor() and dtor() */ - InfoSession(SipStack* pStack); -#if !defined(SWIG) - InfoSession(SipStack* pStack, tsip_ssession_handle_t* pHandle); -#endif - virtual ~InfoSession(); - -public: /* Public functions */ - bool send(const void* payload, unsigned len, ActionConfig* config=tsk_null); - bool accept(ActionConfig* config=tsk_null); - bool reject(ActionConfig* config=tsk_null); -}; - -/* ======================== OptionsSession ========================*/ -class TINYWRAP_API OptionsSession : public SipSession -{ -public: /* ctor() and dtor() */ - OptionsSession(SipStack* pStack); -#if !defined(SWIG) - OptionsSession(SipStack* pStack, tsip_ssession_handle_t* pHandle); -#endif - virtual ~OptionsSession(); - -public: /* Public functions */ - bool send(ActionConfig* config=tsk_null); - bool accept(ActionConfig* config=tsk_null); - bool reject(ActionConfig* config=tsk_null); -}; - - - -/* ======================== PublicationSession ========================*/ -class TINYWRAP_API PublicationSession : public SipSession -{ -public: /* ctor() and dtor() */ - PublicationSession(SipStack* pStack); -#if !defined(SWIG) - PublicationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle); -#endif - virtual ~PublicationSession(); - -public: /* Public functions */ - bool publish(const void* payload, unsigned len, ActionConfig* config=tsk_null); - bool unPublish(ActionConfig* config=tsk_null); -}; - - -/* ======================== RegistrationSession ========================*/ -class TINYWRAP_API RegistrationSession : public SipSession -{ -public: /* ctor() and dtor() */ - RegistrationSession(SipStack* pStack); -#if !defined(SWIG) - RegistrationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle); -#endif - virtual ~RegistrationSession(); - -public: /* Public functions */ - bool register_(ActionConfig* config=tsk_null); - bool unRegister(ActionConfig* config=tsk_null); - bool accept(ActionConfig* config=tsk_null); - bool reject(ActionConfig* config=tsk_null); -}; - - -/* ======================== SubscriptionSession ========================*/ -class TINYWRAP_API SubscriptionSession : public SipSession -{ -public: /* ctor() and dtor() */ - SubscriptionSession(SipStack* pStack); -#if !defined(SWIG) - SubscriptionSession(SipStack* pStack, tsip_ssession_handle_t* pHandle); -#endif - virtual ~SubscriptionSession(); - -public: /* Public functions */ - bool subscribe(); - bool unSubscribe(); -}; - -#endif /* TINYWRAP_SIPSESSION_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_SIPSESSION_H
+#define TINYWRAP_SIPSESSION_H
+
+#include "tinyWRAP_config.h"
+
+#include "tinysip.h"
+#include "tinymedia/tmedia_qos.h"
+#include "ActionConfig.h"
+
+class SipUri;
+class SipStack;
+class MsrpCallback;
+class MediaSessionMgr;
+
+/* ======================== T140Callback ========================*/
+class TINYWRAP_API T140CallbackData
+{
+public:
+#if !defined(SWIG)
+ T140CallbackData(enum tmedia_t140_data_type_e data_type, const void* data_ptr, unsigned data_size) {
+ m_eType = data_type;
+ m_pPtr = data_ptr;
+ m_nSize = data_size;
+ }
+#endif
+ virtual ~T140CallbackData() {}
+
+ inline enum tmedia_t140_data_type_e getType()const {
+ return m_eType;
+ }
+ inline unsigned getSize()const {
+ return m_nSize;
+ }
+ inline unsigned getData(void* pOutput, unsigned nMaxsize)const {
+ unsigned nRetsize = 0;
+ if(pOutput && nMaxsize && m_pPtr) {
+ nRetsize = (m_nSize > nMaxsize) ? nMaxsize : m_nSize;
+ memcpy(pOutput, m_pPtr, nRetsize);
+ }
+ return nRetsize;
+ }
+
+private:
+ enum tmedia_t140_data_type_e m_eType;
+ const void* m_pPtr;
+ unsigned m_nSize;
+};
+
+class TINYWRAP_API T140Callback
+{
+public:
+ T140Callback() {}
+ virtual ~T140Callback() {}
+ virtual int ondata(const T140CallbackData* pData) {
+ return 0;
+ }
+};
+
+#if !defined(SWIG)
+class RtcpCallbackData
+{
+public:
+ RtcpCallbackData(enum tmedia_rtcp_event_type_e event_type, uint32_t ssrc_media) {
+ m_eType = event_type;
+ m_nSSRC = ssrc_media;
+ }
+ virtual ~RtcpCallbackData() {}
+ inline enum tmedia_rtcp_event_type_e getType()const {
+ return m_eType;
+ }
+ inline uint32_t getSSRC()const {
+ return m_nSSRC;
+ }
+private:
+ enum tmedia_rtcp_event_type_e m_eType;
+ uint32_t m_nSSRC;
+};
+
+class TINYWRAP_API RtcpCallback
+{
+public:
+ RtcpCallback() {}
+ virtual ~RtcpCallback() {}
+ virtual int onevent(const RtcpCallbackData* e) {
+ return 0;
+ }
+};
+#endif /* #if !defined(SWIG) */
+
+
+
+/* ======================== SipSession ========================*/
+class TINYWRAP_API SipSession
+{
+public:
+ SipSession(SipStack* stack);
+#if !defined(SWIG)
+ SipSession(SipStack* stack, tsip_ssession_handle_t* pHandle);
+#endif
+ virtual ~SipSession();
+
+public:
+ bool haveOwnership();
+ bool addHeader(const char* name, const char* value);
+ bool removeHeader(const char* name);
+ bool addCaps(const char* name, const char* value);
+ bool addCaps(const char* name);
+ bool removeCaps(const char* name);
+ bool setExpires(unsigned expires);
+ bool setFromUri(const char* fromUriString);
+ bool setFromUri(const SipUri* fromUri);
+ bool setToUri(const char* toUriString);
+ bool setToUri(const SipUri* toUri);
+ bool setSilentHangup(bool silent);
+ bool addSigCompCompartment(const char* compId);
+ bool removeSigCompCompartment();
+#if !defined(SWIG)
+ bool setAuth(const char* authHa1, const char* authIMPI);
+#endif
+ unsigned getId()const;
+
+#if !defined(SWIG)
+ bool setWebSocketSrc(const char* host, int32_t port, const char* proto);
+ const SipStack* getStack() const;
+ const tsip_ssession_handle_t* getWrappedSession() {
+ return m_pHandle;
+ }
+#endif
+
+private:
+ void init(SipStack* stack, tsip_ssession_handle_t* pHandle=tsk_null);
+
+protected:
+ tsip_ssession_handle_t* m_pHandle;
+ const SipStack* m_pStack;
+};
+
+/* ======================== InviteSession ========================*/
+class TINYWRAP_API InviteSession : public SipSession
+{
+public: /* ctor() and dtor() */
+ InviteSession(SipStack* Stack);
+#if !defined(SWIG)
+ InviteSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
+#endif
+ virtual ~InviteSession();
+
+public: /* Public functions */
+ bool accept(ActionConfig* config=tsk_null);
+ bool hangup(ActionConfig* config=tsk_null);
+ bool reject(ActionConfig* config=tsk_null);
+ bool sendInfo(const void* payload, unsigned len, ActionConfig* config=tsk_null);
+ const MediaSessionMgr* getMediaMgr();
+
+private:
+ MediaSessionMgr* m_pMediaMgr;
+};
+
+
+/* ======================== CallSession ========================*/
+class TINYWRAP_API CallSession : public InviteSession
+{
+public: /* ctor() and dtor() */
+ CallSession(SipStack* pStack);
+#if !defined(SWIG)
+ CallSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
+#endif
+ virtual ~CallSession();
+
+public: /* Public functions */
+ bool callAudio(const char* remoteUriString, ActionConfig* config=tsk_null); /* @deprecated */
+ bool callAudio(const SipUri* remoteUri, ActionConfig* config=tsk_null); /* @deprecated */
+ bool callAudioVideo(const char* remoteUriString, ActionConfig* config=tsk_null); /* @deprecated */
+ bool callAudioVideo(const SipUri* remoteUri, ActionConfig* config=tsk_null); /* @deprecated */
+ bool callVideo(const char* remoteUriString, ActionConfig* config=tsk_null); /* @deprecated */
+ bool callVideo(const SipUri* remoteUri, ActionConfig* config=tsk_null); /* @deprecated */
+
+ bool call(const char* remoteUriString, twrap_media_type_t media, ActionConfig* config=tsk_null);
+ bool call(const SipUri* remoteUri, twrap_media_type_t media, ActionConfig* config=tsk_null);
+#if !defined(SWIG)
+ bool setSupportedCodecs(int32_t codecs);
+ int32_t getNegotiatedCodecs();
+ bool setMediaSSRC(twrap_media_type_t media, uint32_t ssrc);
+#endif
+ bool setSessionTimer(unsigned timeout, const char* refresher);
+ bool set100rel(bool enabled);
+ bool setRtcp(bool enabled);
+ bool setRtcpMux(bool enabled);
+ bool setSRtpMode(enum tmedia_srtp_mode_e mode);
+ bool setAvpfMode(enum tmedia_mode_e mode);
+ bool setICE(bool enabled);
+ bool setICEStun(bool enabled);
+ bool setICETurn(bool enabled);
+ bool setSTUNServer(const char* hostname, uint16_t port);
+ bool setSTUNCred(const char* username, const char* password);
+ bool setVideoFps(int32_t fps);
+ bool setVideoBandwidthUploadMax(int32_t max);
+ bool setVideoBandwidthDownloadMax(int32_t max);
+ bool setVideoPrefSize(tmedia_pref_video_size_t pref_video_size);
+ bool setQoS(tmedia_qos_stype_t type, tmedia_qos_strength_t strength);
+ bool hold(ActionConfig* config=tsk_null);
+ bool resume(ActionConfig* config=tsk_null);
+ bool transfer(const char* referToUriString, ActionConfig* config=tsk_null);
+ bool acceptTransfer(ActionConfig* config=tsk_null);
+ bool rejectTransfer(ActionConfig* config=tsk_null);
+ bool sendDTMF(int number);
+ unsigned getSessionTransferId();
+ bool sendT140Data(enum tmedia_t140_data_type_e data_type, const void* data_ptr = NULL, unsigned data_size = 0);
+ bool setT140Callback(const T140Callback* pT140Callback);
+#if !defined(SWIG)
+ bool sendRtcpEvent(enum tmedia_rtcp_event_type_e event_type, twrap_media_type_t media_type, uint32_t ssrc_media = 0);
+ bool setRtcpCallback(const RtcpCallback* pRtcpCallback, twrap_media_type_t media_type);
+ const T140Callback* getT140Callback() const;
+ static int t140OnDataCallback(const void* context, enum tmedia_t140_data_type_e data_type, const void* data_ptr, unsigned data_size);
+ const RtcpCallback* getRtcpCallback() const;
+ static int rtcpOnCallback(const void* context, enum tmedia_rtcp_event_type_e event_type, uint32_t ssrc_media);
+#endif /* #if !defined(SWIG) */
+
+private:
+ const T140Callback* m_pT140Callback;
+ const RtcpCallback* m_pRtcpCallback;
+};
+
+/* ======================== MsrpSession ========================*/
+class TINYWRAP_API MsrpSession : public InviteSession
+{
+public: /* ctor() and dtor() */
+ MsrpSession(SipStack* pStack, MsrpCallback* pCallback);
+#if !defined(SWIG)
+ MsrpSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
+#endif
+ virtual ~MsrpSession();
+
+public: /* Public functions */
+ bool setCallback(MsrpCallback* pCallback);
+ bool callMsrp(const char* remoteUriString, ActionConfig* config=tsk_null);
+ bool callMsrp(const SipUri* remoteUri, ActionConfig* config=tsk_null);
+ bool sendMessage(const void* payload, unsigned len, ActionConfig* config=tsk_null);
+ bool sendFile(ActionConfig* config=tsk_null);
+
+public: /* Public helper function */
+#if !defined(SWIG)
+ inline MsrpCallback* getCallback()const {
+ return m_pCallback;
+ }
+#endif
+
+private:
+ MsrpCallback* m_pCallback;
+};
+
+
+
+/* ======================== MessagingSession ========================*/
+class TINYWRAP_API MessagingSession : public SipSession
+{
+public: /* ctor() and dtor() */
+ MessagingSession(SipStack* pStack);
+#if !defined(SWIG)
+ MessagingSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
+#endif
+ virtual ~MessagingSession();
+
+public: /* Public functions */
+ bool send(const void* payload, unsigned len, ActionConfig* config=tsk_null);
+ bool accept(ActionConfig* config=tsk_null);
+ bool reject(ActionConfig* config=tsk_null);
+};
+
+/* ======================== InfoSession ========================*/
+class TINYWRAP_API InfoSession : public SipSession
+{
+public: /* ctor() and dtor() */
+ InfoSession(SipStack* pStack);
+#if !defined(SWIG)
+ InfoSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
+#endif
+ virtual ~InfoSession();
+
+public: /* Public functions */
+ bool send(const void* payload, unsigned len, ActionConfig* config=tsk_null);
+ bool accept(ActionConfig* config=tsk_null);
+ bool reject(ActionConfig* config=tsk_null);
+};
+
+/* ======================== OptionsSession ========================*/
+class TINYWRAP_API OptionsSession : public SipSession
+{
+public: /* ctor() and dtor() */
+ OptionsSession(SipStack* pStack);
+#if !defined(SWIG)
+ OptionsSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
+#endif
+ virtual ~OptionsSession();
+
+public: /* Public functions */
+ bool send(ActionConfig* config=tsk_null);
+ bool accept(ActionConfig* config=tsk_null);
+ bool reject(ActionConfig* config=tsk_null);
+};
+
+
+
+/* ======================== PublicationSession ========================*/
+class TINYWRAP_API PublicationSession : public SipSession
+{
+public: /* ctor() and dtor() */
+ PublicationSession(SipStack* pStack);
+#if !defined(SWIG)
+ PublicationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
+#endif
+ virtual ~PublicationSession();
+
+public: /* Public functions */
+ bool publish(const void* payload, unsigned len, ActionConfig* config=tsk_null);
+ bool unPublish(ActionConfig* config=tsk_null);
+};
+
+
+/* ======================== RegistrationSession ========================*/
+class TINYWRAP_API RegistrationSession : public SipSession
+{
+public: /* ctor() and dtor() */
+ RegistrationSession(SipStack* pStack);
+#if !defined(SWIG)
+ RegistrationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
+#endif
+ virtual ~RegistrationSession();
+
+public: /* Public functions */
+ bool register_(ActionConfig* config=tsk_null);
+ bool unRegister(ActionConfig* config=tsk_null);
+ bool accept(ActionConfig* config=tsk_null);
+ bool reject(ActionConfig* config=tsk_null);
+};
+
+
+/* ======================== SubscriptionSession ========================*/
+class TINYWRAP_API SubscriptionSession : public SipSession
+{
+public: /* ctor() and dtor() */
+ SubscriptionSession(SipStack* pStack);
+#if !defined(SWIG)
+ SubscriptionSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
+#endif
+ virtual ~SubscriptionSession();
+
+public: /* Public functions */
+ bool subscribe();
+ bool unSubscribe();
+};
+
+#endif /* TINYWRAP_SIPSESSION_H */
diff --git a/bindings/_common/SipStack.cxx b/bindings/_common/SipStack.cxx index 66def3b..40a8ca7 100755 --- a/bindings/_common/SipStack.cxx +++ b/bindings/_common/SipStack.cxx @@ -1,621 +1,621 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "SipStack.h" - -#include "SipSession.h" -#include "SipEvent.h" - -#include "DDebug.h" - -#include "Common.h" - -bool SipStack::g_bInitialized = false; - - -/* === ANSI-C functions (local use) === */ -static int stack_callback(const tsip_event_t *sipevent); -static int session_handle_event(const tsip_event_t *sipevent); - -SipStack::SipStack(SipCallback* pCallback, const char* realm_uri, const char* impi_uri, const char* impu_uri) - :SafeObject() -{ - m_pDebugCallback = tsk_null; - m_pCallback = pCallback; - - /* Initialize network and media layers */ - if(!SipStack::initialize()) { - return;// isValid() will be false - } - - /* Creates stack handle */ - m_pHandle = tsip_stack_create(stack_callback, realm_uri, impi_uri, impu_uri, - TSIP_STACK_SET_USERDATA(this), /* used as context (useful for server-initiated requests) */ - TSIP_STACK_SET_NULL()); -} - -SipStack::~SipStack() -{ - this->stop(); - - /* Destroy stack handle */ - TSK_OBJECT_SAFE_FREE(m_pHandle); -} - -bool SipStack::start() -{ - bool ret = (tsip_stack_start(m_pHandle) == 0); - return ret; -} - -bool SipStack::setDebugCallback(DDebugCallback* pCallback) -{ - if(this && pCallback) { - m_pDebugCallback = pCallback; - tsk_debug_set_arg_data(this); - tsk_debug_set_info_cb(DDebugCallback::debug_info_cb); - tsk_debug_set_warn_cb(DDebugCallback::debug_warn_cb); - tsk_debug_set_error_cb(DDebugCallback::debug_error_cb); - tsk_debug_set_fatal_cb(DDebugCallback::debug_fatal_cb); - } - else if(this) { - m_pDebugCallback = tsk_null; - tsk_debug_set_arg_data(tsk_null); - tsk_debug_set_info_cb(tsk_null); - tsk_debug_set_warn_cb(tsk_null); - tsk_debug_set_error_cb(tsk_null); - tsk_debug_set_fatal_cb(tsk_null); - } - - return true; -} - -bool SipStack::setDisplayName(const char* display_name) -{ - int ret = tsip_stack_set(m_pHandle, - TSIP_STACK_SET_DISPLAY_NAME(display_name), - TSIP_STACK_SET_NULL()); - return (ret == 0); -} - -bool SipStack::setRealm(const char* realm_uri) -{ - int ret = tsip_stack_set(m_pHandle, - TSIP_STACK_SET_REALM(realm_uri), - TSIP_STACK_SET_NULL()); - return (ret == 0); -} - -bool SipStack::setIMPI(const char* impi) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_IMPI(impi), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setIMPU(const char* impu_uri) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_IMPU(impu_uri), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setPassword(const char* password) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_PASSWORD(password), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setAMF(const char* amf) -{ - uint16_t _amf = (uint16_t)tsk_atox(amf); - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_IMS_AKA_AMF(_amf), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setOperatorId(const char* opid) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_IMS_AKA_OPERATOR_ID(opid), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setProxyCSCF(const char* fqdn, unsigned short port, const char* transport, const char* ipversion) -{ - unsigned _port = port;//promote - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_PROXY_CSCF(fqdn, _port, transport, ipversion), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setLocalIP(const char* ip, const char* transport/*=tsk_null*/) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_LOCAL_IP_2(transport, ip), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setLocalPort(unsigned short port, const char* transport/*=tsk_null*/) -{ - unsigned _port = port;//promote - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_LOCAL_PORT_2(transport, _port), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setEarlyIMS(bool enabled) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_EARLY_IMS(enabled? tsk_true : tsk_false), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::addHeader(const char* name, const char* value) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_HEADER(name, value), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::removeHeader(const char* name) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_UNSET_HEADER(name), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::addDnsServer(const char* ip) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_DNS_SERVER(ip), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setDnsDiscovery(bool enabled) -{ - tsk_bool_t _enabled = enabled;// 32bit/64bit workaround - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_DISCOVERY_NAPTR(_enabled), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setAoR(const char* ip, int port) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_AOR(ip, port), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setMode(enum tsip_stack_mode_e mode) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_MODE(mode), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setSigCompParams(unsigned dms, unsigned sms, unsigned cpb, bool enablePresDict) -{ - tsk_bool_t _enablePresDict= enablePresDict;// 32bit/64bit workaround - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_SIGCOMP(dms, sms, cpb, _enablePresDict), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::addSigCompCompartment(const char* compId) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_SIGCOMP_NEW_COMPARTMENT(compId), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::removeSigCompCompartment(const char* compId) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_UNSET_SIGCOMP_COMPARTMENT(compId), - TSIP_STACK_SET_NULL()) == 0); -} - -// @deprecated -bool SipStack::setSTUNEnabledForICE(bool enabled) -{ -#if 0 - tsk_bool_t _enabled = enabled ? tsk_true : tsk_false; - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_ICE_STUN_ENABLED(_enabled), - TSIP_STACK_SET_NULL()) == 0); -#else - // set global value - return (tmedia_defaults_set_icestun_enabled(enabled ? tsk_true : tsk_false) == 0); - // to set the value per session, use "CallSession::setICEStun()" -#endif -} - -// @deprecated -bool SipStack::setSTUNServer(const char* hostname, unsigned short port) -{ -#if 0 - unsigned _port = port;//promote - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_STUN_SERVER(hostname, _port), - TSIP_STACK_SET_NULL()) == 0); -#else - // set global value - return (tmedia_defaults_set_stun_server(hostname, port) == 0); - // to set the value per session, use "CallSession::setSTUNServer()" -#endif -} - -// @deprecated -bool SipStack::setSTUNCred(const char* login, const char* password) -{ -#if 0 - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_STUN_CRED(login, password), - TSIP_STACK_SET_NULL()) == 0); -#else - // set global value - return (tmedia_defaults_set_stun_cred(login, password) == 0); - // to set the value per session, use "CallSession::setSTUNCred()" -#endif -} - -bool SipStack::setSTUNEnabled(bool enabled) -{ - tsk_bool_t _enabled = enabled ? tsk_true : tsk_false; - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_STUN_ENABLED(_enabled), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setTLSSecAgree(bool enabled) -{ - tsk_bool_t _enable = enabled ? tsk_true : tsk_false; - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_SECAGREE_TLS(_enable), - TSIP_STACK_SET_NULL()) == 0); -} - -/*@deprecated: typo */ -bool SipStack::setSSLCretificates(const char* privKey, const char* pubKey, const char* caKey, bool verify/* = false*/) -{ - return setSSLCertificates(privKey, pubKey, caKey, verify); -} - -bool SipStack::setSSLCertificates(const char* privKey, const char* pubKey, const char* caKey, bool verify/* = false*/) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_TLS_CERTS_2(caKey, pubKey, privKey, (verify ? tsk_true : tsk_false)), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setIPSecSecAgree(bool enabled) -{ - tsk_bool_t _enable = enabled; - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_SECAGREE_IPSEC(_enable), - TSIP_STACK_SET_NULL()) == 0); -} - -bool SipStack::setIPSecParameters(const char* algo, const char* ealgo, const char* mode, const char* proto) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_IPSEC_PARAMS(algo, ealgo, mode, proto), - TSIP_STACK_SET_NULL()) == 0); -} - -char* SipStack::dnsENUM(const char* service, const char* e164num, const char* domain) -{ - tnet_dns_ctx_t* dnsctx = tsip_stack_get_dnsctx(m_pHandle); - char* uri = tsk_null; - - if(dnsctx) { - if(!(uri = tnet_dns_enum_2(dnsctx, service, e164num, domain))) { - TSK_DEBUG_ERROR("ENUM(%s) failed", e164num); - } - tsk_object_unref(dnsctx); - return uri; - } - else { - TSK_DEBUG_ERROR("No DNS Context could be found"); - return tsk_null; - } -} - -char* SipStack::dnsNaptrSrv(const char* domain, const char* service, unsigned short *OUTPUT) -{ - tnet_dns_ctx_t* dnsctx = tsip_stack_get_dnsctx(m_pHandle); - char* ip = tsk_null; - tnet_port_t port; - *OUTPUT = 0; - - - if(dnsctx) { - if(!tnet_dns_query_naptr_srv(dnsctx, domain, service, &ip, &port)) { - *OUTPUT = port; - } - tsk_object_unref(dnsctx); - return ip; - } - else { - TSK_DEBUG_ERROR("No DNS Context could be found"); - return tsk_null; - } -} - -char* SipStack::dnsSrv(const char* service, unsigned short* OUTPUT) -{ - tnet_dns_ctx_t* dnsctx = tsip_stack_get_dnsctx(m_pHandle); - char* ip = tsk_null; - tnet_port_t port = 0; - *OUTPUT = 0; - - if(dnsctx) { - if(!tnet_dns_query_srv(dnsctx, service, &ip, &port)) { - *OUTPUT = port; - } - tsk_object_unref(dnsctx); - return ip; - } - else { - TSK_DEBUG_ERROR("No DNS Context could be found"); - return tsk_null; - } -} - -bool SipStack::setMaxFDs(unsigned max_fds) -{ - return (tsip_stack_set(m_pHandle, - TSIP_STACK_SET_MAX_FDS(max_fds), - TSIP_STACK_SET_NULL()) == 0); -} - -char* SipStack::getLocalIPnPort(const char* protocol, unsigned short* OUTPUT) -{ - tnet_ip_t ip; - tnet_port_t port; - int ret; - - if(!OUTPUT || !protocol) { - TSK_DEBUG_ERROR("invalid parameter"); - return tsk_null; - } - - if((ret = tsip_stack_get_local_ip_n_port(m_pHandle, protocol, &port, &ip))) { - TSK_DEBUG_ERROR("Failed to get local ip and port with error code=%d", ret); - return tsk_null; - } - - *OUTPUT = port; - return tsk_strdup(ip); // See Swig %newobject -} - -char* SipStack::getPreferredIdentity() -{ - tsip_uri_t* ppid = tsip_stack_get_preferred_id(m_pHandle); - char* str_ppid = tsk_null; - if(ppid) { - str_ppid = tsip_uri_tostring(ppid, tsk_false, tsk_false); - TSK_OBJECT_SAFE_FREE(ppid); - } - return str_ppid; -} - -bool SipStack::isValid() -{ - return (m_pHandle != tsk_null); -} - -bool SipStack::stop() -{ - int ret = tsip_stack_stop(m_pHandle); - return (ret == 0); -} - -bool SipStack::initialize() -{ - if (!g_bInitialized) { - int ret; - - if((ret = tnet_startup())) { - TSK_DEBUG_ERROR("tnet_startup failed with error code=%d", ret); - return false; - } - if((ret = thttp_startup())) { - TSK_DEBUG_ERROR("thttp_startup failed with error code=%d", ret); - return false; - } - if((ret = tdav_init())) { - TSK_DEBUG_ERROR("tdav_init failed with error code=%d", ret); - return false; - } - g_bInitialized = true; - } - return true; -} - -bool SipStack::deInitialize() -{ - if (SipStack::g_bInitialized) { - tdav_deinit(); - thttp_cleanup(); - tnet_cleanup(); - SipStack::g_bInitialized = false; - } - return false; -} - -void SipStack::setCodecs(tdav_codec_id_t codecs) -{ - tdav_set_codecs(codecs); -} - -void SipStack::setCodecs_2(int64_t codecs) // For stupid languages -{ - SipStack::setCodecs((tdav_codec_id_t)codecs); -} - -bool SipStack::setCodecPriority(tdav_codec_id_t codec_id, int priority) -{ - return tdav_codec_set_priority(codec_id, priority) == 0; -} - -bool SipStack::setCodecPriority_2(int codec_id, int priority)// For stupid languages -{ - return SipStack::setCodecPriority((tdav_codec_id_t)codec_id, priority); -} - -bool SipStack::isCodecSupported(tdav_codec_id_t codec_id) -{ - return tdav_codec_is_supported(codec_id) ? true : false; -} - -bool SipStack::isIPSecSupported() -{ - return tdav_ipsec_is_supported() ? true : false; -} - -static int stack_callback(const tsip_event_t *sipevent) -{ - int ret = 0; - const SipStack* sipStack = tsk_null; - SipEvent* e = tsk_null; - - if(!sipevent) { /* should never happen ...but who know? */ - TSK_DEBUG_WARN("Null SIP event."); - return -1; - } - else { - if(sipevent->type == tsip_event_stack && sipevent->userdata) { - /* sessionless event */ - sipStack = dyn_cast<const SipStack*>((const SipStack*)sipevent->userdata); - } - else { - const void* userdata; - /* gets the stack from the session */ - const tsip_stack_handle_t* stack_handle = tsip_ssession_get_stack(sipevent->ss); - if(stack_handle && (userdata = tsip_stack_get_userdata(stack_handle))) { - sipStack = dyn_cast<const SipStack*>((const SipStack*)userdata); - } - } - } - - if(!sipStack) { - TSK_DEBUG_WARN("Invalid SIP event (Stack is Null)."); - return -2; - } - - sipStack->Lock(); - - switch(sipevent->type) { - case tsip_event_register: { - /* REGISTER */ - if(sipStack->getCallback()) { - e = new RegistrationEvent(sipevent); - sipStack->getCallback()->OnRegistrationEvent((const RegistrationEvent*)e); - } - break; - } - case tsip_event_invite: { - /* INVITE */ - if(sipStack->getCallback()) { - e = new InviteEvent(sipevent); - sipStack->getCallback()->OnInviteEvent((const InviteEvent*)e); - } - break; - } - case tsip_event_message: { - /* MESSAGE */ - if(sipStack->getCallback()) { - e = new MessagingEvent(sipevent); - sipStack->getCallback()->OnMessagingEvent((const MessagingEvent*)e); - } - break; - } - case tsip_event_info: { - /* INFO */ - if(sipStack->getCallback()) { - e = new InfoEvent(sipevent); - sipStack->getCallback()->OnInfoEvent((const InfoEvent*)e); - } - break; - } - case tsip_event_options: { - /* OPTIONS */ - if(sipStack->getCallback()) { - e = new OptionsEvent(sipevent); - sipStack->getCallback()->OnOptionsEvent((const OptionsEvent*)e); - } - break; - } - case tsip_event_publish: { - /* PUBLISH */ - if(sipStack->getCallback()) { - e = new PublicationEvent(sipevent); - sipStack->getCallback()->OnPublicationEvent((const PublicationEvent*)e); - } - break; - } - case tsip_event_subscribe: { - /* SUBSCRIBE */ - if(sipStack->getCallback()) { - e = new SubscriptionEvent(sipevent); - sipStack->getCallback()->OnSubscriptionEvent((const SubscriptionEvent*)e); - } - break; - } - - case tsip_event_dialog: { - /* Common to all dialogs */ - if(sipStack->getCallback()) { - e = new DialogEvent(sipevent); - sipStack->getCallback()->OnDialogEvent((const DialogEvent*)e); - } - break; - } - - case tsip_event_stack: { - /* Stack event */ - if(sipStack->getCallback()) { - e = new StackEvent(sipevent); - sipStack->getCallback()->OnStackEvent((const StackEvent*)e); - } - break; - } - - default: { - /* Unsupported */ - TSK_DEBUG_WARN("%d not supported as SIP event.", sipevent->type); - ret = -3; - break; - } - } - - sipStack->UnLock(); - - if(e) { - delete e; - } - - return ret; -} - +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "SipStack.h"
+
+#include "SipSession.h"
+#include "SipEvent.h"
+
+#include "DDebug.h"
+
+#include "Common.h"
+
+bool SipStack::g_bInitialized = false;
+
+
+/* === ANSI-C functions (local use) === */
+static int stack_callback(const tsip_event_t *sipevent);
+static int session_handle_event(const tsip_event_t *sipevent);
+
+SipStack::SipStack(SipCallback* pCallback, const char* realm_uri, const char* impi_uri, const char* impu_uri)
+ :SafeObject()
+{
+ m_pDebugCallback = tsk_null;
+ m_pCallback = pCallback;
+
+ /* Initialize network and media layers */
+ if(!SipStack::initialize()) {
+ return;// isValid() will be false
+ }
+
+ /* Creates stack handle */
+ m_pHandle = tsip_stack_create(stack_callback, realm_uri, impi_uri, impu_uri,
+ TSIP_STACK_SET_USERDATA(this), /* used as context (useful for server-initiated requests) */
+ TSIP_STACK_SET_NULL());
+}
+
+SipStack::~SipStack()
+{
+ this->stop();
+
+ /* Destroy stack handle */
+ TSK_OBJECT_SAFE_FREE(m_pHandle);
+}
+
+bool SipStack::start()
+{
+ bool ret = (tsip_stack_start(m_pHandle) == 0);
+ return ret;
+}
+
+bool SipStack::setDebugCallback(DDebugCallback* pCallback)
+{
+ if(this && pCallback) {
+ m_pDebugCallback = pCallback;
+ tsk_debug_set_arg_data(this);
+ tsk_debug_set_info_cb(DDebugCallback::debug_info_cb);
+ tsk_debug_set_warn_cb(DDebugCallback::debug_warn_cb);
+ tsk_debug_set_error_cb(DDebugCallback::debug_error_cb);
+ tsk_debug_set_fatal_cb(DDebugCallback::debug_fatal_cb);
+ }
+ else if(this) {
+ m_pDebugCallback = tsk_null;
+ tsk_debug_set_arg_data(tsk_null);
+ tsk_debug_set_info_cb(tsk_null);
+ tsk_debug_set_warn_cb(tsk_null);
+ tsk_debug_set_error_cb(tsk_null);
+ tsk_debug_set_fatal_cb(tsk_null);
+ }
+
+ return true;
+}
+
+bool SipStack::setDisplayName(const char* display_name)
+{
+ int ret = tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_DISPLAY_NAME(display_name),
+ TSIP_STACK_SET_NULL());
+ return (ret == 0);
+}
+
+bool SipStack::setRealm(const char* realm_uri)
+{
+ int ret = tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_REALM(realm_uri),
+ TSIP_STACK_SET_NULL());
+ return (ret == 0);
+}
+
+bool SipStack::setIMPI(const char* impi)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_IMPI(impi),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setIMPU(const char* impu_uri)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_IMPU(impu_uri),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setPassword(const char* password)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_PASSWORD(password),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setAMF(const char* amf)
+{
+ uint16_t _amf = (uint16_t)tsk_atox(amf);
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_IMS_AKA_AMF(_amf),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setOperatorId(const char* opid)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_IMS_AKA_OPERATOR_ID(opid),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setProxyCSCF(const char* fqdn, unsigned short port, const char* transport, const char* ipversion)
+{
+ unsigned _port = port;//promote
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_PROXY_CSCF(fqdn, _port, transport, ipversion),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setLocalIP(const char* ip, const char* transport/*=tsk_null*/)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_LOCAL_IP_2(transport, ip),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setLocalPort(unsigned short port, const char* transport/*=tsk_null*/)
+{
+ unsigned _port = port;//promote
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_LOCAL_PORT_2(transport, _port),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setEarlyIMS(bool enabled)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_EARLY_IMS(enabled? tsk_true : tsk_false),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::addHeader(const char* name, const char* value)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_HEADER(name, value),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::removeHeader(const char* name)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_UNSET_HEADER(name),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::addDnsServer(const char* ip)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_DNS_SERVER(ip),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setDnsDiscovery(bool enabled)
+{
+ tsk_bool_t _enabled = enabled;// 32bit/64bit workaround
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_DISCOVERY_NAPTR(_enabled),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setAoR(const char* ip, int port)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_AOR(ip, port),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setMode(enum tsip_stack_mode_e mode)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_MODE(mode),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setSigCompParams(unsigned dms, unsigned sms, unsigned cpb, bool enablePresDict)
+{
+ tsk_bool_t _enablePresDict= enablePresDict;// 32bit/64bit workaround
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_SIGCOMP(dms, sms, cpb, _enablePresDict),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::addSigCompCompartment(const char* compId)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_SIGCOMP_NEW_COMPARTMENT(compId),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::removeSigCompCompartment(const char* compId)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_UNSET_SIGCOMP_COMPARTMENT(compId),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+// @deprecated
+bool SipStack::setSTUNEnabledForICE(bool enabled)
+{
+#if 0
+ tsk_bool_t _enabled = enabled ? tsk_true : tsk_false;
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_ICE_STUN_ENABLED(_enabled),
+ TSIP_STACK_SET_NULL()) == 0);
+#else
+ // set global value
+ return (tmedia_defaults_set_icestun_enabled(enabled ? tsk_true : tsk_false) == 0);
+ // to set the value per session, use "CallSession::setICEStun()"
+#endif
+}
+
+// @deprecated
+bool SipStack::setSTUNServer(const char* hostname, unsigned short port)
+{
+#if 0
+ unsigned _port = port;//promote
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_STUN_SERVER(hostname, _port),
+ TSIP_STACK_SET_NULL()) == 0);
+#else
+ // set global value
+ return (tmedia_defaults_set_stun_server(hostname, port) == 0);
+ // to set the value per session, use "CallSession::setSTUNServer()"
+#endif
+}
+
+// @deprecated
+bool SipStack::setSTUNCred(const char* login, const char* password)
+{
+#if 0
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_STUN_CRED(login, password),
+ TSIP_STACK_SET_NULL()) == 0);
+#else
+ // set global value
+ return (tmedia_defaults_set_stun_cred(login, password) == 0);
+ // to set the value per session, use "CallSession::setSTUNCred()"
+#endif
+}
+
+bool SipStack::setSTUNEnabled(bool enabled)
+{
+ tsk_bool_t _enabled = enabled ? tsk_true : tsk_false;
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_STUN_ENABLED(_enabled),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setTLSSecAgree(bool enabled)
+{
+ tsk_bool_t _enable = enabled ? tsk_true : tsk_false;
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_SECAGREE_TLS(_enable),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+/*@deprecated: typo */
+bool SipStack::setSSLCretificates(const char* privKey, const char* pubKey, const char* caKey, bool verify/* = false*/)
+{
+ return setSSLCertificates(privKey, pubKey, caKey, verify);
+}
+
+bool SipStack::setSSLCertificates(const char* privKey, const char* pubKey, const char* caKey, bool verify/* = false*/)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_TLS_CERTS_2(caKey, pubKey, privKey, (verify ? tsk_true : tsk_false)),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setIPSecSecAgree(bool enabled)
+{
+ tsk_bool_t _enable = enabled;
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_SECAGREE_IPSEC(_enable),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+bool SipStack::setIPSecParameters(const char* algo, const char* ealgo, const char* mode, const char* proto)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_IPSEC_PARAMS(algo, ealgo, mode, proto),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+char* SipStack::dnsENUM(const char* service, const char* e164num, const char* domain)
+{
+ tnet_dns_ctx_t* dnsctx = tsip_stack_get_dnsctx(m_pHandle);
+ char* uri = tsk_null;
+
+ if(dnsctx) {
+ if(!(uri = tnet_dns_enum_2(dnsctx, service, e164num, domain))) {
+ TSK_DEBUG_ERROR("ENUM(%s) failed", e164num);
+ }
+ tsk_object_unref(dnsctx);
+ return uri;
+ }
+ else {
+ TSK_DEBUG_ERROR("No DNS Context could be found");
+ return tsk_null;
+ }
+}
+
+char* SipStack::dnsNaptrSrv(const char* domain, const char* service, unsigned short *OUTPUT)
+{
+ tnet_dns_ctx_t* dnsctx = tsip_stack_get_dnsctx(m_pHandle);
+ char* ip = tsk_null;
+ tnet_port_t port;
+ *OUTPUT = 0;
+
+
+ if(dnsctx) {
+ if(!tnet_dns_query_naptr_srv(dnsctx, domain, service, &ip, &port)) {
+ *OUTPUT = port;
+ }
+ tsk_object_unref(dnsctx);
+ return ip;
+ }
+ else {
+ TSK_DEBUG_ERROR("No DNS Context could be found");
+ return tsk_null;
+ }
+}
+
+char* SipStack::dnsSrv(const char* service, unsigned short* OUTPUT)
+{
+ tnet_dns_ctx_t* dnsctx = tsip_stack_get_dnsctx(m_pHandle);
+ char* ip = tsk_null;
+ tnet_port_t port = 0;
+ *OUTPUT = 0;
+
+ if(dnsctx) {
+ if(!tnet_dns_query_srv(dnsctx, service, &ip, &port)) {
+ *OUTPUT = port;
+ }
+ tsk_object_unref(dnsctx);
+ return ip;
+ }
+ else {
+ TSK_DEBUG_ERROR("No DNS Context could be found");
+ return tsk_null;
+ }
+}
+
+bool SipStack::setMaxFDs(unsigned max_fds)
+{
+ return (tsip_stack_set(m_pHandle,
+ TSIP_STACK_SET_MAX_FDS(max_fds),
+ TSIP_STACK_SET_NULL()) == 0);
+}
+
+char* SipStack::getLocalIPnPort(const char* protocol, unsigned short* OUTPUT)
+{
+ tnet_ip_t ip;
+ tnet_port_t port;
+ int ret;
+
+ if(!OUTPUT || !protocol) {
+ TSK_DEBUG_ERROR("invalid parameter");
+ return tsk_null;
+ }
+
+ if((ret = tsip_stack_get_local_ip_n_port(m_pHandle, protocol, &port, &ip))) {
+ TSK_DEBUG_ERROR("Failed to get local ip and port with error code=%d", ret);
+ return tsk_null;
+ }
+
+ *OUTPUT = port;
+ return tsk_strdup(ip); // See Swig %newobject
+}
+
+char* SipStack::getPreferredIdentity()
+{
+ tsip_uri_t* ppid = tsip_stack_get_preferred_id(m_pHandle);
+ char* str_ppid = tsk_null;
+ if(ppid) {
+ str_ppid = tsip_uri_tostring(ppid, tsk_false, tsk_false);
+ TSK_OBJECT_SAFE_FREE(ppid);
+ }
+ return str_ppid;
+}
+
+bool SipStack::isValid()
+{
+ return (m_pHandle != tsk_null);
+}
+
+bool SipStack::stop()
+{
+ int ret = tsip_stack_stop(m_pHandle);
+ return (ret == 0);
+}
+
+bool SipStack::initialize()
+{
+ if (!g_bInitialized) {
+ int ret;
+
+ if((ret = tnet_startup())) {
+ TSK_DEBUG_ERROR("tnet_startup failed with error code=%d", ret);
+ return false;
+ }
+ if((ret = thttp_startup())) {
+ TSK_DEBUG_ERROR("thttp_startup failed with error code=%d", ret);
+ return false;
+ }
+ if((ret = tdav_init())) {
+ TSK_DEBUG_ERROR("tdav_init failed with error code=%d", ret);
+ return false;
+ }
+ g_bInitialized = true;
+ }
+ return true;
+}
+
+bool SipStack::deInitialize()
+{
+ if (SipStack::g_bInitialized) {
+ tdav_deinit();
+ thttp_cleanup();
+ tnet_cleanup();
+ SipStack::g_bInitialized = false;
+ }
+ return false;
+}
+
+void SipStack::setCodecs(tdav_codec_id_t codecs)
+{
+ tdav_set_codecs(codecs);
+}
+
+void SipStack::setCodecs_2(int64_t codecs) // For stupid languages
+{
+ SipStack::setCodecs((tdav_codec_id_t)codecs);
+}
+
+bool SipStack::setCodecPriority(tdav_codec_id_t codec_id, int priority)
+{
+ return tdav_codec_set_priority(codec_id, priority) == 0;
+}
+
+bool SipStack::setCodecPriority_2(int codec_id, int priority)// For stupid languages
+{
+ return SipStack::setCodecPriority((tdav_codec_id_t)codec_id, priority);
+}
+
+bool SipStack::isCodecSupported(tdav_codec_id_t codec_id)
+{
+ return tdav_codec_is_supported(codec_id) ? true : false;
+}
+
+bool SipStack::isIPSecSupported()
+{
+ return tdav_ipsec_is_supported() ? true : false;
+}
+
+static int stack_callback(const tsip_event_t *sipevent)
+{
+ int ret = 0;
+ const SipStack* sipStack = tsk_null;
+ SipEvent* e = tsk_null;
+
+ if(!sipevent) { /* should never happen ...but who know? */
+ TSK_DEBUG_WARN("Null SIP event.");
+ return -1;
+ }
+ else {
+ if(sipevent->type == tsip_event_stack && sipevent->userdata) {
+ /* sessionless event */
+ sipStack = dyn_cast<const SipStack*>((const SipStack*)sipevent->userdata);
+ }
+ else {
+ const void* userdata;
+ /* gets the stack from the session */
+ const tsip_stack_handle_t* stack_handle = tsip_ssession_get_stack(sipevent->ss);
+ if(stack_handle && (userdata = tsip_stack_get_userdata(stack_handle))) {
+ sipStack = dyn_cast<const SipStack*>((const SipStack*)userdata);
+ }
+ }
+ }
+
+ if(!sipStack) {
+ TSK_DEBUG_WARN("Invalid SIP event (Stack is Null).");
+ return -2;
+ }
+
+ sipStack->Lock();
+
+ switch(sipevent->type) {
+ case tsip_event_register: {
+ /* REGISTER */
+ if(sipStack->getCallback()) {
+ e = new RegistrationEvent(sipevent);
+ sipStack->getCallback()->OnRegistrationEvent((const RegistrationEvent*)e);
+ }
+ break;
+ }
+ case tsip_event_invite: {
+ /* INVITE */
+ if(sipStack->getCallback()) {
+ e = new InviteEvent(sipevent);
+ sipStack->getCallback()->OnInviteEvent((const InviteEvent*)e);
+ }
+ break;
+ }
+ case tsip_event_message: {
+ /* MESSAGE */
+ if(sipStack->getCallback()) {
+ e = new MessagingEvent(sipevent);
+ sipStack->getCallback()->OnMessagingEvent((const MessagingEvent*)e);
+ }
+ break;
+ }
+ case tsip_event_info: {
+ /* INFO */
+ if(sipStack->getCallback()) {
+ e = new InfoEvent(sipevent);
+ sipStack->getCallback()->OnInfoEvent((const InfoEvent*)e);
+ }
+ break;
+ }
+ case tsip_event_options: {
+ /* OPTIONS */
+ if(sipStack->getCallback()) {
+ e = new OptionsEvent(sipevent);
+ sipStack->getCallback()->OnOptionsEvent((const OptionsEvent*)e);
+ }
+ break;
+ }
+ case tsip_event_publish: {
+ /* PUBLISH */
+ if(sipStack->getCallback()) {
+ e = new PublicationEvent(sipevent);
+ sipStack->getCallback()->OnPublicationEvent((const PublicationEvent*)e);
+ }
+ break;
+ }
+ case tsip_event_subscribe: {
+ /* SUBSCRIBE */
+ if(sipStack->getCallback()) {
+ e = new SubscriptionEvent(sipevent);
+ sipStack->getCallback()->OnSubscriptionEvent((const SubscriptionEvent*)e);
+ }
+ break;
+ }
+
+ case tsip_event_dialog: {
+ /* Common to all dialogs */
+ if(sipStack->getCallback()) {
+ e = new DialogEvent(sipevent);
+ sipStack->getCallback()->OnDialogEvent((const DialogEvent*)e);
+ }
+ break;
+ }
+
+ case tsip_event_stack: {
+ /* Stack event */
+ if(sipStack->getCallback()) {
+ e = new StackEvent(sipevent);
+ sipStack->getCallback()->OnStackEvent((const StackEvent*)e);
+ }
+ break;
+ }
+
+ default: {
+ /* Unsupported */
+ TSK_DEBUG_WARN("%d not supported as SIP event.", sipevent->type);
+ ret = -3;
+ break;
+ }
+ }
+
+ sipStack->UnLock();
+
+ if(e) {
+ delete e;
+ }
+
+ return ret;
+}
+
diff --git a/bindings/_common/SipStack.h b/bindings/_common/SipStack.h index d7b8cdc..a64a455 100755 --- a/bindings/_common/SipStack.h +++ b/bindings/_common/SipStack.h @@ -1,123 +1,123 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_SIPSTACK_H -#define TINYWRAP_SIPSTACK_H - -#include "tinyWRAP_config.h" - -#include "SipCallback.h" -#include "SafeObject.h" - -#include "tinydav/tdav.h" -#include "tinysip.h" -#include "tinyhttp.h" - -class DDebugCallback; - -class TINYWRAP_API SipStack: public SafeObject -{ -public: /* ctor() and dtor() */ - SipStack(SipCallback* pCallback, const char* realm_uri, const char* impi_uri, const char* impu_uri); - ~SipStack(); - -public: /* API functions */ - bool start(); - bool setDebugCallback(DDebugCallback* pCallback); - bool setDisplayName(const char* display_name); - bool setRealm(const char* realm_uri); - bool setIMPI(const char* impi); - bool setIMPU(const char* impu_uri); - bool setPassword(const char* password); - bool setAMF(const char* amf); - bool setOperatorId(const char* opid); - bool setProxyCSCF(const char* fqdn, unsigned short port, const char* transport, const char* ipversion); - bool setLocalIP(const char* ip, const char* transport=tsk_null); - bool setLocalPort(unsigned short port, const char* transport=tsk_null); - bool setEarlyIMS(bool enabled); - bool addHeader(const char* name, const char* value); - bool removeHeader(const char* name); - bool addDnsServer(const char* ip); - bool setDnsDiscovery(bool enabled); - bool setAoR(const char* ip, int port); -#if !defined(SWIG) - bool setMode(enum tsip_stack_mode_e mode); -#endif - - bool setSigCompParams(unsigned dms, unsigned sms, unsigned cpb, bool enablePresDict); - bool addSigCompCompartment(const char* compId); - bool removeSigCompCompartment(const char* compId); - - bool setSTUNEnabledForICE(bool enabled); // @deprecated - bool setSTUNServer(const char* hostname, unsigned short port); // @deprecated - bool setSTUNCred(const char* login, const char* password); // @deprecated - bool setSTUNEnabled(bool enabled); - - bool setTLSSecAgree(bool enabled); - bool setSSLCertificates(const char* privKey, const char* pubKey, const char* caKey, bool verify = false); - bool setSSLCretificates(const char* privKey, const char* pubKey, const char* caKey, bool verify = false); /*@deprecated: typo */ - bool setIPSecSecAgree(bool enabled); - bool setIPSecParameters(const char* algo, const char* ealgo, const char* mode, const char* proto); - - char* dnsENUM(const char* service, const char* e164num, const char* domain); - char* dnsNaptrSrv(const char* domain, const char* service, unsigned short *OUTPUT); - char* dnsSrv(const char* service, unsigned short* OUTPUT); - - bool setMaxFDs(unsigned max_fds); - - char* getLocalIPnPort(const char* protocol, unsigned short* OUTPUT); - - char* getPreferredIdentity(); - - bool isValid(); - bool stop(); - - static bool initialize(); - static bool deInitialize(); - static void setCodecs(tdav_codec_id_t codecs); - static void setCodecs_2(int64_t codecs); // For stupid languages - static bool setCodecPriority(tdav_codec_id_t codec_id, int priority); - static bool setCodecPriority_2(int codec, int priority);// For stupid languages - static bool isCodecSupported(tdav_codec_id_t codec_id); - static bool isIPSecSupported(); - -public: /* Public helper function */ -#if !defined(SWIG) - inline tsip_stack_handle_t* getHandle()const { - return m_pHandle; - } - inline SipCallback* getCallback()const { - return m_pCallback; - } - inline DDebugCallback* getDebugCallback() const { - return m_pDebugCallback; - } -#endif - -private: - SipCallback* m_pCallback; - DDebugCallback* m_pDebugCallback; - tsip_stack_handle_t* m_pHandle; - - static bool g_bInitialized; -}; - -#endif /* TINYWRAP_SIPSTACK_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_SIPSTACK_H
+#define TINYWRAP_SIPSTACK_H
+
+#include "tinyWRAP_config.h"
+
+#include "SipCallback.h"
+#include "SafeObject.h"
+
+#include "tinydav/tdav.h"
+#include "tinysip.h"
+#include "tinyhttp.h"
+
+class DDebugCallback;
+
+class TINYWRAP_API SipStack: public SafeObject
+{
+public: /* ctor() and dtor() */
+ SipStack(SipCallback* pCallback, const char* realm_uri, const char* impi_uri, const char* impu_uri);
+ ~SipStack();
+
+public: /* API functions */
+ bool start();
+ bool setDebugCallback(DDebugCallback* pCallback);
+ bool setDisplayName(const char* display_name);
+ bool setRealm(const char* realm_uri);
+ bool setIMPI(const char* impi);
+ bool setIMPU(const char* impu_uri);
+ bool setPassword(const char* password);
+ bool setAMF(const char* amf);
+ bool setOperatorId(const char* opid);
+ bool setProxyCSCF(const char* fqdn, unsigned short port, const char* transport, const char* ipversion);
+ bool setLocalIP(const char* ip, const char* transport=tsk_null);
+ bool setLocalPort(unsigned short port, const char* transport=tsk_null);
+ bool setEarlyIMS(bool enabled);
+ bool addHeader(const char* name, const char* value);
+ bool removeHeader(const char* name);
+ bool addDnsServer(const char* ip);
+ bool setDnsDiscovery(bool enabled);
+ bool setAoR(const char* ip, int port);
+#if !defined(SWIG)
+ bool setMode(enum tsip_stack_mode_e mode);
+#endif
+
+ bool setSigCompParams(unsigned dms, unsigned sms, unsigned cpb, bool enablePresDict);
+ bool addSigCompCompartment(const char* compId);
+ bool removeSigCompCompartment(const char* compId);
+
+ bool setSTUNEnabledForICE(bool enabled); // @deprecated
+ bool setSTUNServer(const char* hostname, unsigned short port); // @deprecated
+ bool setSTUNCred(const char* login, const char* password); // @deprecated
+ bool setSTUNEnabled(bool enabled);
+
+ bool setTLSSecAgree(bool enabled);
+ bool setSSLCertificates(const char* privKey, const char* pubKey, const char* caKey, bool verify = false);
+ bool setSSLCretificates(const char* privKey, const char* pubKey, const char* caKey, bool verify = false); /*@deprecated: typo */
+ bool setIPSecSecAgree(bool enabled);
+ bool setIPSecParameters(const char* algo, const char* ealgo, const char* mode, const char* proto);
+
+ char* dnsENUM(const char* service, const char* e164num, const char* domain);
+ char* dnsNaptrSrv(const char* domain, const char* service, unsigned short *OUTPUT);
+ char* dnsSrv(const char* service, unsigned short* OUTPUT);
+
+ bool setMaxFDs(unsigned max_fds);
+
+ char* getLocalIPnPort(const char* protocol, unsigned short* OUTPUT);
+
+ char* getPreferredIdentity();
+
+ bool isValid();
+ bool stop();
+
+ static bool initialize();
+ static bool deInitialize();
+ static void setCodecs(tdav_codec_id_t codecs);
+ static void setCodecs_2(int64_t codecs); // For stupid languages
+ static bool setCodecPriority(tdav_codec_id_t codec_id, int priority);
+ static bool setCodecPriority_2(int codec, int priority);// For stupid languages
+ static bool isCodecSupported(tdav_codec_id_t codec_id);
+ static bool isIPSecSupported();
+
+public: /* Public helper function */
+#if !defined(SWIG)
+ inline tsip_stack_handle_t* getHandle()const {
+ return m_pHandle;
+ }
+ inline SipCallback* getCallback()const {
+ return m_pCallback;
+ }
+ inline DDebugCallback* getDebugCallback() const {
+ return m_pDebugCallback;
+ }
+#endif
+
+private:
+ SipCallback* m_pCallback;
+ DDebugCallback* m_pDebugCallback;
+ tsip_stack_handle_t* m_pHandle;
+
+ static bool g_bInitialized;
+};
+
+#endif /* TINYWRAP_SIPSTACK_H */
diff --git a/bindings/_common/SipStack.i b/bindings/_common/SipStack.i index db52855..e2cf203 100755 --- a/bindings/_common/SipStack.i +++ b/bindings/_common/SipStack.i @@ -1,457 +1,457 @@ - -%{ -#include "ActionConfig.h" -#include "MediaSessionMgr.h" -#include "MediaContent.h" -#include "SipUri.h" -#include "SipMessage.h" -#include "SipEvent.h" -#include "SipSession.h" - -#include "ProxyPluginMgr.h" -#include "ProxyConsumer.h" -#include "ProxyProducer.h" - -#include "SipCallback.h" -#include "SafeObject.h" -#include "SipStack.h" -%} - -/* Callbacks */ -%feature("director") SipCallback; -%feature("director") ProxyPluginMgrCallback; -%feature("director") ProxyAudioConsumerCallback; -%feature("director") ProxyVideoConsumerCallback; -%feature("director") ProxyAudioProducerCallback; -%feature("director") ProxyVideoProducerCallback; -%feature("director") T140Callback; - -%nodefaultctor; -%include "ActionConfig.h" -%include "MediaSessionMgr.h" -%include "MediaContent.h" -%include "SipUri.h" -%include "SipMessage.h" -%include "SipEvent.h" -%include "SipSession.h" - -%include "ProxyPluginMgr.h" -%include "ProxyConsumer.h" -%include "ProxyProducer.h" - -%include "SipCallback.h" -%include "SafeObject.h" -%include "SipStack.h" -%clearnodefaultctor; - - -/* ====== From "tinySIP\include\tsip.h" ====== */ -typedef enum tsip_stack_mode_e -{ - tsip_stack_mode_ua, - tsip_stack_mode_p2p, - tsip_stack_mode_mediaproxy, - tsip_stack_mode_mcu -} -tsip_stack_mode_t; - -/* ====== From "tinySIP\include\tinysip\tsip_messag_common.h" ====== */ -typedef enum tsip_request_type_e -{ - tsip_NONE = 0, - - tsip_ACK, - tsip_BYE, - tsip_CANCEL, - tsip_INVITE, - tsip_OPTIONS, - tsip_REGISTER, - tsip_SUBSCRIBE, - tsip_NOTIFY, - tsip_REFER, - tsip_INFO, - tsip_UPDATE, - tsip_MESSAGE, - tsip_PUBLISH, - tsip_PRACK -} -tsip_request_type_t; - - -/* ====== From "tinySIP\include\tinysip\tsip_event.h" ====== */ -typedef enum tsip_event_type_e -{ - tsip_event_invite, - tsip_event_message, - tsip_event_info, - tsip_event_options, - tsip_event_publish, - tsip_event_register, - tsip_event_subscribe, - - tsip_event_dialog -} -tsip_event_type_t; - -// 7xx ==> errors -#define tsip_event_code_dialog_transport_error 702 -#define tsip_event_code_dialog_global_error 703 -#define tsip_event_code_dialog_message_error 704 - -// 8xx ==> success -#define tsip_event_code_dialog_request_incoming 800 -#define tsip_event_code_dialog_request_outgoing 802 -#define tsip_event_code_dialog_request_cancelled 803 -#define tsip_event_code_dialog_request_sent 804 - -// 9xx ==> Informational -#define tsip_event_code_dialog_connecting 900 -#define tsip_event_code_dialog_connected 901 -#define tsip_event_code_dialog_terminating 902 -#define tsip_event_code_dialog_terminated 903 -#define tsip_event_code_stack_starting 950 -#define tsip_event_code_stack_started 951 -#define tsip_event_code_stack_stopping 952 -#define tsip_event_code_stack_stopped 953 -#define tsip_event_code_stack_failed_to_start 954 -#define tsip_event_code_stack_failed_to_stop 955 -#define tsip_event_code_stack_disconnected 956 - -/* ====== From "tinySIP\include\tinysip\tsip_api_register.h" ====== */ -typedef enum tsip_register_event_type_e -{ - tsip_i_newreg, - - tsip_i_register, // refresh - tsip_ao_register, - - tsip_i_unregister, - tsip_ao_unregister, -} -tsip_register_event_type_t; - -/* ====== From "tinySIP\include\tinysip\tsip_api_subscribe.h" ====== */ -typedef enum tsip_subscribe_event_type_e -{ - tsip_i_subscribe, - tsip_ao_subscribe, - - tsip_i_unsubscribe, - tsip_ao_unsubscribe, - - tsip_i_notify, - tsip_ao_notify -} -tsip_subscribe_event_type_t; - -/* ====== From "tinySIP\include\tinysip\tsip_api_publish.h" ====== */ -typedef enum tsip_publish_event_type_e -{ - tsip_i_publish, - tsip_ao_publish, - - tsip_i_unpublish, - tsip_ao_unpublish -} -tsip_publish_event_type_t; - -/* ====== From "tinySIP\include\tinysip\tsip_api_message.h" ====== */ -typedef enum tsip_message_event_type_e -{ - tsip_i_message, - tsip_ao_message, -} -tsip_message_event_type_t; - -/* ====== From "tinySIP\include\tinysip\tsip_api_info.h" ====== */ -typedef enum tsip_info_event_type_e -{ - tsip_i_info, - tsip_ao_info, -} -tsip_info_event_type_t; - -/* ====== From "tinySIP\include\tinysip\tsip_api_options.h" ====== */ -typedef enum tsip_options_event_type_e -{ - tsip_i_options, - tsip_ao_options, -} -tsip_options_event_type_t; - - -/* ====== From "tinySIP\include\tinysip\tsip_api_invite.h" ====== */ -typedef enum tsip_invite_event_type_e -{ - // ============================ - // Sip Events - // - tsip_i_newcall, - - //! in-dialog requests/reponses - tsip_i_request, - tsip_ao_request, - - /* 3GPP TS 24.629: Explicit Call Transfer (ECT) */ - tsip_o_ect_trying, - tsip_o_ect_accepted, - tsip_o_ect_completed, - tsip_o_ect_failed, - tsip_o_ect_notify, - tsip_i_ect_requested, - tsip_i_ect_newcall, - tsip_i_ect_completed, - tsip_i_ect_failed, - tsip_i_ect_notify, - - // ============================ - // Media Events - // - - tsip_m_early_media, - tsip_m_updating, // Trying to update from Audio -> Video for example - tsip_m_updated, // succeed to update - - /* 3GPP TS 24.610: Communication Hold */ - tsip_m_local_hold_ok, - tsip_m_local_hold_nok, - tsip_m_local_resume_ok, - tsip_m_local_resume_nok, - tsip_m_remote_hold, - tsip_m_remote_resume, -} -tsip_invite_event_type_t; - - -/* ====== From "tinymedia/tmedia_qos.h" ====== */ -typedef enum tmedia_qos_stype_e -{ - tmedia_qos_stype_none,/* not part of the RFC */ - - tmedia_qos_stype_segmented, - tmedia_qos_stype_e2e, -} -tmedia_qos_stype_t; - -/* ====== From "tinymedia/tmedia_qos.h" ====== */ -typedef enum tmedia_qos_strength_e -{ - /* do no change the order (none -> optional -> manadatory) */ - tmedia_qos_strength_none, - tmedia_qos_strength_failure, - tmedia_qos_strength_unknown, - tmedia_qos_strength_optional, - tmedia_qos_strength_mandatory -} -tmedia_qos_strength_t; - - -/* ====== From "tinymedia/tmedia_common.h" ====== */ -// used by tinyWRAP -typedef enum tmedia_chroma_e -{ - tmedia_chroma_none=0, - tmedia_chroma_rgb24, // will be stored as bgr24 on x86 (little endians) machines; e.g. WindowsPhone7 - tmedia_chroma_bgr24, // used by windows consumer (DirectShow) - - tmedia_chroma_rgb32, // used by iOS4 consumer (iPhone and iPod touch) - tmedia_chroma_rgb565le, // (used by both android and wince consumers) - tmedia_chroma_rgb565be, - tmedia_chroma_nv12, // used by iOS4 producer (iPhone and iPod Touch 3GS and 4) - tmedia_chroma_nv21, // Yuv420 SP (used by android producer) - tmedia_chroma_yuv422p, - tmedia_chroma_uyvy422, // used by iOS4 producer (iPhone and iPod Touch 3G) - tmedia_chroma_yuv420p, // Default - tmedia_chroma_mjpeg, // Compressed. e.g. used by VirtualBox (Windows as host and Ubuntu as guest) - tmedia_chroma_yuyv422, // YUYV422 (V4L2 preferred format) -} -tmedia_chroma_t; - -/* ====== From "tinymedia/tmedia_common.h" ====== */ -typedef enum tmedia_mode_e -{ - tmedia_mode_none, - tmedia_mode_optional, - tmedia_mode_mandatory -} -tmedia_mode_t; - -/* ====== From "tinymedia/tmedia_common.h" ====== */ -typedef enum tmedia_srtp_mode_e -{ - tmedia_srtp_mode_none, - tmedia_srtp_mode_optional, - tmedia_srtp_mode_mandatory -} -tmedia_srtp_mode_t; - -/* ====== From "tinymedia/tmedia_common.h" ====== */ -typedef enum tmedia_srtp_type_e -{ - tmedia_srtp_type_none = 0x00, - tmedia_srtp_type_sdes = 0x01, - tmedia_srtp_type_dtls = 0x02, - tmedia_srtp_type_sdes_dtls = (0x01 | 0x02) -} -tmedia_srtp_type_t; - -/* ====== From "tinymedia/tmedia_common.h" ====== */ -typedef enum tmedia_t140_data_type_e -{ - tmedia_t140_data_type_utf8, - tmedia_t140_data_type_zero_width_no_break_space = 0xefbbbf, - tmedia_t140_data_type_backspace = 0x08, - tmedia_t140_data_type_esc = 0x1b, - tmedia_t140_data_type_cr = 0x0d, - tmedia_t140_data_type_lf = 0x0a, - tmedia_t140_data_type_cr_lf = 0x0d0a, - tmedia_t140_data_type_interrupt2 = 0x61, - tmedia_t140_data_type_bell = 0x07, - tmedia_t140_data_type_sos = 0x98, - tmedia_t140_data_type_string_term = 0x9c, - tmedia_t140_data_type_graphic_start = 0x9b, - tmedia_t140_data_type_graphic_end = 0x6d, - tmedia_t140_data_type_loss_char_char = 0xfffd, - tmedia_t140_data_type_loss_utf8 = 0xefbfbd, -} -tmedia_t140_data_type_t; - -/* ====== From "tinymedia/tmedia_common.h" ====== */ -#typedef enum tmedia_rtcp_event_type_e -#{ -# tmedia_rtcp_event_type_fir, // Full Intra Refresh -#} -#tmedia_rtcp_event_type_t; - -/* ====== From "tinymedia/tmedia_common.h" ====== */ -typedef enum tmedia_profile_e -{ - tmedia_profile_default, - tmedia_profile_rtcweb -} -tmedia_profile_t; - -/* ====== From "tinymedia/tmedia_common.h" ====== */ -// @deprecated -typedef enum tmedia_bandwidth_level_e -{ - tmedia_bl_low, - tmedia_bl_medium, - tmedia_bl_hight, - tmedia_bl_unrestricted -} -tmedia_bandwidth_level_t; - -/* ====== From "tinymedia/tmedia_common.h" ====== */ -typedef enum tmedia_pref_video_size_s -{ /* must be sorted like this */ - tmedia_pref_video_size_sqcif, // 128 x 98 - tmedia_pref_video_size_qcif, // 176 x 144 - tmedia_pref_video_size_qvga, // 320 x 240 - tmedia_pref_video_size_cif, // 352 x 288 - tmedia_pref_video_size_hvga, // 480 x 320 - tmedia_pref_video_size_vga, // 640 x 480 - tmedia_pref_video_size_4cif, // 704 x 576 - tmedia_pref_video_size_wvga, // 800 x 480 - tmedia_pref_video_size_svga, // 800 x 600 - tmedia_pref_video_size_480p, // 852 x 480 - tmedia_pref_video_size_xga, // 1024 x 768 - tmedia_pref_video_size_720p, // 1280 x 720 - tmedia_pref_video_size_16cif, // 1408 x 1152 - tmedia_pref_video_size_1080p, // 1920 x 1080 - tmedia_pref_video_size_2160p, // 3840 x 2160 -} -tmedia_pref_video_size_t; - - -/* ====== From "tinymedia/tmedia_codec.h" ====== */ -typedef enum tmedia_codec_id_e -{ - tmedia_codec_id_none = 0x00000000, - - tmedia_codec_id_amr_nb_oa = 0x00000001<<0, - tmedia_codec_id_amr_nb_be = 0x00000001<<1, - tmedia_codec_id_amr_wb_oa = 0x00000001<<2, - tmedia_codec_id_amr_wb_be = 0x00000001<<3, - tmedia_codec_id_gsm = 0x00000001<<4, - tmedia_codec_id_pcma = 0x00000001<<5, - tmedia_codec_id_pcmu = 0x00000001<<6, - tmedia_codec_id_ilbc = 0x00000001<<7, - tmedia_codec_id_speex_nb = 0x00000001<<8, - tmedia_codec_id_speex_wb = 0x00000001<<9, - tmedia_codec_id_speex_uwb = 0x00000001<<10, - tmedia_codec_id_bv16 = 0x00000001<<11, - tmedia_codec_id_bv32 = 0x00000001<<12, - tmedia_codec_id_opus = 0x00000001<<13, - tmedia_codec_id_g729ab = 0x00000001<<14, - tmedia_codec_id_g722 = 0x00000001<<15, - - /* room for new Audio codecs */ - - tmedia_codec_id_h261 = 0x00010000<<0, - tmedia_codec_id_h263 = 0x00010000<<1, - tmedia_codec_id_h263p = 0x00010000<<2, - tmedia_codec_id_h263pp = 0x00010000<<3, - tmedia_codec_id_h264_bp = 0x00010000<<4, - tmedia_codec_id_h264_mp = 0x00010000<<5, - tmedia_codec_id_h264_hp = 0x00010000<<6, - tmedia_codec_id_h264_bp10 = tmedia_codec_id_h264_bp, // @deprecated - tmedia_codec_id_h264_bp20 = tmedia_codec_id_h264_bp, // @deprecated - tmedia_codec_id_h264_bp30 = tmedia_codec_id_h264_bp, // @deprecated - tmedia_codec_id_h264_svc = 0x00010000<<7, - tmedia_codec_id_theora = 0x00010000<<8, - tmedia_codec_id_mp4ves_es = 0x00010000<<9, - tmedia_codec_id_vp8 = 0x00010000<<10, - - /* room for new Video codecs */ - - tmedia_codec_id_t140 = 0x00010000<<14, - tmedia_codec_id_red = 0x00010000<<15, -} -tmedia_codec_id_t; - -/* ====== From "tinydav/tdav.h" ====== */ -// @deprecated: to be replaced by "tmedia_codec_id_t" in Doubango 3.0 -typedef enum tdav_codec_id_e -{ - tdav_codec_id_none = 0x00000000, - - tdav_codec_id_amr_nb_oa = 0x00000001<<0, - tdav_codec_id_amr_nb_be = 0x00000001<<1, - tdav_codec_id_amr_wb_oa = 0x00000001<<2, - tdav_codec_id_amr_wb_be = 0x00000001<<3, - tdav_codec_id_gsm = 0x00000001<<4, - tdav_codec_id_pcma = 0x00000001<<5, - tdav_codec_id_pcmu = 0x00000001<<6, - tdav_codec_id_ilbc = 0x00000001<<7, - tdav_codec_id_speex_nb = 0x00000001<<8, - tdav_codec_id_speex_wb = 0x00000001<<9, - tdav_codec_id_speex_uwb = 0x00000001<<10, - tdav_codec_id_bv16 = 0x00000001<<11, - tdav_codec_id_bv32 = 0x00000001<<12, - tdav_codec_id_opus = 0x00000001<<13, - tdav_codec_id_g729ab = 0x00000001<<14, - tdav_codec_id_g722 = 0x00000001<<15, - - /* room for new Audio codecs */ - - tdav_codec_id_h261 = 0x00010000<<0, - tdav_codec_id_h263 = 0x00010000<<1, - tdav_codec_id_h263p = 0x00010000<<2, - tdav_codec_id_h263pp = 0x00010000<<3, - tdav_codec_id_h264_bp = 0x00010000<<4, - tdav_codec_id_h264_mp = 0x00010000<<5, - tdav_codec_id_h264_hp = 0x00010000<<6, - tdav_codec_id_h264_bp10 = tdav_codec_id_h264_bp, // @deprecated - tdav_codec_id_h264_bp20 = tdav_codec_id_h264_bp, // @deprecated - tdav_codec_id_h264_bp30 = tdav_codec_id_h264_bp, // @deprecated - tdav_codec_id_h264_svc = 0x00010000<<7, - tdav_codec_id_theora = 0x00010000<<8, - tdav_codec_id_mp4ves_es = 0x00010000<<9, - tdav_codec_id_vp8 = 0x00010000<<10, - - /* room for new Video codecs */ - - tdav_codec_id_t140 = 0x00010000<<14, - tdav_codec_id_red = 0x00010000<<15, -} -tdav_codec_id_t; +
+%{
+#include "ActionConfig.h"
+#include "MediaSessionMgr.h"
+#include "MediaContent.h"
+#include "SipUri.h"
+#include "SipMessage.h"
+#include "SipEvent.h"
+#include "SipSession.h"
+
+#include "ProxyPluginMgr.h"
+#include "ProxyConsumer.h"
+#include "ProxyProducer.h"
+
+#include "SipCallback.h"
+#include "SafeObject.h"
+#include "SipStack.h"
+%}
+
+/* Callbacks */
+%feature("director") SipCallback;
+%feature("director") ProxyPluginMgrCallback;
+%feature("director") ProxyAudioConsumerCallback;
+%feature("director") ProxyVideoConsumerCallback;
+%feature("director") ProxyAudioProducerCallback;
+%feature("director") ProxyVideoProducerCallback;
+%feature("director") T140Callback;
+
+%nodefaultctor;
+%include "ActionConfig.h"
+%include "MediaSessionMgr.h"
+%include "MediaContent.h"
+%include "SipUri.h"
+%include "SipMessage.h"
+%include "SipEvent.h"
+%include "SipSession.h"
+
+%include "ProxyPluginMgr.h"
+%include "ProxyConsumer.h"
+%include "ProxyProducer.h"
+
+%include "SipCallback.h"
+%include "SafeObject.h"
+%include "SipStack.h"
+%clearnodefaultctor;
+
+
+/* ====== From "tinySIP\include\tsip.h" ====== */
+typedef enum tsip_stack_mode_e
+{
+ tsip_stack_mode_ua,
+ tsip_stack_mode_p2p,
+ tsip_stack_mode_mediaproxy,
+ tsip_stack_mode_mcu
+}
+tsip_stack_mode_t;
+
+/* ====== From "tinySIP\include\tinysip\tsip_messag_common.h" ====== */
+typedef enum tsip_request_type_e
+{
+ tsip_NONE = 0,
+
+ tsip_ACK,
+ tsip_BYE,
+ tsip_CANCEL,
+ tsip_INVITE,
+ tsip_OPTIONS,
+ tsip_REGISTER,
+ tsip_SUBSCRIBE,
+ tsip_NOTIFY,
+ tsip_REFER,
+ tsip_INFO,
+ tsip_UPDATE,
+ tsip_MESSAGE,
+ tsip_PUBLISH,
+ tsip_PRACK
+}
+tsip_request_type_t;
+
+
+/* ====== From "tinySIP\include\tinysip\tsip_event.h" ====== */
+typedef enum tsip_event_type_e
+{
+ tsip_event_invite,
+ tsip_event_message,
+ tsip_event_info,
+ tsip_event_options,
+ tsip_event_publish,
+ tsip_event_register,
+ tsip_event_subscribe,
+
+ tsip_event_dialog
+}
+tsip_event_type_t;
+
+// 7xx ==> errors
+#define tsip_event_code_dialog_transport_error 702
+#define tsip_event_code_dialog_global_error 703
+#define tsip_event_code_dialog_message_error 704
+
+// 8xx ==> success
+#define tsip_event_code_dialog_request_incoming 800
+#define tsip_event_code_dialog_request_outgoing 802
+#define tsip_event_code_dialog_request_cancelled 803
+#define tsip_event_code_dialog_request_sent 804
+
+// 9xx ==> Informational
+#define tsip_event_code_dialog_connecting 900
+#define tsip_event_code_dialog_connected 901
+#define tsip_event_code_dialog_terminating 902
+#define tsip_event_code_dialog_terminated 903
+#define tsip_event_code_stack_starting 950
+#define tsip_event_code_stack_started 951
+#define tsip_event_code_stack_stopping 952
+#define tsip_event_code_stack_stopped 953
+#define tsip_event_code_stack_failed_to_start 954
+#define tsip_event_code_stack_failed_to_stop 955
+#define tsip_event_code_stack_disconnected 956
+
+/* ====== From "tinySIP\include\tinysip\tsip_api_register.h" ====== */
+typedef enum tsip_register_event_type_e
+{
+ tsip_i_newreg,
+
+ tsip_i_register, // refresh
+ tsip_ao_register,
+
+ tsip_i_unregister,
+ tsip_ao_unregister,
+}
+tsip_register_event_type_t;
+
+/* ====== From "tinySIP\include\tinysip\tsip_api_subscribe.h" ====== */
+typedef enum tsip_subscribe_event_type_e
+{
+ tsip_i_subscribe,
+ tsip_ao_subscribe,
+
+ tsip_i_unsubscribe,
+ tsip_ao_unsubscribe,
+
+ tsip_i_notify,
+ tsip_ao_notify
+}
+tsip_subscribe_event_type_t;
+
+/* ====== From "tinySIP\include\tinysip\tsip_api_publish.h" ====== */
+typedef enum tsip_publish_event_type_e
+{
+ tsip_i_publish,
+ tsip_ao_publish,
+
+ tsip_i_unpublish,
+ tsip_ao_unpublish
+}
+tsip_publish_event_type_t;
+
+/* ====== From "tinySIP\include\tinysip\tsip_api_message.h" ====== */
+typedef enum tsip_message_event_type_e
+{
+ tsip_i_message,
+ tsip_ao_message,
+}
+tsip_message_event_type_t;
+
+/* ====== From "tinySIP\include\tinysip\tsip_api_info.h" ====== */
+typedef enum tsip_info_event_type_e
+{
+ tsip_i_info,
+ tsip_ao_info,
+}
+tsip_info_event_type_t;
+
+/* ====== From "tinySIP\include\tinysip\tsip_api_options.h" ====== */
+typedef enum tsip_options_event_type_e
+{
+ tsip_i_options,
+ tsip_ao_options,
+}
+tsip_options_event_type_t;
+
+
+/* ====== From "tinySIP\include\tinysip\tsip_api_invite.h" ====== */
+typedef enum tsip_invite_event_type_e
+{
+ // ============================
+ // Sip Events
+ //
+ tsip_i_newcall,
+
+ //! in-dialog requests/reponses
+ tsip_i_request,
+ tsip_ao_request,
+
+ /* 3GPP TS 24.629: Explicit Call Transfer (ECT) */
+ tsip_o_ect_trying,
+ tsip_o_ect_accepted,
+ tsip_o_ect_completed,
+ tsip_o_ect_failed,
+ tsip_o_ect_notify,
+ tsip_i_ect_requested,
+ tsip_i_ect_newcall,
+ tsip_i_ect_completed,
+ tsip_i_ect_failed,
+ tsip_i_ect_notify,
+
+ // ============================
+ // Media Events
+ //
+
+ tsip_m_early_media,
+ tsip_m_updating, // Trying to update from Audio -> Video for example
+ tsip_m_updated, // succeed to update
+
+ /* 3GPP TS 24.610: Communication Hold */
+ tsip_m_local_hold_ok,
+ tsip_m_local_hold_nok,
+ tsip_m_local_resume_ok,
+ tsip_m_local_resume_nok,
+ tsip_m_remote_hold,
+ tsip_m_remote_resume,
+}
+tsip_invite_event_type_t;
+
+
+/* ====== From "tinymedia/tmedia_qos.h" ====== */
+typedef enum tmedia_qos_stype_e
+{
+ tmedia_qos_stype_none,/* not part of the RFC */
+
+ tmedia_qos_stype_segmented,
+ tmedia_qos_stype_e2e,
+}
+tmedia_qos_stype_t;
+
+/* ====== From "tinymedia/tmedia_qos.h" ====== */
+typedef enum tmedia_qos_strength_e
+{
+ /* do no change the order (none -> optional -> manadatory) */
+ tmedia_qos_strength_none,
+ tmedia_qos_strength_failure,
+ tmedia_qos_strength_unknown,
+ tmedia_qos_strength_optional,
+ tmedia_qos_strength_mandatory
+}
+tmedia_qos_strength_t;
+
+
+/* ====== From "tinymedia/tmedia_common.h" ====== */
+// used by tinyWRAP
+typedef enum tmedia_chroma_e
+{
+ tmedia_chroma_none=0,
+ tmedia_chroma_rgb24, // will be stored as bgr24 on x86 (little endians) machines; e.g. WindowsPhone7
+ tmedia_chroma_bgr24, // used by windows consumer (DirectShow) -
+ tmedia_chroma_rgb32, // used by iOS4 consumer (iPhone and iPod touch)
+ tmedia_chroma_rgb565le, // (used by both android and wince consumers)
+ tmedia_chroma_rgb565be,
+ tmedia_chroma_nv12, // used by iOS4 producer (iPhone and iPod Touch 3GS and 4)
+ tmedia_chroma_nv21, // Yuv420 SP (used by android producer)
+ tmedia_chroma_yuv422p,
+ tmedia_chroma_uyvy422, // used by iOS4 producer (iPhone and iPod Touch 3G)
+ tmedia_chroma_yuv420p, // Default
+ tmedia_chroma_mjpeg, // Compressed. e.g. used by VirtualBox (Windows as host and Ubuntu as guest)
+ tmedia_chroma_yuyv422, // YUYV422 (V4L2 preferred format)
+}
+tmedia_chroma_t;
+
+/* ====== From "tinymedia/tmedia_common.h" ====== */
+typedef enum tmedia_mode_e
+{
+ tmedia_mode_none,
+ tmedia_mode_optional,
+ tmedia_mode_mandatory
+}
+tmedia_mode_t;
+
+/* ====== From "tinymedia/tmedia_common.h" ====== */
+typedef enum tmedia_srtp_mode_e
+{
+ tmedia_srtp_mode_none,
+ tmedia_srtp_mode_optional,
+ tmedia_srtp_mode_mandatory
+}
+tmedia_srtp_mode_t;
+
+/* ====== From "tinymedia/tmedia_common.h" ====== */
+typedef enum tmedia_srtp_type_e
+{
+ tmedia_srtp_type_none = 0x00,
+ tmedia_srtp_type_sdes = 0x01,
+ tmedia_srtp_type_dtls = 0x02,
+ tmedia_srtp_type_sdes_dtls = (0x01 | 0x02)
+}
+tmedia_srtp_type_t;
+
+/* ====== From "tinymedia/tmedia_common.h" ====== */
+typedef enum tmedia_t140_data_type_e
+{
+ tmedia_t140_data_type_utf8,
+ tmedia_t140_data_type_zero_width_no_break_space = 0xefbbbf,
+ tmedia_t140_data_type_backspace = 0x08,
+ tmedia_t140_data_type_esc = 0x1b,
+ tmedia_t140_data_type_cr = 0x0d,
+ tmedia_t140_data_type_lf = 0x0a,
+ tmedia_t140_data_type_cr_lf = 0x0d0a,
+ tmedia_t140_data_type_interrupt2 = 0x61,
+ tmedia_t140_data_type_bell = 0x07,
+ tmedia_t140_data_type_sos = 0x98,
+ tmedia_t140_data_type_string_term = 0x9c,
+ tmedia_t140_data_type_graphic_start = 0x9b,
+ tmedia_t140_data_type_graphic_end = 0x6d,
+ tmedia_t140_data_type_loss_char_char = 0xfffd,
+ tmedia_t140_data_type_loss_utf8 = 0xefbfbd,
+}
+tmedia_t140_data_type_t;
+
+/* ====== From "tinymedia/tmedia_common.h" ====== */
+#typedef enum tmedia_rtcp_event_type_e
+#{
+# tmedia_rtcp_event_type_fir, // Full Intra Refresh
+#}
+#tmedia_rtcp_event_type_t;
+
+/* ====== From "tinymedia/tmedia_common.h" ====== */
+typedef enum tmedia_profile_e
+{
+ tmedia_profile_default,
+ tmedia_profile_rtcweb
+}
+tmedia_profile_t;
+
+/* ====== From "tinymedia/tmedia_common.h" ====== */
+// @deprecated
+typedef enum tmedia_bandwidth_level_e
+{
+ tmedia_bl_low,
+ tmedia_bl_medium,
+ tmedia_bl_hight,
+ tmedia_bl_unrestricted
+}
+tmedia_bandwidth_level_t;
+
+/* ====== From "tinymedia/tmedia_common.h" ====== */
+typedef enum tmedia_pref_video_size_s
+{ /* must be sorted like this */
+ tmedia_pref_video_size_sqcif, // 128 x 98
+ tmedia_pref_video_size_qcif, // 176 x 144
+ tmedia_pref_video_size_qvga, // 320 x 240
+ tmedia_pref_video_size_cif, // 352 x 288
+ tmedia_pref_video_size_hvga, // 480 x 320
+ tmedia_pref_video_size_vga, // 640 x 480
+ tmedia_pref_video_size_4cif, // 704 x 576
+ tmedia_pref_video_size_wvga, // 800 x 480
+ tmedia_pref_video_size_svga, // 800 x 600
+ tmedia_pref_video_size_480p, // 852 x 480
+ tmedia_pref_video_size_xga, // 1024 x 768
+ tmedia_pref_video_size_720p, // 1280 x 720
+ tmedia_pref_video_size_16cif, // 1408 x 1152
+ tmedia_pref_video_size_1080p, // 1920 x 1080
+ tmedia_pref_video_size_2160p, // 3840 x 2160
+}
+tmedia_pref_video_size_t;
+
+
+/* ====== From "tinymedia/tmedia_codec.h" ====== */
+typedef enum tmedia_codec_id_e
+{
+ tmedia_codec_id_none = 0x00000000,
+
+ tmedia_codec_id_amr_nb_oa = 0x00000001<<0,
+ tmedia_codec_id_amr_nb_be = 0x00000001<<1,
+ tmedia_codec_id_amr_wb_oa = 0x00000001<<2,
+ tmedia_codec_id_amr_wb_be = 0x00000001<<3,
+ tmedia_codec_id_gsm = 0x00000001<<4,
+ tmedia_codec_id_pcma = 0x00000001<<5,
+ tmedia_codec_id_pcmu = 0x00000001<<6,
+ tmedia_codec_id_ilbc = 0x00000001<<7,
+ tmedia_codec_id_speex_nb = 0x00000001<<8,
+ tmedia_codec_id_speex_wb = 0x00000001<<9,
+ tmedia_codec_id_speex_uwb = 0x00000001<<10,
+ tmedia_codec_id_bv16 = 0x00000001<<11,
+ tmedia_codec_id_bv32 = 0x00000001<<12,
+ tmedia_codec_id_opus = 0x00000001<<13,
+ tmedia_codec_id_g729ab = 0x00000001<<14,
+ tmedia_codec_id_g722 = 0x00000001<<15,
+
+ /* room for new Audio codecs */
+
+ tmedia_codec_id_h261 = 0x00010000<<0,
+ tmedia_codec_id_h263 = 0x00010000<<1,
+ tmedia_codec_id_h263p = 0x00010000<<2,
+ tmedia_codec_id_h263pp = 0x00010000<<3,
+ tmedia_codec_id_h264_bp = 0x00010000<<4,
+ tmedia_codec_id_h264_mp = 0x00010000<<5,
+ tmedia_codec_id_h264_hp = 0x00010000<<6,
+ tmedia_codec_id_h264_bp10 = tmedia_codec_id_h264_bp, // @deprecated
+ tmedia_codec_id_h264_bp20 = tmedia_codec_id_h264_bp, // @deprecated
+ tmedia_codec_id_h264_bp30 = tmedia_codec_id_h264_bp, // @deprecated
+ tmedia_codec_id_h264_svc = 0x00010000<<7,
+ tmedia_codec_id_theora = 0x00010000<<8,
+ tmedia_codec_id_mp4ves_es = 0x00010000<<9,
+ tmedia_codec_id_vp8 = 0x00010000<<10,
+
+ /* room for new Video codecs */
+
+ tmedia_codec_id_t140 = 0x00010000<<14,
+ tmedia_codec_id_red = 0x00010000<<15,
+}
+tmedia_codec_id_t;
+
+/* ====== From "tinydav/tdav.h" ====== */
+// @deprecated: to be replaced by "tmedia_codec_id_t" in Doubango 3.0
+typedef enum tdav_codec_id_e
+{
+ tdav_codec_id_none = 0x00000000,
+
+ tdav_codec_id_amr_nb_oa = 0x00000001<<0,
+ tdav_codec_id_amr_nb_be = 0x00000001<<1,
+ tdav_codec_id_amr_wb_oa = 0x00000001<<2,
+ tdav_codec_id_amr_wb_be = 0x00000001<<3,
+ tdav_codec_id_gsm = 0x00000001<<4,
+ tdav_codec_id_pcma = 0x00000001<<5,
+ tdav_codec_id_pcmu = 0x00000001<<6,
+ tdav_codec_id_ilbc = 0x00000001<<7,
+ tdav_codec_id_speex_nb = 0x00000001<<8,
+ tdav_codec_id_speex_wb = 0x00000001<<9,
+ tdav_codec_id_speex_uwb = 0x00000001<<10,
+ tdav_codec_id_bv16 = 0x00000001<<11,
+ tdav_codec_id_bv32 = 0x00000001<<12,
+ tdav_codec_id_opus = 0x00000001<<13,
+ tdav_codec_id_g729ab = 0x00000001<<14,
+ tdav_codec_id_g722 = 0x00000001<<15,
+
+ /* room for new Audio codecs */
+
+ tdav_codec_id_h261 = 0x00010000<<0,
+ tdav_codec_id_h263 = 0x00010000<<1,
+ tdav_codec_id_h263p = 0x00010000<<2,
+ tdav_codec_id_h263pp = 0x00010000<<3,
+ tdav_codec_id_h264_bp = 0x00010000<<4,
+ tdav_codec_id_h264_mp = 0x00010000<<5,
+ tdav_codec_id_h264_hp = 0x00010000<<6,
+ tdav_codec_id_h264_bp10 = tdav_codec_id_h264_bp, // @deprecated
+ tdav_codec_id_h264_bp20 = tdav_codec_id_h264_bp, // @deprecated
+ tdav_codec_id_h264_bp30 = tdav_codec_id_h264_bp, // @deprecated
+ tdav_codec_id_h264_svc = 0x00010000<<7,
+ tdav_codec_id_theora = 0x00010000<<8,
+ tdav_codec_id_mp4ves_es = 0x00010000<<9,
+ tdav_codec_id_vp8 = 0x00010000<<10,
+
+ /* room for new Video codecs */
+
+ tdav_codec_id_t140 = 0x00010000<<14,
+ tdav_codec_id_red = 0x00010000<<15,
+}
+tdav_codec_id_t;
diff --git a/bindings/_common/SipUri.cxx b/bindings/_common/SipUri.cxx index a55488e..82bcef3 100755 --- a/bindings/_common/SipUri.cxx +++ b/bindings/_common/SipUri.cxx @@ -1,102 +1,102 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "SipUri.h" - -SipUri::SipUri(const char* uriString, const char* displayName/*=tsk_null*/) -{ - if((m_pUri = tsip_uri_parse(uriString, (tsk_size_t)tsk_strlen(uriString))) && displayName) { - m_pUri->display_name = tsk_strdup(displayName); - } -} - -SipUri::~SipUri() -{ - TSK_OBJECT_SAFE_FREE(m_pUri); -} - -bool SipUri::isValid(const char* uriString) -{ - tsip_uri_t* uri; - bool ret = false; - - if((uri = tsip_uri_parse(uriString, (tsk_size_t)tsk_strlen(uriString)))) { - ret = (uri->type != uri_unknown) - && (!tsk_strnullORempty(uri->host)); - TSK_OBJECT_SAFE_FREE(uri); - } - return ret; -} - -bool SipUri::isValid() -{ - return (m_pUri != tsk_null); -} - -const char* SipUri::getScheme() -{ - if(m_pUri) { - return m_pUri->scheme; - } - return tsk_null; -} - -const char* SipUri::getHost() -{ - return m_pUri ? m_pUri->host : tsk_null; -} - -unsigned short SipUri::getPort() -{ - return m_pUri ? m_pUri->port : 0; -} - -const char* SipUri::getUserName() -{ - return m_pUri ? m_pUri->user_name : tsk_null; -} - -const char* SipUri::getPassword() -{ - return m_pUri ? m_pUri->password : tsk_null; -} - -const char* SipUri::getDisplayName() -{ - return m_pUri ? m_pUri->display_name : tsk_null; -} - -void SipUri::setDisplayName(const char* displayName) -{ - if(m_pUri) { - tsk_strupdate(&m_pUri->display_name, displayName); - } -} - -const char* SipUri::getParamValue(const char* pname) -{ - if(m_pUri && m_pUri->params) { - const char* pvalue = tsk_params_get_param_value(m_pUri->params, pname); - return pvalue; - } - return tsk_null; -} - +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "SipUri.h"
+
+SipUri::SipUri(const char* uriString, const char* displayName/*=tsk_null*/)
+{
+ if((m_pUri = tsip_uri_parse(uriString, (tsk_size_t)tsk_strlen(uriString))) && displayName) {
+ m_pUri->display_name = tsk_strdup(displayName);
+ }
+}
+
+SipUri::~SipUri()
+{
+ TSK_OBJECT_SAFE_FREE(m_pUri);
+}
+
+bool SipUri::isValid(const char* uriString)
+{
+ tsip_uri_t* uri;
+ bool ret = false;
+
+ if((uri = tsip_uri_parse(uriString, (tsk_size_t)tsk_strlen(uriString)))) {
+ ret = (uri->type != uri_unknown)
+ && (!tsk_strnullORempty(uri->host));
+ TSK_OBJECT_SAFE_FREE(uri);
+ }
+ return ret;
+}
+
+bool SipUri::isValid()
+{
+ return (m_pUri != tsk_null);
+}
+
+const char* SipUri::getScheme()
+{
+ if(m_pUri) {
+ return m_pUri->scheme;
+ }
+ return tsk_null;
+}
+
+const char* SipUri::getHost()
+{
+ return m_pUri ? m_pUri->host : tsk_null;
+}
+
+unsigned short SipUri::getPort()
+{
+ return m_pUri ? m_pUri->port : 0;
+}
+
+const char* SipUri::getUserName()
+{
+ return m_pUri ? m_pUri->user_name : tsk_null;
+}
+
+const char* SipUri::getPassword()
+{
+ return m_pUri ? m_pUri->password : tsk_null;
+}
+
+const char* SipUri::getDisplayName()
+{
+ return m_pUri ? m_pUri->display_name : tsk_null;
+}
+
+void SipUri::setDisplayName(const char* displayName)
+{
+ if(m_pUri) {
+ tsk_strupdate(&m_pUri->display_name, displayName);
+ }
+}
+
+const char* SipUri::getParamValue(const char* pname)
+{
+ if(m_pUri && m_pUri->params) {
+ const char* pvalue = tsk_params_get_param_value(m_pUri->params, pname);
+ return pvalue;
+ }
+ return tsk_null;
+}
+
diff --git a/bindings/_common/SipUri.h b/bindings/_common/SipUri.h index 7baac53..94a1081 100755 --- a/bindings/_common/SipUri.h +++ b/bindings/_common/SipUri.h @@ -1,57 +1,57 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_SIPURI_H -#define TINYWRAP_SIPURI_H - -#include "tinyWRAP_config.h" - -#include "tinysip.h" - -class TINYWRAP_API SipUri -{ -public: - SipUri(const char* uriString, const char* displayName=tsk_null); - ~SipUri(); - -public: - static bool isValid(const char*); - - bool isValid(); - const char* getScheme(); - const char* getHost(); - unsigned short getPort(); - const char* getUserName(); - const char* getPassword(); - const char* getDisplayName(); - const char* getParamValue(const char* pname); - void setDisplayName(const char* displayName); -#if !defined(SWIG) - inline const tsip_uri_t* getWrappedUri()const { - return m_pUri; - } -#endif - -private: - tsip_uri_t* m_pUri; -}; - -#endif /* TINYWRAP_SIPURI_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_SIPURI_H
+#define TINYWRAP_SIPURI_H
+
+#include "tinyWRAP_config.h"
+
+#include "tinysip.h"
+
+class TINYWRAP_API SipUri
+{
+public:
+ SipUri(const char* uriString, const char* displayName=tsk_null);
+ ~SipUri();
+
+public:
+ static bool isValid(const char*);
+
+ bool isValid();
+ const char* getScheme();
+ const char* getHost();
+ unsigned short getPort();
+ const char* getUserName();
+ const char* getPassword();
+ const char* getDisplayName();
+ const char* getParamValue(const char* pname);
+ void setDisplayName(const char* displayName);
+#if !defined(SWIG)
+ inline const tsip_uri_t* getWrappedUri()const {
+ return m_pUri;
+ }
+#endif
+
+private:
+ tsip_uri_t* m_pUri;
+};
+
+#endif /* TINYWRAP_SIPURI_H */
diff --git a/bindings/_common/Xcap.cxx b/bindings/_common/Xcap.cxx index 510cb99..a04a177 100755 --- a/bindings/_common/Xcap.cxx +++ b/bindings/_common/Xcap.cxx @@ -1,561 +1,561 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#include "Xcap.h" - -#include "Common.h" - -unsigned XcapStack::count = 0; - -/* === ANSI-C functions (local use) === */ -static int stack_callback(const thttp_event_t *httpevent); - -/* =================================== XCAP Event ==================================== */ -typedef enum twrap_xcap_step_type_e { - txst_name, - txst_pos, - txst_att, - txst_pos_n_att, - txst_ns -} -twrap_xcap_step_type_t; - -typedef struct twrap_xcap_step_s { - TSK_DECLARE_OBJECT; - - twrap_xcap_step_type_t type; - char* qname; - char* att_qname; - char* att_value; - unsigned pos; - struct { - char* prefix; - char* value; - } ns; -} -twrap_xcap_step_t; - -static tsk_object_t* twrap_xcap_step_ctor(tsk_object_t * self, va_list * app) -{ - twrap_xcap_step_t *step = (twrap_xcap_step_t *)self; - if(step) { - } - return self; -} - -static tsk_object_t* twrap_xcap_step_dtor(tsk_object_t * self) -{ - twrap_xcap_step_t *step = (twrap_xcap_step_t *)self; - if(step) { - TSK_FREE(step->qname); - TSK_FREE(step->att_qname); - TSK_FREE(step->att_value); - TSK_FREE(step->ns.prefix); - TSK_FREE(step->ns.value); - } - - return self; -} - -static const tsk_object_def_t twrap_xcap_step_def_s = { - sizeof(twrap_xcap_step_t), - twrap_xcap_step_ctor, - twrap_xcap_step_dtor, - tsk_null, -}; -const tsk_object_def_t *twrap_xcap_step_def_t = &twrap_xcap_step_def_s; - -twrap_xcap_step_t* twrap_xcap_step_create(twrap_xcap_step_type_t type) -{ - twrap_xcap_step_t* step; - if((step = (twrap_xcap_step_t*)tsk_object_new(twrap_xcap_step_def_t))) { - step->type = type; - } - return step; -} - -XcapSelector::XcapSelector(XcapStack* stack) - : auid(tsk_null) -{ - if(stack) { - this->stack_handle = tsk_object_ref(stack->getHandle()); - } - this->steps = tsk_list_create(); -} - - -XcapSelector* XcapSelector::setAUID(const char* auid) -{ - tsk_strupdate(&this->auid, auid); - return this; -} - -XcapSelector* XcapSelector::setName(const char* qname) -{ - twrap_xcap_step_t* step; - if((step = twrap_xcap_step_create(txst_name))) { - step->qname = tsk_strdup(qname); - tsk_list_push_back_data(this->steps, (void**)&step); - } - return this; -} - -XcapSelector* XcapSelector::setAttribute(const char* qname, const char* att_qname, const char* att_value) -{ - twrap_xcap_step_t* step; - if((step = twrap_xcap_step_create(txst_att))) { - step->qname = tsk_strdup(qname); - step->att_qname = tsk_strdup(att_qname); - step->att_value = tsk_strdup(att_value); - tsk_list_push_back_data(this->steps, (void**)&step); - } - return this; -} - -XcapSelector* XcapSelector::setPos(const char* qname, unsigned pos) -{ - twrap_xcap_step_t* step; - if((step = twrap_xcap_step_create(txst_pos))) { - step->qname = tsk_strdup(qname); - step->pos = pos; - tsk_list_push_back_data(this->steps, (void**)&step); - } - return this; -} - -XcapSelector* XcapSelector::setPosAttribute(const char* qname, unsigned pos, const char* att_qname, const char* att_value) -{ - twrap_xcap_step_t* step; - if((step = twrap_xcap_step_create(txst_pos))) { - step->qname = tsk_strdup(qname); - step->pos = pos; - step->att_qname = tsk_strdup(att_qname); - step->att_value = tsk_strdup(att_value); - tsk_list_push_back_data(this->steps, (void**)&step); - } - return this; -} - -XcapSelector* XcapSelector::setNamespace(const char* prefix, const char* value) -{ - twrap_xcap_step_t* step; - if((step = twrap_xcap_step_create(txst_ns))) { - step->ns.prefix = tsk_strdup(prefix); - step->ns.value = tsk_strdup(value); - tsk_list_push_back_data(this->steps, (void**)&step); - } - return this; -} - -/* From tinyXCAP::txcap_selector_get_node_2() */ -char* XcapSelector::getString() -{ - char* node = tsk_null; - char* temp = tsk_null; - char* _namespace = tsk_null; - tsk_buffer_t* buffer = tsk_buffer_create_null(); - const tsk_list_item_t* item; - const twrap_xcap_step_t* step; - - /* Node */ - tsk_list_foreach(item, this->steps) { - step = (twrap_xcap_step_t*)item->data; - switch(step->type) { - case txst_name: - if(tsk_buffer_append_2(buffer, "/%s", step->qname)) { - goto bail; - } - break; - - case txst_pos: - tsk_buffer_append_2(buffer, "/%s%%5B%u%%5D", - step->att_qname, step->pos); - break; - - case txst_att: - tsk_buffer_append_2(buffer, "/%s%%5B@%s=%%22%s%%22%%5D", - step->qname, step->att_qname, step->att_value); - break; - - case txst_pos_n_att: - tsk_buffer_append_2(buffer, "/%s%%5B%u%%5D%%5B@%s=%%22%s%%22%%5D", - step->qname, step->pos, step->att_qname, step->att_value); - break; - - case txst_ns: - tsk_sprintf(&temp, "%sxmlns(%s=%%22%s%%22)", - _namespace?"":"%3F", step->ns.prefix, step->ns.value); - tsk_strcat(&_namespace, temp); - TSK_FREE(temp); - break; - - - } /* switch */ - } /* for */ - - /* append the namespace */ - if(_namespace) { - tsk_buffer_append(buffer, _namespace, (tsk_size_t)tsk_strlen(_namespace)); - TSK_FREE(_namespace); - } - -bail: - if(TSK_BUFFER_DATA(buffer) && TSK_BUFFER_SIZE(buffer)) { - node = tsk_strndup((const char*)TSK_BUFFER_DATA(buffer), TSK_BUFFER_SIZE(buffer)); - } - TSK_OBJECT_SAFE_FREE(buffer); - - - /* Document */ - if(this->auid) { - char* document; - if((document = txcap_selector_get_document(this->stack_handle, this->auid))) { - if(node) { - tsk_strcat_2(&document, "/~~/%s%s", this->auid, node); - TSK_FREE(node); - } - return document; - } - } - - return node; -} - -void XcapSelector::reset() -{ - TSK_FREE(this->auid); - tsk_list_clear_items(this->steps); -} - -XcapSelector::~XcapSelector() -{ - this->reset(); - TSK_OBJECT_SAFE_FREE(this->steps); - - tsk_object_unref(this->stack_handle); -} - -/* =================================== XCAP Message ==================================== */ -XcapMessage::XcapMessage() : - httpmessage(tsk_null) -{ -} - -XcapMessage::XcapMessage(const thttp_message_t *_httpmessage) -{ - this->httpmessage = _httpmessage; -} - -XcapMessage::~XcapMessage() -{ -} - -short XcapMessage::getCode() const -{ - if(this->httpmessage) { - return this->httpmessage->line.response.status_code; - } - return 0; -} - -const char* XcapMessage::getPhrase() const -{ - if(this->httpmessage) { - return this->httpmessage->line.response.reason_phrase; - } - return tsk_null; -} - -char* XcapMessage::getXcapHeaderValue(const char* name, unsigned index /*= 0*/) -{ - const thttp_header_t* header; - if((header = thttp_message_get_headerByName(this->httpmessage, name))) { - return thttp_header_value_tostring(header); - } - return tsk_null; -} - -char* XcapMessage::getXcapHeaderParamValue(const char* name, const char* pname, unsigned index /*= 0*/) -{ - const thttp_header_t* header; - if((header = thttp_message_get_headerByName(this->httpmessage, name))) { - const tsk_param_t* param; - if((param = tsk_params_get_param_by_name(header->params, pname))) { - return tsk_strdup(param->value); - } - } - return tsk_null; -} - -unsigned XcapMessage::getXcapContentLength() -{ - if(this->httpmessage && this->httpmessage->Content) { - return this->httpmessage->Content->size; - } - return 0; -} - -unsigned XcapMessage::getXcapContent(void* output, unsigned maxsize) -{ - unsigned retsize = 0; - if(output && maxsize && this->httpmessage->Content) { - retsize = (this->httpmessage->Content->size > maxsize) ? maxsize : this->httpmessage->Content->size; - memcpy(output, this->httpmessage->Content->data, retsize); - } - return retsize; -} - - -/* =================================== XCAP Event ==================================== */ -XcapEvent::XcapEvent(const thttp_event_t *_httpevent) -{ - this->httpevent = _httpevent; - if(_httpevent) { - this->httpmessage = new XcapMessage(_httpevent->message); - } - else { - this->httpmessage = tsk_null; - } -} - -XcapEvent::~XcapEvent() -{ - if(this->httpmessage) { - delete this->httpmessage; - } -} - -thttp_event_type_t XcapEvent::getType() -{ - return this->httpevent->type; -} - -const XcapMessage* XcapEvent::getXcapMessage() const -{ - return this->httpmessage; -} - - - - -/* =================================== XCAP Callback ==================================== */ -XcapCallback::XcapCallback() -{ -} - -XcapCallback::~XcapCallback() -{ -} - - - - - -/* =================================== XCAP Stack ==================================== */ -XcapStack::XcapStack(XcapCallback* _callback, const char* xui, const char* password, const char* xcap_root) -{ - /* Initialize network layer */ - if(XcapStack::count == 0) { - tnet_startup(); - } - - this->callback = _callback; - this->handle = txcap_stack_create(stack_callback, xui, password, xcap_root, - TXCAP_STACK_SET_USERDATA(this), - TXCAP_STACK_SET_NULL()); -} - -XcapStack::~XcapStack() -{ - TSK_OBJECT_SAFE_FREE(this->handle); - - /* DeInitialize the network layer (only if last stack) */ - if(--XcapStack::count == 0) { - tnet_cleanup(); - } -} - -bool XcapStack::registerAUID(const char* id, const char* mime_type, const char* ns, const char* document_name, bool is_global) -{ - txcap_stack_t* stack = (txcap_stack_t*)this->handle; - if(stack) { - tsk_bool_t _global = is_global?tsk_true:tsk_false; // 32bit <-> 64bit workaround - return (txcap_auid_register(stack->auids, id, mime_type, ns, document_name, _global) == 0); - } - return false; -} - -bool XcapStack::start() -{ - return (txcap_stack_start(this->handle) == 0); -} - -bool XcapStack::setCredentials(const char* xui, const char* password) -{ - return txcap_stack_set(this->handle, - TXCAP_STACK_SET_XUI(xui), - TXCAP_STACK_SET_PASSWORD(password), - TXCAP_STACK_SET_NULL()) == 0; -} - -bool XcapStack::setXcapRoot(const char* xcap_root) -{ - return txcap_stack_set(this->handle, - TXCAP_STACK_SET_ROOT(xcap_root), - TXCAP_STACK_SET_NULL()) == 0; -} - -bool XcapStack::setLocalIP(const char* ip) -{ - return txcap_stack_set(this->handle, - TXCAP_STACK_SET_LOCAL_IP(ip), - TXCAP_STACK_SET_NULL()) == 0; -} - -bool XcapStack::setLocalPort(unsigned port) -{ - tsk_istr_t port_str; - tsk_itoa(port, &port_str); - return txcap_stack_set(this->handle, - TXCAP_STACK_SET_LOCAL_PORT(port_str), - TXCAP_STACK_SET_NULL()) == 0; -} - -bool XcapStack::addHeader(const char* name, const char* value) -{ - return txcap_stack_set(this->handle, - TXCAP_STACK_SET_HEADER(name, value), - TXCAP_STACK_SET_NULL()) == 0; -} - -bool XcapStack::removeHeader(const char* name) -{ - return txcap_stack_set(this->handle, - TXCAP_STACK_UNSET_HEADER(name), - TXCAP_STACK_SET_NULL()) == 0; -} - -bool XcapStack::setTimeout(unsigned timeout) -{ - tsk_istr_t timeout_str; - tsk_itoa(timeout, &timeout_str); - return txcap_stack_set(this->handle, - TXCAP_STACK_SET_TIMEOUT(timeout_str), - TXCAP_STACK_SET_NULL()) == 0; -} - -bool XcapStack::getDocument(const char* url) -{ - return txcap_action_fetch_document(this->handle, - TXCAP_ACTION_SET_REQUEST_URI(url), - TXCAP_ACTION_SET_NULL()) == 0; -} - -bool XcapStack::getElement(const char* url) -{ - return txcap_action_fetch_element(this->handle, - TXCAP_ACTION_SET_REQUEST_URI(url), - TXCAP_ACTION_SET_NULL()) == 0; -} - -bool XcapStack::getAttribute(const char* url) -{ - return txcap_action_fetch_attribute(this->handle, - TXCAP_ACTION_SET_REQUEST_URI(url), - TXCAP_ACTION_SET_NULL()) == 0; -} - -bool XcapStack::deleteDocument(const char* url) -{ - return txcap_action_delete_document(this->handle, - TXCAP_ACTION_SET_REQUEST_URI(url), - TXCAP_ACTION_SET_NULL()) == 0; -} - -bool XcapStack::deleteElement(const char* url) -{ - return txcap_action_delete_element(this->handle, - TXCAP_ACTION_SET_REQUEST_URI(url), - TXCAP_ACTION_SET_NULL()) == 0; -} - -bool XcapStack::deleteAttribute(const char* url) -{ - return txcap_action_delete_attribute(this->handle, - TXCAP_ACTION_SET_REQUEST_URI(url), - TXCAP_ACTION_SET_NULL()) == 0; -} - - -bool XcapStack::putDocument(const char* url, const void* payload, unsigned len, const char* contentType) -{ - return txcap_action_create_document(this->handle, - TXCAP_ACTION_SET_REQUEST_URI(url), - TXCAP_ACTION_SET_PAYLOAD(payload, len), - TXCAP_ACTION_SET_HEADER("Content-Type", contentType), - TXCAP_ACTION_SET_NULL()) == 0; -} - -bool XcapStack::putElement(const char* url, const void* payload, unsigned len) -{ - return txcap_action_create_element(this->handle, - TXCAP_ACTION_SET_REQUEST_URI(url), - TXCAP_ACTION_SET_PAYLOAD(payload, len), - TXCAP_ACTION_SET_NULL()) == 0; -} - -bool XcapStack::putAttribute(const char* url, const void* payload, unsigned len) -{ - return txcap_action_create_attribute(this->handle, - TXCAP_ACTION_SET_REQUEST_URI(url), - TXCAP_ACTION_SET_PAYLOAD(payload, len), - TXCAP_ACTION_SET_NULL()) == 0; -} - - -bool XcapStack::stop() -{ - return (txcap_stack_stop(this->handle) == 0); -} - - -int stack_callback(const thttp_event_t *httpevent) -{ - const XcapStack* stack = tsk_null; - XcapEvent* e = tsk_null; - - const txcap_stack_handle_t* stack_handle = thttp_session_get_userdata(httpevent->session); - if(!stack_handle || !(stack = dyn_cast<const XcapStack*>((const XcapStack*)stack_handle))) { - TSK_DEBUG_ERROR("Invalid user data"); - return -1; - } - - if(stack->getCallback()) { - if((e = new XcapEvent(httpevent))) { - stack->getCallback()->onEvent(e); - delete e; - } - } - return 0; -} - - - +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#include "Xcap.h"
+
+#include "Common.h"
+
+unsigned XcapStack::count = 0;
+
+/* === ANSI-C functions (local use) === */
+static int stack_callback(const thttp_event_t *httpevent);
+
+/* =================================== XCAP Event ==================================== */
+typedef enum twrap_xcap_step_type_e {
+ txst_name,
+ txst_pos,
+ txst_att,
+ txst_pos_n_att,
+ txst_ns
+}
+twrap_xcap_step_type_t;
+
+typedef struct twrap_xcap_step_s {
+ TSK_DECLARE_OBJECT;
+
+ twrap_xcap_step_type_t type;
+ char* qname;
+ char* att_qname;
+ char* att_value;
+ unsigned pos;
+ struct {
+ char* prefix;
+ char* value;
+ } ns;
+}
+twrap_xcap_step_t;
+
+static tsk_object_t* twrap_xcap_step_ctor(tsk_object_t * self, va_list * app)
+{
+ twrap_xcap_step_t *step = (twrap_xcap_step_t *)self;
+ if(step) {
+ }
+ return self;
+}
+
+static tsk_object_t* twrap_xcap_step_dtor(tsk_object_t * self)
+{
+ twrap_xcap_step_t *step = (twrap_xcap_step_t *)self;
+ if(step) {
+ TSK_FREE(step->qname);
+ TSK_FREE(step->att_qname);
+ TSK_FREE(step->att_value);
+ TSK_FREE(step->ns.prefix);
+ TSK_FREE(step->ns.value);
+ }
+
+ return self;
+}
+
+static const tsk_object_def_t twrap_xcap_step_def_s = {
+ sizeof(twrap_xcap_step_t),
+ twrap_xcap_step_ctor,
+ twrap_xcap_step_dtor,
+ tsk_null,
+};
+const tsk_object_def_t *twrap_xcap_step_def_t = &twrap_xcap_step_def_s;
+
+twrap_xcap_step_t* twrap_xcap_step_create(twrap_xcap_step_type_t type)
+{
+ twrap_xcap_step_t* step;
+ if((step = (twrap_xcap_step_t*)tsk_object_new(twrap_xcap_step_def_t))) {
+ step->type = type;
+ }
+ return step;
+}
+
+XcapSelector::XcapSelector(XcapStack* stack)
+ : auid(tsk_null)
+{
+ if(stack) {
+ this->stack_handle = tsk_object_ref(stack->getHandle());
+ }
+ this->steps = tsk_list_create();
+}
+
+
+XcapSelector* XcapSelector::setAUID(const char* auid)
+{
+ tsk_strupdate(&this->auid, auid);
+ return this;
+}
+
+XcapSelector* XcapSelector::setName(const char* qname)
+{
+ twrap_xcap_step_t* step;
+ if((step = twrap_xcap_step_create(txst_name))) {
+ step->qname = tsk_strdup(qname);
+ tsk_list_push_back_data(this->steps, (void**)&step);
+ }
+ return this;
+}
+
+XcapSelector* XcapSelector::setAttribute(const char* qname, const char* att_qname, const char* att_value)
+{
+ twrap_xcap_step_t* step;
+ if((step = twrap_xcap_step_create(txst_att))) {
+ step->qname = tsk_strdup(qname);
+ step->att_qname = tsk_strdup(att_qname);
+ step->att_value = tsk_strdup(att_value);
+ tsk_list_push_back_data(this->steps, (void**)&step);
+ }
+ return this;
+}
+
+XcapSelector* XcapSelector::setPos(const char* qname, unsigned pos)
+{
+ twrap_xcap_step_t* step;
+ if((step = twrap_xcap_step_create(txst_pos))) {
+ step->qname = tsk_strdup(qname);
+ step->pos = pos;
+ tsk_list_push_back_data(this->steps, (void**)&step);
+ }
+ return this;
+}
+
+XcapSelector* XcapSelector::setPosAttribute(const char* qname, unsigned pos, const char* att_qname, const char* att_value)
+{
+ twrap_xcap_step_t* step;
+ if((step = twrap_xcap_step_create(txst_pos))) {
+ step->qname = tsk_strdup(qname);
+ step->pos = pos;
+ step->att_qname = tsk_strdup(att_qname);
+ step->att_value = tsk_strdup(att_value);
+ tsk_list_push_back_data(this->steps, (void**)&step);
+ }
+ return this;
+}
+
+XcapSelector* XcapSelector::setNamespace(const char* prefix, const char* value)
+{
+ twrap_xcap_step_t* step;
+ if((step = twrap_xcap_step_create(txst_ns))) {
+ step->ns.prefix = tsk_strdup(prefix);
+ step->ns.value = tsk_strdup(value);
+ tsk_list_push_back_data(this->steps, (void**)&step);
+ }
+ return this;
+}
+
+/* From tinyXCAP::txcap_selector_get_node_2() */
+char* XcapSelector::getString()
+{
+ char* node = tsk_null;
+ char* temp = tsk_null;
+ char* _namespace = tsk_null;
+ tsk_buffer_t* buffer = tsk_buffer_create_null();
+ const tsk_list_item_t* item;
+ const twrap_xcap_step_t* step;
+
+ /* Node */
+ tsk_list_foreach(item, this->steps) {
+ step = (twrap_xcap_step_t*)item->data;
+ switch(step->type) {
+ case txst_name:
+ if(tsk_buffer_append_2(buffer, "/%s", step->qname)) {
+ goto bail;
+ }
+ break;
+
+ case txst_pos:
+ tsk_buffer_append_2(buffer, "/%s%%5B%u%%5D",
+ step->att_qname, step->pos);
+ break;
+
+ case txst_att:
+ tsk_buffer_append_2(buffer, "/%s%%5B@%s=%%22%s%%22%%5D",
+ step->qname, step->att_qname, step->att_value);
+ break;
+
+ case txst_pos_n_att:
+ tsk_buffer_append_2(buffer, "/%s%%5B%u%%5D%%5B@%s=%%22%s%%22%%5D",
+ step->qname, step->pos, step->att_qname, step->att_value);
+ break;
+
+ case txst_ns:
+ tsk_sprintf(&temp, "%sxmlns(%s=%%22%s%%22)",
+ _namespace?"":"%3F", step->ns.prefix, step->ns.value);
+ tsk_strcat(&_namespace, temp);
+ TSK_FREE(temp);
+ break;
+
+
+ } /* switch */
+ } /* for */
+
+ /* append the namespace */
+ if(_namespace) {
+ tsk_buffer_append(buffer, _namespace, (tsk_size_t)tsk_strlen(_namespace));
+ TSK_FREE(_namespace);
+ }
+
+bail:
+ if(TSK_BUFFER_DATA(buffer) && TSK_BUFFER_SIZE(buffer)) {
+ node = tsk_strndup((const char*)TSK_BUFFER_DATA(buffer), TSK_BUFFER_SIZE(buffer));
+ }
+ TSK_OBJECT_SAFE_FREE(buffer);
+
+
+ /* Document */
+ if(this->auid) {
+ char* document;
+ if((document = txcap_selector_get_document(this->stack_handle, this->auid))) {
+ if(node) {
+ tsk_strcat_2(&document, "/~~/%s%s", this->auid, node);
+ TSK_FREE(node);
+ }
+ return document;
+ }
+ }
+
+ return node;
+}
+
+void XcapSelector::reset()
+{
+ TSK_FREE(this->auid);
+ tsk_list_clear_items(this->steps);
+}
+
+XcapSelector::~XcapSelector()
+{
+ this->reset();
+ TSK_OBJECT_SAFE_FREE(this->steps);
+
+ tsk_object_unref(this->stack_handle);
+}
+
+/* =================================== XCAP Message ==================================== */
+XcapMessage::XcapMessage() :
+ httpmessage(tsk_null)
+{
+}
+
+XcapMessage::XcapMessage(const thttp_message_t *_httpmessage)
+{
+ this->httpmessage = _httpmessage;
+}
+
+XcapMessage::~XcapMessage()
+{
+}
+
+short XcapMessage::getCode() const
+{
+ if(this->httpmessage) {
+ return this->httpmessage->line.response.status_code;
+ }
+ return 0;
+}
+
+const char* XcapMessage::getPhrase() const
+{
+ if(this->httpmessage) {
+ return this->httpmessage->line.response.reason_phrase;
+ }
+ return tsk_null;
+}
+
+char* XcapMessage::getXcapHeaderValue(const char* name, unsigned index /*= 0*/)
+{
+ const thttp_header_t* header;
+ if((header = thttp_message_get_headerByName(this->httpmessage, name))) {
+ return thttp_header_value_tostring(header);
+ }
+ return tsk_null;
+}
+
+char* XcapMessage::getXcapHeaderParamValue(const char* name, const char* pname, unsigned index /*= 0*/)
+{
+ const thttp_header_t* header;
+ if((header = thttp_message_get_headerByName(this->httpmessage, name))) {
+ const tsk_param_t* param;
+ if((param = tsk_params_get_param_by_name(header->params, pname))) {
+ return tsk_strdup(param->value);
+ }
+ }
+ return tsk_null;
+}
+
+unsigned XcapMessage::getXcapContentLength()
+{
+ if(this->httpmessage && this->httpmessage->Content) {
+ return this->httpmessage->Content->size;
+ }
+ return 0;
+}
+
+unsigned XcapMessage::getXcapContent(void* output, unsigned maxsize)
+{
+ unsigned retsize = 0;
+ if(output && maxsize && this->httpmessage->Content) {
+ retsize = (this->httpmessage->Content->size > maxsize) ? maxsize : this->httpmessage->Content->size;
+ memcpy(output, this->httpmessage->Content->data, retsize);
+ }
+ return retsize;
+}
+
+
+/* =================================== XCAP Event ==================================== */
+XcapEvent::XcapEvent(const thttp_event_t *_httpevent)
+{
+ this->httpevent = _httpevent;
+ if(_httpevent) {
+ this->httpmessage = new XcapMessage(_httpevent->message);
+ }
+ else {
+ this->httpmessage = tsk_null;
+ }
+}
+
+XcapEvent::~XcapEvent()
+{
+ if(this->httpmessage) {
+ delete this->httpmessage;
+ }
+}
+
+thttp_event_type_t XcapEvent::getType()
+{
+ return this->httpevent->type;
+}
+
+const XcapMessage* XcapEvent::getXcapMessage() const
+{
+ return this->httpmessage;
+}
+
+
+
+
+/* =================================== XCAP Callback ==================================== */
+XcapCallback::XcapCallback()
+{
+}
+
+XcapCallback::~XcapCallback()
+{
+}
+
+
+
+
+
+/* =================================== XCAP Stack ==================================== */
+XcapStack::XcapStack(XcapCallback* _callback, const char* xui, const char* password, const char* xcap_root)
+{
+ /* Initialize network layer */
+ if(XcapStack::count == 0) {
+ tnet_startup();
+ }
+
+ this->callback = _callback;
+ this->handle = txcap_stack_create(stack_callback, xui, password, xcap_root,
+ TXCAP_STACK_SET_USERDATA(this),
+ TXCAP_STACK_SET_NULL());
+}
+
+XcapStack::~XcapStack()
+{
+ TSK_OBJECT_SAFE_FREE(this->handle);
+
+ /* DeInitialize the network layer (only if last stack) */
+ if(--XcapStack::count == 0) {
+ tnet_cleanup();
+ }
+}
+
+bool XcapStack::registerAUID(const char* id, const char* mime_type, const char* ns, const char* document_name, bool is_global)
+{
+ txcap_stack_t* stack = (txcap_stack_t*)this->handle;
+ if(stack) {
+ tsk_bool_t _global = is_global?tsk_true:tsk_false; // 32bit <-> 64bit workaround
+ return (txcap_auid_register(stack->auids, id, mime_type, ns, document_name, _global) == 0);
+ }
+ return false;
+}
+
+bool XcapStack::start()
+{
+ return (txcap_stack_start(this->handle) == 0);
+}
+
+bool XcapStack::setCredentials(const char* xui, const char* password)
+{
+ return txcap_stack_set(this->handle,
+ TXCAP_STACK_SET_XUI(xui),
+ TXCAP_STACK_SET_PASSWORD(password),
+ TXCAP_STACK_SET_NULL()) == 0;
+}
+
+bool XcapStack::setXcapRoot(const char* xcap_root)
+{
+ return txcap_stack_set(this->handle,
+ TXCAP_STACK_SET_ROOT(xcap_root),
+ TXCAP_STACK_SET_NULL()) == 0;
+}
+
+bool XcapStack::setLocalIP(const char* ip)
+{
+ return txcap_stack_set(this->handle,
+ TXCAP_STACK_SET_LOCAL_IP(ip),
+ TXCAP_STACK_SET_NULL()) == 0;
+}
+
+bool XcapStack::setLocalPort(unsigned port)
+{
+ tsk_istr_t port_str;
+ tsk_itoa(port, &port_str);
+ return txcap_stack_set(this->handle,
+ TXCAP_STACK_SET_LOCAL_PORT(port_str),
+ TXCAP_STACK_SET_NULL()) == 0;
+}
+
+bool XcapStack::addHeader(const char* name, const char* value)
+{
+ return txcap_stack_set(this->handle,
+ TXCAP_STACK_SET_HEADER(name, value),
+ TXCAP_STACK_SET_NULL()) == 0;
+}
+
+bool XcapStack::removeHeader(const char* name)
+{
+ return txcap_stack_set(this->handle,
+ TXCAP_STACK_UNSET_HEADER(name),
+ TXCAP_STACK_SET_NULL()) == 0;
+}
+
+bool XcapStack::setTimeout(unsigned timeout)
+{
+ tsk_istr_t timeout_str;
+ tsk_itoa(timeout, &timeout_str);
+ return txcap_stack_set(this->handle,
+ TXCAP_STACK_SET_TIMEOUT(timeout_str),
+ TXCAP_STACK_SET_NULL()) == 0;
+}
+
+bool XcapStack::getDocument(const char* url)
+{
+ return txcap_action_fetch_document(this->handle,
+ TXCAP_ACTION_SET_REQUEST_URI(url),
+ TXCAP_ACTION_SET_NULL()) == 0;
+}
+
+bool XcapStack::getElement(const char* url)
+{
+ return txcap_action_fetch_element(this->handle,
+ TXCAP_ACTION_SET_REQUEST_URI(url),
+ TXCAP_ACTION_SET_NULL()) == 0;
+}
+
+bool XcapStack::getAttribute(const char* url)
+{
+ return txcap_action_fetch_attribute(this->handle,
+ TXCAP_ACTION_SET_REQUEST_URI(url),
+ TXCAP_ACTION_SET_NULL()) == 0;
+}
+
+bool XcapStack::deleteDocument(const char* url)
+{
+ return txcap_action_delete_document(this->handle,
+ TXCAP_ACTION_SET_REQUEST_URI(url),
+ TXCAP_ACTION_SET_NULL()) == 0;
+}
+
+bool XcapStack::deleteElement(const char* url)
+{
+ return txcap_action_delete_element(this->handle,
+ TXCAP_ACTION_SET_REQUEST_URI(url),
+ TXCAP_ACTION_SET_NULL()) == 0;
+}
+
+bool XcapStack::deleteAttribute(const char* url)
+{
+ return txcap_action_delete_attribute(this->handle,
+ TXCAP_ACTION_SET_REQUEST_URI(url),
+ TXCAP_ACTION_SET_NULL()) == 0;
+}
+
+
+bool XcapStack::putDocument(const char* url, const void* payload, unsigned len, const char* contentType)
+{
+ return txcap_action_create_document(this->handle,
+ TXCAP_ACTION_SET_REQUEST_URI(url),
+ TXCAP_ACTION_SET_PAYLOAD(payload, len),
+ TXCAP_ACTION_SET_HEADER("Content-Type", contentType),
+ TXCAP_ACTION_SET_NULL()) == 0;
+}
+
+bool XcapStack::putElement(const char* url, const void* payload, unsigned len)
+{
+ return txcap_action_create_element(this->handle,
+ TXCAP_ACTION_SET_REQUEST_URI(url),
+ TXCAP_ACTION_SET_PAYLOAD(payload, len),
+ TXCAP_ACTION_SET_NULL()) == 0;
+}
+
+bool XcapStack::putAttribute(const char* url, const void* payload, unsigned len)
+{
+ return txcap_action_create_attribute(this->handle,
+ TXCAP_ACTION_SET_REQUEST_URI(url),
+ TXCAP_ACTION_SET_PAYLOAD(payload, len),
+ TXCAP_ACTION_SET_NULL()) == 0;
+}
+
+
+bool XcapStack::stop()
+{
+ return (txcap_stack_stop(this->handle) == 0);
+}
+
+
+int stack_callback(const thttp_event_t *httpevent)
+{
+ const XcapStack* stack = tsk_null;
+ XcapEvent* e = tsk_null;
+
+ const txcap_stack_handle_t* stack_handle = thttp_session_get_userdata(httpevent->session);
+ if(!stack_handle || !(stack = dyn_cast<const XcapStack*>((const XcapStack*)stack_handle))) {
+ TSK_DEBUG_ERROR("Invalid user data");
+ return -1;
+ }
+
+ if(stack->getCallback()) {
+ if((e = new XcapEvent(httpevent))) {
+ stack->getCallback()->onEvent(e);
+ delete e;
+ }
+ }
+ return 0;
+}
+
+
+
diff --git a/bindings/_common/Xcap.h b/bindings/_common/Xcap.h index 59376d6..733ddab 100755 --- a/bindings/_common/Xcap.h +++ b/bindings/_common/Xcap.h @@ -1,167 +1,167 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ -#ifndef TINYWRAP_XCAP_H -#define TINYWRAP_XCAP_H - -#include "tinyxcap.h" - -class XcapStack; - -typedef tsk_list_t twrap_xcap_steps_L_t; - -// -// XcapSelector -// -class XcapSelector -{ -public: - XcapSelector(XcapStack* stack); - virtual ~XcapSelector(); - -public: /* API functions */ - XcapSelector* setAUID(const char* auid); - XcapSelector* setName(const char* qname); - XcapSelector* setAttribute(const char* qname, const char* att_qname, const char* att_value); - XcapSelector* setPos(const char* qname, unsigned pos); - XcapSelector* setPosAttribute(const char* qname, unsigned pos, const char* att_qname, const char* att_value); - XcapSelector* setNamespace(const char* prefix, const char* value); - - char* getString();// %newobject - void reset(); - -private: - txcap_stack_handle_t* stack_handle; - char* auid; - twrap_xcap_steps_L_t* steps; -}; - -// -// XcapMessage -// -class XcapMessage -{ -public: - XcapMessage(); -#if !defined(SWIG) - XcapMessage(const thttp_message_t *httpmessage); -#endif - virtual ~XcapMessage(); - - short getCode() const; - const char* getPhrase() const; - - char* getXcapHeaderValue(const char* name, unsigned index = 0); - char* getXcapHeaderParamValue(const char* name, const char* param, unsigned index = 0); - unsigned getXcapContentLength(); - unsigned getXcapContent(void* output, unsigned maxsize); - -private: - const thttp_message_t *httpmessage; -}; - -// -// XcapEvent -// -class XcapEvent -{ -public: -#if !defined(SWIG) - XcapEvent(const thttp_event_t *httpevent); -#endif - virtual ~XcapEvent(); - thttp_event_type_t getType(); - const XcapMessage* getXcapMessage() const; - -private: - const thttp_event_t *httpevent; - const XcapMessage* httpmessage; -}; - - -// -// XcapCallback -// -class XcapCallback -{ -public: - XcapCallback(); - virtual ~XcapCallback(); - - virtual int onEvent(const XcapEvent* e)const { - return -1; - } -}; - - -// -// XcapStack -// -class XcapStack -{ -public: - XcapStack(XcapCallback* callback, const char* xui, const char* password, const char* xcap_root); - virtual ~XcapStack(); - -public: /* API functions */ - bool registerAUID(const char* id, const char* mime_type, const char* ns, const char* document_name, bool is_global); - bool start(); - bool setCredentials(const char* xui, const char* password); - bool setXcapRoot(const char* xcap_root); - bool setLocalIP(const char* ip); - bool setLocalPort(unsigned port); - bool addHeader(const char* name, const char* value); - bool removeHeader(const char* name); - bool setTimeout(unsigned timeout); - - bool getDocument(const char* url); - bool getElement(const char* url); - bool getAttribute(const char* url); - - bool deleteDocument(const char* url); - bool deleteElement(const char* url); - bool deleteAttribute(const char* url); - - bool putDocument(const char* url, const void* payload, unsigned len, const char* contentType); - bool putElement(const char* url, const void* payload, unsigned len); - bool putAttribute(const char* url, const void* payload, unsigned len); - - bool stop(); - -public: /* Public helper function */ -#if !defined(SWIG) - txcap_stack_handle_t* getHandle() { - return this->handle; - } - XcapCallback* getCallback()const { - return this->callback; - } -#endif - -private: - txcap_stack_handle_t* handle; - XcapCallback* callback; - - static unsigned count; -}; - - -#endif /* TINYWRAP_XCAP_H */ +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef TINYWRAP_XCAP_H
+#define TINYWRAP_XCAP_H
+
+#include "tinyxcap.h"
+
+class XcapStack;
+
+typedef tsk_list_t twrap_xcap_steps_L_t;
+
+//
+// XcapSelector
+//
+class XcapSelector
+{
+public:
+ XcapSelector(XcapStack* stack);
+ virtual ~XcapSelector();
+
+public: /* API functions */
+ XcapSelector* setAUID(const char* auid);
+ XcapSelector* setName(const char* qname);
+ XcapSelector* setAttribute(const char* qname, const char* att_qname, const char* att_value);
+ XcapSelector* setPos(const char* qname, unsigned pos);
+ XcapSelector* setPosAttribute(const char* qname, unsigned pos, const char* att_qname, const char* att_value);
+ XcapSelector* setNamespace(const char* prefix, const char* value);
+
+ char* getString();// %newobject
+ void reset();
+
+private:
+ txcap_stack_handle_t* stack_handle;
+ char* auid;
+ twrap_xcap_steps_L_t* steps;
+};
+
+//
+// XcapMessage
+//
+class XcapMessage
+{
+public:
+ XcapMessage();
+#if !defined(SWIG)
+ XcapMessage(const thttp_message_t *httpmessage);
+#endif
+ virtual ~XcapMessage();
+
+ short getCode() const;
+ const char* getPhrase() const;
+
+ char* getXcapHeaderValue(const char* name, unsigned index = 0);
+ char* getXcapHeaderParamValue(const char* name, const char* param, unsigned index = 0);
+ unsigned getXcapContentLength();
+ unsigned getXcapContent(void* output, unsigned maxsize);
+
+private:
+ const thttp_message_t *httpmessage;
+};
+
+//
+// XcapEvent
+//
+class XcapEvent
+{
+public:
+#if !defined(SWIG)
+ XcapEvent(const thttp_event_t *httpevent);
+#endif
+ virtual ~XcapEvent();
+ thttp_event_type_t getType();
+ const XcapMessage* getXcapMessage() const;
+
+private:
+ const thttp_event_t *httpevent;
+ const XcapMessage* httpmessage;
+};
+
+
+//
+// XcapCallback
+//
+class XcapCallback
+{
+public:
+ XcapCallback();
+ virtual ~XcapCallback();
+
+ virtual int onEvent(const XcapEvent* e)const {
+ return -1;
+ }
+};
+
+
+//
+// XcapStack
+//
+class XcapStack
+{
+public:
+ XcapStack(XcapCallback* callback, const char* xui, const char* password, const char* xcap_root);
+ virtual ~XcapStack();
+
+public: /* API functions */
+ bool registerAUID(const char* id, const char* mime_type, const char* ns, const char* document_name, bool is_global);
+ bool start();
+ bool setCredentials(const char* xui, const char* password);
+ bool setXcapRoot(const char* xcap_root);
+ bool setLocalIP(const char* ip);
+ bool setLocalPort(unsigned port);
+ bool addHeader(const char* name, const char* value);
+ bool removeHeader(const char* name);
+ bool setTimeout(unsigned timeout);
+
+ bool getDocument(const char* url);
+ bool getElement(const char* url);
+ bool getAttribute(const char* url);
+
+ bool deleteDocument(const char* url);
+ bool deleteElement(const char* url);
+ bool deleteAttribute(const char* url);
+
+ bool putDocument(const char* url, const void* payload, unsigned len, const char* contentType);
+ bool putElement(const char* url, const void* payload, unsigned len);
+ bool putAttribute(const char* url, const void* payload, unsigned len);
+
+ bool stop();
+
+public: /* Public helper function */
+#if !defined(SWIG)
+ txcap_stack_handle_t* getHandle() {
+ return this->handle;
+ }
+ XcapCallback* getCallback()const {
+ return this->callback;
+ }
+#endif
+
+private:
+ txcap_stack_handle_t* handle;
+ XcapCallback* callback;
+
+ static unsigned count;
+};
+
+
+#endif /* TINYWRAP_XCAP_H */
diff --git a/bindings/_common/Xcap.i b/bindings/_common/Xcap.i index 4280119..2c69147 100755 --- a/bindings/_common/Xcap.i +++ b/bindings/_common/Xcap.i @@ -1,22 +1,22 @@ -%{ -#include "Xcap.h" -%} - -/* Callbacks */ -%feature("director") XcapCallback; - - -%nodefaultctor; -%include "Xcap.h" -%clearnodefaultctor; - -typedef enum thttp_event_type_e -{ - thttp_event_dialog_started, - thttp_event_message, - thttp_event_auth_failed, - thttp_event_closed, - thttp_event_transport_error, - thttp_event_dialog_terminated -} +%{
+#include "Xcap.h"
+%}
+
+/* Callbacks */
+%feature("director") XcapCallback;
+
+
+%nodefaultctor;
+%include "Xcap.h"
+%clearnodefaultctor;
+
+typedef enum thttp_event_type_e
+{
+ thttp_event_dialog_started,
+ thttp_event_message,
+ thttp_event_auth_failed,
+ thttp_event_closed,
+ thttp_event_transport_error,
+ thttp_event_dialog_terminated
+}
thttp_event_type_t;
\ No newline at end of file diff --git a/bindings/_common/tinyWRAP.i b/bindings/_common/tinyWRAP.i index 25df7aa..057e294 100755 --- a/bindings/_common/tinyWRAP.i +++ b/bindings/_common/tinyWRAP.i @@ -1,73 +1,73 @@ -/* File : tinyWRAP.i */ -%module(directors="1") tinyWRAP -%include "typemaps.i" -%include <stdint.i> - -%{ -#include "tinyWRAP_config.h" -#include "DDebug.h" -#include "AudioResampler.h" -%} - -%feature("director") DDebugCallback; - -%nodefaultctor; -%include "tinyWRAP_config.h" -%include "DDebug.h" -%include "AudioResampler.h" -%include "Common.h" -%clearnodefaultctor; - - - - - -/* ========== Sip/Sdp Stack ========== */ -%newobject getSipHeaderValue; -%newobject getSdpHeaderValue; -%newobject getSdpHeaderAValue; -%newobject getSipHeaderParamValue; -%newobject SipStack::dnsENUM; -%newobject SipStack::dnsNaptrSrv; -%newobject SipStack::dnsSrv; -%newobject SipStack::getPreferredIdentity; -%newobject SipStack::getLocalIPnPort; -%newobject MediaSessionMgr::producerGetCodec; -%newobject MediaSessionMgr::sessionGetQoS; - -%newobject MessagingEvent::takeSessionOwnership; -%newobject InviteEvent::takeCallSessionOwnership; -%newobject InviteEvent::takeMsrpSessionOwnership; -%newobject RegistrationEvent::takeSessionOwnership; - -%newobject ProxyPluginMgr::createInstance; - -%newobject MediaContent::parse; - -%include SipStack.i - - -/* ========== Xcap Stack ========== */ -%newobject XcapSelector::getString; - -%newobject getXcapHeaderValue; -%newobject getXcapHeaderParamValue; - -%include Xcap.i - - -/* ========== SMS ========== */ -%newobject SMSEncoder::encodeSubmit; -%newobject SMSEncoder::encodeDeliver; -%newobject SMSEncoder::encodeACK; -%newobject SMSEncoder::encodeError; -%newobject SMSEncoder::decode; - -%include SMS.i - - -/* ========== MSRP ========== */ -%newobject getMsrpHeaderValue; -%newobject getMsrpHeaderParamValue; - -%include Msrp.i +/* File : tinyWRAP.i */
+%module(directors="1") tinyWRAP
+%include "typemaps.i"
+%include <stdint.i>
+
+%{
+#include "tinyWRAP_config.h"
+#include "DDebug.h"
+#include "AudioResampler.h"
+%}
+
+%feature("director") DDebugCallback;
+
+%nodefaultctor;
+%include "tinyWRAP_config.h"
+%include "DDebug.h"
+%include "AudioResampler.h"
+%include "Common.h"
+%clearnodefaultctor;
+
+
+
+
+
+/* ========== Sip/Sdp Stack ========== */
+%newobject getSipHeaderValue;
+%newobject getSdpHeaderValue;
+%newobject getSdpHeaderAValue;
+%newobject getSipHeaderParamValue;
+%newobject SipStack::dnsENUM;
+%newobject SipStack::dnsNaptrSrv;
+%newobject SipStack::dnsSrv;
+%newobject SipStack::getPreferredIdentity;
+%newobject SipStack::getLocalIPnPort;
+%newobject MediaSessionMgr::producerGetCodec;
+%newobject MediaSessionMgr::sessionGetQoS;
+
+%newobject MessagingEvent::takeSessionOwnership;
+%newobject InviteEvent::takeCallSessionOwnership;
+%newobject InviteEvent::takeMsrpSessionOwnership;
+%newobject RegistrationEvent::takeSessionOwnership;
+
+%newobject ProxyPluginMgr::createInstance;
+
+%newobject MediaContent::parse;
+
+%include SipStack.i
+
+
+/* ========== Xcap Stack ========== */
+%newobject XcapSelector::getString;
+
+%newobject getXcapHeaderValue;
+%newobject getXcapHeaderParamValue;
+
+%include Xcap.i
+
+
+/* ========== SMS ========== */
+%newobject SMSEncoder::encodeSubmit;
+%newobject SMSEncoder::encodeDeliver;
+%newobject SMSEncoder::encodeACK;
+%newobject SMSEncoder::encodeError;
+%newobject SMSEncoder::decode;
+
+%include SMS.i
+
+
+/* ========== MSRP ========== */
+%newobject getMsrpHeaderValue;
+%newobject getMsrpHeaderParamValue;
+
+%include Msrp.i
diff --git a/bindings/_common/tinyWRAP_config.h b/bindings/_common/tinyWRAP_config.h index 16fb4fd..98fa719 100755 --- a/bindings/_common/tinyWRAP_config.h +++ b/bindings/_common/tinyWRAP_config.h @@ -1,72 +1,72 @@ -/* -* Copyright (C) 2010-2011 Mamadou Diop. -* -* Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* -* This file is part of Open Source Doubango Framework. -* -* DOUBANGO is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* DOUBANGO is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with DOUBANGO. -* -*/ - -#ifndef TINYWRAP_CONFIG_H -#define TINYWRAP_CONFIG_H - -#ifdef __SYMBIAN32__ -#undef _WIN32 /* Because of WINSCW */ -#endif - -// Windows (XP/Vista/7/CE and Windows Mobile) macro definition. -#if defined(WIN32)|| defined(_WIN32) || defined(_WIN32_WCE) -# define TWRAP_UNDER_WINDOWS 1 -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP || WINAPI_FAMILY == WINAPI_FAMILY_APP) -# define TWRAP_UNDER_WINDOWS_RT 1 -# endif -#endif - -#if (TWRAP_UNDER_WINDOWS || defined(__SYMBIAN32__)) && defined(TINYWRAP_EXPORTS) -# define TINYWRAP_API __declspec(dllexport) -# define TINYWRAP_GEXTERN extern __declspec(dllexport) -#elif (TWRAP_UNDER_WINDOWS || defined(__SYMBIAN32__)) && !defined(TINYWRAP_IMPORTS_IGNORE) -# define TINYWRAP_API __declspec(dllimport) -# define TINYWRAP_GEXTERN __declspec(dllimport) -#else -# define TINYWRAP_API -# define TINYWRAP_GEXTERN extern -#endif - -/* Guards against C++ name mangling -*/ -#ifdef __cplusplus -# define TWRAP_BEGIN_DECLS extern "C" { -# define TWRAP_END_DECLS } -#else -# define TWRAP_BEGIN_DECLS -# define TWRAP_END_DECLS -#endif - -/* Disable some well-known warnings -*/ -#ifdef _MSC_VER -# define _CRT_SECURE_NO_WARNINGS -#endif - -#include <stdint.h> - - -#if HAVE_CONFIG_H -#include "../config.h" -#endif - -#endif // TINYWRAP_CONFIG_H +/*
+* Copyright (C) 2010-2011 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+#ifndef TINYWRAP_CONFIG_H
+#define TINYWRAP_CONFIG_H
+
+#ifdef __SYMBIAN32__
+#undef _WIN32 /* Because of WINSCW */
+#endif
+
+// Windows (XP/Vista/7/CE and Windows Mobile) macro definition.
+#if defined(WIN32)|| defined(_WIN32) || defined(_WIN32_WCE)
+# define TWRAP_UNDER_WINDOWS 1
+# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP || WINAPI_FAMILY == WINAPI_FAMILY_APP)
+# define TWRAP_UNDER_WINDOWS_RT 1
+# endif
+#endif
+
+#if (TWRAP_UNDER_WINDOWS || defined(__SYMBIAN32__)) && defined(TINYWRAP_EXPORTS)
+# define TINYWRAP_API __declspec(dllexport)
+# define TINYWRAP_GEXTERN extern __declspec(dllexport)
+#elif (TWRAP_UNDER_WINDOWS || defined(__SYMBIAN32__)) && !defined(TINYWRAP_IMPORTS_IGNORE)
+# define TINYWRAP_API __declspec(dllimport)
+# define TINYWRAP_GEXTERN __declspec(dllimport)
+#else
+# define TINYWRAP_API
+# define TINYWRAP_GEXTERN extern
+#endif
+
+/* Guards against C++ name mangling
+*/
+#ifdef __cplusplus
+# define TWRAP_BEGIN_DECLS extern "C" {
+# define TWRAP_END_DECLS }
+#else
+# define TWRAP_BEGIN_DECLS
+# define TWRAP_END_DECLS
+#endif
+
+/* Disable some well-known warnings
+*/
+#ifdef _MSC_VER
+# define _CRT_SECURE_NO_WARNINGS
+#endif
+
+#include <stdint.h>
+
+
+#if HAVE_CONFIG_H
+#include "../config.h"
+#endif
+
+#endif // TINYWRAP_CONFIG_H
diff --git a/bindings/csharp/QoS.cs b/bindings/csharp/QoS.cs index 87aa892..87aa892 100644..100755 --- a/bindings/csharp/QoS.cs +++ b/bindings/csharp/QoS.cs diff --git a/bindings/java/QoS.java b/bindings/java/QoS.java index e216f8d..e216f8d 100644..100755 --- a/bindings/java/QoS.java +++ b/bindings/java/QoS.java diff --git a/bindings/java/android/QoS.java b/bindings/java/android/QoS.java index e216f8d..e216f8d 100644..100755 --- a/bindings/java/android/QoS.java +++ b/bindings/java/android/QoS.java diff --git a/thirdparties/mac/include/srtp/config.h b/thirdparties/mac/include/srtp/config.h index dfaaa99..dfaaa99 100644..100755 --- a/thirdparties/mac/include/srtp/config.h +++ b/thirdparties/mac/include/srtp/config.h diff --git a/thirdparties/mac/lib/i386/libcrypto.a b/thirdparties/mac/lib/i386/libcrypto.a Binary files differindex 5719460..5719460 100644..100755 --- a/thirdparties/mac/lib/i386/libcrypto.a +++ b/thirdparties/mac/lib/i386/libcrypto.a diff --git a/thirdparties/mac/lib/i386/libsrtp.a b/thirdparties/mac/lib/i386/libsrtp.a Binary files differindex 0767739..0767739 100644..100755 --- a/thirdparties/mac/lib/i386/libsrtp.a +++ b/thirdparties/mac/lib/i386/libsrtp.a diff --git a/thirdparties/mac/lib/i386/libssl.a b/thirdparties/mac/lib/i386/libssl.a Binary files differindex 5045c9a..5045c9a 100644..100755 --- a/thirdparties/mac/lib/i386/libssl.a +++ b/thirdparties/mac/lib/i386/libssl.a diff --git a/thirdparties/mac/lib/x86_64/libcrypto.a b/thirdparties/mac/lib/x86_64/libcrypto.a Binary files differindex 0615936..0615936 100644..100755 --- a/thirdparties/mac/lib/x86_64/libcrypto.a +++ b/thirdparties/mac/lib/x86_64/libcrypto.a diff --git a/thirdparties/mac/lib/x86_64/libsrtp.a b/thirdparties/mac/lib/x86_64/libsrtp.a Binary files differindex 516002c..516002c 100644..100755 --- a/thirdparties/mac/lib/x86_64/libsrtp.a +++ b/thirdparties/mac/lib/x86_64/libsrtp.a diff --git a/thirdparties/mac/lib/x86_64/libssl.a b/thirdparties/mac/lib/x86_64/libssl.a Binary files differindex a431706..a431706 100644..100755 --- a/thirdparties/mac/lib/x86_64/libssl.a +++ b/thirdparties/mac/lib/x86_64/libssl.a diff --git a/tinyDAV/src/video/tdav_session_video.c b/tinyDAV/src/video/tdav_session_video.c index 755323a..c867605 100755 --- a/tinyDAV/src/video/tdav_session_video.c +++ b/tinyDAV/src/video/tdav_session_video.c @@ -614,12 +614,12 @@ static int tdav_session_video_rtcp_cb(const void* callback_data, const trtp_rtcp case trtp_rtcp_psfb_fci_type_afb: { if (psfb->afb.type == trtp_rtcp_psfb_afb_type_remb) { uint64_t bw_up_reported_kpbs = ((psfb->afb.remb.mantissa << psfb->afb.remb.exp) >> 10); - TSK_DEBUG_INFO("Receiving RTCP-AFB-REMB (%u), exp=%u, mantissa=%u, bandwidth=%ukbps", ((const trtp_rtcp_report_fb_t*)psfb)->ssrc_media, psfb->afb.remb.exp, psfb->afb.remb.mantissa, bw_up_reported_kpbs); + TSK_DEBUG_INFO("Receiving RTCP-AFB-REMB (%u), exp=%u, mantissa=%u, bandwidth=%llukbps", ((const trtp_rtcp_report_fb_t*)psfb)->ssrc_media, psfb->afb.remb.exp, psfb->afb.remb.mantissa, bw_up_reported_kpbs); if (base->congestion_ctrl_enabled) { if (session->qos_metrics.bw_up_est_kbps != 0) { float q3 = bw_up_reported_kpbs / (float)session->qos_metrics.bw_up_est_kbps; q3 = TSK_CLAMP(0.f, q3, 1.f); - TSK_DEBUG_INFO("bw_up_estimated_kbps=%llu, bw_up_reported_kpbs=%llu, q3=%f", session->qos_metrics.bw_up_est_kbps, bw_up_reported_kpbs, q3); + TSK_DEBUG_INFO("bw_up_estimated_kbps=%u, bw_up_reported_kpbs=%llu, q3=%f", session->qos_metrics.bw_up_est_kbps, bw_up_reported_kpbs, q3); tsk_mutex_lock(video->h_mutex_qos); session->qos_metrics.q3 = (session->qos_metrics.q3 + q3) / (video->q3_n++ ? 2.f : 1.f); tsk_mutex_unlock(video->h_mutex_qos); @@ -1539,7 +1539,7 @@ static int _tdav_session_video_report_bw_usage_and_jcng(tdav_session_video_t* se jcng_q = q5; } } - TSK_DEBUG_INFO("video with congestion control enabled: est_bw_down=%llukbps, est_jcng=%f", session->qos_metrics.bw_down_est_kbps, jcng_q); + TSK_DEBUG_INFO("video with congestion control enabled: est_bw_down=%ukbps, est_jcng=%f", session->qos_metrics.bw_down_est_kbps, jcng_q); ret = trtp_manager_set_app_bw_and_jcng(base->rtp_manager, INT_MAX/* unused */, (int32_t)session->qos_metrics.bw_down_est_kbps, jcng_q); self->last_sendreport_time = tsk_time_now(); } diff --git a/tinyNET/src/tnet_transport_cfsocket.c b/tinyNET/src/tnet_transport_cfsocket.c index ed844b6..5ffe88d 100755 --- a/tinyNET/src/tnet_transport_cfsocket.c +++ b/tinyNET/src/tnet_transport_cfsocket.c @@ -319,6 +319,7 @@ static int recvData(tnet_transport_t *transport, transport_socket_xt* active_soc if (len && buffer) { tnet_transport_event_t* e = tnet_transport_event_create(event_data, transport->callback_data, active_socket->fd); + transport->bytes_in += len; if (e && buffer && len) { e->data = buffer; buffer = NULL; @@ -485,6 +486,7 @@ tsk_size_t tnet_transport_send(const tnet_transport_handle_t *handle, tnet_fd_t } bail: + transport->bytes_out += numberOfBytesSent; return numberOfBytesSent; } @@ -517,6 +519,7 @@ tsk_size_t tnet_transport_sendto(const tnet_transport_handle_t *handle, tnet_fd_ } bail: + transport->bytes_out += numberOfBytesSent; return numberOfBytesSent; } @@ -1034,6 +1037,7 @@ void __CFSocketCallBack(CFSocketRef s, CFSocketCallBackType callbackType, CFData int len = (int)CFDataGetLength((CFDataRef)data); if (ptr && len > 0) { tnet_transport_event_t* e = tnet_transport_event_create(event_data, transport->callback_data, sock->fd); + transport->bytes_in += len; if (e) { e->data = tsk_malloc(len); if (e->data) { diff --git a/website/.htaccess b/website/.htaccess index 740e433..740e433 100644..100755 --- a/website/.htaccess +++ b/website/.htaccess |