diff --git a/.indent.pro b/.indent.pro new file mode 100644 index 0000000000..277412ce04 --- /dev/null +++ b/.indent.pro @@ -0,0 +1 @@ +-brs -npsl -di0 -br -ce -d0 -cli0 -npcs -nfc1 -ut -i4 -ts4 -l120 -cs -T size_t -T pieces -T switch_file_t -T switch_thread_cond_t -T switch_thread -T switch_threadattr_t -T switch_thread_start_t -T switch_socket_t -T switch_sockaddr_t -T switch_memory_pool -T switch_pollfd_t -T switch_pollset_t -T switch_time_t -T switch_time_exp_t -T switch_hash -T switch_hash_index_t -T switch_strmatch_pattern -T switch_uuid_t -T switch_queue_t -T switch_mutex_t -T __int8 -T __int16 -T __int32 -T __int64 -T int8_t -T int16_t -T int32_t -T int64_t -T long -T switch_core_db -T switch_core_session_message -T switch_audio_resampler -T switch_event_header -T switch_event -T switch_event_subclass -T switch_event_node -T switch_loadable_module -T switch_frame -T switch_channel -T switch_endpoint_interface -T switch_timer_interface -T switch_dialplan_interface -T switch_codec_interface -T switch_application_interface -T switch_api_interface -T switch_file_interface -T switch_file_handle -T switch_core_session -T switch_loadable_module_interface -T switch_caller_profile -T switch_caller_step -T switch_caller_extension -T switch_caller_application -T switch_event_handler_table -T switch_timer -T switch_codec -T switch_core_thread_session -T switch_codec_implementation -T switch_io_event_hook_outgoing_channel -T switch_io_event_hook_answer_channel -T switch_io_event_hook_receive_message -T switch_io_event_hook_read_frame -T switch_io_event_hook_write_frame -T switch_io_event_hook_kill_channel -T switch_io_event_hook_waitfor_read -T switch_io_event_hook_waitfor_write -T switch_io_event_hook_send_dtmf -T switch_io_routines -T switch_io_event_hooks -T switch_buffer -T switch_codec_settings -T switch_config -T switch_lock_flag -T switch_core_session_message_t -T switch_stack_t -T switch_status -T switch_text_channel -T switch_channel_state -T switch_channel_flag -T switch_signal -T switch_codec_flag -T switch_codec_type -T switch_timer_flag -T switch_file_flag -T switch_io_flag -T switch_event_t \ No newline at end of file diff --git a/AUTHORS b/AUTHORS index e69de29bb2..021867cc56 100644 --- a/AUTHORS +++ b/AUTHORS @@ -0,0 +1,25 @@ +The Initial Developer of the Original Code is +Anthony Minessale II +Portions created by the Initial Developer are Copyright (C) +the Initial Developer. All Rights Reserved. + +The PRIMARY AUTHORS are (and/or have been): + + Anthony Minessale II - Primary developer of all core components + and many of the included modules. Much of freeswitch is based on his work. + + Michael Jerris - Windows porter and responsible for the + windows\msvc build system. + + +And here is an inevitably incomplete list of MUCH-APPRECIATED CONTRIBUTORS -- +people who have submitted patches, reported bugs, and generally made Freeswitch +that much better: + + Joshua Colp - For his help making mod_exosip possible, and for just being a swell guy! + Brian K. West - For countless hours of work on BSD and Mac support, finding countless bugs, + and moral support. + +A big THANK YOU goes to: + + diff --git a/COPYING b/COPYING index d60c31a97a..1bf2b1279d 100644 --- a/COPYING +++ b/COPYING @@ -1,340 +1,471 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 + MOZILLA PUBLIC LICENSE + Version 1.1 - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. + --------------- - Preamble +1. Definitions. - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. + 1.0.1. "Commercial Use" means distribution or otherwise making the + Covered Code available to a third party. - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. + 1.1. "Contributor" means each entity that creates or contributes to + the creation of Modifications. - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. + 1.2. "Contributor Version" means the combination of the Original + Code, prior Modifications used by a Contributor, and the Modifications + made by that particular Contributor. - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. + 1.3. "Covered Code" means the Original Code or Modifications or the + combination of the Original Code and Modifications, in each case + including portions thereof. - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. + 1.4. "Electronic Distribution Mechanism" means a mechanism generally + accepted in the software development community for the electronic + transfer of data. - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. + 1.5. "Executable" means Covered Code in any form other than Source + Code. - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. + 1.6. "Initial Developer" means the individual or entity identified + as the Initial Developer in the Source Code notice required by Exhibit + A. - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + 1.7. "Larger Work" means a work which combines Covered Code or + portions thereof with code not governed by the terms of this License. - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". + 1.8. "License" means this document. -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. + 1.8.1. "Licensable" means having the right to grant, to the maximum + extent possible, whether at the time of the initial grant or + subsequently acquired, any and all of the rights conveyed herein. - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. + 1.9. "Modifications" means any addition to or deletion from the + substance or structure of either the Original Code or any previous + Modifications. When Covered Code is released as a series of files, a + Modification is: + A. Any addition to or deletion from the contents of a file + containing Original Code or previous Modifications. -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. + B. Any new file that contains any part of the Original Code or + previous Modifications. - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: + 1.10. "Original Code" means Source Code of computer software code + which is described in the Source Code notice required by Exhibit A as + Original Code, and which, at the time of its release under this + License is not already Covered Code governed by this License. - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. + 1.10.1. "Patent Claims" means any patent claim(s), now owned or + hereafter acquired, including without limitation, method, process, + and apparatus claims, in any patent Licensable by grantor. - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. + 1.11. "Source Code" means the preferred form of the Covered Code for + making modifications to it, including all modules it contains, plus + any associated interface definition files, scripts used to control + compilation and installation of an Executable, or source code + differential comparisons against either the Original Code or another + well known, available Covered Code of the Contributor's choice. The + Source Code can be in a compressed or archival form, provided the + appropriate decompression or de-archiving software is widely available + for no charge. - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. + 1.12. "You" (or "Your") means an individual or a legal entity + exercising rights under, and complying with all of the terms of, this + License or a future version of this License issued under Section 6.1. + For legal entities, "You" includes any entity which controls, is + controlled by, or is under common control with You. For purposes of + this definition, "control" means (a) the power, direct or indirect, + to cause the direction or management of such entity, whether by + contract or otherwise, or (b) ownership of more than fifty percent + (50%) of the outstanding shares or beneficial ownership of such + entity. -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. +2. Source Code License. -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. + 2.1. The Initial Developer Grant. + The Initial Developer hereby grants You a world-wide, royalty-free, + non-exclusive license, subject to third party intellectual property + claims: + (a) under intellectual property rights (other than patent or + trademark) Licensable by Initial Developer to use, reproduce, + modify, display, perform, sublicense and distribute the Original + Code (or portions thereof) with or without Modifications, and/or + as part of a Larger Work; and - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: + (b) under Patents Claims infringed by the making, using or + selling of Original Code, to make, have made, use, practice, + sell, and offer for sale, and/or otherwise dispose of the + Original Code (or portions thereof). - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, + (c) the licenses granted in this Section 2.1(a) and (b) are + effective on the date Initial Developer first distributes + Original Code under the terms of this License. - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, + (d) Notwithstanding Section 2.1(b) above, no patent license is + granted: 1) for code that You delete from the Original Code; 2) + separate from the Original Code; or 3) for infringements caused + by: i) the modification of the Original Code or ii) the + combination of the Original Code with other software or devices. - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) + 2.2. Contributor Grant. + Subject to third party intellectual property claims, each Contributor + hereby grants You a world-wide, royalty-free, non-exclusive license -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. + (a) under intellectual property rights (other than patent or + trademark) Licensable by Contributor, to use, reproduce, modify, + display, perform, sublicense and distribute the Modifications + created by such Contributor (or portions thereof) either on an + unmodified basis, with other Modifications, as Covered Code + and/or as part of a Larger Work; and -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. + (b) under Patent Claims infringed by the making, using, or + selling of Modifications made by that Contributor either alone + and/or in combination with its Contributor Version (or portions + of such combination), to make, use, sell, offer for sale, have + made, and/or otherwise dispose of: 1) Modifications made by that + Contributor (or portions thereof); and 2) the combination of + Modifications made by that Contributor with its Contributor + Version (or portions of such combination). - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. + (c) the licenses granted in Sections 2.2(a) and 2.2(b) are + effective on the date Contributor first makes Commercial Use of + the Covered Code. - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. + (d) Notwithstanding Section 2.2(b) above, no patent license is + granted: 1) for any code that Contributor has deleted from the + Contributor Version; 2) separate from the Contributor Version; + 3) for infringements caused by: i) third party modifications of + Contributor Version or ii) the combination of Modifications made + by that Contributor with other software (except as part of the + Contributor Version) or other devices; or 4) under Patent Claims + infringed by Covered Code in the absence of Modifications made by + that Contributor. - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. +3. Distribution Obligations. -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. + 3.1. Application of License. + The Modifications which You create or to which You contribute are + governed by the terms of this License, including without limitation + Section 2.2. The Source Code version of Covered Code may be + distributed only under the terms of this License or a future version + of this License released under Section 6.1, and You must include a + copy of this License with every copy of the Source Code You + distribute. You may not offer or impose any terms on any Source Code + version that alters or restricts the applicable version of this + License or the recipients' rights hereunder. However, You may include + an additional document offering the additional rights described in + Section 3.5. -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. + 3.2. Availability of Source Code. + Any Modification which You create or to which You contribute must be + made available in Source Code form under the terms of this License + either on the same media as an Executable version or via an accepted + Electronic Distribution Mechanism to anyone to whom you made an + Executable version available; and if made available via Electronic + Distribution Mechanism, must remain available for at least twelve (12) + months after the date it initially became available, or at least six + (6) months after a subsequent version of that particular Modification + has been made available to such recipients. You are responsible for + ensuring that the Source Code version remains available even if the + Electronic Distribution Mechanism is maintained by a third party. -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. + 3.3. Description of Modifications. + You must cause all Covered Code to which You contribute to contain a + file documenting the changes You made to create that Covered Code and + the date of any change. You must include a prominent statement that + the Modification is derived, directly or indirectly, from Original + Code provided by the Initial Developer and including the name of the + Initial Developer in (a) the Source Code, and (b) in any notice in an + Executable version or related documentation in which You describe the + origin or ownership of the Covered Code. - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. + 3.4. Intellectual Property Matters + (a) Third Party Claims. + If Contributor has knowledge that a license under a third party's + intellectual property rights is required to exercise the rights + granted by such Contributor under Sections 2.1 or 2.2, + Contributor must include a text file with the Source Code + distribution titled "LEGAL" which describes the claim and the + party making the claim in sufficient detail that a recipient will + know whom to contact. If Contributor obtains such knowledge after + the Modification is made available as described in Section 3.2, + Contributor shall promptly modify the LEGAL file in all copies + Contributor makes available thereafter and shall take other steps + (such as notifying appropriate mailing lists or newsgroups) + reasonably calculated to inform those who received the Covered + Code that new knowledge has been obtained. -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. + (b) Contributor APIs. + If Contributor's Modifications include an application programming + interface and Contributor has knowledge of patent licenses which + are reasonably necessary to implement that API, Contributor must + also include this information in the LEGAL file. - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. + (c) Representations. + Contributor represents that, except as disclosed pursuant to + Section 3.4(a) above, Contributor believes that Contributor's + Modifications are Contributor's original creation(s) and/or + Contributor has sufficient rights to grant the rights conveyed by + this License. - NO WARRANTY + 3.5. Required Notices. + You must duplicate the notice in Exhibit A in each file of the Source + Code. If it is not possible to put such notice in a particular Source + Code file due to its structure, then You must include such notice in a + location (such as a relevant directory) where a user would be likely + to look for such a notice. If You created one or more Modification(s) + You may add your name as a Contributor to the notice described in + Exhibit A. You must also duplicate this License in any documentation + for the Source Code where You describe recipients' rights or ownership + rights relating to Covered Code. You may choose to offer, and to + charge a fee for, warranty, support, indemnity or liability + obligations to one or more recipients of Covered Code. However, You + may do so only on Your own behalf, and not on behalf of the Initial + Developer or any Contributor. You must make it absolutely clear than + any such warranty, support, indemnity or liability obligation is + offered by You alone, and You hereby agree to indemnify the Initial + Developer and every Contributor for any liability incurred by the + Initial Developer or such Contributor as a result of warranty, + support, indemnity or liability terms You offer. - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. + 3.6. Distribution of Executable Versions. + You may distribute Covered Code in Executable form only if the + requirements of Section 3.1-3.5 have been met for that Covered Code, + and if You include a notice stating that the Source Code version of + the Covered Code is available under the terms of this License, + including a description of how and where You have fulfilled the + obligations of Section 3.2. The notice must be conspicuously included + in any notice in an Executable version, related documentation or + collateral in which You describe recipients' rights relating to the + Covered Code. You may distribute the Executable version of Covered + Code or ownership rights under a license of Your choice, which may + contain terms different from this License, provided that You are in + compliance with the terms of this License and that the license for the + Executable version does not attempt to limit or alter the recipient's + rights in the Source Code version from the rights set forth in this + License. If You distribute the Executable version under a different + license You must make it absolutely clear that any terms which differ + from this License are offered by You alone, not by the Initial + Developer or any Contributor. You hereby agree to indemnify the + Initial Developer and every Contributor for any liability incurred by + the Initial Developer or such Contributor as a result of any such + terms You offer. - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. + 3.7. Larger Works. + You may create a Larger Work by combining Covered Code with other code + not governed by the terms of this License and distribute the Larger + Work as a single product. In such a case, You must make sure the + requirements of this License are fulfilled for the Covered Code. - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs +4. Inability to Comply Due to Statute or Regulation. - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. + If it is impossible for You to comply with any of the terms of this + License with respect to some or all of the Covered Code due to + statute, judicial order, or regulation then You must: (a) comply with + the terms of this License to the maximum extent possible; and (b) + describe the limitations and the code they affect. Such description + must be included in the LEGAL file described in Section 3.4 and must + be included with all distributions of the Source Code. Except to the + extent prohibited by statute or regulation, such description must be + sufficiently detailed for a recipient of ordinary skill to be able to + understand it. - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. +5. Application of this License. - - Copyright (C) + This License applies to code to which the Initial Developer has + attached the notice in Exhibit A and to related Covered Code. - This program 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 2 of the License, or - (at your option) any later version. +6. Versions of the License. - This program 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. + 6.1. New Versions. + Netscape Communications Corporation ("Netscape") may publish revised + and/or new versions of the License from time to time. Each version + will be given a distinguishing version number. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + 6.2. Effect of New Versions. + Once Covered Code has been published under a particular version of the + License, You may always continue to use it under the terms of that + version. You may also choose to use such Covered Code under the terms + of any subsequent version of the License published by Netscape. No one + other than Netscape has the right to modify the terms applicable to + Covered Code created under this License. + + 6.3. Derivative Works. + If You create or use a modified version of this License (which you may + only do in order to apply it to code which is not already Covered Code + governed by this License), You must (a) rename Your license so that + the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", + "MPL", "NPL" or any confusingly similar phrase do not appear in your + license (except to note that your license differs from this License) + and (b) otherwise make it clear that Your version of the license + contains terms which differ from the Mozilla Public License and + Netscape Public License. (Filling in the name of the Initial + Developer, Original Code or Contributor in the notice described in + Exhibit A shall not of themselves be deemed to be modifications of + this License.) + +7. DISCLAIMER OF WARRANTY. + + COVERED CODE 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. + +8. TERMINATION. + + 8.1. This License and the rights granted hereunder will terminate + automatically if You fail to comply with terms herein and fail to cure + such breach within 30 days of becoming aware of the breach. All + sublicenses to the Covered Code which are properly granted shall + survive any termination of this License. Provisions which, by their + nature, must remain in effect beyond the termination of this License + shall survive. + + 8.2. If You initiate litigation by asserting a patent infringement + claim (excluding declatory judgment actions) against Initial Developer + or a Contributor (the Initial Developer or Contributor against whom + You file such action is referred to as "Participant") alleging that: + + (a) such Participant's Contributor Version directly or indirectly + infringes any patent, then any and all rights granted by such + Participant to You under Sections 2.1 and/or 2.2 of this License + shall, upon 60 days notice from Participant terminate prospectively, + unless if within 60 days after receipt of notice You either: (i) + agree in writing to pay Participant a mutually agreeable reasonable + royalty for Your past and future use of Modifications made by such + Participant, or (ii) withdraw Your litigation claim with respect to + the Contributor Version against such Participant. If within 60 days + of notice, a reasonable royalty and payment arrangement are not + mutually agreed upon in writing by the parties or the litigation claim + is not withdrawn, the rights granted by Participant to You under + Sections 2.1 and/or 2.2 automatically terminate at the expiration of + the 60 day notice period specified above. + + (b) any software, hardware, or device, other than such Participant's + Contributor Version, directly or indirectly infringes any patent, then + any rights granted to You by such Participant under Sections 2.1(b) + and 2.2(b) are revoked effective as of the date You first made, used, + sold, distributed, or had made, Modifications made by that + Participant. + + 8.3. If You assert a patent infringement claim against Participant + alleging that such Participant's Contributor Version directly or + indirectly infringes any patent where such claim is resolved (such as + by license or settlement) prior to the initiation of patent + infringement litigation, then the reasonable value of the licenses + granted by such Participant under Sections 2.1 or 2.2 shall be taken + into account in determining the amount or value of any payment or + license. + + 8.4. In the event of termination under Sections 8.1 or 8.2 above, + all end user license agreements (excluding distributors and resellers) + which have been validly granted by You or any distributor hereunder + prior to termination shall survive termination. + +9. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT + (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL + DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, + OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR + ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY + CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, + WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER + COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN + INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF + LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY + RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW + PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE + EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO + THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +10. U.S. GOVERNMENT END USERS. + + The Covered Code is a "commercial item," as that term is defined in + 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer + software" and "commercial computer software documentation," as such + terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 + C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), + all U.S. Government End Users acquire Covered Code with only those + rights set forth herein. + +11. MISCELLANEOUS. + + This License represents the complete agreement concerning subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. This License shall be governed by + California law provisions (except to the extent applicable law, if + any, provides otherwise), excluding its conflict-of-law provisions. + With respect to disputes in which at least one party is a citizen of, + or an entity chartered or registered to do business in the United + States of America, any litigation relating to this License shall be + subject to the jurisdiction of the Federal Courts of the Northern + District of California, with venue lying in Santa Clara County, + California, with the losing party responsible for costs, including + without limitation, court costs and reasonable attorneys' fees and + expenses. The application of the United Nations Convention on + Contracts for the International Sale of Goods is expressly excluded. + Any law or regulation which provides that the language of a contract + shall be construed against the drafter shall not apply to this + License. + +12. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is + responsible for claims and damages arising, directly or indirectly, + out of its utilization of rights under this License and You agree to + work with Initial Developer and Contributors to distribute such + responsibility on an equitable basis. Nothing herein is intended or + shall be deemed to constitute any admission of liability. + +13. MULTIPLE-LICENSED CODE. + + Initial Developer may designate portions of the Covered Code as + "Multiple-Licensed". "Multiple-Licensed" means that the Initial + Developer permits you to utilize portions of the Covered Code under + Your choice of the NPL or the alternative licenses, if any, specified + by the Initial Developer in the file described in Exhibit A. + +EXHIBIT A -Mozilla Public License. + + ``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 ______________________________________. + + The Initial Developer of the Original Code is ________________________. + Portions created by ______________________ are Copyright (C) ______ + _______________________. All Rights Reserved. + + Contributor(s): ______________________________________. + + Alternatively, the contents of this file may be used under the terms + of the _____ license (the "[___] License"), in which case the + provisions of [______] License are applicable instead of those + above. If you wish to allow use of your version of this file only + under the terms of the [____] License and not to allow others to use + your version of this file under the MPL, indicate your decision by + deleting the provisions above and replace them with the notice and + other provisions required by the [___] License. If you do not delete + the provisions above, a recipient may use your version of this file + under either the MPL or the [___] License." + + [NOTE: The text of this Exhibit A may differ slightly from the text of + the notices in the Source Code files of the Original Code. You should + use the text of this Exhibit A rather than the text found in the + Original Code Source Code for Your Modifications.] -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/INSTALL b/INSTALL index a85a552726..ccfd329ecb 100644 --- a/INSTALL +++ b/INSTALL @@ -25,3 +25,15 @@ UNIX: Windows 32: + Requires: Microsoft Visual Studio 2005 or + Visual C++ 2005 Express Edition and Platform SDK + Internet connectivity to download dependency libraries + +1) Open /w32/vsnet/Freeswitch.sln + +2) Choose Release or Debug build + +3) Build solution or your choice of modules using the ide. + + + \ No newline at end of file diff --git a/docs/Doxygen.conf b/docs/Doxygen.conf index 3807f4aa0d..12ce744b86 100644 --- a/docs/Doxygen.conf +++ b/docs/Doxygen.conf @@ -44,7 +44,7 @@ IGNORE_PREFIX = switch_ #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- -EXTRACT_ALL = NO +EXTRACT_ALL = YES EXTRACT_PRIVATE = NO EXTRACT_STATIC = NO EXTRACT_LOCAL_CLASSES = YES @@ -68,7 +68,7 @@ GENERATE_DEPRECATEDLIST= YES ENABLED_SECTIONS = MAX_INITIALIZER_LINES = 30 SHOW_USED_FILES = YES -SHOW_DIRECTORIES = NO +SHOW_DIRECTORIES = YES FILE_VERSION_FILTER = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages @@ -125,8 +125,8 @@ FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- -SOURCE_BROWSER = NO -INLINE_SOURCES = NO +SOURCE_BROWSER = YES +INLINE_SOURCES = YES STRIP_CODE_COMMENTS = YES REFERENCED_BY_RELATION = YES REFERENCES_RELATION = YES @@ -149,9 +149,9 @@ HTML_FOOTER = HTML_STYLESHEET = HTML_ALIGN_MEMBERS = YES GENERATE_HTMLHELP = NO -CHM_FILE = +CHM_FILE = freeswitch.chm HHC_LOCATION = -GENERATE_CHI = NO +GENERATE_CHI = YES BINARY_TOC = NO TOC_EXPAND = NO DISABLE_INDEX = NO @@ -186,14 +186,14 @@ RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- -GENERATE_MAN = NO +GENERATE_MAN = YES MAN_OUTPUT = man MAN_EXTENSION = .3 MAN_LINKS = NO #--------------------------------------------------------------------------- # configuration options related to the XML output #--------------------------------------------------------------------------- -GENERATE_XML = NO +GENERATE_XML = YES XML_OUTPUT = xml XML_SCHEMA = XML_DTD = @@ -205,7 +205,7 @@ GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # configuration options related to the Perl module output #--------------------------------------------------------------------------- -GENERATE_PERLMOD = NO +GENERATE_PERLMOD = YES PERLMOD_LATEX = NO PERLMOD_PRETTY = YES PERLMOD_MAKEVAR_PREFIX = diff --git a/indent_options.sh b/indent_options.sh new file mode 100755 index 0000000000..da67165ba4 --- /dev/null +++ b/indent_options.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo -n "-brs -npsl -di0 -br -ce -d0 -cli0 -npcs -nfc1 -ut -i4 -ts4 -l120 -cs -T size_t " > .indent.pro +grep typedef src/include/*.h | grep switch_ | grep -v "\*\|{" | perl -ne '@l = split; $l[2] =~ s/;//g ; print "-T $l[2] "' >> .indent.pro +grep "} switch_" src/include/*.h | perl -ne '@l = split; $l[1] =~ s/;//g ; print " -T $l[1] "' >> .indent.pro diff --git a/src/mod/applications/mod_bridgecall/mod_bridgecall.c b/src/mod/applications/mod_bridgecall/mod_bridgecall.c index 2c57a5c348..e533f8e516 100644 --- a/src/mod/applications/mod_bridgecall/mod_bridgecall.c +++ b/src/mod/applications/mod_bridgecall/mod_bridgecall.c @@ -55,7 +55,7 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj) session_a = data->objs[0]; session_b = data->objs[1]; - + stream_id_p = data->objs[2]; if (stream_id_p) { stream_id = *stream_id_p; @@ -64,16 +64,16 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj) chan_a = switch_core_session_get_channel(session_a); chan_b = switch_core_session_get_channel(session_b); - while(data->running > 0) { + while (data->running > 0) { switch_channel_state b_state = switch_channel_get_state(chan_b); switch (b_state) { -case CS_HANGUP: - data->running = -1; - continue; - break; -default: - break; + case CS_HANGUP: + data->running = -1; + continue; + break; + default: + break; } if (switch_channel_has_dtmf(chan_a)) { @@ -81,16 +81,17 @@ default: switch_channel_dequeue_dtmf(chan_a, dtmf, sizeof(dtmf)); switch_core_session_send_dtmf(session_b, dtmf); } - - if (switch_core_session_read_frame(session_a, &read_frame, -1, stream_id) == SWITCH_STATUS_SUCCESS && read_frame->datalen) { + + if (switch_core_session_read_frame(session_a, &read_frame, -1, stream_id) == SWITCH_STATUS_SUCCESS + && read_frame->datalen) { if (switch_core_session_write_frame(session_b, read_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "write: Bad Frame.... Bubye!\n"); data->running = -1; } - } else { + } else { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "read: Bad Frame.... Bubye!\n"); data->running = -1; - } + } } @@ -115,7 +116,8 @@ static switch_status audio_bridge_on_hangup(switch_core_session *session) other_channel = switch_core_session_get_channel(other_session); assert(other_channel != NULL); - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "CUSTOM HANGUP %s kill %s\n", switch_channel_get_name(channel), switch_channel_get_name(other_channel)); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "CUSTOM HANGUP %s kill %s\n", switch_channel_get_name(channel), + switch_channel_get_name(other_channel)); switch_core_session_kill_channel(other_session, SWITCH_SIG_KILL); switch_core_session_kill_channel(session, SWITCH_SIG_KILL); @@ -143,21 +145,21 @@ static switch_status audio_bridge_on_ring(switch_core_session *session) } static const switch_event_handler_table audio_bridge_peer_event_handlers = { - /*.on_init*/ NULL, - /*.on_ring*/ audio_bridge_on_ring, - /*.on_execute*/ NULL, - /*.on_hangup*/ audio_bridge_on_hangup, - /*.on_loopback*/ NULL, - /*.on_transmit*/ NULL + /*.on_init */ NULL, + /*.on_ring */ audio_bridge_on_ring, + /*.on_execute */ NULL, + /*.on_hangup */ audio_bridge_on_hangup, + /*.on_loopback */ NULL, + /*.on_transmit */ NULL }; static const switch_event_handler_table audio_bridge_caller_event_handlers = { - /*.on_init*/ NULL, - /*.on_ring*/ NULL, - /*.on_execute*/ NULL, - /*.on_hangup*/ audio_bridge_on_hangup, - /*.on_loopback*/ NULL, - /*.on_transmit*/ NULL + /*.on_init */ NULL, + /*.on_ring */ NULL, + /*.on_execute */ NULL, + /*.on_hangup */ audio_bridge_on_hangup, + /*.on_loopback */ NULL, + /*.on_transmit */ NULL }; static void audio_bridge_function(switch_core_session *session, char *data) @@ -165,8 +167,8 @@ static void audio_bridge_function(switch_core_session *session, char *data) switch_channel *caller_channel, *peer_channel; switch_core_session *peer_session; switch_caller_profile *caller_profile, *caller_caller_profile; - char chan_type[128]= {'\0'}, *chan_data; - int timelimit = 60; /* probably a useful option to pass in when there's time */ + char chan_type[128] = { '\0' }, *chan_data; + int timelimit = 60; /* probably a useful option to pass in when there's time */ caller_channel = switch_core_session_get_channel(session); assert(caller_channel != NULL); @@ -180,17 +182,15 @@ static void audio_bridge_function(switch_core_session *session, char *data) caller_caller_profile = switch_channel_get_caller_profile(caller_channel); caller_profile = switch_caller_profile_new(session, - caller_caller_profile->dialplan, - caller_caller_profile->caller_id_name, - caller_caller_profile->caller_id_number, - caller_caller_profile->network_addr, - NULL, - NULL, - chan_data); + caller_caller_profile->dialplan, + caller_caller_profile->caller_id_name, + caller_caller_profile->caller_id_number, + caller_caller_profile->network_addr, NULL, NULL, chan_data); - if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session) != SWITCH_STATUS_SUCCESS) { + if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session) != + SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "DOH!\n"); switch_channel_hangup(caller_channel); return; @@ -215,11 +215,11 @@ static void audio_bridge_function(switch_core_session *session, char *data) switch_channel_set_private(caller_channel, peer_session); switch_channel_set_private(peer_channel, session); - switch_channel_set_event_handlers(caller_channel, &audio_bridge_caller_event_handlers); + switch_channel_set_event_handlers(caller_channel, &audio_bridge_caller_event_handlers); switch_channel_set_event_handlers(peer_channel, &audio_bridge_peer_event_handlers); switch_core_session_thread_launch(peer_session); - for(;;) { + for (;;) { int state = switch_channel_get_state(peer_channel); if (state > CS_RING) { break; @@ -228,11 +228,10 @@ static void audio_bridge_function(switch_core_session *session, char *data) } time(&start); - while(switch_channel_get_state(caller_channel) == CS_EXECUTE && - switch_channel_get_state(peer_channel) == CS_TRANSMIT && - !switch_channel_test_flag(peer_channel, CF_ANSWERED) && - ((time(NULL) - start) < timelimit)) { - switch_yield(20000); + while (switch_channel_get_state(caller_channel) == CS_EXECUTE && + switch_channel_get_state(peer_channel) == CS_TRANSMIT && + !switch_channel_test_flag(peer_channel, CF_ANSWERED) && ((time(NULL) - start) < timelimit)) { + switch_yield(20000); } if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) { @@ -259,21 +258,22 @@ static void audio_bridge_function(switch_core_session *session, char *data) static const switch_application_interface bridge_application_interface = { - /*.interface_name*/ "bridge", - /*.application_function*/ audio_bridge_function + /*.interface_name */ "bridge", + /*.application_function */ audio_bridge_function }; static const switch_loadable_module_interface mod_bridgecall_module_interface = { - /*.module_name = */ modname, - /*.endpoint_interface = */ NULL, - /*.timer_interface = */ NULL, - /*.dialplan_interface = */ NULL, - /*.codec_interface = */ NULL, - /*.application_interface*/ &bridge_application_interface + /*.module_name = */ modname, + /*.endpoint_interface = */ NULL, + /*.timer_interface = */ NULL, + /*.dialplan_interface = */ NULL, + /*.codec_interface = */ NULL, + /*.application_interface */ &bridge_application_interface }; -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ /* connect my internal structure to the blank pointer passed to me */ *interface = &mod_bridgecall_module_interface; diff --git a/src/mod/applications/mod_playback/mod_playback.c b/src/mod/applications/mod_playback/mod_playback.c index 75fe0c13da..f68ebe97f5 100644 --- a/src/mod/applications/mod_playback/mod_playback.c +++ b/src/mod/applications/mod_playback/mod_playback.c @@ -59,11 +59,11 @@ void playback_function(switch_core_session *session, char *data) assert(channel != NULL); if (switch_core_file_open(&fh, - data, - SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, - switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { - switch_channel_hangup(channel); - return; + data, + SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, + switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { + switch_channel_hangup(channel); + return; } switch_channel_answer(channel); @@ -81,17 +81,17 @@ void playback_function(switch_core_session *session, char *data) codec_name = "L16"; if (switch_core_codec_init(&codec, - codec_name, - fh.samplerate, - interval, - fh.channels, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL, - pool) == SWITCH_STATUS_SUCCESS) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n"); - write_frame.codec = &codec; + codec_name, + fh.samplerate, + interval, + fh.channels, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, pool) == SWITCH_STATUS_SUCCESS) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n"); + write_frame.codec = &codec; } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed %s@%dhz %d channels %dms\n", codec_name, fh.samplerate, fh.channels, interval); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed %s@%dhz %d channels %dms\n", + codec_name, fh.samplerate, fh.channels, interval); switch_core_file_close(&fh); switch_channel_hangup(channel); return; @@ -108,11 +108,11 @@ void playback_function(switch_core_session *session, char *data) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer success %d bytes per %d ms!\n", len, interval); /* start a thread to absorb incoming audio */ - for(stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) { + for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) { switch_core_service_session(session, &thread_session, stream_id); } ilen = samples; - while(switch_channel_get_state(channel) == CS_EXECUTE) { + while (switch_channel_get_state(channel) == CS_EXECUTE) { int done = 0; if (switch_channel_has_dtmf(channel)) { @@ -139,12 +139,12 @@ void playback_function(switch_core_session *session, char *data) } write_frame.datalen = ilen * 2; - write_frame.samples = (int)ilen; + write_frame.samples = (int) ilen; #ifdef SWAP_LINEAR - switch_swap_linear(write_frame.data, (int)write_frame.datalen / 2); + switch_swap_linear(write_frame.data, (int) write_frame.datalen / 2); #endif - for(stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) { + for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) { if (switch_core_session_write_frame(session, &write_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bad Write\n"); done = 1; @@ -178,20 +178,21 @@ void playback_function(switch_core_session *session, char *data) } static const switch_application_interface playback_application_interface = { - /*.interface_name*/ "playback", - /*.application_function*/ playback_function + /*.interface_name */ "playback", + /*.application_function */ playback_function }; static const switch_loadable_module_interface mod_playback_module_interface = { - /*.module_name = */ modname, - /*.endpoint_interface = */ NULL, - /*.timer_interface = */ NULL, - /*.dialplan_interface = */ NULL, - /*.codec_interface = */ NULL, - /*.application_interface*/ &playback_application_interface + /*.module_name = */ modname, + /*.endpoint_interface = */ NULL, + /*.timer_interface = */ NULL, + /*.dialplan_interface = */ NULL, + /*.codec_interface = */ NULL, + /*.application_interface */ &playback_application_interface }; -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ /* connect my internal structure to the blank pointer passed to me */ *interface = &mod_playback_module_interface; @@ -207,7 +208,3 @@ if it returns anything but SWITCH_STATUS_TERM it will be called again automaticl //switch_status switch_module_runtime(void) - - - - diff --git a/src/mod/applications/mod_skel/mod_skel.c b/src/mod/applications/mod_skel/mod_skel.c index 21126d1f3e..a069433082 100644 --- a/src/mod/applications/mod_skel/mod_skel.c +++ b/src/mod/applications/mod_skel/mod_skel.c @@ -34,15 +34,16 @@ static const char modname[] = "mod_skel"; static switch_loadable_module_interface skel_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ NULL, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ NULL, - /*.application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ NULL, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL }; -switch_status switch_module_load(switch_loadable_module_interface **interface, char *filename) { +switch_status switch_module_load(switch_loadable_module_interface **interface, char *filename) +{ /* connect my internal structure to the blank pointer passed to me */ *interface = &skel_module_interface; @@ -51,4 +52,3 @@ switch_status switch_module_load(switch_loadable_module_interface **interface, c /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } - diff --git a/src/mod/codecs/mod_g711/g711.c b/src/mod/codecs/mod_g711/g711.c index b69eb4f912..2d47891c99 100644 --- a/src/mod/codecs/mod_g711/g711.c +++ b/src/mod/codecs/mod_g711/g711.c @@ -47,70 +47,71 @@ */ #define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */ #define QUANT_MASK (0xf) /* Quantization field mask. */ -#define NSEGS (8) /* Number of A-law segments. */ -#define SEG_SHIFT (4) /* Left shift for segment number. */ +#define NSEGS (8) /* Number of A-law segments. */ +#define SEG_SHIFT (4) /* Left shift for segment number. */ #define SEG_MASK (0x70) /* Segment field mask. */ -static short seg_aend[8] = {0x1F, 0x3F, 0x7F, 0xFF, - 0x1FF, 0x3FF, 0x7FF, 0xFFF}; -static short seg_uend[8] = {0x3F, 0x7F, 0xFF, 0x1FF, - 0x3FF, 0x7FF, 0xFFF, 0x1FFF}; +static short seg_aend[8] = { 0x1F, 0x3F, 0x7F, 0xFF, + 0x1FF, 0x3FF, 0x7FF, 0xFFF +}; +static short seg_uend[8] = { 0x3F, 0x7F, 0xFF, 0x1FF, + 0x3FF, 0x7FF, 0xFFF, 0x1FFF +}; /* copy from CCITT G.711 specifications */ -unsigned char _u2a[128] = { /* u- to A-law conversions */ - 1, 1, 2, 2, 3, 3, 4, 4, - 5, 5, 6, 6, 7, 7, 8, 8, - 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, - 25, 27, 29, 31, 33, 34, 35, 36, - 37, 38, 39, 40, 41, 42, 43, 44, - 46, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, 58, 59, 60, 61, 62, - 64, 65, 66, 67, 68, 69, 70, 71, - 72, 73, 74, 75, 76, 77, 78, 79, +unsigned char _u2a[128] = { /* u- to A-law conversions */ + 1, 1, 2, 2, 3, 3, 4, 4, + 5, 5, 6, 6, 7, 7, 8, 8, + 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, + 25, 27, 29, 31, 33, 34, 35, 36, + 37, 38, 39, 40, 41, 42, 43, 44, + 46, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, + 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, /* corrected: 81, 82, 83, 84, 85, 86, 87, 88, should be: */ - 80, 82, 83, 84, 85, 86, 87, 88, - 89, 90, 91, 92, 93, 94, 95, 96, - 97, 98, 99, 100, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 117, 118, 119, 120, - 121, 122, 123, 124, 125, 126, 127, 128}; + 80, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 91, 92, 93, 94, 95, 96, + 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128 +}; -unsigned char _a2u[128] = { /* A- to u-law conversions */ - 1, 3, 5, 7, 9, 11, 13, 15, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - 32, 32, 33, 33, 34, 34, 35, 35, - 36, 37, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 48, 48, 49, 49, - 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, 64, - 65, 66, 67, 68, 69, 70, 71, 72, +unsigned char _a2u[128] = { /* A- to u-law conversions */ + 1, 3, 5, 7, 9, 11, 13, 15, + 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, + 32, 32, 33, 33, 34, 34, 35, 35, + 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 48, 49, 49, + 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 64, + 65, 66, 67, 68, 69, 70, 71, 72, /* corrected: 73, 74, 75, 76, 77, 78, 79, 79, should be: */ - 73, 74, 75, 76, 77, 78, 79, 80, - 80, 81, 82, 83, 84, 85, 86, 87, - 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, - 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, 117, 118, 119, - 120, 121, 122, 123, 124, 125, 126, 127}; + 73, 74, 75, 76, 77, 78, 79, 80, + 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 127 +}; -static short search( - short val, - short *table, - short size) +static short search(short val, short *table, short size) { - short i; - - for (i = 0; i < size; i++) { - if (val <= *table++) - return (i); - } - return (size); + short i; + + for (i = 0; i < size; i++) { + if (val <= *table++) + return (i); + } + return (size); } /* @@ -132,66 +133,63 @@ static short search( * For further information see John C. Bellamy's Digital Telephony, 1982, * John Wiley & Sons, pps 98-111 and 472-476. */ -unsigned char -linear2alaw(short pcm_val) /* 2's complement (16-bit range) */ -{ - short mask; - short seg; - unsigned char aval; - - pcm_val = pcm_val >> 3; +unsigned char linear2alaw(short pcm_val) +{ /* 2's complement (16-bit range) */ + short mask; + short seg; + unsigned char aval; - if (pcm_val >= 0) { - mask = 0xD5; /* sign (7th) bit = 1 */ - } else { - mask = 0x55; /* sign bit = 0 */ - pcm_val = -pcm_val - 1; - } - - /* Convert the scaled magnitude to segment number. */ - seg = search(pcm_val, seg_aend, 8); - - /* Combine the sign, segment, and quantization bits. */ - - if (seg >= 8) /* out of range, return maximum value. */ - return (unsigned char) (0x7F ^ mask); - else { - aval = (unsigned char) seg << SEG_SHIFT; - if (seg < 2) - aval |= (pcm_val >> 1) & QUANT_MASK; - else - aval |= (pcm_val >> seg) & QUANT_MASK; - return (aval ^ mask); - } + pcm_val = pcm_val >> 3; + + if (pcm_val >= 0) { + mask = 0xD5; /* sign (7th) bit = 1 */ + } else { + mask = 0x55; /* sign bit = 0 */ + pcm_val = -pcm_val - 1; + } + + /* Convert the scaled magnitude to segment number. */ + seg = search(pcm_val, seg_aend, 8); + + /* Combine the sign, segment, and quantization bits. */ + + if (seg >= 8) /* out of range, return maximum value. */ + return (unsigned char) (0x7F ^ mask); + else { + aval = (unsigned char) seg << SEG_SHIFT; + if (seg < 2) + aval |= (pcm_val >> 1) & QUANT_MASK; + else + aval |= (pcm_val >> seg) & QUANT_MASK; + return (aval ^ mask); + } } /* * alaw2linear() - Convert an A-law value to 16-bit linear PCM * */ -short -alaw2linear( - unsigned char a_val) +short alaw2linear(unsigned char a_val) { - short t; - short seg; - - a_val ^= 0x55; - - t = (a_val & QUANT_MASK) << 4; - seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT; - switch (seg) { - case 0: - t += 8; - break; - case 1: - t += 0x108; - break; - default: - t += 0x108; - t <<= seg - 1; - } - return ((a_val & SIGN_BIT) ? t : -t); + short t; + short seg; + + a_val ^= 0x55; + + t = (a_val & QUANT_MASK) << 4; + seg = ((unsigned) a_val & SEG_MASK) >> SEG_SHIFT; + switch (seg) { + case 0: + t += 8; + break; + case 1: + t += 0x108; + break; + default: + t += 0x108; + t <<= seg - 1; + } + return ((a_val & SIGN_BIT) ? t : -t); } #define BIAS (0x84) /* Bias for linear code. */ @@ -226,39 +224,38 @@ alaw2linear( * For further information see John C. Bellamy's Digital Telephony, 1982, * John Wiley & Sons, pps 98-111 and 472-476. */ -unsigned char -linear2ulaw( - short pcm_val) /* 2's complement (16-bit range) */ -{ - short mask; - short seg; - unsigned char uval; - - /* Get the sign and the magnitude of the value. */ - pcm_val = pcm_val >> 2; - if (pcm_val < 0) { - pcm_val = -pcm_val; - mask = 0x7F; - } else { - mask = 0xFF; - } - if ( pcm_val > CLIP ) pcm_val = CLIP; /* clip the magnitude */ - pcm_val += (BIAS >> 2); - - /* Convert the scaled magnitude to segment number. */ - seg = search(pcm_val, seg_uend, 8); - - /* - * Combine the sign, segment, quantization bits; - * and complement the code word. - */ - if (seg >= 8) /* out of range, return maximum value. */ - return (unsigned char) (0x7F ^ mask); - else { - uval = (unsigned char) (seg << 4) | ((pcm_val >> (seg + 1)) & 0xF); - return (uval ^ mask); - } - +unsigned char linear2ulaw(short pcm_val) +{ /* 2's complement (16-bit range) */ + short mask; + short seg; + unsigned char uval; + + /* Get the sign and the magnitude of the value. */ + pcm_val = pcm_val >> 2; + if (pcm_val < 0) { + pcm_val = -pcm_val; + mask = 0x7F; + } else { + mask = 0xFF; + } + if (pcm_val > CLIP) + pcm_val = CLIP; /* clip the magnitude */ + pcm_val += (BIAS >> 2); + + /* Convert the scaled magnitude to segment number. */ + seg = search(pcm_val, seg_uend, 8); + + /* + * Combine the sign, segment, quantization bits; + * and complement the code word. + */ + if (seg >= 8) /* out of range, return maximum value. */ + return (unsigned char) (0x7F ^ mask); + else { + uval = (unsigned char) (seg << 4) | ((pcm_val >> (seg + 1)) & 0xF); + return (uval ^ mask); + } + } /* @@ -270,43 +267,35 @@ linear2ulaw( * Note that this function expects to be passed the complement of the * original code word. This is in keeping with ISDN conventions. */ -short -ulaw2linear( - unsigned char u_val) +short ulaw2linear(unsigned char u_val) { - short t; - - /* Complement to obtain normal u-law value. */ - u_val = ~u_val; - - /* - * Extract and bias the quantization bits. Then - * shift up by the segment number and subtract out the bias. - */ - t = ((u_val & QUANT_MASK) << 3) + BIAS; - t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT; - - return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS)); + short t; + + /* Complement to obtain normal u-law value. */ + u_val = ~u_val; + + /* + * Extract and bias the quantization bits. Then + * shift up by the segment number and subtract out the bias. + */ + t = ((u_val & QUANT_MASK) << 3) + BIAS; + t <<= ((unsigned) u_val & SEG_MASK) >> SEG_SHIFT; + + return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS)); } /* A-law to u-law conversion */ -unsigned char -alaw2ulaw( - unsigned char aval) +unsigned char alaw2ulaw(unsigned char aval) { - aval &= 0xff; - return (unsigned char) ((aval & 0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) : - (0x7F ^ _a2u[aval ^ 0x55])); + aval &= 0xff; + return (unsigned char) ((aval & 0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) : (0x7F ^ _a2u[aval ^ 0x55])); } /* u-law to A-law conversion */ -unsigned char -ulaw2alaw( - unsigned char uval) +unsigned char ulaw2alaw(unsigned char uval) { - uval &= 0xff; - return (unsigned char) ((uval & 0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) : - (0x55 ^ (_u2a[0x7F ^ uval] - 1))); + uval &= 0xff; + return (unsigned char) ((uval & 0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) : (0x55 ^ (_u2a[0x7F ^ uval] - 1))); } /* ---------- end of g711.c ----------------------------------------------------- */ diff --git a/src/mod/codecs/mod_g711/mod_g711.c b/src/mod/codecs/mod_g711/mod_g711.c index af3395ded5..327a604bc7 100644 --- a/src/mod/codecs/mod_g711/mod_g711.c +++ b/src/mod/codecs/mod_g711/mod_g711.c @@ -36,7 +36,8 @@ static const char modname[] = "mod_g711codec"; -static switch_status switch_g711u_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings) +static switch_status switch_g711u_init(switch_codec *codec, switch_codec_flag flags, + const struct switch_codec_settings *codec_settings) { int encoding, decoding; @@ -57,9 +58,7 @@ static switch_status switch_g711u_encode(switch_codec *codec, size_t decoded_data_len, int decoded_rate, void *encoded_data, - size_t *encoded_data_len, - int *encoded_rate, - unsigned int *flag) + size_t *encoded_data_len, int *encoded_rate, unsigned int *flag) { short *dbuf; unsigned char *ebuf; @@ -83,9 +82,7 @@ static switch_status switch_g711u_decode(switch_codec *codec, size_t encoded_data_len, int encoded_rate, void *decoded_data, - size_t *decoded_data_len, - int *decoded_rate, - unsigned int *flag) + size_t *decoded_data_len, int *decoded_rate, unsigned int *flag) { short *dbuf; unsigned char *ebuf; @@ -114,7 +111,8 @@ static switch_status switch_g711u_destroy(switch_codec *codec) } -static switch_status switch_g711a_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings) +static switch_status switch_g711a_init(switch_codec *codec, switch_codec_flag flags, + const struct switch_codec_settings *codec_settings) { int encoding, decoding; @@ -135,9 +133,7 @@ static switch_status switch_g711a_encode(switch_codec *codec, size_t decoded_data_len, int decoded_rate, void *encoded_data, - size_t *encoded_data_len, - int *encoded_rate, - unsigned int *flag) + size_t *encoded_data_len, int *encoded_rate, unsigned int *flag) { short *dbuf; unsigned char *ebuf; @@ -161,9 +157,7 @@ static switch_status switch_g711a_decode(switch_codec *codec, size_t encoded_data_len, int encoded_rate, void *decoded_data, - size_t *decoded_data_len, - int *decoded_rate, - unsigned int *flag) + size_t *decoded_data_len, int *decoded_rate, unsigned int *flag) { short *dbuf; unsigned char *ebuf; @@ -195,126 +189,122 @@ static switch_status switch_g711a_destroy(switch_codec *codec) static const switch_codec_implementation g711u_8k_60ms_implementation = { - /*.samples_per_second*/ 8000, - /*.bits_per_second*/ 19200, - /*.microseconds_per_frame*/ 60000, - /*.samples_per_frame*/ 480, - /*.bytes_per_frame*/ 960, - /*.encoded_bytes_per_frame*/ 480, - /*.number_of_channels*/ 1, - /*.pref_frames_per_packet*/ 1, - /*.max_frames_per_packet*/ 1, - /*.init*/ switch_g711u_init, - /*.encode*/ switch_g711u_encode, - /*.decode*/ switch_g711u_decode, - /*.destroy*/ switch_g711u_destroy + /*.samples_per_second */ 8000, + /*.bits_per_second */ 19200, + /*.microseconds_per_frame */ 60000, + /*.samples_per_frame */ 480, + /*.bytes_per_frame */ 960, + /*.encoded_bytes_per_frame */ 480, + /*.number_of_channels */ 1, + /*.pref_frames_per_packet */ 1, + /*.max_frames_per_packet */ 1, + /*.init */ switch_g711u_init, + /*.encode */ switch_g711u_encode, + /*.decode */ switch_g711u_decode, + /*.destroy */ switch_g711u_destroy }; static const switch_codec_implementation g711u_8k_30ms_implementation = { - /*.samples_per_second*/ 8000, - /*.bits_per_second*/ 96000, - /*.microseconds_per_frame*/ 30000, - /*.samples_per_frame*/ 240, - /*.bytes_per_frame*/ 480, - /*.encoded_bytes_per_frame*/ 240, - /*.number_of_channels*/ 1, - /*.pref_frames_per_packet*/ 1, - /*.max_frames_per_packet*/ 1, - /*.init*/ switch_g711u_init, - /*.encode*/ switch_g711u_encode, - /*.decode*/ switch_g711u_decode, - /*.destroy*/ switch_g711u_destroy, - /*.next*/ &g711u_8k_60ms_implementation + /*.samples_per_second */ 8000, + /*.bits_per_second */ 96000, + /*.microseconds_per_frame */ 30000, + /*.samples_per_frame */ 240, + /*.bytes_per_frame */ 480, + /*.encoded_bytes_per_frame */ 240, + /*.number_of_channels */ 1, + /*.pref_frames_per_packet */ 1, + /*.max_frames_per_packet */ 1, + /*.init */ switch_g711u_init, + /*.encode */ switch_g711u_encode, + /*.decode */ switch_g711u_decode, + /*.destroy */ switch_g711u_destroy, + /*.next */ &g711u_8k_60ms_implementation }; static const switch_codec_implementation g711u_16k_implementation = { - /*.samples_per_second*/ 16000, - /*.bits_per_second*/ 128000, - /*.microseconds_per_frame*/ 20000, - /*.samples_per_frame*/ 320, - /*.bytes_per_frame*/ 640, - /*.encoded_bytes_per_frame*/ 320, - /*.number_of_channels*/ 1, - /*.pref_frames_per_packet*/ 1, - /*.max_frames_per_packet*/ 1, - /*.init*/ switch_g711u_init, - /*.encode*/ switch_g711u_encode, - /*.decode*/ switch_g711u_decode, - /*.destroy*/ switch_g711u_destroy, + /*.samples_per_second */ 16000, + /*.bits_per_second */ 128000, + /*.microseconds_per_frame */ 20000, + /*.samples_per_frame */ 320, + /*.bytes_per_frame */ 640, + /*.encoded_bytes_per_frame */ 320, + /*.number_of_channels */ 1, + /*.pref_frames_per_packet */ 1, + /*.max_frames_per_packet */ 1, + /*.init */ switch_g711u_init, + /*.encode */ switch_g711u_encode, + /*.decode */ switch_g711u_decode, + /*.destroy */ switch_g711u_destroy, }; static const switch_codec_implementation g711u_8k_implementation = { - /*.samples_per_second*/ 8000, - /*.bits_per_second*/ 64000, - /*.microseconds_per_frame*/ 20000, - /*.samples_per_frame*/ 160, - /*.bytes_per_frame*/ 320, - /*.encoded_bytes_per_frame*/ 160, - /*.number_of_channels*/ 1, - /*.pref_frames_per_packet*/ 1, - /*.max_frames_per_packet*/ 1, - /*.init*/ switch_g711u_init, - /*.encode*/ switch_g711u_encode, - /*.decode*/ switch_g711u_decode, - /*.destroy*/ switch_g711u_destroy, - /*.next*/ &g711u_16k_implementation + /*.samples_per_second */ 8000, + /*.bits_per_second */ 64000, + /*.microseconds_per_frame */ 20000, + /*.samples_per_frame */ 160, + /*.bytes_per_frame */ 320, + /*.encoded_bytes_per_frame */ 160, + /*.number_of_channels */ 1, + /*.pref_frames_per_packet */ 1, + /*.max_frames_per_packet */ 1, + /*.init */ switch_g711u_init, + /*.encode */ switch_g711u_encode, + /*.decode */ switch_g711u_decode, + /*.destroy */ switch_g711u_destroy, + /*.next */ &g711u_16k_implementation }; static const switch_codec_implementation g711a_8k_implementation = { - /*.samples_per_second*/ 8000, - /*.bits_per_second*/ 64000, - /*.microseconds_per_frame*/ 20000, - /*.samples_per_frame*/ 160, - /*.bytes_per_frame*/ 320, - /*.encoded_bytes_per_frame*/ 160, - /*.number_of_channels*/ 1, - /*.pref_frames_per_packet*/ 1, - /*.max_frames_per_packet*/ 1, - /*.init*/ switch_g711a_init, - /*.encode*/ switch_g711a_encode, - /*.decode*/ switch_g711a_decode, - /*.destroy*/ switch_g711a_destroy + /*.samples_per_second */ 8000, + /*.bits_per_second */ 64000, + /*.microseconds_per_frame */ 20000, + /*.samples_per_frame */ 160, + /*.bytes_per_frame */ 320, + /*.encoded_bytes_per_frame */ 160, + /*.number_of_channels */ 1, + /*.pref_frames_per_packet */ 1, + /*.max_frames_per_packet */ 1, + /*.init */ switch_g711a_init, + /*.encode */ switch_g711a_encode, + /*.decode */ switch_g711a_decode, + /*.destroy */ switch_g711a_destroy }; static const switch_codec_interface g711a_codec_interface = { - /*.interface_name*/ "g711 alaw", - /*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO, - /*.ianacode*/ 8, - /*.iananame*/ "PCMA", - /*.implementations*/ &g711a_8k_implementation + /*.interface_name */ "g711 alaw", + /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, + /*.ianacode */ 8, + /*.iananame */ "PCMA", + /*.implementations */ &g711a_8k_implementation }; static const switch_codec_interface g711u_codec_interface = { - /*.interface_name*/ "g711 ulaw", - /*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO, - /*.ianacode*/ 0, - /*.iananame*/ "PCMU", - /*.implementations*/ &g711u_8k_implementation, - /*.next*/ &g711a_codec_interface + /*.interface_name */ "g711 ulaw", + /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, + /*.ianacode */ 0, + /*.iananame */ "PCMU", + /*.implementations */ &g711u_8k_implementation, + /*.next */ &g711a_codec_interface }; static switch_loadable_module_interface g711_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ NULL, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ &g711u_codec_interface, - /*.application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ NULL, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ &g711u_codec_interface, + /*.application_interface */ NULL }; -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ /* connect my internal structure to the blank pointer passed to me */ *interface = &g711_module_interface; /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } - - - - - diff --git a/src/mod/codecs/mod_g729/mod_g729.c b/src/mod/codecs/mod_g729/mod_g729.c index e85d461ea1..72d47a6413 100644 --- a/src/mod/codecs/mod_g729/mod_g729.c +++ b/src/mod/codecs/mod_g729/mod_g729.c @@ -28,176 +28,142 @@ * * mod_codec_g729.c -- G729 Codec Module * - */ + */ #include "switch.h" #include "g729.h" - -static const char modname[] = "mod_codec_g729"; - -struct g729_context { - struct dec_state decoder_object; - struct cod_state encoder_object; -}; - -static switch_status switch_g729_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings) -{ - struct g729_context *context = NULL; - int encoding, decoding; - - encoding = (flags & SWITCH_CODEC_FLAG_ENCODE); - decoding = (flags & SWITCH_CODEC_FLAG_DECODE); - - if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g729_context))))) { - return SWITCH_STATUS_FALSE; - } else { - if (encoding) { - g729_init_coder(&context->encoder_object, 0); - } - if (decoding) { - g729_init_decoder(&context->decoder_object); - } - - codec->private = context; - - return SWITCH_STATUS_SUCCESS; - } -} - -static switch_status switch_g729_destroy(switch_codec *codec) -{ - codec->private = NULL; - return SWITCH_STATUS_SUCCESS; -} - - -static switch_status switch_g729_encode(switch_codec *codec, - switch_codec *other_codec, - void *decoded_data, - size_t decoded_data_len, - int decoded_rate, - void *encoded_data, - size_t *encoded_data_len, - int *encoded_rate, - unsigned int *flag) -{ - struct g729_context *context = codec->private; - int cbret = 0; - - if (!context) { - return SWITCH_STATUS_FALSE; - } - if (decoded_data_len % 160 == 0) { - unsigned int new_len = 0; - INT16 *ddp = decoded_data; - char *edp = encoded_data; - int x; - int loops = (int) decoded_data_len / 160; - - for(x = 0; x < loops && new_len < *encoded_data_len; x++) { - g729_coder(&context->encoder_object, ddp, edp, &cbret); - edp += 10; - ddp += 80; - new_len += 10; - } - if( new_len <= *encoded_data_len ) { - *encoded_data_len = new_len; - } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len); - return SWITCH_STATUS_FALSE; - } - } - return SWITCH_STATUS_SUCCESS; -} - - -static switch_status switch_g729_decode(switch_codec *codec, - switch_codec *other_codec, - void *encoded_data, - size_t encoded_data_len, - int encoded_rate, - void *decoded_data, - size_t *decoded_data_len, - int *decoded_rate, - unsigned int *flag) -{ - struct g729_context *context = codec->private; - - if (!context) { - return SWITCH_STATUS_FALSE; - } - - - if (encoded_data_len % 10 == 0) { - int loops = (int) encoded_data_len / 10; - char *edp = encoded_data; - short *ddp = decoded_data; - int x; - unsigned int new_len = 0; - for(x = 0; x < loops && new_len < *decoded_data_len; x++) { - g729_decoder(&context->decoder_object, ddp, edp, 10); - ddp += 80; - edp += 10; - new_len += 160; - } - if (new_len <= *decoded_data_len) { - *decoded_data_len = new_len; - } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n"); - return SWITCH_STATUS_FALSE; - } - } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len); - } - - - return SWITCH_STATUS_SUCCESS; -} - -/* Registration */ - -static const switch_codec_implementation g729_8k_implementation = { - /*.samples_per_second*/ 8000, - /*.bits_per_second*/ 64000, - /*.microseconds_per_frame*/ 20000, - /*.samples_per_frame*/ 160, - /*.bytes_per_frame*/ 320, - /*.encoded_bytes_per_frame*/ 20, - /*.number_of_channels*/ 1, - /*.pref_frames_per_packet*/ 1, - /*.max_frames_per_packet*/ 24, - /*.init*/ switch_g729_init, - /*.encode*/ switch_g729_encode, - /*.decode*/ switch_g729_decode, - /*.destroy*/ switch_g729_destroy, -}; - -static const switch_codec_interface g729_codec_interface = { - /*.interface_name*/ "g729", - /*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO, - /*.ianacode*/ 18, - /*.iananame*/ "G729", - /*.implementations*/ &g729_8k_implementation, -}; - -static switch_loadable_module_interface g729_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ NULL, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ &g729_codec_interface, - /*.application_interface*/ NULL -}; - - -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { - /* connect my internal structure to the blank pointer passed to me */ - *interface = &g729_module_interface; - - /* indicate that the module should continue to be loaded */ - return SWITCH_STATUS_SUCCESS; -} - - - - - + static const char modname[] = "mod_codec_g729"; + struct g729_context { + struct dec_state decoder_object; + struct cod_state encoder_object; + }; + static switch_status switch_g729_init(switch_codec *codec, switch_codec_flag flags, + const struct switch_codec_settings *codec_settings) +{ + struct g729_context *context = NULL; + int encoding, decoding; + encoding = (flags & SWITCH_CODEC_FLAG_ENCODE); + decoding = (flags & SWITCH_CODEC_FLAG_DECODE); + if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g729_context))))) { + return SWITCH_STATUS_FALSE; + } else { + if (encoding) { + g729_init_coder(&context->encoder_object, 0); + } + if (decoding) { + g729_init_decoder(&context->decoder_object); + } + codec->private = context; + return SWITCH_STATUS_SUCCESS; + } + } + static switch_status switch_g729_destroy(switch_codec *codec) +{ + codec->private = NULL; + return SWITCH_STATUS_SUCCESS; + } + static switch_status switch_g729_encode(switch_codec *codec, switch_codec *other_codec, void *decoded_data, + size_t decoded_data_len, int decoded_rate, void *encoded_data, + size_t *encoded_data_len, int *encoded_rate, unsigned int *flag) +{ + struct g729_context *context = codec->private; + int cbret = 0; + if (!context) { + return SWITCH_STATUS_FALSE; + } + if (decoded_data_len % 160 == 0) { + unsigned int new_len = 0; + INT16 * ddp = decoded_data; + char *edp = encoded_data; + int x; + int loops = (int) decoded_data_len / 160; + for (x = 0; x < loops && new_len < *encoded_data_len; x++) { + g729_coder(&context->encoder_object, ddp, edp, &cbret); + edp += 10; + ddp += 80; + new_len += 10; + } + if (new_len <= *encoded_data_len) { + *encoded_data_len = new_len; + } else { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len); + return SWITCH_STATUS_FALSE; + } + } + return SWITCH_STATUS_SUCCESS; + } + static switch_status switch_g729_decode(switch_codec *codec, switch_codec *other_codec, void *encoded_data, + size_t encoded_data_len, int encoded_rate, void *decoded_data, + size_t *decoded_data_len, int *decoded_rate, unsigned int *flag) +{ + struct g729_context *context = codec->private; + if (!context) { + return SWITCH_STATUS_FALSE; + } + if (encoded_data_len % 10 == 0) { + int loops = (int) encoded_data_len / 10; + char *edp = encoded_data; + short *ddp = decoded_data; + int x; + unsigned int new_len = 0; + for (x = 0; x < loops && new_len < *decoded_data_len; x++) { + g729_decoder(&context->decoder_object, ddp, edp, 10); + ddp += 80; + edp += 10; + new_len += 160; + } + if (new_len <= *decoded_data_len) { + *decoded_data_len = new_len; + } else { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n"); + return SWITCH_STATUS_FALSE; + } + } else { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len); + } + return SWITCH_STATUS_SUCCESS; + } + + +/* Registration */ + static const switch_codec_implementation g729_8k_implementation = { + /*.samples_per_second */ 8000, + /*.bits_per_second */ 64000, + /*.microseconds_per_frame */ 20000, + /*.samples_per_frame */ 160, + /*.bytes_per_frame */ 320, + /*.encoded_bytes_per_frame */ 20, + /*.number_of_channels */ 1, + /*.pref_frames_per_packet */ 1, + /*.max_frames_per_packet */ 24, + /*.init */ switch_g729_init, + /*.encode */ switch_g729_encode, + /*.decode */ switch_g729_decode, + /*.destroy */ switch_g729_destroy, +}; + static const switch_codec_interface g729_codec_interface = { + /*.interface_name */ "g729", + /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, + /*.ianacode */ 18, + /*.iananame */ "G729", + /*.implementations */ &g729_8k_implementation, +}; + static switch_loadable_module_interface g729_module_interface = { + /*.module_name */ modname, + /*.endpoint_interface */ NULL, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ &g729_codec_interface, + /*.application_interface */ NULL +}; + SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, + char *filename) +{ + + /* connect my internal structure to the blank pointer passed to me */ + *interface = &g729_module_interface; + + /* indicate that the module should continue to be loaded */ + return SWITCH_STATUS_SUCCESS; + } + + diff --git a/src/mod/codecs/mod_gsm/mod_gsm.c b/src/mod/codecs/mod_gsm/mod_gsm.c index b0e3e04258..8e5b819213 100644 --- a/src/mod/codecs/mod_gsm/mod_gsm.c +++ b/src/mod/codecs/mod_gsm/mod_gsm.c @@ -28,180 +28,148 @@ * * mod_codec_gsm.c -- gsm Codec Module * - */ + */ #include "switch.h" #include "gsm.h" - -static const char modname[] = "mod_codec_gsm"; - -struct gsm_context { - gsm encoder; - gsm decoder; -}; - -static switch_status switch_gsm_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings) -{ - struct gsm_context *context; - int encoding, decoding; - - encoding = (flags & SWITCH_CODEC_FLAG_ENCODE); - decoding = (flags & SWITCH_CODEC_FLAG_DECODE); - - if (!(encoding || decoding)) { - return SWITCH_STATUS_FALSE; - } else { - context = switch_core_alloc(codec->memory_pool, sizeof(*context)); - if (encoding) context->encoder = gsm_create(); - if (decoding) context->decoder = gsm_create(); - } - - codec->private = context; - - return SWITCH_STATUS_SUCCESS; - -} - -static switch_status switch_gsm_destroy(switch_codec *codec) -{ - struct gsm_context *context = codec->private; - int encoding = (codec->flags & SWITCH_CODEC_FLAG_ENCODE); - int decoding = (codec->flags & SWITCH_CODEC_FLAG_DECODE); - - if (encoding) gsm_destroy(context->encoder); - if (decoding) gsm_destroy(context->decoder); - - codec->private = NULL; - return SWITCH_STATUS_SUCCESS; -} - - -static switch_status switch_gsm_encode(switch_codec *codec, - switch_codec *other_codec, - void *decoded_data, - size_t decoded_data_len, - int decoded_rate, - void *encoded_data, - size_t *encoded_data_len, - int *encoded_rate, - unsigned int *flag) -{ - struct gsm_context *context = codec->private; - int cbret = 0; - - if (!context) { - return SWITCH_STATUS_FALSE; - } - if (decoded_data_len % 320 == 0) { - unsigned int new_len = 0; - gsm_signal *ddp = decoded_data; - gsm_byte *edp = encoded_data; - int x; - int loops = (int) decoded_data_len / 320; - for(x = 0; x < loops && new_len < *encoded_data_len; x++) { - gsm_encode(context->encoder, ddp, edp); - edp += 33; - ddp += 160; - new_len += 33; - } - if( new_len <= *encoded_data_len ) { - *encoded_data_len = new_len; - } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len); - return SWITCH_STATUS_FALSE; - } - } - - return SWITCH_STATUS_SUCCESS; -} - - -static switch_status switch_gsm_decode(switch_codec *codec, - switch_codec *other_codec, - void *encoded_data, - size_t encoded_data_len, - int encoded_rate, - void *decoded_data, - size_t *decoded_data_len, - int *decoded_rate, - unsigned int *flag) -{ - struct gsm_context *context = codec->private; - - if (!context) { - return SWITCH_STATUS_FALSE; - } - - - if (encoded_data_len % 33 == 0) { - int loops = (int) encoded_data_len / 33; - gsm_byte *edp = encoded_data; - gsm_signal *ddp = decoded_data; - int x; - unsigned int new_len = 0; - for(x = 0; x < loops && new_len < *decoded_data_len; x++) { - gsm_decode(context->decoder, edp, ddp); - ddp += 160; - edp += 33; - new_len += 320; - } - if (new_len <= *decoded_data_len) { - *decoded_data_len = new_len; - } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n"); - return SWITCH_STATUS_FALSE; - } - } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len); - } - - return SWITCH_STATUS_SUCCESS; -} - -/* Registration */ - -static const switch_codec_implementation gsm_8k_implementation = { - /*.samples_per_second*/ 8000, - /*.bits_per_second*/ 13200, - /*.microseconds_per_frame*/ 20000, - /*.samples_per_frame*/ 160, - /*.bytes_per_frame*/ 320, - /*.encoded_bytes_per_frame*/ 33, - /*.number_of_channels*/ 1, - /*.pref_frames_per_packet*/ 1, - /*.max_frames_per_packet*/ 1, - /*.init*/ switch_gsm_init, - /*.encode*/ switch_gsm_encode, - /*.decode*/ switch_gsm_decode, - /*.destroy*/ switch_gsm_destroy, -}; - -static const switch_codec_interface gsm_codec_interface = { - /*.interface_name*/ "gsm", - /*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO, - /*.ianacode*/ 3, - /*.iananame*/ "gsm", - /*.implementations*/ &gsm_8k_implementation, -}; - -static switch_loadable_module_interface gsm_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ NULL, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ &gsm_codec_interface, - /*.application_interface*/ NULL -}; - - -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { - /* connect my internal structure to the blank pointer passed to me */ - *interface = &gsm_module_interface; - - /* indicate that the module should continue to be loaded */ - return SWITCH_STATUS_SUCCESS; -} - - - - - + static const char modname[] = "mod_codec_gsm"; + struct gsm_context { + gsm encoder; + gsm decoder; + }; + static switch_status switch_gsm_init(switch_codec *codec, switch_codec_flag flags, + const struct switch_codec_settings *codec_settings) +{ + struct gsm_context *context; + int encoding, decoding; + encoding = (flags & SWITCH_CODEC_FLAG_ENCODE); + decoding = (flags & SWITCH_CODEC_FLAG_DECODE); + if (!(encoding || decoding)) { + return SWITCH_STATUS_FALSE; + } else { + context = switch_core_alloc(codec->memory_pool, sizeof(*context)); + if (encoding) + context->encoder = gsm_create(); + if (decoding) + context->decoder = gsm_create(); + } + codec->private = context; + return SWITCH_STATUS_SUCCESS; + } + static switch_status switch_gsm_destroy(switch_codec *codec) +{ + struct gsm_context *context = codec->private; + int encoding = (codec->flags & SWITCH_CODEC_FLAG_ENCODE); + int decoding = (codec->flags & SWITCH_CODEC_FLAG_DECODE); + if (encoding) + gsm_destroy(context->encoder); + if (decoding) + gsm_destroy(context->decoder); + codec->private = NULL; + return SWITCH_STATUS_SUCCESS; + } + static switch_status switch_gsm_encode(switch_codec *codec, switch_codec *other_codec, void *decoded_data, + size_t decoded_data_len, int decoded_rate, void *encoded_data, + size_t *encoded_data_len, int *encoded_rate, unsigned int *flag) +{ + struct gsm_context *context = codec->private; + int cbret = 0; + if (!context) { + return SWITCH_STATUS_FALSE; + } + if (decoded_data_len % 320 == 0) { + unsigned int new_len = 0; + gsm_signal * ddp = decoded_data; + gsm_byte * edp = encoded_data; + int x; + int loops = (int) decoded_data_len / 320; + for (x = 0; x < loops && new_len < *encoded_data_len; x++) { + gsm_encode(context->encoder, ddp, edp); + edp += 33; + ddp += 160; + new_len += 33; + } + if (new_len <= *encoded_data_len) { + *encoded_data_len = new_len; + } else { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len); + return SWITCH_STATUS_FALSE; + } + } + return SWITCH_STATUS_SUCCESS; + } + static switch_status switch_gsm_decode(switch_codec *codec, switch_codec *other_codec, void *encoded_data, + size_t encoded_data_len, int encoded_rate, void *decoded_data, + size_t *decoded_data_len, int *decoded_rate, unsigned int *flag) +{ + struct gsm_context *context = codec->private; + if (!context) { + return SWITCH_STATUS_FALSE; + } + if (encoded_data_len % 33 == 0) { + int loops = (int) encoded_data_len / 33; + gsm_byte * edp = encoded_data; + gsm_signal * ddp = decoded_data; + int x; + unsigned int new_len = 0; + for (x = 0; x < loops && new_len < *decoded_data_len; x++) { + gsm_decode(context->decoder, edp, ddp); + ddp += 160; + edp += 33; + new_len += 320; + } + if (new_len <= *decoded_data_len) { + *decoded_data_len = new_len; + } else { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n"); + return SWITCH_STATUS_FALSE; + } + } else { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len); + } + return SWITCH_STATUS_SUCCESS; + } + + +/* Registration */ + static const switch_codec_implementation gsm_8k_implementation = { + /*.samples_per_second */ 8000, + /*.bits_per_second */ 13200, + /*.microseconds_per_frame */ 20000, + /*.samples_per_frame */ 160, + /*.bytes_per_frame */ 320, + /*.encoded_bytes_per_frame */ 33, + /*.number_of_channels */ 1, + /*.pref_frames_per_packet */ 1, + /*.max_frames_per_packet */ 1, + /*.init */ switch_gsm_init, + /*.encode */ switch_gsm_encode, + /*.decode */ switch_gsm_decode, + /*.destroy */ switch_gsm_destroy, +}; + static const switch_codec_interface gsm_codec_interface = { + /*.interface_name */ "gsm", + /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, + /*.ianacode */ 3, + /*.iananame */ "gsm", + /*.implementations */ &gsm_8k_implementation, +}; + static switch_loadable_module_interface gsm_module_interface = { + /*.module_name */ modname, + /*.endpoint_interface */ NULL, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ &gsm_codec_interface, + /*.application_interface */ NULL +}; + SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, + char *filename) +{ + + /* connect my internal structure to the blank pointer passed to me */ + *interface = &gsm_module_interface; + + /* indicate that the module should continue to be loaded */ + return SWITCH_STATUS_SUCCESS; + } + + diff --git a/src/mod/codecs/mod_l16/mod_l16.c b/src/mod/codecs/mod_l16/mod_l16.c index bfab9083f0..15ed56501e 100644 --- a/src/mod/codecs/mod_l16/mod_l16.c +++ b/src/mod/codecs/mod_l16/mod_l16.c @@ -35,7 +35,8 @@ static const char modname[] = "mod_rawaudio"; -static switch_status switch_raw_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings) +static switch_status switch_raw_init(switch_codec *codec, switch_codec_flag flags, + const struct switch_codec_settings *codec_settings) { int encoding, decoding; struct raw_context *context = NULL; @@ -51,17 +52,15 @@ static switch_status switch_raw_init(switch_codec *codec, switch_codec_flag flag } static switch_status switch_raw_encode(switch_codec *codec, - switch_codec *other_codec, - void *decoded_data, - size_t decoded_data_len, - int decoded_rate, - void *encoded_data, - size_t *encoded_data_len, - int *encoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *decoded_data, + size_t decoded_data_len, + int decoded_rate, + void *encoded_data, + size_t *encoded_data_len, int *encoded_rate, unsigned int *flag) { - /* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary.*/ + /* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary. */ if (codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) { memcpy(encoded_data, decoded_data, decoded_data_len); *encoded_data_len = decoded_data_len; @@ -71,14 +70,12 @@ static switch_status switch_raw_encode(switch_codec *codec, } static switch_status switch_raw_decode(switch_codec *codec, - switch_codec *other_codec, - void *encoded_data, - size_t encoded_data_len, - int encoded_rate, - void *decoded_data, - size_t *decoded_data_len, - int *decoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *encoded_data, + size_t encoded_data_len, + int encoded_rate, + void *decoded_data, + size_t *decoded_data_len, int *decoded_rate, unsigned int *flag) { if (codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) { memcpy(decoded_data, encoded_data, encoded_data_len); @@ -91,12 +88,12 @@ static switch_status switch_raw_decode(switch_codec *codec, static switch_status switch_raw_destroy(switch_codec *codec) { - + return SWITCH_STATUS_SUCCESS; } static const switch_codec_implementation raw_32k_implementation = { - /*.samples_per_second = */ 32000, + /*.samples_per_second = */ 32000, /*.bits_per_second = */ 512000, /*.microseconds_per_frame = */ 20000, /*.samples_per_frame = */ 640, @@ -164,52 +161,48 @@ static const switch_codec_implementation raw_8k_implementation = { static const switch_codec_implementation raw_8k_30ms_implementation = { - /*.samples_per_second*/ 8000, - /*.bits_per_second*/ 128000, - /*.microseconds_per_frame*/ 30000, - /*.samples_per_frame*/ 240, - /*.bytes_per_frame*/ 480, - /*.encoded_bytes_per_frame*/ 480, - /*.number_of_channels*/ 1, - /*.pref_frames_per_packet*/ 1, - /*.max_frames_per_packet*/ 1, - /*.init*/ switch_raw_init, - /*.encode*/ switch_raw_encode, - /*.decode*/ switch_raw_decode, - /*.destroy*/ switch_raw_destroy, - /*.next*/ &raw_8k_implementation + /*.samples_per_second */ 8000, + /*.bits_per_second */ 128000, + /*.microseconds_per_frame */ 30000, + /*.samples_per_frame */ 240, + /*.bytes_per_frame */ 480, + /*.encoded_bytes_per_frame */ 480, + /*.number_of_channels */ 1, + /*.pref_frames_per_packet */ 1, + /*.max_frames_per_packet */ 1, + /*.init */ switch_raw_init, + /*.encode */ switch_raw_encode, + /*.decode */ switch_raw_decode, + /*.destroy */ switch_raw_destroy, + /*.next */ &raw_8k_implementation }; static const switch_codec_interface raw_codec_interface = { - /*.interface_name*/ "raw signed linear (16 bit)", - /*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO, - /*.ianacode*/ 10, - /*.iananame*/ "L16", - /*.implementations*/ &raw_8k_30ms_implementation + /*.interface_name */ "raw signed linear (16 bit)", + /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, + /*.ianacode */ 10, + /*.iananame */ "L16", + /*.implementations */ &raw_8k_30ms_implementation }; static switch_loadable_module_interface raw_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ NULL, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ &raw_codec_interface, - /*.application_interface*/ NULL, - /*.api_interface*/ NULL, - ///*.file_interface*/ &raw_file_interface + /*.module_name */ modname, + /*.endpoint_interface */ NULL, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ &raw_codec_interface, + /*.application_interface */ NULL, + /*.api_interface */ NULL, + ///*.file_interface*/ &raw_file_interface }; -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { - /* connect my internal structure to the blank pointer passed to me */ +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ + /* connect my internal structure to the blank pointer passed to me */ *interface = &raw_module_interface; - /* indicate that the module should continue to be loaded */ + /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } - - - - - diff --git a/src/mod/codecs/mod_speex/mod_speex.c b/src/mod/codecs/mod_speex/mod_speex.c index d20d646cab..ff5a6edba8 100644 --- a/src/mod/codecs/mod_speex/mod_speex.c +++ b/src/mod/codecs/mod_speex/mod_speex.c @@ -36,22 +36,22 @@ static const char modname[] = "mod_speexcodec"; const struct switch_codec_settings default_codec_settings = { - /*.quality*/ 5, - /*.complexity*/ 5, - /*.enhancement*/ 1, - /*.vad*/ 0, - /*.vbr*/ 0, - /*.vbr_quality*/ 4, - /*.abr*/ 0, - /*.dtx*/ 0, - /*.preproc*/ 0, - /*.pp_vad*/ 0, - /*.pp_agc*/ 0, - /*.pp_agc_level*/ 8000, - /*.pp_denoise*/ 0, - /*.pp_dereverb*/ 0, - /*.pp_dereverb_decay*/ 0.4f, - /*.pp_dereverb_level*/ 0.3f, + /*.quality */ 5, + /*.complexity */ 5, + /*.enhancement */ 1, + /*.vad */ 0, + /*.vbr */ 0, + /*.vbr_quality */ 4, + /*.abr */ 0, + /*.dtx */ 0, + /*.preproc */ 0, + /*.pp_vad */ 0, + /*.pp_agc */ 0, + /*.pp_agc_level */ 8000, + /*.pp_denoise */ 0, + /*.pp_dereverb */ 0, + /*.pp_dereverb_decay */ 0.4f, + /*.pp_dereverb_level */ 0.3f, }; struct speex_context { @@ -72,11 +72,12 @@ struct speex_context { int decoder_mode; }; -static switch_status switch_speex_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings) +static switch_status switch_speex_init(switch_codec *codec, switch_codec_flag flags, + const struct switch_codec_settings *codec_settings) { struct speex_context *context = NULL; int encoding, decoding; - + encoding = (flags & SWITCH_CODEC_FLAG_ENCODE); decoding = (flags & SWITCH_CODEC_FLAG_DECODE); @@ -90,7 +91,7 @@ static switch_status switch_speex_init(switch_codec *codec, switch_codec_flag fl return SWITCH_STATUS_FALSE; } else { const SpeexMode *mode = NULL; - + context->codec = codec; if (codec->implementation->samples_per_second == 8000) { mode = &speex_nb_mode; @@ -110,14 +111,17 @@ static switch_status switch_speex_init(switch_codec *codec, switch_codec_flag fl speex_encoder_ctl(context->encoder_state, SPEEX_GET_FRAME_SIZE, &context->encoder_frame_size); speex_encoder_ctl(context->encoder_state, SPEEX_SET_COMPLEXITY, &codec->codec_settings.complexity); if (codec->codec_settings.preproc) { - context->pp = speex_preprocess_state_init(context->encoder_frame_size, codec->implementation->samples_per_second); + context->pp = + speex_preprocess_state_init(context->encoder_frame_size, codec->implementation->samples_per_second); speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_VAD, &codec->codec_settings.pp_vad); speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_AGC, &codec->codec_settings.pp_agc); speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_AGC_LEVEL, &codec->codec_settings.pp_agc_level); speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DENOISE, &codec->codec_settings.pp_denoise); speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB, &codec->codec_settings.pp_dereverb); - speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &codec->codec_settings.pp_dereverb_decay); - speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &codec->codec_settings.pp_dereverb_level); + speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, + &codec->codec_settings.pp_dereverb_decay); + speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, + &codec->codec_settings.pp_dereverb_level); } if (!codec->codec_settings.abr && !codec->codec_settings.vbr) { @@ -134,8 +138,8 @@ static switch_status switch_speex_init(switch_codec *codec, switch_codec_flag fl speex_encoder_ctl(context->encoder_state, SPEEX_SET_ABR, &codec->codec_settings.abr); } if (codec->codec_settings.dtx) { - speex_encoder_ctl(context->encoder_state, SPEEX_SET_DTX, &codec->codec_settings.dtx); - } + speex_encoder_ctl(context->encoder_state, SPEEX_SET_DTX, &codec->codec_settings.dtx); + } } if (decoding) { @@ -154,14 +158,12 @@ static switch_status switch_speex_init(switch_codec *codec, switch_codec_flag fl } static switch_status switch_speex_encode(switch_codec *codec, - switch_codec *other_codec, - void *decoded_data, - size_t decoded_data_len, - int decoded_rate, - void *encoded_data, - size_t *encoded_data_len, - int *encoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *decoded_data, + size_t decoded_data_len, + int decoded_rate, + void *encoded_data, + size_t *encoded_data_len, int *encoded_rate, unsigned int *flag) { struct speex_context *context = codec->private; short *buf; @@ -178,7 +180,8 @@ static switch_status switch_speex_encode(switch_codec *codec, } if (is_speech) { - is_speech = speex_encode_int(context->encoder_state, buf, &context->encoder_bits) || ! context->codec->codec_settings.dtx; + is_speech = speex_encode_int(context->encoder_state, buf, &context->encoder_bits) + || !context->codec->codec_settings.dtx; } else { speex_bits_pack(&context->encoder_bits, 0, 5); } @@ -202,7 +205,7 @@ static switch_status switch_speex_encode(switch_codec *codec, speex_bits_pack(&context->encoder_bits, 15, 5); - *encoded_data_len = speex_bits_write(&context->encoder_bits, (char *)encoded_data, context->encoder_frame_size); + *encoded_data_len = speex_bits_write(&context->encoder_bits, (char *) encoded_data, context->encoder_frame_size); speex_bits_reset(&context->encoder_bits); @@ -210,14 +213,12 @@ static switch_status switch_speex_encode(switch_codec *codec, } static switch_status switch_speex_decode(switch_codec *codec, - switch_codec *other_codec, - void *encoded_data, - size_t encoded_data_len, - int encoded_rate, - void *decoded_data, - size_t *decoded_data_len, - int *decoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *encoded_data, + size_t encoded_data_len, + int encoded_rate, + void *decoded_data, + size_t *decoded_data_len, int *decoded_rate, unsigned int *flag) { struct speex_context *context = codec->private; short *buf; @@ -230,10 +231,10 @@ static switch_status switch_speex_decode(switch_codec *codec, if (*flag & SWITCH_CODEC_FLAG_SILENCE) { speex_decode_int(context->decoder_state, NULL, buf); } else { - speex_bits_read_from(&context->decoder_bits, (char *)encoded_data, (int)*decoded_data_len); + speex_bits_read_from(&context->decoder_bits, (char *) encoded_data, (int) *decoded_data_len); speex_decode_int(context->decoder_state, &context->decoder_bits, buf); } - + return SWITCH_STATUS_SUCCESS; } @@ -261,79 +262,80 @@ static switch_status switch_speex_destroy(switch_codec *codec) } codec->private = NULL; - + return SWITCH_STATUS_SUCCESS; } /* Registration */ static const switch_codec_implementation speex_32k_implementation = { - /*.samples_per_second*/ 32000, - /*.bits_per_second*/ 512000, - /*.nanoseconds_per_frame*/ 20000, - /*.samples_per_frame*/ 640, - /*.bytes_per_frame*/ 1280, - /*.encoded_bytes_per_frame*/ 1280, - /*.number_of_channels*/ 1, - /*.pref_frames_per_packet*/ 1, - /*.max_frames_per_packet*/ 1, - /*.init*/ switch_speex_init, - /*.encode*/ switch_speex_encode, - /*.decode*/ switch_speex_decode, - /*.destroy*/ switch_speex_destroy + /*.samples_per_second */ 32000, + /*.bits_per_second */ 512000, + /*.nanoseconds_per_frame */ 20000, + /*.samples_per_frame */ 640, + /*.bytes_per_frame */ 1280, + /*.encoded_bytes_per_frame */ 1280, + /*.number_of_channels */ 1, + /*.pref_frames_per_packet */ 1, + /*.max_frames_per_packet */ 1, + /*.init */ switch_speex_init, + /*.encode */ switch_speex_encode, + /*.decode */ switch_speex_decode, + /*.destroy */ switch_speex_destroy }; static const switch_codec_implementation speex_16k_implementation = { - /*.samples_per_second*/ 16000, - /*.bits_per_second*/ 256000, - /*.nanoseconds_per_frame*/ 20000, - /*.samples_per_frame*/ 320, - /*.bytes_per_frame*/ 640, - /*.encoded_bytes_per_frame*/ 640, - /*.number_of_channels*/ 1, - /*.pref_frames_per_packet*/ 1, - /*.max_frames_per_packet*/ 1, - /*.init*/ switch_speex_init, - /*.encode*/ switch_speex_encode, - /*.decode*/ switch_speex_decode, - /*.destroy*/ switch_speex_destroy, - /*.next*/ &speex_32k_implementation + /*.samples_per_second */ 16000, + /*.bits_per_second */ 256000, + /*.nanoseconds_per_frame */ 20000, + /*.samples_per_frame */ 320, + /*.bytes_per_frame */ 640, + /*.encoded_bytes_per_frame */ 640, + /*.number_of_channels */ 1, + /*.pref_frames_per_packet */ 1, + /*.max_frames_per_packet */ 1, + /*.init */ switch_speex_init, + /*.encode */ switch_speex_encode, + /*.decode */ switch_speex_decode, + /*.destroy */ switch_speex_destroy, + /*.next */ &speex_32k_implementation }; static const switch_codec_implementation speex_8k_implementation = { - /*.samples_per_second*/ 8000, - /*.bits_per_second*/ 128000, - /*.nanoseconds_per_frame*/ 20000, - /*.samples_per_frame*/ 160, - /*.bytes_per_frame*/ 320, - /*.encoded_bytes_per_frame*/ 320, - /*.number_of_channels*/ 1, - /*.pref_frames_per_packet*/ 1, - /*.max_frames_per_packet*/ 1, - /*.init*/ switch_speex_init, - /*.encode*/ switch_speex_encode, - /*.decode*/ switch_speex_decode, - /*.destroy*/ switch_speex_destroy, - /*.next*/ &speex_16k_implementation + /*.samples_per_second */ 8000, + /*.bits_per_second */ 128000, + /*.nanoseconds_per_frame */ 20000, + /*.samples_per_frame */ 160, + /*.bytes_per_frame */ 320, + /*.encoded_bytes_per_frame */ 320, + /*.number_of_channels */ 1, + /*.pref_frames_per_packet */ 1, + /*.max_frames_per_packet */ 1, + /*.init */ switch_speex_init, + /*.encode */ switch_speex_encode, + /*.decode */ switch_speex_decode, + /*.destroy */ switch_speex_destroy, + /*.next */ &speex_16k_implementation }; static const switch_codec_interface speex_codec_interface = { - /*.interface_name*/ "speex", - /*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO, - /*.ianacode*/ 98, - /*.iananame*/ "speex", - /*.implementations*/ &speex_8k_implementation + /*.interface_name */ "speex", + /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, + /*.ianacode */ 98, + /*.iananame */ "speex", + /*.implementations */ &speex_8k_implementation }; static switch_loadable_module_interface speex_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ NULL, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ &speex_codec_interface, - /*.application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ NULL, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ &speex_codec_interface, + /*.application_interface */ NULL }; -SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) +{ /* connect my internal structure to the blank pointer passed to me */ *interface = &speex_module_interface; diff --git a/src/mod/dialplans/mod_dialplan_demo/mod_dialplan_demo.c b/src/mod/dialplans/mod_dialplan_demo/mod_dialplan_demo.c index c071f613bb..611d149d95 100644 --- a/src/mod/dialplans/mod_dialplan_demo/mod_dialplan_demo.c +++ b/src/mod/dialplans/mod_dialplan_demo/mod_dialplan_demo.c @@ -52,7 +52,8 @@ switch_caller_extension *demo_dialplan_hunt(switch_core_session *session) caller_profile = switch_channel_get_caller_profile(channel); //switch_channel_set_variable(channel, "pleasework", "yay"); - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hello %s You Dialed %s!\n", caller_profile->caller_id_name, caller_profile->destination_number); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hello %s You Dialed %s!\n", caller_profile->caller_id_name, + caller_profile->destination_number); if (!switch_config_open_file(&cfg, cf)) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf); @@ -76,14 +77,17 @@ switch_caller_extension *demo_dialplan_hunt(switch_core_session *session) continue; } if (!extension) { - if (!(extension = switch_caller_extension_new(session, caller_profile->destination_number, caller_profile->destination_number))) { + if (! + (extension = + switch_caller_extension_new(session, caller_profile->destination_number, + caller_profile->destination_number))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "memory error!\n"); break; } } switch_caller_extension_add_application(session, extension, app, data); - } + } } } @@ -100,9 +104,9 @@ switch_caller_extension *demo_dialplan_hunt(switch_core_session *session) static const switch_dialplan_interface demo_dialplan_interface = { - /*.interface_name =*/ "demo", + /*.interface_name = */ "demo", /*.hunt_function = */ demo_dialplan_hunt - /*.next = NULL */ + /*.next = NULL */ }; static const switch_loadable_module_interface demo_dialplan_module_interface = { @@ -111,10 +115,11 @@ static const switch_loadable_module_interface demo_dialplan_module_interface = { /*.timer_interface = */ NULL, /*.dialplan_interface = */ &demo_dialplan_interface, /*.codec_interface = */ NULL, - /*.application_interface =*/ NULL + /*.application_interface = */ NULL }; -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ /* connect my internal structure to the blank pointer passed to me */ *interface = &demo_dialplan_module_interface; diff --git a/src/mod/dialplans/mod_pcre/mod_pcre.c b/src/mod/dialplans/mod_pcre/mod_pcre.c index 753c208210..3c5731428f 100644 --- a/src/mod/dialplans/mod_pcre/mod_pcre.c +++ b/src/mod/dialplans/mod_pcre/mod_pcre.c @@ -60,7 +60,8 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session) channel = switch_core_session_get_channel(session); caller_profile = switch_channel_get_caller_profile(channel); - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Processing %s->%s!\n", caller_profile->caller_id_name, caller_profile->destination_number); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Processing %s->%s!\n", caller_profile->caller_id_name, + caller_profile->destination_number); if (!switch_config_open_file(&cfg, cf)) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf); @@ -69,24 +70,23 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session) } while (switch_config_next_pair(&cfg, &var, &val)) { - if (cfg.catno != catno) { /* new category */ + if (cfg.catno != catno) { /* new category */ catno = cfg.catno; exten_name = cfg.category; cleanre(); match_count = 0; } - + if (!strcasecmp(var, "regex")) { const char *error = NULL; int erroffset = 0; - + cleanre(); - re = pcre_compile( - val, /* the pattern */ - 0, /* default options */ - &error, /* for error message */ - &erroffset, /* for error offset */ - NULL); /* use default character tables */ + re = pcre_compile(val, /* the pattern */ + 0, /* default options */ + &error, /* for error message */ + &erroffset, /* for error offset */ + NULL); /* use default character tables */ if (error) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "COMPILE ERROR: %d [%s]\n", erroffset, error); cleanre(); @@ -94,31 +94,31 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session) return NULL; } - match_count = pcre_exec( - re, /* result of pcre_compile() */ - NULL, /* we didn't study the pattern */ - caller_profile->destination_number, /* the subject string */ - strlen(caller_profile->destination_number), /* the length of the subject string */ - 0, /* start at offset 0 in the subject */ - 0, /* default options */ - ovector, /* vector of integers for substring information */ - sizeof(ovector) / sizeof(ovector[0])); /* number of elements (NOT size in bytes) */ + match_count = pcre_exec(re, /* result of pcre_compile() */ + NULL, /* we didn't study the pattern */ + caller_profile->destination_number, /* the subject string */ + strlen(caller_profile->destination_number), /* the length of the subject string */ + 0, /* start at offset 0 in the subject */ + 0, /* default options */ + ovector, /* vector of integers for substring information */ + sizeof(ovector) / sizeof(ovector[0])); /* number of elements (NOT size in bytes) */ } else if (match_count > 0 && !strcasecmp(var, "match")) { if (!re) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "ERROR: match without regex in %s line %d\n", cfg.path, cfg.lineno); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "ERROR: match without regex in %s line %d\n", cfg.path, + cfg.lineno); continue; } else { char newval[1024] = ""; char index[10] = ""; char replace[128] = ""; - int x, y=0, z=0, num = 0; + int x, y = 0, z = 0, num = 0; char *data; for (x = 0; x < sizeof(newval) && x < strlen(val);) { if (val[x] == '$') { x++; - - while(val[x] > 47 && val[x] < 58) { + + while (val[x] > 47 && val[x] < 58) { index[z++] = val[x]; x++; } @@ -126,9 +126,11 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session) z = 0; num = atoi(index); - if (pcre_copy_substring(caller_profile->destination_number, ovector, match_count, num, replace, sizeof(replace)) > 0) { + if (pcre_copy_substring + (caller_profile->destination_number, ovector, match_count, num, replace, + sizeof(replace)) > 0) { int r; - for(r = 0; r < strlen(replace); r++) { + for (r = 0; r < strlen(replace); r++) { newval[y++] = replace[r]; } } @@ -150,9 +152,11 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session) continue; } - + if (!extension) { - if (!(extension = switch_caller_extension_new(session, exten_name, caller_profile->destination_number))) { + if (! + (extension = + switch_caller_extension_new(session, exten_name, caller_profile->destination_number))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "memory error!\n"); break; } @@ -162,7 +166,7 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session) } } } - + switch_config_close_file(&cfg); if (extension) { @@ -177,9 +181,9 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session) static const switch_dialplan_interface dialplan_interface = { - /*.interface_name =*/ "pcre", + /*.interface_name = */ "pcre", /*.hunt_function = */ dialplan_hunt - /*.next = NULL */ + /*.next = NULL */ }; static const switch_loadable_module_interface dialplan_module_interface = { @@ -188,10 +192,11 @@ static const switch_loadable_module_interface dialplan_module_interface = { /*.timer_interface = */ NULL, /*.dialplan_interface = */ &dialplan_interface, /*.codec_interface = */ NULL, - /*.application_interface =*/ NULL + /*.application_interface = */ NULL }; -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ /* connect my internal structure to the blank pointer passed to me */ *interface = &dialplan_module_interface; diff --git a/src/mod/endpoints/mod_exosip/mod_exosip.c b/src/mod/endpoints/mod_exosip/mod_exosip.c index aef165afc0..1012d1f2e0 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip.c @@ -61,7 +61,7 @@ typedef enum { TFLAG_DTMF = (1 << 3), TFLAG_READING = (1 << 4), TFLAG_WRITING = (1 << 5), - TFLAG_USING_CODEC = (1 << 6), + TFLAG_USING_CODEC = (1 << 6), TFLAG_RTP = (1 << 7), TFLAG_BYE = (1 << 8) } TFLAGS; @@ -87,7 +87,7 @@ static struct { } globals; struct private_object { - unsigned int flags; + unsigned int flags; switch_core_session *session; switch_frame read_frame; switch_codec read_codec; @@ -144,11 +144,14 @@ static switch_status exosip_on_init(switch_core_session *session); static switch_status exosip_on_hangup(switch_core_session *session); static switch_status exosip_on_loopback(switch_core_session *session); static switch_status exosip_on_transmit(switch_core_session *session); -static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id); -static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id); +static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session); +static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags, int stream_id); +static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags, int stream_id); static int config_exosip(int reload); -static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload); +static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload); static switch_status exosip_kill_channel(switch_core_session *session, int sig); static void activate_rtp(struct private_object *tech_pvt); static void deactivate_rtp(struct private_object *tech_pvt); @@ -190,16 +193,16 @@ static int sdp_add_codec(struct osip_rfc3264 *cnf, int codec_type, int payload, } switch (codec_type) { -case SWITCH_CODEC_TYPE_AUDIO: - med->m_media = osip_strdup("audio"); - osip_rfc3264_add_audio_media(cnf, med, -1); - break; -case SWITCH_CODEC_TYPE_VIDEO: - med->m_media = osip_strdup("video"); - osip_rfc3264_add_video_media(cnf, med, -1); - break; -default: - break; + case SWITCH_CODEC_TYPE_AUDIO: + med->m_media = osip_strdup("audio"); + osip_rfc3264_add_audio_media(cnf, med, -1); + break; + case SWITCH_CODEC_TYPE_VIDEO: + med->m_media = osip_strdup("video"); + osip_rfc3264_add_video_media(cnf, med, -1); + break; + default: + break; } return 0; } @@ -232,7 +235,7 @@ static switch_status exosip_on_init(switch_core_session *session) char *dest_uri; switch_codec_interface *codecs[SWITCH_MAX_CODECS]; int num_codecs = 0; - /* do SIP Goodies...*/ + /* do SIP Goodies... */ /* Generate callerid URI */ eXosip_guess_localip(AF_INET, localip, 128); @@ -245,14 +248,17 @@ static switch_status exosip_on_init(switch_core_session *session) /* Initialize SDP */ sdp_message_init(&tech_pvt->local_sdp); sdp_message_v_version_set(tech_pvt->local_sdp, "0"); - sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip); + sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", + tech_pvt->local_sdp_audio_ip); sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call"); sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL); sdp_message_t_time_descr_add(tech_pvt->local_sdp, "0", "0"); snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port); sdp_message_m_media_add(tech_pvt->local_sdp, "audio", port, NULL, "RTP/AVP"); /* Add in every codec we support on this outbound call */ - if ((num_codecs = switch_loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) { + if ((num_codecs = + switch_loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, + sizeof(codecs) / sizeof(codecs[0]))) > 0) { int i; static const switch_codec_implementation *imp; for (i = 0; i < num_codecs; i++) { @@ -260,12 +266,14 @@ static switch_status exosip_on_init(switch_core_session *session) snprintf(tmp, sizeof(tmp), "%i", codecs[i]->ianacode); sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup(tmp)); - for (imp = codecs[i]->implementations ; imp ; imp = imp->next) { + for (imp = codecs[i]->implementations; imp; imp = imp->next) { /* Add to SDP config */ - sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++); + sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, + imp->samples_per_second, x++); /* Add to SDP message */ - snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second); + snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame, + imp->samples_per_second); sdp_message_a_attribute_add(tech_pvt->local_sdp, 0, "rtpmap", osip_strdup(tmp)); memset(tmp, 0, sizeof(tmp)); } @@ -273,7 +281,9 @@ static switch_status exosip_on_init(switch_core_session *session) } /* Setup our INVITE */ eXosip_lock(); - if (!(dest_uri = (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) { + if (! + (dest_uri = + (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "AIEEEE!\n"); assert(dest_uri != NULL); } @@ -292,7 +302,7 @@ static switch_status exosip_on_init(switch_core_session *session) switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); tech_pvt->did = -1; eXosip_unlock(); - } + } /* Let Media Work */ switch_set_flag(tech_pvt, TFLAG_IO); @@ -331,7 +341,7 @@ static switch_status exosip_on_hangup(switch_core_session *session) assert(tech_pvt != NULL); - switch_core_hash_delete(globals.call_hash, tech_pvt->call_id); + switch_core_hash_delete(globals.call_hash, tech_pvt->call_id); switch_set_flag(tech_pvt, TFLAG_BYE); @@ -346,7 +356,8 @@ static switch_status exosip_on_hangup(switch_core_session *session) switch_core_codec_destroy(&tech_pvt->write_codec); } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel), tech_pvt->cid, tech_pvt->did, i); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel), + tech_pvt->cid, tech_pvt->did, i); return SWITCH_STATUS_SUCCESS; } @@ -362,14 +373,16 @@ static switch_status exosip_on_transmit(switch_core_session *session) return SWITCH_STATUS_SUCCESS; } -static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session) +static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session) { if ((*new_session = switch_core_session_request(&exosip_endpoint_interface, NULL))) { struct private_object *tech_pvt; switch_channel *channel; switch_core_session_add_stream(*new_session, NULL); - if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { + if ((tech_pvt = + (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(*new_session); switch_core_session_set_private(*new_session, tech_pvt); @@ -412,7 +425,7 @@ static void deactivate_rtp(struct private_object *tech_pvt) if (tech_pvt->rtp_session) { switch_mutex_lock(tech_pvt->rtp_lock); - while(loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) { + while (loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) { switch_yield(10000); loops++; } @@ -454,25 +467,20 @@ static void activate_rtp(struct private_object *tech_pvt) } switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activating RTP %s:%d->%s:%d codec: %d ms: %d\n", - tech_pvt->local_sdp_audio_ip, - tech_pvt->local_sdp_audio_port, - tech_pvt->remote_sdp_audio_ip, - tech_pvt->remote_sdp_audio_port, - tech_pvt->read_codec.codec_interface->ianacode, - ms - ); + tech_pvt->local_sdp_audio_ip, + tech_pvt->local_sdp_audio_port, + tech_pvt->remote_sdp_audio_ip, + tech_pvt->remote_sdp_audio_port, tech_pvt->read_codec.codec_interface->ianacode, ms); - tech_pvt->rtp_session = jrtp4c_new( - tech_pvt->local_sdp_audio_ip, - tech_pvt->local_sdp_audio_port, - tech_pvt->remote_sdp_audio_ip, - tech_pvt->remote_sdp_audio_port, - tech_pvt->read_codec.codec_interface->ianacode, - tech_pvt->read_codec.implementation->samples_per_second, - &err); + tech_pvt->rtp_session = jrtp4c_new(tech_pvt->local_sdp_audio_ip, + tech_pvt->local_sdp_audio_port, + tech_pvt->remote_sdp_audio_ip, + tech_pvt->remote_sdp_audio_port, + tech_pvt->read_codec.codec_interface->ianacode, + tech_pvt->read_codec.implementation->samples_per_second, &err); if (tech_pvt->rtp_session) { tech_pvt->ssrc = jrtp4c_get_ssrc(tech_pvt->rtp_session); @@ -511,20 +519,21 @@ static switch_status exosip_answer_channel(switch_core_session *session) sdp_message_to_str(tech_pvt->local_sdp, &buf); osip_message_set_body(answer, buf, strlen(buf)); osip_message_set_content_type(answer, "application/sdp"); - free(buf); + free(buf); eXosip_call_send_answer(tech_pvt->tid, 200, answer); eXosip_unlock(); - } + } return SWITCH_STATUS_SUCCESS; } -static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id) +static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags, int stream_id) { struct private_object *tech_pvt = NULL; - size_t bytes = 0, samples = 0, frames=0, ms=0; + size_t bytes = 0, samples = 0, frames = 0, ms = 0; switch_channel *channel = NULL; channel = switch_core_session_get_channel(session); @@ -553,18 +562,18 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram assert(tech_pvt->rtp_session != NULL); tech_pvt->read_frame.datalen = 0; - while(!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) { - tech_pvt->read_frame.datalen = jrtp4c_read(tech_pvt->rtp_session, - tech_pvt->read_frame.data, - sizeof(tech_pvt->read_buf)); + while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) + && tech_pvt->read_frame.datalen == 0) { + tech_pvt->read_frame.datalen = + jrtp4c_read(tech_pvt->rtp_session, tech_pvt->read_frame.data, sizeof(tech_pvt->read_buf)); if (tech_pvt->read_frame.datalen > 0) { bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame; frames = (tech_pvt->read_frame.datalen / bytes); samples = frames * tech_pvt->read_codec.implementation->samples_per_frame; ms = frames * tech_pvt->read_codec.implementation->microseconds_per_frame; - tech_pvt->timestamp_recv += (int32_t)samples; - tech_pvt->read_frame.samples = (int)samples; + tech_pvt->timestamp_recv += (int32_t) samples; + tech_pvt->read_frame.samples = (int) samples; break; } @@ -598,12 +607,13 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram } -static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) +static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags, int stream_id) { struct private_object *tech_pvt; switch_channel *channel = NULL; switch_status status = SWITCH_STATUS_SUCCESS; - int bytes=0, samples=0, ms=0, frames=0; + int bytes = 0, samples = 0, ms = 0, frames = 0; channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -629,7 +639,7 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra if (switch_test_flag(tech_pvt, TFLAG_USING_CODEC)) { bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame; - frames = ((int)frame->datalen / bytes); + frames = ((int) frame->datalen / bytes); samples = frames * tech_pvt->read_codec.implementation->samples_per_frame; ms = frames * tech_pvt->read_codec.implementation->microseconds_per_frame / 1000; } else { @@ -640,8 +650,8 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra //printf("%s %s->%s send %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, ms, tech_pvt->timestamp_send); - jrtp4c_write(tech_pvt->rtp_session, frame->data, (int)frame->datalen, samples); - tech_pvt->timestamp_send += (int)samples; + jrtp4c_write(tech_pvt->rtp_session, frame->data, (int) frame->datalen, samples); + tech_pvt->timestamp_send += (int) samples; switch_clear_flag(tech_pvt, TFLAG_WRITING); //switch_mutex_unlock(tech_pvt->rtp_lock); @@ -700,39 +710,39 @@ static switch_status exosip_waitfor_write(switch_core_session *session, int ms, } static const switch_io_routines exosip_io_routines = { - /*.outgoing_channel*/ exosip_outgoing_channel, - /*.answer_channel*/ exosip_answer_channel, - /*.read_frame*/ exosip_read_frame, - /*.write_frame*/ exosip_write_frame, - /*.kill_channel*/ exosip_kill_channel, - /*.waitfor_read*/ exosip_waitfor_read, - /*.waitfor_read*/ exosip_waitfor_write + /*.outgoing_channel */ exosip_outgoing_channel, + /*.answer_channel */ exosip_answer_channel, + /*.read_frame */ exosip_read_frame, + /*.write_frame */ exosip_write_frame, + /*.kill_channel */ exosip_kill_channel, + /*.waitfor_read */ exosip_waitfor_read, + /*.waitfor_read */ exosip_waitfor_write }; -static const switch_event_handler_table exosip_event_handlers = { - /*.on_init*/ exosip_on_init, - /*.on_ring*/ exosip_on_ring, - /*.on_execute*/ exosip_on_execute, - /*.on_hangup*/ exosip_on_hangup, - /*.on_loopback*/ exosip_on_loopback, - /*.on_transmit*/ exosip_on_transmit +static const switch_event_handler_table exosip_event_handlers = { + /*.on_init */ exosip_on_init, + /*.on_ring */ exosip_on_ring, + /*.on_execute */ exosip_on_execute, + /*.on_hangup */ exosip_on_hangup, + /*.on_loopback */ exosip_on_loopback, + /*.on_transmit */ exosip_on_transmit }; static const switch_endpoint_interface exosip_endpoint_interface = { - /*.interface_name*/ "exosip", - /*.io_routines*/ &exosip_io_routines, - /*.event_handlers*/ &exosip_event_handlers, - /*.private*/ NULL, - /*.next*/ NULL + /*.interface_name */ "exosip", + /*.io_routines */ &exosip_io_routines, + /*.event_handlers */ &exosip_event_handlers, + /*.private */ NULL, + /*.next */ NULL }; static const switch_loadable_module_interface exosip_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ &exosip_endpoint_interface, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ NULL, - /*.application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ &exosip_endpoint_interface, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL }; #if 1 @@ -740,14 +750,15 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void) { if (globals.running) { globals.running = -1; - while(globals.running) { + while (globals.running) { switch_yield(100000); } } return SWITCH_STATUS_SUCCESS; } #endif -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ /* NOTE: **interface is **_interface because the common lib redefines interface to struct in some situations */ if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) { @@ -762,7 +773,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul return SWITCH_STATUS_SUCCESS; } -static switch_status exosip_create_call(eXosip_event_t *event) +static switch_status exosip_create_call(eXosip_event_t * event) { switch_core_session *session; sdp_message_t *remote_sdp = NULL; @@ -794,14 +805,12 @@ static switch_status exosip_create_call(eXosip_event_t *event) } if ((tech_pvt->caller_profile = switch_caller_profile_new(session, - globals.dialplan, - event->request->from->displayname, - event->request->from->url->username, - event->request->from->url->host, - NULL, - NULL, - event->request->req_uri->username))) { - switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); + globals.dialplan, + event->request->from->displayname, + event->request->from->url->username, + event->request->from->url->host, + NULL, NULL, event->request->req_uri->username))) { + switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); } switch_set_flag(tech_pvt, TFLAG_INBOUND); @@ -824,14 +833,17 @@ static switch_status exosip_create_call(eXosip_event_t *event) osip_rfc3264_init(&tech_pvt->sdp_config); /* Add in what codecs we support locally */ - if ((num_codecs = switch_loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) { + if ((num_codecs = + switch_loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, + sizeof(codecs) / sizeof(codecs[0]))) > 0) { int i; static const switch_codec_implementation *imp; for (i = 0; i < num_codecs; i++) { int x = 0; - for (imp = codecs[i]->implementations ; imp ; imp = imp->next) { - sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++); + for (imp = codecs[i]->implementations; imp; imp = imp->next) { + sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, + imp->samples_per_second, x++); } } } @@ -840,17 +852,18 @@ static switch_status exosip_create_call(eXosip_event_t *event) sdp_message_parse(tech_pvt->local_sdp, local_sdp_str); sdp_message_to_str(remote_sdp, &remote_sdp_str); - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str,remote_sdp_str); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str, remote_sdp_str); mline = 0; - while (0==osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) { + while (0 == osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) { if (audio_tab[0] == NULL && video_tab[0] == NULL && t38_tab[0] == NULL && app_tab[0] == NULL) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got no compatible codecs!\n"); break; } - for (pos=0; audio_tab[pos]!=NULL; pos++) { - osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos], mline); + for (pos = 0; audio_tab[pos] != NULL; pos++) { + osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos], + mline); if (parse_sdp_media(audio_tab[pos], &dname, &drate, &dpayload) == SWITCH_STATUS_SUCCESS) { tech_pvt->payload_num = atoi(dpayload); break; @@ -859,7 +872,8 @@ static switch_status exosip_create_call(eXosip_event_t *event) mline++; } free(remote_sdp_str); - sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip); + sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", + tech_pvt->local_sdp_audio_ip); sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call"); sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL); snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port); @@ -872,7 +886,7 @@ static switch_status exosip_create_call(eXosip_event_t *event) tech_pvt->remote_sdp_audio_port = atoi(remote_med->m_port); snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", event->cid); - switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); + switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); if (!dname) { exosip_on_hangup(session); @@ -887,34 +901,33 @@ static switch_status exosip_create_call(eXosip_event_t *event) int rate = atoi(drate); if (switch_core_codec_init(&tech_pvt->read_codec, - dname, - rate, - globals.codec_ms, - 1, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL, - switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { + dname, + rate, + globals.codec_ms, + 1, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); + switch_channel_hangup(channel); + return SWITCH_STATUS_FALSE; + } else { + if (switch_core_codec_init(&tech_pvt->write_codec, + dname, + rate, + globals.codec_ms, + 1, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_channel_hangup(channel); return SWITCH_STATUS_FALSE; - } else { - if (switch_core_codec_init(&tech_pvt->write_codec, - dname, - rate, - globals.codec_ms, - 1, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL, - switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); - switch_channel_hangup(channel); - return SWITCH_STATUS_FALSE; } else { int ms; tech_pvt->read_frame.rate = rate; switch_set_flag(tech_pvt, TFLAG_USING_CODEC); ms = tech_pvt->write_codec.implementation->microseconds_per_frame / 1000; - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate, ms); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate, + ms); tech_pvt->read_frame.codec = &tech_pvt->read_codec; switch_core_session_set_read_codec(session, &tech_pvt->read_codec); switch_core_session_set_write_codec(session, &tech_pvt->write_codec); @@ -939,13 +952,14 @@ static switch_status exosip_create_call(eXosip_event_t *event) } -static void destroy_call_by_event(eXosip_event_t *event) +static void destroy_call_by_event(eXosip_event_t * event) { struct private_object *tech_pvt; switch_channel *channel = NULL; if (!(tech_pvt = get_pvt_by_call_id(event->cid))) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n", event->cid); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n", + event->cid); return; } @@ -958,7 +972,7 @@ static void destroy_call_by_event(eXosip_event_t *event) } -static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload) +static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload) { int pos = 0; sdp_attribute_t *attr = NULL; @@ -966,7 +980,7 @@ static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **dr switch_status status = SWITCH_STATUS_GENERR; while (osip_list_eol(media->a_attributes, pos) == 0) { - attr = (sdp_attribute_t *)osip_list_get(media->a_attributes, pos); + attr = (sdp_attribute_t *) osip_list_get(media->a_attributes, pos); if (attr != NULL && strcasecmp(attr->a_att_field, "rtpmap") == 0) { payload = attr->a_att_value; if ((name = strchr(payload, ' '))) { @@ -987,7 +1001,8 @@ static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **dr *dname = strdup("L16"); *drate = strdup("8000"); } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n", *dpayload, *dname, *drate); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n", + *dpayload, *dname, *drate); break; } attr = NULL; @@ -997,7 +1012,7 @@ static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **dr return status; } -static void handle_answer(eXosip_event_t *event) +static void handle_answer(eXosip_event_t * event) { osip_message_t *ack = NULL; sdp_message_t *remote_sdp = NULL; @@ -1052,28 +1067,27 @@ static void handle_answer(eXosip_event_t *event) if (switch_core_codec_init(&tech_pvt->read_codec, - dname, - rate, - globals.codec_ms, - 1, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL, - switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { + dname, + rate, + globals.codec_ms, + 1, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); + switch_channel_hangup(channel); + return; + } else { + if (switch_core_codec_init(&tech_pvt->write_codec, + dname, + rate, + globals.codec_ms, + 1, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, + switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_channel_hangup(channel); return; - } else { - if (switch_core_codec_init(&tech_pvt->write_codec, - dname, - rate, - globals.codec_ms, - 1, - SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE, - NULL, - switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); - switch_channel_hangup(channel); - return; } else { int ms; tech_pvt->read_frame.rate = rate; @@ -1107,133 +1121,119 @@ static void handle_answer(eXosip_event_t *event) } } -static void log_event(eXosip_event_t *je) +static void log_event(eXosip_event_t * je) { char buf[100]; buf[0] = '\0'; if (je->type == EXOSIP_CALL_NOANSWER) { - snprintf (buf, 99, "<- (%i %i) No answer", je->cid, je->did); + snprintf(buf, 99, "<- (%i %i) No answer", je->cid, je->did); } else if (je->type == EXOSIP_CALL_CLOSED) { - snprintf (buf, 99, "<- (%i %i) Call Closed", je->cid, je->did); + snprintf(buf, 99, "<- (%i %i) Call Closed", je->cid, je->did); } else if (je->type == EXOSIP_CALL_RELEASED) { - snprintf (buf, 99, "<- (%i %i) Call released", je->cid, je->did); - } else if (je->type == EXOSIP_MESSAGE_NEW - && je->request!=NULL && MSG_IS_MESSAGE(je->request)) { - char *tmp = NULL; + snprintf(buf, 99, "<- (%i %i) Call released", je->cid, je->did); + } else if (je->type == EXOSIP_MESSAGE_NEW && je->request != NULL && MSG_IS_MESSAGE(je->request)) { + char *tmp = NULL; - if (je->request != NULL) { - osip_body_t *body; - osip_from_to_str (je->request->from, &tmp); + if (je->request != NULL) { + osip_body_t *body; + osip_from_to_str(je->request->from, &tmp); - osip_message_get_body (je->request, 0, &body); - if (body != NULL && body->body != NULL) { - snprintf (buf, 99, "<- (%i) from: %s TEXT: %s", - je->tid, tmp, body->body); - } - osip_free (tmp); - } else { - snprintf (buf, 99, "<- (%i) New event for unknown request?", je->tid); + osip_message_get_body(je->request, 0, &body); + if (body != NULL && body->body != NULL) { + snprintf(buf, 99, "<- (%i) from: %s TEXT: %s", je->tid, tmp, body->body); } + osip_free(tmp); + } else { + snprintf(buf, 99, "<- (%i) New event for unknown request?", je->tid); + } } else if (je->type == EXOSIP_MESSAGE_NEW) { char *tmp = NULL; - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (%i) %s from: %s", - je->tid, je->request->sip_method, tmp); - osip_free (tmp); + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (%i) %s from: %s", je->tid, je->request->sip_method, tmp); + osip_free(tmp); } else if (je->type == EXOSIP_MESSAGE_PROCEEDING - || je->type == EXOSIP_MESSAGE_ANSWERED - || je->type == EXOSIP_MESSAGE_REDIRECTED - || je->type == EXOSIP_MESSAGE_REQUESTFAILURE - || je->type == EXOSIP_MESSAGE_SERVERFAILURE - || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) { - if (je->response != NULL && je->request != NULL) { - char *tmp = NULL; + || je->type == EXOSIP_MESSAGE_ANSWERED + || je->type == EXOSIP_MESSAGE_REDIRECTED + || je->type == EXOSIP_MESSAGE_REQUESTFAILURE + || je->type == EXOSIP_MESSAGE_SERVERFAILURE || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) { + if (je->response != NULL && je->request != NULL) { + char *tmp = NULL; - osip_to_to_str (je->request->to, &tmp); - snprintf (buf, 99, "<- (%i) [%i %s for %s] to: %s", - je->tid, je->response->status_code, - je->response->reason_phrase, je->request->sip_method, tmp); - osip_free (tmp); - } else if (je->request != NULL) { - snprintf (buf, 99, "<- (%i) Error for %s request", - je->tid, je->request->sip_method); - } else { - snprintf (buf, 99, "<- (%i) Error for unknown request", je->tid); - } + osip_to_to_str(je->request->to, &tmp); + snprintf(buf, 99, "<- (%i) [%i %s for %s] to: %s", + je->tid, je->response->status_code, je->response->reason_phrase, je->request->sip_method, tmp); + osip_free(tmp); + } else if (je->request != NULL) { + snprintf(buf, 99, "<- (%i) Error for %s request", je->tid, je->request->sip_method); + } else { + snprintf(buf, 99, "<- (%i) Error for unknown request", je->tid); + } } else if (je->response == NULL && je->request != NULL && je->cid > 0) { char *tmp = NULL; - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (%i %i) %s from: %s", - je->cid, je->did, je->request->cseq->method, tmp); - osip_free (tmp); + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (%i %i) %s from: %s", je->cid, je->did, je->request->cseq->method, tmp); + osip_free(tmp); } else if (je->response != NULL && je->cid > 0) { char *tmp = NULL; - osip_to_to_str (je->request->to, &tmp); - snprintf (buf, 99, "<- (%i %i) [%i %s] for %s to: %s", - je->cid, je->did, je->response->status_code, - je->response->reason_phrase, je->request->sip_method, tmp); - osip_free (tmp); + osip_to_to_str(je->request->to, &tmp); + snprintf(buf, 99, "<- (%i %i) [%i %s] for %s to: %s", + je->cid, je->did, je->response->status_code, + je->response->reason_phrase, je->request->sip_method, tmp); + osip_free(tmp); } else if (je->response == NULL && je->request != NULL && je->rid > 0) { char *tmp = NULL; - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (%i) %s from: %s", - je->rid, je->request->cseq->method, tmp); - osip_free (tmp); + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (%i) %s from: %s", je->rid, je->request->cseq->method, tmp); + osip_free(tmp); } else if (je->response != NULL && je->rid > 0) { char *tmp = NULL; - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (%i) [%i %s] from: %s", - je->rid, je->response->status_code, - je->response->reason_phrase, tmp); - osip_free (tmp); + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (%i) [%i %s] from: %s", + je->rid, je->response->status_code, je->response->reason_phrase, tmp); + osip_free(tmp); } else if (je->response == NULL && je->request != NULL && je->sid > 0) { char *tmp = NULL; char *stat = NULL; osip_header_t *sub_state; - osip_message_header_get_byname (je->request, "subscription-state", - 0, &sub_state); + osip_message_header_get_byname(je->request, "subscription-state", 0, &sub_state); if (sub_state != NULL && sub_state->hvalue != NULL) stat = sub_state->hvalue; - osip_uri_to_str (je->request->from->url, &tmp); - snprintf (buf, 99, "<- (%i) [%s] %s from: %s", - je->sid, stat, je->request->cseq->method, tmp); - osip_free (tmp); + osip_uri_to_str(je->request->from->url, &tmp); + snprintf(buf, 99, "<- (%i) [%s] %s from: %s", je->sid, stat, je->request->cseq->method, tmp); + osip_free(tmp); } else if (je->response != NULL && je->sid > 0) { char *tmp = NULL; - osip_uri_to_str (je->request->to->url, &tmp); - snprintf (buf, 99, "<- (%i) [%i %s] from: %s", - je->sid, je->response->status_code, - je->response->reason_phrase, tmp); - osip_free (tmp); + osip_uri_to_str(je->request->to->url, &tmp); + snprintf(buf, 99, "<- (%i) [%i %s] from: %s", + je->sid, je->response->status_code, je->response->reason_phrase, tmp); + osip_free(tmp); } else if (je->response == NULL && je->request != NULL) { char *tmp = NULL; - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s", - je->cid, je->did, je->sid, je->nid, - je->request->sip_method, tmp); - osip_free (tmp); + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s", + je->cid, je->did, je->sid, je->nid, je->request->sip_method, tmp); + osip_free(tmp); } else if (je->response != NULL) { char *tmp = NULL; - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s", - je->cid, je->did, je->sid, je->nid, - je->response->status_code, je->response->reason_phrase, - je->request->sip_method, tmp); - osip_free (tmp); + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s", + je->cid, je->did, je->sid, je->nid, + je->response->status_code, je->response->reason_phrase, je->request->sip_method, tmp); + osip_free(tmp); } else { - snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s", - je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo); + snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s", + je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo); } switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\n%s\n", buf); /* Print it out */ @@ -1241,7 +1241,7 @@ static void log_event(eXosip_event_t *je) -static int config_exosip(int reload) +static int config_exosip(int reload) { switch_config cfg; char *var, *val; @@ -1307,88 +1307,88 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) config_exosip(0); - if (eXosip_init ()) { + if (eXosip_init()) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_init initialization failed!\n"); return SWITCH_STATUS_TERM; } - if (eXosip_listen_addr (IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) { + if (eXosip_listen_addr(IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_listen_addr failed!\n"); return SWITCH_STATUS_TERM; } - + globals.running = 1; while (globals.running > 0) { - if (!(event = eXosip_event_wait(0,100))) { + if (!(event = eXosip_event_wait(0, 100))) { switch_yield(1000); continue; } eXosip_lock(); - eXosip_automatic_action (); + eXosip_automatic_action(); eXosip_unlock(); log_event(event); - switch(event->type) { - case EXOSIP_CALL_INVITE: - exosip_create_call(event); - break; - case EXOSIP_CALL_REINVITE: - /* See what the reinvite is about - on hold or whatever */ - //handle_reinvite(event); - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got a reinvite.\n"); - break; - case EXOSIP_CALL_MESSAGE_NEW: - if (event->request != NULL && MSG_IS_REFER(event->request)) { - //handle_call_transfer(event); - } - break; - case EXOSIP_CALL_ACK: - /* If audio is not flowing and this has SDP - fire it up! */ - break; - case EXOSIP_CALL_ANSWERED: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was answered.\n"); - handle_answer(event); - break; - case EXOSIP_CALL_PROCEEDING: - /* This is like a 100 Trying... yeah */ - break; - case EXOSIP_CALL_RINGING: - //handle_ringing(event); - break; - case EXOSIP_CALL_REDIRECTED: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call was redirect\n"); - break; - case EXOSIP_CALL_CLOSED: - destroy_call_by_event(event); - break; - case EXOSIP_CALL_RELEASED: - destroy_call_by_event(event); - break; - case EXOSIP_CALL_NOANSWER: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was not answered.\n"); - destroy_call_by_event(event); - break; - case EXOSIP_CALL_REQUESTFAILURE: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Request failure\n"); - destroy_call_by_event(event); - break; - case EXOSIP_CALL_SERVERFAILURE: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Server failure\n"); - destroy_call_by_event(event); - break; - case EXOSIP_CALL_GLOBALFAILURE: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Global failure\n"); - destroy_call_by_event(event); - break; - /* Registration related stuff */ - case EXOSIP_REGISTRATION_NEW: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Received registration attempt\n"); - break; - default: - /* Unknown event... casually absorb it for now */ - break; + switch (event->type) { + case EXOSIP_CALL_INVITE: + exosip_create_call(event); + break; + case EXOSIP_CALL_REINVITE: + /* See what the reinvite is about - on hold or whatever */ + //handle_reinvite(event); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got a reinvite.\n"); + break; + case EXOSIP_CALL_MESSAGE_NEW: + if (event->request != NULL && MSG_IS_REFER(event->request)) { + //handle_call_transfer(event); + } + break; + case EXOSIP_CALL_ACK: + /* If audio is not flowing and this has SDP - fire it up! */ + break; + case EXOSIP_CALL_ANSWERED: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was answered.\n"); + handle_answer(event); + break; + case EXOSIP_CALL_PROCEEDING: + /* This is like a 100 Trying... yeah */ + break; + case EXOSIP_CALL_RINGING: + //handle_ringing(event); + break; + case EXOSIP_CALL_REDIRECTED: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call was redirect\n"); + break; + case EXOSIP_CALL_CLOSED: + destroy_call_by_event(event); + break; + case EXOSIP_CALL_RELEASED: + destroy_call_by_event(event); + break; + case EXOSIP_CALL_NOANSWER: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was not answered.\n"); + destroy_call_by_event(event); + break; + case EXOSIP_CALL_REQUESTFAILURE: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Request failure\n"); + destroy_call_by_event(event); + break; + case EXOSIP_CALL_SERVERFAILURE: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Server failure\n"); + destroy_call_by_event(event); + break; + case EXOSIP_CALL_GLOBALFAILURE: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Global failure\n"); + destroy_call_by_event(event); + break; + /* Registration related stuff */ + case EXOSIP_REGISTRATION_NEW: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Received registration attempt\n"); + break; + default: + /* Unknown event... casually absorb it for now */ + break; } //switch_console_printf(SWITCH_CHANNEL_CONSOLE, "There was an event (%d) [%s]\n", event->type, event->textinfo); @@ -1399,8 +1399,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) eXosip_quit(); globals.running = 0; switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Monitor Thread Exiting\n"); - //switch_sleep(2000000); - + //switch_sleep(2000000); + return SWITCH_STATUS_TERM; } - diff --git a/src/mod/endpoints/mod_exosip/mod_exosip_ccrtp.c b/src/mod/endpoints/mod_exosip/mod_exosip_ccrtp.c index 751d33c128..c6401c838e 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip_ccrtp.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip_ccrtp.c @@ -62,7 +62,7 @@ typedef enum { TFLAG_DTMF = (1 << 3), TFLAG_READING = (1 << 4), TFLAG_WRITING = (1 << 5), - TFLAG_USING_CODEC = (1 << 6), + TFLAG_USING_CODEC = (1 << 6), TFLAG_RTP = (1 << 7), TFLAG_BYE = (1 << 8) } TFLAGS; @@ -88,7 +88,7 @@ static struct { } globals; struct private_object { - unsigned int flags; + unsigned int flags; switch_core_session *session; switch_frame read_frame; switch_codec read_codec; @@ -136,7 +136,7 @@ static void set_global_dialplan(char *dialplan) free(globals.dialplan); globals.dialplan = NULL; } - + globals.dialplan = strdup(dialplan); } @@ -145,11 +145,14 @@ static switch_status exosip_on_init(switch_core_session *session); static switch_status exosip_on_hangup(switch_core_session *session); static switch_status exosip_on_loopback(switch_core_session *session); static switch_status exosip_on_transmit(switch_core_session *session); -static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags); -static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags); +static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session); +static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags); +static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags); static int config_exosip(int reload); -static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload); +static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload); static switch_status exosip_kill_channel(switch_core_session *session, int sig); static void activate_rtp(struct private_object *tech_pvt); static void deactivate_rtp(struct private_object *tech_pvt); @@ -202,7 +205,7 @@ static int sdp_add_codec(struct osip_rfc3264 *cnf, int codec_type, int payload, default: break; } - return 0; + return 0; } @@ -232,7 +235,7 @@ static switch_status exosip_on_init(switch_core_session *session) char *dest_uri; switch_codec_interface *codecs[512]; int num_codecs = 0; - /* do SIP Goodies...*/ + /* do SIP Goodies... */ /* Generate callerid URI */ eXosip_guess_localip(AF_INET, localip, 128); @@ -245,14 +248,17 @@ static switch_status exosip_on_init(switch_core_session *session) /* Initialize SDP */ sdp_message_init(&tech_pvt->local_sdp); sdp_message_v_version_set(tech_pvt->local_sdp, "0"); - sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip); + sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", + tech_pvt->local_sdp_audio_ip); sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call"); sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL); sdp_message_t_time_descr_add(tech_pvt->local_sdp, "0", "0"); snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port); sdp_message_m_media_add(tech_pvt->local_sdp, "audio", port, NULL, "RTP/AVP"); /* Add in every codec we support on this outbound call */ - if ((num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) { + if ((num_codecs = + loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, + sizeof(codecs) / sizeof(codecs[0]))) > 0) { int i; static const switch_codec_implementation *imp; for (i = 0; i < num_codecs; i++) { @@ -260,12 +266,14 @@ static switch_status exosip_on_init(switch_core_session *session) snprintf(tmp, sizeof(tmp), "%i", codecs[i]->ianacode); sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup(tmp)); - for (imp = codecs[i]->implementations ; imp ; imp = imp->next) { + for (imp = codecs[i]->implementations; imp; imp = imp->next) { /* Add to SDP config */ - sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++); + sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, + imp->samples_per_second, x++); /* Add to SDP message */ - snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second); + snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame, + imp->samples_per_second); sdp_message_a_attribute_add(tech_pvt->local_sdp, 0, "rtpmap", osip_strdup(tmp)); memset(tmp, 0, sizeof(tmp)); } @@ -273,7 +281,9 @@ static switch_status exosip_on_init(switch_core_session *session) } /* Setup our INVITE */ eXosip_lock(); - if (!(dest_uri = (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) { + if (! + (dest_uri = + (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "AIEEEE!\n"); assert(dest_uri != NULL); } @@ -292,7 +302,7 @@ static switch_status exosip_on_init(switch_core_session *session) switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); tech_pvt->did = -1; eXosip_unlock(); - } + } /* Let Media Work */ switch_set_flag(tech_pvt, TFLAG_IO); @@ -331,8 +341,8 @@ static switch_status exosip_on_hangup(switch_core_session *session) assert(tech_pvt != NULL); - switch_core_hash_delete(globals.call_hash, tech_pvt->call_id); - + switch_core_hash_delete(globals.call_hash, tech_pvt->call_id); + switch_set_flag(tech_pvt, TFLAG_BYE); switch_clear_flag(tech_pvt, TFLAG_IO); @@ -346,7 +356,8 @@ static switch_status exosip_on_hangup(switch_core_session *session) switch_core_codec_destroy(&tech_pvt->write_codec); } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel), tech_pvt->cid, tech_pvt->did, i); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel), + tech_pvt->cid, tech_pvt->did, i); return SWITCH_STATUS_SUCCESS; } @@ -362,7 +373,8 @@ static switch_status exosip_on_transmit(switch_core_session *session) return SWITCH_STATUS_SUCCESS; } -static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session) +static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session) { if ((*new_session = switch_core_session_request(&exosip_endpoint_interface, NULL))) { struct private_object *tech_pvt; @@ -370,7 +382,8 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc switch_caller_profile *caller_profile, *originator_caller_profile = NULL; switch_core_session_add_stream(*new_session, NULL); - if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { + if ((tech_pvt = + (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(*new_session); switch_core_session_set_private(*new_session, tech_pvt); @@ -404,7 +417,7 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc switch_channel_set_originator_caller_profile(channel, cloned_profile); } } - + switch_channel_set_flag(channel, CF_OUTBOUND); switch_set_flag(tech_pvt, TFLAG_OUTBOUND); switch_channel_set_state(channel, CS_INIT); @@ -421,7 +434,7 @@ static void deactivate_rtp(struct private_object *tech_pvt) if (tech_pvt->rtp_session) { //switch_mutex_lock(tech_pvt->rtp_lock); - while(loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) { + while (loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) { switch_yield(10000); loops++; } @@ -457,22 +470,16 @@ static void activate_rtp(struct private_object *tech_pvt) tech_pvt->local_sdp_audio_ip, tech_pvt->local_sdp_audio_port, tech_pvt->remote_sdp_audio_ip, - tech_pvt->remote_sdp_audio_port, - tech_pvt->read_codec.codec_interface->ianacode, - ms - ); + tech_pvt->remote_sdp_audio_port, tech_pvt->read_codec.codec_interface->ianacode, ms); - tech_pvt->rtp_session = ccrtp4c_new( - tech_pvt->local_sdp_audio_ip, + tech_pvt->rtp_session = ccrtp4c_new(tech_pvt->local_sdp_audio_ip, tech_pvt->local_sdp_audio_port, tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port, - tech_pvt->read_codec.codec_interface->ianacode, - ms, - ms * 15); + tech_pvt->read_codec.codec_interface->ianacode, ms, ms * 15); if (tech_pvt->rtp_session) { tech_pvt->ssrc = ccrtp4c_get_ssrc(tech_pvt->rtp_session); @@ -507,20 +514,21 @@ static switch_status exosip_answer_channel(switch_core_session *session) sdp_message_to_str(tech_pvt->local_sdp, &buf); osip_message_set_body(answer, buf, strlen(buf)); osip_message_set_content_type(answer, "application/sdp"); - free(buf); + free(buf); eXosip_call_send_answer(tech_pvt->tid, 200, answer); eXosip_unlock(); - } + } return SWITCH_STATUS_SUCCESS; } -static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags) +static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags) { struct private_object *tech_pvt = NULL; - size_t bytes = 0, samples = 0, frames=0, ms=0; + size_t bytes = 0, samples = 0, frames = 0, ms = 0; switch_channel *channel = NULL; channel = switch_core_session_get_channel(session); @@ -546,12 +554,11 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram assert(tech_pvt->rtp_session != NULL); tech_pvt->read_frame.datalen = 0; - - while(!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) { - if ((tech_pvt->read_frame.datalen = - ccrtp4c_read(tech_pvt->rtp_session, - tech_pvt->read_frame.data, - sizeof(tech_pvt->read_buf), + + while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) + && tech_pvt->read_frame.datalen == 0) { + if ((tech_pvt->read_frame.datalen = + ccrtp4c_read(tech_pvt->rtp_session, tech_pvt->read_frame.data, sizeof(tech_pvt->read_buf), &tech_pvt->timestamp_recv))) { bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame; frames = (tech_pvt->read_frame.datalen / bytes); @@ -562,9 +569,9 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram } switch_yield(100); } - + //printf("%s %s->%s recv %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->local_sdp_audio_ip, tech_pvt->read_frame.datalen, samples, frames, ms, tech_pvt->timestamp_recv); - + //switch_mutex_unlock(tech_pvt->rtp_lock); @@ -582,24 +589,25 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram *frame = &tech_pvt->read_frame; - + return SWITCH_STATUS_SUCCESS; } -static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags) +static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags) { struct private_object *tech_pvt; switch_channel *channel = NULL; switch_status status = SWITCH_STATUS_SUCCESS; - int bytes=0, samples=0, ms=0, frames=0; + int bytes = 0, samples = 0, ms = 0, frames = 0; channel = switch_core_session_get_channel(session); assert(channel != NULL); tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - + if (!switch_test_flag(tech_pvt, TFLAG_RTP)) { activate_rtp(tech_pvt); } @@ -624,14 +632,14 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra } else { assert(0); } - + //printf("%s %s->%s send %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, ms, tech_pvt->timestamp_send); - - tech_pvt->timestamp_send += (int)samples; + + tech_pvt->timestamp_send += (int) samples; ccrtp4c_write(tech_pvt->rtp_session, frame->data, frame->datalen, &tech_pvt->timestamp_send); - + switch_clear_flag(tech_pvt, TFLAG_WRITING); @@ -655,7 +663,7 @@ static switch_status exosip_kill_channel(switch_core_session *session, int sig) switch_clear_flag(tech_pvt, TFLAG_IO); switch_set_flag(tech_pvt, TFLAG_BYE); - + return SWITCH_STATUS_SUCCESS; } @@ -685,45 +693,45 @@ static switch_status exosip_waitfor_write(switch_core_session *session, int ms) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - + return SWITCH_STATUS_SUCCESS; } - + static const switch_io_routines exosip_io_routines = { - /*.outgoing_channel*/ exosip_outgoing_channel, - /*.answer_channel*/ exosip_answer_channel, - /*.read_frame*/ exosip_read_frame, - /*.write_frame*/ exosip_write_frame, - /*.kill_channel*/ exosip_kill_channel, - /*.waitfor_read*/ exosip_waitfor_read, - /*.waitfor_read*/ exosip_waitfor_write + /*.outgoing_channel */ exosip_outgoing_channel, + /*.answer_channel */ exosip_answer_channel, + /*.read_frame */ exosip_read_frame, + /*.write_frame */ exosip_write_frame, + /*.kill_channel */ exosip_kill_channel, + /*.waitfor_read */ exosip_waitfor_read, + /*.waitfor_read */ exosip_waitfor_write }; -static const switch_event_handler_table exosip_event_handlers = { - /*.on_init*/ exosip_on_init, - /*.on_ring*/ exosip_on_ring, - /*.on_execute*/ exosip_on_execute, - /*.on_hangup*/ exosip_on_hangup, - /*.on_loopback*/ exosip_on_loopback, - /*.on_transmit*/ exosip_on_transmit +static const switch_event_handler_table exosip_event_handlers = { + /*.on_init */ exosip_on_init, + /*.on_ring */ exosip_on_ring, + /*.on_execute */ exosip_on_execute, + /*.on_hangup */ exosip_on_hangup, + /*.on_loopback */ exosip_on_loopback, + /*.on_transmit */ exosip_on_transmit }; static const switch_endpoint_interface exosip_endpoint_interface = { - /*.interface_name*/ "exosip", - /*.io_routines*/ &exosip_io_routines, - /*.event_handlers*/ &exosip_event_handlers, - /*.private*/ NULL, - /*.next*/ NULL + /*.interface_name */ "exosip", + /*.io_routines */ &exosip_io_routines, + /*.event_handlers */ &exosip_event_handlers, + /*.private */ NULL, + /*.next */ NULL }; static const switch_loadable_module_interface exosip_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ &exosip_endpoint_interface, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ NULL, - /*.application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ &exosip_endpoint_interface, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL }; @@ -731,7 +739,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void) { if (globals.running) { globals.running = -1; - while(globals.running) { + while (globals.running) { switch_yield(1000); } } @@ -739,14 +747,15 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void) return SWITCH_STATUS_SUCCESS; } -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ /* NOTE: **interface is **_interface because the common lib redefines interface to struct in some situations */ if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n"); return SWITCH_STATUS_TERM; } - + /* connect my internal structure to the blank pointer passed to me */ *interface = &exosip_module_interface; @@ -754,7 +763,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul return SWITCH_STATUS_SUCCESS; } -static switch_status exosip_create_call(eXosip_event_t *event) +static switch_status exosip_create_call(eXosip_event_t * event) { switch_core_session *session; sdp_message_t *remote_sdp = NULL; @@ -784,14 +793,13 @@ static switch_status exosip_create_call(eXosip_event_t *event) switch_core_session_destroy(&session); return SWITCH_STATUS_MEMERR; } - + if ((tech_pvt->caller_profile = switch_caller_profile_new(session, - globals.dialplan, - event->request->from->displayname, - event->request->from->url->username, - event->request->from->url->username, - NULL, - event->request->req_uri->username))) { + globals.dialplan, + event->request->from->displayname, + event->request->from->url->username, + event->request->from->url->username, + NULL, event->request->req_uri->username))) { switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); } @@ -802,7 +810,7 @@ static switch_status exosip_create_call(eXosip_event_t *event) snprintf(name, sizeof(name), "Exosip/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff); switch_channel_set_name(channel, name); - + if (!(remote_sdp = eXosip_get_sdp_info(event->request))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Find Remote SDP!\n"); exosip_on_hangup(session); @@ -814,15 +822,18 @@ static switch_status exosip_create_call(eXosip_event_t *event) tech_pvt->local_sdp_audio_port = next_rtp_port(); osip_rfc3264_init(&tech_pvt->sdp_config); /* Add in what codecs we support locally */ - - if ((num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) { + + if ((num_codecs = + loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, + sizeof(codecs) / sizeof(codecs[0]))) > 0) { int i; static const switch_codec_implementation *imp; for (i = 0; i < num_codecs; i++) { int x = 0; - for (imp = codecs[i]->implementations ; imp ; imp = imp->next) { - sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++); + for (imp = codecs[i]->implementations; imp; imp = imp->next) { + sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, + imp->samples_per_second, x++); } } } @@ -831,17 +842,18 @@ static switch_status exosip_create_call(eXosip_event_t *event) sdp_message_parse(tech_pvt->local_sdp, local_sdp_str); sdp_message_to_str(remote_sdp, &remote_sdp_str); - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str,remote_sdp_str); - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str, remote_sdp_str); + mline = 0; - while (0==osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) { + while (0 == osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) { if (audio_tab[0] == NULL && video_tab[0] == NULL && t38_tab[0] == NULL && app_tab[0] == NULL) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got no compatible codecs!\n"); break; } - for (pos=0; audio_tab[pos]!=NULL; pos++) { - osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos], mline); + for (pos = 0; audio_tab[pos] != NULL; pos++) { + osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos], + mline); if (parse_sdp_media(audio_tab[pos], &dname, &drate, &dpayload) == SWITCH_STATUS_SUCCESS) { tech_pvt->payload_num = atoi(dpayload); break; @@ -850,7 +862,8 @@ static switch_status exosip_create_call(eXosip_event_t *event) mline++; } free(remote_sdp_str); - sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip); + sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", + tech_pvt->local_sdp_audio_ip); sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call"); sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL); snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port); @@ -861,9 +874,9 @@ static switch_status exosip_create_call(eXosip_event_t *event) snprintf(tech_pvt->remote_sdp_audio_ip, 50, conn->c_addr); tech_pvt->remote_sdp_audio_port = atoi(remote_med->m_port); - + snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", event->cid); - switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); + switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); if (!dname) { exosip_on_hangup(session); @@ -878,21 +891,21 @@ static switch_status exosip_create_call(eXosip_event_t *event) int rate = atoi(drate); if (switch_core_codec_init(&tech_pvt->read_codec, - dname, - rate, - globals.codec_ms, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL) != SWITCH_STATUS_SUCCESS) { + dname, + rate, + globals.codec_ms, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_channel_hangup(channel); return SWITCH_STATUS_FALSE; } else { if (switch_core_codec_init(&tech_pvt->write_codec, - dname, - rate, - globals.codec_ms, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL) != SWITCH_STATUS_SUCCESS) { + dname, + rate, + globals.codec_ms, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_channel_hangup(channel); return SWITCH_STATUS_FALSE; @@ -900,14 +913,15 @@ static switch_status exosip_create_call(eXosip_event_t *event) int ms; switch_set_flag(tech_pvt, TFLAG_USING_CODEC); ms = tech_pvt->write_codec.implementation->nanoseconds_per_frame / 1000; - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate, ms); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate, + ms); tech_pvt->read_frame.codec = &tech_pvt->read_codec; switch_core_session_set_read_codec(session, &tech_pvt->read_codec); switch_core_session_set_write_codec(session, &tech_pvt->write_codec); } } } - + switch_core_session_thread_launch(session); } else { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Create new Inbound Channel!\n"); @@ -920,13 +934,14 @@ static switch_status exosip_create_call(eXosip_event_t *event) } -static void destroy_call_by_event(eXosip_event_t *event) +static void destroy_call_by_event(eXosip_event_t * event) { struct private_object *tech_pvt; switch_channel *channel = NULL; if (!(tech_pvt = get_pvt_by_call_id(event->cid))) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n", event->cid); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n", + event->cid); return; } @@ -936,10 +951,10 @@ static void destroy_call_by_event(eXosip_event_t *event) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "destroy %s\n", switch_channel_get_name(channel)); exosip_kill_channel(tech_pvt->session, SWITCH_SIG_KILL); switch_channel_hangup(channel); - + } -static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload) +static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload) { int pos = 0; sdp_attribute_t *attr = NULL; @@ -947,7 +962,7 @@ static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **dr switch_status status = SWITCH_STATUS_GENERR; while (osip_list_eol(media->a_attributes, pos) == 0) { - attr = (sdp_attribute_t *)osip_list_get(media->a_attributes, pos); + attr = (sdp_attribute_t *) osip_list_get(media->a_attributes, pos); if (attr != NULL && strcasecmp(attr->a_att_field, "rtpmap") == 0) { payload = attr->a_att_value; if ((name = strchr(payload, ' '))) { @@ -968,7 +983,8 @@ static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **dr *dname = strdup("L16"); *drate = strdup("8000"); } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n", *dpayload, *dname, *drate); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n", + *dpayload, *dname, *drate); break; } attr = NULL; @@ -978,7 +994,7 @@ static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **dr return status; } -static void handle_answer(eXosip_event_t *event) +static void handle_answer(eXosip_event_t * event) { osip_message_t *ack = NULL; sdp_message_t *remote_sdp = NULL; @@ -1026,18 +1042,22 @@ static void handle_answer(eXosip_event_t *event) /* Assign them thar IDs */ tech_pvt->did = event->did; tech_pvt->tid = event->tid; - + if (1) { int rate = atoi(drate); - if (switch_core_codec_init(&tech_pvt->read_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) { + if (switch_core_codec_init + (&tech_pvt->read_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_channel_hangup(channel); return; } else { - if (switch_core_codec_init(&tech_pvt->write_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) { + if (switch_core_codec_init + (&tech_pvt->write_codec, dname, rate, globals.codec_ms, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_channel_hangup(channel); return; @@ -1058,7 +1078,7 @@ static void handle_answer(eXosip_event_t *event) eXosip_call_build_ack(event->did, &ack); eXosip_call_send_ack(event->did, ack); eXosip_unlock(); - + free(dname); free(drate); free(dpayload); @@ -1072,133 +1092,119 @@ static void handle_answer(eXosip_event_t *event) } -static void log_event(eXosip_event_t *je) +static void log_event(eXosip_event_t * je) { char buf[100]; buf[0] = '\0'; if (je->type == EXOSIP_CALL_NOANSWER) { - snprintf (buf, 99, "<- (%i %i) No answer", je->cid, je->did); + snprintf(buf, 99, "<- (%i %i) No answer", je->cid, je->did); } else if (je->type == EXOSIP_CALL_CLOSED) { - snprintf (buf, 99, "<- (%i %i) Call Closed", je->cid, je->did); + snprintf(buf, 99, "<- (%i %i) Call Closed", je->cid, je->did); } else if (je->type == EXOSIP_CALL_RELEASED) { - snprintf (buf, 99, "<- (%i %i) Call released", je->cid, je->did); - } else if (je->type == EXOSIP_MESSAGE_NEW - && je->request!=NULL && MSG_IS_MESSAGE(je->request)) { + snprintf(buf, 99, "<- (%i %i) Call released", je->cid, je->did); + } else if (je->type == EXOSIP_MESSAGE_NEW && je->request != NULL && MSG_IS_MESSAGE(je->request)) { char *tmp = NULL; - + if (je->request != NULL) { osip_body_t *body; - osip_from_to_str (je->request->from, &tmp); - - osip_message_get_body (je->request, 0, &body); + osip_from_to_str(je->request->from, &tmp); + + osip_message_get_body(je->request, 0, &body); if (body != NULL && body->body != NULL) { - snprintf (buf, 99, "<- (%i) from: %s TEXT: %s", - je->tid, tmp, body->body); + snprintf(buf, 99, "<- (%i) from: %s TEXT: %s", je->tid, tmp, body->body); } - osip_free (tmp); + osip_free(tmp); } else { - snprintf (buf, 99, "<- (%i) New event for unknown request?", je->tid); + snprintf(buf, 99, "<- (%i) New event for unknown request?", je->tid); } } else if (je->type == EXOSIP_MESSAGE_NEW) { char *tmp = NULL; - - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (%i) %s from: %s", - je->tid, je->request->sip_method, tmp); - osip_free (tmp); + + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (%i) %s from: %s", je->tid, je->request->sip_method, tmp); + osip_free(tmp); } else if (je->type == EXOSIP_MESSAGE_PROCEEDING - || je->type == EXOSIP_MESSAGE_ANSWERED - || je->type == EXOSIP_MESSAGE_REDIRECTED - || je->type == EXOSIP_MESSAGE_REQUESTFAILURE - || je->type == EXOSIP_MESSAGE_SERVERFAILURE - || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) { + || je->type == EXOSIP_MESSAGE_ANSWERED + || je->type == EXOSIP_MESSAGE_REDIRECTED + || je->type == EXOSIP_MESSAGE_REQUESTFAILURE + || je->type == EXOSIP_MESSAGE_SERVERFAILURE || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) { if (je->response != NULL && je->request != NULL) { char *tmp = NULL; - - osip_to_to_str (je->request->to, &tmp); - snprintf (buf, 99, "<- (%i) [%i %s for %s] to: %s", - je->tid, je->response->status_code, - je->response->reason_phrase, je->request->sip_method, tmp); - osip_free (tmp); + + osip_to_to_str(je->request->to, &tmp); + snprintf(buf, 99, "<- (%i) [%i %s for %s] to: %s", + je->tid, je->response->status_code, je->response->reason_phrase, je->request->sip_method, tmp); + osip_free(tmp); } else if (je->request != NULL) { - snprintf (buf, 99, "<- (%i) Error for %s request", - je->tid, je->request->sip_method); + snprintf(buf, 99, "<- (%i) Error for %s request", je->tid, je->request->sip_method); } else { - snprintf (buf, 99, "<- (%i) Error for unknown request", je->tid); + snprintf(buf, 99, "<- (%i) Error for unknown request", je->tid); } } else if (je->response == NULL && je->request != NULL && je->cid > 0) { char *tmp = NULL; - - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (%i %i) %s from: %s", - je->cid, je->did, je->request->cseq->method, tmp); - osip_free (tmp); + + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (%i %i) %s from: %s", je->cid, je->did, je->request->cseq->method, tmp); + osip_free(tmp); } else if (je->response != NULL && je->cid > 0) { char *tmp = NULL; - - osip_to_to_str (je->request->to, &tmp); - snprintf (buf, 99, "<- (%i %i) [%i %s] for %s to: %s", - je->cid, je->did, je->response->status_code, - je->response->reason_phrase, je->request->sip_method, tmp); - osip_free (tmp); + + osip_to_to_str(je->request->to, &tmp); + snprintf(buf, 99, "<- (%i %i) [%i %s] for %s to: %s", + je->cid, je->did, je->response->status_code, + je->response->reason_phrase, je->request->sip_method, tmp); + osip_free(tmp); } else if (je->response == NULL && je->request != NULL && je->rid > 0) { char *tmp = NULL; - - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (%i) %s from: %s", - je->rid, je->request->cseq->method, tmp); - osip_free (tmp); + + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (%i) %s from: %s", je->rid, je->request->cseq->method, tmp); + osip_free(tmp); } else if (je->response != NULL && je->rid > 0) { char *tmp = NULL; - - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (%i) [%i %s] from: %s", - je->rid, je->response->status_code, - je->response->reason_phrase, tmp); - osip_free (tmp); + + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (%i) [%i %s] from: %s", + je->rid, je->response->status_code, je->response->reason_phrase, tmp); + osip_free(tmp); } else if (je->response == NULL && je->request != NULL && je->sid > 0) { char *tmp = NULL; char *stat = NULL; osip_header_t *sub_state; - - osip_message_header_get_byname (je->request, "subscription-state", - 0, &sub_state); + + osip_message_header_get_byname(je->request, "subscription-state", 0, &sub_state); if (sub_state != NULL && sub_state->hvalue != NULL) stat = sub_state->hvalue; - - osip_uri_to_str (je->request->from->url, &tmp); - snprintf (buf, 99, "<- (%i) [%s] %s from: %s", - je->sid, stat, je->request->cseq->method, tmp); - osip_free (tmp); + + osip_uri_to_str(je->request->from->url, &tmp); + snprintf(buf, 99, "<- (%i) [%s] %s from: %s", je->sid, stat, je->request->cseq->method, tmp); + osip_free(tmp); } else if (je->response != NULL && je->sid > 0) { char *tmp = NULL; - - osip_uri_to_str (je->request->to->url, &tmp); - snprintf (buf, 99, "<- (%i) [%i %s] from: %s", - je->sid, je->response->status_code, - je->response->reason_phrase, tmp); - osip_free (tmp); + + osip_uri_to_str(je->request->to->url, &tmp); + snprintf(buf, 99, "<- (%i) [%i %s] from: %s", + je->sid, je->response->status_code, je->response->reason_phrase, tmp); + osip_free(tmp); } else if (je->response == NULL && je->request != NULL) { char *tmp = NULL; - - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s", - je->cid, je->did, je->sid, je->nid, - je->request->sip_method, tmp); - osip_free (tmp); + + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s", + je->cid, je->did, je->sid, je->nid, je->request->sip_method, tmp); + osip_free(tmp); } else if (je->response != NULL) { char *tmp = NULL; - - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s", - je->cid, je->did, je->sid, je->nid, - je->response->status_code, je->response->reason_phrase, - je->request->sip_method, tmp); - osip_free (tmp); + + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s", + je->cid, je->did, je->sid, je->nid, + je->response->status_code, je->response->reason_phrase, je->request->sip_method, tmp); + osip_free(tmp); } else { - snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s", - je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo); + snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s", + je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo); } switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\n%s\n", buf); /* Print it out */ @@ -1209,21 +1215,21 @@ static void log_event(eXosip_event_t *je) static void *monitor_thread_run(void) { eXosip_event_t *event = NULL; - + globals.running = 1; while (globals.running > 0) { - if (!(event = eXosip_event_wait(0,100))) { + if (!(event = eXosip_event_wait(0, 100))) { switch_yield(100); continue; } eXosip_lock(); - eXosip_automatic_action (); + eXosip_automatic_action(); eXosip_unlock(); log_event(event); - switch(event->type) { + switch (event->type) { case EXOSIP_CALL_INVITE: exosip_create_call(event); break; @@ -1295,7 +1301,7 @@ static void *monitor_thread_run(void) } -static int config_exosip(int reload) +static int config_exosip(int reload) { switch_config cfg; char *var, *val; @@ -1329,7 +1335,7 @@ static int config_exosip(int reload) } } } - + if (!globals.codec_ms) { globals.codec_ms = 20; } @@ -1344,11 +1350,11 @@ static int config_exosip(int reload) set_global_dialplan("default"); } - if (eXosip_init ()) { + if (eXosip_init()) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_init initialization failed!\n"); return SWITCH_STATUS_GENERR; } - if (eXosip_listen_addr (IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) { + if (eXosip_listen_addr(IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_listen_addr failed!\n"); return SWITCH_STATUS_GENERR; } @@ -1371,4 +1377,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) config_exosip(0); return SWITCH_STATUS_TERM; } - diff --git a/src/mod/endpoints/mod_exosip/mod_exosip_ucl.c b/src/mod/endpoints/mod_exosip/mod_exosip_ucl.c index dca8a34789..b1197bfbdf 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip_ucl.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip_ucl.c @@ -77,7 +77,7 @@ typedef enum { TFLAG_DTMF = (1 << 3), TFLAG_READING = (1 << 4), TFLAG_WRITING = (1 << 5), - TFLAG_USING_CODEC = (1 << 6), + TFLAG_USING_CODEC = (1 << 6), TFLAG_RTP = (1 << 7), TFLAG_BYE = (1 << 8) } TFLAGS; @@ -103,7 +103,7 @@ static struct { } globals; struct private_object { - unsigned int flags; + unsigned int flags; switch_core_session *session; switch_frame read_frame; switch_codec read_codec; @@ -116,7 +116,7 @@ struct private_object { int32_t timestamp_send; int32_t timestamp_recv; int payload_num; - struct rtp *rtp_session; + struct rtp *rtp_session; struct osip_rfc3264 *sdp_config; sdp_message_t *remote_sdp; sdp_message_t *local_sdp; @@ -151,7 +151,7 @@ static void set_global_dialplan(char *dialplan) free(globals.dialplan); globals.dialplan = NULL; } - + globals.dialplan = strdup(dialplan); } @@ -160,11 +160,14 @@ static switch_status exosip_on_init(switch_core_session *session); static switch_status exosip_on_hangup(switch_core_session *session); static switch_status exosip_on_loopback(switch_core_session *session); static switch_status exosip_on_transmit(switch_core_session *session); -static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags); -static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags); +static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session); +static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags); +static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags); static int config_exosip(int reload); -static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload); +static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload); static switch_status exosip_kill_channel(switch_core_session *session, int sig); static void activate_rtp(struct private_object *tech_pvt); static void deactivate_rtp(struct private_object *tech_pvt); @@ -217,7 +220,7 @@ static int sdp_add_codec(struct osip_rfc3264 *cnf, int codec_type, int payload, default: break; } - return 0; + return 0; } @@ -247,7 +250,7 @@ static switch_status exosip_on_init(switch_core_session *session) char *dest_uri; switch_codec_interface *codecs[512]; int num_codecs = 0; - /* do SIP Goodies...*/ + /* do SIP Goodies... */ /* Generate callerid URI */ eXosip_guess_localip(AF_INET, localip, 128); @@ -260,14 +263,17 @@ static switch_status exosip_on_init(switch_core_session *session) /* Initialize SDP */ sdp_message_init(&tech_pvt->local_sdp); sdp_message_v_version_set(tech_pvt->local_sdp, "0"); - sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip); + sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", + tech_pvt->local_sdp_audio_ip); sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call"); sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL); sdp_message_t_time_descr_add(tech_pvt->local_sdp, "0", "0"); snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port); sdp_message_m_media_add(tech_pvt->local_sdp, "audio", port, NULL, "RTP/AVP"); /* Add in every codec we support on this outbound call */ - if ((num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) { + if ((num_codecs = + loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, + sizeof(codecs) / sizeof(codecs[0]))) > 0) { int i; static const switch_codec_implementation *imp; for (i = 0; i < num_codecs; i++) { @@ -275,12 +281,14 @@ static switch_status exosip_on_init(switch_core_session *session) snprintf(tmp, sizeof(tmp), "%i", codecs[i]->ianacode); sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup(tmp)); - for (imp = codecs[i]->implementations ; imp ; imp = imp->next) { + for (imp = codecs[i]->implementations; imp; imp = imp->next) { /* Add to SDP config */ - sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++); + sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, + imp->samples_per_second, x++); /* Add to SDP message */ - snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second); + snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame, + imp->samples_per_second); sdp_message_a_attribute_add(tech_pvt->local_sdp, 0, "rtpmap", osip_strdup(tmp)); memset(tmp, 0, sizeof(tmp)); } @@ -288,7 +296,9 @@ static switch_status exosip_on_init(switch_core_session *session) } /* Setup our INVITE */ eXosip_lock(); - if (!(dest_uri = (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) { + if (! + (dest_uri = + (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "AIEEEE!\n"); assert(dest_uri != NULL); } @@ -307,7 +317,7 @@ static switch_status exosip_on_init(switch_core_session *session) switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); tech_pvt->did = -1; eXosip_unlock(); - } + } /* Let Media Work */ @@ -347,8 +357,8 @@ static switch_status exosip_on_hangup(switch_core_session *session) assert(tech_pvt != NULL); - switch_core_hash_delete(globals.call_hash, tech_pvt->call_id); - + switch_core_hash_delete(globals.call_hash, tech_pvt->call_id); + switch_set_flag(tech_pvt, TFLAG_BYE); switch_clear_flag(tech_pvt, TFLAG_IO); @@ -362,7 +372,8 @@ static switch_status exosip_on_hangup(switch_core_session *session) switch_core_codec_destroy(&tech_pvt->write_codec); } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel), tech_pvt->cid, tech_pvt->did, i); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel), + tech_pvt->cid, tech_pvt->did, i); return SWITCH_STATUS_SUCCESS; } @@ -378,7 +389,8 @@ static switch_status exosip_on_transmit(switch_core_session *session) return SWITCH_STATUS_SUCCESS; } -static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session) +static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session) { if ((*new_session = switch_core_session_request(&exosip_endpoint_interface, NULL))) { struct private_object *tech_pvt; @@ -386,7 +398,8 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc switch_caller_profile *caller_profile, *originator_caller_profile = NULL; switch_core_session_add_stream(*new_session, NULL); - if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { + if ((tech_pvt = + (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(*new_session); switch_core_session_set_private(*new_session, tech_pvt); @@ -420,7 +433,7 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc switch_channel_set_originator_caller_profile(channel, cloned_profile); } } - + switch_channel_set_flag(channel, CF_OUTBOUND); switch_set_flag(tech_pvt, TFLAG_OUTBOUND); switch_channel_set_state(channel, CS_INIT); @@ -433,7 +446,7 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc #if 0 static const char *event_names[] = { "RX_RTP", - "RX_SR", + "RX_SR", "RX_RR", "RX_SDES", "RX_BYE", @@ -447,30 +460,29 @@ static const char *event_names[] = { }; #endif -static void rtp_event_handler(struct rtp *session, rtp_event *event) +static void rtp_event_handler(struct rtp *session, rtp_event * event) { - rtp_packet *packet; + rtp_packet *packet; struct private_object *tech_pvt = (struct private_object *) rtp_get_userdata(session); if (!session) { return; } + //switch_console_printf(SWITCH_CHANNEL_CONSOLE, "RTP EVENT (%s)\n", event_names[event->type]); - //switch_console_printf(SWITCH_CHANNEL_CONSOLE, "RTP EVENT (%s)\n", event_names[event->type]); - - switch(event->type) { + switch (event->type) { case RX_RTP: - if((packet = (rtp_packet *) event->data)) { + if ((packet = (rtp_packet *) event->data)) { if (packet->data_len < 10000) { memcpy(tech_pvt->read_buf, packet->data, packet->data_len); tech_pvt->read_frame.datalen = packet->data_len; } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF PACKET LEN %d\n", packet->data_len); - } - free(packet); /* xfree() is mandatory to release RTP packet data */ + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF PACKET LEN %d\n", packet->data_len); + } + free(packet); /* xfree() is mandatory to release RTP packet data */ } - break; + break; case RR_TIMEOUT: case RX_BYE: switch_set_flag(tech_pvt, TFLAG_BYE); @@ -485,7 +497,7 @@ static void deactivate_rtp(struct private_object *tech_pvt) if (tech_pvt->rtp_session) { //switch_mutex_lock(tech_pvt->rtp_lock); - while(loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) { + while (loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) { switch_yield(10000); loops++; } @@ -507,9 +519,8 @@ static void activate_rtp(struct private_object *tech_pvt) assert(channel != NULL); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activating RTP %d->%s:%d\n", - tech_pvt->local_sdp_audio_port, - tech_pvt->remote_sdp_audio_ip, - tech_pvt->remote_sdp_audio_port); + tech_pvt->local_sdp_audio_port, + tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port); //switch_mutex_lock(tech_pvt->rtp_lock); @@ -521,13 +532,13 @@ static void activate_rtp(struct private_object *tech_pvt) bw *= 8; } - tech_pvt->rtp_session = rtp_init(tech_pvt->remote_sdp_audio_ip, /* Host/Group IP address */ + tech_pvt->rtp_session = rtp_init(tech_pvt->remote_sdp_audio_ip, /* Host/Group IP address */ tech_pvt->local_sdp_audio_port, /* receive port */ tech_pvt->remote_sdp_audio_port, /* transmit port */ - ms * 2, /* time-to-live */ - bw, /* B/W estimate */ - rtp_event_handler, /* RTP event callback */ - (void *) tech_pvt); /* App. specific data */ + ms * 2, /* time-to-live */ + bw, /* B/W estimate */ + rtp_event_handler, /* RTP event callback */ + (void *) tech_pvt); /* App. specific data */ if (tech_pvt->rtp_session) { @@ -537,7 +548,7 @@ static void activate_rtp(struct private_object *tech_pvt) rtp_set_sdes(tech_pvt->rtp_session, tech_pvt->ssrc, RTCP_SDES_NAME, "test", 4); rtp_set_sdes(tech_pvt->rtp_session, tech_pvt->ssrc, RTCP_SDES_PHONE, "test", 4); rtp_set_sdes(tech_pvt->rtp_session, tech_pvt->ssrc, RTCP_SDES_TOOL, "test", 4); - switch_set_flag(tech_pvt, TFLAG_RTP); + switch_set_flag(tech_pvt, TFLAG_RTP); } else { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Oh oh is your port even?\n"); } @@ -566,22 +577,23 @@ static switch_status exosip_answer_channel(switch_core_session *session) sdp_message_to_str(tech_pvt->local_sdp, &buf); osip_message_set_body(answer, buf, strlen(buf)); osip_message_set_content_type(answer, "application/sdp"); - free(buf); + free(buf); eXosip_call_send_answer(tech_pvt->tid, 200, answer); eXosip_unlock(); - } + } return SWITCH_STATUS_SUCCESS; } -static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags) +static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags) { struct private_object *tech_pvt = NULL; size_t bytes = 0, samples = 0, frames, ms, x; switch_channel *channel = NULL; - int ns=0; + int ns = 0; struct timeval tv; channel = switch_core_session_get_channel(session); @@ -616,9 +628,9 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram //switch_mutex_lock(tech_pvt->rtp_lock); tv.tv_sec = 0; tv.tv_usec = ns; - while(switch_test_flag(tech_pvt, TFLAG_IO) && !switch_test_flag(tech_pvt, TFLAG_BYE)) { + while (switch_test_flag(tech_pvt, TFLAG_IO) && !switch_test_flag(tech_pvt, TFLAG_BYE)) { x = rtp_recv(tech_pvt->rtp_session, &tv, tech_pvt->timestamp_recv); - if(x < 0) { + if (x < 0) { break; } if (tech_pvt->read_frame.datalen) { @@ -629,7 +641,7 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram break; } } - tech_pvt->timestamp_recv += (int)samples; + tech_pvt->timestamp_recv += (int) samples; //printf("%s\trecv %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->read_frame.datalen, samples, frames, ms, tech_pvt->timestamp_recv); //switch_mutex_unlock(tech_pvt->rtp_lock); @@ -651,7 +663,8 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram } -static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags) +static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags) { struct private_object *tech_pvt; switch_channel *channel = NULL; @@ -663,7 +676,7 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - + if (!switch_test_flag(tech_pvt, TFLAG_RTP)) { activate_rtp(tech_pvt); } @@ -688,16 +701,14 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra } else { assert(0); } - tech_pvt->timestamp_send += (int)samples; + tech_pvt->timestamp_send += (int) samples; //printf("%s %s->%s send %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, ms, tech_pvt->timestamp_recv); - + rtp_send_ctrl(tech_pvt->rtp_session, tech_pvt->timestamp_send, NULL); x = rtp_send_data(tech_pvt->rtp_session, tech_pvt->timestamp_send, tech_pvt->payload_num, - 0, 0, 0, - (char *)frame->data, (int)frame->datalen, - 0, 0, 0); + 0, 0, 0, (char *) frame->data, (int) frame->datalen, 0, 0, 0); switch_clear_flag(tech_pvt, TFLAG_WRITING); @@ -752,45 +763,45 @@ static switch_status exosip_waitfor_write(switch_core_session *session, int ms) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - + return SWITCH_STATUS_SUCCESS; } - + static const switch_io_routines exosip_io_routines = { - /*.outgoing_channel*/ exosip_outgoing_channel, - /*.answer_channel*/ exosip_answer_channel, - /*.read_frame*/ exosip_read_frame, - /*.write_frame*/ exosip_write_frame, - /*.kill_channel*/ exosip_kill_channel, - /*.waitfor_read*/ exosip_waitfor_read, - /*.waitfor_read*/ exosip_waitfor_write + /*.outgoing_channel */ exosip_outgoing_channel, + /*.answer_channel */ exosip_answer_channel, + /*.read_frame */ exosip_read_frame, + /*.write_frame */ exosip_write_frame, + /*.kill_channel */ exosip_kill_channel, + /*.waitfor_read */ exosip_waitfor_read, + /*.waitfor_read */ exosip_waitfor_write }; -static const switch_event_handler_table exosip_event_handlers = { - /*.on_init*/ exosip_on_init, - /*.on_ring*/ exosip_on_ring, - /*.on_execute*/ exosip_on_execute, - /*.on_hangup*/ exosip_on_hangup, - /*.on_loopback*/ exosip_on_loopback, - /*.on_transmit*/ exosip_on_transmit +static const switch_event_handler_table exosip_event_handlers = { + /*.on_init */ exosip_on_init, + /*.on_ring */ exosip_on_ring, + /*.on_execute */ exosip_on_execute, + /*.on_hangup */ exosip_on_hangup, + /*.on_loopback */ exosip_on_loopback, + /*.on_transmit */ exosip_on_transmit }; static const switch_endpoint_interface exosip_endpoint_interface = { - /*.interface_name*/ "exosip", - /*.io_routines*/ &exosip_io_routines, - /*.event_handlers*/ &exosip_event_handlers, - /*.private*/ NULL, - /*.next*/ NULL + /*.interface_name */ "exosip", + /*.io_routines */ &exosip_io_routines, + /*.event_handlers */ &exosip_event_handlers, + /*.private */ NULL, + /*.next */ NULL }; static const switch_loadable_module_interface exosip_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ &exosip_endpoint_interface, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ NULL, - /*.application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ &exosip_endpoint_interface, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL }; @@ -798,7 +809,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void) { if (globals.running) { globals.running = -1; - while(globals.running) { + while (globals.running) { switch_yield(1000); } } @@ -806,14 +817,16 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void) return SWITCH_STATUS_SUCCESS; } -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **_interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **_interface, + char *filename) +{ /* NOTE: **interface is **_interface because the common lib redefines interface to struct in some situations */ if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n"); return SWITCH_STATUS_TERM; } - + /* connect my internal structure to the blank pointer passed to me */ *_interface = &exosip_module_interface; @@ -821,7 +834,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul return SWITCH_STATUS_SUCCESS; } -static switch_status exosip_create_call(eXosip_event_t *event) +static switch_status exosip_create_call(eXosip_event_t * event) { switch_core_session *session; sdp_message_t *remote_sdp = NULL; @@ -851,14 +864,13 @@ static switch_status exosip_create_call(eXosip_event_t *event) switch_core_session_destroy(&session); return SWITCH_STATUS_MEMERR; } - + if ((tech_pvt->caller_profile = switch_caller_profile_new(session, - globals.dialplan, - event->request->from->displayname, - event->request->from->url->username, - event->request->from->url->username, - NULL, - event->request->req_uri->username))) { + globals.dialplan, + event->request->from->displayname, + event->request->from->url->username, + event->request->from->url->username, + NULL, event->request->req_uri->username))) { switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); } @@ -869,7 +881,7 @@ static switch_status exosip_create_call(eXosip_event_t *event) snprintf(name, sizeof(name), "Exosip/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff); switch_channel_set_name(channel, name); - + if (!(remote_sdp = eXosip_get_sdp_info(event->request))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Find Remote SDP!\n"); exosip_on_hangup(session); @@ -881,15 +893,18 @@ static switch_status exosip_create_call(eXosip_event_t *event) tech_pvt->local_sdp_audio_port = next_rtp_port(); osip_rfc3264_init(&tech_pvt->sdp_config); /* Add in what codecs we support locally */ - - if ((num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) { + + if ((num_codecs = + loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, + sizeof(codecs) / sizeof(codecs[0]))) > 0) { int i; static const switch_codec_implementation *imp; for (i = 0; i < num_codecs; i++) { int x = 0; - for (imp = codecs[i]->implementations ; imp ; imp = imp->next) { - sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++); + for (imp = codecs[i]->implementations; imp; imp = imp->next) { + sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, + imp->samples_per_second, x++); } } } @@ -898,17 +913,18 @@ static switch_status exosip_create_call(eXosip_event_t *event) sdp_message_parse(tech_pvt->local_sdp, local_sdp_str); sdp_message_to_str(remote_sdp, &remote_sdp_str); - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str,remote_sdp_str); - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str, remote_sdp_str); + mline = 0; - while (0==osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) { + while (0 == osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) { if (audio_tab[0] == NULL && video_tab[0] == NULL && t38_tab[0] == NULL && app_tab[0] == NULL) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got no compatible codecs!\n"); break; } - for (pos=0; audio_tab[pos]!=NULL; pos++) { - osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos], mline); + for (pos = 0; audio_tab[pos] != NULL; pos++) { + osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos], + mline); if (parse_sdp_media(audio_tab[pos], &dname, &drate, &dpayload) == SWITCH_STATUS_SUCCESS) { tech_pvt->payload_num = atoi(dpayload); break; @@ -917,7 +933,8 @@ static switch_status exosip_create_call(eXosip_event_t *event) mline++; } free(remote_sdp_str); - sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip); + sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", + tech_pvt->local_sdp_audio_ip); sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call"); sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL); snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port); @@ -928,9 +945,9 @@ static switch_status exosip_create_call(eXosip_event_t *event) snprintf(tech_pvt->remote_sdp_audio_ip, 50, conn->c_addr); tech_pvt->remote_sdp_audio_port = atoi(remote_med->m_port); - + snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", event->cid); - switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); + switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); if (!dname) { exosip_on_hangup(session); @@ -945,21 +962,21 @@ static switch_status exosip_create_call(eXosip_event_t *event) int rate = atoi(drate); if (switch_core_codec_init(&tech_pvt->read_codec, - dname, - rate, - globals.codec_ms, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL) != SWITCH_STATUS_SUCCESS) { + dname, + rate, + globals.codec_ms, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_channel_hangup(channel); return SWITCH_STATUS_FALSE; } else { if (switch_core_codec_init(&tech_pvt->write_codec, - dname, - rate, - globals.codec_ms, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL) != SWITCH_STATUS_SUCCESS) { + dname, + rate, + globals.codec_ms, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_channel_hangup(channel); return SWITCH_STATUS_FALSE; @@ -967,14 +984,15 @@ static switch_status exosip_create_call(eXosip_event_t *event) int ms; switch_set_flag(tech_pvt, TFLAG_USING_CODEC); ms = tech_pvt->write_codec.implementation->nanoseconds_per_frame / 1000; - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate, ms); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate, + ms); tech_pvt->read_frame.codec = &tech_pvt->read_codec; switch_core_session_set_read_codec(session, &tech_pvt->read_codec); switch_core_session_set_write_codec(session, &tech_pvt->write_codec); } } } - + switch_core_session_thread_launch(session); } else { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Create new Inbound Channel!\n"); @@ -987,13 +1005,14 @@ static switch_status exosip_create_call(eXosip_event_t *event) } -static void destroy_call_by_event(eXosip_event_t *event) +static void destroy_call_by_event(eXosip_event_t * event) { struct private_object *tech_pvt; switch_channel *channel = NULL; if (!(tech_pvt = get_pvt_by_call_id(event->cid))) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n", event->cid); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n", + event->cid); return; } @@ -1003,10 +1022,10 @@ static void destroy_call_by_event(eXosip_event_t *event) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "destroy %s\n", switch_channel_get_name(channel)); exosip_kill_channel(tech_pvt->session, SWITCH_SIG_KILL); switch_channel_hangup(channel); - + } -static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload) +static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload) { int pos = 0; sdp_attribute_t *attr = NULL; @@ -1014,7 +1033,7 @@ static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **dr switch_status status = SWITCH_STATUS_GENERR; while (osip_list_eol(media->a_attributes, pos) == 0) { - attr = (sdp_attribute_t *)osip_list_get(media->a_attributes, pos); + attr = (sdp_attribute_t *) osip_list_get(media->a_attributes, pos); if (attr != NULL && strcasecmp(attr->a_att_field, "rtpmap") == 0) { payload = attr->a_att_value; if ((name = strchr(payload, ' '))) { @@ -1035,7 +1054,8 @@ static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **dr *dname = strdup("L16"); *drate = strdup("8000"); } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n", *dpayload, *dname, *drate); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n", + *dpayload, *dname, *drate); break; } attr = NULL; @@ -1045,7 +1065,7 @@ static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **dr return status; } -static void handle_answer(eXosip_event_t *event) +static void handle_answer(eXosip_event_t * event) { osip_message_t *ack = NULL; sdp_message_t *remote_sdp = NULL; @@ -1093,18 +1113,22 @@ static void handle_answer(eXosip_event_t *event) /* Assign them thar IDs */ tech_pvt->did = event->did; tech_pvt->tid = event->tid; - + if (1) { int rate = atoi(drate); - if (switch_core_codec_init(&tech_pvt->read_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) { + if (switch_core_codec_init + (&tech_pvt->read_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_channel_hangup(channel); return; } else { - if (switch_core_codec_init(&tech_pvt->write_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) { + if (switch_core_codec_init + (&tech_pvt->write_codec, dname, rate, globals.codec_ms, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_channel_hangup(channel); return; @@ -1125,7 +1149,7 @@ static void handle_answer(eXosip_event_t *event) eXosip_call_build_ack(event->did, &ack); eXosip_call_send_ack(event->did, ack); eXosip_unlock(); - + free(dname); free(drate); free(dpayload); @@ -1137,133 +1161,119 @@ static void handle_answer(eXosip_event_t *event) } -static void log_event(eXosip_event_t *je) +static void log_event(eXosip_event_t * je) { char buf[100]; buf[0] = '\0'; if (je->type == EXOSIP_CALL_NOANSWER) { - snprintf (buf, 99, "<- (%i %i) No answer", je->cid, je->did); + snprintf(buf, 99, "<- (%i %i) No answer", je->cid, je->did); } else if (je->type == EXOSIP_CALL_CLOSED) { - snprintf (buf, 99, "<- (%i %i) Call Closed", je->cid, je->did); + snprintf(buf, 99, "<- (%i %i) Call Closed", je->cid, je->did); } else if (je->type == EXOSIP_CALL_RELEASED) { - snprintf (buf, 99, "<- (%i %i) Call released", je->cid, je->did); - } else if (je->type == EXOSIP_MESSAGE_NEW - && je->request!=NULL && MSG_IS_MESSAGE(je->request)) { + snprintf(buf, 99, "<- (%i %i) Call released", je->cid, je->did); + } else if (je->type == EXOSIP_MESSAGE_NEW && je->request != NULL && MSG_IS_MESSAGE(je->request)) { char *tmp = NULL; - + if (je->request != NULL) { osip_body_t *body; - osip_from_to_str (je->request->from, &tmp); - - osip_message_get_body (je->request, 0, &body); + osip_from_to_str(je->request->from, &tmp); + + osip_message_get_body(je->request, 0, &body); if (body != NULL && body->body != NULL) { - snprintf (buf, 99, "<- (%i) from: %s TEXT: %s", - je->tid, tmp, body->body); + snprintf(buf, 99, "<- (%i) from: %s TEXT: %s", je->tid, tmp, body->body); } - osip_free (tmp); + osip_free(tmp); } else { - snprintf (buf, 99, "<- (%i) New event for unknown request?", je->tid); + snprintf(buf, 99, "<- (%i) New event for unknown request?", je->tid); } } else if (je->type == EXOSIP_MESSAGE_NEW) { char *tmp = NULL; - - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (%i) %s from: %s", - je->tid, je->request->sip_method, tmp); - osip_free (tmp); + + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (%i) %s from: %s", je->tid, je->request->sip_method, tmp); + osip_free(tmp); } else if (je->type == EXOSIP_MESSAGE_PROCEEDING - || je->type == EXOSIP_MESSAGE_ANSWERED - || je->type == EXOSIP_MESSAGE_REDIRECTED - || je->type == EXOSIP_MESSAGE_REQUESTFAILURE - || je->type == EXOSIP_MESSAGE_SERVERFAILURE - || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) { + || je->type == EXOSIP_MESSAGE_ANSWERED + || je->type == EXOSIP_MESSAGE_REDIRECTED + || je->type == EXOSIP_MESSAGE_REQUESTFAILURE + || je->type == EXOSIP_MESSAGE_SERVERFAILURE || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) { if (je->response != NULL && je->request != NULL) { char *tmp = NULL; - - osip_to_to_str (je->request->to, &tmp); - snprintf (buf, 99, "<- (%i) [%i %s for %s] to: %s", - je->tid, je->response->status_code, - je->response->reason_phrase, je->request->sip_method, tmp); - osip_free (tmp); + + osip_to_to_str(je->request->to, &tmp); + snprintf(buf, 99, "<- (%i) [%i %s for %s] to: %s", + je->tid, je->response->status_code, je->response->reason_phrase, je->request->sip_method, tmp); + osip_free(tmp); } else if (je->request != NULL) { - snprintf (buf, 99, "<- (%i) Error for %s request", - je->tid, je->request->sip_method); + snprintf(buf, 99, "<- (%i) Error for %s request", je->tid, je->request->sip_method); } else { - snprintf (buf, 99, "<- (%i) Error for unknown request", je->tid); + snprintf(buf, 99, "<- (%i) Error for unknown request", je->tid); } } else if (je->response == NULL && je->request != NULL && je->cid > 0) { char *tmp = NULL; - - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (%i %i) %s from: %s", - je->cid, je->did, je->request->cseq->method, tmp); - osip_free (tmp); + + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (%i %i) %s from: %s", je->cid, je->did, je->request->cseq->method, tmp); + osip_free(tmp); } else if (je->response != NULL && je->cid > 0) { char *tmp = NULL; - - osip_to_to_str (je->request->to, &tmp); - snprintf (buf, 99, "<- (%i %i) [%i %s] for %s to: %s", - je->cid, je->did, je->response->status_code, - je->response->reason_phrase, je->request->sip_method, tmp); - osip_free (tmp); + + osip_to_to_str(je->request->to, &tmp); + snprintf(buf, 99, "<- (%i %i) [%i %s] for %s to: %s", + je->cid, je->did, je->response->status_code, + je->response->reason_phrase, je->request->sip_method, tmp); + osip_free(tmp); } else if (je->response == NULL && je->request != NULL && je->rid > 0) { char *tmp = NULL; - - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (%i) %s from: %s", - je->rid, je->request->cseq->method, tmp); - osip_free (tmp); + + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (%i) %s from: %s", je->rid, je->request->cseq->method, tmp); + osip_free(tmp); } else if (je->response != NULL && je->rid > 0) { char *tmp = NULL; - - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (%i) [%i %s] from: %s", - je->rid, je->response->status_code, - je->response->reason_phrase, tmp); - osip_free (tmp); + + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (%i) [%i %s] from: %s", + je->rid, je->response->status_code, je->response->reason_phrase, tmp); + osip_free(tmp); } else if (je->response == NULL && je->request != NULL && je->sid > 0) { char *tmp = NULL; char *stat = NULL; osip_header_t *sub_state; - - osip_message_header_get_byname (je->request, "subscription-state", - 0, &sub_state); + + osip_message_header_get_byname(je->request, "subscription-state", 0, &sub_state); if (sub_state != NULL && sub_state->hvalue != NULL) stat = sub_state->hvalue; - - osip_uri_to_str (je->request->from->url, &tmp); - snprintf (buf, 99, "<- (%i) [%s] %s from: %s", - je->sid, stat, je->request->cseq->method, tmp); - osip_free (tmp); + + osip_uri_to_str(je->request->from->url, &tmp); + snprintf(buf, 99, "<- (%i) [%s] %s from: %s", je->sid, stat, je->request->cseq->method, tmp); + osip_free(tmp); } else if (je->response != NULL && je->sid > 0) { char *tmp = NULL; - - osip_uri_to_str (je->request->to->url, &tmp); - snprintf (buf, 99, "<- (%i) [%i %s] from: %s", - je->sid, je->response->status_code, - je->response->reason_phrase, tmp); - osip_free (tmp); + + osip_uri_to_str(je->request->to->url, &tmp); + snprintf(buf, 99, "<- (%i) [%i %s] from: %s", + je->sid, je->response->status_code, je->response->reason_phrase, tmp); + osip_free(tmp); } else if (je->response == NULL && je->request != NULL) { char *tmp = NULL; - - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s", - je->cid, je->did, je->sid, je->nid, - je->request->sip_method, tmp); - osip_free (tmp); + + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s", + je->cid, je->did, je->sid, je->nid, je->request->sip_method, tmp); + osip_free(tmp); } else if (je->response != NULL) { char *tmp = NULL; - - osip_from_to_str (je->request->from, &tmp); - snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s", - je->cid, je->did, je->sid, je->nid, - je->response->status_code, je->response->reason_phrase, - je->request->sip_method, tmp); - osip_free (tmp); + + osip_from_to_str(je->request->from, &tmp); + snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s", + je->cid, je->did, je->sid, je->nid, + je->response->status_code, je->response->reason_phrase, je->request->sip_method, tmp); + osip_free(tmp); } else { - snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s", - je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo); + snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s", + je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo); } switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\n%s\n", buf); /* Print it out */ @@ -1274,21 +1284,21 @@ static void log_event(eXosip_event_t *je) static void *monitor_thread_run(void) { eXosip_event_t *event = NULL; - + globals.running = 1; while (globals.running > 0) { - if (!(event = eXosip_event_wait(0,100))) { + if (!(event = eXosip_event_wait(0, 100))) { switch_yield(100); continue; } eXosip_lock(); - eXosip_automatic_action (); + eXosip_automatic_action(); eXosip_unlock(); log_event(event); - switch(event->type) { + switch (event->type) { case EXOSIP_CALL_INVITE: exosip_create_call(event); break; @@ -1360,7 +1370,7 @@ static void *monitor_thread_run(void) } -static int config_exosip(int reload) +static int config_exosip(int reload) { switch_config cfg; char *var, *val; @@ -1394,7 +1404,7 @@ static int config_exosip(int reload) } } } - + if (!globals.codec_ms) { globals.codec_ms = 20; } @@ -1409,11 +1419,11 @@ static int config_exosip(int reload) set_global_dialplan("default"); } - if (eXosip_init ()) { + if (eXosip_init()) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_init initialization failed!\n"); return SWITCH_STATUS_GENERR; } - if (eXosip_listen_addr (IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) { + if (eXosip_listen_addr(IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_listen_addr failed!\n"); return SWITCH_STATUS_GENERR; } @@ -1436,4 +1446,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) config_exosip(0); return SWITCH_STATUS_TERM; } - diff --git a/src/mod/endpoints/mod_iax/mod_iax.c b/src/mod/endpoints/mod_iax/mod_iax.c index 612a8cf6e2..d44d57b929 100644 --- a/src/mod/endpoints/mod_iax/mod_iax.c +++ b/src/mod/endpoints/mod_iax/mod_iax.c @@ -83,7 +83,7 @@ struct private_object { unsigned char databuf[SWITCH_RECCOMMENDED_BUFFER_SIZE]; switch_core_session *session; struct iax_session *iax_session; - switch_caller_profile *caller_profile; + switch_caller_profile *caller_profile; unsigned int codec; unsigned int codecs; unsigned short samprate; @@ -92,19 +92,21 @@ struct private_object { }; SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan) -SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string) -SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string) + SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string) + SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string) -static char *IAXNAMES[] = {"IAX_EVENT_CONNECT","IAX_EVENT_ACCEPT","IAX_EVENT_HANGUP","IAX_EVENT_REJECT","IAX_EVENT_VOICE", - "IAX_EVENT_DTMF","IAX_EVENT_TIMEOUT","IAX_EVENT_LAGRQ","IAX_EVENT_LAGRP","IAX_EVENT_RINGA", - "IAX_EVENT_PING","IAX_EVENT_PONG","IAX_EVENT_BUSY","IAX_EVENT_ANSWER","IAX_EVENT_IMAGE", - "IAX_EVENT_AUTHRQ","IAX_EVENT_AUTHRP","IAX_EVENT_REGREQ","IAX_EVENT_REGACK", - "IAX_EVENT_URL","IAX_EVENT_LDCOMPLETE","IAX_EVENT_TRANSFER","IAX_EVENT_DPREQ", - "IAX_EVENT_DPREP","IAX_EVENT_DIAL","IAX_EVENT_QUELCH","IAX_EVENT_UNQUELCH", - "IAX_EVENT_UNLINK","IAX_EVENT_LINKREJECT","IAX_EVENT_TEXT","IAX_EVENT_REGREJ", - "IAX_EVENT_LINKURL","IAX_EVENT_CNG","IAX_EVENT_REREQUEST","IAX_EVENT_TXREPLY", - "IAX_EVENT_TXREJECT","IAX_EVENT_TXACCEPT","IAX_EVENT_TXREADY"}; + static char *IAXNAMES[] = + { "IAX_EVENT_CONNECT", "IAX_EVENT_ACCEPT", "IAX_EVENT_HANGUP", "IAX_EVENT_REJECT", "IAX_EVENT_VOICE", + "IAX_EVENT_DTMF", "IAX_EVENT_TIMEOUT", "IAX_EVENT_LAGRQ", "IAX_EVENT_LAGRP", "IAX_EVENT_RINGA", + "IAX_EVENT_PING", "IAX_EVENT_PONG", "IAX_EVENT_BUSY", "IAX_EVENT_ANSWER", "IAX_EVENT_IMAGE", + "IAX_EVENT_AUTHRQ", "IAX_EVENT_AUTHRP", "IAX_EVENT_REGREQ", "IAX_EVENT_REGACK", + "IAX_EVENT_URL", "IAX_EVENT_LDCOMPLETE", "IAX_EVENT_TRANSFER", "IAX_EVENT_DPREQ", + "IAX_EVENT_DPREP", "IAX_EVENT_DIAL", "IAX_EVENT_QUELCH", "IAX_EVENT_UNQUELCH", + "IAX_EVENT_UNLINK", "IAX_EVENT_LINKREJECT", "IAX_EVENT_TEXT", "IAX_EVENT_REGREJ", + "IAX_EVENT_LINKURL", "IAX_EVENT_CNG", "IAX_EVENT_REREQUEST", "IAX_EVENT_TXREPLY", + "IAX_EVENT_TXREJECT", "IAX_EVENT_TXACCEPT", "IAX_EVENT_TXREADY" + }; struct ast_iana { @@ -114,31 +116,30 @@ struct ast_iana { }; //999 means it's wrong nad i dont know the real one -static struct ast_iana AST_IANA[] = - {{AST_FORMAT_G723_1, 4, "g723.1"}, - {AST_FORMAT_GSM, 3, "gsm"}, - {AST_FORMAT_ULAW, 0, "ulaw"}, - {AST_FORMAT_ALAW, 8, "alaw"}, - {AST_FORMAT_G726, 999, "g726"}, - {AST_FORMAT_ADPCM, 999, "adpcm"}, - {AST_FORMAT_SLINEAR, 10, "slinear"}, - {AST_FORMAT_LPC10, 7, "lpc10"}, - {AST_FORMAT_G729A, 18, "g729"}, - {AST_FORMAT_SPEEX, 98, "speex"}, - {AST_FORMAT_ILBC, 999, "ilbc"}, - {AST_FORMAT_MAX_AUDIO, 999, ""}, - {AST_FORMAT_JPEG, 999, ""}, - {AST_FORMAT_PNG, 999, ""}, - {AST_FORMAT_H261, 999, ""}, - {AST_FORMAT_H263, 999, ""}, - {AST_FORMAT_MAX_VIDEO, 999, ""}, - {0,0} - }; +static struct ast_iana AST_IANA[] = { {AST_FORMAT_G723_1, 4, "g723.1"}, +{AST_FORMAT_GSM, 3, "gsm"}, +{AST_FORMAT_ULAW, 0, "ulaw"}, +{AST_FORMAT_ALAW, 8, "alaw"}, +{AST_FORMAT_G726, 999, "g726"}, +{AST_FORMAT_ADPCM, 999, "adpcm"}, +{AST_FORMAT_SLINEAR, 10, "slinear"}, +{AST_FORMAT_LPC10, 7, "lpc10"}, +{AST_FORMAT_G729A, 18, "g729"}, +{AST_FORMAT_SPEEX, 98, "speex"}, +{AST_FORMAT_ILBC, 999, "ilbc"}, +{AST_FORMAT_MAX_AUDIO, 999, ""}, +{AST_FORMAT_JPEG, 999, ""}, +{AST_FORMAT_PNG, 999, ""}, +{AST_FORMAT_H261, 999, ""}, +{AST_FORMAT_H263, 999, ""}, +{AST_FORMAT_MAX_VIDEO, 999, ""}, +{0, 0} +}; static char *ast2str(unsigned int ast) { int x; - for(x = 0; x < 32; x++) { + for (x = 0; x < 32; x++) { if ((1 << x) == ast) { return AST_IANA[x].name; } @@ -151,7 +152,7 @@ static unsigned int iana2ast(int iana) int x = 0; unsigned int ast = 0; - for(x = 0; AST_IANA[x].ast; x++) { + for (x = 0; AST_IANA[x].ast; x++) { if (AST_IANA[x].iana == iana) { ast = AST_IANA[x].ast; break; @@ -161,11 +162,11 @@ static unsigned int iana2ast(int iana) return ast; } -static unsigned short iax_build_codec_rates(void) +static unsigned short iax_build_codec_rates(void) { int x; unsigned short samples = 0; - + for (x = 0; x < globals.codec_rates_last; x++) { int rate = atoi(globals.codec_rates[x]); switch (rate) { @@ -200,7 +201,9 @@ typedef enum { IAX_QUERY = 2 } iax_io_t; -static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_session *iax_session, unsigned int *format, unsigned int *cababilities, unsigned short *samprate, iax_io_t io) +static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_session *iax_session, + unsigned int *format, unsigned int *cababilities, unsigned short *samprate, + iax_io_t io) { char *dname = NULL; //int rate = 8000; @@ -213,14 +216,18 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s if (globals.codec_string) { if (!(num_codecs = switch_loadable_module_get_codecs_sorted(switch_core_session_get_pool(tech_pvt->session), - codecs, - SWITCH_MAX_CODECS, - globals.codec_order, - globals.codec_order_last)) > 0) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n"); - return SWITCH_STATUS_GENERR; + codecs, + SWITCH_MAX_CODECS, + globals.codec_order, + globals.codec_order_last)) > 0) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n"); + return SWITCH_STATUS_GENERR; } - } else if (!(num_codecs = switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), codecs, SWITCH_MAX_CODECS)) > 0) { + } else + if (! + (num_codecs = + switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), codecs, + SWITCH_MAX_CODECS)) > 0) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n"); return SWITCH_STATUS_GENERR; } @@ -260,7 +267,7 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s len = iax_pref_codec_get(iax_session, prefs, sizeof(prefs)); } - if (len) { /*they sent us a pref and we don't want to be codec master*/ + if (len) { /*they sent us a pref and we don't want to be codec master */ char pref_str[256] = "("; for (x = 0; x < len; x++) { @@ -283,7 +290,7 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s } } } else { - if (*format & mixed_cap) { /* is the one we asked for here? */ + if (*format & mixed_cap) { /* is the one we asked for here? */ chosen = *format; for (x = 0; x < num_codecs; x++) { unsigned int cap = iana2ast(codecs[x]->ianacode); @@ -291,7 +298,7 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s dname = codecs[x]->iananame; } } - } else { /* c'mon there has to be SOMETHING...*/ + } else { /* c'mon there has to be SOMETHING... */ for (x = 0; x < num_codecs; x++) { unsigned int cap = iana2ast(codecs[x]->ianacode); if (cap & mixed_cap) { @@ -318,7 +325,7 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s //printf("\n\n******WTF %u %u %u\n******\n", *samprate, samples, mixed); srate = 8000; - + if (mixed & IAX_RATE_16KHZ) { srate = 16000; } @@ -344,9 +351,8 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s srate, 0, 1, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL, - switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); return SWITCH_STATUS_GENERR; } else { @@ -355,11 +361,10 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s srate, 0, 1, - SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE, - NULL, - switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); - switch_core_codec_destroy(&tech_pvt->read_codec); + switch_core_codec_destroy(&tech_pvt->read_codec); return SWITCH_STATUS_GENERR; } else { int ms; @@ -392,9 +397,12 @@ static switch_status channel_on_hangup(switch_core_session *session); static switch_status channel_on_ring(switch_core_session *session); static switch_status channel_on_loopback(switch_core_session *session); static switch_status channel_on_transmit(switch_core_session *session); -static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id); -static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id); +static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session); +static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags, int stream_id); +static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags, int stream_id); static switch_status channel_kill_channel(switch_core_session *session, int sig); @@ -434,7 +442,7 @@ static switch_status channel_on_init(switch_core_session *session) switch_set_flag(tech_pvt, TFLAG_IO); switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); - //switch_thread_cond_create(&tech_pvt->cond, switch_core_session_get_pool(session)); + //switch_thread_cond_create(&tech_pvt->cond, switch_core_session_get_pool(session)); //switch_mutex_lock(tech_pvt->mutex); /* Move Channel's State Machine to RING */ @@ -551,7 +559,8 @@ static switch_status channel_on_transmit(switch_core_session *session) /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines that allocate memory or you will have 1 channel with memory allocated from another channel's pool! */ -static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session) +static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session) { if ((*new_session = switch_core_session_request(&channel_endpoint_interface, NULL))) { struct private_object *tech_pvt; @@ -561,7 +570,8 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit unsigned short samprate = 0; switch_core_session_add_stream(*new_session, NULL); - if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { + if ((tech_pvt = + (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(*new_session); switch_core_session_set_private(*new_session, tech_pvt); @@ -601,10 +611,8 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit } iax_call(tech_pvt->iax_session, - caller_profile->caller_id_number, - caller_profile->caller_id_name, - caller_profile->destination_number, - NULL, 0, req, cap); + caller_profile->caller_id_number, + caller_profile->caller_id_name, caller_profile->destination_number, NULL, 0, req, cap); switch_channel_set_flag(channel, CF_OUTBOUND); switch_set_flag(tech_pvt, TFLAG_OUTBOUND); @@ -645,7 +653,7 @@ static switch_status channel_send_dtmf(switch_core_session *session, char *dtmf) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); if (tech_pvt->iax_session) { - for(digit = dtmf; *digit; digit++) { + for (digit = dtmf; *digit; digit++) { iax_send_dtmf(tech_pvt->iax_session, *digit); } } @@ -653,7 +661,8 @@ static switch_status channel_send_dtmf(switch_core_session *session, char *dtmf) return SWITCH_STATUS_SUCCESS; } -static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id) +static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -668,26 +677,27 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra while (switch_test_flag(tech_pvt, TFLAG_IO)) { //switch_thread_cond_wait(tech_pvt->cond, tech_pvt->mutex); if (!switch_test_flag(tech_pvt, TFLAG_IO)) { - return SWITCH_STATUS_FALSE; + return SWITCH_STATUS_FALSE; } - + if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) { switch_clear_flag(tech_pvt, TFLAG_VOICE); - if(!tech_pvt->read_frame.datalen) { + if (!tech_pvt->read_frame.datalen) { continue; } - + *frame = &tech_pvt->read_frame; return SWITCH_STATUS_SUCCESS; } switch_yield(1000); } - - + + return SWITCH_STATUS_FALSE; } -static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) +static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -699,16 +709,16 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - if(!switch_test_flag(tech_pvt, TFLAG_IO)) { + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { return SWITCH_STATUS_FALSE; } - #ifndef BIGENDIAN if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) { - switch_swap_linear(frame->data, (int)frame->datalen / 2); + switch_swap_linear(frame->data, (int) frame->datalen / 2); } #endif - iax_send_voice(tech_pvt->iax_session, tech_pvt->codec, frame->data, (int)frame->datalen, tech_pvt->write_codec.implementation->samples_per_frame); + iax_send_voice(tech_pvt->iax_session, tech_pvt->codec, frame->data, (int) frame->datalen, + tech_pvt->write_codec.implementation->samples_per_frame); return SWITCH_STATUS_SUCCESS; @@ -732,44 +742,45 @@ static switch_status channel_answer_channel(switch_core_session *session) } static const switch_event_handler_table channel_event_handlers = { - /*.on_init*/ channel_on_init, - /*.on_ring*/ channel_on_ring, - /*.on_execute*/ channel_on_execute, - /*.on_hangup*/ channel_on_hangup, - /*.on_loopback*/ channel_on_loopback, - /*.on_transmit*/ channel_on_transmit + /*.on_init */ channel_on_init, + /*.on_ring */ channel_on_ring, + /*.on_execute */ channel_on_execute, + /*.on_hangup */ channel_on_hangup, + /*.on_loopback */ channel_on_loopback, + /*.on_transmit */ channel_on_transmit }; static const switch_io_routines channel_io_routines = { - /*.outgoing_channel*/ channel_outgoing_channel, - /*.answer_channel*/ channel_answer_channel, - /*.read_frame*/ channel_read_frame, - /*.write_frame*/ channel_write_frame, - /*.kill_channel*/ channel_kill_channel, - /*.waitfor_read*/ channel_waitfor_read, - /*.waitfor_write*/ channel_waitfor_write, - /*.send_dtmf*/ channel_send_dtmf + /*.outgoing_channel */ channel_outgoing_channel, + /*.answer_channel */ channel_answer_channel, + /*.read_frame */ channel_read_frame, + /*.write_frame */ channel_write_frame, + /*.kill_channel */ channel_kill_channel, + /*.waitfor_read */ channel_waitfor_read, + /*.waitfor_write */ channel_waitfor_write, + /*.send_dtmf */ channel_send_dtmf }; static const switch_endpoint_interface channel_endpoint_interface = { - /*.interface_name*/ "iax", - /*.io_routines*/ &channel_io_routines, - /*.event_handlers*/ &channel_event_handlers, - /*.private*/ NULL, - /*.next*/ NULL + /*.interface_name */ "iax", + /*.io_routines */ &channel_io_routines, + /*.event_handlers */ &channel_event_handlers, + /*.private */ NULL, + /*.next */ NULL }; static const switch_loadable_module_interface channel_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ &channel_endpoint_interface, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ NULL, - /*.application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ &channel_endpoint_interface, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL }; -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n"); @@ -820,10 +831,12 @@ static switch_status load_config(void) set_global_dialplan(val); } else if (!strcmp(var, "codec_prefs")) { set_global_codec_string(val); - globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS); + globals.codec_order_last = + switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS); } else if (!strcmp(var, "codec_rates")) { set_global_codec_rates_string(val); - globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS); + globals.codec_rates_last = + switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS); } } } @@ -860,17 +873,17 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) iax_set_error(iax_err_cb); iax_set_output(iax_out_cb); - netfd = iax_get_fd(); + netfd = iax_get_fd(); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "IAX Ready Port %d\n", globals.port); - for(;;) { + for (;;) { if (running == -1) { break; } - /* Wait for an event.*/ + /* Wait for an event. */ if ((iaxevent = iax_get_event(0)) == NULL) { switch_yield(1000); continue; @@ -879,173 +892,182 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) if (globals.debug && iaxevent->etype != IAX_EVENT_VOICE) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Event %d [%s]!\n", - iaxevent->etype, IAXNAMES[iaxevent->etype]); + iaxevent->etype, IAXNAMES[iaxevent->etype]); } switch (iaxevent->etype) { - case IAX_EVENT_REGACK: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration completed successfully.\n"); - if (iaxevent->ies.refresh) refresh = iaxevent->ies.refresh; - break; - case IAX_EVENT_REGREJ: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration failed.\n"); - break; - case IAX_EVENT_TIMEOUT: - break; - case IAX_EVENT_ACCEPT: - if (tech_pvt) { - unsigned int cap = iax_session_get_capability(iaxevent->session); - unsigned int format = iaxevent->ies.format; + case IAX_EVENT_REGACK: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration completed successfully.\n"); + if (iaxevent->ies.refresh) + refresh = iaxevent->ies.refresh; + break; + case IAX_EVENT_REGREJ: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration failed.\n"); + break; + case IAX_EVENT_TIMEOUT: + break; + case IAX_EVENT_ACCEPT: + if (tech_pvt) { + unsigned int cap = iax_session_get_capability(iaxevent->session); + unsigned int format = iaxevent->ies.format; - if (iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, &iaxevent->ies.samprate, IAX_SET) != SWITCH_STATUS_SUCCESS) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF? %d %d\n",iaxevent->ies.format, iaxevent->ies.capability); - } + if (iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, &iaxevent->ies.samprate, IAX_SET) != + SWITCH_STATUS_SUCCESS) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF? %d %d\n", iaxevent->ies.format, + iaxevent->ies.capability); } + } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call accepted.\n"); - break; - case IAX_EVENT_RINGA: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Ringing heard.\n"); - break; - case IAX_EVENT_PONG: - // informative only - break; - case IAX_EVENT_ANSWER: - // the other side answered our call - if (tech_pvt) { - switch_channel *channel; - if ((channel = switch_core_session_get_channel(tech_pvt->session))) { - if (switch_channel_test_flag(channel, CF_ANSWERED)) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF Mutiple Answer %s?\n", switch_channel_get_name(channel)); - } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Answer %s\n", switch_channel_get_name(channel)); - switch_channel_answer(channel); - } - } - } - - break; - case IAX_EVENT_CONNECT: - // incoming call detected - switch_console_printf(SWITCH_CHANNEL_CONSOLE, - "Incoming call connected %s, %s, %s %d/%d\n", - iaxevent->ies.called_number, - iaxevent->ies.calling_number, - iaxevent->ies.calling_name, - iaxevent->ies.format, - iaxevent->ies.capability); - - if (iaxevent) { - switch_core_session *session; - - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "New Inbound Channel %s!\n", iaxevent->ies.calling_name); - if ((session = switch_core_session_request(&channel_endpoint_interface, NULL))) { - struct private_object *tech_pvt; - switch_channel *channel; - - switch_core_session_add_stream(session, NULL); - if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) { - memset(tech_pvt, 0, sizeof(*tech_pvt)); - channel = switch_core_session_get_channel(session); - switch_core_session_set_private(session, tech_pvt); - tech_pvt->session = session; - } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hey where is my memory pool?\n"); - switch_core_session_destroy(&session); - break; - } - - - if ((tech_pvt->caller_profile = switch_caller_profile_new(session, - globals.dialplan, - iaxevent->ies.calling_name, - iaxevent->ies.calling_number, - iax_get_peer_ip(iaxevent->session), - iaxevent->ies.calling_ani, - NULL, - iaxevent->ies.called_number))) { - char name[128]; - switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); - snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff); - switch_channel_set_name(channel, name); - } - - if (iax_set_codec(tech_pvt, iaxevent->session, - &iaxevent->ies.format, - &iaxevent->ies.capability, - &iaxevent->ies.samprate, - IAX_SET) != SWITCH_STATUS_SUCCESS) { - iax_reject(iaxevent->session, "Codec Error!"); - switch_core_session_destroy(&session); - } else { - tech_pvt->iax_session = iaxevent->session; - tech_pvt->session = session; - iax_accept(tech_pvt->iax_session, tech_pvt->codec); - iax_ring_announce(tech_pvt->iax_session); - switch_channel_set_state(channel, CS_INIT); - switch_core_session_thread_launch(session); - } - } - } - break; - case IAX_EVENT_REJECT: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Rejected call.\n"); - case IAX_EVENT_BUSY: - case IAX_EVENT_HANGUP: - if (tech_pvt) { - switch_channel *channel; - - switch_clear_flag(tech_pvt, TFLAG_IO); - switch_clear_flag(tech_pvt, TFLAG_VOICE); - if ((channel = switch_core_session_get_channel(tech_pvt->session))) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hangup %s\n", switch_channel_get_name(channel)); - switch_set_flag(tech_pvt, TFLAG_HANGUP); - switch_channel_hangup(channel); - //switch_thread_cond_signal(tech_pvt->cond); - iaxevent->session = NULL; + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call accepted.\n"); + break; + case IAX_EVENT_RINGA: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Ringing heard.\n"); + break; + case IAX_EVENT_PONG: + // informative only + break; + case IAX_EVENT_ANSWER: + // the other side answered our call + if (tech_pvt) { + switch_channel *channel; + if ((channel = switch_core_session_get_channel(tech_pvt->session))) { + if (switch_channel_test_flag(channel, CF_ANSWERED)) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF Mutiple Answer %s?\n", + switch_channel_get_name(channel)); } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Session? %s\n", switch_test_flag(tech_pvt, TFLAG_VOICE) ? "yes" : "no"); - } - } - break; - case IAX_EVENT_CNG: - // pseudo-silence - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sending silence\n"); - break; - case IAX_EVENT_VOICE: - if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen)) { - switch_channel *channel; - if ((channel = switch_core_session_get_channel(tech_pvt->session)) && switch_channel_get_state(channel) <= CS_HANGUP) { - int bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame; - int frames = (int)(tech_pvt->read_frame.datalen / bytes); - tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame; - memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen); - /* wake up the i/o thread*/ - switch_set_flag(tech_pvt, TFLAG_VOICE); - //switch_thread_cond_signal(tech_pvt->cond); - } - } - break; - case IAX_EVENT_TRANSFER: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call transfer occurred.\n"); - //session[0] = iaxevent->session; - break; - case IAX_EVENT_DTMF: - if (tech_pvt) { - switch_channel *channel; - if ((channel = switch_core_session_get_channel(tech_pvt->session))) { - char str[2] = {iaxevent->subclass}; - if (globals.debug) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s DTMF %s\n", str, switch_channel_get_name(channel)); - } - switch_channel_queue_dtmf(channel, str); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Answer %s\n", + switch_channel_get_name(channel)); + switch_channel_answer(channel); } } + } - break; - default: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Don't know what to do with IAX event %d.\n", iaxevent->etype); - break; + break; + case IAX_EVENT_CONNECT: + // incoming call detected + switch_console_printf(SWITCH_CHANNEL_CONSOLE, + "Incoming call connected %s, %s, %s %d/%d\n", + iaxevent->ies.called_number, + iaxevent->ies.calling_number, + iaxevent->ies.calling_name, iaxevent->ies.format, iaxevent->ies.capability); + + if (iaxevent) { + switch_core_session *session; + + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "New Inbound Channel %s!\n", + iaxevent->ies.calling_name); + if ((session = switch_core_session_request(&channel_endpoint_interface, NULL))) { + struct private_object *tech_pvt; + switch_channel *channel; + + switch_core_session_add_stream(session, NULL); + if ((tech_pvt = + (struct private_object *) switch_core_session_alloc(session, + sizeof(struct private_object)))) { + memset(tech_pvt, 0, sizeof(*tech_pvt)); + channel = switch_core_session_get_channel(session); + switch_core_session_set_private(session, tech_pvt); + tech_pvt->session = session; + } else { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hey where is my memory pool?\n"); + switch_core_session_destroy(&session); + break; + } + + + if ((tech_pvt->caller_profile = switch_caller_profile_new(session, + globals.dialplan, + iaxevent->ies.calling_name, + iaxevent->ies.calling_number, + iax_get_peer_ip(iaxevent->session), + iaxevent->ies.calling_ani, + NULL, iaxevent->ies.called_number))) { + char name[128]; + switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); + snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number, + rand() & 0xffff); + switch_channel_set_name(channel, name); + } + + if (iax_set_codec(tech_pvt, iaxevent->session, + &iaxevent->ies.format, + &iaxevent->ies.capability, + &iaxevent->ies.samprate, IAX_SET) != SWITCH_STATUS_SUCCESS) { + iax_reject(iaxevent->session, "Codec Error!"); + switch_core_session_destroy(&session); + } else { + tech_pvt->iax_session = iaxevent->session; + tech_pvt->session = session; + iax_accept(tech_pvt->iax_session, tech_pvt->codec); + iax_ring_announce(tech_pvt->iax_session); + switch_channel_set_state(channel, CS_INIT); + switch_core_session_thread_launch(session); + } + } + } + break; + case IAX_EVENT_REJECT: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Rejected call.\n"); + case IAX_EVENT_BUSY: + case IAX_EVENT_HANGUP: + if (tech_pvt) { + switch_channel *channel; + + switch_clear_flag(tech_pvt, TFLAG_IO); + switch_clear_flag(tech_pvt, TFLAG_VOICE); + if ((channel = switch_core_session_get_channel(tech_pvt->session))) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hangup %s\n", switch_channel_get_name(channel)); + switch_set_flag(tech_pvt, TFLAG_HANGUP); + switch_channel_hangup(channel); + //switch_thread_cond_signal(tech_pvt->cond); + iaxevent->session = NULL; + } else { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Session? %s\n", + switch_test_flag(tech_pvt, TFLAG_VOICE) ? "yes" : "no"); + } + } + break; + case IAX_EVENT_CNG: + // pseudo-silence + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sending silence\n"); + break; + case IAX_EVENT_VOICE: + if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen)) { + switch_channel *channel; + if ((channel = switch_core_session_get_channel(tech_pvt->session)) + && switch_channel_get_state(channel) <= CS_HANGUP) { + int bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame; + int frames = (int) (tech_pvt->read_frame.datalen / bytes); + tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame; + memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen); + /* wake up the i/o thread */ + switch_set_flag(tech_pvt, TFLAG_VOICE); + //switch_thread_cond_signal(tech_pvt->cond); + } + } + break; + case IAX_EVENT_TRANSFER: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call transfer occurred.\n"); + //session[0] = iaxevent->session; + break; + case IAX_EVENT_DTMF: + if (tech_pvt) { + switch_channel *channel; + if ((channel = switch_core_session_get_channel(tech_pvt->session))) { + char str[2] = { iaxevent->subclass }; + if (globals.debug) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s DTMF %s\n", str, + switch_channel_get_name(channel)); + } + switch_channel_queue_dtmf(channel, str); + } + } + + break; + default: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Don't know what to do with IAX event %d.\n", + iaxevent->etype); + break; } iax_event_free(iaxevent); @@ -1075,4 +1097,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void) } return SWITCH_STATUS_SUCCESS; } - diff --git a/src/mod/endpoints/mod_opal/mod_opal.c b/src/mod/endpoints/mod_opal/mod_opal.c index 8159f23f34..3a4aa205c6 100644 --- a/src/mod/endpoints/mod_opal/mod_opal.c +++ b/src/mod/endpoints/mod_opal/mod_opal.c @@ -54,7 +54,7 @@ struct private_object { struct switch_frame frame; unsigned char databuf[SWITCH_RECCOMMENDED_BUFFER_SIZE]; switch_core_session *session; - switch_caller_profile *caller_profile; + switch_caller_profile *caller_profile; }; @@ -65,9 +65,12 @@ static switch_status channel_on_hangup(switch_core_session *session); static switch_status channel_on_ring(switch_core_session *session); static switch_status channel_on_loopback(switch_core_session *session); static switch_status channel_on_transmit(switch_core_session *session); -static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id); -static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id); +static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session); +static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags, int stream_id); +static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags, int stream_id); static switch_status channel_kill_channel(switch_core_session *session, int sig); @@ -119,7 +122,7 @@ static switch_status channel_on_execute(switch_core_session *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel)); @@ -130,7 +133,7 @@ static switch_status channel_on_hangup(switch_core_session *session) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; - + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -147,7 +150,7 @@ static switch_status channel_kill_channel(switch_core_session *session, int sig) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; - + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -157,7 +160,7 @@ static switch_status channel_kill_channel(switch_core_session *session, int sig) switch_channel_hangup(channel); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL KILL\n", switch_channel_get_name(channel)); - + return SWITCH_STATUS_SUCCESS; } @@ -177,15 +180,17 @@ static switch_status channel_on_transmit(switch_core_session *session) /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines that allocate memory or you will have 1 channel with memory allocated from another channel's pool! */ -static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session) +static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session) { if ((*new_session = switch_core_session_request(&channel_endpoint_interface, NULL))) { struct private_object *tech_pvt; switch_channel *channel, *orig_channel; switch_caller_profile *caller_profile, *originator_caller_profile = NULL; - + switch_core_session_add_stream(*new_session, NULL); - if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { + if ((tech_pvt = + (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(*new_session); switch_core_session_set_private(*new_session, tech_pvt); @@ -218,7 +223,7 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit switch_channel_set_originator_caller_profile(channel, cloned_profile); } } - + switch_channel_set_flag(channel, CF_OUTBOUND); switch_set_flag(tech_pvt, TFLAG_OUTBOUND); switch_channel_set_state(channel, CS_INIT); @@ -250,7 +255,8 @@ static switch_status channel_waitfor_write(switch_core_session *session, int ms, } -static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id) +static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -266,7 +272,8 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra return SWITCH_STATUS_SUCCESS; } -static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) +static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -279,43 +286,43 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr assert(tech_pvt != NULL); return SWITCH_STATUS_SUCCESS; - + } static const switch_event_handler_table channel_event_handlers = { - /*.on_init*/ channel_on_init, - /*.on_ring*/ channel_on_ring, - /*.on_execute*/ channel_on_execute, - /*.on_hangup*/ channel_on_hangup, - /*.on_loopback*/ channel_on_loopback, - /*.on_transmit*/ channel_on_transmit + /*.on_init */ channel_on_init, + /*.on_ring */ channel_on_ring, + /*.on_execute */ channel_on_execute, + /*.on_hangup */ channel_on_hangup, + /*.on_loopback */ channel_on_loopback, + /*.on_transmit */ channel_on_transmit }; static const switch_io_routines channel_io_routines = { - /*.outgoing_channel*/ channel_outgoing_channel, - /*.answer_channel*/ NULL, - /*.read_frame*/ channel_read_frame, - /*.write_frame*/ channel_write_frame, - /*.kill_channel*/ channel_kill_channel, - /*.waitfor_read*/ channel_waitfor_read, - /*.waitfor_write*/ channel_waitfor_write + /*.outgoing_channel */ channel_outgoing_channel, + /*.answer_channel */ NULL, + /*.read_frame */ channel_read_frame, + /*.write_frame */ channel_write_frame, + /*.kill_channel */ channel_kill_channel, + /*.waitfor_read */ channel_waitfor_read, + /*.waitfor_write */ channel_waitfor_write }; static const switch_endpoint_interface channel_endpoint_interface = { - /*.interface_name*/ "opal", - /*.io_routines*/ &channel_io_routines, - /*.event_handlers*/ &channel_event_handlers, - /*.private*/ NULL, - /*.next*/ NULL + /*.interface_name */ "opal", + /*.io_routines */ &channel_io_routines, + /*.event_handlers */ &channel_event_handlers, + /*.private */ NULL, + /*.next */ NULL }; static const switch_loadable_module_interface channel_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ &channel_endpoint_interface, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ NULL, - /*.application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ &channel_endpoint_interface, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL }; @@ -338,19 +345,20 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void) } */ -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ switch_config cfg; char *var, *val; char *cf = "opal.conf"; - + memset(&globals, 0, sizeof(globals)); - + if (!switch_config_open_file(&cfg, cf)) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf); return SWITCH_STATUS_TERM; } - + while (switch_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "settings")) { @@ -364,7 +372,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul switch_config_close_file(&cfg); - + if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n"); return SWITCH_STATUS_TERM; diff --git a/src/mod/endpoints/mod_portaudio/mod_portaudio.c b/src/mod/endpoints/mod_portaudio/mod_portaudio.c index 787ce0d83c..657cb73632 100644 --- a/src/mod/endpoints/mod_portaudio/mod_portaudio.c +++ b/src/mod/endpoints/mod_portaudio/mod_portaudio.c @@ -81,51 +81,55 @@ static struct { struct private_object { unsigned int flags; switch_codec read_codec; - switch_codec write_codec; + switch_codec write_codec; struct switch_frame read_frame; unsigned char databuf[SWITCH_RECCOMMENDED_BUFFER_SIZE]; switch_core_session *session; - switch_caller_profile *caller_profile; + switch_caller_profile *caller_profile; char call_id[50]; PaError err; - PABLIO_Stream *audio_in; - PABLIO_Stream *audio_out; + PABLIO_Stream *audio_in; + PABLIO_Stream *audio_out; int indev; int outdev; }; SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan) -SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_name, globals.cid_name) -SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_num, globals.cid_num) + SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_name, globals.cid_name) + SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_num, globals.cid_num) -static const switch_endpoint_interface channel_endpoint_interface; + static const switch_endpoint_interface channel_endpoint_interface; -static switch_status channel_on_init(switch_core_session *session); -static switch_status channel_on_hangup(switch_core_session *session); -static switch_status channel_on_ring(switch_core_session *session); -static switch_status channel_on_loopback(switch_core_session *session); -static switch_status channel_on_transmit(switch_core_session *session); -static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id); -static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id); -static switch_status channel_kill_channel(switch_core_session *session, int sig); -static switch_status engage_device(struct private_object *tech_pvt); -static int dump_info(void); -static switch_status load_config(void); -static int get_dev_by_name(char *name, int in); -static switch_status place_call(char *dest, char *out, size_t outlen); -static switch_status hup_call(char *callid, char *out, size_t outlen); -static switch_status call_info(char *callid, char *out, size_t outlen); -static switch_status send_dtmf(char *callid, char *out, size_t outlen); -static switch_status answer_call(char *callid, char *out, size_t outlen); + static switch_status channel_on_init(switch_core_session *session); + static switch_status channel_on_hangup(switch_core_session *session); + static switch_status channel_on_ring(switch_core_session *session); + static switch_status channel_on_loopback(switch_core_session *session); + static switch_status channel_on_transmit(switch_core_session *session); + static switch_status channel_outgoing_channel(switch_core_session *session, + switch_caller_profile *outbound_profile, + switch_core_session **new_session); + static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags, int stream_id); + static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags, int stream_id); + static switch_status channel_kill_channel(switch_core_session *session, int sig); + static switch_status engage_device(struct private_object *tech_pvt); + static int dump_info(void); + static switch_status load_config(void); + static int get_dev_by_name(char *name, int in); + static switch_status place_call(char *dest, char *out, size_t outlen); + static switch_status hup_call(char *callid, char *out, size_t outlen); + static switch_status call_info(char *callid, char *out, size_t outlen); + static switch_status send_dtmf(char *callid, char *out, size_t outlen); + static switch_status answer_call(char *callid, char *out, size_t outlen); /* State methods they get called when the state changes to the specific state returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it. */ -static switch_status channel_on_init(switch_core_session *session) + static switch_status channel_on_init(switch_core_session *session) { switch_channel *channel; struct private_object *tech_pvt = NULL; @@ -140,7 +144,7 @@ static switch_status channel_on_init(switch_core_session *session) tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); switch_set_flag(tech_pvt, TFLAG_IO); - + /* Move Channel's State Machine to RING */ switch_channel_set_state(channel, CS_RING); @@ -174,7 +178,7 @@ static switch_status channel_on_execute(switch_core_session *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel)); @@ -223,7 +227,7 @@ static switch_status channel_kill_channel(switch_core_session *session, int sig) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; - + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -236,7 +240,7 @@ static switch_status channel_kill_channel(switch_core_session *session, int sig) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL KILL\n", switch_channel_get_name(channel)); - + return SWITCH_STATUS_SUCCESS; } @@ -264,25 +268,25 @@ static switch_status channel_on_transmit(switch_core_session *session) /* Turn on the device */ engage_device(tech_pvt); - while(switch_channel_get_state(channel) == CS_TRANSMIT && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) { + while (switch_channel_get_state(channel) == CS_TRANSMIT && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) { if (switch_time_now() - last >= waitsec) { - char buf[512]; - switch_event *event; + char buf[512]; + switch_event *event; - snprintf(buf, sizeof(buf), "BRRRRING! BRRRRING! call %s\n", tech_pvt->call_id); + snprintf(buf, sizeof(buf), "BRRRRING! BRRRRING! call %s\n", tech_pvt->call_id); - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_RINGING) == SWITCH_STATUS_SUCCESS) { - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_info", buf); - switch_event_fire(&event); - } + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_RINGING) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_info", buf); + switch_event_fire(&event); + } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s\n", buf); - last = switch_time_now(); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s\n", buf); + last = switch_time_now(); } switch_yield(50000); } - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "CHANNEL TRANSMIT\n"); @@ -293,7 +297,8 @@ static switch_status channel_on_transmit(switch_core_session *session) /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines that allocate memory or you will have 1 channel with memory allocated from another channel's pool! */ -static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session) +static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session) { if ((*new_session = switch_core_session_request(&channel_endpoint_interface, NULL))) { struct private_object *tech_pvt; @@ -301,7 +306,8 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit switch_caller_profile *caller_profile; switch_core_session_add_stream(*new_session, NULL); - if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { + if ((tech_pvt = + (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); channel = switch_core_session_get_channel(*new_session); switch_core_session_set_private(*new_session, tech_pvt); @@ -317,7 +323,9 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; - snprintf(name, sizeof(name), "PortAudio/%s-%04x", caller_profile->destination_number ? caller_profile->destination_number : modname, rand() & 0xffff); + snprintf(name, sizeof(name), "PortAudio/%s-%04x", + caller_profile->destination_number ? caller_profile->destination_number : modname, + rand() & 0xffff); switch_channel_set_name(channel, name); } else { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Doh! no caller profile\n"); @@ -365,10 +373,11 @@ static switch_status channel_send_dtmf(switch_core_session *session, char *dtmf) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "DTMF ON CALL %s [%s]\n", tech_pvt->call_id, dtmf); - return SWITCH_STATUS_SUCCESS; + return SWITCH_STATUS_SUCCESS; } -static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id) +static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -385,10 +394,12 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra return SWITCH_STATUS_FALSE; } - + switch_mutex_lock(globals.device_lock); - if (tech_pvt->audio_in && - (samples = ReadAudioStream(tech_pvt->audio_in, tech_pvt->read_frame.data, tech_pvt->read_codec.implementation->samples_per_frame))) { + if (tech_pvt->audio_in && + (samples = + ReadAudioStream(tech_pvt->audio_in, tech_pvt->read_frame.data, + tech_pvt->read_codec.implementation->samples_per_frame))) { tech_pvt->read_frame.datalen = samples * 2; tech_pvt->read_frame.samples = samples; *frame = &tech_pvt->read_frame; @@ -399,7 +410,8 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra return status; } -static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) +static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -410,19 +422,18 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - if(!switch_test_flag(tech_pvt, TFLAG_IO)) { + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { return SWITCH_STATUS_FALSE; } - //switch_mutex_lock(globals.device_lock); if (tech_pvt->audio_out) { - WriteAudioStream(tech_pvt->audio_out, (short *)frame->data, (int)(frame->datalen / sizeof(SAMPLE))); + WriteAudioStream(tech_pvt->audio_out, (short *) frame->data, (int) (frame->datalen / sizeof(SAMPLE))); status = SWITCH_STATUS_SUCCESS; } //switch_mutex_unlock(globals.device_lock); return status; - + } static switch_status channel_answer_channel(switch_core_session *session) @@ -441,82 +452,83 @@ static switch_status channel_answer_channel(switch_core_session *session) static struct switch_api_interface send_dtmf_interface = { - /*.interface_name*/ "padtmf", - /*.desc*/ "PortAudio Dial DTMF", - /*.function*/ send_dtmf, - /*.next*/ NULL + /*.interface_name */ "padtmf", + /*.desc */ "PortAudio Dial DTMF", + /*.function */ send_dtmf, + /*.next */ NULL }; static struct switch_api_interface answer_call_interface = { - /*.interface_name*/ "paoffhook", - /*.desc*/ "PortAudio Answer Call", - /*.function*/ answer_call, - /*.next*/ &send_dtmf_interface + /*.interface_name */ "paoffhook", + /*.desc */ "PortAudio Answer Call", + /*.function */ answer_call, + /*.next */ &send_dtmf_interface }; static struct switch_api_interface channel_info_interface = { - /*.interface_name*/ "painfo", - /*.desc*/ "PortAudio Call Info", - /*.function*/ call_info, - /*.next*/ &answer_call_interface + /*.interface_name */ "painfo", + /*.desc */ "PortAudio Call Info", + /*.function */ call_info, + /*.next */ &answer_call_interface }; static struct switch_api_interface channel_hup_interface = { - /*.interface_name*/ "pahup", - /*.desc*/ "PortAudio Hangup Call", - /*.function*/ hup_call, - /*.next*/ &channel_info_interface + /*.interface_name */ "pahup", + /*.desc */ "PortAudio Hangup Call", + /*.function */ hup_call, + /*.next */ &channel_info_interface }; static struct switch_api_interface channel_api_interface = { - /*.interface_name*/ "pacall", - /*.desc*/ "PortAudio Call", - /*.function*/ place_call, - /*.next*/ &channel_hup_interface + /*.interface_name */ "pacall", + /*.desc */ "PortAudio Call", + /*.function */ place_call, + /*.next */ &channel_hup_interface }; static const switch_event_handler_table channel_event_handlers = { - /*.on_init*/ channel_on_init, - /*.on_ring*/ channel_on_ring, - /*.on_execute*/ channel_on_execute, - /*.on_hangup*/ channel_on_hangup, - /*.on_loopback*/ channel_on_loopback, - /*.on_transmit*/ channel_on_transmit + /*.on_init */ channel_on_init, + /*.on_ring */ channel_on_ring, + /*.on_execute */ channel_on_execute, + /*.on_hangup */ channel_on_hangup, + /*.on_loopback */ channel_on_loopback, + /*.on_transmit */ channel_on_transmit }; static const switch_io_routines channel_io_routines = { - /*.outgoing_channel*/ channel_outgoing_channel, - /*.answer_channel*/ channel_answer_channel, - /*.read_frame*/ channel_read_frame, - /*.write_frame*/ channel_write_frame, - /*.kill_channel*/ channel_kill_channel, - /*.waitfor_read*/ channel_waitfor_read, - /*.waitfor_write*/ channel_waitfor_write, - /*.send_dtmf*/ channel_send_dtmf + /*.outgoing_channel */ channel_outgoing_channel, + /*.answer_channel */ channel_answer_channel, + /*.read_frame */ channel_read_frame, + /*.write_frame */ channel_write_frame, + /*.kill_channel */ channel_kill_channel, + /*.waitfor_read */ channel_waitfor_read, + /*.waitfor_write */ channel_waitfor_write, + /*.send_dtmf */ channel_send_dtmf }; static const switch_endpoint_interface channel_endpoint_interface = { - /*.interface_name*/ "portaudio", - /*.io_routines*/ &channel_io_routines, - /*.event_handlers*/ &channel_event_handlers, - /*.private*/ NULL, - /*.next*/ NULL + /*.interface_name */ "portaudio", + /*.io_routines */ &channel_io_routines, + /*.event_handlers */ &channel_event_handlers, + /*.private */ NULL, + /*.next */ NULL }; static const switch_loadable_module_interface channel_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ &channel_endpoint_interface, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ NULL, - /*.application_interface*/ NULL, - /*.api_interface*/ &channel_api_interface + /*.module_name */ modname, + /*.endpoint_interface */ &channel_endpoint_interface, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL, + /*.api_interface */ &channel_api_interface }; -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n"); @@ -528,7 +540,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul load_config(); switch_core_hash_init(&globals.call_hash, module_pool); switch_mutex_init(&globals.device_lock, SWITCH_MUTEX_NESTED, module_pool); - + dump_info(); if (switch_event_reserve_subclass(MY_EVENT_RINGING) != SWITCH_STATUS_SUCCESS) { @@ -549,14 +561,14 @@ static switch_status load_config(void) switch_config cfg; char *var, *val; char *cf = "portaudio.conf"; - + memset(&globals, 0, sizeof(globals)); - + if (!switch_config_open_file(&cfg, cf)) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf); return SWITCH_STATUS_TERM; } - + while (switch_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "settings")) { if (!strcmp(var, "debug")) { @@ -571,13 +583,13 @@ static switch_status load_config(void) set_global_cid_num(val); } else if (!strcmp(var, "indev")) { if (*val == '#') { - globals.indev = atoi(val+1); + globals.indev = atoi(val + 1); } else { globals.indev = get_dev_by_name(val, 1); } } else if (!strcmp(var, "outdev")) { if (*val == '#') { - globals.outdev = atoi(val+1); + globals.outdev = atoi(val + 1); } else { globals.outdev = get_dev_by_name(val, 0); } @@ -588,13 +600,13 @@ static switch_status load_config(void) if (!globals.dialplan) { set_global_dialplan("default"); } - + if (!globals.sample_rate) { globals.sample_rate = 8000; } switch_config_close_file(&cfg); - + return SWITCH_STATUS_SUCCESS; } @@ -610,28 +622,28 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void) { - Pa_Terminate(); - + Pa_Terminate(); + return SWITCH_STATUS_SUCCESS; } static int get_dev_by_name(char *name, int in) { - int i; - int numDevices; - const PaDeviceInfo *pdi; - numDevices = Pa_CountDevices(); + int i; + int numDevices; + const PaDeviceInfo *pdi; + numDevices = Pa_CountDevices(); - if( numDevices < 0 ) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices ); - return -2; - } - - for( i=0; iname, name)) { - if(in && pdi->maxInputChannels) { + if (numDevices < 0) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices); + return -2; + } + + for (i = 0; i < numDevices; i++) { + pdi = Pa_GetDeviceInfo(i); + if (strstr(pdi->name, name)) { + if (in && pdi->maxInputChannels) { return i; } else if (!in && pdi->maxOutputChannels) { return i; @@ -644,58 +656,62 @@ static int get_dev_by_name(char *name, int in) static int dump_info(void) { - int i,j; - int numDevices; - const PaDeviceInfo *pdi; - PaError err; - numDevices = Pa_CountDevices(); - if( numDevices < 0 ) - { - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices ); - err = numDevices; - goto error; - } - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Number of devices = %d\n", numDevices ); - for( i=0; iname ); - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Max Inputs = %d", pdi->maxInputChannels ); - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, ", Max Outputs = %d\n", pdi->maxOutputChannels ); - if( pdi->numSampleRates == -1 ) - { - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Sample Rate Range = %f to %f\n", pdi->sampleRates[0], pdi->sampleRates[1] ); - } - else - { - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Sample Rates ="); - for( j=0; jnumSampleRates; j++ ) - { - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " %8.2f,", pdi->sampleRates[j] ); - } - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "\n"); - } - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Native Sample Formats = "); - if( pdi->nativeSampleFormats & paInt8 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt8, "); - if( pdi->nativeSampleFormats & paUInt8 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paUInt8, "); - if( pdi->nativeSampleFormats & paInt16 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt16, "); - if( pdi->nativeSampleFormats & paInt32 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt32, "); - if( pdi->nativeSampleFormats & paFloat32 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paFloat32, "); - if( pdi->nativeSampleFormats & paInt24 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt24, "); - if( pdi->nativeSampleFormats & paPackedInt24 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paPackedInt24, "); - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "\n"); - } - - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "----------------------------------------------\n"); - return 0; -error: - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "An error occured while using the portaudio stream\n" ); - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Error number: %d\n", err ); - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Error message: %s\n", Pa_GetErrorText( err ) ); - return err; + int i, j; + int numDevices; + const PaDeviceInfo *pdi; + PaError err; + numDevices = Pa_CountDevices(); + if (numDevices < 0) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices); + err = numDevices; + goto error; + } + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Number of devices = %d\n", numDevices); + for (i = 0; i < numDevices; i++) { + pdi = Pa_GetDeviceInfo(i); + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "---------------------------------------------- #%d", i); + if (i == Pa_GetDefaultInputDeviceID()) + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " DefaultInput"); + if (i == Pa_GetDefaultOutputDeviceID()) + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " DefaultOutput"); + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "\nName = %s\n", pdi->name); + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Max Inputs = %d", pdi->maxInputChannels); + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, ", Max Outputs = %d\n", pdi->maxOutputChannels); + if (pdi->numSampleRates == -1) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Sample Rate Range = %f to %f\n", pdi->sampleRates[0], + pdi->sampleRates[1]); + } else { + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Sample Rates ="); + for (j = 0; j < pdi->numSampleRates; j++) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " %8.2f,", pdi->sampleRates[j]); + } + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "\n"); + } + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Native Sample Formats = "); + if (pdi->nativeSampleFormats & paInt8) + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt8, "); + if (pdi->nativeSampleFormats & paUInt8) + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paUInt8, "); + if (pdi->nativeSampleFormats & paInt16) + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt16, "); + if (pdi->nativeSampleFormats & paInt32) + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt32, "); + if (pdi->nativeSampleFormats & paFloat32) + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paFloat32, "); + if (pdi->nativeSampleFormats & paInt24) + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt24, "); + if (pdi->nativeSampleFormats & paPackedInt24) + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paPackedInt24, "); + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "\n"); + } + + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "----------------------------------------------\n"); + return 0; + error: + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "An error occured while using the portaudio stream\n"); + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Error number: %d\n", err); + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Error message: %s\n", Pa_GetErrorText(err)); + return err; } static switch_status engage_device(struct private_object *tech_pvt) @@ -713,56 +729,59 @@ static switch_status engage_device(struct private_object *tech_pvt) codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL, - switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); - return SWITCH_STATUS_FALSE; - } else { - if (switch_core_codec_init(&tech_pvt->write_codec, - "L16", - sample_rate, - codec_ms, - 1, - SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE, - NULL, - switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); - switch_core_codec_destroy(&tech_pvt->read_codec); - return SWITCH_STATUS_FALSE; - } - } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Loaded codec L16 %dhz %dms on %s\n", sample_rate, codec_ms, switch_channel_get_name(channel)); - tech_pvt->read_frame.rate = sample_rate; - tech_pvt->read_frame.codec = &tech_pvt->read_codec; - switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec); - switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec); - - tech_pvt->indev = globals.indev; - tech_pvt->outdev = globals.outdev; - - switch_mutex_lock(globals.device_lock); - if ((tech_pvt->err = OpenAudioStream( &tech_pvt->audio_in, sample_rate, SAMPLE_TYPE, PABLIO_READ | PABLIO_MONO, tech_pvt->indev, -1)) == paNoError) { - if ((tech_pvt->err = OpenAudioStream(&tech_pvt->audio_out, sample_rate, SAMPLE_TYPE, PABLIO_WRITE | PABLIO_MONO, -1, tech_pvt->outdev)) != paNoError) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open audio out [%d]!\n", tech_pvt->outdev); - CloseAudioStream(tech_pvt->audio_in); - tech_pvt->audio_in = NULL; - } - } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open audio in [%d]!\n", tech_pvt->indev); - } - switch_mutex_unlock(globals.device_lock); - - if (tech_pvt->err == paNoError) { - snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", globals.call_id++); - switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); - return SWITCH_STATUS_SUCCESS; - } else { - switch_core_codec_destroy(&tech_pvt->read_codec); - switch_core_codec_destroy(&tech_pvt->write_codec); - switch_core_session_destroy(&tech_pvt->session); - } - + NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); return SWITCH_STATUS_FALSE; + } else { + if (switch_core_codec_init(&tech_pvt->write_codec, + "L16", + sample_rate, + codec_ms, + 1, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); + switch_core_codec_destroy(&tech_pvt->read_codec); + return SWITCH_STATUS_FALSE; + } + } + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Loaded codec L16 %dhz %dms on %s\n", sample_rate, codec_ms, + switch_channel_get_name(channel)); + tech_pvt->read_frame.rate = sample_rate; + tech_pvt->read_frame.codec = &tech_pvt->read_codec; + switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec); + switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec); + + tech_pvt->indev = globals.indev; + tech_pvt->outdev = globals.outdev; + + switch_mutex_lock(globals.device_lock); + if ((tech_pvt->err = + OpenAudioStream(&tech_pvt->audio_in, sample_rate, SAMPLE_TYPE, PABLIO_READ | PABLIO_MONO, tech_pvt->indev, + -1)) == paNoError) { + if ((tech_pvt->err = + OpenAudioStream(&tech_pvt->audio_out, sample_rate, SAMPLE_TYPE, PABLIO_WRITE | PABLIO_MONO, -1, + tech_pvt->outdev)) != paNoError) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open audio out [%d]!\n", tech_pvt->outdev); + CloseAudioStream(tech_pvt->audio_in); + tech_pvt->audio_in = NULL; + } + } else { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open audio in [%d]!\n", tech_pvt->indev); + } + switch_mutex_unlock(globals.device_lock); + + if (tech_pvt->err == paNoError) { + snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", globals.call_id++); + switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); + return SWITCH_STATUS_SUCCESS; + } else { + switch_core_codec_destroy(&tech_pvt->read_codec); + switch_core_codec_destroy(&tech_pvt->write_codec); + switch_core_session_destroy(&tech_pvt->session); + } + + return SWITCH_STATUS_FALSE; } static switch_status place_call(char *dest, char *out, size_t outlen) @@ -796,14 +815,12 @@ static switch_status place_call(char *dest, char *out, size_t outlen) if ((tech_pvt->caller_profile = switch_caller_profile_new(session, globals.dialplan, globals.cid_name, - globals.cid_num, - NULL, - NULL, - NULL, - dest))) { + globals.cid_num, NULL, NULL, NULL, dest))) { char name[128]; switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); - snprintf(name, sizeof(name), "PortAudio/%s-%04x", tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : modname, rand() & 0xffff); + snprintf(name, sizeof(name), "PortAudio/%s-%04x", + tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile-> + destination_number : modname, rand() & 0xffff); switch_channel_set_name(channel, name); } tech_pvt->session = session; @@ -812,7 +829,7 @@ static switch_status place_call(char *dest, char *out, size_t outlen) switch_core_session_thread_launch(tech_pvt->session); snprintf(out, outlen, "SUCCESS: %s", tech_pvt->call_id); } - } + } return status; } @@ -828,7 +845,7 @@ static switch_status hup_call(char *callid, char *out, size_t outlen) callid = tmp; } if (!callid || !strcasecmp(callid, "all")) { - switch_hash_index_t* hi; + switch_hash_index_t *hi; void *val; int i = 0; @@ -845,7 +862,7 @@ static switch_status hup_call(char *callid, char *out, size_t outlen) return SWITCH_STATUS_SUCCESS; } - + if ((tech_pvt = switch_core_hash_find(globals.call_hash, callid))) { channel = switch_core_session_get_channel(tech_pvt->session); @@ -909,7 +926,7 @@ static void print_info(struct private_object *tech_pvt, char *out, size_t outlen assert(channel != NULL); snprintf(out, outlen, "CALL %s\t%s\t%s\t%s\t%s\n", - tech_pvt->call_id, + tech_pvt->call_id, tech_pvt->caller_profile->caller_id_name ? tech_pvt->caller_profile->caller_id_name : "n/a", tech_pvt->caller_profile->caller_id_number ? tech_pvt->caller_profile->caller_id_number : "n/a", tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : "n/a", @@ -920,19 +937,19 @@ static void print_info(struct private_object *tech_pvt, char *out, size_t outlen static switch_status call_info(char *callid, char *out, size_t outlen) { struct private_object *tech_pvt; - switch_hash_index_t* hi; + switch_hash_index_t *hi; void *val; if (!callid || !strcasecmp(callid, "all")) { for (hi = apr_hash_first(module_pool, globals.call_hash); hi; hi = switch_hash_next(hi)) { switch_hash_this(hi, NULL, NULL, &val); tech_pvt = val; - print_info(tech_pvt, out + strlen(out), outlen - strlen(out)); + print_info(tech_pvt, out + strlen(out), outlen - strlen(out)); } } else if ((tech_pvt = switch_core_hash_find(globals.call_hash, callid))) { print_info(tech_pvt, out, outlen); } else { strncpy(out, "NO SUCH CALL", outlen - 1); } - + return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/endpoints/mod_portaudio/pablio.c b/src/mod/endpoints/mod_portaudio/pablio.c index b5735daea0..b393aeacf1 100644 --- a/src/mod/endpoints/mod_portaudio/pablio.c +++ b/src/mod/endpoints/mod_portaudio/pablio.c @@ -32,12 +32,12 @@ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - */ - + */ + /* History: * PLB021214 - check for valid stream in CloseAudioStream() to prevent hang. * add timeOutMSec to CloseAudioStream() to prevent hang. - */ + */ #include #include #include @@ -45,146 +45,155 @@ #include "ringbuffer.h" #include "pablio.h" #include - -/************************************************************************/ -/******** Constants *****************************************************/ -/************************************************************************/ - + +/************************************************************************/ +/******** Constants *****************************************************/ +/************************************************************************/ + #define FRAMES_PER_BUFFER (256) - -/************************************************************************/ -/******** Prototypes ****************************************************/ -/************************************************************************/ - -static int blockingIOCallback( void *inputBuffer, void *outputBuffer, - unsigned long framesPerBuffer, - PaTimestamp outTime, void *userData ); -static PaError PABLIO_InitFIFO( RingBuffer *rbuf, long numFrames, long bytesPerFrame ); -static PaError PABLIO_TermFIFO( RingBuffer *rbuf ); - -/************************************************************************/ -/******** Functions *****************************************************/ -/************************************************************************/ - + +/************************************************************************/ +/******** Prototypes ****************************************************/ +/************************************************************************/ + static int blockingIOCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData); + static PaError PABLIO_InitFIFO(RingBuffer * rbuf, long numFrames, long bytesPerFrame); + static PaError PABLIO_TermFIFO(RingBuffer * rbuf); + +/************************************************************************/ +/******** Functions *****************************************************/ +/************************************************************************/ + /* Called from PortAudio. * Read and write data only if there is room in FIFOs. - */ -static int blockingIOCallback( void *inputBuffer, void *outputBuffer, - unsigned long framesPerBuffer, - PaTimestamp outTime, void *userData ) -{ - PABLIO_Stream *data = (PABLIO_Stream*)userData; - long numBytes = data->bytesPerFrame * framesPerBuffer; - (void) outTime; - - /* This may get called with NULL inputBuffer during initial setup. */ - if( inputBuffer != NULL ) - { - RingBuffer_Write( &data->inFIFO, inputBuffer, numBytes ); - } - if( outputBuffer != NULL ) - { - int i; - int numRead = RingBuffer_Read( &data->outFIFO, outputBuffer, numBytes ); - /* Zero out remainder of buffer if we run out of data. */ - for( i=numRead; ibuffer ) free( rbuf->buffer ); - rbuf->buffer = NULL; - return paNoError; -} - + */ +static int blockingIOCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData) +{ + PABLIO_Stream * data = (PABLIO_Stream *) userData; + long numBytes = data->bytesPerFrame * framesPerBuffer; + (void) outTime; + + /* This may get called with NULL inputBuffer during initial setup. */ + if (inputBuffer != NULL) + { + RingBuffer_Write(&data->inFIFO, inputBuffer, numBytes); + } + if (outputBuffer != NULL) + { + int i; + int numRead = RingBuffer_Read(&data->outFIFO, outputBuffer, numBytes); + + /* Zero out remainder of buffer if we run out of data. */ + for (i = numRead; i < numBytes; i++) + { + ((char *) outputBuffer)[i] = 0; + } } + return 0; + } + + +/* Allocate buffer. */ +static PaError PABLIO_InitFIFO(RingBuffer * rbuf, long numFrames, long bytesPerFrame) +{ + long numBytes = numFrames * bytesPerFrame; + char *buffer = (char *) malloc(numBytes); + if (buffer == NULL) + return paInsufficientMemory; + memset(buffer, 0, numBytes); + return (PaError) RingBuffer_Init(rbuf, numBytes, buffer); + } + + +/* Free buffer. */ +static PaError PABLIO_TermFIFO(RingBuffer * rbuf) +{ + if (rbuf->buffer) + free(rbuf->buffer); + rbuf->buffer = NULL; + return paNoError; + } + + /************************************************************ * Write data to ring buffer. * Will not return until all the data has been written. - */ -long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames ) -{ - long bytesWritten; - char *p = (char *) data; - long numBytes = aStream->bytesPerFrame * numFrames; - while( numBytes > 0) - { - bytesWritten = RingBuffer_Write( &aStream->outFIFO, p, numBytes ); - numBytes -= bytesWritten; - p += bytesWritten; - if( numBytes > 0) Pa_Sleep(10); - } - return numFrames; -} - + */ +long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames) +{ + long bytesWritten; + char *p = (char *) data; + long numBytes = aStream->bytesPerFrame * numFrames; + while (numBytes > 0) + { + bytesWritten = RingBuffer_Write(&aStream->outFIFO, p, numBytes); + numBytes -= bytesWritten; + p += bytesWritten; + if (numBytes > 0) + Pa_Sleep(10); + } + return numFrames; + } + + /************************************************************ * Read data from ring buffer. * Will not return until all the data has been read. - */ -long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames ) -{ - long bytesRead; - char *p = (char *) data; - long numBytes = aStream->bytesPerFrame * numFrames; - while( numBytes > 0) - { - bytesRead = RingBuffer_Read( &aStream->inFIFO, p, numBytes ); - numBytes -= bytesRead; - p += bytesRead; - if( numBytes > 0) Pa_Sleep(10); - } - return numFrames; -} - + */ +long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames) +{ + long bytesRead; + char *p = (char *) data; + long numBytes = aStream->bytesPerFrame * numFrames; + while (numBytes > 0) + { + bytesRead = RingBuffer_Read(&aStream->inFIFO, p, numBytes); + numBytes -= bytesRead; + p += bytesRead; + if (numBytes > 0) + Pa_Sleep(10); + } + return numFrames; + } + + /************************************************************ * Return the number of frames that could be written to the stream without * having to wait. - */ -long GetAudioStreamWriteable( PABLIO_Stream *aStream ) -{ - int bytesEmpty = RingBuffer_GetWriteAvailable( &aStream->outFIFO ); - return bytesEmpty / aStream->bytesPerFrame; -} - + */ +long GetAudioStreamWriteable(PABLIO_Stream * aStream) +{ + int bytesEmpty = RingBuffer_GetWriteAvailable(&aStream->outFIFO); + return bytesEmpty / aStream->bytesPerFrame; + } + + /************************************************************ * Return the number of frames that are available to be read from the * stream without having to wait. - */ -long GetAudioStreamReadable( PABLIO_Stream *aStream ) -{ - int bytesFull = RingBuffer_GetReadAvailable( &aStream->inFIFO ); - return bytesFull / aStream->bytesPerFrame; -} - -/************************************************************/ -static unsigned long RoundUpToNextPowerOf2( unsigned long n ) -{ - long numBits = 0; - if( ((n-1) & n) == 0) return n; /* Already Power of two. */ - while( n > 0 ) - { - n= n>>1; - numBits++; - } - return (1<inFIFO); + return bytesFull / aStream->bytesPerFrame; + } + + +/************************************************************/ +static unsigned long RoundUpToNextPowerOf2(unsigned long n) +{ + long numBits = 0; + if (((n - 1) & n) == 0) + return n; /* Already Power of two. */ + while (n > 0) + { + n = n >> 1; + numBits++; + } + return (1 << numBits); + } + + /************************************************************ * Opens a PortAudio stream with default characteristics. * Allocates PABLIO_Stream structure. @@ -192,136 +201,133 @@ static unsigned long RoundUpToNextPowerOf2( unsigned long n ) * flags parameter can be an ORed combination of: * PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE, * and either PABLIO_MONO or PABLIO_STEREO - */ -PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate, - PaSampleFormat format, long flags, int indev, int outdev ) -{ - long bytesPerSample; - long doRead = 0; - long doWrite = 0; - PaError err; - PABLIO_Stream *aStream; - long minNumBuffers; - long numFrames; + */ + PaError OpenAudioStream(PABLIO_Stream ** rwblPtr, double sampleRate, PaSampleFormat format, long flags, int indev, + int outdev) +{ + long bytesPerSample; + long doRead = 0; + long doWrite = 0; + PaError err; + PABLIO_Stream * aStream; + long minNumBuffers; + long numFrames; + + /* Allocate PABLIO_Stream structure for caller. */ + aStream = (PABLIO_Stream *) malloc(sizeof(PABLIO_Stream)); + if (aStream == NULL) + return paInsufficientMemory; + memset(aStream, 0, sizeof(PABLIO_Stream)); + + /* Determine size of a sample. */ + bytesPerSample = Pa_GetSampleSize(format); + if (bytesPerSample < 0) + { + err = (PaError) bytesPerSample; + goto error; + } + aStream->samplesPerFrame = ((flags & PABLIO_MONO) != 0) ? 1 : 2; + aStream->bytesPerFrame = bytesPerSample * aStream->samplesPerFrame; + + /* Initialize PortAudio */ + err = Pa_Initialize(); + if (err != paNoError) + goto error; + + /* Warning: numFrames must be larger than amount of data processed per interrupt + * inside PA to prevent glitches. Just to be safe, adjust size upwards. + */ + minNumBuffers = 2 * Pa_GetMinNumBuffers(FRAMES_PER_BUFFER, sampleRate); + numFrames = minNumBuffers * FRAMES_PER_BUFFER; + + /* The PortAudio callback runs in a high priority thread. But PABLIO + * runs in a normal foreground thread. So we may have much worse + * latency in PABLIO. So adjust latency to a safe level. + */ + { + const int safeLatencyMSec = 200; + int minLatencyMSec = (int) ((1000 * numFrames) / sampleRate); + if (minLatencyMSec < safeLatencyMSec) + { + numFrames = (int) ((safeLatencyMSec * sampleRate) / 1000); + } + } numFrames = RoundUpToNextPowerOf2(numFrames); + + /* Initialize Ring Buffers */ + doRead = ((flags & PABLIO_READ) != 0); + doWrite = ((flags & PABLIO_WRITE) != 0); + if (doRead) + { + err = PABLIO_InitFIFO(&aStream->inFIFO, numFrames, aStream->bytesPerFrame); + if (err != paNoError) + goto error; + } + if (doWrite) + { + long numBytes; + err = PABLIO_InitFIFO(&aStream->outFIFO, numFrames, aStream->bytesPerFrame); + if (err != paNoError) + goto error; + + /* Make Write FIFO appear full initially. */ + numBytes = RingBuffer_GetWriteAvailable(&aStream->outFIFO); + RingBuffer_AdvanceWriteIndex(&aStream->outFIFO, numBytes); + } + + /* Open a PortAudio stream that we will use to communicate with the underlying + * audio drivers. */ + err = Pa_OpenStream( &aStream->stream, + (doRead ? (indev > -1) ? indev : Pa_GetDefaultInputDeviceID() : paNoDevice), + (doRead ? aStream->samplesPerFrame : 0), format, NULL, + (doWrite ? (outdev > -1) ? outdev : Pa_GetDefaultOutputDeviceID() : paNoDevice), + (doWrite ? aStream->samplesPerFrame : 0), format, NULL, sampleRate, FRAMES_PER_BUFFER, + minNumBuffers, paClipOff, + /* we won't output out of range samples so don't bother clipping them */ + blockingIOCallback, aStream); + if (err != paNoError) + goto error; + err = Pa_StartStream(aStream->stream); + if (err != paNoError) + goto error; + *rwblPtr = aStream; + return paNoError; + error: CloseAudioStream(aStream); + *rwblPtr = NULL; + return err; + } + + +/************************************************************/ + PaError CloseAudioStream(PABLIO_Stream * aStream) +{ + PaError err = paNoError; + int bytesEmpty; + int byteSize = aStream->outFIFO.bufferSize; + if (aStream->stream != NULL) /* Make sure stream was opened. PLB021214 */ + { + + /* If we are writing data, make sure we play everything written. */ + if (byteSize > 0) + { + int timeOutMSec = 2000; + bytesEmpty = RingBuffer_GetWriteAvailable(&aStream->outFIFO); + while ((bytesEmpty < byteSize) && (timeOutMSec > 0)) + { + Pa_Sleep(20); + timeOutMSec -= 20; + bytesEmpty = RingBuffer_GetWriteAvailable(&aStream->outFIFO); + } + } + err = Pa_StopStream(aStream->stream); + if (err != paNoError) + goto error; + err = Pa_CloseStream(aStream->stream); + } + error: Pa_Terminate(); + PABLIO_TermFIFO(&aStream->inFIFO); + PABLIO_TermFIFO(&aStream->outFIFO); + free(aStream); + return err; + } + - /* Allocate PABLIO_Stream structure for caller. */ - aStream = (PABLIO_Stream *) malloc( sizeof(PABLIO_Stream) ); - if( aStream == NULL ) return paInsufficientMemory; - memset( aStream, 0, sizeof(PABLIO_Stream) ); - - /* Determine size of a sample. */ - bytesPerSample = Pa_GetSampleSize( format ); - if( bytesPerSample < 0 ) - { - err = (PaError) bytesPerSample; - goto error; - } - aStream->samplesPerFrame = ((flags&PABLIO_MONO) != 0) ? 1 : 2; - aStream->bytesPerFrame = bytesPerSample * aStream->samplesPerFrame; - - /* Initialize PortAudio */ - err = Pa_Initialize(); - if( err != paNoError ) goto error; - - /* Warning: numFrames must be larger than amount of data processed per interrupt - * inside PA to prevent glitches. Just to be safe, adjust size upwards. - */ - minNumBuffers = 2 * Pa_GetMinNumBuffers( FRAMES_PER_BUFFER, sampleRate ); - numFrames = minNumBuffers * FRAMES_PER_BUFFER; - /* The PortAudio callback runs in a high priority thread. But PABLIO - * runs in a normal foreground thread. So we may have much worse - * latency in PABLIO. So adjust latency to a safe level. - */ - { - const int safeLatencyMSec = 200; - int minLatencyMSec = (int) ((1000 * numFrames) / sampleRate); - if( minLatencyMSec < safeLatencyMSec ) - { - numFrames = (int) ((safeLatencyMSec * sampleRate) / 1000); - } - } - numFrames = RoundUpToNextPowerOf2( numFrames ); - - /* Initialize Ring Buffers */ - doRead = ((flags & PABLIO_READ) != 0); - doWrite = ((flags & PABLIO_WRITE) != 0); - if(doRead) - { - err = PABLIO_InitFIFO( &aStream->inFIFO, numFrames, aStream->bytesPerFrame ); - if( err != paNoError ) goto error; - } - if(doWrite) - { - long numBytes; - err = PABLIO_InitFIFO( &aStream->outFIFO, numFrames, aStream->bytesPerFrame ); - if( err != paNoError ) goto error; - /* Make Write FIFO appear full initially. */ - numBytes = RingBuffer_GetWriteAvailable( &aStream->outFIFO ); - RingBuffer_AdvanceWriteIndex( &aStream->outFIFO, numBytes ); - } - - /* Open a PortAudio stream that we will use to communicate with the underlying - * audio drivers. */ - err = Pa_OpenStream( - &aStream->stream, - (doRead ? (indev > -1) ? indev : Pa_GetDefaultInputDeviceID() : paNoDevice), - (doRead ? aStream->samplesPerFrame : 0 ), - format, - NULL, - (doWrite ? (outdev > -1) ? outdev : Pa_GetDefaultOutputDeviceID() : paNoDevice), - (doWrite ? aStream->samplesPerFrame : 0 ), - format, - NULL, - sampleRate, - FRAMES_PER_BUFFER, - minNumBuffers, - paClipOff, /* we won't output out of range samples so don't bother clipping them */ - blockingIOCallback, - aStream ); - if( err != paNoError ) goto error; - - err = Pa_StartStream( aStream->stream ); - if( err != paNoError ) goto error; - - *rwblPtr = aStream; - return paNoError; - -error: - CloseAudioStream( aStream ); - *rwblPtr = NULL; - return err; -} - -/************************************************************/ -PaError CloseAudioStream( PABLIO_Stream *aStream ) -{ - PaError err = paNoError; - int bytesEmpty; - int byteSize = aStream->outFIFO.bufferSize; - - if( aStream->stream != NULL ) /* Make sure stream was opened. PLB021214 */ - { - /* If we are writing data, make sure we play everything written. */ - if( byteSize > 0 ) - { - int timeOutMSec = 2000; - bytesEmpty = RingBuffer_GetWriteAvailable( &aStream->outFIFO ); - while( (bytesEmpty < byteSize) && (timeOutMSec > 0) ) - { - Pa_Sleep( 20 ); - timeOutMSec -= 20; - bytesEmpty = RingBuffer_GetWriteAvailable( &aStream->outFIFO ); - } - } - err = Pa_StopStream( aStream->stream ); - if( err != paNoError ) goto error; - err = Pa_CloseStream( aStream->stream ); - } - -error: - Pa_Terminate(); - PABLIO_TermFIFO( &aStream->inFIFO ); - PABLIO_TermFIFO( &aStream->outFIFO ); - free( aStream ); - return err; -} diff --git a/src/mod/endpoints/mod_portaudio/ringbuffer.c b/src/mod/endpoints/mod_portaudio/ringbuffer.c index 867b501965..fc9b495d17 100644 --- a/src/mod/endpoints/mod_portaudio/ringbuffer.c +++ b/src/mod/endpoints/mod_portaudio/ringbuffer.c @@ -32,168 +32,188 @@ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - */ + */ #include #include #include #include "ringbuffer.h" #include - + /*************************************************************************** * Initialize FIFO. * numBytes must be power of 2, returns -1 if not. - */ -long RingBuffer_Init( RingBuffer *rbuf, long numBytes, void *dataPtr ) -{ - if( ((numBytes-1) & numBytes) != 0) return -1; /* Not Power of two. */ - rbuf->bufferSize = numBytes; - rbuf->buffer = (char *)dataPtr; - RingBuffer_Flush( rbuf ); - rbuf->bigMask = (numBytes*2)-1; - rbuf->smallMask = (numBytes)-1; - return 0; -} -/*************************************************************************** -** Return number of bytes available for reading. */ -long RingBuffer_GetReadAvailable( RingBuffer *rbuf ) -{ - return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask ); -} -/*************************************************************************** -** Return number of bytes available for writing. */ -long RingBuffer_GetWriteAvailable( RingBuffer *rbuf ) -{ - return ( rbuf->bufferSize - RingBuffer_GetReadAvailable(rbuf)); -} + */ +long RingBuffer_Init(RingBuffer * rbuf, long numBytes, void *dataPtr) +{ + if (((numBytes - 1) & numBytes) != 0) + return -1; /* Not Power of two. */ + rbuf->bufferSize = numBytes; + rbuf->buffer = (char *) dataPtr; + RingBuffer_Flush(rbuf); + rbuf->bigMask = (numBytes * 2) - 1; + rbuf->smallMask = (numBytes) - 1; + return 0; + } + /*************************************************************************** -** Clear buffer. Should only be called when buffer is NOT being read. */ -void RingBuffer_Flush( RingBuffer *rbuf ) -{ - rbuf->writeIndex = rbuf->readIndex = 0; -} +** Return number of bytes available for reading. */ +long RingBuffer_GetReadAvailable(RingBuffer * rbuf) +{ + return ((rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask); + } + +/*************************************************************************** +** Return number of bytes available for writing. */ +long RingBuffer_GetWriteAvailable(RingBuffer * rbuf) +{ + return (rbuf->bufferSize - RingBuffer_GetReadAvailable(rbuf)); + } + + +/*************************************************************************** +** Clear buffer. Should only be called when buffer is NOT being read. */ +void RingBuffer_Flush(RingBuffer * rbuf) +{ + rbuf->writeIndex = rbuf->readIndex = 0; + } + /*************************************************************************** ** Get address of region(s) to which we can write data. ** If the region is contiguous, size2 will be zero. ** If non-contiguous, size2 will be the size of second region. ** Returns room available to be written or numBytes, whichever is smaller. -*/ -long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes, - void **dataPtr1, long *sizePtr1, - void **dataPtr2, long *sizePtr2 ) -{ - long index; - long available = RingBuffer_GetWriteAvailable( rbuf ); - if( numBytes > available ) numBytes = available; - /* Check to see if write is not contiguous. */ - index = rbuf->writeIndex & rbuf->smallMask; - if( (index + numBytes) > rbuf->bufferSize ) - { - /* Write data in two blocks that wrap the buffer. */ - long firstHalf = rbuf->bufferSize - index; - *dataPtr1 = &rbuf->buffer[index]; - *sizePtr1 = firstHalf; - *dataPtr2 = &rbuf->buffer[0]; - *sizePtr2 = numBytes - firstHalf; - } - else - { - *dataPtr1 = &rbuf->buffer[index]; - *sizePtr1 = numBytes; - *dataPtr2 = NULL; - *sizePtr2 = 0; - } - return numBytes; -} - - +*/ +long RingBuffer_GetWriteRegions(RingBuffer * rbuf, long numBytes, void **dataPtr1, long *sizePtr1, void **dataPtr2, + long *sizePtr2) +{ + long index; + long available = RingBuffer_GetWriteAvailable(rbuf); + if (numBytes > available) + numBytes = available; + + /* Check to see if write is not contiguous. */ + index = rbuf->writeIndex & rbuf->smallMask; + if ((index + numBytes) > rbuf->bufferSize) + { + + /* Write data in two blocks that wrap the buffer. */ + long firstHalf = rbuf->bufferSize - index; + *dataPtr1 = &rbuf->buffer[index]; + *sizePtr1 = firstHalf; + *dataPtr2 = &rbuf->buffer[0]; + *sizePtr2 = numBytes - firstHalf; + } + + else + { + *dataPtr1 = &rbuf->buffer[index]; + *sizePtr1 = numBytes; + *dataPtr2 = NULL; + *sizePtr2 = 0; + } + return numBytes; + } + + /*************************************************************************** -*/ -long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes ) -{ - return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask; -} - +*/ +long RingBuffer_AdvanceWriteIndex(RingBuffer * rbuf, long numBytes) +{ + return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask; + } + + /*************************************************************************** ** Get address of region(s) from which we can read data. ** If the region is contiguous, size2 will be zero. ** If non-contiguous, size2 will be the size of second region. ** Returns room available to be written or numBytes, whichever is smaller. -*/ -long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes, - void **dataPtr1, long *sizePtr1, - void **dataPtr2, long *sizePtr2 ) -{ - long index; - long available = RingBuffer_GetReadAvailable( rbuf ); - if( numBytes > available ) numBytes = available; - /* Check to see if read is not contiguous. */ - index = rbuf->readIndex & rbuf->smallMask; - if( (index + numBytes) > rbuf->bufferSize ) - { - /* Write data in two blocks that wrap the buffer. */ - long firstHalf = rbuf->bufferSize - index; - *dataPtr1 = &rbuf->buffer[index]; - *sizePtr1 = firstHalf; - *dataPtr2 = &rbuf->buffer[0]; - *sizePtr2 = numBytes - firstHalf; - } - else - { - *dataPtr1 = &rbuf->buffer[index]; - *sizePtr1 = numBytes; - *dataPtr2 = NULL; - *sizePtr2 = 0; - } - return numBytes; -} -/*************************************************************************** -*/ -long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes ) -{ - return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask; -} +*/ +long RingBuffer_GetReadRegions(RingBuffer * rbuf, long numBytes, void **dataPtr1, long *sizePtr1, void **dataPtr2, + long *sizePtr2) +{ + long index; + long available = RingBuffer_GetReadAvailable(rbuf); + if (numBytes > available) + numBytes = available; + + /* Check to see if read is not contiguous. */ + index = rbuf->readIndex & rbuf->smallMask; + if ((index + numBytes) > rbuf->bufferSize) + { + + /* Write data in two blocks that wrap the buffer. */ + long firstHalf = rbuf->bufferSize - index; + *dataPtr1 = &rbuf->buffer[index]; + *sizePtr1 = firstHalf; + *dataPtr2 = &rbuf->buffer[0]; + *sizePtr2 = numBytes - firstHalf; + } + + else + { + *dataPtr1 = &rbuf->buffer[index]; + *sizePtr1 = numBytes; + *dataPtr2 = NULL; + *sizePtr2 = 0; + } + return numBytes; + } + /*************************************************************************** -** Return bytes written. */ -long RingBuffer_Write( RingBuffer *rbuf, void *data, long numBytes ) -{ - long size1, size2, numWritten; - void *data1, *data2; - numWritten = RingBuffer_GetWriteRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 ); - if( size2 > 0 ) - { - - memcpy( data1, data, size1 ); - data = ((char *)data) + size1; - memcpy( data2, data, size2 ); - } - else - { - memcpy( data1, data, size1 ); - } - RingBuffer_AdvanceWriteIndex( rbuf, numWritten ); - return numWritten; -} - +*/ +long RingBuffer_AdvanceReadIndex(RingBuffer * rbuf, long numBytes) +{ + return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask; + } + + /*************************************************************************** -** Return bytes read. */ -long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes ) -{ - long size1, size2, numRead; - void *data1, *data2; - numRead = RingBuffer_GetReadRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 ); - if( size2 > 0 ) - { - memcpy( data, data1, size1 ); - data = ((char *)data) + size1; - memcpy( data, data2, size2 ); - } - else - { - memcpy( data, data1, size1 ); - } - RingBuffer_AdvanceReadIndex( rbuf, numRead ); - return numRead; -} +** Return bytes written. */ +long RingBuffer_Write(RingBuffer * rbuf, void *data, long numBytes) +{ + long size1, size2, numWritten; + void *data1, *data2; + numWritten = RingBuffer_GetWriteRegions(rbuf, numBytes, &data1, &size1, &data2, &size2); + if (size2 > 0) + { + memcpy(data1, data, size1); + data = ((char *) data) + size1; + memcpy(data2, data, size2); + } + + else + { + memcpy(data1, data, size1); + } + RingBuffer_AdvanceWriteIndex(rbuf, numWritten); + return numWritten; + } + + +/*************************************************************************** +** Return bytes read. */ +long RingBuffer_Read(RingBuffer * rbuf, void *data, long numBytes) +{ + long size1, size2, numRead; + void *data1, *data2; + numRead = RingBuffer_GetReadRegions(rbuf, numBytes, &data1, &size1, &data2, &size2); + if (size2 > 0) + { + memcpy(data, data1, size1); + data = ((char *) data) + size1; + memcpy(data, data2, size2); + } + + else + { + memcpy(data, data1, size1); + } + RingBuffer_AdvanceReadIndex(rbuf, numRead); + return numRead; + } + + diff --git a/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c b/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c index a15784c407..7766e43506 100644 --- a/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c +++ b/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c @@ -86,8 +86,8 @@ static struct { struct private_object { - unsigned int flags; /* FLAGS */ - struct switch_frame frame; /* Frame for Writing */ + unsigned int flags; /* FLAGS */ + struct switch_frame frame; /* Frame for Writing */ unsigned char databuf[SWITCH_RECCOMMENDED_BUFFER_SIZE]; struct sangoma_pri *spri; pri_event ring_event; @@ -110,7 +110,7 @@ static void set_global_dialplan(char *dialplan) free(globals.dialplan); globals.dialplan = NULL; } - + globals.dialplan = strdup(dialplan); } @@ -153,15 +153,18 @@ static switch_status wanpipe_on_init(switch_core_session *session); static switch_status wanpipe_on_hangup(switch_core_session *session); static switch_status wanpipe_on_loopback(switch_core_session *session); static switch_status wanpipe_on_transmit(switch_core_session *session); -static switch_status wanpipe_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status wanpipe_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id); -static switch_status wanpipe_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id); -static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event); -static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event); -static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event); +static switch_status wanpipe_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session); +static switch_status wanpipe_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags, int stream_id); +static switch_status wanpipe_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags, int stream_id); +static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event); +static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event); +static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event); static int check_flags(struct sangoma_pri *spri); -static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event); -static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event); +static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event); +static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event); static void *pri_thread_run(switch_thread *thread, void *obj); static int config_wanpipe(int reload); @@ -184,10 +187,10 @@ static switch_status wanpipe_on_init(switch_core_session *session) assert(tech_pvt != NULL); tech_pvt->frame.data = tech_pvt->databuf; - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WANPIPE INIT\n"); - + /* Move Channel's State Machine to RING */ switch_channel_set_state(channel, CS_RING); return SWITCH_STATUS_SUCCESS; @@ -221,10 +224,14 @@ static switch_status wanpipe_on_hangup(switch_core_session *session) assert(tech_pvt != NULL); switch_socket_close(&tech_pvt->socket); - - pri_hangup(tech_pvt->spri->pri, tech_pvt->hangup_event.hangup.call ? tech_pvt->hangup_event.hangup.call : tech_pvt->ring_event.ring.call, tech_pvt->cause); - pri_destroycall(tech_pvt->spri->pri, tech_pvt->hangup_event.hangup.call ? tech_pvt->hangup_event.hangup.call : tech_pvt->ring_event.ring.call); - + + pri_hangup(tech_pvt->spri->pri, + tech_pvt->hangup_event.hangup.call ? tech_pvt->hangup_event.hangup.call : tech_pvt->ring_event.ring.call, + tech_pvt->cause); + pri_destroycall(tech_pvt->spri->pri, + tech_pvt->hangup_event.hangup.call ? tech_pvt->hangup_event.hangup.call : tech_pvt->ring_event.ring. + call); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WANPIPE HANGUP\n"); return SWITCH_STATUS_SUCCESS; } @@ -241,7 +248,8 @@ static switch_status wanpipe_on_transmit(switch_core_session *session) return SWITCH_STATUS_SUCCESS; } -static switch_status wanpipe_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session) +static switch_status wanpipe_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NOT IMPLEMENTED\n"); @@ -252,7 +260,7 @@ static switch_status wanpipe_answer_channel(switch_core_session *session) { struct private_object *tech_pvt; switch_channel *channel = NULL; - + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -260,13 +268,14 @@ static switch_status wanpipe_answer_channel(switch_core_session *session) assert(tech_pvt != NULL); pri_answer(tech_pvt->spri->pri, tech_pvt->ring_event.ring.call, 0, 1); - + return SWITCH_STATUS_SUCCESS; } -static switch_status wanpipe_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id) +static switch_status wanpipe_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags, int stream_id) { struct private_object *tech_pvt; switch_channel *channel = NULL; @@ -278,25 +287,22 @@ static switch_status wanpipe_read_frame(switch_core_session *session, switch_fra tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - + bp = tech_pvt->databuf; *frame = NULL; memset(tech_pvt->databuf, 0, sizeof(tech_pvt->databuf)); while (bytes < globals.bytes_per_frame) { - if ((res = switch_socket_waitfor(tech_pvt->socket, timeout, POLLIN|POLLERR)) < 0) { + if ((res = switch_socket_waitfor(tech_pvt->socket, timeout, POLLIN | POLLERR)) < 0) { return SWITCH_STATUS_GENERR; } else if (res == 0) { tech_pvt->frame.datalen = 0; return SWITCH_STATUS_SUCCESS; } - if ((res = sangoma_readmsg_socket( - tech_pvt->socket, + if ((res = sangoma_readmsg_socket(tech_pvt->socket, &tech_pvt->hdrframe, - sizeof(tech_pvt->hdrframe), - bp, - sizeof(tech_pvt->databuf) - bytes, 0)) < 0) { + sizeof(tech_pvt->hdrframe), bp, sizeof(tech_pvt->databuf) - bytes, 0)) < 0) { if (errno == EBUSY) { continue; } else { @@ -306,13 +312,14 @@ static switch_status wanpipe_read_frame(switch_core_session *session, switch_fra bytes += res; bp += bytes; } - tech_pvt->frame.datalen = bytes; - + tech_pvt->frame.datalen = bytes; + *frame = &tech_pvt->frame; return SWITCH_STATUS_SUCCESS; } -static switch_status wanpipe_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) +static switch_status wanpipe_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags, int stream_id) { struct private_object *tech_pvt; switch_channel *channel = NULL; @@ -329,14 +336,12 @@ static switch_status wanpipe_write_frame(switch_core_session *session, switch_fr while (bytes > 0) { switch_socket_waitfor(tech_pvt->socket, -1, POLLOUT | POLLERR | POLLHUP); - res = sangoma_sendmsg_socket( - tech_pvt->socket, - &tech_pvt->hdrframe, - sizeof(tech_pvt->hdrframe), - bp, - PACKET_LEN, 0); + res = sangoma_sendmsg_socket(tech_pvt->socket, + &tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), bp, PACKET_LEN, 0); if (res < 0) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bad Write frame len %d write %d bytes returned %d errno %d!\n", frame->datalen, PACKET_LEN, res, errno); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, + "Bad Write frame len %d write %d bytes returned %d errno %d!\n", frame->datalen, + PACKET_LEN, res, errno); if (errno == EBUSY) { continue; } @@ -352,47 +357,48 @@ static switch_status wanpipe_write_frame(switch_core_session *session, switch_fr return status; } -static const switch_io_routines wanpipe_io_routines*/ { - /*.outgoing_channel*/ wanpipe_outgoing_channel, - /*.answer_channel*/ wanpipe_answer_channel, - /*.read_frame*/ wanpipe_read_frame, - /*.write_frame*/ wanpipe_write_frame +static const switch_io_routines wanpipe_io_routines */ { + /*.outgoing_channel */ wanpipe_outgoing_channel, + /*.answer_channel */ wanpipe_answer_channel, + /*.read_frame */ wanpipe_read_frame, + /*.write_frame */ wanpipe_write_frame }; -static const switch_event_handler_table wanpipe_event_handlers = { - /*.on_init*/ wanpipe_on_init, - /*.on_ring*/ wanpipe_on_ring, - /*.on_execute*/ NULL, - /*.on_hangup*/ wanpipe_on_hangup, - /*.on_loopback*/ wanpipe_on_loopback, - /*.on_transmit*/ wanpipe_on_transmit +static const switch_event_handler_table wanpipe_event_handlers = { + /*.on_init */ wanpipe_on_init, + /*.on_ring */ wanpipe_on_ring, + /*.on_execute */ NULL, + /*.on_hangup */ wanpipe_on_hangup, + /*.on_loopback */ wanpipe_on_loopback, + /*.on_transmit */ wanpipe_on_transmit }; static const switch_endpoint_interface wanpipe_endpoint_interface = { - /*.interface_name*/ "wanpipe", - /*.io_routines*/ &wanpipe_io_routines, - /*.event_handlers*/ &wanpipe_event_handlers, - /*.private*/ NULL, - /*.next*/ NULL + /*.interface_name */ "wanpipe", + /*.io_routines */ &wanpipe_io_routines, + /*.event_handlers */ &wanpipe_event_handlers, + /*.private */ NULL, + /*.next */ NULL }; static const switch_loadable_module_interface wanpipe_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ &wanpipe_endpoint_interface, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ NULL, - /*.application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ &wanpipe_endpoint_interface, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL }; -Public switch_status switch_module_load(const switch_loadable_module_interface **interface, chanr *filename) { +Public switch_status switch_module_load(const switch_loadable_module_interface **interface, chanr * filename) +{ if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n"); return SWITCH_STATUS_TERM; } - + /* connect my internal structure to the blank pointer passed to me */ *interface = &wanpipe_module_interface; @@ -406,7 +412,7 @@ Public switch_status switch_module_load(const switch_loadable_module_interface * /* Event Handlers */ -static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event) +static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "number is: %s\n", event->ring.callednum); if (strlen(event->ring.callednum) > 3) { @@ -416,7 +422,7 @@ static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri return 0; } -static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event) +static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event) { struct channel_map *chanmap; switch_core_session *session; @@ -431,18 +437,18 @@ static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, p tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - + tech_pvt->cause = event->hangup.cause; memcpy(&tech_pvt->hangup_event, event, sizeof(*event)); switch_channel_set_state(channel, CS_HANGUP); } - - switch_console_printf(SWITCH_CHANNEL_CONSOLE,"-- Hanging up channel %d\n", event->hangup.channel); + + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "-- Hanging up channel %d\n", event->hangup.channel); return 0; } -static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event) +static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event) { char name[128]; switch_core_session *session; @@ -453,11 +459,13 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri chanmap = spri->private; if (chanmap->map[event->ring.channel]) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE,"--Duplicate Ring on channel %d (ignored)\n", event->ring.channel); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "--Duplicate Ring on channel %d (ignored)\n", + event->ring.channel); return 0; } - switch_console_printf(SWITCH_CHANNEL_CONSOLE,"-- Ring on channel %d (from %s to %s)\n", event->ring.channel, event->ring.callingnum, event->ring.callednum); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "-- Ring on channel %d (from %s to %s)\n", event->ring.channel, + event->ring.callingnum, event->ring.callednum); sprintf(name, "w%dg%d", globals.span, event->ring.channel); if ((session = switch_core_session_request(&wanpipe_endpoint_interface, NULL))) { @@ -476,18 +484,18 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri switch_core_session_destroy(&session); return 0; } - + if (event->ring.ani2 >= 0) { snprintf(ani2str, 5, "%.2d", event->ring.ani2); } if ((tech_pvt->caller_profile = switch_caller_profile_new(session, - globals.dialplan, - "wanpipe fixme", - event->ring.callingnum, - event->ring.callingani, - switch_strlen_zero(ani2str) ? NULL : ani2str, - event->ring.callednum))) { + globals.dialplan, + "wanpipe fixme", + event->ring.callingnum, + event->ring.callingani, + switch_strlen_zero(ani2str) ? NULL : ani2str, + event->ring.callednum))) { switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); } @@ -502,7 +510,6 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri if ((fd = sangoma_create_socket_intr(spri->span, event->ring.channel)) < 0) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open fd!\n"); } - //sangoma_tdm_set_hw_period(fd, &tdm_api, 480); tech_pvt->socket = fd; @@ -520,27 +527,28 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri static int check_flags(struct sangoma_pri *spri) { - + return 0; } -static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event) +static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event) { int fd; - switch_console_printf(SWITCH_CHANNEL_CONSOLE,"-- Restarting channel %d\n", event->restart.channel); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "-- Restarting channel %d\n", event->restart.channel); if ((fd = sangoma_create_socket_intr(spri->span, event->restart.channel)) < 0) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE,"Can't open fd!\n"); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open fd!\n"); } else { close(fd); } return 0; } -static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event) +static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE,"Caught Event %d (%s)\n", event_type, sangoma_pri_event_str(event_type)); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Caught Event %d (%s)\n", event_type, + sangoma_pri_event_str(event_type)); return 0; } @@ -559,13 +567,13 @@ static void *pri_thread_run(switch_thread *thread, void *obj) spri->on_loop = check_flags; spri->private = &chanmap; sangoma_run_pri(spri); - + free(spri); return NULL; } -static int config_wanpipe(int reload) +static int config_wanpipe(int reload) { switch_config cfg; char *var, *val; @@ -596,7 +604,7 @@ static int config_wanpipe(int reload) globals.bytes_per_frame = atoi(val); } else if (!strcmp(var, "dialplan")) { set_global_dialplan(val); - } + } } } @@ -606,18 +614,12 @@ static int config_wanpipe(int reload) set_global_dialplan("default"); } - if ((spri=switch_core_alloc(module_pool, sizeof(*spri)))) { + if ((spri = switch_core_alloc(module_pool, sizeof(*spri)))) { memset(spri, 0, sizeof(*spri)); - sangoma_init_pri(spri, - globals.span, - globals.dchan, - 23, - globals.pswitch, - globals.node, - globals.debug); - + sangoma_init_pri(spri, globals.span, globals.dchan, 23, globals.pswitch, globals.node, globals.debug); + pri_thread_run(NULL, spri); - + } else { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "error!\n"); } @@ -632,4 +634,3 @@ Public switch_status switch_module_runtime(void) config_wanpipe(0); return SWITCH_STATUS_TERM; } - diff --git a/src/mod/endpoints/mod_woomera/mod_woomera.c b/src/mod/endpoints/mod_woomera/mod_woomera.c index 0f6ce7de66..50dd61c810 100644 --- a/src/mod/endpoints/mod_woomera/mod_woomera.c +++ b/src/mod/endpoints/mod_woomera/mod_woomera.c @@ -39,7 +39,7 @@ #define WOOMERA_LINE_SEPERATOR "\r\n" #define WOOMERA_RECORD_SEPERATOR "\r\n\r\n" #define WOOMERA_DEBUG_PREFIX "**[DEBUG]** " -#define WOOMERA_DEBUG_LINE "--------------------------------------------------------------------------------" +#define WOOMERA_DEBUG_LINE "--------------------------------------------------------------------------------" #define WOOMERA_HARD_TIMEOUT -10000 #define WOOMERA_QLEN 10 #define WOOMERA_RECONNECT_TIME 5000000 @@ -104,7 +104,7 @@ struct woomera_message { static struct { - int next_woomera_port; + int next_woomera_port; int debug; int panic; int rtpmode; @@ -122,7 +122,7 @@ struct woomera_profile { int woomera_port; char audio_ip[WOOMERA_STRLEN]; char dialplan[WOOMERA_STRLEN]; -// pthread_t thread; +// pthread_t thread; unsigned int flags; int thread_running; struct woomera_event_queue event_queue; @@ -171,23 +171,27 @@ static switch_status woomerachan_on_hangup(switch_core_session *session); static switch_status woomerachan_on_ring(switch_core_session *session); static switch_status woomerachan_on_loopback(switch_core_session *session); static switch_status woomerachan_on_transmit(switch_core_session *session); -static switch_status woomerachan_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session); -static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id); -static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id); +static switch_status woomerachan_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session); +static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags, int stream_id); +static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags, int stream_id); static switch_status woomerachan_kill_channel(switch_core_session *session, int sig); -static void tech_destroy(private_object *tech_pvt); -static void woomera_printf(woomera_profile *profile, switch_socket_t *socket, char *fmt, ...); -static char *woomera_message_header(woomera_message *wmsg, char *key); -static int woomera_enqueue_event(woomera_event_queue *event_queue, woomera_message *wmsg); -static int woomera_dequeue_event(woomera_event_queue *event_queue, woomera_message *wmsg); -static int woomera_message_parse(switch_socket_t *fd, woomera_message *wmsg, int timeout, woomera_profile *profile, woomera_event_queue *event_queue); -static int connect_woomera(switch_socket_t **new_sock, woomera_profile *profile, int flags); -static int woomera_profile_thread_running(woomera_profile *profile, int set, int new); -static int woomera_locate_socket(woomera_profile *profile, switch_socket_t **woomera_socket); -static int tech_create_read_socket(private_object *tech_pvt); +static void tech_destroy(private_object * tech_pvt); +static void woomera_printf(woomera_profile * profile, switch_socket_t *socket, char *fmt, ...); +static char *woomera_message_header(woomera_message * wmsg, char *key); +static int woomera_enqueue_event(woomera_event_queue * event_queue, woomera_message * wmsg); +static int woomera_dequeue_event(woomera_event_queue * event_queue, woomera_message * wmsg); +static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, int timeout, woomera_profile * profile, + woomera_event_queue * event_queue); +static int connect_woomera(switch_socket_t **new_sock, woomera_profile * profile, int flags); +static int woomera_profile_thread_running(woomera_profile * profile, int set, int new); +static int woomera_locate_socket(woomera_profile * profile, switch_socket_t **woomera_socket); +static int tech_create_read_socket(private_object * tech_pvt); static void *woomera_channel_thread_run(switch_thread *thread, void *obj); static void *woomera_thread_run(void *obj); -static int tech_activate(private_object *tech_pvt); +static int tech_activate(private_object * tech_pvt); /* State methods they get called when the state changes to the specific state @@ -208,13 +212,17 @@ static switch_status woomerachan_on_init(switch_core_session *session) tech_pvt->frame.data = tech_pvt->databuf; - if (switch_core_codec_init(&tech_pvt->read_codec, "L16", rate, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { + if (switch_core_codec_init + (&tech_pvt->read_codec, "L16", rate, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, + switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Cannot set read codec\n", switch_channel_get_name(channel)); switch_channel_hangup(channel); return SWITCH_STATUS_FALSE; } - if (switch_core_codec_init(&tech_pvt->write_codec, "L16", rate, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { + if (switch_core_codec_init + (&tech_pvt->write_codec, "L16", rate, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, + switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Cannot set read codec\n", switch_channel_get_name(channel)); switch_channel_hangup(channel); return SWITCH_STATUS_FALSE; @@ -228,7 +236,7 @@ static switch_status woomerachan_on_init(switch_core_session *session) switch_set_flag(tech_pvt, TFLAG_ACTIVATE); switch_core_session_launch_thread(session, woomera_channel_thread_run, session); - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s WOOMERACHAN INIT\n", switch_channel_get_name(channel)); return SWITCH_STATUS_SUCCESS; @@ -261,7 +269,7 @@ static switch_status woomerachan_on_execute(switch_core_session *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s WOOMERACHAN EXECUTE\n", switch_channel_get_name(channel)); @@ -272,7 +280,7 @@ static switch_status woomerachan_on_hangup(switch_core_session *session) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; - + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -295,7 +303,7 @@ static void woomera_socket_close(switch_socket_t **socket) } -static void udp_socket_close(struct private_object *tech_pvt) +static void udp_socket_close(struct private_object *tech_pvt) { if (tech_pvt->udp_socket) { apr_socket_shutdown(tech_pvt->udp_socket, APR_SHUTDOWN_READWRITE); @@ -308,7 +316,7 @@ static switch_status woomerachan_kill_channel(switch_core_session *session, int { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; - + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -322,9 +330,10 @@ static switch_status woomerachan_kill_channel(switch_core_session *session, int udp_socket_close(tech_pvt); switch_channel_hangup(channel); - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s WOOMERACHAN KILL %d\n", switch_channel_get_name(channel), tech_pvt->udp_socket); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s WOOMERACHAN KILL %d\n", switch_channel_get_name(channel), + tech_pvt->udp_socket); + - return SWITCH_STATUS_SUCCESS; } @@ -344,14 +353,16 @@ static switch_status woomerachan_on_transmit(switch_core_session *session) /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines that allocate memory or you will have 1 channel with memory allocated from another channel's pool! */ -static switch_status woomerachan_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session) +static switch_status woomerachan_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, + switch_core_session **new_session) { if ((*new_session = switch_core_session_request(&woomerachan_endpoint_interface, NULL))) { struct private_object *tech_pvt; switch_channel *channel; - + switch_core_session_add_stream(*new_session, NULL); - if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { + if ((tech_pvt = + (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); tech_pvt->profile = &default_profile; channel = switch_core_session_get_channel(*new_session); @@ -409,7 +420,8 @@ static switch_status woomerachan_waitfor_write(switch_core_session *session, int return switch_socket_waitfor(&tech_pvt->write_poll, ms); } -static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id) +static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, + switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -426,21 +438,24 @@ static switch_status woomerachan_read_frame(switch_core_session *session, switch return SWITCH_STATUS_GENERR; } /* - if ((status = woomerachan_waitfor_read(session, -1)) != SWITCH_STATUS_SUCCESS) { - return status; - }1< - */ + if ((status = woomerachan_waitfor_read(session, -1)) != SWITCH_STATUS_SUCCESS) { + return status; + }1< + */ pframe = &tech_pvt->frame; - *frame = pframe; - + *frame = pframe; + pframe->datalen = sizeof(tech_pvt->databuf); - if ((status = switch_socket_recvfrom (tech_pvt->udpread, tech_pvt->udp_socket, 0, tech_pvt->databuf, &pframe->datalen)) == SWITCH_STATUS_SUCCESS) { - pframe->samples = (int)pframe->datalen / 2; + if ((status = + switch_socket_recvfrom(tech_pvt->udpread, tech_pvt->udp_socket, 0, tech_pvt->databuf, + &pframe->datalen)) == SWITCH_STATUS_SUCCESS) { + pframe->samples = (int) pframe->datalen / 2; } return status; } -static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) +static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, + switch_io_flag flags, int stream_id) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; @@ -458,72 +473,69 @@ static switch_status woomerachan_write_frame(switch_core_session *session, switc pframe = &tech_pvt->frame; return switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, frame->data, &frame->datalen); - + } static const switch_event_handler_table woomerachan_event_handlers = { - /*.on_init*/ woomerachan_on_init, - /*.on_ring*/ woomerachan_on_ring, - /*.on_execute*/ woomerachan_on_execute, - /*.on_hangup*/ woomerachan_on_hangup, - /*.on_loopback*/ woomerachan_on_loopback, - /*.on_transmit*/ woomerachan_on_transmit + /*.on_init */ woomerachan_on_init, + /*.on_ring */ woomerachan_on_ring, + /*.on_execute */ woomerachan_on_execute, + /*.on_hangup */ woomerachan_on_hangup, + /*.on_loopback */ woomerachan_on_loopback, + /*.on_transmit */ woomerachan_on_transmit }; static const switch_io_routines woomerachan_io_routines = { - /*.outgoing_channel*/ woomerachan_outgoing_channel, - /*.answer_channel*/ NULL, - /*.read_frame*/ woomerachan_read_frame, - /*.write_frame*/ woomerachan_write_frame, - /*.kill_channel*/ woomerachan_kill_channel, - /*.waitfor_read*/ woomerachan_waitfor_read, - /*.waitfor_write*/ woomerachan_waitfor_write + /*.outgoing_channel */ woomerachan_outgoing_channel, + /*.answer_channel */ NULL, + /*.read_frame */ woomerachan_read_frame, + /*.write_frame */ woomerachan_write_frame, + /*.kill_channel */ woomerachan_kill_channel, + /*.waitfor_read */ woomerachan_waitfor_read, + /*.waitfor_write */ woomerachan_waitfor_write }; static const switch_endpoint_interface woomerachan_endpoint_interface = { - /*.interface_name*/ "woomera", - /*.io_routines*/ &woomerachan_io_routines, - /*.event_handlers*/ &woomerachan_event_handlers, - /*.private*/ NULL, - /*.next*/ NULL + /*.interface_name */ "woomera", + /*.io_routines */ &woomerachan_io_routines, + /*.event_handlers */ &woomerachan_event_handlers, + /*.private */ NULL, + /*.next */ NULL }; static const switch_loadable_module_interface woomerachan_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ &woomerachan_endpoint_interface, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ NULL, - /*.application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ &woomerachan_endpoint_interface, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL }; -static void tech_destroy(private_object *tech_pvt) +static void tech_destroy(private_object * tech_pvt) { woomera_message wmsg; - + if (globals.debug > 1) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "+++DESTROY\n"); } - woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "hangup %s%s", tech_pvt->call_info.callid, WOOMERA_RECORD_SEPERATOR); - if(woomera_message_parse(tech_pvt->command_channel, - &wmsg, - WOOMERA_HARD_TIMEOUT, - tech_pvt->profile, - &tech_pvt->event_queue - ) < 0) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} Already Disconnected\n", tech_pvt->profile->name); + woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "hangup %s%s", tech_pvt->call_info.callid, + WOOMERA_RECORD_SEPERATOR); + if (woomera_message_parse + (tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} Already Disconnected\n", tech_pvt->profile->name); } - + woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "bye%s", WOOMERA_RECORD_SEPERATOR); woomera_socket_close(&tech_pvt->command_channel); udp_socket_close(tech_pvt); } -static void woomera_printf(woomera_profile *profile, switch_socket_t *socket, char *fmt, ...) +static void woomera_printf(woomera_profile * profile, switch_socket_t *socket, char *fmt, ...) { char *stuff; size_t res = 0, len = 0; @@ -531,7 +543,7 @@ static void woomera_printf(woomera_profile *profile, switch_socket_t *socket, ch va_list ap; va_start(ap, fmt); #ifndef vasprintf - stuff = (char *)malloc(10240); + stuff = (char *) malloc(10240); vsnprintf(stuff, 10240, fmt, ap); #else res = vasprintf(&stuff, fmt, ap); @@ -541,22 +553,23 @@ static void woomera_printf(woomera_profile *profile, switch_socket_t *socket, ch switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Out of memory\n"); } else { if (profile && globals.debug) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Send Message: {%s} [%s/%d]\n%s\n%s", profile->name, profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, stuff); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Send Message: {%s} [%s/%d]\n%s\n%s", profile->name, + profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, stuff); } len = strlen(stuff); switch_socket_send(socket, stuff, &len); - + free(stuff); } } -static char *woomera_message_header(woomera_message *wmsg, char *key) +static char *woomera_message_header(woomera_message * wmsg, char *key) { int x = 0; char *value = NULL; - for (x = 0 ; x < wmsg->last ; x++) { + for (x = 0; x < wmsg->last; x++) { if (!strcasecmp(wmsg->names[x], key)) { value = wmsg->values[x]; break; @@ -566,7 +579,7 @@ static char *woomera_message_header(woomera_message *wmsg, char *key) return value; } -static int woomera_enqueue_event(woomera_event_queue *event_queue, woomera_message *wmsg) +static int woomera_enqueue_event(woomera_event_queue * event_queue, woomera_message * wmsg) { woomera_message *new, *mptr; @@ -577,7 +590,7 @@ static int woomera_enqueue_event(woomera_event_queue *event_queue, woomera_messa if (!event_queue->head) { event_queue->head = new; } else { - for (mptr = event_queue->head; mptr && mptr->next ; mptr = mptr->next); + for (mptr = event_queue->head; mptr && mptr->next; mptr = mptr->next); mptr->next = new; } return 1; @@ -588,10 +601,10 @@ static int woomera_enqueue_event(woomera_event_queue *event_queue, woomera_messa return 0; } -static int woomera_dequeue_event(woomera_event_queue *event_queue, woomera_message *wmsg) +static int woomera_dequeue_event(woomera_event_queue * event_queue, woomera_message * wmsg) { woomera_message *mptr = NULL; - + if (event_queue->head) { mptr = event_queue->head; event_queue->head = mptr->next; @@ -604,11 +617,12 @@ static int woomera_dequeue_event(woomera_event_queue *event_queue, woomera_messa } else { memset(wmsg, 0, sizeof(woomera_message)); } - + return 0; } -static int woomera_message_parse(switch_socket_t *fd, woomera_message *wmsg, int timeout, woomera_profile *profile, woomera_event_queue *event_queue) +static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, int timeout, woomera_profile * profile, + woomera_event_queue * event_queue) { char *cur, *cr, *next = NULL, *eor = NULL; char buf[2048] = "", *ptr; @@ -617,7 +631,7 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message *wmsg, int memset(wmsg, 0, sizeof(woomera_message)); - if (fd < 0 ) { + if (fd < 0) { return -1; } @@ -647,17 +661,18 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message *wmsg, int next = buf; if (globals.debug) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Receive Message: {%s} [%s/%d]\n%s\n%s", profile->name, profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, buf); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Receive Message: {%s} [%s/%d]\n%s\n%s", profile->name, + profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, buf); } - while((cur = next)) { + while ((cur = next)) { if ((cr = strstr(cur, WOOMERA_LINE_SEPERATOR))) { *cr = '\0'; next = cr + (sizeof(WOOMERA_LINE_SEPERATOR) - 1); if (!strcmp(next, WOOMERA_RECORD_SEPERATOR)) { break; } - } + } if (!cur || !cur[0]) { break; @@ -710,9 +725,9 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message *wmsg, int *val = '\0'; val++; } - strncpy(wmsg->values[wmsg->last-1], val, WOOMERA_STRLEN); + strncpy(wmsg->values[wmsg->last - 1], val, WOOMERA_STRLEN); } - strncpy(wmsg->names[wmsg->last-1], name, WOOMERA_STRLEN); + strncpy(wmsg->names[wmsg->last - 1], name, WOOMERA_STRLEN); if (name && val && !strcasecmp(name, "content-type")) { switch_set_flag(wmsg, WFLAG_CONTENT); bytes = atoi(val); @@ -744,11 +759,11 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message *wmsg, int * wmsg will be overwritten but it's ok we just queued it. */ return woomera_message_parse(fd, wmsg, timeout, profile, event_queue); - + } else if (wmsg->mval > 99 && wmsg->mval < 200) { /* reply in the 100's are nice but we need to wait for another reply call ourself recursively to find the reply > 199 and forget this reply. - */ + */ return woomera_message_parse(fd, wmsg, timeout, profile, event_queue); } else { return switch_test_flag(wmsg, WFLAG_EXISTS); @@ -756,7 +771,7 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message *wmsg, int } -static int connect_woomera(switch_socket_t **new_sock, woomera_profile *profile, int flags) +static int connect_woomera(switch_socket_t **new_sock, woomera_profile * profile, int flags) { switch_sockaddr_t *sa; @@ -771,12 +786,12 @@ static int connect_woomera(switch_socket_t **new_sock, woomera_profile *profile, return -1; } /* - status = switch_socket_bind((*new_sock), sa); - if (0 && status != SWITCH_STATUS_SUCCESS) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't Bind to %s:%d!\n", profile->woomera_host, profile->woomera_port); - return -1; - } - */ + status = switch_socket_bind((*new_sock), sa); + if (0 && status != SWITCH_STATUS_SUCCESS) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't Bind to %s:%d!\n", profile->woomera_host, profile->woomera_port); + return -1; + } + */ status = switch_socket_connect((*new_sock), sa); if (status != SWITCH_STATUS_SUCCESS) { return -1; @@ -785,7 +800,7 @@ static int connect_woomera(switch_socket_t **new_sock, woomera_profile *profile, return 1; } -static int woomera_profile_thread_running(woomera_profile *profile, int set, int new) +static int woomera_profile_thread_running(woomera_profile * profile, int set, int new) { int running = 0; @@ -796,20 +811,21 @@ static int woomera_profile_thread_running(woomera_profile *profile, int set, int running = profile->thread_running; switch_mutex_unlock(profile->iolock); return running; - + } -static int woomera_locate_socket(woomera_profile *profile, switch_socket_t **woomera_socket) +static int woomera_locate_socket(woomera_profile * profile, switch_socket_t **woomera_socket) { woomera_message wmsg; - + for (;;) { while (connect_woomera(woomera_socket, profile, 0) < 0) { if (!woomera_profile_thread_running(profile, 0, 0)) { break; } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} Cannot Reconnect to Woomera! retry in 5 seconds\n", profile->name); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} Cannot Reconnect to Woomera! retry in 5 seconds\n", + profile->name); switch_sleep(WOOMERA_RECONNECT_TIME); } @@ -817,11 +833,7 @@ static int woomera_locate_socket(woomera_profile *profile, switch_socket_t **woo if (switch_test_flag(profile, PFLAG_INBOUND)) { woomera_printf(profile, *woomera_socket, "LISTEN%s", WOOMERA_RECORD_SEPERATOR); if (woomera_message_parse(*woomera_socket, - &wmsg, - WOOMERA_HARD_TIMEOUT, - profile, - &profile->event_queue - ) < 0) { + &wmsg, WOOMERA_HARD_TIMEOUT, profile, &profile->event_queue) < 0) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", profile->name); globals.panic = 1; woomera_profile_thread_running(&default_profile, 1, 0); @@ -829,7 +841,7 @@ static int woomera_locate_socket(woomera_profile *profile, switch_socket_t **woo if (*woomera_socket) { woomera_socket_close(woomera_socket); } - + continue; } } @@ -837,13 +849,13 @@ static int woomera_locate_socket(woomera_profile *profile, switch_socket_t **woo } switch_sleep(100); break; - } + } return *woomera_socket ? 1 : 0; } -static int tech_create_read_socket(private_object *tech_pvt) +static int tech_create_read_socket(private_object * tech_pvt) { switch_memory_pool *pool = switch_core_session_get_pool(tech_pvt->session); @@ -857,20 +869,20 @@ static int tech_create_read_socket(private_object *tech_pvt) switch_sockaddr_info_get(&tech_pvt->udpread, tech_pvt->profile->audio_ip, SWITCH_UNSPEC, tech_pvt->port, 0, pool); if (switch_socket_create(&tech_pvt->udp_socket, AF_INET, SOCK_DGRAM, 0, pool) == SWITCH_STATUS_SUCCESS) { switch_socket_bind(tech_pvt->udp_socket, tech_pvt->udpread); - switch_socket_create_pollfd(&tech_pvt->read_poll, tech_pvt->udp_socket, SWITCH_POLLIN|SWITCH_POLLERR, pool); - switch_socket_create_pollfd(&tech_pvt->write_poll, tech_pvt->udp_socket, SWITCH_POLLOUT|SWITCH_POLLERR, pool); + switch_socket_create_pollfd(&tech_pvt->read_poll, tech_pvt->udp_socket, SWITCH_POLLIN | SWITCH_POLLERR, pool); + switch_socket_create_pollfd(&tech_pvt->write_poll, tech_pvt->udp_socket, SWITCH_POLLOUT | SWITCH_POLLERR, pool); } return 0; } -static int tech_activate(private_object *tech_pvt) +static int tech_activate(private_object * tech_pvt) { woomera_message wmsg; if (tech_pvt) { - if((connect_woomera(&tech_pvt->command_channel, tech_pvt->profile, 0))) { + if ((connect_woomera(&tech_pvt->command_channel, tech_pvt->profile, 0))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "connected to woomera!\n"); } else { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't connect to woomera!\n"); @@ -881,34 +893,25 @@ static int tech_activate(private_object *tech_pvt) if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) { woomera_printf(tech_pvt->profile, - tech_pvt->command_channel, - "CALL %s%sRaw-Audio: %s/%d%sLocal-Name: %s!%s%s", + tech_pvt->command_channel, + "CALL %s%sRaw-Audio: %s/%d%sLocal-Name: %s!%s%s", tech_pvt->caller_profile->destination_number, WOOMERA_LINE_SEPERATOR, tech_pvt->profile->audio_ip, tech_pvt->port, WOOMERA_LINE_SEPERATOR, tech_pvt->caller_profile->caller_id_name, - tech_pvt->caller_profile->caller_id_number, - WOOMERA_RECORD_SEPERATOR - ); + tech_pvt->caller_profile->caller_id_number, WOOMERA_RECORD_SEPERATOR); woomera_message_parse(tech_pvt->command_channel, - &wmsg, - WOOMERA_HARD_TIMEOUT, - tech_pvt->profile, - &tech_pvt->event_queue - ); + &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue); } else { switch_set_flag(tech_pvt, TFLAG_PARSE_INCOMING); woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "LISTEN%s", WOOMERA_RECORD_SEPERATOR); if (woomera_message_parse(tech_pvt->command_channel, - &wmsg, - WOOMERA_HARD_TIMEOUT, - tech_pvt->profile, - &tech_pvt->event_queue - ) < 0) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name); + &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", + tech_pvt->profile->name); switch_set_flag(tech_pvt, TFLAG_ABORT); globals.panic = 1; } @@ -941,9 +944,9 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj) if (!tech_pvt->udp_socket) { tech_create_read_socket(tech_pvt); } - - for(;;) { + + for (;;) { if (globals.panic) { switch_set_flag(tech_pvt, TFLAG_ABORT); } @@ -964,31 +967,29 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj) if (switch_test_flag(tech_pvt, TFLAG_ANSWER)) { switch_clear_flag(tech_pvt, TFLAG_ANSWER); #ifdef USE_ANSWER - woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "ANSWER %s%s",tech_pvt->call_info.callid, WOOMERA_RECORD_SEPERATOR); - if(woomera_message_parse(tech_pvt->command_channel, - &wmsg, - WOOMERA_HARD_TIMEOUT, - tech_pvt->profile, - &tech_pvt->event_queue - ) < 0) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name); + woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "ANSWER %s%s", tech_pvt->call_info.callid, + WOOMERA_RECORD_SEPERATOR); + if (woomera_message_parse + (tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, + &tech_pvt->event_queue) < 0) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", + tech_pvt->profile->name); switch_set_flag(tech_pvt, TFLAG_ABORT); globals.panic = 1; continue; } #endif } - + if (switch_test_flag(tech_pvt, TFLAG_DTMF)) { switch_mutex_lock(tech_pvt->iolock); - woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "DTMF %s %s%s",tech_pvt->call_info.callid, tech_pvt->dtmfbuf, WOOMERA_RECORD_SEPERATOR); - if(woomera_message_parse(tech_pvt->command_channel, - &wmsg, - WOOMERA_HARD_TIMEOUT, - tech_pvt->profile, - &tech_pvt->event_queue - ) < 0) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name); + woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "DTMF %s %s%s", tech_pvt->call_info.callid, + tech_pvt->dtmfbuf, WOOMERA_RECORD_SEPERATOR); + if (woomera_message_parse + (tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, + &tech_pvt->event_queue) < 0) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", + tech_pvt->profile->name); switch_set_flag(tech_pvt, TFLAG_ABORT); globals.panic = 1; continue; @@ -997,13 +998,14 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj) memset(tech_pvt->dtmfbuf, 0, sizeof(tech_pvt->dtmfbuf)); switch_mutex_unlock(tech_pvt->iolock); } - -#if 1==0 /*convert to use switch_time_now */ - if(tech_pvt->timeout) { +#if 1==0 /*convert to use switch_time_now */ + if (tech_pvt->timeout) { struct timeval now; int elapsed; gettimeofday(&now, NULL); - elapsed = (((now.tv_sec * 1000) + now.tv_usec / 1000) - ((tech_pvt->started.tv_sec * 1000) + tech_pvt->started.tv_usec / 1000)); + elapsed = + (((now.tv_sec * 1000) + now.tv_usec / 1000) - + ((tech_pvt->started.tv_sec * 1000) + tech_pvt->started.tv_usec / 1000)); if (elapsed > tech_pvt->timeout) { /* call timed out! */ switch_set_flag(tech_pvt, TFLAG_ABORT); @@ -1015,29 +1017,24 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj) break; } /* Check for events */ - if((res = woomera_dequeue_event(&tech_pvt->event_queue, &wmsg)) || - (res = woomera_message_parse(tech_pvt->command_channel, - &wmsg, - 100, - tech_pvt->profile, - NULL - ))) { + if ((res = woomera_dequeue_event(&tech_pvt->event_queue, &wmsg)) || + (res = woomera_message_parse(tech_pvt->command_channel, &wmsg, 100, tech_pvt->profile, NULL))) { if (res < 0 || !strcasecmp(wmsg.command, "HANGUP")) { switch_set_flag(tech_pvt, TFLAG_ABORT); continue; } else if (!strcasecmp(wmsg.command, "DTMF")) { /* - struct ast_frame dtmf_frame = {AST_FRAME_DTMF}; - int x = 0; - for (x = 0; x < strlen(wmsg.command_args); x++) { - dtmf_frame.subclass = wmsg.command_args[x]; - ast_queue_frame(tech_pvt->owner, ast_frdup(&dtmf_frame)); - if (globals.debug > 1) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "SEND DTMF [%c] to %s\n", dtmf_frame.subclass, tech_pvt->owner->name); - } - } - */ + struct ast_frame dtmf_frame = {AST_FRAME_DTMF}; + int x = 0; + for (x = 0; x < strlen(wmsg.command_args); x++) { + dtmf_frame.subclass = wmsg.command_args[x]; + ast_queue_frame(tech_pvt->owner, ast_frdup(&dtmf_frame)); + if (globals.debug > 1) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "SEND DTMF [%c] to %s\n", dtmf_frame.subclass, tech_pvt->owner->name); + } + } + */ } else if (!strcasecmp(wmsg.command, "PROCEED")) { /* This packet has lots of info so well keep it */ tech_pvt->call_info = wmsg; @@ -1059,7 +1056,7 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj) if ((p = woomera_message_header(&wmsg, "Remote-Name"))) { strncpy(cid_name, p, sizeof(cid_name)); } - + if ((cid_num = strchr(cid_name, '!'))) { *cid_num = '\0'; cid_num++; @@ -1070,40 +1067,31 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj) if ((tech_pvt->caller_profile = switch_caller_profile_new(session, tech_pvt->profile->dialplan, - cid_name, - cid_num, - ip, - NULL, - NULL, - exten))) { + cid_name, cid_num, ip, NULL, NULL, exten))) { char name[128]; switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); - snprintf(name, sizeof(name), "Woomera/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff); + snprintf(name, sizeof(name), "Woomera/%s-%04x", tech_pvt->caller_profile->destination_number, + rand() & 0xffff); switch_channel_set_name(channel, name); } - woomera_printf(tech_pvt->profile, tech_pvt->command_channel, + woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "%s %s%s" "Raw-Audio: %s/%d%s", MEDIA_ANSWER, wmsg.callid, WOOMERA_LINE_SEPERATOR, - tech_pvt->profile->audio_ip, - tech_pvt->port, - WOOMERA_RECORD_SEPERATOR); - - if(woomera_message_parse(tech_pvt->command_channel, - &wmsg, - WOOMERA_HARD_TIMEOUT, - tech_pvt->profile, - &tech_pvt->event_queue - ) < 0) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name); + tech_pvt->profile->audio_ip, tech_pvt->port, WOOMERA_RECORD_SEPERATOR); + + if (woomera_message_parse(tech_pvt->command_channel, + &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", + tech_pvt->profile->name); switch_set_flag(tech_pvt, TFLAG_ABORT); globals.panic = 1; continue; } - + } else if (!strcasecmp(wmsg.command, "CONNECT")) { } else if (!strcasecmp(wmsg.command, "MEDIA")) { @@ -1115,7 +1103,7 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj) int port = 0; strncpy(ip, raw_audio_header, sizeof(ip) - 1); - if ((ptr=strchr(ip, '/'))) { + if ((ptr = strchr(ip, '/'))) { *ptr = '\0'; ptr++; port = atoi(ptr); @@ -1129,9 +1117,12 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj) SWITCH_UNSPEC, port, 0, - switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { + switch_core_session_get_pool(tech_pvt->session)) != + SWITCH_STATUS_SUCCESS) { if (globals.debug) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "{%s} Cannot resolve %s\n", tech_pvt->profile->name, ip); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, + WOOMERA_DEBUG_PREFIX "{%s} Cannot resolve %s\n", + tech_pvt->profile->name, ip); } switch_channel_hangup(channel); } @@ -1139,20 +1130,22 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj) } } if (globals.debug > 2) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "CHECK {%s}(%d)\n", tech_pvt->profile->name, res); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "CHECK {%s}(%d)\n", + tech_pvt->profile->name, res); } } if (globals.debug > 1) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "Monitor thread for %s done.\n", tech_pvt->profile->name); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "Monitor thread for %s done.\n", + tech_pvt->profile->name); } return NULL; } - -static void *woomera_thread_run(void *obj) + +static void *woomera_thread_run(void *obj) { int res = 0; @@ -1161,12 +1154,12 @@ static void *woomera_thread_run(void *obj) profile = obj; switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Started Woomera Thread {%s}.\n", profile->name); - + profile->thread_running = 1; profile->woomera_socket = NULL; - while(woomera_profile_thread_running(profile, 0, 0)) { + while (woomera_profile_thread_running(profile, 0, 0)) { /* listen on socket and handle events */ if (globals.panic == 2) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Woomera is disabled!\n"); @@ -1174,21 +1167,22 @@ static void *woomera_thread_run(void *obj) continue; } - if (! profile->woomera_socket) { + if (!profile->woomera_socket) { if (woomera_locate_socket(profile, &profile->woomera_socket)) { globals.panic = 0; } if (!woomera_profile_thread_running(profile, 0, 0)) { break; } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Woomera Thread Up {%s} %s/%d\n", profile->name, profile->woomera_host, profile->woomera_port); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Woomera Thread Up {%s} %s/%d\n", profile->name, + profile->woomera_host, profile->woomera_port); } if (globals.panic) { if (globals.panic != 2) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Help I'm in a state of panic!\n"); - globals.panic = 0;//fix + globals.panic = 0; //fix } woomera_socket_close(&profile->woomera_socket); @@ -1197,15 +1191,12 @@ static void *woomera_thread_run(void *obj) } if ((res = woomera_dequeue_event(&profile->event_queue, &wmsg) || - (res = woomera_message_parse(profile->woomera_socket, - &wmsg, + (res = woomera_message_parse(profile->woomera_socket, &wmsg, /* if we are not stingy with threads we can block forever */ - 0, - profile, - NULL - )))) { + 0, profile, NULL)))) { if (res < 0) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! I lost my connection to woomera!\n", profile->name); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! I lost my connection to woomera!\n", + profile->name); woomera_socket_close(&profile->woomera_socket); //global_set_flag(TFLAG_ABORT); @@ -1216,18 +1207,16 @@ static void *woomera_thread_run(void *obj) if (switch_test_flag(profile, PFLAG_INBOUND)) { woomera_printf(profile, profile->woomera_socket, "LISTEN%s", WOOMERA_RECORD_SEPERATOR); if (woomera_message_parse(profile->woomera_socket, - &wmsg, - WOOMERA_HARD_TIMEOUT, - profile, - &profile->event_queue - ) < 0) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", profile->name); + &wmsg, WOOMERA_HARD_TIMEOUT, profile, &profile->event_queue) < 0) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", + profile->name); globals.panic = 1; woomera_socket_close(&profile->woomera_socket); - } + } } if (profile->woomera_socket) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Woomera Thread Up {%s} %s/%d\n", profile->name, profile->woomera_host, profile->woomera_port); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Woomera Thread Up {%s} %s/%d\n", profile->name, + profile->woomera_host, profile->woomera_port); } } continue; @@ -1236,11 +1225,11 @@ static void *woomera_thread_run(void *obj) if (!strcasecmp(wmsg.command, "INCOMING")) { char *name; switch_core_session *session; - + if (!(name = woomera_message_header(&wmsg, "Remote-Address"))) { name = woomera_message_header(&wmsg, "Channel-Name"); } - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "New Inbound Channel %s!\n", name); if ((session = switch_core_session_request(&woomerachan_endpoint_interface, NULL))) { struct private_object *tech_pvt; @@ -1248,7 +1237,8 @@ static void *woomera_thread_run(void *obj) switch_core_session_add_stream(session, NULL); - if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) { + if ((tech_pvt = + (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) { memset(tech_pvt, 0, sizeof(*tech_pvt)); tech_pvt->profile = &default_profile; channel = switch_core_session_get_channel(session); @@ -1264,14 +1254,14 @@ static void *woomera_thread_run(void *obj) } } } - + if (globals.debug > 2) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Main Thread {%s} Select Return %d\n", profile->name, res); } switch_yield(100); } - + if (profile->woomera_socket) { woomera_printf(profile, profile->woomera_socket, "BYE%s", WOOMERA_RECORD_SEPERATOR); @@ -1305,30 +1295,31 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void) return SWITCH_STATUS_SUCCESS; } -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ switch_config cfg; char *var, *val; struct woomera_profile *profile = &default_profile; char *cf = "woomera.conf"; - + memset(&globals, 0, sizeof(globals)); globals.next_woomera_port = WOOMERA_MIN_PORT; - + if (!switch_config_open_file(&cfg, cf)) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf); return SWITCH_STATUS_TERM; } - + switch_set_flag(profile, PFLAG_INBOUND | PFLAG_OUTBOUND); profile->name = "main"; strncpy(profile->dialplan, "default", sizeof(profile->dialplan) - 1); - + while (switch_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "settings")) { - if (!strcmp(var, "noload") && atoi(val)) { - return SWITCH_STATUS_TERM; - } + if (!strcmp(var, "noload") && atoi(val)) { + return SWITCH_STATUS_TERM; + } if (!strcmp(var, "debug")) { globals.debug = atoi(val); } @@ -1359,7 +1350,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul switch_config_close_file(&cfg); - + if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) { //switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n"); @@ -1376,7 +1367,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no lock\n"); return SWITCH_STATUS_TERM; } - + /* connect my internal structure to the blank pointer passed to me */ *interface = &woomerachan_module_interface; @@ -1384,6 +1375,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } - - - diff --git a/src/mod/event_handlers/mod_event_test/mod_event_test.c b/src/mod/event_handlers/mod_event_test/mod_event_test.c index 58c406c719..7ec278257d 100644 --- a/src/mod/event_handlers/mod_event_test/mod_event_test.c +++ b/src/mod/event_handlers/mod_event_test/mod_event_test.c @@ -33,11 +33,11 @@ static const char modname[] = "mod_event_test"; -static void event_handler (switch_event *event) +static void event_handler(switch_event *event) { char buf[1024]; - switch(event->event_id) { + switch (event->event_id) { case SWITCH_EVENT_LOG: return; break; @@ -50,12 +50,12 @@ static void event_handler (switch_event *event) static switch_loadable_module_interface event_test_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ NULL, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ NULL, - /*.application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ NULL, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL }; #define MY_EVENT_COOL "test::cool" @@ -76,9 +76,9 @@ static void *torture_thread(switch_thread *thread, void *obj) z = THREADS++; - while(THREADS > 0) { + while (THREADS > 0) { int x; - for(x = 0; x < 1; x++) { + for (x = 0; x < 1; x++) { if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_COOL) == SWITCH_STATUS_SUCCESS) { switch_event_add_header(event, "event_info", "hello world %d %d", z, y++); switch_event_fire(&event); @@ -104,7 +104,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void) #endif -SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) +{ /* connect my internal structure to the blank pointer passed to me */ *interface = &event_test_module_interface; @@ -112,16 +113,16 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_inte switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't register subclass!"); return SWITCH_STATUS_GENERR; } - #ifdef TORTURE_ME - if (switch_event_bind((char *)modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) { + if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != + SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't bind!\n"); return SWITCH_STATUS_GENERR; } if (1) { int x = 0; - for(x = 0 ; x < TTHREADS ; x++) { + for (x = 0; x < TTHREADS; x++) { switch_core_launch_thread(torture_thread, NULL); } } @@ -130,4 +131,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_inte /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } - diff --git a/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c b/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c index 6f983723d6..0f4f5f08ab 100644 --- a/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c +++ b/src/mod/event_handlers/mod_xmpp_event/mod_xmpp_event.c @@ -58,7 +58,7 @@ static struct { struct session session; } globals; -static void event_handler (switch_event *event) +static void event_handler(switch_event *event) { char buf[1024]; iks *msg; @@ -76,7 +76,7 @@ static void event_handler (switch_event *event) } } - switch(event->event_id) { + switch (event->event_id) { default: switch_event_serialize(event, buf, sizeof(buf), NULL); //switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nEVENT\n--------------------------------\n%s\n", buf); @@ -91,8 +91,8 @@ static void event_handler (switch_event *event) SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_jid, globals.jid) - SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_target_jid, globals.target_jid) - SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_passwd, globals.passwd) + SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_target_jid, globals.target_jid) + SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_passwd, globals.passwd) static switch_status load_config(void) @@ -103,13 +103,13 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_jid, globals.jid) char *cf = "xmpp_event.conf"; int count = 0; - memset(&globals, 0, sizeof(globals)); + memset(&globals, 0, sizeof(globals)); if (!switch_config_open_file(&cfg, cf)) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf); return SWITCH_STATUS_TERM; } - + while (switch_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "settings")) { if (!strcmp(var, "jid")) { @@ -131,76 +131,79 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_jid, globals.jid) if (count == 3) { /* TBD use config to pick what events to bind to */ - if (switch_event_bind((char *)modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) { + if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != + SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't bind!\n"); return SWITCH_STATUS_GENERR; } - + status = SWITCH_STATUS_SUCCESS; } return status; - + } -int on_result (struct session *sess, ikspak *pak) +int on_result(struct session *sess, ikspak * pak) { return IKS_FILTER_EAT; } -int on_stream (struct session *sess, int type, iks *node) +int on_stream(struct session *sess, int type, iks * node) { sess->counter = opt_timeout; switch (type) { case IKS_NODE_START: - if (opt_use_tls && !iks_is_secure (sess->parser)) { - iks_start_tls (sess->parser); + if (opt_use_tls && !iks_is_secure(sess->parser)) { + iks_start_tls(sess->parser); } break; case IKS_NODE_NORMAL: - if (strcmp ("stream:features", iks_name (node)) == 0) { - sess->features = iks_stream_features (node); - if (opt_use_tls && !iks_is_secure (sess->parser)) break; + if (strcmp("stream:features", iks_name(node)) == 0) { + sess->features = iks_stream_features(node); + if (opt_use_tls && !iks_is_secure(sess->parser)) + break; if (sess->authorized) { iks *t; if (sess->features & IKS_STREAM_BIND) { - t = iks_make_resource_bind (sess->acc); - iks_send (sess->parser, t); - iks_delete (t); + t = iks_make_resource_bind(sess->acc); + iks_send(sess->parser, t); + iks_delete(t); } if (sess->features & IKS_STREAM_SESSION) { - t = iks_make_session (); - iks_insert_attrib (t, "id", "auth"); - iks_send (sess->parser, t); - iks_delete (t); + t = iks_make_session(); + iks_insert_attrib(t, "id", "auth"); + iks_send(sess->parser, t); + iks_delete(t); } } else { if (sess->features & IKS_STREAM_SASL_MD5) - iks_start_sasl (sess->parser, IKS_SASL_DIGEST_MD5, sess->acc->user, sess->pass); + iks_start_sasl(sess->parser, IKS_SASL_DIGEST_MD5, sess->acc->user, sess->pass); else if (sess->features & IKS_STREAM_SASL_PLAIN) - iks_start_sasl (sess->parser, IKS_SASL_PLAIN, sess->acc->user, sess->pass); + iks_start_sasl(sess->parser, IKS_SASL_PLAIN, sess->acc->user, sess->pass); } - } else if (strcmp ("failure", iks_name (node)) == 0) { + } else if (strcmp("failure", iks_name(node)) == 0) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sasl authentication failed\n"); - } else if (strcmp ("success", iks_name (node)) == 0) { + } else if (strcmp("success", iks_name(node)) == 0) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "server connected\n"); sess->authorized = 1; - iks_send_header (sess->parser, sess->acc->server); + iks_send_header(sess->parser, sess->acc->server); } else { ikspak *pak; - pak = iks_packet (node); - iks_filter_packet (my_filter, pak); - if (sess->job_done == 1) return IKS_HOOK; + pak = iks_packet(node); + iks_filter_packet(my_filter, pak); + if (sess->job_done == 1) + return IKS_HOOK; } break; #if 0 case IKS_NODE_STOP: switch_console_printf(SWITCH_CHANNEL_CONSOLE, "server disconnected\n"); break; - + case IKS_NODE_ERROR: switch_console_printf(SWITCH_CHANNEL_CONSOLE, "stream error\n"); break; @@ -208,13 +211,14 @@ int on_stream (struct session *sess, int type, iks *node) } - if (node) iks_delete (node); + if (node) + iks_delete(node); return IKS_OK; } -int on_msg (void *user_data, ikspak *pak) +int on_msg(void *user_data, ikspak * pak) { - char *cmd = iks_find_cdata (pak->x, "body"); + char *cmd = iks_find_cdata(pak->x, "body"); char *arg = NULL; char retbuf[1024] = ""; char *p; @@ -227,67 +231,67 @@ int on_msg (void *user_data, ikspak *pak) if ((arg = strchr(cmd, ' '))) { *arg++ = '\0'; - } + } switch_api_execute(cmd, arg, retbuf, sizeof(retbuf)); return 0; } -int on_error (void *user_data, ikspak *pak) +int on_error(void *user_data, ikspak * pak) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "authorization failed\n"); return IKS_FILTER_EAT; } -void on_log (struct session *sess, const char *data, size_t size, int is_incoming) +void on_log(struct session *sess, const char *data, size_t size, int is_incoming) { - if (iks_is_secure (sess->parser)) fprintf (stderr, "Sec"); - if (is_incoming) fprintf (stderr, "RECV"); else fprintf (stderr, "SEND"); - fprintf (stderr, "[%s]\n", data); + if (iks_is_secure(sess->parser)) + fprintf(stderr, "Sec"); + if (is_incoming) + fprintf(stderr, "RECV"); + else + fprintf(stderr, "SEND"); + fprintf(stderr, "[%s]\n", data); } -void j_setup_filter (struct session *sess) +void j_setup_filter(struct session *sess) { - if (my_filter) iks_filter_delete (my_filter); - my_filter = iks_filter_new (); - iks_filter_add_rule (my_filter, on_msg, 0, - IKS_RULE_TYPE, IKS_PAK_MESSAGE, - IKS_RULE_SUBTYPE, IKS_TYPE_CHAT, - IKS_RULE_FROM, globals.target_jid, - IKS_RULE_DONE); - iks_filter_add_rule (my_filter, (iksFilterHook *) on_result, sess, - IKS_RULE_TYPE, IKS_PAK_IQ, - IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, - IKS_RULE_ID, "auth", - IKS_RULE_DONE); - iks_filter_add_rule (my_filter, on_error, sess, - IKS_RULE_TYPE, IKS_PAK_IQ, - IKS_RULE_SUBTYPE, IKS_TYPE_ERROR, - IKS_RULE_ID, "auth", - IKS_RULE_DONE); + if (my_filter) + iks_filter_delete(my_filter); + my_filter = iks_filter_new(); + iks_filter_add_rule(my_filter, on_msg, 0, + IKS_RULE_TYPE, IKS_PAK_MESSAGE, + IKS_RULE_SUBTYPE, IKS_TYPE_CHAT, IKS_RULE_FROM, globals.target_jid, IKS_RULE_DONE); + iks_filter_add_rule(my_filter, (iksFilterHook *) on_result, sess, + IKS_RULE_TYPE, IKS_PAK_IQ, + IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, "auth", IKS_RULE_DONE); + iks_filter_add_rule(my_filter, on_error, sess, + IKS_RULE_TYPE, IKS_PAK_IQ, + IKS_RULE_SUBTYPE, IKS_TYPE_ERROR, IKS_RULE_ID, "auth", IKS_RULE_DONE); } -static void xmpp_connect (char *jabber_id, char *pass) +static void xmpp_connect(char *jabber_id, char *pass) { while (RUNNING == 1) { int e; - memset (&globals.session, 0, sizeof (globals.session)); - globals.session.parser = iks_stream_new (IKS_NS_CLIENT, &globals.session, (iksStreamHook *) on_stream); - if (globals.debug) iks_set_log_hook (globals.session.parser, (iksLogHook *) on_log); - globals.session.acc = iks_id_new (iks_parser_stack (globals.session.parser), jabber_id); + memset(&globals.session, 0, sizeof(globals.session)); + globals.session.parser = iks_stream_new(IKS_NS_CLIENT, &globals.session, (iksStreamHook *) on_stream); + if (globals.debug) + iks_set_log_hook(globals.session.parser, (iksLogHook *) on_log); + globals.session.acc = iks_id_new(iks_parser_stack(globals.session.parser), jabber_id); if (NULL == globals.session.acc->resource) { /* user gave no resource name, use the default */ char tmp[512]; - sprintf (tmp, "%s@%s/%s", globals.session.acc->user, globals.session.acc->server, modname); - globals.session.acc = iks_id_new (iks_parser_stack (globals.session.parser), tmp); + sprintf(tmp, "%s@%s/%s", globals.session.acc->user, globals.session.acc->server, modname); + globals.session.acc = iks_id_new(iks_parser_stack(globals.session.parser), tmp); } globals.session.pass = pass; - j_setup_filter (&globals.session); + j_setup_filter(&globals.session); - e = iks_connect_tcp (globals.session.parser, globals.session.acc->server, IKS_JABBER_PORT); + e = iks_connect_tcp(globals.session.parser, globals.session.acc->server, IKS_JABBER_PORT); switch (e) { case IKS_OK: break; @@ -303,13 +307,13 @@ static void xmpp_connect (char *jabber_id, char *pass) globals.session.counter = opt_timeout; while (RUNNING == 1) { - e = iks_recv (globals.session.parser, 1); + e = iks_recv(globals.session.parser, 1); - if(globals.session.job_done) { + if (globals.session.job_done) { break; } - if (IKS_HOOK == e) { + if (IKS_HOOK == e) { break; } @@ -320,38 +324,39 @@ static void xmpp_connect (char *jabber_id, char *pass) } if (!globals.session.authorized) { - if (IKS_NET_TLSFAIL == e) { + if (IKS_NET_TLSFAIL == e) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "tls handshake failed\n"); switch_sleep(5000000); break; } - if (globals.session.counter == 0) { + if (globals.session.counter == 0) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "network timeout\n"); switch_sleep(5000000); break; } } } - + iks_disconnect(globals.session.parser); - iks_parser_delete (globals.session.parser); + iks_parser_delete(globals.session.parser); globals.session.authorized = 0; } RUNNING = 0; - + } - + static switch_loadable_module_interface xmpp_event_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ NULL, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ NULL, - /*.application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ NULL, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL }; -SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) +{ /* connect my internal structure to the blank pointer passed to me */ *interface = &xmpp_event_module_interface; diff --git a/src/mod/formats/mod_sndfile/mod_sndfile.c b/src/mod/formats/mod_sndfile/mod_sndfile.c index 98a4f7dc25..c76e6b0d49 100644 --- a/src/mod/formats/mod_sndfile/mod_sndfile.c +++ b/src/mod/formats/mod_sndfile/mod_sndfile.c @@ -36,7 +36,7 @@ static const char modname[] = "mod_sndfile"; struct sndfile_context { SF_INFO sfinfo; - SNDFILE* handle; + SNDFILE *handle; }; typedef struct sndfile_context sndfile_context; @@ -48,11 +48,11 @@ switch_status sndfile_file_open(switch_file_handle *handle, char *path) char *ext; if (!(ext = strrchr(path, '.'))) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Format\n"); - return SWITCH_STATUS_GENERR; - } - ext++; - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Format\n"); + return SWITCH_STATUS_GENERR; + } + ext++; + if (switch_test_flag(handle, SWITCH_FILE_FLAG_READ)) { mode += SFM_READ; @@ -97,18 +97,19 @@ switch_status sndfile_file_open(switch_file_handle *handle, char *path) } if (!strcmp(ext, "gsm")) { - context->sfinfo.format = SF_FORMAT_RAW |SF_FORMAT_GSM610; + context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_GSM610; context->sfinfo.channels = 1; context->sfinfo.samplerate = 8000; } if (!(context->handle = sf_open(path, mode, &context->sfinfo))) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Opening File [%s] [%s]\n", path, sf_strerror(context->handle)); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Opening File [%s] [%s]\n", path, + sf_strerror(context->handle)); return SWITCH_STATUS_GENERR; } switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Opening File [%s] %dhz\n", path, context->sfinfo.samplerate); - handle->samples = (unsigned int)context->sfinfo.frames; + handle->samples = (unsigned int) context->sfinfo.frames; handle->samplerate = context->sfinfo.samplerate; handle->channels = context->sfinfo.channels; handle->format = context->sfinfo.format; @@ -125,63 +126,63 @@ switch_status sndfile_file_close(switch_file_handle *handle) sndfile_context *context = handle->private; sf_close(context->handle); - + return SWITCH_STATUS_SUCCESS; } switch_status sndfile_file_seek(switch_file_handle *handle, unsigned int *cur_sample, unsigned int samples, int whence) { sndfile_context *context = handle->private; - + if (!handle->seekable) { return SWITCH_STATUS_NOTIMPL; } - *cur_sample = (unsigned int)sf_seek(context->handle, samples, whence); - + *cur_sample = (unsigned int) sf_seek(context->handle, samples, whence); + return SWITCH_STATUS_SUCCESS; } -switch_status sndfile_file_read (switch_file_handle *handle, void *data, size_t *len) +switch_status sndfile_file_read(switch_file_handle *handle, void *data, size_t *len) { size_t inlen = *len; sndfile_context *context = handle->private; - if (switch_test_flag(handle, SWITCH_FILE_DATA_RAW)) { - *len = (size_t)sf_read_raw (context->handle, data, inlen); + if (switch_test_flag(handle, SWITCH_FILE_DATA_RAW)) { + *len = (size_t) sf_read_raw(context->handle, data, inlen); } else if (switch_test_flag(handle, SWITCH_FILE_DATA_INT)) { - *len = (size_t)sf_readf_int(context->handle, (int *) data, inlen); + *len = (size_t) sf_readf_int(context->handle, (int *) data, inlen); } else if (switch_test_flag(handle, SWITCH_FILE_DATA_SHORT)) { - *len = (size_t)sf_readf_short(context->handle, (short *) data, inlen); + *len = (size_t) sf_readf_short(context->handle, (short *) data, inlen); } else if (switch_test_flag(handle, SWITCH_FILE_DATA_FLOAT)) { - *len = (size_t)sf_readf_float(context->handle, (float *) data, inlen); + *len = (size_t) sf_readf_float(context->handle, (float *) data, inlen); } else if (switch_test_flag(handle, SWITCH_FILE_DATA_DOUBLE)) { - *len = (size_t)sf_readf_double(context->handle, (double *) data, inlen); + *len = (size_t) sf_readf_double(context->handle, (double *) data, inlen); } else { - *len = (size_t)sf_readf_int(context->handle, (int *) data, inlen); + *len = (size_t) sf_readf_int(context->handle, (int *) data, inlen); } return SWITCH_STATUS_SUCCESS; } -switch_status sndfile_file_write (switch_file_handle *handle, void *data, size_t *len) +switch_status sndfile_file_write(switch_file_handle *handle, void *data, size_t *len) { size_t inlen = *len; sndfile_context *context = handle->private; - - if (switch_test_flag(handle, SWITCH_FILE_DATA_RAW)) { - *len = (size_t)sf_write_raw (context->handle, data, inlen); + + if (switch_test_flag(handle, SWITCH_FILE_DATA_RAW)) { + *len = (size_t) sf_write_raw(context->handle, data, inlen); } else if (switch_test_flag(handle, SWITCH_FILE_DATA_INT)) { - *len = (size_t)sf_writef_int(context->handle, (int *) data, inlen); + *len = (size_t) sf_writef_int(context->handle, (int *) data, inlen); } else if (switch_test_flag(handle, SWITCH_FILE_DATA_SHORT)) { - *len = (size_t)sf_writef_short(context->handle, (short *) data, inlen); + *len = (size_t) sf_writef_short(context->handle, (short *) data, inlen); } else if (switch_test_flag(handle, SWITCH_FILE_DATA_FLOAT)) { - *len = (size_t)sf_writef_float(context->handle, (float *) data, inlen); + *len = (size_t) sf_writef_float(context->handle, (float *) data, inlen); } else if (switch_test_flag(handle, SWITCH_FILE_DATA_DOUBLE)) { - *len = (size_t)sf_writef_double(context->handle, (double *) data, inlen); + *len = (size_t) sf_writef_double(context->handle, (double *) data, inlen); } else { - *len = (size_t)sf_writef_int(context->handle, (int *) data, inlen); + *len = (size_t) sf_writef_int(context->handle, (int *) data, inlen); } return SWITCH_STATUS_SUCCESS; @@ -192,60 +193,61 @@ switch_status sndfile_file_write (switch_file_handle *handle, void *data, size_t static char **supported_formats; static switch_file_interface sndfile_file_interface = { - /*.interface_name*/ modname, - /*.file_open*/ sndfile_file_open, - /*.file_close*/ sndfile_file_close, - /*.file_read*/ sndfile_file_read, - /*.file_write*/ sndfile_file_write, - /*.file_seek*/ sndfile_file_seek, - /*.extens*/ NULL, - /*.next*/ NULL, + /*.interface_name */ modname, + /*.file_open */ sndfile_file_open, + /*.file_close */ sndfile_file_close, + /*.file_read */ sndfile_file_read, + /*.file_write */ sndfile_file_write, + /*.file_seek */ sndfile_file_seek, + /*.extens */ NULL, + /*.next */ NULL, }; static switch_loadable_module_interface sndfile_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ NULL, - /*.timer_interface*/ NULL, - /*.dialplan_interface*/ NULL, - /*.codec_interface*/ NULL, - /*.application_interface*/ NULL, - /*.api_interface*/ NULL, - /*.file_interface*/ &sndfile_file_interface + /*.module_name */ modname, + /*.endpoint_interface */ NULL, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL, + /*.api_interface */ NULL, + /*.file_interface */ &sndfile_file_interface }; static switch_status setup_formats(void) { - SF_FORMAT_INFO info ; - SF_INFO sfinfo ; - char buffer [128] ; - int format, major_count, subtype_count, m, s ; - int len,x,skip; - char *extras[] = {"r8", "r16", "r24", "r32", "gsm", NULL}; + SF_FORMAT_INFO info; + SF_INFO sfinfo; + char buffer[128]; + int format, major_count, subtype_count, m, s; + int len, x, skip; + char *extras[] = { "r8", "r16", "r24", "r32", "gsm", NULL }; int exlen = (sizeof(extras) / sizeof(extras[0])); - buffer [0] = 0 ; - sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ; - if (strlen (buffer) < 1) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Line %d: could not retrieve lib version.\n", __LINE__) ; + buffer[0] = 0; + sf_command(NULL, SFC_GET_LIB_VERSION, buffer, sizeof(buffer)); + if (strlen(buffer) < 1) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Line %d: could not retrieve lib version.\n", __LINE__); return SWITCH_STATUS_FALSE; } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nLibSndFile Version : %s Supported Formats\n", buffer) ; - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "================================================================================\n"); - sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof (int)) ; - sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof (int)) ; - - sfinfo.channels = 1 ; + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nLibSndFile Version : %s Supported Formats\n", buffer); + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, + "================================================================================\n"); + sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof(int)); + sf_command(NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof(int)); + + sfinfo.channels = 1; len = ((major_count + (exlen + 2)) * sizeof(char *)); supported_formats = switch_core_permenant_alloc(len); len = 0; - for (m = 0 ; m < major_count ; m++) { + for (m = 0; m < major_count; m++) { skip = 0; - info.format = m ; - sf_command (NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof (info)) ; - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "%s (extension \"%s\")\n", info.name, info.extension) ; - for (x = 0 ; x < len ; x++) { + info.format = m; + sf_command(NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof(info)); + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "%s (extension \"%s\")\n", info.name, info.extension); + for (x = 0; x < len; x++) { if (supported_formats[x] == info.extension) { skip++; break; @@ -255,31 +257,33 @@ static switch_status setup_formats(void) supported_formats[len++] = (char *) info.extension; } format = info.format; - - for (s = 0 ; s < subtype_count ; s++) { - info.format = s ; - sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &info, sizeof (info)) ; - format = (format & SF_FORMAT_TYPEMASK) | info.format ; - sfinfo.format = format ; - if (sf_format_check (&sfinfo)) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " %s\n", info.name) ; + + for (s = 0; s < subtype_count; s++) { + info.format = s; + sf_command(NULL, SFC_GET_FORMAT_SUBTYPE, &info, sizeof(info)); + format = (format & SF_FORMAT_TYPEMASK) | info.format; + sfinfo.format = format; + if (sf_format_check(&sfinfo)) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " %s\n", info.name); } } } - for(m=0; m< exlen; m++) { + for (m = 0; m < exlen; m++) { supported_formats[len++] = extras[m]; } - - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "================================================================================\n"); + + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, + "================================================================================\n"); return SWITCH_STATUS_SUCCESS; } -SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) { +SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) +{ + - if (setup_formats() != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_FALSE; } @@ -291,4 +295,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_inte /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } - diff --git a/src/mod/timers/mod_softtimer/mod_softtimer.c b/src/mod/timers/mod_softtimer/mod_softtimer.c index c379436ab3..8da44f9064 100644 --- a/src/mod/timers/mod_softtimer/mod_softtimer.c +++ b/src/mod/timers/mod_softtimer/mod_softtimer.c @@ -71,9 +71,9 @@ static switch_status soft_timer_next(switch_timer *timer) #ifdef WINTIMER private->base.QuadPart += timer->interval * (private->freq.QuadPart / 1000); - for(;;) { + for (;;) { QueryPerformanceCounter(&private->now); - if(private->now.QuadPart >= private->base.QuadPart) { + if (private->now.QuadPart >= private->base.QuadPart) { break; } switch_yield(100); @@ -98,31 +98,27 @@ static switch_status soft_timer_destroy(switch_timer *timer) } static const switch_timer_interface soft_timer_interface = { - /*.interface_name*/ "soft", - /*.timer_init*/ soft_timer_init, - /*.timer_next*/ soft_timer_next, - /*.timer_destroy*/ soft_timer_destroy + /*.interface_name */ "soft", + /*.timer_init */ soft_timer_init, + /*.timer_next */ soft_timer_next, + /*.timer_destroy */ soft_timer_destroy }; static const switch_loadable_module_interface mod_timers_module_interface = { - /*.module_name*/ modname, - /*.endpoint_interface*/ NULL, - /*.timer_interface*/ &soft_timer_interface, - /*.switch_dialplan_interface*/ NULL, - /*.switch_codec_interface*/ NULL, - /*.switch_application_interface*/ NULL + /*.module_name */ modname, + /*.endpoint_interface */ NULL, + /*.timer_interface */ &soft_timer_interface, + /*.switch_dialplan_interface */ NULL, + /*.switch_codec_interface */ NULL, + /*.switch_application_interface */ NULL }; -SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { - +SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) +{ + /* connect my internal structure to the blank pointer passed to me */ *interface = &mod_timers_module_interface; /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } - - - - - diff --git a/src/switch.c b/src/switch.c index 36aee26d65..9e4755a150 100644 --- a/src/switch.c +++ b/src/switch.c @@ -31,7 +31,8 @@ */ #include -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ char *err = NULL; switch_event *event; @@ -47,7 +48,7 @@ int main(int argc, char *argv[]) { } } - if(err) { + if (err) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error: %s", err); exit(-1); } @@ -75,5 +76,3 @@ int main(int argc, char *argv[]) { return 0; } - - diff --git a/src/switch_buffer.c b/src/switch_buffer.c index 2008839e7a..98aba36055 100644 --- a/src/switch_buffer.c +++ b/src/switch_buffer.c @@ -41,7 +41,8 @@ SWITCH_DECLARE(switch_status) switch_buffer_create(switch_memory_pool *pool, swi { switch_buffer *new_buffer; - if ((new_buffer = switch_core_alloc(pool, sizeof(switch_buffer))) && (new_buffer->data = switch_core_alloc(pool, max_len))) { + if ((new_buffer = switch_core_alloc(pool, sizeof(switch_buffer))) + && (new_buffer->data = switch_core_alloc(pool, max_len))) { new_buffer->datalen = max_len; *buffer = new_buffer; return SWITCH_STATUS_SUCCESS; @@ -54,7 +55,7 @@ SWITCH_DECLARE(int) switch_buffer_len(switch_buffer *buffer) assert(buffer != NULL); - return (int)buffer->datalen; + return (int) buffer->datalen; } @@ -63,14 +64,14 @@ SWITCH_DECLARE(int) switch_buffer_freespace(switch_buffer *buffer) { assert(buffer != NULL); - return (int)(buffer->datalen - buffer->used); + return (int) (buffer->datalen - buffer->used); } SWITCH_DECLARE(int) switch_buffer_inuse(switch_buffer *buffer) { assert(buffer != NULL); - return (int)buffer->used; + return (int) buffer->used; } SWITCH_DECLARE(int) switch_buffer_toss(switch_buffer *buffer, size_t datalen) @@ -91,7 +92,7 @@ SWITCH_DECLARE(int) switch_buffer_toss(switch_buffer *buffer, size_t datalen) memmove(buffer->data, buffer->data + reading, buffer->datalen - reading); buffer->used -= datalen; - return (int)buffer->datalen; + return (int) buffer->datalen; } SWITCH_DECLARE(int) switch_buffer_read(switch_buffer *buffer, void *data, size_t datalen) @@ -115,7 +116,7 @@ SWITCH_DECLARE(int) switch_buffer_read(switch_buffer *buffer, void *data, size_t memmove(buffer->data, buffer->data + reading, buffer->datalen - reading); buffer->used -= reading; //printf("o %d = %d\n", reading, buffer->used); - return (int)reading; + return (int) reading; } SWITCH_DECLARE(int) switch_buffer_write(switch_buffer *buffer, void *data, size_t datalen) @@ -135,6 +136,5 @@ SWITCH_DECLARE(int) switch_buffer_write(switch_buffer *buffer, void *data, size_ buffer->used += datalen; } //printf("i %d = %d\n", datalen, buffer->used); - return (int)buffer->used; + return (int) buffer->used; } - diff --git a/src/switch_caller.c b/src/switch_caller.c index 338b6f3f22..a49eba3f72 100644 --- a/src/switch_caller.c +++ b/src/switch_caller.c @@ -36,9 +36,7 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_core_se char *caller_id_name, char *caller_id_number, char *network_addr, - char *ani, - char *ani2, - char *destination_number) + char *ani, char *ani2, char *destination_number) { @@ -75,8 +73,8 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_clone(switch_core_ return profile; } -SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile *caller_profile, char *prefix, switch_event *event) - +SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile *caller_profile, char *prefix, + switch_event *event) { char header_name[1024]; @@ -112,9 +110,7 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile } SWITCH_DECLARE(switch_caller_extension *) switch_caller_extension_new(switch_core_session *session, - char *extension_name, - char *extension_number - ) + char *extension_name, char *extension_number) { switch_caller_extension *caller_extension = NULL; @@ -130,8 +126,7 @@ SWITCH_DECLARE(switch_caller_extension *) switch_caller_extension_new(switch_cor SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session *session, switch_caller_extension *caller_extension, - char *application_name, - char *application_data) + char *application_name, char *application_data) { switch_caller_application *caller_application = NULL; @@ -142,7 +137,7 @@ SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session caller_application->application_data = switch_core_session_strdup(session, application_data); if (!caller_extension->applications) { caller_extension->applications = caller_application; - } else if(caller_extension->last_application) { + } else if (caller_extension->last_application) { caller_extension->last_application->next = caller_application; } @@ -151,6 +146,3 @@ SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session } } - - - diff --git a/src/switch_channel.c b/src/switch_channel.c index 5564f3b769..d60dca668d 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -71,7 +71,8 @@ SWITCH_DECLARE(switch_status) switch_channel_alloc(switch_channel **channel, swi return SWITCH_STATUS_SUCCESS; } -SWITCH_DECLARE(switch_status) switch_channel_set_raw_mode (switch_channel *channel, int freq, int bits, int channels, int ms, int kbps) +SWITCH_DECLARE(switch_status) switch_channel_set_raw_mode(switch_channel *channel, int freq, int bits, int channels, + int ms, int kbps) { assert(channel != NULL); @@ -86,7 +87,8 @@ SWITCH_DECLARE(switch_status) switch_channel_set_raw_mode (switch_channel *chann return SWITCH_STATUS_SUCCESS; } -SWITCH_DECLARE(switch_status) switch_channel_get_raw_mode (switch_channel *channel, int *freq, int *bits, int *channels, int *ms, int *kbps) +SWITCH_DECLARE(switch_status) switch_channel_get_raw_mode(switch_channel *channel, int *freq, int *bits, int *channels, + int *ms, int *kbps) { if (freq) { *freq = channel->freq; @@ -128,7 +130,7 @@ SWITCH_DECLARE(switch_status) switch_channel_queue_dtmf(switch_channel *channel, assert(channel != NULL); switch_mutex_lock(channel->dtmf_mutex); - if (switch_buffer_inuse(channel->dtmf_buffer) + strlen(dtmf) > (size_t)switch_buffer_len(channel->dtmf_buffer)) { + if (switch_buffer_inuse(channel->dtmf_buffer) + strlen(dtmf) > (size_t) switch_buffer_len(channel->dtmf_buffer)) { switch_buffer_toss(channel->dtmf_buffer, strlen(dtmf)); } @@ -164,8 +166,7 @@ SWITCH_DECLARE(int) switch_channel_dequeue_dtmf(switch_channel *channel, char *d SWITCH_DECLARE(switch_status) switch_channel_init(switch_channel *channel, switch_core_session *session, - switch_channel_state state, - switch_channel_flag flags) + switch_channel_state state, switch_channel_flag flags) { assert(channel != NULL); channel->state = state; @@ -277,115 +278,117 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_set_state(switch_channel *ch } /* STUB for more dev - case CS_INIT: - switch(state) { + case CS_INIT: + switch(state) { + case CS_NEW: + case CS_INIT: + case CS_LOOPBACK: + case CS_TRANSMIT: + case CS_RING: + case CS_EXECUTE: + case CS_HANGUP: + case CS_DONE: + + default: + break; + } + break; + */ + + switch (last_state) { case CS_NEW: + switch (state) { + default: + ok++; + break; + } + break; + case CS_INIT: + switch (state) { + case CS_LOOPBACK: + case CS_TRANSMIT: + case CS_RING: + case CS_EXECUTE: + case CS_HANGUP: + ok++; + default: + break; + } + break; + case CS_LOOPBACK: + switch (state) { + case CS_TRANSMIT: + case CS_RING: + case CS_EXECUTE: + case CS_HANGUP: + ok++; + default: + break; + } + break; + case CS_TRANSMIT: + switch (state) { + case CS_LOOPBACK: + case CS_RING: + case CS_EXECUTE: + case CS_HANGUP: + ok++; + default: + break; + } + break; + case CS_RING: + switch (state) { + case CS_LOOPBACK: + case CS_EXECUTE: + case CS_HANGUP: + case CS_TRANSMIT: + ok++; + default: + break; + } + break; + case CS_EXECUTE: + switch (state) { + case CS_LOOPBACK: + case CS_TRANSMIT: + case CS_RING: + case CS_HANGUP: + ok++; + default: + break; + } + break; + case CS_HANGUP: - case CS_DONE: + switch (state) { + case CS_DONE: + ok++; + default: + break; + } + break; default: - break; - } - break; - */ - - switch(last_state) { -case CS_NEW: - switch(state) { -default: - ok++; - break; - } - break; - -case CS_INIT: - switch(state) { -case CS_LOOPBACK: -case CS_TRANSMIT: -case CS_RING: -case CS_EXECUTE: -case CS_HANGUP: - ok++; -default: - break; - } - break; - -case CS_LOOPBACK: - switch(state) { -case CS_TRANSMIT: -case CS_RING: -case CS_EXECUTE: -case CS_HANGUP: - ok++; -default: - break; - } - break; - -case CS_TRANSMIT: - switch(state) { -case CS_LOOPBACK: -case CS_RING: -case CS_EXECUTE: -case CS_HANGUP: - ok++; -default: - break; - } - break; - -case CS_RING: - switch(state) { -case CS_LOOPBACK: -case CS_EXECUTE: -case CS_HANGUP: -case CS_TRANSMIT: - ok++; -default: - break; - } - break; - -case CS_EXECUTE: - switch(state) { -case CS_LOOPBACK: -case CS_TRANSMIT: -case CS_RING: -case CS_HANGUP: - ok++; -default: - break; - } - break; - -case CS_HANGUP: - switch(state) { -case CS_DONE: - ok++; -default: - break; - } - break; - -default: - break; + break; } if (ok) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s State Change %s -> %s\n", channel->name, state_names[last_state], state_names[state]); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s State Change %s -> %s\n", channel->name, + state_names[last_state], state_names[state]); channel->state = state; switch_core_session_signal_state_change(channel->session); } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Invalid State Change %s -> %s\n", channel->name, state_names[last_state], state_names[state]); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Invalid State Change %s -> %s\n", channel->name, + state_names[last_state], state_names[state]); //we won't tolerate an invalid state change so we can make sure we are as robust as a nice cup of dark coffee! if (channel->state < CS_HANGUP) { @@ -399,7 +402,7 @@ default: SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, switch_event *event) { switch_caller_profile *caller_profile, *originator_caller_profile, *originatee_caller_profile; - switch_hash_index_t* hi; + switch_hash_index_t *hi; void *val; const void *var; @@ -407,12 +410,13 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit originator_caller_profile = switch_channel_get_originator_caller_profile(channel); originatee_caller_profile = switch_channel_get_originatee_caller_profile(channel); - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State", (char *) switch_channel_state_name(channel->state)); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State", + (char *) switch_channel_state_name(channel->state)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", switch_channel_get_name(channel)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(channel->session)); - /* Index Caller's Profile */ + /* Index Caller's Profile */ if (caller_profile) { switch_caller_profile_event_set_data(caller_profile, "Caller", event); } @@ -428,7 +432,8 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit } /* Index Variables */ - for (hi = switch_hash_first(switch_core_session_get_pool(channel->session), channel->variables); hi; hi = switch_hash_next(hi)) { + for (hi = switch_hash_first(switch_core_session_get_pool(channel->session), channel->variables); hi; + hi = switch_hash_next(hi)) { char buf[1024]; switch_event_subclass *subclass; switch_hash_this(hi, &var, NULL, &val); @@ -453,13 +458,15 @@ SWITCH_DECLARE(switch_caller_profile *) switch_channel_get_caller_profile(switch return channel->caller_profile; } -SWITCH_DECLARE(void) switch_channel_set_originator_caller_profile(switch_channel *channel, switch_caller_profile *caller_profile) +SWITCH_DECLARE(void) switch_channel_set_originator_caller_profile(switch_channel *channel, + switch_caller_profile *caller_profile) { assert(channel != NULL); channel->originator_caller_profile = caller_profile; } -SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel *channel, switch_caller_profile *caller_profile) +SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel *channel, + switch_caller_profile *caller_profile) { assert(channel != NULL); channel->originatee_caller_profile = caller_profile; @@ -477,7 +484,8 @@ SWITCH_DECLARE(switch_caller_profile *) switch_channel_get_originatee_caller_pro return channel->originatee_caller_profile; } -SWITCH_DECLARE(void) switch_channel_set_event_handlers(switch_channel *channel, const struct switch_event_handler_table *event_handlers) +SWITCH_DECLARE(void) switch_channel_set_event_handlers(switch_channel *channel, + const struct switch_event_handler_table *event_handlers) { assert(channel != NULL); channel->event_handlers = event_handlers; @@ -489,7 +497,8 @@ SWITCH_DECLARE(const struct switch_event_handler_table *) switch_channel_get_eve return channel->event_handlers; } -SWITCH_DECLARE(void) switch_channel_set_caller_extension(switch_channel *channel, switch_caller_extension *caller_extension) +SWITCH_DECLARE(void) switch_channel_set_caller_extension(switch_channel *channel, + switch_caller_extension *caller_extension) { assert(channel != NULL); channel->caller_extension = caller_extension; @@ -509,7 +518,7 @@ SWITCH_DECLARE(switch_status) switch_channel_hangup(switch_channel *channel) assert(channel != NULL); if (channel->state < CS_HANGUP) { channel->state = CS_HANGUP; - switch_core_session_signal_state_change(channel->session); + switch_core_session_signal_state_change(channel->session); } return channel->state; } diff --git a/src/switch_config.c b/src/switch_config.c index 78b70f9fb5..fa05107e25 100644 --- a/src/switch_config.c +++ b/src/switch_config.c @@ -83,7 +83,7 @@ SWITCH_DECLARE(int) switch_config_next_pair(switch_config *cfg, char **var, char *var = *val = NULL; - for(;;) { + for (;;) { cfg->lineno++; if (!fgets(cfg->buf, sizeof(cfg->buf), cfg->file)) { @@ -154,6 +154,3 @@ SWITCH_DECLARE(int) switch_config_next_pair(switch_config *cfg, char **var, char return ret; } - - - diff --git a/src/switch_console.c b/src/switch_console.c index b5c381b1ab..1a2240e058 100644 --- a/src/switch_console.c +++ b/src/switch_console.c @@ -54,15 +54,10 @@ static int switch_console_process(char *cmd) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\n" "Valid Commands:\n\n" - "version\n" - "help - umm yeah..\n" - "%sshutdown - stop the program\n\n", - perlhelp - ); + "version\n" "help - umm yeah..\n" "%sshutdown - stop the program\n\n", perlhelp); return 1; } - #ifdef EMBED_PERL if (!strncmp(cmd, "perl ", 5)) { cmd += 5; @@ -71,7 +66,7 @@ static int switch_console_process(char *cmd) return 1; } #endif - if ((arg = strchr(cmd, '\r')) || (arg=strchr(cmd, '\n'))) { + if ((arg = strchr(cmd, '\r')) || (arg = strchr(cmd, '\n'))) { *arg = '\0'; arg = NULL; } @@ -79,14 +74,16 @@ static int switch_console_process(char *cmd) *arg++ = '\0'; } if (switch_api_execute(cmd, arg, retbuf, sizeof(retbuf)) == SWITCH_STATUS_SUCCESS) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "API CALL [%s(%s)] output:\n%s\n", cmd, arg ? arg : "", retbuf); + switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "API CALL [%s(%s)] output:\n%s\n", cmd, arg ? arg : "", + retbuf); } else { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Unknown Command: %s\n", cmd); } return 1; } -SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *file, const char *func, int line, char *fmt, ...) +SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *file, const char *func, int line, + char *fmt, ...) { char *data; int ret = 0; @@ -120,18 +117,18 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *fi switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); if (channel == SWITCH_CHANNEL_ID_CONSOLE) { - fprintf(handle, "[%d] %s %s:%d %s() %s", (int)getpid(), date, filep, line, func, data); + fprintf(handle, "[%d] %s %s:%d %s() %s", (int) getpid(), date, filep, line, func, data); } - else if (channel == SWITCH_CHANNEL_ID_EVENT && - switch_event_running() == SWITCH_STATUS_SUCCESS && - switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) { + else if (channel == SWITCH_CHANNEL_ID_EVENT && + switch_event_running() == SWITCH_STATUS_SUCCESS && + switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) { - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data); - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep); - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", func); - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line); - switch_event_fire(&event); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", func); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line); + switch_event_fire(&event); } free(data); } @@ -161,14 +158,14 @@ SWITCH_DECLARE(void) switch_console_loop(void) } memset(&cmd, 0, sizeof(cmd)); - for (x=0; sizeof(cmd) ;x++) { + for (x = 0; sizeof(cmd); x++) { cmd[x] = getchar(); if (cmd[x] == '\n') { cmd[x] = '\0'; break; } } - if(cmd[0]) { + if (cmd[0]) { running = switch_console_process(cmd); } } diff --git a/src/switch_core.c b/src/switch_core.c index dbb55986d5..9e4479ef73 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -35,8 +35,8 @@ #include #include -static char *embedding[] = { "", "-e", ""}; -EXTERN_C void xs_init (pTHX); +static char *embedding[] = { "", "-e", "" }; +EXTERN_C void xs_init(pTHX); #endif @@ -81,7 +81,7 @@ struct switch_core_session { void *streams[SWITCH_MAX_STREAMS]; int stream_count; - char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1]; + char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; void *private; }; @@ -100,7 +100,7 @@ struct switch_core_runtime { /* Prototypes */ static int handle_SIGINT(int sig); static int handle_SIGPIPE(int sig); -static void * SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread *thread, void *obj); +static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread *thread, void *obj); static void switch_core_standard_on_init(switch_core_session *session); static void switch_core_standard_on_hangup(switch_core_session *session); static void switch_core_standard_on_ring(switch_core_session *session); @@ -134,7 +134,7 @@ static int handle_SIGINT(int sig) } -static void db_pick_path(char *dbname, char *buf, size_t size) +static void db_pick_path(char *dbname, char *buf, size_t size) { memset(buf, 0, size); @@ -145,7 +145,7 @@ static void db_pick_path(char *dbname, char *buf, size_t size) } } -SWITCH_DECLARE(switch_core_db *) switch_core_db_open_file(char *filename) +SWITCH_DECLARE(switch_core_db *) switch_core_db_open_file(char *filename) { switch_core_db *db; char path[1024]; @@ -154,7 +154,7 @@ SWITCH_DECLARE(switch_core_db *) switch_core_db_open_file(char *filename) if (switch_core_db_open(path, &db)) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "SQL ERR [%s]\n", switch_core_db_errmsg(db)); switch_core_db_close(db); - db=NULL; + db = NULL; } return db; } @@ -186,7 +186,7 @@ SWITCH_DECLARE(switch_status) switch_core_do_perl(char *txt) } #endif -SWITCH_DECLARE (switch_status) switch_core_session_message_send(char *uuid_str, switch_core_session_message *message) +SWITCH_DECLARE(switch_status) switch_core_session_message_send(char *uuid_str, switch_core_session_message *message) { switch_core_session *session = NULL; @@ -221,7 +221,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_set_write_codec(switch_core_se return SWITCH_STATUS_SUCCESS; } -SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *codec_name, int rate, int ms, int channels, switch_codec_flag flags, const switch_codec_settings *codec_settings, switch_memory_pool *pool) +SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *codec_name, int rate, int ms, + int channels, switch_codec_flag flags, + const switch_codec_settings *codec_settings, + switch_memory_pool *pool) { const switch_codec_interface *codec_interface; const switch_codec_implementation *iptr, *implementation = NULL; @@ -236,9 +239,9 @@ SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char * return SWITCH_STATUS_GENERR; } - for(iptr = codec_interface->implementations; iptr; iptr = iptr->next) { - if ((!rate || rate == iptr->samples_per_second) && - (!ms || ms == (iptr->microseconds_per_frame / 1000)) && + for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) { + if ((!rate || rate == iptr->samples_per_second) && + (!ms || ms == (iptr->microseconds_per_frame / 1000)) && (!channels || channels == iptr->number_of_channels)) { implementation = iptr; break; @@ -263,7 +266,8 @@ SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char * return SWITCH_STATUS_SUCCESS; } else { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s Exists but not then desired implementation.\n", codec_name); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s Exists but not then desired implementation.\n", + codec_name); } return SWITCH_STATUS_NOTIMPL; @@ -276,9 +280,7 @@ SWITCH_DECLARE(switch_status) switch_core_codec_encode(switch_codec *codec, size_t decoded_data_len, int decoded_rate, void *encoded_data, - size_t *encoded_data_len, - int *encoded_rate, - unsigned int *flag) + size_t *encoded_data_len, int *encoded_rate, unsigned int *flag) { assert(codec != NULL); assert(encoded_data != NULL); @@ -299,11 +301,7 @@ SWITCH_DECLARE(switch_status) switch_core_codec_encode(switch_codec *codec, other_codec, decoded_data, decoded_data_len, - decoded_rate, - encoded_data, - encoded_data_len, - encoded_rate, - flag); + decoded_rate, encoded_data, encoded_data_len, encoded_rate, flag); } @@ -313,9 +311,7 @@ SWITCH_DECLARE(switch_status) switch_core_codec_decode(switch_codec *codec, size_t encoded_data_len, int encoded_rate, void *decoded_data, - size_t *decoded_data_len, - int *decoded_rate, - unsigned int *flag) + size_t *decoded_data_len, int *decoded_rate, unsigned int *flag) { assert(codec != NULL); @@ -337,11 +333,7 @@ SWITCH_DECLARE(switch_status) switch_core_codec_decode(switch_codec *codec, other_codec, encoded_data, encoded_data_len, - encoded_rate, - decoded_data, - decoded_data_len, - decoded_rate, - flag); + encoded_rate, decoded_data, decoded_data_len, decoded_rate, flag); } @@ -363,7 +355,8 @@ SWITCH_DECLARE(switch_status) switch_core_codec_destroy(switch_codec *codec) return SWITCH_STATUS_SUCCESS; } -SWITCH_DECLARE(switch_status) switch_core_file_open(switch_file_handle *fh, char *file_path, unsigned int flags, switch_memory_pool *pool) +SWITCH_DECLARE(switch_status) switch_core_file_open(switch_file_handle *fh, char *file_path, unsigned int flags, + switch_memory_pool *pool) { char *ext; switch_status status; @@ -398,17 +391,18 @@ SWITCH_DECLARE(switch_status) switch_core_file_read(switch_file_handle *fh, void { assert(fh != NULL); - return fh->file_interface->file_read(fh, data, (unsigned int *)len); + return fh->file_interface->file_read(fh, data, (unsigned int *) len); } SWITCH_DECLARE(switch_status) switch_core_file_write(switch_file_handle *fh, void *data, size_t *len) { assert(fh != NULL); - return fh->file_interface->file_write(fh, data, (unsigned int *)len); + return fh->file_interface->file_write(fh, data, (unsigned int *) len); } -SWITCH_DECLARE(switch_status) switch_core_file_seek(switch_file_handle *fh, unsigned int *cur_pos, unsigned int samples, int whence) +SWITCH_DECLARE(switch_status) switch_core_file_seek(switch_file_handle *fh, unsigned int *cur_pos, unsigned int samples, + int whence) { return fh->file_interface->file_seek(fh, cur_pos, samples, whence); } @@ -419,7 +413,8 @@ SWITCH_DECLARE(switch_status) switch_core_file_close(switch_file_handle *fh) } -SWITCH_DECLARE(switch_status) switch_core_timer_init(switch_timer *timer, char *timer_name, int interval, int samples, switch_memory_pool *pool) +SWITCH_DECLARE(switch_status) switch_core_timer_init(switch_timer *timer, char *timer_name, int interval, int samples, + switch_memory_pool *pool) { switch_timer_interface *timer_interface; switch_status status; @@ -498,8 +493,8 @@ static void *switch_core_service_thread(switch_thread *thread, void *obj) return NULL; #endif - while(data->running > 0) { - switch(switch_core_session_read_frame(session, &read_frame, -1, stream_id)) { + while (data->running > 0) { + switch (switch_core_session_read_frame(session, &read_frame, -1, stream_id)) { case SWITCH_STATUS_SUCCESS: break; case SWITCH_STATUS_TIMEOUT: @@ -527,13 +522,14 @@ SWITCH_DECLARE(void) switch_core_thread_session_end(switch_core_thread_session * if (thread_session->running > 0) { thread_session->running = -1; - while(thread_session->running) { + while (thread_session->running) { switch_yield(1000); } } } -SWITCH_DECLARE(void) switch_core_service_session(switch_core_session *session, switch_core_thread_session *thread_session, int stream_id) +SWITCH_DECLARE(void) switch_core_service_session(switch_core_session *session, + switch_core_thread_session *thread_session, int stream_id) { thread_session->running = 1; thread_session->objs[0] = session; @@ -548,7 +544,7 @@ SWITCH_DECLARE(switch_memory_pool *) switch_core_session_get_pool(switch_core_se /* **ONLY** alloc things with this function that **WILL NOT** outlive the session itself or expect an earth shattering KABOOM!*/ -SWITCH_DECLARE(void *)switch_core_session_alloc(switch_core_session *session, size_t memory) +SWITCH_DECLARE(void *) switch_core_session_alloc(switch_core_session *session, size_t memory) { void *ptr = NULL; assert(session != NULL); @@ -581,7 +577,8 @@ SWITCH_DECLARE(char *) switch_core_permenant_strdup(char *todup) assert(runtime.memory_pool != NULL); - if (!todup) return NULL; + if (!todup) + return NULL; len = strlen(todup) + 1; if (todup && (duped = apr_palloc(runtime.memory_pool, len))) { @@ -598,7 +595,8 @@ SWITCH_DECLARE(char *) switch_core_session_strdup(switch_core_session *session, assert(session != NULL); assert(session->pool != NULL); - if (!todup) return NULL; + if (!todup) + return NULL; len = strlen(todup) + 1; @@ -616,7 +614,8 @@ SWITCH_DECLARE(char *) switch_core_strdup(switch_memory_pool *pool, char *todup) assert(pool != NULL); assert(todup != NULL); - if (!todup) return NULL; + if (!todup) + return NULL; len = strlen(todup) + 1; if (todup && (duped = apr_palloc(pool, len))) { @@ -671,8 +670,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_s } if (endpoint_interface->io_routines->outgoing_channel) { - if ((status = endpoint_interface->io_routines->outgoing_channel(session, caller_profile, new_session)) == SWITCH_STATUS_SUCCESS) { - for (ptr = session->event_hooks.outgoing_channel; ptr ; ptr = ptr->next) { + if ((status = + endpoint_interface->io_routines->outgoing_channel(session, caller_profile, + new_session)) == SWITCH_STATUS_SUCCESS) { + for (ptr = session->event_hooks.outgoing_channel; ptr; ptr = ptr->next) { if ((status = ptr->outgoing_channel(session, caller_profile, *new_session)) != SWITCH_STATUS_SUCCESS) { break; } @@ -716,7 +717,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_answer_channel(switch_core_ses assert(session != NULL); if (session->endpoint_interface->io_routines->answer_channel) { if ((status = session->endpoint_interface->io_routines->answer_channel(session)) == SWITCH_STATUS_SUCCESS) { - for (ptr = session->event_hooks.answer_channel; ptr ; ptr = ptr->next) { + for (ptr = session->event_hooks.answer_channel; ptr; ptr = ptr->next) { if ((status = ptr->answer_channel(session)) != SWITCH_STATUS_SUCCESS) { break; } @@ -729,15 +730,17 @@ SWITCH_DECLARE(switch_status) switch_core_session_answer_channel(switch_core_ses return status; } -SWITCH_DECLARE(switch_status) switch_core_session_receive_message(switch_core_session *session, switch_core_session_message *message) +SWITCH_DECLARE(switch_status) switch_core_session_receive_message(switch_core_session *session, + switch_core_session_message *message) { struct switch_io_event_hook_receive_message *ptr; switch_status status = SWITCH_STATUS_FALSE; assert(session != NULL); if (session->endpoint_interface->io_routines->receive_message) { - if ((status = session->endpoint_interface->io_routines->receive_message(session, message)) == SWITCH_STATUS_SUCCESS) { - for (ptr = session->event_hooks.receive_message; ptr ; ptr = ptr->next) { + if ((status = + session->endpoint_interface->io_routines->receive_message(session, message)) == SWITCH_STATUS_SUCCESS) { + for (ptr = session->event_hooks.receive_message; ptr; ptr = ptr->next) { if ((status = ptr->receive_message(session, message)) != SWITCH_STATUS_SUCCESS) { break; } @@ -750,7 +753,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_receive_message(switch_core_se return status; } -SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session *session, switch_frame **frame, int timeout, int stream_id) +SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session *session, switch_frame **frame, + int timeout, int stream_id) { struct switch_io_event_hook_read_frame *ptr; switch_status status = SWITCH_STATUS_FALSE; @@ -763,8 +767,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session timeout, SWITCH_IO_FLAG_NOOP, stream_id)) == SWITCH_STATUS_SUCCESS) { - for (ptr = session->event_hooks.read_frame; ptr ; ptr = ptr->next) { - if ((status = ptr->read_frame(session, frame, timeout, SWITCH_IO_FLAG_NOOP, stream_id)) != SWITCH_STATUS_SUCCESS) { + for (ptr = session->event_hooks.read_frame; ptr; ptr = ptr->next) { + if ((status = + ptr->read_frame(session, frame, timeout, SWITCH_IO_FLAG_NOOP, + stream_id)) != SWITCH_STATUS_SUCCESS) { break; } } @@ -776,7 +782,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session } /* if you think this code is redundant.... too bad! I like to understand what I'm doing */ - if ((session->read_codec && (*frame)->codec && session->read_codec->implementation != (*frame)->codec->implementation)) { + if ((session->read_codec && (*frame)->codec + && session->read_codec->implementation != (*frame)->codec->implementation)) { need_codec = TRUE; } @@ -800,9 +807,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session read_frame->datalen, session->read_codec->implementation->samples_per_second, session->raw_read_frame.data, - &session->raw_read_frame.datalen, - &session->raw_read_frame.rate, - &flag); + &session->raw_read_frame.datalen, &session->raw_read_frame.rate, &flag); switch (status) { case SWITCH_STATUS_RESAMPLE: @@ -811,8 +816,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session read_frame->codec->implementation->samples_per_second, read_frame->codec->implementation->bytes_per_frame * 20, session->read_codec->implementation->samples_per_second, - session->read_codec->implementation->bytes_per_frame * 20, - session->pool); + session->read_codec->implementation->bytes_per_frame * 20, session->pool); } case SWITCH_STATUS_SUCCESS: read_frame = &session->raw_read_frame; @@ -821,7 +825,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session status = SWITCH_STATUS_SUCCESS; break; default: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", session->read_codec->codec_interface->interface_name); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", + session->read_codec->codec_interface->interface_name); return status; break; } @@ -829,13 +834,12 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session if (session->read_resampler) { short *data = read_frame->data; - session->read_resampler->from_len = switch_short_to_float(data, session->read_resampler->from, (int)read_frame->datalen / 2 ); - session->read_resampler->to_len = switch_resample_process(session->read_resampler, - session->read_resampler->from, - session->read_resampler->from_len, - session->read_resampler->to, - (int)session->read_resampler->to_size, - 0); + session->read_resampler->from_len = + switch_short_to_float(data, session->read_resampler->from, (int) read_frame->datalen / 2); + session->read_resampler->to_len = + switch_resample_process(session->read_resampler, session->read_resampler->from, + session->read_resampler->from_len, session->read_resampler->to, + (int) session->read_resampler->to_size, 0); switch_float_to_short(session->read_resampler->to, data, read_frame->datalen); read_frame->samples = session->read_resampler->to_len; read_frame->datalen = session->read_resampler->to_len * 2; @@ -846,7 +850,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session if ((*frame)->datalen == session->read_codec->implementation->bytes_per_frame) { perfect = TRUE; } else { - if (! session->raw_read_buffer) { + if (!session->raw_read_buffer) { int bytes = session->read_codec->implementation->bytes_per_frame * 10; switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Engaging Read Buffer at %d bytes\n", bytes); switch_buffer_create(session->pool, &session->raw_read_buffer, bytes); @@ -865,7 +869,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session } else { session->raw_read_frame.datalen = switch_buffer_read(session->raw_read_buffer, session->raw_read_frame.data, - session->read_codec->implementation->bytes_per_frame); + session->read_codec->implementation-> + bytes_per_frame); session->raw_read_frame.rate = session->read_codec->implementation->samples_per_second; enc_frame = &session->raw_read_frame; } @@ -877,8 +882,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session (*frame)->codec->implementation->samples_per_second, session->enc_read_frame.data, &session->enc_read_frame.datalen, - &session->enc_read_frame.rate, - &flag); + &session->enc_read_frame.rate, &flag); switch (status) { @@ -892,7 +896,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session status = SWITCH_STATUS_SUCCESS; break; default: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", + session->read_codec->codec_interface->interface_name); *frame = NULL; status = SWITCH_STATUS_GENERR; break; @@ -904,13 +909,17 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session return status; } -static switch_status perform_write(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) { +static switch_status perform_write(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, + int stream_id) +{ struct switch_io_event_hook_write_frame *ptr; switch_status status = SWITCH_STATUS_FALSE; if (session->endpoint_interface->io_routines->write_frame) { - if ((status = session->endpoint_interface->io_routines->write_frame(session, frame, timeout, flags, stream_id)) == SWITCH_STATUS_SUCCESS) { - for (ptr = session->event_hooks.write_frame; ptr ; ptr = ptr->next) { + if ((status = + session->endpoint_interface->io_routines->write_frame(session, frame, timeout, flags, + stream_id)) == SWITCH_STATUS_SUCCESS) { + for (ptr = session->event_hooks.write_frame; ptr; ptr = ptr->next) { if ((status = ptr->write_frame(session, frame, timeout, flags, stream_id)) != SWITCH_STATUS_SUCCESS) { break; } @@ -920,7 +929,8 @@ static switch_status perform_write(switch_core_session *session, switch_frame *f return status; } -SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_session *session, switch_frame *frame, int timeout, int stream_id) +SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_session *session, switch_frame *frame, + int timeout, int stream_id) { switch_status status = SWITCH_STATUS_FALSE; @@ -950,9 +960,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio frame->datalen, session->write_codec->implementation->samples_per_second, session->raw_write_frame.data, - &session->raw_write_frame.datalen, - &session->raw_write_frame.rate, - &flag); + &session->raw_write_frame.datalen, &session->raw_write_frame.rate, &flag); switch (status) { case SWITCH_STATUS_RESAMPLE: @@ -974,21 +982,21 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio status = SWITCH_STATUS_SUCCESS; break; default: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", + frame->codec->codec_interface->interface_name); return status; break; } - } + } if (session->write_resampler) { short *data = write_frame->data; - session->write_resampler->from_len = switch_short_to_float(data, session->write_resampler->from, (int)write_frame->datalen / 2); - session->write_resampler->to_len = switch_resample_process(session->write_resampler, - session->write_resampler->from, - session->write_resampler->from_len, - session->write_resampler->to, - (int)session->write_resampler->to_size, - 0); + session->write_resampler->from_len = + switch_short_to_float(data, session->write_resampler->from, (int) write_frame->datalen / 2); + session->write_resampler->to_len = + switch_resample_process(session->write_resampler, session->write_resampler->from, + session->write_resampler->from_len, session->write_resampler->to, + (int) session->write_resampler->to_size, 0); switch_float_to_short(session->write_resampler->to, data, write_frame->datalen * 2); write_frame->samples = session->write_resampler->to_len; write_frame->datalen = session->write_resampler->to_len * 2; @@ -1003,9 +1011,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Engaging Write Buffer at %d bytes to accomidate %d->%d\n", bytes, - write_frame->datalen, - session->write_codec->implementation->bytes_per_frame); - if ((status = switch_buffer_create(session->pool, &session->raw_write_buffer, bytes)) != SWITCH_STATUS_SUCCESS) { + write_frame->datalen, session->write_codec->implementation->bytes_per_frame); + if ((status = + switch_buffer_create(session->pool, &session->raw_write_buffer, + bytes)) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Write Buffer Failed!\n"); return status; } @@ -1026,8 +1035,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio session->write_codec->implementation->samples_per_second, session->enc_write_frame.data, &session->enc_write_frame.datalen, - &session->enc_write_frame.rate, - &flag); + &session->enc_write_frame.rate, &flag); switch (status) { case SWITCH_STATUS_RESAMPLE: @@ -1040,7 +1048,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio status = SWITCH_STATUS_SUCCESS; break; default: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", + session->read_codec->codec_interface->interface_name); write_frame = NULL; return status; break; @@ -1058,9 +1067,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio int x; for (x = 0; x < frames; x++) { if ((session->raw_write_frame.datalen = - switch_buffer_read(session->raw_write_buffer, - session->raw_write_frame.data, - bytes))) { + switch_buffer_read(session->raw_write_buffer, session->raw_write_frame.data, bytes))) { enc_frame = &session->raw_write_frame; session->raw_write_frame.rate = session->write_codec->implementation->samples_per_second; @@ -1072,8 +1079,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio frame->codec->implementation->samples_per_second, session->enc_write_frame.data, &session->enc_write_frame.datalen, - &session->enc_write_frame.rate, - &flag); + &session->enc_write_frame.rate, &flag); @@ -1084,9 +1090,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio status = switch_resample_create(&session->read_resampler, frame->codec->implementation->samples_per_second, frame->codec->implementation->bytes_per_frame * 20, - session->write_codec->implementation->samples_per_second, - session->write_codec->implementation->bytes_per_frame * 20, - session->pool); + session->write_codec->implementation-> + samples_per_second, + session->write_codec->implementation-> + bytes_per_frame * 20, session->pool); } break; case SWITCH_STATUS_SUCCESS: @@ -1097,7 +1104,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio status = SWITCH_STATUS_SUCCESS; break; default: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", + session->read_codec->codec_interface->interface_name); write_frame = NULL; return status; break; @@ -1105,16 +1113,16 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio if (session->read_resampler) { short *data = write_frame->data; - + session->read_resampler->from_len = switch_short_to_float(data, - session->read_resampler->from, - (int)write_frame->datalen / 2); - session->read_resampler->to_len = switch_resample_process(session->read_resampler, session->read_resampler->from, - session->read_resampler->from_len, - session->read_resampler->to, - (int)session->read_resampler->to_size, - 0); + (int) write_frame->datalen / + 2); + session->read_resampler->to_len = + switch_resample_process(session->read_resampler, session->read_resampler->from, + session->read_resampler->from_len, + session->read_resampler->to, + (int) session->read_resampler->to_size, 0); switch_float_to_short(session->read_resampler->to, data, write_frame->datalen * 2); write_frame->samples = session->read_resampler->to_len; write_frame->datalen = session->read_resampler->to_len * 2; @@ -1140,7 +1148,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_kill_channel(switch_core_sessi if (session->endpoint_interface->io_routines->kill_channel) { if ((status = session->endpoint_interface->io_routines->kill_channel(session, sig)) == SWITCH_STATUS_SUCCESS) { - for (ptr = session->event_hooks.kill_channel; ptr ; ptr = ptr->next) { + for (ptr = session->event_hooks.kill_channel; ptr; ptr = ptr->next) { if ((status = ptr->kill_channel(session, sig)) != SWITCH_STATUS_SUCCESS) { break; } @@ -1158,8 +1166,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_waitfor_read(switch_core_sessi switch_status status = SWITCH_STATUS_FALSE; if (session->endpoint_interface->io_routines->waitfor_read) { - if ((status = session->endpoint_interface->io_routines->waitfor_read(session, timeout, stream_id)) == SWITCH_STATUS_SUCCESS) { - for (ptr = session->event_hooks.waitfor_read; ptr ; ptr = ptr->next) { + if ((status = + session->endpoint_interface->io_routines->waitfor_read(session, timeout, + stream_id)) == SWITCH_STATUS_SUCCESS) { + for (ptr = session->event_hooks.waitfor_read; ptr; ptr = ptr->next) { if ((status = ptr->waitfor_read(session, timeout, stream_id)) != SWITCH_STATUS_SUCCESS) { break; } @@ -1171,14 +1181,17 @@ SWITCH_DECLARE(switch_status) switch_core_session_waitfor_read(switch_core_sessi } -SWITCH_DECLARE(switch_status) switch_core_session_waitfor_write(switch_core_session *session, int timeout, int stream_id) +SWITCH_DECLARE(switch_status) switch_core_session_waitfor_write(switch_core_session *session, int timeout, + int stream_id) { struct switch_io_event_hook_waitfor_write *ptr; switch_status status = SWITCH_STATUS_FALSE; if (session->endpoint_interface->io_routines->waitfor_write) { - if ((status = session->endpoint_interface->io_routines->waitfor_write(session, timeout, stream_id)) == SWITCH_STATUS_SUCCESS) { - for (ptr = session->event_hooks.waitfor_write; ptr ; ptr = ptr->next) { + if ((status = + session->endpoint_interface->io_routines->waitfor_write(session, timeout, + stream_id)) == SWITCH_STATUS_SUCCESS) { + for (ptr = session->event_hooks.waitfor_write; ptr; ptr = ptr->next) { if ((status = ptr->waitfor_write(session, timeout, stream_id)) != SWITCH_STATUS_SUCCESS) { break; } @@ -1190,14 +1203,14 @@ SWITCH_DECLARE(switch_status) switch_core_session_waitfor_write(switch_core_sess } -SWITCH_DECLARE(switch_status) switch_core_session_send_dtmf(switch_core_session *session, char *dtmf) +SWITCH_DECLARE(switch_status) switch_core_session_send_dtmf(switch_core_session *session, char *dtmf) { struct switch_io_event_hook_send_dtmf *ptr; switch_status status = SWITCH_STATUS_FALSE; if (session->endpoint_interface->io_routines->send_dtmf) { if ((status = session->endpoint_interface->io_routines->send_dtmf(session, dtmf)) == SWITCH_STATUS_SUCCESS) { - for (ptr = session->event_hooks.send_dtmf; ptr ; ptr = ptr->next) { + for (ptr = session->event_hooks.send_dtmf; ptr; ptr = ptr->next) { if ((status = ptr->send_dtmf(session, dtmf)) != SWITCH_STATUS_SUCCESS) { break; } @@ -1208,7 +1221,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_send_dtmf(switch_core_session return status; } -SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_outgoing(switch_core_session *session, switch_outgoing_channel_hook outgoing_channel) +SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_outgoing(switch_core_session *session, + switch_outgoing_channel_hook outgoing_channel) { switch_io_event_hook_outgoing_channel *hook, *ptr; @@ -1218,7 +1232,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_outgoing(switch if (!session->event_hooks.outgoing_channel) { session->event_hooks.outgoing_channel = hook; } else { - for(ptr = session->event_hooks.outgoing_channel ; ptr && ptr->next; ptr = ptr->next); + for (ptr = session->event_hooks.outgoing_channel; ptr && ptr->next; ptr = ptr->next); ptr->next = hook; } @@ -1229,7 +1243,9 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_outgoing(switch return SWITCH_STATUS_MEMERR; } -SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_answer_channel(switch_core_session *session, switch_answer_channel_hook answer_channel) +SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_answer_channel(switch_core_session *session, + switch_answer_channel_hook + answer_channel) { switch_io_event_hook_answer_channel *hook, *ptr; @@ -1239,7 +1255,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_answer_channel( if (!session->event_hooks.answer_channel) { session->event_hooks.answer_channel = hook; } else { - for(ptr = session->event_hooks.answer_channel ; ptr && ptr->next; ptr = ptr->next); + for (ptr = session->event_hooks.answer_channel; ptr && ptr->next; ptr = ptr->next); ptr->next = hook; } @@ -1251,7 +1267,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_answer_channel( } -SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_read_frame(switch_core_session *session, switch_read_frame_hook read_frame) +SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_read_frame(switch_core_session *session, + switch_read_frame_hook read_frame) { switch_io_event_hook_read_frame *hook, *ptr; @@ -1261,7 +1278,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_read_frame(swit if (!session->event_hooks.read_frame) { session->event_hooks.read_frame = hook; } else { - for(ptr = session->event_hooks.read_frame ; ptr && ptr->next; ptr = ptr->next); + for (ptr = session->event_hooks.read_frame; ptr && ptr->next; ptr = ptr->next); ptr->next = hook; } @@ -1273,7 +1290,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_read_frame(swit } -SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_write_frame(switch_core_session *session, switch_write_frame_hook write_frame) +SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_write_frame(switch_core_session *session, + switch_write_frame_hook write_frame) { switch_io_event_hook_write_frame *hook, *ptr; @@ -1283,7 +1301,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_write_frame(swi if (!session->event_hooks.write_frame) { session->event_hooks.write_frame = hook; } else { - for(ptr = session->event_hooks.write_frame ; ptr && ptr->next; ptr = ptr->next); + for (ptr = session->event_hooks.write_frame; ptr && ptr->next; ptr = ptr->next); ptr->next = hook; } @@ -1295,7 +1313,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_write_frame(swi } -SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_kill_channel(switch_core_session *session, switch_kill_channel_hook kill_channel) +SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_kill_channel(switch_core_session *session, + switch_kill_channel_hook kill_channel) { switch_io_event_hook_kill_channel *hook, *ptr; @@ -1305,7 +1324,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_kill_channel(sw if (!session->event_hooks.kill_channel) { session->event_hooks.kill_channel = hook; } else { - for(ptr = session->event_hooks.kill_channel ; ptr && ptr->next; ptr = ptr->next); + for (ptr = session->event_hooks.kill_channel; ptr && ptr->next; ptr = ptr->next); ptr->next = hook; } @@ -1317,7 +1336,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_kill_channel(sw } -SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_read(switch_core_session *session, switch_waitfor_read_hook waitfor_read) +SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_read(switch_core_session *session, + switch_waitfor_read_hook waitfor_read) { switch_io_event_hook_waitfor_read *hook, *ptr; @@ -1327,7 +1347,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_read(sw if (!session->event_hooks.waitfor_read) { session->event_hooks.waitfor_read = hook; } else { - for(ptr = session->event_hooks.waitfor_read ; ptr && ptr->next; ptr = ptr->next); + for (ptr = session->event_hooks.waitfor_read; ptr && ptr->next; ptr = ptr->next); ptr->next = hook; } @@ -1339,7 +1359,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_read(sw } -SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_write(switch_core_session *session, switch_waitfor_write_hook waitfor_write) +SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_write(switch_core_session *session, + switch_waitfor_write_hook waitfor_write) { switch_io_event_hook_waitfor_write *hook, *ptr; @@ -1349,7 +1370,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_write(s if (!session->event_hooks.waitfor_write) { session->event_hooks.waitfor_write = hook; } else { - for(ptr = session->event_hooks.waitfor_write ; ptr && ptr->next; ptr = ptr->next); + for (ptr = session->event_hooks.waitfor_write; ptr && ptr->next; ptr = ptr->next); ptr->next = hook; } @@ -1362,7 +1383,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_write(s } -SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_send_dtmf(switch_core_session *session, switch_send_dtmf_hook send_dtmf) +SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_send_dtmf(switch_core_session *session, + switch_send_dtmf_hook send_dtmf) { switch_io_event_hook_send_dtmf *hook, *ptr; @@ -1372,7 +1394,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_send_dtmf(switc if (!session->event_hooks.send_dtmf) { session->event_hooks.send_dtmf = hook; } else { - for(ptr = session->event_hooks.send_dtmf ; ptr && ptr->next; ptr = ptr->next); + for (ptr = session->event_hooks.send_dtmf; ptr && ptr->next; ptr = ptr->next); ptr->next = hook; } @@ -1459,16 +1481,21 @@ static void switch_core_standard_on_execute(switch_core_session *session) } while (switch_channel_get_state(session->channel) == CS_EXECUTE && extension->current_application) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Execute %s(%s)\n", extension->current_application->application_name, + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Execute %s(%s)\n", + extension->current_application->application_name, extension->current_application->application_data); - if (!(application_interface = switch_loadable_module_get_application_interface(extension->current_application->application_name))) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Application %s\n", extension->current_application->application_name); + if (! + (application_interface = + switch_loadable_module_get_application_interface(extension->current_application->application_name))) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Application %s\n", + extension->current_application->application_name); switch_channel_set_state(session->channel, CS_HANGUP); return; } if (!application_interface->application_function) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Function for %s\n", extension->current_application->application_name); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Function for %s\n", + extension->current_application->application_name); switch_channel_set_state(session->channel, CS_HANGUP); return; } @@ -1489,7 +1516,7 @@ static void switch_core_standard_on_loopback(switch_core_session *session) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Standard LOOPBACK\n"); while ((state = switch_channel_get_state(session->channel)) == CS_LOOPBACK) { - for(stream_id = 0; stream_id < session->stream_count; stream_id++) { + for (stream_id = 0; stream_id < session->stream_count; stream_id++) { if (switch_core_session_read_frame(session, &frame, -1, stream_id) == SWITCH_STATUS_SUCCESS) { switch_core_session_write_frame(session, frame, -1, stream_id); } @@ -1516,20 +1543,20 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) const switch_event_handler_table *application_event_handlers = NULL; /* - Life of the channel. you have channel and pool in your session - everywhere you go you use the session to malloc with - switch_core_session_alloc(session, ) + Life of the channel. you have channel and pool in your session + everywhere you go you use the session to malloc with + switch_core_session_alloc(session, ) - The enpoint module gets the first crack at implementing the state - if it wants to, it can cancel the default behaviour by returning SWITCH_STATUS_FALSE + The enpoint module gets the first crack at implementing the state + if it wants to, it can cancel the default behaviour by returning SWITCH_STATUS_FALSE - Next comes the channel's event handler table that can be set by an application - which also can veto the next behaviour in line by returning SWITCH_STATUS_FALSE + Next comes the channel's event handler table that can be set by an application + which also can veto the next behaviour in line by returning SWITCH_STATUS_FALSE - Finally the default state behaviour is called. + Finally the default state behaviour is called. - */ + */ assert(session != NULL); application_event_handlers = switch_channel_get_event_handlers(session->channel); @@ -1552,93 +1579,93 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) switch_event_fire(&event); } - switch ( state ) { - case CS_NEW: /* Just created, Waiting for first instructions */ + switch (state) { + case CS_NEW: /* Just created, Waiting for first instructions */ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State NEW\n"); break; case CS_DONE: continue; break; - case CS_HANGUP: /* Deactivate and end the thread */ + case CS_HANGUP: /* Deactivate and end the thread */ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State HANGUP\n"); if (!driver_event_handlers->on_hangup || (driver_event_handlers->on_hangup && - driver_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS && + driver_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS && midstate == switch_channel_get_state(session->channel))) { if (!application_event_handlers || !application_event_handlers->on_hangup || (application_event_handlers->on_hangup && - application_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS && + application_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS && midstate == switch_channel_get_state(session->channel))) { switch_core_standard_on_hangup(session); } } switch_channel_set_state(session->channel, CS_DONE); break; - case CS_INIT: /* Basic setup tasks */ + case CS_INIT: /* Basic setup tasks */ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State INIT\n"); if (!driver_event_handlers->on_init || (driver_event_handlers->on_init && - driver_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS && + driver_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS && midstate == switch_channel_get_state(session->channel))) { if (!application_event_handlers || !application_event_handlers->on_init || (application_event_handlers->on_init && - application_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS && + application_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS && midstate == switch_channel_get_state(session->channel))) { switch_core_standard_on_init(session); } } break; - case CS_RING: /* Look for a dialplan and find something to do */ + case CS_RING: /* Look for a dialplan and find something to do */ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State RING\n"); if (!driver_event_handlers->on_ring || (driver_event_handlers->on_ring && - driver_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS && + driver_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS && midstate == switch_channel_get_state(session->channel))) { if (!application_event_handlers || !application_event_handlers->on_ring || (application_event_handlers->on_ring && - application_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS && + application_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS && midstate == switch_channel_get_state(session->channel))) { switch_core_standard_on_ring(session); } } break; - case CS_EXECUTE: /* Execute an Operation*/ + case CS_EXECUTE: /* Execute an Operation */ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State EXECUTE\n"); if (!driver_event_handlers->on_execute || (driver_event_handlers->on_execute && - driver_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS && + driver_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS && midstate == switch_channel_get_state(session->channel))) { if (!application_event_handlers || !application_event_handlers->on_execute || (application_event_handlers->on_execute && - application_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS && + application_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS && midstate == switch_channel_get_state(session->channel))) { switch_core_standard_on_execute(session); } } break; - case CS_LOOPBACK: /* loop all data back to source */ + case CS_LOOPBACK: /* loop all data back to source */ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State LOOPBACK\n"); if (!driver_event_handlers->on_loopback || (driver_event_handlers->on_loopback && - driver_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS && + driver_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS && midstate == switch_channel_get_state(session->channel))) { if (!application_event_handlers || !application_event_handlers->on_loopback || (application_event_handlers->on_loopback && - application_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS && + application_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS && midstate == switch_channel_get_state(session->channel))) { switch_core_standard_on_loopback(session); } } break; - case CS_TRANSMIT: /* send/recieve data to/from another channel */ + case CS_TRANSMIT: /* send/recieve data to/from another channel */ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State TRANSMIT\n"); if (!driver_event_handlers->on_transmit || (driver_event_handlers->on_transmit && - driver_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS && + driver_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS && midstate == switch_channel_get_state(session->channel))) { if (!application_event_handlers || !application_event_handlers->on_transmit || (application_event_handlers->on_transmit && - application_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS && + application_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS && midstate == switch_channel_get_state(session->channel))) { switch_core_standard_on_transmit(session); } @@ -1741,17 +1768,12 @@ SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void } ts->objs[0] = obj; - switch_thread_create(&thread, - thd_attr, - func, - ts, - pool - ); + switch_thread_create(&thread, thd_attr, func, ts, pool); } } -static void * SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread *thread, void *obj) +static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread *thread, void *obj) { switch_core_session *session = obj; @@ -1759,7 +1781,7 @@ static void * SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread *threa session->thread = thread; session->id = runtime.session_id++; - if(runtime.session_id >= sizeof(unsigned long)) + if (runtime.session_id >= sizeof(unsigned long)) runtime.session_id = 1; snprintf(session->name, sizeof(session->name), "%ld", session->id); @@ -1781,30 +1803,21 @@ SWITCH_DECLARE(void) switch_core_session_thread_launch(switch_core_session *sess switch_threadattr_create(&thd_attr, session->pool); switch_threadattr_detach_set(thd_attr, 1); - if (switch_thread_create(&thread, - thd_attr, - switch_core_session_thread, - session, - session->pool - ) != APR_SUCCESS) { + if (switch_thread_create(&thread, thd_attr, switch_core_session_thread, session, session->pool) != APR_SUCCESS) { switch_core_session_destroy(&session); } } -SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session *session, switch_thread_start_t func, void *obj) +SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session *session, switch_thread_start_t func, + void *obj) { switch_thread *thread; switch_threadattr_t *thd_attr = NULL; switch_threadattr_create(&thd_attr, session->pool); switch_threadattr_detach_set(thd_attr, 1); - switch_thread_create(&thread, - thd_attr, - func, - obj, - session->pool - ); + switch_thread_create(&thread, thd_attr, func, obj, session->pool); } @@ -1820,7 +1833,8 @@ SWITCH_DECLARE(void *) switch_core_alloc(switch_memory_pool *pool, size_t memory return ptr; } -SWITCH_DECLARE(switch_core_session *) switch_core_session_request(const switch_endpoint_interface *endpoint_interface, switch_memory_pool *pool) +SWITCH_DECLARE(switch_core_session *) switch_core_session_request(const switch_endpoint_interface *endpoint_interface, + switch_memory_pool *pool) { switch_memory_pool *usepool; switch_core_session *session; @@ -1869,7 +1883,7 @@ SWITCH_DECLARE(switch_core_session *) switch_core_session_request(const switch_e session->enc_read_frame.data = session->enc_read_buf; session->enc_read_frame.buflen = sizeof(session->enc_read_buf); - switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED ,session->pool); + switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool); switch_thread_cond_create(&session->cond, session->pool); return session; @@ -1888,11 +1902,11 @@ SWITCH_DECLARE(switch_core_session *) switch_core_session_request_by_name(char * } -static void core_event_handler (switch_event *event) +static void core_event_handler(switch_event *event) { char buf[1024]; - switch(event->event_id) { + switch (event->event_id) { case SWITCH_EVENT_LOG: return; break; @@ -1936,13 +1950,14 @@ SWITCH_DECLARE(switch_status) switch_core_init(void) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Opening DB!\n"); } else { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Opening DB\n"); - if (switch_event_bind("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL) != SWITCH_STATUS_SUCCESS) { + if (switch_event_bind("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL) != + SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't bind event handler!\n"); } } #ifdef EMBED_PERL - if (! (my_perl = perl_alloc())) { + if (!(my_perl = perl_alloc())) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate perl intrepreter\n"); switch_core_destroy(); return SWITCH_STATUS_MEMERR; @@ -1961,12 +1976,12 @@ SWITCH_DECLARE(switch_status) switch_core_init(void) switch_core_hash_init(&runtime.session_table, runtime.memory_pool); /* set signal handlers and startup time */ - (void) signal(SIGINT,(void *) handle_SIGINT); + (void) signal(SIGINT, (void *) handle_SIGINT); #ifdef SIGPIPE - (void) signal(SIGPIPE,(void *) handle_SIGPIPE); + (void) signal(SIGPIPE, (void *) handle_SIGPIPE); #endif #ifdef TRAP_BUS - (void) signal(SIGBUS,(void *) handle_SIGBUS); + (void) signal(SIGBUS, (void *) handle_SIGBUS); #endif time(&runtime.initiated); @@ -2000,4 +2015,3 @@ SWITCH_DECLARE(switch_status) switch_core_destroy(void) return SWITCH_STATUS_SUCCESS; } - diff --git a/src/switch_event.c b/src/switch_event.c index aa9e7c5fd8..96b538d10b 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -31,7 +31,7 @@ */ #include -static switch_event_node *EVENT_NODES[SWITCH_EVENT_ALL+1] = {NULL}; +static switch_event_node *EVENT_NODES[SWITCH_EVENT_ALL + 1] = { NULL }; static switch_mutex_t *BLOCK = NULL; static switch_mutex_t *POOL_LOCK = NULL; static switch_memory_pool *RUNTIME_POOL = NULL; @@ -59,10 +59,10 @@ static void *locked_alloc(size_t len) void *mem; switch_mutex_lock(POOL_LOCK); - /* -----------------------------------------------*/ + /* ----------------------------------------------- */ mem = switch_core_alloc(THRUNTIME_POOL, len); switch_mutex_unlock(POOL_LOCK); - /* ----------------------------------------------*/ + /* ---------------------------------------------- */ return mem; } @@ -72,13 +72,14 @@ static void *locked_dup(char *str) char *dup; switch_mutex_lock(POOL_LOCK); - /* -----------------------------------------------*/ + /* ----------------------------------------------- */ dup = switch_core_strdup(THRUNTIME_POOL, str); switch_mutex_unlock(POOL_LOCK); - /* ----------------------------------------------*/ + /* ---------------------------------------------- */ return dup; } + #define ALLOC(size) locked_alloc(size) #define DUP(str) locked_dup(str) #endif @@ -139,7 +140,7 @@ static int switch_events_match(switch_event *event, switch_event_node *node) return match; } -static void * SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void *obj) +static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void *obj) { switch_event_node *node; switch_event *out_event = NULL; @@ -149,11 +150,11 @@ static void * SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void assert(POOL_LOCK != NULL); assert(RUNTIME_POOL != NULL); THREAD_RUNNING = 1; - while(THREAD_RUNNING == 1 || switch_queue_size(EVENT_QUEUE)) { + while (THREAD_RUNNING == 1 || switch_queue_size(EVENT_QUEUE)) { #ifdef MALLOC_EVENTS switch_mutex_lock(POOL_LOCK); - /* -----------------------------------------------*/ + /* ----------------------------------------------- */ if (POOL_COUNT >= POOL_COUNT_MAX) { if (THRUNTIME_POOL == APOOL) { THRUNTIME_POOL = BPOOL; @@ -164,14 +165,14 @@ static void * SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void POOL_COUNT = 0; } switch_mutex_unlock(POOL_LOCK); - /* -----------------------------------------------*/ + /* ----------------------------------------------- */ #endif while (switch_queue_trypop(EVENT_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) { out_event = pop; - for(e = out_event->event_id;; e = SWITCH_EVENT_ALL) { - for(node = EVENT_NODES[e]; node; node = node->next) { + for (e = out_event->event_id;; e = SWITCH_EVENT_ALL) { + for (node = EVENT_NODES[e]; node; node = node->next) { if (switch_events_match(out_event, node)) { out_event->bind_user_data = node->user_data; node->callback(out_event); @@ -234,7 +235,7 @@ SWITCH_DECLARE(switch_status) switch_event_shutdown(void) { THREAD_RUNNING = -1; - while(THREAD_RUNNING) { + while (THREAD_RUNNING) { switch_yield(1000); } return SWITCH_STATUS_SUCCESS; @@ -267,31 +268,26 @@ SWITCH_DECLARE(switch_status) switch_event_init(switch_memory_pool *pool) switch_mutex_init(&BLOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL); switch_mutex_init(&POOL_LOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL); switch_core_hash_init(&CUSTOM_HASH, RUNTIME_POOL); - switch_thread_create(&thread, - thd_attr, - switch_event_thread, - NULL, - RUNTIME_POOL - ); + switch_thread_create(&thread, thd_attr, switch_event_thread, NULL, RUNTIME_POOL); - while(!THREAD_RUNNING) { + while (!THREAD_RUNNING) { switch_yield(1000); } return SWITCH_STATUS_SUCCESS; } -SWITCH_DECLARE(switch_status) switch_event_create_subclass(switch_event **event, switch_event_t event_id, char *subclass_name) +SWITCH_DECLARE(switch_status) switch_event_create_subclass(switch_event **event, switch_event_t event_id, + char *subclass_name) { if (event_id != SWITCH_EVENT_CUSTOM && subclass_name) { return SWITCH_STATUS_GENERR; } - if(!(*event = ALLOC(sizeof(switch_event)))) { + if (!(*event = ALLOC(sizeof(switch_event)))) { return SWITCH_STATUS_MEMERR; } - #ifdef MALLOC_EVENTS memset(*event, 0, sizeof(switch_event)); #endif @@ -309,7 +305,7 @@ SWITCH_DECLARE(char *) switch_event_get_header(switch_event *event, char *header { switch_event_header *hp; if (header_name) { - for(hp = event->headers; hp; hp = hp->next) { + for (hp = event->headers; hp; hp = hp->next) { if (!strcasecmp(hp->name, header_name)) { return hp->value; } @@ -318,7 +314,8 @@ SWITCH_DECLARE(char *) switch_event_get_header(switch_event *event, char *header return NULL; } -SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name, char *fmt, ...) +SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name, + char *fmt, ...) { int ret = 0; char data[2048]; @@ -459,7 +456,7 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char * } for (hp = event->headers; hp; hp = hp->next) { - snprintf(buf+len, buflen-len, "%s: %s\n", hp->name, hp->value); + snprintf(buf + len, buflen - len, "%s: %s\n", hp->name, hp->value); len = strlen(buf); } @@ -471,14 +468,14 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char * } if (body) { - int blen = (int)strlen(body); + int blen = (int) strlen(body); if (blen) { - snprintf(buf+len, buflen-len, "Content-Length: %d\n\n%s", blen, body); + snprintf(buf + len, buflen - len, "Content-Length: %d\n\n%s", blen, body); } else { - snprintf(buf+len, buflen-len, "\n"); + snprintf(buf + len, buflen - len, "\n"); } } else { - snprintf(buf+len, buflen-len, "\n"); + snprintf(buf + len, buflen - len, "\n"); } if (data) { @@ -489,7 +486,8 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char * } -SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func, int line, switch_event **event, void *user_data) +SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func, int line, switch_event **event, + void *user_data) { switch_time_exp_t tm; @@ -535,7 +533,8 @@ SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func, return SWITCH_STATUS_SUCCESS; } -SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event, char *subclass_name, switch_event_callback_t callback, void *user_data) +SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event, char *subclass_name, + switch_event_callback_t callback, void *user_data) { switch_event_node *event_node; switch_event_subclass *subclass = NULL; @@ -556,7 +555,7 @@ SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event, if (event <= SWITCH_EVENT_ALL && (event_node = switch_core_alloc(RUNTIME_POOL, sizeof(switch_event_node)))) { switch_mutex_lock(BLOCK); - /* -----------------------------------------------*/ + /* ----------------------------------------------- */ event_node->id = switch_core_strdup(RUNTIME_POOL, id); event_node->event_id = event; event_node->subclass = subclass; @@ -569,10 +568,9 @@ SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event, EVENT_NODES[event] = event_node; switch_mutex_unlock(BLOCK); - /* -----------------------------------------------*/ + /* ----------------------------------------------- */ return SWITCH_STATUS_SUCCESS; } return SWITCH_STATUS_MEMERR; } - diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 2f0ad5d22d..8c82e9af87 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -91,7 +91,8 @@ static void *switch_loadable_module_exec(switch_thread *thread, void *obj) return NULL; } -static switch_status switch_loadable_module_load_file(char *filename, switch_memory_pool *pool, switch_loadable_module **new_module) +static switch_status switch_loadable_module_load_file(char *filename, switch_memory_pool *pool, + switch_loadable_module **new_module) { switch_loadable_module *module = NULL; apr_dso_handle_t *dso = NULL; @@ -129,7 +130,7 @@ static switch_status switch_loadable_module_load_file(char *filename, switch_mem break; } - if (! (module = switch_core_permenant_alloc( sizeof(switch_loadable_module) ))) { + if (!(module = switch_core_permenant_alloc(sizeof(switch_loadable_module)))) { err = "Could not allocate memory\n"; break; } @@ -192,7 +193,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init() char *ptr; apr_finfo_t finfo; apr_dir_t *module_dir_handle; - apr_int32_t finfo_flags = APR_FINFO_DIRENT|APR_FINFO_TYPE|APR_FINFO_NAME; + apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME; switch_loadable_module *new_module; #ifdef WIN32 const char *ext = ".dll"; @@ -250,9 +251,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init() const switch_endpoint_interface *ptr; for (ptr = new_module->interface->endpoint_interface; ptr; ptr = ptr->next) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Endpoint '%s'\n", ptr->interface_name); - switch_core_hash_insert(loadable_modules.endpoint_hash, - (char *) ptr->interface_name, - (void *) ptr); + switch_core_hash_insert(loadable_modules.endpoint_hash, (char *) ptr->interface_name, (void *) ptr); } } @@ -260,76 +259,64 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init() const switch_codec_implementation *impl; const switch_codec_interface *ptr; - for(ptr = new_module->interface->codec_interface; ptr; ptr = ptr->next) { - for(impl = ptr->implementations; impl ; impl = impl->next) { + for (ptr = new_module->interface->codec_interface; ptr; ptr = ptr->next) { + for (impl = ptr->implementations; impl; impl = impl->next) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, - "Adding Codec '%s' (%s) %dkhz %dms\n", - ptr->iananame, - ptr->interface_name, - impl->samples_per_second, - impl->microseconds_per_frame / 1000); + "Adding Codec '%s' (%s) %dkhz %dms\n", + ptr->iananame, + ptr->interface_name, + impl->samples_per_second, impl->microseconds_per_frame / 1000); } - switch_core_hash_insert(loadable_modules.codec_hash, - (char *) ptr->iananame, - (void *) ptr); + switch_core_hash_insert(loadable_modules.codec_hash, (char *) ptr->iananame, (void *) ptr); } } if (new_module->interface->dialplan_interface) { const switch_dialplan_interface *ptr; - for(ptr = new_module->interface->dialplan_interface; ptr; ptr = ptr->next) { + for (ptr = new_module->interface->dialplan_interface; ptr; ptr = ptr->next) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Dialplan '%s'\n", ptr->interface_name); - switch_core_hash_insert(loadable_modules.dialplan_hash, - (char *) ptr->interface_name, - (void *) ptr); + switch_core_hash_insert(loadable_modules.dialplan_hash, (char *) ptr->interface_name, (void *) ptr); } } if (new_module->interface->timer_interface) { const switch_timer_interface *ptr; - for(ptr = new_module->interface->timer_interface; ptr; ptr = ptr->next) { + for (ptr = new_module->interface->timer_interface; ptr; ptr = ptr->next) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Timer '%s'\n", ptr->interface_name); - switch_core_hash_insert(loadable_modules.timer_hash, - (char *) ptr->interface_name, - (void *) ptr); + switch_core_hash_insert(loadable_modules.timer_hash, (char *) ptr->interface_name, (void *) ptr); } } if (new_module->interface->application_interface) { const switch_application_interface *ptr; - for(ptr = new_module->interface->application_interface; ptr; ptr = ptr->next) { + for (ptr = new_module->interface->application_interface; ptr; ptr = ptr->next) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Application '%s'\n", ptr->interface_name); switch_core_hash_insert(loadable_modules.application_hash, - (char *) ptr->interface_name, - (void *) ptr); + (char *) ptr->interface_name, (void *) ptr); } } if (new_module->interface->api_interface) { const switch_api_interface *ptr; - for(ptr = new_module->interface->api_interface; ptr; ptr = ptr->next) { + for (ptr = new_module->interface->api_interface; ptr; ptr = ptr->next) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding API Function '%s'\n", ptr->interface_name); - switch_core_hash_insert(loadable_modules.api_hash, - (char *) ptr->interface_name, - (void *) ptr); + switch_core_hash_insert(loadable_modules.api_hash, (char *) ptr->interface_name, (void *) ptr); } } if (new_module->interface->file_interface) { const switch_file_interface *ptr; - for(ptr = new_module->interface->file_interface; ptr; ptr = ptr->next) { + for (ptr = new_module->interface->file_interface; ptr; ptr = ptr->next) { int i; - for (i = 0 ; ptr->extens[i]; i++) { + for (i = 0; ptr->extens[i]; i++) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding File Format '%s'\n", ptr->extens[i]); - switch_core_hash_insert(loadable_modules.file_hash, - (char *) ptr->extens[i], - (void *) ptr); + switch_core_hash_insert(loadable_modules.file_hash, (char *) ptr->extens[i], (void *) ptr); } } } @@ -344,7 +331,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init() SWITCH_DECLARE(void) switch_loadable_module_shutdown(void) { - switch_hash_index_t* hi; + switch_hash_index_t *hi; void *val; switch_loadable_module *module; @@ -397,9 +384,10 @@ SWITCH_DECLARE(switch_file_interface *) switch_loadable_module_get_file_interfac return switch_core_hash_find(loadable_modules.file_hash, name); } -SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool *pool, switch_codec_interface **array, int arraylen) +SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool *pool, switch_codec_interface **array, + int arraylen) { - switch_hash_index_t* hi; + switch_hash_index_t *hi; void *val; int i = 0; @@ -415,12 +403,13 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool *pool, } -SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(switch_memory_pool *pool, switch_codec_interface **array, int arraylen, char **prefs, int preflen) +SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(switch_memory_pool *pool, switch_codec_interface **array, + int arraylen, char **prefs, int preflen) { int x, i = 0; switch_codec_interface *codec_interface; - for(x = 0; x < preflen; x++) { + for (x = 0; x < preflen; x++) { if ((codec_interface = switch_loadable_module_get_codec_interface(prefs[x]))) { array[i++] = codec_interface; } diff --git a/src/switch_mutex.c b/src/switch_mutex.c index 00a69150c7..8cb9b6c4a3 100644 --- a/src/switch_mutex.c +++ b/src/switch_mutex.c @@ -31,9 +31,7 @@ */ #include -SWITCH_DECLARE(switch_status) switch_mutex_init(switch_mutex_t **lock, - switch_lock_flag flags, - switch_memory_pool *pool) +SWITCH_DECLARE(switch_status) switch_mutex_init(switch_mutex_t **lock, switch_lock_flag flags, switch_memory_pool *pool) { return (apr_thread_mutex_create(lock, flags, pool) == APR_SUCCESS) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_GENERR; @@ -58,5 +56,3 @@ SWITCH_DECLARE(switch_status) switch_mutex_trylock(switch_mutex_t *lock) { return apr_thread_mutex_trylock(lock); } - - diff --git a/src/switch_resample.c b/src/switch_resample.c index 0a98df78bf..64f0285db0 100644 --- a/src/switch_resample.c +++ b/src/switch_resample.c @@ -49,9 +49,7 @@ SWITCH_DECLARE(switch_status) switch_resample_create(switch_audio_resampler **new_resampler, int from_rate, size_t from_size, - int to_rate, - size_t to_size, - switch_memory_pool *pool) + int to_rate, size_t to_size, switch_memory_pool *pool) { switch_audio_resampler *resampler; @@ -61,10 +59,11 @@ SWITCH_DECLARE(switch_status) switch_resample_create(switch_audio_resampler **ne resampler->from_rate = from_rate; resampler->to_rate = to_rate; - resampler->factor = ((double)resampler->to_rate / (double)resampler->from_rate); + resampler->factor = ((double) resampler->to_rate / (double) resampler->from_rate); resampler->resampler = resample_open(QUALITY, resampler->factor, resampler->factor); - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Resampler %d->%d %f\n", resampler->from_rate, resampler->to_rate, resampler->factor); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Resampler %d->%d %f\n", resampler->from_rate, + resampler->to_rate, resampler->factor); resampler->from_size = from_size; resampler->from = (float *) switch_core_alloc(pool, resampler->from_size); resampler->to_size = to_size; @@ -75,14 +74,16 @@ SWITCH_DECLARE(switch_status) switch_resample_create(switch_audio_resampler **ne } -SWITCH_DECLARE(int) switch_resample_process(switch_audio_resampler *resampler, float *src, int srclen, float *dst, int dstlen, int last) +SWITCH_DECLARE(int) switch_resample_process(switch_audio_resampler *resampler, float *src, int srclen, float *dst, + int dstlen, int last) { - int o=0, srcused=0, srcpos=0, out=0; + int o = 0, srcused = 0, srcpos = 0, out = 0; - for(;;) { - int srcBlock = MIN(srclen-srcpos, srclen); - int lastFlag = (last && (srcBlock == srclen-srcpos)); - o = resample_process(resampler->resampler, resampler->factor, &src[srcpos], srcBlock, lastFlag, &srcused, &dst[out], dstlen-out); + for (;;) { + int srcBlock = MIN(srclen - srcpos, srclen); + int lastFlag = (last && (srcBlock == srclen - srcpos)); + o = resample_process(resampler->resampler, resampler->factor, &src[srcpos], srcBlock, lastFlag, &srcused, + &dst[out], dstlen - out); //printf("resampling %d/%d (%d) %d %f\n", srcpos, srclen, MIN(dstlen-out, dstlen), srcused, factor); srcpos += srcused; @@ -106,15 +107,17 @@ SWITCH_DECLARE(size_t) switch_float_to_short(float *f, short *s, size_t len) { size_t i; float ft; - for(i=0;i= 0) { - s[i] = (short)(ft+0.5); + if (ft >= 0) { + s[i] = (short) (ft + 0.5); } else { - s[i] = (short)(ft-0.5); + s[i] = (short) (ft - 0.5); } - if ((float)s[i] > MAXSAMPLE) s[i] = (short)MAXSAMPLE; - if (s[i] < (short)-MAXSAMPLE) s[i] = (short)-MAXSAMPLE; + if ((float) s[i] > MAXSAMPLE) + s[i] = (short) MAXSAMPLE; + if (s[i] < (short) -MAXSAMPLE) + s[i] = (short) -MAXSAMPLE; } return len; } @@ -124,16 +127,18 @@ SWITCH_DECLARE(int) switch_char_to_float(char *c, float *f, int len) int i; if (len % 2) { - return(-1); + return (-1); } - for(i=1;i MAXSAMPLE) f[(int)(i/2)] = MAXSAMPLE; - if (f[(int)(i/2)] < -MAXSAMPLE) f[(int)(i/2)] = -MAXSAMPLE; + for (i = 1; i < len; i += 2) { + f[(int) (i / 2)] = (float) (((c[i]) * 0x100) + c[i - 1]); + f[(int) (i / 2)] /= NORMFACT; + if (f[(int) (i / 2)] > MAXSAMPLE) + f[(int) (i / 2)] = MAXSAMPLE; + if (f[(int) (i / 2)] < -MAXSAMPLE) + f[(int) (i / 2)] = -MAXSAMPLE; } - return len/2; + return len / 2; } SWITCH_DECLARE(int) switch_float_to_char(float *f, char *c, int len) @@ -141,25 +146,25 @@ SWITCH_DECLARE(int) switch_float_to_char(float *f, char *c, int len) int i; float ft; long l; - for(i=0;i= 0) { - l = (long)(ft+0.5); + l = (long) (ft + 0.5); } else { - l = (long)(ft-0.5); + l = (long) (ft - 0.5); } - c[i*2] = (unsigned char)((l)&0xff); - c[i*2+1] = (unsigned char)(((l)>>8)&0xff); + c[i * 2] = (unsigned char) ((l) & 0xff); + c[i * 2 + 1] = (unsigned char) (((l) >> 8) & 0xff); } - return len*2; + return len * 2; } SWITCH_DECLARE(int) switch_short_to_float(short *s, float *f, int len) { int i; - for(i=0;i> 8) & 0x00ff) | ((buf[i] << 8) & 0xff00); + buf[i] = ((buf[i] >> 8) & 0x00ff) | ((buf[i] << 8) & 0xff00); } } diff --git a/src/switch_utils.c b/src/switch_utils.c index ad9edfed08..2b07e372d7 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -73,16 +73,17 @@ SWITCH_DECLARE(char *) switch_cut_path(char *in) char delims[] = "/\\"; char *i; - for(i = delims; *i; i++) { + for (i = delims; *i; i++) { p = in; - while((p = strchr(p, *i))) { + while ((p = strchr(p, *i))) { ret = ++p; } } return ret; } -SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock, unsigned int flags, switch_memory_pool *pool) +SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock, + unsigned int flags, switch_memory_pool *pool) { switch_pollset_t *pollset; switch_status status; @@ -102,7 +103,7 @@ SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll, SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms) { - switch_status status; + switch_status status; int nsds = 0; if ((status = switch_poll(poll, 1, &nsds, ms)) != SWITCH_STATUS_SUCCESS) { @@ -117,6 +118,6 @@ SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms) void include_me(void) { apr_socket_shutdown(NULL, 0); - apr_socket_recvfrom(NULL , NULL, 0, NULL, NULL); + apr_socket_recvfrom(NULL, NULL, 0, NULL, NULL); } #endif