From 6890d16836e85deed9e8ca91d095473347013ccc Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 21 Feb 2006 16:13:57 +0000 Subject: Structure reorganziation, added polyp plugin - Reorganized the directory structure: Now each plugin(s) is loaded in own subdirectory. - Added polypaudio plugin by Pierre Ossman - Fixed COPYING file to LGPL (under which all codes are released, so far) --- COPYING | 664 ++++++++++++++++++++++++++++++++------------------- Makefile.am | 9 +- configure.in | 17 +- ctl/Makefile.am | 2 - ctl/oss/Makefile.am | 10 - ctl/oss/ctl_oss.c | 452 ----------------------------------- doc/Makefile.am | 1 + doc/README-jack | 46 ++++ doc/README-pcm-oss | 33 +++ jack/Makefile.am | 9 + jack/pcm_jack.c | 428 +++++++++++++++++++++++++++++++++ oss/Makefile.am | 14 ++ oss/ctl_oss.c | 452 +++++++++++++++++++++++++++++++++++ oss/pcm_oss.c | 423 ++++++++++++++++++++++++++++++++ pcm/Makefile.am | 2 - pcm/jack/Makefile.am | 10 - pcm/jack/README | 46 ---- pcm/jack/pcm_jack.c | 428 --------------------------------- pcm/oss/Makefile.am | 10 - pcm/oss/README | 33 --- pcm/oss/pcm_oss.c | 423 -------------------------------- polyp/Makefile.am | 14 ++ polyp/ctl_polyp.c | 455 +++++++++++++++++++++++++++++++++++ polyp/pcm_polyp.c | 626 ++++++++++++++++++++++++++++++++++++++++++++++++ polyp/polyp.c | 350 +++++++++++++++++++++++++++ polyp/polyp.h | 60 +++++ 26 files changed, 3343 insertions(+), 1674 deletions(-) delete mode 100644 ctl/Makefile.am delete mode 100644 ctl/oss/Makefile.am delete mode 100644 ctl/oss/ctl_oss.c create mode 100644 doc/Makefile.am create mode 100644 doc/README-jack create mode 100644 doc/README-pcm-oss create mode 100644 jack/Makefile.am create mode 100644 jack/pcm_jack.c create mode 100644 oss/Makefile.am create mode 100644 oss/ctl_oss.c create mode 100644 oss/pcm_oss.c delete mode 100644 pcm/Makefile.am delete mode 100644 pcm/jack/Makefile.am delete mode 100644 pcm/jack/README delete mode 100644 pcm/jack/pcm_jack.c delete mode 100644 pcm/oss/Makefile.am delete mode 100644 pcm/oss/README delete mode 100644 pcm/oss/pcm_oss.c create mode 100644 polyp/Makefile.am create mode 100644 polyp/ctl_polyp.c create mode 100644 polyp/pcm_polyp.c create mode 100644 polyp/polyp.c create mode 100644 polyp/polyp.h diff --git a/COPYING b/COPYING index 5b6e7c6..b1e3f5a 100644 --- a/COPYING +++ b/COPYING @@ -1,221 +1,397 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Copyright (C) 1991, 1999 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. +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + Preamble 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. - - 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. +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +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 and use pieces of +it in new free programs; and that you are informed that you can do +these things. 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. - - 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. - - 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. - - 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. - - 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. +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. The precise terms and conditions for copying, distribution and -modification follow. +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. - GNU GENERAL PUBLIC LICENSE + GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - 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". - -Activities other than copying, distribution and modification are not + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, 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 library. + + 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. 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. - -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. - - 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 +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete 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 distribute a copy of this License along with the +Library. + + 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. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: - a) You must cause the modified files to carry prominent notices + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. - 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. - - 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.) - + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, +identifiable sections of that work are not derived from the Library, 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 +on the Library, 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. +entire whole, and thus to each and every part regardless of who wrote +it. 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. +collective works based on the Library. -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 +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. - 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: - - 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, - - 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, - - 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.) - -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. - -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 + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you 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. + + If distribution of 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 satisfies the requirement to +distribute the source code, even though third parties are not compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be 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. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. - 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. - - 5. You are not required to accept this License, since you have not + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library 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. + + 9. 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 +distribute the Library 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 +modifying or distributing the Library (or any work based on the +Library), 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. +the Library or works based on it. - 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 + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +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 +You are not responsible for enforcing compliance by third parties with this License. - - 7. If, as a consequence of a court judgment or allegation of patent + + 11. 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 +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library 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. +refrain entirely from distribution of the Library. -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. +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. 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 +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 @@ -225,116 +401,104 @@ impose that choice. 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 + + 12. If the distribution and/or use of the Library 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. - - 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. - -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. - - 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. +original copyright holder who places the Library 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. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser 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. + +Each version is given a distinguishing version number. If the Library +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 Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +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. NO WARRANTY - 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. - - 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. + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "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 +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. 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 LIBRARY 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 +LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. END OF TERMS AND CONDITIONS - How to Apply These Terms to Your New Programs + How to Apply These Terms to Your New Libraries - 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 you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). - 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. + To apply these terms, attach the following notices to the library. 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. - + Copyright (C) - 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. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + This library 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. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - 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 +school, if any, to sign a "copyright disclaimer" for the library, 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. + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. - , 1 April 1989 + , 1 April 1990 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. +That's all there is to it! + + diff --git a/Makefile.am b/Makefile.am index e72ac58..b5adc0b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,11 @@ -SUBDIRS = pcm ctl +if HAVE_JACK +JACKDIR = jack +endif +if HAVE_POLYP +POLYPDIR = polyp +endif + +SUBDIRS = oss $(JACKDIR) $(POLYPDIR) doc EXTRA_DIST = cvscompile version AUTOMAKE_OPTIONS = foreign diff --git a/configure.in b/configure.in index 42b5f56..7efad81 100644 --- a/configure.in +++ b/configure.in @@ -1,4 +1,4 @@ -AC_INIT(pcm/oss/pcm_oss.c) +AC_INIT(oss/pcm_oss.c) AM_INIT_AUTOMAKE(alsa-plugins, 1.0.10) AC_PREFIX_DEFAULT(/usr) @@ -12,15 +12,18 @@ PKG_CHECK_MODULES(ALSA, alsa >= 1.0.9) AC_CHECK_LIB(asound, snd_pcm_ioplug_create,, AC_ERROR([*** libasound has no external plugin SDK]), -ldl) -PKG_CHECK_MODULES(JACK, jack >= 0.98) +PKG_CHECK_MODULES(JACK, jack >= 0.98, [HAVE_JACK=yes], [HAVE_JACK=no]) +AM_CONDITIONAL(HAVE_JACK, test x$HAVE_JACK = xyes) + +PKG_CHECK_MODULES(polypaudio, [polyplib polyplib-mainloop], [HAVE_POLYP=yes], [HAVE_POLYP=no]) +AM_CONDITIONAL(HAVE_POLYP, test x$HAVE_POLYP = xyes) SAVE_PLUGINS_VERSION AC_OUTPUT([ Makefile - pcm/Makefile - pcm/oss/Makefile - pcm/jack/Makefile - ctl/Makefile - ctl/oss/Makefile + oss/Makefile + jack/Makefile + polyp/Makefile + doc/Makefile ]) diff --git a/ctl/Makefile.am b/ctl/Makefile.am deleted file mode 100644 index 8c1ac17..0000000 --- a/ctl/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -SUBDIRS = oss - diff --git a/ctl/oss/Makefile.am b/ctl/oss/Makefile.am deleted file mode 100644 index e8b6811..0000000 --- a/ctl/oss/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -asound_module_ctl_oss_LTLIBRARIES = libasound_module_ctl_oss.la - -asound_module_ctl_ossdir = $(libdir)/alsa-lib - -AM_CFLAGS = -Wall -g @ALSA_CFLAGS@ -libasound_module_ctl_oss_la_SOURCES = ctl_oss.c -libasound_module_ctl_oss_la_LDFLAGS = -module -avoid-version -export-dynamic -libasound_module_ctl_oss_la_LIBADD = @ALSA_LIBS@ - -#EXTRA_DIST = README diff --git a/ctl/oss/ctl_oss.c b/ctl/oss/ctl_oss.c deleted file mode 100644 index a7cfa8f..0000000 --- a/ctl/oss/ctl_oss.c +++ /dev/null @@ -1,452 +0,0 @@ -/* - * ALSA <-> OSS mixer control plugin - * - * Copyright (c) 2005 by Takashi Iwai - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * TODO: implement the pseudo poll with thread (and pipe as pollfd)? - */ - -#include -#include -#include -#include -#include - -typedef struct snd_ctl_oss { - snd_ctl_ext_t ext; - char *device; - int fd; - int exclusive_input; - int stereo_mask; - int num_vol_ctls; - int vol_ctl[SOUND_MIXER_NRDEVICES]; - int num_rec_items; - int rec_item[SOUND_MIXER_NRDEVICES]; -} snd_ctl_oss_t; - -static const char *vol_devices[SOUND_MIXER_NRDEVICES] = { - [SOUND_MIXER_VOLUME] = "Master Playback Volume", - [SOUND_MIXER_BASS] = "Tone Control - Bass", - [SOUND_MIXER_TREBLE] = "Tone Control - Treble", - [SOUND_MIXER_SYNTH] = "Synth Playback Volume", - [SOUND_MIXER_PCM] = "PCM Playback Volume", - [SOUND_MIXER_SPEAKER] = "PC Speaker Playback Volume", - [SOUND_MIXER_LINE] = "Line Playback Volume", - [SOUND_MIXER_MIC] = "Mic Playback Volume", - [SOUND_MIXER_CD] = "CD Playback Volume", - [SOUND_MIXER_IMIX] = "Monitor Mix Playback Volume", - [SOUND_MIXER_ALTPCM] = "Headphone Playback Volume", - [SOUND_MIXER_RECLEV] = "Capture Volume", - [SOUND_MIXER_IGAIN] = "Capture Volume", - [SOUND_MIXER_OGAIN] = "Playback Volume", - [SOUND_MIXER_LINE1] = "Aux Playback Volume", - [SOUND_MIXER_LINE2] = "Aux1 Playback Volume", - [SOUND_MIXER_LINE3] = "Line1 Playback Volume", - [SOUND_MIXER_DIGITAL1] = "IEC958 Playback Volume", - [SOUND_MIXER_DIGITAL2] = "Digital Playback Volume", - [SOUND_MIXER_DIGITAL3] = "Digital1 Playback Volume", - [SOUND_MIXER_PHONEIN] = "Phone Playback Volume", - [SOUND_MIXER_PHONEOUT] = "Master Mono Playback Volume", - [SOUND_MIXER_VIDEO] = "Video Playback Volume", - [SOUND_MIXER_RADIO] = "Radio Playback Volume", - [SOUND_MIXER_MONITOR] = "Monitor Playback Volume", -}; - -static const char *rec_devices[SOUND_MIXER_NRDEVICES] = { - [SOUND_MIXER_VOLUME] = "Mix Capture Switch", - [SOUND_MIXER_SYNTH] = "Synth Capture Switch", - [SOUND_MIXER_PCM] = "PCM Capture Switch", - [SOUND_MIXER_LINE] = "Line Capture Switch", - [SOUND_MIXER_MIC] = "Mic Capture Switch", - [SOUND_MIXER_CD] = "CD Capture Switch", - [SOUND_MIXER_LINE1] = "Aux Capture Switch", - [SOUND_MIXER_LINE2] = "Aux1 Capture Switch", - [SOUND_MIXER_LINE3] = "Line1 Capture Switch", - [SOUND_MIXER_DIGITAL1] = "IEC958 Capture Switch", - [SOUND_MIXER_DIGITAL2] = "Digital Capture Switch", - [SOUND_MIXER_DIGITAL3] = "Digital1 Capture Switch", - [SOUND_MIXER_PHONEIN] = "Phone Capture Switch", - [SOUND_MIXER_VIDEO] = "Video Capture Switch", - [SOUND_MIXER_RADIO] = "Radio Capture Switch", -}; - -static const char *rec_items[SOUND_MIXER_NRDEVICES] = { - [SOUND_MIXER_VOLUME] = "Mix", - [SOUND_MIXER_SYNTH] = "Synth", - [SOUND_MIXER_PCM] = "PCM", - [SOUND_MIXER_LINE] = "Line", - [SOUND_MIXER_MIC] = "Mic", - [SOUND_MIXER_CD] = "CD", - [SOUND_MIXER_LINE1] = "Aux", - [SOUND_MIXER_LINE2] = "Aux1", - [SOUND_MIXER_LINE3] = "Line1", - [SOUND_MIXER_DIGITAL1] = "IEC958", - [SOUND_MIXER_DIGITAL2] = "Digital", - [SOUND_MIXER_DIGITAL3] = "Digital1", - [SOUND_MIXER_PHONEIN] = "Phone", - [SOUND_MIXER_VIDEO] = "Video", - [SOUND_MIXER_RADIO] = "Radio", -}; - -static void oss_close(snd_ctl_ext_t *ext) -{ - snd_ctl_oss_t *oss = ext->private_data; - - close(oss->fd); - free(oss->device); - free(oss); -} - -static int oss_elem_count(snd_ctl_ext_t *ext) -{ - snd_ctl_oss_t *oss = ext->private_data; - int num; - - num = oss->num_vol_ctls; - if (oss->exclusive_input) - num++; - else if (oss->num_rec_items) - num += oss->num_rec_items; - return num; -} - -static int oss_elem_list(snd_ctl_ext_t *ext, unsigned int offset, snd_ctl_elem_id_t *id) -{ - snd_ctl_oss_t *oss = ext->private_data; - - snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER); - if (offset < oss->num_vol_ctls) - snd_ctl_elem_id_set_name(id, vol_devices[oss->vol_ctl[offset]]); - else if (oss->exclusive_input) - snd_ctl_elem_id_set_name(id, "Capture Source"); - else { - offset -= oss->num_vol_ctls; - snd_ctl_elem_id_set_name(id, rec_devices[oss->rec_item[offset]]); - } - return 0; -} - -#define OSS_KEY_DEVICE_MASK 0x1f -#define OSS_KEY_CAPTURE_FLAG (1 << 8) -#define OSS_KEY_CAPTURE_MUX (1 << 16) - -static snd_ctl_ext_key_t oss_find_elem(snd_ctl_ext_t *ext, - const snd_ctl_elem_id_t *id) -{ - snd_ctl_oss_t *oss = ext->private_data; - const char *name; - int i, key; - - name = snd_ctl_elem_id_get_name(id); - if (! strcmp(name, "Capture Source")) { - if (oss->exclusive_input) - return OSS_KEY_CAPTURE_MUX; - else - return SND_CTL_EXT_KEY_NOT_FOUND; - } - for (i = 0; i < oss->num_vol_ctls; i++) { - key = oss->vol_ctl[i]; - if (! strcmp(name, vol_devices[key])) - return key; - } - for (i = 0; i < oss->num_rec_items; i++) { - key = oss->rec_item[i]; - if (! strcmp(name, rec_devices[key])) - return key | OSS_KEY_CAPTURE_FLAG; - } - return SND_CTL_EXT_KEY_NOT_FOUND; -} - -static int oss_get_attribute(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, - int *type, unsigned int *acc, unsigned int *count) -{ - snd_ctl_oss_t *oss = ext->private_data; - - if (key == OSS_KEY_CAPTURE_MUX) { - *type = SND_CTL_ELEM_TYPE_ENUMERATED; - *acc = SND_CTL_EXT_ACCESS_READWRITE; - *count = 1; - } else if (key & OSS_KEY_CAPTURE_FLAG) { - *type = SND_CTL_ELEM_TYPE_BOOLEAN; - *acc = SND_CTL_EXT_ACCESS_READWRITE; - *count = 1; - } else { - *type = SND_CTL_ELEM_TYPE_INTEGER; - *acc = SND_CTL_EXT_ACCESS_READWRITE; - if (oss->stereo_mask & (1 << key)) - *count = 2; - else - *count = 1; - } - return 0; -} - -static int oss_get_integer_info(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, - long *imin, long *imax, long *istep) -{ - *istep = 0; - *imin = 0; - *imax = 100; - return 0; -} - -static int oss_get_enumerated_info(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, - unsigned int *items) -{ - snd_ctl_oss_t *oss = ext->private_data; - - *items = oss->num_rec_items; - return 0; -} - -static int oss_get_enumerated_name(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, - unsigned int item, char *name, size_t name_max_len) -{ - snd_ctl_oss_t *oss = ext->private_data; - - if (item >= oss->num_rec_items) - return -EINVAL; - item = oss->rec_item[item]; - strncpy(name, rec_items[item], name_max_len - 1); - name[name_max_len - 1] = 0; - return 0; -} - -static int oss_read_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value) -{ - snd_ctl_oss_t *oss = ext->private_data; - int val; - - if (key & OSS_KEY_CAPTURE_FLAG) { - key &= OSS_KEY_DEVICE_MASK; - if (ioctl(oss->fd, SOUND_MIXER_READ_RECSRC, &val) < 0) - return -errno; - *value = (val & (1 << key)) ? 1 : 0; - } else { - if (ioctl(oss->fd, MIXER_READ(key), &val) < 0) - return -errno; - *value = val & 0xff; - if (oss->stereo_mask & (1 << key)) - value[1] = (val >> 8) & 0xff; - } - return 0; -} - -static int oss_read_enumerated(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items) -{ - snd_ctl_oss_t *oss = ext->private_data; - int i, val; - - *items = 0; - if (ioctl(oss->fd, SOUND_MIXER_READ_RECSRC, &val) < 0) - return -errno; - for (i = 0; i < oss->num_rec_items; i++) { - if (val & (1 << oss->rec_item[i])) { - *items = i; - break; - } - } - return 0; -} - -static int oss_write_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value) -{ - snd_ctl_oss_t *oss = ext->private_data; - int val, oval; - - if (key & OSS_KEY_CAPTURE_FLAG) { - key &= OSS_KEY_DEVICE_MASK; - if (ioctl(oss->fd, SOUND_MIXER_READ_RECSRC, &oval) < 0) - return -errno; - if (*value) - val = oval | (1 << key); - else - val = oval & ~(1 << key); - if (oval == val) - return 0; - if (ioctl(oss->fd, SOUND_MIXER_WRITE_RECSRC, &val) < 0) - return -errno; - return 1; - } else { - val = *value; - if (oss->stereo_mask & (1 << key)) - val |= value[1] << 8; - if (ioctl(oss->fd, MIXER_READ(key), &oval) < 0) - return -errno; - if (oval == val) - return 0; - if (ioctl(oss->fd, MIXER_WRITE(key), &val) < 0) - return -errno; - return 1; - } -} - -static int oss_write_enumerated(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, - unsigned int *items) -{ - snd_ctl_oss_t *oss = ext->private_data; - int val, oval; - - if (ioctl(oss->fd, SOUND_MIXER_READ_RECSRC, &oval) < 0) - return -errno; - val = 1 << oss->rec_item[*items]; - if (val == oval) - return 0; - if (ioctl(oss->fd, SOUND_MIXER_WRITE_RECSRC, &val) < 0) - return -errno; - return 1; -} - -static int oss_read_event(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id, - unsigned int *event_mask) -{ - return -EAGAIN; -} - -static snd_ctl_ext_callback_t oss_ext_callback = { - .close = oss_close, - .elem_count = oss_elem_count, - .elem_list = oss_elem_list, - .find_elem = oss_find_elem, - .get_attribute = oss_get_attribute, - .get_integer_info = oss_get_integer_info, - .get_enumerated_info = oss_get_enumerated_info, - .get_enumerated_name = oss_get_enumerated_name, - .read_integer = oss_read_integer, - .read_enumerated = oss_read_enumerated, - .write_integer = oss_write_integer, - .write_enumerated = oss_write_enumerated, - .read_event = oss_read_event, -}; - - -SND_CTL_PLUGIN_DEFINE_FUNC(oss) -{ - snd_config_iterator_t it, next; - const char *device = "/dev/mixer"; - struct mixer_info mixinfo; - int i, err, val; - snd_ctl_oss_t *oss; - - snd_config_for_each(it, next, conf) { - snd_config_t *n = snd_config_iterator_entry(it); - const char *id; - if (snd_config_get_id(n, &id) < 0) - continue; - if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0) - continue; - if (strcmp(id, "device") == 0) { - if (snd_config_get_string(n, &device) < 0) { - SNDERR("Invalid type for %s", id); - return -EINVAL; - } - continue; - } - SNDERR("Unknown field %s", id); - return -EINVAL; - } - - oss = calloc(1, sizeof(*oss)); - oss->device = strdup(device); - oss->fd = -1; - if (oss->device == NULL) { - SNDERR("cannot allocate"); - free(oss); - return -ENOMEM; - } - oss->fd = open(device, O_RDWR); - if (oss->fd < 0) { - err = -errno; - SNDERR("Cannot open device %s", device); - goto error; - } - - if (ioctl(oss->fd, SOUND_MIXER_INFO, &mixinfo) < 0) { - err = -errno; - SNDERR("Cannot get mixer info for device %s", device); - goto error; - } - - oss->ext.version = SND_CTL_EXT_VERSION; - oss->ext.card_idx = 0; /* FIXME */ - strncpy(oss->ext.id, mixinfo.id, sizeof(oss->ext.id) - 1); - strcpy(oss->ext.driver, "OSS-Emulation"); - strncpy(oss->ext.name, mixinfo.name, sizeof(oss->ext.name) - 1); - strncpy(oss->ext.longname, mixinfo.name, sizeof(oss->ext.longname) - 1); - strncpy(oss->ext.mixername, mixinfo.name, sizeof(oss->ext.mixername) - 1); - oss->ext.poll_fd = -1; - oss->ext.callback = &oss_ext_callback; - oss->ext.private_data = oss; - - oss->num_vol_ctls = 0; - val = 0; - if (ioctl(oss->fd, SOUND_MIXER_READ_DEVMASK, &val) < 0) - perror("ctl_oss: DEVMASK error"); - else { - for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { - if ((val & (1 << i)) && vol_devices[i]) - oss->vol_ctl[oss->num_vol_ctls++] = i; - } - } - - if (ioctl(oss->fd, SOUND_MIXER_READ_STEREODEVS, &oss->stereo_mask) < 0) - perror("ctl_oss: STEREODEVS error"); - val = 0; - if (ioctl(oss->fd, SOUND_MIXER_READ_CAPS, &val) < 0) - perror("ctl_oss: MIXER_CAPS error"); - else if (val & SOUND_CAP_EXCL_INPUT) - oss->exclusive_input = 1; - - oss->num_rec_items = 0; - val = 0; - if (ioctl(oss->fd, SOUND_MIXER_READ_RECMASK, &val) < 0) - perror("ctl_oss: MIXER_RECMASK error"); - else { - for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { - if (val & (1 << i)) { - if (oss->exclusive_input) { - if (! rec_items[i]) - continue; - } else { - if (! rec_devices[i]) - continue; - } - oss->rec_item[oss->num_rec_items++] = i; - } - } - } - if (! oss->num_rec_items) - oss->exclusive_input = 0; - - err = snd_ctl_ext_create(&oss->ext, name, mode); - if (err < 0) - goto error; - - *handlep = oss->ext.handle; - return 0; - - error: - if (oss->fd >= 0) - close(oss->fd); - free(oss->device); - free(oss); - return err; -} - -SND_CTL_PLUGIN_SYMBOL(oss); diff --git a/doc/Makefile.am b/doc/Makefile.am new file mode 100644 index 0000000..a431171 --- /dev/null +++ b/doc/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = README-pcm-oss diff --git a/doc/README-jack b/doc/README-jack new file mode 100644 index 0000000..4579174 --- /dev/null +++ b/doc/README-jack @@ -0,0 +1,46 @@ +JACK <--> ALSA PCM plugin +========================= + +This plugin converts the ALSA API over JACK (Jack Audio Connection +Kit, http://jackit.sf.net) API. ALSA native applications can work +transparently together with jackd for both playback and capture. + + ALSA apps (playback) -> ALSA-lib -> JACK plugin -> JACK deamon + ALSA apps (capture) <- ALSA-lib <- JACK plugin <- JACK daemon + +This plugin provides the PCM type "jack". The typical configuration +looks like below: + + pcm.jack { + type jack + playback_ports { + 0 alsa_pcm:playback_1 + 1 alsa_pcm:playback_1 + } + capture_ports { + 0 alsa_pcm:capture_1 + 1 alsa_pcm:pcapture_1 + } + } + +Put the above to ~/.asoundrc (or /etc/asound.conf), and use "jack" PCM +with your ALSA apps. For example, + + % aplay -Djack foo.wav + +The jack plugin can have two config options: playback_ports and +capture_ports. Both are compound type config, including the following +format: + { + channel port-name + channel port-name + ... + } +The first argument is the channel number (zero-based) and the second +is the corresponding JACK port name. + +The plugin is installed in /usr/lib/alsa-lib directory as default, +which is the default search path of additional plugins for alsa-lib. +On a 64bit system like x86-64, the proper prefix option (typically, +--prefix=/usr/lib64) must be given to configure script. + diff --git a/doc/README-pcm-oss b/doc/README-pcm-oss new file mode 100644 index 0000000..42b73cb --- /dev/null +++ b/doc/README-pcm-oss @@ -0,0 +1,33 @@ +OSS <--> ALSA PCM plugin +======================== + +This plugin converts the ALSA API over OSS API. With this plugin, +ALSA native apps can run on OSS drivers. + +This plugin provides the PCM type "oss". The typical configuration +looks like below: + + pcm.oss { + type oss + device /dev/dsp + } + +Put the above to ~/.asoundrc (or /etc/asound.conf), and use "oss" PCM +with your ALSA apps. For example, + + % aplay -Doss foo.wav + +For playing arbitrary formats, you should use "plug" layer together, + + % aplay -Dplug:oss foo.wav + +The oss plugin can have an option: device. This specifies the device +file path of OSS to open. If not given, /dev/dsp is used. + +The function supported by this plugin is limited. For example, you +cannot use dmix together with this plugin. Don't expect too much :) + +The plugin is installed in /usr/lib/alsa-lib directory as default, +which is the default search path of additional plugins for alsa-lib. +On a 64bit system like x86-64, the proper prefix option (typically, +--prefix=/usr/lib64) must be given to configure script. diff --git a/jack/Makefile.am b/jack/Makefile.am new file mode 100644 index 0000000..6b5ddb0 --- /dev/null +++ b/jack/Makefile.am @@ -0,0 +1,9 @@ +asound_module_pcm_jack_LTLIBRARIES = libasound_module_pcm_jack.la + +asound_module_pcm_jackdir = $(libdir)/alsa-lib + +AM_CFLAGS = -Wall -g @ALSA_CFLAGS@ @JACK_CFLAGS@ +AM_LDFLAGS = -module -avoid-version -export-dynamic + +libasound_module_pcm_jack_la_SOURCES = pcm_jack.c +libasound_module_pcm_jack_la_LIBADD = @ALSA_LIBS@ @JACK_LIBS@ diff --git a/jack/pcm_jack.c b/jack/pcm_jack.c new file mode 100644 index 0000000..855f837 --- /dev/null +++ b/jack/pcm_jack.c @@ -0,0 +1,428 @@ +/* + * PCM - JACK plugin + * + * Copyright (c) 2003 by Maarten de Boer + * 2005 Takashi Iwai + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include + +typedef enum _jack_format { + SND_PCM_JACK_FORMAT_RAW +} snd_pcm_jack_format_t; + +typedef struct { + snd_pcm_ioplug_t io; + + int fd; + int activated; /* jack is activated? */ + + char **port_names; + unsigned int num_ports; + unsigned int hw_ptr; + unsigned int sample_bits; + + unsigned int channels; + snd_pcm_channel_area_t *areas; + + jack_port_t **ports; + jack_client_t *client; +} snd_pcm_jack_t; + +static void snd_pcm_jack_free(snd_pcm_jack_t *jack) +{ + if (jack) { + unsigned int i; + if (jack->client) + jack_client_close(jack->client); + if (jack->port_names) { + for (i = 0; i < jack->num_ports; i++) + free(jack->port_names[i]); + free(jack->port_names); + } + close(jack->fd); + close(jack->io.poll_fd); + free(jack->areas); + free(jack); + } +} + +static int snd_pcm_jack_close(snd_pcm_ioplug_t *io) +{ + snd_pcm_jack_t *jack = io->private_data; + snd_pcm_jack_free(jack); + return 0; +} + +static int snd_pcm_jack_poll_revents(snd_pcm_ioplug_t *io, + struct pollfd *pfds, unsigned int nfds, + unsigned short *revents) +{ + static char buf[1]; + + assert(pfds && nfds == 1 && revents); + + read(pfds[0].fd, buf, 1); + + *revents = pfds[0].revents; + return 0; +} + +static snd_pcm_sframes_t snd_pcm_jack_pointer(snd_pcm_ioplug_t *io) +{ + snd_pcm_jack_t *jack = io->private_data; + return jack->hw_ptr; +} + +static int +snd_pcm_jack_process_cb(jack_nframes_t nframes, snd_pcm_ioplug_t *io) +{ + snd_pcm_jack_t *jack = io->private_data; + const snd_pcm_channel_area_t *areas; + snd_pcm_uframes_t xfer = 0; + static char buf[1]; + unsigned int channel; + + for (channel = 0; channel < io->channels; channel++) { + jack->areas[channel].addr = + jack_port_get_buffer (jack->ports[channel], nframes); + jack->areas[channel].first = 0; + jack->areas[channel].step = jack->sample_bits; + } + + if (io->state != SND_PCM_STATE_RUNNING) { + if (io->stream == SND_PCM_STREAM_PLAYBACK) { + for (channel = 0; channel < io->channels; channel++) + snd_pcm_area_silence(&jack->areas[channel], 0, nframes, io->format); + return 0; + } + } + + areas = snd_pcm_ioplug_mmap_areas(io); + + while (xfer < nframes) { + snd_pcm_uframes_t frames = nframes - xfer; + snd_pcm_uframes_t offset = jack->hw_ptr; + snd_pcm_uframes_t cont = io->buffer_size - offset; + + if (cont < frames) + frames = cont; + + for (channel = 0; channel < io->channels; channel++) { + if (io->stream == SND_PCM_STREAM_PLAYBACK) + snd_pcm_area_copy(&jack->areas[channel], xfer, &areas[channel], offset, frames, io->format); + else + snd_pcm_area_copy(&areas[channel], offset, &jack->areas[channel], xfer, frames, io->format); + } + + jack->hw_ptr += frames; + jack->hw_ptr %= io->buffer_size; + xfer += frames; + } + + write(jack->fd, buf, 1); /* for polling */ + + return 0; +} + +static int snd_pcm_jack_prepare(snd_pcm_ioplug_t *io) +{ + snd_pcm_jack_t *jack = io->private_data; + unsigned int i; + + jack->hw_ptr = 0; + + if (jack->ports) + return 0; + + jack->ports = calloc(io->channels, sizeof(jack_port_t*)); + + for (i = 0; i < io->channels; i++) { + char port_name[32]; + if (io->stream == SND_PCM_STREAM_PLAYBACK) { + + sprintf(port_name, "out_%03d\n", i); + jack->ports[i] = jack_port_register(jack->client, port_name, + JACK_DEFAULT_AUDIO_TYPE, + JackPortIsOutput, 0); + } else { + sprintf(port_name, "in_%03d\n", i); + jack->ports[i] = jack_port_register(jack->client, port_name, + JACK_DEFAULT_AUDIO_TYPE, + JackPortIsInput, 0); + } + } + + jack_set_process_callback(jack->client, + (JackProcessCallback)snd_pcm_jack_process_cb, io); + return 0; +} + +static int snd_pcm_jack_start(snd_pcm_ioplug_t *io) +{ + snd_pcm_jack_t *jack = io->private_data; + unsigned int i; + + if (jack_activate (jack->client)) + return -EIO; + + jack->activated = 1; + + for (i = 0; i < io->channels && i < jack->num_ports; i++) { + if (jack->port_names[i]) { + const char *src, *dst; + if (io->stream == SND_PCM_STREAM_PLAYBACK) { + src = jack_port_name(jack->ports[i]); + dst = jack->port_names[i]; + } else { + src = jack->port_names[i]; + dst = jack_port_name(jack->ports[i]); + } + if (jack_connect(jack->client, src, dst)) { + fprintf(stderr, "cannot connect %s to %s\n", src, dst); + return -EIO; + } + } + } + + return 0; +} + +static int snd_pcm_jack_stop(snd_pcm_ioplug_t *io) +{ + snd_pcm_jack_t *jack = io->private_data; + + if (jack->activated) { + jack_deactivate(jack->client); + jack->activated = 0; + } +#if 0 + unsigned i; + for (i = 0; i < io->channels; i++) { + if (jack->ports[i]) { + jack_port_unregister(jack->client, jack->ports[i]); + jack->ports[i] = NULL; + } + } +#endif + return 0; +} + +static snd_pcm_ioplug_callback_t jack_pcm_callback = { + .close = snd_pcm_jack_close, + .start = snd_pcm_jack_start, + .stop = snd_pcm_jack_stop, + .pointer = snd_pcm_jack_pointer, + .prepare = snd_pcm_jack_prepare, + .poll_revents = snd_pcm_jack_poll_revents, +}; + +#define ARRAY_SIZE(ary) (sizeof(ary)/sizeof(ary[0])) + +static int jack_set_hw_constraint(snd_pcm_jack_t *jack) +{ + unsigned int access_list[] = { + SND_PCM_ACCESS_MMAP_INTERLEAVED, + SND_PCM_ACCESS_MMAP_NONINTERLEAVED, + SND_PCM_ACCESS_RW_INTERLEAVED, + SND_PCM_ACCESS_RW_NONINTERLEAVED + }; + unsigned int format = SND_PCM_FORMAT_FLOAT; + unsigned int rate = jack_get_sample_rate(jack->client); + int err; + + jack->sample_bits = snd_pcm_format_physical_width(format); + if ((err = snd_pcm_ioplug_set_param_list(&jack->io, SND_PCM_IOPLUG_HW_ACCESS, + ARRAY_SIZE(access_list), access_list)) < 0 || + (err = snd_pcm_ioplug_set_param_list(&jack->io, SND_PCM_IOPLUG_HW_FORMAT, + 1, &format)) < 0 || + (err = snd_pcm_ioplug_set_param_minmax(&jack->io, SND_PCM_IOPLUG_HW_CHANNELS, + jack->channels, jack->channels)) < 0 || + (err = snd_pcm_ioplug_set_param_minmax(&jack->io, SND_PCM_IOPLUG_HW_RATE, + rate, rate)) < 0 || + (err = snd_pcm_ioplug_set_param_minmax(&jack->io, SND_PCM_IOPLUG_HW_PERIOD_BYTES, + 128, 64*1024)) < 0 || + (err = snd_pcm_ioplug_set_param_minmax(&jack->io, SND_PCM_IOPLUG_HW_PERIODS, + 2, 64)) < 0) + return err; + + return 0; +} + +static int parse_ports(snd_pcm_jack_t *jack, snd_config_t *conf) +{ + snd_config_iterator_t i, next; + char **ports = NULL; + unsigned int cnt = 0; + unsigned int channel; + + if (conf) { + snd_config_for_each(i, next, conf) { + snd_config_t *n = snd_config_iterator_entry(i); + const char *id; + if (snd_config_get_id(n, &id) < 0) + continue; + cnt++; + } + jack->port_names = ports = calloc(cnt, sizeof(char*)); + if (ports == NULL) + return -ENOMEM; + jack->num_ports = cnt; + snd_config_for_each(i, next, conf) { + snd_config_t *n = snd_config_iterator_entry(i); + const char *id; + const char *port; + + if (snd_config_get_id(n, &id) < 0) + continue; + channel = atoi(id); + if (snd_config_get_string(n, &port) < 0) + continue; + ports[channel] = port ? strdup(port) : NULL; + } + } + return 0; +} + +static int snd_pcm_jack_open(snd_pcm_t **pcmp, const char *name, + snd_config_t *playback_conf, + snd_config_t *capture_conf, + snd_pcm_stream_t stream, int mode) +{ + snd_pcm_jack_t *jack; + int err; + int fd[2]; + static unsigned int num = 0; + char jack_client_name[32]; + + assert(pcmp); + jack = calloc(1, sizeof(*jack)); + if (!jack) + return -ENOMEM; + + err = parse_ports(jack, stream == SND_PCM_STREAM_PLAYBACK ? + playback_conf : capture_conf); + if (err) { + snd_pcm_jack_free(jack); + return err; + } + + jack->channels = jack->num_ports; + if (jack->channels == 0) { + SNDERR("define the %s_ports section", + stream == SND_PCM_STREAM_PLAYBACK ? "playback" : "capture"); + snd_pcm_jack_free(jack); + return -EINVAL; + } + + if (snprintf(jack_client_name, sizeof(jack_client_name), "alsa-jack.%s%s.%d.%d", name, + stream == SND_PCM_STREAM_PLAYBACK ? "P" : "C", getpid(), num++) + >= (int)sizeof(jack_client_name)) { + fprintf(stderr, "%s: WARNING: JACK client name '%s' truncated to %d characters, might not be unique\n", + __func__, jack_client_name, (int)strlen(jack_client_name)); + } + + jack->client = jack_client_new(jack_client_name); + + if (jack->client == 0) { + snd_pcm_jack_free(jack); + return -ENOENT; + } + + jack->areas = calloc(jack->channels, sizeof(snd_pcm_channel_area_t)); + if (! jack->areas) { + snd_pcm_jack_free(jack); + return -ENOMEM; + } + + socketpair(AF_LOCAL, SOCK_STREAM, 0, fd); + + jack->fd = fd[0]; + + jack->io.version = SND_PCM_IOPLUG_VERSION; + jack->io.name = "ALSA <-> JACK PCM I/O Plugin"; + jack->io.callback = &jack_pcm_callback; + jack->io.private_data = jack; + jack->io.poll_fd = fd[1]; + jack->io.poll_events = POLLIN; + jack->io.mmap_rw = 1; + + err = snd_pcm_ioplug_create(&jack->io, name, stream, mode); + if (err < 0) { + snd_pcm_jack_free(jack); + return err; + } + + err = jack_set_hw_constraint(jack); + if (err < 0) { + snd_pcm_ioplug_delete(&jack->io); + return err; + } + + *pcmp = jack->io.pcm; + + return 0; +} + + +SND_PCM_PLUGIN_DEFINE_FUNC(jack) +{ + snd_config_iterator_t i, next; + snd_config_t *playback_conf = NULL; + snd_config_t *capture_conf = NULL; + int err; + + snd_config_for_each(i, next, conf) { + snd_config_t *n = snd_config_iterator_entry(i); + const char *id; + if (snd_config_get_id(n, &id) < 0) + continue; + if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0) + continue; + if (strcmp(id, "playback_ports") == 0) { + if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) { + SNDERR("Invalid type for %s", id); + return -EINVAL; + } + playback_conf = n; + continue; + } + if (strcmp(id, "capture_ports") == 0) { + if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) { + SNDERR("Invalid type for %s", id); + return -EINVAL; + } + capture_conf = n; + continue; + } + SNDERR("Unknown field %s", id); + return -EINVAL; + } + + err = snd_pcm_jack_open(pcmp, name, playback_conf, capture_conf, stream, mode); + + return err; +} + +SND_PCM_PLUGIN_SYMBOL(jack); diff --git a/oss/Makefile.am b/oss/Makefile.am new file mode 100644 index 0000000..84223bc --- /dev/null +++ b/oss/Makefile.am @@ -0,0 +1,14 @@ +asound_module_pcm_oss_LTLIBRARIES = libasound_module_pcm_oss.la +asound_module_ctl_oss_LTLIBRARIES = libasound_module_ctl_oss.la + +asound_module_pcm_ossdir = $(libdir)/alsa-lib +asound_module_ctl_ossdir = $(libdir)/alsa-lib + +AM_CFLAGS = -Wall -g @ALSA_CFLAGS@ +AM_LDFLAGS = -module -avoid-version -export-dynamic + +libasound_module_pcm_oss_la_SOURCES = pcm_oss.c +libasound_module_pcm_oss_la_LIBADD = @ALSA_LIBS@ + +libasound_module_ctl_oss_la_SOURCES = ctl_oss.c +libasound_module_ctl_oss_la_LIBADD = @ALSA_LIBS@ diff --git a/oss/ctl_oss.c b/oss/ctl_oss.c new file mode 100644 index 0000000..a7cfa8f --- /dev/null +++ b/oss/ctl_oss.c @@ -0,0 +1,452 @@ +/* + * ALSA <-> OSS mixer control plugin + * + * Copyright (c) 2005 by Takashi Iwai + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * TODO: implement the pseudo poll with thread (and pipe as pollfd)? + */ + +#include +#include +#include +#include +#include + +typedef struct snd_ctl_oss { + snd_ctl_ext_t ext; + char *device; + int fd; + int exclusive_input; + int stereo_mask; + int num_vol_ctls; + int vol_ctl[SOUND_MIXER_NRDEVICES]; + int num_rec_items; + int rec_item[SOUND_MIXER_NRDEVICES]; +} snd_ctl_oss_t; + +static const char *vol_devices[SOUND_MIXER_NRDEVICES] = { + [SOUND_MIXER_VOLUME] = "Master Playback Volume", + [SOUND_MIXER_BASS] = "Tone Control - Bass", + [SOUND_MIXER_TREBLE] = "Tone Control - Treble", + [SOUND_MIXER_SYNTH] = "Synth Playback Volume", + [SOUND_MIXER_PCM] = "PCM Playback Volume", + [SOUND_MIXER_SPEAKER] = "PC Speaker Playback Volume", + [SOUND_MIXER_LINE] = "Line Playback Volume", + [SOUND_MIXER_MIC] = "Mic Playback Volume", + [SOUND_MIXER_CD] = "CD Playback Volume", + [SOUND_MIXER_IMIX] = "Monitor Mix Playback Volume", + [SOUND_MIXER_ALTPCM] = "Headphone Playback Volume", + [SOUND_MIXER_RECLEV] = "Capture Volume", + [SOUND_MIXER_IGAIN] = "Capture Volume", + [SOUND_MIXER_OGAIN] = "Playback Volume", + [SOUND_MIXER_LINE1] = "Aux Playback Volume", + [SOUND_MIXER_LINE2] = "Aux1 Playback Volume", + [SOUND_MIXER_LINE3] = "Line1 Playback Volume", + [SOUND_MIXER_DIGITAL1] = "IEC958 Playback Volume", + [SOUND_MIXER_DIGITAL2] = "Digital Playback Volume", + [SOUND_MIXER_DIGITAL3] = "Digital1 Playback Volume", + [SOUND_MIXER_PHONEIN] = "Phone Playback Volume", + [SOUND_MIXER_PHONEOUT] = "Master Mono Playback Volume", + [SOUND_MIXER_VIDEO] = "Video Playback Volume", + [SOUND_MIXER_RADIO] = "Radio Playback Volume", + [SOUND_MIXER_MONITOR] = "Monitor Playback Volume", +}; + +static const char *rec_devices[SOUND_MIXER_NRDEVICES] = { + [SOUND_MIXER_VOLUME] = "Mix Capture Switch", + [SOUND_MIXER_SYNTH] = "Synth Capture Switch", + [SOUND_MIXER_PCM] = "PCM Capture Switch", + [SOUND_MIXER_LINE] = "Line Capture Switch", + [SOUND_MIXER_MIC] = "Mic Capture Switch", + [SOUND_MIXER_CD] = "CD Capture Switch", + [SOUND_MIXER_LINE1] = "Aux Capture Switch", + [SOUND_MIXER_LINE2] = "Aux1 Capture Switch", + [SOUND_MIXER_LINE3] = "Line1 Capture Switch", + [SOUND_MIXER_DIGITAL1] = "IEC958 Capture Switch", + [SOUND_MIXER_DIGITAL2] = "Digital Capture Switch", + [SOUND_MIXER_DIGITAL3] = "Digital1 Capture Switch", + [SOUND_MIXER_PHONEIN] = "Phone Capture Switch", + [SOUND_MIXER_VIDEO] = "Video Capture Switch", + [SOUND_MIXER_RADIO] = "Radio Capture Switch", +}; + +static const char *rec_items[SOUND_MIXER_NRDEVICES] = { + [SOUND_MIXER_VOLUME] = "Mix", + [SOUND_MIXER_SYNTH] = "Synth", + [SOUND_MIXER_PCM] = "PCM", + [SOUND_MIXER_LINE] = "Line", + [SOUND_MIXER_MIC] = "Mic", + [SOUND_MIXER_CD] = "CD", + [SOUND_MIXER_LINE1] = "Aux", + [SOUND_MIXER_LINE2] = "Aux1", + [SOUND_MIXER_LINE3] = "Line1", + [SOUND_MIXER_DIGITAL1] = "IEC958", + [SOUND_MIXER_DIGITAL2] = "Digital", + [SOUND_MIXER_DIGITAL3] = "Digital1", + [SOUND_MIXER_PHONEIN] = "Phone", + [SOUND_MIXER_VIDEO] = "Video", + [SOUND_MIXER_RADIO] = "Radio", +}; + +static void oss_close(snd_ctl_ext_t *ext) +{ + snd_ctl_oss_t *oss = ext->private_data; + + close(oss->fd); + free(oss->device); + free(oss); +} + +static int oss_elem_count(snd_ctl_ext_t *ext) +{ + snd_ctl_oss_t *oss = ext->private_data; + int num; + + num = oss->num_vol_ctls; + if (oss->exclusive_input) + num++; + else if (oss->num_rec_items) + num += oss->num_rec_items; + return num; +} + +static int oss_elem_list(snd_ctl_ext_t *ext, unsigned int offset, snd_ctl_elem_id_t *id) +{ + snd_ctl_oss_t *oss = ext->private_data; + + snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER); + if (offset < oss->num_vol_ctls) + snd_ctl_elem_id_set_name(id, vol_devices[oss->vol_ctl[offset]]); + else if (oss->exclusive_input) + snd_ctl_elem_id_set_name(id, "Capture Source"); + else { + offset -= oss->num_vol_ctls; + snd_ctl_elem_id_set_name(id, rec_devices[oss->rec_item[offset]]); + } + return 0; +} + +#define OSS_KEY_DEVICE_MASK 0x1f +#define OSS_KEY_CAPTURE_FLAG (1 << 8) +#define OSS_KEY_CAPTURE_MUX (1 << 16) + +static snd_ctl_ext_key_t oss_find_elem(snd_ctl_ext_t *ext, + const snd_ctl_elem_id_t *id) +{ + snd_ctl_oss_t *oss = ext->private_data; + const char *name; + int i, key; + + name = snd_ctl_elem_id_get_name(id); + if (! strcmp(name, "Capture Source")) { + if (oss->exclusive_input) + return OSS_KEY_CAPTURE_MUX; + else + return SND_CTL_EXT_KEY_NOT_FOUND; + } + for (i = 0; i < oss->num_vol_ctls; i++) { + key = oss->vol_ctl[i]; + if (! strcmp(name, vol_devices[key])) + return key; + } + for (i = 0; i < oss->num_rec_items; i++) { + key = oss->rec_item[i]; + if (! strcmp(name, rec_devices[key])) + return key | OSS_KEY_CAPTURE_FLAG; + } + return SND_CTL_EXT_KEY_NOT_FOUND; +} + +static int oss_get_attribute(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + int *type, unsigned int *acc, unsigned int *count) +{ + snd_ctl_oss_t *oss = ext->private_data; + + if (key == OSS_KEY_CAPTURE_MUX) { + *type = SND_CTL_ELEM_TYPE_ENUMERATED; + *acc = SND_CTL_EXT_ACCESS_READWRITE; + *count = 1; + } else if (key & OSS_KEY_CAPTURE_FLAG) { + *type = SND_CTL_ELEM_TYPE_BOOLEAN; + *acc = SND_CTL_EXT_ACCESS_READWRITE; + *count = 1; + } else { + *type = SND_CTL_ELEM_TYPE_INTEGER; + *acc = SND_CTL_EXT_ACCESS_READWRITE; + if (oss->stereo_mask & (1 << key)) + *count = 2; + else + *count = 1; + } + return 0; +} + +static int oss_get_integer_info(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + long *imin, long *imax, long *istep) +{ + *istep = 0; + *imin = 0; + *imax = 100; + return 0; +} + +static int oss_get_enumerated_info(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + unsigned int *items) +{ + snd_ctl_oss_t *oss = ext->private_data; + + *items = oss->num_rec_items; + return 0; +} + +static int oss_get_enumerated_name(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + unsigned int item, char *name, size_t name_max_len) +{ + snd_ctl_oss_t *oss = ext->private_data; + + if (item >= oss->num_rec_items) + return -EINVAL; + item = oss->rec_item[item]; + strncpy(name, rec_items[item], name_max_len - 1); + name[name_max_len - 1] = 0; + return 0; +} + +static int oss_read_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value) +{ + snd_ctl_oss_t *oss = ext->private_data; + int val; + + if (key & OSS_KEY_CAPTURE_FLAG) { + key &= OSS_KEY_DEVICE_MASK; + if (ioctl(oss->fd, SOUND_MIXER_READ_RECSRC, &val) < 0) + return -errno; + *value = (val & (1 << key)) ? 1 : 0; + } else { + if (ioctl(oss->fd, MIXER_READ(key), &val) < 0) + return -errno; + *value = val & 0xff; + if (oss->stereo_mask & (1 << key)) + value[1] = (val >> 8) & 0xff; + } + return 0; +} + +static int oss_read_enumerated(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items) +{ + snd_ctl_oss_t *oss = ext->private_data; + int i, val; + + *items = 0; + if (ioctl(oss->fd, SOUND_MIXER_READ_RECSRC, &val) < 0) + return -errno; + for (i = 0; i < oss->num_rec_items; i++) { + if (val & (1 << oss->rec_item[i])) { + *items = i; + break; + } + } + return 0; +} + +static int oss_write_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value) +{ + snd_ctl_oss_t *oss = ext->private_data; + int val, oval; + + if (key & OSS_KEY_CAPTURE_FLAG) { + key &= OSS_KEY_DEVICE_MASK; + if (ioctl(oss->fd, SOUND_MIXER_READ_RECSRC, &oval) < 0) + return -errno; + if (*value) + val = oval | (1 << key); + else + val = oval & ~(1 << key); + if (oval == val) + return 0; + if (ioctl(oss->fd, SOUND_MIXER_WRITE_RECSRC, &val) < 0) + return -errno; + return 1; + } else { + val = *value; + if (oss->stereo_mask & (1 << key)) + val |= value[1] << 8; + if (ioctl(oss->fd, MIXER_READ(key), &oval) < 0) + return -errno; + if (oval == val) + return 0; + if (ioctl(oss->fd, MIXER_WRITE(key), &val) < 0) + return -errno; + return 1; + } +} + +static int oss_write_enumerated(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + unsigned int *items) +{ + snd_ctl_oss_t *oss = ext->private_data; + int val, oval; + + if (ioctl(oss->fd, SOUND_MIXER_READ_RECSRC, &oval) < 0) + return -errno; + val = 1 << oss->rec_item[*items]; + if (val == oval) + return 0; + if (ioctl(oss->fd, SOUND_MIXER_WRITE_RECSRC, &val) < 0) + return -errno; + return 1; +} + +static int oss_read_event(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id, + unsigned int *event_mask) +{ + return -EAGAIN; +} + +static snd_ctl_ext_callback_t oss_ext_callback = { + .close = oss_close, + .elem_count = oss_elem_count, + .elem_list = oss_elem_list, + .find_elem = oss_find_elem, + .get_attribute = oss_get_attribute, + .get_integer_info = oss_get_integer_info, + .get_enumerated_info = oss_get_enumerated_info, + .get_enumerated_name = oss_get_enumerated_name, + .read_integer = oss_read_integer, + .read_enumerated = oss_read_enumerated, + .write_integer = oss_write_integer, + .write_enumerated = oss_write_enumerated, + .read_event = oss_read_event, +}; + + +SND_CTL_PLUGIN_DEFINE_FUNC(oss) +{ + snd_config_iterator_t it, next; + const char *device = "/dev/mixer"; + struct mixer_info mixinfo; + int i, err, val; + snd_ctl_oss_t *oss; + + snd_config_for_each(it, next, conf) { + snd_config_t *n = snd_config_iterator_entry(it); + const char *id; + if (snd_config_get_id(n, &id) < 0) + continue; + if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0) + continue; + if (strcmp(id, "device") == 0) { + if (snd_config_get_string(n, &device) < 0) { + SNDERR("Invalid type for %s", id); + return -EINVAL; + } + continue; + } + SNDERR("Unknown field %s", id); + return -EINVAL; + } + + oss = calloc(1, sizeof(*oss)); + oss->device = strdup(device); + oss->fd = -1; + if (oss->device == NULL) { + SNDERR("cannot allocate"); + free(oss); + return -ENOMEM; + } + oss->fd = open(device, O_RDWR); + if (oss->fd < 0) { + err = -errno; + SNDERR("Cannot open device %s", device); + goto error; + } + + if (ioctl(oss->fd, SOUND_MIXER_INFO, &mixinfo) < 0) { + err = -errno; + SNDERR("Cannot get mixer info for device %s", device); + goto error; + } + + oss->ext.version = SND_CTL_EXT_VERSION; + oss->ext.card_idx = 0; /* FIXME */ + strncpy(oss->ext.id, mixinfo.id, sizeof(oss->ext.id) - 1); + strcpy(oss->ext.driver, "OSS-Emulation"); + strncpy(oss->ext.name, mixinfo.name, sizeof(oss->ext.name) - 1); + strncpy(oss->ext.longname, mixinfo.name, sizeof(oss->ext.longname) - 1); + strncpy(oss->ext.mixername, mixinfo.name, sizeof(oss->ext.mixername) - 1); + oss->ext.poll_fd = -1; + oss->ext.callback = &oss_ext_callback; + oss->ext.private_data = oss; + + oss->num_vol_ctls = 0; + val = 0; + if (ioctl(oss->fd, SOUND_MIXER_READ_DEVMASK, &val) < 0) + perror("ctl_oss: DEVMASK error"); + else { + for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { + if ((val & (1 << i)) && vol_devices[i]) + oss->vol_ctl[oss->num_vol_ctls++] = i; + } + } + + if (ioctl(oss->fd, SOUND_MIXER_READ_STEREODEVS, &oss->stereo_mask) < 0) + perror("ctl_oss: STEREODEVS error"); + val = 0; + if (ioctl(oss->fd, SOUND_MIXER_READ_CAPS, &val) < 0) + perror("ctl_oss: MIXER_CAPS error"); + else if (val & SOUND_CAP_EXCL_INPUT) + oss->exclusive_input = 1; + + oss->num_rec_items = 0; + val = 0; + if (ioctl(oss->fd, SOUND_MIXER_READ_RECMASK, &val) < 0) + perror("ctl_oss: MIXER_RECMASK error"); + else { + for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { + if (val & (1 << i)) { + if (oss->exclusive_input) { + if (! rec_items[i]) + continue; + } else { + if (! rec_devices[i]) + continue; + } + oss->rec_item[oss->num_rec_items++] = i; + } + } + } + if (! oss->num_rec_items) + oss->exclusive_input = 0; + + err = snd_ctl_ext_create(&oss->ext, name, mode); + if (err < 0) + goto error; + + *handlep = oss->ext.handle; + return 0; + + error: + if (oss->fd >= 0) + close(oss->fd); + free(oss->device); + free(oss); + return err; +} + +SND_CTL_PLUGIN_SYMBOL(oss); diff --git a/oss/pcm_oss.c b/oss/pcm_oss.c new file mode 100644 index 0000000..fb520f8 --- /dev/null +++ b/oss/pcm_oss.c @@ -0,0 +1,423 @@ +/* + * ALSA <-> OSS PCM I/O plugin + * + * Copyright (c) 2005 by Takashi Iwai + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include + +typedef struct snd_pcm_oss { + snd_pcm_ioplug_t io; + char *device; + int fd; + int fragment_set; + int caps; + int format; + unsigned int period_shift; + unsigned int periods; + unsigned int frame_bytes; +} snd_pcm_oss_t; + +static snd_pcm_sframes_t oss_write(snd_pcm_ioplug_t *io, + const snd_pcm_channel_area_t *areas, + snd_pcm_uframes_t offset, + snd_pcm_uframes_t size) +{ + snd_pcm_oss_t *oss = io->private_data; + const char *buf; + ssize_t result; + + /* we handle only an interleaved buffer */ + buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8; + size *= oss->frame_bytes; + result = write(oss->fd, buf, size); + if (result <= 0) + return result; + return result / oss->frame_bytes; +} + +static snd_pcm_sframes_t oss_read(snd_pcm_ioplug_t *io, + const snd_pcm_channel_area_t *areas, + snd_pcm_uframes_t offset, + snd_pcm_uframes_t size) +{ + snd_pcm_oss_t *oss = io->private_data; + char *buf; + ssize_t result; + + /* we handle only an interleaved buffer */ + buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8; + size *= oss->frame_bytes; + result = read(oss->fd, buf, size); + if (result <= 0) + return result; + return result / oss->frame_bytes; +} + +static snd_pcm_sframes_t oss_pointer(snd_pcm_ioplug_t *io) +{ + snd_pcm_oss_t *oss = io->private_data; + struct count_info info; + int ptr; + + if (ioctl(oss->fd, io->stream == SND_PCM_STREAM_PLAYBACK ? + SNDCTL_DSP_GETOPTR : SNDCTL_DSP_GETIPTR, &info) < 0) { + fprintf(stderr, "*** OSS: oss_pointer error\n"); + return 0; + } + ptr = snd_pcm_bytes_to_frames(io->pcm, info.ptr); + return ptr; +} + +static int oss_start(snd_pcm_ioplug_t *io) +{ + snd_pcm_oss_t *oss = io->private_data; + int tmp = io->stream == SND_PCM_STREAM_PLAYBACK ? + PCM_ENABLE_OUTPUT : PCM_ENABLE_INPUT; + + if (ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &tmp) < 0) { + fprintf(stderr, "*** OSS: trigger failed\n"); + if (io->stream == SND_PCM_STREAM_CAPTURE) + /* fake read to trigger */ + read(oss->fd, &tmp, 0); + } + return 0; +} + +static int oss_stop(snd_pcm_ioplug_t *io) +{ + snd_pcm_oss_t *oss = io->private_data; + int tmp = 0; + + ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &tmp); + return 0; +} + +static int oss_drain(snd_pcm_ioplug_t *io) +{ + snd_pcm_oss_t *oss = io->private_data; + + if (io->stream == SND_PCM_STREAM_PLAYBACK) + ioctl(oss->fd, SNDCTL_DSP_SYNC); + return 0; +} + +static int oss_prepare(snd_pcm_ioplug_t *io) +{ + snd_pcm_oss_t *oss = io->private_data; + int tmp; + + ioctl(oss->fd, SNDCTL_DSP_RESET); + + tmp = io->channels; + if (ioctl(oss->fd, SNDCTL_DSP_CHANNELS, &tmp) < 0) { + perror("SNDCTL_DSP_CHANNELS"); + return -EINVAL; + } + tmp = oss->format; + if (ioctl(oss->fd, SNDCTL_DSP_SETFMT, &tmp) < 0) { + perror("SNDCTL_DSP_SETFMT"); + return -EINVAL; + } + tmp = io->rate; + if (ioctl(oss->fd, SNDCTL_DSP_SPEED, &tmp) < 0 || + tmp > io->rate * 1.01 || tmp < io->rate * 0.99) { + perror("SNDCTL_DSP_SPEED"); + return -EINVAL; + } + return 0; +} + +static int oss_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params) +{ + snd_pcm_oss_t *oss = io->private_data; + int i, tmp, err; + unsigned int period_bytes; + long oflags, flags; + + oss->frame_bytes = (snd_pcm_format_physical_width(io->format) * io->channels) / 8; + switch (io->format) { + case SND_PCM_FORMAT_U8: + oss->format = AFMT_U8; + break; + case SND_PCM_FORMAT_S16_LE: + oss->format = AFMT_S16_LE; + break; + case SND_PCM_FORMAT_S16_BE: + oss->format = AFMT_S16_BE; + break; + default: + fprintf(stderr, "*** OSS: unsupported format %s\n", snd_pcm_format_name(io->format)); + return -EINVAL; + } + period_bytes = io->period_size * oss->frame_bytes; + oss->period_shift = 0; + for (i = 31; i >= 4; i--) { + if (period_bytes & (1U << i)) { + oss->period_shift = i; + break; + } + } + if (! oss->period_shift) { + fprintf(stderr, "*** OSS: invalid period size %d\n", (int)io->period_size); + return -EINVAL; + } + + _retry: + tmp = oss->period_shift | (oss->periods << 16); + if (ioctl(oss->fd, SNDCTL_DSP_SETFRAGMENT, &tmp) < 0) { + if (! oss->fragment_set) { + perror("SNDCTL_DSP_SETFRAGMENT"); + fprintf(stderr, "*** period shift = %d, periods = %d\n", oss->period_shift, oss->periods); + return -EINVAL; + } + /* OSS has no proper way to reinitialize the fragments */ + /* try to reopen the device */ + close(oss->fd); + oss->fd = open(oss->device, io->stream == SND_PCM_STREAM_PLAYBACK ? + O_WRONLY : O_RDONLY); + if (oss->fd < 0) { + err = -errno; + SNDERR("Cannot reopen the device %s", oss->device); + return err; + } + io->poll_fd = oss->fd; + io->poll_events = io->stream == SND_PCM_STREAM_PLAYBACK ? + POLLOUT : POLLIN; + snd_pcm_ioplug_reinit_status(io); + oss->fragment_set = 0; + goto _retry; + } + oss->fragment_set = 1; + + if ((flags = fcntl(oss->fd, F_GETFL)) < 0) { + err = -errno; + perror("F_GETFL"); + } else { + oflags = flags; + if (io->nonblock) + flags |= O_NONBLOCK; + else + flags &= ~O_NONBLOCK; + if (flags != oflags && + fcntl(oss->fd, F_SETFL, flags) < 0) { + err = -errno; + perror("F_SETFL"); + } + } + + return 0; +} + +#define ARRAY_SIZE(ary) (sizeof(ary)/sizeof(ary[0])) + +static int oss_hw_constraint(snd_pcm_oss_t *oss) +{ + snd_pcm_ioplug_t *io = &oss->io; + static snd_pcm_access_t access_list[] = { + SND_PCM_ACCESS_RW_INTERLEAVED, + SND_PCM_ACCESS_MMAP_INTERLEAVED + }; + unsigned int nformats; + unsigned int format[5]; + unsigned int nchannels; + unsigned int channel[6]; + /* period and buffer bytes must be power of two */ + static unsigned int bytes_list[] = { + 1U<<8, 1U<<9, 1U<<10, 1U<<11, 1U<<12, 1U<<13, 1U<<14, 1U<<15, + 1U<<16, 1U<<17, 1U<<18, 1U<<19, 1U<<20, 1U<<21, 1U<<22, 1U<<23 + }; + int i, err, tmp; + + /* check trigger */ + oss->caps = 0; + if (ioctl(oss->fd, SNDCTL_DSP_GETCAPS, &oss->caps) >= 0) { + if (! (oss->caps & DSP_CAP_TRIGGER)) + fprintf(stderr, "*** OSS: trigger is not supported!\n"); + } + + /* access type - interleaved only */ + if ((err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_ACCESS, + ARRAY_SIZE(access_list), access_list)) < 0) + return err; + + /* supported formats */ + tmp = 0; + ioctl(oss->fd, SNDCTL_DSP_GETFMTS, &tmp); + nformats = 0; + if (tmp & AFMT_U8) + format[nformats++] = SND_PCM_FORMAT_U8; + if (tmp & AFMT_S16_LE) + format[nformats++] = SND_PCM_FORMAT_S16_LE; + if (tmp & AFMT_S16_BE) + format[nformats++] = SND_PCM_FORMAT_S16_BE; + if (tmp & AFMT_MU_LAW) + format[nformats++] = SND_PCM_FORMAT_MU_LAW; + if (! nformats) + format[nformats++] = SND_PCM_FORMAT_S16; + if ((err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_FORMAT, + nformats, format)) < 0) + return err; + + /* supported channels */ + nchannels = 0; + for (i = 0; i < 6; i++) { + tmp = i + 1; + if (ioctl(oss->fd, SNDCTL_DSP_CHANNELS, &tmp) >= 0) + channel[nchannels++] = tmp; + } + if (! nchannels) /* assume 2ch stereo */ + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_CHANNELS, + 2, 2); + else + err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_CHANNELS, + nchannels, channel); + if (err < 0) + return err; + + /* supported rates */ + /* FIXME: should query? */ + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_RATE, 8000, 480000); + if (err < 0) + return err; + + /* period size (in power of two) */ + err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_PERIOD_BYTES, + ARRAY_SIZE(bytes_list), bytes_list); + if (err < 0) + return err; + /* periods */ + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_PERIODS, 2, 1024); + if (err < 0) + return err; + /* buffer size (in power of two) */ + err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_BUFFER_BYTES, + ARRAY_SIZE(bytes_list), bytes_list); + if (err < 0) + return err; + + return 0; +} + + +static int oss_close(snd_pcm_ioplug_t *io) +{ + snd_pcm_oss_t *oss = io->private_data; + + close(oss->fd); + free(oss->device); + free(oss); + return 0; +} + +static snd_pcm_ioplug_callback_t oss_playback_callback = { + .start = oss_start, + .stop = oss_stop, + .transfer = oss_write, + .pointer = oss_pointer, + .close = oss_close, + .hw_params = oss_hw_params, + .prepare = oss_prepare, + .drain = oss_drain, +}; + +static snd_pcm_ioplug_callback_t oss_capture_callback = { + .start = oss_start, + .stop = oss_stop, + .transfer = oss_read, + .pointer = oss_pointer, + .close = oss_close, + .hw_params = oss_hw_params, + .prepare = oss_prepare, + .drain = oss_drain, +}; + + +SND_PCM_PLUGIN_DEFINE_FUNC(oss) +{ + snd_config_iterator_t i, next; + const char *device = "/dev/dsp"; + int err; + snd_pcm_oss_t *oss; + + snd_config_for_each(i, next, conf) { + snd_config_t *n = snd_config_iterator_entry(i); + const char *id; + if (snd_config_get_id(n, &id) < 0) + continue; + if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0) + continue; + if (strcmp(id, "device") == 0) { + if (snd_config_get_string(n, &device) < 0) { + SNDERR("Invalid type for %s", id); + return -EINVAL; + } + continue; + } + SNDERR("Unknown field %s", id); + return -EINVAL; + } + + oss = calloc(1, sizeof(*oss)); + oss->device = strdup(device); + if (oss->device == NULL) { + SNDERR("cannot allocate"); + free(oss); + return -ENOMEM; + } + oss->fd = open(device, stream == SND_PCM_STREAM_PLAYBACK ? + O_WRONLY : O_RDONLY); + if (oss->fd < 0) { + err = -errno; + SNDERR("Cannot open device %s", device); + goto error; + } + + oss->io.version = SND_PCM_IOPLUG_VERSION; + oss->io.name = "ALSA <-> OSS PCM I/O Plugin"; + oss->io.poll_fd = oss->fd; + oss->io.poll_events = stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN; + oss->io.mmap_rw = 0; + oss->io.callback = stream == SND_PCM_STREAM_PLAYBACK ? + &oss_playback_callback : &oss_capture_callback; + oss->io.private_data = oss; + + err = snd_pcm_ioplug_create(&oss->io, name, stream, mode); + if (err < 0) + goto error; + + if ((err = oss_hw_constraint(oss)) < 0) { + snd_pcm_ioplug_delete(&oss->io); + return err; + } + + *pcmp = oss->io.pcm; + return 0; + + error: + if (oss->fd >= 0) + close(oss->fd); + free(oss->device); + free(oss); + return err; +} + +SND_PCM_PLUGIN_SYMBOL(oss); diff --git a/pcm/Makefile.am b/pcm/Makefile.am deleted file mode 100644 index 9f0dd9a..0000000 --- a/pcm/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -SUBDIRS = oss jack - diff --git a/pcm/jack/Makefile.am b/pcm/jack/Makefile.am deleted file mode 100644 index e71ce65..0000000 --- a/pcm/jack/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -asound_module_pcm_jack_LTLIBRARIES = libasound_module_pcm_jack.la - -asound_module_pcm_jackdir = $(libdir)/alsa-lib - -AM_CFLAGS = -Wall -g @ALSA_CFLAGS@ @JACK_CFLAGS@ -libasound_module_pcm_jack_la_SOURCES = pcm_jack.c -libasound_module_pcm_jack_la_LDFLAGS = -module -avoid-version -export-dynamic -libasound_module_pcm_jack_la_LIBADD = @ALSA_LIBS@ @JACK_LIBS@ - -EXTRA_DIST = README diff --git a/pcm/jack/README b/pcm/jack/README deleted file mode 100644 index 4579174..0000000 --- a/pcm/jack/README +++ /dev/null @@ -1,46 +0,0 @@ -JACK <--> ALSA PCM plugin -========================= - -This plugin converts the ALSA API over JACK (Jack Audio Connection -Kit, http://jackit.sf.net) API. ALSA native applications can work -transparently together with jackd for both playback and capture. - - ALSA apps (playback) -> ALSA-lib -> JACK plugin -> JACK deamon - ALSA apps (capture) <- ALSA-lib <- JACK plugin <- JACK daemon - -This plugin provides the PCM type "jack". The typical configuration -looks like below: - - pcm.jack { - type jack - playback_ports { - 0 alsa_pcm:playback_1 - 1 alsa_pcm:playback_1 - } - capture_ports { - 0 alsa_pcm:capture_1 - 1 alsa_pcm:pcapture_1 - } - } - -Put the above to ~/.asoundrc (or /etc/asound.conf), and use "jack" PCM -with your ALSA apps. For example, - - % aplay -Djack foo.wav - -The jack plugin can have two config options: playback_ports and -capture_ports. Both are compound type config, including the following -format: - { - channel port-name - channel port-name - ... - } -The first argument is the channel number (zero-based) and the second -is the corresponding JACK port name. - -The plugin is installed in /usr/lib/alsa-lib directory as default, -which is the default search path of additional plugins for alsa-lib. -On a 64bit system like x86-64, the proper prefix option (typically, ---prefix=/usr/lib64) must be given to configure script. - diff --git a/pcm/jack/pcm_jack.c b/pcm/jack/pcm_jack.c deleted file mode 100644 index 855f837..0000000 --- a/pcm/jack/pcm_jack.c +++ /dev/null @@ -1,428 +0,0 @@ -/* - * PCM - JACK plugin - * - * Copyright (c) 2003 by Maarten de Boer - * 2005 Takashi Iwai - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include -#include -#include - -typedef enum _jack_format { - SND_PCM_JACK_FORMAT_RAW -} snd_pcm_jack_format_t; - -typedef struct { - snd_pcm_ioplug_t io; - - int fd; - int activated; /* jack is activated? */ - - char **port_names; - unsigned int num_ports; - unsigned int hw_ptr; - unsigned int sample_bits; - - unsigned int channels; - snd_pcm_channel_area_t *areas; - - jack_port_t **ports; - jack_client_t *client; -} snd_pcm_jack_t; - -static void snd_pcm_jack_free(snd_pcm_jack_t *jack) -{ - if (jack) { - unsigned int i; - if (jack->client) - jack_client_close(jack->client); - if (jack->port_names) { - for (i = 0; i < jack->num_ports; i++) - free(jack->port_names[i]); - free(jack->port_names); - } - close(jack->fd); - close(jack->io.poll_fd); - free(jack->areas); - free(jack); - } -} - -static int snd_pcm_jack_close(snd_pcm_ioplug_t *io) -{ - snd_pcm_jack_t *jack = io->private_data; - snd_pcm_jack_free(jack); - return 0; -} - -static int snd_pcm_jack_poll_revents(snd_pcm_ioplug_t *io, - struct pollfd *pfds, unsigned int nfds, - unsigned short *revents) -{ - static char buf[1]; - - assert(pfds && nfds == 1 && revents); - - read(pfds[0].fd, buf, 1); - - *revents = pfds[0].revents; - return 0; -} - -static snd_pcm_sframes_t snd_pcm_jack_pointer(snd_pcm_ioplug_t *io) -{ - snd_pcm_jack_t *jack = io->private_data; - return jack->hw_ptr; -} - -static int -snd_pcm_jack_process_cb(jack_nframes_t nframes, snd_pcm_ioplug_t *io) -{ - snd_pcm_jack_t *jack = io->private_data; - const snd_pcm_channel_area_t *areas; - snd_pcm_uframes_t xfer = 0; - static char buf[1]; - unsigned int channel; - - for (channel = 0; channel < io->channels; channel++) { - jack->areas[channel].addr = - jack_port_get_buffer (jack->ports[channel], nframes); - jack->areas[channel].first = 0; - jack->areas[channel].step = jack->sample_bits; - } - - if (io->state != SND_PCM_STATE_RUNNING) { - if (io->stream == SND_PCM_STREAM_PLAYBACK) { - for (channel = 0; channel < io->channels; channel++) - snd_pcm_area_silence(&jack->areas[channel], 0, nframes, io->format); - return 0; - } - } - - areas = snd_pcm_ioplug_mmap_areas(io); - - while (xfer < nframes) { - snd_pcm_uframes_t frames = nframes - xfer; - snd_pcm_uframes_t offset = jack->hw_ptr; - snd_pcm_uframes_t cont = io->buffer_size - offset; - - if (cont < frames) - frames = cont; - - for (channel = 0; channel < io->channels; channel++) { - if (io->stream == SND_PCM_STREAM_PLAYBACK) - snd_pcm_area_copy(&jack->areas[channel], xfer, &areas[channel], offset, frames, io->format); - else - snd_pcm_area_copy(&areas[channel], offset, &jack->areas[channel], xfer, frames, io->format); - } - - jack->hw_ptr += frames; - jack->hw_ptr %= io->buffer_size; - xfer += frames; - } - - write(jack->fd, buf, 1); /* for polling */ - - return 0; -} - -static int snd_pcm_jack_prepare(snd_pcm_ioplug_t *io) -{ - snd_pcm_jack_t *jack = io->private_data; - unsigned int i; - - jack->hw_ptr = 0; - - if (jack->ports) - return 0; - - jack->ports = calloc(io->channels, sizeof(jack_port_t*)); - - for (i = 0; i < io->channels; i++) { - char port_name[32]; - if (io->stream == SND_PCM_STREAM_PLAYBACK) { - - sprintf(port_name, "out_%03d\n", i); - jack->ports[i] = jack_port_register(jack->client, port_name, - JACK_DEFAULT_AUDIO_TYPE, - JackPortIsOutput, 0); - } else { - sprintf(port_name, "in_%03d\n", i); - jack->ports[i] = jack_port_register(jack->client, port_name, - JACK_DEFAULT_AUDIO_TYPE, - JackPortIsInput, 0); - } - } - - jack_set_process_callback(jack->client, - (JackProcessCallback)snd_pcm_jack_process_cb, io); - return 0; -} - -static int snd_pcm_jack_start(snd_pcm_ioplug_t *io) -{ - snd_pcm_jack_t *jack = io->private_data; - unsigned int i; - - if (jack_activate (jack->client)) - return -EIO; - - jack->activated = 1; - - for (i = 0; i < io->channels && i < jack->num_ports; i++) { - if (jack->port_names[i]) { - const char *src, *dst; - if (io->stream == SND_PCM_STREAM_PLAYBACK) { - src = jack_port_name(jack->ports[i]); - dst = jack->port_names[i]; - } else { - src = jack->port_names[i]; - dst = jack_port_name(jack->ports[i]); - } - if (jack_connect(jack->client, src, dst)) { - fprintf(stderr, "cannot connect %s to %s\n", src, dst); - return -EIO; - } - } - } - - return 0; -} - -static int snd_pcm_jack_stop(snd_pcm_ioplug_t *io) -{ - snd_pcm_jack_t *jack = io->private_data; - - if (jack->activated) { - jack_deactivate(jack->client); - jack->activated = 0; - } -#if 0 - unsigned i; - for (i = 0; i < io->channels; i++) { - if (jack->ports[i]) { - jack_port_unregister(jack->client, jack->ports[i]); - jack->ports[i] = NULL; - } - } -#endif - return 0; -} - -static snd_pcm_ioplug_callback_t jack_pcm_callback = { - .close = snd_pcm_jack_close, - .start = snd_pcm_jack_start, - .stop = snd_pcm_jack_stop, - .pointer = snd_pcm_jack_pointer, - .prepare = snd_pcm_jack_prepare, - .poll_revents = snd_pcm_jack_poll_revents, -}; - -#define ARRAY_SIZE(ary) (sizeof(ary)/sizeof(ary[0])) - -static int jack_set_hw_constraint(snd_pcm_jack_t *jack) -{ - unsigned int access_list[] = { - SND_PCM_ACCESS_MMAP_INTERLEAVED, - SND_PCM_ACCESS_MMAP_NONINTERLEAVED, - SND_PCM_ACCESS_RW_INTERLEAVED, - SND_PCM_ACCESS_RW_NONINTERLEAVED - }; - unsigned int format = SND_PCM_FORMAT_FLOAT; - unsigned int rate = jack_get_sample_rate(jack->client); - int err; - - jack->sample_bits = snd_pcm_format_physical_width(format); - if ((err = snd_pcm_ioplug_set_param_list(&jack->io, SND_PCM_IOPLUG_HW_ACCESS, - ARRAY_SIZE(access_list), access_list)) < 0 || - (err = snd_pcm_ioplug_set_param_list(&jack->io, SND_PCM_IOPLUG_HW_FORMAT, - 1, &format)) < 0 || - (err = snd_pcm_ioplug_set_param_minmax(&jack->io, SND_PCM_IOPLUG_HW_CHANNELS, - jack->channels, jack->channels)) < 0 || - (err = snd_pcm_ioplug_set_param_minmax(&jack->io, SND_PCM_IOPLUG_HW_RATE, - rate, rate)) < 0 || - (err = snd_pcm_ioplug_set_param_minmax(&jack->io, SND_PCM_IOPLUG_HW_PERIOD_BYTES, - 128, 64*1024)) < 0 || - (err = snd_pcm_ioplug_set_param_minmax(&jack->io, SND_PCM_IOPLUG_HW_PERIODS, - 2, 64)) < 0) - return err; - - return 0; -} - -static int parse_ports(snd_pcm_jack_t *jack, snd_config_t *conf) -{ - snd_config_iterator_t i, next; - char **ports = NULL; - unsigned int cnt = 0; - unsigned int channel; - - if (conf) { - snd_config_for_each(i, next, conf) { - snd_config_t *n = snd_config_iterator_entry(i); - const char *id; - if (snd_config_get_id(n, &id) < 0) - continue; - cnt++; - } - jack->port_names = ports = calloc(cnt, sizeof(char*)); - if (ports == NULL) - return -ENOMEM; - jack->num_ports = cnt; - snd_config_for_each(i, next, conf) { - snd_config_t *n = snd_config_iterator_entry(i); - const char *id; - const char *port; - - if (snd_config_get_id(n, &id) < 0) - continue; - channel = atoi(id); - if (snd_config_get_string(n, &port) < 0) - continue; - ports[channel] = port ? strdup(port) : NULL; - } - } - return 0; -} - -static int snd_pcm_jack_open(snd_pcm_t **pcmp, const char *name, - snd_config_t *playback_conf, - snd_config_t *capture_conf, - snd_pcm_stream_t stream, int mode) -{ - snd_pcm_jack_t *jack; - int err; - int fd[2]; - static unsigned int num = 0; - char jack_client_name[32]; - - assert(pcmp); - jack = calloc(1, sizeof(*jack)); - if (!jack) - return -ENOMEM; - - err = parse_ports(jack, stream == SND_PCM_STREAM_PLAYBACK ? - playback_conf : capture_conf); - if (err) { - snd_pcm_jack_free(jack); - return err; - } - - jack->channels = jack->num_ports; - if (jack->channels == 0) { - SNDERR("define the %s_ports section", - stream == SND_PCM_STREAM_PLAYBACK ? "playback" : "capture"); - snd_pcm_jack_free(jack); - return -EINVAL; - } - - if (snprintf(jack_client_name, sizeof(jack_client_name), "alsa-jack.%s%s.%d.%d", name, - stream == SND_PCM_STREAM_PLAYBACK ? "P" : "C", getpid(), num++) - >= (int)sizeof(jack_client_name)) { - fprintf(stderr, "%s: WARNING: JACK client name '%s' truncated to %d characters, might not be unique\n", - __func__, jack_client_name, (int)strlen(jack_client_name)); - } - - jack->client = jack_client_new(jack_client_name); - - if (jack->client == 0) { - snd_pcm_jack_free(jack); - return -ENOENT; - } - - jack->areas = calloc(jack->channels, sizeof(snd_pcm_channel_area_t)); - if (! jack->areas) { - snd_pcm_jack_free(jack); - return -ENOMEM; - } - - socketpair(AF_LOCAL, SOCK_STREAM, 0, fd); - - jack->fd = fd[0]; - - jack->io.version = SND_PCM_IOPLUG_VERSION; - jack->io.name = "ALSA <-> JACK PCM I/O Plugin"; - jack->io.callback = &jack_pcm_callback; - jack->io.private_data = jack; - jack->io.poll_fd = fd[1]; - jack->io.poll_events = POLLIN; - jack->io.mmap_rw = 1; - - err = snd_pcm_ioplug_create(&jack->io, name, stream, mode); - if (err < 0) { - snd_pcm_jack_free(jack); - return err; - } - - err = jack_set_hw_constraint(jack); - if (err < 0) { - snd_pcm_ioplug_delete(&jack->io); - return err; - } - - *pcmp = jack->io.pcm; - - return 0; -} - - -SND_PCM_PLUGIN_DEFINE_FUNC(jack) -{ - snd_config_iterator_t i, next; - snd_config_t *playback_conf = NULL; - snd_config_t *capture_conf = NULL; - int err; - - snd_config_for_each(i, next, conf) { - snd_config_t *n = snd_config_iterator_entry(i); - const char *id; - if (snd_config_get_id(n, &id) < 0) - continue; - if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0) - continue; - if (strcmp(id, "playback_ports") == 0) { - if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) { - SNDERR("Invalid type for %s", id); - return -EINVAL; - } - playback_conf = n; - continue; - } - if (strcmp(id, "capture_ports") == 0) { - if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) { - SNDERR("Invalid type for %s", id); - return -EINVAL; - } - capture_conf = n; - continue; - } - SNDERR("Unknown field %s", id); - return -EINVAL; - } - - err = snd_pcm_jack_open(pcmp, name, playback_conf, capture_conf, stream, mode); - - return err; -} - -SND_PCM_PLUGIN_SYMBOL(jack); diff --git a/pcm/oss/Makefile.am b/pcm/oss/Makefile.am deleted file mode 100644 index c907231..0000000 --- a/pcm/oss/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -asound_module_pcm_oss_LTLIBRARIES = libasound_module_pcm_oss.la - -asound_module_pcm_ossdir = $(libdir)/alsa-lib - -AM_CFLAGS = -Wall -g @ALSA_CFLAGS@ -libasound_module_pcm_oss_la_SOURCES = pcm_oss.c -libasound_module_pcm_oss_la_LDFLAGS = -module -avoid-version -export-dynamic -libasound_module_pcm_oss_la_LIBADD = @ALSA_LIBS@ - -EXTRA_DIST = README diff --git a/pcm/oss/README b/pcm/oss/README deleted file mode 100644 index 42b73cb..0000000 --- a/pcm/oss/README +++ /dev/null @@ -1,33 +0,0 @@ -OSS <--> ALSA PCM plugin -======================== - -This plugin converts the ALSA API over OSS API. With this plugin, -ALSA native apps can run on OSS drivers. - -This plugin provides the PCM type "oss". The typical configuration -looks like below: - - pcm.oss { - type oss - device /dev/dsp - } - -Put the above to ~/.asoundrc (or /etc/asound.conf), and use "oss" PCM -with your ALSA apps. For example, - - % aplay -Doss foo.wav - -For playing arbitrary formats, you should use "plug" layer together, - - % aplay -Dplug:oss foo.wav - -The oss plugin can have an option: device. This specifies the device -file path of OSS to open. If not given, /dev/dsp is used. - -The function supported by this plugin is limited. For example, you -cannot use dmix together with this plugin. Don't expect too much :) - -The plugin is installed in /usr/lib/alsa-lib directory as default, -which is the default search path of additional plugins for alsa-lib. -On a 64bit system like x86-64, the proper prefix option (typically, ---prefix=/usr/lib64) must be given to configure script. diff --git a/pcm/oss/pcm_oss.c b/pcm/oss/pcm_oss.c deleted file mode 100644 index fb520f8..0000000 --- a/pcm/oss/pcm_oss.c +++ /dev/null @@ -1,423 +0,0 @@ -/* - * ALSA <-> OSS PCM I/O plugin - * - * Copyright (c) 2005 by Takashi Iwai - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include - -typedef struct snd_pcm_oss { - snd_pcm_ioplug_t io; - char *device; - int fd; - int fragment_set; - int caps; - int format; - unsigned int period_shift; - unsigned int periods; - unsigned int frame_bytes; -} snd_pcm_oss_t; - -static snd_pcm_sframes_t oss_write(snd_pcm_ioplug_t *io, - const snd_pcm_channel_area_t *areas, - snd_pcm_uframes_t offset, - snd_pcm_uframes_t size) -{ - snd_pcm_oss_t *oss = io->private_data; - const char *buf; - ssize_t result; - - /* we handle only an interleaved buffer */ - buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8; - size *= oss->frame_bytes; - result = write(oss->fd, buf, size); - if (result <= 0) - return result; - return result / oss->frame_bytes; -} - -static snd_pcm_sframes_t oss_read(snd_pcm_ioplug_t *io, - const snd_pcm_channel_area_t *areas, - snd_pcm_uframes_t offset, - snd_pcm_uframes_t size) -{ - snd_pcm_oss_t *oss = io->private_data; - char *buf; - ssize_t result; - - /* we handle only an interleaved buffer */ - buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8; - size *= oss->frame_bytes; - result = read(oss->fd, buf, size); - if (result <= 0) - return result; - return result / oss->frame_bytes; -} - -static snd_pcm_sframes_t oss_pointer(snd_pcm_ioplug_t *io) -{ - snd_pcm_oss_t *oss = io->private_data; - struct count_info info; - int ptr; - - if (ioctl(oss->fd, io->stream == SND_PCM_STREAM_PLAYBACK ? - SNDCTL_DSP_GETOPTR : SNDCTL_DSP_GETIPTR, &info) < 0) { - fprintf(stderr, "*** OSS: oss_pointer error\n"); - return 0; - } - ptr = snd_pcm_bytes_to_frames(io->pcm, info.ptr); - return ptr; -} - -static int oss_start(snd_pcm_ioplug_t *io) -{ - snd_pcm_oss_t *oss = io->private_data; - int tmp = io->stream == SND_PCM_STREAM_PLAYBACK ? - PCM_ENABLE_OUTPUT : PCM_ENABLE_INPUT; - - if (ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &tmp) < 0) { - fprintf(stderr, "*** OSS: trigger failed\n"); - if (io->stream == SND_PCM_STREAM_CAPTURE) - /* fake read to trigger */ - read(oss->fd, &tmp, 0); - } - return 0; -} - -static int oss_stop(snd_pcm_ioplug_t *io) -{ - snd_pcm_oss_t *oss = io->private_data; - int tmp = 0; - - ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &tmp); - return 0; -} - -static int oss_drain(snd_pcm_ioplug_t *io) -{ - snd_pcm_oss_t *oss = io->private_data; - - if (io->stream == SND_PCM_STREAM_PLAYBACK) - ioctl(oss->fd, SNDCTL_DSP_SYNC); - return 0; -} - -static int oss_prepare(snd_pcm_ioplug_t *io) -{ - snd_pcm_oss_t *oss = io->private_data; - int tmp; - - ioctl(oss->fd, SNDCTL_DSP_RESET); - - tmp = io->channels; - if (ioctl(oss->fd, SNDCTL_DSP_CHANNELS, &tmp) < 0) { - perror("SNDCTL_DSP_CHANNELS"); - return -EINVAL; - } - tmp = oss->format; - if (ioctl(oss->fd, SNDCTL_DSP_SETFMT, &tmp) < 0) { - perror("SNDCTL_DSP_SETFMT"); - return -EINVAL; - } - tmp = io->rate; - if (ioctl(oss->fd, SNDCTL_DSP_SPEED, &tmp) < 0 || - tmp > io->rate * 1.01 || tmp < io->rate * 0.99) { - perror("SNDCTL_DSP_SPEED"); - return -EINVAL; - } - return 0; -} - -static int oss_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params) -{ - snd_pcm_oss_t *oss = io->private_data; - int i, tmp, err; - unsigned int period_bytes; - long oflags, flags; - - oss->frame_bytes = (snd_pcm_format_physical_width(io->format) * io->channels) / 8; - switch (io->format) { - case SND_PCM_FORMAT_U8: - oss->format = AFMT_U8; - break; - case SND_PCM_FORMAT_S16_LE: - oss->format = AFMT_S16_LE; - break; - case SND_PCM_FORMAT_S16_BE: - oss->format = AFMT_S16_BE; - break; - default: - fprintf(stderr, "*** OSS: unsupported format %s\n", snd_pcm_format_name(io->format)); - return -EINVAL; - } - period_bytes = io->period_size * oss->frame_bytes; - oss->period_shift = 0; - for (i = 31; i >= 4; i--) { - if (period_bytes & (1U << i)) { - oss->period_shift = i; - break; - } - } - if (! oss->period_shift) { - fprintf(stderr, "*** OSS: invalid period size %d\n", (int)io->period_size); - return -EINVAL; - } - - _retry: - tmp = oss->period_shift | (oss->periods << 16); - if (ioctl(oss->fd, SNDCTL_DSP_SETFRAGMENT, &tmp) < 0) { - if (! oss->fragment_set) { - perror("SNDCTL_DSP_SETFRAGMENT"); - fprintf(stderr, "*** period shift = %d, periods = %d\n", oss->period_shift, oss->periods); - return -EINVAL; - } - /* OSS has no proper way to reinitialize the fragments */ - /* try to reopen the device */ - close(oss->fd); - oss->fd = open(oss->device, io->stream == SND_PCM_STREAM_PLAYBACK ? - O_WRONLY : O_RDONLY); - if (oss->fd < 0) { - err = -errno; - SNDERR("Cannot reopen the device %s", oss->device); - return err; - } - io->poll_fd = oss->fd; - io->poll_events = io->stream == SND_PCM_STREAM_PLAYBACK ? - POLLOUT : POLLIN; - snd_pcm_ioplug_reinit_status(io); - oss->fragment_set = 0; - goto _retry; - } - oss->fragment_set = 1; - - if ((flags = fcntl(oss->fd, F_GETFL)) < 0) { - err = -errno; - perror("F_GETFL"); - } else { - oflags = flags; - if (io->nonblock) - flags |= O_NONBLOCK; - else - flags &= ~O_NONBLOCK; - if (flags != oflags && - fcntl(oss->fd, F_SETFL, flags) < 0) { - err = -errno; - perror("F_SETFL"); - } - } - - return 0; -} - -#define ARRAY_SIZE(ary) (sizeof(ary)/sizeof(ary[0])) - -static int oss_hw_constraint(snd_pcm_oss_t *oss) -{ - snd_pcm_ioplug_t *io = &oss->io; - static snd_pcm_access_t access_list[] = { - SND_PCM_ACCESS_RW_INTERLEAVED, - SND_PCM_ACCESS_MMAP_INTERLEAVED - }; - unsigned int nformats; - unsigned int format[5]; - unsigned int nchannels; - unsigned int channel[6]; - /* period and buffer bytes must be power of two */ - static unsigned int bytes_list[] = { - 1U<<8, 1U<<9, 1U<<10, 1U<<11, 1U<<12, 1U<<13, 1U<<14, 1U<<15, - 1U<<16, 1U<<17, 1U<<18, 1U<<19, 1U<<20, 1U<<21, 1U<<22, 1U<<23 - }; - int i, err, tmp; - - /* check trigger */ - oss->caps = 0; - if (ioctl(oss->fd, SNDCTL_DSP_GETCAPS, &oss->caps) >= 0) { - if (! (oss->caps & DSP_CAP_TRIGGER)) - fprintf(stderr, "*** OSS: trigger is not supported!\n"); - } - - /* access type - interleaved only */ - if ((err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_ACCESS, - ARRAY_SIZE(access_list), access_list)) < 0) - return err; - - /* supported formats */ - tmp = 0; - ioctl(oss->fd, SNDCTL_DSP_GETFMTS, &tmp); - nformats = 0; - if (tmp & AFMT_U8) - format[nformats++] = SND_PCM_FORMAT_U8; - if (tmp & AFMT_S16_LE) - format[nformats++] = SND_PCM_FORMAT_S16_LE; - if (tmp & AFMT_S16_BE) - format[nformats++] = SND_PCM_FORMAT_S16_BE; - if (tmp & AFMT_MU_LAW) - format[nformats++] = SND_PCM_FORMAT_MU_LAW; - if (! nformats) - format[nformats++] = SND_PCM_FORMAT_S16; - if ((err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_FORMAT, - nformats, format)) < 0) - return err; - - /* supported channels */ - nchannels = 0; - for (i = 0; i < 6; i++) { - tmp = i + 1; - if (ioctl(oss->fd, SNDCTL_DSP_CHANNELS, &tmp) >= 0) - channel[nchannels++] = tmp; - } - if (! nchannels) /* assume 2ch stereo */ - err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_CHANNELS, - 2, 2); - else - err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_CHANNELS, - nchannels, channel); - if (err < 0) - return err; - - /* supported rates */ - /* FIXME: should query? */ - err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_RATE, 8000, 480000); - if (err < 0) - return err; - - /* period size (in power of two) */ - err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_PERIOD_BYTES, - ARRAY_SIZE(bytes_list), bytes_list); - if (err < 0) - return err; - /* periods */ - err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_PERIODS, 2, 1024); - if (err < 0) - return err; - /* buffer size (in power of two) */ - err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_BUFFER_BYTES, - ARRAY_SIZE(bytes_list), bytes_list); - if (err < 0) - return err; - - return 0; -} - - -static int oss_close(snd_pcm_ioplug_t *io) -{ - snd_pcm_oss_t *oss = io->private_data; - - close(oss->fd); - free(oss->device); - free(oss); - return 0; -} - -static snd_pcm_ioplug_callback_t oss_playback_callback = { - .start = oss_start, - .stop = oss_stop, - .transfer = oss_write, - .pointer = oss_pointer, - .close = oss_close, - .hw_params = oss_hw_params, - .prepare = oss_prepare, - .drain = oss_drain, -}; - -static snd_pcm_ioplug_callback_t oss_capture_callback = { - .start = oss_start, - .stop = oss_stop, - .transfer = oss_read, - .pointer = oss_pointer, - .close = oss_close, - .hw_params = oss_hw_params, - .prepare = oss_prepare, - .drain = oss_drain, -}; - - -SND_PCM_PLUGIN_DEFINE_FUNC(oss) -{ - snd_config_iterator_t i, next; - const char *device = "/dev/dsp"; - int err; - snd_pcm_oss_t *oss; - - snd_config_for_each(i, next, conf) { - snd_config_t *n = snd_config_iterator_entry(i); - const char *id; - if (snd_config_get_id(n, &id) < 0) - continue; - if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0) - continue; - if (strcmp(id, "device") == 0) { - if (snd_config_get_string(n, &device) < 0) { - SNDERR("Invalid type for %s", id); - return -EINVAL; - } - continue; - } - SNDERR("Unknown field %s", id); - return -EINVAL; - } - - oss = calloc(1, sizeof(*oss)); - oss->device = strdup(device); - if (oss->device == NULL) { - SNDERR("cannot allocate"); - free(oss); - return -ENOMEM; - } - oss->fd = open(device, stream == SND_PCM_STREAM_PLAYBACK ? - O_WRONLY : O_RDONLY); - if (oss->fd < 0) { - err = -errno; - SNDERR("Cannot open device %s", device); - goto error; - } - - oss->io.version = SND_PCM_IOPLUG_VERSION; - oss->io.name = "ALSA <-> OSS PCM I/O Plugin"; - oss->io.poll_fd = oss->fd; - oss->io.poll_events = stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN; - oss->io.mmap_rw = 0; - oss->io.callback = stream == SND_PCM_STREAM_PLAYBACK ? - &oss_playback_callback : &oss_capture_callback; - oss->io.private_data = oss; - - err = snd_pcm_ioplug_create(&oss->io, name, stream, mode); - if (err < 0) - goto error; - - if ((err = oss_hw_constraint(oss)) < 0) { - snd_pcm_ioplug_delete(&oss->io); - return err; - } - - *pcmp = oss->io.pcm; - return 0; - - error: - if (oss->fd >= 0) - close(oss->fd); - free(oss->device); - free(oss); - return err; -} - -SND_PCM_PLUGIN_SYMBOL(oss); diff --git a/polyp/Makefile.am b/polyp/Makefile.am new file mode 100644 index 0000000..858de93 --- /dev/null +++ b/polyp/Makefile.am @@ -0,0 +1,14 @@ +asound_module_pcm_LTLIBRARIES = libasound_module_pcm_polyp.la +asound_module_ctl_LTLIBRARIES = libasound_module_ctl_polyp.la + +asound_module_pcmdir = $(libdir)/alsa-lib +asound_module_ctldir = $(libdir)/alsa-lib + +AM_CFLAGS = -Wall -g @ALSA_CFLAGS@ $(PTHREAD_CFLAGS) $(polypaudio_CFLAGS) -D_GNU_SOURCE +AM_LDFLAGS = -module -avoid-version -export-dynamic + +libasound_module_pcm_polyp_la_SOURCES = pcm_polyp.c polyp.c polyp.h +libasound_module_pcm_polyp_la_LIBADD = @ALSA_LIBS@ $(PTHREAD_LIBS) $(polypaudio_LIBS) + +libasound_module_ctl_polyp_la_SOURCES = ctl_polyp.c polyp.c polyp.h +libasound_module_ctl_polyp_la_LIBADD = @ALSA_LIBS@ $(PTHREAD_LIBS) $(polypaudio_LIBS) diff --git a/polyp/ctl_polyp.c b/polyp/ctl_polyp.c new file mode 100644 index 0000000..16043bf --- /dev/null +++ b/polyp/ctl_polyp.c @@ -0,0 +1,455 @@ +/* + * ALSA <-> Polypaudio mixer control plugin + * + * Copyright (c) 2006 by Pierre Ossman + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include +#include + +#include "polyp.h" + +typedef struct snd_ctl_polyp { + snd_ctl_ext_t ext; + + snd_polyp_t *p; + + char *device; + + pa_cvolume volume; + + int subscribed; + int updated; +} snd_ctl_polyp_t; + +#define MIXER_NAME "Master" + +static void sink_info_cb(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) +{ + snd_ctl_polyp_t *ctl = (snd_ctl_polyp_t*)userdata; + int chan; + + if (is_last) + return; + + assert(ctl && i); + + if (ctl->volume.channels == i->volume.channels) { + for (chan = 0;chan < ctl->volume.channels;chan++) + if (i->volume.values[chan] != ctl->volume.values[chan]) + break; + + if (chan == ctl->volume.channels) + return; + + ctl->updated = 1; + } + + memcpy(&ctl->volume, &i->volume, sizeof(pa_cvolume)); +} + +static void event_cb(pa_context *c, pa_subscription_event_type_t t, + uint32_t index, void *userdata) +{ + snd_ctl_polyp_t *ctl = (snd_ctl_polyp_t*)userdata; + pa_operation *o; + + assert(ctl && ctl->p && ctl->p->context); + + o = pa_context_get_sink_info_by_name(ctl->p->context, ctl->device, + sink_info_cb, ctl); + pa_operation_unref(o); +} + +static int polyp_update_volume(snd_ctl_polyp_t *ctl) +{ + int err; + pa_operation *o; + + assert(ctl && ctl->p && ctl->p->context); + + o = pa_context_get_sink_info_by_name(ctl->p->context, ctl->device, + sink_info_cb, ctl); + err = polyp_wait_operation(ctl->p, o); + pa_operation_unref(o); + if (err < 0) + return err; + + return 0; +} + +static int polyp_elem_count(snd_ctl_ext_t *ext) +{ + snd_ctl_polyp_t *ctl = ext->private_data; + + assert(ctl); + + if (ctl->device) + return 1; + + return 0; +} + +static int polyp_elem_list(snd_ctl_ext_t *ext, unsigned int offset, + snd_ctl_elem_id_t *id) +{ + snd_ctl_polyp_t *ctl = ext->private_data; + + assert(ctl); + + snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER); + snd_ctl_elem_id_set_name(id, MIXER_NAME); + + return 0; +} + +static snd_ctl_ext_key_t polyp_find_elem(snd_ctl_ext_t *ext, + const snd_ctl_elem_id_t *id) +{ + const char *name; + + name = snd_ctl_elem_id_get_name(id); + + if (strcmp(name, MIXER_NAME) == 0) + return 0; + + return SND_CTL_EXT_KEY_NOT_FOUND; +} + +static int polyp_get_attribute(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + int *type, unsigned int *acc, unsigned int *count) +{ + snd_ctl_polyp_t *ctl = ext->private_data; + int err; + + assert(ctl && ctl->p); + + if (key != 0) + return -EINVAL; + + err = polyp_finish_poll(ctl->p); + if (err < 0) + return err; + + err = polyp_check_connection(ctl->p); + if (err < 0) + return err; + + err = polyp_update_volume(ctl); + if (err < 0) + return err; + + *type = SND_CTL_ELEM_TYPE_INTEGER; + *acc = SND_CTL_EXT_ACCESS_READWRITE; + *count = ctl->volume.channels; + + return 0; +} + +static int polyp_get_integer_info(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + long *imin, long *imax, long *istep) +{ + if (key != 0) + return -EINVAL; + + *istep = 1; + *imin = 0; + *imax = PA_VOLUME_NORM; + + return 0; +} + +static int polyp_read_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + long *value) +{ + snd_ctl_polyp_t *ctl = ext->private_data; + int err, i; + + assert(ctl && ctl->p); + + if (key != 0) + return -EINVAL; + + err = polyp_finish_poll(ctl->p); + if (err < 0) + return err; + + err = polyp_check_connection(ctl->p); + if (err < 0) + return err; + + err = polyp_update_volume(ctl); + if (err < 0) + return err; + + for (i = 0;i < ctl->volume.channels;i++) + value[i] = ctl->volume.values[i]; + + return 0; +} + +static int polyp_write_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + long *value) +{ + snd_ctl_polyp_t *ctl = ext->private_data; + int err, i; + pa_cvolume vol; + pa_operation *o; + + assert(ctl && ctl->p && ctl->p->context); + + if (key != 0) + return -EINVAL; + + err = polyp_finish_poll(ctl->p); + if (err < 0) + return err; + + err = polyp_check_connection(ctl->p); + if (err < 0) + return err; + + err = polyp_update_volume(ctl); + if (err < 0) + return err; + + for (i = 0;i < ctl->volume.channels;i++) + if (value[i] != ctl->volume.values[i]) + break; + + if (i == ctl->volume.channels) + return 0; + + memset(&vol, 0, sizeof(pa_cvolume)); + + vol.channels = ctl->volume.channels; + for (i = 0;i < vol.channels;i++) + vol.values[i] = value[i]; + + o = pa_context_set_sink_volume_by_name(ctl->p->context, ctl->device, &vol, + NULL, NULL); + + err = polyp_wait_operation(ctl->p, o); + pa_operation_unref(o); + if (err < 0) + return err; + + return 1; +} + +static void polyp_subscribe_events(snd_ctl_ext_t *ext, int subscribe) +{ + snd_ctl_polyp_t *ctl = ext->private_data; + + assert(ctl); + + ctl->subscribed = !!(subscribe & SND_CTL_EVENT_MASK_VALUE); +} + +static int polyp_read_event(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id, + unsigned int *event_mask) +{ + snd_ctl_polyp_t *ctl = ext->private_data; + + assert(ctl); + + if (!ctl->updated || !ctl->subscribed) + return -EAGAIN; + + polyp_elem_list(ext, 0, id); + *event_mask = SND_CTL_EVENT_MASK_VALUE; + ctl->updated = 0; + + return 1; +} + +static int polyp_ctl_poll_descriptors_count(snd_ctl_ext_t *ext) +{ + snd_ctl_polyp_t *ctl = ext->private_data; + + assert(ctl && ctl->p); + + return polyp_poll_descriptors_count(ctl->p); +} + +static int polyp_ctl_poll_descriptors(snd_ctl_ext_t *ext, struct pollfd *pfd, unsigned int space) +{ + snd_ctl_polyp_t *ctl = ext->private_data; + + assert(ctl && ctl->p); + + return polyp_poll_descriptors(ctl->p, pfd, space); +} + +static int polyp_ctl_poll_revents(snd_ctl_ext_t *ext, struct pollfd *pfd, unsigned int nfds, unsigned short *revents) +{ + snd_ctl_polyp_t *ctl = ext->private_data; + int err; + + assert(ctl && ctl->p); + + err = polyp_poll_revents(ctl->p, pfd, nfds, revents); + if (err < 0) + return err; + + *revents = 0; + + if (ctl->updated) + *revents |= POLLIN; + + return 0; +} + +static void polyp_close(snd_ctl_ext_t *ext) +{ + snd_ctl_polyp_t *ctl = ext->private_data; + + assert(ctl); + + if (ctl->p) + polyp_free(ctl->p); + + if (ctl->device) + free(ctl->device); + + free(ctl); +} + +static snd_ctl_ext_callback_t polyp_ext_callback = { + .elem_count = polyp_elem_count, + .elem_list = polyp_elem_list, + .find_elem = polyp_find_elem, + .get_attribute = polyp_get_attribute, + .get_integer_info = polyp_get_integer_info, + .read_integer = polyp_read_integer, + .write_integer = polyp_write_integer, + .subscribe_events = polyp_subscribe_events, + .read_event = polyp_read_event, + .poll_descriptors_count = polyp_ctl_poll_descriptors_count, + .poll_descriptors = polyp_ctl_poll_descriptors, + .poll_revents = polyp_ctl_poll_revents, + .close = polyp_close, +}; + +static void server_info_cb(pa_context *c, const pa_server_info*i, void *userdata) +{ + snd_ctl_polyp_t *ctl = (snd_ctl_polyp_t*)userdata; + + assert(ctl && i && i->default_sink_name); + + ctl->device = strdup(i->default_sink_name); +} + +SND_CTL_PLUGIN_DEFINE_FUNC(polyp) +{ + snd_config_iterator_t i, next; + const char *server = NULL; + const char *device = NULL; + int err; + snd_ctl_polyp_t *ctl; + pa_operation *o; + + snd_config_for_each(i, next, conf) { + snd_config_t *n = snd_config_iterator_entry(i); + const char *id; + if (snd_config_get_id(n, &id) < 0) + continue; + if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0) + continue; + if (strcmp(id, "server") == 0) { + if (snd_config_get_string(n, &server) < 0) { + SNDERR("Invalid type for %s", id); + return -EINVAL; + } + continue; + } + if (strcmp(id, "device") == 0) { + if (snd_config_get_string(n, &device) < 0) { + SNDERR("Invalid type for %s", id); + return -EINVAL; + } + continue; + } + SNDERR("Unknown field %s", id); + return -EINVAL; + } + + ctl = calloc(1, sizeof(*ctl)); + + ctl->p = polyp_new(); + assert(ctl->p); + + err = polyp_connect(ctl->p, server); + if (err < 0) + goto error; + + err = polyp_start_thread(ctl->p); + if (err < 0) + goto error; + + if (device) + ctl->device = strdup(device); + else { + o = pa_context_get_server_info(ctl->p->context, server_info_cb, ctl); + err = polyp_wait_operation(ctl->p, o); + pa_operation_unref(o); + if (err < 0) + goto error; + } + + pa_context_set_subscribe_callback(ctl->p->context, event_cb, ctl); + + o = pa_context_subscribe(ctl->p->context, PA_SUBSCRIPTION_MASK_SINK, NULL, NULL); + err = polyp_wait_operation(ctl->p, o); + pa_operation_unref(o); + if (err < 0) + goto error; + + ctl->ext.version = SND_CTL_EXT_VERSION; + ctl->ext.card_idx = 0; + strncpy(ctl->ext.id, "polyp", sizeof(ctl->ext.id) - 1); + strncpy(ctl->ext.driver, "Polypaudio plugin", sizeof(ctl->ext.driver) - 1); + strncpy(ctl->ext.name, "Polypaudio", sizeof(ctl->ext.name) - 1); + strncpy(ctl->ext.longname, "Polypaudio", sizeof(ctl->ext.longname) - 1); + strncpy(ctl->ext.mixername, "Polypaudio", sizeof(ctl->ext.mixername) - 1); + ctl->ext.poll_fd = -1; + ctl->ext.callback = &polyp_ext_callback; + ctl->ext.private_data = ctl; + + err = snd_ctl_ext_create(&ctl->ext, name, mode); + if (err < 0) + goto error; + + *handlep = ctl->ext.handle; + + return 0; + +error: + if (ctl->device) + free(ctl->device); + + if (ctl->p) + polyp_free(ctl->p); + + free(ctl); + + return err; +} + +SND_CTL_PLUGIN_SYMBOL(polyp); diff --git a/polyp/pcm_polyp.c b/polyp/pcm_polyp.c new file mode 100644 index 0000000..e3ea506 --- /dev/null +++ b/polyp/pcm_polyp.c @@ -0,0 +1,626 @@ +/* + * ALSA <-> Polypaudio PCM I/O plugin + * + * Copyright (c) 2006 by Pierre Ossman + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +#include +#include + +#include "polyp.h" + +typedef struct snd_pcm_polyp { + snd_pcm_ioplug_t io; + + snd_polyp_t *p; + + char *device; + + /* Since ALSA expects a ring buffer we must do some voodoo. */ + size_t last_size; + size_t ptr; + + size_t offset; + + pa_stream *stream; + + pa_sample_spec ss; + unsigned int frame_size; + pa_buffer_attr buffer_attr; +} snd_pcm_polyp_t; + +static void update_ptr(snd_pcm_polyp_t *pcm) +{ + size_t size; + + if (pcm->io.stream == SND_PCM_STREAM_PLAYBACK) + size = pa_stream_writable_size(pcm->stream); + else + size = pa_stream_readable_size(pcm->stream) - pcm->offset; + + if (size > pcm->last_size) { + pcm->ptr += size - pcm->last_size; + pcm->ptr %= pcm->buffer_attr.maxlength; + } + + pcm->last_size = size; +} + +static int polyp_start(snd_pcm_ioplug_t *io) +{ + snd_pcm_polyp_t *pcm = io->private_data; + pa_operation *o; + int err; + + assert(pcm && pcm->p && pcm->stream); + + err = polyp_finish_poll(pcm->p); + if (err < 0) + return err; + + err = polyp_check_connection(pcm->p); + if (err < 0) + return err; + + o = pa_stream_cork(pcm->stream, 0, NULL, NULL); + assert(o); + + err = polyp_wait_operation(pcm->p, o); + + pa_operation_unref(o); + + if (err < 0) + return -EIO; + + return 0; +} + +static int polyp_stop(snd_pcm_ioplug_t *io) +{ + snd_pcm_polyp_t *pcm = io->private_data; + pa_operation *o; + int err; + + assert(pcm && pcm->p && pcm->stream); + + err = polyp_finish_poll(pcm->p); + if (err < 0) + return err; + + err = polyp_check_connection(pcm->p); + if (err < 0) + return err; + + o = pa_stream_flush(pcm->stream, NULL, NULL); + assert(o); + + err = polyp_wait_operation(pcm->p, o); + + pa_operation_unref(o); + + if (err < 0) + return -EIO; + + o = pa_stream_cork(pcm->stream, 1, NULL, NULL); + assert(o); + + err = polyp_wait_operation(pcm->p, o); + + pa_operation_unref(o); + + if (err < 0) + return -EIO; + + return 0; +} + +int polyp_drain(snd_pcm_ioplug_t *io) +{ + snd_pcm_polyp_t *pcm = io->private_data; + pa_operation *o; + int err; + + assert(pcm && pcm->p && pcm->stream); + + err = polyp_finish_poll(pcm->p); + if (err < 0) + return err; + + err = polyp_check_connection(pcm->p); + if (err < 0) + return err; + + o = pa_stream_drain(pcm->stream, NULL, NULL); + assert(o); + + err = polyp_wait_operation(pcm->p, o); + + pa_operation_unref(o); + + if (err < 0) + return -EIO; + + return 0; +} + +static snd_pcm_sframes_t polyp_pointer(snd_pcm_ioplug_t *io) +{ + snd_pcm_polyp_t *pcm = io->private_data; + int err; + + assert(pcm && pcm->p && pcm->stream); + + err = polyp_finish_poll(pcm->p); + if (err < 0) + return err; + + err = polyp_check_connection(pcm->p); + if (err < 0) + return err; + + update_ptr(pcm); + + err = polyp_start_poll(pcm->p); + if (err < 0) + return err; + + return snd_pcm_bytes_to_frames(io->pcm, pcm->ptr); +} + +static snd_pcm_sframes_t polyp_write(snd_pcm_ioplug_t *io, + const snd_pcm_channel_area_t *areas, + snd_pcm_uframes_t offset, + snd_pcm_uframes_t size) +{ + snd_pcm_polyp_t *pcm = io->private_data; + const char *buf; + int err; + + assert(pcm && pcm->p && pcm->stream); + + err = polyp_finish_poll(pcm->p); + if (err < 0) + return err; + + err = polyp_check_connection(pcm->p); + if (err < 0) + return err; + + /* Make sure the buffer pointer is in sync */ + update_ptr(pcm); + + assert(pcm->last_size >= (size * pcm->frame_size)); + + buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8; + + pa_stream_write(pcm->stream, buf, size * pcm->frame_size, NULL, 0); + + /* Make sure the buffer pointer is in sync */ + update_ptr(pcm); + + return size; +} + +static snd_pcm_sframes_t polyp_read(snd_pcm_ioplug_t *io, + const snd_pcm_channel_area_t *areas, + snd_pcm_uframes_t offset, + snd_pcm_uframes_t size) +{ + snd_pcm_polyp_t *pcm = io->private_data; + void *dst_buf, *src_buf; + size_t remain_size, frag_length; + int err; + + assert(pcm && pcm->p && pcm->stream); + + err = polyp_finish_poll(pcm->p); + if (err < 0) + return err; + + err = polyp_check_connection(pcm->p); + if (err < 0) + return err; + + /* Make sure the buffer pointer is in sync */ + update_ptr(pcm); + + remain_size = size * pcm->frame_size; + + dst_buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8; + while (remain_size > 0) { + pa_stream_peek(pcm->stream, (void**)&src_buf, &frag_length); + if (frag_length == 0) + break; + + src_buf = (char*)src_buf + pcm->offset; + frag_length -= pcm->offset; + + if (frag_length > remain_size) { + pcm->offset += remain_size; + frag_length = remain_size; + } else + pcm->offset = 0; + + memcpy(dst_buf, src_buf, frag_length); + + if (pcm->offset == 0) + pa_stream_drop(pcm->stream); + + dst_buf = (char*)dst_buf + frag_length; + remain_size -= frag_length; + } + + /* Make sure the buffer pointer is in sync */ + update_ptr(pcm); + + return size - (remain_size / pcm->frame_size); +} + +static int polyp_pcm_poll_descriptors_count(snd_pcm_ioplug_t *io) +{ + snd_pcm_polyp_t *pcm = io->private_data; + + assert(pcm && pcm->p); + + return polyp_poll_descriptors_count(pcm->p); +} + +static int polyp_pcm_poll_descriptors(snd_pcm_ioplug_t *io, struct pollfd *pfd, unsigned int space) +{ + snd_pcm_polyp_t *pcm = io->private_data; + + assert(pcm && pcm->p); + + return polyp_poll_descriptors(pcm->p, pfd, space); +} + +static int polyp_pcm_poll_revents(snd_pcm_ioplug_t *io, struct pollfd *pfd, unsigned int nfds, unsigned short *revents) +{ + snd_pcm_polyp_t *pcm = io->private_data; + int err; + + assert(pcm && pcm->p); + + err = polyp_poll_revents(pcm->p, pfd, nfds, revents); + if (err < 0) + return err; + + *revents = 0; + + /* + * Make sure we have an up-to-date value. + */ + update_ptr(pcm); + + /* + * ALSA thinks in periods, not bytes, samples or frames. + */ + if (pcm->last_size >= pcm->buffer_attr.minreq) { + if (io->stream == SND_PCM_STREAM_PLAYBACK) + *revents |= POLLIN; + else + *revents |= POLLOUT; + } + + return 0; +} + +static int polyp_prepare(snd_pcm_ioplug_t *io) +{ + snd_pcm_polyp_t *pcm = io->private_data; + int err; + pa_stream_state_t state; + + assert(pcm && pcm->p); + + err = polyp_finish_poll(pcm->p); + if (err < 0) + return err; + + if (pcm->stream) { + pa_stream_unref(pcm->stream); + pcm->stream = NULL; + } + + err = polyp_check_connection(pcm->p); + if (err < 0) + return err; + + assert(pcm->stream == NULL); + + if (io->stream == SND_PCM_STREAM_PLAYBACK) + pcm->stream = pa_stream_new(pcm->p->context, "ALSA Playback", &pcm->ss, NULL); + else + pcm->stream = pa_stream_new(pcm->p->context, "ALSA Capture", &pcm->ss, NULL); + assert(pcm->stream); + + if (io->stream == SND_PCM_STREAM_PLAYBACK) + pa_stream_connect_playback(pcm->stream, pcm->device, &pcm->buffer_attr, 0, NULL); + else + pa_stream_connect_record(pcm->stream, pcm->device, &pcm->buffer_attr, 0); + + while (1) { + state = pa_stream_get_state(pcm->stream); + + if (state == PA_STREAM_FAILED) + goto error; + + if (state == PA_STREAM_READY) + break; + + err = pa_mainloop_iterate(pcm->p->mainloop, 1, NULL); + if (err < 0) + return -EIO; + } + + pcm->last_size = 0; + pcm->ptr = 0; + pcm->offset = 0; + + return 0; + +error: + fprintf(stderr, "*** POLYPAUDIO: Unable to create stream.\n"); + pa_stream_unref(pcm->stream); + pcm->stream = NULL; + return -EIO; +} + +static int polyp_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params) +{ + snd_pcm_polyp_t *pcm = io->private_data; + + assert(pcm && pcm->p && !pcm->stream); + + pcm->frame_size = (snd_pcm_format_physical_width(io->format) * io->channels) / 8; + + switch (io->format) { + case SND_PCM_FORMAT_U8: + pcm->ss.format = PA_SAMPLE_U8; + break; + case SND_PCM_FORMAT_A_LAW: + pcm->ss.format = PA_SAMPLE_ALAW; + break; + case SND_PCM_FORMAT_MU_LAW: + pcm->ss.format = PA_SAMPLE_ULAW; + break; + case SND_PCM_FORMAT_S16_LE: + pcm->ss.format = PA_SAMPLE_S16LE; + break; + case SND_PCM_FORMAT_S16_BE: + pcm->ss.format = PA_SAMPLE_S16BE; + break; + case SND_PCM_FORMAT_FLOAT_LE: + pcm->ss.format = PA_SAMPLE_FLOAT32LE; + break; + case SND_PCM_FORMAT_FLOAT_BE: + pcm->ss.format = PA_SAMPLE_FLOAT32BE; + break; + default: + fprintf(stderr, "*** POLYPAUDIO: unsupported format %s\n", + snd_pcm_format_name(io->format)); + return -EINVAL; + } + + pcm->ss.rate = io->rate; + pcm->ss.channels = io->channels; + + pcm->buffer_attr.maxlength = io->buffer_size * pcm->frame_size; + pcm->buffer_attr.tlength = io->buffer_size * pcm->frame_size; + pcm->buffer_attr.prebuf = io->period_size * pcm->frame_size; + pcm->buffer_attr.minreq = io->period_size * pcm->frame_size; + pcm->buffer_attr.fragsize = io->period_size * pcm->frame_size; + + return 0; +} + +static int polyp_close(snd_pcm_ioplug_t *io) +{ + snd_pcm_polyp_t *pcm = io->private_data; + + assert(pcm); + + if (pcm->stream) + pa_stream_unref(pcm->stream); + + if (pcm->p) + polyp_free(pcm->p); + + if (pcm->device) + free(pcm->device); + + free(pcm); + + return 0; +} + +static snd_pcm_ioplug_callback_t polyp_playback_callback = { + .start = polyp_start, + .stop = polyp_stop, + .drain = polyp_drain, + .pointer = polyp_pointer, + .transfer = polyp_write, + .poll_descriptors_count = polyp_pcm_poll_descriptors_count, + .poll_descriptors = polyp_pcm_poll_descriptors, + .poll_revents = polyp_pcm_poll_revents, + .prepare = polyp_prepare, + .hw_params = polyp_hw_params, + .close = polyp_close, +}; + + +static snd_pcm_ioplug_callback_t polyp_capture_callback = { + .start = polyp_start, + .stop = polyp_stop, + .pointer = polyp_pointer, + .transfer = polyp_read, + .poll_descriptors_count = polyp_pcm_poll_descriptors_count, + .poll_descriptors = polyp_pcm_poll_descriptors, + .poll_revents = polyp_pcm_poll_revents, + .prepare = polyp_prepare, + .hw_params = polyp_hw_params, + .close = polyp_close, +}; + + +static int polyp_hw_constraint(snd_pcm_polyp_t *pcm) +{ + snd_pcm_ioplug_t *io = &pcm->io; + + static const snd_pcm_access_t access_list[] = { + SND_PCM_ACCESS_RW_INTERLEAVED + }; + static const unsigned int formats[] = { + SND_PCM_FORMAT_U8, + SND_PCM_FORMAT_A_LAW, + SND_PCM_FORMAT_MU_LAW, + SND_PCM_FORMAT_S16_LE, + SND_PCM_FORMAT_S16_BE, + SND_PCM_FORMAT_FLOAT_LE, + SND_PCM_FORMAT_FLOAT_BE + }; + + int err; + + err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_ACCESS, + ARRAY_SIZE(access_list), access_list); + if (err < 0) + return err; + + err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_FORMAT, + ARRAY_SIZE(formats), formats); + if (err < 0) + return err; + + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_CHANNELS, + 1, PA_CHANNELS_MAX); + if (err < 0) + return err; + + /* FIXME: Investigate actual min and max */ + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_RATE, + 8000, 48000); + if (err < 0) + return err; + + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_RATE, + 8000, 48000); + if (err < 0) + return err; + + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_PERIOD_BYTES, + 1, 4294967295U); + if (err < 0) + return err; + + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_PERIODS, + 2, 4294967295U); + if (err < 0) + return err; + + err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_BUFFER_BYTES, + 1, 4294967295U); + if (err < 0) + return err; + + return 0; +} + +SND_PCM_PLUGIN_DEFINE_FUNC(polyp) +{ + snd_config_iterator_t i, next; + const char *server = NULL; + const char *device = NULL; + int err; + snd_pcm_polyp_t *pcm; + + snd_config_for_each(i, next, conf) { + snd_config_t *n = snd_config_iterator_entry(i); + const char *id; + if (snd_config_get_id(n, &id) < 0) + continue; + if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0) + continue; + if (strcmp(id, "server") == 0) { + if (snd_config_get_string(n, &server) < 0) { + SNDERR("Invalid type for %s", id); + return -EINVAL; + } + continue; + } + if (strcmp(id, "device") == 0) { + if (snd_config_get_string(n, &device) < 0) { + SNDERR("Invalid type for %s", id); + return -EINVAL; + } + continue; + } + SNDERR("Unknown field %s", id); + return -EINVAL; + } + + pcm = calloc(1, sizeof(*pcm)); + + if (device) + pcm->device = strdup(device); + + pcm->p = polyp_new(); + assert(pcm->p); + + err = polyp_connect(pcm->p, server); + if (err < 0) + goto error; + + err = polyp_start_thread(pcm->p); + if (err < 0) + goto error; + + pcm->io.version = SND_PCM_IOPLUG_VERSION; + pcm->io.name = "ALSA <-> Polypaudio PCM I/O Plugin"; + pcm->io.poll_fd = -1; + pcm->io.poll_events = 0; + pcm->io.mmap_rw = 0; + pcm->io.callback = stream == SND_PCM_STREAM_PLAYBACK ? + &polyp_playback_callback : &polyp_capture_callback; + pcm->io.private_data = pcm; + + err = snd_pcm_ioplug_create(&pcm->io, name, stream, mode); + if (err < 0) + goto error; + + err = polyp_hw_constraint(pcm); + if (err < 0) { + snd_pcm_ioplug_delete(&pcm->io); + goto error; + } + + *pcmp = pcm->io.pcm; + return 0; + +error: + if (pcm->p) + polyp_free(pcm->p); + + free(pcm); + + return err; +} + +SND_PCM_PLUGIN_SYMBOL(polyp); diff --git a/polyp/polyp.c b/polyp/polyp.c new file mode 100644 index 0000000..139152f --- /dev/null +++ b/polyp/polyp.c @@ -0,0 +1,350 @@ +/* + * ALSA <-> Polypaudio plugins + * + * Copyright (c) 2006 by Pierre Ossman + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include + +#include + +#include "polyp.h" + +enum { + COMMAND_POLL = 'p', + COMMAND_QUIT = 'q', + COMMAND_POLL_DONE = 'P', + COMMAND_POLL_FAILED = 'F', +}; + +static int write_command(snd_polyp_t *p, char command) +{ + if (write(p->main_fd, &command, 1) != 1) + return -errno; + return 0; +} + +static int write_reply(snd_polyp_t *p, char reply) +{ + if (write(p->thread_fd, &reply, 1) != 1) + return -errno; + return 0; +} + +static int read_command(snd_polyp_t *p) +{ + char command; + + if (read(p->thread_fd, &command, 1) != 1) + return -errno; + + return command; +} + +static int read_reply(snd_polyp_t *p) +{ + char reply; + + if (read(p->main_fd, &reply, 1) != 1) + return -errno; + + return reply; +} + +static void* thread_func(void *data) +{ + snd_polyp_t *p = (snd_polyp_t*)data; + sigset_t mask; + char command; + int ret; + + sigfillset(&mask); + pthread_sigmask(SIG_BLOCK, &mask, NULL); + + do { + command = read_command(p); + if (command < 0) + break; + + switch (command) { + case COMMAND_POLL: + do { + ret = pa_mainloop_poll(p->mainloop); + } while ((ret < 0) && (errno == EINTR)); + + ret = write_reply(p, (ret < 0) ? COMMAND_POLL_FAILED : COMMAND_POLL_DONE); + if (ret < 0) + return NULL; + + break; + } + } while (command != COMMAND_QUIT); + + return NULL; +} + +int polyp_start_poll(snd_polyp_t *p) +{ + int err; + + assert(p); + + if (p->state == POLYP_STATE_POLLING) + return 0; + + assert(p->state == POLYP_STATE_READY); + + err = pa_mainloop_prepare(p->mainloop, -1); + if (err < 0) + return err; + + err = write_command(p, COMMAND_POLL); + if (err < 0) + return err; + + p->state = POLYP_STATE_POLLING; + + return 0; +} + +int polyp_finish_poll(snd_polyp_t *p) +{ + char reply; + int err; + + assert(p); + + if (p->state == POLYP_STATE_READY) + return 0; + + assert(p->state == POLYP_STATE_POLLING); + + p->state = POLYP_STATE_READY; + + pa_mainloop_wakeup(p->mainloop); + + reply = read_reply(p); + + if (reply == COMMAND_POLL_DONE) { + err = pa_mainloop_dispatch(p->mainloop); + if (err < 0) + return err; + } else + return -EIO; + + return 0; +} + +int polyp_check_connection(snd_polyp_t *p) +{ + pa_context_state_t state; + + assert(p && p->context); + + state = pa_context_get_state(p->context); + + if (state != PA_CONTEXT_READY) + return -EIO; + + return 0; +} + +int polyp_wait_operation(snd_polyp_t *p, pa_operation *o) +{ + int err; + + assert(p && o && (p->state == POLYP_STATE_READY)); + + while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) { + err = pa_mainloop_iterate(p->mainloop, 1, NULL); + if (err < 0) + return err; + } + + return 0; +} + +snd_polyp_t *polyp_new() +{ + snd_polyp_t *p; + + p = calloc(1, sizeof(snd_polyp_t)); + assert(p); + + p->state = POLYP_STATE_INIT; + + p->main_fd = -1; + p->thread_fd = -1; + p->thread_running = 0; + + p->mainloop = pa_mainloop_new(); + assert(p->mainloop); + + p->context = pa_context_new(pa_mainloop_get_api(p->mainloop), + "ALSA Plugin"); + assert(p->context); + + return p; +} + +void polyp_free(snd_polyp_t *p) +{ + if (p->thread_running) { + assert(p->mainloop && p->thread); + write_command(p, COMMAND_QUIT); + pa_mainloop_wakeup(p->mainloop); + pthread_join(p->thread, NULL); + } + + if (p->context) + pa_context_unref(p->context); + if (p->mainloop) + pa_mainloop_free(p->mainloop); + + if (p->thread_fd >= 0) + close(p->thread_fd); + if (p->main_fd >= 0) + close(p->main_fd); + + free(p); +} + +int polyp_connect(snd_polyp_t *p, const char *server) +{ + int err; + pa_context_state_t state; + + assert(p && p->context && p->mainloop && (p->state == POLYP_STATE_INIT)); + + err = pa_context_connect(p->context, server, 1, NULL); + if (err < 0) + goto error; + + while (1) { + state = pa_context_get_state(p->context); + + if (state == PA_CONTEXT_FAILED) + goto error; + + if (state == PA_CONTEXT_READY) + break; + + err = pa_mainloop_iterate(p->mainloop, 1, NULL); + if (err < 0) + return -EIO; + } + + p->state = POLYP_STATE_CONNECTED; + + return 0; + +error: + fprintf(stderr, "*** POLYPAUDIO: Unable to connect: %s\n", + pa_strerror(pa_context_errno(p->context))); + return -ECONNREFUSED; +} + +int polyp_start_thread(snd_polyp_t *p) +{ + int err; + int fd[2] = { -1, -1 }; + + assert(p && (p->state == POLYP_STATE_CONNECTED)); + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) { + perror("socketpair()"); + return -errno; + } + + p->thread_fd = fd[0]; + p->main_fd = fd[1]; + + p->thread_running = 0; + + err = pthread_create(&p->thread, NULL, thread_func, p); + if (err) { + SNDERR("pthread_create(): %s", strerror(err)); + close(fd[0]); + close(fd[1]); + p->main_fd = -1; + p->thread_fd = -1; + return -err; + } + + p->thread_running = 1; + + p->state = POLYP_STATE_READY; + + return 0; +} + +int polyp_poll_descriptors_count(snd_polyp_t *p) +{ + assert(p); + + if (p->main_fd >= 0) + return 1; + else + return 0; +} + +int polyp_poll_descriptors(snd_polyp_t *p, struct pollfd *pfd, unsigned int space) +{ + int err; + + assert(p); + + err = polyp_finish_poll(p); + if (err < 0) + return err; + + err = polyp_start_poll(p); + if (err < 0) + return err; + + assert(space >= 1); + + pfd[0].fd = p->main_fd; + pfd[0].events = POLL_IN; + pfd[0].revents = 0; + + return 1; +} + +int polyp_poll_revents(snd_polyp_t *p, struct pollfd *pfd, unsigned int nfds, unsigned short *revents) +{ + int err; + + assert(p); + + err = polyp_finish_poll(p); + if (err < 0) + return err; + + err = polyp_check_connection(p); + if (err < 0) + return err; + + /* + * The application might redo the poll immediatly. + */ + return polyp_poll_descriptors(p, pfd, nfds); +} diff --git a/polyp/polyp.h b/polyp/polyp.h new file mode 100644 index 0000000..60cf872 --- /dev/null +++ b/polyp/polyp.h @@ -0,0 +1,60 @@ +/* + * ALSA <-> Polypaudio plugins + * + * Copyright (c) 2006 by Pierre Ossman + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include +#include + +#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) + +typedef struct snd_polyp { + pa_mainloop *mainloop; + pa_context *context; + + int thread_fd, main_fd; + + pthread_t thread; + int thread_running; + + enum { + POLYP_STATE_INIT, + POLYP_STATE_CONNECTED, + POLYP_STATE_READY, + POLYP_STATE_POLLING, + } state; +} snd_polyp_t; + +int polyp_start_poll(snd_polyp_t *p); +int polyp_finish_poll(snd_polyp_t *p); + +int polyp_check_connection(snd_polyp_t *p); + +int polyp_wait_operation(snd_polyp_t *p, pa_operation *o); + +snd_polyp_t *polyp_new(); +void polyp_free(snd_polyp_t *p); + +int polyp_connect(snd_polyp_t *p, const char *server); +int polyp_start_thread(snd_polyp_t *p); + +int polyp_poll_descriptors_count(snd_polyp_t *p); +int polyp_poll_descriptors(snd_polyp_t *p, struct pollfd *pfd, unsigned int space); +int polyp_poll_revents(snd_polyp_t *p, struct pollfd *pfd, unsigned int nfds, unsigned short *revents); -- cgit