1
1
mirror of https://github.com/bitgapp/eqMac.git synced 2024-11-22 04:33:53 +03:00

rewrote driver

This commit is contained in:
Nodeful 2021-07-10 15:35:04 +03:00
parent b1f9f702c9
commit ec5502b031
85 changed files with 4591 additions and 21808 deletions

875
LICENSE
View File

@ -1,674 +1,201 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. 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
them 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.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. 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.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey 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;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If 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 convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU 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 that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
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.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
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.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
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.
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
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 3 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program 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, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU 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 Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -40,7 +40,7 @@ I'm notoriously known for lacking in communication with users due to lack of tim
## Technology
eqMac was built using these technologies:
* [Driver](https://github.com/bitgapp/eqMac/tree/master/native/driver) - System Audio loopback/passthrough device based on [BackgroundMusic](https://github.com/kyleneideck/BackgroundMusic) project. The driver grabs the system audio stream and sends it to the input channels. eqMac can grab this stream, process it and send to the appropriate audio device. Still very low level C++ code although the driver runs in User space instead of Kernel like the previous drivers, which means it's much more secure and stable.
* [Driver](https://github.com/bitgapp/eqMac/tree/master/native/driver) - System Audio loopback/passthrough device based on [Apple's Null Audio Server Driver Plug-in](https://developer.apple.com/documentation/coreaudio/creating_an_audio_server_driver_plug-in) example. The driver grabs the system audio stream and sends it to the input channels. eqMac can grab this stream, process it and send to the appropriate audio device. Still very low level C++ code although the driver runs in User space instead of Kernel like the previous drivers, which means it's much more secure and stable.
* [App](https://github.com/bitgapp/eqMac/tree/master/native/app) - Native backend to the whole app. Responsible for audio processing, filesystem access, window management, API and general lifecycle of eqMac. Written in Swift and uses Apple's more modern [AVAudioEngine API](https://developer.apple.com/documentation/avfoundation/avaudioengine), unlike the previous version that used a deprecated AUGraph API.
* [UI](https://github.com/bitgapp/eqMac/tree/master/ui) - Web based user interface that is hosted remotely and thus allows for over the air updates & bug fixes. Built with [Angular](https://angular.io/) + [TypeScript](https://www.typescriptlang.org/) and is cached for offline availability.
@ -52,7 +52,7 @@ Check the documentation below to understand how to start eqMac debug process fro
[@nodeful](https://github.com/nodeful) - Creator and Developer of eqMac
[@kyleneideck](https://github.com/kyleneideck) - For his hard work on the [BGMDriver](https://github.com/kyleneideck/BackgroundMusic)
Apple Inc. - For open sourcing this [HAL Driver Example](https://developer.apple.com/documentation/coreaudio/creating_an_audio_server_driver_plug-in)
[@titanicbobo](https://github.com/titanicbobo) - For the [Big Sur icon design](https://github.com/bitgapp/eqMac/blob/master/assets/icon/icon.svg)

View File

@ -83,15 +83,6 @@ class Driver {
}
}
static var hasSafetyOffset: Bool {
var address = AudioObjectPropertyAddress(
mSelector: getPropertySelectorFromString(CustomProperties.kAudioDeviceCustomPropertySafetyOffset.rawValue),
mScope: kAudioObjectPropertyScopeOutput,
mElement: kAudioObjectPropertyElementMaster
)
Console.log(CustomProperties.kAudioDeviceCustomPropertySafetyOffset.rawValue, address.mSelector)
return AudioObjectHasProperty(Driver.device!.id, &address)
}
static var safetyOffset: UInt32 {
get {
return Driver.device!.safetyOffset(direction: .playback)!
@ -99,7 +90,7 @@ class Driver {
set {
var address = AudioObjectPropertyAddress(
mSelector: getPropertySelectorFromString(CustomProperties.kAudioDeviceCustomPropertySafetyOffset.rawValue),
mScope: kAudioObjectPropertyScopeGlobal,
mScope: kAudioObjectPropertyScopeOutput,
mElement: kAudioObjectPropertyElementMaster
)

View File

@ -7,115 +7,17 @@
objects = {
/* Begin PBXBuildFile section */
19FE766482B57D852CCF6F0A /* EQM_MuteControl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 19FE7E6DC2A1B61211D74782 /* EQM_MuteControl.cpp */; };
19FE77D40F15EA060B462D83 /* EQM_Control.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 19FE7BC3396C4E50D21E1BC8 /* EQM_Control.cpp */; };
1C0CB6B91C642C600084C15A /* EQM_Client.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C0CB6B01C642C600084C15A /* EQM_Client.cpp */; };
1C0CB6BA1C642C600084C15A /* EQM_ClientMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C0CB6B21C642C600084C15A /* EQM_ClientMap.cpp */; };
1C0CB6BB1C642C600084C15A /* EQM_Clients.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C0CB6B41C642C600084C15A /* EQM_Clients.cpp */; };
1C38210E1C4A163A00A0C8C6 /* EQM_TaskQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C38210C1C4A163A00A0C8C6 /* EQM_TaskQueue.cpp */; };
1C7010751F05ED5100D8CCDC /* EQM_AudibleState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C7010731F05ED5100D8CCDC /* EQM_AudibleState.cpp */; };
1C7010791F07A0BA00D8CCDC /* EQM_VolumeControl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C7010771F07A0BA00D8CCDC /* EQM_VolumeControl.cpp */; };
1CA2A9E21E8D1D08007A76A4 /* EQM_Stream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CA2A9E01E8D1D08007A76A4 /* EQM_Stream.cpp */; };
1CB8B36E1BBBD541000E2DD1 /* EQM_PlugInInterface.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB8B36D1BBBD541000E2DD1 /* EQM_PlugInInterface.cpp */; };
1CB8B37D1BBCCF62000E2DD1 /* EQM_PlugIn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB8B37B1BBCCF62000E2DD1 /* EQM_PlugIn.cpp */; };
1CB8B3801BBCCF87000E2DD1 /* EQM_Device.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB8B37E1BBCCF87000E2DD1 /* EQM_Device.cpp */; };
1CB8B3831BBCE7B5000E2DD1 /* EQM_Object.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB8B3811BBCE7B5000E2DD1 /* EQM_Object.cpp */; };
1CB8B3921BBCF50A000E2DD1 /* EQM_WrappedAudioEngine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB8B3901BBCF50A000E2DD1 /* EQM_WrappedAudioEngine.cpp */; };
1CDF3ABC1E863B980001E9B7 /* EQM_NullDevice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CDF3ABA1E863B980001E9B7 /* EQM_NullDevice.cpp */; };
1CDF3ABF1E8644C20001E9B7 /* EQM_AbstractDevice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CDF3ABD1E8644C20001E9B7 /* EQM_AbstractDevice.cpp */; };
2743C9CD1D7EF8760089613B /* CACFArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CE3E68F1BE2683900167F5D /* CACFArray.cpp */; };
2743C9CF1D7EF8760089613B /* CACFDictionary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CE3E68C1BE263CA00167F5D /* CACFDictionary.cpp */; };
2743C9D11D7EF8760089613B /* CACFNumber.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C305D9B1BE294B5004EBB91 /* CACFNumber.cpp */; };
2743C9D31D7EF8760089613B /* CACFString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB8B38A1BBCF4A9000E2DD1 /* CACFString.cpp */; };
2743C9D51D7EF8760089613B /* CADebugger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CC1DF871BE558B000FB8FE4 /* CADebugger.cpp */; };
2743C9D71D7EF8760089613B /* CADebugMacros.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB8B3701BBBD8A4000E2DD1 /* CADebugMacros.cpp */; };
2743C9D91D7EF8760089613B /* CADebugPrintf.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB8B3781BBBDFA2000E2DD1 /* CADebugPrintf.cpp */; };
2743C9DB1D7EF8760089613B /* CADispatchQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB8B3931BBD2418000E2DD1 /* CADispatchQueue.cpp */; };
2743C9DE1D7EF8760089613B /* CAHostTimeBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB8B3871BBCF08A000E2DD1 /* CAHostTimeBase.cpp */; };
2743C9E01D7EF8760089613B /* CAMutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB8B3841BBCEFE8000E2DD1 /* CAMutex.cpp */; };
2743C9E21D7EF8760089613B /* CAPThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C38210F1C4A18DE00A0C8C6 /* CAPThread.cpp */; };
2743C9E41D7EF8760089613B /* CAVolumeCurve.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB8B38C1BBCF4A9000E2DD1 /* CAVolumeCurve.cpp */; };
2743C9E61D7EF8E00089613B /* libPublicUtility.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2743C9C61D7EF84B0089613B /* libPublicUtility.a */; };
E00879C9237EC3D3006AACF8 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E00879C8237EC3D3006AACF8 /* Accelerate.framework */; };
E01A29F42456E4F800369F41 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E01A29F32456E4F800369F41 /* Foundation.framework */; };
E01A29F62456E4FF00369F41 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E01A29F52456E4FF00369F41 /* CoreAudio.framework */; };
789B5F202699153000C72029 /* eqMac.c in Sources */ = {isa = PBXBuildFile; fileRef = 789B5F1F2699153000C72029 /* eqMac.c */; };
E01A29F82456E50500369F41 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E01A29F72456E50500369F41 /* CoreFoundation.framework */; };
E07380E22284D9F200FF0F53 /* EQM_Utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E07380E02284D9F200FF0F53 /* EQM_Utils.cpp */; };
E0DAAFBD21FE545F00DCCCEC /* icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = E0DAAFBC21FE545F00DCCCEC /* icon.icns */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
19FE7431C588F36F4F1E70BB /* EQM_MuteControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_MuteControl.h; sourceTree = "<group>"; };
19FE7B8CE9148B3D8D7517C6 /* EQM_Control.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_Control.h; sourceTree = "<group>"; };
19FE7BC3396C4E50D21E1BC8 /* EQM_Control.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_Control.cpp; sourceTree = "<group>"; };
19FE7E6DC2A1B61211D74782 /* EQM_MuteControl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_MuteControl.cpp; sourceTree = "<group>"; };
1C0CB6A61C4E06C00084C15A /* CAAtomicStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CAAtomicStack.h; path = PublicUtility/CAAtomicStack.h; sourceTree = "<group>"; };
1C0CB6A71C4E06F70084C15A /* CAAtomic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CAAtomic.h; path = PublicUtility/CAAtomic.h; sourceTree = "<group>"; };
1C0CB6A91C50A3AF0084C15A /* CAAutoDisposer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CAAutoDisposer.h; path = PublicUtility/CAAutoDisposer.h; sourceTree = "<group>"; };
1C0CB6B01C642C600084C15A /* EQM_Client.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_Client.cpp; sourceTree = "<group>"; };
1C0CB6B11C642C600084C15A /* EQM_Client.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_Client.h; sourceTree = "<group>"; };
1C0CB6B21C642C600084C15A /* EQM_ClientMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_ClientMap.cpp; sourceTree = "<group>"; };
1C0CB6B31C642C600084C15A /* EQM_ClientMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_ClientMap.h; sourceTree = "<group>"; };
1C0CB6B41C642C600084C15A /* EQM_Clients.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_Clients.cpp; sourceTree = "<group>"; };
1C0CB6B51C642C600084C15A /* EQM_Clients.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_Clients.h; sourceTree = "<group>"; };
1C0CB6B81C642C600084C15A /* EQM_ClientTasks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_ClientTasks.h; sourceTree = "<group>"; };
1C305D9B1BE294B5004EBB91 /* CACFNumber.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CACFNumber.cpp; path = PublicUtility/CACFNumber.cpp; sourceTree = "<group>"; };
1C305D9C1BE294B5004EBB91 /* CACFNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CACFNumber.h; path = PublicUtility/CACFNumber.h; sourceTree = "<group>"; };
1C37B3681E9B8D3C000DF98F /* CAPropertyAddress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CAPropertyAddress.h; path = PublicUtility/CAPropertyAddress.h; sourceTree = "<group>"; };
1C38210C1C4A163A00A0C8C6 /* EQM_TaskQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_TaskQueue.cpp; sourceTree = "<group>"; };
1C38210D1C4A163A00A0C8C6 /* EQM_TaskQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_TaskQueue.h; sourceTree = "<group>"; };
1C38210F1C4A18DE00A0C8C6 /* CAPThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CAPThread.cpp; path = PublicUtility/CAPThread.cpp; sourceTree = "<group>"; };
1C3821101C4A18DE00A0C8C6 /* CAPThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CAPThread.h; path = PublicUtility/CAPThread.h; sourceTree = "<group>"; };
1C7010731F05ED5100D8CCDC /* EQM_AudibleState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_AudibleState.cpp; sourceTree = "<group>"; };
1C7010741F05ED5100D8CCDC /* EQM_AudibleState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_AudibleState.h; sourceTree = "<group>"; };
1C7010771F07A0BA00D8CCDC /* EQM_VolumeControl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_VolumeControl.cpp; sourceTree = "<group>"; };
1C7010781F07A0BA00D8CCDC /* EQM_VolumeControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_VolumeControl.h; sourceTree = "<group>"; };
1CA2A9E01E8D1D08007A76A4 /* EQM_Stream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_Stream.cpp; sourceTree = "<group>"; };
1CA2A9E11E8D1D08007A76A4 /* EQM_Stream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_Stream.h; sourceTree = "<group>"; };
1CB8B3641BBBB78D000E2DD1 /* eqMac.driver */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = eqMac.driver; sourceTree = BUILT_PRODUCTS_DIR; };
1CB8B3681BBBB78D000E2DD1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
1CB8B36D1BBBD541000E2DD1 /* EQM_PlugInInterface.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_PlugInInterface.cpp; sourceTree = "<group>"; };
1CB8B3701BBBD8A4000E2DD1 /* CADebugMacros.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CADebugMacros.cpp; path = PublicUtility/CADebugMacros.cpp; sourceTree = "<group>"; };
1CB8B3711BBBD8A4000E2DD1 /* CADebugMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CADebugMacros.h; path = PublicUtility/CADebugMacros.h; sourceTree = "<group>"; };
1CB8B3721BBBD8A4000E2DD1 /* CAException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CAException.h; path = PublicUtility/CAException.h; sourceTree = "<group>"; };
1CB8B3781BBBDFA2000E2DD1 /* CADebugPrintf.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CADebugPrintf.cpp; path = PublicUtility/CADebugPrintf.cpp; sourceTree = "<group>"; };
1CB8B3791BBBDFA2000E2DD1 /* CADebugPrintf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CADebugPrintf.h; path = PublicUtility/CADebugPrintf.h; sourceTree = "<group>"; };
1CB8B37B1BBCCF62000E2DD1 /* EQM_PlugIn.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_PlugIn.cpp; sourceTree = "<group>"; };
1CB8B37C1BBCCF62000E2DD1 /* EQM_PlugIn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_PlugIn.h; sourceTree = "<group>"; };
1CB8B37E1BBCCF87000E2DD1 /* EQM_Device.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_Device.cpp; sourceTree = "<group>"; };
1CB8B37F1BBCCF87000E2DD1 /* EQM_Device.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_Device.h; sourceTree = "<group>"; };
1CB8B3811BBCE7B5000E2DD1 /* EQM_Object.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_Object.cpp; sourceTree = "<group>"; };
1CB8B3821BBCE7B5000E2DD1 /* EQM_Object.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_Object.h; sourceTree = "<group>"; };
1CB8B3841BBCEFE8000E2DD1 /* CAMutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CAMutex.cpp; path = PublicUtility/CAMutex.cpp; sourceTree = "<group>"; };
1CB8B3851BBCEFE8000E2DD1 /* CAMutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CAMutex.h; path = PublicUtility/CAMutex.h; sourceTree = "<group>"; };
1CB8B3871BBCF08A000E2DD1 /* CAHostTimeBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CAHostTimeBase.cpp; path = PublicUtility/CAHostTimeBase.cpp; sourceTree = "<group>"; };
1CB8B3881BBCF08A000E2DD1 /* CAHostTimeBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CAHostTimeBase.h; path = PublicUtility/CAHostTimeBase.h; sourceTree = "<group>"; };
1CB8B38A1BBCF4A9000E2DD1 /* CACFString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CACFString.cpp; path = PublicUtility/CACFString.cpp; sourceTree = "<group>"; };
1CB8B38B1BBCF4A9000E2DD1 /* CACFString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CACFString.h; path = PublicUtility/CACFString.h; sourceTree = "<group>"; };
1CB8B38C1BBCF4A9000E2DD1 /* CAVolumeCurve.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CAVolumeCurve.cpp; path = PublicUtility/CAVolumeCurve.cpp; sourceTree = "<group>"; };
1CB8B38D1BBCF4A9000E2DD1 /* CAVolumeCurve.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CAVolumeCurve.h; path = PublicUtility/CAVolumeCurve.h; sourceTree = "<group>"; };
1CB8B3901BBCF50A000E2DD1 /* EQM_WrappedAudioEngine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_WrappedAudioEngine.cpp; sourceTree = "<group>"; };
1CB8B3911BBCF50A000E2DD1 /* EQM_WrappedAudioEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_WrappedAudioEngine.h; sourceTree = "<group>"; };
1CB8B3931BBD2418000E2DD1 /* CADispatchQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CADispatchQueue.cpp; path = PublicUtility/CADispatchQueue.cpp; sourceTree = "<group>"; };
1CB8B3941BBD2418000E2DD1 /* CADispatchQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CADispatchQueue.h; path = PublicUtility/CADispatchQueue.h; sourceTree = "<group>"; };
1CC1DF871BE558B000FB8FE4 /* CADebugger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CADebugger.cpp; path = PublicUtility/CADebugger.cpp; sourceTree = "<group>"; };
1CC1DF881BE558B000FB8FE4 /* CADebugger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CADebugger.h; path = PublicUtility/CADebugger.h; sourceTree = "<group>"; };
1CDF3ABA1E863B980001E9B7 /* EQM_NullDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_NullDevice.cpp; sourceTree = "<group>"; };
1CDF3ABB1E863B980001E9B7 /* EQM_NullDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_NullDevice.h; sourceTree = "<group>"; };
1CDF3ABD1E8644C20001E9B7 /* EQM_AbstractDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_AbstractDevice.cpp; sourceTree = "<group>"; };
1CDF3ABE1E8644C20001E9B7 /* EQM_AbstractDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_AbstractDevice.h; sourceTree = "<group>"; };
1CE3E68C1BE263CA00167F5D /* CACFDictionary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CACFDictionary.cpp; path = PublicUtility/CACFDictionary.cpp; sourceTree = "<group>"; };
1CE3E68D1BE263CA00167F5D /* CACFDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CACFDictionary.h; path = PublicUtility/CACFDictionary.h; sourceTree = "<group>"; };
1CE3E68F1BE2683900167F5D /* CACFArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CACFArray.cpp; path = PublicUtility/CACFArray.cpp; sourceTree = "<group>"; };
1CE3E6901BE2683900167F5D /* CACFArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CACFArray.h; path = PublicUtility/CACFArray.h; sourceTree = "<group>"; };
2743C9C61D7EF84B0089613B /* libPublicUtility.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPublicUtility.a; sourceTree = BUILT_PRODUCTS_DIR; };
E00879C8237EC3D3006AACF8 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
E01A29F32456E4F800369F41 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
E01A29F52456E4FF00369F41 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
789B5F1E2699153000C72029 /* eqMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = eqMac.h; sourceTree = "<group>"; };
789B5F1F2699153000C72029 /* eqMac.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = eqMac.c; sourceTree = "<group>"; };
E01A29F72456E50500369F41 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
E07380DF2284D9CC00FF0F53 /* EQM_Types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_Types.h; sourceTree = "<group>"; };
E07380E02284D9F200FF0F53 /* EQM_Utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EQM_Utils.cpp; sourceTree = "<group>"; };
E07380E12284D9F200FF0F53 /* EQM_Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EQM_Utils.h; sourceTree = "<group>"; };
E0DAAFBC21FE545F00DCCCEC /* icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = icon.icns; sourceTree = "<group>"; };
E0FA2BB021FBB917001C99CD /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -126,43 +28,17 @@
buildActionMask = 2147483647;
files = (
E01A29F82456E50500369F41 /* CoreFoundation.framework in Frameworks */,
E01A29F62456E4FF00369F41 /* CoreAudio.framework in Frameworks */,
E01A29F42456E4F800369F41 /* Foundation.framework in Frameworks */,
E00879C9237EC3D3006AACF8 /* Accelerate.framework in Frameworks */,
2743C9E61D7EF8E00089613B /* libPublicUtility.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
2743C9C31D7EF84B0089613B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
1C0CB6AF1C642C600084C15A /* DeviceClients */ = {
isa = PBXGroup;
children = (
1C0CB6B11C642C600084C15A /* EQM_Client.h */,
1C0CB6B01C642C600084C15A /* EQM_Client.cpp */,
1C0CB6B31C642C600084C15A /* EQM_ClientMap.h */,
1C0CB6B21C642C600084C15A /* EQM_ClientMap.cpp */,
1C0CB6B51C642C600084C15A /* EQM_Clients.h */,
1C0CB6B41C642C600084C15A /* EQM_Clients.cpp */,
1C0CB6B81C642C600084C15A /* EQM_ClientTasks.h */,
);
path = DeviceClients;
sourceTree = "<group>";
};
1CB8B3591BBBB69C000E2DD1 = {
isa = PBXGroup;
children = (
1CB8B3661BBBB78D000E2DD1 /* Source */,
E0FA2BAF21FBB917001C99CD /* Scripts */,
1CB8B36F1BBBD7AE000E2DD1 /* PublicUtility */,
1CB8B3651BBBB78D000E2DD1 /* Products */,
1CB8B3671BBBB78D000E2DD1 /* Supporting Files */,
E00879C7237EC3D3006AACF8 /* Frameworks */,
@ -173,7 +49,6 @@
isa = PBXGroup;
children = (
1CB8B3641BBBB78D000E2DD1 /* eqMac.driver */,
2743C9C61D7EF84B0089613B /* libPublicUtility.a */,
);
name = Products;
sourceTree = "<group>";
@ -181,35 +56,8 @@
1CB8B3661BBBB78D000E2DD1 /* Source */ = {
isa = PBXGroup;
children = (
E07380E02284D9F200FF0F53 /* EQM_Utils.cpp */,
E07380E12284D9F200FF0F53 /* EQM_Utils.h */,
E07380DF2284D9CC00FF0F53 /* EQM_Types.h */,
1CB8B36D1BBBD541000E2DD1 /* EQM_PlugInInterface.cpp */,
1CB8B37C1BBCCF62000E2DD1 /* EQM_PlugIn.h */,
1CB8B37B1BBCCF62000E2DD1 /* EQM_PlugIn.cpp */,
1CB8B3821BBCE7B5000E2DD1 /* EQM_Object.h */,
1CB8B3811BBCE7B5000E2DD1 /* EQM_Object.cpp */,
1CDF3ABE1E8644C20001E9B7 /* EQM_AbstractDevice.h */,
1CDF3ABD1E8644C20001E9B7 /* EQM_AbstractDevice.cpp */,
1CB8B37F1BBCCF87000E2DD1 /* EQM_Device.h */,
1CB8B37E1BBCCF87000E2DD1 /* EQM_Device.cpp */,
1C7010741F05ED5100D8CCDC /* EQM_AudibleState.h */,
1C7010731F05ED5100D8CCDC /* EQM_AudibleState.cpp */,
1CDF3ABB1E863B980001E9B7 /* EQM_NullDevice.h */,
1CDF3ABA1E863B980001E9B7 /* EQM_NullDevice.cpp */,
1CA2A9E11E8D1D08007A76A4 /* EQM_Stream.h */,
1CA2A9E01E8D1D08007A76A4 /* EQM_Stream.cpp */,
19FE7B8CE9148B3D8D7517C6 /* EQM_Control.h */,
19FE7BC3396C4E50D21E1BC8 /* EQM_Control.cpp */,
1C7010781F07A0BA00D8CCDC /* EQM_VolumeControl.h */,
1C7010771F07A0BA00D8CCDC /* EQM_VolumeControl.cpp */,
19FE7431C588F36F4F1E70BB /* EQM_MuteControl.h */,
19FE7E6DC2A1B61211D74782 /* EQM_MuteControl.cpp */,
1C0CB6AF1C642C600084C15A /* DeviceClients */,
1C38210D1C4A163A00A0C8C6 /* EQM_TaskQueue.h */,
1C38210C1C4A163A00A0C8C6 /* EQM_TaskQueue.cpp */,
1CB8B3911BBCF50A000E2DD1 /* EQM_WrappedAudioEngine.h */,
1CB8B3901BBCF50A000E2DD1 /* EQM_WrappedAudioEngine.cpp */,
789B5F1E2699153000C72029 /* eqMac.h */,
789B5F1F2699153000C72029 /* eqMac.c */,
);
path = Source;
sourceTree = "<group>";
@ -223,49 +71,10 @@
path = "Supporting Files";
sourceTree = "<group>";
};
1CB8B36F1BBBD7AE000E2DD1 /* PublicUtility */ = {
isa = PBXGroup;
children = (
1C0CB6A71C4E06F70084C15A /* CAAtomic.h */,
1C37B3681E9B8D3C000DF98F /* CAPropertyAddress.h */,
1C0CB6A61C4E06C00084C15A /* CAAtomicStack.h */,
1C0CB6A91C50A3AF0084C15A /* CAAutoDisposer.h */,
1CE3E68F1BE2683900167F5D /* CACFArray.cpp */,
1CE3E6901BE2683900167F5D /* CACFArray.h */,
1CE3E68C1BE263CA00167F5D /* CACFDictionary.cpp */,
1CE3E68D1BE263CA00167F5D /* CACFDictionary.h */,
1C305D9B1BE294B5004EBB91 /* CACFNumber.cpp */,
1C305D9C1BE294B5004EBB91 /* CACFNumber.h */,
1CB8B38A1BBCF4A9000E2DD1 /* CACFString.cpp */,
1CB8B38B1BBCF4A9000E2DD1 /* CACFString.h */,
1CC1DF871BE558B000FB8FE4 /* CADebugger.cpp */,
1CC1DF881BE558B000FB8FE4 /* CADebugger.h */,
1CB8B3701BBBD8A4000E2DD1 /* CADebugMacros.cpp */,
1CB8B3711BBBD8A4000E2DD1 /* CADebugMacros.h */,
1CB8B3781BBBDFA2000E2DD1 /* CADebugPrintf.cpp */,
1CB8B3791BBBDFA2000E2DD1 /* CADebugPrintf.h */,
1CB8B3931BBD2418000E2DD1 /* CADispatchQueue.cpp */,
1CB8B3941BBD2418000E2DD1 /* CADispatchQueue.h */,
1CB8B3721BBBD8A4000E2DD1 /* CAException.h */,
1CB8B3871BBCF08A000E2DD1 /* CAHostTimeBase.cpp */,
1CB8B3881BBCF08A000E2DD1 /* CAHostTimeBase.h */,
1CB8B3841BBCEFE8000E2DD1 /* CAMutex.cpp */,
1CB8B3851BBCEFE8000E2DD1 /* CAMutex.h */,
1C38210F1C4A18DE00A0C8C6 /* CAPThread.cpp */,
1C3821101C4A18DE00A0C8C6 /* CAPThread.h */,
1CB8B38C1BBCF4A9000E2DD1 /* CAVolumeCurve.cpp */,
1CB8B38D1BBCF4A9000E2DD1 /* CAVolumeCurve.h */,
);
name = PublicUtility;
sourceTree = "<group>";
};
E00879C7237EC3D3006AACF8 /* Frameworks */ = {
isa = PBXGroup;
children = (
E01A29F72456E50500369F41 /* CoreFoundation.framework */,
E01A29F52456E4FF00369F41 /* CoreAudio.framework */,
E01A29F32456E4F800369F41 /* Foundation.framework */,
E00879C8237EC3D3006AACF8 /* Accelerate.framework */,
);
name = Frameworks;
sourceTree = "<group>";
@ -280,16 +89,6 @@
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
2743C9C41D7EF84B0089613B /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */
1CB8B3631BBBB78D000E2DD1 /* eqMac */ = {
isa = PBXNativeTarget;
@ -309,23 +108,6 @@
productReference = 1CB8B3641BBBB78D000E2DD1 /* eqMac.driver */;
productType = "com.apple.product-type.bundle";
};
2743C9C51D7EF84B0089613B /* PublicUtility */ = {
isa = PBXNativeTarget;
buildConfigurationList = 2743C9C71D7EF84B0089613B /* Build configuration list for PBXNativeTarget "PublicUtility" */;
buildPhases = (
2743C9C21D7EF84B0089613B /* Sources */,
2743C9C31D7EF84B0089613B /* Frameworks */,
2743C9C41D7EF84B0089613B /* Headers */,
);
buildRules = (
);
dependencies = (
);
name = PublicUtility;
productName = PublicUtility;
productReference = 2743C9C61D7EF84B0089613B /* libPublicUtility.a */;
productType = "com.apple.product-type.library.static";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
@ -341,10 +123,6 @@
DevelopmentTeam = JZA6C97KJA;
ProvisioningStyle = Manual;
};
2743C9C51D7EF84B0089613B = {
CreatedOnToolsVersion = 8.0;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = 1CB8B35D1BBBB69C000E2DD1 /* Build configuration list for PBXProject "Driver" */;
@ -361,7 +139,6 @@
projectRoot = "";
targets = (
1CB8B3631BBBB78D000E2DD1 /* eqMac */,
2743C9C51D7EF84B0089613B /* PublicUtility */,
);
};
/* End PBXProject section */
@ -402,42 +179,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1CA2A9E21E8D1D08007A76A4 /* EQM_Stream.cpp in Sources */,
1C7010751F05ED5100D8CCDC /* EQM_AudibleState.cpp in Sources */,
1CB8B3801BBCCF87000E2DD1 /* EQM_Device.cpp in Sources */,
1C0CB6B91C642C600084C15A /* EQM_Client.cpp in Sources */,
1CB8B3921BBCF50A000E2DD1 /* EQM_WrappedAudioEngine.cpp in Sources */,
1CB8B36E1BBBD541000E2DD1 /* EQM_PlugInInterface.cpp in Sources */,
1CB8B37D1BBCCF62000E2DD1 /* EQM_PlugIn.cpp in Sources */,
1CDF3ABF1E8644C20001E9B7 /* EQM_AbstractDevice.cpp in Sources */,
1C7010791F07A0BA00D8CCDC /* EQM_VolumeControl.cpp in Sources */,
1C0CB6BA1C642C600084C15A /* EQM_ClientMap.cpp in Sources */,
E07380E22284D9F200FF0F53 /* EQM_Utils.cpp in Sources */,
1CB8B3831BBCE7B5000E2DD1 /* EQM_Object.cpp in Sources */,
1C38210E1C4A163A00A0C8C6 /* EQM_TaskQueue.cpp in Sources */,
1C0CB6BB1C642C600084C15A /* EQM_Clients.cpp in Sources */,
1CDF3ABC1E863B980001E9B7 /* EQM_NullDevice.cpp in Sources */,
19FE766482B57D852CCF6F0A /* EQM_MuteControl.cpp in Sources */,
19FE77D40F15EA060B462D83 /* EQM_Control.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
2743C9C21D7EF84B0089613B /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2743C9CD1D7EF8760089613B /* CACFArray.cpp in Sources */,
2743C9CF1D7EF8760089613B /* CACFDictionary.cpp in Sources */,
2743C9D11D7EF8760089613B /* CACFNumber.cpp in Sources */,
2743C9D31D7EF8760089613B /* CACFString.cpp in Sources */,
2743C9D51D7EF8760089613B /* CADebugger.cpp in Sources */,
2743C9D71D7EF8760089613B /* CADebugMacros.cpp in Sources */,
2743C9D91D7EF8760089613B /* CADebugPrintf.cpp in Sources */,
2743C9DB1D7EF8760089613B /* CADispatchQueue.cpp in Sources */,
2743C9DE1D7EF8760089613B /* CAHostTimeBase.cpp in Sources */,
2743C9E01D7EF8760089613B /* CAMutex.cpp in Sources */,
2743C9E21D7EF8760089613B /* CAPThread.cpp in Sources */,
2743C9E41D7EF8760089613B /* CAVolumeCurve.cpp in Sources */,
789B5F202699153000C72029 /* eqMac.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -581,13 +323,19 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_ENABLE_MODULES = NO;
CLANG_ENABLE_OBJC_ARC = NO;
CLANG_WARN_ASSIGN_ENUM = NO;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = NO;
CLANG_WARN_UNREACHABLE_CODE = YES;
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
@ -595,26 +343,35 @@
CURRENT_PROJECT_VERSION = 1.2.2;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = JZA6C97KJA;
GCC_C_LANGUAGE_STANDARD = "compiler-default";
ENABLE_NS_ASSERTIONS = YES;
GCC_C_LANGUAGE_STANDARD = c11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_CPP_RTTI = NO;
GCC_ENABLE_CPP_RTTI = YES;
GCC_INLINES_ARE_PRIVATE_EXTERN = NO;
GCC_PREPROCESSOR_DEFINITIONS = "";
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Audio/Plug-Ins/HAL";
IPHONEOS_DEPLOYMENT_TARGET = "";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MARKETING_VERSION = 1.2.2;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = NO;
ONLY_ACTIVE_ARCH = YES;
OTHER_CODE_SIGN_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = com.bitgapp.eqmac.driver;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx;
SKIP_INSTALL = NO;
TVOS_DEPLOYMENT_TARGET = "";
WARNING_CFLAGS = "";
WATCHOS_DEPLOYMENT_TARGET = "";
WRAPPER_EXTENSION = driver;
};
name = Debug;
@ -623,13 +380,19 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_ENABLE_MODULES = NO;
CLANG_ENABLE_OBJC_ARC = NO;
CLANG_WARN_ASSIGN_ENUM = NO;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = NO;
CLANG_WARN_UNREACHABLE_CODE = YES;
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
@ -637,16 +400,21 @@
CURRENT_PROJECT_VERSION = 1.2.2;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = JZA6C97KJA;
ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = "compiler-default";
GCC_ENABLE_CPP_RTTI = NO;
ENABLE_NS_ASSERTIONS = YES;
GCC_C_LANGUAGE_STANDARD = c11;
GCC_ENABLE_CPP_RTTI = YES;
GCC_INLINES_ARE_PRIVATE_EXTERN = NO;
GCC_PREPROCESSOR_DEFINITIONS = "";
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Audio/Plug-Ins/HAL";
IPHONEOS_DEPLOYMENT_TARGET = "";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MARKETING_VERSION = 1.2.2;
MTL_ENABLE_DEBUG_INFO = NO;
@ -656,65 +424,13 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx;
SKIP_INSTALL = NO;
TVOS_DEPLOYMENT_TARGET = "";
WARNING_CFLAGS = "";
WATCHOS_DEPLOYMENT_TARGET = "";
WRAPPER_EXTENSION = driver;
};
name = Release;
};
2743C9C81D7EF84B0089613B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
EXECUTABLE_PREFIX = lib;
GCC_DYNAMIC_NO_PIC = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
};
name = Debug;
};
2743C9C91D7EF84B0089613B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
EXECUTABLE_PREFIX = lib;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
MTL_ENABLE_DEBUG_INFO = NO;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
@ -736,15 +452,6 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
2743C9C71D7EF84B0089613B /* Build configuration list for PBXNativeTarget "PublicUtility" */ = {
isa = XCConfigurationList;
buildConfigurations = (
2743C9C81D7EF84B0089613B /* Debug */,
2743C9C91D7EF84B0089613B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 1CB8B35A1BBBB69C000E2DD1 /* Project object */;

View File

@ -1,305 +0,0 @@
/*
File: CAAtomic.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
/*
This file implements all Atomic operations using Interlocked functions specified in
Winbase.h
NOTE: According to Microsoft documentation, all Interlocked functions generates a
full barrier.
On Windows:
As the Interlocked functions returns the Old value, Extra checks and operations
are made after the atomic operation to return value consistent with OSX counterparts.
*/
#ifndef __CAAtomic_h__
#define __CAAtomic_h__
#if TARGET_OS_WIN32
#include <windows.h>
#include <intrin.h>
#pragma intrinsic(_InterlockedOr)
#pragma intrinsic(_InterlockedAnd)
#else
#include <CoreFoundation/CFBase.h>
#include <libkern/OSAtomic.h>
#endif
inline void CAMemoryBarrier()
{
#if TARGET_OS_WIN32
MemoryBarrier();
#else
OSMemoryBarrier();
#endif
}
inline SInt32 CAAtomicAdd32Barrier(SInt32 theAmt, volatile SInt32* theValue)
{
#if TARGET_OS_WIN32
long lRetVal = InterlockedExchangeAdd((volatile long*)theValue, theAmt);
// InterlockedExchangeAdd returns the original value which differs from OSX version.
// At this point the addition would have occured and hence returning the new value
// to keep it sync with OSX.
return lRetVal + theAmt;
#else
return OSAtomicAdd32Barrier(theAmt, (volatile int32_t *)theValue);
#endif
}
inline SInt32 CAAtomicOr32Barrier(UInt32 theMask, volatile UInt32* theValue)
{
#if TARGET_OS_WIN32
// InterlockedAnd macro is not defined in x86 platform, and hence using the intrinsic
// function instead.
long j = _InterlockedOr((volatile long*)theValue, theMask);
// _InterlockedOr returns the original value which differs from OSX version.
// Returning the new value similar to OSX
return (SInt32)(j | theMask);
#else
return OSAtomicOr32Barrier(theMask, (volatile uint32_t *)theValue);
#endif
}
inline SInt32 CAAtomicAnd32Barrier(UInt32 theMask, volatile UInt32* theValue)
{
#if TARGET_OS_WIN32
// InterlockedAnd macro is not defined in x86 platform, and hence using the intrinsic
// function instead.
long j = _InterlockedAnd((volatile long*)theValue, theMask);
// _InterlockedAnd returns the original value which differs from OSX version.
// Returning the new value similar to OSX
return (SInt32)(j & theMask);
#else
return OSAtomicAnd32Barrier(theMask, (volatile uint32_t *)theValue);
#endif
}
inline bool CAAtomicCompareAndSwap32Barrier(SInt32 oldValue, SInt32 newValue, volatile SInt32 *theValue)
{
#if TARGET_OS_WIN32
// InterlockedCompareExchange returns the old value. But we need to return bool value.
long lRetVal = InterlockedCompareExchange((volatile long*)theValue, newValue, oldValue);
// Hence we check if the new value is set and if it is we return true else false.
// If theValue is equal to oldValue then the swap happens. Otherwise swap doesn't happen.
return (oldValue == lRetVal);
#else
return OSAtomicCompareAndSwap32Barrier(oldValue, newValue, (volatile int32_t *)theValue);
#endif
}
inline SInt32 CAAtomicIncrement32(volatile SInt32* theValue)
{
#if TARGET_OS_WIN32
return (SInt32)InterlockedIncrement((volatile long*)theValue);
#else
return OSAtomicIncrement32((volatile int32_t *)theValue);
#endif
}
inline SInt32 CAAtomicDecrement32(volatile SInt32* theValue)
{
#if TARGET_OS_WIN32
return (SInt32)InterlockedDecrement((volatile long*)theValue);
#else
return OSAtomicDecrement32((volatile int32_t *)theValue);
#endif
}
inline SInt32 CAAtomicIncrement32Barrier(volatile SInt32* theValue)
{
#if TARGET_OS_WIN32
return CAAtomicIncrement32(theValue);
#else
return OSAtomicIncrement32Barrier((volatile int32_t *)theValue);
#endif
}
inline SInt32 CAAtomicDecrement32Barrier(volatile SInt32* theValue)
{
#if TARGET_OS_WIN32
return CAAtomicDecrement32(theValue);
#else
return OSAtomicDecrement32Barrier((volatile int32_t *)theValue);
#endif
}
inline bool CAAtomicTestAndClearBarrier(int bitToClear, void* theAddress)
{
#if TARGET_OS_WIN32
BOOL bOldVal = InterlockedBitTestAndReset((long*)theAddress, bitToClear);
return (bOldVal ? true : false);
#else
return OSAtomicTestAndClearBarrier(bitToClear, (volatile void *)theAddress);
#endif
}
inline bool CAAtomicTestAndClear(int bitToClear, void* theAddress)
{
#if TARGET_OS_WIN32
BOOL bOldVal = CAAtomicTestAndClearBarrier(bitToClear, (long*)theAddress);
return (bOldVal ? true : false);
#else
return OSAtomicTestAndClear(bitToClear, (volatile void *)theAddress);
#endif
}
inline bool CAAtomicTestAndSetBarrier(int bitToSet, void* theAddress)
{
#if TARGET_OS_WIN32
BOOL bOldVal = InterlockedBitTestAndSet((long*)theAddress, bitToSet);
return (bOldVal ? true : false);
#else
return OSAtomicTestAndSetBarrier(bitToSet, (volatile void *)theAddress);
#endif
}
// int32_t flavors -- for C++ only since we can't overload in C
// CFBase.h defines SInt32 as signed int which is similar to int32_t. If CFBase.h is included, then
// this will generate redefinition error. But on Mac, CFBase.h, still includes MacTypes.h where
// SInt32 is defined as signed long so this would work there.
// So in order to fix the redefinition errors, we define these functions only if MacTypes.h is included.
#if defined(__cplusplus) && defined(__MACTYPES__) && !__LP64__
inline int32_t CAAtomicAdd32Barrier(int32_t theAmt, volatile int32_t* theValue)
{
return CAAtomicAdd32Barrier(theAmt, (volatile SInt32 *)theValue);
}
inline int32_t CAAtomicOr32Barrier(uint32_t theMask, volatile uint32_t* theValue)
{
return CAAtomicOr32Barrier(theMask, (volatile UInt32 *)theValue);
}
inline int32_t CAAtomicAnd32Barrier(uint32_t theMask, volatile uint32_t* theValue)
{
return CAAtomicAnd32Barrier(theMask, (volatile UInt32 *)theValue);
}
inline bool CAAtomicCompareAndSwap32Barrier(int32_t oldValue, int32_t newValue, volatile int32_t *theValue)
{
return CAAtomicCompareAndSwap32Barrier(oldValue, newValue, (volatile SInt32 *)theValue);
}
inline int32_t CAAtomicIncrement32(volatile int32_t* theValue)
{
return CAAtomicIncrement32((volatile SInt32 *)theValue);
}
inline int32_t CAAtomicDecrement32(volatile int32_t* theValue)
{
return CAAtomicDecrement32((volatile SInt32 *)theValue);
}
inline int32_t CAAtomicIncrement32Barrier(volatile int32_t* theValue)
{
return CAAtomicIncrement32Barrier((volatile SInt32 *)theValue);
}
inline int32_t CAAtomicDecrement32Barrier(volatile int32_t* theValue)
{
return CAAtomicDecrement32Barrier((volatile SInt32 *)theValue);
}
#endif // __cplusplus && !__LP64__
#if __LP64__
inline bool CAAtomicCompareAndSwap64Barrier( int64_t __oldValue, int64_t __newValue, volatile int64_t *__theValue )
{
return OSAtomicCompareAndSwap64Barrier(__oldValue, __newValue, __theValue);
}
#endif
inline bool CAAtomicCompareAndSwapPtrBarrier(void *__oldValue, void *__newValue, volatile void ** __theValue)
{
#if __LP64__
return CAAtomicCompareAndSwap64Barrier((int64_t)__oldValue, (int64_t)__newValue, (int64_t *)__theValue);
#else
return CAAtomicCompareAndSwap32Barrier((int32_t)__oldValue, (int32_t)__newValue, (int32_t *)__theValue);
#endif
}
/* Spinlocks. These use memory barriers as required to synchronize access to shared
* memory protected by the lock. The lock operation spins, but employs various strategies
* to back off if the lock is held, making it immune to most priority-inversion livelocks.
* The try operation immediately returns false if the lock was held, true if it took the
* lock. The convention is that unlocked is zero, locked is nonzero.
*/
#define CA_SPINLOCK_INIT 0
typedef int32_t CASpinLock;
bool CASpinLockTry( volatile CASpinLock *__lock );
void CASpinLockLock( volatile CASpinLock *__lock );
void CASpinLockUnlock( volatile CASpinLock *__lock );
inline void CASpinLockLock( volatile CASpinLock *__lock )
{
#if TARGET_OS_MAC
OSSpinLockLock(__lock);
#else
while (CAAtomicTestAndSetBarrier(0, (void*)__lock))
usleep(1000); // ???
#endif
}
inline void CASpinLockUnlock( volatile CASpinLock *__lock )
{
#if TARGET_OS_MAC
OSSpinLockUnlock(__lock);
#else
CAAtomicTestAndClearBarrier(0, (void*)__lock);
#endif
}
inline bool CASpinLockTry( volatile CASpinLock *__lock )
{
#if TARGET_OS_MAC
return OSSpinLockTry(__lock);
#else
return (CAAtomicTestAndSetBarrier(0, (void*)__lock) == 0);
#endif
}
#endif // __CAAtomic_h__

View File

@ -1,239 +0,0 @@
/*
File: CAAtomicStack.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#ifndef __CAAtomicStack_h__
#define __CAAtomicStack_h__
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <libkern/OSAtomic.h>
#else
#include <CAAtomic.h>
#endif
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
#include <CoreServices/CoreServices.h>
#endif
// linked list LIFO or FIFO (pop_all_reversed) stack, elements are pushed and popped atomically
// class T must implement T *& next().
template <class T>
class TAtomicStack {
public:
TAtomicStack() : mHead(NULL) { }
// non-atomic routines, for use when initializing/deinitializing, operate NON-atomically
void push_NA(T *item)
{
item->next() = mHead;
mHead = item;
}
T * pop_NA()
{
T *result = mHead;
if (result)
mHead = result->next();
return result;
}
bool empty() const { return mHead == NULL; }
T * head() { return mHead; }
// atomic routines
void push_atomic(T *item)
{
T *head_;
do {
head_ = mHead;
item->next() = head_;
} while (!compare_and_swap(head_, item, &mHead));
}
void push_multiple_atomic(T *item)
// pushes entire linked list headed by item
{
T *head_, *p = item, *tail;
// find the last one -- when done, it will be linked to head
do {
tail = p;
p = p->next();
} while (p);
do {
head_ = mHead;
tail->next() = head_;
} while (!compare_and_swap(head_, item, &mHead));
}
T * pop_atomic_single_reader()
// this may only be used when only one thread may potentially pop from the stack.
// if multiple threads may pop, this suffers from the ABA problem.
// <rdar://problem/4606346> TAtomicStack suffers from the ABA problem
{
T *result;
do {
if ((result = mHead) == NULL)
break;
} while (!compare_and_swap(result, result->next(), &mHead));
return result;
}
T * pop_atomic()
// This is inefficient for large linked lists.
// prefer pop_all() to a series of calls to pop_atomic.
// push_multiple_atomic has to traverse the entire list.
{
T *result = pop_all();
if (result) {
T *next = result->next();
if (next)
// push all the remaining items back onto the stack
push_multiple_atomic(next);
}
return result;
}
T * pop_all()
{
T *result;
do {
if ((result = mHead) == NULL)
break;
} while (!compare_and_swap(result, NULL, &mHead));
return result;
}
T* pop_all_reversed()
{
TAtomicStack<T> reversed;
T *p = pop_all(), *next;
while (p != NULL) {
next = p->next();
reversed.push_NA(p);
p = next;
}
return reversed.mHead;
}
static bool compare_and_swap(T *oldvalue, T *newvalue, T **pvalue)
{
#if TARGET_OS_MAC
#if __LP64__
return ::OSAtomicCompareAndSwap64Barrier(int64_t(oldvalue), int64_t(newvalue), (int64_t *)pvalue);
#elif MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
return ::OSAtomicCompareAndSwap32Barrier(int32_t(oldvalue), int32_t(newvalue), (int32_t *)pvalue);
#else
return ::CompareAndSwap(UInt32(oldvalue), UInt32(newvalue), (UInt32 *)pvalue);
#endif
#else
//return ::CompareAndSwap(UInt32(oldvalue), UInt32(newvalue), (UInt32 *)pvalue);
return CAAtomicCompareAndSwap32Barrier(SInt32(oldvalue), SInt32(newvalue), (SInt32*)pvalue);
#endif
}
protected:
T * mHead;
};
#if ((MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) && !TARGET_OS_WIN32)
#include <libkern/OSAtomic.h>
class CAAtomicStack {
public:
CAAtomicStack(size_t nextPtrOffset) : mNextPtrOffset(nextPtrOffset) {
/*OSQueueHead h = OS_ATOMIC_QUEUE_INIT; mHead = h;*/
mHead.opaque1 = 0; mHead.opaque2 = 0;
}
// a subset of the above
void push_atomic(void *p) { OSAtomicEnqueue(&mHead, p, mNextPtrOffset); }
void push_NA(void *p) { push_atomic(p); }
void * pop_atomic() { return OSAtomicDequeue(&mHead, mNextPtrOffset); }
void * pop_atomic_single_reader() { return pop_atomic(); }
void * pop_NA() { return pop_atomic(); }
private:
OSQueueHead mHead;
size_t mNextPtrOffset;
};
// a more efficient subset of TAtomicStack using OSQueue.
template <class T>
class TAtomicStack2 {
public:
TAtomicStack2() {
/*OSQueueHead h = OS_ATOMIC_QUEUE_INIT; mHead = h;*/
mHead.opaque1 = 0; mHead.opaque2 = 0;
mNextPtrOffset = -1;
}
void push_atomic(T *item) {
if (mNextPtrOffset < 0) {
T **pnext = &item->next(); // hack around offsetof not working with C++
mNextPtrOffset = (Byte *)pnext - (Byte *)item;
}
OSAtomicEnqueue(&mHead, item, mNextPtrOffset);
}
void push_NA(T *item) { push_atomic(item); }
T * pop_atomic() { return (T *)OSAtomicDequeue(&mHead, mNextPtrOffset); }
T * pop_atomic_single_reader() { return pop_atomic(); }
T * pop_NA() { return pop_atomic(); }
// caution: do not try to implement pop_all_reversed here. the writer could add new elements
// while the reader is trying to pop old ones!
private:
OSQueueHead mHead;
ssize_t mNextPtrOffset;
};
#else
#define TAtomicStack2 TAtomicStack
#endif // MAC_OS_X_VERSION_MAX_ALLOWED && !TARGET_OS_WIN32
#endif // __CAAtomicStack_h__

View File

@ -1,508 +0,0 @@
/*
File: CAAutoDisposer.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#if !defined(__CAPtr_h__)
#define __CAPtr_h__
#include <stdlib.h> // for malloc
#include <new> // for bad_alloc
#include <string.h> // for memset
inline void* CA_malloc(size_t size)
{
void* p = malloc(size);
if (!p && size) throw std::bad_alloc();
return p;
}
inline void* CA_realloc(void* old, size_t size)
{
#if TARGET_OS_WIN32
void* p = realloc(old, size);
#else
void* p = reallocf(old, size); // reallocf ensures the old pointer is freed if memory is full (p is NULL).
#endif
if (!p && size) throw std::bad_alloc();
return p;
}
#ifndef UINTPTR_MAX
#if __LP64__
#define UINTPTR_MAX 18446744073709551615ULL
#else
#define UINTPTR_MAX 4294967295U
#endif
#endif
inline void* CA_calloc(size_t n, size_t size)
{
// ensure that multiplication will not overflow
if (n && UINTPTR_MAX / n < size) throw std::bad_alloc();
size_t nsize = n*size;
void* p = malloc(nsize);
if (!p && nsize) throw std::bad_alloc();
memset(p, 0, nsize);
return p;
}
// helper class for automatic conversions
template <typename T>
struct CAPtrRef
{
T* ptr_;
explicit CAPtrRef(T* ptr) : ptr_(ptr) {}
};
template <typename T>
class CAAutoFree
{
private:
T* ptr_;
public:
CAAutoFree() : ptr_(0) {}
explicit CAAutoFree(T* ptr) : ptr_(ptr) {}
template<typename U>
CAAutoFree(CAAutoFree<U>& that) : ptr_(that.release()) {} // take ownership
// C++ std says: a template constructor is never a copy constructor
CAAutoFree(CAAutoFree<T>& that) : ptr_(that.release()) {} // take ownership
CAAutoFree(size_t n, bool clear = false)
// this becomes an ambiguous call if n == 0
: ptr_(0)
{
size_t maxItems = ~size_t(0) / sizeof(T);
if (n > maxItems)
throw std::bad_alloc();
ptr_ = static_cast<T*>(clear ? CA_calloc(n, sizeof(T)) : CA_malloc(n * sizeof(T)));
}
~CAAutoFree() { free(); }
void alloc(size_t numItems, bool clear = false)
{
size_t maxItems = ~size_t(0) / sizeof(T);
if (numItems > maxItems) throw std::bad_alloc();
free();
ptr_ = static_cast<T*>(clear ? CA_calloc(numItems, sizeof(T)) : CA_malloc(numItems * sizeof(T)));
}
void allocBytes(size_t numBytes, bool clear = false)
{
free();
ptr_ = static_cast<T*>(clear ? CA_calloc(1, numBytes) : CA_malloc(numBytes));
}
void reallocBytes(size_t numBytes)
{
ptr_ = static_cast<T*>(CA_realloc(ptr_, numBytes));
}
void reallocItems(size_t numItems)
{
size_t maxItems = ~size_t(0) / sizeof(T);
if (numItems > maxItems) throw std::bad_alloc();
ptr_ = static_cast<T*>(CA_realloc(ptr_, numItems * sizeof(T)));
}
template <typename U>
CAAutoFree& operator=(CAAutoFree<U>& that)
{
set(that.release()); // take ownership
return *this;
}
CAAutoFree& operator=(CAAutoFree& that)
{
set(that.release()); // take ownership
return *this;
}
CAAutoFree& operator=(T* ptr)
{
set(ptr);
return *this;
}
template <typename U>
CAAutoFree& operator=(U* ptr)
{
set(ptr);
return *this;
}
T& operator*() const { return *ptr_; }
T* operator->() const { return ptr_; }
T* operator()() const { return ptr_; }
T* get() const { return ptr_; }
operator T*() const { return ptr_; }
bool operator==(CAAutoFree const& that) const { return ptr_ == that.ptr_; }
bool operator!=(CAAutoFree const& that) const { return ptr_ != that.ptr_; }
bool operator==(T* ptr) const { return ptr_ == ptr; }
bool operator!=(T* ptr) const { return ptr_ != ptr; }
T* release()
{
// release ownership
T* result = ptr_;
ptr_ = 0;
return result;
}
void set(T* ptr)
{
if (ptr != ptr_)
{
::free(ptr_);
ptr_ = ptr;
}
}
void free()
{
set(0);
}
// automatic conversions to allow assignment from results of functions.
// hard to explain. see auto_ptr implementation and/or Josuttis' STL book.
CAAutoFree(CAPtrRef<T> ref) : ptr_(ref.ptr_) { }
CAAutoFree& operator=(CAPtrRef<T> ref)
{
set(ref.ptr_);
return *this;
}
template<typename U>
operator CAPtrRef<U>()
{ return CAPtrRef<U>(release()); }
template<typename U>
operator CAAutoFree<U>()
{ return CAAutoFree<U>(release()); }
};
template <typename T>
class CAAutoDelete
{
private:
T* ptr_;
public:
CAAutoDelete() : ptr_(0) {}
explicit CAAutoDelete(T* ptr) : ptr_(ptr) {}
template<typename U>
CAAutoDelete(CAAutoDelete<U>& that) : ptr_(that.release()) {} // take ownership
// C++ std says: a template constructor is never a copy constructor
CAAutoDelete(CAAutoDelete<T>& that) : ptr_(that.release()) {} // take ownership
~CAAutoDelete() { free(); }
template <typename U>
CAAutoDelete& operator=(CAAutoDelete<U>& that)
{
set(that.release()); // take ownership
return *this;
}
CAAutoDelete& operator=(CAAutoDelete& that)
{
set(that.release()); // take ownership
return *this;
}
CAAutoDelete& operator=(T* ptr)
{
set(ptr);
return *this;
}
template <typename U>
CAAutoDelete& operator=(U* ptr)
{
set(ptr);
return *this;
}
T& operator*() const { return *ptr_; }
T* operator->() const { return ptr_; }
T* operator()() const { return ptr_; }
T* get() const { return ptr_; }
operator T*() const { return ptr_; }
bool operator==(CAAutoDelete const& that) const { return ptr_ == that.ptr_; }
bool operator!=(CAAutoDelete const& that) const { return ptr_ != that.ptr_; }
bool operator==(T* ptr) const { return ptr_ == ptr; }
bool operator!=(T* ptr) const { return ptr_ != ptr; }
T* release()
{
// release ownership
T* result = ptr_;
ptr_ = 0;
return result;
}
void set(T* ptr)
{
if (ptr != ptr_)
{
delete ptr_;
ptr_ = ptr;
}
}
void free()
{
set(0);
}
// automatic conversions to allow assignment from results of functions.
// hard to explain. see auto_ptr implementation and/or Josuttis' STL book.
CAAutoDelete(CAPtrRef<T> ref) : ptr_(ref.ptr_) { }
CAAutoDelete& operator=(CAPtrRef<T> ref)
{
set(ref.ptr_);
return *this;
}
template<typename U>
operator CAPtrRef<U>()
{ return CAPtrRef<U>(release()); }
template<typename U>
operator CAAutoFree<U>()
{ return CAAutoFree<U>(release()); }
};
template <typename T>
class CAAutoArrayDelete
{
private:
T* ptr_;
public:
CAAutoArrayDelete() : ptr_(0) {}
explicit CAAutoArrayDelete(T* ptr) : ptr_(ptr) {}
template<typename U>
CAAutoArrayDelete(CAAutoArrayDelete<U>& that) : ptr_(that.release()) {} // take ownership
// C++ std says: a template constructor is never a copy constructor
CAAutoArrayDelete(CAAutoArrayDelete<T>& that) : ptr_(that.release()) {} // take ownership
// this becomes an ambiguous call if n == 0
CAAutoArrayDelete(size_t n) : ptr_(new T[n]) {}
~CAAutoArrayDelete() { free(); }
void alloc(size_t numItems)
{
free();
ptr_ = new T [numItems];
}
template <typename U>
CAAutoArrayDelete& operator=(CAAutoArrayDelete<U>& that)
{
set(that.release()); // take ownership
return *this;
}
CAAutoArrayDelete& operator=(CAAutoArrayDelete& that)
{
set(that.release()); // take ownership
return *this;
}
CAAutoArrayDelete& operator=(T* ptr)
{
set(ptr);
return *this;
}
template <typename U>
CAAutoArrayDelete& operator=(U* ptr)
{
set(ptr);
return *this;
}
T& operator*() const { return *ptr_; }
T* operator->() const { return ptr_; }
T* operator()() const { return ptr_; }
T* get() const { return ptr_; }
operator T*() const { return ptr_; }
bool operator==(CAAutoArrayDelete const& that) const { return ptr_ == that.ptr_; }
bool operator!=(CAAutoArrayDelete const& that) const { return ptr_ != that.ptr_; }
bool operator==(T* ptr) const { return ptr_ == ptr; }
bool operator!=(T* ptr) const { return ptr_ != ptr; }
T* release()
{
// release ownership
T* result = ptr_;
ptr_ = 0;
return result;
}
void set(T* ptr)
{
if (ptr != ptr_)
{
delete [] ptr_;
ptr_ = ptr;
}
}
void free()
{
set(0);
}
// automatic conversions to allow assignment from results of functions.
// hard to explain. see auto_ptr implementation and/or Josuttis' STL book.
CAAutoArrayDelete(CAPtrRef<T> ref) : ptr_(ref.ptr_) { }
CAAutoArrayDelete& operator=(CAPtrRef<T> ref)
{
set(ref.ptr_);
return *this;
}
template<typename U>
operator CAPtrRef<U>()
{ return CAPtrRef<U>(release()); }
template<typename U>
operator CAAutoArrayDelete<U>()
{ return CAAutoFree<U>(release()); }
};
// convenience function
template <typename T>
void free(CAAutoFree<T>& p)
{
p.free();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
#if 0
// example program showing ownership transfer
CAAutoFree<char> source()
{
// source allocates and returns ownership to the caller.
const char* str = "this is a test";
size_t size = strlen(str) + 1;
CAAutoFree<char> captr(size, false);
strlcpy(captr(), str, size);
printf("source %08X %08X '%s'\n", &captr, captr(), captr());
return captr;
}
void user(CAAutoFree<char> const& captr)
{
// passed by const reference. user can access the pointer but does not take ownership.
printf("user: %08X %08X '%s'\n", &captr, captr(), captr());
}
void sink(CAAutoFree<char> captr)
{
// passed by value. sink takes ownership and frees the pointer on return.
printf("sink: %08X %08X '%s'\n", &captr, captr(), captr());
}
int main (int argc, char * const argv[])
{
CAAutoFree<char> captr(source());
printf("main captr A %08X %08X\n", &captr, captr());
user(captr);
sink(captr);
printf("main captr B %08X %08X\n", &captr, captr());
return 0;
}
#endif
#endif

View File

@ -1,206 +0,0 @@
/*
File: CABitOperations.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#ifndef _CABitOperations_h_
#define _CABitOperations_h_
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
//#include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
#include <CoreFoundation/CFBase.h>
#else
// #include <MacTypes.h>
#include "CFBase.h"
#endif
#include <TargetConditionals.h>
// return whether a number is a power of two
inline UInt32 IsPowerOfTwo(UInt32 x)
{
return (x & (x-1)) == 0;
}
// count the leading zeros in a word
// Metrowerks Codewarrior. powerpc native count leading zeros instruction:
// I think it's safe to remove this ...
//#define CountLeadingZeroes(x) ((int)__cntlzw((unsigned int)x))
inline UInt32 CountLeadingZeroes(UInt32 arg)
{
// GNUC / LLVM have a builtin
#if defined(__GNUC__) || defined(__llvm___)
#if (TARGET_CPU_X86 || TARGET_CPU_X86_64)
if (arg == 0) return 32;
#endif // TARGET_CPU_X86 || TARGET_CPU_X86_64
return __builtin_clz(arg);
#elif TARGET_OS_WIN32
UInt32 tmp;
__asm{
bsr eax, arg
mov ecx, 63
cmovz eax, ecx
xor eax, 31
mov tmp, eax // this moves the result in tmp to return.
}
return tmp;
#else
#error "Unsupported architecture"
#endif // defined(__GNUC__)
}
// Alias (with different spelling)
#define CountLeadingZeros CountLeadingZeroes
inline UInt32 CountLeadingZeroesLong(UInt64 arg)
{
// GNUC / LLVM have a builtin
#if defined(__GNUC__) || defined(__llvm___)
#if (TARGET_CPU_X86 || TARGET_CPU_X86_64)
if (arg == 0) return 64;
#endif // TARGET_CPU_X86 || TARGET_CPU_X86_64
return __builtin_clzll(arg);
#elif TARGET_OS_WIN32
UInt32 x = CountLeadingZeroes((UInt32)(arg >> 32));
if(x < 32)
return x;
else
return 32+CountLeadingZeroes((UInt32)arg);
#else
#error "Unsupported architecture"
#endif // defined(__GNUC__)
}
#define CountLeadingZerosLong CountLeadingZeroesLong
// count trailing zeroes
inline UInt32 CountTrailingZeroes(UInt32 x)
{
return 32 - CountLeadingZeroes(~x & (x-1));
}
// count leading ones
inline UInt32 CountLeadingOnes(UInt32 x)
{
return CountLeadingZeroes(~x);
}
// count trailing ones
inline UInt32 CountTrailingOnes(UInt32 x)
{
return 32 - CountLeadingZeroes(x & (~x-1));
}
// number of bits required to represent x.
inline UInt32 NumBits(UInt32 x)
{
return 32 - CountLeadingZeroes(x);
}
// base 2 log of next power of two greater or equal to x
inline UInt32 Log2Ceil(UInt32 x)
{
return 32 - CountLeadingZeroes(x - 1);
}
// base 2 log of next power of two less or equal to x
inline UInt32 Log2Floor(UInt32 x)
{
return 32 - CountLeadingZeroes(x) - 1;
}
// next power of two greater or equal to x
inline UInt32 NextPowerOfTwo(UInt32 x)
{
return 1 << Log2Ceil(x);
}
// counting the one bits in a word
inline UInt32 CountOnes(UInt32 x)
{
// secret magic algorithm for counting bits in a word.
x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
return (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
}
// counting the zero bits in a word
inline UInt32 CountZeroes(UInt32 x)
{
return CountOnes(~x);
}
// return the bit position (0..31) of the least significant bit
inline UInt32 LSBitPos(UInt32 x)
{
return CountTrailingZeroes(x & -(SInt32)x);
}
// isolate the least significant bit
inline UInt32 LSBit(UInt32 x)
{
return x & -(SInt32)x;
}
// return the bit position (0..31) of the most significant bit
inline UInt32 MSBitPos(UInt32 x)
{
return 31 - CountLeadingZeroes(x);
}
// isolate the most significant bit
inline UInt32 MSBit(UInt32 x)
{
return 1 << MSBitPos(x);
}
// Division optimized for power of 2 denominators
inline UInt32 DivInt(UInt32 numerator, UInt32 denominator)
{
if(IsPowerOfTwo(denominator))
return numerator >> (31 - CountLeadingZeroes(denominator));
else
return numerator/denominator;
}
#endif

View File

@ -1,821 +0,0 @@
/*
File: CACFArray.cpp
Abstract: CACFArray.h
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
//=============================================================================
// Includes
//=============================================================================
// Self Include
#include "CACFArray.h"
// PublicUtility Includes
#include "CACFDictionary.h"
#include "CACFNumber.h"
#include "CACFString.h"
//=============================================================================
// CACFArray
//=============================================================================
bool CACFArray::HasItem(const void* inItem) const
{
bool theAnswer = false;
if(mCFArray != NULL)
{
CFRange theRange = { 0, CFArrayGetCount(mCFArray)};
theAnswer = CFArrayContainsValue(mCFArray, theRange, inItem);
}
return theAnswer;
}
bool CACFArray::GetIndexOfItem(const void* inItem, UInt32& outIndex) const
{
bool theAnswer = false;
outIndex = 0;
if(mCFArray != NULL)
{
CFRange theRange = { 0, CFArrayGetCount(mCFArray)};
CFIndex theIndex = CFArrayGetFirstIndexOfValue(mCFArray, theRange, inItem);
if(theIndex != -1)
{
theAnswer = true;
outIndex = ToUInt32(theIndex);
}
}
return theAnswer;
}
bool CACFArray::GetBool(UInt32 inIndex, bool& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inIndex, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFBooleanGetTypeID()))
{
outValue = CFBooleanGetValue(static_cast<CFBooleanRef>(theValue));
theAnswer = true;
}
else if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
{
SInt32 theNumericValue = 0;
CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &theNumericValue);
outValue = theNumericValue != 0;
theAnswer = true;
}
}
return theAnswer;
}
bool CACFArray::GetSInt32(UInt32 inIndex, SInt32& outItem) const
{
bool theAnswer = false;
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theItem), kCFNumberSInt32Type, &outItem);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFArray::GetUInt32(UInt32 inIndex, UInt32& outItem) const
{
bool theAnswer = false;
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theItem), kCFNumberSInt32Type, &outItem);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFArray::GetSInt64(UInt32 inIndex, SInt64& outItem) const
{
bool theAnswer = false;
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theItem), kCFNumberSInt64Type, &outItem);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFArray::GetUInt64(UInt32 inIndex, UInt64& outItem) const
{
bool theAnswer = false;
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theItem), kCFNumberSInt64Type, &outItem);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFArray::GetFloat32(UInt32 inIndex, Float32& outItem) const
{
bool theAnswer = false;
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theItem), kCFNumberFloat32Type, &outItem);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFArray::GetFloat64(UInt32 inIndex, Float64& outItem) const
{
bool theAnswer = false;
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theItem), kCFNumberFloat64Type, &outItem);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFArray::Get4CC(UInt32 inIndex, UInt32& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inIndex, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &outValue);
theAnswer = true;
}
else if((theValue != NULL) && (CFGetTypeID(theValue) == CFStringGetTypeID()))
{
CFStringRef theString = static_cast<CFStringRef>(theValue);
if(CFStringGetLength(theString) == 4)
{
char theCString[5];
CFStringGetCString(theString, theCString, 5, kCFStringEncodingASCII);
outValue = CFSwapInt32BigToHost(*reinterpret_cast<UInt32*>(theCString));
}
}
}
return theAnswer;
}
bool CACFArray::GetString(UInt32 inIndex, CFStringRef& outItem) const
{
bool theAnswer = false;
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFStringGetTypeID()))
{
outItem = static_cast<CFStringRef>(theItem);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFArray::GetArray(UInt32 inIndex, CFArrayRef& outItem) const
{
bool theAnswer = false;
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFArrayGetTypeID()))
{
outItem = static_cast<CFArrayRef>(theItem);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFArray::GetDictionary(UInt32 inIndex, CFDictionaryRef& outItem) const
{
bool theAnswer = false;
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFDictionaryGetTypeID()))
{
outItem = static_cast<CFDictionaryRef>(theItem);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFArray::GetData(UInt32 inIndex, CFDataRef& outItem) const
{
bool theAnswer = false;
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFDataGetTypeID()))
{
outItem = static_cast<CFDataRef>(theItem);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFArray::GetUUID(UInt32 inIndex, CFUUIDRef& outItem) const
{
bool theAnswer = false;
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFUUIDGetTypeID()))
{
outItem = static_cast<CFUUIDRef>(theItem);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFArray::GetCFType(UInt32 inIndex, CFTypeRef& outItem) const
{
bool theAnswer = false;
if((mCFArray != NULL) && (inIndex < GetNumberItems()))
{
outItem = CFArrayGetValueAtIndex(mCFArray, static_cast<CFIndex>(inIndex));
theAnswer = outItem != NULL;
}
return theAnswer;
}
void CACFArray::GetCACFString(UInt32 inIndex, CACFString& outItem) const
{
outItem = static_cast<CFStringRef>(NULL);
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFStringGetTypeID()))
{
outItem = static_cast<CFStringRef>(theItem);
}
}
}
void CACFArray::GetCACFArray(UInt32 inIndex, CACFArray& outItem) const
{
outItem = static_cast<CFArrayRef>(NULL);
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFArrayGetTypeID()))
{
outItem = static_cast<CFArrayRef>(theItem);
}
}
}
void CACFArray::GetCACFDictionary(UInt32 inIndex, CACFDictionary& outItem) const
{
outItem = static_cast<CFDictionaryRef>(NULL);
CFTypeRef theItem = NULL;
if(GetCFType(inIndex, theItem))
{
if((theItem != NULL) && (CFGetTypeID(theItem) == CFDictionaryGetTypeID()))
{
outItem = static_cast<CFDictionaryRef>(theItem);
}
}
}
bool CACFArray::AppendBool(bool inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFBoolean theItem(inItem);
if(theItem.IsValid())
{
theAnswer = AppendCFType(theItem.GetCFBoolean());
}
}
return theAnswer;
}
bool CACFArray::AppendSInt32(SInt32 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = AppendCFType(theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::AppendUInt32(UInt32 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = AppendCFType(theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::AppendSInt64(SInt64 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = AppendCFType(theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::AppendUInt64(UInt64 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = AppendCFType(theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::AppendFloat32(Float32 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = AppendCFType(theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::AppendFloat64(Float64 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = AppendCFType(theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::AppendString(const CFStringRef inItem)
{
return AppendCFType(inItem);
}
bool CACFArray::AppendArray(const CFArrayRef inItem)
{
return AppendCFType(inItem);
}
bool CACFArray::AppendDictionary(const CFDictionaryRef inItem)
{
return AppendCFType(inItem);
}
bool CACFArray::AppendData(const CFDataRef inItem)
{
return AppendCFType(inItem);
}
bool CACFArray::AppendCFType(const CFTypeRef inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CFArrayAppendValue(mCFArray, inItem);
theAnswer = true;
}
return theAnswer;
}
bool CACFArray::InsertBool(UInt32 inIndex, bool inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFBoolean theItem(inItem);
if(theItem.IsValid())
{
theAnswer = InsertCFType(inIndex, theItem.GetCFBoolean());
}
}
return theAnswer;
}
bool CACFArray::InsertSInt32(UInt32 inIndex, SInt32 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = InsertCFType(inIndex, theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::InsertUInt32(UInt32 inIndex, UInt32 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = InsertCFType(inIndex, theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::InsertSInt64(UInt32 inIndex, SInt64 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = InsertCFType(inIndex, theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::InsertUInt64(UInt32 inIndex, UInt64 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = InsertCFType(inIndex, theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::InsertFloat32(UInt32 inIndex, Float32 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = InsertCFType(inIndex, theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::InsertFloat64(UInt32 inIndex, Float64 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = InsertCFType(inIndex, theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::InsertString(UInt32 inIndex, const CFStringRef inItem)
{
return InsertCFType(inIndex, inItem);
}
bool CACFArray::InsertArray(UInt32 inIndex, const CFArrayRef inItem)
{
return InsertCFType(inIndex, inItem);
}
bool CACFArray::InsertDictionary(UInt32 inIndex, const CFDictionaryRef inItem)
{
return InsertCFType(inIndex, inItem);
}
bool CACFArray::InsertData(UInt32 inIndex, const CFDataRef inItem)
{
return InsertCFType(inIndex, inItem);
}
bool CACFArray::InsertCFType(UInt32 inIndex, const CFTypeRef inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable)
{
if(inIndex < GetNumberItems())
{
CFArrayInsertValueAtIndex(mCFArray, static_cast<CFIndex>(inIndex), inItem);
}
else
{
CFArrayAppendValue(mCFArray, inItem);
}
theAnswer = true;
}
return theAnswer;
}
bool CACFArray::SetBool(UInt32 inIndex, bool inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
{
CACFBoolean theItem(inItem);
if(theItem.IsValid())
{
theAnswer = SetCFType(inIndex, theItem.GetCFBoolean());
}
}
return theAnswer;
}
bool CACFArray::SetSInt32(UInt32 inIndex, SInt32 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = SetCFType(inIndex, theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::SetUInt32(UInt32 inIndex, UInt32 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = SetCFType(inIndex, theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::SetSInt64(UInt32 inIndex, SInt64 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = SetCFType(inIndex, theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::SetUInt64(UInt32 inIndex, UInt64 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = SetCFType(inIndex, theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::SetFloat32(UInt32 inIndex, Float32 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = SetCFType(inIndex, theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::SetFloat64(UInt32 inIndex, Float64 inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
{
CACFNumber theItem(inItem);
if(theItem.IsValid())
{
theAnswer = SetCFType(inIndex, theItem.GetCFNumber());
}
}
return theAnswer;
}
bool CACFArray::SetString(UInt32 inIndex, const CFStringRef inItem)
{
return SetCFType(inIndex, inItem);
}
bool CACFArray::SetArray(UInt32 inIndex, const CFArrayRef inItem)
{
return SetCFType(inIndex, inItem);
}
bool CACFArray::SetDictionary(UInt32 inIndex, const CFDictionaryRef inItem)
{
return SetCFType(inIndex, inItem);
}
bool CACFArray::SetData(UInt32 inIndex, const CFDataRef inItem)
{
return SetCFType(inIndex, inItem);
}
bool CACFArray::SetCFType(UInt32 inIndex, const CFTypeRef inItem)
{
bool theAnswer = false;
if((mCFArray != NULL) && mMutable && (inIndex <= GetNumberItems()))
{
CFArraySetValueAtIndex(mCFArray, static_cast<CFIndex>(inIndex), inItem);
theAnswer = true;
}
return theAnswer;
}

View File

@ -1,195 +0,0 @@
/*
File: CACFArray.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#if !defined(__CACFArray_h__)
#define __CACFArray_h__
//=============================================================================
// Includes
//=============================================================================
// System Includes
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreAudio/CoreAudioTypes.h>
#include <CoreFoundation/CoreFoundation.h>
#else
#include <CoreAudioTypes.h>
#include <CoreFoundation.h>
#endif
#include "CADebugMacros.h"
//=============================================================================
// Types
//=============================================================================
class CACFDictionary;
class CACFString;
//=============================================================================
// CACFArray
//=============================================================================
class CACFArray
{
// Construction/Destruction
public:
CACFArray() : mCFArray(CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks)), mRelease(true), mMutable(true) {}
explicit CACFArray(bool inRelease) : mCFArray(CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks)), mRelease(inRelease), mMutable(true) {}
CACFArray(UInt32 inMaxNumberItems, bool inRelease) : mCFArray(CFArrayCreateMutable(NULL, static_cast<CFIndex>(inMaxNumberItems), &kCFTypeArrayCallBacks)), mRelease(inRelease), mMutable(true) {}
CACFArray(CFArrayRef inCFArray, bool inRelease) : mCFArray(const_cast<CFMutableArrayRef>(inCFArray)), mRelease(inRelease), mMutable(false) {}
CACFArray(CFMutableArrayRef inCFArray, bool inRelease) : mCFArray(inCFArray), mRelease(inRelease), mMutable(true) {}
CACFArray(const CACFArray& inArray) : mCFArray(inArray.mCFArray), mRelease(inArray.mRelease), mMutable(inArray.mMutable) { Retain(); }
CACFArray& operator=(const CACFArray& inArray) { Release(); mCFArray = inArray.mCFArray; mRelease = inArray.mRelease; mMutable = inArray.mMutable; Retain(); return *this; }
CACFArray& operator=(CFArrayRef inCFArray) { Release(); mCFArray = const_cast<CFMutableArrayRef>(inCFArray); mMutable = false; Retain(); return *this; }
CACFArray& operator=(CFMutableArrayRef inCFArray) { Release(); mCFArray = inCFArray; mMutable = true; Retain(); return *this; }
~CACFArray() { Release(); }
private:
void Retain() { if(mRelease && (mCFArray != NULL)) { CFRetain(mCFArray); } }
void Release() { if(mRelease && (mCFArray != NULL)) { CFRelease(mCFArray); } }
// Attributes
public:
bool IsValid() const { return mCFArray != NULL; }
bool IsMutable() const { return mMutable; }
bool CanModify() const { return mMutable && (mCFArray != NULL); }
bool WillRelease() const { return mRelease; }
void ShouldRelease(bool inRelease) { mRelease = inRelease; }
CFTypeID GetTypeID() const { return CFGetTypeID(mCFArray); }
CFArrayRef GetCFArray() const { return mCFArray; }
CFArrayRef CopyCFArray() const { if(mCFArray != NULL) { CFRetain(mCFArray); } return mCFArray; }
CFMutableArrayRef GetCFMutableArray() const { return mCFArray; }
CFMutableArrayRef CopyCFMutableArray() const { if(mCFArray != NULL) { CFRetain(mCFArray); } return mCFArray; }
CFPropertyListRef AsPropertyList() const { return mCFArray; }
void SetCFMutableArrayFromCopy(CFArrayRef inArray, bool inRelease = true) { Release(); mCFArray = CFArrayCreateMutableCopy(NULL, 0, inArray); mMutable = true; mRelease = inRelease; }
// Item Operations
public:
UInt32 GetNumberItems() const { UInt32 theAnswer = 0; if(mCFArray != NULL) { theAnswer = ToUInt32(CFArrayGetCount(mCFArray)); } return theAnswer; }
bool HasItem(const void* inItem) const;
void RemoveItem(const void* inItem) { UInt32 theIndex; if(CanModify() && GetIndexOfItem(inItem, theIndex)) { RemoveItemAtIndex(theIndex); } }
bool GetIndexOfItem(const void* inItem, UInt32& outIndex) const;
void RemoveItemAtIndex(UInt32 inIndex) { if(CanModify()) { CFArrayRemoveValueAtIndex(mCFArray, static_cast<CFIndex>(inIndex)); } }
void Clear() { if(CanModify()) { CFArrayRemoveAllValues(mCFArray); } }
void Sort(CFComparatorFunction inCompareFunction) { if(CanModify()) { CFRange theRange = { 0, CFArrayGetCount(mCFArray) }; CFArraySortValues(mCFArray, theRange, inCompareFunction, NULL); } }
void SortNumbers() { Sort((CFComparatorFunction)CFNumberCompare); }
void SortStrings() { Sort((CFComparatorFunction)CFStringCompare); }
bool GetBool(UInt32 inIndex, bool& outValue) const;
bool GetSInt32(UInt32 inIndex, SInt32& outItem) const;
bool GetUInt32(UInt32 inIndex, UInt32& outItem) const;
bool GetSInt64(UInt32 inIndex, SInt64& outItem) const;
bool GetUInt64(UInt32 inIndex, UInt64& outItem) const;
bool GetFloat32(UInt32 inIndex, Float32& outItem) const;
bool GetFloat64(UInt32 inIndex, Float64& outItem) const;
bool Get4CC(UInt32 inIndex, UInt32& outValue) const;
bool GetString(UInt32 inIndex, CFStringRef& outItem) const;
bool GetArray(UInt32 inIndex, CFArrayRef& outItem) const;
bool GetDictionary(UInt32 inIndex, CFDictionaryRef& outItem) const;
bool GetData(UInt32 inIndex, CFDataRef& outItem) const;
bool GetUUID(UInt32 inIndex, CFUUIDRef& outItem) const;
bool GetCFType(UInt32 inIndex, CFTypeRef& outItem) const;
void GetCACFString(UInt32 inIndex, CACFString& outItem) const;
void GetCACFArray(UInt32 inIndex, CACFArray& outItem) const;
void GetCACFDictionary(UInt32 inIndex, CACFDictionary& outItem) const;
bool AppendBool(bool inItem);
bool AppendSInt32(SInt32 inItem);
bool AppendUInt32(UInt32 inItem);
bool AppendSInt64(SInt64 inItem);
bool AppendUInt64(UInt64 inItem);
bool AppendFloat32(Float32 inItem);
bool AppendFloat64(Float64 inItem);
bool AppendString(const CFStringRef inItem);
bool AppendArray(const CFArrayRef inItem);
bool AppendDictionary(const CFDictionaryRef inItem);
bool AppendData(const CFDataRef inItem);
bool AppendCFType(const CFTypeRef inItem);
bool InsertBool(UInt32 inIndex, bool inItem);
bool InsertSInt32(UInt32 inIndex, SInt32 inItem);
bool InsertUInt32(UInt32 inIndex, UInt32 inItem);
bool InsertSInt64(UInt32 inIndex, SInt64 inItem);
bool InsertUInt64(UInt32 inIndex, UInt64 inItem);
bool InsertFloat32(UInt32 inIndex, Float32 inItem);
bool InsertFloat64(UInt32 inIndex, Float64 inItem);
bool InsertString(UInt32 inIndex, const CFStringRef inItem);
bool InsertArray(UInt32 inIndex, const CFArrayRef inItem);
bool InsertDictionary(UInt32 inIndex, const CFDictionaryRef inItem);
bool InsertData(UInt32 inIndex, const CFDataRef inItem);
bool InsertCFType(UInt32 inIndex, const CFTypeRef inItem);
bool SetBool(UInt32 inIndex, bool inItem);
bool SetSInt32(UInt32 inIndex, SInt32 inItem);
bool SetUInt32(UInt32 inIndex, UInt32 inItem);
bool SetSInt64(UInt32 inIndex, SInt64 inItem);
bool SetUInt64(UInt32 inIndex, UInt64 inItem);
bool SetFloat32(UInt32 inIndex, Float32 inItem);
bool SetFloat64(UInt32 inIndex, Float64 inItem);
bool SetString(UInt32 inIndex, const CFStringRef inItem);
bool SetArray(UInt32 inIndex, const CFArrayRef inItem);
bool SetDictionary(UInt32 inIndex, const CFDictionaryRef inItem);
bool SetData(UInt32 inIndex, const CFDataRef inItem);
bool SetCFType(UInt32 inIndex, const CFTypeRef inItem);
// Implementation
private:
CFMutableArrayRef mCFArray;
bool mRelease;
bool mMutable;
CACFArray(const void*); // prevent accidental instantiation with a pointer via bool constructor
};
#endif

View File

@ -1,581 +0,0 @@
/*
File: CACFDictionary.cpp
Abstract: CACFDictionary.h
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
//=============================================================================
// Includes
//=============================================================================
// Self Include
#include "CACFDictionary.h"
// PublicUtility Includes
#include "CACFArray.h"
#include "CACFNumber.h"
#include "CACFString.h"
//=============================================================================
// CACFDictionary
//=============================================================================
bool CACFDictionary::HasKey(const CFStringRef inKey) const
{
return CFDictionaryContainsKey(mCFDictionary, inKey) != 0;
}
UInt32 CACFDictionary::Size () const
{
return mCFDictionary ? ToUInt32(CFDictionaryGetCount(mCFDictionary)) : 0;
}
void CACFDictionary::GetKeys (const void **keys) const
{
CFDictionaryGetKeysAndValues(mCFDictionary, keys, NULL);
}
void CACFDictionary::GetKeysAndValues (const void **keys, const void **values) const
{
CFDictionaryGetKeysAndValues(mCFDictionary, keys, values);
}
bool CACFDictionary::GetBool(const CFStringRef inKey, bool& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFBooleanGetTypeID()))
{
outValue = CFBooleanGetValue(static_cast<CFBooleanRef>(theValue));
theAnswer = true;
}
else if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
{
SInt32 theNumericValue = 0;
CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &theNumericValue);
outValue = theNumericValue != 0;
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetSInt32(const CFStringRef inKey, SInt32& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &outValue);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetUInt32(const CFStringRef inKey, UInt32& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &outValue);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetSInt64(const CFStringRef inKey, SInt64& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt64Type, &outValue);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetUInt64(const CFStringRef inKey, UInt64& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt64Type, &outValue);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetFloat32FromString(const CFStringRef inKey, Float32& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFStringGetTypeID()))
{
outValue = static_cast<Float32>(CFStringGetDoubleValue(static_cast<CFStringRef>(theValue)));
}
}
return theAnswer;
}
bool CACFDictionary::GetUInt32FromString(const CFStringRef inKey, UInt32& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFStringGetTypeID()))
{
outValue = CFStringGetIntValue(static_cast<CFStringRef>(theValue));
}
}
return theAnswer;
}
bool CACFDictionary::GetFloat32(const CFStringRef inKey, Float32& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberFloat32Type, &outValue);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetFloat64(const CFStringRef inKey, Float64& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberFloat64Type, &outValue);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetFixed32(const CFStringRef inKey, Float32& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
{
SInt32 theFixed32 = 0;
CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &theFixed32);
// this is a 16.16 value so convert it to a float
Float32 theSign = theFixed32 < 0 ? -1.0f : 1.0f;
theFixed32 *= (SInt32)theSign;
Float32 theWholePart = (theFixed32 & 0x7FFF0000) >> 16;
Float32 theFractPart = theFixed32 & 0x0000FFFF;
theFractPart /= 65536.0f;
outValue = theSign * (theWholePart + theFractPart);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetFixed64(const CFStringRef inKey, Float64& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
{
SInt64 theFixed64 = 0;
CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt64Type, &theFixed64);
outValue = static_cast<Float64>(theFixed64 >> 32);
outValue += static_cast<Float64>(theFixed64 & 0x00000000FFFFFFFFLL) / static_cast<Float64>(0x0000000100000000LL);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::Get4CC(const CFStringRef inKey, UInt32& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFNumberGetTypeID()))
{
CFNumberGetValue(static_cast<CFNumberRef>(theValue), kCFNumberSInt32Type, &outValue);
theAnswer = true;
}
else if((theValue != NULL) && (CFGetTypeID(theValue) == CFStringGetTypeID()))
{
CFStringRef theString = static_cast<CFStringRef>(theValue);
if(CFStringGetLength(theString) == 4)
{
char theCString[5];
CFStringGetCString(theString, theCString, 5, kCFStringEncodingASCII);
outValue = CFSwapInt32BigToHost(*reinterpret_cast<UInt32*>(theCString));
}
}
}
return theAnswer;
}
bool CACFDictionary::GetString(const CFStringRef inKey, CFStringRef& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFStringGetTypeID()))
{
outValue = static_cast<CFStringRef>(theValue);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetArray(const CFStringRef inKey, CFArrayRef& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFArrayGetTypeID()))
{
outValue = static_cast<CFArrayRef>(theValue);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetDictionary(const CFStringRef inKey, CFDictionaryRef& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFDictionaryGetTypeID()))
{
outValue = static_cast<CFDictionaryRef>(theValue);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetData(const CFStringRef inKey, CFDataRef& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFDataGetTypeID()))
{
outValue = static_cast<CFDataRef>(theValue);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetCFType(const CFStringRef inKey, CFTypeRef& outValue) const
{
bool theAnswer = false;
if(mCFDictionary != NULL)
{
outValue = CFDictionaryGetValue(mCFDictionary, inKey);
theAnswer = (outValue != NULL);
}
return theAnswer;
}
bool CACFDictionary::GetURL(const CFStringRef inKey, CFURLRef& outValue) const
{
bool theAnswer = false;
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFURLGetTypeID()))
{
outValue = static_cast<CFURLRef>(theValue);
theAnswer = true;
}
}
return theAnswer;
}
bool CACFDictionary::GetCFTypeWithCStringKey(const char* inKey, CFTypeRef& outValue) const
{
bool theAnswer = false;
if(mCFDictionary != NULL)
{
CACFString theKey(inKey);
if(theKey.IsValid())
{
theAnswer = GetCFType(theKey.GetCFString(), outValue);
}
}
return theAnswer;
}
void CACFDictionary::GetCACFString(const CFStringRef inKey, CACFString& outValue) const
{
outValue = static_cast<CFStringRef>(NULL);
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFStringGetTypeID()))
{
outValue = static_cast<CFStringRef>(theValue);
}
}
}
void CACFDictionary::GetCACFArray(const CFStringRef inKey, CACFArray& outValue) const
{
outValue = static_cast<CFArrayRef>(NULL);
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFArrayGetTypeID()))
{
outValue = static_cast<CFArrayRef>(theValue);
}
}
}
void CACFDictionary::GetCACFDictionary(const CFStringRef inKey, CACFDictionary& outValue) const
{
outValue = static_cast<CFDictionaryRef>(NULL);
CFTypeRef theValue = NULL;
if(GetCFType(inKey, theValue))
{
if((theValue != NULL) && (CFGetTypeID(theValue) == CFDictionaryGetTypeID()))
{
outValue = static_cast<CFDictionaryRef>(theValue);
}
}
}
bool CACFDictionary::AddBool(const CFStringRef inKey, bool inValue)
{
CACFBoolean theValue(inValue);
return AddCFType(inKey, theValue.GetCFBoolean());
}
bool CACFDictionary::AddSInt32(const CFStringRef inKey, SInt32 inValue)
{
CACFNumber theValue(inValue);
return AddCFType(inKey, theValue.GetCFNumber());
}
bool CACFDictionary::AddUInt32(const CFStringRef inKey, UInt32 inValue)
{
CACFNumber theValue(inValue);
return AddCFType(inKey, theValue.GetCFNumber());
}
bool CACFDictionary::AddSInt64(const CFStringRef inKey, SInt64 inValue)
{
CACFNumber theValue(inValue);
return AddCFType(inKey, theValue.GetCFNumber());
}
bool CACFDictionary::AddUInt64(const CFStringRef inKey, UInt64 inValue)
{
CACFNumber theValue(inValue);
return AddCFType(inKey, theValue.GetCFNumber());
}
bool CACFDictionary::AddFloat32(const CFStringRef inKey, Float32 inValue)
{
CACFNumber theValue(inValue);
return AddCFType(inKey, theValue.GetCFNumber());
}
bool CACFDictionary::AddFloat64(const CFStringRef inKey, Float64 inValue)
{
CACFNumber theValue(inValue);
return AddCFType(inKey, theValue.GetCFNumber());
}
bool CACFDictionary::AddNumber(const CFStringRef inKey, const CFNumberRef inValue)
{
return AddCFType(inKey, inValue);
}
bool CACFDictionary::AddString(const CFStringRef inKey, const CFStringRef inValue)
{
return AddCFType(inKey, inValue);
}
bool CACFDictionary::AddArray(const CFStringRef inKey, const CFArrayRef inValue)
{
return AddCFType(inKey, inValue);
}
bool CACFDictionary::AddDictionary(const CFStringRef inKey, const CFDictionaryRef inValue)
{
return AddCFType(inKey, inValue);
}
bool CACFDictionary::AddData(const CFStringRef inKey, const CFDataRef inValue)
{
return AddCFType(inKey, inValue);
}
bool CACFDictionary::AddURL(const CFStringRef inKey, const CFURLRef inValue)
{
return AddCFType (inKey, inValue);
}
bool CACFDictionary::AddCFTypeWithCStringKey(const char* inKey, const CFTypeRef inValue)
{
bool theAnswer = false;
if (inKey)
{
CACFString theKey(inKey);
if(theKey.IsValid())
{
theAnswer = AddCFType(theKey.GetCFString(), inValue);
}
}
return theAnswer;
}
bool CACFDictionary::AddCString(const CFStringRef inKey, const char* inValue)
{
bool theAnswer = false;
if (inValue)
{
CACFString theValue(inValue);
if(theValue.IsValid())
{
theAnswer = AddCFType(inKey, theValue.GetCFString());
}
}
return theAnswer;
}
bool CACFDictionary::AddCFType(const CFStringRef inKey, const CFTypeRef inValue)
{
bool theAnswer = false;
if(mMutable && (mCFDictionary != NULL) && inValue)
{
CFDictionarySetValue(mCFDictionary, inKey, inValue);
theAnswer = true;
}
return theAnswer;
}

View File

@ -1,176 +0,0 @@
/*
File: CACFDictionary.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#if !defined(__CACFDictionary_h__)
#define __CACFDictionary_h__
//=============================================================================
// Includes
//=============================================================================
// System Includes
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreFoundation/CoreFoundation.h>
#else
#include <CoreFoundation.h>
#endif
//=============================================================================
// Types
//=============================================================================
class CACFArray;
class CACFString;
//=============================================================================
// CACFDictionary
//=============================================================================
class CACFDictionary
{
// Construction/Destruction
public:
CACFDictionary() : mCFDictionary(CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)), mRelease(true), mMutable(true) {}
explicit CACFDictionary(bool inRelease) : mCFDictionary(CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)), mRelease(inRelease), mMutable(true) {}
CACFDictionary(CFDictionaryRef inCFDictionary, bool inRelease) : mCFDictionary(const_cast<CFMutableDictionaryRef>(inCFDictionary)), mRelease(inRelease), mMutable(false) {}
CACFDictionary(CFMutableDictionaryRef inCFDictionary, bool inRelease) : mCFDictionary(inCFDictionary), mRelease(inRelease), mMutable(true) {}
CACFDictionary(const CACFDictionary& inDictionary) : mCFDictionary(inDictionary.mCFDictionary), mRelease(inDictionary.mRelease), mMutable(inDictionary.mMutable) { Retain(); }
CACFDictionary& operator=(const CACFDictionary& inDictionary) { Release(); mCFDictionary = inDictionary.mCFDictionary; mRelease = inDictionary.mRelease; mMutable = inDictionary.mMutable; Retain(); return *this; }
CACFDictionary& operator=(CFDictionaryRef inDictionary) { Release(); mCFDictionary = const_cast<CFMutableDictionaryRef>(inDictionary); mMutable = false; Retain(); return *this; }
CACFDictionary& operator=(CFMutableDictionaryRef inDictionary) { Release(); mCFDictionary = inDictionary; mMutable = true; Retain(); return *this; }
~CACFDictionary() { Release(); }
private:
void Retain() { if(mRelease && (mCFDictionary != NULL)) { CFRetain(mCFDictionary); } }
void Release() { if(mRelease && (mCFDictionary != NULL)) { CFRelease(mCFDictionary); } }
// Attributes
public:
bool IsValid() const { return mCFDictionary != NULL; }
bool IsMutable() const { return mMutable;}
bool CanModify() const { return mMutable && (mCFDictionary != NULL); }
bool WillRelease() const { return mRelease; }
void ShouldRelease(bool inRelease) { mRelease = inRelease; }
CFDictionaryRef GetDict() const { return mCFDictionary; }
CFDictionaryRef GetCFDictionary() const { return mCFDictionary; }
CFDictionaryRef CopyCFDictionary() const { if(mCFDictionary != NULL) { CFRetain(mCFDictionary); } return mCFDictionary; }
CFMutableDictionaryRef GetMutableDict() { return mCFDictionary; }
CFMutableDictionaryRef GetCFMutableDictionary() const { return mCFDictionary; }
CFMutableDictionaryRef CopyCFMutableDictionary() const { if(mCFDictionary != NULL) { CFRetain(mCFDictionary); } return mCFDictionary; }
void SetCFMutableDictionaryFromCopy(CFDictionaryRef inDictionary, bool inRelease = true) { Release(); mCFDictionary = CFDictionaryCreateMutableCopy(NULL, 0, inDictionary); mMutable = true; mRelease = inRelease; }
void SetCFMutableDictionaryToEmpty(bool inRelease = true) { Release(); mCFDictionary = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); mMutable = true; mRelease = inRelease; }
CFPropertyListRef AsPropertyList() const { return mCFDictionary; }
OSStatus GetDictIfMutable(CFMutableDictionaryRef& outDict) const { OSStatus theAnswer = -1; if(mMutable) { outDict = mCFDictionary; theAnswer = 0; } return theAnswer; }
// Item Operations
public:
bool HasKey(const CFStringRef inKey) const;
UInt32 Size() const;
void GetKeys(const void** keys) const;
void GetKeysAndValues (const void **keys, const void **values) const;
bool GetBool(const CFStringRef inKey, bool& outValue) const;
bool GetSInt32(const CFStringRef inKey, SInt32& outValue) const;
bool GetUInt32(const CFStringRef inKey, UInt32& outValue) const;
bool GetUInt32FromString(const CFStringRef inKey, UInt32& outValue) const;
bool GetSInt64(const CFStringRef inKey, SInt64& outValue) const;
bool GetUInt64(const CFStringRef inKey, UInt64& outValue) const;
bool GetFloat32(const CFStringRef inKey, Float32& outValue) const;
bool GetFloat32FromString(const CFStringRef inKey, Float32& outValue) const;
bool GetFloat64(const CFStringRef inKey, Float64& outValue) const;
bool GetFixed32(const CFStringRef inKey, Float32& outValue) const;
bool GetFixed64(const CFStringRef inKey, Float64& outValue) const;
bool Get4CC(const CFStringRef inKey, UInt32& outValue) const;
bool GetString(const CFStringRef inKey, CFStringRef& outValue) const;
bool GetArray(const CFStringRef inKey, CFArrayRef& outValue) const;
bool GetDictionary(const CFStringRef inKey, CFDictionaryRef& outValue) const;
bool GetData(const CFStringRef inKey, CFDataRef& outValue) const;
bool GetCFType(const CFStringRef inKey, CFTypeRef& outValue) const;
bool GetURL(const CFStringRef inKey, CFURLRef& outValue) const;
bool GetCFTypeWithCStringKey(const char* inKey, CFTypeRef& outValue) const;
void GetCACFString(const CFStringRef inKey, CACFString& outItem) const;
void GetCACFArray(const CFStringRef inKey, CACFArray& outItem) const;
void GetCACFDictionary(const CFStringRef inKey, CACFDictionary& outItem) const;
bool AddBool(const CFStringRef inKey, bool inValue);
bool AddSInt32(const CFStringRef inKey, SInt32 inValue);
bool AddUInt32(const CFStringRef inKey, UInt32 inValue);
bool AddSInt64(const CFStringRef inKey, SInt64 inValue);
bool AddUInt64(const CFStringRef inKey, UInt64 inValue);
bool AddFloat32(const CFStringRef inKey, Float32 inValue);
bool AddFloat64(const CFStringRef inKey, Float64 inValue);
bool AddNumber(const CFStringRef inKey, const CFNumberRef inValue);
bool AddString(const CFStringRef inKey, const CFStringRef inValue);
bool AddArray(const CFStringRef inKey, const CFArrayRef inValue);
bool AddDictionary(const CFStringRef inKey, const CFDictionaryRef inValue);
bool AddData(const CFStringRef inKey, const CFDataRef inValue);
bool AddCFType(const CFStringRef inKey, const CFTypeRef inValue);
bool AddURL(const CFStringRef inKey, const CFURLRef inValue);
bool AddCFTypeWithCStringKey(const char* inKey, const CFTypeRef inValue);
bool AddCString(const CFStringRef inKey, const char* inValue);
void RemoveKey(const CFStringRef inKey) { if(CanModify()) { CFDictionaryRemoveValue(mCFDictionary, inKey); } }
void Clear() { if(CanModify()) { CFDictionaryRemoveAllValues(mCFDictionary); } }
void Show() { CFShow(mCFDictionary); }
// Implementation
private:
CFMutableDictionaryRef mCFDictionary;
bool mRelease;
bool mMutable;
CACFDictionary(const void*); // prevent accidental instantiation with a pointer via bool constructor
};
#endif //__CACFDictionary_h__

View File

@ -1,83 +0,0 @@
/*
File: CACFNumber.cpp
Abstract: CACFNumber.h
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
//=============================================================================
// Includes
//=============================================================================
#include "CACFNumber.h"
//=============================================================================
// CACFNumber
//=============================================================================
Float32 CACFNumber::GetFixed32() const
{
SInt32 theFixedValue = GetSInt32();
// this is a 16.16 value so convert it to a float
Float32 theSign = theFixedValue < 0 ? -1.0f : 1.0f;
theFixedValue *= (SInt32)theSign;
Float32 theWholePart = (theFixedValue & 0x7FFF0000) >> 16;
Float32 theFractPart = theFixedValue & 0x0000FFFF;
theFractPart /= 65536.0f;
return theSign * (theWholePart + theFractPart);
}
Float64 CACFNumber::GetFixed64() const
{
SInt64 theFixedValue = GetSInt64();
// this is a 32.32 value so convert it to a double
Float64 theSign = theFixedValue < 0 ? -1.0 : 1.0;
theFixedValue *= (SInt64)theSign;
Float64 theWholePart = (theFixedValue & 0x7FFFFFFF00000000LL) >> 32;
Float64 theFractPart = theFixedValue & 0x00000000FFFFFFFFLL;
theFractPart /= 4294967296.0;
return theSign * (theWholePart + theFractPart);
}

View File

@ -1,151 +0,0 @@
/*
File: CACFNumber.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#if !defined(__CACFNumber_h__)
#define __CACFNumber_h__
//=============================================================================
// Includes
//=============================================================================
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreAudio/CoreAudioTypes.h>
#include <CoreFoundation/CFNumber.h>
#else
#include <CoreAudioTypes.h>
#include <CFNumber.h>
#endif
//=============================================================================
// CACFBoolean
//=============================================================================
class CACFBoolean
{
// Construction/Destruction
public:
explicit CACFBoolean(CFBooleanRef inCFBoolean) : mCFBoolean(inCFBoolean), mWillRelease(true) {}
CACFBoolean(CFBooleanRef inCFBoolean, bool inWillRelease) : mCFBoolean(inCFBoolean), mWillRelease(inWillRelease) {}
explicit CACFBoolean(bool inValue) : mCFBoolean(inValue ? kCFBooleanTrue : kCFBooleanFalse), mWillRelease(true) { Retain(); }
~CACFBoolean() { Release(); }
CACFBoolean(const CACFBoolean& inBoolean) : mCFBoolean(inBoolean.mCFBoolean), mWillRelease(inBoolean.mWillRelease) { Retain(); }
CACFBoolean& operator=(const CACFBoolean& inBoolean) { Release(); mCFBoolean = inBoolean.mCFBoolean; mWillRelease = inBoolean.mWillRelease; Retain(); return *this; }
CACFBoolean& operator=(CFBooleanRef inCFBoolean) { Release(); mCFBoolean = inCFBoolean; mWillRelease = true; return *this; }
private:
void Retain() { if(mWillRelease && (mCFBoolean != NULL)) { CFRetain(mCFBoolean); } }
void Release() { if(mWillRelease && (mCFBoolean != NULL)) { CFRelease(mCFBoolean); } }
CFBooleanRef mCFBoolean;
bool mWillRelease;
// Operations
public:
void AllowRelease() { mWillRelease = true; }
void DontAllowRelease() { mWillRelease = false; }
bool IsValid() { return mCFBoolean != NULL; }
// Value Access
public:
CFBooleanRef GetCFBoolean() const { return mCFBoolean; }
CFBooleanRef CopyCFBoolean() const { if(mCFBoolean != NULL) { CFRetain(mCFBoolean); } return mCFBoolean; }
bool GetBoolean() const { bool theAnswer = false; if(mCFBoolean != NULL) { theAnswer = CFEqual(mCFBoolean, kCFBooleanTrue); } return theAnswer; }
CACFBoolean(const void*); // prevent accidental instantiation with a pointer via bool constructor
};
//=============================================================================
// CACFNumber
//=============================================================================
class CACFNumber
{
// Construction/Destruction
public:
explicit CACFNumber(CFNumberRef inCFNumber) : mCFNumber(inCFNumber), mWillRelease(true) {}
CACFNumber(CFNumberRef inCFNumber, bool inWillRelease) : mCFNumber(inCFNumber), mWillRelease(inWillRelease) {}
CACFNumber(SInt32 inValue) : mCFNumber(CFNumberCreate(NULL, kCFNumberSInt32Type, &inValue)), mWillRelease(true) {}
CACFNumber(UInt32 inValue) : mCFNumber(CFNumberCreate(NULL, kCFNumberSInt32Type, &inValue)), mWillRelease(true) {}
CACFNumber(SInt64 inValue) : mCFNumber(CFNumberCreate(NULL, kCFNumberSInt64Type, &inValue)), mWillRelease(true) {}
CACFNumber(UInt64 inValue) : mCFNumber(CFNumberCreate(NULL, kCFNumberSInt64Type, &inValue)), mWillRelease(true) {}
CACFNumber(Float32 inValue) : mCFNumber(CFNumberCreate(NULL, kCFNumberFloat32Type, &inValue)), mWillRelease(true) {}
CACFNumber(Float64 inValue) : mCFNumber(CFNumberCreate(NULL, kCFNumberFloat64Type, &inValue)), mWillRelease(true) {}
~CACFNumber() { Release(); }
CACFNumber(const CACFNumber& inNumber) : mCFNumber(inNumber.mCFNumber), mWillRelease(inNumber.mWillRelease) { Retain(); }
CACFNumber& operator=(const CACFNumber& inNumber) { Release(); mCFNumber = inNumber.mCFNumber; mWillRelease = inNumber.mWillRelease; Retain(); return *this; }
CACFNumber& operator=(CFNumberRef inCFNumber) { Release(); mCFNumber = inCFNumber; mWillRelease = true; return *this; }
private:
void Retain() { if(mWillRelease && (mCFNumber != NULL)) { CFRetain(mCFNumber); } }
void Release() { if(mWillRelease && (mCFNumber != NULL)) { CFRelease(mCFNumber); } }
CFNumberRef mCFNumber;
bool mWillRelease;
// Operations
public:
void AllowRelease() { mWillRelease = true; }
void DontAllowRelease() { mWillRelease = false; }
bool IsValid() const { return mCFNumber != NULL; }
// Value Access
public:
CFNumberRef GetCFNumber() const { return mCFNumber; }
CFNumberRef CopyCFNumber() const { if(mCFNumber != NULL) { CFRetain(mCFNumber); } return mCFNumber; }
SInt8 GetSInt8() const { SInt8 theAnswer = 0; if(mCFNumber != NULL) { CFNumberGetValue(mCFNumber, kCFNumberSInt8Type, &theAnswer); } return theAnswer; }
SInt32 GetSInt32() const { SInt32 theAnswer = 0; if(mCFNumber != NULL) { CFNumberGetValue(mCFNumber, kCFNumberSInt32Type, &theAnswer); } return theAnswer; }
UInt32 GetUInt32() const { UInt32 theAnswer = 0; if(mCFNumber != NULL) { CFNumberGetValue(mCFNumber, kCFNumberSInt32Type, &theAnswer); } return theAnswer; }
Float32 GetFloat32() const { Float32 theAnswer = 0.0f; if(mCFNumber != NULL) { CFNumberGetValue(mCFNumber, kCFNumberFloat32Type, &theAnswer); } return theAnswer; }
Float32 GetFixed32() const;
Float64 GetFixed64() const;
SInt64 GetSInt64() const { SInt64 theAnswer = 0; if(mCFNumber != NULL) { CFNumberGetValue(mCFNumber, kCFNumberSInt64Type, &theAnswer); } return theAnswer; }
CACFNumber(const void*); // prevent accidental instantiation with a pointer via bool constructor
};
#endif

View File

@ -1,110 +0,0 @@
/*
File: CACFString.cpp
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
//=============================================================================
// Includes
//=============================================================================
#include "CACFString.h"
//=============================================================================
// CACFString
//=============================================================================
UInt32 CACFString::GetStringByteLength(CFStringRef inCFString, CFStringEncoding inEncoding)
{
CFIndex theAnswer = 0;
if(inCFString != NULL)
{
CFRange theRange = { 0, CFStringGetLength(inCFString) };
CFStringGetBytes(inCFString, theRange, inEncoding, 0, false, NULL, 0x7FFFFFFF, &theAnswer);
}
return UInt32(theAnswer);
}
void CACFString::GetCString(CFStringRef inCFString, char* outString, UInt32& ioStringSize, CFStringEncoding inEncoding)
{
if(ioStringSize > 0)
{
if(inCFString != NULL)
{
CFIndex theLength = 0;
CFRange theRange = { 0, CFStringGetLength(inCFString) };
CFStringGetBytes(inCFString, theRange, inEncoding, 0, false, (UInt8*)outString, static_cast<CFIndex>(ioStringSize - 1), &theLength);
outString[theLength] = 0;
ioStringSize = ToUInt32(theLength) + 1;
}
else
{
outString[0] = 0;
ioStringSize = 1;
}
}
}
void CACFString::GetUnicodeString(CFStringRef inCFString, UInt16* outString, UInt32& ioStringSize)
{
if(ioStringSize > 0)
{
if(inCFString != NULL)
{
CFRange theStringRange = { 0, CFStringGetLength(inCFString) };
if(static_cast<UInt32>(theStringRange.length) > ioStringSize)
{
theStringRange.length = static_cast<CFIndex>(ioStringSize);
}
CFStringGetCharacters(inCFString, theStringRange, outString);
ioStringSize = ToUInt32(theStringRange.length);
}
else
{
outString[0] = 0;
ioStringSize = 0;
}
}
}

View File

@ -1,180 +0,0 @@
/*
File: CACFString.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
#if !defined(__CACFString_h__)
#define __CACFString_h__
//=============================================================================
// Includes
//=============================================================================
#include "CADebugMacros.h"
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreAudio/CoreAudioTypes.h>
#include <CoreFoundation/CFString.h>
#else
#include <CoreAudioTypes.h>
#include <CFString.h>
#endif
//=============================================================================
// CACFString
//
// Notes
// - Using the AssignWithoutRetain() method will fool the static analyzer into thinking that the
// CFString being assigned will be leaked. This is because the static analyzer is not smart
// enough to understand that the destructor will release the object.
//=============================================================================
class CACFString
{
// Construction/Destruction
public:
CACFString() : mCFString(NULL), mWillRelease(true) {}
CACFString(CFStringRef inCFString, bool inWillRelease = true) : mCFString(inCFString), mWillRelease(inWillRelease) {}
CACFString(const char* inCString, bool inWillRelease = true) : mCFString(CFStringCreateWithCString(NULL, inCString, kCFStringEncodingASCII)), mWillRelease(inWillRelease) {}
CACFString(const char* inCString, CFStringEncoding inCStringEncoding, bool inWillRelease = true) : mCFString(CFStringCreateWithCString(NULL, inCString, inCStringEncoding)), mWillRelease(inWillRelease) {}
~CACFString() { Release(); }
CACFString(const CACFString& inString) : mCFString(inString.mCFString), mWillRelease(inString.mWillRelease) { Retain(); }
CACFString& operator=(const CACFString& inString) { if (inString.mCFString != mCFString) { Release(); mCFString = inString.mCFString; mWillRelease = inString.mWillRelease; Retain(); } return *this; }
CACFString& operator=(CFStringRef inCFString) { if (inCFString != mCFString) { Release(); mCFString = inCFString; } mWillRelease = true; Retain(); return *this; }
void AssignWithoutRetain(CFStringRef inCFString) { if (inCFString != mCFString) { Release(); mCFString = inCFString; } mWillRelease = true; }
private:
void Retain() { if(mWillRelease && (mCFString != NULL)) { CFRetain(mCFString); } }
void Release() { if(mWillRelease && (mCFString != NULL)) { CFRelease(mCFString); } }
CFStringRef mCFString;
bool mWillRelease;
// Operations
public:
void AllowRelease() { mWillRelease = true; }
void DontAllowRelease() { mWillRelease = false; }
bool IsValid() const { return mCFString != NULL; }
bool IsEqualTo(CFStringRef inString) const { bool theAnswer = false; if(mCFString != NULL) { theAnswer = CFStringCompare(inString, mCFString, 0) == kCFCompareEqualTo; } return theAnswer; }
bool StartsWith(CFStringRef inString) const { bool theAnswer = false; if(mCFString != NULL) { theAnswer = CFStringHasPrefix(mCFString, inString); } return theAnswer; }
bool EndsWith(CFStringRef inString) const { bool theAnswer = false; if(mCFString != NULL) { theAnswer = CFStringHasSuffix(mCFString, inString); } return theAnswer; }
// Value Access
public:
CFStringRef GetCFString() const { return mCFString; }
CFStringRef CopyCFString() const { if(mCFString != NULL) { CFRetain(mCFString); } return mCFString; }
const CFStringRef* GetPointerToStorage() const { return &mCFString; }
CFStringRef& GetStorage() { Release(); mWillRelease = true; return mCFString; }
UInt32 GetLength() const { UInt32 theAnswer = 0; if(mCFString != NULL) { theAnswer = ToUInt32(CFStringGetLength(mCFString)); } return theAnswer; }
UInt32 GetByteLength(CFStringEncoding inEncoding = kCFStringEncodingUTF8) const { UInt32 theAnswer = 0; if(mCFString != NULL) { theAnswer = GetStringByteLength(mCFString, inEncoding); } return theAnswer; }
void GetCString(char* outString, UInt32& ioStringSize, CFStringEncoding inEncoding = kCFStringEncodingUTF8) const { GetCString(mCFString, outString, ioStringSize, inEncoding); }
void GetUnicodeString(UInt16* outString, UInt32& ioStringSize) const { GetUnicodeString(mCFString, outString, ioStringSize); }
SInt32 GetAsInteger() { return GetAsInteger(mCFString); }
Float64 GetAsFloat64() { return GetAsFloat64(mCFString); }
static UInt32 GetStringLength(CFStringRef inCFString) { UInt32 theAnswer = 0; if(inCFString != NULL) { theAnswer = ToUInt32(CFStringGetLength(inCFString)); } return theAnswer; }
static UInt32 GetStringByteLength(CFStringRef inCFString, CFStringEncoding inEncoding = kCFStringEncodingUTF8);
static void GetCString(CFStringRef inCFString, char* outString, UInt32& ioStringSize, CFStringEncoding inEncoding = kCFStringEncodingUTF8);
static void GetUnicodeString(CFStringRef inCFString, UInt16* outString, UInt32& ioStringSize);
static SInt32 GetAsInteger(CFStringRef inCFString) { SInt32 theAnswer = 0; if(inCFString != NULL){ theAnswer = CFStringGetIntValue(inCFString); } return theAnswer; }
static Float64 GetAsFloat64(CFStringRef inCFString) { Float64 theAnswer = 0; if(inCFString != NULL){ theAnswer = CFStringGetDoubleValue(inCFString); } return theAnswer; }
};
inline bool operator<(const CACFString& x, const CACFString& y) { return CFStringCompare(x.GetCFString(), y.GetCFString(), 0) == kCFCompareLessThan; }
inline bool operator==(const CACFString& x, const CACFString& y) { return CFStringCompare(x.GetCFString(), y.GetCFString(), 0) == kCFCompareEqualTo; }
inline bool operator!=(const CACFString& x, const CACFString& y) { return !(x == y); }
inline bool operator<=(const CACFString& x, const CACFString& y) { return (x < y) || (x == y); }
inline bool operator>=(const CACFString& x, const CACFString& y) { return !(x < y); }
inline bool operator>(const CACFString& x, const CACFString& y) { return !((x < y) || (x == y)); }
//=============================================================================
// CACFMutableString
//=============================================================================
class CACFMutableString
{
// Construction/Destruction
public:
CACFMutableString() : mCFMutableString(NULL), mWillRelease(true) {}
CACFMutableString(CFMutableStringRef inCFMutableString, bool inWillRelease = true) : mCFMutableString(inCFMutableString), mWillRelease(inWillRelease) {}
CACFMutableString(CFStringRef inStringToCopy, bool /*inMakeCopy*/, bool inWillRelease = true) : mCFMutableString(CFStringCreateMutableCopy(NULL, 0, inStringToCopy)), mWillRelease(inWillRelease) {}
CACFMutableString(const char* inCString, bool inWillRelease = true) : mCFMutableString(NULL), mWillRelease(inWillRelease) { CACFString theString(inCString); mCFMutableString = CFStringCreateMutableCopy(NULL, 0, theString.GetCFString()); }
CACFMutableString(const char* inCString, CFStringEncoding inCStringEncoding, bool inWillRelease = true) : mCFMutableString(NULL), mWillRelease(inWillRelease) { CACFString theString(inCString, inCStringEncoding); mCFMutableString = CFStringCreateMutableCopy(NULL, 0, theString.GetCFString()); }
~CACFMutableString() { Release(); }
CACFMutableString(const CACFMutableString& inString) : mCFMutableString(inString.mCFMutableString), mWillRelease(inString.mWillRelease) { Retain(); }
CACFMutableString& operator=(const CACFMutableString& inString) { Release(); mCFMutableString = inString.mCFMutableString; mWillRelease = inString.mWillRelease; Retain(); return *this; }
CACFMutableString& operator=(CFMutableStringRef inCFMutableString) { Release(); mCFMutableString = inCFMutableString; mWillRelease = true; return *this; }
private:
void Retain() { if(mWillRelease && (mCFMutableString != NULL)) { CFRetain(mCFMutableString); } }
void Release() { if(mWillRelease && (mCFMutableString != NULL)) { CFRelease(mCFMutableString); } }
CFMutableStringRef mCFMutableString;
bool mWillRelease;
// Operations
public:
void AllowRelease() { mWillRelease = true; }
void DontAllowRelease() { mWillRelease = false; }
bool IsValid() { return mCFMutableString != NULL; }
bool IsEqualTo(CFStringRef inString) const { bool theAnswer = false; if(mCFMutableString != NULL) { theAnswer = CFStringCompare(inString, mCFMutableString, 0) == kCFCompareEqualTo; } return theAnswer; }
bool StartsWith(CFStringRef inString) const { bool theAnswer = false; if(mCFMutableString != NULL) { theAnswer = CFStringHasPrefix(mCFMutableString, inString); } return theAnswer; }
bool EndsWith(CFStringRef inString) const { bool theAnswer = false; if(mCFMutableString != NULL) { theAnswer = CFStringHasSuffix(mCFMutableString, inString); } return theAnswer; }
void Append(CFStringRef inString) { if(mCFMutableString != NULL) { CFStringAppend(mCFMutableString, inString); } }
// Value Access
public:
CFMutableStringRef GetCFMutableString() const { return mCFMutableString; }
CFMutableStringRef CopyCFMutableString() const { if(mCFMutableString != NULL) { CFRetain(mCFMutableString); } return mCFMutableString; }
UInt32 GetLength() const { UInt32 theAnswer = 0; if(mCFMutableString != NULL) { theAnswer = ToUInt32(CFStringGetLength(mCFMutableString)); } return theAnswer; }
UInt32 GetByteLength(CFStringEncoding inEncoding = kCFStringEncodingUTF8) const { UInt32 theAnswer = 0; if(mCFMutableString != NULL) { theAnswer = CACFString::GetStringByteLength(mCFMutableString, inEncoding); } return theAnswer; }
void GetCString(char* outString, UInt32& ioStringSize, CFStringEncoding inEncoding = kCFStringEncodingUTF8) const { CACFString::GetCString(mCFMutableString, outString, ioStringSize, inEncoding); }
void GetUnicodeString(UInt16* outString, UInt32& ioStringSize) const { CACFString::GetUnicodeString(mCFMutableString, outString, ioStringSize); }
SInt32 GetAsInteger() { return CACFString::GetAsInteger(mCFMutableString); }
Float64 GetAsFloat64() { return CACFString::GetAsFloat64(mCFMutableString); }
};
#endif

View File

@ -1,116 +0,0 @@
/*
File: CADebugMacros.cpp
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
#include "CADebugMacros.h"
#include <stdio.h>
#include <stdarg.h>
#if TARGET_API_MAC_OSX
#include <syslog.h>
#endif
#if DEBUG
#include <stdio.h>
void DebugPrint(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
}
#endif // DEBUG
void LogError(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
// EQM edit: vprintf leaves args in an undefined state, which can cause a crash in
// vsyslog. Also added __ASSERT_STOP. Original code commented out below.
//#if DEBUG
// vprintf(fmt, args);
//#endif
//#if TARGET_API_MAC_OSX
// vsyslog(LOG_ERR, fmt, args);
//#endif
#if (DEBUG || !TARGET_API_MAC_OSX) && !CoreAudio_UseSysLog
printf("[ERROR] ");
vprintf(fmt, args);
printf("\n");
#else
vsyslog(LOG_ERR, fmt, args);
#endif
#if DEBUG
__ASSERT_STOP;
#endif
// EQM edit end
va_end(args);
}
void LogWarning(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
// EQM edit: vprintf leaves args in an undefined state, which can cause a crash in
// vsyslog. Also added __ASSERT_STOP. Original code commented out below.
//#if DEBUG
// vprintf(fmt, args);
//#endif
//#if TARGET_API_MAC_OSX
// vsyslog(LOG_WARNING, fmt, args);
//#endif
#if (DEBUG || !TARGET_API_MAC_OSX) && !CoreAudio_UseSysLog
printf("[WARNING] ");
vprintf(fmt, args);
printf("\n");
#else
vsyslog(LOG_WARNING, fmt, args);
#endif
#if DEBUG
//__ASSERT_STOP; // TODO: Add a toggle for this to the project file (under "Preprocessor Macros"). Default to off.
#endif
// EQM edit end
va_end(args);
}

View File

@ -1,583 +0,0 @@
/*
File: CADebugMacros.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
#if !defined(__CADebugMacros_h__)
#define __CADebugMacros_h__
//=============================================================================
// Includes
//=============================================================================
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreAudio/CoreAudioTypes.h>
#else
#include "CoreAudioTypes.h"
#endif
//=============================================================================
// CADebugMacros
//=============================================================================
//#define CoreAudio_StopOnFailure 1
//#define CoreAudio_TimeStampMessages 1
//#define CoreAudio_ThreadStampMessages 1
//#define CoreAudio_FlushDebugMessages 1
#if TARGET_RT_BIG_ENDIAN
#define CA4CCToCString(the4CC) { ((char*)&the4CC)[0], ((char*)&the4CC)[1], ((char*)&the4CC)[2], ((char*)&the4CC)[3], 0 }
#define CACopy4CCToCString(theCString, the4CC) { theCString[0] = ((char*)&the4CC)[0]; theCString[1] = ((char*)&the4CC)[1]; theCString[2] = ((char*)&the4CC)[2]; theCString[3] = ((char*)&the4CC)[3]; theCString[4] = 0; }
#else
#define CA4CCToCString(the4CC) { ((char*)&the4CC)[3], ((char*)&the4CC)[2], ((char*)&the4CC)[1], ((char*)&the4CC)[0], 0 }
#define CACopy4CCToCString(theCString, the4CC) { theCString[0] = ((char*)&the4CC)[3]; theCString[1] = ((char*)&the4CC)[2]; theCString[2] = ((char*)&the4CC)[1]; theCString[3] = ((char*)&the4CC)[0]; theCString[4] = 0; }
#endif
// This is a macro that does a sizeof and casts the result to a UInt32. This is useful for all the
// places where -wshorten64-32 catches assigning a sizeof expression to a UInt32.
// For want of a better place to park this, we'll park it here.
#define SizeOf32(X) ((UInt32)sizeof(X))
// This is a macro that does a offsetof and casts the result to a UInt32. This is useful for all the
// places where -wshorten64-32 catches assigning an offsetof expression to a UInt32.
// For want of a better place to park this, we'll park it here.
#define OffsetOf32(X, Y) ((UInt32)offsetof(X, Y))
// This macro casts the expression to a UInt32. It is called out specially to allow us to track casts
// that have been added purely to avert -wshorten64-32 warnings on 64 bit platforms.
// For want of a better place to park this, we'll park it here.
#define ToUInt32(X) ((UInt32)(X))
#define ToSInt32(X) ((SInt32)(X))
#pragma mark Basic Definitions
#if DEBUG || CoreAudio_Debug
// can be used to break into debugger immediately, also see CADebugger
#define BusError() { long* p=NULL; *p=0; }
// basic debugging print routines
#if TARGET_OS_MAC && !TARGET_API_MAC_CARBON
extern void DebugStr(const unsigned char* debuggerMsg);
#define DebugMessage(msg) DebugStr("\p"msg)
#define DebugMessageN1(msg, N1)
#define DebugMessageN2(msg, N1, N2)
#define DebugMessageN3(msg, N1, N2, N3)
#else
#include "CADebugPrintf.h"
#if (CoreAudio_FlushDebugMessages && !CoreAudio_UseSysLog) || defined(CoreAudio_UseSideFile)
#define FlushRtn ,fflush(DebugPrintfFile)
#else
#define FlushRtn
#endif
#if CoreAudio_ThreadStampMessages
#include <pthread.h>
#include "CAHostTimeBase.h"
#if TARGET_RT_64_BIT
#define DebugPrintfThreadIDFormat "%16p"
#else
#define DebugPrintfThreadIDFormat "%8p"
#endif
#define DebugMsg(inFormat, ...) DebugPrintf("%17qd: " DebugPrintfThreadIDFormat " " inFormat, CAHostTimeBase::GetCurrentTimeInNanos(), pthread_self(), ## __VA_ARGS__) FlushRtn
#elif CoreAudio_TimeStampMessages
#include "CAHostTimeBase.h"
#define DebugMsg(inFormat, ...) DebugPrintf("%17qd: " inFormat, CAHostTimeBase::GetCurrentTimeInNanos(), ## __VA_ARGS__) FlushRtn
#else
#define DebugMsg(inFormat, ...) DebugPrintf(inFormat, ## __VA_ARGS__) FlushRtn
#endif
#endif
void DebugPrint(const char *fmt, ...); // can be used like printf
#ifndef DEBUGPRINT
#define DEBUGPRINT(msg) DebugPrint msg // have to double-parenthesize arglist (see Debugging.h)
#endif
#if VERBOSE
#define vprint(msg) DEBUGPRINT(msg)
#else
#define vprint(msg)
#endif
// Original macro keeps its function of turning on and off use of CADebuggerStop() for both asserts and throws.
// For backwards compat, it overrides any setting of the two sub-macros.
#if CoreAudio_StopOnFailure
#include "CADebugger.h"
#undef CoreAudio_StopOnAssert
#define CoreAudio_StopOnAssert 1
#undef CoreAudio_StopOnThrow
#define CoreAudio_StopOnThrow 1
#define STOP CADebuggerStop()
#else
#define STOP
#endif
#if CoreAudio_StopOnAssert
#if !CoreAudio_StopOnFailure
#include "CADebugger.h"
#define STOP
#endif
#define __ASSERT_STOP CADebuggerStop()
#else
#define __ASSERT_STOP
#endif
#if CoreAudio_StopOnThrow
#if !CoreAudio_StopOnFailure
#include "CADebugger.h"
#define STOP
#endif
#define __THROW_STOP CADebuggerStop()
#else
#define __THROW_STOP
#endif
#else
#define DebugMsg(inFormat, ...)
#ifndef DEBUGPRINT
#define DEBUGPRINT(msg)
#endif
#define vprint(msg)
#define STOP
#define __ASSERT_STOP
#define __THROW_STOP
#endif
// Old-style numbered DebugMessage calls are implemented in terms of DebugMsg() now
#define DebugMessage(msg) DebugMsg(msg)
#define DebugMessageN1(msg, N1) DebugMsg(msg, N1)
#define DebugMessageN2(msg, N1, N2) DebugMsg(msg, N1, N2)
#define DebugMessageN3(msg, N1, N2, N3) DebugMsg(msg, N1, N2, N3)
#define DebugMessageN4(msg, N1, N2, N3, N4) DebugMsg(msg, N1, N2, N3, N4)
#define DebugMessageN5(msg, N1, N2, N3, N4, N5) DebugMsg(msg, N1, N2, N3, N4, N5)
#define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6) DebugMsg(msg, N1, N2, N3, N4, N5, N6)
#define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7) DebugMsg(msg, N1, N2, N3, N4, N5, N6, N7)
#define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8) DebugMsg(msg, N1, N2, N3, N4, N5, N6, N7, N8)
#define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9) DebugMsg(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9)
// EQM edit: Added __printflike.
void LogError(const char *fmt, ...) __printflike(1, 2); // writes to syslog (and stderr if debugging)
void LogWarning(const char *fmt, ...) __printflike(1, 2); // writes to syslog (and stderr if debugging)
#define NO_ACTION (void)0
#if DEBUG || CoreAudio_Debug
#pragma mark Debug Macros
#define Assert(inCondition, inMessage) \
if(!(inCondition)) \
{ \
DebugMessage(inMessage); \
__ASSERT_STOP; \
}
#define AssertFileLine(inCondition, inMessage) \
if(!(inCondition)) \
{ \
DebugMessageN3("%s, line %d: %s", __FILE__, __LINE__, inMessage); \
__ASSERT_STOP; \
}
#define AssertNoError(inError, inMessage) \
{ \
SInt32 __Err = (inError); \
if(__Err != 0) \
{ \
char __4CC[5] = CA4CCToCString(__Err); \
DebugMessageN2(inMessage ", Error: %d (%s)", (int)__Err, __4CC); \
__ASSERT_STOP; \
} \
}
#define AssertNoKernelError(inError, inMessage) \
{ \
unsigned int __Err = (unsigned int)(inError); \
if(__Err != 0) \
{ \
DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
__ASSERT_STOP; \
} \
}
#define AssertNotNULL(inPtr, inMessage) \
{ \
if((inPtr) == NULL) \
{ \
DebugMessage(inMessage); \
__ASSERT_STOP; \
} \
}
#define FailIf(inCondition, inHandler, inMessage) \
if(inCondition) \
{ \
DebugMessage(inMessage); \
STOP; \
goto inHandler; \
}
#define FailWithAction(inCondition, inAction, inHandler, inMessage) \
if(inCondition) \
{ \
DebugMessage(inMessage); \
STOP; \
{ inAction; } \
goto inHandler; \
}
#define FailIfNULL(inPointer, inAction, inHandler, inMessage) \
if((inPointer) == NULL) \
{ \
DebugMessage(inMessage); \
STOP; \
{ inAction; } \
goto inHandler; \
}
#define FailIfKernelError(inKernelError, inAction, inHandler, inMessage) \
{ \
unsigned int __Err = (inKernelError); \
if(__Err != 0) \
{ \
DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
STOP; \
{ inAction; } \
goto inHandler; \
} \
}
#define FailIfError(inError, inAction, inHandler, inMessage) \
{ \
SInt32 __Err = (inError); \
if(__Err != 0) \
{ \
char __4CC[5] = CA4CCToCString(__Err); \
DebugMessageN2(inMessage ", Error: %ld (%s)", (long int)__Err, __4CC); \
STOP; \
{ inAction; } \
goto inHandler; \
} \
}
#define FailIfNoMessage(inCondition, inHandler, inMessage) \
if(inCondition) \
{ \
STOP; \
goto inHandler; \
}
#define FailWithActionNoMessage(inCondition, inAction, inHandler, inMessage) \
if(inCondition) \
{ \
STOP; \
{ inAction; } \
goto inHandler; \
}
#define FailIfNULLNoMessage(inPointer, inAction, inHandler, inMessage) \
if((inPointer) == NULL) \
{ \
STOP; \
{ inAction; } \
goto inHandler; \
}
#define FailIfKernelErrorNoMessage(inKernelError, inAction, inHandler, inMessage) \
{ \
unsigned int __Err = (inKernelError); \
if(__Err != 0) \
{ \
STOP; \
{ inAction; } \
goto inHandler; \
} \
}
#define FailIfErrorNoMessage(inError, inAction, inHandler, inMessage) \
{ \
SInt32 __Err = (inError); \
if(__Err != 0) \
{ \
STOP; \
{ inAction; } \
goto inHandler; \
} \
}
#if defined(__cplusplus)
#define Throw(inException) __THROW_STOP; throw (inException)
#define ThrowIf(inCondition, inException, inMessage) \
if(inCondition) \
{ \
DebugMessage(inMessage); \
Throw(inException); \
}
#define ThrowIfNULL(inPointer, inException, inMessage) \
if((inPointer) == NULL) \
{ \
DebugMessage(inMessage); \
Throw(inException); \
}
#define ThrowIfKernelError(inKernelError, inException, inMessage) \
{ \
int __Err = (inKernelError); \
if(__Err != 0) \
{ \
DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
Throw(inException); \
} \
}
#define ThrowIfError(inError, inException, inMessage) \
{ \
SInt32 __Err = (inError); \
if(__Err != 0) \
{ \
char __4CC[5] = CA4CCToCString(__Err); \
DebugMessageN2(inMessage ", Error: %d (%s)", (int)__Err, __4CC); \
Throw(inException); \
} \
}
#if TARGET_OS_WIN32
#define ThrowIfWinError(inError, inException, inMessage) \
{ \
HRESULT __Err = (inError); \
if(FAILED(__Err)) \
{ \
DebugMessageN2(inMessage ", Code: %d, Facility: 0x%X", HRESULT_CODE(__Err), HRESULT_FACILITY(__Err)); \
Throw(inException); \
} \
}
#endif
#define SubclassResponsibility(inMethodName, inException) \
{ \
DebugMessage(inMethodName": Subclasses must implement this method"); \
Throw(inException); \
}
#endif // defined(__cplusplus)
#else
#pragma mark Release Macros
#define Assert(inCondition, inMessage) \
if(!(inCondition)) \
{ \
__ASSERT_STOP; \
}
#define AssertFileLine(inCondition, inMessage) Assert(inCondition, inMessage)
#define AssertNoError(inError, inMessage) \
{ \
SInt32 __Err = (inError); \
if(__Err != 0) \
{ \
__ASSERT_STOP; \
} \
}
#define AssertNoKernelError(inError, inMessage) \
{ \
unsigned int __Err = (unsigned int)(inError); \
if(__Err != 0) \
{ \
__ASSERT_STOP; \
} \
}
#define AssertNotNULL(inPtr, inMessage) \
{ \
if((inPtr) == NULL) \
{ \
__ASSERT_STOP; \
} \
}
#define FailIf(inCondition, inHandler, inMessage) \
if(inCondition) \
{ \
STOP; \
goto inHandler; \
}
#define FailWithAction(inCondition, inAction, inHandler, inMessage) \
if(inCondition) \
{ \
STOP; \
{ inAction; } \
goto inHandler; \
}
#define FailIfNULL(inPointer, inAction, inHandler, inMessage) \
if((inPointer) == NULL) \
{ \
STOP; \
{ inAction; } \
goto inHandler; \
}
#define FailIfKernelError(inKernelError, inAction, inHandler, inMessage) \
if((inKernelError) != 0) \
{ \
STOP; \
{ inAction; } \
goto inHandler; \
}
#define FailIfError(inError, inAction, inHandler, inMessage) \
if((inError) != 0) \
{ \
STOP; \
{ inAction; } \
goto inHandler; \
}
#define FailIfNoMessage(inCondition, inHandler, inMessage) \
if(inCondition) \
{ \
STOP; \
goto inHandler; \
}
#define FailWithActionNoMessage(inCondition, inAction, inHandler, inMessage) \
if(inCondition) \
{ \
STOP; \
{ inAction; } \
goto inHandler; \
}
#define FailIfNULLNoMessage(inPointer, inAction, inHandler, inMessage) \
if((inPointer) == NULL) \
{ \
STOP; \
{ inAction; } \
goto inHandler; \
}
#define FailIfKernelErrorNoMessage(inKernelError, inAction, inHandler, inMessage) \
{ \
unsigned int __Err = (inKernelError); \
if(__Err != 0) \
{ \
STOP; \
{ inAction; } \
goto inHandler; \
} \
}
#define FailIfErrorNoMessage(inError, inAction, inHandler, inMessage) \
{ \
SInt32 __Err = (inError); \
if(__Err != 0) \
{ \
STOP; \
{ inAction; } \
goto inHandler; \
} \
}
#if defined(__cplusplus)
#define Throw(inException) __THROW_STOP; throw (inException)
#define ThrowIf(inCondition, inException, inMessage) \
if(inCondition) \
{ \
Throw(inException); \
}
#define ThrowIfNULL(inPointer, inException, inMessage) \
if((inPointer) == NULL) \
{ \
Throw(inException); \
}
// EQM edit: Changed "unsigned int" to "int" to silence -Wsign-conversion.
#define ThrowIfKernelError(inKernelError, inException, inMessage) \
{ \
int __Err = (inKernelError); \
if(__Err != 0) \
{ \
Throw(inException); \
} \
}
#define ThrowIfError(inError, inException, inMessage) \
{ \
SInt32 __Err = (inError); \
if(__Err != 0) \
{ \
Throw(inException); \
} \
}
#if TARGET_OS_WIN32
#define ThrowIfWinError(inError, inException, inMessage) \
{ \
HRESULT __Err = (inError); \
if(FAILED(__Err)) \
{ \
Throw(inException); \
} \
}
#endif
#define SubclassResponsibility(inMethodName, inException) \
{ \
Throw(inException); \
}
#endif // defined(__cplusplus)
#endif // DEBUG || CoreAudio_Debug
#endif

View File

@ -1,89 +0,0 @@
/*
File: CADebugPrintf.cpp
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
//==================================================================================================
// Includes
//==================================================================================================
// Self Include
#include "CADebugPrintf.h"
#if DEBUG || CoreAudio_Debug
#if TARGET_OS_WIN32
#include <stdarg.h>
#include <stdio.h>
#include <Windows.h>
extern "C"
int CAWin32DebugPrintf(char* inFormat, ...)
{
char theMessage[1024];
va_list theArguments;
va_start(theArguments, inFormat);
_vsnprintf(theMessage, 1024, inFormat, theArguments);
va_end(theArguments);
OutputDebugString(theMessage);
return 0;
}
#endif
#if defined(CoreAudio_UseSideFile)
#include <unistd.h>
FILE* sDebugPrintfSideFile = NULL;
extern "C"
void OpenDebugPrintfSideFile()
{
if(sDebugPrintfSideFile == NULL)
{
char theFileName[1024];
snprintf(theFileName, sizeof(theFileName), CoreAudio_UseSideFile, getpid());
sDebugPrintfSideFile = fopen(theFileName, "a+");
DebugPrintfRtn(DebugPrintfFileComma "\n------------------------------\n");
}
}
#endif
#endif

View File

@ -1,115 +0,0 @@
/*
File: CADebugPrintf.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
#if !defined(__CADebugPrintf_h__)
#define __CADebugPrintf_h__
//=============================================================================
// Includes
//=============================================================================
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreAudio/CoreAudioTypes.h>
#else
#include "CoreAudioTypes.h"
#endif
//=============================================================================
// Macros to redirect debugging output to various logging services
//=============================================================================
//#define CoreAudio_UseSysLog 1
//#define CoreAudio_UseSideFile "/CoreAudio-%d.txt"
#if DEBUG || CoreAudio_Debug
#if TARGET_OS_WIN32
#if defined(__cplusplus)
extern "C"
#endif
extern int CAWin32DebugPrintf(char* inFormat, ...);
#define DebugPrintfRtn CAWin32DebugPrintf
#define DebugPrintfFile
#define DebugPrintfLineEnding "\n"
#define DebugPrintfFileComma
#else
#if CoreAudio_UseSysLog
#include <sys/syslog.h>
#define DebugPrintfRtn syslog
#define DebugPrintfFile LOG_NOTICE
#define DebugPrintfLineEnding ""
#define DebugPrintfFileComma DebugPrintfFile,
#elif defined(CoreAudio_UseSideFile)
#include <stdio.h>
#if defined(__cplusplus)
extern "C"
#endif
void OpenDebugPrintfSideFile();
extern FILE* sDebugPrintfSideFile;
#define DebugPrintfRtn fprintf
#define DebugPrintfFile ((sDebugPrintfSideFile != NULL) ? sDebugPrintfSideFile : stderr)
#define DebugPrintfLineEnding "\n"
#define DebugPrintfFileComma DebugPrintfFile,
#else
#include <stdio.h>
#define DebugPrintfRtn fprintf
#define DebugPrintfFile stderr
#define DebugPrintfLineEnding "\n"
#define DebugPrintfFileComma DebugPrintfFile,
#endif
#endif
#define DebugPrintf(inFormat, ...) DebugPrintfRtn(DebugPrintfFileComma inFormat DebugPrintfLineEnding, ## __VA_ARGS__)
#else
#define DebugPrintfRtn
#define DebugPrintfFile
#define DebugPrintfLineEnding
#define DebugPrintfFileComma
#define DebugPrintf(inFormat, ...)
#endif
#endif

View File

@ -1,103 +0,0 @@
/*
File: CADebugger.cpp
Abstract: CADebugger.h
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
//=============================================================================
// Includes
//=============================================================================
#include "CADebugger.h"
//=============================================================================
// CADebugger
//=============================================================================
#if TARGET_API_MAC_OSX
#include <sys/sysctl.h>
#include <stdlib.h>
#include <unistd.h>
bool CAIsDebuggerAttached(void)
{
int mib[4];
struct kinfo_proc info;
size_t size;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();
size = sizeof(info);
info.kp_proc.p_flag = 0;
sysctl(mib, 4, &info, &size, NULL, 0);
return (info.kp_proc.p_flag & P_TRACED) == P_TRACED;
}
#endif
void CADebuggerStop(void)
{
#if CoreAudio_Debug
#if TARGET_API_MAC_OSX
if(CAIsDebuggerAttached())
{
#if defined(__i386__) || defined(__x86_64__)
asm("int3");
#else
__builtin_trap();
#endif
}
else
{
abort();
}
#else
__debugbreak();
#endif
#endif
}

View File

@ -1,69 +0,0 @@
/*
File: CADebugger.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#if !defined(__CADebugger_h__)
#define __CADebugger_h__
//=============================================================================
// Includes
//=============================================================================
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreAudio/CoreAudioTypes.h>
#else
#include <CoreAudioTypes.h>
#endif
//=============================================================================
// CADebugger
//=============================================================================
#if TARGET_API_MAC_OSX
extern bool CAIsDebuggerAttached(void);
#endif
extern void CADebuggerStop(void);
#endif

View File

@ -1,438 +0,0 @@
/*
File: CADispatchQueue.cpp
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
/*==================================================================================================
CADispatchQueue.cpp
==================================================================================================*/
//==================================================================================================
// Includes
//==================================================================================================
// Self Include
#include "CADispatchQueue.h"
// PublicUtility Includes
#include "CACFString.h"
#include "CADebugMacros.h"
#include "CAException.h"
#include "CAHostTimeBase.h"
// System Includes
#include <mach/mach.h>
// Standard Library Includes
#include <algorithm>
//==================================================================================================
// CADispatchQueue
//==================================================================================================
CADispatchQueue::CADispatchQueue(const char* inName)
:
mDispatchQueue(NULL),
mPortDeathList(),
mMachPortReceiverList()
{
mDispatchQueue = dispatch_queue_create(inName, NULL);
ThrowIfNULL(mDispatchQueue, CAException('what'), "CADispatchQueue::CADispatchQueue: failed to create the dispatch queue");
}
CADispatchQueue::CADispatchQueue(CFStringRef inName)
:
mDispatchQueue(NULL),
mPortDeathList(),
mMachPortReceiverList()
{
CACFString theCFName(inName, false);
char theName[256];
UInt32 theSize = 256;
theCFName.GetCString(theName, theSize);
mDispatchQueue = dispatch_queue_create(theName, NULL);
ThrowIfNULL(mDispatchQueue, CAException('what'), "CADispatchQueue::CADispatchQueue: failed to create the dispatch queue");
}
CADispatchQueue::CADispatchQueue(CFStringRef inPattern, CFStringRef inName)
:
mDispatchQueue(NULL),
mPortDeathList(),
mMachPortReceiverList()
{
CACFString theCFName(CFStringCreateWithFormat(NULL, NULL, inPattern, inName), true);
char theName[256];
UInt32 theSize = 256;
theCFName.GetCString(theName, theSize);
mDispatchQueue = dispatch_queue_create(theName, NULL);
ThrowIfNULL(mDispatchQueue, CAException('what'), "CADispatchQueue::CADispatchQueue: failed to create the dispatch queue");
}
CADispatchQueue::~CADispatchQueue()
{
// Clean up the port death watchers if any are still around. Note that we do this explicitly to
// be sure the source is cleaned up before the queue is released
mPortDeathList.clear();
Assert(mMachPortReceiverList.size() == 0, "CADispatchQueue::~CADispatchQueue: Implicitly removing the mach port receviers. It is best to explicitly call RemoveMachPortRecevier().");
mMachPortReceiverList.clear();
// release the dispatch queue
dispatch_release(mDispatchQueue);
}
void CADispatchQueue::Dispatch(bool inDoSync, dispatch_block_t inTask) const
{
if(inDoSync)
{
// Executing a task synchronously while already on the dispatch queue will result in a deadlock
dispatch_sync(mDispatchQueue, inTask);
}
else
{
dispatch_async(mDispatchQueue, inTask);
}
}
void CADispatchQueue::Dispatch(UInt64 inNanoseconds, dispatch_block_t inTask) const
{
if(inNanoseconds == 0)
{
dispatch_async(mDispatchQueue, inTask);
}
else
{
dispatch_after(dispatch_time(0, static_cast<int64_t>(CAHostTimeBase::ConvertFromNanos(inNanoseconds))), mDispatchQueue, inTask);
}
}
void CADispatchQueue::Dispatch(bool inDoSync, void* inTaskContext, dispatch_function_t inTask) const
{
if(inDoSync)
{
// Executing a task synchronously while already on the dispatch queue will result in a deadlock
dispatch_sync_f(mDispatchQueue, inTaskContext, inTask);
}
else
{
dispatch_async_f(mDispatchQueue, inTaskContext, inTask);
}
}
void CADispatchQueue::Dispatch(UInt64 inNanoseconds, void* inTaskContext, dispatch_function_t inTask) const
{
if(inNanoseconds == 0)
{
dispatch_async_f(mDispatchQueue, inTaskContext, inTask);
}
else
{
dispatch_after_f(dispatch_time(0, static_cast<int64_t>(CAHostTimeBase::ConvertFromNanos(inNanoseconds))), mDispatchQueue, inTaskContext, inTask);
}
}
void CADispatchQueue::Dispatch_Global(dispatch_queue_priority_t inQueuePriority, bool inDoSync, dispatch_block_t inTask)
{
dispatch_queue_t theDispatchQueue = dispatch_get_global_queue(inQueuePriority, 0);
if(inDoSync)
{
// Executing a task synchronously while already on the dispatch queue will result in a deadlock
dispatch_sync(theDispatchQueue, inTask);
}
else
{
dispatch_async(theDispatchQueue, inTask);
}
}
void CADispatchQueue::Dispatch_Global(dispatch_queue_priority_t inQueuePriority, UInt64 inNanoseconds, dispatch_block_t inTask)
{
dispatch_queue_t theDispatchQueue = dispatch_get_global_queue(inQueuePriority, 0);
if(inNanoseconds == 0)
{
dispatch_async(theDispatchQueue, inTask);
}
else
{
dispatch_after(dispatch_time(0, static_cast<int64_t>(CAHostTimeBase::ConvertFromNanos(inNanoseconds))), theDispatchQueue, inTask);
}
}
void CADispatchQueue::Dispatch_Global(dispatch_queue_priority_t inQueuePriority, bool inDoSync, void* inTaskContext, dispatch_function_t inTask)
{
dispatch_queue_t theDispatchQueue = dispatch_get_global_queue(inQueuePriority, 0);
if(inDoSync)
{
// Executing a task synchronously while already on the dispatch queue will result in a deadlock
dispatch_sync_f(theDispatchQueue, inTaskContext, inTask);
}
else
{
dispatch_async_f(theDispatchQueue, inTaskContext, inTask);
}
}
void CADispatchQueue::Dispatch_Global(dispatch_queue_priority_t inQueuePriority, UInt64 inNanoseconds, void* inTaskContext, dispatch_function_t inTask)
{
dispatch_queue_t theDispatchQueue = dispatch_get_global_queue(inQueuePriority, 0);
if(inNanoseconds == 0)
{
dispatch_async_f(theDispatchQueue, inTaskContext, inTask);
}
else
{
dispatch_after_f(dispatch_time(0, static_cast<int64_t>(CAHostTimeBase::ConvertFromNanos(inNanoseconds))), theDispatchQueue, inTaskContext, inTask);
}
}
void CADispatchQueue::Dispatch_Main(bool inDoSync, dispatch_block_t inTask)
{
dispatch_queue_t theDispatchQueue = dispatch_get_main_queue();
if(inDoSync)
{
// Executing a task synchronously while already on the dispatch queue will result in a deadlock
dispatch_sync(theDispatchQueue, inTask);
}
else
{
dispatch_async(theDispatchQueue, inTask);
}
}
void CADispatchQueue::Dispatch_Main(UInt64 inNanoseconds, dispatch_block_t inTask)
{
dispatch_queue_t theDispatchQueue = dispatch_get_main_queue();
if(inNanoseconds == 0)
{
dispatch_async(theDispatchQueue, inTask);
}
else
{
dispatch_after(dispatch_time(0, static_cast<int64_t>(CAHostTimeBase::ConvertFromNanos(inNanoseconds))), theDispatchQueue, inTask);
}
}
void CADispatchQueue::Dispatch_Main(bool inDoSync, void* inTaskContext, dispatch_function_t inTask)
{
dispatch_queue_t theDispatchQueue = dispatch_get_main_queue();
if(inDoSync)
{
// Executing a task synchronously while already on the dispatch queue will result in a deadlock
dispatch_sync_f(theDispatchQueue, inTaskContext, inTask);
}
else
{
dispatch_async_f(theDispatchQueue, inTaskContext, inTask);
}
}
void CADispatchQueue::Dispatch_Main(UInt64 inNanoseconds, void* inTaskContext, dispatch_function_t inTask)
{
dispatch_queue_t theDispatchQueue = dispatch_get_main_queue();
if(inNanoseconds == 0)
{
dispatch_async_f(theDispatchQueue, inTaskContext, inTask);
}
else
{
dispatch_after_f(dispatch_time(0, static_cast<int64_t>(CAHostTimeBase::ConvertFromNanos(inNanoseconds))), theDispatchQueue, inTaskContext, inTask);
}
}
void CADispatchQueue::InstallMachPortDeathNotification(mach_port_t inMachPort, dispatch_block_t inNotificationTask)
{
ThrowIf(inMachPort == MACH_PORT_NULL, CAException('nope'), "CADispatchQueue::InstallMachPortDeathNotification: a mach port is required");
// look in the list to see if we've already created an event source for it
bool wasFound = false;
EventSourceList::iterator theIterator = mPortDeathList.begin();
while(!wasFound && (theIterator != mPortDeathList.end()))
{
wasFound = theIterator->mMachPort == inMachPort;
if(!wasFound)
{
++theIterator;
}
}
// create and install the event source for the port
if(!wasFound)
{
// create an event source for the mach port
dispatch_source_t theDispatchSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_SEND, inMachPort, DISPATCH_MACH_SEND_DEAD, mDispatchQueue);
ThrowIfNULL(theDispatchSource, CAException('what'), "CADispatchQueue::InstallMachPortDeathNotification: failed to create the mach port event source");
// install the event handler
dispatch_source_set_event_handler(theDispatchSource, inNotificationTask);
// put the info in the list
mPortDeathList.push_back(EventSource(theDispatchSource, inMachPort));
// resume the event source so that it can start handling messages and also so that the source can be released
dispatch_resume(theDispatchSource);
}
}
void CADispatchQueue::RemoveMachPortDeathNotification(mach_port_t inMachPort)
{
bool wasFound = false;
EventSourceList::iterator theIterator = mPortDeathList.begin();
while(!wasFound && (theIterator != mPortDeathList.end()))
{
wasFound = theIterator->mMachPort == inMachPort;
if(!wasFound)
{
++theIterator;
}
}
if(wasFound)
{
if(theIterator->mDispatchSource != NULL)
{
dispatch_source_cancel(theIterator->mDispatchSource);
}
mPortDeathList.erase(theIterator);
}
}
void CADispatchQueue::InstallMachPortReceiver(mach_port_t inMachPort, dispatch_block_t inMessageTask)
{
ThrowIf(inMachPort == MACH_PORT_NULL, CAException('nope'), "CADispatchQueue::InstallMachPortReceiver: a mach port is required");
// look in the list to see if we've already created an event source for it
bool wasFound = false;
EventSourceList::iterator theIterator = mMachPortReceiverList.begin();
while(!wasFound && (theIterator != mMachPortReceiverList.end()))
{
wasFound = theIterator->mMachPort == inMachPort;
if(!wasFound)
{
++theIterator;
}
}
// create and install the event source for the port
if(!wasFound)
{
// create an event source for the mach port
dispatch_source_t theDispatchSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, inMachPort, 0, mDispatchQueue);
ThrowIfNULL(theDispatchSource, CAException('what'), "CADispatchQueue::InstallMachPortReceiver: failed to create the mach port event source");
// install an event handler that maps the mach messages to the MIG server function
dispatch_source_set_event_handler(theDispatchSource, inMessageTask);
// put the info in the list
mMachPortReceiverList.push_back(EventSource(theDispatchSource, inMachPort));
// resume the event source so that it can start handling messages and also so that the source can be released
dispatch_resume(theDispatchSource);
}
}
void CADispatchQueue::RemoveMachPortReceiver(mach_port_t inMachPort, dispatch_block_t inCompletionTask)
{
bool wasFound = false;
EventSourceList::iterator theIterator = mMachPortReceiverList.begin();
while(!wasFound && (theIterator != mMachPortReceiverList.end()))
{
wasFound = theIterator->mMachPort == inMachPort;
if(!wasFound)
{
++theIterator;
}
}
if(wasFound)
{
if(theIterator->mDispatchSource != NULL)
{
// Set the cancel handler to the completion block. Note that the mach port cannot be freed
// before the completion block runs due to a race condition. See the note in the comments
// dispatch_source_set_cancel_handler in <dispatch/source.h>.
if(inCompletionTask != 0)
{
dispatch_source_set_cancel_handler(theIterator->mDispatchSource, inCompletionTask);
}
dispatch_source_cancel(theIterator->mDispatchSource);
}
mMachPortReceiverList.erase(theIterator);
}
}
void CADispatchQueue::RemoveMachPortReceiver(mach_port_t inMachPort, bool inDestroySendRight, bool inDestroyReceiveRight)
{
RemoveMachPortReceiver(inMachPort, ^{
if(inDestroySendRight)
{
kern_return_t theError = mach_port_deallocate(mach_task_self(), inMachPort);
AssertNoKernelError(theError, "CADispatchQueue::RemoveMachPortReceiver: deallocating the send right failed");
}
if(inDestroyReceiveRight)
{
kern_return_t theError = mach_port_mod_refs(mach_task_self(), inMachPort, MACH_PORT_RIGHT_RECEIVE, -1);
AssertNoKernelError(theError, "CADispatchQueue::RemoveMachPortReceiver: deallocating the receive right failed");
}
});
}
CADispatchQueue& CADispatchQueue::GetGlobalSerialQueue()
{
dispatch_once_f(&sGlobalSerialQueueInitialized, NULL, InitializeGlobalSerialQueue);
ThrowIfNULL(sGlobalSerialQueue, CAException('nope'), "CADispatchQueue::GetGlobalSerialQueue: there is no global serial queue");
return *sGlobalSerialQueue;
}
void CADispatchQueue::InitializeGlobalSerialQueue(void*)
{
try
{
sGlobalSerialQueue = new CADispatchQueue("com.apple.audio.CADispatchQueue.SerialQueue");
}
catch(...)
{
sGlobalSerialQueue = NULL;
}
}
CADispatchQueue* CADispatchQueue::sGlobalSerialQueue = NULL;
dispatch_once_t CADispatchQueue::sGlobalSerialQueueInitialized = 0;

View File

@ -1,235 +0,0 @@
/*
File: CADispatchQueue.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
/*==================================================================================================
CADispatchQueue.h
==================================================================================================*/
#if !defined(__CADispatchQueue_h__)
#define __CADispatchQueue_h__
//==================================================================================================
// Includes
//==================================================================================================
// System Includes
#include <CoreFoundation/CFString.h>
#include <dispatch/dispatch.h>
// Standard Library Includes
#include <functional>
#include <vector>
/*==================================================================================================
CADispatchQueue
This class provides a wrapper for a libdispatch dispatch queue and several kinds of event
sources such as MIG servers, port death notifications and other mach port related support. Being
a libdispatch client, the unit of work is represented as either a function pointer and context
pointer pair or as a Block.
One thing to keep in mind when using a Block-based construct is that you get a copy of the
pointer but you do not get a copy of the memory that the pointer is pointing at. The net effect
is that if you have a task that frees the memory that is referenced by a subsequent task,
this second task would crash when dereferencing the pointer. This means that every task
needs to include some code to validate any pointers it is using before dereferencing them.
A common example of this problem comes up with C++ objects. Suppose you have an instance method
that creates a Block that calls other instance methods or accesses the object's fields. Suppose
further that the Block is submitted to a dispatch queue for execution. If the object gets
deallocated before the Block can run, the Block will crash. Thus, the Block needs to validate
that the "this" pointer is still valid when it executes.
Another place where this comes up often is when attempting to implment a function by dispatching
the work asynchronously. Any arguments to the function that point to the stack will be invalid.
This is particularly troublesome inside of a MIG function.
Still another common issue with using Blocks and dispatch functions with C++ is that it is vital
that no exceptions ever leave a Block or a dispatch function. If an exception was thrown out of
a block, the result would be undefined and probably would result in the program calling
the terminate() function in the standard C++ library (whose default implementation is to call
abort(3)). Given that, all Blocks and dispatch functions that might end up throwing an exception
need to catch those exceptions.
==================================================================================================*/
class CADispatchQueue
{
#pragma mark Construction/Destruction
public:
CADispatchQueue(const char* inName);
CADispatchQueue(CFStringRef inName);
CADispatchQueue(CFStringRef inPattern, CFStringRef inName);
virtual ~CADispatchQueue();
private:
CADispatchQueue(const CADispatchQueue&);
CADispatchQueue& operator=(const CADispatchQueue&);
#pragma mark Execution Operations
public:
void Dispatch(bool inDoSync, dispatch_block_t inTask) const;
void Dispatch(UInt64 inNanoseconds, dispatch_block_t inTask) const;
void Dispatch(bool inDoSync, void* inTaskContext, dispatch_function_t inTask) const;
void Dispatch(UInt64 inNanoseconds, void* inTaskContext, dispatch_function_t inTask) const;
static void Dispatch_Global(dispatch_queue_priority_t inQueuePriority, bool inDoSync, dispatch_block_t inTask);
static void Dispatch_Global(dispatch_queue_priority_t inQueuePriority, UInt64 inNanoseconds, dispatch_block_t inTask);
static void Dispatch_Global(dispatch_queue_priority_t inQueuePriority, bool inDoSync, void* inTaskContext, dispatch_function_t inTask);
static void Dispatch_Global(dispatch_queue_priority_t inQueuePriority, UInt64 inNanoseconds, void* inTaskContext, dispatch_function_t inTask);
static void Dispatch_Main(bool inDoSync, dispatch_block_t inTask);
static void Dispatch_Main(UInt64 inNanoseconds, dispatch_block_t inTask);
static void Dispatch_Main(bool inDoSync, void* inTaskContext, dispatch_function_t inTask);
static void Dispatch_Main(UInt64 inNanoseconds, void* inTaskContext, dispatch_function_t inTask);
#pragma mark Event Sources
public:
void InstallMachPortDeathNotification(mach_port_t inMachPort, dispatch_block_t inNotificationTask);
void RemoveMachPortDeathNotification(mach_port_t inMachPort);
void InstallMachPortReceiver(mach_port_t inMachPort, dispatch_block_t inMessageTask);
void RemoveMachPortReceiver(mach_port_t inMachPort, dispatch_block_t inCompletionTask);
void RemoveMachPortReceiver(mach_port_t inMachPort, bool inDestroySendRight, bool inDestroyReceiveRight);
#pragma mark Implementation
public:
dispatch_queue_t GetDispatchQueue() const;
static CADispatchQueue& GetGlobalSerialQueue();
protected:
static void InitializeGlobalSerialQueue(void*);
struct EventSource
{
dispatch_source_t mDispatchSource;
mach_port_t mMachPort;
EventSource();
EventSource(dispatch_source_t inDispatchSource, mach_port_t inMachPort);
EventSource(const EventSource& inEventSource);
EventSource& operator=(const EventSource& inEventSource);
~EventSource();
void Retain();
void Release();
};
typedef std::vector<EventSource> EventSourceList;
dispatch_queue_t mDispatchQueue;
EventSourceList mPortDeathList;
EventSourceList mMachPortReceiverList;
static CADispatchQueue* sGlobalSerialQueue;
static dispatch_once_t sGlobalSerialQueueInitialized;
};
//==================================================================================================
#pragma mark CADispatchQueue Inline Method Implementations
//==================================================================================================
inline dispatch_queue_t CADispatchQueue::GetDispatchQueue() const
{
return mDispatchQueue;
}
inline CADispatchQueue::EventSource::EventSource()
:
mDispatchSource(NULL),
mMachPort(MACH_PORT_NULL)
{
}
inline CADispatchQueue::EventSource::EventSource(dispatch_source_t inDispatchSource, mach_port_t inMachPort)
:
mDispatchSource(inDispatchSource),
mMachPort(inMachPort)
{
}
inline CADispatchQueue::EventSource::EventSource(const EventSource& inEventSource)
:
mDispatchSource(inEventSource.mDispatchSource),
mMachPort(inEventSource.mMachPort)
{
Retain();
}
inline CADispatchQueue::EventSource& CADispatchQueue::EventSource::operator=(const EventSource& inEventSource)
{
Release();
mDispatchSource = inEventSource.mDispatchSource;
mMachPort = inEventSource.mMachPort;
Retain();
return *this;
}
inline CADispatchQueue::EventSource::~EventSource()
{
Release();
}
inline void CADispatchQueue::EventSource::Retain()
{
if(mDispatchSource != NULL)
{
dispatch_retain(mDispatchSource);
}
}
inline void CADispatchQueue::EventSource::Release()
{
if(mDispatchSource != NULL)
{
dispatch_release(mDispatchSource);
mDispatchSource = NULL;
}
}
#endif // __CADispatchQueue_h__

View File

@ -1,83 +0,0 @@
/*
File: CAException.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
#if !defined(__CAException_h__)
#define __CAException_h__
//=============================================================================
// Includes
//=============================================================================
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreAudio/CoreAudioTypes.h>
#else
#include "CoreAudioTypes.h"
#endif
//=============================================================================
// CAException
//=============================================================================
class CAException
{
public:
CAException(OSStatus inError) : mError(inError) {}
CAException(const CAException& inException) : mError(inException.mError) {}
CAException& operator=(const CAException& inException) { mError = inException.mError; return *this; }
~CAException() {}
OSStatus GetError() const { return mError; }
protected:
OSStatus mError;
};
#define CATry try{
#define CACatch } catch(...) {}
#define CASwallowException(inExpression) try { inExpression; } catch(...) {}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,238 +0,0 @@
/*
File: CAHALAudioDevice.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#if !defined(__CAHALAudioDevice_h__)
#define __CAHALAudioDevice_h__
//==================================================================================================
// Includes
//==================================================================================================
// Super Class Includes
#include "CAHALAudioObject.h"
// PublicUtility Includes
#include "CADebugMacros.h"
#include "CAException.h"
//==================================================================================================
// CAHALAudioDevice
//==================================================================================================
class CAHALAudioDevice
:
public CAHALAudioObject
{
// Construction/Destruction
public:
CAHALAudioDevice(AudioObjectID inAudioDevice);
CAHALAudioDevice(CFStringRef inUID);
virtual ~CAHALAudioDevice();
// General Stuff
public:
CFStringRef CopyDeviceUID() const;
bool HasModelUID() const;
CFStringRef CopyModelUID() const;
CFStringRef CopyConfigurationApplicationBundleID() const;
CFURLRef CopyIconLocation() const;
UInt32 GetTransportType() const;
bool CanBeDefaultDevice(bool inIsInput, bool inIsSystem) const;
bool HasDevicePlugInStatus() const;
OSStatus GetDevicePlugInStatus() const;
bool IsAlive() const;
bool IsHidden() const;
pid_t GetHogModeOwner() const;
bool IsHogModeSettable() const;
bool TakeHogMode();
void ReleaseHogMode();
bool HasPreferredStereoChannels(bool inIsInput) const;
void GetPreferredStereoChannels(bool inIsInput, UInt32& outLeft, UInt32& outRight) const;
void SetPreferredStereoChannels(bool inIsInput, UInt32 inLeft, UInt32 inRight);
bool HasPreferredChannelLayout(bool inIsInput) const;
void GetPreferredChannelLayout(bool inIsInput, AudioChannelLayout& outChannelLayout) const;
void SetPreferredStereoChannels(bool inIsInput, AudioChannelLayout& inChannelLayout);
UInt32 GetNumberRelatedAudioDevices() const;
void GetRelatedAudioDevices(UInt32& ioNumberRelatedDevices, AudioObjectID* outRelatedDevices) const;
AudioObjectID GetRelatedAudioDeviceByIndex(UInt32 inIndex) const;
// Stream Stuff
public:
UInt32 GetNumberStreams(bool inIsInput) const;
void GetStreams(bool inIsInput, UInt32& ioNumberStreams, AudioObjectID* outStreamList) const;
AudioObjectID GetStreamByIndex(bool inIsInput, UInt32 inIndex) const;
UInt32 GetTotalNumberChannels(bool inIsInput) const;
void GetCurrentVirtualFormats(bool inIsInput, UInt32& ioNumberStreams, AudioStreamBasicDescription* outFormats) const;
void GetCurrentPhysicalFormats(bool inIsInput, UInt32& ioNumberStreams, AudioStreamBasicDescription* outFormats) const;
// IO Stuff
public:
bool IsRunning() const;
bool IsRunningSomewhere() const;
UInt32 GetLatency(bool inIsInput) const;
UInt32 GetSafetyOffset(bool inIsInput) const;
bool HasClockDomain() const;
UInt32 GetClockDomain() const;
Float64 GetActualSampleRate() const;
Float64 GetNominalSampleRate() const;
void SetNominalSampleRate(Float64 inSampleRate);
UInt32 GetNumberAvailableNominalSampleRateRanges() const;
void GetAvailableNominalSampleRateRanges(UInt32& ioNumberRanges, AudioValueRange* outRanges) const;
void GetAvailableNominalSampleRateRangeByIndex(UInt32 inIndex, Float64& outMinimum, Float64& outMaximum) const;
bool IsValidNominalSampleRate(Float64 inSampleRate) const;
bool IsIOBufferSizeSettable() const;
UInt32 GetIOBufferSize() const;
void SetIOBufferSize(UInt32 inBufferSize);
bool UsesVariableIOBufferSizes() const;
UInt32 GetMaximumVariableIOBufferSize() const;
bool HasIOBufferSizeRange() const;
void GetIOBufferSizeRange(UInt32& outMinimum, UInt32& outMaximum) const;
AudioDeviceIOProcID CreateIOProcID(AudioDeviceIOProc inIOProc, void* inClientData);
AudioDeviceIOProcID CreateIOProcIDWithBlock(dispatch_queue_t inDispatchQueue, AudioDeviceIOBlock inIOBlock);
void DestroyIOProcID(AudioDeviceIOProcID inIOProcID);
void StartIOProc(AudioDeviceIOProcID inIOProcID);
void StartIOProcAtTime(AudioDeviceIOProcID inIOProcID, AudioTimeStamp& ioStartTime, bool inIsInput, bool inIgnoreHardware);
void StopIOProc(AudioDeviceIOProcID inIOProcID);
void GetIOProcStreamUsage(AudioDeviceIOProcID inIOProcID, bool inIsInput, bool* outStreamUsage) const;
void SetIOProcStreamUsage(AudioDeviceIOProcID inIOProcID, bool inIsInput, const bool* inStreamUsage);
Float32 GetIOCycleUsage() const;
void SetIOCycleUsage(Float32 inValue);
// Time Operations
public:
void GetCurrentTime(AudioTimeStamp& outTime);
void TranslateTime(const AudioTimeStamp& inTime, AudioTimeStamp& outTime);
void GetNearestStartTime(AudioTimeStamp& ioTime, bool inIsInput, bool inIgnoreHardware);
// Controls
public:
bool HasVolumeControl(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool VolumeControlIsSettable(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
Float32 GetVolumeControlScalarValue(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
Float32 GetVolumeControlDecibelValue(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
void SetVolumeControlScalarValue(AudioObjectPropertyScope inScope, UInt32 inChannel, Float32 inValue);
void SetVolumeControlDecibelValue(AudioObjectPropertyScope inScope, UInt32 inChannel, Float32 inValue);
Float32 GetVolumeControlScalarForDecibelValue(AudioObjectPropertyScope inScope, UInt32 inChannel, Float32 inValue) const;
Float32 GetVolumeControlDecibelForScalarValue(AudioObjectPropertyScope inScope, UInt32 inChannel, Float32 inValue) const;
bool HasSubVolumeControl(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool SubVolumeControlIsSettable(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
Float32 GetSubVolumeControlScalarValue(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
Float32 GetSubVolumeControlDecibelValue(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
void SetSubVolumeControlScalarValue(AudioObjectPropertyScope inScope, UInt32 inChannel, Float32 inValue);
void SetSubVolumeControlDecibelValue(AudioObjectPropertyScope inScope, UInt32 inChannel, Float32 inValue);
Float32 GetSubVolumeControlScalarForDecibelValue(AudioObjectPropertyScope inScope, UInt32 inChannel, Float32 inValue) const;
Float32 GetSubVolumeControlDecibelForScalarValue(AudioObjectPropertyScope inScope, UInt32 inChannel, Float32 inValue) const;
bool HasMuteControl(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool MuteControlIsSettable(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool GetMuteControlValue(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
void SetMuteControlValue(AudioObjectPropertyScope inScope, UInt32 inChannel, bool inValue);
bool HasSoloControl(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool SoloControlIsSettable(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool GetSoloControlValue(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
void SetSoloControlValue(AudioObjectPropertyScope inScope, UInt32 inChannel, bool inValue);
bool HasStereoPanControl(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool StereoPanControlIsSettable(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
Float32 GetStereoPanControlValue(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
void SetStereoPanControlValue(AudioObjectPropertyScope inScope, UInt32 inChannel, Float32 inValue);
void GetStereoPanControlChannels(AudioObjectPropertyScope inScope, UInt32 inChannel, UInt32& outLeftChannel, UInt32& outRightChannel) const;
bool HasJackControl(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool GetJackControlValue(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool HasSubMuteControl(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool SubMuteControlIsSettable(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool GetSubMuteControlValue(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
void SetSubMuteControlValue(AudioObjectPropertyScope inScope, UInt32 inChannel, bool inValue);
bool HasiSubOwnerControl(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool iSubOwnerControlIsSettable(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool GetiSubOwnerControlValue(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
void SetiSubOwnerControlValue(AudioObjectPropertyScope inScope, UInt32 inChannel, bool inValue);
bool HasDataSourceControl(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool DataSourceControlIsSettable(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
UInt32 GetCurrentDataSourceID(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
void SetCurrentDataSourceByID(AudioObjectPropertyScope inScope, UInt32 inChannel, UInt32 inID);
UInt32 GetNumberAvailableDataSources(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
void GetAvailableDataSources(AudioObjectPropertyScope inScope, UInt32 inChannel, UInt32& ioNumberSources, UInt32* outSources) const;
UInt32 GetAvailableDataSourceByIndex(AudioObjectPropertyScope inScope, UInt32 inChannel, UInt32 inIndex) const;
CFStringRef CopyDataSourceNameForID(AudioObjectPropertyScope inScope, UInt32 inChannel, UInt32 inID) const;
bool HasDataDestinationControl(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
bool DataDestinationControlIsSettable(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
UInt32 GetCurrentDataDestinationID(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
void SetCurrentDataDestinationByID(AudioObjectPropertyScope inScope, UInt32 inChannel, UInt32 inID);
UInt32 GetNumberAvailableDataDestinations(AudioObjectPropertyScope inScope, UInt32 inChannel) const;
void GetAvailableDataDestinations(AudioObjectPropertyScope inScope, UInt32 inChannel, UInt32& ioNumberDestinations, UInt32* outDestinations) const;
UInt32 GetAvailableDataDestinationByIndex(AudioObjectPropertyScope inScope, UInt32 inChannel, UInt32 inIndex) const;
CFStringRef CopyDataDestinationNameForID(AudioObjectPropertyScope inScope, UInt32 inChannel, UInt32 inID) const;
bool HasClockSourceControl() const;
bool ClockSourceControlIsSettable() const;
UInt32 GetCurrentClockSourceID() const;
void SetCurrentClockSourceByID(UInt32 inID);
UInt32 GetNumberAvailableClockSources() const;
void GetAvailableClockSources(UInt32& ioNumberSources, UInt32* outSources) const;
UInt32 GetAvailableClockSourceByIndex(UInt32 inIndex) const;
CFStringRef CopyClockSourceNameForID(UInt32 inID) const;
UInt32 GetClockSourceKindForID(UInt32 inID) const;
};
inline AudioDeviceIOProcID CAHALAudioDevice::CreateIOProcIDWithBlock(dispatch_queue_t inDispatchQueue, AudioDeviceIOBlock inIOBlock)
{
AudioDeviceIOProcID theAnswer = NULL;
OSStatus theError = AudioDeviceCreateIOProcIDWithBlock(&theAnswer, mObjectID, inDispatchQueue, inIOBlock);
ThrowIfError(theError, CAException(theError), "CAHALAudioDevice::CreateIOProcIDWithBlock: got an error creating the IOProc ID");
return theAnswer;
}
#endif

View File

@ -1,370 +0,0 @@
/*
File: CAHALAudioObject.cpp
Abstract: CAHALAudioObject.h
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
//==================================================================================================
// Includes
//==================================================================================================
// Self Include
#include "CAHALAudioObject.h"
// PublicUtility Includes
#include "CAAutoDisposer.h"
#include "CADebugMacros.h"
#include "CAException.h"
#include "CAPropertyAddress.h"
//==================================================================================================
// CAHALAudioObject
//==================================================================================================
CAHALAudioObject::CAHALAudioObject(AudioObjectID inObjectID)
:
mObjectID(inObjectID)
{
}
CAHALAudioObject::~CAHALAudioObject()
{
}
AudioObjectID CAHALAudioObject::GetObjectID() const
{
return mObjectID;
}
void CAHALAudioObject::SetObjectID(AudioObjectID inObjectID)
{
mObjectID = inObjectID;
}
AudioClassID CAHALAudioObject::GetClassID() const
{
// set up the return value
AudioClassID theAnswer = 0;
// set up the property address
CAPropertyAddress theAddress(kAudioObjectPropertyClass);
// make sure the property exists
if(HasProperty(theAddress))
{
UInt32 theSize = sizeof(AudioClassID);
GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
}
return theAnswer;
}
AudioObjectID CAHALAudioObject::GetOwnerObjectID() const
{
// set up the return value
AudioObjectID theAnswer = 0;
// set up the property address
CAPropertyAddress theAddress(kAudioObjectPropertyOwner);
// make sure the property exists
if(HasProperty(theAddress))
{
// get the property data
UInt32 theSize = sizeof(AudioObjectID);
GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
}
return theAnswer;
}
CFStringRef CAHALAudioObject::CopyOwningPlugInBundleID() const
{
// set up the return value
CFStringRef theAnswer = NULL;
// set up the property address
CAPropertyAddress theAddress(kAudioObjectPropertyCreator);
// make sure the property exists
if(HasProperty(theAddress))
{
// get the property data
UInt32 theSize = sizeof(CFStringRef);
GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
}
return theAnswer;
}
CFStringRef CAHALAudioObject::CopyName() const
{
// set up the return value
CFStringRef theAnswer = NULL;
// set up the property address
CAPropertyAddress theAddress(kAudioObjectPropertyName);
// make sure the property exists
if(HasProperty(theAddress))
{
// get the property data
UInt32 theSize = sizeof(CFStringRef);
GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
}
return theAnswer;
}
CFStringRef CAHALAudioObject::CopyManufacturer() const
{
// set up the return value
CFStringRef theAnswer = NULL;
// set up the property address
CAPropertyAddress theAddress(kAudioObjectPropertyManufacturer);
// make sure the property exists
if(HasProperty(theAddress))
{
// get the property data
UInt32 theSize = sizeof(CFStringRef);
GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
}
return theAnswer;
}
CFStringRef CAHALAudioObject::CopyNameForElement(AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement) const
{
// set up the return value
CFStringRef theAnswer = NULL;
// set up the property address
CAPropertyAddress theAddress(kAudioObjectPropertyElementName, inScope, inElement);
// make sure the property exists
if(HasProperty(theAddress))
{
// get the property data
UInt32 theSize = sizeof(CFStringRef);
GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
}
return theAnswer;
}
CFStringRef CAHALAudioObject::CopyCategoryNameForElement(AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement) const
{
// set up the return value
CFStringRef theAnswer = NULL;
// set up the property address
CAPropertyAddress theAddress(kAudioObjectPropertyElementCategoryName, inScope, inElement);
// make sure the property exists
if(HasProperty(theAddress))
{
// get the property data
UInt32 theSize = sizeof(CFStringRef);
GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
}
return theAnswer;
}
CFStringRef CAHALAudioObject::CopyNumberNameForElement(AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement) const
{
// set up the return value
CFStringRef theAnswer = NULL;
// set up the property address
CAPropertyAddress theAddress(kAudioObjectPropertyElementNumberName, inScope, inElement);
// make sure the property exists
if(HasProperty(theAddress))
{
// get the property data
UInt32 theSize = sizeof(CFStringRef);
GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
}
return theAnswer;
}
bool CAHALAudioObject::ObjectExists(AudioObjectID inObjectID)
{
Boolean isSettable;
CAPropertyAddress theAddress(kAudioObjectPropertyClass);
return (inObjectID == 0) || (AudioObjectIsPropertySettable(inObjectID, &theAddress, &isSettable) != 0);
}
UInt32 CAHALAudioObject::GetNumberOwnedObjects(AudioClassID inClass) const
{
// set up the return value
UInt32 theAnswer = 0;
// set up the property address
CAPropertyAddress theAddress(kAudioObjectPropertyOwnedObjects);
// figure out the qualifier
UInt32 theQualifierSize = 0;
void* theQualifierData = NULL;
if(inClass != 0)
{
theQualifierSize = sizeof(AudioObjectID);
theQualifierData = &inClass;
}
// get the property data size
theAnswer = GetPropertyDataSize(theAddress, theQualifierSize, theQualifierData);
// calculate the number of object IDs
theAnswer /= SizeOf32(AudioObjectID);
return theAnswer;
}
void CAHALAudioObject::GetAllOwnedObjects(AudioClassID inClass, UInt32& ioNumberObjects, AudioObjectID* ioObjectIDs) const
{
// set up the property address
CAPropertyAddress theAddress(kAudioObjectPropertyOwnedObjects);
// figure out the qualifier
UInt32 theQualifierSize = 0;
void* theQualifierData = NULL;
if(inClass != 0)
{
theQualifierSize = sizeof(AudioObjectID);
theQualifierData = &inClass;
}
// get the property data
UInt32 theDataSize = ioNumberObjects * SizeOf32(AudioClassID);
GetPropertyData(theAddress, theQualifierSize, theQualifierData, theDataSize, ioObjectIDs);
// set the number of object IDs being returned
ioNumberObjects = theDataSize / SizeOf32(AudioObjectID);
}
AudioObjectID CAHALAudioObject::GetOwnedObjectByIndex(AudioClassID inClass, UInt32 inIndex)
{
// set up the property address
CAPropertyAddress theAddress(kAudioObjectPropertyOwnedObjects);
// figure out the qualifier
UInt32 theQualifierSize = 0;
void* theQualifierData = NULL;
if(inClass != 0)
{
theQualifierSize = sizeof(AudioObjectID);
theQualifierData = &inClass;
}
// figure out how much space to allocate
UInt32 theDataSize = GetPropertyDataSize(theAddress, theQualifierSize, theQualifierData);
UInt32 theNumberObjectIDs = theDataSize / SizeOf32(AudioObjectID);
// set up the return value
AudioObjectID theAnswer = 0;
// maker sure the index is in range
if(inIndex < theNumberObjectIDs)
{
// allocate it
CAAutoArrayDelete<AudioObjectID> theObjectList(theDataSize / sizeof(AudioObjectID));
// get the property data
GetPropertyData(theAddress, theQualifierSize, theQualifierData, theDataSize, theObjectList);
// get the return value
theAnswer = theObjectList[inIndex];
}
return theAnswer;
}
bool CAHALAudioObject::HasProperty(const AudioObjectPropertyAddress& inAddress) const
{
return AudioObjectHasProperty(mObjectID, &inAddress);
}
bool CAHALAudioObject::IsPropertySettable(const AudioObjectPropertyAddress& inAddress) const
{
Boolean isSettable = false;
OSStatus theError = AudioObjectIsPropertySettable(mObjectID, &inAddress, &isSettable);
ThrowIfError(theError, CAException(theError), "CAHALAudioObject::IsPropertySettable: got an error getting info about a property");
return isSettable != 0;
}
UInt32 CAHALAudioObject::GetPropertyDataSize(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData) const
{
UInt32 theDataSize = 0;
OSStatus theError = AudioObjectGetPropertyDataSize(mObjectID, &inAddress, inQualifierDataSize, inQualifierData, &theDataSize);
ThrowIfError(theError, CAException(theError), "CAHALAudioObject::GetPropertyDataSize: got an error getting the property data size");
return theDataSize;
}
void CAHALAudioObject::GetPropertyData(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32& ioDataSize, void* outData) const
{
OSStatus theError = AudioObjectGetPropertyData(mObjectID, &inAddress, inQualifierDataSize, inQualifierData, &ioDataSize, outData);
ThrowIfError(theError, CAException(theError), "CAHALAudioObject::GetPropertyData: got an error getting the property data");
}
void CAHALAudioObject::SetPropertyData(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData)
{
OSStatus theError = AudioObjectSetPropertyData(mObjectID, &inAddress, inQualifierDataSize, inQualifierData, inDataSize, inData);
ThrowIfError(theError, CAException(theError), "CAHALAudioObject::SetPropertyData: got an error setting the property data");
}
void CAHALAudioObject::AddPropertyListener(const AudioObjectPropertyAddress& inAddress, AudioObjectPropertyListenerProc inListenerProc, void* inClientData)
{
OSStatus theError = AudioObjectAddPropertyListener(mObjectID, &inAddress, inListenerProc, inClientData);
ThrowIfError(theError, CAException(theError), "CAHALAudioObject::AddPropertyListener: got an error adding a property listener");
}
void CAHALAudioObject::RemovePropertyListener(const AudioObjectPropertyAddress& inAddress, AudioObjectPropertyListenerProc inListenerProc, void* inClientData)
{
OSStatus theError = AudioObjectRemovePropertyListener(mObjectID, &inAddress, inListenerProc, inClientData);
ThrowIfError(theError, CAException(theError), "CAHALAudioObject::RemovePropertyListener: got an error removing a property listener");
}

View File

@ -1,155 +0,0 @@
/*
File: CAHALAudioObject.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#if !defined(__CAHALAudioObject_h__)
#define __CAHALAudioObject_h__
//==================================================================================================
// Includes
//==================================================================================================
// PublicUtility Includes
#include "CADebugMacros.h"
#include "CAException.h"
// System Includes
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreAudio/CoreAudio.h>
#include <CoreFoundation/CoreFoundation.h>
#else
#include <CoreAudio.h>
#include <CoreFoundation.h>
#endif
//==================================================================================================
// CAHALAudioObject
//==================================================================================================
class CAHALAudioObject
{
// Construction/Destruction
public:
CAHALAudioObject(AudioObjectID inObjectID);
virtual ~CAHALAudioObject();
// Attributes
public:
AudioObjectID GetObjectID() const;
void SetObjectID(AudioObjectID inObjectID);
AudioClassID GetClassID() const;
AudioObjectID GetOwnerObjectID() const;
CFStringRef CopyOwningPlugInBundleID() const;
CFStringRef CopyName() const;
CFStringRef CopyManufacturer() const;
CFStringRef CopyNameForElement(AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement) const;
CFStringRef CopyCategoryNameForElement(AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement) const;
CFStringRef CopyNumberNameForElement(AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement) const;
static bool ObjectExists(AudioObjectID inObjectID);
// Owned Objects
public:
UInt32 GetNumberOwnedObjects(AudioClassID inClass) const;
void GetAllOwnedObjects(AudioClassID inClass, UInt32& ioNumberObjects, AudioObjectID* ioObjectIDs) const;
AudioObjectID GetOwnedObjectByIndex(AudioClassID inClass, UInt32 inIndex);
// Property Operations
public:
bool HasProperty(const AudioObjectPropertyAddress& inAddress) const;
bool IsPropertySettable(const AudioObjectPropertyAddress& inAddress) const;
UInt32 GetPropertyDataSize(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData) const;
void GetPropertyData(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32& ioDataSize, void* outData) const;
void SetPropertyData(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData);
UInt32 GetPropertyData_UInt32(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) const { UInt32 theAnswer = 0; UInt32 theDataSize = SizeOf32(UInt32); GetPropertyData(inAddress, inQualifierDataSize, inQualifierData, theDataSize, &theAnswer); return theAnswer; }
void SetPropertyData_UInt32(const AudioObjectPropertyAddress& inAddress, UInt32 inValue, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) { SetPropertyData(inAddress, inQualifierDataSize, inQualifierData, SizeOf32(UInt32), &inValue); }
Float32 GetPropertyData_Float32(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) const { Float32 theAnswer = 0; UInt32 theDataSize = SizeOf32(Float32); GetPropertyData(inAddress, inQualifierDataSize, inQualifierData, theDataSize, &theAnswer); return theAnswer; }
void SetPropertyData_Float32(const AudioObjectPropertyAddress& inAddress, Float32 inValue, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) { SetPropertyData(inAddress, inQualifierDataSize, inQualifierData, SizeOf32(Float32), &inValue); }
Float64 GetPropertyData_Float64(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) const { Float64 theAnswer = 0; UInt32 theDataSize = SizeOf32(Float64); GetPropertyData(inAddress, inQualifierDataSize, inQualifierData, theDataSize, &theAnswer); return theAnswer; }
void SetPropertyData_Float64(const AudioObjectPropertyAddress& inAddress, Float64 inValue, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) { SetPropertyData(inAddress, inQualifierDataSize, inQualifierData, SizeOf32(Float64), &inValue); }
CFTypeRef GetPropertyData_CFType(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) const { CFTypeRef theAnswer = NULL; UInt32 theDataSize = SizeOf32(CFTypeRef); GetPropertyData(inAddress, inQualifierDataSize, inQualifierData, theDataSize, &theAnswer); return theAnswer; }
void SetPropertyData_CFType(const AudioObjectPropertyAddress& inAddress, CFTypeRef inValue, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) { SetPropertyData(inAddress, inQualifierDataSize, inQualifierData, SizeOf32(CFTypeRef), &inValue); }
CFStringRef GetPropertyData_CFString(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) const { CFStringRef theAnswer = NULL; UInt32 theDataSize = SizeOf32(CFStringRef); GetPropertyData(inAddress, inQualifierDataSize, inQualifierData, theDataSize, &theAnswer); return theAnswer; }
void SetPropertyData_CFString(const AudioObjectPropertyAddress& inAddress, CFStringRef inValue, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) { SetPropertyData(inAddress, inQualifierDataSize, inQualifierData, SizeOf32(CFStringRef), &inValue); }
template <class T> void GetPropertyData_Struct(const AudioObjectPropertyAddress& inAddress, T& outStruct, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) const { UInt32 theDataSize = SizeOf32(T); GetPropertyData(inAddress, inQualifierDataSize, inQualifierData, theDataSize, &outStruct); }
template <class T> void SetPropertyData_Struct(const AudioObjectPropertyAddress& inAddress, T& inStruct, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) { SetPropertyData(inAddress, inQualifierDataSize, inQualifierData, SizeOf32(T), &inStruct); }
template <class T> UInt32 GetPropertyData_ArraySize(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) const { return GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData) / SizeOf32(T); }
template <class T> void GetPropertyData_Array(const AudioObjectPropertyAddress& inAddress, UInt32& ioNumberItems, T* outArray, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) const { UInt32 theDataSize = ioNumberItems * SizeOf32(T); GetPropertyData(inAddress, inQualifierDataSize, inQualifierData, theDataSize, outArray); ioNumberItems = theDataSize / SizeOf32(T); }
template <class T> void SetPropertyData_Array(const AudioObjectPropertyAddress& inAddress, UInt32 inNumberItems, T* inArray, UInt32 inQualifierDataSize = 0, const void* inQualifierData = NULL) { SetPropertyData(inAddress, inQualifierDataSize, inQualifierData, inNumberItems * SizeOf32(T), inArray); }
void AddPropertyListener(const AudioObjectPropertyAddress& inAddress, AudioObjectPropertyListenerProc inListenerProc, void* inClientData);
void RemovePropertyListener(const AudioObjectPropertyAddress& inAddress, AudioObjectPropertyListenerProc inListenerProc, void* inClientData);
void AddPropertyListenerBlock(const AudioObjectPropertyAddress& inAddress, dispatch_queue_t inDispatchQueue, AudioObjectPropertyListenerBlock inListenerBlock);
void RemovePropertyListenerBlock(const AudioObjectPropertyAddress& inAddress, dispatch_queue_t inDispatchQueue, AudioObjectPropertyListenerBlock inListenerBlock);
// Implementation
protected:
AudioObjectID mObjectID;
};
inline void CAHALAudioObject::AddPropertyListenerBlock(const AudioObjectPropertyAddress& inAddress, dispatch_queue_t inDispatchQueue, AudioObjectPropertyListenerBlock inListenerBlock)
{
OSStatus theError = AudioObjectAddPropertyListenerBlock(mObjectID, &inAddress, inDispatchQueue, inListenerBlock);
ThrowIfError(theError, CAException(theError), "CAHALAudioObject::AddPropertyListenerBlock: got an error adding a property listener");
}
inline void CAHALAudioObject::RemovePropertyListenerBlock(const AudioObjectPropertyAddress& inAddress, dispatch_queue_t inDispatchQueue, AudioObjectPropertyListenerBlock inListenerBlock)
{
OSStatus theError = AudioObjectRemovePropertyListenerBlock(mObjectID, &inAddress, inDispatchQueue, inListenerBlock);
ThrowIfError(theError, CAException(theError), "CAHALAudioObject::RemovePropertyListener: got an error removing a property listener");
}
#endif

View File

@ -1,182 +0,0 @@
/*
File: CAHALAudioStream.cpp
Abstract: CAHALAudioStream.h
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
//==================================================================================================
// Includes
//==================================================================================================
// Self Include
#include "CAHALAudioStream.h"
// PublicUtility Includes
#include "CAAutoDisposer.h"
#include "CADebugMacros.h"
#include "CAException.h"
#include "CAPropertyAddress.h"
//==================================================================================================
// CAHALAudioStream
//==================================================================================================
CAHALAudioStream::CAHALAudioStream(AudioObjectID inAudioStream)
:
CAHALAudioObject(inAudioStream)
{
}
CAHALAudioStream::~CAHALAudioStream()
{
}
UInt32 CAHALAudioStream::GetDirection() const
{
CAPropertyAddress theAddress(kAudioStreamPropertyDirection);
return GetPropertyData_UInt32(theAddress, 0, NULL);
}
UInt32 CAHALAudioStream::GetTerminalType() const
{
CAPropertyAddress theAddress(kAudioStreamPropertyTerminalType);
return GetPropertyData_UInt32(theAddress, 0, NULL);
}
UInt32 CAHALAudioStream::GetStartingChannel() const
{
CAPropertyAddress theAddress(kAudioStreamPropertyStartingChannel);
return GetPropertyData_UInt32(theAddress, 0, NULL);
}
UInt32 CAHALAudioStream::GetLatency() const
{
CAPropertyAddress theAddress(kAudioStreamPropertyLatency);
return GetPropertyData_UInt32(theAddress, 0, NULL);
}
void CAHALAudioStream::GetCurrentVirtualFormat(AudioStreamBasicDescription& outFormat) const
{
CAPropertyAddress theAddress(kAudioStreamPropertyVirtualFormat);
UInt32 theSize = sizeof(AudioStreamBasicDescription);
GetPropertyData(theAddress, 0, NULL, theSize, &outFormat);
}
void CAHALAudioStream::SetCurrentVirtualFormat(const AudioStreamBasicDescription& inFormat)
{
CAPropertyAddress theAddress(kAudioStreamPropertyVirtualFormat);
SetPropertyData(theAddress, 0, NULL, sizeof(AudioStreamBasicDescription), &inFormat);
}
UInt32 CAHALAudioStream::GetNumberAvailableVirtualFormats() const
{
CAPropertyAddress theAddress(kAudioStreamPropertyAvailableVirtualFormats);
UInt32 theAnswer = GetPropertyDataSize(theAddress, 0, NULL);
theAnswer /= SizeOf32(AudioStreamRangedDescription);
return theAnswer;
}
void CAHALAudioStream::GetAvailableVirtualFormats(UInt32& ioNumberFormats, AudioStreamRangedDescription* outFormats) const
{
CAPropertyAddress theAddress(kAudioStreamPropertyAvailableVirtualFormats);
UInt32 theSize = ioNumberFormats * SizeOf32(AudioStreamRangedDescription);
GetPropertyData(theAddress, 0, NULL, theSize, outFormats);
ioNumberFormats = theSize / SizeOf32(AudioStreamRangedDescription);
}
void CAHALAudioStream::GetAvailableVirtualFormatByIndex(UInt32 inIndex, AudioStreamRangedDescription& outFormat) const
{
UInt32 theNumberFormats = GetNumberAvailableVirtualFormats();
if((theNumberFormats > 0) && (inIndex < theNumberFormats))
{
CAAutoArrayDelete<AudioStreamRangedDescription> theFormats(theNumberFormats);
GetAvailableVirtualFormats(theNumberFormats, theFormats);
if((theNumberFormats > 0) && (inIndex < theNumberFormats))
{
outFormat = theFormats[inIndex];
}
}
}
void CAHALAudioStream::GetCurrentPhysicalFormat(AudioStreamBasicDescription& outFormat) const
{
CAPropertyAddress theAddress(kAudioStreamPropertyPhysicalFormat);
UInt32 theSize = sizeof(AudioStreamBasicDescription);
GetPropertyData(theAddress, 0, NULL, theSize, &outFormat);
}
void CAHALAudioStream::SetCurrentPhysicalFormat(const AudioStreamBasicDescription& inFormat)
{
CAPropertyAddress theAddress(kAudioStreamPropertyPhysicalFormat);
SetPropertyData(theAddress, 0, NULL, sizeof(AudioStreamBasicDescription), &inFormat);
}
UInt32 CAHALAudioStream::GetNumberAvailablePhysicalFormats() const
{
CAPropertyAddress theAddress(kAudioStreamPropertyAvailablePhysicalFormats);
UInt32 theAnswer = GetPropertyDataSize(theAddress, 0, NULL);
theAnswer /= SizeOf32(AudioStreamRangedDescription);
return theAnswer;
}
void CAHALAudioStream::GetAvailablePhysicalFormats(UInt32& ioNumberFormats, AudioStreamRangedDescription* outFormats) const
{
CAPropertyAddress theAddress(kAudioStreamPropertyAvailablePhysicalFormats);
UInt32 theSize = ioNumberFormats * SizeOf32(AudioStreamRangedDescription);
GetPropertyData(theAddress, 0, NULL, theSize, outFormats);
ioNumberFormats = theSize / SizeOf32(AudioStreamRangedDescription);
}
void CAHALAudioStream::GetAvailablePhysicalFormatByIndex(UInt32 inIndex, AudioStreamRangedDescription& outFormat) const
{
UInt32 theNumberFormats = GetNumberAvailablePhysicalFormats();
if((theNumberFormats > 0) && (inIndex < theNumberFormats))
{
CAAutoArrayDelete<AudioStreamRangedDescription> theFormats(theNumberFormats);
GetAvailablePhysicalFormats(theNumberFormats, theFormats);
if((theNumberFormats > 0) && (inIndex < theNumberFormats))
{
outFormat = theFormats[inIndex];
}
}
}

View File

@ -1,94 +0,0 @@
/*
File: CAHALAudioStream.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#if !defined(__CAHALAudioStream_h__)
#define __CAHALAudioStream_h__
//==================================================================================================
// Includes
//==================================================================================================
// Super Class Includes
#include "CAHALAudioObject.h"
//==================================================================================================
// CAHALAudioStream
//==================================================================================================
class CAHALAudioStream
:
public CAHALAudioObject
{
// Construction/Destruction
public:
CAHALAudioStream(AudioObjectID inAudioStream);
virtual ~CAHALAudioStream();
// Attributes
public:
UInt32 GetDirection() const;
UInt32 GetTerminalType() const;
UInt32 GetStartingChannel() const;
UInt32 GetLatency() const;
// Format Info
public:
void GetCurrentVirtualFormat(AudioStreamBasicDescription& outFormat) const;
void SetCurrentVirtualFormat(const AudioStreamBasicDescription& inFormat);
UInt32 GetNumberAvailableVirtualFormats() const;
void GetAvailableVirtualFormats(UInt32& ioNumberFormats, AudioStreamRangedDescription* outFormats) const;
void GetAvailableVirtualFormatByIndex(UInt32 inIndex, AudioStreamRangedDescription& outFormat) const;
void GetCurrentPhysicalFormat(AudioStreamBasicDescription& outFormat) const;
void SetCurrentPhysicalFormat(const AudioStreamBasicDescription& inFormat);
UInt32 GetNumberAvailablePhysicalFormats() const;
void GetAvailablePhysicalFormats(UInt32& ioNumberFormats, AudioStreamRangedDescription* outFormats) const;
void GetAvailablePhysicalFormatByIndex(UInt32 inIndex, AudioStreamRangedDescription& outFormat) const;
};
#endif

View File

@ -1,181 +0,0 @@
/*
File: CAHALAudioSystemObject.cpp
Abstract: CAHALAudioSystemObject.h
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
//==================================================================================================
// Includes
//==================================================================================================
// Self Include
#include "CAHALAudioSystemObject.h"
// PublicUtility Includes
#include "CAAutoDisposer.h"
#include "CACFString.h"
#include "CAHALAudioDevice.h"
#include "CAPropertyAddress.h"
//==================================================================================================
// CAHALAudioSystemObject
//==================================================================================================
CAHALAudioSystemObject::CAHALAudioSystemObject()
:
CAHALAudioObject(kAudioObjectSystemObject)
{
}
CAHALAudioSystemObject::~CAHALAudioSystemObject()
{
}
UInt32 CAHALAudioSystemObject::GetNumberAudioDevices() const
{
CAPropertyAddress theAddress(kAudioHardwarePropertyDevices);
UInt32 theAnswer = GetPropertyDataSize(theAddress, 0, NULL);
theAnswer /= SizeOf32(AudioObjectID);
return theAnswer;
}
void CAHALAudioSystemObject::GetAudioDevices(UInt32& ioNumberAudioDevices, AudioObjectID* outAudioDevices) const
{
CAPropertyAddress theAddress(kAudioHardwarePropertyDevices);
UInt32 theSize = ioNumberAudioDevices * SizeOf32(AudioObjectID);
GetPropertyData(theAddress, 0, NULL, theSize, outAudioDevices);
ioNumberAudioDevices = theSize / SizeOf32(AudioObjectID);
}
AudioObjectID CAHALAudioSystemObject::GetAudioDeviceAtIndex(UInt32 inIndex) const
{
AudioObjectID theAnswer = kAudioObjectUnknown;
UInt32 theNumberDevices = GetNumberAudioDevices();
if((theNumberDevices > 0) && (inIndex < theNumberDevices))
{
CAAutoArrayDelete<AudioObjectID> theDeviceList(theNumberDevices);
GetAudioDevices(theNumberDevices, theDeviceList);
if((theNumberDevices > 0) && (inIndex < theNumberDevices))
{
theAnswer = theDeviceList[inIndex];
}
}
return theAnswer;
}
AudioObjectID CAHALAudioSystemObject::GetAudioDeviceForUID(CFStringRef inUID) const
{
AudioObjectID theAnswer = kAudioObjectUnknown;
AudioValueTranslation theValue = { &inUID, sizeof(CFStringRef), &theAnswer, sizeof(AudioObjectID) };
CAPropertyAddress theAddress(kAudioHardwarePropertyDeviceForUID);
UInt32 theSize = sizeof(AudioValueTranslation);
GetPropertyData(theAddress, 0, NULL, theSize, &theValue);
return theAnswer;
}
void CAHALAudioSystemObject::LogBasicDeviceInfo()
{
UInt32 theNumberDevices = GetNumberAudioDevices();
CAAutoArrayDelete<AudioObjectID> theDeviceList(theNumberDevices);
GetAudioDevices(theNumberDevices, theDeviceList);
DebugMessageN1("CAHALAudioSystemObject::LogBasicDeviceInfo: %d devices", (int)theNumberDevices);
for(UInt32 theDeviceIndex = 0; theDeviceIndex < theNumberDevices; ++theDeviceIndex)
{
char theCString[256];
UInt32 theCStringSize = sizeof(theCString);
DebugMessageN1("CAHALAudioSystemObject::LogBasicDeviceInfo: Device %d", (int)theDeviceIndex);
CAHALAudioDevice theDevice(theDeviceList[theDeviceIndex]);
DebugMessageN1("CAHALAudioSystemObject::LogBasicDeviceInfo: Object ID: %d", (int)theDeviceList[theDeviceIndex]);
CACFString theDeviceName(theDevice.CopyName());
theCStringSize = sizeof(theCString);
theDeviceName.GetCString(theCString, theCStringSize);
DebugMessageN1("CAHALAudioSystemObject::LogBasicDeviceInfo: Name: %s", theCString);
CACFString theDeviceUID(theDevice.CopyDeviceUID());
theCStringSize = sizeof(theCString);
theDeviceUID.GetCString(theCString, theCStringSize);
DebugMessageN1("CAHALAudioSystemObject::LogBasicDeviceInfo: UID: %s", theCString);
}
}
static inline AudioObjectPropertySelector CAHALAudioSystemObject_CalculateDefaultDeviceProperySelector(bool inIsInput, bool inIsSystem)
{
AudioObjectPropertySelector theAnswer = kAudioHardwarePropertyDefaultOutputDevice;
if(inIsInput)
{
theAnswer = kAudioHardwarePropertyDefaultInputDevice;
}
else if(inIsSystem)
{
theAnswer = kAudioHardwarePropertyDefaultSystemOutputDevice;
}
return theAnswer;
}
AudioObjectID CAHALAudioSystemObject::GetDefaultAudioDevice(bool inIsInput, bool inIsSystem) const
{
AudioObjectID theAnswer = kAudioObjectUnknown;
CAPropertyAddress theAddress(CAHALAudioSystemObject_CalculateDefaultDeviceProperySelector(inIsInput, inIsSystem));
UInt32 theSize = sizeof(AudioObjectID);
GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
return theAnswer;
}
void CAHALAudioSystemObject::SetDefaultAudioDevice(bool inIsInput, bool inIsSystem, AudioObjectID inNewDefaultDevice)
{
CAPropertyAddress theAddress(CAHALAudioSystemObject_CalculateDefaultDeviceProperySelector(inIsInput, inIsSystem));
UInt32 theSize = sizeof(AudioObjectID);
SetPropertyData(theAddress, 0, NULL, theSize, &inNewDefaultDevice);
}
AudioObjectID CAHALAudioSystemObject::GetAudioPlugInForBundleID(CFStringRef inUID) const
{
AudioObjectID theAnswer = kAudioObjectUnknown;
AudioValueTranslation theValue = { &inUID, sizeof(CFStringRef), &theAnswer, sizeof(AudioObjectID) };
CAPropertyAddress theAddress(kAudioHardwarePropertyPlugInForBundleID);
UInt32 theSize = sizeof(AudioValueTranslation);
GetPropertyData(theAddress, 0, NULL, theSize, &theValue);
return theAnswer;
}

View File

@ -1,90 +0,0 @@
/*
File: CAHALAudioSystemObject.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#if !defined(__CAHALAudioSystemObject_h__)
#define __CAHALAudioSystemObject_h__
//==================================================================================================
// Includes
//==================================================================================================
// Super Class Includes
#include "CAHALAudioObject.h"
//==================================================================================================
// CAHALAudioSystemObject
//==================================================================================================
class CAHALAudioSystemObject
:
public CAHALAudioObject
{
// Construction/Destruction
public:
CAHALAudioSystemObject();
virtual ~CAHALAudioSystemObject();
// Audio Device List Management
public:
UInt32 GetNumberAudioDevices() const;
void GetAudioDevices(UInt32& ioNumberAudioDevices, AudioObjectID* outAudioDevices) const;
AudioObjectID GetAudioDeviceAtIndex(UInt32 inIndex) const;
AudioObjectID GetAudioDeviceForUID(CFStringRef inUID) const;
void LogBasicDeviceInfo();
// Default Device Management
public:
AudioObjectID GetDefaultAudioDevice(bool inIsInput, bool inIsSystem) const;
void SetDefaultAudioDevice(bool inIsInput, bool inIsSystem, AudioObjectID inNewDefaultDevice);
// PlugIns
public:
AudioObjectID GetAudioPlugInForBundleID(CFStringRef inBundleID) const;
};
#endif

View File

@ -1,99 +0,0 @@
/*
File: CAHostTimeBase.cpp
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
//=============================================================================
// Includes
//=============================================================================
#include "CAHostTimeBase.h"
Float64 CAHostTimeBase::sFrequency = 0;
Float64 CAHostTimeBase::sInverseFrequency = 0;
UInt32 CAHostTimeBase::sMinDelta = 0;
UInt32 CAHostTimeBase::sToNanosNumerator = 0;
UInt32 CAHostTimeBase::sToNanosDenominator = 0;
pthread_once_t CAHostTimeBase::sIsInited = PTHREAD_ONCE_INIT;
#if Track_Host_TimeBase
UInt64 CAHostTimeBase::sLastTime = 0;
#endif
//=============================================================================
// CAHostTimeBase
//
// This class provides platform independent access to the host's time base.
//=============================================================================
void CAHostTimeBase::Initialize()
{
// get the info about Absolute time
#if TARGET_OS_MAC
struct mach_timebase_info theTimeBaseInfo;
mach_timebase_info(&theTimeBaseInfo);
sMinDelta = 1;
sToNanosNumerator = theTimeBaseInfo.numer;
sToNanosDenominator = theTimeBaseInfo.denom;
// the frequency of that clock is: (sToNanosDenominator / sToNanosNumerator) * 10^9
sFrequency = static_cast<Float64>(sToNanosDenominator) / static_cast<Float64>(sToNanosNumerator);
sFrequency *= 1000000000.0;
#elif TARGET_OS_WIN32
LARGE_INTEGER theFrequency;
QueryPerformanceFrequency(&theFrequency);
sMinDelta = 1;
sToNanosNumerator = 1000000000ULL;
sToNanosDenominator = *((UInt64*)&theFrequency);
sFrequency = static_cast<Float64>(*((UInt64*)&theFrequency));
#endif
sInverseFrequency = 1.0 / sFrequency;
#if Log_Host_Time_Base_Parameters
DebugPrintf("Host Time Base Parameters");
DebugPrintf(" Minimum Delta: %lu", (unsigned long)sMinDelta);
DebugPrintf(" Frequency: %f", sFrequency);
DebugPrintf(" To Nanos Numerator: %lu", (unsigned long)sToNanosNumerator);
DebugPrintf(" To Nanos Denominator: %lu", (unsigned long)sToNanosDenominator);
#endif
}

View File

@ -1,234 +0,0 @@
/*
File: CAHostTimeBase.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
#if !defined(__CAHostTimeBase_h__)
#define __CAHostTimeBase_h__
//=============================================================================
// Includes
//=============================================================================
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreAudio/CoreAudioTypes.h>
#else
#include <CoreAudioTypes.h>
#endif
#if TARGET_OS_MAC
#include <mach/mach_time.h>
#include <pthread.h>
#elif TARGET_OS_WIN32
#include <windows.h>
#include "WinPThreadDefs.h"
#else
#error Unsupported operating system
#endif
#include "CADebugPrintf.h"
//=============================================================================
// CAHostTimeBase
//
// This class provides platform independent access to the host's time base.
//=============================================================================
#if CoreAudio_Debug
// #define Log_Host_Time_Base_Parameters 1
// #define Track_Host_TimeBase 1
#endif
class CAHostTimeBase
{
public:
static UInt64 ConvertToNanos(UInt64 inHostTime);
static UInt64 ConvertFromNanos(UInt64 inNanos);
static UInt64 GetTheCurrentTime();
#if TARGET_OS_MAC
static UInt64 GetCurrentTime() { return GetTheCurrentTime(); }
#endif
static UInt64 GetCurrentTimeInNanos();
static Float64 GetFrequency() { pthread_once(&sIsInited, Initialize); return sFrequency; }
static Float64 GetInverseFrequency() { pthread_once(&sIsInited, Initialize); return sInverseFrequency; }
static UInt32 GetMinimumDelta() { pthread_once(&sIsInited, Initialize); return sMinDelta; }
static UInt64 AbsoluteHostDeltaToNanos(UInt64 inStartTime, UInt64 inEndTime);
static SInt64 HostDeltaToNanos(UInt64 inStartTime, UInt64 inEndTime);
static UInt64 MultiplyByRatio(UInt64 inMuliplicand, UInt32 inNumerator, UInt32 inDenominator);
private:
static void Initialize();
static pthread_once_t sIsInited;
static Float64 sFrequency;
static Float64 sInverseFrequency;
static UInt32 sMinDelta;
static UInt32 sToNanosNumerator;
static UInt32 sToNanosDenominator;
#if Track_Host_TimeBase
static UInt64 sLastTime;
#endif
};
inline UInt64 CAHostTimeBase::GetTheCurrentTime()
{
UInt64 theTime = 0;
#if TARGET_OS_MAC
theTime = mach_absolute_time();
#elif TARGET_OS_WIN32
LARGE_INTEGER theValue;
QueryPerformanceCounter(&theValue);
theTime = *((UInt64*)&theValue);
#endif
#if Track_Host_TimeBase
if(sLastTime != 0)
{
if(theTime <= sLastTime)
{
DebugPrintf("CAHostTimeBase::GetTheCurrentTime: the current time is earlier than the last time, now: %qd, then: %qd", theTime, sLastTime);
}
sLastTime = theTime;
}
else
{
sLastTime = theTime;
}
#endif
return theTime;
}
inline UInt64 CAHostTimeBase::ConvertToNanos(UInt64 inHostTime)
{
pthread_once(&sIsInited, Initialize);
UInt64 theAnswer = MultiplyByRatio(inHostTime, sToNanosNumerator, sToNanosDenominator);
#if CoreAudio_Debug
if(((sToNanosNumerator > sToNanosDenominator) && (theAnswer < inHostTime)) || ((sToNanosDenominator > sToNanosNumerator) && (theAnswer > inHostTime)))
{
DebugPrintf("CAHostTimeBase::ConvertToNanos: The conversion wrapped");
}
#endif
return theAnswer;
}
inline UInt64 CAHostTimeBase::ConvertFromNanos(UInt64 inNanos)
{
pthread_once(&sIsInited, Initialize);
UInt64 theAnswer = MultiplyByRatio(inNanos, sToNanosDenominator, sToNanosNumerator);
#if CoreAudio_Debug
if(((sToNanosDenominator > sToNanosNumerator) && (theAnswer < inNanos)) || ((sToNanosNumerator > sToNanosDenominator) && (theAnswer > inNanos)))
{
DebugPrintf("CAHostTimeBase::ConvertFromNanos: The conversion wrapped");
}
#endif
return theAnswer;
}
inline UInt64 CAHostTimeBase::GetCurrentTimeInNanos()
{
return ConvertToNanos(GetTheCurrentTime());
}
inline UInt64 CAHostTimeBase::AbsoluteHostDeltaToNanos(UInt64 inStartTime, UInt64 inEndTime)
{
UInt64 theAnswer;
if(inStartTime <= inEndTime)
{
theAnswer = inEndTime - inStartTime;
}
else
{
theAnswer = inStartTime - inEndTime;
}
return ConvertToNanos(theAnswer);
}
inline SInt64 CAHostTimeBase::HostDeltaToNanos(UInt64 inStartTime, UInt64 inEndTime)
{
SInt64 theAnswer;
SInt64 theSign = 1;
if(inStartTime <= inEndTime)
{
theAnswer = static_cast<SInt64>(inEndTime - inStartTime);
}
else
{
theAnswer = static_cast<SInt64>(inStartTime - inEndTime);
theSign = -1;
}
return theSign * static_cast<SInt64>(ConvertToNanos(static_cast<UInt64>(theAnswer)));
}
inline UInt64 CAHostTimeBase::MultiplyByRatio(UInt64 inMuliplicand, UInt32 inNumerator, UInt32 inDenominator)
{
#if TARGET_OS_MAC && TARGET_RT_64_BIT
__uint128_t theAnswer = inMuliplicand;
#else
long double theAnswer = inMuliplicand;
#endif
if(inNumerator != inDenominator)
{
theAnswer *= inNumerator;
theAnswer /= inDenominator;
}
return static_cast<UInt64>(theAnswer);
}
#endif

View File

@ -1,345 +0,0 @@
/*
File: CAMutex.cpp
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
//==================================================================================================
// Includes
//==================================================================================================
// Self Include
#include "CAMutex.h"
#if TARGET_OS_MAC
#include <errno.h>
#endif
// PublicUtility Includes
#include "CADebugMacros.h"
#include "CAException.h"
#include "CAHostTimeBase.h"
//==================================================================================================
// Logging
//==================================================================================================
#if CoreAudio_Debug
// #define Log_Ownership 1
// #define Log_Errors 1
// #define Log_LongLatencies 1
// #define LongLatencyThreshholdNS 1000000ULL // nanoseconds
#endif
//==================================================================================================
// CAMutex
//==================================================================================================
CAMutex::CAMutex(const char* inName)
:
mName(inName),
mOwner(0)
{
#if TARGET_OS_MAC
OSStatus theError = pthread_mutex_init(&mMutex, NULL);
ThrowIf(theError != 0, CAException(theError), "CAMutex::CAMutex: Could not init the mutex");
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: CAMutex::CAMutex: creating %s, owner: %p\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), mName, mOwner);
#endif
#elif TARGET_OS_WIN32
mMutex = CreateMutex(NULL, false, NULL);
ThrowIfNULL(mMutex, CAException(GetLastError()), "CAMutex::CAMutex: could not create the mutex.");
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%lu %.4f: CAMutex::CAMutex: creating %s, owner: %lu\n", GetCurrentThreadId(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), mName, mOwner);
#endif
#endif
}
CAMutex::~CAMutex()
{
#if TARGET_OS_MAC
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: CAMutex::~CAMutex: destroying %s, owner: %p\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), mName, mOwner);
#endif
pthread_mutex_destroy(&mMutex);
#elif TARGET_OS_WIN32
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%lu %.4f: CAMutex::~CAMutex: destroying %s, owner: %lu\n", GetCurrentThreadId(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), mName, mOwner);
#endif
if(mMutex != NULL)
{
CloseHandle(mMutex);
}
#endif
}
bool CAMutex::Lock()
{
bool theAnswer = false;
#if TARGET_OS_MAC
pthread_t theCurrentThread = pthread_self();
if(!pthread_equal(theCurrentThread, mOwner))
{
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: CAMutex::Lock: thread %p is locking %s, owner: %p\n", theCurrentThread, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), theCurrentThread, mName, mOwner);
#endif
#if Log_LongLatencies
UInt64 lockTryTime = CAHostTimeBase::GetCurrentTimeInNanos();
#endif
OSStatus theError = pthread_mutex_lock(&mMutex);
ThrowIf(theError != 0, CAException(theError), "CAMutex::Lock: Could not lock the mutex");
mOwner = theCurrentThread;
theAnswer = true;
#if Log_LongLatencies
UInt64 lockAcquireTime = CAHostTimeBase::GetCurrentTimeInNanos();
if (lockAcquireTime - lockTryTime >= LongLatencyThresholdNS)
DebugPrintfRtn(DebugPrintfFileComma "Thread %p took %.6fs to acquire the lock %s\n", theCurrentThread, (lockAcquireTime - lockTryTime) * 1.0e-9 /* nanos to seconds */, mName);
#endif
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: CAMutex::Lock: thread %p has locked %s, owner: %p\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), pthread_self(), mName, mOwner);
#endif
}
#elif TARGET_OS_WIN32
if(mOwner != GetCurrentThreadId())
{
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%lu %.4f: CAMutex::Lock: thread %lu is locking %s, owner: %lu\n", GetCurrentThreadId(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), GetCurrentThreadId(), mName, mOwner);
#endif
OSStatus theError = WaitForSingleObject(mMutex, INFINITE);
ThrowIfError(theError, CAException(theError), "CAMutex::Lock: could not lock the mutex");
mOwner = GetCurrentThreadId();
theAnswer = true;
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%lu %.4f: CAMutex::Lock: thread %lu has locked %s, owner: %lu\n", GetCurrentThreadId(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), GetCurrentThreadId(), mName, mOwner);
#endif
}
#endif
return theAnswer;
}
void CAMutex::Unlock()
{
#if TARGET_OS_MAC
if(pthread_equal(pthread_self(), mOwner))
{
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: CAMutex::Unlock: thread %p is unlocking %s, owner: %p\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), pthread_self(), mName, mOwner);
#endif
mOwner = 0;
OSStatus theError = pthread_mutex_unlock(&mMutex);
ThrowIf(theError != 0, CAException(theError), "CAMutex::Unlock: Could not unlock the mutex");
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: CAMutex::Unlock: thread %p has unlocked %s, owner: %p\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), pthread_self(), mName, mOwner);
#endif
}
else
{
DebugMessage("CAMutex::Unlock: A thread is attempting to unlock a Mutex it doesn't own");
}
#elif TARGET_OS_WIN32
if(mOwner == GetCurrentThreadId())
{
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%lu %.4f: CAMutex::Unlock: thread %lu is unlocking %s, owner: %lu\n", GetCurrentThreadId(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), GetCurrentThreadId(), mName, mOwner);
#endif
mOwner = 0;
bool wasReleased = ReleaseMutex(mMutex);
ThrowIf(!wasReleased, CAException(GetLastError()), "CAMutex::Unlock: Could not unlock the mutex");
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%lu %.4f: CAMutex::Unlock: thread %lu has unlocked %s, owner: %lu\n", GetCurrentThreadId(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), GetCurrentThreadId(), mName, mOwner);
#endif
}
else
{
DebugMessage("CAMutex::Unlock: A thread is attempting to unlock a Mutex it doesn't own");
}
#endif
}
bool CAMutex::Try(bool& outWasLocked)
{
bool theAnswer = false;
outWasLocked = false;
#if TARGET_OS_MAC
pthread_t theCurrentThread = pthread_self();
if(!pthread_equal(theCurrentThread, mOwner))
{
// this means the current thread doesn't already own the lock
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: CAMutex::Try: thread %p is try-locking %s, owner: %p\n", theCurrentThread, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), theCurrentThread, mName, mOwner);
#endif
// go ahead and call trylock to see if we can lock it.
int theError = pthread_mutex_trylock(&mMutex);
if(theError == 0)
{
// return value of 0 means we successfully locked the lock
mOwner = theCurrentThread;
theAnswer = true;
outWasLocked = true;
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: CAMutex::Try: thread %p has locked %s, owner: %p\n", theCurrentThread, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), theCurrentThread, mName, mOwner);
#endif
}
else if(theError == EBUSY)
{
// return value of EBUSY means that the lock was already locked by another thread
theAnswer = false;
outWasLocked = false;
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: CAMutex::Try: thread %p failed to lock %s, owner: %p\n", theCurrentThread, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), theCurrentThread, mName, mOwner);
#endif
}
else
{
// any other return value means something really bad happenned
ThrowIfError(theError, CAException(theError), "CAMutex::Try: call to pthread_mutex_trylock failed");
}
}
else
{
// this means the current thread already owns the lock
theAnswer = true;
outWasLocked = false;
}
#elif TARGET_OS_WIN32
if(mOwner != GetCurrentThreadId())
{
// this means the current thread doesn't own the lock
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%lu %.4f: CAMutex::Try: thread %lu is try-locking %s, owner: %lu\n", GetCurrentThreadId(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), GetCurrentThreadId(), mName, mOwner);
#endif
// try to acquire the mutex
OSStatus theError = WaitForSingleObject(mMutex, 0);
if(theError == WAIT_OBJECT_0)
{
// this means we successfully locked the lock
mOwner = GetCurrentThreadId();
theAnswer = true;
outWasLocked = true;
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%lu %.4f: CAMutex::Try: thread %lu has locked %s, owner: %lu\n", GetCurrentThreadId(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), GetCurrentThreadId(), mName, mOwner);
#endif
}
else if(theError == WAIT_TIMEOUT)
{
// this means that the lock was already locked by another thread
theAnswer = false;
outWasLocked = false;
#if Log_Ownership
DebugPrintfRtn(DebugPrintfFileComma "%lu %.4f: CAMutex::Try: thread %lu failed to lock %s, owner: %lu\n", GetCurrentThreadId(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), GetCurrentThreadId(), mName, mOwner);
#endif
}
else
{
// any other return value means something really bad happenned
ThrowIfError(theError, CAException(GetLastError()), "CAMutex::Try: call to lock the mutex failed");
}
}
else
{
// this means the current thread already owns the lock
theAnswer = true;
outWasLocked = false;
}
#endif
return theAnswer;
}
bool CAMutex::IsFree() const
{
return mOwner == 0;
}
bool CAMutex::IsOwnedByCurrentThread() const
{
bool theAnswer = true;
#if TARGET_OS_MAC
theAnswer = pthread_equal(pthread_self(), mOwner);
#elif TARGET_OS_WIN32
theAnswer = (mOwner == GetCurrentThreadId());
#endif
return theAnswer;
}
CAMutex::Unlocker::Unlocker(CAMutex& inMutex)
: mMutex(inMutex),
mNeedsLock(false)
{
Assert(mMutex.IsOwnedByCurrentThread(), "Major problem: Unlocker attempted to unlock a mutex not owned by the current thread!");
mMutex.Unlock();
mNeedsLock = true;
}
CAMutex::Unlocker::~Unlocker()
{
if(mNeedsLock)
{
mMutex.Lock();
}
}

View File

@ -1,164 +0,0 @@
/*
File: CAMutex.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
#ifndef __CAMutex_h__
#define __CAMutex_h__
//==================================================================================================
// Includes
//==================================================================================================
// System Includes
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreAudio/CoreAudioTypes.h>
#else
#include <CoreAudioTypes.h>
#endif
#if TARGET_OS_MAC
#include <pthread.h>
#elif TARGET_OS_WIN32
#include <windows.h>
#else
#error Unsupported operating system
#endif
//==================================================================================================
// A recursive mutex.
//==================================================================================================
class CAMutex
{
// Construction/Destruction
public:
CAMutex(const char* inName);
virtual ~CAMutex();
// Actions
public:
virtual bool Lock();
virtual void Unlock();
virtual bool Try(bool& outWasLocked); // returns true if lock is free, false if not
virtual bool IsFree() const;
virtual bool IsOwnedByCurrentThread() const;
// Implementation
protected:
const char* mName;
#if TARGET_OS_MAC
pthread_t mOwner;
pthread_mutex_t mMutex;
#elif TARGET_OS_WIN32
UInt32 mOwner;
HANDLE mMutex;
#endif
// Helper class to manage taking and releasing recursively
public:
class Locker
{
// Construction/Destruction
public:
Locker(CAMutex& inMutex) : mMutex(&inMutex), mNeedsRelease(false) { mNeedsRelease = mMutex->Lock(); }
Locker(const CAMutex& inMutex) : mMutex(const_cast<CAMutex*>(&inMutex)), mNeedsRelease(false) { mNeedsRelease = mMutex->Lock(); }
Locker(CAMutex* inMutex) : mMutex(inMutex), mNeedsRelease(false) { mNeedsRelease = (mMutex != NULL && mMutex->Lock()); }
// in this case the mutex can be null
~Locker() { if(mNeedsRelease) { mMutex->Unlock(); } }
private:
Locker(const Locker&);
Locker& operator=(const Locker&);
// Implementation
private:
CAMutex* mMutex;
bool mNeedsRelease;
};
// Unlocker
class Unlocker
{
public:
Unlocker(CAMutex& inMutex);
~Unlocker();
private:
CAMutex& mMutex;
bool mNeedsLock;
// Hidden definitions of copy ctor, assignment operator
Unlocker(const Unlocker& copy); // Not implemented
Unlocker& operator=(const Unlocker& copy); // Not implemented
};
// you can use this with Try - if you take the lock in try, pass in the outWasLocked var
class Tryer {
// Construction/Destruction
public:
Tryer (CAMutex &mutex) : mMutex(mutex), mNeedsRelease(false), mHasLock(false) { mHasLock = mMutex.Try (mNeedsRelease); }
~Tryer () { if (mNeedsRelease) mMutex.Unlock(); }
bool HasLock () const { return mHasLock; }
private:
Tryer(const Tryer&);
Tryer& operator=(const Tryer&);
// Implementation
private:
CAMutex & mMutex;
bool mNeedsRelease;
bool mHasLock;
};
};
#endif // __CAMutex_h__

View File

@ -1,450 +0,0 @@
/*
File: CAPThread.cpp
Abstract: CAPThread.h
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
//=============================================================================
// Includes
//=============================================================================
// Self Include
#include "CAPThread.h"
// PublicUtility Includes
#include "CADebugMacros.h"
#include "CAException.h"
// System Includes
#if TARGET_OS_MAC
#include <mach/mach.h>
#endif
// Standard Library Includes
#include <stdio.h>
//==================================================================================================
// CAPThread
//==================================================================================================
// returns the thread's priority as it was last set by the API
#define CAPTHREAD_SET_PRIORITY 0
// returns the thread's priority as it was last scheduled by the Kernel
#define CAPTHREAD_SCHEDULED_PRIORITY 1
//#define Log_SetPriority 1
CAPThread::CAPThread(ThreadRoutine inThreadRoutine, void* inParameter, UInt32 inPriority, bool inFixedPriority, bool inAutoDelete, const char* inThreadName)
:
#if TARGET_OS_MAC
mPThread(0),
mSpawningThreadPriority(getScheduledPriority(pthread_self(), CAPTHREAD_SET_PRIORITY)),
#elif TARGET_OS_WIN32
mThreadHandle(NULL),
mThreadID(0),
#endif
mThreadRoutine(inThreadRoutine),
mThreadParameter(inParameter),
mPriority(inPriority),
mPeriod(0),
mComputation(0),
mConstraint(0),
mIsPreemptible(true),
mTimeConstraintSet(false),
mFixedPriority(inFixedPriority),
mAutoDelete(inAutoDelete)
{
if(inThreadName != NULL)
{
strlcpy(mThreadName, inThreadName, kMaxThreadNameLength);
}
else
{
memset(mThreadName, 0, kMaxThreadNameLength);
}
}
CAPThread::CAPThread(ThreadRoutine inThreadRoutine, void* inParameter, UInt32 inPeriod, UInt32 inComputation, UInt32 inConstraint, bool inIsPreemptible, bool inAutoDelete, const char* inThreadName)
:
#if TARGET_OS_MAC
mPThread(0),
mSpawningThreadPriority(getScheduledPriority(pthread_self(), CAPTHREAD_SET_PRIORITY)),
#elif TARGET_OS_WIN32
mThreadHandle(NULL),
mThreadID(0),
#endif
mThreadRoutine(inThreadRoutine),
mThreadParameter(inParameter),
mPriority(kDefaultThreadPriority),
mPeriod(inPeriod),
mComputation(inComputation),
mConstraint(inConstraint),
mIsPreemptible(inIsPreemptible),
mTimeConstraintSet(true),
mFixedPriority(false),
mAutoDelete(inAutoDelete)
{
if(inThreadName != NULL)
{
strlcpy(mThreadName, inThreadName, kMaxThreadNameLength);
}
else
{
memset(mThreadName, 0, kMaxThreadNameLength);
}
}
CAPThread::~CAPThread()
{
}
UInt32 CAPThread::GetScheduledPriority()
{
#if TARGET_OS_MAC
return CAPThread::getScheduledPriority( mPThread, CAPTHREAD_SCHEDULED_PRIORITY );
#elif TARGET_OS_WIN32
UInt32 theAnswer = 0;
if(mThreadHandle != NULL)
{
theAnswer = GetThreadPriority(mThreadHandle);
}
return theAnswer;
#endif
}
UInt32 CAPThread::GetScheduledPriority(NativeThread thread)
{
#if TARGET_OS_MAC
return getScheduledPriority( thread, CAPTHREAD_SCHEDULED_PRIORITY );
#elif TARGET_OS_WIN32
return 0; // ???
#endif
}
void CAPThread::SetPriority(UInt32 inPriority, bool inFixedPriority)
{
mPriority = inPriority;
mTimeConstraintSet = false;
mFixedPriority = inFixedPriority;
#if TARGET_OS_MAC
if(mPThread != 0)
{
SetPriority(mPThread, mPriority, mFixedPriority);
}
#elif TARGET_OS_WIN32
if(mThreadID != NULL)
{
SetPriority(mThreadID, mPriority, mFixedPriority);
}
#endif
}
void CAPThread::SetPriority(NativeThread inThread, UInt32 inPriority, bool inFixedPriority)
{
#if TARGET_OS_MAC
if(inThread != 0)
{
kern_return_t theError = 0;
// set whether or not this is a fixed priority thread
if (inFixedPriority)
{
thread_extended_policy_data_t theFixedPolicy = { false };
theError = thread_policy_set(pthread_mach_thread_np(inThread), THREAD_EXTENDED_POLICY, (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT);
AssertNoKernelError(theError, "CAPThread::SetPriority: failed to set the fixed-priority policy");
}
// set the thread's absolute priority which is relative to the priority on which thread_policy_set() is called
UInt32 theCurrentThreadPriority = getScheduledPriority(pthread_self(), CAPTHREAD_SET_PRIORITY);
thread_precedence_policy_data_t thePrecedencePolicy = { static_cast<integer_t>(inPriority - theCurrentThreadPriority) };
theError = thread_policy_set(pthread_mach_thread_np(inThread), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&thePrecedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT);
AssertNoKernelError(theError, "CAPThread::SetPriority: failed to set the precedence policy");
#if Log_SetPriority
DebugMessageN4("CAPThread::SetPriority: requsted: %lu spawning: %lu current: %lu assigned: %d", mPriority, mSpawningThreadPriority, theCurrentThreadPriority, thePrecedencePolicy.importance);
#endif
}
#elif TARGET_OS_WIN32
if(inThread != NULL)
{
HANDLE hThread = OpenThread(NULL, FALSE, inThread);
if(hThread != NULL) {
SetThreadPriority(hThread, inPriority);
CloseHandle(hThread);
}
}
#endif
}
void CAPThread::SetTimeConstraints(UInt32 inPeriod, UInt32 inComputation, UInt32 inConstraint, bool inIsPreemptible)
{
mPeriod = inPeriod;
mComputation = inComputation;
mConstraint = inConstraint;
mIsPreemptible = inIsPreemptible;
mTimeConstraintSet = true;
#if TARGET_OS_MAC
if(mPThread != 0)
{
thread_time_constraint_policy_data_t thePolicy;
thePolicy.period = mPeriod;
thePolicy.computation = mComputation;
thePolicy.constraint = mConstraint;
thePolicy.preemptible = mIsPreemptible;
AssertNoError(thread_policy_set(pthread_mach_thread_np(mPThread), THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t)&thePolicy, THREAD_TIME_CONSTRAINT_POLICY_COUNT), "CAPThread::SetTimeConstraints: thread_policy_set failed");
}
#elif TARGET_OS_WIN32
if(mThreadHandle != NULL)
{
SetThreadPriority(mThreadHandle, THREAD_PRIORITY_TIME_CRITICAL);
}
#endif
}
void CAPThread::Start()
{
#if TARGET_OS_MAC
Assert(mPThread == 0, "CAPThread::Start: can't start because the thread is already running");
if(mPThread == 0)
{
OSStatus theResult;
pthread_attr_t theThreadAttributes;
theResult = pthread_attr_init(&theThreadAttributes);
ThrowIf(theResult != 0, CAException(theResult), "CAPThread::Start: Thread attributes could not be created.");
theResult = pthread_attr_setdetachstate(&theThreadAttributes, PTHREAD_CREATE_DETACHED);
ThrowIf(theResult != 0, CAException(theResult), "CAPThread::Start: A thread could not be created in the detached state.");
theResult = pthread_create(&mPThread, &theThreadAttributes, (ThreadRoutine)CAPThread::Entry, this);
ThrowIf(theResult != 0 || !mPThread, CAException(theResult), "CAPThread::Start: Could not create a thread.");
pthread_attr_destroy(&theThreadAttributes);
}
#elif TARGET_OS_WIN32
Assert(mThreadID == 0, "CAPThread::Start: can't start because the thread is already running");
if(mThreadID == 0)
{
// clean up the existing thread handle
if(mThreadHandle != NULL)
{
CloseHandle(mThreadHandle);
mThreadHandle = NULL;
}
// create a new thread
mThreadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Entry, this, 0, &mThreadID);
ThrowIf(mThreadHandle == NULL, CAException(GetLastError()), "CAPThread::Start: Could not create a thread.");
}
#endif
}
#if TARGET_OS_MAC
void* CAPThread::Entry(CAPThread* inCAPThread)
{
void* theAnswer = NULL;
#if TARGET_OS_MAC
inCAPThread->mPThread = pthread_self();
#elif TARGET_OS_WIN32
// do we need to do something here?
#endif
#if !TARGET_OS_IPHONE && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
if(inCAPThread->mThreadName[0] != 0)
{
pthread_setname_np(inCAPThread->mThreadName);
}
#endif
try
{
if(inCAPThread->mTimeConstraintSet)
{
inCAPThread->SetTimeConstraints(inCAPThread->mPeriod, inCAPThread->mComputation, inCAPThread->mConstraint, inCAPThread->mIsPreemptible);
}
else
{
inCAPThread->SetPriority(inCAPThread->mPriority, inCAPThread->mFixedPriority);
}
if(inCAPThread->mThreadRoutine != NULL)
{
theAnswer = inCAPThread->mThreadRoutine(inCAPThread->mThreadParameter);
}
}
catch (...)
{
// what should be done here?
}
inCAPThread->mPThread = 0;
if (inCAPThread->mAutoDelete)
delete inCAPThread;
return theAnswer;
}
UInt32 CAPThread::getScheduledPriority(pthread_t inThread, int inPriorityKind)
{
thread_basic_info_data_t threadInfo;
policy_info_data_t thePolicyInfo;
unsigned int count;
if (inThread == NULL)
return 0;
// get basic info
count = THREAD_BASIC_INFO_COUNT;
thread_info (pthread_mach_thread_np (inThread), THREAD_BASIC_INFO, (thread_info_t)&threadInfo, &count);
switch (threadInfo.policy) {
case POLICY_TIMESHARE:
count = POLICY_TIMESHARE_INFO_COUNT;
thread_info(pthread_mach_thread_np (inThread), THREAD_SCHED_TIMESHARE_INFO, (thread_info_t)&(thePolicyInfo.ts), &count);
if (inPriorityKind == CAPTHREAD_SCHEDULED_PRIORITY) {
return static_cast<UInt32>(thePolicyInfo.ts.cur_priority);
}
return static_cast<UInt32>(thePolicyInfo.ts.base_priority);
break;
case POLICY_FIFO:
count = POLICY_FIFO_INFO_COUNT;
thread_info(pthread_mach_thread_np (inThread), THREAD_SCHED_FIFO_INFO, (thread_info_t)&(thePolicyInfo.fifo), &count);
if ( (thePolicyInfo.fifo.depressed) && (inPriorityKind == CAPTHREAD_SCHEDULED_PRIORITY) ) {
return static_cast<UInt32>(thePolicyInfo.fifo.depress_priority);
}
return static_cast<UInt32>(thePolicyInfo.fifo.base_priority);
break;
case POLICY_RR:
count = POLICY_RR_INFO_COUNT;
thread_info(pthread_mach_thread_np (inThread), THREAD_SCHED_RR_INFO, (thread_info_t)&(thePolicyInfo.rr), &count);
if ( (thePolicyInfo.rr.depressed) && (inPriorityKind == CAPTHREAD_SCHEDULED_PRIORITY) ) {
return static_cast<UInt32>(thePolicyInfo.rr.depress_priority);
}
return static_cast<UInt32>(thePolicyInfo.rr.base_priority);
break;
}
return 0;
}
#elif TARGET_OS_WIN32
UInt32 WINAPI CAPThread::Entry(CAPThread* inCAPThread)
{
UInt32 theAnswer = 0;
try
{
if(inCAPThread->mTimeConstraintSet)
{
inCAPThread->SetTimeConstraints(inCAPThread->mPeriod, inCAPThread->mComputation, inCAPThread->mConstraint, inCAPThread->mIsPreemptible);
}
else
{
inCAPThread->SetPriority(inCAPThread->mPriority, inCAPThread->mFixedPriority);
}
if(inCAPThread->mThreadRoutine != NULL)
{
theAnswer = reinterpret_cast<UInt32>(inCAPThread->mThreadRoutine(inCAPThread->mThreadParameter));
}
inCAPThread->mThreadID = 0;
}
catch (...)
{
// what should be done here?
}
CloseHandle(inCAPThread->mThreadHandle);
inCAPThread->mThreadHandle = NULL;
if (inCAPThread->mAutoDelete)
delete inCAPThread;
return theAnswer;
}
extern "C"
Boolean CompareAndSwap(UInt32 inOldValue, UInt32 inNewValue, UInt32* inOldValuePtr)
{
return InterlockedCompareExchange((volatile LONG*)inOldValuePtr, inNewValue, inOldValue) == inOldValue;
}
#endif
void CAPThread::SetName(const char* inThreadName)
{
if(inThreadName != NULL)
{
strlcpy(mThreadName, inThreadName, kMaxThreadNameLength);
}
else
{
memset(mThreadName, 0, kMaxThreadNameLength);
}
}
#if CoreAudio_Debug
void CAPThread::DebugPriority(const char *label)
{
#if !TARGET_OS_WIN32
if (mTimeConstraintSet)
printf("CAPThread::%s %p: pri=<time constraint>, spawning pri=%d, scheduled pri=%d\n", label, this,
(int)mSpawningThreadPriority, (mPThread != NULL) ? (int)GetScheduledPriority() : -1);
else
printf("CAPThread::%s %p: pri=%d%s, spawning pri=%d, scheduled pri=%d\n", label, this, (int)mPriority, mFixedPriority ? " fixed" : "",
(int)mSpawningThreadPriority, (mPThread != NULL) ? (int)GetScheduledPriority() : -1);
#else
if (mTimeConstraintSet)
{
printf("CAPThread::%s %p: pri=<time constraint>, spawning pri=%d, scheduled pri=%d\n", label, this,
(int)mPriority, (mThreadHandle != NULL) ? (int)GetScheduledPriority() : -1);
}
else
{
printf("CAPThread::%s %p: pri=%d%s, spawning pri=%d, scheduled pri=%d\n", label, this, (int)mPriority, mFixedPriority ? " fixed" : "",
(int)mPriority, (mThreadHandle != NULL) ? (int)GetScheduledPriority() : -1);
}
#endif
}
#endif

View File

@ -1,191 +0,0 @@
/*
File: CAPThread.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#if !defined(__CAPThread_h__)
#define __CAPThread_h__
//==================================================================================================
// Includes
//==================================================================================================
// System Includes
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreFoundation/CFBase.h>
#else
#include <CFBase.h>
#endif
#if TARGET_OS_MAC
#include <pthread.h>
#include <unistd.h>
#elif TARGET_OS_WIN32
#include <windows.h>
#else
#error Unsupported operating system
#endif
//==================================================================================================
// CAPThread
//
// This class wraps a pthread and a Win32 thread.
// caution: long-running fixed priority threads can make the system unresponsive
//==================================================================================================
class CAPThread
{
// Types
public:
typedef void* (*ThreadRoutine)(void* inParameter);
// Constants
public:
enum
{
#if TARGET_OS_MAC
kMinThreadPriority = 1,
kMaxThreadPriority = 63,
kDefaultThreadPriority = 31,
kMaxThreadNameLength = 64
#elif TARGET_OS_WIN32
kMinThreadPriority = 1,
kMaxThreadPriority = 31,
kDefaultThreadPriority = THREAD_PRIORITY_NORMAL,
kMaxThreadNameLength = 256
#endif
};
// Construction/Destruction
public:
CAPThread(ThreadRoutine inThreadRoutine, void* inParameter, UInt32 inPriority = kDefaultThreadPriority, bool inFixedPriority=false, bool inAutoDelete=false, const char* inThreadName = NULL);
CAPThread(ThreadRoutine inThreadRoutine, void* inParameter, UInt32 inPeriod, UInt32 inComputation, UInt32 inConstraint, bool inIsPreemptible, bool inAutoDelete=false, const char* inThreadName = NULL);
virtual ~CAPThread();
// Properties
public:
#if TARGET_OS_MAC
typedef pthread_t NativeThread;
NativeThread GetNativeThread() { return mPThread; }
static NativeThread GetCurrentThread() { return pthread_self(); }
static bool IsNativeThreadsEqual(NativeThread a, NativeThread b) { return (a==b); }
bool operator==(NativeThread b) { return pthread_equal(mPThread,b); }
pthread_t GetPThread() const { return mPThread; }
bool IsCurrentThread() const { return (0 != mPThread) && (pthread_self() == mPThread); }
bool IsRunning() const { return 0 != mPThread; }
static UInt32 getScheduledPriority(pthread_t inThread, int inPriorityKind);
#elif TARGET_OS_WIN32
typedef unsigned long NativeThread;
NativeThread GetNativeThread() { return mThreadID; }
static NativeThread GetCurrentThread() { return GetCurrentThreadId(); }
static bool IsNativeThreadsEqual(NativeThread a, NativeThread b) { return (a==b); }
bool operator ==(NativeThread b) { return (mThreadID==b); }
HANDLE GetThreadHandle() const { return mThreadHandle; }
UInt32 GetThreadID() const { return mThreadID; }
bool IsCurrentThread() const { return (0 != mThreadID) && (GetCurrentThreadId() == mThreadID); }
bool IsRunning() const { return 0 != mThreadID; }
#endif
bool IsTimeShareThread() const { return !mTimeConstraintSet; }
bool IsTimeConstraintThread() const { return mTimeConstraintSet; }
UInt32 GetPriority() const { return mPriority; }
UInt32 GetScheduledPriority();
static UInt32 GetScheduledPriority(NativeThread thread);
void SetPriority(UInt32 inPriority, bool inFixedPriority=false);
static void SetPriority(NativeThread inThread, UInt32 inPriority, bool inFixedPriority = false);
void GetTimeConstraints(UInt32& outPeriod, UInt32& outComputation, UInt32& outConstraint, bool& outIsPreemptible) const { outPeriod = mPeriod; outComputation = mComputation; outConstraint = mConstraint; outIsPreemptible = mIsPreemptible; }
void SetTimeConstraints(UInt32 inPeriod, UInt32 inComputation, UInt32 inConstraint, bool inIsPreemptible);
void ClearTimeConstraints() { SetPriority(mPriority); }
bool WillAutoDelete() const { return mAutoDelete; }
void SetAutoDelete(bool b) { mAutoDelete = b; }
void SetName(const char* inThreadName);
#if CoreAudio_Debug
void DebugPriority(const char *label);
#endif
// Actions
public:
virtual void Start();
// Implementation
protected:
#if TARGET_OS_MAC
static void* Entry(CAPThread* inCAPThread);
#elif TARGET_OS_WIN32
static UInt32 WINAPI Entry(CAPThread* inCAPThread);
#endif
#if TARGET_OS_MAC
pthread_t mPThread;
UInt32 mSpawningThreadPriority;
#elif TARGET_OS_WIN32
HANDLE mThreadHandle;
unsigned long mThreadID;
#endif
ThreadRoutine mThreadRoutine;
void* mThreadParameter;
char mThreadName[kMaxThreadNameLength];
UInt32 mPriority;
UInt32 mPeriod;
UInt32 mComputation;
UInt32 mConstraint;
bool mIsPreemptible;
bool mTimeConstraintSet;
bool mFixedPriority;
bool mAutoDelete; // delete self when thread terminates
};
#endif

View File

@ -1,312 +0,0 @@
/*
File: CAPropertyAddress.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#if !defined(__CAPropertyAddress_h__)
#define __CAPropertyAddress_h__
//==================================================================================================
// Includes
//==================================================================================================
// PublicUtility Includes
#include "CADebugMacros.h"
// System Includes
#include <CoreAudio/AudioHardware.h>
// Standard Library Includes
#include <algorithm>
#include <functional>
#include <vector>
//==================================================================================================
// CAPropertyAddress
//
// CAPropertyAddress extends the AudioObjectPropertyAddress structure to C++ including constructors
// and other utility operations. Note that there is no defined operator< or operator== because the
// presence of wildcards for the fields make comparisons ambiguous without specifying whether or
// not to take the wildcards into account. Consequently, if you want to use this struct in an STL
// data structure, you'll need to specify the approriate function object explicitly in the template
// declaration.
//==================================================================================================
struct CAPropertyAddress
:
public AudioObjectPropertyAddress
{
// Construction/Destruction
public:
CAPropertyAddress() : AudioObjectPropertyAddress() { mSelector = 0; mScope = kAudioObjectPropertyScopeGlobal; mElement = kAudioObjectPropertyElementMaster; }
CAPropertyAddress(AudioObjectPropertySelector inSelector) : AudioObjectPropertyAddress() { mSelector = inSelector; mScope = kAudioObjectPropertyScopeGlobal; mElement = kAudioObjectPropertyElementMaster; }
CAPropertyAddress(AudioObjectPropertySelector inSelector, AudioObjectPropertyScope inScope) : AudioObjectPropertyAddress() { mSelector = inSelector; mScope = inScope; mElement = kAudioObjectPropertyElementMaster; }
CAPropertyAddress(AudioObjectPropertySelector inSelector, AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement) : AudioObjectPropertyAddress() { mSelector = inSelector; mScope = inScope; mElement = inElement; }
CAPropertyAddress(const AudioObjectPropertyAddress& inAddress) : AudioObjectPropertyAddress(inAddress){}
CAPropertyAddress(const CAPropertyAddress& inAddress) : AudioObjectPropertyAddress(inAddress){}
CAPropertyAddress& operator=(const AudioObjectPropertyAddress& inAddress) { AudioObjectPropertyAddress::operator=(inAddress); return *this; }
CAPropertyAddress& operator=(const CAPropertyAddress& inAddress) { AudioObjectPropertyAddress::operator=(inAddress); return *this; }
// Operations
public:
static bool IsSameAddress(const AudioObjectPropertyAddress& inAddress1, const AudioObjectPropertyAddress& inAddress2) { return (inAddress1.mScope == inAddress2.mScope) && (inAddress1.mSelector == inAddress2.mSelector) && (inAddress1.mElement == inAddress2.mElement); }
static bool IsLessThanAddress(const AudioObjectPropertyAddress& inAddress1, const AudioObjectPropertyAddress& inAddress2) { bool theAnswer = false; if(inAddress1.mScope != inAddress2.mScope) { theAnswer = inAddress1.mScope < inAddress2.mScope; } else if(inAddress1.mSelector != inAddress2.mSelector) { theAnswer = inAddress1.mSelector < inAddress2.mSelector; } else { theAnswer = inAddress1.mElement < inAddress2.mElement; } return theAnswer; }
static bool IsCongruentSelector(AudioObjectPropertySelector inSelector1, AudioObjectPropertySelector inSelector2) { return (inSelector1 == inSelector2) || (inSelector1 == kAudioObjectPropertySelectorWildcard) || (inSelector2 == kAudioObjectPropertySelectorWildcard); }
static bool IsCongruentScope(AudioObjectPropertyScope inScope1, AudioObjectPropertyScope inScope2) { return (inScope1 == inScope2) || (inScope1 == kAudioObjectPropertyScopeWildcard) || (inScope2 == kAudioObjectPropertyScopeWildcard); }
static bool IsCongruentElement(AudioObjectPropertyElement inElement1, AudioObjectPropertyElement inElement2) { return (inElement1 == inElement2) || (inElement1 == kAudioObjectPropertyElementWildcard) || (inElement2 == kAudioObjectPropertyElementWildcard); }
static bool IsCongruentAddress(const AudioObjectPropertyAddress& inAddress1, const AudioObjectPropertyAddress& inAddress2) { return IsCongruentScope(inAddress1.mScope, inAddress2.mScope) && IsCongruentSelector(inAddress1.mSelector, inAddress2.mSelector) && IsCongruentElement(inAddress1.mElement, inAddress2.mElement); }
static bool IsCongruentLessThanAddress(const AudioObjectPropertyAddress& inAddress1, const AudioObjectPropertyAddress& inAddress2) { bool theAnswer = false; if(!IsCongruentScope(inAddress1.mScope, inAddress2.mScope)) { theAnswer = inAddress1.mScope < inAddress2.mScope; } else if(!IsCongruentSelector(inAddress1.mSelector, inAddress2.mSelector)) { theAnswer = inAddress1.mSelector < inAddress2.mSelector; } else if(!IsCongruentElement(inAddress1.mElement, inAddress2.mElement)) { theAnswer = inAddress1.mElement < inAddress2.mElement; } return theAnswer; }
// STL Helpers
public:
struct EqualTo : public std::binary_function<AudioObjectPropertyAddress, AudioObjectPropertyAddress, bool>
{
bool operator()(const AudioObjectPropertyAddress& inAddress1, const AudioObjectPropertyAddress& inAddress2) const { return IsSameAddress(inAddress1, inAddress2); }
};
struct LessThan : public std::binary_function<AudioObjectPropertyAddress, AudioObjectPropertyAddress, bool>
{
bool operator()(const AudioObjectPropertyAddress& inAddress1, const AudioObjectPropertyAddress& inAddress2) const { return IsLessThanAddress(inAddress1, inAddress2); }
};
struct CongruentEqualTo : public std::binary_function<AudioObjectPropertyAddress, AudioObjectPropertyAddress, bool>
{
bool operator()(const AudioObjectPropertyAddress& inAddress1, const AudioObjectPropertyAddress& inAddress2) const { return IsCongruentAddress(inAddress1, inAddress2); }
};
struct CongruentLessThan : public std::binary_function<AudioObjectPropertyAddress, AudioObjectPropertyAddress, bool>
{
bool operator()(const AudioObjectPropertyAddress& inAddress1, const AudioObjectPropertyAddress& inAddress2) const { return IsCongruentLessThanAddress(inAddress1, inAddress2); }
};
};
//==================================================================================================
// CAPropertyAddressList
//
// An auto-resizing array of CAPropertyAddress structures.
//==================================================================================================
class CAPropertyAddressList
{
// Construction/Destruction
public:
CAPropertyAddressList() : mAddressList(), mToken(NULL) {}
explicit CAPropertyAddressList(void* inToken) : mAddressList(), mToken(inToken) {}
explicit CAPropertyAddressList(uintptr_t inToken) : mAddressList(), mToken(reinterpret_cast<void*>(inToken)) {}
CAPropertyAddressList(const CAPropertyAddressList& inAddressList) : mAddressList(inAddressList.mAddressList), mToken(inAddressList.mToken) {}
CAPropertyAddressList& operator=(const CAPropertyAddressList& inAddressList) { mAddressList = inAddressList.mAddressList; mToken = inAddressList.mToken; return *this; }
~CAPropertyAddressList() {}
// Operations
public:
void* GetToken() const { return mToken; }
void SetToken(void* inToken) { mToken = inToken; }
uintptr_t GetIntToken() const { return reinterpret_cast<uintptr_t>(mToken); }
void SetIntToken(uintptr_t inToken) { mToken = reinterpret_cast<void*>(inToken); }
AudioObjectID GetAudioObjectIDToken() const { return static_cast<AudioObjectID>(reinterpret_cast<uintptr_t>(mToken)); }
bool IsEmpty() const { return mAddressList.empty(); }
UInt32 GetNumberItems() const { return ToUInt32(mAddressList.size()); }
void GetItemByIndex(UInt32 inIndex, AudioObjectPropertyAddress& outAddress) const { if(inIndex < mAddressList.size()) { outAddress = mAddressList.at(inIndex); } }
const AudioObjectPropertyAddress* GetItems() const { return &(*mAddressList.begin()); }
AudioObjectPropertyAddress* GetItems() { return &(*mAddressList.begin()); }
bool HasItem(const AudioObjectPropertyAddress& inAddress) const { AddressList::const_iterator theIterator = std::find_if(mAddressList.begin(), mAddressList.end(), std::bind(CAPropertyAddress::CongruentEqualTo(), inAddress, std::placeholders::_1)); return theIterator != mAddressList.end(); }
bool HasExactItem(const AudioObjectPropertyAddress& inAddress) const { AddressList::const_iterator theIterator = std::find_if(mAddressList.begin(), mAddressList.end(), std::bind(CAPropertyAddress::EqualTo(), inAddress, std::placeholders::_1)); return theIterator != mAddressList.end(); }
void AppendItem(const AudioObjectPropertyAddress& inAddress) { mAddressList.push_back(inAddress); }
void AppendUniqueItem(const AudioObjectPropertyAddress& inAddress) { if(!HasItem(inAddress)) { mAddressList.push_back(inAddress); } }
void AppendUniqueExactItem(const AudioObjectPropertyAddress& inAddress) { if(!HasExactItem(inAddress)) { mAddressList.push_back(inAddress); } }
void InsertItemAtIndex(UInt32 inIndex, const AudioObjectPropertyAddress& inAddress) { if(inIndex < mAddressList.size()) { AddressList::iterator theIterator = mAddressList.begin(); std::advance(theIterator, static_cast<int>(inIndex)); mAddressList.insert(theIterator, inAddress); } else { mAddressList.push_back(inAddress); } }
void EraseExactItem(const AudioObjectPropertyAddress& inAddress) { AddressList::iterator theIterator = std::find_if(mAddressList.begin(), mAddressList.end(), std::bind(CAPropertyAddress::EqualTo(), inAddress, std::placeholders::_1)); if(theIterator != mAddressList.end()) { mAddressList.erase(theIterator); } }
void EraseItemAtIndex(UInt32 inIndex) { if(inIndex < mAddressList.size()) { AddressList::iterator theIterator = mAddressList.begin(); std::advance(theIterator, static_cast<int>(inIndex)); mAddressList.erase(theIterator); } }
void EraseAllItems() { mAddressList.clear(); }
// Implementation
private:
typedef std::vector<CAPropertyAddress> AddressList;
AddressList mAddressList;
void* mToken;
};
//==================================================================================================
// CAPropertyAddressListVector
//
// An auto-resizing array of CAPropertyAddressList objects.
//==================================================================================================
class CAPropertyAddressListVector
{
// Construction/Destruction
public:
CAPropertyAddressListVector() : mAddressListVector() {}
CAPropertyAddressListVector(const CAPropertyAddressListVector& inAddressListVector) : mAddressListVector(inAddressListVector.mAddressListVector) {}
CAPropertyAddressListVector& operator=(const CAPropertyAddressListVector& inAddressListVector) { mAddressListVector = inAddressListVector.mAddressListVector; return *this; }
~CAPropertyAddressListVector() {}
// Operations
public:
bool IsEmpty() const { return mAddressListVector.empty(); }
bool HasAnyNonEmptyItems() const;
bool HasAnyItemsWithAddress(const AudioObjectPropertyAddress& inAddress) const;
bool HasAnyItemsWithExactAddress(const AudioObjectPropertyAddress& inAddress) const;
UInt32 GetNumberItems() const { return ToUInt32(mAddressListVector.size()); }
const CAPropertyAddressList& GetItemByIndex(UInt32 inIndex) const { return mAddressListVector.at(inIndex); }
CAPropertyAddressList& GetItemByIndex(UInt32 inIndex) { return mAddressListVector.at(inIndex); }
const CAPropertyAddressList* GetItemByToken(void* inToken) const;
CAPropertyAddressList* GetItemByToken(void* inToken);
const CAPropertyAddressList* GetItemByIntToken(uintptr_t inToken) const;
CAPropertyAddressList* GetItemByIntToken(uintptr_t inToken);
void AppendItem(const CAPropertyAddressList& inAddressList) { mAddressListVector.push_back(inAddressList); }
void EraseAllItems() { mAddressListVector.clear(); }
// Implementation
private:
typedef std::vector<CAPropertyAddressList> AddressListVector;
AddressListVector mAddressListVector;
};
inline bool CAPropertyAddressListVector::HasAnyNonEmptyItems() const
{
bool theAnswer = false;
for(AddressListVector::const_iterator theIterator = mAddressListVector.begin(); !theAnswer && (theIterator != mAddressListVector.end()); ++theIterator)
{
theAnswer = !theIterator->IsEmpty();
}
return theAnswer;
}
inline bool CAPropertyAddressListVector::HasAnyItemsWithAddress(const AudioObjectPropertyAddress& inAddress) const
{
bool theAnswer = false;
for(AddressListVector::const_iterator theIterator = mAddressListVector.begin(); !theAnswer && (theIterator != mAddressListVector.end()); ++theIterator)
{
theAnswer = theIterator->HasItem(inAddress);
}
return theAnswer;
}
inline bool CAPropertyAddressListVector::HasAnyItemsWithExactAddress(const AudioObjectPropertyAddress& inAddress) const
{
bool theAnswer = false;
for(AddressListVector::const_iterator theIterator = mAddressListVector.begin(); !theAnswer && (theIterator != mAddressListVector.end()); ++theIterator)
{
theAnswer = theIterator->HasExactItem(inAddress);
}
return theAnswer;
}
inline const CAPropertyAddressList* CAPropertyAddressListVector::GetItemByToken(void* inToken) const
{
const CAPropertyAddressList* theAnswer = NULL;
bool wasFound = false;
for(AddressListVector::const_iterator theIterator = mAddressListVector.begin(); !wasFound && (theIterator != mAddressListVector.end()); ++theIterator)
{
if(theIterator->GetToken() == inToken)
{
wasFound = true;
theAnswer = &(*theIterator);
}
}
return theAnswer;
}
inline CAPropertyAddressList* CAPropertyAddressListVector::GetItemByToken(void* inToken)
{
CAPropertyAddressList* theAnswer = NULL;
bool wasFound = false;
for(AddressListVector::iterator theIterator = mAddressListVector.begin(); !wasFound && (theIterator != mAddressListVector.end()); ++theIterator)
{
if(theIterator->GetToken() == inToken)
{
wasFound = true;
theAnswer = &(*theIterator);
}
}
return theAnswer;
}
inline const CAPropertyAddressList* CAPropertyAddressListVector::GetItemByIntToken(uintptr_t inToken) const
{
const CAPropertyAddressList* theAnswer = NULL;
bool wasFound = false;
for(AddressListVector::const_iterator theIterator = mAddressListVector.begin(); !wasFound && (theIterator != mAddressListVector.end()); ++theIterator)
{
if(theIterator->GetIntToken() == inToken)
{
wasFound = true;
theAnswer = &(*theIterator);
}
}
return theAnswer;
}
inline CAPropertyAddressList* CAPropertyAddressListVector::GetItemByIntToken(uintptr_t inToken)
{
CAPropertyAddressList* theAnswer = NULL;
bool wasFound = false;
for(AddressListVector::iterator theIterator = mAddressListVector.begin(); !wasFound && (theIterator != mAddressListVector.end()); ++theIterator)
{
if(theIterator->GetIntToken() == inToken)
{
wasFound = true;
theAnswer = &(*theIterator);
}
}
return theAnswer;
}
#endif

View File

@ -1,319 +0,0 @@
/*
File: CARingBuffer.cpp
Abstract: CARingBuffer.h
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#include "CARingBuffer.h"
#include "CABitOperations.h"
#include "CAAutoDisposer.h"
#include "CAAtomic.h"
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <libkern/OSAtomic.h>
CARingBuffer::CARingBuffer() :
mBuffers(NULL), mNumberChannels(0), mCapacityFrames(0), mCapacityBytes(0)
{
}
CARingBuffer::~CARingBuffer()
{
Deallocate();
}
void CARingBuffer::Allocate(int nChannels, UInt32 bytesPerFrame, UInt32 capacityFrames)
{
Deallocate();
capacityFrames = NextPowerOfTwo(capacityFrames);
mNumberChannels = nChannels;
mBytesPerFrame = bytesPerFrame;
mCapacityFrames = capacityFrames;
mCapacityFramesMask = capacityFrames - 1;
mCapacityBytes = bytesPerFrame * capacityFrames;
// put everything in one memory allocation, first the pointers, then the deinterleaved channels
UInt32 allocSize = (mCapacityBytes + sizeof(Byte *)) * nChannels;
Byte *p = (Byte *)CA_malloc(allocSize);
memset(p, 0, allocSize);
mBuffers = (Byte **)p;
p += nChannels * sizeof(Byte *);
for (int i = 0; i < nChannels; ++i) {
mBuffers[i] = p;
p += mCapacityBytes;
}
for (UInt32 i = 0; i<kGeneralRingTimeBoundsQueueSize; ++i)
{
mTimeBoundsQueue[i].mStartTime = 0;
mTimeBoundsQueue[i].mEndTime = 0;
mTimeBoundsQueue[i].mUpdateCounter = 0;
}
mTimeBoundsQueuePtr = 0;
}
void CARingBuffer::Deallocate()
{
if (mBuffers) {
free(mBuffers);
mBuffers = NULL;
}
mNumberChannels = 0;
mCapacityBytes = 0;
mCapacityFrames = 0;
}
inline void ZeroRange(Byte **buffers, int nchannels, int offset, int nbytes)
{
while (--nchannels >= 0) {
memset(*buffers + offset, 0, nbytes);
++buffers;
}
}
inline void StoreABL(Byte **buffers, int destOffset, const AudioBufferList *abl, int srcOffset, int nbytes)
{
int nchannels = abl->mNumberBuffers;
const AudioBuffer *src = abl->mBuffers;
while (--nchannels >= 0) {
if (srcOffset > (int)src->mDataByteSize) continue;
memcpy(*buffers + destOffset, (Byte *)src->mData + srcOffset, std::min(nbytes, (int)src->mDataByteSize - srcOffset));
++buffers;
++src;
}
}
inline void FetchABL(AudioBufferList *abl, int destOffset, Byte **buffers, int srcOffset, int nbytes)
{
int nchannels = abl->mNumberBuffers;
AudioBuffer *dest = abl->mBuffers;
while (--nchannels >= 0) {
if (destOffset > (int)dest->mDataByteSize) continue;
memcpy((Byte *)dest->mData + destOffset, *buffers + srcOffset, std::min(nbytes, (int)dest->mDataByteSize - destOffset));
++buffers;
++dest;
}
}
inline void ZeroABL(AudioBufferList *abl, int destOffset, int nbytes)
{
int nBuffers = abl->mNumberBuffers;
AudioBuffer *dest = abl->mBuffers;
while (--nBuffers >= 0) {
if (destOffset > (int)dest->mDataByteSize) continue;
memset((Byte *)dest->mData + destOffset, 0, std::min(nbytes, (int)dest->mDataByteSize - destOffset));
++dest;
}
}
CARingBufferError CARingBuffer::Store(const AudioBufferList *abl, UInt32 framesToWrite, SampleTime startWrite)
{
if (framesToWrite == 0)
return kCARingBufferError_OK;
if (framesToWrite > mCapacityFrames)
return kCARingBufferError_TooMuch; // too big!
SampleTime endWrite = startWrite + framesToWrite;
if (startWrite < EndTime()) {
// going backwards, throw everything out
SetTimeBounds(startWrite, startWrite);
} else if (endWrite - StartTime() <= mCapacityFrames) {
// the buffer has not yet wrapped and will not need to
} else {
// advance the start time past the region we are about to overwrite
SampleTime newStart = endWrite - mCapacityFrames; // one buffer of time behind where we're writing
SampleTime newEnd = std::max(newStart, EndTime());
SetTimeBounds(newStart, newEnd);
}
// write the new frames
Byte **buffers = mBuffers;
int nchannels = mNumberChannels;
int offset0, offset1, nbytes;
SampleTime curEnd = EndTime();
if (startWrite > curEnd) {
// we are skipping some samples, so zero the range we are skipping
offset0 = FrameOffset(curEnd);
offset1 = FrameOffset(startWrite);
if (offset0 < offset1)
ZeroRange(buffers, nchannels, offset0, offset1 - offset0);
else {
ZeroRange(buffers, nchannels, offset0, mCapacityBytes - offset0);
ZeroRange(buffers, nchannels, 0, offset1);
}
offset0 = offset1;
} else {
offset0 = FrameOffset(startWrite);
}
offset1 = FrameOffset(endWrite);
if (offset0 < offset1)
StoreABL(buffers, offset0, abl, 0, offset1 - offset0);
else {
nbytes = mCapacityBytes - offset0;
StoreABL(buffers, offset0, abl, 0, nbytes);
StoreABL(buffers, 0, abl, nbytes, offset1);
}
// now update the end time
SetTimeBounds(StartTime(), endWrite);
return kCARingBufferError_OK; // success
}
void CARingBuffer::SetTimeBounds(SampleTime startTime, SampleTime endTime)
{
UInt32 nextPtr = mTimeBoundsQueuePtr + 1;
UInt32 index = nextPtr & kGeneralRingTimeBoundsQueueMask;
mTimeBoundsQueue[index].mStartTime = startTime;
mTimeBoundsQueue[index].mEndTime = endTime;
mTimeBoundsQueue[index].mUpdateCounter = nextPtr;
CAAtomicCompareAndSwap32Barrier(mTimeBoundsQueuePtr, mTimeBoundsQueuePtr + 1, (SInt32*)&mTimeBoundsQueuePtr);
}
CARingBufferError CARingBuffer::GetTimeBounds(SampleTime &startTime, SampleTime &endTime)
{
for (int i=0; i<8; ++i) // fail after a few tries.
{
UInt32 curPtr = mTimeBoundsQueuePtr;
UInt32 index = curPtr & kGeneralRingTimeBoundsQueueMask;
CARingBuffer::TimeBounds* bounds = mTimeBoundsQueue + index;
startTime = bounds->mStartTime;
endTime = bounds->mEndTime;
UInt32 newPtr = bounds->mUpdateCounter;
if (newPtr == curPtr)
return kCARingBufferError_OK;
}
return kCARingBufferError_CPUOverload;
}
CARingBufferError CARingBuffer::ClipTimeBounds(SampleTime& startRead, SampleTime& endRead)
{
SampleTime startTime, endTime;
CARingBufferError err = GetTimeBounds(startTime, endTime);
if (err) return err;
if (startRead > endTime || endRead < startTime) {
endRead = startRead;
return kCARingBufferError_OK;
}
startRead = std::max(startRead, startTime);
endRead = std::min(endRead, endTime);
endRead = std::max(endRead, startRead);
return kCARingBufferError_OK; // success
}
CARingBufferError CARingBuffer::Fetch(AudioBufferList *abl, UInt32 nFrames, SampleTime startRead)
{
if (nFrames == 0)
return kCARingBufferError_OK;
startRead = std::max(0LL, startRead);
SampleTime endRead = startRead + nFrames;
SampleTime startRead0 = startRead;
SampleTime endRead0 = endRead;
CARingBufferError err = ClipTimeBounds(startRead, endRead);
if (err) return err;
if (startRead == endRead) {
ZeroABL(abl, 0, nFrames * mBytesPerFrame);
return kCARingBufferError_OK;
}
SInt32 byteSize = (SInt32)((endRead - startRead) * mBytesPerFrame);
SInt32 destStartByteOffset = std::max((SInt32)0, (SInt32)((startRead - startRead0) * mBytesPerFrame));
if (destStartByteOffset > 0) {
ZeroABL(abl, 0, std::min((SInt32)(nFrames * mBytesPerFrame), destStartByteOffset));
}
SInt32 destEndSize = std::max((SInt32)0, (SInt32)(endRead0 - endRead));
if (destEndSize > 0) {
ZeroABL(abl, destStartByteOffset + byteSize, destEndSize * mBytesPerFrame);
}
Byte **buffers = mBuffers;
int offset0 = FrameOffset(startRead);
int offset1 = FrameOffset(endRead);
int nbytes;
if (offset0 < offset1) {
nbytes = offset1 - offset0;
FetchABL(abl, destStartByteOffset, buffers, offset0, nbytes);
} else {
nbytes = mCapacityBytes - offset0;
FetchABL(abl, destStartByteOffset, buffers, offset0, nbytes);
FetchABL(abl, destStartByteOffset + nbytes, buffers, 0, offset1);
nbytes += offset1;
}
int nchannels = abl->mNumberBuffers;
AudioBuffer *dest = abl->mBuffers;
while (--nchannels >= 0)
{
dest->mDataByteSize = nbytes;
dest++;
}
return noErr;
}

View File

@ -1,126 +0,0 @@
/*
File: CARingBuffer.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreAudio/CoreAudioTypes.h>
#else
#include <CoreAudioTypes.h>
#endif
#ifndef CARingBuffer_Header
#define CARingBuffer_Header
enum {
kCARingBufferError_OK = 0,
kCARingBufferError_TooMuch = 3, // fetch start time is earlier than buffer start time and fetch end time is later than buffer end time
kCARingBufferError_CPUOverload = 4 // the reader is unable to get enough CPU cycles to capture a consistent snapshot of the time bounds
};
typedef SInt32 CARingBufferError;
const UInt32 kGeneralRingTimeBoundsQueueSize = 32;
const UInt32 kGeneralRingTimeBoundsQueueMask = kGeneralRingTimeBoundsQueueSize - 1;
class CARingBuffer {
public:
typedef SInt64 SampleTime;
CARingBuffer();
~CARingBuffer();
void Allocate(int nChannels, UInt32 bytesPerFrame, UInt32 capacityFrames);
// capacityFrames will be rounded up to a power of 2
void Deallocate();
CARingBufferError Store(const AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber);
// Copy nFrames of data into the ring buffer at the specified sample time.
// The sample time should normally increase sequentially, though gaps
// are filled with zeroes. A sufficiently large gap effectively empties
// the buffer before storing the new data.
// If frameNumber is less than the previous frame number, the behavior is undefined.
// Return false for failure (buffer not large enough).
CARingBufferError Fetch(AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber);
// will alter mNumDataBytes of the buffers
CARingBufferError GetTimeBounds(SampleTime &startTime, SampleTime &endTime);
protected:
int FrameOffset(SampleTime frameNumber) { return (frameNumber & mCapacityFramesMask) * mBytesPerFrame; }
CARingBufferError ClipTimeBounds(SampleTime& startRead, SampleTime& endRead);
// these should only be called from Store.
SampleTime StartTime() const { return mTimeBoundsQueue[mTimeBoundsQueuePtr & kGeneralRingTimeBoundsQueueMask].mStartTime; }
SampleTime EndTime() const { return mTimeBoundsQueue[mTimeBoundsQueuePtr & kGeneralRingTimeBoundsQueueMask].mEndTime; }
void SetTimeBounds(SampleTime startTime, SampleTime endTime);
protected:
Byte ** mBuffers; // allocated in one chunk of memory
int mNumberChannels;
UInt32 mBytesPerFrame; // within one deinterleaved channel
UInt32 mCapacityFrames; // per channel, must be a power of 2
UInt32 mCapacityFramesMask;
UInt32 mCapacityBytes; // per channel
// range of valid sample time in the buffer
typedef struct {
volatile SampleTime mStartTime;
volatile SampleTime mEndTime;
volatile UInt32 mUpdateCounter;
} TimeBounds;
CARingBuffer::TimeBounds mTimeBoundsQueue[kGeneralRingTimeBoundsQueueSize];
UInt32 mTimeBoundsQueuePtr;
};
#endif

View File

@ -1,482 +0,0 @@
/*
File: CAVolumeCurve.cpp
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
//=============================================================================
// Includes
//=============================================================================
#include "CAVolumeCurve.h"
#include "CADebugMacros.h"
#include <math.h>
//=============================================================================
// CAVolumeCurve
//=============================================================================
CAVolumeCurve::CAVolumeCurve()
:
mTag(0),
mCurveMap(),
mIsApplyingTransferFunction(true),
mTransferFunction(kPow2Over1Curve),
mRawToScalarExponentNumerator(2.0f),
mRawToScalarExponentDenominator(1.0f)
{
}
CAVolumeCurve::~CAVolumeCurve()
{
}
SInt32 CAVolumeCurve::GetMinimumRaw() const
{
SInt32 theAnswer = 0;
if(!mCurveMap.empty())
{
CurveMap::const_iterator theIterator = mCurveMap.begin();
theAnswer = theIterator->first.mMinimum;
}
return theAnswer;
}
SInt32 CAVolumeCurve::GetMaximumRaw() const
{
SInt32 theAnswer = 0;
if(!mCurveMap.empty())
{
CurveMap::const_iterator theIterator = mCurveMap.begin();
std::advance(theIterator, static_cast<int>(mCurveMap.size() - 1));
theAnswer = theIterator->first.mMaximum;
}
return theAnswer;
}
Float32 CAVolumeCurve::GetMinimumDB() const
{
Float32 theAnswer = 0;
if(!mCurveMap.empty())
{
CurveMap::const_iterator theIterator = mCurveMap.begin();
theAnswer = theIterator->second.mMinimum;
}
return theAnswer;
}
Float32 CAVolumeCurve::GetMaximumDB() const
{
Float32 theAnswer = 0;
if(!mCurveMap.empty())
{
CurveMap::const_iterator theIterator = mCurveMap.begin();
std::advance(theIterator, static_cast<int>(mCurveMap.size() - 1));
theAnswer = theIterator->second.mMaximum;
}
return theAnswer;
}
void CAVolumeCurve::SetTransferFunction(UInt32 inTransferFunction)
{
mTransferFunction = inTransferFunction;
// figure out the co-efficients
switch(inTransferFunction)
{
case kLinearCurve:
mIsApplyingTransferFunction = false;
mRawToScalarExponentNumerator = 1.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
case kPow1Over3Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 1.0f;
mRawToScalarExponentDenominator = 3.0f;
break;
case kPow1Over2Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 1.0f;
mRawToScalarExponentDenominator = 2.0f;
break;
case kPow3Over4Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 3.0f;
mRawToScalarExponentDenominator = 4.0f;
break;
case kPow3Over2Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 3.0f;
mRawToScalarExponentDenominator = 2.0f;
break;
case kPow2Over1Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 2.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
case kPow3Over1Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 3.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
case kPow4Over1Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 4.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
case kPow5Over1Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 5.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
case kPow6Over1Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 6.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
case kPow7Over1Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 7.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
case kPow8Over1Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 8.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
case kPow9Over1Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 9.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
case kPow10Over1Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 10.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
case kPow11Over1Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 11.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
case kPow12Over1Curve:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 12.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
default:
mIsApplyingTransferFunction = true;
mRawToScalarExponentNumerator = 2.0f;
mRawToScalarExponentDenominator = 1.0f;
break;
};
}
void CAVolumeCurve::AddRange(SInt32 inMinRaw, SInt32 inMaxRaw, Float32 inMinDB, Float32 inMaxDB)
{
CARawPoint theRaw(inMinRaw, inMaxRaw);
CADBPoint theDB(inMinDB, inMaxDB);
bool isOverlapped = false;
bool isDone = false;
CurveMap::iterator theIterator = mCurveMap.begin();
while((theIterator != mCurveMap.end()) && !isOverlapped && !isDone)
{
isOverlapped = CARawPoint::Overlap(theRaw, theIterator->first);
isDone = theRaw >= theIterator->first;
if(!isOverlapped && !isDone)
{
std::advance(theIterator, 1);
}
}
if(!isOverlapped)
{
mCurveMap.insert(CurveMap::value_type(theRaw, theDB));
}
else
{
DebugMessage("CAVolumeCurve::AddRange: new point overlaps");
}
}
void CAVolumeCurve::ResetRange()
{
mCurveMap.clear();
}
bool CAVolumeCurve::CheckForContinuity() const
{
bool theAnswer = true;
CurveMap::const_iterator theIterator = mCurveMap.begin();
if(theIterator != mCurveMap.end())
{
SInt32 theRaw = theIterator->first.mMinimum;
Float32 theDB = theIterator->second.mMinimum;
do
{
SInt32 theRawMin = theIterator->first.mMinimum;
SInt32 theRawMax = theIterator->first.mMaximum;
SInt32 theRawRange = theRawMax - theRawMin;
Float32 theDBMin = theIterator->second.mMinimum;
Float32 theDBMax = theIterator->second.mMaximum;
Float32 theDBRange = theDBMax - theDBMin;
theAnswer = theRaw == theRawMin;
theAnswer = theAnswer && (theDB == theDBMin);
theRaw += theRawRange;
theDB += theDBRange;
std::advance(theIterator, 1);
}
while((theIterator != mCurveMap.end()) && theAnswer);
}
return theAnswer;
}
SInt32 CAVolumeCurve::ConvertDBToRaw(Float32 inDB) const
{
// clamp the value to the dB range
Float32 theOverallDBMin = GetMinimumDB();
Float32 theOverallDBMax = GetMaximumDB();
if(inDB < theOverallDBMin) inDB = theOverallDBMin;
if(inDB > theOverallDBMax) inDB = theOverallDBMax;
// get the first entry in the curve map;
CurveMap::const_iterator theIterator = mCurveMap.begin();
// initialize the answer to the minimum raw of the first item in the curve map
SInt32 theAnswer = theIterator->first.mMinimum;
// iterate through the curve map until we run out of dB
bool isDone = false;
while(!isDone && (theIterator != mCurveMap.end()))
{
SInt32 theRawMin = theIterator->first.mMinimum;
SInt32 theRawMax = theIterator->first.mMaximum;
SInt32 theRawRange = theRawMax - theRawMin;
Float32 theDBMin = theIterator->second.mMinimum;
Float32 theDBMax = theIterator->second.mMaximum;
Float32 theDBRange = theDBMax - theDBMin;
Float32 theDBPerRaw = theDBRange / static_cast<Float32>(theRawRange);
// figure out how many steps we are into this entry in the curve map
if(inDB > theDBMax)
{
// we're past the end of this one, so add in the whole range for this entry
theAnswer += theRawRange;
}
else
{
// it's somewhere within the current entry
// figure out how many steps it is
Float32 theNumberRawSteps = inDB - theDBMin;
theNumberRawSteps /= theDBPerRaw;
// only move in whole steps
theNumberRawSteps = roundf(theNumberRawSteps);
// add this many steps to the answer
theAnswer += static_cast<SInt32>(theNumberRawSteps);
// mark that we are done
isDone = true;
}
// go to the next entry in the curve map
std::advance(theIterator, 1);
}
return theAnswer;
}
Float32 CAVolumeCurve::ConvertRawToDB(SInt32 inRaw) const
{
Float32 theAnswer = 0;
// clamp the raw value
SInt32 theOverallRawMin = GetMinimumRaw();
SInt32 theOverallRawMax = GetMaximumRaw();
if(inRaw < theOverallRawMin) inRaw = theOverallRawMin;
if(inRaw > theOverallRawMax) inRaw = theOverallRawMax;
// figure out how many raw steps need to be taken from the first one
SInt32 theNumberRawSteps = inRaw - theOverallRawMin;
// get the first item in the curve map
CurveMap::const_iterator theIterator = mCurveMap.begin();
// initialize the answer to the minimum dB of the first item in the curve map
theAnswer = theIterator->second.mMinimum;
// iterate through the curve map until we run out of steps
while((theNumberRawSteps > 0) && (theIterator != mCurveMap.end()))
{
// compute some values
SInt32 theRawMin = theIterator->first.mMinimum;
SInt32 theRawMax = theIterator->first.mMaximum;
SInt32 theRawRange = theRawMax - theRawMin;
Float32 theDBMin = theIterator->second.mMinimum;
Float32 theDBMax = theIterator->second.mMaximum;
Float32 theDBRange = theDBMax - theDBMin;
Float32 theDBPerRaw = theDBRange / static_cast<Float32>(theRawRange);
// there might be more steps than the current map entry accounts for
SInt32 theRawStepsToAdd = std::min(theRawRange, theNumberRawSteps);
// add this many steps worth of db to the answer;
theAnswer += theRawStepsToAdd * theDBPerRaw;
// figure out how many steps are left
theNumberRawSteps -= theRawStepsToAdd;
// go to the next map entry
std::advance(theIterator, 1);
}
return theAnswer;
}
Float32 CAVolumeCurve::ConvertRawToScalar(SInt32 inRaw) const
{
// get some important values
Float32 theDBMin = GetMinimumDB();
Float32 theDBMax = GetMaximumDB();
Float32 theDBRange = theDBMax - theDBMin;
SInt32 theRawMin = GetMinimumRaw();
SInt32 theRawMax = GetMaximumRaw();
SInt32 theRawRange = theRawMax - theRawMin;
// range the raw value
if(inRaw < theRawMin) inRaw = theRawMin;
if(inRaw > theRawMax) inRaw = theRawMax;
// calculate the distance in the range inRaw is
Float32 theAnswer = static_cast<Float32>(inRaw - theRawMin) / static_cast<Float32>(theRawRange);
// only apply a curve to the scalar values if the dB range is greater than 30
if(mIsApplyingTransferFunction && (theDBRange > 30.0f))
{
theAnswer = powf(theAnswer, mRawToScalarExponentNumerator / mRawToScalarExponentDenominator);
}
return theAnswer;
}
Float32 CAVolumeCurve::ConvertDBToScalar(Float32 inDB) const
{
SInt32 theRawValue = ConvertDBToRaw(inDB);
Float32 theAnswer = ConvertRawToScalar(theRawValue);
return theAnswer;
}
SInt32 CAVolumeCurve::ConvertScalarToRaw(Float32 inScalar) const
{
// range the scalar value
inScalar = std::min(1.0f, std::max(0.0f, inScalar));
// get some important values
Float32 theDBMin = GetMinimumDB();
Float32 theDBMax = GetMaximumDB();
Float32 theDBRange = theDBMax - theDBMin;
SInt32 theRawMin = GetMinimumRaw();
SInt32 theRawMax = GetMaximumRaw();
SInt32 theRawRange = theRawMax - theRawMin;
// have to undo the curve if the dB range is greater than 30
if(mIsApplyingTransferFunction && (theDBRange > 30.0f))
{
inScalar = powf(inScalar, mRawToScalarExponentDenominator / mRawToScalarExponentNumerator);
}
// now we can figure out how many raw steps this is
Float32 theNumberRawSteps = inScalar * static_cast<Float32>(theRawRange);
theNumberRawSteps = roundf(theNumberRawSteps);
// the answer is the minimum raw value plus the number of raw steps
SInt32 theAnswer = theRawMin + static_cast<SInt32>(theNumberRawSteps);
return theAnswer;
}
Float32 CAVolumeCurve::ConvertScalarToDB(Float32 inScalar) const
{
SInt32 theRawValue = ConvertScalarToRaw(inScalar);
Float32 theAnswer = ConvertRawToDB(theRawValue);
return theAnswer;
}

View File

@ -1,178 +0,0 @@
/*
File: CAVolumeCurve.h
Abstract: Part of CoreAudio Utility Classes
Version: 1.0.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
#if !defined(__CAVolumeCurve_h__)
#define __CAVolumeCurve_h__
//=============================================================================
// Includes
//=============================================================================
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
#include <CoreAudio/CoreAudioTypes.h>
#else
#include <CoreAudioTypes.h>
#endif
#include <map>
//=============================================================================
// Types
//=============================================================================
struct CARawPoint
{
SInt32 mMinimum;
SInt32 mMaximum;
CARawPoint() : mMinimum(0), mMaximum(0) {}
CARawPoint(const CARawPoint& inPoint) : mMinimum(inPoint.mMinimum), mMaximum(inPoint.mMaximum) {}
CARawPoint(SInt32 inMinimum, SInt32 inMaximum) : mMinimum(inMinimum), mMaximum(inMaximum) {}
CARawPoint& operator=(const CARawPoint& inPoint) { mMinimum = inPoint.mMinimum; mMaximum = inPoint.mMaximum; return *this; }
static bool Overlap(const CARawPoint& x, const CARawPoint& y) { return (x.mMinimum < y.mMaximum) && (x.mMaximum > y.mMinimum); }
};
inline bool operator<(const CARawPoint& x, const CARawPoint& y) { return x.mMinimum < y.mMinimum; }
inline bool operator==(const CARawPoint& x, const CARawPoint& y) { return (x.mMinimum == y.mMinimum) && (x.mMaximum == y.mMaximum); }
inline bool operator!=(const CARawPoint& x, const CARawPoint& y) { return !(x == y); }
inline bool operator<=(const CARawPoint& x, const CARawPoint& y) { return (x < y) || (x == y); }
inline bool operator>=(const CARawPoint& x, const CARawPoint& y) { return !(x < y); }
inline bool operator>(const CARawPoint& x, const CARawPoint& y) { return !((x < y) || (x == y)); }
struct CADBPoint
{
Float32 mMinimum;
Float32 mMaximum;
CADBPoint() : mMinimum(0), mMaximum(0) {}
CADBPoint(const CADBPoint& inPoint) : mMinimum(inPoint.mMinimum), mMaximum(inPoint.mMaximum) {}
CADBPoint(Float32 inMinimum, Float32 inMaximum) : mMinimum(inMinimum), mMaximum(inMaximum) {}
CADBPoint& operator=(const CADBPoint& inPoint) { mMinimum = inPoint.mMinimum; mMaximum = inPoint.mMaximum; return *this; }
static bool Overlap(const CADBPoint& x, const CADBPoint& y) { return (x.mMinimum < y.mMaximum) && (x.mMaximum >= y.mMinimum); }
};
inline bool operator<(const CADBPoint& x, const CADBPoint& y) { return x.mMinimum < y.mMinimum; }
inline bool operator==(const CADBPoint& x, const CADBPoint& y) { return (x.mMinimum == y.mMinimum) && (x.mMaximum == y.mMaximum); }
inline bool operator!=(const CADBPoint& x, const CADBPoint& y) { return !(x == y); }
inline bool operator<=(const CADBPoint& x, const CADBPoint& y) { return (x < y) || (x == y); }
inline bool operator>=(const CADBPoint& x, const CADBPoint& y) { return !(x < y); }
inline bool operator>(const CADBPoint& x, const CADBPoint& y) { return !((x < y) || (x == y)); }
//=============================================================================
// CAVolumeCurve
//=============================================================================
class CAVolumeCurve
{
// Constants
public:
enum
{
kLinearCurve = 0,
kPow1Over3Curve = 1,
kPow1Over2Curve = 2,
kPow3Over4Curve = 3,
kPow3Over2Curve = 4,
kPow2Over1Curve = 5,
kPow3Over1Curve = 6,
kPow4Over1Curve = 7,
kPow5Over1Curve = 8,
kPow6Over1Curve = 9,
kPow7Over1Curve = 10,
kPow8Over1Curve = 11,
kPow9Over1Curve = 12,
kPow10Over1Curve = 13,
kPow11Over1Curve = 14,
kPow12Over1Curve = 15
};
// Construction/Destruction
public:
CAVolumeCurve();
virtual ~CAVolumeCurve();
// Attributes
public:
UInt32 GetTag() const { return mTag; }
void SetTag(UInt32 inTag) { mTag = inTag; }
SInt32 GetMinimumRaw() const;
SInt32 GetMaximumRaw() const;
Float32 GetMinimumDB() const;
Float32 GetMaximumDB() const;
void SetIsApplyingTransferFunction(bool inIsApplyingTransferFunction) { mIsApplyingTransferFunction = inIsApplyingTransferFunction; }
UInt32 GetTransferFunction() const { return mTransferFunction; }
void SetTransferFunction(UInt32 inTransferFunction);
// Operations
public:
void AddRange(SInt32 mMinRaw, SInt32 mMaxRaw, Float32 inMinDB, Float32 inMaxDB);
void ResetRange();
bool CheckForContinuity() const;
SInt32 ConvertDBToRaw(Float32 inDB) const;
Float32 ConvertRawToDB(SInt32 inRaw) const;
Float32 ConvertRawToScalar(SInt32 inRaw) const;
Float32 ConvertDBToScalar(Float32 inDB) const;
SInt32 ConvertScalarToRaw(Float32 inScalar) const;
Float32 ConvertScalarToDB(Float32 inScalar) const;
// Implementation
private:
typedef std::map<CARawPoint, CADBPoint> CurveMap;
UInt32 mTag;
CurveMap mCurveMap;
bool mIsApplyingTransferFunction;
UInt32 mTransferFunction;
Float32 mRawToScalarExponentNumerator;
Float32 mRawToScalarExponentDenominator;
};
#endif

View File

@ -11,35 +11,6 @@ if [ "${CONFIGURATION}" = "Debug" ]; then
# Install the new driver
sudo -A cp -f -r "$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME" /Library/Audio/Plug-Ins/HAL/
# Restart CoreAudio
coreaudiod_plist="/System/Library/LaunchDaemons/com.apple.audio.coreaudiod.plist"
(sudo -A launchctl kickstart -k system/com.apple.audio.coreaudiod &>/dev/null || \
sudo -A launchctl kill SIGTERM system/com.apple.audio.coreaudiod &>/dev/null || \
sudo -A launchctl kill TERM system/com.apple.audio.coreaudiod &>/dev/null || \
sudo -A launchctl kill 15 system/com.apple.audio.coreaudiod &>/dev/null || \
sudo -A launchctl kill -15 system/com.apple.audio.coreaudiod &>/dev/null || \
(sudo -A launchctl unload "$coreaudiod_plist" &>/dev/null && \
sudo -A launchctl load "$coreaudiod_plist" &>/dev/null) || \
sudo -A killall coreaudiod &>/dev/null)
sleep 5
# Wait until coreaudiod has restarted and device is ready to use.
retries=5
while [[ $retries -gt 0 ]]; do
if ! system_profiler SPAudioDataType | grep "eqMac:" >/dev/null 2>&1; then
retries=$((retries - 1))
if [[ $retries -gt 0 ]]; then
echo "Device not ready yet, waiting..."
sleep 3
else
echo "ERROR: Device did not become active"
exit 1
fi
else
retries=0
fi
done
echo "Device became active"
sudo -A launchctl kickstart -k system/com.apple.audio.coreaudiod
fi

View File

@ -1,37 +0,0 @@
//
// EQM_Client.cpp
// EQMDriver
//
//
// Self Include
#include "EQM_Client.h"
EQM_Client::EQM_Client(const AudioServerPlugInClientInfo* inClientInfo)
:
mClientID(inClientInfo->mClientID),
mProcessID(inClientInfo->mProcessID),
mIsNativeEndian(inClientInfo->mIsNativeEndian),
mBundleID(inClientInfo->mBundleID)
{
// The bundle ID ref we were passed is only valid until our plugin returns control to the HAL, so we need to retain
// it. (CACFString will handle the rest of its ownership/destruction.)
if(inClientInfo->mBundleID != NULL)
{
CFRetain(inClientInfo->mBundleID);
}
}
void EQM_Client::Copy(const EQM_Client& inClient)
{
mClientID = inClient.mClientID;
mProcessID = inClient.mProcessID;
mBundleID = inClient.mBundleID;
mIsNativeEndian = inClient.mIsNativeEndian;
mDoingIO = inClient.mDoingIO;
mIsMusicPlayer = inClient.mIsMusicPlayer;
mRelativeVolume = inClient.mRelativeVolume;
mPanPosition = inClient.mPanPosition;
}

View File

@ -1,67 +0,0 @@
//
// EQM_Client.h
// EQMDriver
//
//
#ifndef __EQMDriver__EQM_Client__
#define __EQMDriver__EQM_Client__
// PublicUtility Includes
#include "CACFString.h"
// System Includes
#include <CoreAudio/AudioServerPlugIn.h>
#pragma clang assume_nonnull begin
//==================================================================================================
// EQM_Client
//
// Client meaning a client (of the host) of the EQMDevice, i.e. an app registered with the HAL,
// generally so it can do IO at some point.
//==================================================================================================
class EQM_Client
{
public:
EQM_Client() = default;
EQM_Client(const AudioServerPlugInClientInfo* inClientInfo);
~EQM_Client() = default;
EQM_Client(const EQM_Client& inClient) { Copy(inClient); };
EQM_Client& operator=(const EQM_Client& inClient) { Copy(inClient); return *this; }
private:
void Copy(const EQM_Client& inClient);
public:
// These fields are duplicated from AudioServerPlugInClientInfo (except the mBundleID CFStringRef is
// wrapped in a CACFString here).
UInt32 mClientID;
pid_t mProcessID;
Boolean mIsNativeEndian = true;
CACFString mBundleID;
// Becomes true when the client triggers the plugin host to call StartIO or to begin
// kAudioServerPlugInIOOperationThread, and false again on StopIO or when
// kAudioServerPlugInIOOperationThread ends
bool mDoingIO = false;
// True if EQMApp has set this client as belonging to the music player app
bool mIsMusicPlayer = false;
// The client's volume relative to other clients. In the range [0.0, 4.0], defaults to 1.0 (unchanged).
// mRelativeVolumeCurve is applied to this value when it's set.
Float32 mRelativeVolume = 1.0;
// The client's pan position, in the range [-100, 100] where -100 is left and 100 is right
SInt32 mPanPosition = 0;
};
#pragma clang assume_nonnull end
#endif /* __EQMDriver__EQM_Client__ */

View File

@ -1,431 +0,0 @@
//
// EQM_ClientMap.cpp
// EQMDriver
//
// Copyright © 2017 Andrew Tonner
//
// Self Include
#include "EQM_ClientMap.h"
// Local Includes
#include "EQM_Types.h"
// PublicUtility Includes
#include "CACFDictionary.h"
#include "CAException.h"
#pragma clang assume_nonnull begin
void EQM_ClientMap::AddClient(EQM_Client inClient)
{
CAMutex::Locker theShadowMapsLocker(mShadowMapsMutex);
// If this client has been a client in the past (and has a bundle ID), copy its previous audio settings
auto pastClientItr = inClient.mBundleID.IsValid() ? mPastClientMap.find(inClient.mBundleID) : mPastClientMap.end();
if(pastClientItr != mPastClientMap.end())
{
DebugMsg("EQM_ClientMap::AddClient: Found previous volume %f and pan %d for client %u",
pastClientItr->second.mRelativeVolume,
pastClientItr->second.mPanPosition,
inClient.mClientID);
inClient.mRelativeVolume = pastClientItr->second.mRelativeVolume;
inClient.mPanPosition = pastClientItr->second.mPanPosition;
}
// Add the new client to the shadow maps
AddClientToShadowMaps(inClient);
// Swap the maps with their shadow maps
SwapInShadowMaps();
// The shadow maps (which were the main maps until we swapped them) are now missing the new client. Add it again to
// keep the sets of maps identical.
AddClientToShadowMaps(inClient);
// Insert the client into the past clients map. We do this here rather than in RemoveClient
// because some apps add multiple clients with the same bundle ID and we want to give them all
// the same settings (volume, etc.).
if(inClient.mBundleID.IsValid())
{
mPastClientMap[inClient.mBundleID] = inClient;
}
}
void EQM_ClientMap::AddClientToShadowMaps(EQM_Client inClient)
{
ThrowIf(mClientMapShadow.count(inClient.mClientID) != 0,
EQM_InvalidClientException(),
"EQM_ClientMap::AddClientToShadowMaps: Tried to add client whose client ID was already in use");
// Add to the client ID shadow map
mClientMapShadow[inClient.mClientID] = inClient;
// Get a reference to the client in the map so we can add it to the pointer maps
EQM_Client& clientInMap = mClientMapShadow.at(inClient.mClientID);
// Add to the PID shadow map
mClientMapByPIDShadow[inClient.mProcessID].push_back(&clientInMap);
// Add to the bundle ID shadow map
if(inClient.mBundleID.IsValid())
{
mClientMapByBundleIDShadow[inClient.mBundleID].push_back(&clientInMap);
}
}
EQM_Client EQM_ClientMap::RemoveClient(UInt32 inClientID)
{
CAMutex::Locker theShadowMapsLocker(mShadowMapsMutex);
auto theClientItr = mClientMapShadow.find(inClientID);
// Removing a client that was never added is an error
ThrowIf(theClientItr == mClientMapShadow.end(),
EQM_InvalidClientException(),
"EQM_ClientMap::RemoveClient: Could not find client to be removed");
EQM_Client theClient = theClientItr->second;
// Remove the client from the shadow maps
mClientMapShadow.erase(theClientItr);
mClientMapByPIDShadow.erase(theClient.mProcessID);
if(theClient.mBundleID.IsValid())
{
mClientMapByBundleID.erase(theClient.mBundleID);
}
// Swap the maps with their shadow maps
SwapInShadowMaps();
// Erase the client again so the maps and their shadow maps are kept identical
mClientMapShadow.erase(inClientID);
mClientMapByPIDShadow.erase(theClient.mProcessID);
if(theClient.mBundleID.IsValid())
{
mClientMapByBundleID.erase(theClient.mBundleID);
}
return theClient;
}
bool EQM_ClientMap::GetClientRT(UInt32 inClientID, EQM_Client* outClient) const
{
CAMutex::Locker theMapsLocker(mMapsMutex);
return GetClient(mClientMap, inClientID, outClient);
}
bool EQM_ClientMap::GetClientNonRT(UInt32 inClientID, EQM_Client* outClient) const
{
CAMutex::Locker theShadowMapsLocker(mShadowMapsMutex);
return GetClient(mClientMapShadow, inClientID, outClient);
}
//static
bool EQM_ClientMap::GetClient(const std::map<UInt32, EQM_Client>& inClientMap, UInt32 inClientID, EQM_Client* outClient)
{
auto theClientItr = inClientMap.find(inClientID);
if(theClientItr != inClientMap.end())
{
*outClient = theClientItr->second;
return true;
}
return false;
}
std::vector<EQM_Client> EQM_ClientMap::GetClientsByPID(pid_t inPID) const
{
CAMutex::Locker theShadowMapsLocker(mShadowMapsMutex);
std::vector<EQM_Client> theClients;
auto theMapItr = mClientMapByPIDShadow.find(inPID);
if(theMapItr != mClientMapByPIDShadow.end())
{
// Found clients with the PID, so copy them into the return vector
for(auto& theClientPtrsItr : theMapItr->second)
{
theClients.push_back(*theClientPtrsItr);
}
}
return theClients;
}
#pragma mark Music Player
void EQM_ClientMap::UpdateMusicPlayerFlags(pid_t inMusicPlayerPID)
{
CAMutex::Locker theShadowMapsLocker(mShadowMapsMutex);
auto theIsMusicPlayerTest = [&] (EQM_Client theClient) {
return (theClient.mProcessID == inMusicPlayerPID);
};
UpdateMusicPlayerFlagsInShadowMaps(theIsMusicPlayerTest);
SwapInShadowMaps();
UpdateMusicPlayerFlagsInShadowMaps(theIsMusicPlayerTest);
}
void EQM_ClientMap::UpdateMusicPlayerFlags(CACFString inMusicPlayerBundleID)
{
CAMutex::Locker theShadowMapsLocker(mShadowMapsMutex);
auto theIsMusicPlayerTest = [&] (EQM_Client theClient) {
return (theClient.mBundleID.IsValid() && theClient.mBundleID == inMusicPlayerBundleID);
};
UpdateMusicPlayerFlagsInShadowMaps(theIsMusicPlayerTest);
SwapInShadowMaps();
UpdateMusicPlayerFlagsInShadowMaps(theIsMusicPlayerTest);
}
void EQM_ClientMap::UpdateMusicPlayerFlagsInShadowMaps(std::function<bool(EQM_Client)> inIsMusicPlayerTest)
{
for(auto& theItr : mClientMapShadow)
{
EQM_Client& theClient = theItr.second;
theClient.mIsMusicPlayer = inIsMusicPlayerTest(theClient);
}
}
#pragma mark App Volumes
CACFArray EQM_ClientMap::CopyClientRelativeVolumesAsAppVolumes(CAVolumeCurve inVolumeCurve) const
{
// Since this is a read-only, non-real-time operation, we can read from the shadow maps to avoid
// locking the main maps.
CAMutex::Locker theShadowMapsLocker(mShadowMapsMutex);
CACFArray theAppVolumes(false);
for(auto& theClientEntry : mClientMapShadow)
{
CopyClientIntoAppVolumesArray(theClientEntry.second, inVolumeCurve, theAppVolumes);
}
for(auto& thePastClientEntry : mPastClientMap)
{
CopyClientIntoAppVolumesArray(thePastClientEntry.second, inVolumeCurve, theAppVolumes);
}
return theAppVolumes;
}
void EQM_ClientMap::CopyClientIntoAppVolumesArray(EQM_Client inClient, CAVolumeCurve inVolumeCurve, CACFArray& ioAppVolumes) const
{
// Only include clients set to a non-default volume or pan
if(inClient.mRelativeVolume != 1.0 || inClient.mPanPosition != 0)
{
CACFDictionary theAppVolume(false);
theAppVolume.AddSInt32(CFSTR(kEQMAppVolumesKey_ProcessID), inClient.mProcessID);
theAppVolume.AddString(CFSTR(kEQMAppVolumesKey_BundleID), inClient.mBundleID.CopyCFString());
// Reverse the volume conversion from SetClientsRelativeVolumes
theAppVolume.AddSInt32(CFSTR(kEQMAppVolumesKey_RelativeVolume),
inVolumeCurve.ConvertScalarToRaw(inClient.mRelativeVolume / 4));
theAppVolume.AddSInt32(CFSTR(kEQMAppVolumesKey_PanPosition),
inClient.mPanPosition);
ioAppVolumes.AppendDictionary(theAppVolume.GetDict());
}
}
template <typename T>
std::vector<EQM_Client*> * _Nullable GetClientsFromMap(std::map<T, std::vector<EQM_Client*>> & map, T key) {
auto theClientItr = map.find(key);
if(theClientItr != map.end()) {
return &theClientItr->second;
}
return nullptr;
}
std::vector<EQM_Client*> * _Nullable EQM_ClientMap::GetClients(pid_t inAppPid) {
return GetClientsFromMap(mClientMapByPIDShadow, inAppPid);
}
std::vector<EQM_Client*> * _Nullable EQM_ClientMap::GetClients(CACFString inAppBundleID) {
return GetClientsFromMap(mClientMapByBundleIDShadow, inAppBundleID);
}
void ShowSetRelativeVolumeMessage(pid_t inAppPID, EQM_Client* theClient);
void ShowSetRelativeVolumeMessage(CACFString inAppBundleID, EQM_Client* theClient);
void ShowSetRelativeVolumeMessage(pid_t inAppPID, EQM_Client* theClient) {
(void)inAppPID;
(void)theClient;
DebugMsg("EQM_ClientMap::ShowSetRelativeVolumeMessage: Set volume %f for client %u by pid (%d)",
theClient->mRelativeVolume,
theClient->mClientID,
inAppPID);
}
void ShowSetRelativeVolumeMessage(CACFString inAppBundleID, EQM_Client* theClient) {
(void)inAppBundleID;
(void)theClient;
DebugMsg("EQM_ClientMap::ShowSetRelativeVolumeMessage: Set volume %f for client %u by bundle ID (%s)",
theClient->mRelativeVolume,
theClient->mClientID,
CFStringGetCStringPtr(inAppBundleID.GetCFString(), kCFStringEncodingUTF8));
}
// Template method declarations are running into LLVM bug 23987
// TODO: template these.
//bool EQM_ClientMap::SetClientsRelativeVolume(pid_t inAppPID, Float32 inRelativeVolume) {
// return SetClientsRelativeVolumeT<pid_t>(inAppPID, inRelativeVolume);
//}
//bool EQM_ClientMap::SetClientsRelativeVolume(CACFString inAppBundleID, Float32 inRelativeVolume) {
// return SetClientsRelativeVolumeT<CACFString>(inAppBundleID, inRelativeVolume)
//}
//template <typename T>
//bool EQM_ClientMap::SetClientsRelativeVolume(T searchKey, Float32 inRelativeVolume)
bool EQM_ClientMap::SetClientsRelativeVolume(pid_t searchKey, Float32 inRelativeVolume)
{
bool didChangeVolume = false;
CAMutex::Locker theShadowMapsLocker(mShadowMapsMutex);
auto theSetVolumesInShadowMapsFunc = [&] {
// Look up the clients for the key and update their volumes
auto theClients = GetClients(searchKey);
if(theClients != nullptr)
{
for(EQM_Client* theClient : *theClients)
{
theClient->mRelativeVolume = inRelativeVolume;
ShowSetRelativeVolumeMessage(searchKey, theClient);
didChangeVolume = true;
}
}
};
theSetVolumesInShadowMapsFunc();
SwapInShadowMaps();
theSetVolumesInShadowMapsFunc();
return didChangeVolume;
}
bool EQM_ClientMap::SetClientsRelativeVolume(CACFString searchKey, Float32 inRelativeVolume)
{
bool didChangeVolume = false;
CAMutex::Locker theShadowMapsLocker(mShadowMapsMutex);
auto theSetVolumesInShadowMapsFunc = [&] {
// Look up the clients for the key and update their volumes
auto theClients = GetClients(searchKey);
if(theClients != nullptr)
{
for(EQM_Client* theClient : *theClients)
{
theClient->mRelativeVolume = inRelativeVolume;
ShowSetRelativeVolumeMessage(searchKey, theClient);
didChangeVolume = true;
}
}
};
theSetVolumesInShadowMapsFunc();
SwapInShadowMaps();
theSetVolumesInShadowMapsFunc();
return didChangeVolume;
}
bool EQM_ClientMap::SetClientsPanPosition(pid_t searchKey, SInt32 inPanPosition)
{
bool didChangePanPosition = false;
CAMutex::Locker theShadowMapsLocker(mShadowMapsMutex);
auto theSetPansInShadowMapsFunc = [&] {
// Look up the clients for the key and update their pan positions
auto theClients = GetClients(searchKey);
if(theClients != nullptr) {
for(auto theClient: *theClients) {
theClient->mPanPosition = inPanPosition;
didChangePanPosition = true;
}
}
};
theSetPansInShadowMapsFunc();
SwapInShadowMaps();
theSetPansInShadowMapsFunc();
return didChangePanPosition;
}
bool EQM_ClientMap::SetClientsPanPosition(CACFString searchKey, SInt32 inPanPosition)
{
bool didChangePanPosition = false;
CAMutex::Locker theShadowMapsLocker(mShadowMapsMutex);
auto theSetPansInShadowMapsFunc = [&] {
// Look up the clients for the key and update their pan positions
auto theClients = GetClients(searchKey);
if(theClients != nullptr) {
for(auto theClient: *theClients) {
theClient->mPanPosition = inPanPosition;
didChangePanPosition = true;
}
}
};
theSetPansInShadowMapsFunc();
SwapInShadowMaps();
theSetPansInShadowMapsFunc();
return didChangePanPosition;
}
void EQM_ClientMap::UpdateClientIOStateNonRT(UInt32 inClientID, bool inDoingIO)
{
CAMutex::Locker theShadowMapsLocker(mShadowMapsMutex);
mClientMapShadow[inClientID].mDoingIO = inDoingIO;
SwapInShadowMaps();
mClientMapShadow[inClientID].mDoingIO = inDoingIO;
}
void EQM_ClientMap::SwapInShadowMaps()
{
mTaskQueue->QueueSync_SwapClientShadowMaps(this);
}
void EQM_ClientMap::SwapInShadowMapsRT()
{
#if DEBUG
// This method should only be called by the realtime worker thread in EQM_TaskQueue. The only safe way to call it is on a realtime
// thread while a non-realtime thread is holding the shadow maps mutex. (These assertions assume that the realtime worker thread is
// the only thread we'll call this on, but we could decide to change that at some point.)
mTaskQueue->AssertCurrentThreadIsRTWorkerThread("EQM_ClientMap::SwapInShadowMapsRT");
Assert(!mShadowMapsMutex.IsFree(), "Can't swap in the shadow maps while the shadow maps mutex is free");
Assert(!mShadowMapsMutex.IsOwnedByCurrentThread(), "The shadow maps mutex should not be held by a realtime thread");
#endif
CAMutex::Locker theMapsLocker(mMapsMutex);
mClientMap.swap(mClientMapShadow);
mClientMapByPID.swap(mClientMapByPIDShadow);
mClientMapByBundleID.swap(mClientMapByBundleIDShadow);
}
#pragma clang assume_nonnull end

View File

@ -1,179 +0,0 @@
//
// EQM_ClientMap.h
// EQMDriver
//
//
#ifndef __EQMDriver__EQM_ClientMap__
#define __EQMDriver__EQM_ClientMap__
// Local Includes
#include "EQM_Client.h"
#include "EQM_TaskQueue.h"
// PublicUtility Includes
#include "CAMutex.h"
#include "CACFString.h"
#include "CACFArray.h"
#include "CAVolumeCurve.h"
// STL Includes
#include <map>
#include <vector>
#include <functional>
// Forward Declarations
class EQM_ClientTasks;
#pragma clang assume_nonnull begin
//==================================================================================================
// EQM_ClientMap
//
// This class stores the clients (EQM_Client) that have been registered with EQMDevice by the HAL.
// It also maintains maps from clients' PIDs and bundle IDs to the clients. When a client is
// removed by the HAL we add it to a map of past clients to keep track of settings specific to that
// client. (Currently only the client's volume.)
//
// Since the maps are read from during IO, this class has to to be real-time safe when accessing
// them. So each map has an identical "shadow" map, which we use to buffer updates.
//
// To update the clients we lock the shadow maps, modify them, have EQM_TaskQueue's real-time
// thread swap them with the main maps, and then repeat the modification to keep both sets of maps
// identical. We have to swap the maps on a real-time thread so we can take the main maps' lock
// without risking priority inversion, but this way the actual work doesn't need to be real-time
// safe.
//
// Methods that only read from the maps and are called on non-real-time threads will just read
// from the shadow maps because it's easier.
//
// Methods whose names end with "RT" and "NonRT" can only safely be called from real-time and
// non-real-time threads respectively. (Methods with neither are most likely non-RT.)
//==================================================================================================
class EQM_ClientMap
{
friend class EQM_ClientTasks;
typedef std::vector<EQM_Client*> EQM_ClientPtrList;
public:
EQM_ClientMap(EQM_TaskQueue* inTaskQueue) : mTaskQueue(inTaskQueue), mMapsMutex("Maps mutex"), mShadowMapsMutex("Shadow maps mutex") { };
void AddClient(EQM_Client inClient);
private:
void AddClientToShadowMaps(EQM_Client inClient);
public:
// Returns the removed client
EQM_Client RemoveClient(UInt32 inClientID);
// These methods are functionally identical except that GetClientRT must only be called from real-time threads and GetClientNonRT
// must only be called from non-real-time threads. Both return true if a client was found.
bool GetClientRT(UInt32 inClientID, EQM_Client* outClient) const;
bool GetClientNonRT(UInt32 inClientID, EQM_Client* outClient) const;
private:
static bool GetClient(const std::map<UInt32, EQM_Client>& inClientMap,
UInt32 inClientID,
EQM_Client* outClient);
public:
std::vector<EQM_Client> GetClientsByPID(pid_t inPID) const;
// Set the isMusicPlayer flag for each client. (True if the client has the given bundle ID/PID, false otherwise.)
void UpdateMusicPlayerFlags(pid_t inMusicPlayerPID);
void UpdateMusicPlayerFlags(CACFString inMusicPlayerBundleID);
private:
void UpdateMusicPlayerFlagsInShadowMaps(std::function<bool(EQM_Client)> inIsMusicPlayerTest);
public:
// Copies the current and past clients into an array in the format expected for
// kAudioDeviceCustomPropertyAppVolumes. (Except that CACFArray and CACFDictionary are used instead
// of unwrapped CFArray and CFDictionary refs.)
CACFArray CopyClientRelativeVolumesAsAppVolumes(CAVolumeCurve inVolumeCurve) const;
private:
void CopyClientIntoAppVolumesArray(EQM_Client inClient, CAVolumeCurve inVolumeCurve, CACFArray& ioAppVolumes) const;
public:
// Using the template function hits LLVM Bug 23987
// TODO Switch to template function
// Returns true if a client for the key was found and its relative volume changed.
//template <typename T>
//bool SetClientsRelativeVolume(T _Null_unspecified searchKey, Float32 inRelativeVolume);
//
//template <typename T>
//bool SetClientsPanPosition(T _Null_unspecified searchKey, SInt32 inPanPosition);
// Returns true if a client for PID inAppPID was found and its relative volume changed.
bool SetClientsRelativeVolume(pid_t inAppPID, Float32 inRelativeVolume);
// Returns true if a client for bundle ID inAppBundleID was found and its relative volume changed.
bool SetClientsRelativeVolume(CACFString inAppBundleID, Float32 inRelativeVolume);
// Returns true if a client for PID inAppPID was found and its pan position changed.
bool SetClientsPanPosition(pid_t inAppPID, SInt32 inPanPosition);
// Returns true if a client for bundle ID inAppBundleID was found and its pan position changed.
bool SetClientsPanPosition(CACFString inAppBundleID, SInt32 inPanPosition);
void StartIONonRT(UInt32 inClientID) { UpdateClientIOStateNonRT(inClientID, true); }
void StopIONonRT(UInt32 inClientID) { UpdateClientIOStateNonRT(inClientID, false); }
// Client lookup for PID inAppPID
std::vector<EQM_Client*> * _Nullable GetClients(pid_t inAppPid);
// Client lookup for bundle ID inAppBundleID
std::vector<EQM_Client*> * _Nullable GetClients(CACFString inAppBundleID);
private:
void UpdateClientIOStateNonRT(UInt32 inClientID, bool inDoingIO);
// Has a real-time thread call SwapInShadowMapsRT. (Synchronously queues the call as a task on mTaskQueue.)
// The shadow maps mutex must be locked when calling this method.
void SwapInShadowMaps();
// Note that this method is called by EQM_TaskQueue through the EQM_ClientTasks interface. The shadow maps
// mutex must be locked when calling this method.
void SwapInShadowMapsRT();
private:
EQM_TaskQueue* mTaskQueue;
// Must be held to access mClientMap or mClientMapByPID. Code that runs while holding this mutex needs
// to be real-time safe. Should probably not be held for most operations on mClientMapByBundleID because,
// as far as I can tell, code that works with CFStrings is unlikely to be real-time safe.
CAMutex mMapsMutex;
// Should only be locked by non-real-time threads. Should not be released until the maps have been
// made identical to their shadow maps.
CAMutex mShadowMapsMutex;
// The clients currently registered with EQMDevice. Indexed by client ID.
std::map<UInt32, EQM_Client> mClientMap;
// We keep this in sync with mClientMap so it can be modified outside of real-time safe sections and
// then swapped in on a real-time thread, which is safe.
std::map<UInt32, EQM_Client> mClientMapShadow;
// These maps hold lists of pointers to clients in mClientMap/mClientMapShadow. Lists because a process
// can have multiple clients and clients can have the same bundle ID.
std::map<pid_t, EQM_ClientPtrList> mClientMapByPID;
std::map<pid_t, EQM_ClientPtrList> mClientMapByPIDShadow;
std::map<CACFString, EQM_ClientPtrList> mClientMapByBundleID;
std::map<CACFString, EQM_ClientPtrList> mClientMapByBundleIDShadow;
// Clients are added to mPastClientMap so we can restore settings specific to them if they get
// added again.
std::map<CACFString, EQM_Client> mPastClientMap;
};
#pragma clang assume_nonnull end
#endif /* __EQMDriver__EQM_ClientMap__ */

View File

@ -1,39 +0,0 @@
//
// EQM_ClientTasks.h
// EQMDriver
//
//
// The interface between the client classes (EQM_Client, EQM_Clients and EQM_ClientMap) and EQM_TaskQueue.
//
#ifndef __EQMDriver__EQM_ClientTasks__
#define __EQMDriver__EQM_ClientTasks__
// Local Includes
#include "EQM_Clients.h"
#include "EQM_ClientMap.h"
// Forward Declarations
class EQM_TaskQueue;
#pragma clang assume_nonnull begin
class EQM_ClientTasks
{
friend class EQM_TaskQueue;
private:
static bool StartIONonRT(EQM_Clients* inClients, UInt32 inClientID) { return inClients->StartIONonRT(inClientID); }
static bool StopIONonRT(EQM_Clients* inClients, UInt32 inClientID) { return inClients->StopIONonRT(inClientID); }
static void SwapInShadowMapsRT(EQM_ClientMap* inClientMap) { inClientMap->SwapInShadowMapsRT(); }
};
#pragma clang assume_nonnull end
#endif /* __EQMDriver__EQM_ClientTasks__ */

View File

@ -1,386 +0,0 @@
//
// EQM_Clients.cpp
// EQMDriver
//
// Copyright © 2017 Andrew Tonner
//
// Self Include
#include "EQM_Clients.h"
// Local Includes
#include "EQM_Types.h"
#include "EQM_PlugIn.h"
// PublicUtility Includes
#include "CAException.h"
#include "CACFDictionary.h"
#include "CADispatchQueue.h"
#pragma mark Construction/Destruction
EQM_Clients::EQM_Clients(AudioObjectID inOwnerDeviceID, EQM_TaskQueue* inTaskQueue)
:
mOwnerDeviceID(inOwnerDeviceID),
mClientMap(inTaskQueue)
{
mRelativeVolumeCurve.AddRange(kAppRelativeVolumeMinRawValue,
kAppRelativeVolumeMaxRawValue,
kAppRelativeVolumeMinDbValue,
kAppRelativeVolumeMaxDbValue);
}
#pragma mark Add/Remove Clients
void EQM_Clients::AddClient(EQM_Client inClient)
{
CAMutex::Locker theLocker(mMutex);
// Check whether this is the music player's client
bool pidMatchesMusicPlayerProperty =
(mMusicPlayerProcessIDProperty != 0 && inClient.mProcessID == mMusicPlayerProcessIDProperty);
bool bundleIDMatchesMusicPlayerProperty =
(mMusicPlayerBundleIDProperty != "" &&
inClient.mBundleID.IsValid() &&
inClient.mBundleID == mMusicPlayerBundleIDProperty);
inClient.mIsMusicPlayer = (pidMatchesMusicPlayerProperty || bundleIDMatchesMusicPlayerProperty);
if(inClient.mIsMusicPlayer)
{
DebugMsg("EQM_Clients::AddClient: Adding music player client. mClientID = %u", inClient.mClientID);
}
mClientMap.AddClient(inClient);
// If we're adding EQMApp, update our local copy of its client ID
// if(inClient.mBundleID.IsValid() && inClient.mBundleID == kEQMAppBundleID)
// {
// mEQMAppClientID = inClient.mClientID;
// }
}
void EQM_Clients::RemoveClient(const UInt32 inClientID)
{
CAMutex::Locker theLocker(mMutex);
EQM_Client theRemovedClient = mClientMap.RemoveClient(inClientID);
// If we're removing EQMApp, clear our local copy of its client ID
if(theRemovedClient.mClientID == mEQMAppClientID)
{
mEQMAppClientID = -1;
}
}
#pragma mark IO Status
bool EQM_Clients::StartIONonRT(UInt32 inClientID)
{
CAMutex::Locker theLocker(mMutex);
bool didStartIO = false;
EQM_Client theClient;
bool didFindClient = mClientMap.GetClientNonRT(inClientID, &theClient);
ThrowIf(!didFindClient, EQM_InvalidClientException(), "EQM_Clients::StartIO: Cannot start IO for client that was never added");
bool sendIsRunningNotification = false;
bool sendIsRunningSomewhereOtherThanEQMAppNotification = false;
if(!theClient.mDoingIO)
{
// Make sure we can start
ThrowIf(mStartCount == UINT64_MAX, CAException(kAudioHardwareIllegalOperationError), "EQM_Clients::StartIO: failed to start because the ref count was maxxed out already");
DebugMsg("EQM_Clients::StartIO: Client %u (%s, %d) starting IO",
inClientID,
CFStringGetCStringPtr(theClient.mBundleID.GetCFString(), kCFStringEncodingUTF8),
theClient.mProcessID);
mClientMap.StartIONonRT(inClientID);
mStartCount++;
// Update mStartCountExcludingEQMApp
if(!IsEQMApp(inClientID))
{
ThrowIf(mStartCountExcludingEQMApp == UINT64_MAX, CAException(kAudioHardwareIllegalOperationError), "EQM_Clients::StartIO: failed to start because mStartCountExcludingEQMApp was maxxed out already");
mStartCountExcludingEQMApp++;
if(mStartCountExcludingEQMApp == 1)
{
sendIsRunningSomewhereOtherThanEQMAppNotification = true;
}
}
// Return true if no other clients were running IO before this one started, which means the device should start IO
didStartIO = (mStartCount == 1);
sendIsRunningNotification = didStartIO;
}
Assert(mStartCountExcludingEQMApp == mStartCount - 1 || mStartCountExcludingEQMApp == mStartCount,
"mStartCount and mStartCountExcludingEQMApp are out of sync");
SendIORunningNotifications(sendIsRunningNotification, sendIsRunningSomewhereOtherThanEQMAppNotification);
return didStartIO;
}
bool EQM_Clients::StopIONonRT(UInt32 inClientID)
{
CAMutex::Locker theLocker(mMutex);
bool didStopIO = false;
EQM_Client theClient;
bool didFindClient = mClientMap.GetClientNonRT(inClientID, &theClient);
ThrowIf(!didFindClient, EQM_InvalidClientException(), "EQM_Clients::StopIO: Cannot stop IO for client that was never added");
bool sendIsRunningNotification = false;
bool sendIsRunningSomewhereOtherThanEQMAppNotification = false;
if(theClient.mDoingIO)
{
DebugMsg("EQM_Clients::StopIO: Client %u (%s, %d) stopping IO",
inClientID,
CFStringGetCStringPtr(theClient.mBundleID.GetCFString(), kCFStringEncodingUTF8),
theClient.mProcessID);
mClientMap.StopIONonRT(inClientID);
ThrowIf(mStartCount <= 0, CAException(kAudioHardwareIllegalOperationError), "EQM_Clients::StopIO: Underflowed mStartCount");
mStartCount--;
// Update mStartCountExcludingEQMApp
if(!IsEQMApp(inClientID))
{
ThrowIf(mStartCountExcludingEQMApp <= 0, CAException(kAudioHardwareIllegalOperationError), "EQM_Clients::StopIO: Underflowed mStartCountExcludingEQMApp");
mStartCountExcludingEQMApp--;
if(mStartCountExcludingEQMApp == 0)
{
sendIsRunningSomewhereOtherThanEQMAppNotification = true;
}
}
// Return true if we stopped IO entirely (i.e. there are no clients still running IO)
didStopIO = (mStartCount == 0);
sendIsRunningNotification = didStopIO;
}
Assert(mStartCountExcludingEQMApp == mStartCount - 1 || mStartCountExcludingEQMApp == mStartCount,
"mStartCount and mStartCountExcludingEQMApp are out of sync");
SendIORunningNotifications(sendIsRunningNotification, sendIsRunningSomewhereOtherThanEQMAppNotification);
return didStopIO;
}
bool EQM_Clients::ClientsRunningIO() const
{
return mStartCount > 0;
}
bool EQM_Clients::ClientsOtherThanEQMAppRunningIO() const
{
return mStartCountExcludingEQMApp > 0;
}
void EQM_Clients::SendIORunningNotifications(bool sendIsRunningNotification, bool sendIsRunningSomewhereOtherThanEQMAppNotification) const
{
if(sendIsRunningNotification || sendIsRunningSomewhereOtherThanEQMAppNotification)
{
CADispatchQueue::GetGlobalSerialQueue().Dispatch(false, ^{
AudioObjectPropertyAddress theChangedProperties[2];
UInt32 theNotificationCount = 0;
if(sendIsRunningNotification)
{
DebugMsg("EQM_Clients::SendIORunningNotifications: Sending kAudioDevicePropertyDeviceIsRunning");
theChangedProperties[0] = { kAudioDevicePropertyDeviceIsRunning, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
theNotificationCount++;
}
if(sendIsRunningSomewhereOtherThanEQMAppNotification)
{
DebugMsg("EQM_Clients::SendIORunningNotifications: Sending kAudioDeviceCustomPropertyDeviceIsRunningSomewhereOtherThanEQMApp");
theChangedProperties[theNotificationCount] = kEQMRunningSomewhereOtherThanEQMAppAddress;
theNotificationCount++;
}
EQM_PlugIn::Host_PropertiesChanged(mOwnerDeviceID, theNotificationCount, theChangedProperties);
});
}
}
#pragma mark Music Player
bool EQM_Clients::SetMusicPlayer(const pid_t inPID)
{
ThrowIf(inPID < 0, EQM_InvalidClientPIDException(), "EQM_Clients::SetMusicPlayer: Invalid music player PID");
CAMutex::Locker theLocker(mMutex);
if(mMusicPlayerProcessIDProperty == inPID)
{
// We're not changing the properties, so return false
return false;
}
mMusicPlayerProcessIDProperty = inPID;
// Unset the bundle ID property
mMusicPlayerBundleIDProperty = "";
DebugMsg("EQM_Clients::SetMusicPlayer: Setting music player by PID. inPID=%d", inPID);
// Update the clients' mIsMusicPlayer fields
mClientMap.UpdateMusicPlayerFlags(inPID);
return true;
}
bool EQM_Clients::SetMusicPlayer(const CACFString inBundleID)
{
Assert(inBundleID.IsValid(), "EQM_Clients::SetMusicPlayer: Invalid CACFString given as bundle ID");
CAMutex::Locker theLocker(mMutex);
if(mMusicPlayerBundleIDProperty == inBundleID)
{
// We're not changing the properties, so return false
return false;
}
mMusicPlayerBundleIDProperty = inBundleID;
// Unset the PID property
mMusicPlayerProcessIDProperty = 0;
DebugMsg("EQM_Clients::SetMusicPlayer: Setting music player by bundle ID. inBundleID=%s",
CFStringGetCStringPtr(inBundleID.GetCFString(), kCFStringEncodingUTF8));
// Update the clients' mIsMusicPlayer fields
mClientMap.UpdateMusicPlayerFlags(inBundleID);
return true;
}
bool EQM_Clients::IsMusicPlayerRT(const UInt32 inClientID) const
{
EQM_Client theClient;
bool didGetClient = mClientMap.GetClientRT(inClientID, &theClient);
return didGetClient && theClient.mIsMusicPlayer;
}
#pragma mark App Volumes
Float32 EQM_Clients::GetClientRelativeVolumeRT(UInt32 inClientID) const
{
EQM_Client theClient;
bool didGetClient = mClientMap.GetClientRT(inClientID, &theClient);
return (didGetClient ? theClient.mRelativeVolume : 1.0f);
}
SInt32 EQM_Clients::GetClientPanPositionRT(UInt32 inClientID) const
{
EQM_Client theClient;
bool didGetClient = mClientMap.GetClientRT(inClientID, &theClient);
return (didGetClient ? theClient.mPanPosition : kAppPanCenterRawValue);
}
bool EQM_Clients::SetClientsRelativeVolumes(const CACFArray inAppVolumes)
{
bool didChangeAppVolumes = false;
// Each element in appVolumes is a CFDictionary containing the process id and/or bundle id of an app, and its
// new relative volume
for(UInt32 i = 0; i < inAppVolumes.GetNumberItems(); i++)
{
CACFDictionary theAppVolume(false);
inAppVolumes.GetCACFDictionary(i, theAppVolume);
// Get the app's PID from the dict
pid_t theAppPID;
bool didFindPID = theAppVolume.GetSInt32(CFSTR(kEQMAppVolumesKey_ProcessID), theAppPID);
// Get the app's bundle ID from the dict
CACFString theAppBundleID;
theAppBundleID.DontAllowRelease();
theAppVolume.GetCACFString(CFSTR(kEQMAppVolumesKey_BundleID), theAppBundleID);
ThrowIf(!didFindPID && !theAppBundleID.IsValid(),
EQM_InvalidClientRelativeVolumeException(),
"EQM_Clients::SetClientsRelativeVolumes: App volume was sent without PID or bundle ID for app");
bool didGetVolume;
{
SInt32 theRawRelativeVolume;
didGetVolume = theAppVolume.GetSInt32(CFSTR(kEQMAppVolumesKey_RelativeVolume), theRawRelativeVolume);
if (didGetVolume) {
ThrowIf(didGetVolume && (theRawRelativeVolume < kAppRelativeVolumeMinRawValue || theRawRelativeVolume > kAppRelativeVolumeMaxRawValue),
EQM_InvalidClientRelativeVolumeException(),
"EQM_Clients::SetClientsRelativeVolumes: Relative volume for app out of valid range");
// Apply the volume curve to the raw volume
//
// mRelativeVolumeCurve uses the default kPow2Over1Curve transfer function, so we also multiply by 4 to
// keep the middle volume equal to 1 (meaning apps' volumes are unchanged by default).
Float32 theRelativeVolume = mRelativeVolumeCurve.ConvertRawToScalar(theRawRelativeVolume) * 4;
// Try to update the client's volume, first by PID and then by bundle ID. Always try
// both because apps can have multiple clients.
if(mClientMap.SetClientsRelativeVolume(theAppPID, theRelativeVolume))
{
didChangeAppVolumes = true;
}
if(mClientMap.SetClientsRelativeVolume(theAppBundleID, theRelativeVolume))
{
didChangeAppVolumes = true;
}
// TODO: If the app isn't currently a client, we should add it to the past clients
// map, or update its past volume if it's already in there.
}
}
bool didGetPanPosition;
{
SInt32 thePanPosition;
didGetPanPosition = theAppVolume.GetSInt32(CFSTR(kEQMAppVolumesKey_PanPosition), thePanPosition);
if (didGetPanPosition) {
ThrowIf(didGetPanPosition && (thePanPosition < kAppPanLeftRawValue || thePanPosition > kAppPanRightRawValue),
EQM_InvalidClientPanPositionException(),
"EQM_Clients::SetClientsRelativeVolumes: Pan position for app out of valid range");
if(mClientMap.SetClientsPanPosition(theAppPID, thePanPosition))
{
didChangeAppVolumes = true;
}
if(mClientMap.SetClientsPanPosition(theAppBundleID, thePanPosition))
{
didChangeAppVolumes = true;
}
// TODO: If the app isn't currently a client, we should add it to the past clients
// map, or update its past pan position if it's already in there.
}
}
ThrowIf(!didGetVolume && !didGetPanPosition,
EQM_InvalidClientRelativeVolumeException(),
"EQM_Clients::SetClientsRelativeVolumes: No volume or pan position in request");
}
return didChangeAppVolumes;
}

View File

@ -1,135 +0,0 @@
//
// EQM_Clients.h
// EQMDriver
//
//
#ifndef __EQMDriver__EQM_Clients__
#define __EQMDriver__EQM_Clients__
// Local Includes
#include "EQM_Client.h"
#include "EQM_ClientMap.h"
// PublicUtility Includes
#include "CAVolumeCurve.h"
#include "CAMutex.h"
#include "CACFArray.h"
// System Includes
#include <CoreAudio/AudioServerPlugIn.h>
// Forward Declations
class EQM_ClientTasks;
#pragma clang assume_nonnull begin
//==================================================================================================
// EQM_Clients
//
// Holds information about the clients (of the host) of the EQMDevice, i.e. the apps registered
// with the HAL, generally so they can do IO at some point. EQMApp and the music player are special
// case clients.
//
// Methods whose names end with "RT" should only be called from real-time threads.
//==================================================================================================
class EQM_Clients
{
friend class EQM_ClientTasks;
public:
EQM_Clients(AudioObjectID inOwnerDeviceID, EQM_TaskQueue* inTaskQueue);
~EQM_Clients() = default;
// Disallow copying. (It could make sense to implement these in future, but we don't need them currently.)
EQM_Clients(const EQM_Clients&) = delete;
EQM_Clients& operator=(const EQM_Clients&) = delete;
void AddClient(EQM_Client inClient);
void RemoveClient(const UInt32 inClientID);
private:
// Only EQM_TaskQueue is allowed to call these (through the EQM_ClientTasks interface). We get notifications
// from the HAL when clients start/stop IO and they have to be processed in the order we receive them to
// avoid race conditions. If these methods could be called directly those calls would skip any queued calls.
bool StartIONonRT(UInt32 inClientID);
bool StopIONonRT(UInt32 inClientID);
public:
bool ClientsRunningIO() const;
bool ClientsOtherThanEQMAppRunningIO() const;
private:
void SendIORunningNotifications(bool sendIsRunningNotification, bool sendIsRunningSomewhereOtherThanEQMAppNotification) const;
public:
EQM_ClientMap mClientMap;
bool IsEQMApp(UInt32 inClientID) const { return inClientID == mEQMAppClientID; }
bool EQMAppHasClientRegistered() const { return mEQMAppClientID != -1; }
inline pid_t GetMusicPlayerProcessIDProperty() const { return mMusicPlayerProcessIDProperty; }
inline CFStringRef CopyMusicPlayerBundleIDProperty() const { return mMusicPlayerBundleIDProperty.CopyCFString(); }
// Returns true if the PID was changed
bool SetMusicPlayer(const pid_t inPID);
// Returns true if the bundle ID was changed
bool SetMusicPlayer(const CACFString inBundleID);
bool IsMusicPlayerRT(const UInt32 inClientID) const;
Float32 GetClientRelativeVolumeRT(UInt32 inClientID) const;
SInt32 GetClientPanPositionRT(UInt32 inClientID) const;
// Copies the current and past clients into an array in the format expected for
// kAudioDeviceCustomPropertyAppVolumes. (Except that CACFArray and CACFDictionary are used instead
// of unwrapped CFArray and CFDictionary refs.)
CACFArray CopyClientRelativeVolumesAsAppVolumes() const { return mClientMap.CopyClientRelativeVolumesAsAppVolumes(mRelativeVolumeCurve); };
// inAppVolumes is an array of dicts with the keys kEQMAppVolumesKey_ProcessID,
// kEQMAppVolumesKey_BundleID and optionally kEQMAppVolumesKey_RelativeVolume and
// kEQMAppVolumesKey_PanPosition. This method finds the client for
// each app by PID or bundle ID, sets the volume and applies mRelativeVolumeCurve to it.
//
// Returns true if any clients' relative volumes were changed.
bool SetClientsRelativeVolumes(const CACFArray inAppVolumes);
private:
AudioObjectID mOwnerDeviceID;
// Counters for the number of clients that are doing IO. These are used to tell whether any clients
// are currently doing IO without having to check every client's mDoingIO.
//
// We need to reference count this rather than just using a bool because the HAL might (but usually
// doesn't) call our StartIO/StopIO functions for clients other than the first to start and last to
// stop.
UInt64 mStartCount = 0;
UInt64 mStartCountExcludingEQMApp = 0;
CAMutex mMutex { "Clients" };
SInt64 mEQMAppClientID = -1;
// The value of the kAudioDeviceCustomPropertyMusicPlayerProcessID property, or 0 if it's unset/null.
// We store this separately because the music player might not always be a client, but could be added
// as one at a later time.
pid_t mMusicPlayerProcessIDProperty = 0;
// The value of the kAudioDeviceCustomPropertyMusicPlayerBundleID property, or the empty string it it's
// unset/null. UTF8 encoding.
//
// As with mMusicPlayerProcessID, we keep a copy of the bundle ID the user sets for the music player
// because there might be no client with that bundle ID. In that case we need to be able to give the
// property's value if the HAL asks for it, and to recognise the music player if it's added a client.
CACFString mMusicPlayerBundleIDProperty { "" };
// The volume curve we apply to raw client volumes before they're used
CAVolumeCurve mRelativeVolumeCurve;
};
#pragma clang assume_nonnull end
#endif /* __EQMDriver__EQM_Clients__ */

View File

@ -1,53 +0,0 @@
//
// EQMXPCProtocols.h
// SharedSource
//
//
// Local Includes
#include "EQM_Types.h"
// System Includes
#import <Foundation/Foundation.h>
#pragma clang assume_nonnull begin
static NSString* kEQMXPCHelperMachServiceName = @kEQMXPCHelperBundleID;
// The protocol that EQMXPCHelper will vend as its XPC API.
@protocol EQMXPCHelperXPCProtocol
// Tells EQMXPCHelper that the caller is EQMApp and passes a listener endpoint that EQMXPCHelper can use to create connections to EQMApp.
// EQMXPCHelper may also pass the endpoint on to EQMDriver so it can do the same.
- (void) registerAsEQMAppWithListenerEndpoint:(NSXPCListenerEndpoint*)endpoint reply:(void (^)(void))reply;
- (void) unregisterAsEQMApp;
// EQMDriver calls this remote method when it wants EQMApp to start IO. EQMXPCHelper passes the message along and then passes the response
// back. This allows EQMDriver to wait for the audio hardware to start up, which means it can let the HAL know when it's safe to start
// sending us audio data from the client.
//
// If EQMApp can be reached, the error it returns will be passed the reply block. Otherwise, the reply block will be passed an error with
// one of the kEQMXPC_* error codes. It may have an underlying error using one of the NSXPCConnection* error codes from FoundationErrors.h.
- (void) startEQMAppPlayThroughSyncWithReply:(void (^)(NSError*))reply forUISoundsDevice:(BOOL)isUI;
// EQMXPCHelper will set the system's default output device to deviceID if it loses its connection
// to EQMApp and EQMApp has left EQMDevice as the default device. It waits for a short time first to
// give EQMApp a chance to fix the connection.
//
// This is so EQMDevice isn't left as the default device if EQMApp crashes or otherwise terminates
// abnormally. If audio is played to EQMDevice and EQMApp isn't running, the user won't hear it.
- (void) setOutputDeviceToMakeDefaultOnAbnormalTermination:(AudioObjectID)deviceID;
@end
// The protocol that EQMApp will vend as its XPC API.
@protocol EQMAppXPCProtocol
- (void) startPlayThroughSyncWithReply:(void (^)(NSError*))reply forUISoundsDevice:(BOOL)isUI;
@end
#pragma clang assume_nonnull end

View File

@ -1,395 +0,0 @@
//
// EQM_AbstractDevice.cpp
// EQMDriver
//
//
// Portions copyright (C) 2013 Apple Inc. All Rights Reserved.
//
// Self Include
#include "EQM_AbstractDevice.h"
// Local Includes
#include "EQM_Utils.h"
// PublicUtility Includes
#include "CAException.h"
#include "CADebugMacros.h"
#pragma clang assume_nonnull begin
EQM_AbstractDevice::EQM_AbstractDevice(AudioObjectID inObjectID, AudioObjectID inOwnerObjectID)
:
EQM_Object(inObjectID, kAudioDeviceClassID, kAudioObjectClassID, inOwnerObjectID)
{
}
EQM_AbstractDevice::~EQM_AbstractDevice()
{
}
#pragma mark Property Operations
bool EQM_AbstractDevice::HasProperty(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const
{
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioObjectPropertyName:
case kAudioObjectPropertyManufacturer:
case kAudioDevicePropertyDeviceUID:
case kAudioDevicePropertyModelUID:
case kAudioDevicePropertyTransportType:
case kAudioDevicePropertyRelatedDevices:
case kAudioDevicePropertyClockDomain:
case kAudioDevicePropertyDeviceIsAlive:
case kAudioDevicePropertyDeviceIsRunning:
case kAudioDevicePropertyDeviceCanBeDefaultDevice:
case kAudioDevicePropertyDeviceCanBeDefaultSystemDevice:
case kAudioDevicePropertyLatency:
case kAudioDevicePropertyStreams:
case kAudioObjectPropertyControlList:
case kAudioDevicePropertySafetyOffset:
case kAudioDevicePropertyNominalSampleRate:
case kAudioDevicePropertyAvailableNominalSampleRates:
case kAudioDevicePropertyIsHidden:
case kAudioDevicePropertyZeroTimeStampPeriod:
theAnswer = true;
break;
default:
theAnswer = EQM_Object::HasProperty(inObjectID, inClientPID, inAddress);
break;
};
return theAnswer;
}
bool EQM_AbstractDevice::IsPropertySettable(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const
{
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioObjectPropertyName:
case kAudioObjectPropertyManufacturer:
case kAudioDevicePropertyDeviceUID:
case kAudioDevicePropertyModelUID:
case kAudioDevicePropertyTransportType:
case kAudioDevicePropertyRelatedDevices:
case kAudioDevicePropertyClockDomain:
case kAudioDevicePropertyDeviceIsAlive:
case kAudioDevicePropertyDeviceIsRunning:
case kAudioDevicePropertyDeviceCanBeDefaultDevice:
case kAudioDevicePropertyDeviceCanBeDefaultSystemDevice:
case kAudioDevicePropertyLatency:
case kAudioDevicePropertyStreams:
case kAudioObjectPropertyControlList:
case kAudioDevicePropertySafetyOffset:
case kAudioDevicePropertyNominalSampleRate:
case kAudioDevicePropertyAvailableNominalSampleRates:
case kAudioDevicePropertyIsHidden:
case kAudioDevicePropertyZeroTimeStampPeriod:
theAnswer = false;
break;
default:
theAnswer = EQM_Object::IsPropertySettable(inObjectID, inClientPID, inAddress);
break;
};
return theAnswer;
}
UInt32 EQM_AbstractDevice::GetPropertyDataSize(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData) const
{
UInt32 theAnswer = 0;
switch(inAddress.mSelector)
{
case kAudioObjectPropertyName:
theAnswer = sizeof(CFStringRef);
break;
case kAudioObjectPropertyManufacturer:
theAnswer = sizeof(CFStringRef);
break;
case kAudioDevicePropertyDeviceUID:
theAnswer = sizeof(CFStringRef);
break;
case kAudioDevicePropertyModelUID:
theAnswer = sizeof(CFStringRef);
break;
case kAudioDevicePropertyTransportType:
theAnswer = sizeof(UInt32);
break;
case kAudioDevicePropertyRelatedDevices:
theAnswer = sizeof(AudioObjectID);
break;
case kAudioDevicePropertyClockDomain:
theAnswer = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceCanBeDefaultDevice:
theAnswer = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceCanBeDefaultSystemDevice:
theAnswer = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceIsAlive:
theAnswer = sizeof(AudioClassID);
break;
case kAudioDevicePropertyDeviceIsRunning:
theAnswer = sizeof(UInt32);
break;
case kAudioDevicePropertyLatency:
theAnswer = sizeof(UInt32);
break;
case kAudioDevicePropertyStreams:
theAnswer = 0;
break;
case kAudioObjectPropertyControlList:
theAnswer = 0;
break;
case kAudioDevicePropertySafetyOffset:
theAnswer = sizeof(UInt32);
break;
case kAudioDevicePropertyNominalSampleRate:
theAnswer = sizeof(Float64);
break;
case kAudioDevicePropertyAvailableNominalSampleRates:
theAnswer = 0;
break;
case kAudioDevicePropertyIsHidden:
theAnswer = sizeof(UInt32);
break;
case kAudioDevicePropertyZeroTimeStampPeriod:
theAnswer = sizeof(UInt32);
break;
default:
theAnswer = EQM_Object::GetPropertyDataSize(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData);
break;
};
return theAnswer;
}
void EQM_AbstractDevice::GetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData,
UInt32 inDataSize,
UInt32& outDataSize,
void* outData) const
{
UInt32 theNumberItemsToFetch;
switch(inAddress.mSelector)
{
case kAudioObjectPropertyName:
case kAudioObjectPropertyManufacturer:
case kAudioDevicePropertyDeviceUID:
case kAudioDevicePropertyModelUID:
case kAudioDevicePropertyDeviceIsRunning:
case kAudioDevicePropertyZeroTimeStampPeriod:
case kAudioDevicePropertyNominalSampleRate:
case kAudioDevicePropertyAvailableNominalSampleRates:
// Should be unreachable. Reaching this point would mean a concrete device has delegated
// a required property that can't be handled by this class or its parent, BGM_Object.
//
// See BGM_Device for info about these properties.
//
// TODO: Write a test that checks all required properties for each subclass.
EQMAssert(false,
"EQM_AbstractDevice::GetPropertyData: Property %u not handled in subclass",
inAddress.mSelector);
// Throw in release builds.
Throw(CAException(kAudioHardwareIllegalOperationError));
case kAudioDevicePropertyTransportType:
// This value represents how the device is attached to the system. This can be
// any 32 bit integer, but common values for this property are defined in
// <CoreAudio/AudioHardwareBase.h>.
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_AbstractDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyTransportType for the device");
// Default to virtual device.
*reinterpret_cast<UInt32*>(outData) = kAudioDeviceTransportTypeVirtual;
outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyRelatedDevices:
// The related devices property identifies device objects that are very closely
// related. Generally, this is for relating devices that are packaged together
// in the hardware such as when the input side and the output side of a piece
// of hardware can be clocked separately and therefore need to be represented
// as separate AudioDevice objects. In such case, both devices would report
// that they are related to each other. Note that at minimum, a device is
// related to itself, so this list will always be at least one item long.
// Calculate the number of items that have been requested. Note that this
// number is allowed to be smaller than the actual size of the list. In such
// case, only that number of items will be returned
theNumberItemsToFetch = inDataSize / sizeof(AudioObjectID);
// Default to only have the one device.
if(theNumberItemsToFetch > 1)
{
theNumberItemsToFetch = 1;
}
// Write the devices' object IDs into the return value.
if(theNumberItemsToFetch > 0)
{
reinterpret_cast<AudioObjectID*>(outData)[0] = GetObjectID();
}
// Report how much we wrote.
outDataSize = theNumberItemsToFetch * sizeof(AudioObjectID);
break;
case kAudioDevicePropertyClockDomain:
// This property allows the device to declare what other devices it is
// synchronized with in hardware. The way it works is that if two devices have
// the same value for this property and the value is not zero, then the two
// devices are synchronized in hardware. Note that a device that either can't
// be synchronized with others or doesn't know should return 0 for this
// property.
//
// Default to 0.
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_AbstractDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyClockDomain for the device");
*reinterpret_cast<UInt32*>(outData) = 0;
outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceIsAlive:
// Default to alive.
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_AbstractDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyDeviceIsAlive for the device");
*reinterpret_cast<UInt32*>(outData) = 1;
outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceCanBeDefaultDevice:
// This property returns whether or not the device wants to be able to be the
// default device for content. This is the device that iTunes and QuickTime
// will use to play their content on and FaceTime will use as it's microphone.
// Nearly all devices should allow for this.
//
// Default to true.
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_AbstractDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyDeviceCanBeDefaultDevice for the device");
*reinterpret_cast<UInt32*>(outData) = 1;
outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceCanBeDefaultSystemDevice:
// This property returns whether or not the device wants to be the system
// default device. This is the device that is used to play interface sounds and
// other incidental or UI-related sounds on. Most devices should allow this
// although devices with lots of latency may not want to.
//
// Default to true.
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_AbstractDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyDeviceCanBeDefaultSystemDevice for the device");
*reinterpret_cast<UInt32*>(outData) = 1;
outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyLatency:
// This property returns the presentation latency of the device. Default to 0.
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_AbstractDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyLatency for the device");
*reinterpret_cast<UInt32*>(outData) = 0;
outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyStreams:
// Default to not having any streams.
outDataSize = 0;
break;
case kAudioObjectPropertyControlList:
// Default to not having any controls.
outDataSize = 0;
break;
case kAudioDevicePropertySafetyOffset:
// This property returns the how close to now the HAL can read and write. Default to 0.
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_AbstractDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertySafetyOffset for the device");
*reinterpret_cast<UInt32*>(outData) = 0;
outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyIsHidden:
// This returns whether or not the device is visible to clients. Default to not hidden.
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_AbstractDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyIsHidden for the device");
*reinterpret_cast<UInt32*>(outData) = 0;
outDataSize = sizeof(UInt32);
break;
default:
EQM_Object::GetPropertyData(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData,
inDataSize,
outDataSize,
outData);
break;
};
}
#pragma clang assume_nonnull end

View File

@ -1,96 +0,0 @@
//
// EQM_AbstractDevice.h
// EQMDriver
//
//
//
#ifndef EQM_Driver__EQM_AbstractDevice
#define EQM_Driver__EQM_AbstractDevice
// SuperClass Includes
#include "EQM_Object.h"
#pragma clang assume_nonnull begin
class EQM_AbstractDevice
:
public EQM_Object
{
#pragma mark Construction/Destruction
protected:
EQM_AbstractDevice(AudioObjectID inObjectID,
AudioObjectID inOwnerObjectID);
virtual ~EQM_AbstractDevice();
#pragma mark Property Operations
public:
virtual bool HasProperty(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const;
virtual bool IsPropertySettable(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const;
virtual UInt32 GetPropertyDataSize(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData) const;
virtual void GetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData,
UInt32 inDataSize,
UInt32& outDataSize,
void* outData) const;
#pragma mark IO Operations
public:
virtual void StartIO(UInt32 inClientID) = 0;
virtual void StopIO(UInt32 inClientID) = 0;
virtual void GetZeroTimeStamp(Float64& outSampleTime,
UInt64& outHostTime,
UInt64& outSeed) = 0;
virtual void WillDoIOOperation(UInt32 inOperationID,
bool& outWillDo,
bool& outWillDoInPlace) const = 0;
virtual void BeginIOOperation(UInt32 inOperationID,
UInt32 inIOBufferFrameSize,
const AudioServerPlugInIOCycleInfo& inIOCycleInfo,
UInt32 inClientID) = 0;
virtual void DoIOOperation(AudioObjectID inStreamObjectID,
UInt32 inClientID, UInt32 inOperationID,
UInt32 inIOBufferFrameSize,
const AudioServerPlugInIOCycleInfo& inIOCycleInfo,
void* ioMainBuffer,
void* __nullable ioSecondaryBuffer) = 0;
virtual void EndIOOperation(UInt32 inOperationID,
UInt32 inIOBufferFrameSize,
const AudioServerPlugInIOCycleInfo& inIOCycleInfo,
UInt32 inClientID) = 0;
#pragma mark Implementation
public:
virtual CFStringRef CopyDeviceUID() const = 0;
virtual void AddClient(const AudioServerPlugInClientInfo* inClientInfo) = 0;
virtual void RemoveClient(const AudioServerPlugInClientInfo* inClientInfo) = 0;
virtual void PerformConfigChange(UInt64 inChangeAction,
void* __nullable inChangeInfo) = 0;
virtual void AbortConfigChange(UInt64 inChangeAction,
void* __nullable inChangeInfo) = 0;
};
#pragma clang assume_nonnull end
#endif /* EQM_Driver__EQM_AbstractDevice */

View File

@ -1,196 +0,0 @@
//
// EQM_AudibleState.cpp
// EQMDriver
//
// Copyright © 2016 Josh Junon
//
// Self Include
#include "EQM_AudibleState.h"
// PublicUtility Includes
#include "CADebugMacros.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-conversion"
#include "CAAtomic.h"
#pragma clang diagnostic pop
// STL Includes
#include <algorithm> // For std::min and std::max.
// TODO: This is just the first value I tried.
static const Float32 kSampleVolumeMarginRaw = 0.0001f;
EQM_AudibleState::EQM_AudibleState()
:
mState(kEQMDeviceIsSilent),
mSampleTimes({0, 0, 0, 0})
{
}
EQMDeviceAudibleState EQM_AudibleState::GetState() const noexcept
{
CAMemoryBarrier(); // Probably unnecessary.
return mState;
}
void EQM_AudibleState::Reset() noexcept
{
mState = kEQMDeviceIsSilent;
mSampleTimes.latestSilent = 0;
mSampleTimes.latestAudibleNonMusic = 0;
mSampleTimes.latestSilentMusic = 0;
mSampleTimes.latestAudibleMusic = 0;
}
void EQM_AudibleState::UpdateWithClientIO(bool inClientIsMusicPlayer,
UInt32 inIOBufferFrameSize,
Float64 inOutputSampleTime,
const Float32* inBuffer)
{
// Update the sample times of the most recent audible music, silent music and audible non-music
// samples we've received.
Float64 endFrameSampleTime = inOutputSampleTime + inIOBufferFrameSize - 1;
if(inClientIsMusicPlayer)
{
if(BufferIsAudible(inIOBufferFrameSize, inBuffer))
{
mSampleTimes.latestAudibleMusic = std::max(mSampleTimes.latestAudibleMusic,
endFrameSampleTime);
}
else
{
mSampleTimes.latestSilentMusic = std::max(mSampleTimes.latestSilentMusic,
endFrameSampleTime);
}
}
else if(endFrameSampleTime > mSampleTimes.latestAudibleNonMusic && // Don't bother checking the
// buffer if it won't change
// anything.
BufferIsAudible(inIOBufferFrameSize, inBuffer))
{
mSampleTimes.latestAudibleNonMusic = std::max(mSampleTimes.latestAudibleNonMusic,
endFrameSampleTime);
}
}
bool EQM_AudibleState::UpdateWithMixedIO(UInt32 inIOBufferFrameSize,
Float64 inOutputSampleTime,
const Float32* inBuffer)
{
// Update the sample time of the most recent silent sample we've received. (The music player
// client is not considered separate for the latest silent sample.)
bool audible = BufferIsAudible(inIOBufferFrameSize, inBuffer);
// The sample time of the last frame we're looking at.
Float64 endFrameSampleTime = inOutputSampleTime + inIOBufferFrameSize - 1;
if(!audible)
{
mSampleTimes.latestSilent = std::max(mSampleTimes.latestSilent, endFrameSampleTime);
}
return RecalculateState(endFrameSampleTime);
}
bool EQM_AudibleState::RecalculateState(Float64 inEndFrameSampleTime)
{
Float64 sinceLatestSilent = inEndFrameSampleTime - mSampleTimes.latestSilent;
Float64 sinceLatestMusicSilent = inEndFrameSampleTime - mSampleTimes.latestSilentMusic;
Float64 sinceLatestAudible = inEndFrameSampleTime - mSampleTimes.latestAudibleNonMusic;
Float64 sinceLatestMusicAudible = inEndFrameSampleTime - mSampleTimes.latestAudibleMusic;
bool didChangeState = false;
// Update mState
// Change from silent/silentExceptMusic to audible
if(mState != kEQMDeviceIsAudible &&
sinceLatestSilent >= kDeviceAudibleStateMinChangedFramesForUpdate &&
// Check that non-music audio is currently playing
sinceLatestAudible <= 0 && mSampleTimes.latestAudibleNonMusic != 0)
{
DebugMsg("EQM_AudibleState::RecalculateState: Changing "
"kAudioDeviceCustomPropertyDeviceAudibleState to audible");
mState = kEQMDeviceIsAudible;
CAMemoryBarrier();
didChangeState = true;
}
// Change from silent to silentExceptMusic
else if(((mState == kEQMDeviceIsSilent &&
sinceLatestMusicSilent >= kDeviceAudibleStateMinChangedFramesForUpdate) ||
// ...or from audible to silentExceptMusic
(mState == kEQMDeviceIsAudible &&
sinceLatestAudible >= kDeviceAudibleStateMinChangedFramesForUpdate &&
sinceLatestMusicSilent >= kDeviceAudibleStateMinChangedFramesForUpdate)) &&
// In case we haven't seen any music samples yet (either audible or silent), check that
// music is currently playing
sinceLatestMusicAudible <= 0 && mSampleTimes.latestAudibleMusic != 0)
{
DebugMsg("EQM_AudibleState::RecalculateState: Changing "
"kAudioDeviceCustomPropertyDeviceAudibleState to silent except music");
mState = kEQMDeviceIsSilentExceptMusic;
CAMemoryBarrier();
didChangeState = true;
}
// Change from audible/silentExceptMusic to silent
else if(mState != kEQMDeviceIsSilent &&
sinceLatestAudible >= kDeviceAudibleStateMinChangedFramesForUpdate &&
sinceLatestMusicAudible >= kDeviceAudibleStateMinChangedFramesForUpdate)
{
DebugMsg("EQM_AudibleState::RecalculateState: Changing "
"kAudioDeviceCustomPropertyDeviceAudibleState to silent");
mState = kEQMDeviceIsSilent;
CAMemoryBarrier();
didChangeState = true;
}
return didChangeState;
}
// static
bool EQM_AudibleState::BufferIsAudible(UInt32 inIOBufferFrameSize, const Float32* inBuffer)
{
// Check each frame to see if any are audible. This could be much more accurate, but seems to
// work well enough for now.
//
// The trade off here is between pausing the music player at the wrong time and unpausing it at
// the wrong time. If a short sound (e.g. a UI alert) plays but has a long, barely-audible tail,
// we might not detect the silence quickly enough and pause the music player. Similarly, if
// we've paused the music player and there's a period of near-silence in the new audio, we might
// unpause the music and briefly interrupt the new audio.
//
// A fairly long period of silence before unpausing the music player isn't a big problem, which
// means EQMApp can wait much longer before unpausing than before pausing. So this function errs
// toward considering the buffer silent, which helps EQMApp ignore short sounds.
if(inIOBufferFrameSize > 0)
{
// Bounds for the left channel samples.
Float32 firstSampleLLower = inBuffer[0] - kSampleVolumeMarginRaw;
Float32 firstSampleLUpper = inBuffer[0] + kSampleVolumeMarginRaw;
// Bounds for the right channel samples.
Float32 firstSampleRLower = inBuffer[1] - kSampleVolumeMarginRaw;
Float32 firstSampleRUpper = inBuffer[1] + kSampleVolumeMarginRaw;
for(UInt32 i = 0; i < inIOBufferFrameSize * 2; i += 2)
{
bool audibleL =
(inBuffer[i] < firstSampleLLower) || (inBuffer[i] > firstSampleLUpper);
bool audibleR =
(inBuffer[i + 1] < firstSampleRLower) || (inBuffer[i + 1] > firstSampleRUpper);
if(audibleL || audibleR)
{
return true;
}
}
}
return false;
}

View File

@ -1,87 +0,0 @@
//
// EQM_AudibleState.h
// EQMDriver
//
//
// Inspects a stream of audio data and reports whether it's silent, silent except for the user's
// music player, or audible.
//
// See kAudioDeviceCustomPropertyDeviceAudibleState and the EQMDeviceAudibleState enum in
// EQM_Types.h for more info.
//
// Not thread-safe.
//
#ifndef EQMDriver__EQM_AudibleState
#define EQMDriver__EQM_AudibleState
// Local Includes
#include "EQM_Types.h"
// System Includes
#include <MacTypes.h>
#pragma clang assume_nonnull begin
class EQM_AudibleState
{
public:
EQM_AudibleState();
/*!
@return The current audible state of the device, to be used as the value of the
kAudioDeviceCustomPropertyDeviceAudibleState property.
*/
EQMDeviceAudibleState GetState() const noexcept;
/*! Set the audible state back to kEQMDeviceIsSilent and ignore all previous IO. */
void Reset() noexcept;
/*!
Read an audio buffer sent by a single device client (i.e. a process playing audio) and update
the audible state. The update will only affect the return value of GetState after the next
call to UpdateWithMixedIO, when all IO for the cycle has been read.
Real-time safe. Not thread safe.
*/
void UpdateWithClientIO(bool inClientIsMusicPlayer,
UInt32 inIOBufferFrameSize,
Float64 inOutputSampleTime,
const Float32* inBuffer);
/*!
Read a fully mixed audio buffer and update the audible state. All client (unmixed) buffers for
the same cycle must be read with UpdateWithClientIO before calling this function.
Real-time safe. Not thread safe.
@return True if the audible state changed.
*/
bool UpdateWithMixedIO(UInt32 inIOBufferFrameSize,
Float64 inOutputSampleTime,
const Float32* inBuffer);
private:
bool RecalculateState(Float64 inEndFrameSampleTime);
static bool BufferIsAudible(UInt32 inIOBufferFrameSize,
const Float32* inBuffer);
private:
EQMDeviceAudibleState mState;
struct
{
Float64 latestAudibleNonMusic;
Float64 latestSilent;
Float64 latestAudibleMusic;
Float64 latestSilentMusic;
} mSampleTimes;
};
#pragma clang assume_nonnull end
#endif /* EQMDriver__EQM_AudibleState */

View File

@ -1,167 +0,0 @@
//
// EQM_Control.cpp
// EQMDriver
//
//
// Portions copyright (C) 2013 Apple Inc. All Rights Reserved.
//
// Self Include
#include "EQM_Control.h"
// PublicUtility Includes
#include "CADebugMacros.h"
#include "CAException.h"
// System Includes
#include <CoreAudio/AudioHardwareBase.h>
#pragma clang assume_nonnull begin
EQM_Control::EQM_Control(AudioObjectID inObjectID,
AudioClassID inClassID,
AudioClassID inBaseClassID,
AudioObjectID inOwnerObjectID,
AudioObjectPropertyScope inScope,
AudioObjectPropertyElement inElement)
:
EQM_Object(inObjectID, inClassID, inBaseClassID, inOwnerObjectID),
mScope(inScope),
mElement(inElement)
{
}
bool EQM_Control::HasProperty(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const
{
CheckObjectID(inObjectID);
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioControlPropertyScope:
case kAudioControlPropertyElement:
theAnswer = true;
break;
default:
theAnswer = EQM_Object::HasProperty(inObjectID, inClientPID, inAddress);
break;
};
return theAnswer;
}
bool EQM_Control::IsPropertySettable(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const
{
CheckObjectID(inObjectID);
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioControlPropertyScope:
case kAudioControlPropertyElement:
theAnswer = false;
break;
default:
theAnswer = EQM_Object::IsPropertySettable(inObjectID, inClientPID, inAddress);
break;
};
return theAnswer;
}
UInt32 EQM_Control::GetPropertyDataSize(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData) const
{
CheckObjectID(inObjectID);
UInt32 theAnswer = 0;
switch(inAddress.mSelector)
{
case kAudioControlPropertyScope:
theAnswer = sizeof(AudioObjectPropertyScope);
break;
case kAudioControlPropertyElement:
theAnswer = sizeof(AudioObjectPropertyElement);
break;
default:
theAnswer = EQM_Object::GetPropertyDataSize(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData);
break;
};
return theAnswer;
}
void EQM_Control::GetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData,
UInt32 inDataSize,
UInt32& outDataSize,
void* outData) const
{
CheckObjectID(inObjectID);
switch(inAddress.mSelector)
{
case kAudioControlPropertyScope:
// This property returns the scope that the control is attached to.
ThrowIf(inDataSize < sizeof(AudioObjectPropertyScope),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Control::GetPropertyData: not enough space for the return value of "
"kAudioControlPropertyScope for the control");
*reinterpret_cast<AudioObjectPropertyScope*>(outData) = mScope;
outDataSize = sizeof(AudioObjectPropertyScope);
break;
case kAudioControlPropertyElement:
// This property returns the element that the control is attached to.
ThrowIf(inDataSize < sizeof(AudioObjectPropertyElement),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Control::GetPropertyData: not enough space for the return value of "
"kAudioControlPropertyElement for the control");
*reinterpret_cast<AudioObjectPropertyElement*>(outData) = mElement;
outDataSize = sizeof(AudioObjectPropertyElement);
break;
default:
EQM_Object::GetPropertyData(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData,
inDataSize,
outDataSize,
outData);
break;
};
}
void EQM_Control::CheckObjectID(AudioObjectID inObjectID) const
{
ThrowIf(inObjectID == kAudioObjectUnknown || inObjectID != GetObjectID(),
CAException(kAudioHardwareBadObjectError),
"EQM_Control::CheckObjectID: wrong audio object ID for the control");
}
#pragma clang assume_nonnull end

View File

@ -1,72 +0,0 @@
//
// EQM_Control.h
// EQMDriver
//
//
//
// An AudioObject that represents a user-controllable aspect of a device or stream, such as volume
// or balance.
//
//
#ifndef EQMDriver__EQM_Control
#define EQMDriver__EQM_Control
// Superclass Includes
#include "EQM_Object.h"
#pragma clang assume_nonnull begin
class EQM_Control
:
public EQM_Object
{
protected:
EQM_Control(AudioObjectID inObjectID,
AudioClassID inClassID,
AudioClassID inBaseClassID,
AudioObjectID inOwnerObjectID,
AudioObjectPropertyScope inScope = kAudioObjectPropertyScopeOutput,
AudioObjectPropertyElement inElement = kAudioObjectPropertyElementMaster
);
#pragma mark Property Operations
public:
virtual bool HasProperty(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const;
virtual bool IsPropertySettable(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const;
virtual UInt32 GetPropertyDataSize(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData) const;
virtual void GetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData,
UInt32 inDataSize,
UInt32& outDataSize,
void* outData) const;
#pragma mark Implementation
protected:
void CheckObjectID(AudioObjectID inObjectID) const;
protected:
const AudioObjectPropertyScope mScope;
const AudioObjectPropertyElement mElement;
};
#pragma clang assume_nonnull end
#endif /* EQMDriver__EQM_Control */

File diff suppressed because it is too large Load Diff

View File

@ -1,261 +0,0 @@
//
// EQM_Device.h
// EQMDriver
//
// Portions copyright (C) 2013 Apple Inc. All Rights Reserved.
//
// Based largely on SA_Device.h from Apple's SimpleAudioDriver Plug-In sample code.
// https://developer.apple.com/library/mac/samplecode/AudioDriverExamples
//
#ifndef EQMDriver__EQM_Device
#define EQMDriver__EQM_Device
// SuperClass Includes
#include "EQM_AbstractDevice.h"
// Local Includes
#include "EQM_Types.h"
#include "EQM_WrappedAudioEngine.h"
#include "EQM_Clients.h"
#include "EQM_TaskQueue.h"
#include "EQM_AudibleState.h"
#include "EQM_Stream.h"
#include "EQM_VolumeControl.h"
#include "EQM_MuteControl.h"
// PublicUtility Includes
#include "CAMutex.h"
#include "CAVolumeCurve.h"
// System Includes
#include <CoreFoundation/CoreFoundation.h>
#include <pthread.h>
class EQM_Device
:
public EQM_AbstractDevice
{
#pragma mark Construction/Destruction
public:
static EQM_Device& GetInstance();
static EQM_Device& GetUISoundsInstance();
virtual void Activate();
virtual void Deactivate();
private:
static void StaticInitializer();
protected:
EQM_Device(AudioObjectID inObjectID,
const CFStringRef __nonnull inDeviceName,
const CFStringRef __nonnull inDeviceUID,
const CFStringRef __nonnull inDeviceModelUID,
AudioObjectID inInputStreamID,
AudioObjectID inOutputStreamID,
AudioObjectID inOutputVolumeControlID,
AudioObjectID inOutputMuteControlID);
virtual ~EQM_Device();
private:
void InitLoopback();
#pragma mark Property Operations
public:
virtual bool HasProperty(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress) const;
virtual bool IsPropertySettable(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress) const;
virtual UInt32 GetPropertyDataSize(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* __nullable inQualifierData) const;
virtual void GetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* __nullable inQualifierData, UInt32 inDataSize, UInt32& outDataSize, void* __nonnull outData) const;
virtual void SetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* __nullable inQualifierData, UInt32 inDataSize, const void* __nonnull inData);
#pragma mark Device Property Operations
private:
bool Device_HasProperty(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress) const;
bool Device_IsPropertySettable(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress) const;
UInt32 Device_GetPropertyDataSize(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* __nullable inQualifierData) const;
void Device_GetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* __nullable inQualifierData, UInt32 inDataSize, UInt32& outDataSize, void* __nonnull outData) const;
void Device_SetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* __nullable inQualifierData, UInt32 inDataSize, const void* __nonnull inData);
#pragma mark IO Operations
public:
void StartIO(UInt32 inClientID);
void StopIO(UInt32 inClientID);
void GetZeroTimeStamp(Float64& outSampleTime, UInt64& outHostTime, UInt64& outSeed);
void WillDoIOOperation(UInt32 inOperationID, bool& outWillDo, bool& outWillDoInPlace) const;
void BeginIOOperation(UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo& inIOCycleInfo, UInt32 inClientID);
void DoIOOperation(AudioObjectID inStreamObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo& inIOCycleInfo, void* __nonnull ioMainBuffer, void* __nullable ioSecondaryBuffer);
void EndIOOperation(UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo& inIOCycleInfo, UInt32 inClientID);
private:
void ReadInputData(UInt32 inIOBufferFrameSize, Float64 inSampleTime, void* __nonnull outBuffer);
void WriteOutputData(UInt32 inIOBufferFrameSize, Float64 inSampleTime, const void* __nonnull inBuffer);
void ApplyClientRelativeVolume(UInt32 inClientID, UInt32 inIOBufferFrameSize, void* __nonnull inBuffer) const;
#pragma mark Accessors
public:
/*!
Enable or disable the device's volume and/or mute controls. This function is async because it
has to ask the host to stop IO for the device before the controls can be enabled/disabled.
See EQM_Device::PerformConfigChange and RequestDeviceConfigurationChange in AudioServerPlugIn.h.
*/
void RequestEnabledControls(bool inVolumeEnabled, bool inMuteEnabled);
Float64 GetSampleRate() const;
UInt32 GetSafetyOffset() const;
UInt32 GetLatency() const;
void RequestSampleRate(Float64 inRequestedSampleRate);
private:
/*!
@return The Audio Object that has the ID inObjectID and belongs to this device.
@throws CAException if there is no such Audio Object.
*/
const EQM_Object& GetOwnedObjectByID(AudioObjectID inObjectID) const;
EQM_Object& GetOwnedObjectByID(AudioObjectID inObjectID);
/*! @return The number of Audio Objects belonging to this device, e.g. streams and controls. */
UInt32 GetNumberOfSubObjects() const;
/*! @return The number of Audio Objects with output scope belonging to this device. */
UInt32 GetNumberOfOutputSubObjects() const;
/*!
@return The number of control Audio Objects with output scope belonging to this device, e.g.
output volume and mute controls.
*/
UInt32 GetNumberOfOutputControls() const;
/*!
Enable or disable the device's volume and/or mute controls.
Private because (after initialisation) this can only be called after asking the host to stop IO
for the device. See EQM_Device::RequestEnabledControls, EQM_Device::PerformConfigChange and
RequestDeviceConfigurationChange in AudioServerPlugIn.h.
*/
void SetEnabledControls(bool inVolumeEnabled, bool inMuteEnabled);
/*!
Set the device's sample rate.
Private because (after initialisation) this can only be called after asking the host to stop IO
for the device. See EQM_Device::RequestEnabledControls, EQM_Device::PerformConfigChange and
RequestDeviceConfigurationChange in AudioServerPlugIn.h.
@param inNewSampleRate The sample rate.
@param force If true, set the sample rate on the device even if it's currently set to inNewSampleRate.
@throws CAException if inNewSampleRate < 1 or if applying the sample rate to one of the streams
fails.
*/
void SetSampleRate(Float64 inNewSampleRate, bool force = false);
void SetSafetyOffset(UInt32 inNewSafetyOffset);
void SetLatency(UInt32 inNewLatency);
void SetShown(bool shown);
/*! @return True if inObjectID is the ID of one of this device's streams. */
inline bool IsStreamID(AudioObjectID inObjectID) const noexcept;
#pragma mark Hardware Accessors
private:
void _HW_Open();
void _HW_Close();
kern_return_t _HW_StartIO();
void _HW_StopIO();
Float64 _HW_GetSampleRate() const;
kern_return_t _HW_SetSampleRate(Float64 inNewSampleRate);
UInt32 _HW_GetRingBufferFrameSize() const;
#pragma mark Implementation
public:
CFStringRef __nonnull CopyDeviceUID() const { return mDeviceUID; }
void AddClient(const AudioServerPlugInClientInfo* __nonnull inClientInfo);
void RemoveClient(const AudioServerPlugInClientInfo* __nonnull inClientInfo);
/*!
Apply a change requested with EQM_PlugIn::Host_RequestDeviceConfigurationChange. See
PerformDeviceConfigurationChange in AudioServerPlugIn.h.
*/
void PerformConfigChange(UInt64 inChangeAction, void* __nullable inChangeInfo);
/*! Cancel a change requested with EQM_PlugIn::Host_RequestDeviceConfigurationChange. */
void AbortConfigChange(UInt64 inChangeAction, void* __nullable inChangeInfo);
private:
static pthread_once_t sStaticInitializer;
static EQM_Device* __nonnull sInstance;
static EQM_Device* __nonnull sUISoundsInstance;
#define kDeviceName "eqMac"
#define kDeviceName_UISounds "eqMac (UI Sounds)"
#define kDeviceManufacturerName "Bitgapp"
const CFStringRef __nonnull mDeviceName;
const CFStringRef __nonnull mDeviceUID;
const CFStringRef __nonnull mDeviceModelUID;
enum
{
// The number of global/output sub-objects varies because the controls can be disabled.
kNumberOfInputSubObjects = 1,
kNumberOfStreams = 2,
kNumberOfInputStreams = 1,
kNumberOfOutputStreams = 1
};
CAMutex mStateMutex;
CAMutex mIOMutex;
const Float64 kSampleRateDefault = 44100.0;
const UInt32 kSafetyOffsetDefault = 0;
const UInt32 kLatencyDefault = 0;
const bool kShownDefault = false;
// Before we can change sample rate, the host has to stop the device. The new sample rate is
// stored here while it does.
Float64 mPendingSampleRate;
EQM_WrappedAudioEngine* __nullable mWrappedAudioEngine;
EQM_TaskQueue mTaskQueue;
EQM_Clients mClients;
#define kLoopbackRingBufferFrameSize 16384
Float64 mLoopbackSampleRate;
UInt32 mSafetyOffset;
UInt32 mLatency;
bool mShown;
Float32 mLoopbackRingBuffer[kLoopbackRingBufferFrameSize * 2];
// TODO: a comment explaining why we need a clock for loopback-only mode
struct {
Float64 hostTicksPerFrame = 0.0;
UInt64 numberTimeStamps = 0;
UInt64 anchorHostTime = 0;
} mLoopbackTime;
EQM_Stream mInputStream;
EQM_Stream mOutputStream;
EQM_AudibleState mAudibleState;
enum class ChangeAction : UInt64
{
SetSampleRate,
SetEnabledControls
};
EQM_VolumeControl mVolumeControl;
EQM_MuteControl mMuteControl;
bool mPendingOutputVolumeControlEnabled = true;
bool mPendingOutputMuteControlEnabled = true;
};
#endif /* EQMDriver__EQM_Device */

View File

@ -1,209 +0,0 @@
//
// EQM_MuteControl.cpp
// EQMDriver
//
//
// Self Include
#include "EQM_MuteControl.h"
// Local Includes
#include "EQM_PlugIn.h"
// PublicUtility Includes
#include "CADebugMacros.h"
#include "CAException.h"
#include "CADispatchQueue.h"
#pragma clang assume_nonnull begin
#pragma mark Construction/Destruction
EQM_MuteControl::EQM_MuteControl(AudioObjectID inObjectID,
AudioObjectID inOwnerObjectID,
AudioObjectPropertyScope inScope,
AudioObjectPropertyElement inElement)
:
EQM_Control(inObjectID,
kAudioMuteControlClassID,
kAudioBooleanControlClassID,
inOwnerObjectID,
inScope,
inElement),
mMutex("Mute Control"),
mMuted(false)
{
}
#pragma mark Property Operations
bool EQM_MuteControl::HasProperty(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const
{
CheckObjectID(inObjectID);
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioBooleanControlPropertyValue:
theAnswer = true;
break;
default:
theAnswer = EQM_Control::HasProperty(inObjectID, inClientPID, inAddress);
break;
};
return theAnswer;
}
bool EQM_MuteControl::IsPropertySettable(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const
{
CheckObjectID(inObjectID);
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioBooleanControlPropertyValue:
theAnswer = true;
break;
default:
theAnswer = EQM_Control::IsPropertySettable(inObjectID, inClientPID, inAddress);
break;
};
return theAnswer;
}
UInt32 EQM_MuteControl::GetPropertyDataSize(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData) const
{
CheckObjectID(inObjectID);
UInt32 theAnswer = 0;
switch(inAddress.mSelector)
{
case kAudioBooleanControlPropertyValue:
theAnswer = sizeof(UInt32);
break;
default:
theAnswer = EQM_Control::GetPropertyDataSize(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData);
break;
};
return theAnswer;
}
void EQM_MuteControl::GetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData,
UInt32 inDataSize,
UInt32& outDataSize,
void* outData) const
{
CheckObjectID(inObjectID);
switch(inAddress.mSelector)
{
case kAudioBooleanControlPropertyValue:
// This returns the mute value of the control.
{
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_MuteControl::GetPropertyData: not enough space for the return value "
"of kAudioBooleanControlPropertyValue for the mute control");
CAMutex::Locker theLocker(mMutex);
// Non-zero for true, which means audio is being muted.
*reinterpret_cast<UInt32*>(outData) = mMuted ? 1 : 0;
outDataSize = sizeof(UInt32);
}
break;
default:
EQM_Control::GetPropertyData(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData,
inDataSize,
outDataSize,
outData);
break;
};
}
void EQM_MuteControl::SetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData,
UInt32 inDataSize,
const void* inData)
{
CheckObjectID(inObjectID);
switch(inAddress.mSelector)
{
case kAudioBooleanControlPropertyValue:
{
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_MuteControl::SetPropertyData: wrong size for the data for "
"kAudioBooleanControlPropertyValue");
CAMutex::Locker theLocker(mMutex);
// Non-zero for true, meaning audio will be muted.
bool theNewMuted = (*reinterpret_cast<const UInt32*>(inData) != 0);
if(mMuted != theNewMuted)
{
mMuted = theNewMuted;
// Send notifications.
CADispatchQueue::GetGlobalSerialQueue().Dispatch(false, ^{
AudioObjectPropertyAddress theChangedProperty[1];
theChangedProperty[0] = {
kAudioBooleanControlPropertyValue, mScope, mElement
};
EQM_PlugIn::Host_PropertiesChanged(inObjectID, 1, theChangedProperty);
});
}
}
break;
default:
EQM_Control::SetPropertyData(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData,
inDataSize,
inData);
break;
};
}
#pragma clang assume_nonnull end

View File

@ -1,82 +0,0 @@
//
// EQM_MuteControl.h
// EQMDriver
//
//
//
#ifndef EQMDriver__EQM_MuteControl
#define EQMDriver__EQM_MuteControl
// Superclass Includes
#include "EQM_Control.h"
// PublicUtility Includes
#include "CAMutex.h"
// System Includes
#include <MacTypes.h>
#include <CoreAudio/CoreAudio.h>
#pragma clang assume_nonnull begin
class EQM_MuteControl
:
public EQM_Control
{
#pragma mark Construction/Destruction
public:
EQM_MuteControl(AudioObjectID inObjectID,
AudioObjectID inOwnerObjectID,
AudioObjectPropertyScope inScope = kAudioObjectPropertyScopeOutput,
AudioObjectPropertyElement inElement =
kAudioObjectPropertyElementMaster);
#pragma mark Property Operations
bool HasProperty(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const;
bool IsPropertySettable(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const;
UInt32 GetPropertyDataSize(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData) const;
void GetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData,
UInt32 inDataSize,
UInt32& outDataSize,
void* outData) const;
void SetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData,
UInt32 inDataSize,
const void* inData);
#pragma mark Implementation
private:
CAMutex mMutex;
bool mMuted;
};
#pragma clang assume_nonnull end
#endif /* EQMDriver__EQM_MuteControl */

View File

@ -1,497 +0,0 @@
//
// EQM_NullDevice.cpp
// EQMDriver
//
//
//
// Self Include
#include "EQM_NullDevice.h"
// Local Includes
#include "EQM_PlugIn.h"
// PublicUtility Includes
#include "CADebugMacros.h"
#include "CAException.h"
#include "CAPropertyAddress.h"
#include "CADispatchQueue.h"
#include "CAHostTimeBase.h"
#pragma clang assume_nonnull begin
static const Float64 kSampleRate = 44100.0;
static const UInt32 kZeroTimeStampPeriod = 10000; // Arbitrary.
#pragma mark Construction/Destruction
pthread_once_t EQM_NullDevice::sStaticInitializer = PTHREAD_ONCE_INIT;
EQM_NullDevice* EQM_NullDevice::sInstance = nullptr;
EQM_NullDevice& EQM_NullDevice::GetInstance()
{
pthread_once(&sStaticInitializer, StaticInitializer);
return *sInstance;
}
void EQM_NullDevice::StaticInitializer()
{
try
{
sInstance = new EQM_NullDevice;
// Note that we leave the device inactive initially. EQMApp will activate it when needed.
}
catch(...)
{
DebugMsg("EQM_NullDevice::StaticInitializer: Failed to create the device");
delete sInstance;
sInstance = nullptr;
}
}
EQM_NullDevice::EQM_NullDevice()
:
EQM_AbstractDevice(kObjectID_Device_Null, kAudioObjectPlugInObject),
mStateMutex("Null Device State"),
mIOMutex("Null Device IO"),
mStream(kObjectID_Stream_Null, kObjectID_Device_Null, false, kSampleRate)
{
}
EQM_NullDevice::~EQM_NullDevice()
{
}
void EQM_NullDevice::Activate()
{
CAMutex::Locker theStateLocker(mStateMutex);
if(!IsActive())
{
// Call the super-class, which just marks the object as active.
EQM_AbstractDevice::Activate();
// Calculate the number of host clock ticks per frame for this device's clock. // Calculate the host ticks per frame for the clock.
mHostTicksPerFrame = CAHostTimeBase::GetFrequency() / kSampleRate;
SendDeviceIsAlivePropertyNotifications();
}
}
void EQM_NullDevice::Deactivate()
{
CAMutex::Locker theStateLocker(mStateMutex);
if(IsActive())
{
CAMutex::Locker theIOLocker(mIOMutex);
// Mark the object inactive by calling the super-class.
EQM_AbstractDevice::Deactivate();
SendDeviceIsAlivePropertyNotifications();
}
}
void EQM_NullDevice::SendDeviceIsAlivePropertyNotifications()
{
CADispatchQueue::GetGlobalSerialQueue().Dispatch(false, ^{
AudioObjectPropertyAddress theChangedProperties[] = {
CAPropertyAddress(kAudioDevicePropertyDeviceIsAlive)
};
EQM_PlugIn::Host_PropertiesChanged(GetObjectID(), 1, theChangedProperties);
});
}
#pragma mark Property Operations
bool EQM_NullDevice::HasProperty(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const
{
if(inObjectID == mStream.GetObjectID())
{
return mStream.HasProperty(inObjectID, inClientPID, inAddress);
}
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioDevicePropertyDeviceCanBeDefaultDevice:
case kAudioDevicePropertyDeviceCanBeDefaultSystemDevice:
theAnswer = true;
break;
default:
theAnswer = EQM_AbstractDevice::HasProperty(inObjectID, inClientPID, inAddress);
break;
};
return theAnswer;
}
bool EQM_NullDevice::IsPropertySettable(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const
{
// Forward stream properties.
if(inObjectID == mStream.GetObjectID())
{
return mStream.IsPropertySettable(inObjectID, inClientPID, inAddress);
}
bool theAnswer = false;
switch(inAddress.mSelector)
{
default:
theAnswer = EQM_AbstractDevice::IsPropertySettable(inObjectID, inClientPID, inAddress);
break;
};
return theAnswer;
}
UInt32 EQM_NullDevice::GetPropertyDataSize(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData) const
{
// Forward stream properties.
if(inObjectID == mStream.GetObjectID())
{
return mStream.GetPropertyDataSize(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData);
}
UInt32 theAnswer = 0;
switch(inAddress.mSelector)
{
case kAudioDevicePropertyStreams:
theAnswer = 1 * sizeof(AudioObjectID);
break;
case kAudioDevicePropertyAvailableNominalSampleRates:
theAnswer = 1 * sizeof(AudioValueRange);
break;
default:
theAnswer = EQM_AbstractDevice::GetPropertyDataSize(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData);
break;
};
return theAnswer;
}
void EQM_NullDevice::GetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData,
UInt32 inDataSize,
UInt32& outDataSize,
void* outData) const
{
// Forward stream properties.
if(inObjectID == mStream.GetObjectID())
{
return mStream.GetPropertyData(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData,
inDataSize,
outDataSize,
outData);
}
// See EQM_Device::Device_GetPropertyData for more information about these properties.
switch(inAddress.mSelector)
{
case kAudioObjectPropertyName:
ThrowIf(inDataSize < sizeof(AudioObjectID),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_NullDevice::GetPropertyData: not enough space for the return value of "
"kAudioObjectPropertyName for the device");
*reinterpret_cast<CFStringRef*>(outData) = CFSTR(kNullDeviceName);
outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyManufacturer:
ThrowIf(inDataSize < sizeof(AudioObjectID),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_NullDevice::GetPropertyData: not enough space for the return value of "
"kAudioObjectPropertyManufacturer for the device");
*reinterpret_cast<CFStringRef*>(outData) = CFSTR(kNullDeviceManufacturerName);
outDataSize = sizeof(CFStringRef);
break;
case kAudioDevicePropertyDeviceUID:
ThrowIf(inDataSize < sizeof(AudioObjectID),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_NullDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyDeviceUID for the device");
*reinterpret_cast<CFStringRef*>(outData) = CFSTR(kEQMNullDeviceUID);
outDataSize = sizeof(CFStringRef);
break;
case kAudioDevicePropertyModelUID:
ThrowIf(inDataSize < sizeof(AudioObjectID),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_NullDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyModelUID for the device");
*reinterpret_cast<CFStringRef*>(outData) = CFSTR(kEQMNullDeviceModelUID);
outDataSize = sizeof(CFStringRef);
break;
case kAudioDevicePropertyDeviceIsAlive:
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_NullDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyDeviceIsAlive for the device");
*reinterpret_cast<UInt32*>(outData) = IsActive() ? 1 : 0;
outDataSize = sizeof(UInt32);
break;
case kAudioDevicePropertyDeviceIsRunning:
{
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_NullDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyDeviceIsRunning for the device");
CAMutex::Locker theStateLocker(mStateMutex);
// 1 means the device is running, i.e. doing IO.
*reinterpret_cast<UInt32*>(outData) = (mClientsDoingIO > 0) ? 1 : 0;
outDataSize = sizeof(UInt32);
}
break;
case kAudioDevicePropertyStreams:
if(inDataSize >= sizeof(AudioObjectID) &&
(inAddress.mScope == kAudioObjectPropertyScopeGlobal ||
inAddress.mScope == kAudioObjectPropertyScopeOutput))
{
// Return the ID of this device's stream.
reinterpret_cast<AudioObjectID*>(outData)[0] = kObjectID_Stream_Null;
// Report how much we wrote.
outDataSize = 1 * sizeof(AudioObjectID);
}
else
{
// Return nothing if we don't have a stream of the given scope or there's no room
// for the response.
outDataSize = 0;
}
break;
case kAudioDevicePropertyNominalSampleRate:
ThrowIf(inDataSize < sizeof(Float64),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_NullDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyNominalSampleRate for the device");
*reinterpret_cast<Float64*>(outData) = kSampleRate;
outDataSize = sizeof(Float64);
break;
case kAudioDevicePropertyAvailableNominalSampleRates:
// Check we were given space to return something.
if((inDataSize / sizeof(AudioValueRange)) >= 1)
{
// This device doesn't support changing the sample rate.
reinterpret_cast<AudioValueRange*>(outData)[0].mMinimum = kSampleRate;
reinterpret_cast<AudioValueRange*>(outData)[0].mMaximum = kSampleRate;
outDataSize = sizeof(AudioValueRange);
}
else
{
outDataSize = 0;
}
break;
case kAudioDevicePropertyZeroTimeStampPeriod:
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_NullDevice::GetPropertyData: not enough space for the return value of "
"kAudioDevicePropertyZeroTimeStampPeriod for the device");
*reinterpret_cast<UInt32*>(outData) = kZeroTimeStampPeriod;
outDataSize = sizeof(UInt32);
break;
default:
EQM_AbstractDevice::GetPropertyData(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData,
inDataSize,
outDataSize,
outData);
break;
};
}
void EQM_NullDevice::SetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData,
UInt32 inDataSize,
const void* inData)
{
// This device doesn't have any settable properties, so just pass stream properties along.
if(inObjectID == mStream.GetObjectID())
{
mStream.SetPropertyData(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData,
inDataSize,
inData);
}
else if(inObjectID == GetObjectID())
{
EQM_AbstractDevice::SetPropertyData(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData,
inDataSize,
inData);
}
else
{
Throw(CAException(kAudioHardwareBadObjectError));
}
}
#pragma mark IO Operations
void EQM_NullDevice::StartIO(UInt32 inClientID)
{
#pragma unused (inClientID)
CAMutex::Locker theStateLocker(mStateMutex);
if(mClientsDoingIO == 0)
{
// Reset the clock.
mNumberTimeStamps = 0;
mAnchorHostTime = mach_absolute_time();
// Send notifications.
DebugMsg("EQM_NullDevice::StartIO: Sending kAudioDevicePropertyDeviceIsRunning");
CADispatchQueue::GetGlobalSerialQueue().Dispatch(false, ^{
AudioObjectPropertyAddress theChangedProperty[] = {
CAPropertyAddress(kAudioDevicePropertyDeviceIsRunning)
};
EQM_PlugIn::Host_PropertiesChanged(kObjectID_Device_Null, 1, theChangedProperty);
});
}
mClientsDoingIO++;
}
void EQM_NullDevice::StopIO(UInt32 inClientID)
{
#pragma unused (inClientID)
CAMutex::Locker theStateLocker(mStateMutex);
ThrowIf(mClientsDoingIO == 0,
CAException(kAudioHardwareIllegalOperationError),
"EQM_NullDevice::StopIO: Underflowed mClientsDoingIO");
mClientsDoingIO--;
if(mClientsDoingIO == 0)
{
// Send notifications.
DebugMsg("EQM_NullDevice::StopIO: Sending kAudioDevicePropertyDeviceIsRunning");
CADispatchQueue::GetGlobalSerialQueue().Dispatch(false, ^{
AudioObjectPropertyAddress theChangedProperty[] = {
CAPropertyAddress(kAudioDevicePropertyDeviceIsRunning)
};
EQM_PlugIn::Host_PropertiesChanged(kObjectID_Device_Null, 1, theChangedProperty);
});
}
}
void EQM_NullDevice::GetZeroTimeStamp(Float64& outSampleTime,
UInt64& outHostTime,
UInt64& outSeed)
{
CAMutex::Locker theIOLocker(mIOMutex);
// Not sure whether there's actually any point to implementing this. The documentation says that
// clockless devices don't need to, but if the device doesn't have
// kAudioDevicePropertyZeroTimeStampPeriod the HAL seems to reject it. So we give it a simple
// clock similar to the loopback clock in EQM_Device.
UInt64 theCurrentHostTime = mach_absolute_time();
// Calculate the next host time.
Float64 theHostTicksPerPeriod = mHostTicksPerFrame * static_cast<Float64>(kZeroTimeStampPeriod);
Float64 theHostTickOffset = static_cast<Float64>(mNumberTimeStamps + 1) * theHostTicksPerPeriod;
UInt64 theNextHostTime = mAnchorHostTime + static_cast<UInt64>(theHostTickOffset);
// Go to the next period if the next host time is less than the current time.
if(theNextHostTime <= theCurrentHostTime)
{
mNumberTimeStamps++;
}
Float64 theHostTicksSinceAnchor =
(static_cast<Float64>(mNumberTimeStamps) * theHostTicksPerPeriod);
// Set the return values.
outSampleTime = mNumberTimeStamps * kZeroTimeStampPeriod;
outHostTime = static_cast<UInt64>(mAnchorHostTime + theHostTicksSinceAnchor);
outSeed = 1;
}
void EQM_NullDevice::WillDoIOOperation(UInt32 inOperationID,
bool& outWillDo,
bool& outWillDoInPlace) const
{
switch(inOperationID)
{
case kAudioServerPlugInIOOperationWriteMix:
outWillDo = true;
outWillDoInPlace = true;
break;
default:
outWillDo = false;
outWillDoInPlace = true;
break;
};
}
void EQM_NullDevice::DoIOOperation(AudioObjectID inStreamObjectID,
UInt32 inClientID,
UInt32 inOperationID,
UInt32 inIOBufferFrameSize,
const AudioServerPlugInIOCycleInfo& inIOCycleInfo,
void* ioMainBuffer,
void* __nullable ioSecondaryBuffer)
{
#pragma unused (inStreamObjectID, inClientID, inOperationID, inIOCycleInfo, inIOBufferFrameSize)
#pragma unused (ioMainBuffer, ioSecondaryBuffer)
// Ignore the audio data.
}
#pragma clang assume_nonnull end

View File

@ -1,171 +0,0 @@
//
// EQM_NullDevice.h
// EQMDriver
//
//
//
// A device with one output stream that ignores any audio played on that stream.
//
// If we change EQMDevice's controls list, to match the output device set in EQMApp, we need to
// change the OS X default device so other programs (including the OS X audio UI) will update
// themselves. We could just change to the real output device and change back, but that could have
// side effects the user wouldn't expect. For example, an app the user had muted might be unmuted
// for a short period.
//
// Instead, EQMApp temporarily enables this device and uses it to toggle the default device. This
// device is disabled at all other times so it can be hidden from the user. (We can't just use
// kAudioDevicePropertyIsHidden because hidden devices can't be default and the HAL doesn't seem to
// let devices change kAudioDevicePropertyIsHidden after setting it initially.)
//
// It might be worth eventually having a virtual device for each real output device, but this is
// simpler and seems to work well enough for now.
//
#ifndef EQMDriver__EQM_NullDevice
#define EQMDriver__EQM_NullDevice
// SuperClass Includes
#include "EQM_AbstractDevice.h"
// Local Includes
#include "EQM_Types.h"
#include "EQM_Stream.h"
// PublicUtility Includes
#include "CAMutex.h"
// System Includes
#include <pthread.h>
#pragma clang assume_nonnull begin
class EQM_NullDevice
:
public EQM_AbstractDevice
{
#pragma mark Construction/Destruction
public:
static EQM_NullDevice& GetInstance();
private:
static void StaticInitializer();
protected:
EQM_NullDevice();
virtual ~EQM_NullDevice();
public:
virtual void Activate();
virtual void Deactivate();
private:
void SendDeviceIsAlivePropertyNotifications();
#pragma mark Property Operations
public:
bool HasProperty(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const;
bool IsPropertySettable(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const;
UInt32 GetPropertyDataSize(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData) const;
void GetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData,
UInt32 inDataSize,
UInt32& outDataSize,
void* outData) const;
void SetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData,
UInt32 inDataSize,
const void* inData);
#pragma mark IO Operations
public:
void StartIO(UInt32 inClientID);
void StopIO(UInt32 inClientID);
void GetZeroTimeStamp(Float64& outSampleTime,
UInt64& outHostTime,
UInt64& outSeed);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
void WillDoIOOperation(UInt32 inOperationID,
bool& outWillDo,
bool& outWillDoInPlace) const;
void BeginIOOperation(UInt32 inOperationID,
UInt32 inIOBufferFrameSize,
const AudioServerPlugInIOCycleInfo& inIOCycleInfo,
UInt32 inClientID)
{ /* No-op */ };
void DoIOOperation(AudioObjectID inStreamObjectID,
UInt32 inClientID,
UInt32 inOperationID,
UInt32 inIOBufferFrameSize,
const AudioServerPlugInIOCycleInfo& inIOCycleInfo,
void* ioMainBuffer,
void* __nullable ioSecondaryBuffer);
void EndIOOperation(UInt32 inOperationID,
UInt32 inIOBufferFrameSize,
const AudioServerPlugInIOCycleInfo& inIOCycleInfo,
UInt32 inClientID)
{ /* No-op */ };
#pragma mark Implementation
public:
CFStringRef CopyDeviceUID() const
{ return CFSTR(kEQMNullDeviceUID); };
void AddClient(const AudioServerPlugInClientInfo* inClientInfo)
{ /* No-op */ };
void RemoveClient(const AudioServerPlugInClientInfo* inClientInfo)
{ /* No-op */ };
void PerformConfigChange(UInt64 inChangeAction,
void* __nullable inChangeInfo)
{ /* No-op */ };
void AbortConfigChange(UInt64 inChangeAction,
void* __nullable inChangeInfo)
{ /* No-op */ };
#pragma clang diagnostic pop
private:
static pthread_once_t sStaticInitializer;
static EQM_NullDevice* sInstance;
#define kNullDeviceName "eqMac Null Device"
#define kNullDeviceManufacturerName \
"Bitgapp"
CAMutex mStateMutex;
CAMutex mIOMutex;
EQM_Stream mStream;
UInt32 mClientsDoingIO = 0;
Float64 mHostTicksPerFrame = 0.0;
UInt64 mNumberTimeStamps = 0;
UInt64 mAnchorHostTime = 0;
};
#pragma clang assume_nonnull end
#endif /* EQMDriver__EQM_NullDevice */

View File

@ -1,167 +0,0 @@
// EQM_Object.cpp
// EQMDriver
//
// Portions copyright (C) 2013 Apple Inc. All Rights Reserved.
//
// Based largely on SA_Object.cpp from Apple's SimpleAudioDriver Plug-In sample code.
// https://developer.apple.com/library/mac/samplecode/AudioDriverExamples
//
// Similarly to EQM_Object.h, this file hasn't been changed much from SA_Object.cpp, except to
// remove the SA_ObjectMap class.
//
// Self Include
#include "EQM_Object.h"
// PublicUtility Includes
#include "CADebugMacros.h"
#include "CAException.h"
//==================================================================================================
#pragma mark -
#pragma mark EQM_Object
//==================================================================================================
#pragma mark Construction/Destruction
EQM_Object::EQM_Object(AudioObjectID inObjectID, AudioClassID inClassID, AudioClassID inBaseClassID, AudioObjectID inOwnerObjectID)
:
mObjectID(inObjectID),
mClassID(inClassID),
mBaseClassID(inBaseClassID),
mOwnerObjectID(inOwnerObjectID),
mIsActive(false)
{
}
void EQM_Object::Activate()
{
mIsActive = true;
}
void EQM_Object::Deactivate()
{
mIsActive = false;
}
EQM_Object::~EQM_Object()
{
}
#pragma mark Property Operations
bool EQM_Object::HasProperty(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress) const
{
#pragma unused(inObjectID, inClientPID)
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyOwnedObjects:
theAnswer = true;
break;
};
return theAnswer;
}
bool EQM_Object::IsPropertySettable(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress) const
{
#pragma unused(inObjectID, inClientPID)
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
case kAudioObjectPropertyOwner:
case kAudioObjectPropertyOwnedObjects:
theAnswer = false;
break;
default:
Throw(CAException(kAudioHardwareUnknownPropertyError));
};
return theAnswer;
}
UInt32 EQM_Object::GetPropertyDataSize(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData) const
{
#pragma unused(inObjectID, inClientPID, inQualifierDataSize, inQualifierData)
UInt32 theAnswer = 0;
switch(inAddress.mSelector)
{
case kAudioObjectPropertyBaseClass:
case kAudioObjectPropertyClass:
theAnswer = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
theAnswer = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyOwnedObjects:
theAnswer = 0;
break;
default:
Throw(CAException(kAudioHardwareUnknownPropertyError));
};
return theAnswer;
}
void EQM_Object::GetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32& outDataSize, void* outData) const
{
#pragma unused(inObjectID, inClientPID, inQualifierDataSize, inQualifierData)
switch(inAddress.mSelector)
{
case kAudioObjectPropertyBaseClass:
// This is the AudioClassID of the base class of this object. This is an invariant.
ThrowIf(inDataSize < sizeof(AudioClassID), CAException(kAudioHardwareBadPropertySizeError), "EQM_Object::GetPropertyData: not enough space for the return value of kAudioObjectPropertyBaseClass");
*reinterpret_cast<AudioClassID*>(outData) = mBaseClassID;
outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
// This is the AudioClassID of the class of this object. This is an invariant.
ThrowIf(inDataSize < sizeof(AudioClassID), CAException(kAudioHardwareBadPropertySizeError), "EQM_Object::GetPropertyData: not enough space for the return value of kAudioObjectPropertyClass");
*reinterpret_cast<AudioClassID*>(outData) = mClassID;
outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
// The AudioObjectID of the object that owns this object. This is an invariant.
ThrowIf(inDataSize < sizeof(AudioObjectID), CAException(kAudioHardwareBadPropertySizeError), "EQM_Object::GetPropertyData: not enough space for the return value of kAudioObjectPropertyOwner");
*reinterpret_cast<AudioClassID*>(outData) = mOwnerObjectID;
outDataSize = sizeof(AudioObjectID);
break;
case kAudioObjectPropertyOwnedObjects:
// This is an array of AudioObjectIDs for the objects owned by this object. By default,
// objects don't own any other objects. This is an invariant by default, but an object
// that can contain other objects will likely need to do some synchronization to access
// this property.
outDataSize = 0;
break;
default:
Throw(CAException(kAudioHardwareUnknownPropertyError));
};
}
void EQM_Object::SetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData)
{
#pragma unused(inObjectID, inClientPID, inQualifierDataSize, inQualifierData, inDataSize, inData)
switch(inAddress.mSelector)
{
default:
Throw(CAException(kAudioHardwareUnknownPropertyError));
};
}

View File

@ -1,146 +0,0 @@
//
// EQM_Object.h
// EQMDriver
//
// Portions copyright (C) 2013 Apple Inc. All Rights Reserved.
//
// Based largely on SA_Object.h from Apple's SimpleAudioDriver Plug-In sample code.
// https://developer.apple.com/library/mac/samplecode/AudioDriverExamples
//
// The base class for our classes that represent audio objects. (See AudioServerPlugIn.h for a
// quick explanation of audio objects.)
//
// This is a stripped down version of SA_Object.h. Unlike the sample code plugin that SA_Object.h
// is from, we have a fixed set of audio objects. So we've removed the code that handled
// growing/shrinking that set.
//
#ifndef __EQMDriver__EQM_Object__
#define __EQMDriver__EQM_Object__
// System Includes
#include <CoreAudio/AudioServerPlugIn.h>
// TODO: Update the large comment below to reflect what was removed from SA_Object.h? It hasn't
// been changed at all so far, except to replace "SA_Object" with "EQM_Object".
//==================================================================================================
// EQM_Object
//
// This is the base class for objects managed by EQM_ObjectMap. It's only job is to ensure that
// objects of this type have the proper external semantics for a reference counted object. This
// means that the desctructor is protected so that these objects cannot be deleted directly. Also,
// these objects many not make a copy of another object or be assigned from another object. Note
// that the reference count of the object is tracked and owned by the EQM_ObjectMap.
//
// These objects provide RTTI information tied to the constants describing the HAL's API class
// hierarchy as described in the headers. The class ID and base class IDs passed in to the
// constructor must operate with the semantics described in AudioObjectBase.h where the base class
// has to always be one of the standard classes. The class ID can be a custom value or a standard
// value however. If it is a standard value, the base class should be the proper standard base
// class. So for example, a standard volume control object will say that it's class is
// kAudioVolumeControlClassID and that its base class is kAudioLevelControlClassID. In the case of
// a custom boolean control, it would say that it's class is a custom value like 'MYBL' and that
// its base class is kAudioBooleanControlClassID.
//
// Subclasses of this class must implement Activate(). This method is called after an object has
// been constructed and inserted into the object map. Until Activate() is called, a constructed
// object may not do anything active such as sending/receiving notifications or creating other
// objects. Active operations may be performed in the Activate() method proper however. Note that
// Activate() is called prior to any references to the object being handed out. As such, it does
// not need to worry about being thread safe while Activate() is in progress.
//
// Subclasses of this class must also implement Deactivate(). This method is called when the object
// is at the end of it's lifecycle. Once Deactivate() has been called, the object may no longer
// perform active opertions, including Deactivating other objects. This is based on the notion that
// all the objects have a definite point at which they are considered dead to the outside world.
// For example, an AudioDevice object is dead if it's hardware is unplugged. The point of death is
// the notification the owner of the device gets to signal that it has been unplugged. Note that it
// is both normal and expected that a dead object might still have outstanding references. Thus, an
// object has to put in some care to do the right thing when these zombie references are used. The
// best thing to do is to just have those queries return appropriate errors.
//
// Deactivate() itself needs to be thread safe with respect to other operations taking place on the
// object. This also means taking care to handle the Deactivation of owned objects. For example, an
// AudioDevice object will almost always own one or more AudioStream objects. If the stream is in a
// separate lock domain from it's owning device, then the device has to be very careful about how
// it deactivates the stream such that it doesn't try to lock the stream's lock while holding the
// device's lock which will inevitably lead to a deadlock situation. There are two reasonable
// approaches to dealing with this kind of situation. The first is to just not get into it by
// making the device share a lock domain with all it's owned objects like streams and controls. The
// other approach is to use dispatch queues to make the work of Deactivating owned objects take
// place outside of the device's lock domain. For example, if the device needs to deactivate a
// stream, it can remove the stream from any tracking in the device object and then dispatch
// asynchronously the Deactivate() call on the stream and the release of the reference the device
// has on the stream.
//
// Note that both Activate() and Deactivate() are called by objects at large. Typically,
// Activate() is called by the creator of the object, usually right after the object has been
// allocated. Deactivate() will usually be called by the owner of the object upon recognizing that
// the object is dead to the outside world. Going back to the example of an AudioDevice getting
// unplugged, the Deactivate() method will be called by whomever receives the notification about
// the hardware going away, which is often the owner of the object.
//
// This class also defines methods to implement the portion of the
// AudioServerPlugInDriverInterface that deals with properties. The five methods all have the same
// basic arguments and semantics. The class also provides the implementation for
// the minimum required properties for all AudioObjects. There is a detailed commentary about each
// specific property in the GetPropertyData() method.
//
// It is important that a thread retain and hold a reference while it is using an EQM_Object and
// that the reference be released promptly when the thread is finished using the object. By
// assuming this, a EQM_Object can minimize the amount of locking it needs to do. In particular,
// purely static or invariant data can be handled without any locking at all.
//==================================================================================================
class EQM_Object
{
#pragma mark Construction/Destruction
public:
EQM_Object(AudioObjectID inObjectID, AudioClassID inClassID, AudioClassID inBaseClassID, AudioObjectID inOwnerObjectID);
virtual void Activate();
virtual void Deactivate();
protected:
virtual ~EQM_Object();
private:
EQM_Object(const EQM_Object&);
EQM_Object& operator=(const EQM_Object&);
#pragma mark Attributes
public:
AudioObjectID GetObjectID() const { return mObjectID; }
void* GetObjectIDAsPtr() const { uintptr_t thePtr = mObjectID; return reinterpret_cast<void*>(thePtr); }
AudioClassID GetClassID() const { return mClassID; }
AudioClassID GetBaseClassID() const { return mBaseClassID; }
AudioObjectID GetOwnerObjectID() const { return mOwnerObjectID; }
bool IsActive() const { return mIsActive; }
#pragma mark Property Operations
public:
virtual bool HasProperty(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress) const;
virtual bool IsPropertySettable(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress) const;
virtual UInt32 GetPropertyDataSize(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData) const;
virtual void GetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32& outDataSize, void* outData) const;
virtual void SetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData);
#pragma mark Implementation
protected:
AudioObjectID mObjectID;
AudioClassID mClassID;
AudioClassID mBaseClassID;
AudioObjectID mOwnerObjectID;
bool mIsActive;
};
#endif /* __EQMDriver__EQM_Object__ */

View File

@ -1,489 +0,0 @@
//
// EQM_PlugIn.cpp
// EQMDriver
//
// Portions copyright (C) 2013 Apple Inc. All Rights Reserved.
//
// Based largely on SA_PlugIn.cpp from Apple's SimpleAudioDriver Plug-In sample code.
// https://developer.apple.com/library/mac/samplecode/AudioDriverExamples
//
// Self Include
#include "EQM_PlugIn.h"
// Local Includes
#include "EQM_Device.h"
#include "EQM_NullDevice.h"
// PublicUtility Includes
#include "CAException.h"
#include "CADebugMacros.h"
#include "CAPropertyAddress.h"
#include "CADispatchQueue.h"
#pragma mark Construction/Destruction
pthread_once_t EQM_PlugIn::sStaticInitializer = PTHREAD_ONCE_INIT;
EQM_PlugIn* EQM_PlugIn::sInstance = NULL;
AudioServerPlugInHostRef EQM_PlugIn::sHost = NULL;
EQM_PlugIn& EQM_PlugIn::GetInstance()
{
pthread_once(&sStaticInitializer, StaticInitializer);
return *sInstance;
}
void EQM_PlugIn::StaticInitializer()
{
try
{
sInstance = new EQM_PlugIn;
sInstance->Activate();
}
catch(...)
{
DebugMsg("EQM_PlugIn::StaticInitializer: failed to create the plug-in");
delete sInstance;
sInstance = NULL;
}
}
EQM_PlugIn::EQM_PlugIn()
:
EQM_Object(kAudioObjectPlugInObject, kAudioPlugInClassID, kAudioObjectClassID, 0),
mMutex("EQM_PlugIn")
{
}
EQM_PlugIn::~EQM_PlugIn()
{
}
void EQM_PlugIn::Deactivate()
{
CAMutex::Locker theLocker(mMutex);
EQM_Object::Deactivate();
// TODO:
//_RemoveAllDevices();
}
#pragma mark Property Operations
bool EQM_PlugIn::HasProperty(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress) const
{
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioObjectPropertyManufacturer:
case kAudioPlugInPropertyDeviceList:
case kAudioPlugInPropertyTranslateUIDToDevice:
case kAudioPlugInPropertyResourceBundle:
case kAudioObjectPropertyCustomPropertyInfoList:
case kAudioPlugInCustomPropertyNullDeviceActive:
case kAudioPlugInCustomPropertyDeviceActive:
case kAudioPlugInCustomPropertyUIDeviceActive:
theAnswer = true;
break;
default:
theAnswer = EQM_Object::HasProperty(inObjectID, inClientPID, inAddress);
};
return theAnswer;
}
bool EQM_PlugIn::IsPropertySettable(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress) const
{
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioObjectPropertyManufacturer:
case kAudioPlugInPropertyDeviceList:
case kAudioPlugInPropertyTranslateUIDToDevice:
case kAudioPlugInPropertyResourceBundle:
case kAudioObjectPropertyCustomPropertyInfoList:
theAnswer = false;
break;
case kAudioPlugInCustomPropertyNullDeviceActive:
case kAudioPlugInCustomPropertyDeviceActive:
case kAudioPlugInCustomPropertyUIDeviceActive:
theAnswer = true;
break;
default:
theAnswer = EQM_Object::IsPropertySettable(inObjectID, inClientPID, inAddress);
};
return theAnswer;
}
UInt32 EQM_PlugIn::GetPropertyDataSize(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData) const
{
UInt32 theAnswer = 0;
switch(inAddress.mSelector)
{
case kAudioObjectPropertyManufacturer:
theAnswer = sizeof(CFStringRef);
break;
case kAudioObjectPropertyOwnedObjects:
case kAudioPlugInPropertyDeviceList:
// The plug-in owns the main EQM_Device, the instance of EQM_Device that handles UI
// sounds and, if it's enabled, the null device.
theAnswer = (EQM_NullDevice::GetInstance().IsActive() ? 3 : 2) * sizeof(AudioObjectID);
break;
case kAudioPlugInPropertyTranslateUIDToDevice:
theAnswer = sizeof(AudioObjectID);
break;
case kAudioPlugInPropertyResourceBundle:
theAnswer = sizeof(CFStringRef);
break;
case kAudioObjectPropertyCustomPropertyInfoList:
theAnswer = sizeof(AudioServerPlugInCustomPropertyInfo);
break;
case kAudioPlugInCustomPropertyNullDeviceActive:
case kAudioPlugInCustomPropertyDeviceActive:
case kAudioPlugInCustomPropertyUIDeviceActive:
theAnswer = sizeof(CFBooleanRef);
break;
default:
theAnswer = EQM_Object::GetPropertyDataSize(inObjectID, inClientPID, inAddress, inQualifierDataSize, inQualifierData);
};
return theAnswer;
}
void EQM_PlugIn::GetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32& outDataSize, void* outData) const
{
switch(inAddress.mSelector)
{
case kAudioObjectPropertyManufacturer:
// This is the human readable name of the maker of the plug-in.
ThrowIf(inDataSize < sizeof(CFStringRef), CAException(kAudioHardwareBadPropertySizeError), "EQM_PlugIn::GetPropertyData: not enough space for the return value of kAudioObjectPropertyManufacturer");
*reinterpret_cast<CFStringRef*>(outData) = CFSTR("Bitgapp");
outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyOwnedObjects:
// Fall through because this plug-in object only owns the devices.
case kAudioPlugInPropertyDeviceList:
{
AudioObjectID* theReturnedDeviceList = reinterpret_cast<AudioObjectID*>(outData);
UInt32 added = 0;
if(inDataSize >= 3 * sizeof(AudioObjectID))
{
if(EQM_NullDevice::GetInstance().IsActive())
{
theReturnedDeviceList[added] = kObjectID_Device_Null;
outDataSize += sizeof(AudioObjectID);
added++;
}
if (EQM_Device::GetInstance().IsActive()) {
theReturnedDeviceList[added] = kObjectID_Device;
outDataSize += sizeof(AudioObjectID);
added++;
}
if (EQM_Device::GetUISoundsInstance().IsActive()) {
theReturnedDeviceList[added] = kObjectID_Device_UI_Sounds;
added++;
}
}
else if(inDataSize >= 2 * sizeof(AudioObjectID))
{
if (EQM_Device::GetInstance().IsActive()) {
theReturnedDeviceList[added] = kObjectID_Device;
outDataSize += sizeof(AudioObjectID);
added++;
}
if (EQM_Device::GetUISoundsInstance().IsActive()) {
theReturnedDeviceList[added] = kObjectID_Device_UI_Sounds;
added++;
}
}
else if(inDataSize >= sizeof(AudioObjectID))
{
if (EQM_Device::GetInstance().IsActive()) {
theReturnedDeviceList[added] = kObjectID_Device;
outDataSize += sizeof(AudioObjectID);
added++;
}
}
outDataSize = added * sizeof(AudioObjectID);
}
break;
case kAudioPlugInPropertyTranslateUIDToDevice:
{
// This property translates the UID passed in the qualifier as a CFString into the
// AudioObjectID for the device the UID refers to or kAudioObjectUnknown if no device
// has the UID.
ThrowIf(inQualifierDataSize < sizeof(CFStringRef), CAException(kAudioHardwareBadPropertySizeError), "EQM_PlugIn::GetPropertyData: the qualifier size is too small for kAudioPlugInPropertyTranslateUIDToDevice");
ThrowIf(inDataSize < sizeof(AudioObjectID), CAException(kAudioHardwareBadPropertySizeError), "EQM_PlugIn::GetPropertyData: not enough space for the return value of kAudioPlugInPropertyTranslateUIDToDevice");
CFStringRef theUID = *reinterpret_cast<const CFStringRef*>(inQualifierData);
AudioObjectID* outID = reinterpret_cast<AudioObjectID*>(outData);
if(CFEqual(theUID, EQM_Device::GetInstance().CopyDeviceUID()))
{
DebugMsg("EQM_PlugIn::GetPropertyData: Returning EQMDevice for "
"kAudioPlugInPropertyTranslateUIDToDevice");
*outID = kObjectID_Device;
}
else if(CFEqual(theUID, EQM_Device::GetUISoundsInstance().CopyDeviceUID()))
{
DebugMsg("EQM_PlugIn::GetPropertyData: Returning EQMUISoundsDevice for "
"kAudioPlugInPropertyTranslateUIDToDevice");
*outID = kObjectID_Device_UI_Sounds;
}
else if(EQM_NullDevice::GetInstance().IsActive() &&
CFEqual(theUID, EQM_NullDevice::GetInstance().CopyDeviceUID()))
{
DebugMsg("EQM_PlugIn::GetPropertyData: Returning null device for "
"kAudioPlugInPropertyTranslateUIDToDevice");
*outID = kObjectID_Device_Null;
}
else
{
LogWarning("EQM_PlugIn::GetPropertyData: Returning kAudioObjectUnknown for "
"kAudioPlugInPropertyTranslateUIDToDevice");
*outID = kAudioObjectUnknown;
}
outDataSize = sizeof(AudioObjectID);
}
break;
case kAudioPlugInPropertyResourceBundle:
// The resource bundle is a path relative to the path of the plug-in's bundle.
// To specify that the plug-in bundle itself should be used, we just return the
// empty string.
ThrowIf(inDataSize < sizeof(AudioObjectID), CAException(kAudioHardwareBadPropertySizeError), "EQM_GetPlugInPropertyData: not enough space for the return value of kAudioPlugInPropertyResourceBundle");
*reinterpret_cast<CFStringRef*>(outData) = CFSTR("");
outDataSize = sizeof(CFStringRef);
break;
case kAudioObjectPropertyCustomPropertyInfoList:
if(inDataSize >= sizeof(AudioServerPlugInCustomPropertyInfo))
{
AudioServerPlugInCustomPropertyInfo* outCustomProperties =
reinterpret_cast<AudioServerPlugInCustomPropertyInfo*>(outData);
UInt32 propertyType = kAudioServerPlugInCustomPropertyDataTypeCFPropertyList;
UInt32 qualifierType = kAudioServerPlugInCustomPropertyDataTypeNone;
outCustomProperties[0].mSelector = kAudioPlugInCustomPropertyNullDeviceActive;
outCustomProperties[0].mPropertyDataType = propertyType;
outCustomProperties[0].mQualifierDataType = qualifierType;
outCustomProperties[1].mSelector = kAudioPlugInCustomPropertyDeviceActive;
outCustomProperties[1].mPropertyDataType = propertyType;
outCustomProperties[1].mQualifierDataType = qualifierType;
outCustomProperties[2].mSelector = kAudioPlugInCustomPropertyUIDeviceActive;
outCustomProperties[2].mPropertyDataType = propertyType;
outCustomProperties[2].mQualifierDataType = qualifierType;
outDataSize = 3 * sizeof(AudioServerPlugInCustomPropertyInfo);
}
else
{
outDataSize = 0;
}
break;
case kAudioPlugInCustomPropertyNullDeviceActive:
ThrowIf(inDataSize < sizeof(CFBooleanRef),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_PlugIn::GetPropertyData: not enough space for the return value of "
"kAudioPlugInCustomPropertyNullDeviceActive");
*reinterpret_cast<CFBooleanRef*>(outData) =
EQM_NullDevice::GetInstance().IsActive() ? kCFBooleanTrue : kCFBooleanFalse;
outDataSize = sizeof(CFBooleanRef);
break;
case kAudioPlugInCustomPropertyDeviceActive:
ThrowIf(inDataSize < sizeof(CFBooleanRef),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_PlugIn::GetPropertyData: not enough space for the return value of "
"kAudioPlugInCustomPropertyDevicesActive");
*reinterpret_cast<CFBooleanRef*>(outData) =
EQM_Device::GetInstance().IsActive() ? kCFBooleanTrue : kCFBooleanFalse;
outDataSize = sizeof(CFBooleanRef);
break;
case kAudioPlugInCustomPropertyUIDeviceActive:
ThrowIf(inDataSize < sizeof(CFBooleanRef),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_PlugIn::GetPropertyData: not enough space for the return value of "
"kAudioPlugInCustomPropertyDevicesActive");
*reinterpret_cast<CFBooleanRef*>(outData) =
EQM_Device::GetUISoundsInstance().IsActive() ? kCFBooleanTrue : kCFBooleanFalse;
outDataSize = sizeof(CFBooleanRef);
break;
default:
EQM_Object::GetPropertyData(inObjectID, inClientPID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, outDataSize, outData);
break;
};
}
void EQM_PlugIn::SetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData)
{
switch(inAddress.mSelector)
{
case kAudioPlugInCustomPropertyNullDeviceActive:
{
ThrowIf(inDataSize < sizeof(CFBooleanRef),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_PlugIn::SetPropertyData: wrong size for the data for "
"kAudioPlugInCustomPropertyNullDeviceActive");
CFBooleanRef theIsActiveRef = *reinterpret_cast<const CFBooleanRef*>(inData);
ThrowIfNULL(theIsActiveRef,
CAException(kAudioHardwareIllegalOperationError),
"EQM_PlugIn::SetPropertyData: null reference given for "
"kAudioPlugInCustomPropertyNullDeviceActive");
ThrowIf(CFGetTypeID(theIsActiveRef) != CFBooleanGetTypeID(),
CAException(kAudioHardwareIllegalOperationError),
"EQM_PlugIn::SetPropertyData: CFType given for "
"kAudioPlugInCustomPropertyNullDeviceActive was not a CFBoolean");
bool theIsActive = CFBooleanGetValue(theIsActiveRef);
if(theIsActive != EQM_NullDevice::GetInstance().IsActive())
{
// Activate/deactivate the Null Device. We only make it active for a short
// period, while changing output device in EQMApp, so it can be hidden from the
// user.
if(theIsActive)
{
DebugMsg("EQM_PlugIn::SetPropertyData: Activating null device");
EQM_NullDevice::GetInstance().Activate();
}
else
{
DebugMsg("EQM_PlugIn::SetPropertyData: Deactivating null device");
EQM_NullDevice::GetInstance().Deactivate();
}
// Send notifications.
CADispatchQueue::GetGlobalSerialQueue().Dispatch(false, ^{
AudioObjectPropertyAddress theChangedProperties[] = {
CAPropertyAddress(kAudioObjectPropertyOwnedObjects),
CAPropertyAddress(kAudioPlugInPropertyDeviceList)
};
Host_PropertiesChanged(GetObjectID(), 2, theChangedProperties);
});
}
}
break;
case kAudioPlugInCustomPropertyDeviceActive:
{
ThrowIf(inDataSize < sizeof(CFBooleanRef),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_PlugIn::SetPropertyData: wrong size for the data for "
"kAudioPlugInCustomPropertyNullDeviceActive");
CFBooleanRef theIsActiveRef = *reinterpret_cast<const CFBooleanRef*>(inData);
ThrowIfNULL(theIsActiveRef,
CAException(kAudioHardwareIllegalOperationError),
"EQM_PlugIn::SetPropertyData: null reference given for "
"kAudioPlugInCustomPropertyNullDeviceActive");
ThrowIf(CFGetTypeID(theIsActiveRef) != CFBooleanGetTypeID(),
CAException(kAudioHardwareIllegalOperationError),
"EQM_PlugIn::SetPropertyData: CFType given for "
"kAudioPlugInCustomPropertyNullDeviceActive was not a CFBoolean");
bool theIsActive = CFBooleanGetValue(theIsActiveRef);
if(theIsActive != EQM_Device::GetInstance().IsActive())
{
if(theIsActive)
{
DebugMsg("EQM_PlugIn::SetPropertyData: Activating Device");
EQM_Device::GetInstance().Activate();
}
else
{
DebugMsg("EQM_PlugIn::SetPropertyData: Deactivating Device");
EQM_Device::GetInstance().Deactivate();
}
// Send notifications.
CADispatchQueue::GetGlobalSerialQueue().Dispatch(false, ^{
AudioObjectPropertyAddress theChangedProperties[] = {
CAPropertyAddress(kAudioObjectPropertyOwnedObjects),
CAPropertyAddress(kAudioPlugInPropertyDeviceList)
};
Host_PropertiesChanged(GetObjectID(), 2, theChangedProperties);
});
}
}
break;
case kAudioPlugInCustomPropertyUIDeviceActive: {
ThrowIf(inDataSize < sizeof(CFBooleanRef),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_PlugIn::SetPropertyData: wrong size for the data for "
"kAudioPlugInCustomPropertyNullDeviceActive");
CFBooleanRef theIsActiveRef = *reinterpret_cast<const CFBooleanRef*>(inData);
ThrowIfNULL(theIsActiveRef,
CAException(kAudioHardwareIllegalOperationError),
"EQM_PlugIn::SetPropertyData: null reference given for "
"kAudioPlugInCustomPropertyNullDeviceActive");
ThrowIf(CFGetTypeID(theIsActiveRef) != CFBooleanGetTypeID(),
CAException(kAudioHardwareIllegalOperationError),
"EQM_PlugIn::SetPropertyData: CFType given for "
"kAudioPlugInCustomPropertyNullDeviceActive was not a CFBoolean");
bool theIsActive = CFBooleanGetValue(theIsActiveRef);
if(theIsActive != EQM_Device::GetUISoundsInstance().IsActive())
{
if(theIsActive)
{
DebugMsg("EQM_PlugIn::SetPropertyData: Activating Device");
EQM_Device::GetUISoundsInstance().Activate();
}
else
{
DebugMsg("EQM_PlugIn::SetPropertyData: Deactivating Device");
EQM_Device::GetUISoundsInstance().Deactivate();
}
// Send notifications.
CADispatchQueue::GetGlobalSerialQueue().Dispatch(false, ^{
AudioObjectPropertyAddress theChangedProperties[] = {
CAPropertyAddress(kAudioObjectPropertyOwnedObjects),
CAPropertyAddress(kAudioPlugInPropertyDeviceList)
};
Host_PropertiesChanged(GetObjectID(), 2, theChangedProperties);
});
}
}
break;
default:
EQM_Object::SetPropertyData(inObjectID, inClientPID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, inData);
break;
};
}

View File

@ -1,74 +0,0 @@
//
// EQM_PlugIn.h
// EQMDriver
//
// Portions copyright (C) 2013 Apple Inc. All Rights Reserved.
//
// Based largely on SA_PlugIn.h from Apple's SimpleAudioDriver Plug-In sample code.
// https://developer.apple.com/library/mac/samplecode/AudioDriverExamples
//
#ifndef __EQMDriver__EQM_PlugIn__
#define __EQMDriver__EQM_PlugIn__
// SuperClass Includes
#include "EQM_Object.h"
// Local Includes
#include "EQM_Types.h"
// PublicUtility Includes
#include "CAMutex.h"
class EQM_PlugIn
:
public EQM_Object
{
#pragma mark Construction/Destruction
public:
static EQM_PlugIn& GetInstance();
protected:
EQM_PlugIn();
virtual ~EQM_PlugIn();
virtual void Deactivate();
private:
static void StaticInitializer();
#pragma mark Host Access
public:
static void SetHost(AudioServerPlugInHostRef inHost) { sHost = inHost; }
static void Host_PropertiesChanged(AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioObjectPropertyAddress inAddresses[]) { if(sHost != NULL) { sHost->PropertiesChanged(sHost, inObjectID, inNumberAddresses, inAddresses); } }
static void Host_RequestDeviceConfigurationChange(AudioObjectID inDeviceObjectID, UInt64 inChangeAction, void* inChangeInfo) { if(sHost != NULL) { sHost->RequestDeviceConfigurationChange(sHost, inDeviceObjectID, inChangeAction, inChangeInfo); } }
#pragma mark Property Operations
public:
virtual bool HasProperty(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress) const;
virtual bool IsPropertySettable(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress) const;
virtual UInt32 GetPropertyDataSize(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData) const;
virtual void GetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32& outDataSize, void* outData) const;
virtual void SetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData);
#pragma mark Implementation
public:
const CFStringRef GetBundleID() const { return CFSTR(kEQMDriverBundleID); }
private:
CAMutex mMutex;
static pthread_once_t sStaticInitializer;
static EQM_PlugIn* sInstance;
static AudioServerPlugInHostRef sHost;
};
#endif /* __EQMDriver__EQM_PlugIn__ */

View File

@ -1,955 +0,0 @@
//
// EQM_PlugInInterface.cpp
// EQMDriver
//
// Portions copyright (C) 2013 Apple Inc. All Rights Reserved.
//
// Based largely on SA_PlugIn.cpp from Apple's SimpleAudioDriver Plug-In sample code.
// https://developer.apple.com/library/mac/samplecode/AudioDriverExamples
//
// System Includes
#include <CoreAudio/AudioServerPlugIn.h>
// PublicUtility Includes
#include "CADebugMacros.h"
#include "CAException.h"
// Local Includes
#include "EQM_Types.h"
#include "EQM_Object.h"
#include "EQM_PlugIn.h"
#include "EQM_Device.h"
#include "EQM_NullDevice.h"
#pragma mark COM Prototypes
// Entry points for the COM methods
extern "C" void* EQM_Create(CFAllocatorRef inAllocator, CFUUIDRef inRequestedTypeUUID);
static HRESULT EQM_QueryInterface(void* inDriver, REFIID inUUID, LPVOID* outInterface);
static ULONG EQM_AddRef(void* inDriver);
static ULONG EQM_Release(void* inDriver);
static OSStatus EQM_Initialize(AudioServerPlugInDriverRef inDriver, AudioServerPlugInHostRef inHost);
static OSStatus EQM_CreateDevice(AudioServerPlugInDriverRef inDriver, CFDictionaryRef inDescription, const AudioServerPlugInClientInfo* inClientInfo, AudioObjectID* outDeviceObjectID);
static OSStatus EQM_DestroyDevice(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID);
static OSStatus EQM_AddDeviceClient(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, const AudioServerPlugInClientInfo* inClientInfo);
static OSStatus EQM_RemoveDeviceClient(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, const AudioServerPlugInClientInfo* inClientInfo);
static OSStatus EQM_PerformDeviceConfigurationChange(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt64 inChangeAction, void* inChangeInfo);
static OSStatus EQM_AbortDeviceConfigurationChange(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt64 inChangeAction, void* inChangeInfo);
static Boolean EQM_HasProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus EQM_IsPropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus EQM_GetPropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus EQM_GetPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus EQM_SetPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData);
static OSStatus EQM_StartIO(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID);
static OSStatus EQM_StopIO(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID);
static OSStatus EQM_GetZeroTimeStamp(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, Float64* outSampleTime, UInt64* outHostTime, UInt64* outSeed);
static OSStatus EQM_WillDoIOOperation(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, UInt32 inOperationID, Boolean* outWillDo, Boolean* outWillDoInPlace);
static OSStatus EQM_BeginIOOperation(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo* inIOCycleInfo);
static OSStatus EQM_DoIOOperation(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, AudioObjectID inStreamObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo* inIOCycleInfo, void* ioMainBuffer, void* ioSecondaryBuffer);
static OSStatus EQM_EndIOOperation(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo* inIOCycleInfo);
#pragma mark The COM Interface
static AudioServerPlugInDriverInterface gAudioServerPlugInDriverInterface =
{
NULL,
EQM_QueryInterface,
EQM_AddRef,
EQM_Release,
EQM_Initialize,
EQM_CreateDevice,
EQM_DestroyDevice,
EQM_AddDeviceClient,
EQM_RemoveDeviceClient,
EQM_PerformDeviceConfigurationChange,
EQM_AbortDeviceConfigurationChange,
EQM_HasProperty,
EQM_IsPropertySettable,
EQM_GetPropertyDataSize,
EQM_GetPropertyData,
EQM_SetPropertyData,
EQM_StartIO,
EQM_StopIO,
EQM_GetZeroTimeStamp,
EQM_WillDoIOOperation,
EQM_BeginIOOperation,
EQM_DoIOOperation,
EQM_EndIOOperation
};
static AudioServerPlugInDriverInterface* gAudioServerPlugInDriverInterfacePtr = &gAudioServerPlugInDriverInterface;
static AudioServerPlugInDriverRef gAudioServerPlugInDriverRef = &gAudioServerPlugInDriverInterfacePtr;
static UInt32 gAudioServerPlugInDriverRefCount = 1;
// TODO: This name is a bit misleading because the devices are actually owned by the plug-in.
static EQM_Object& EQM_LookUpOwnerObject(AudioObjectID inObjectID)
{
switch(inObjectID)
{
case kObjectID_PlugIn:
return EQM_PlugIn::GetInstance();
case kObjectID_Device:
case kObjectID_Stream_Input:
case kObjectID_Stream_Output:
case kObjectID_Volume_Output_Master:
case kObjectID_Mute_Output_Master:
return EQM_Device::GetInstance();
case kObjectID_Device_UI_Sounds:
case kObjectID_Stream_Input_UI_Sounds:
case kObjectID_Stream_Output_UI_Sounds:
case kObjectID_Volume_Output_Master_UI_Sounds:
return EQM_Device::GetUISoundsInstance();
case kObjectID_Device_Null:
case kObjectID_Stream_Null:
return EQM_NullDevice::GetInstance();
}
DebugMsg("EQM_LookUpOwnerObject: unknown object");
Throw(CAException(kAudioHardwareBadObjectError));
}
static EQM_AbstractDevice& EQM_LookUpDevice(AudioObjectID inObjectID)
{
switch(inObjectID)
{
case kObjectID_Device:
return EQM_Device::GetInstance();
case kObjectID_Device_UI_Sounds:
return EQM_Device::GetUISoundsInstance();
case kObjectID_Device_Null:
return EQM_NullDevice::GetInstance();
}
DebugMsg("EQM_LookUpDevice: unknown device");
Throw(CAException(kAudioHardwareBadDeviceError));
}
#pragma mark Factory
extern "C"
void* EQM_Create(CFAllocatorRef inAllocator, CFUUIDRef inRequestedTypeUUID)
{
// This is the CFPlugIn factory function. Its job is to create the implementation for the given
// type provided that the type is supported. Because this driver is simple and all its
// initialization is handled via static initalization when the bundle is loaded, all that
// needs to be done is to return the AudioServerPlugInDriverRef that points to the driver's
// interface. A more complicated driver would create any base line objects it needs to satisfy
// the IUnknown methods that are used to discover that actual interface to talk to the driver.
// The majority of the driver's initilization should be handled in the Initialize() method of
// the driver's AudioServerPlugInDriverInterface.
#pragma unused(inAllocator)
void* theAnswer = NULL;
if(CFEqual(inRequestedTypeUUID, kAudioServerPlugInTypeUUID))
{
theAnswer = gAudioServerPlugInDriverRef;
EQM_PlugIn::GetInstance();
}
return theAnswer;
}
#pragma mark Inheritence
static HRESULT EQM_QueryInterface(void* inDriver, REFIID inUUID, LPVOID* outInterface)
{
// This function is called by the HAL to get the interface to talk to the plug-in through.
// AudioServerPlugIns are required to support the IUnknown interface and the
// AudioServerPlugInDriverInterface. As it happens, all interfaces must also provide the
// IUnknown interface, so we can always just return the single interface we made with
// gAudioServerPlugInDriverInterfacePtr regardless of which one is asked for.
HRESULT theAnswer = 0;
CFUUIDRef theRequestedUUID = NULL;
try
{
// validate the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef, CAException(kAudioHardwareBadObjectError), "EQM_QueryInterface: bad driver reference");
ThrowIfNULL(outInterface, CAException(kAudioHardwareIllegalOperationError), "EQM_QueryInterface: no place to store the returned interface");
// make a CFUUIDRef from inUUID
theRequestedUUID = CFUUIDCreateFromUUIDBytes(NULL, inUUID);
ThrowIf(theRequestedUUID == NULL, CAException(kAudioHardwareIllegalOperationError), "EQM_QueryInterface: failed to create the CFUUIDRef");
// AudioServerPlugIns only support two interfaces, IUnknown (which has to be supported by all
// CFPlugIns and AudioServerPlugInDriverInterface (which is the actual interface the HAL will
// use).
ThrowIf(!CFEqual(theRequestedUUID, IUnknownUUID) && !CFEqual(theRequestedUUID, kAudioServerPlugInDriverInterfaceUUID), CAException(E_NOINTERFACE), "EQM_QueryInterface: requested interface is unsupported");
ThrowIf(gAudioServerPlugInDriverRefCount == UINT32_MAX, CAException(E_NOINTERFACE), "EQM_QueryInterface: the ref count is maxxed out");
// do the work
++gAudioServerPlugInDriverRefCount;
*outInterface = gAudioServerPlugInDriverRef;
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
theAnswer = kAudioHardwareUnspecifiedError;
}
if(theRequestedUUID != NULL)
{
CFRelease(theRequestedUUID);
}
return theAnswer;
}
static ULONG EQM_AddRef(void* inDriver)
{
// This call returns the resulting reference count after the increment.
ULONG theAnswer = 0;
// check the arguments
FailIf(inDriver != gAudioServerPlugInDriverRef, Done, "EQM_AddRef: bad driver reference");
FailIf(gAudioServerPlugInDriverRefCount == UINT32_MAX, Done, "EQM_AddRef: out of references");
// increment the refcount
++gAudioServerPlugInDriverRefCount;
theAnswer = gAudioServerPlugInDriverRefCount;
Done:
return theAnswer;
}
static ULONG EQM_Release(void* inDriver)
{
// This call returns the resulting reference count after the decrement.
ULONG theAnswer = 0;
// check the arguments
FailIf(inDriver != gAudioServerPlugInDriverRef, Done, "EQM_Release: bad driver reference");
FailIf(gAudioServerPlugInDriverRefCount == UINT32_MAX, Done, "EQM_Release: out of references");
// decrement the refcount
// Note that we don't do anything special if the refcount goes to zero as the HAL
// will never fully release a plug-in it opens. We keep managing the refcount so that
// the API semantics are correct though.
--gAudioServerPlugInDriverRefCount;
theAnswer = gAudioServerPlugInDriverRefCount;
Done:
return theAnswer;
}
#pragma mark Basic Operations
static OSStatus EQM_Initialize(AudioServerPlugInDriverRef inDriver, AudioServerPlugInHostRef inHost)
{
// The job of this method is, as the name implies, to get the driver initialized. One specific
// thing that needs to be done is to store the AudioServerPlugInHostRef so that it can be used
// later. Note that when this call returns, the HAL will scan the various lists the driver
// maintains (such as the device list) to get the inital set of objects the driver is
// publishing. So, there is no need to notifiy the HAL about any objects created as part of the
// execution of this method.
OSStatus theAnswer = 0;
try
{
// Check the arguments.
ThrowIf(inDriver != gAudioServerPlugInDriverRef,
CAException(kAudioHardwareBadObjectError),
"EQM_Initialize: bad driver reference");
// Store the AudioServerPlugInHostRef.
EQM_PlugIn::GetInstance().SetHost(inHost);
// Init/activate the devices.
EQM_Device::GetInstance();
EQM_Device::GetUISoundsInstance();
EQM_NullDevice::GetInstance();
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_CreateDevice(AudioServerPlugInDriverRef inDriver, CFDictionaryRef inDescription, const AudioServerPlugInClientInfo* inClientInfo, AudioObjectID* outDeviceObjectID)
{
// This method is used to tell a driver that implements the Transport Manager semantics to
// create an AudioEndpointDevice from a set of AudioEndpoints. Since this driver is not a
// Transport Manager, we just return kAudioHardwareUnsupportedOperationError.
#pragma unused(inDriver, inDescription, inClientInfo, outDeviceObjectID)
return kAudioHardwareUnsupportedOperationError;
}
static OSStatus EQM_DestroyDevice(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID)
{
// This method is used to tell a driver that implements the Transport Manager semantics to
// destroy an AudioEndpointDevice. Since this driver is not a Transport Manager, we just check
// the arguments and return kAudioHardwareUnsupportedOperationError.
#pragma unused(inDriver, inDeviceObjectID)
return kAudioHardwareUnsupportedOperationError;
}
static OSStatus EQM_AddDeviceClient(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, const AudioServerPlugInClientInfo* inClientInfo)
{
// This method is used to inform the driver about a new client that is using the given device.
// This allows the device to act differently depending on who the client is.
OSStatus theAnswer = 0;
try
{
// Check the arguments.
ThrowIf(inDriver != gAudioServerPlugInDriverRef,
CAException(kAudioHardwareBadObjectError),
"EQM_AddDeviceClient: bad driver reference");
ThrowIf(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device_UI_Sounds && inDeviceObjectID != kObjectID_Device_Null,
CAException(kAudioHardwareBadObjectError),
"EQM_AddDeviceClient: unknown device");
// Inform the device.
EQM_LookUpDevice(inDeviceObjectID).AddClient(inClientInfo);
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(EQM_InvalidClientException)
{
theAnswer = kAudioHardwareIllegalOperationError;
}
catch(...)
{
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_RemoveDeviceClient(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, const AudioServerPlugInClientInfo* inClientInfo)
{
// This method is used to inform the driver about a client that is no longer using the given
// device.
OSStatus theAnswer = 0;
try
{
// Check the arguments.
ThrowIf(inDriver != gAudioServerPlugInDriverRef,
CAException(kAudioHardwareBadObjectError),
"EQM_RemoveDeviceClient: bad driver reference");
ThrowIf(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device_UI_Sounds && inDeviceObjectID != kObjectID_Device_Null,
CAException(kAudioHardwareBadObjectError),
"EQM_RemoveDeviceClient: unknown device");
// Inform the device.
EQM_LookUpDevice(inDeviceObjectID).RemoveClient(inClientInfo);
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(EQM_InvalidClientException)
{
theAnswer = kAudioHardwareIllegalOperationError;
}
catch(...)
{
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_PerformDeviceConfigurationChange(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt64 inChangeAction, void* inChangeInfo)
{
// This method is called to tell the device that it can perform the configuation change that it
// had requested via a call to the host method, RequestDeviceConfigurationChange(). The
// arguments, inChangeAction and inChangeInfo are the same as what was passed to
// RequestDeviceConfigurationChange().
//
// The HAL guarantees that IO will be stopped while this method is in progress. The HAL will
// also handle figuring out exactly what changed for the non-control related properties. This
// means that the only notifications that would need to be sent here would be for either
// custom properties the HAL doesn't know about or for controls.
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef,
CAException(kAudioHardwareBadObjectError),
"EQM_PerformDeviceConfigurationChange: bad driver reference");
ThrowIf(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device_UI_Sounds && inDeviceObjectID != kObjectID_Device_Null,
CAException(kAudioHardwareBadDeviceError),
"EQM_PerformDeviceConfigurationChange: unknown device");
// tell the device to do the work
EQM_LookUpDevice(inDeviceObjectID).PerformConfigChange(inChangeAction, inChangeInfo);
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_AbortDeviceConfigurationChange(AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt64 inChangeAction, void* inChangeInfo)
{
// This method is called to tell the driver that a request for a config change has been denied.
// This provides the driver an opportunity to clean up any state associated with the request.
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef,
CAException(kAudioHardwareBadObjectError),
"EQM_PerformDeviceConfigurationChange: bad driver reference");
ThrowIf(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device_UI_Sounds && inDeviceObjectID != kObjectID_Device_Null,
CAException(kAudioHardwareBadDeviceError),
"EQM_PerformDeviceConfigurationChange: unknown device");
// tell the device to do the work
EQM_LookUpDevice(inDeviceObjectID).AbortConfigChange(inChangeAction, inChangeInfo);
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
#pragma mark Property Operations
static Boolean EQM_HasProperty(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress)
{
// This method returns whether or not the given object has the given property.
Boolean theAnswer = false;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef, CAException(kAudioHardwareBadObjectError), "EQM_HasProperty: bad driver reference");
ThrowIfNULL(inAddress, CAException(kAudioHardwareIllegalOperationError), "EQM_HasProperty: no address");
theAnswer = EQM_LookUpOwnerObject(inObjectID).HasProperty(inObjectID, inClientProcessID, *inAddress);
}
catch(const CAException& inException)
{
theAnswer = false;
}
catch(...)
{
LogError("EQM_PlugInInterface::EQM_HasProperty: unknown exception. (object: %u, address: %u)",
inObjectID,
inAddress ? inAddress->mSelector : 0);
theAnswer = false;
}
return theAnswer;
}
static OSStatus EQM_IsPropertySettable(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable)
{
// This method returns whether or not the given property on the object can have its value
// changed.
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef, CAException(kAudioHardwareBadObjectError), "EQM_IsPropertySettable: bad driver reference");
ThrowIfNULL(inAddress, CAException(kAudioHardwareIllegalOperationError), "EQM_IsPropertySettable: no address");
ThrowIfNULL(outIsSettable, CAException(kAudioHardwareIllegalOperationError), "EQM_IsPropertySettable: no place to put the return value");
EQM_Object& theAudioObject = EQM_LookUpOwnerObject(inObjectID);
if(theAudioObject.HasProperty(inObjectID, inClientProcessID, *inAddress))
{
*outIsSettable = theAudioObject.IsPropertySettable(inObjectID, inClientProcessID, *inAddress);
}
else
{
theAnswer = kAudioHardwareUnknownPropertyError;
}
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
LogError("EQM_PlugInInterface::EQM_IsPropertySettable: unknown exception. (object: %u, address: %u)",
inObjectID,
inAddress ? inAddress->mSelector : 0);
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_GetPropertyDataSize(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize)
{
// This method returns the byte size of the property's data.
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef, CAException(kAudioHardwareBadObjectError), "EQM_GetPropertyDataSize: bad driver reference");
ThrowIfNULL(inAddress, CAException(kAudioHardwareIllegalOperationError), "EQM_GetPropertyDataSize: no address");
ThrowIfNULL(outDataSize, CAException(kAudioHardwareIllegalOperationError), "EQM_GetPropertyDataSize: no place to put the return value");
EQM_Object& theAudioObject = EQM_LookUpOwnerObject(inObjectID);
if(theAudioObject.HasProperty(inObjectID, inClientProcessID, *inAddress))
{
*outDataSize = theAudioObject.GetPropertyDataSize(inObjectID, inClientProcessID, *inAddress, inQualifierDataSize, inQualifierData);
}
else
{
theAnswer = kAudioHardwareUnknownPropertyError;
}
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
LogError("EQM_PlugInInterface::EQM_GetPropertyDataSize: unknown exception. (object: %u, address: %u)",
inObjectID,
inAddress ? inAddress->mSelector : 0);
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_GetPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData)
{
// This method fetches the data for a given property
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef, CAException(kAudioHardwareBadObjectError), "EQM_GetPropertyData: bad driver reference");
ThrowIfNULL(inAddress, CAException(kAudioHardwareIllegalOperationError), "EQM_GetPropertyData: no address");
ThrowIfNULL(outDataSize, CAException(kAudioHardwareIllegalOperationError), "EQM_GetPropertyData: no place to put the return value size");
ThrowIfNULL(outData, CAException(kAudioHardwareIllegalOperationError), "EQM_GetPropertyData: no place to put the return value");
EQM_Object& theAudioObject = EQM_LookUpOwnerObject(inObjectID);
if(theAudioObject.HasProperty(inObjectID, inClientProcessID, *inAddress))
{
theAudioObject.GetPropertyData(inObjectID, inClientProcessID, *inAddress, inQualifierDataSize, inQualifierData, inDataSize, *outDataSize, outData);
}
else
{
theAnswer = kAudioHardwareUnknownPropertyError;
}
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
LogError("EQM_PlugInInterface::EQM_GetPropertyData: unknown exception. (object: %u, address: %u)",
inObjectID,
inAddress ? inAddress->mSelector : 0);
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_SetPropertyData(AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData)
{
// This method changes the value of the given property
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef, CAException(kAudioHardwareBadObjectError), "EQM_SetPropertyData: bad driver reference");
ThrowIfNULL(inAddress, CAException(kAudioHardwareIllegalOperationError), "EQM_SetPropertyData: no address");
ThrowIfNULL(inData, CAException(kAudioHardwareIllegalOperationError), "EQM_SetPropertyData: no data");
EQM_Object& theAudioObject = EQM_LookUpOwnerObject(inObjectID);
if(theAudioObject.HasProperty(inObjectID, inClientProcessID, *inAddress))
{
if(theAudioObject.IsPropertySettable(inObjectID, inClientProcessID, *inAddress))
{
theAudioObject.SetPropertyData(inObjectID, inClientProcessID, *inAddress, inQualifierDataSize, inQualifierData, inDataSize, inData);
}
else
{
theAnswer = kAudioHardwareUnsupportedOperationError;
}
}
else
{
theAnswer = kAudioHardwareUnknownPropertyError;
}
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
LogError("EQM_PlugInInterface::EQM_SetPropertyData: unknown exception. (object: %u, address: %u)",
inObjectID,
inAddress ? inAddress->mSelector : 0);
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
#pragma mark IO Operations
static OSStatus EQM_StartIO(AudioServerPlugInDriverRef inDriver,
AudioObjectID inDeviceObjectID,
UInt32 inClientID)
{
// This call tells the device that IO is starting for the given client. When this routine
// returns, the device's clock is running and it is ready to have data read/written. It is
// important to note that multiple clients can have IO running on the device at the same time.
// So, work only needs to be done when the first client starts. All subsequent starts simply
// increment the counter.
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef,
CAException(kAudioHardwareBadObjectError),
"EQM_StartIO: bad driver reference");
ThrowIf(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device_UI_Sounds && inDeviceObjectID != kObjectID_Device_Null,
CAException(kAudioHardwareBadDeviceError),
"EQM_StartIO: unknown device");
// tell the device to do the work
EQM_LookUpDevice(inDeviceObjectID).StartIO(inClientID);
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_StopIO(AudioServerPlugInDriverRef inDriver,
AudioObjectID inDeviceObjectID,
UInt32 inClientID)
{
// This call tells the device that the client has stopped IO. The driver can stop the hardware
// once all clients have stopped.
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef,
CAException(kAudioHardwareBadObjectError),
"EQM_StopIO: bad driver reference");
ThrowIf(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device_UI_Sounds && inDeviceObjectID != kObjectID_Device_Null,
CAException(kAudioHardwareBadDeviceError),
"EQM_StopIO: unknown device");
// tell the device to do the work
EQM_LookUpDevice(inDeviceObjectID).StopIO(inClientID);
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_GetZeroTimeStamp(AudioServerPlugInDriverRef inDriver,
AudioObjectID inDeviceObjectID,
UInt32 inClientID,
Float64* outSampleTime,
UInt64* outHostTime,
UInt64* outSeed)
{
#pragma unused(inClientID)
// This method returns the current zero time stamp for the device. The HAL models the timing of
// a device as a series of time stamps that relate the sample time to a host time. The zero
// time stamps are spaced such that the sample times are the value of
// kAudioDevicePropertyZeroTimeStampPeriod apart. This is often modeled using a ring buffer
// where the zero time stamp is updated when wrapping around the ring buffer.
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef,
CAException(kAudioHardwareBadObjectError),
"EQM_GetZeroTimeStamp: bad driver reference");
ThrowIfNULL(outSampleTime,
CAException(kAudioHardwareIllegalOperationError),
"EQM_GetZeroTimeStamp: no place to put the sample time");
ThrowIfNULL(outHostTime,
CAException(kAudioHardwareIllegalOperationError),
"EQM_GetZeroTimeStamp: no place to put the host time");
ThrowIfNULL(outSeed,
CAException(kAudioHardwareIllegalOperationError),
"EQM_GetZeroTimeStamp: no place to put the seed");
ThrowIf(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device_UI_Sounds && inDeviceObjectID != kObjectID_Device_Null,
CAException(kAudioHardwareBadDeviceError),
"EQM_GetZeroTimeStamp: unknown device");
// tell the device to do the work
EQM_LookUpDevice(inDeviceObjectID).GetZeroTimeStamp(*outSampleTime, *outHostTime, *outSeed);
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_WillDoIOOperation(AudioServerPlugInDriverRef inDriver,
AudioObjectID inDeviceObjectID,
UInt32 inClientID,
UInt32 inOperationID,
Boolean* outWillDo,
Boolean* outWillDoInPlace)
{
#pragma unused(inClientID)
// This method returns whether or not the device will do a given IO operation.
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef,
CAException(kAudioHardwareBadObjectError),
"EQM_WillDoIOOperation: bad driver reference");
ThrowIfNULL(outWillDo,
CAException(kAudioHardwareIllegalOperationError),
"EQM_WillDoIOOperation: no place to put the will-do return value");
ThrowIfNULL(outWillDoInPlace,
CAException(kAudioHardwareIllegalOperationError),
"EQM_WillDoIOOperation: no place to put the in-place return value");
ThrowIf(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device_UI_Sounds && inDeviceObjectID != kObjectID_Device_Null,
CAException(kAudioHardwareBadDeviceError),
"EQM_WillDoIOOperation: unknown device");
// tell the device to do the work
bool willDo = false;
bool willDoInPlace = false;
EQM_LookUpDevice(inDeviceObjectID).WillDoIOOperation(inOperationID, willDo, willDoInPlace);
// set the return values
*outWillDo = willDo;
*outWillDoInPlace = willDoInPlace;
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_BeginIOOperation(AudioServerPlugInDriverRef inDriver,
AudioObjectID inDeviceObjectID,
UInt32 inClientID,
UInt32 inOperationID,
UInt32 inIOBufferFrameSize,
const AudioServerPlugInIOCycleInfo* inIOCycleInfo)
{
// This is called at the beginning of an IO operation.
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef,
CAException(kAudioHardwareBadObjectError),
"EQM_BeginIOOperation: bad driver reference");
ThrowIfNULL(inIOCycleInfo,
CAException(kAudioHardwareIllegalOperationError),
"EQM_BeginIOOperation: no cycle info");
ThrowIf(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device_UI_Sounds && inDeviceObjectID != kObjectID_Device_Null,
CAException(kAudioHardwareBadDeviceError),
"EQM_BeginIOOperation: unknown device");
// tell the device to do the work
EQM_LookUpDevice(inDeviceObjectID).BeginIOOperation(inOperationID,
inIOBufferFrameSize,
*inIOCycleInfo,
inClientID);
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
DebugMsg("EQM_PlugInInterface::EQM_BeginIOOperation: unknown exception. (device: %s, operation: %u)",
(inDeviceObjectID == kObjectID_Device ? "EQMDevice" : "other"),
inOperationID);
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_DoIOOperation(AudioServerPlugInDriverRef inDriver,
AudioObjectID inDeviceObjectID,
AudioObjectID inStreamObjectID,
UInt32 inClientID,
UInt32 inOperationID,
UInt32 inIOBufferFrameSize,
const AudioServerPlugInIOCycleInfo* inIOCycleInfo,
void* ioMainBuffer,
void* ioSecondaryBuffer)
{
// This is called to actually perform a given IO operation.
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef,
CAException(kAudioHardwareBadObjectError),
"EQM_EndIOOperation: bad driver reference");
ThrowIfNULL(inIOCycleInfo,
CAException(kAudioHardwareIllegalOperationError),
"EQM_EndIOOperation: no cycle info");
ThrowIf(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device_UI_Sounds && inDeviceObjectID != kObjectID_Device_Null,
CAException(kAudioHardwareBadDeviceError),
"EQM_EndIOOperation: unknown device");
// tell the device to do the work
EQM_LookUpDevice(inDeviceObjectID).DoIOOperation(inStreamObjectID,
inClientID,
inOperationID,
inIOBufferFrameSize,
*inIOCycleInfo,
ioMainBuffer,
ioSecondaryBuffer);
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
DebugMsg("EQM_PlugInInterface::EQM_DoIOOperation: unknown exception. (device: %s, operation: %u)",
(inDeviceObjectID == kObjectID_Device ? "EQMDevice" : "other"),
inOperationID);
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}
static OSStatus EQM_EndIOOperation(AudioServerPlugInDriverRef inDriver,
AudioObjectID inDeviceObjectID,
UInt32 inClientID,
UInt32 inOperationID,
UInt32 inIOBufferFrameSize,
const AudioServerPlugInIOCycleInfo* inIOCycleInfo)
{
// This is called at the end of an IO operation.
OSStatus theAnswer = 0;
try
{
// check the arguments
ThrowIf(inDriver != gAudioServerPlugInDriverRef,
CAException(kAudioHardwareBadObjectError),
"EQM_EndIOOperation: bad driver reference");
ThrowIfNULL(inIOCycleInfo,
CAException(kAudioHardwareIllegalOperationError),
"EQM_EndIOOperation: no cycle info");
ThrowIf(inDeviceObjectID != kObjectID_Device && inDeviceObjectID != kObjectID_Device_UI_Sounds && inDeviceObjectID != kObjectID_Device_Null,
CAException(kAudioHardwareBadDeviceError),
"EQM_EndIOOperation: unknown device");
// tell the device to do the work
EQM_LookUpDevice(inDeviceObjectID).EndIOOperation(inOperationID,
inIOBufferFrameSize,
*inIOCycleInfo,
inClientID);
}
catch(const CAException& inException)
{
theAnswer = inException.GetError();
}
catch(...)
{
DebugMsg("EQM_PlugInInterface::EQM_EndIOOperation: unknown exception. (device: %s, operation: %u)",
(inDeviceObjectID == kObjectID_Device ? "EQMDevice" : "other"),
inOperationID);
theAnswer = kAudioHardwareUnspecifiedError;
}
return theAnswer;
}

View File

@ -1,473 +0,0 @@
// EQM_Stream.cpp
// EQMDriver
//
//
// Portions copyright (C) 2013 Apple Inc. All Rights Reserved.
//
// Self Include
#include "EQM_Stream.h"
// Local Includes
#include "EQM_Types.h"
#include "EQM_Utils.h"
#include "EQM_Device.h"
#include "EQM_PlugIn.h"
// PublicUtility Includes
#include "CADebugMacros.h"
#include "CAException.h"
#include "CAPropertyAddress.h"
#include "CADispatchQueue.h"
#pragma clang assume_nonnull begin
EQM_Stream::EQM_Stream(AudioObjectID inObjectID,
AudioDeviceID inOwnerDeviceID,
bool inIsInput,
Float64 inSampleRate,
UInt32 inStartingChannel)
:
EQM_Object(inObjectID, kAudioStreamClassID, kAudioObjectClassID, inOwnerDeviceID),
mStateMutex(inIsInput ? "Input Stream State" : "Output Stream State"),
mIsInput(inIsInput),
mIsStreamActive(false),
mSampleRate(inSampleRate),
mStartingChannel(inStartingChannel)
{
}
EQM_Stream::~EQM_Stream()
{
}
bool EQM_Stream::HasProperty(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const
{
// For each object, this driver implements all the required properties plus a few extras that
// are useful but not required. There is more detailed commentary about each property in the
// GetPropertyData() method.
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioStreamPropertyIsActive:
case kAudioStreamPropertyDirection:
case kAudioStreamPropertyTerminalType:
case kAudioStreamPropertyStartingChannel:
case kAudioStreamPropertyLatency:
case kAudioStreamPropertyVirtualFormat:
case kAudioStreamPropertyPhysicalFormat:
case kAudioStreamPropertyAvailableVirtualFormats:
case kAudioStreamPropertyAvailablePhysicalFormats:
theAnswer = true;
break;
default:
theAnswer = EQM_Object::HasProperty(inObjectID, inClientPID, inAddress);
break;
};
return theAnswer;
}
bool EQM_Stream::IsPropertySettable(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const
{
// For each object, this driver implements all the required properties plus a few extras that
// are useful but not required. There is more detailed commentary about each property in the
// GetPropertyData() method.
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioStreamPropertyDirection:
case kAudioStreamPropertyTerminalType:
case kAudioStreamPropertyStartingChannel:
case kAudioStreamPropertyLatency:
case kAudioStreamPropertyAvailableVirtualFormats:
case kAudioStreamPropertyAvailablePhysicalFormats:
theAnswer = false;
break;
case kAudioStreamPropertyIsActive:
case kAudioStreamPropertyVirtualFormat:
case kAudioStreamPropertyPhysicalFormat:
theAnswer = true;
break;
default:
theAnswer = EQM_Object::IsPropertySettable(inObjectID, inClientPID, inAddress);
break;
};
return theAnswer;
}
UInt32 EQM_Stream::GetPropertyDataSize(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData) const
{
// For each object, this driver implements all the required properties plus a few extras that
// are useful but not required. There is more detailed commentary about each property in the
// GetPropertyData() method.
UInt32 theAnswer = 0;
switch(inAddress.mSelector)
{
case kAudioStreamPropertyIsActive:
theAnswer = sizeof(UInt32);
break;
case kAudioStreamPropertyDirection:
theAnswer = sizeof(UInt32);
break;
case kAudioStreamPropertyTerminalType:
theAnswer = sizeof(UInt32);
break;
case kAudioStreamPropertyStartingChannel:
theAnswer = sizeof(UInt32);
break;
case kAudioStreamPropertyLatency:
theAnswer = sizeof(UInt32);
break;
case kAudioStreamPropertyVirtualFormat:
case kAudioStreamPropertyPhysicalFormat:
theAnswer = sizeof(AudioStreamBasicDescription);
break;
case kAudioStreamPropertyAvailableVirtualFormats:
case kAudioStreamPropertyAvailablePhysicalFormats:
theAnswer = 1 * sizeof(AudioStreamRangedDescription);
break;
default:
theAnswer = EQM_Object::GetPropertyDataSize(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData);
break;
};
return theAnswer;
}
void EQM_Stream::GetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData,
UInt32 inDataSize,
UInt32& outDataSize,
void* outData) const
{
// Since most of the data that will get returned is static, there are few instances where it is
// necessary to lock the state mutex.
switch(inAddress.mSelector)
{
case kAudioObjectPropertyBaseClass:
// The base class for kAudioStreamClassID is kAudioObjectClassID
ThrowIf(inDataSize < sizeof(AudioClassID),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Stream::GetPropertyData: not enough space for the return "
"value of kAudioObjectPropertyBaseClass for the stream");
*reinterpret_cast<AudioClassID*>(outData) = kAudioObjectClassID;
outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyClass:
// Streams are of the class kAudioStreamClassID
ThrowIf(inDataSize < sizeof(AudioClassID),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Stream::GetPropertyData: not enough space for the return "
"value of kAudioObjectPropertyClass for the stream");
*reinterpret_cast<AudioClassID*>(outData) = kAudioStreamClassID;
outDataSize = sizeof(AudioClassID);
break;
case kAudioObjectPropertyOwner:
// A stream's owner is a device object.
{
ThrowIf(inDataSize < sizeof(AudioObjectID),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Stream::GetPropertyData: not enough space for the return "
"value of kAudioObjectPropertyOwner for the stream");
// Lock the state mutex to create a memory barrier, just in case a subclass ever
// allows mOwnerObjectID to be modified.
CAMutex::Locker theStateLocker(mStateMutex);
// Return the requested value.
*reinterpret_cast<AudioObjectID*>(outData) = mOwnerObjectID;
outDataSize = sizeof(AudioObjectID);
}
break;
case kAudioStreamPropertyIsActive:
// This property tells the device whether or not the given stream is going to
// be used for IO. Note that we need to take the state lock to examine this
// value.
{
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Stream::GetPropertyData: not enough space for the return "
"value of kAudioStreamPropertyIsActive for the stream");
// Take the state lock.
CAMutex::Locker theStateLocker(mStateMutex);
// Return the requested value.
*reinterpret_cast<UInt32*>(outData) = mIsStreamActive;
outDataSize = sizeof(UInt32);
}
break;
case kAudioStreamPropertyDirection:
// This returns whether the stream is an input or output stream.
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Stream::GetPropertyData: not enough space for the return value of "
"kAudioStreamPropertyDirection for the stream");
*reinterpret_cast<UInt32*>(outData) = mIsInput ? 1 : 0;
outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyTerminalType:
// This returns a value that indicates what is at the other end of the stream
// such as a speaker or headphones or a microphone.
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Stream::GetPropertyData: not enough space for the return value of "
"kAudioStreamPropertyTerminalType for the stream");
*reinterpret_cast<UInt32*>(outData) =
mIsInput ? kAudioStreamTerminalTypeMicrophone : kAudioStreamTerminalTypeSpeaker;
outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyStartingChannel:
// This property returns the absolute channel number for the first channel in
// the stream. For example, if a device has two output streams with two
// channels each, then the starting channel number for the first stream is 1
// and the starting channel number for the second stream is 3.
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Stream::GetPropertyData: not enough space for the return "
"value of kAudioStreamPropertyStartingChannel for the stream");
*reinterpret_cast<UInt32*>(outData) = mStartingChannel;
outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyLatency:
// This property returns any additonal presentation latency the stream has.
ThrowIf(inDataSize < sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Stream::GetPropertyData: not enough space for the return "
"value of kAudioStreamPropertyLatency for the stream");
*reinterpret_cast<UInt32*>(outData) = 0;
outDataSize = sizeof(UInt32);
break;
case kAudioStreamPropertyVirtualFormat:
case kAudioStreamPropertyPhysicalFormat:
// This returns the current format of the stream in an AudioStreamBasicDescription.
// For devices that don't override the mix operation, the virtual format has to be the
// same as the physical format.
{
ThrowIf(inDataSize < sizeof(AudioStreamBasicDescription),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Stream::GetPropertyData: not enough space for the return "
"value of kAudioStreamPropertyVirtualFormat for the stream");
// This particular device always vends 32-bit native endian floats
AudioStreamBasicDescription* outASBD =
reinterpret_cast<AudioStreamBasicDescription*>(outData);
// Our streams have the same sample rate as the device they belong to.
outASBD->mSampleRate = mSampleRate;
outASBD->mFormatID = kAudioFormatLinearPCM;
outASBD->mFormatFlags =
kAudioFormatFlagIsFloat | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
outASBD->mBytesPerPacket = 8;
outASBD->mFramesPerPacket = 1;
outASBD->mBytesPerFrame = 8;
outASBD->mChannelsPerFrame = 2;
outASBD->mBitsPerChannel = 32;
outDataSize = sizeof(AudioStreamBasicDescription);
}
break;
case kAudioStreamPropertyAvailableVirtualFormats:
case kAudioStreamPropertyAvailablePhysicalFormats:
// This returns an array of AudioStreamRangedDescriptions that describe what
// formats are supported.
if((inDataSize / sizeof(AudioStreamRangedDescription)) >= 1)
{
AudioStreamRangedDescription* outASRD =
reinterpret_cast<AudioStreamRangedDescription*>(outData);
outASRD[0].mFormat.mSampleRate = mSampleRate;
outASRD[0].mFormat.mFormatID = kAudioFormatLinearPCM;
outASRD[0].mFormat.mFormatFlags =
kAudioFormatFlagIsFloat | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
outASRD[0].mFormat.mBytesPerPacket = 8;
outASRD[0].mFormat.mFramesPerPacket = 1;
outASRD[0].mFormat.mBytesPerFrame = 8;
outASRD[0].mFormat.mChannelsPerFrame = 2;
outASRD[0].mFormat.mBitsPerChannel = 32;
// These match kAudioDevicePropertyAvailableNominalSampleRates.
outASRD[0].mSampleRateRange.mMinimum = 1.0;
outASRD[0].mSampleRateRange.mMaximum = 1000000000.0;
// Report how much we wrote.
outDataSize = sizeof(AudioStreamRangedDescription);
}
else
{
outDataSize = 0;
}
break;
default:
EQM_Object::GetPropertyData(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData,
inDataSize,
outDataSize,
outData);
break;
};
}
void EQM_Stream::SetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData,
UInt32 inDataSize,
const void* inData)
{
// There is more detailed commentary about each property in the GetPropertyData() method.
switch(inAddress.mSelector)
{
case kAudioStreamPropertyIsActive:
{
// Changing the active state of a stream doesn't affect IO or change the structure
// so we can just save the state and send the notification.
ThrowIf(inDataSize != sizeof(UInt32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Stream::SetPropertyData: wrong size for the data for "
"kAudioStreamPropertyIsActive");
bool theNewIsActive = *reinterpret_cast<const UInt32*>(inData) != 0;
CAMutex::Locker theStateLocker(mStateMutex);
if(mIsStreamActive != theNewIsActive)
{
mIsStreamActive = theNewIsActive;
// Send the notification.
CADispatchQueue::GetGlobalSerialQueue().Dispatch(false, ^{
AudioObjectPropertyAddress theProperty[] = {
CAPropertyAddress(kAudioStreamPropertyIsActive)
};
EQM_PlugIn::Host_PropertiesChanged(inObjectID, 1, theProperty);
});
}
}
break;
case kAudioStreamPropertyVirtualFormat:
case kAudioStreamPropertyPhysicalFormat:
{
// The device that owns the stream handles changing the stream format, as it needs
// to be handled via the RequestConfigChange/PerformConfigChange machinery. The
// stream only needs to validate the format at this point.
//
// Note that because our devices only supports 2 channel 32 bit float data, the only
// thing that can change is the sample rate.
ThrowIf(inDataSize != sizeof(AudioStreamBasicDescription),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_Stream::SetPropertyData: wrong size for the data for "
"kAudioStreamPropertyPhysicalFormat");
const AudioStreamBasicDescription* theNewFormat =
reinterpret_cast<const AudioStreamBasicDescription*>(inData);
ThrowIf(theNewFormat->mFormatID != kAudioFormatLinearPCM,
CAException(kAudioDeviceUnsupportedFormatError),
"EQM_Stream::SetPropertyData: unsupported format ID for "
"kAudioStreamPropertyPhysicalFormat");
ThrowIf(theNewFormat->mFormatFlags !=
(kAudioFormatFlagIsFloat |
kAudioFormatFlagsNativeEndian |
kAudioFormatFlagIsPacked),
CAException(kAudioDeviceUnsupportedFormatError),
"EQM_Stream::SetPropertyData: unsupported format flags for "
"kAudioStreamPropertyPhysicalFormat");
ThrowIf(theNewFormat->mBytesPerPacket != 8,
CAException(kAudioDeviceUnsupportedFormatError),
"EQM_Stream::SetPropertyData: unsupported bytes per packet for "
"kAudioStreamPropertyPhysicalFormat");
ThrowIf(theNewFormat->mFramesPerPacket != 1,
CAException(kAudioDeviceUnsupportedFormatError),
"EQM_Stream::SetPropertyData: unsupported frames per packet for "
"kAudioStreamPropertyPhysicalFormat");
ThrowIf(theNewFormat->mBytesPerFrame != 8,
CAException(kAudioDeviceUnsupportedFormatError),
"EQM_Stream::SetPropertyData: unsupported bytes per frame for "
"kAudioStreamPropertyPhysicalFormat");
ThrowIf(theNewFormat->mChannelsPerFrame != 2,
CAException(kAudioDeviceUnsupportedFormatError),
"EQM_Stream::SetPropertyData: unsupported channels per frame for "
"kAudioStreamPropertyPhysicalFormat");
ThrowIf(theNewFormat->mBitsPerChannel != 32,
CAException(kAudioDeviceUnsupportedFormatError),
"EQM_Stream::SetPropertyData: unsupported bits per channel for "
"kAudioStreamPropertyPhysicalFormat");
ThrowIf(theNewFormat->mSampleRate < 1.0,
CAException(kAudioDeviceUnsupportedFormatError),
"EQM_Stream::SetPropertyData: unsupported sample rate for "
"kAudioStreamPropertyPhysicalFormat");
}
break;
default:
EQM_Object::SetPropertyData(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData,
inDataSize,
inData);
break;
};
}
#pragma mark Accessors
void EQM_Stream::SetSampleRate(Float64 inSampleRate)
{
CAMutex::Locker theStateLocker(mStateMutex);
mSampleRate = inSampleRate;
}
#pragma clang assume_nonnull end

View File

@ -1,97 +0,0 @@
// EQM_Stream.h
// EQMDriver
//
//
//
// An input or output audio stream. Each stream belongs to a device (see EQM_AbstractDevice), which
// in turn belongs to a plug-in (see EQM_PlugIn).
//
// This class only handles the stream's HAL properties, i.e. the metadata about the stream, not the
// audio data itself.
//
#ifndef EQMDriver__EQM_Stream
#define EQMDriver__EQM_Stream
// SuperClass Includes
#include "EQM_Object.h"
// PublicUtility Includes
#include "CAMutex.h"
// System Includes
#include <CoreAudio/AudioHardwareBase.h>
#pragma clang assume_nonnull begin
class EQM_Stream
:
public EQM_Object
{
#pragma mark Construction/Destruction
public:
EQM_Stream(AudioObjectID inObjectID,
AudioObjectID inOwnerDeviceID,
bool inIsInput,
Float64 inSampleRate,
UInt32 inStartingChannel = 1);
virtual ~EQM_Stream();
#pragma mark Property Operations
public:
bool HasProperty(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const;
bool IsPropertySettable(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const;
UInt32 GetPropertyDataSize(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData) const;
void GetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData,
UInt32 inDataSize,
UInt32& outDataSize,
void* outData) const;
void SetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* __nullable inQualifierData,
UInt32 inDataSize,
const void* inData);
#pragma mark Accessors
void SetSampleRate(Float64 inSampleRate);
private:
CAMutex mStateMutex;
bool mIsInput;
Float64 mSampleRate;
/*! True if the stream is enabled and doing IO. See kAudioStreamPropertyIsActive. */
bool mIsStreamActive;
/*!
The absolute channel number for the first channel in the stream. For example, if a device has
two output streams with two channels each, then the starting channel number for the first
stream is 1 and the starting channel number for the second stream is 3. See
kAudioStreamPropertyStartingChannel.
*/
UInt32 mStartingChannel;
};
#pragma clang assume_nonnull end
#endif /* EQMDriver__EQM_Stream */

View File

@ -1,472 +0,0 @@
//
// EQM_TaskQueue.cpp
// EQMDriver
//
//
// Self Include
#include "EQM_TaskQueue.h"
// Local Includes
#include "EQM_Types.h"
#include "EQM_Utils.h"
#include "EQM_PlugIn.h"
#include "EQM_Clients.h"
#include "EQM_ClientMap.h"
#include "EQM_ClientTasks.h"
// PublicUtility Includes
#include "CAException.h"
#include "CADebugMacros.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-conversion"
#include "CAAtomic.h"
#pragma clang diagnostic pop
// System Includes
#include <mach/mach_init.h>
#include <mach/mach_time.h>
#include <mach/task.h>
#pragma clang assume_nonnull begin
#pragma mark Construction/destruction
EQM_TaskQueue::EQM_TaskQueue()
:
// The inline documentation for thread_time_constraint_policy.period says "A value of 0 indicates that there is no
// inherent periodicity in the computation". So I figure setting the period to 0 means the scheduler will take as long
// as it wants to wake our real-time thread, which is fine for us, but once it has only other real-time threads can
// preempt us. (And that's only if they won't make our computation take longer than kRealTimeThreadMaximumComputationNs).
mRealTimeThread(&EQM_TaskQueue::RealTimeThreadProc,
this,
/* inPeriod = */ 0,
NanosToAbsoluteTime(kRealTimeThreadNominalComputationNs),
NanosToAbsoluteTime(kRealTimeThreadMaximumComputationNs),
/* inIsPreemptible = */ true),
mNonRealTimeThread(&EQM_TaskQueue::NonRealTimeThreadProc, this)
{
// Init the semaphores
auto createSemaphore = [] () {
semaphore_t theSemaphore;
kern_return_t theError = semaphore_create(mach_task_self(), &theSemaphore, SYNC_POLICY_FIFO, 0);
EQM_Utils::ThrowIfMachError("EQM_TaskQueue::EQM_TaskQueue", "semaphore_create", theError);
ThrowIf(theSemaphore == SEMAPHORE_NULL,
CAException(kAudioHardwareUnspecifiedError),
"EQM_TaskQueue::EQM_TaskQueue: Could not create semaphore");
return theSemaphore;
};
mRealTimeThreadWorkQueuedSemaphore = createSemaphore();
mNonRealTimeThreadWorkQueuedSemaphore = createSemaphore();
mRealTimeThreadSyncTaskCompletedSemaphore = createSemaphore();
mNonRealTimeThreadSyncTaskCompletedSemaphore = createSemaphore();
// Pre-allocate enough tasks in mNonRealTimeThreadTasksFreeList that the real-time threads should never have to
// allocate memory when adding a task to the non-realtime queue.
for(UInt32 i = 0; i < kNonRealTimeThreadTaskBufferSize; i++)
{
EQM_Task* theTask = new EQM_Task;
mNonRealTimeThreadTasksFreeList.push_NA(theTask);
}
// Start the worker threads
mRealTimeThread.Start();
mNonRealTimeThread.Start();
}
EQM_TaskQueue::~EQM_TaskQueue()
{
// Join the worker threads
EQMLogAndSwallowExceptionsMsg("EQM_TaskQueue::~EQM_TaskQueue", "QueueSync", ([&] {
QueueSync(kEQMTaskStopWorkerThread, /* inRunOnRealtimeThread = */ true);
QueueSync(kEQMTaskStopWorkerThread, /* inRunOnRealtimeThread = */ false);
}));
// Destroy the semaphores
auto destroySemaphore = [] (semaphore_t inSemaphore) {
kern_return_t theError = semaphore_destroy(mach_task_self(), inSemaphore);
EQM_Utils::LogIfMachError("EQM_TaskQueue::~EQM_TaskQueue", "semaphore_destroy", theError);
};
destroySemaphore(mRealTimeThreadWorkQueuedSemaphore);
destroySemaphore(mNonRealTimeThreadWorkQueuedSemaphore);
destroySemaphore(mRealTimeThreadSyncTaskCompletedSemaphore);
destroySemaphore(mNonRealTimeThreadSyncTaskCompletedSemaphore);
EQM_Task* theTask;
// Delete the tasks in the non-realtime tasks free list
while((theTask = mNonRealTimeThreadTasksFreeList.pop_atomic()) != NULL)
{
delete theTask;
}
// Delete any tasks left on the non-realtime queue that need to be
while((theTask = mNonRealTimeThreadTasks.pop_atomic()) != NULL)
{
if(!theTask->IsSync())
{
delete theTask;
}
}
}
//static
UInt32 EQM_TaskQueue::NanosToAbsoluteTime(UInt32 inNanos)
{
// Converts a duration from nanoseconds to absolute time (i.e. number of bus cycles). Used for calculating
// the real-time thread's time constraint policy.
mach_timebase_info_data_t theTimebaseInfo;
mach_timebase_info(&theTimebaseInfo);
Float64 theTicksPerNs = static_cast<Float64>(theTimebaseInfo.denom) / theTimebaseInfo.numer;
return static_cast<UInt32>(inNanos * theTicksPerNs);
}
#pragma mark Task queueing
void EQM_TaskQueue::QueueSync_SwapClientShadowMaps(EQM_ClientMap* inClientMap)
{
// TODO: Is there any reason to use uintptr_t when we pass pointers to tasks like this? I can't think of any
// reason for a system to have (non-function) pointers larger than 64-bit, so I figure they should fit.
//
// From http://en.cppreference.com/w/cpp/language/reinterpret_cast:
// "A pointer converted to an integer of sufficient size and back to the same pointer type is guaranteed
// to have its original value [...]"
QueueSync(kEQMTaskSwapClientShadowMaps, /* inRunOnRealtimeThread = */ true, reinterpret_cast<UInt64>(inClientMap));
}
void EQM_TaskQueue::QueueAsync_SendPropertyNotification(AudioObjectPropertySelector inProperty, AudioObjectID inDeviceID)
{
DebugMsg("EQM_TaskQueue::QueueAsync_SendPropertyNotification: Queueing property notification. inProperty=%u inDeviceID=%u",
inProperty,
inDeviceID);
EQM_Task theTask(kEQMTaskSendPropertyNotification, /* inIsSync = */ false, inProperty, inDeviceID);
QueueOnNonRealtimeThread(theTask);
}
bool EQM_TaskQueue::Queue_UpdateClientIOState(bool inSync, EQM_Clients* inClients, UInt32 inClientID, bool inDoingIO)
{
DebugMsg("EQM_TaskQueue::Queue_UpdateClientIOState: Queueing %s %s",
(inDoingIO ? "kEQMTaskStartClientIO" : "kEQMTaskStopClientIO"),
(inSync ? "synchronously" : "asynchronously"));
EQM_TaskID theTaskID = (inDoingIO ? kEQMTaskStartClientIO : kEQMTaskStopClientIO);
UInt64 theClientsPtrArg = reinterpret_cast<UInt64>(inClients);
UInt64 theClientIDTaskArg = static_cast<UInt64>(inClientID);
if(inSync)
{
return QueueSync(theTaskID, false, theClientsPtrArg, theClientIDTaskArg);
}
else
{
EQM_Task theTask(theTaskID, /* inIsSync = */ false, theClientsPtrArg, theClientIDTaskArg);
QueueOnNonRealtimeThread(theTask);
// This method's return value isn't used when queueing async, because we can't know what it should be yet.
return false;
}
}
UInt64 EQM_TaskQueue::QueueSync(EQM_TaskID inTaskID, bool inRunOnRealtimeThread, UInt64 inTaskArg1, UInt64 inTaskArg2)
{
DebugMsg("EQM_TaskQueue::QueueSync: Queueing task synchronously to be processed on the %s thread. inTaskID=%d inTaskArg1=%llu inTaskArg2=%llu",
(inRunOnRealtimeThread ? "realtime" : "non-realtime"),
inTaskID,
inTaskArg1,
inTaskArg2);
// Create the task
EQM_Task theTask(inTaskID, /* inIsSync = */ true, inTaskArg1, inTaskArg2);
// Add the task to the queue
TAtomicStack<EQM_Task>& theTasks = (inRunOnRealtimeThread ? mRealTimeThreadTasks : mNonRealTimeThreadTasks);
theTasks.push_atomic(&theTask);
// Wake the worker thread so it'll process the task. (Note that semaphore_signal has an implicit barrier.)
kern_return_t theError = semaphore_signal(inRunOnRealtimeThread ? mRealTimeThreadWorkQueuedSemaphore : mNonRealTimeThreadWorkQueuedSemaphore);
EQM_Utils::ThrowIfMachError("EQM_TaskQueue::QueueSync", "semaphore_signal", theError);
// Wait until the task has been processed.
//
// The worker thread signals all threads waiting on this semaphore when it finishes a task. The comments in WorkerThreadProc
// explain why we have to check the condition in a loop here.
bool didLogTimeoutMessage = false;
while(!theTask.IsComplete())
{
semaphore_t theTaskCompletedSemaphore =
inRunOnRealtimeThread ? mRealTimeThreadSyncTaskCompletedSemaphore : mNonRealTimeThreadSyncTaskCompletedSemaphore;
// TODO: Because the worker threads use semaphore_signal_all instead of semaphore_signal, a thread can miss the signal if
// it isn't waiting at the right time. Using a timeout for now as a temporary fix so threads don't get stuck here.
theError = semaphore_timedwait(theTaskCompletedSemaphore,
(mach_timespec_t){ 0, kRealTimeThreadMaximumComputationNs * 4 });
if(theError == KERN_OPERATION_TIMED_OUT)
{
if(!didLogTimeoutMessage && inRunOnRealtimeThread)
{
DebugMsg("EQM_TaskQueue::QueueSync: Task %d taking longer than expected.", theTask.GetTaskID());
didLogTimeoutMessage = true;
}
}
else
{
EQM_Utils::ThrowIfMachError("EQM_TaskQueue::QueueSync", "semaphore_timedwait", theError);
}
CAMemoryBarrier();
}
if(didLogTimeoutMessage)
{
DebugMsg("EQM_TaskQueue::QueueSync: Late task %d finished.", theTask.GetTaskID());
}
if(theTask.GetReturnValue() != INT64_MAX)
{
DebugMsg("EQM_TaskQueue::QueueSync: Task %d returned %llu.", theTask.GetTaskID(), theTask.GetReturnValue());
}
return theTask.GetReturnValue();
}
void EQM_TaskQueue::QueueOnNonRealtimeThread(EQM_Task inTask)
{
// Add the task to our task list
EQM_Task* freeTask = mNonRealTimeThreadTasksFreeList.pop_atomic();
if(freeTask == NULL)
{
LogWarning("EQM_TaskQueue::QueueOnNonRealtimeThread: No pre-allocated tasks left in the free list. Allocating new task.");
freeTask = new EQM_Task;
}
*freeTask = inTask;
mNonRealTimeThreadTasks.push_atomic(freeTask);
// Signal the worker thread to process the task. (Note that semaphore_signal has an implicit barrier.)
kern_return_t theError = semaphore_signal(mNonRealTimeThreadWorkQueuedSemaphore);
EQM_Utils::ThrowIfMachError("EQM_TaskQueue::QueueOnNonRealtimeThread", "semaphore_signal", theError);
}
#pragma mark Worker threads
void EQM_TaskQueue::AssertCurrentThreadIsRTWorkerThread(const char* inCallerMethodName)
{
#if DEBUG // This Assert macro always checks the condition, even in release builds if the compiler doesn't optimise it away
if(!mRealTimeThread.IsCurrentThread())
{
DebugMsg("%s should only be called on the realtime worker thread.", inCallerMethodName);
__ASSERT_STOP; // TODO: Figure out a better way to assert with a formatted message
}
Assert(mRealTimeThread.IsTimeConstraintThread(), "mRealTimeThread should be in a time-constraint priority band.");
#else
#pragma unused (inCallerMethodName)
#endif
}
//static
void* __nullable EQM_TaskQueue::RealTimeThreadProc(void* inRefCon)
{
DebugMsg("EQM_TaskQueue::RealTimeThreadProc: The realtime worker thread has started");
EQM_TaskQueue* refCon = static_cast<EQM_TaskQueue*>(inRefCon);
refCon->WorkerThreadProc(refCon->mRealTimeThreadWorkQueuedSemaphore,
refCon->mRealTimeThreadSyncTaskCompletedSemaphore,
&refCon->mRealTimeThreadTasks,
NULL,
[&] (EQM_Task* inTask) { return refCon->ProcessRealTimeThreadTask(inTask); });
return NULL;
}
//static
void* __nullable EQM_TaskQueue::NonRealTimeThreadProc(void* inRefCon)
{
DebugMsg("EQM_TaskQueue::NonRealTimeThreadProc: The non-realtime worker thread has started");
EQM_TaskQueue* refCon = static_cast<EQM_TaskQueue*>(inRefCon);
refCon->WorkerThreadProc(refCon->mNonRealTimeThreadWorkQueuedSemaphore,
refCon->mNonRealTimeThreadSyncTaskCompletedSemaphore,
&refCon->mNonRealTimeThreadTasks,
&refCon->mNonRealTimeThreadTasksFreeList,
[&] (EQM_Task* inTask) { return refCon->ProcessNonRealTimeThreadTask(inTask); });
return NULL;
}
void EQM_TaskQueue::WorkerThreadProc(semaphore_t inWorkQueuedSemaphore, semaphore_t inSyncTaskCompletedSemaphore, TAtomicStack<EQM_Task>* inTasks, TAtomicStack2<EQM_Task>* __nullable inFreeList, std::function<bool(EQM_Task*)> inProcessTask)
{
bool theThreadShouldStop = false;
while(!theThreadShouldStop)
{
// Wait until a thread signals that it's added tasks to the queue.
//
// Note that we don't have to hold any lock before waiting. If the semaphore is signalled before we begin waiting we'll
// still get the signal after we do.
kern_return_t theError = semaphore_wait(inWorkQueuedSemaphore);
EQM_Utils::ThrowIfMachError("EQM_TaskQueue::WorkerThreadProc", "semaphore_wait", theError);
// Fetch the tasks from the queue.
//
// The tasks need to be processed in the order they were added to the queue. Since pop_all_reversed is atomic, other threads
// can't add new tasks while we're reading, which would mix up the order.
EQM_Task* theTask = inTasks->pop_all_reversed();
while(theTask != NULL &&
!theThreadShouldStop) // Stop processing tasks if we're shutting down
{
EQM_Task* theNextTask = theTask->mNext;
EQMAssert(!theTask->IsComplete(),
"EQM_TaskQueue::WorkerThreadProc: Cannot process already completed task (ID %d)",
theTask->GetTaskID());
EQMAssert(theTask != theNextTask,
"EQM_TaskQueue::WorkerThreadProc: EQM_Task %p (ID %d) was added to %s multiple times. arg1=%llu arg2=%llu",
theTask,
theTask->GetTaskID(),
(inTasks == &mRealTimeThreadTasks ? "mRealTimeThreadTasks" : "mNonRealTimeThreadTasks"),
theTask->GetArg1(),
theTask->GetArg2());
// Process the task
theThreadShouldStop = inProcessTask(theTask);
// If the task was queued synchronously, let the thread that queued it know we're finished
if(theTask->IsSync())
{
// Marking the task as completed allows QueueSync to return, which means it's possible for theTask to point to
// invalid memory after this point.
CAMemoryBarrier();
theTask->MarkCompleted();
// Signal any threads waiting for their task to be processed.
//
// We use semaphore_signal_all instead of semaphore_signal to avoid a race condition in QueueSync. It's possible
// for threads calling QueueSync to wait on the semaphore in an order different to the order of the tasks they just
// added to the queue. So after each task is completed we have every waiting thread check if it was theirs.
//
// Note that semaphore_signal_all has an implicit barrier.
theError = semaphore_signal_all(inSyncTaskCompletedSemaphore);
EQM_Utils::ThrowIfMachError("EQM_TaskQueue::WorkerThreadProc", "semaphore_signal_all", theError);
}
else if(inFreeList != NULL)
{
// After completing an async task, move it to the free list so the memory can be reused
inFreeList->push_atomic(theTask);
}
theTask = theNextTask;
}
}
}
bool EQM_TaskQueue::ProcessRealTimeThreadTask(EQM_Task* inTask)
{
AssertCurrentThreadIsRTWorkerThread("EQM_TaskQueue::ProcessRealTimeThreadTask");
switch(inTask->GetTaskID())
{
case kEQMTaskStopWorkerThread:
DebugMsg("EQM_TaskQueue::ProcessRealTimeThreadTask: Stopping");
// Return that the thread should stop itself
return true;
case kEQMTaskSwapClientShadowMaps:
{
DebugMsg("EQM_TaskQueue::ProcessRealTimeThreadTask: Swapping the shadow maps in EQM_ClientMap");
EQM_ClientMap* theClientMap = reinterpret_cast<EQM_ClientMap*>(inTask->GetArg1());
EQM_ClientTasks::SwapInShadowMapsRT(theClientMap);
}
break;
default:
Assert(false, "EQM_TaskQueue::ProcessRealTimeThreadTask: Unexpected task ID");
break;
}
return false;
}
bool EQM_TaskQueue::ProcessNonRealTimeThreadTask(EQM_Task* inTask)
{
#if DEBUG // This Assert macro always checks the condition, if for some reason the compiler doesn't optimise it away, even in release builds
Assert(mNonRealTimeThread.IsCurrentThread(), "ProcessNonRealTimeThreadTask should only be called on the non-realtime worker thread.");
Assert(mNonRealTimeThread.IsTimeShareThread(), "mNonRealTimeThread should not be in a time-constraint priority band.");
#endif
switch(inTask->GetTaskID())
{
case kEQMTaskStopWorkerThread:
DebugMsg("EQM_TaskQueue::ProcessNonRealTimeThreadTask: Stopping");
// Return that the thread should stop itself
return true;
case kEQMTaskStartClientIO:
DebugMsg("EQM_TaskQueue::ProcessNonRealTimeThreadTask: Processing kEQMTaskStartClientIO");
try
{
EQM_Clients* theClients = reinterpret_cast<EQM_Clients*>(inTask->GetArg1());
bool didStartIO = EQM_ClientTasks::StartIONonRT(theClients, static_cast<UInt32>(inTask->GetArg2()));
inTask->SetReturnValue(didStartIO);
}
// TODO: Catch the other types of exceptions EQM_ClientTasks::StartIONonRT can throw here as well. Set the task's return
// value (rather than rethrowing) so the exceptions can be handled if the task was queued sync. Then
// QueueSync_StartClientIO can throw some exception and EQM_StartIO can return an appropriate error code to the
// HAL, instead of the driver just crashing.
//
// Do the same for the kEQMTaskStopClientIO case below. And should we set a return value in the catch block for
// EQM_InvalidClientException as well, so it can also be rethrown in QueueSync_StartClientIO and then handled?
catch(EQM_InvalidClientException)
{
DebugMsg("EQM_TaskQueue::ProcessNonRealTimeThreadTask: Ignoring EQM_InvalidClientException thrown by StartIONonRT. %s",
"It's possible the client was removed before this task was processed.");
}
break;
case kEQMTaskStopClientIO:
DebugMsg("EQM_TaskQueue::ProcessNonRealTimeThreadTask: Processing kEQMTaskStopClientIO");
try
{
EQM_Clients* theClients = reinterpret_cast<EQM_Clients*>(inTask->GetArg1());
bool didStopIO = EQM_ClientTasks::StopIONonRT(theClients, static_cast<UInt32>(inTask->GetArg2()));
inTask->SetReturnValue(didStopIO);
}
catch(EQM_InvalidClientException)
{
DebugMsg("EQM_TaskQueue::ProcessNonRealTimeThreadTask: Ignoring EQM_InvalidClientException thrown by StopIONonRT. %s",
"It's possible the client was removed before this task was processed.");
}
break;
case kEQMTaskSendPropertyNotification:
DebugMsg("EQM_TaskQueue::ProcessNonRealTimeThreadTask: Processing kEQMTaskSendPropertyNotification");
{
AudioObjectPropertyAddress thePropertyAddress[] = {
{ static_cast<UInt32>(inTask->GetArg1()), kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster } };
EQM_PlugIn::Host_PropertiesChanged(static_cast<AudioObjectID>(inTask->GetArg2()), 1, thePropertyAddress);
}
break;
default:
Assert(false, "EQM_TaskQueue::ProcessNonRealTimeThreadTask: Unexpected task ID");
break;
}
return false;
}
#pragma clang assume_nonnull end

View File

@ -1,186 +0,0 @@
//
// EQM_TaskQueue.h
// EQMDriver
//
//
#ifndef __EQMDriver__EQM_TaskQueue__
#define __EQMDriver__EQM_TaskQueue__
// PublicUtility Includes
#include "CAPThread.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-conversion"
#include "CAAtomicStack.h"
#pragma clang diagnostic pop
// STL Includes
#include <functional>
// System Includes
#include <mach/semaphore.h>
#include <CoreAudio/AudioHardware.h>
// Forward declarations
class EQM_Clients;
class EQM_ClientMap;
#pragma clang assume_nonnull begin
//==================================================================================================
// EQM_TaskQueue
//
// This class has two worker threads, one with real-time priority and one with default priority,
// that tasks can be dispatched to. The two main use cases are dispatching work from a real-time
// thread to be done async, and dispatching work from a non-real-time thread that needs to run on
// a real-time thread to avoid priority inversions.
//==================================================================================================
class EQM_TaskQueue
{
private:
enum EQM_TaskID {
kEQMTaskUninitialized,
kEQMTaskStopWorkerThread,
// Realtime thread only
kEQMTaskSwapClientShadowMaps,
// Non-realtime thread only
kEQMTaskStartClientIO,
kEQMTaskStopClientIO,
kEQMTaskSendPropertyNotification
};
class EQM_Task
{
public:
EQM_Task(EQM_TaskID inTaskID = kEQMTaskUninitialized, bool inIsSync = false, UInt64 inArg1 = 0, UInt64 inArg2 = 0) : mNext(NULL), mTaskID(inTaskID), mIsSync(inIsSync), mArg1(inArg1), mArg2(inArg2) { };
EQM_TaskID GetTaskID() { return mTaskID; }
// True if the thread that queued this task is blocking until the task is completed
bool IsSync() { return mIsSync; }
UInt64 GetArg1() { return mArg1; }
UInt64 GetArg2() { return mArg2; }
UInt64 GetReturnValue() { return mReturnValue; }
void SetReturnValue(UInt64 inReturnValue) { mReturnValue = inReturnValue; }
bool IsComplete() { return mIsComplete; }
void MarkCompleted() { mIsComplete = true; }
// Used by TAtomicStack
EQM_Task* __nullable & next() { return mNext; }
EQM_Task* __nullable mNext;
private:
EQM_TaskID mTaskID;
bool mIsSync;
UInt64 mArg1;
UInt64 mArg2;
UInt64 mReturnValue = INT64_MAX;
bool mIsComplete = false;
};
public:
EQM_TaskQueue();
~EQM_TaskQueue();
// Disallow copying
EQM_TaskQueue(const EQM_TaskQueue&) = delete;
EQM_TaskQueue& operator=(const EQM_TaskQueue&) = delete;
private:
static UInt32 NanosToAbsoluteTime(UInt32 inNanos);
public:
void QueueSync_SwapClientShadowMaps(EQM_ClientMap* inClientMap);
// Sends a property changed notification to the EQMDevice host. Assumes the scope and element are kAudioObjectPropertyScopeGlobal and
// kAudioObjectPropertyElementMaster because currently those are the only ones we use.
void QueueAsync_SendPropertyNotification(AudioObjectPropertySelector inProperty, AudioObjectID inDeviceID);
// Set/unset a client's is-doing-IO flag
inline bool QueueSync_StartClientIO(EQM_Clients* inClients, UInt32 inClientID) { return Queue_UpdateClientIOState(true, inClients, inClientID, true); }
inline bool QueueSync_StopClientIO(EQM_Clients* inClients, UInt32 inClientID) { return Queue_UpdateClientIOState(true, inClients, inClientID, false); }
inline void QueueAsync_StartClientIO(EQM_Clients* inClients, UInt32 inClientID) { Queue_UpdateClientIOState(false, inClients, inClientID, true); }
inline void QueueAsync_StopClientIO(EQM_Clients* inClients, UInt32 inClientID) { Queue_UpdateClientIOState(false, inClients, inClientID, false); }
private:
bool Queue_UpdateClientIOState(bool inSync, EQM_Clients* inClients, UInt32 inClientID, bool inDoingIO);
UInt64 QueueSync(EQM_TaskID inTaskID, bool inRunOnRealtimeThread, UInt64 inTaskArg1 = 0, UInt64 inTaskArg2 = 0);
void QueueOnNonRealtimeThread(EQM_Task inTask);
public:
void AssertCurrentThreadIsRTWorkerThread(const char* inCallerMethodName);
private:
static void* __nullable RealTimeThreadProc(void* inRefCon);
static void* __nullable NonRealTimeThreadProc(void* inRefCon);
void WorkerThreadProc(semaphore_t inWorkQueuedSemaphore, semaphore_t inSyncTaskCompletedSemaphore, TAtomicStack<EQM_Task>* inTasks, TAtomicStack2<EQM_Task>* __nullable inFreeList, std::function<bool(EQM_Task*)> inProcessTask);
// These return true when the thread should be stopped
bool ProcessRealTimeThreadTask(EQM_Task* inTask);
bool ProcessNonRealTimeThreadTask(EQM_Task* inTask);
private:
// The worker threads that perform the queued tasks
CAPThread mRealTimeThread;
CAPThread mNonRealTimeThread;
// The approximate amount of time we'll need whenever our real-time thread is scheduled. This is currently just
// set to the minimum (see sched_prim.c) because our real-time tasks do very little work.
//
// TODO: Would it be better to specify these in absolute time, which would make them relative to the system's bus
// speed? Or even calculate them from the system's CPU/RAM speed? Note that none of our tasks actually have
// a deadline (though that might change). They just have to run with real-time priority to avoid causing
// priority inversions on the IO thread.
static const UInt32 kRealTimeThreadNominalComputationNs = 50 * NSEC_PER_USEC;
// The maximum amount of time the real-time thread can take to finish its computation after being scheduled.
static const UInt32 kRealTimeThreadMaximumComputationNs = 60 * NSEC_PER_USEC;
// We use Mach semaphores for communication with the worker threads because signalling them is real-time safe.
// Signalled to tell the worker threads when there are tasks for them process.
semaphore_t mRealTimeThreadWorkQueuedSemaphore;
semaphore_t mNonRealTimeThreadWorkQueuedSemaphore;
// Signalled when a worker thread completes a task, if the thread that queued that task is blocking on it.
semaphore_t mRealTimeThreadSyncTaskCompletedSemaphore;
semaphore_t mNonRealTimeThreadSyncTaskCompletedSemaphore;
// When a task is queued we add it to one of these, depending on which worker thread it will run on. Using
// TAtomicStack lets us safely add and remove tasks on real-time threads.
//
// We use TAtomicStack rather than TAtomicStack2 because we need pop_all_reversed() to make sure we process the
// tasks in order. (It might have been better to use OSAtomicFifoEnqueue/OSAtomicFifoDequeue, but I only
// recently found out about them.)
TAtomicStack<EQM_Task> mRealTimeThreadTasks;
TAtomicStack<EQM_Task> mNonRealTimeThreadTasks;
// The number of tasks to pre-allocate and add to the non-realtime task free list. Should be large enough that
// the free list is never emptied. (At least not while IO could be running.)
static const UInt32 kNonRealTimeThreadTaskBufferSize = 512;
// Realtime threads can't safely allocate memory, so when they queue a task the memory for it comes from this
// free list. We pre-allocate as many tasks as they should ever need in the constructor. (But if the free list
// runs out of tasks somehow the realtime thread will allocate a new one.)
//
// There's a similar free list used in Apple's CAThreadSafeList.h.
//
// We can use TAtomicStack2 instead of TAtomicStack because we never call pop_all on the free list.
TAtomicStack2<EQM_Task> mNonRealTimeThreadTasksFreeList;
};
#pragma clang assume_nonnull end
#endif /* __EQMDriver__EQM_TaskQueue__ */

View File

@ -1,36 +0,0 @@
//
// EQM_TestUtils.h
// SharedSource
//
//
#ifndef __SharedSource__EQM_TestUtils__
#define __SharedSource__EQM_TestUtils__
// Test Framework
#import <XCTest/XCTest.h>
#if defined(__cplusplus)
// STL Includes
#include <functional>
// Fails the test if f doesn't throw ExpectedException when run.
// (The "self" argument is required by XCTFail, presumably so it can report the context.)
template<typename ExpectedException>
void EQMShouldThrow(XCTestCase* self, const std::function<void()>& f)
{
try
{
f();
XCTFail();
}
catch (ExpectedException)
{ }
}
#endif /* defined(__cplusplus) */
#endif /* __SharedSource__EQM_TestUtils__ */

View File

@ -1,244 +0,0 @@
//
// EQM_Types.h
// SharedSource
//
//
#ifndef SharedSource__EQM_Types
#define SharedSource__EQM_Types
// STL Includes
#if defined(__cplusplus)
#include <stdexcept>
#endif
// System Includes
#include <CoreAudio/AudioServerPlugIn.h>
#pragma mark Project URLs
#pragma mark IDs
// TODO: Change these and the other defines to const strings?
#define kEQMDriverBundleID "com.bitgapp.eqmac.driver"
#define kEQMAppBundleID "com.bitgapp.eqmac"
#define kEQMDeviceUID "EQMDevice"
#define kEQMDeviceModelUID "EQMDeviceModelUID"
#define kEQMDeviceUID_UISounds "EQMDevice_UISounds"
#define kEQMDeviceModelUID_UISounds "EQMDeviceModelUID_UISounds"
#define kEQMNullDeviceUID "EQMNullDevice"
#define kEQMNullDeviceModelUID "EQMNullDeviceModelUID"
// The object IDs for the audio objects this driver implements.
//
// EQMDevice always publishes this fixed set of objects (except when EQMDevice's volume or mute
// controls are disabled). We might need to change that at some point, but so far it hasn't caused
// any problems and it makes the driver much simpler.
enum
{
kObjectID_PlugIn = kAudioObjectPlugInObject,
// EQMDevice
kObjectID_Device = 2, // Belongs to kObjectID_PlugIn
kObjectID_Stream_Input = 3, // Belongs to kObjectID_Device
kObjectID_Stream_Output = 4, // Belongs to kObjectID_Device
kObjectID_Volume_Output_Master = 5, // Belongs to kObjectID_Device
kObjectID_Mute_Output_Master = 6, // Belongs to kObjectID_Device
// Null Device
kObjectID_Device_Null = 7, // Belongs to kObjectID_PlugIn
kObjectID_Stream_Null = 8, // Belongs to kObjectID_Device_Null
// EQMDevice for UI sounds
kObjectID_Device_UI_Sounds = 9, // Belongs to kObjectID_PlugIn
kObjectID_Stream_Input_UI_Sounds = 10, // Belongs to kObjectID_Device_UI_Sounds
kObjectID_Stream_Output_UI_Sounds = 11, // Belongs to kObjectID_Device_UI_Sounds
kObjectID_Volume_Output_Master_UI_Sounds = 12, // Belongs to kObjectID_Device_UI_Sounds
};
// AudioObjectPropertyElement docs: "Elements are numbered sequentially where 0 represents the
// master element."
static const AudioObjectPropertyElement kMasterChannel = kAudioObjectPropertyElementMaster;
#pragma EQM Plug-in Custom Properties
enum
{
// A CFBoolean. True if the null device is enabled. Settable, false by default.
kAudioPlugInCustomPropertyNullDeviceActive = 'nuld',
kAudioPlugInCustomPropertyDeviceActive = 'deva',
kAudioPlugInCustomPropertyUIDeviceActive = 'uida'
};
#pragma mark EQMDevice Custom Properties
enum
{
// TODO: Combine the two music player properties
// The process ID of the music player as a CFNumber. Setting this property will also clear the value of
// kAudioDeviceCustomPropertyMusicPlayerBundleID. We use 0 to mean unset.
//
// There is currently no way for a client to tell whether the process it has set as the music player is a
// client of the EQMDevice.
kAudioDeviceCustomPropertyMusicPlayerProcessID = 'mppi',
// The music player's bundle ID as a CFString (UTF8), or the empty string if it's unset/null. Setting this
// property will also clear the value of kAudioDeviceCustomPropertyMusicPlayerProcessID.
kAudioDeviceCustomPropertyMusicPlayerBundleID = 'mpbi',
// A CFNumber that specifies whether the device is silent, playing only music (i.e. the client set as the
// music player is the only client playing audio) or audible. See enum values below. This property is only
// updated after the audible state has been different for kDeviceAudibleStateMinChangedFramesForUpdate
// consecutive frames. (To avoid excessive CPU use if for some reason the audible state starts changing
// very often.)
kAudioDeviceCustomPropertyDeviceAudibleState = 'daud',
// A CFBoolean similar to kAudioDevicePropertyDeviceIsRunning except it ignores whether IO is running for
// EQMApp. This is so EQMApp knows when it can stop doing IO to save CPU.
kAudioDeviceCustomPropertyDeviceIsRunningSomewhereOtherThanEQMApp = 'runo',
// A CFArray of CFDictionaries that each contain an app's pid, bundle ID and volume relative to other
// running apps. See the dictionary keys below for more info.
//
// Getting this property will only return apps with volumes other than the default. Setting this property
// will add new app volumes or replace existing ones, but there's currently no way to delete an app from
// the internal collection.
kAudioDeviceCustomPropertyAppVolumes = 'apvs',
// A CFArray of CFBooleans indicating which of EQMDevice's controls are enabled. All controls are enabled
// by default. This property is settable. See the array indices below for more info.
kAudioDeviceCustomPropertyEnabledOutputControls = 'bgct',
kAudioDeviceCustomPropertyLatency = 'cltc',
kAudioDeviceCustomPropertySafetyOffset = 'csfo',
kAudioDeviceCustomPropertyShown = 'shwn',
kAudioDeviceCustomPropertyVersion = 'vrsn'
};
// The number of silent/audible frames before EQMDriver will change kAudioDeviceCustomPropertyDeviceAudibleState
#define kDeviceAudibleStateMinChangedFramesForUpdate (2 << 11)
enum EQMDeviceAudibleState : SInt32
{
// kAudioDeviceCustomPropertyDeviceAudibleState values
//
// No audio is playing on the device's streams (regardless of whether IO is running or not)
kEQMDeviceIsSilent = 'silt',
// The client whose bundle ID matches the current value of kCustomAudioDevicePropertyMusicPlayerBundleID is the
// only audible client
kEQMDeviceIsSilentExceptMusic = 'olym',
kEQMDeviceIsAudible = 'audi'
};
// kAudioDeviceCustomPropertyAppVolumes keys
//
// A CFNumber<SInt32> between kAppRelativeVolumeMinRawValue and kAppRelativeVolumeMaxRawValue. A value greater than
// the midpoint increases the client's volume and a value less than the midpoint decreases it. A volume curve is
// applied to kEQMAppVolumesKey_RelativeVolume when it's first set and then each of the app's samples are multiplied
// by it.
#define kEQMAppVolumesKey_RelativeVolume "rvol"
// A CFNumber<SInt32> between kAppPanLeftRawValue and kAppPanRightRawValue. A negative value has a higher proportion
// of left channel, and a positive value has a higher proportion of right channel.
#define kEQMAppVolumesKey_PanPosition "ppos"
// The app's pid as a CFNumber. May be omitted if kEQMAppVolumesKey_BundleID is present.
#define kEQMAppVolumesKey_ProcessID "pid"
// The app's bundle ID as a CFString. May be omitted if kEQMAppVolumesKey_ProcessID is present.
#define kEQMAppVolumesKey_BundleID "bid"
// Volume curve range for app volumes
#define kAppRelativeVolumeMaxRawValue 100
#define kAppRelativeVolumeMinRawValue 0
#define kAppRelativeVolumeMinDbValue -96.0f
#define kAppRelativeVolumeMaxDbValue 0.0f
// Pan position values
#define kAppPanLeftRawValue -100
#define kAppPanCenterRawValue 0
#define kAppPanRightRawValue 100
// kAudioDeviceCustomPropertyEnabledOutputControls indices
enum
{
// True if EQMDevice's master output volume control is enabled.
kEQMEnabledOutputControlsIndex_Volume = 0,
// True if EQMDevice's master output mute control is enabled.
kEQMEnabledOutputControlsIndex_Mute = 1
};
#pragma mark EQMDevice Custom Property Addresses
// For convenience.
static const AudioObjectPropertyAddress kEQMMusicPlayerProcessIDAddress = {
kAudioDeviceCustomPropertyMusicPlayerProcessID,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
static const AudioObjectPropertyAddress kEQMMusicPlayerBundleIDAddress = {
kAudioDeviceCustomPropertyMusicPlayerBundleID,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
static const AudioObjectPropertyAddress kEQMAudibleStateAddress = {
kAudioDeviceCustomPropertyDeviceAudibleState,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
static const AudioObjectPropertyAddress kEQMRunningSomewhereOtherThanEQMAppAddress = {
kAudioDeviceCustomPropertyDeviceIsRunningSomewhereOtherThanEQMApp,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
static const AudioObjectPropertyAddress kEQMAppVolumesAddress = {
kAudioDeviceCustomPropertyAppVolumes,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
static const AudioObjectPropertyAddress kEQMEnabledOutputControlsAddress = {
kAudioDeviceCustomPropertyEnabledOutputControls,
kAudioObjectPropertyScopeOutput,
kAudioObjectPropertyElementMaster
};
#pragma mark Exceptions
#if defined(__cplusplus)
class EQM_InvalidClientException : public std::runtime_error {
public:
EQM_InvalidClientException() : std::runtime_error("InvalidClient") { }
};
class EQM_InvalidClientPIDException : public std::runtime_error {
public:
EQM_InvalidClientPIDException() : std::runtime_error("InvalidClientPID") { }
};
class EQM_InvalidClientRelativeVolumeException : public std::runtime_error {
public:
EQM_InvalidClientRelativeVolumeException() : std::runtime_error("InvalidClientRelativeVolume") { }
};
class EQM_InvalidClientPanPositionException : public std::runtime_error {
public:
EQM_InvalidClientPanPositionException() : std::runtime_error("InvalidClientPanPosition") { }
};
class EQM_DeviceNotSetException : public std::runtime_error {
public:
EQM_DeviceNotSetException() : std::runtime_error("DeviceNotSet") { }
};
#endif
// Assume we've failed to start the output device if it isn't running IO after this timeout expires.
//
// Currently set to 30s because some devices, e.g. AirPlay, can legitimately take that long to start.
//
// TODO: Should we have a timeout at all? Is there a notification we can subscribe to that will tell us whether the
// device is still making progress? Should we regularly poll mOutputDevice.IsAlive() while we're waiting to
// check it's still responsive?
static const UInt64 kStartIOTimeoutNsec = 30 * NSEC_PER_SEC;
#endif /* SharedSource__EQM_Types */

View File

@ -1,235 +0,0 @@
//
// EQM_Utils.cpp
// SharedSource
//
//
// Self Include
#include "EQM_Utils.h"
// Local Includes
#include "EQM_Types.h"
// System Includes
#include <MacTypes.h>
#include <mach/mach_error.h>
#include <CoreFoundation/CoreFoundation.h> // For kCFCoreFoundationVersionNumber
#include <libproc.h>
#include <stdio.h>
#include <string.h>
#include <sys/sysctl.h>
#include <stdlib.h>
#include <unistd.h>
#include <Carbon/Carbon.h>
#pragma clang assume_nonnull begin
dispatch_queue_t EQMGetDispatchQueue_PriorityUserInteractive()
{
long queueClass;
// Compile-time check that QOS_CLASS_USER_INTERACTIVE can be used. It was added in 10.10.
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 // MAC_OS_X_VERSION_10_10
// Runtime check for the same.
if(floor(kCFCoreFoundationVersionNumber) > kCFCoreFoundationVersionNumber10_9)
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
queueClass = QOS_CLASS_USER_INTERACTIVE;
#pragma clang diagnostic pop
}
else
#endif
{
// Fallback for older versions.
queueClass = DISPATCH_QUEUE_PRIORITY_HIGH;
}
return dispatch_get_global_queue(queueClass, 0);
}
namespace EQM_Utils
{
// Forward declarations
static OSStatus LogAndSwallowExceptions(const char* __nullable fileName,
int lineNumber,
const char* callerName,
const char* __nullable message,
bool expected,
const std::function<void(void)>& function);
bool process_at_path_running (const char *path) {
pid_t pids[2048];
int bytes = proc_listpids(PROC_ALL_PIDS, 0, pids, sizeof(pids));
unsigned long n_proc = (unsigned long)(bytes) / sizeof(pids[0]);
for (int i = 0; i < (int)n_proc; i++) {
char proc_path[MAXPATHLEN+1] = {0};
proc_pidinfo(pids[i], PROC_PIDPATHINFO, 0,
&proc_path, sizeof(proc_path));
if (strcmp(path, proc_path) == 0) {
return true;
}
}
return false;
}
#pragma mark Exception utils
bool LogIfMachError(const char* callerName,
const char* errorReturnedBy,
mach_error_t error)
{
if(error != KERN_SUCCESS)
{
char* errorStr = mach_error_string(error);
LogError("%s: %s returned an error (%d): %s\n",
callerName,
errorReturnedBy,
error,
errorStr ? errorStr : "Unknown error");
return false;
}
return true;
}
void ThrowIfMachError(const char* callerName,
const char* errorReturnedBy,
mach_error_t error)
{
if(!LogIfMachError(callerName, errorReturnedBy, error))
{
Throw(CAException(error));
}
}
OSStatus LogAndSwallowExceptions(const char* __nullable fileName,
int lineNumber,
const char* callerName,
const std::function<void(void)>& function)
{
return LogAndSwallowExceptions(fileName, lineNumber, callerName, nullptr, true, function);
}
OSStatus LogAndSwallowExceptions(const char* __nullable fileName,
int lineNumber,
const char* callerName,
const char* __nullable message,
const std::function<void(void)>& function)
{
return LogAndSwallowExceptions(fileName, lineNumber, callerName, message, true, function);
}
void LogException(const char* __nullable fileName,
int lineNumber,
const char* callerName,
const CAException& e)
{
OSStatus err = e.GetError();
const char err4CC[5] = CA4CCToCString(err);
LogError("%s:%d:%s: CAException, code: '%s' (%d).",
(fileName ? fileName : ""),
lineNumber,
callerName,
err4CC,
err);
}
void LogUnexpectedException(const char* __nullable fileName,
int lineNumber,
const char* callerName)
{
LogError("%s:%d:%s: Unknown unexpected exception.",
(fileName ? fileName : ""),
lineNumber,
callerName);
}
OSStatus LogUnexpectedExceptions(const char* callerName,
const std::function<void(void)>& function)
{
return LogUnexpectedExceptions(nullptr, -1, callerName, nullptr, function);
}
OSStatus LogUnexpectedExceptions(const char* __nullable fileName,
int lineNumber,
const char* callerName,
const std::function<void(void)>& function)
{
return LogUnexpectedExceptions(fileName, lineNumber, callerName, nullptr, function);
}
OSStatus LogUnexpectedExceptions(const char* __nullable fileName,
int lineNumber,
const char* callerName,
const char* __nullable message,
const std::function<void(void)>& function)
{
return LogAndSwallowExceptions(fileName, lineNumber, callerName, message, false, function);
}
#pragma mark Implementation
static OSStatus LogAndSwallowExceptions(const char* __nullable fileName,
int lineNumber,
const char* callerName,
const char* __nullable message,
bool expected,
const std::function<void(void)>& function)
{
try
{
function();
}
catch(const CAException& e)
{
// TODO: Can/should we log a stack trace somewhere? (If so, also in the following catch
// block.)
// TODO: Log a warning instead of an error for expected exceptions?
OSStatus err = e.GetError();
const char err4CC[5] = CA4CCToCString(err);
LogError("%s:%d:%s: %sCAException, code: '%s' (%d). %s%s",
(fileName ? fileName : ""),
lineNumber,
callerName,
(expected ? "" : "Unexpected "),
err4CC,
err,
(message ? message : ""),
(message ? "." : ""));
#if EQM_StopDebuggerOnLoggedExceptions || EQM_StopDebuggerOnLoggedUnexpectedExceptions
#if !EQM_StopDebuggerOnLoggedExceptions
if(!expected)
#endif
{
EQMAssert(false, "CAException");
}
#endif
return e.GetError();
}
catch(...)
{
LogError("%s:%d:%s: %s exception. %s%s",
(fileName ? fileName : ""),
lineNumber,
callerName,
(expected ? "Unknown" : "Unexpected unknown"),
(message ? message : ""),
(message ? "." : ""));
#if EQM_StopDebuggerOnLoggedExceptions || EQM_StopDebuggerOnLoggedUnexpectedExceptions
EQMAssert(false, "Unknown exception");
#endif
return -1;
}
return noErr;
}
}
#pragma clang assume_nonnull end

View File

@ -1,201 +0,0 @@
//
// EQM_Utils.h
// SharedSource
//
//
#ifndef SharedSource__EQM_Utils
#define SharedSource__EQM_Utils
// PublicUtility Includes
#include "CADebugMacros.h"
#if defined(__cplusplus)
#include "CAException.h"
// STL Includes
#include <functional>
#endif /* defined(__cplusplus) */
// System Includes
#include <mach/error.h>
#include <dispatch/dispatch.h>
#pragma mark Macros
// The Assert macro from CADebugMacros with support for format strings added.
#define EQMAssert(inCondition, inMessage, ...) \
if(!(inCondition)) \
{ \
DebugMsg(inMessage, ## __VA_ARGS__); \
__ASSERT_STOP; \
}
#define EQMAssertNonNull(expression) \
EQMAssertNonNull2((expression), #expression)
#define EQMAssertNonNull2(expression, expressionStr) \
EQMAssert((expression), \
"%s:%d:%s: '%s' is null", \
__FILE__, \
__LINE__, \
__FUNCTION__, \
expressionStr);
#pragma mark Objective-C Macros
#if defined(__OBJC__)
#if __has_feature(objc_generics)
// This trick is from https://gist.github.com/robb/d55b72d62d32deaee5fa
@interface EQMNonNullCastHelper<__covariant T>
- (nonnull T) asNonNull;
@end
// Explicitly casts expressions from nullable to non-null. Only works with expressions that
// evaluate to Objective-C objects. Use EQM_Utils::NN for other types.
//
// TODO: Replace existing non-null casts with this.
#define EQMNN(expression) ({ \
__typeof((expression)) value = (expression); \
EQMAssertNonNull2(value, #expression); \
EQMNonNullCastHelper<__typeof((expression))>* helper; \
(__typeof(helper.asNonNull))value; \
})
#else /* __has_feature(objc_generics) */
#define EQMNN(expression) ({ \
id value = (expression); \
EQMAssertNonNull2(value, #expression); \
value; \
})
#endif /* __has_feature(objc_generics) */
#endif /* defined(__OBJC__) */
#pragma mark C++ Macros
#if defined(__cplusplus)
#define EQMLogException(exception) \
EQM_Utils::LogException(__FILE__, __LINE__, __FUNCTION__, exception)
#define EQMLogExceptionIn(callerName, exception) \
EQM_Utils::LogException(__FILE__, __LINE__, callerName, exception)
#define EQMLogAndSwallowExceptions(callerName, function) \
EQM_Utils::LogAndSwallowExceptions(__FILE__, __LINE__, callerName, function)
#define EQMLogAndSwallowExceptionsMsg(callerName, message, function) \
EQM_Utils::LogAndSwallowExceptions(__FILE__, __LINE__, callerName, message, function)
#define EQMLogUnexpectedException() \
EQM_Utils::LogUnexpectedException(__FILE__, __LINE__, __FUNCTION__)
#define EQMLogUnexpectedExceptionIn(callerName) \
EQM_Utils::LogUnexpectedException(__FILE__, __LINE__, callerName)
#define EQMLogUnexpectedExceptions(callerName, function) \
EQM_Utils::LogUnexpectedExceptions(__FILE__, __LINE__, callerName, function)
#define EQMLogUnexpectedExceptionsMsg(callerName, message, function) \
EQM_Utils::LogUnexpectedExceptions(__FILE__, __LINE__, callerName, message, function)
#endif /* defined(__cplusplus) */
#pragma clang assume_nonnull begin
#pragma mark C Utility Functions
dispatch_queue_t EQMGetDispatchQueue_PriorityUserInteractive(void);
#if defined(__cplusplus)
#pragma mark C++ Utility Functions
namespace EQM_Utils
{
// Used to explicitly cast from nullable to non-null. For Objective-C objects, use the EQMNN
// macro (above).
template <typename T>
inline T __nonnull NN(T __nullable v) {
EQMAssertNonNull(v);
return static_cast<T __nonnull>(v);
}
// Log (and swallow) errors returned by Mach functions. Returns false if there was an error.
bool LogIfMachError(const char* callerName,
const char* errorReturnedBy,
mach_error_t error);
// Similar to ThrowIfKernelError from CADebugMacros.h, but also logs (in debug builds) the
// Mach error string that corresponds to the error.
void ThrowIfMachError(const char* callerName,
const char* errorReturnedBy,
mach_error_t error);
// If function throws an exception, log an error and continue.
//
// Fails/stops debug builds. It's likely that if we log an error for an exception in release
// builds, even if it's expected (i.e. not a bug in eqMac), we'd want to know if
// it gets thrown during testing/debugging.
OSStatus LogAndSwallowExceptions(const char* __nullable fileName,
int lineNumber,
const char* callerName,
const std::function<void(void)>& function);
OSStatus LogAndSwallowExceptions(const char* __nullable fileName,
int lineNumber,
const char* callerName,
const char* __nullable message,
const std::function<void(void)>& function);
void LogException(const char* __nullable fileName,
int lineNumber,
const char* callerName,
const CAException& e);
void LogUnexpectedException(const char* __nullable fileName,
int lineNumber,
const char* callerName);
OSStatus LogUnexpectedExceptions(const char* callerName,
const std::function<void(void)>& function);
OSStatus LogUnexpectedExceptions(const char* __nullable fileName,
int lineNumber,
const char* callerName,
const std::function<void(void)>& function);
bool process_at_path_running (const char *path);
// Log unexpected exceptions and continue.
//
// Generally, you don't want to use this unless the alternative is to crash. And even then
// crashing is often the better option. (Especially if we've added crash reporting by the
// time you're reading this.)
//
// Fails/stops debug builds.
//
// TODO: Allow a format string and args for the message.
OSStatus LogUnexpectedExceptions(const char* __nullable fileName,
int lineNumber,
const char* callerName,
const char* __nullable message,
const std::function<void(void)>& function);
}
#endif /* defined(__cplusplus) */
#pragma clang assume_nonnull end
#endif /* SharedSource__EQM_Utils */

View File

@ -1,441 +0,0 @@
//
// EQM_VolumeControl.cpp
// EQMDriver
//
// Portions copyright (C) 2013 Apple Inc. All Rights Reserved.
//
// Self Include
#include "EQM_VolumeControl.h"
// Local Includes
#include "EQM_PlugIn.h"
// PublicUtility Includes
#include "CAException.h"
#include "CADebugMacros.h"
#include "CADispatchQueue.h"
#include "EQM_Utils.h"
// STL Includes
#include <algorithm>
// System Includes
#include <CoreAudio/AudioHardwareBase.h>
#include <Accelerate/Accelerate.h>
#pragma clang assume_nonnull begin
#pragma mark Construction/Destruction
EQM_VolumeControl::EQM_VolumeControl(AudioObjectID inObjectID,
AudioObjectID inOwnerObjectID,
AudioObjectPropertyScope inScope,
AudioObjectPropertyElement inElement)
:
EQM_Control(inObjectID,
kAudioVolumeControlClassID,
kAudioLevelControlClassID,
inOwnerObjectID,
inScope,
inElement),
mMutex("Volume Control"),
mVolumeRaw(kDefaultMinRawVolume),
mAmplitudeGain(0.0f),
mMinVolumeRaw(kDefaultMinRawVolume),
mMaxVolumeRaw(kDefaultMaxRawVolume),
mMinVolumeDb(kDefaultMinDbVolume),
mMaxVolumeDb(kDefaultMaxDbVolume),
mWillApplyVolumeToAudio(false)
{
// Setup the volume curve with the one range
mVolumeCurve.AddRange(mMinVolumeRaw, mMaxVolumeRaw, mMinVolumeDb, mMaxVolumeDb);
}
#pragma mark Property Operations
bool EQM_VolumeControl::HasProperty(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const
{
CheckObjectID(inObjectID);
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioLevelControlPropertyScalarValue:
case kAudioLevelControlPropertyDecibelValue:
case kAudioLevelControlPropertyDecibelRange:
case kAudioLevelControlPropertyConvertScalarToDecibels:
case kAudioLevelControlPropertyConvertDecibelsToScalar:
theAnswer = true;
break;
default:
theAnswer = EQM_Control::HasProperty(inObjectID, inClientPID, inAddress);
break;
};
return theAnswer;
}
bool EQM_VolumeControl::IsPropertySettable(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const
{
CheckObjectID(inObjectID);
bool theAnswer = false;
switch(inAddress.mSelector)
{
case kAudioLevelControlPropertyDecibelRange:
case kAudioLevelControlPropertyConvertScalarToDecibels:
case kAudioLevelControlPropertyConvertDecibelsToScalar:
theAnswer = false;
break;
case kAudioLevelControlPropertyScalarValue:
case kAudioLevelControlPropertyDecibelValue:
theAnswer = true;
break;
default:
theAnswer = EQM_Control::IsPropertySettable(inObjectID, inClientPID, inAddress);
break;
};
return theAnswer;
}
UInt32 EQM_VolumeControl::GetPropertyDataSize(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData) const
{
CheckObjectID(inObjectID);
UInt32 theAnswer = 0;
switch(inAddress.mSelector)
{
case kAudioLevelControlPropertyScalarValue:
theAnswer = sizeof(Float32);
break;
case kAudioLevelControlPropertyDecibelValue:
theAnswer = sizeof(Float32);
break;
case kAudioLevelControlPropertyDecibelRange:
theAnswer = sizeof(AudioValueRange);
break;
case kAudioLevelControlPropertyConvertScalarToDecibels:
theAnswer = sizeof(Float32);
break;
case kAudioLevelControlPropertyConvertDecibelsToScalar:
theAnswer = sizeof(Float32);
break;
default:
theAnswer = EQM_Control::GetPropertyDataSize(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData);
break;
};
return theAnswer;
}
void EQM_VolumeControl::GetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData,
UInt32 inDataSize,
UInt32& outDataSize,
void* outData) const
{
CheckObjectID(inObjectID);
switch(inAddress.mSelector)
{
case kAudioLevelControlPropertyScalarValue:
// This returns the value of the control in the normalized range of 0 to 1.
{
ThrowIf(inDataSize < sizeof(Float32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_VolumeControl::GetPropertyData: not enough space for the return value "
"of kAudioLevelControlPropertyScalarValue for the volume control");
CAMutex::Locker theLocker(mMutex);
*reinterpret_cast<Float32*>(outData) = mVolumeCurve.ConvertRawToScalar(mVolumeRaw);
outDataSize = sizeof(Float32);
}
break;
case kAudioLevelControlPropertyDecibelValue:
// This returns the dB value of the control.
{
ThrowIf(inDataSize < sizeof(Float32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_VolumeControl::GetPropertyData: not enough space for the return value "
"of kAudioLevelControlPropertyDecibelValue for the volume control");
CAMutex::Locker theLocker(mMutex);
*reinterpret_cast<Float32*>(outData) = mVolumeCurve.ConvertRawToDB(mVolumeRaw);
outDataSize = sizeof(Float32);
}
break;
case kAudioLevelControlPropertyDecibelRange:
// This returns the dB range of the control.
ThrowIf(inDataSize < sizeof(AudioValueRange),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_VolumeControl::GetPropertyData: not enough space for the return value of "
"kAudioLevelControlPropertyDecibelRange for the volume control");
reinterpret_cast<AudioValueRange*>(outData)->mMinimum = mVolumeCurve.GetMinimumDB();
reinterpret_cast<AudioValueRange*>(outData)->mMaximum = mVolumeCurve.GetMaximumDB();
outDataSize = sizeof(AudioValueRange);
break;
case kAudioLevelControlPropertyConvertScalarToDecibels:
// This takes the scalar value in outData and converts it to dB.
{
ThrowIf(inDataSize < sizeof(Float32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_VolumeControl::GetPropertyData: not enough space for the return value "
"of kAudioLevelControlPropertyConvertScalarToDecibels for the volume "
"control");
// clamp the value to be between 0 and 1
Float32 theVolumeValue = *reinterpret_cast<Float32*>(outData);
theVolumeValue = std::min(1.0f, std::max(0.0f, theVolumeValue));
// do the conversion
*reinterpret_cast<Float32*>(outData) =
mVolumeCurve.ConvertScalarToDB(theVolumeValue);
// report how much we wrote
outDataSize = sizeof(Float32);
}
break;
case kAudioLevelControlPropertyConvertDecibelsToScalar:
// This takes the dB value in outData and converts it to scalar.
{
ThrowIf(inDataSize < sizeof(Float32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_VolumeControl::GetPropertyData: not enough space for the return value "
"of kAudioLevelControlPropertyConvertDecibelsToScalar for the volume "
"control");
// clamp the value to be between mMinVolumeDb and mMaxVolumeDb
Float32 theVolumeValue = *reinterpret_cast<Float32*>(outData);
theVolumeValue = std::min(mMaxVolumeDb, std::max(mMinVolumeDb, theVolumeValue));
// do the conversion
*reinterpret_cast<Float32*>(outData) =
mVolumeCurve.ConvertDBToScalar(theVolumeValue);
// report how much we wrote
outDataSize = sizeof(Float32);
}
break;
default:
EQM_Control::GetPropertyData(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData,
inDataSize,
outDataSize,
outData);
break;
};
}
void EQM_VolumeControl::SetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData,
UInt32 inDataSize,
const void* inData)
{
CheckObjectID(inObjectID);
switch(inAddress.mSelector)
{
case kAudioLevelControlPropertyScalarValue:
{
ThrowIf(inDataSize != sizeof(Float32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_VolumeControl::SetPropertyData: wrong size for the data for "
"kAudioLevelControlPropertyScalarValue");
// Read the new scalar volume.
Float32 theNewVolumeScalar = *reinterpret_cast<const Float32*>(inData);
SetVolumeScalar(theNewVolumeScalar);
}
break;
case kAudioLevelControlPropertyDecibelValue:
{
ThrowIf(inDataSize != sizeof(Float32),
CAException(kAudioHardwareBadPropertySizeError),
"EQM_VolumeControl::SetPropertyData: wrong size for the data for "
"kAudioLevelControlPropertyDecibelValue");
// Read the new volume in dB.
Float32 theNewVolumeDb = *reinterpret_cast<const Float32*>(inData);
SetVolumeDb(theNewVolumeDb);
}
break;
default:
EQM_Control::SetPropertyData(inObjectID,
inClientPID,
inAddress,
inQualifierDataSize,
inQualifierData,
inDataSize,
inData);
break;
};
}
#pragma mark Accessors
void EQM_VolumeControl::SetVolumeScalar(Float32 inNewVolumeScalar)
{
// For the scalar volume, we clamp the new value to [0, 1]. Note that if this value changes, it
// implies that the dB value changes too.
inNewVolumeScalar = std::min(1.0f, std::max(0.0f, inNewVolumeScalar));
// Store the new volume.
SInt32 theNewVolumeRaw = mVolumeCurve.ConvertScalarToRaw(inNewVolumeScalar);
SetVolumeRaw(theNewVolumeRaw);
}
void EQM_VolumeControl::SetVolumeDb(Float32 inNewVolumeDb)
{
// For the dB value, we first convert it to a raw value since that is how the value is tracked.
// Note that if this value changes, it implies that the scalar value changes as well.
// Clamp the new volume.
inNewVolumeDb = std::min(mMaxVolumeDb, std::max(mMinVolumeDb, inNewVolumeDb));
// Store the new volume.
SInt32 theNewVolumeRaw = mVolumeCurve.ConvertDBToRaw(inNewVolumeDb);
SetVolumeRaw(theNewVolumeRaw);
}
void EQM_VolumeControl::SetWillApplyVolumeToAudio(bool inWillApplyVolumeToAudio)
{
mWillApplyVolumeToAudio = inWillApplyVolumeToAudio;
}
#pragma mark IO Operations
bool EQM_VolumeControl::WillApplyVolumeToAudioRT() const
{
return mWillApplyVolumeToAudio;
}
void EQM_VolumeControl::ApplyVolumeToAudioRT(Float32* ioBuffer, UInt32 inBufferFrameSize) const
{
ThrowIf(!mWillApplyVolumeToAudio,
CAException(kAudioHardwareIllegalOperationError),
"EQM_VolumeControl::ApplyVolumeToAudioRT: This control doesn't process audio data");
// Don't bother if the change is very unlikely to be perceptible.
if((mAmplitudeGain < 0.99f) || (mAmplitudeGain > 1.01f))
{
// Apply the amount of gain/loss for the current volume to the audio signal by multiplying
// each sample. This call to vDSP_vsmul is equivalent to
//
// for(UInt32 i = 0; i < inBufferFrameSize * 2; i++)
// {
// ioBuffer[i] *= mAmplitudeGain;
// }
//
// but a bit faster on processors with newer SIMD instructions. However, it shouldn't take
// more than a few microseconds either way. (Unless some of the samples were subnormal
// numbers for some reason.)
//
// It would be a tiny bit faster still to not do this in-place, i.e. use separate input and
// output buffers, but then we'd have to copy the data into the output buffer when the
// volume is at 1.0. With our current use of this class, most people will leave the volume
// at 1.0, so it wouldn't be worth it.
vDSP_vsmul(ioBuffer, 1, &mAmplitudeGain, ioBuffer, 1, inBufferFrameSize * 2);
}
}
#pragma mark Implementation
void EQM_VolumeControl::SetVolumeRaw(SInt32 inNewVolumeRaw)
{
CAMutex::Locker theLocker(mMutex);
// Make sure the new raw value is in the proper range.
inNewVolumeRaw = std::min(std::max(mMinVolumeRaw, inNewVolumeRaw), mMaxVolumeRaw);
// Store the new volume.
if(mVolumeRaw != inNewVolumeRaw)
{
mVolumeRaw = inNewVolumeRaw;
// CAVolumeCurve deals with volumes in three different scales: scalar, dB and raw. Raw
// volumes are the number of steps along the dB curve, so dB and raw volumes are linearly
// related.
//
// macOS uses the scalar volume to set the position of its volume sliders for the
// device. We have to set the scalar volume to the position of our volume slider for a
// device (more specifically, a linear mapping of it onto [0,1]) or macOS's volume sliders
// or it will work differently to our own.
//
// When we set a new slider position as the device's scalar volume, we convert it to raw
// with CAVolumeCurve::ConvertScalarToRaw, which will "undo the curve". However, we haven't
// applied the curve at that point.
//
// So, to actually apply the curve, we use CAVolumeCurve::ConvertRawToScalar to get the
// linear slider position back, map it onto the range of raw volumes and use
// CAVolumeCurve::ConvertRawToScalar again to apply the curve.
//
// It might be that we should be using CAVolumeCurve with transfer functions x^n where
// 0 < n < 1, but a lot more of the transfer functions it supports have n >= 1, including
// the default one. So I'm a bit confused.
//
// TODO: I think this means the dB volume we report will be wrong. It also makes the code
// pretty confusing.
Float32 theSliderPosition = mVolumeCurve.ConvertRawToScalar(mVolumeRaw);
// TODO: This assumes the control should never boost the signal. (So, technically, it never
// actually applies gain, only loss.)
SInt32 theRawRange = mMaxVolumeRaw - mMinVolumeRaw;
SInt32 theSliderPositionInRawSteps = static_cast<SInt32>(theSliderPosition * theRawRange);
theSliderPositionInRawSteps += mMinVolumeRaw;
mAmplitudeGain = mVolumeCurve.ConvertRawToScalar(theSliderPositionInRawSteps);
EQMAssert((mAmplitudeGain >= 0.0f) && (mAmplitudeGain <= 1.0f), "Gain not in [0,1]");
// Send notifications.
CADispatchQueue::GetGlobalSerialQueue().Dispatch(false, ^{
AudioObjectPropertyAddress theChangedProperties[2];
theChangedProperties[0] = { kAudioLevelControlPropertyScalarValue, mScope, mElement };
theChangedProperties[1] = { kAudioLevelControlPropertyDecibelValue, mScope, mElement };
EQM_PlugIn::Host_PropertiesChanged(GetObjectID(), 2, theChangedProperties);
});
}
}
#pragma clang assume_nonnull end

View File

@ -1,151 +0,0 @@
//
// EQM_VolumeControl.h
// EQMDriver
//
//
//
#ifndef EQMDriver__EQM_VolumeControl
#define EQMDriver__EQM_VolumeControl
// Superclass Includes
#include "EQM_Control.h"
// PublicUtility Includes
#include "CAVolumeCurve.h"
#include "CAMutex.h"
#pragma clang assume_nonnull begin
class EQM_VolumeControl
:
public EQM_Control
{
#pragma mark Construction/Destruction
public:
EQM_VolumeControl(AudioObjectID inObjectID,
AudioObjectID inOwnerObjectID,
AudioObjectPropertyScope inScope = kAudioObjectPropertyScopeOutput,
AudioObjectPropertyElement inElement =
kAudioObjectPropertyElementMaster);
#pragma mark Property Operations
virtual bool HasProperty(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const;
virtual bool IsPropertySettable(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress) const;
virtual UInt32 GetPropertyDataSize(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData) const;
virtual void GetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData,
UInt32 inDataSize,
UInt32& outDataSize,
void* outData) const;
virtual void SetPropertyData(AudioObjectID inObjectID,
pid_t inClientPID,
const AudioObjectPropertyAddress& inAddress,
UInt32 inQualifierDataSize,
const void* inQualifierData,
UInt32 inDataSize,
const void* inData);
#pragma mark Accessors
/*!
@return The curve used by this control to convert volume values from scalar into signal gain
and/or decibels. A continuous 2D function.
*/
CAVolumeCurve& GetVolumeCurve() { return mVolumeCurve; }
/*!
Set the volume of this control to a given position along its volume curve. (See
GetVolumeCurve.)
Passing 1.0 sets the volume to the maximum and 0.0 sets it to the minimum. The gain/loss the
control applies (and/or reports to apply) to the audio it controls is given by the y-position
of the curve at the x-position inNewVolumeScalar.
In general, since the control's volume curve will be applied to the given value, it should be
linearly related to a volume input by the user.
@param inNewVolumeScalar The volume to set. Will be clamped to [0.0, 1.0].
*/
void SetVolumeScalar(Float32 inNewVolumeScalar);
/*!
Set the volume of this control in decibels.
@param inNewVolumeDb The volume to set. Will be clamped to the minimum/maximum dB volumes of
the control. See GetVolumeCurve.
*/
void SetVolumeDb(Float32 inNewVolumeDb);
/*!
Set this volume control to apply its volume to audio data, which allows clients to call
ApplyVolumeToAudioRT. When this is set true, WillApplyVolumeToAudioRT will return true. Set to
false initially.
*/
void SetWillApplyVolumeToAudio(bool inWillApplyVolumeToAudio);
#pragma mark IO Operations
/*!
@return True if clients should use ApplyVolumeToAudioRT to apply this volume control's volume
to their audio data while doing IO.
*/
bool WillApplyVolumeToAudioRT() const;
/*!
Apply this volume control's volume to the samples in ioBuffer. That is, increase/decrease the
volumes of the samples by the current volume of this control.
@param ioBuffer The audio sample buffer to process.
@param inBufferFrameSize The number of sample frames in ioBuffer. The audio is assumed to be in
stereo, i.e. two samples per frame. (Though, hopefully we'll support
more at some point.)
@throws CAException If SetWillApplyVolumeToAudio hasn't been used to set this control to apply
its volume to audio data.
*/
void ApplyVolumeToAudioRT(Float32* ioBuffer, UInt32 inBufferFrameSize) const;
#pragma mark Implementation
protected:
void SetVolumeRaw(SInt32 inNewVolumeRaw);
private:
const SInt32 kDefaultMinRawVolume = 0;
const SInt32 kDefaultMaxRawVolume = 96;
const Float32 kDefaultMinDbVolume = -96.0f;
const Float32 kDefaultMaxDbVolume = 0.0f;
CAMutex mMutex;
SInt32 mVolumeRaw;
SInt32 mMinVolumeRaw;
SInt32 mMaxVolumeRaw;
Float32 mMinVolumeDb;
Float32 mMaxVolumeDb;
CAVolumeCurve mVolumeCurve;
// The gain (or loss) to apply to an audio signal to increase/decrease its volume by the current
// volume of this control.
Float32 mAmplitudeGain;
bool mWillApplyVolumeToAudio;
};
#pragma clang assume_nonnull end
#endif /* EQMDriver__EQM_VolumeControl */

View File

@ -1,29 +0,0 @@
//
// EQM_WrappedAudioEngine.cpp
// EQMDriver
//
//
// Self Include
#include "EQM_WrappedAudioEngine.h"
// TODO: Register to be notified when the IO Registry values for these change so we can cache them
UInt64 EQM_WrappedAudioEngine::GetSampleRate() const
{
return 0;
}
kern_return_t EQM_WrappedAudioEngine::SetSampleRate(Float64 inNewSampleRate)
{
#pragma unused (inNewSampleRate)
return 0;
}
UInt32 EQM_WrappedAudioEngine::GetSampleBufferFrameSize() const
{
return 0;
}

View File

@ -1,32 +0,0 @@
//
// EQM_WrappedAudioEngine.h
// EQMDriver
//
//
// The plan for this is to allow devices with IOAudioEngine drivers to be used as the output device
// directly from EQMDriver, rather than going through EQMApp. That way we get roughly the same CPU
// usage and latency as normal, and don't need to worry about pausing EQMApp's IO when no clients
// are doing IO. It also lets EQMDriver mostly continue working without EQMApp running. I've written
// a very experimental version that mostly works but the code needs a lot of clean up so I haven't
// added it to this project yet.
//
#ifndef __EQMDriver__EQM_WrappedAudioEngine__
#define __EQMDriver__EQM_WrappedAudioEngine__
#include <CoreAudio/CoreAudioTypes.h>
#include <mach/kern_return.h>
class EQM_WrappedAudioEngine
{
public:
UInt64 GetSampleRate() const;
kern_return_t SetSampleRate(Float64 inNewSampleRate);
UInt32 GetSampleBufferFrameSize() const;
};
#endif /* __EQMDriver__EQM_WrappedAudioEngine__ */

4058
native/driver/Source/eqMac.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,277 @@
//
// eqMac.h
// eqMac Driver
//
// Created by Nodeful on 09/07/2021.
// Copyright © 2021 Apple. All rights reserved.
//
#ifndef eqMac_h
#define eqMac_h
#endif /* eqMac_h */
#include <CoreAudio/AudioServerPlugIn.h>
#include <dispatch/dispatch.h>
#include <mach/mach_time.h>
#include <pthread.h>
#include <stdint.h>
#include <sys/syslog.h>
//==================================================================================================
#pragma mark -
#pragma mark Macros
//==================================================================================================
#if TARGET_RT_BIG_ENDIAN
#define FourCCToCString(the4CC) { ((char*)&the4CC)[0], ((char*)&the4CC)[1], ((char*)&the4CC)[2], ((char*)&the4CC)[3], 0 }
#else
#define FourCCToCString(the4CC) { ((char*)&the4CC)[3], ((char*)&the4CC)[2], ((char*)&the4CC)[1], ((char*)&the4CC)[0], 0 }
#endif
#if DEBUG
#define DebugMsg(inFormat, ...) printf(inFormat "\n", ## __VA_ARGS__)
#define FailIf(inCondition, inHandler, inMessage) \
if (inCondition) { \
DebugMsg(inMessage); \
goto inHandler; \
}
#define FailWithAction(inCondition, inAction, inHandler, inMessage) \
if (inCondition) { \
DebugMsg(inMessage); \
{ inAction; } \
goto inHandler; \
}
#else
#define DebugMsg(inFormat, ...)
#define FailIf(inCondition, inHandler, inMessage) \
if (inCondition) { \
goto inHandler; \
}
#define FailWithAction(inCondition, inAction, inHandler, inMessage) \
if (inCondition) { \
{ inAction; } \
goto inHandler; \
}
#endif
//==================================================================================================
#pragma mark -
#pragma mark eqMac State
//==================================================================================================
// The purpose of the eqMac sample is to provide a bare bones implementations to
// illustrate the minimal set of things a driver has to do. The sample driver has the following
// qualities:
// - a plug-in
// - custom property with the selector kPlugIn_CustomPropertyID = 'PCst'
// - a box
// - a device
// - supports 44100 and 48000 sample rates
// - provides a rate scalar of 1.0 via hard coding
// - a single input stream
// - supports 2 channels of 32 bit float LPCM samples
// - always produces zeros
// - a single output stream
// - supports 2 channels of 32 bit float LPCM samples
// - data written to it is ignored
// - controls
// - master input volume
// - master output volume
// - master input mute
// - master output mute
// - master input data source
// - master output data source
// - master play-through data destination
// - all are for illustration purposes only and do not actually manipulate data
// Declare the internal object ID numbers for all the objects this driver implements. Note that
// this driver has a fixed set of objects that never grows or shrinks. If this were not the case,
// the driver would need to have a means to dynamically allocate these IDs. It's important to
// realize that a lot of the structure of this driver is vastly simpler when the IDs are all
// known a priori. Comments in the code will try to identify some of these simplifications and
// point out what a more complicated driver will need to do.
enum {
kObjectID_PlugIn = kAudioObjectPlugInObject,
kObjectID_Box = 2,
kObjectID_Device = 3,
kObjectID_Stream_Input = 4,
kObjectID_Volume_Input_Master = 5,
kObjectID_Mute_Input_Master = 6,
kObjectID_DataSource_Input_Master = 7,
kObjectID_Stream_Output = 8,
kObjectID_Volume_Output_Master = 9,
kObjectID_Mute_Output_Master = 10,
kObjectID_DataSource_Output_Master = 11,
// kObjectID_DataDestination_PlayThru_Master = 12
};
// Custom Properties
enum {
kAudioDeviceCustomPropertyLatency = 'cltc',
kAudioDeviceCustomPropertySafetyOffset = 'csfo',
kAudioDeviceCustomPropertyShown = 'shwn',
kAudioDeviceCustomPropertyVersion = 'vrsn'
};
// Declare the stuff that tracks the state of the plug-in, the device and its sub-objects.
// Note that we use global variables here because this driver only ever has a single device. If
// multiple devices were supported, this state would need to be encapsulated in one or more structs
// so that each object's state can be tracked individually.
// Note also that we share a single mutex across all objects to be thread safe for the same reason.
#define kChannelCount 2
#define kBitsPerChannel 32
#define kBytesPerChannel (kBitsPerChannel / 8)
#define kBytesPerFrame (kChannelCount * kBytesPerChannel)
#define kDevice_Name "eqMac"
#define kDevice_Manufacturer "Bitgapp Ltd"
static Float32* buffer;
#define kBufferSize (65536 * kChannelCount)
#define kPlugIn_BundleID "com.bitgapp.eqmac.driver"
static pthread_mutex_t gPlugIn_StateMutex = PTHREAD_MUTEX_INITIALIZER;
static UInt32 gPlugIn_RefCount = 0;
static AudioServerPlugInHostRef gPlugIn_Host = NULL;
static const AudioObjectPropertySelector kPlugIn_CustomPropertyID = 'PCst';
#define kBox_UID "eqMacBox_UID"
static CFStringRef gBox_Name = NULL;
static Boolean gBox_Acquired = true;
#define kDevice_UID "EQMDevice"
#define kDevice_ModelUID "EQMDeviceModelUID"
static pthread_mutex_t gDevice_IOMutex = PTHREAD_MUTEX_INITIALIZER;
static Float64 gDevice_SampleRate = 44100.0;
static UInt64 gDevice_IOIsRunning = 0;
static const UInt32 kDevice_RingBufferSize = 16384;
static Float64 gDevice_HostTicksPerFrame = 0.0;
static UInt64 gDevice_NumberTimeStamps = 0;
static Float64 gDevice_AnchorSampleTime = 0.0;
static UInt64 gDevice_AnchorHostTime = 0;
static bool gStream_Input_IsActive = true;
static bool gStream_Output_IsActive = true;
static const Float32 kVolume_MinDB = -96.0;
static const Float32 kVolume_MaxDB = 0.0;
static Float32 gVolume_Input_Master_Value = 1.0;
static Float32 gVolume_Output_Master_Value = 1.0;
static bool gMute_Input_Master_Value = false;
static bool gMute_Output_Master_Value = false;
static const UInt32 kDataSource_NumberItems = 1;
#define kDataSource_ItemNamePattern kDevice_Name
static UInt32 gDataSource_Input_Master_Value = 0;
static UInt32 gDataSource_Output_Master_Value = 0;
//static UInt32 gDataDestination_PlayThru_Master_Value = 0;
static UInt32 mShown = 0;
static UInt32 mSafetyOffset = 0;
static UInt32 mLatency = 0;
#
//==================================================================================================
#pragma mark -
#pragma mark AudioServerPlugInDriverInterface Implementation
//==================================================================================================
#pragma mark Prototypes
// Entry points for the COM methods
void* eqMac_Create (CFAllocatorRef inAllocator, CFUUIDRef inRequestedTypeUUID);
static HRESULT eqMac_QueryInterface (void* inDriver, REFIID inUUID, LPVOID* outInterface);
static ULONG eqMac_AddRef (void* inDriver);
static ULONG eqMac_Release (void* inDriver);
static OSStatus eqMac_Initialize (AudioServerPlugInDriverRef inDriver, AudioServerPlugInHostRef inHost);
static OSStatus eqMac_CreateDevice (AudioServerPlugInDriverRef inDriver, CFDictionaryRef inDescription, const AudioServerPlugInClientInfo* inClientInfo, AudioObjectID* outDeviceObjectID);
static OSStatus eqMac_DestroyDevice (AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID);
static OSStatus eqMac_AddDeviceClient (AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, const AudioServerPlugInClientInfo* inClientInfo);
static OSStatus eqMac_RemoveDeviceClient (AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, const AudioServerPlugInClientInfo* inClientInfo);
static OSStatus eqMac_PerformDeviceConfigurationChange (AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt64 inChangeAction, void* inChangeInfo);
static OSStatus eqMac_AbortDeviceConfigurationChange (AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt64 inChangeAction, void* inChangeInfo);
static Boolean eqMac_HasProperty (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus eqMac_IsPropertySettable (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus eqMac_GetPropertyDataSize (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus eqMac_GetPropertyData (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus eqMac_SetPropertyData (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData);
static OSStatus eqMac_StartIO (AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID);
static OSStatus eqMac_StopIO (AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID);
static OSStatus eqMac_GetZeroTimeStamp (AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, Float64* outSampleTime, UInt64* outHostTime, UInt64* outSeed);
static OSStatus eqMac_WillDoIOOperation (AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, UInt32 inOperationID, Boolean* outWillDo, Boolean* outWillDoInPlace);
static OSStatus eqMac_BeginIOOperation (AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo* inIOCycleInfo);
static OSStatus eqMac_DoIOOperation (AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, AudioObjectID inStreamObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo* inIOCycleInfo, void* ioMainBuffer, void* ioSecondaryBuffer);
static OSStatus eqMac_EndIOOperation (AudioServerPlugInDriverRef inDriver, AudioObjectID inDeviceObjectID, UInt32 inClientID, UInt32 inOperationID, UInt32 inIOBufferFrameSize, const AudioServerPlugInIOCycleInfo* inIOCycleInfo);
// Implementation
static Boolean eqMac_HasPlugInProperty (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus eqMac_IsPlugInPropertySettable (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus eqMac_GetPlugInPropertyDataSize (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus eqMac_GetPlugInPropertyData (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus eqMac_SetPlugInPropertyData (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2]);
static Boolean eqMac_HasBoxProperty (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus eqMac_IsBoxPropertySettable (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus eqMac_GetBoxPropertyDataSize (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus eqMac_GetBoxPropertyData (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus eqMac_SetBoxPropertyData (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2]);
static Boolean eqMac_HasDeviceProperty (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus eqMac_IsDevicePropertySettable (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus eqMac_GetDevicePropertyDataSize (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus eqMac_GetDevicePropertyData (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus eqMac_SetDevicePropertyData (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2]);
static Boolean eqMac_HasStreamProperty (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus eqMac_IsStreamPropertySettable (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus eqMac_GetStreamPropertyDataSize (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus eqMac_GetStreamPropertyData (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus eqMac_SetStreamPropertyData (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2]);
static Boolean eqMac_HasControlProperty (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress);
static OSStatus eqMac_IsControlPropertySettable (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable);
static OSStatus eqMac_GetControlPropertyDataSize (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize);
static OSStatus eqMac_GetControlPropertyData (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32* outDataSize, void* outData);
static OSStatus eqMac_SetControlPropertyData (AudioServerPlugInDriverRef inDriver, AudioObjectID inObjectID, pid_t inClientProcessID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, UInt32* outNumberPropertiesChanged, AudioObjectPropertyAddress outChangedAddresses[2]);
#pragma mark The Interface
static AudioServerPlugInDriverInterface gAudioServerPlugInDriverInterface = {
NULL,
eqMac_QueryInterface,
eqMac_AddRef,
eqMac_Release,
eqMac_Initialize,
eqMac_CreateDevice,
eqMac_DestroyDevice,
eqMac_AddDeviceClient,
eqMac_RemoveDeviceClient,
eqMac_PerformDeviceConfigurationChange,
eqMac_AbortDeviceConfigurationChange,
eqMac_HasProperty,
eqMac_IsPropertySettable,
eqMac_GetPropertyDataSize,
eqMac_GetPropertyData,
eqMac_SetPropertyData,
eqMac_StartIO,
eqMac_StopIO,
eqMac_GetZeroTimeStamp,
eqMac_WillDoIOOperation,
eqMac_BeginIOOperation,
eqMac_DoIOOperation,
eqMac_EndIOOperation
};
static AudioServerPlugInDriverInterface* gAudioServerPlugInDriverInterfacePtr = &gAudioServerPlugInDriverInterface;
static AudioServerPlugInDriverRef gAudioServerPlugInDriverRef = &gAudioServerPlugInDriverInterfacePtr;

View File

@ -23,7 +23,7 @@
<key>CFPlugInFactories</key>
<dict>
<key>7080ba34-76cc-40b2-b2b3-819d28460e7e</key>
<string>EQM_Create</string>
<string>eqMac_Create</string>
</dict>
<key>CFPlugInTypes</key>
<dict>