freeswitch-svn
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
May 2009
- 14 participants
- 307 discussions
Author: mikej
Date: Wed May 27 18:37:16 2009
New Revision: 13483
Log:
last test
Modified:
freeswitch/trunk/Makefile.am
Modified: freeswitch/trunk/Makefile.am
==============================================================================
--- freeswitch/trunk/Makefile.am (original)
+++ freeswitch/trunk/Makefile.am Wed May 27 18:37:16 2009
@@ -492,5 +492,3 @@
coffee me_a_sandwich me_a_sammich:
@echo "Who do you think I am? Make it yourself!"
-
-
1
0
Author: mikej
Date: Wed May 27 18:33:46 2009
New Revision: 13482
Log:
poke
Modified:
freeswitch/trunk/Makefile.am
Modified: freeswitch/trunk/Makefile.am
==============================================================================
--- freeswitch/trunk/Makefile.am (original)
+++ freeswitch/trunk/Makefile.am Wed May 27 18:33:46 2009
@@ -493,3 +493,4 @@
coffee me_a_sandwich me_a_sammich:
@echo "Who do you think I am? Make it yourself!"
+
1
0
Author: mikej
Date: Wed May 27 18:31:52 2009
New Revision: 13481
Log:
poke
Modified:
freeswitch/trunk/Makefile.am
Modified: freeswitch/trunk/Makefile.am
==============================================================================
--- freeswitch/trunk/Makefile.am (original)
+++ freeswitch/trunk/Makefile.am Wed May 27 18:31:52 2009
@@ -492,3 +492,4 @@
coffee me_a_sandwich me_a_sammich:
@echo "Who do you think I am? Make it yourself!"
+
1
0
Author: mikej
Date: Wed May 27 18:29:06 2009
New Revision: 13480
Log:
poke
Modified:
freeswitch/trunk/Makefile.am
Modified: freeswitch/trunk/Makefile.am
==============================================================================
--- freeswitch/trunk/Makefile.am (original)
+++ freeswitch/trunk/Makefile.am Wed May 27 18:29:06 2009
@@ -184,7 +184,6 @@
freeswitch_LDADD += libs/libedit/src/.libs/libedit.a
endif
-
if ADD_LIBEDIT
CORE_CFLAGS += -Ilibs/libedit/src -DSWITCH_HAVE_LIBEDIT
CORE_LIBS += libs/libedit/src/.libs/libedit.a
1
0
Author: mikej
Date: Wed May 27 18:27:45 2009
New Revision: 13479
Log:
poke
Modified:
freeswitch/trunk/Makefile.am
Modified: freeswitch/trunk/Makefile.am
==============================================================================
--- freeswitch/trunk/Makefile.am (original)
+++ freeswitch/trunk/Makefile.am Wed May 27 18:27:45 2009
@@ -103,8 +103,6 @@
libs/libteletone/src/libteletone_detect.c\
libs/libteletone/src/libteletone_generate.c
-
-
library_includedir = $(PREFIX)/include
library_include_HEADERS = \
1
0
[Freeswitch-svn] [commit] r13477 - freeswitch/trunk/src/mod/applications/mod_expr
by FreeSWITCH SVN 27 May '09
by FreeSWITCH SVN 27 May '09
27 May '09
Author: mikej
Date: Wed May 27 18:23:29 2009
New Revision: 13477
Log:
dos2unix
Modified:
freeswitch/trunk/src/mod/applications/mod_expr/exprpriv.h
Modified: freeswitch/trunk/src/mod/applications/mod_expr/exprpriv.h
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_expr/exprpriv.h (original)
+++ freeswitch/trunk/src/mod/applications/mod_expr/exprpriv.h Wed May 27 18:23:29 2009
@@ -206,16 +206,16 @@
int exprFuncListAddType(exprFuncList *flist, char *name, int type, int min, int max, int refmin, int refmax);
int exprFuncListGet(exprFuncList *flist, char *name, exprFuncType *ptr, int *type, int *min, int *max, int *refmin, int *refmax);
-#ifdef WIN32
-#define SWITCH_DECLARE(type) __declspec(dllimport) type __stdcall
-#else
-#define SWITCH_DECLARE(type) type
-#endif
-
-SWITCH_DECLARE(int) switch_isalnum(int c);
-SWITCH_DECLARE(int) switch_isalpha(int c);
-SWITCH_DECLARE(int) switch_isdigit(int c);
-SWITCH_DECLARE(int) switch_isspace(int c);
+#ifdef WIN32
+#define SWITCH_DECLARE(type) __declspec(dllimport) type __stdcall
+#else
+#define SWITCH_DECLARE(type) type
+#endif
+
+SWITCH_DECLARE(int) switch_isalnum(int c);
+SWITCH_DECLARE(int) switch_isalpha(int c);
+SWITCH_DECLARE(int) switch_isdigit(int c);
+SWITCH_DECLARE(int) switch_isspace(int c);
#ifdef __cplusplus
}
1
0
[Freeswitch-svn] [commit] r13476 - freeswitch/trunk/src/mod/applications/mod_stress
by FreeSWITCH SVN 27 May '09
by FreeSWITCH SVN 27 May '09
27 May '09
Author: mikej
Date: Wed May 27 18:22:15 2009
New Revision: 13476
Log:
dos2unix
Modified:
freeswitch/trunk/src/mod/applications/mod_stress/FFTReal.h
Modified: freeswitch/trunk/src/mod/applications/mod_stress/FFTReal.h
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_stress/FFTReal.h (original)
+++ freeswitch/trunk/src/mod/applications/mod_stress/FFTReal.h Wed May 27 18:22:15 2009
@@ -1,139 +1,139 @@
-/*****************************************************************************
-* *
-* DIGITAL SIGNAL PROCESSING TOOLS *
-* Version 1.03, 2001/06/15 *
-* (c) 1999 - Laurent de Soras *
-* *
-* FFTReal.h *
-* Fourier transformation of real number arrays. *
-* Portable ISO C++ *
-* *
-* Tab = 3 *
-*****************************************************************************/
-
-
-
-#if defined (FFTReal_CURRENT_HEADER)
- #error Recursive inclusion of FFTReal header file.
-#endif
-#define FFTReal_CURRENT_HEADER
-
-#if ! defined (FFTReal_HEADER_INCLUDED)
-#define FFTReal_HEADER_INCLUDED
-
-
-
-#if defined (_MSC_VER)
-#pragma pack (push, 8)
-#endif // _MSC_VER
-
-
-
-class FFTReal
-{
-
-/*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
-
-public:
-
- /* Change this typedef to use a different floating point type in your FFTs
- (i.e. float, double or long double). */
- typedef float flt_t;
-
- explicit FFTReal (const long length);
- ~FFTReal ();
- void do_fft (flt_t f [], const flt_t x []) const;
- void do_ifft (const flt_t f [], flt_t x []) const;
- void rescale (flt_t x []) const;
-
-
-
-/*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
-
-private:
-
- /* Bit-reversed look-up table nested class */
- class BitReversedLUT
- {
- public:
- explicit BitReversedLUT (const int nbr_bits);
- ~BitReversedLUT ();
- const long * get_ptr () const
- {
- return (_ptr);
- }
- private:
- long * _ptr;
- };
-
- /* Trigonometric look-up table nested class */
- class TrigoLUT
- {
- public:
- explicit TrigoLUT (const int nbr_bits);
- ~TrigoLUT ();
- const flt_t * get_ptr (const int level) const
- {
- return (_ptr + (1L << (level - 1)) - 4);
- };
- private:
- flt_t * _ptr;
- };
-
- const BitReversedLUT _bit_rev_lut;
- const TrigoLUT _trigo_lut;
- const flt_t _sqrt2_2;
- const long _length;
- const int _nbr_bits;
- flt_t * _buffer_ptr;
-
-
-
-/*\\\ FORBIDDEN MEMBER FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
-
-private:
-
- FFTReal (const FFTReal &other);
- const FFTReal& operator = (const FFTReal &other);
- int operator == (const FFTReal &other);
- int operator != (const FFTReal &other);
-};
-
-
-
-#if defined (_MSC_VER)
-#pragma pack (pop)
-#endif // _MSC_VER
-
-
-
-#endif // FFTReal_HEADER_INCLUDED
-
-#undef FFTReal_CURRENT_HEADER
-
-
-
-/*****************************************************************************
-
- LEGAL
-
- Source code may be freely used for any purpose, including commercial
- applications. Programs must display in their "About" dialog-box (or
- documentation) a text telling they use these routines by Laurent de Soras.
- Modified source code can be distributed, but modifications must be clearly
- indicated.
-
- CONTACT
-
- Laurent de Soras
- 92 avenue Albert 1er
- 92500 Rueil-Malmaison
- France
-
- ldesoras(a)club-internet.fr
-
-*****************************************************************************/
-
-
-
-/*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
+/*****************************************************************************
+* *
+* DIGITAL SIGNAL PROCESSING TOOLS *
+* Version 1.03, 2001/06/15 *
+* (c) 1999 - Laurent de Soras *
+* *
+* FFTReal.h *
+* Fourier transformation of real number arrays. *
+* Portable ISO C++ *
+* *
+* Tab = 3 *
+*****************************************************************************/
+
+
+
+#if defined (FFTReal_CURRENT_HEADER)
+ #error Recursive inclusion of FFTReal header file.
+#endif
+#define FFTReal_CURRENT_HEADER
+
+#if ! defined (FFTReal_HEADER_INCLUDED)
+#define FFTReal_HEADER_INCLUDED
+
+
+
+#if defined (_MSC_VER)
+#pragma pack (push, 8)
+#endif // _MSC_VER
+
+
+
+class FFTReal
+{
+
+/*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
+
+public:
+
+ /* Change this typedef to use a different floating point type in your FFTs
+ (i.e. float, double or long double). */
+ typedef float flt_t;
+
+ explicit FFTReal (const long length);
+ ~FFTReal ();
+ void do_fft (flt_t f [], const flt_t x []) const;
+ void do_ifft (const flt_t f [], flt_t x []) const;
+ void rescale (flt_t x []) const;
+
+
+
+/*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
+
+private:
+
+ /* Bit-reversed look-up table nested class */
+ class BitReversedLUT
+ {
+ public:
+ explicit BitReversedLUT (const int nbr_bits);
+ ~BitReversedLUT ();
+ const long * get_ptr () const
+ {
+ return (_ptr);
+ }
+ private:
+ long * _ptr;
+ };
+
+ /* Trigonometric look-up table nested class */
+ class TrigoLUT
+ {
+ public:
+ explicit TrigoLUT (const int nbr_bits);
+ ~TrigoLUT ();
+ const flt_t * get_ptr (const int level) const
+ {
+ return (_ptr + (1L << (level - 1)) - 4);
+ };
+ private:
+ flt_t * _ptr;
+ };
+
+ const BitReversedLUT _bit_rev_lut;
+ const TrigoLUT _trigo_lut;
+ const flt_t _sqrt2_2;
+ const long _length;
+ const int _nbr_bits;
+ flt_t * _buffer_ptr;
+
+
+
+/*\\\ FORBIDDEN MEMBER FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
+
+private:
+
+ FFTReal (const FFTReal &other);
+ const FFTReal& operator = (const FFTReal &other);
+ int operator == (const FFTReal &other);
+ int operator != (const FFTReal &other);
+};
+
+
+
+#if defined (_MSC_VER)
+#pragma pack (pop)
+#endif // _MSC_VER
+
+
+
+#endif // FFTReal_HEADER_INCLUDED
+
+#undef FFTReal_CURRENT_HEADER
+
+
+
+/*****************************************************************************
+
+ LEGAL
+
+ Source code may be freely used for any purpose, including commercial
+ applications. Programs must display in their "About" dialog-box (or
+ documentation) a text telling they use these routines by Laurent de Soras.
+ Modified source code can be distributed, but modifications must be clearly
+ indicated.
+
+ CONTACT
+
+ Laurent de Soras
+ 92 avenue Albert 1er
+ 92500 Rueil-Malmaison
+ France
+
+ ldesoras(a)club-internet.fr
+
+*****************************************************************************/
+
+
+
+/*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
1
0
[Freeswitch-svn] [commit] r13475 - freeswitch/trunk/src/mod/endpoints/mod_opal
by FreeSWITCH SVN 27 May '09
by FreeSWITCH SVN 27 May '09
27 May '09
Author: mikej
Date: Wed May 27 18:20:26 2009
New Revision: 13475
Log:
dos2unix
Modified:
freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal.h
Modified: freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal.h (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal.h Wed May 27 18:20:26 2009
@@ -1,275 +1,275 @@
-/* Opal endpoint interface for Freeswitch Modular Media Switching Software Library /
- * Soft-Switch Application
- *
- * Version: MPL 1.1
- *
- * Copyright (c) 2007 Tuyan Ozipek (tuyanozipek(a)gmail.com)
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * Contributor(s):
- * Tuyan Ozipek (tuyanozipek(a)gmail.com)
- * Lukasz Zwierko (lzwierko(a)gmail.com)
- * Robert Jongbloed (robertj(a)voxlucida.com.au)
- *
- */
-
-
-#ifndef __FREESWITCH_MOD_OPAL__
-#define __FREESWITCH_MOD_OPAL__
-
-#if defined(__GNUC__) && defined(HAVE_VISIBILITY)
-#pragma GCC visibility push(default)
-#endif
-
-#include <ptlib.h>
-#include <opal/manager.h>
-#include <opal/localep.h>
-#include <h323/h323ep.h>
-#include <iax2/iax2ep.h>
-
-#if defined(__GNUC__) && defined(HAVE_VISIBILITY)
-#pragma GCC visibility pop
-#endif
-
-#undef strcasecmp
-#undef strncasecmp
-
-#define HAVE_APR
-#include <switch.h>
-#include <switch_version.h>
-#define MODNAME "mod_opal"
-
-
-class FSEndPoint;
-class FSManager;
-
-
-struct mod_opal_globals {
- int trace_level;
- char *codec_string;
- char *context;
- char *dialplan;
-};
-
-extern struct mod_opal_globals mod_opal_globals;
-
-
-class FSProcess : public PLibraryProcess {
- PCLASSINFO(FSProcess, PLibraryProcess);
-
- public:
- FSProcess();
- ~FSProcess();
-
- bool Initialise(switch_loadable_module_interface_t *iface);
-
- FSManager & GetManager() const { return *m_manager; }
-
- protected:
- FSManager * m_manager;
-};
-
-
-struct FSListener {
- FSListener() {
- }
-
- PString name;
- OpalTransportAddress listenAddress;
- PString localUserName;
- PString gatekeeper;
-};
-
-
-class FSCall : public OpalCall {
- PCLASSINFO(FSCall, OpalCall);
- public:
- FSCall(OpalManager & manager);
- virtual PBoolean OnSetUp(OpalConnection & connection);
-};
-
-
-class FSManager : public OpalManager {
- PCLASSINFO(FSManager, OpalManager);
-
- public:
- FSManager();
-
- bool Initialise(switch_loadable_module_interface_t *iface);
-
- switch_status_t ReadConfig(int reload);
-
- switch_endpoint_interface_t *GetSwitchInterface() const {
- return m_FreeSwitch;
- }
-
- virtual OpalCall * CreateCall(void * userData);
-
- private:
- switch_endpoint_interface_t *m_FreeSwitch;
-
- H323EndPoint *m_h323ep;
- IAX2EndPoint *m_iaxep;
- FSEndPoint *m_fsep;
-
- PString m_gkAddress;
- PString m_gkIdentifer;
- PString m_gkInterface;
-
- list < FSListener > m_listeners;
-};
-
-
-class FSConnection;
-typedef struct {
- switch_timer_t read_timer;
- switch_codec_t read_codec;
- switch_codec_t write_codec;
-
- switch_timer_t vid_read_timer;
- switch_codec_t vid_read_codec;
- switch_codec_t vid_write_codec;
- FSConnection *me;
-} opal_private_t;
-
-
-class FSEndPoint:public OpalLocalEndPoint {
- PCLASSINFO(FSEndPoint, OpalLocalEndPoint);
- public:
- FSEndPoint(FSManager & manager);
-
- virtual bool OnIncomingCall(OpalLocalConnection &);
- virtual OpalLocalConnection *CreateConnection(OpalCall &, void *);
-};
-
-
-#define DECLARE_CALLBACK0(name) \
- static switch_status_t name(switch_core_session_t *session) { \
- opal_private_t *tech_pvt = (opal_private_t *) switch_core_session_get_private(session); \
- return tech_pvt && tech_pvt->me != NULL ? tech_pvt->me->name() : SWITCH_STATUS_FALSE; } \
-switch_status_t name()
-
-#define DECLARE_CALLBACK1(name, type1, name1) \
- static switch_status_t name(switch_core_session_t *session, type1 name1) { \
- opal_private_t *tech_pvt = (opal_private_t *) switch_core_session_get_private(session); \
- return tech_pvt && tech_pvt->me != NULL ? tech_pvt->me->name(name1) : SWITCH_STATUS_FALSE; } \
-switch_status_t name(type1 name1)
-
-#define DECLARE_CALLBACK3(name, type1, name1, type2, name2, type3, name3) \
- static switch_status_t name(switch_core_session_t *session, type1 name1, type2 name2, type3 name3) { \
- opal_private_t *tech_pvt = (opal_private_t *) switch_core_session_get_private(session); \
- return tech_pvt && tech_pvt->me != NULL ? tech_pvt->me->name(name1, name2, name3) : SWITCH_STATUS_FALSE; } \
-switch_status_t name(type1 name1, type2 name2, type3 name3)
-
-
-
-
-class FSConnection:public OpalLocalConnection {
- PCLASSINFO(FSConnection, OpalLocalConnection)
-
- public:
- FSConnection(OpalCall & call,
- FSEndPoint & endpoint,
- switch_caller_profile_t *outbound_profile,
- switch_core_session_t *fsSession,
- switch_channel_t *fsChannel);
-
- virtual bool OnIncoming();
- virtual void OnReleased();
- virtual PBoolean SetAlerting(const PString & calleeName, PBoolean withMedia);
- virtual void OnAlerting();
- virtual void OnEstablished();
- virtual OpalMediaStream *CreateMediaStream(const OpalMediaFormat &, unsigned, PBoolean);
- virtual PBoolean OnOpenMediaStream(OpalMediaStream & stream);
- virtual OpalMediaFormatList GetMediaFormats() const;
- virtual PBoolean SendUserInputTone(char tone, unsigned duration);
- virtual PBoolean SendUserInputString(const PString & value);
-
- void SetCodecs();
-
- DECLARE_CALLBACK0(on_init);
- DECLARE_CALLBACK0(on_routing);
- DECLARE_CALLBACK0(on_execute);
-
- DECLARE_CALLBACK0(on_exchange_media);
- DECLARE_CALLBACK0(on_soft_execute);
-
- DECLARE_CALLBACK1(kill_channel, int, sig);
- DECLARE_CALLBACK1(send_dtmf, const switch_dtmf_t *, dtmf);
- DECLARE_CALLBACK1(receive_message, switch_core_session_message_t *, msg);
- DECLARE_CALLBACK1(receive_event, switch_event_t *, event);
- DECLARE_CALLBACK0(state_change);
- DECLARE_CALLBACK3(read_audio_frame, switch_frame_t **, frame, switch_io_flag_t, flags, int, stream_id);
- DECLARE_CALLBACK3(write_audio_frame, switch_frame_t *, frame, switch_io_flag_t, flags, int, stream_id);
- DECLARE_CALLBACK3(read_video_frame, switch_frame_t **, frame, switch_io_flag_t, flag, int, stream_id);
- DECLARE_CALLBACK3(write_video_frame, switch_frame_t *, frame, switch_io_flag_t, flag, int, stream_id);
-
- switch_status_t read_frame(const OpalMediaType & mediaType, switch_frame_t **frame, switch_io_flag_t flags);
- switch_status_t write_frame(const OpalMediaType & mediaType, const switch_frame_t *frame, switch_io_flag_t flags);
-
- switch_core_session_t *GetSession() const {
- return m_fsSession;
- }
-
- private:
- FSEndPoint & m_endpoint;
- switch_core_session_t *m_fsSession;
- switch_channel_t *m_fsChannel;
- PSyncPoint m_rxAudioOpened;
- PSyncPoint m_txAudioOpened;
- OpalMediaFormatList m_switchMediaFormats;
-};
-
-
-class FSMediaStream:public OpalMediaStream {
- PCLASSINFO(FSMediaStream, OpalMediaStream);
- public:
- FSMediaStream(FSConnection & conn, const OpalMediaFormat & mediaFormat, ///< Media format for stream
- unsigned sessionID, ///< Session number for stream
- bool isSource ///< Is a source stream
- );
-
- virtual PBoolean Open();
- virtual PBoolean Close();
- virtual PBoolean IsSynchronous() const;
- virtual PBoolean RequiresPatchThread(OpalMediaStream *) const;
-
- switch_status_t read_frame(switch_frame_t **frame, switch_io_flag_t flags);
- switch_status_t write_frame(const switch_frame_t *frame, switch_io_flag_t flags);
-
- private:
- switch_core_session_t *m_fsSession;
- switch_channel_t *m_fsChannel;
- switch_timer_t *m_switchTimer;
- switch_codec_t *m_switchCodec;
- switch_frame_t m_readFrame;
- unsigned char m_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
- RTP_DataFrame m_readRTP;
- bool m_callOnStart;
- uint32_t m_timeStamp;
-
- bool CheckPatchAndLock();
-};
-
-
-#endif /* __FREESWITCH_MOD_OPAL__ */
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:nil
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4: expandtabs:
- */
+/* Opal endpoint interface for Freeswitch Modular Media Switching Software Library /
+ * Soft-Switch Application
+ *
+ * Version: MPL 1.1
+ *
+ * Copyright (c) 2007 Tuyan Ozipek (tuyanozipek(a)gmail.com)
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Contributor(s):
+ * Tuyan Ozipek (tuyanozipek(a)gmail.com)
+ * Lukasz Zwierko (lzwierko(a)gmail.com)
+ * Robert Jongbloed (robertj(a)voxlucida.com.au)
+ *
+ */
+
+
+#ifndef __FREESWITCH_MOD_OPAL__
+#define __FREESWITCH_MOD_OPAL__
+
+#if defined(__GNUC__) && defined(HAVE_VISIBILITY)
+#pragma GCC visibility push(default)
+#endif
+
+#include <ptlib.h>
+#include <opal/manager.h>
+#include <opal/localep.h>
+#include <h323/h323ep.h>
+#include <iax2/iax2ep.h>
+
+#if defined(__GNUC__) && defined(HAVE_VISIBILITY)
+#pragma GCC visibility pop
+#endif
+
+#undef strcasecmp
+#undef strncasecmp
+
+#define HAVE_APR
+#include <switch.h>
+#include <switch_version.h>
+#define MODNAME "mod_opal"
+
+
+class FSEndPoint;
+class FSManager;
+
+
+struct mod_opal_globals {
+ int trace_level;
+ char *codec_string;
+ char *context;
+ char *dialplan;
+};
+
+extern struct mod_opal_globals mod_opal_globals;
+
+
+class FSProcess : public PLibraryProcess {
+ PCLASSINFO(FSProcess, PLibraryProcess);
+
+ public:
+ FSProcess();
+ ~FSProcess();
+
+ bool Initialise(switch_loadable_module_interface_t *iface);
+
+ FSManager & GetManager() const { return *m_manager; }
+
+ protected:
+ FSManager * m_manager;
+};
+
+
+struct FSListener {
+ FSListener() {
+ }
+
+ PString name;
+ OpalTransportAddress listenAddress;
+ PString localUserName;
+ PString gatekeeper;
+};
+
+
+class FSCall : public OpalCall {
+ PCLASSINFO(FSCall, OpalCall);
+ public:
+ FSCall(OpalManager & manager);
+ virtual PBoolean OnSetUp(OpalConnection & connection);
+};
+
+
+class FSManager : public OpalManager {
+ PCLASSINFO(FSManager, OpalManager);
+
+ public:
+ FSManager();
+
+ bool Initialise(switch_loadable_module_interface_t *iface);
+
+ switch_status_t ReadConfig(int reload);
+
+ switch_endpoint_interface_t *GetSwitchInterface() const {
+ return m_FreeSwitch;
+ }
+
+ virtual OpalCall * CreateCall(void * userData);
+
+ private:
+ switch_endpoint_interface_t *m_FreeSwitch;
+
+ H323EndPoint *m_h323ep;
+ IAX2EndPoint *m_iaxep;
+ FSEndPoint *m_fsep;
+
+ PString m_gkAddress;
+ PString m_gkIdentifer;
+ PString m_gkInterface;
+
+ list < FSListener > m_listeners;
+};
+
+
+class FSConnection;
+typedef struct {
+ switch_timer_t read_timer;
+ switch_codec_t read_codec;
+ switch_codec_t write_codec;
+
+ switch_timer_t vid_read_timer;
+ switch_codec_t vid_read_codec;
+ switch_codec_t vid_write_codec;
+ FSConnection *me;
+} opal_private_t;
+
+
+class FSEndPoint:public OpalLocalEndPoint {
+ PCLASSINFO(FSEndPoint, OpalLocalEndPoint);
+ public:
+ FSEndPoint(FSManager & manager);
+
+ virtual bool OnIncomingCall(OpalLocalConnection &);
+ virtual OpalLocalConnection *CreateConnection(OpalCall &, void *);
+};
+
+
+#define DECLARE_CALLBACK0(name) \
+ static switch_status_t name(switch_core_session_t *session) { \
+ opal_private_t *tech_pvt = (opal_private_t *) switch_core_session_get_private(session); \
+ return tech_pvt && tech_pvt->me != NULL ? tech_pvt->me->name() : SWITCH_STATUS_FALSE; } \
+switch_status_t name()
+
+#define DECLARE_CALLBACK1(name, type1, name1) \
+ static switch_status_t name(switch_core_session_t *session, type1 name1) { \
+ opal_private_t *tech_pvt = (opal_private_t *) switch_core_session_get_private(session); \
+ return tech_pvt && tech_pvt->me != NULL ? tech_pvt->me->name(name1) : SWITCH_STATUS_FALSE; } \
+switch_status_t name(type1 name1)
+
+#define DECLARE_CALLBACK3(name, type1, name1, type2, name2, type3, name3) \
+ static switch_status_t name(switch_core_session_t *session, type1 name1, type2 name2, type3 name3) { \
+ opal_private_t *tech_pvt = (opal_private_t *) switch_core_session_get_private(session); \
+ return tech_pvt && tech_pvt->me != NULL ? tech_pvt->me->name(name1, name2, name3) : SWITCH_STATUS_FALSE; } \
+switch_status_t name(type1 name1, type2 name2, type3 name3)
+
+
+
+
+class FSConnection:public OpalLocalConnection {
+ PCLASSINFO(FSConnection, OpalLocalConnection)
+
+ public:
+ FSConnection(OpalCall & call,
+ FSEndPoint & endpoint,
+ switch_caller_profile_t *outbound_profile,
+ switch_core_session_t *fsSession,
+ switch_channel_t *fsChannel);
+
+ virtual bool OnIncoming();
+ virtual void OnReleased();
+ virtual PBoolean SetAlerting(const PString & calleeName, PBoolean withMedia);
+ virtual void OnAlerting();
+ virtual void OnEstablished();
+ virtual OpalMediaStream *CreateMediaStream(const OpalMediaFormat &, unsigned, PBoolean);
+ virtual PBoolean OnOpenMediaStream(OpalMediaStream & stream);
+ virtual OpalMediaFormatList GetMediaFormats() const;
+ virtual PBoolean SendUserInputTone(char tone, unsigned duration);
+ virtual PBoolean SendUserInputString(const PString & value);
+
+ void SetCodecs();
+
+ DECLARE_CALLBACK0(on_init);
+ DECLARE_CALLBACK0(on_routing);
+ DECLARE_CALLBACK0(on_execute);
+
+ DECLARE_CALLBACK0(on_exchange_media);
+ DECLARE_CALLBACK0(on_soft_execute);
+
+ DECLARE_CALLBACK1(kill_channel, int, sig);
+ DECLARE_CALLBACK1(send_dtmf, const switch_dtmf_t *, dtmf);
+ DECLARE_CALLBACK1(receive_message, switch_core_session_message_t *, msg);
+ DECLARE_CALLBACK1(receive_event, switch_event_t *, event);
+ DECLARE_CALLBACK0(state_change);
+ DECLARE_CALLBACK3(read_audio_frame, switch_frame_t **, frame, switch_io_flag_t, flags, int, stream_id);
+ DECLARE_CALLBACK3(write_audio_frame, switch_frame_t *, frame, switch_io_flag_t, flags, int, stream_id);
+ DECLARE_CALLBACK3(read_video_frame, switch_frame_t **, frame, switch_io_flag_t, flag, int, stream_id);
+ DECLARE_CALLBACK3(write_video_frame, switch_frame_t *, frame, switch_io_flag_t, flag, int, stream_id);
+
+ switch_status_t read_frame(const OpalMediaType & mediaType, switch_frame_t **frame, switch_io_flag_t flags);
+ switch_status_t write_frame(const OpalMediaType & mediaType, const switch_frame_t *frame, switch_io_flag_t flags);
+
+ switch_core_session_t *GetSession() const {
+ return m_fsSession;
+ }
+
+ private:
+ FSEndPoint & m_endpoint;
+ switch_core_session_t *m_fsSession;
+ switch_channel_t *m_fsChannel;
+ PSyncPoint m_rxAudioOpened;
+ PSyncPoint m_txAudioOpened;
+ OpalMediaFormatList m_switchMediaFormats;
+};
+
+
+class FSMediaStream:public OpalMediaStream {
+ PCLASSINFO(FSMediaStream, OpalMediaStream);
+ public:
+ FSMediaStream(FSConnection & conn, const OpalMediaFormat & mediaFormat, ///< Media format for stream
+ unsigned sessionID, ///< Session number for stream
+ bool isSource ///< Is a source stream
+ );
+
+ virtual PBoolean Open();
+ virtual PBoolean Close();
+ virtual PBoolean IsSynchronous() const;
+ virtual PBoolean RequiresPatchThread(OpalMediaStream *) const;
+
+ switch_status_t read_frame(switch_frame_t **frame, switch_io_flag_t flags);
+ switch_status_t write_frame(const switch_frame_t *frame, switch_io_flag_t flags);
+
+ private:
+ switch_core_session_t *m_fsSession;
+ switch_channel_t *m_fsChannel;
+ switch_timer_t *m_switchTimer;
+ switch_codec_t *m_switchCodec;
+ switch_frame_t m_readFrame;
+ unsigned char m_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
+ RTP_DataFrame m_readRTP;
+ bool m_callOnStart;
+ uint32_t m_timeStamp;
+
+ bool CheckPatchAndLock();
+};
+
+
+#endif /* __FREESWITCH_MOD_OPAL__ */
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:nil
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4: expandtabs:
+ */
1
0
[Freeswitch-svn] [commit] r13474 - freeswitch/trunk/src/mod/formats/mod_portaudio_stream
by FreeSWITCH SVN 27 May '09
by FreeSWITCH SVN 27 May '09
27 May '09
Author: mikej
Date: Wed May 27 18:17:45 2009
New Revision: 13474
Log:
dos2unix
Modified:
freeswitch/trunk/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c
Modified: freeswitch/trunk/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c
==============================================================================
--- freeswitch/trunk/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c (original)
+++ freeswitch/trunk/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c Wed May 27 18:17:45 2009
@@ -1,639 +1,639 @@
-/*
- * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm(a)freeswitch.org>
- *
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- *
- * The Initial Developer of the Original Code is
- * Anthony Minessale II <anthm(a)freeswitch.org>
- * Portions created by the Initial Developer are Copyright (C)
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * mod_portaudio_stream.c -- Portaudio Streaming interface Audio
- *
- */
-#include "switch.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include "pablio.h"
-#include <string.h>
-
-#define DEFAULT_PREBUFFER_SIZE 1024 * 64
-#define SAMPLE_TYPE paInt16
-#define PREFERRED_RATE 8000
-
-SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_stream_load);
-SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_portaudio_stream_shutdown);
-SWITCH_MODULE_DEFINITION(mod_portaudio_stream, mod_portaudio_stream_load, mod_portaudio_stream_shutdown, NULL);
-static switch_memory_pool_t *module_pool = NULL;
-
-struct portaudio_stream_source;
-
-static struct {
- int running;
- int threads;
- switch_mutex_t *mutex;
- switch_hash_t *source_hash;
-
-} globals;
-
-
-struct portaudio_stream_context {
- struct portaudio_stream_source *source;
- switch_mutex_t *audio_mutex;
- switch_buffer_t *audio_buffer;
- int err;
- const char *func;
- const char *file;
- int line;
- switch_file_handle_t *handle;
- struct portaudio_stream_context *next;
-};
-
-typedef struct portaudio_stream_context portaudio_stream_context_t;
-
-struct portaudio_stream_source {
- char *sourcename;
- int sourcedev;
- int rate;
- int interval;
- char *timer_name;
- int total;
- int ready;
- int stopped;
- uint8_t channels;
- switch_size_t samples;
- uint32_t prebuf;
- portaudio_stream_context_t *context_list;
- switch_mutex_t *mutex;
- switch_memory_pool_t *pool;
- switch_thread_rwlock_t *rwlock;
- PABLIO_Stream *audio_stream;
- switch_frame_t read_frame;
- switch_timer_t timer;
- switch_codec_t read_codec;
- switch_codec_t write_codec;
- switch_mutex_t *device_lock;
- unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
-};
-
-typedef struct portaudio_stream_source portaudio_stream_source_t;
-
-
-
-static int get_dev_by_number(char *numstr, int in)
-{
- int numDevices = Pa_GetDeviceCount();
- const PaDeviceInfo *pdi;
- char *end_ptr;
- int number;
-
- number = (int) strtol(numstr, &end_ptr, 10);
-
- if (end_ptr == numstr || number < 0) {
- return -1;
- }
-
- if (number > -1 && number < numDevices && (pdi = Pa_GetDeviceInfo(number))) {
- if (in && pdi->maxInputChannels) {
- return number;
- } else if (!in && pdi->maxOutputChannels) {
- return number;
- }
- }
-
- return -1;
-}
-
-static int get_dev_by_name(char *name, int in)
-{
- int i;
- int numDevices;
- const PaDeviceInfo *pdi;
- numDevices = Pa_GetDeviceCount();
-
- if (numDevices < 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
- return -2;
- }
-
- for (i = 0; i < numDevices; i++) {
- int match = 0;
- pdi = Pa_GetDeviceInfo(i);
-
- if (switch_strlen_zero(name)) {
- match = 1;
- } else if (pdi && pdi->name && strstr(pdi->name, name)) {
- match = 1;
- }
-
- if (match) {
- if (in && pdi->maxInputChannels) {
- return i;
- } else if (!in && pdi->maxOutputChannels) {
- return i;
- }
- }
- }
-
- return -1;
-}
-
-static switch_status_t engage_device(portaudio_stream_source_t *source,int restart)
-{
- PaStreamParameters inputParameters,outputParameters;
- PaError err;
- int sample_rate = source->rate;
- int codec_ms = source->interval;
-
- switch_mutex_init(&source->device_lock, SWITCH_MUTEX_NESTED, module_pool);
-
- if (source->timer.timer_interface) {
- switch_core_timer_sync(&source->timer);
- }
-
- if (source->audio_stream) {
- return SWITCH_STATUS_SUCCESS;
- }
-
- if (!switch_core_codec_ready(&source->read_codec)) {
- if (switch_core_codec_init(&source->read_codec,
- "L16",
- NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
- NULL) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
- return SWITCH_STATUS_FALSE;
- }
- }
-
- switch_assert(source->read_codec.implementation);
-
- if (!switch_core_codec_ready(&source->write_codec) {
- if (switch_core_codec_init(&source->write_codec,
- "L16",
- NULL,
- sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
- NULL) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
- switch_core_codec_destroy(&source->read_codec);
- return SWITCH_STATUS_FALSE;
- }
- }
-
-
- if (!source->timer.timer_interface) {
- if (switch_core_timer_init(&source->timer,
- source->timer_name, codec_ms, source->read_codec.implementation->samples_per_packet,
- module_pool) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
- switch_core_codec_destroy(&source->read_codec);
- switch_core_codec_destroy(&source->write_codec);
- return SWITCH_STATUS_FALSE;
- }
- }
-
- source->read_frame.rate = sample_rate;
- source->read_frame.codec = &source->read_codec;
-
- switch_mutex_lock(source->device_lock);
- /* LOCKED ************************************************************************************************** */
- inputParameters.device = source->sourcedev;
- inputParameters.channelCount = 1;
- inputParameters.sampleFormat = SAMPLE_TYPE;
- inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency;
- inputParameters.hostApiSpecificStreamInfo = NULL;
- outputParameters.device = source->sourcedev;
- outputParameters.channelCount = 1;
- outputParameters.sampleFormat = SAMPLE_TYPE;
- outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
- outputParameters.hostApiSpecificStreamInfo = NULL;
-
-
- err = OpenAudioStream(&source->audio_stream, &inputParameters, NULL, sample_rate, paClipOff,
- source->read_codec.implementation->samples_per_packet, 0);
- /* UNLOCKED ************************************************************************************************* */
- if (err != paNoError) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening audio device retrying\n");
- switch_yield(1000000);
- err = OpenAudioStream(&source->audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff,
- source->read_codec.implementation->samples_per_packet, 0);
- }
-
- switch_mutex_unlock(source->device_lock);
- if (err != paNoError) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open audio device\n");
- switch_core_codec_destroy(&source->read_codec);
- switch_core_timer_destroy(&source->timer);
- return SWITCH_STATUS_FALSE;
- }
-
-
- return SWITCH_STATUS_SUCCESS;
-}
-
-static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void *obj)
-{
- portaudio_stream_source_t *source = obj;
- portaudio_stream_context_t *cp;
- int samples = 0;
- int bused, bytesToWrite;
-
-
- switch_mutex_lock(globals.mutex);
- globals.threads++;
- switch_mutex_unlock(globals.mutex);
-
- if (!source->prebuf) {
- source->prebuf = DEFAULT_PREBUFFER_SIZE;
- }
-
-
-
- switch_mutex_lock(globals.mutex);
- switch_core_hash_insert(globals.source_hash, source->sourcename, source);
- switch_mutex_unlock(globals.mutex);
-
-
- switch_thread_rwlock_create(&source->rwlock, source->pool);
-
- if (engage_device(source,0)!=SWITCH_STATUS_SUCCESS){
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, " Dev %d cant be engaged !\n",(int) source->sourcedev);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " Dev %d engaged at %d rate!\n",(int) source->sourcedev, (int) source->rate);
- if (globals.running && !source->stopped) {
- source->ready = 1;
-
- if (!source->audio_stream){
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Audio Stream wops!\n");
- source->stopped = 0;
- source->ready = 0;
- } else {
- while (globals.running && !source->stopped) {
- samples = 0;
- switch_mutex_lock(source->device_lock);
- samples = ReadAudioStream(source->audio_stream, source->databuf,
- source->read_codec.implementation->samples_per_packet , &source->timer);
- switch_mutex_unlock(source->device_lock);
-
-
- if (samples) {
- bytesToWrite = source->samples;
- if (samples < bytesToWrite) {
- bytesToWrite = samples;
- }
- bytesToWrite *= source->audio_stream->bytesPerFrame;
-
- if (source->total) {
-
- switch_mutex_lock(source->mutex);
- for (cp = source->context_list; cp; cp = cp->next) {
-
- switch_mutex_lock(cp->audio_mutex);
-
- bused = switch_buffer_inuse(cp->audio_buffer);
- if (bused > source->samples * 768 ) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Leaking stream handle! [%s() %s:%d] %d used %d max\n", cp->func, cp->file,
- cp->line,(int) bused, (int) ( source->samples * 768));
- switch_buffer_zero(cp->audio_buffer);
- } else {
- switch_buffer_write(cp->audio_buffer, source->databuf, bytesToWrite);
- }
-
- switch_mutex_unlock(cp->audio_mutex);
- }
- switch_mutex_unlock(source->mutex);
- }
-
- }
-
- }
- }
-
- }
- }
-
-
- source->ready = 0;
-
- switch_mutex_lock(globals.mutex);
- switch_core_hash_delete(globals.source_hash, source->sourcename);
- switch_mutex_unlock(globals.mutex);
-
- switch_thread_rwlock_wrlock(source->rwlock);
- switch_thread_rwlock_unlock(source->rwlock);
-
-
- switch_mutex_lock(source->device_lock);
- CloseAudioStream(source->audio_stream);
- if (switch_core_codec_ready(&source->read_codec)) {
- switch_core_codec_destroy(&source->read_codec);
- switch_core_codec_destroy(&source->write_codec);
- }
- if (switch_core_codec_ready(&source->write_codec) {
- switch_core_codec_destroy(&source->write_codec);
- }
- switch_mutex_unlock(source->device_lock);
-
-
- switch_core_destroy_memory_pool(&source->pool);
-
- switch_mutex_lock(globals.mutex);
- globals.threads--;
- switch_mutex_unlock(globals.mutex);
-
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " thread ending succesfully !\n");
- switch_thread_exit(thread,SWITCH_STATUS_SUCCESS);
-
- return NULL;
-}
-
-
-static switch_status_t portaudio_stream_file_open(switch_file_handle_t *handle, const char *path)
-{
- portaudio_stream_context_t *context ;
- portaudio_stream_source_t *source;
- switch_memory_pool_t *pool;
- switch_status_t status = SWITCH_STATUS_FALSE;
- switch_thread_t *thread;
- switch_threadattr_t *thd_attr = NULL;
- uint32_t rate = PREFERRED_RATE;
- char *npath ;
- int devNumber;
-
-
-
-
-
- handle->pre_buffer_datalen = 0;
-
- if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This format does not support writing! (yet)\n");
- return status;
- }
-
- npath = switch_core_strdup(module_pool, path);
-
- int tmp = handle->samplerate;
- if (tmp == 8000 || tmp == 16000 || tmp == 32000 || tmp == 48000) {
- rate = tmp;
- }
-
- if (*path == '#') {
- devNumber = get_dev_by_number(npath + 1, 1);
- } else {
- devNumber = get_dev_by_name(npath , 1);
- }
- npath = switch_mprintf("device-%d at %d",devNumber,rate);
-
-
-
- switch_mutex_lock(globals.mutex);
- source = switch_core_hash_find(globals.source_hash, npath);
-
- /* dev isnt there, try to start thread */
- if (!source) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, " source isnt Created, create and start thread!\n");
-
- if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, " :S no pool\n");
- } else {
- source = switch_core_alloc(pool, sizeof(*source));
- if (source!=NULL){
- source->pool = pool;
- source->sourcedev = devNumber;
- source->sourcename = switch_core_strdup(source->pool, npath);
- source->rate = rate;
- source->interval = 20;
- source->channels = 1;
- source->timer_name = "soft";
- source->prebuf = DEFAULT_PREBUFFER_SIZE;
- source->stopped = 0;
- source->ready = 0;
- source->samples = switch_samples_per_packet(source->rate, source->interval);
-
-
-
- switch_mutex_init(&source->mutex, SWITCH_MUTEX_NESTED, source->pool);
-
-
-
- switch_threadattr_create(&thd_attr, source->pool);
- switch_threadattr_detach_set(thd_attr, 1);
-
- switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
- switch_thread_create(&thread, thd_attr, read_stream_thread, source, source->pool);
-
- }
-
- }
-
- }
- switch_mutex_unlock(globals.mutex);
- switch_yield(1000000);
- /* dev already engaged */
- if (source) {
-
- /*wait for source to be ready*/
-
- while(source->ready==0){switch_yield(100000);}
-
-
- if (switch_thread_rwlock_tryrdlock(source->rwlock) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, " error rwlock !\n");
- source = NULL;
- }
-
- }
-
-
-
- if (source) {
- status = SWITCH_STATUS_SUCCESS;
-
- if ((context = switch_core_alloc(handle->memory_pool, sizeof(*context))) == 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, " error allocating context!\n");
- status = SWITCH_STATUS_MEMERR;
- } else {
- /* everything goes fine at this point */
- handle->samples = 0;
- handle->samplerate = source->rate;
- handle->channels = 1;
- handle->format = 0;
- handle->sections = 0;
- handle->seekable = 0;
- handle->speed = 0;
- handle->private_info = context;
- handle->interval = source->interval;
-
-
- switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, handle->memory_pool);
- if (switch_buffer_create_dynamic(&context->audio_buffer, 512, 1024, 0) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
- status = SWITCH_STATUS_MEMERR;
- } else {
- /* context created... then continue */
- context->source = source;
- context->file = handle->file;
- context->func = handle->func;
- context->line = handle->line;
- context->handle = handle;
- switch_mutex_lock(source->mutex);
- context->next = source->context_list;
- source->context_list = context;
- source->total++;
- switch_mutex_unlock(source->mutex);
-
- }
- }
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown source %s\n", path);
- status = SWITCH_STATUS_FALSE;
- }
-
-
-
- return status;
-}
-
-
-static switch_status_t portaudio_stream_file_close(switch_file_handle_t *handle)
-{
- portaudio_stream_context_t *cp, *last = NULL, *context = handle->private_info;
-
-
- switch_mutex_lock(context->source->mutex);
- for (cp = context->source->context_list; cp; cp = cp->next) {
- if (cp == context) {
- if (last) {
- last->next = cp->next;
- } else {
- context->source->context_list = cp->next;
- }
- break;
- }
- last = cp;
- }
- context->source->total--;
- switch_mutex_unlock(context->source->mutex);
- switch_buffer_destroy(&context->audio_buffer);
- switch_thread_rwlock_unlock(context->source->rwlock);
-
- return SWITCH_STATUS_SUCCESS;
-}
-
-
-static switch_status_t portaudio_stream_file_read(switch_file_handle_t *handle, void *data, size_t *len)
-{
- portaudio_stream_context_t *context = handle->private_info;
- switch_size_t bytes = 0;
- int bytesPerSample = context->source->audio_stream->bytesPerFrame;
- size_t need = *len * bytesPerSample;
-
-
-
- if (!context->source->ready) {
- *len = 0;
- return SWITCH_STATUS_FALSE;
- }
-
- switch_mutex_lock(context->audio_mutex);
- if ((bytes = switch_buffer_read(context->audio_buffer, data, need))) {
- *len = bytes / bytesPerSample;
- } else {
- if (need > 2560) {
- need = 2560;
- }
- memset(data, 255, need);
- *len = need / bytesPerSample;
- }
- switch_mutex_unlock(context->audio_mutex);
-
-
-
- handle->sample_count += *len;
- return SWITCH_STATUS_SUCCESS;
-
-
-}
-
-/* Registration */
-
-static char *supported_formats[SWITCH_MAX_CODECS] = { 0 };
-
-static void shutdown_event_handler(switch_event_t *event)
-{
- globals.running = 0;
-}
-
-SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_stream_load)
-{
- switch_file_interface_t *file_interface;
- supported_formats[0] = "portaudio_stream";
-
- module_pool = pool;
-
- Pa_Initialize();
-
- *module_interface = switch_loadable_module_create_module_interface(pool, modname);
- file_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE);
- file_interface->interface_name = modname;
- file_interface->extens = supported_formats;
- file_interface->file_open = portaudio_stream_file_open;
- file_interface->file_close = portaudio_stream_file_close;
- file_interface->file_read = portaudio_stream_file_read;
-
- if (switch_event_bind(modname, SWITCH_EVENT_SHUTDOWN, SWITCH_EVENT_SUBCLASS_ANY, shutdown_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind shutdown event handler!\n");
- }
-
- memset(&globals, 0, sizeof(globals));
- globals.running = 1;
- globals.threads = 0;
- switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
- switch_core_hash_init(&globals.source_hash, module_pool);
-
-
- /* indicate that the module should continue to be loaded */
- return SWITCH_STATUS_SUCCESS;
-}
-
-SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_portaudio_stream_shutdown)
-{
- globals.running = 0;
- switch_event_unbind_callback(shutdown_event_handler);
-
- while(globals.threads > 0) {
- switch_yield(100000);
- }
-
- Pa_Terminate();
-
- switch_core_hash_destroy(&globals.source_hash);
- return SWITCH_STATUS_SUCCESS;
-}
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
- */
+/*
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005-2009, Anthony Minessale II <anthm(a)freeswitch.org>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II <anthm(a)freeswitch.org>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * mod_portaudio_stream.c -- Portaudio Streaming interface Audio
+ *
+ */
+#include "switch.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "pablio.h"
+#include <string.h>
+
+#define DEFAULT_PREBUFFER_SIZE 1024 * 64
+#define SAMPLE_TYPE paInt16
+#define PREFERRED_RATE 8000
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_stream_load);
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_portaudio_stream_shutdown);
+SWITCH_MODULE_DEFINITION(mod_portaudio_stream, mod_portaudio_stream_load, mod_portaudio_stream_shutdown, NULL);
+static switch_memory_pool_t *module_pool = NULL;
+
+struct portaudio_stream_source;
+
+static struct {
+ int running;
+ int threads;
+ switch_mutex_t *mutex;
+ switch_hash_t *source_hash;
+
+} globals;
+
+
+struct portaudio_stream_context {
+ struct portaudio_stream_source *source;
+ switch_mutex_t *audio_mutex;
+ switch_buffer_t *audio_buffer;
+ int err;
+ const char *func;
+ const char *file;
+ int line;
+ switch_file_handle_t *handle;
+ struct portaudio_stream_context *next;
+};
+
+typedef struct portaudio_stream_context portaudio_stream_context_t;
+
+struct portaudio_stream_source {
+ char *sourcename;
+ int sourcedev;
+ int rate;
+ int interval;
+ char *timer_name;
+ int total;
+ int ready;
+ int stopped;
+ uint8_t channels;
+ switch_size_t samples;
+ uint32_t prebuf;
+ portaudio_stream_context_t *context_list;
+ switch_mutex_t *mutex;
+ switch_memory_pool_t *pool;
+ switch_thread_rwlock_t *rwlock;
+ PABLIO_Stream *audio_stream;
+ switch_frame_t read_frame;
+ switch_timer_t timer;
+ switch_codec_t read_codec;
+ switch_codec_t write_codec;
+ switch_mutex_t *device_lock;
+ unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
+};
+
+typedef struct portaudio_stream_source portaudio_stream_source_t;
+
+
+
+static int get_dev_by_number(char *numstr, int in)
+{
+ int numDevices = Pa_GetDeviceCount();
+ const PaDeviceInfo *pdi;
+ char *end_ptr;
+ int number;
+
+ number = (int) strtol(numstr, &end_ptr, 10);
+
+ if (end_ptr == numstr || number < 0) {
+ return -1;
+ }
+
+ if (number > -1 && number < numDevices && (pdi = Pa_GetDeviceInfo(number))) {
+ if (in && pdi->maxInputChannels) {
+ return number;
+ } else if (!in && pdi->maxOutputChannels) {
+ return number;
+ }
+ }
+
+ return -1;
+}
+
+static int get_dev_by_name(char *name, int in)
+{
+ int i;
+ int numDevices;
+ const PaDeviceInfo *pdi;
+ numDevices = Pa_GetDeviceCount();
+
+ if (numDevices < 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
+ return -2;
+ }
+
+ for (i = 0; i < numDevices; i++) {
+ int match = 0;
+ pdi = Pa_GetDeviceInfo(i);
+
+ if (switch_strlen_zero(name)) {
+ match = 1;
+ } else if (pdi && pdi->name && strstr(pdi->name, name)) {
+ match = 1;
+ }
+
+ if (match) {
+ if (in && pdi->maxInputChannels) {
+ return i;
+ } else if (!in && pdi->maxOutputChannels) {
+ return i;
+ }
+ }
+ }
+
+ return -1;
+}
+
+static switch_status_t engage_device(portaudio_stream_source_t *source,int restart)
+{
+ PaStreamParameters inputParameters,outputParameters;
+ PaError err;
+ int sample_rate = source->rate;
+ int codec_ms = source->interval;
+
+ switch_mutex_init(&source->device_lock, SWITCH_MUTEX_NESTED, module_pool);
+
+ if (source->timer.timer_interface) {
+ switch_core_timer_sync(&source->timer);
+ }
+
+ if (source->audio_stream) {
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ if (!switch_core_codec_ready(&source->read_codec)) {
+ if (switch_core_codec_init(&source->read_codec,
+ "L16",
+ NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
+ NULL) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
+ return SWITCH_STATUS_FALSE;
+ }
+ }
+
+ switch_assert(source->read_codec.implementation);
+
+ if (!switch_core_codec_ready(&source->write_codec) {
+ if (switch_core_codec_init(&source->write_codec,
+ "L16",
+ NULL,
+ sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
+ NULL) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
+ switch_core_codec_destroy(&source->read_codec);
+ return SWITCH_STATUS_FALSE;
+ }
+ }
+
+
+ if (!source->timer.timer_interface) {
+ if (switch_core_timer_init(&source->timer,
+ source->timer_name, codec_ms, source->read_codec.implementation->samples_per_packet,
+ module_pool) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
+ switch_core_codec_destroy(&source->read_codec);
+ switch_core_codec_destroy(&source->write_codec);
+ return SWITCH_STATUS_FALSE;
+ }
+ }
+
+ source->read_frame.rate = sample_rate;
+ source->read_frame.codec = &source->read_codec;
+
+ switch_mutex_lock(source->device_lock);
+ /* LOCKED ************************************************************************************************** */
+ inputParameters.device = source->sourcedev;
+ inputParameters.channelCount = 1;
+ inputParameters.sampleFormat = SAMPLE_TYPE;
+ inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency;
+ inputParameters.hostApiSpecificStreamInfo = NULL;
+ outputParameters.device = source->sourcedev;
+ outputParameters.channelCount = 1;
+ outputParameters.sampleFormat = SAMPLE_TYPE;
+ outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
+ outputParameters.hostApiSpecificStreamInfo = NULL;
+
+
+ err = OpenAudioStream(&source->audio_stream, &inputParameters, NULL, sample_rate, paClipOff,
+ source->read_codec.implementation->samples_per_packet, 0);
+ /* UNLOCKED ************************************************************************************************* */
+ if (err != paNoError) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening audio device retrying\n");
+ switch_yield(1000000);
+ err = OpenAudioStream(&source->audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff,
+ source->read_codec.implementation->samples_per_packet, 0);
+ }
+
+ switch_mutex_unlock(source->device_lock);
+ if (err != paNoError) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open audio device\n");
+ switch_core_codec_destroy(&source->read_codec);
+ switch_core_timer_destroy(&source->timer);
+ return SWITCH_STATUS_FALSE;
+ }
+
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void *obj)
+{
+ portaudio_stream_source_t *source = obj;
+ portaudio_stream_context_t *cp;
+ int samples = 0;
+ int bused, bytesToWrite;
+
+
+ switch_mutex_lock(globals.mutex);
+ globals.threads++;
+ switch_mutex_unlock(globals.mutex);
+
+ if (!source->prebuf) {
+ source->prebuf = DEFAULT_PREBUFFER_SIZE;
+ }
+
+
+
+ switch_mutex_lock(globals.mutex);
+ switch_core_hash_insert(globals.source_hash, source->sourcename, source);
+ switch_mutex_unlock(globals.mutex);
+
+
+ switch_thread_rwlock_create(&source->rwlock, source->pool);
+
+ if (engage_device(source,0)!=SWITCH_STATUS_SUCCESS){
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, " Dev %d cant be engaged !\n",(int) source->sourcedev);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " Dev %d engaged at %d rate!\n",(int) source->sourcedev, (int) source->rate);
+ if (globals.running && !source->stopped) {
+ source->ready = 1;
+
+ if (!source->audio_stream){
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Audio Stream wops!\n");
+ source->stopped = 0;
+ source->ready = 0;
+ } else {
+ while (globals.running && !source->stopped) {
+ samples = 0;
+ switch_mutex_lock(source->device_lock);
+ samples = ReadAudioStream(source->audio_stream, source->databuf,
+ source->read_codec.implementation->samples_per_packet , &source->timer);
+ switch_mutex_unlock(source->device_lock);
+
+
+ if (samples) {
+ bytesToWrite = source->samples;
+ if (samples < bytesToWrite) {
+ bytesToWrite = samples;
+ }
+ bytesToWrite *= source->audio_stream->bytesPerFrame;
+
+ if (source->total) {
+
+ switch_mutex_lock(source->mutex);
+ for (cp = source->context_list; cp; cp = cp->next) {
+
+ switch_mutex_lock(cp->audio_mutex);
+
+ bused = switch_buffer_inuse(cp->audio_buffer);
+ if (bused > source->samples * 768 ) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Leaking stream handle! [%s() %s:%d] %d used %d max\n", cp->func, cp->file,
+ cp->line,(int) bused, (int) ( source->samples * 768));
+ switch_buffer_zero(cp->audio_buffer);
+ } else {
+ switch_buffer_write(cp->audio_buffer, source->databuf, bytesToWrite);
+ }
+
+ switch_mutex_unlock(cp->audio_mutex);
+ }
+ switch_mutex_unlock(source->mutex);
+ }
+
+ }
+
+ }
+ }
+
+ }
+ }
+
+
+ source->ready = 0;
+
+ switch_mutex_lock(globals.mutex);
+ switch_core_hash_delete(globals.source_hash, source->sourcename);
+ switch_mutex_unlock(globals.mutex);
+
+ switch_thread_rwlock_wrlock(source->rwlock);
+ switch_thread_rwlock_unlock(source->rwlock);
+
+
+ switch_mutex_lock(source->device_lock);
+ CloseAudioStream(source->audio_stream);
+ if (switch_core_codec_ready(&source->read_codec)) {
+ switch_core_codec_destroy(&source->read_codec);
+ switch_core_codec_destroy(&source->write_codec);
+ }
+ if (switch_core_codec_ready(&source->write_codec) {
+ switch_core_codec_destroy(&source->write_codec);
+ }
+ switch_mutex_unlock(source->device_lock);
+
+
+ switch_core_destroy_memory_pool(&source->pool);
+
+ switch_mutex_lock(globals.mutex);
+ globals.threads--;
+ switch_mutex_unlock(globals.mutex);
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " thread ending succesfully !\n");
+ switch_thread_exit(thread,SWITCH_STATUS_SUCCESS);
+
+ return NULL;
+}
+
+
+static switch_status_t portaudio_stream_file_open(switch_file_handle_t *handle, const char *path)
+{
+ portaudio_stream_context_t *context ;
+ portaudio_stream_source_t *source;
+ switch_memory_pool_t *pool;
+ switch_status_t status = SWITCH_STATUS_FALSE;
+ switch_thread_t *thread;
+ switch_threadattr_t *thd_attr = NULL;
+ uint32_t rate = PREFERRED_RATE;
+ char *npath ;
+ int devNumber;
+
+
+
+
+
+ handle->pre_buffer_datalen = 0;
+
+ if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This format does not support writing! (yet)\n");
+ return status;
+ }
+
+ npath = switch_core_strdup(module_pool, path);
+
+ int tmp = handle->samplerate;
+ if (tmp == 8000 || tmp == 16000 || tmp == 32000 || tmp == 48000) {
+ rate = tmp;
+ }
+
+ if (*path == '#') {
+ devNumber = get_dev_by_number(npath + 1, 1);
+ } else {
+ devNumber = get_dev_by_name(npath , 1);
+ }
+ npath = switch_mprintf("device-%d at %d",devNumber,rate);
+
+
+
+ switch_mutex_lock(globals.mutex);
+ source = switch_core_hash_find(globals.source_hash, npath);
+
+ /* dev isnt there, try to start thread */
+ if (!source) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, " source isnt Created, create and start thread!\n");
+
+ if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, " :S no pool\n");
+ } else {
+ source = switch_core_alloc(pool, sizeof(*source));
+ if (source!=NULL){
+ source->pool = pool;
+ source->sourcedev = devNumber;
+ source->sourcename = switch_core_strdup(source->pool, npath);
+ source->rate = rate;
+ source->interval = 20;
+ source->channels = 1;
+ source->timer_name = "soft";
+ source->prebuf = DEFAULT_PREBUFFER_SIZE;
+ source->stopped = 0;
+ source->ready = 0;
+ source->samples = switch_samples_per_packet(source->rate, source->interval);
+
+
+
+ switch_mutex_init(&source->mutex, SWITCH_MUTEX_NESTED, source->pool);
+
+
+
+ switch_threadattr_create(&thd_attr, source->pool);
+ switch_threadattr_detach_set(thd_attr, 1);
+
+ switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+ switch_thread_create(&thread, thd_attr, read_stream_thread, source, source->pool);
+
+ }
+
+ }
+
+ }
+ switch_mutex_unlock(globals.mutex);
+ switch_yield(1000000);
+ /* dev already engaged */
+ if (source) {
+
+ /*wait for source to be ready*/
+
+ while(source->ready==0){switch_yield(100000);}
+
+
+ if (switch_thread_rwlock_tryrdlock(source->rwlock) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, " error rwlock !\n");
+ source = NULL;
+ }
+
+ }
+
+
+
+ if (source) {
+ status = SWITCH_STATUS_SUCCESS;
+
+ if ((context = switch_core_alloc(handle->memory_pool, sizeof(*context))) == 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, " error allocating context!\n");
+ status = SWITCH_STATUS_MEMERR;
+ } else {
+ /* everything goes fine at this point */
+ handle->samples = 0;
+ handle->samplerate = source->rate;
+ handle->channels = 1;
+ handle->format = 0;
+ handle->sections = 0;
+ handle->seekable = 0;
+ handle->speed = 0;
+ handle->private_info = context;
+ handle->interval = source->interval;
+
+
+ switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, handle->memory_pool);
+ if (switch_buffer_create_dynamic(&context->audio_buffer, 512, 1024, 0) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
+ status = SWITCH_STATUS_MEMERR;
+ } else {
+ /* context created... then continue */
+ context->source = source;
+ context->file = handle->file;
+ context->func = handle->func;
+ context->line = handle->line;
+ context->handle = handle;
+ switch_mutex_lock(source->mutex);
+ context->next = source->context_list;
+ source->context_list = context;
+ source->total++;
+ switch_mutex_unlock(source->mutex);
+
+ }
+ }
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown source %s\n", path);
+ status = SWITCH_STATUS_FALSE;
+ }
+
+
+
+ return status;
+}
+
+
+static switch_status_t portaudio_stream_file_close(switch_file_handle_t *handle)
+{
+ portaudio_stream_context_t *cp, *last = NULL, *context = handle->private_info;
+
+
+ switch_mutex_lock(context->source->mutex);
+ for (cp = context->source->context_list; cp; cp = cp->next) {
+ if (cp == context) {
+ if (last) {
+ last->next = cp->next;
+ } else {
+ context->source->context_list = cp->next;
+ }
+ break;
+ }
+ last = cp;
+ }
+ context->source->total--;
+ switch_mutex_unlock(context->source->mutex);
+ switch_buffer_destroy(&context->audio_buffer);
+ switch_thread_rwlock_unlock(context->source->rwlock);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+
+static switch_status_t portaudio_stream_file_read(switch_file_handle_t *handle, void *data, size_t *len)
+{
+ portaudio_stream_context_t *context = handle->private_info;
+ switch_size_t bytes = 0;
+ int bytesPerSample = context->source->audio_stream->bytesPerFrame;
+ size_t need = *len * bytesPerSample;
+
+
+
+ if (!context->source->ready) {
+ *len = 0;
+ return SWITCH_STATUS_FALSE;
+ }
+
+ switch_mutex_lock(context->audio_mutex);
+ if ((bytes = switch_buffer_read(context->audio_buffer, data, need))) {
+ *len = bytes / bytesPerSample;
+ } else {
+ if (need > 2560) {
+ need = 2560;
+ }
+ memset(data, 255, need);
+ *len = need / bytesPerSample;
+ }
+ switch_mutex_unlock(context->audio_mutex);
+
+
+
+ handle->sample_count += *len;
+ return SWITCH_STATUS_SUCCESS;
+
+
+}
+
+/* Registration */
+
+static char *supported_formats[SWITCH_MAX_CODECS] = { 0 };
+
+static void shutdown_event_handler(switch_event_t *event)
+{
+ globals.running = 0;
+}
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_stream_load)
+{
+ switch_file_interface_t *file_interface;
+ supported_formats[0] = "portaudio_stream";
+
+ module_pool = pool;
+
+ Pa_Initialize();
+
+ *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+ file_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE);
+ file_interface->interface_name = modname;
+ file_interface->extens = supported_formats;
+ file_interface->file_open = portaudio_stream_file_open;
+ file_interface->file_close = portaudio_stream_file_close;
+ file_interface->file_read = portaudio_stream_file_read;
+
+ if (switch_event_bind(modname, SWITCH_EVENT_SHUTDOWN, SWITCH_EVENT_SUBCLASS_ANY, shutdown_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind shutdown event handler!\n");
+ }
+
+ memset(&globals, 0, sizeof(globals));
+ globals.running = 1;
+ globals.threads = 0;
+ switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
+ switch_core_hash_init(&globals.source_hash, module_pool);
+
+
+ /* indicate that the module should continue to be loaded */
+ return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_portaudio_stream_shutdown)
+{
+ globals.running = 0;
+ switch_event_unbind_callback(shutdown_event_handler);
+
+ while(globals.threads > 0) {
+ switch_yield(100000);
+ }
+
+ Pa_Terminate();
+
+ switch_core_hash_destroy(&globals.source_hash);
+ return SWITCH_STATUS_SUCCESS;
+}
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
+ */
1
0
Author: mikej
Date: Wed May 27 18:07:50 2009
New Revision: 13473
Log:
dos2unix
Modified:
freeswitch/trunk/src/inet_pton.c
freeswitch/trunk/src/switch_dso.c
Modified: freeswitch/trunk/src/inet_pton.c
==============================================================================
--- freeswitch/trunk/src/inet_pton.c (original)
+++ freeswitch/trunk/src/inet_pton.c Wed May 27 18:07:50 2009
@@ -1,238 +1,238 @@
-/* This is from the BIND 4.9.4 release, modified to compile by itself */
-
-/* Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#ifndef HAVE_INET_PTON
-
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#include <string.h>
-#include <errno.h>
-
-#define IN6ADDRSZ 16
-#define INADDRSZ 4
-#define INT16SZ 2
-
-#ifdef WIN32
-#include <winsock2.h>
-#define EAFNOSUPPORT WSAEAFNOSUPPORT
-#endif
-
-/*
- * WARNING: Don't even consider trying to compile this on a system where
- * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
- */
-
-static int inet_pton4(const char *src, unsigned char *dst);
-#ifdef ENABLE_IPV6
-static int inet_pton6(const char *src, unsigned char *dst);
-#endif
-
-/* int
- * inet_pton(af, src, dst)
- * convert from presentation format (which usually means ASCII printable)
- * to network format (which is usually some kind of binary format).
- * return:
- * 1 if the address was valid for the specified address family
- * 0 if the address wasn't valid (`dst' is untouched in this case)
- * -1 if some other error occurred (`dst' is untouched in this case, too)
- * author:
- * Paul Vixie, 1996.
- */
-int
-switch_inet_pton(int af, const char *src, void *dst)
-{
- switch (af) {
- case AF_INET:
- return (inet_pton4(src, (unsigned char *)dst));
-#ifdef ENABLE_IPV6
-#ifndef AF_INET6
-#define AF_INET6 (AF_MAX+1) /* just to let this compile */
-#endif
- case AF_INET6:
- return (inet_pton6(src, (unsigned char *)dst));
-#endif
- default:
- errno = EAFNOSUPPORT;
- return (-1);
- }
- /* NOTREACHED */
-}
-
-/* int
- * inet_pton4(src, dst)
- * like inet_aton() but without all the hexadecimal and shorthand.
- * return:
- * 1 if `src' is a valid dotted quad, else 0.
- * notice:
- * does not touch `dst' unless it's returning 1.
- * author:
- * Paul Vixie, 1996.
- */
-static int
-inet_pton4(const char *src, unsigned char *dst)
-{
- static const char digits[] = "0123456789";
- int saw_digit, octets, ch;
- unsigned char tmp[INADDRSZ], *tp;
-
- saw_digit = 0;
- octets = 0;
- tp = tmp;
- *tp = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- if ((pch = strchr(digits, ch)) != NULL) {
- unsigned int val = *tp * 10 + (unsigned int)(pch - digits);
-
- if (val > 255)
- return (0);
- *tp = (unsigned char)val;
- if (! saw_digit) {
- if (++octets > 4)
- return (0);
- saw_digit = 1;
- }
- } else if (ch == '.' && saw_digit) {
- if (octets == 4)
- return (0);
- *++tp = 0;
- saw_digit = 0;
- } else
- return (0);
- }
- if (octets < 4)
- return (0);
- /* bcopy(tmp, dst, INADDRSZ); */
- memcpy(dst, tmp, INADDRSZ);
- return (1);
-}
-
-#ifdef ENABLE_IPV6
-/* int
- * inet_pton6(src, dst)
- * convert presentation level address to network order binary form.
- * return:
- * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
- * notice:
- * (1) does not touch `dst' unless it's returning 1.
- * (2) :: in a full address is silently ignored.
- * credit:
- * inspired by Mark Andrews.
- * author:
- * Paul Vixie, 1996.
- */
-static int
-inet_pton6(const char *src, unsigned char *dst)
-{
- static const char xdigits_l[] = "0123456789abcdef",
- xdigits_u[] = "0123456789ABCDEF";
- unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
- const char *xdigits, *curtok;
- int ch, saw_xdigit;
- unsigned int val;
-
- memset((tp = tmp), 0, IN6ADDRSZ);
- endp = tp + IN6ADDRSZ;
- colonp = NULL;
- /* Leading :: requires some special handling. */
- if (*src == ':')
- if (*++src != ':')
- return (0);
- curtok = src;
- saw_xdigit = 0;
- val = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
- pch = strchr((xdigits = xdigits_u), ch);
- if (pch != NULL) {
- val <<= 4;
- val |= (pch - xdigits);
- if (val > 0xffff)
- return (0);
- saw_xdigit = 1;
- continue;
- }
- if (ch == ':') {
- curtok = src;
- if (!saw_xdigit) {
- if (colonp)
- return (0);
- colonp = tp;
- continue;
- }
- if (tp + INT16SZ > endp)
- return (0);
- *tp++ = (unsigned char) (val >> 8) & 0xff;
- *tp++ = (unsigned char) val & 0xff;
- saw_xdigit = 0;
- val = 0;
- continue;
- }
- if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
- inet_pton4(curtok, tp) > 0) {
- tp += INADDRSZ;
- saw_xdigit = 0;
- break; /* '\0' was seen by inet_pton4(). */
- }
- return (0);
- }
- if (saw_xdigit) {
- if (tp + INT16SZ > endp)
- return (0);
- *tp++ = (unsigned char) (val >> 8) & 0xff;
- *tp++ = (unsigned char) val & 0xff;
- }
- if (colonp != NULL) {
- /*
- * Since some memmove()'s erroneously fail to handle
- * overlapping regions, we'll do the shift by hand.
- */
- const int n = tp - colonp;
- int i;
-
- for (i = 1; i <= n; i++) {
- endp[- i] = colonp[n - i];
- colonp[n - i] = 0;
- }
- tp = endp;
- }
- if (tp != endp)
- return (0);
- /* bcopy(tmp, dst, IN6ADDRSZ); */
- memcpy(dst, tmp, IN6ADDRSZ);
- return (1);
-}
-#endif /* ENABLE_IPV6 */
-
-#endif /* HAVE_INET_PTON */
+/* This is from the BIND 4.9.4 release, modified to compile by itself */
+
+/* Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifndef HAVE_INET_PTON
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#include <string.h>
+#include <errno.h>
+
+#define IN6ADDRSZ 16
+#define INADDRSZ 4
+#define INT16SZ 2
+
+#ifdef WIN32
+#include <winsock2.h>
+#define EAFNOSUPPORT WSAEAFNOSUPPORT
+#endif
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static int inet_pton4(const char *src, unsigned char *dst);
+#ifdef ENABLE_IPV6
+static int inet_pton6(const char *src, unsigned char *dst);
+#endif
+
+/* int
+ * inet_pton(af, src, dst)
+ * convert from presentation format (which usually means ASCII printable)
+ * to network format (which is usually some kind of binary format).
+ * return:
+ * 1 if the address was valid for the specified address family
+ * 0 if the address wasn't valid (`dst' is untouched in this case)
+ * -1 if some other error occurred (`dst' is untouched in this case, too)
+ * author:
+ * Paul Vixie, 1996.
+ */
+int
+switch_inet_pton(int af, const char *src, void *dst)
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_pton4(src, (unsigned char *)dst));
+#ifdef ENABLE_IPV6
+#ifndef AF_INET6
+#define AF_INET6 (AF_MAX+1) /* just to let this compile */
+#endif
+ case AF_INET6:
+ return (inet_pton6(src, (unsigned char *)dst));
+#endif
+ default:
+ errno = EAFNOSUPPORT;
+ return (-1);
+ }
+ /* NOTREACHED */
+}
+
+/* int
+ * inet_pton4(src, dst)
+ * like inet_aton() but without all the hexadecimal and shorthand.
+ * return:
+ * 1 if `src' is a valid dotted quad, else 0.
+ * notice:
+ * does not touch `dst' unless it's returning 1.
+ * author:
+ * Paul Vixie, 1996.
+ */
+static int
+inet_pton4(const char *src, unsigned char *dst)
+{
+ static const char digits[] = "0123456789";
+ int saw_digit, octets, ch;
+ unsigned char tmp[INADDRSZ], *tp;
+
+ saw_digit = 0;
+ octets = 0;
+ tp = tmp;
+ *tp = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr(digits, ch)) != NULL) {
+ unsigned int val = *tp * 10 + (unsigned int)(pch - digits);
+
+ if (val > 255)
+ return (0);
+ *tp = (unsigned char)val;
+ if (! saw_digit) {
+ if (++octets > 4)
+ return (0);
+ saw_digit = 1;
+ }
+ } else if (ch == '.' && saw_digit) {
+ if (octets == 4)
+ return (0);
+ *++tp = 0;
+ saw_digit = 0;
+ } else
+ return (0);
+ }
+ if (octets < 4)
+ return (0);
+ /* bcopy(tmp, dst, INADDRSZ); */
+ memcpy(dst, tmp, INADDRSZ);
+ return (1);
+}
+
+#ifdef ENABLE_IPV6
+/* int
+ * inet_pton6(src, dst)
+ * convert presentation level address to network order binary form.
+ * return:
+ * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
+ * notice:
+ * (1) does not touch `dst' unless it's returning 1.
+ * (2) :: in a full address is silently ignored.
+ * credit:
+ * inspired by Mark Andrews.
+ * author:
+ * Paul Vixie, 1996.
+ */
+static int
+inet_pton6(const char *src, unsigned char *dst)
+{
+ static const char xdigits_l[] = "0123456789abcdef",
+ xdigits_u[] = "0123456789ABCDEF";
+ unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
+ const char *xdigits, *curtok;
+ int ch, saw_xdigit;
+ unsigned int val;
+
+ memset((tp = tmp), 0, IN6ADDRSZ);
+ endp = tp + IN6ADDRSZ;
+ colonp = NULL;
+ /* Leading :: requires some special handling. */
+ if (*src == ':')
+ if (*++src != ':')
+ return (0);
+ curtok = src;
+ saw_xdigit = 0;
+ val = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
+ pch = strchr((xdigits = xdigits_u), ch);
+ if (pch != NULL) {
+ val <<= 4;
+ val |= (pch - xdigits);
+ if (val > 0xffff)
+ return (0);
+ saw_xdigit = 1;
+ continue;
+ }
+ if (ch == ':') {
+ curtok = src;
+ if (!saw_xdigit) {
+ if (colonp)
+ return (0);
+ colonp = tp;
+ continue;
+ }
+ if (tp + INT16SZ > endp)
+ return (0);
+ *tp++ = (unsigned char) (val >> 8) & 0xff;
+ *tp++ = (unsigned char) val & 0xff;
+ saw_xdigit = 0;
+ val = 0;
+ continue;
+ }
+ if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
+ inet_pton4(curtok, tp) > 0) {
+ tp += INADDRSZ;
+ saw_xdigit = 0;
+ break; /* '\0' was seen by inet_pton4(). */
+ }
+ return (0);
+ }
+ if (saw_xdigit) {
+ if (tp + INT16SZ > endp)
+ return (0);
+ *tp++ = (unsigned char) (val >> 8) & 0xff;
+ *tp++ = (unsigned char) val & 0xff;
+ }
+ if (colonp != NULL) {
+ /*
+ * Since some memmove()'s erroneously fail to handle
+ * overlapping regions, we'll do the shift by hand.
+ */
+ const int n = tp - colonp;
+ int i;
+
+ for (i = 1; i <= n; i++) {
+ endp[- i] = colonp[n - i];
+ colonp[n - i] = 0;
+ }
+ tp = endp;
+ }
+ if (tp != endp)
+ return (0);
+ /* bcopy(tmp, dst, IN6ADDRSZ); */
+ memcpy(dst, tmp, IN6ADDRSZ);
+ return (1);
+}
+#endif /* ENABLE_IPV6 */
+
+#endif /* HAVE_INET_PTON */
Modified: freeswitch/trunk/src/switch_dso.c
==============================================================================
--- freeswitch/trunk/src/switch_dso.c (original)
+++ freeswitch/trunk/src/switch_dso.c Wed May 27 18:07:50 2009
@@ -1,139 +1,139 @@
-/*
- * Cross Platform dso/dll load abstraction
- * Copyright(C) 2008 Michael Jerris
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so.
- *
- * This work is provided under this license on an "as is" basis, without warranty of any kind,
- * either expressed or implied, including, without limitation, warranties that the covered code
- * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
- * risk as to the quality and performance of the covered code is with you. Should any covered
- * code prove defective in any respect, you (not the initial developer or any other contributor)
- * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
- * constitutes an essential part of this license. No use of any covered code is authorized hereunder
- * except under this disclaimer.
- *
- */
-
-#include <switch.h>
-#include "switch_dso.h"
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef WIN32
-
-SWITCH_DECLARE(void) switch_dso_destroy(switch_dso_lib_t *lib) {
- if (lib && *lib) {
- FreeLibrary(*lib);
- *lib = NULL;
- }
-}
-
-SWITCH_DECLARE(switch_dso_lib_t) switch_dso_open(const char *path, int global, char **err) {
- HINSTANCE lib;
-
- lib = LoadLibraryEx(path, NULL, 0);
-
- if (!lib) {
- LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
- }
-
- if (!lib) {
- DWORD error = GetLastError();
- *err = switch_mprintf("dll open error [%ul]\n", error);
- }
-
- return lib;
-}
-
-SWITCH_DECLARE(switch_dso_func_t) switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
- FARPROC func = GetProcAddress(lib, sym);
- if (!func) {
- DWORD error = GetLastError();
- *err = switch_mprintf("dll sym error [%ul]\n", error);
- }
- return (switch_dso_func_t)func;
-}
-
-SWITCH_DECLARE(void *) switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
- FARPROC addr = GetProcAddress(lib, sym);
- if (!addr) {
- DWORD error = GetLastError();
- *err = switch_mprintf("dll sym error [%ul]\n", error);
- }
- return (void *)(intptr_t)addr;
-}
-
-
-#else
-/*
-** {========================================================================
-** This is an implementation of loadlib based on the dlfcn interface.
-** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
-** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least
-** as an emulation layer on top of native functions.
-** =========================================================================
-*/
-
-
-#include <dlfcn.h>
-
-void switch_dso_destroy(switch_dso_lib_t *lib) {
- if (lib && *lib) {
- dlclose(*lib);
- *lib = NULL;
- }
-}
-
-switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
- void *lib;
-
- if (global) {
- lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
- } else {
- lib = dlopen(path, RTLD_NOW | RTLD_LOCAL);
- }
-
- if (lib == NULL) {
- const char *dlerr = dlerror();
- /* Work around broken uclibc returning NULL on both dlopen() and dlerror() */
- if (dlerr) {
- *err = strdup(dlerr);
- } else {
- *err = strdup("Unknown error");
- }
- }
- return lib;
-}
-
-switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
- void *func = dlsym(lib, sym);
- if (!func) {
- *err = strdup(dlerror());
- }
- return (switch_dso_func_t)(intptr_t)func;
-}
-
-void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
- void *addr = dlsym(lib, sym);
- if (!addr) {
- *err = strdup(dlerror());
- }
- return addr;
-}
-
-#endif
-/* }====================================================== */
-
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4
- */
+/*
+ * Cross Platform dso/dll load abstraction
+ * Copyright(C) 2008 Michael Jerris
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so.
+ *
+ * This work is provided under this license on an "as is" basis, without warranty of any kind,
+ * either expressed or implied, including, without limitation, warranties that the covered code
+ * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
+ * risk as to the quality and performance of the covered code is with you. Should any covered
+ * code prove defective in any respect, you (not the initial developer or any other contributor)
+ * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
+ * constitutes an essential part of this license. No use of any covered code is authorized hereunder
+ * except under this disclaimer.
+ *
+ */
+
+#include <switch.h>
+#include "switch_dso.h"
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef WIN32
+
+SWITCH_DECLARE(void) switch_dso_destroy(switch_dso_lib_t *lib) {
+ if (lib && *lib) {
+ FreeLibrary(*lib);
+ *lib = NULL;
+ }
+}
+
+SWITCH_DECLARE(switch_dso_lib_t) switch_dso_open(const char *path, int global, char **err) {
+ HINSTANCE lib;
+
+ lib = LoadLibraryEx(path, NULL, 0);
+
+ if (!lib) {
+ LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+ }
+
+ if (!lib) {
+ DWORD error = GetLastError();
+ *err = switch_mprintf("dll open error [%ul]\n", error);
+ }
+
+ return lib;
+}
+
+SWITCH_DECLARE(switch_dso_func_t) switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+ FARPROC func = GetProcAddress(lib, sym);
+ if (!func) {
+ DWORD error = GetLastError();
+ *err = switch_mprintf("dll sym error [%ul]\n", error);
+ }
+ return (switch_dso_func_t)func;
+}
+
+SWITCH_DECLARE(void *) switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+ FARPROC addr = GetProcAddress(lib, sym);
+ if (!addr) {
+ DWORD error = GetLastError();
+ *err = switch_mprintf("dll sym error [%ul]\n", error);
+ }
+ return (void *)(intptr_t)addr;
+}
+
+
+#else
+/*
+** {========================================================================
+** This is an implementation of loadlib based on the dlfcn interface.
+** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
+** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least
+** as an emulation layer on top of native functions.
+** =========================================================================
+*/
+
+
+#include <dlfcn.h>
+
+void switch_dso_destroy(switch_dso_lib_t *lib) {
+ if (lib && *lib) {
+ dlclose(*lib);
+ *lib = NULL;
+ }
+}
+
+switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
+ void *lib;
+
+ if (global) {
+ lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
+ } else {
+ lib = dlopen(path, RTLD_NOW | RTLD_LOCAL);
+ }
+
+ if (lib == NULL) {
+ const char *dlerr = dlerror();
+ /* Work around broken uclibc returning NULL on both dlopen() and dlerror() */
+ if (dlerr) {
+ *err = strdup(dlerr);
+ } else {
+ *err = strdup("Unknown error");
+ }
+ }
+ return lib;
+}
+
+switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+ void *func = dlsym(lib, sym);
+ if (!func) {
+ *err = strdup(dlerror());
+ }
+ return (switch_dso_func_t)(intptr_t)func;
+}
+
+void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+ void *addr = dlsym(lib, sym);
+ if (!addr) {
+ *err = strdup(dlerror());
+ }
+ return addr;
+}
+
+#endif
+/* }====================================================== */
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4
+ */
1
0