rpld-0.1.9/ 0000755 0001750 0001750 00000000000 12266603012 010602 5 ustar phi phi rpld-0.1.9/codec-helper/ 0000755 0001750 0001750 00000000000 12266602740 013143 5 ustar phi phi rpld-0.1.9/codec-helper/rpld-codec-helper-gstreamer 0000755 0001750 0001750 00000001765 11501404247 020353 0 ustar phi phi #!/bin/sh
# Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
#
# This file is part of RoarAudio PlayList Daemon,
# a playlist management daemon for RoarAudio.
# See README for details.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3
# as published by the Free Software Foundation.
#
# RoarAudio 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 software; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
{
gst-launch fdsrc fd=0 ! decodebin ! audioconvert ! capsfilter caps="audio/x-raw-int,width=16,channels=2,rate=44100" ! fdsink fd=3 > /dev/null 2> /dev/null
} 3>&1
#ll
rpld-0.1.9/codec-helper/rpld-codec-helper.1 0000644 0001750 0001750 00000002047 11504134235 016512 0 ustar phi phi .\" rpld-codec-helper.1:
.TH "rpld-codec-helper" "1" "July 2010" "RoarAudio PlayList Daemon" "System User's Manual: rpld"
.SH NAME
rpld-codec-helper \- Codec helper script for RoarAudio PlayList Daemon
.SH SYNOPSIS
rpld-codec-helper
.SH DESCRIPTION
The RoarAudio PlayList Daemon is a daemon which manages playlists and can play
files or streams from those lists using a RoarAudio Sound Server.
This program is used internally by rpld to support codecs which are not supported by
the sound server. Those formats are normally non-free ones. If you use recommended
formats like Ogg Vorbis this seldom will be used.
This program should never be called directly (by user).
Functionality of this is not part of rpld to keep sources clean and to avoid depends
on code with doubtful legal status.
.SH "OPTIONS"
This program does not have any options.
.SH "SEE ALSO"
\fBrpld\fR(1),
\fBRoarAudio\fR(7).
.SH "HISTORY"
Support for codec helper script was added with release 0.1beta0 and 0.1rc4 will be
the first release shipping a codec helper script.
.\" ll
rpld-0.1.9/COPYING.gplv3 0000644 0001750 0001750 00000104513 11274114601 012672 0 ustar phi phi GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
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.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 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 .
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:
Copyright (C)
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
.
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
.
rpld-0.1.9/ChangeLog 0000644 0001750 0001750 00000017161 12266601524 012370 0 ustar phi phi v. 0.1.9 - Sat Jan 18 2014 23:41 CET
* Print warning when --load-playlist is used (Closes: #361)
* Did some hardening, also fixed a bit in AUTOQUEUE support.
* Avoid segfault on wrong SEARCHPLE syntax (Closes: #364)
* Corrected rpld_ple_copy() to also copy filenames (Closes: #365)
* Updated copyright statements.
v. 0.1.8 - Sat Nov 23 2013 11:45 CET
* Added AUTOQUEUE command.
* Updated copyright statements.
* Added support to handle multiple filenames per plent (Closes: #319)
* Added FALLBACK pointer.
* Cleanup.
* Fixed playlist leak.
* Improved LISTCLIENTS command.
* Corrected parser errors for simple protocol (Closes: #357)
v. 0.1.7 - Mon Dec 10 2012 16:00 CET
* Updated win32 port.
v. 0.1.6 - Wed Oct 18 2012 25:51 CEST
* Init plugins before we start playback.
This fixes a bug with the playback-logging plugin.
* Allow to use NEXT command with autoqueue.
* Fixed double free caused by deleting to copies of
a PLE with extra meta data.
* Moved to new build system (See: #325)
* Done win32 port updates.
* Cleanup of HAVE_LIBROAR_UUID.
* Changed default socket location to ~/.rpld.
* Improved RePlayGain support.
v. 0.1.5 - Mon Sep 17 2012 21:23 CEST
* Reenabled --bl-codec.
* Updated plugin host interface (version changed).
* Also try to read from codec-helper if input from the
data source is available. Should avoid stalled
codec-helpers.
* Applied "01-hyphen-used-as-minus-sign.diff" patch to manpage from Debian.
* Added a plugin to write a log file for queues (Closes: #298)
* Added support to export a playlist via command line parameters.
* Replaced --load-playlist with --playlist-import.
* Disabled starting of rpld in debian-like init script by default.
This is to better allow per-user sessions as well as rpld instances
running only with servers of type +fork.
* Added support for server meta data like provided by the RoarAudio
Protocol. Also added command SERVERINFO. (Closes: #312)
* Fixed PAUSE command on streams using codec-helper (Closes: #316)
* Allow backend objects not connected to the server.
This is used to avoid queues disappearing on restore in case
the server is unreachable (Closes: #317)
* Correctly handle EOF while in IMPORT (Closes: #320)
* Work around win32's %lli-bug (See: #271)
* Ignore all lines in simple protocol starting with hash ('#').
* Added support to report version, buildstamp as well as
distribution-version-string.
* Added SEARCHPLE command.
v. 0.1.4 - Tue Aug 21 2012 13:09 CEST
* Add support to hold more meta data (Closes: #202)
* Fixed an memory leak in IMPORT and EXPORT commands when using STDIN/STDOUT.
* Added support to read and write URAS playlists (Closes: #299)
* Added script to manipulate stores offline (Closes: #59)
* Updated plugin host interface (version changed) (Closes: #304)
* Changed --load-playlist with --restore back to expected behavior.
v. 0.1.3 - Thu Aug 09 2012 17:00 CEST
* Use UUID API of libroar and remove dependency on libuuid (Closes: #266)
* Delay adding queue to "Main Queue" until command lion switches are read
and server address is set. This allows --server to as expected again
(Closes: #259)
* Added support to not connect to a server at startup (Closes: #260)
* Free Main Queue and Main History early in case of loading "new" (>= 0.1rc7)
stores. This saves a few bytes of runtime memory.
* Prepared porting to the common protocol interface (See: #261)
* Do not try to install deprecated tools (Closes: #289)
* Enabled optimizer (-O2).
* Implemented Common Protocol Interface support (Closes: #261)
* Added watchdog (Closes: #292)
v. 0.1.2 - Tue Jul 10 2012 17:43 CEST
* Fixed a segfault in autoqueue.
* Added new command LISTCLIENTS (Closes: #227)
* Added new command IDENTIFY (Closes: #242)
* Removed the deprecated tools
rpld-{play,stop,prev,store,addplaylist,delplaylist} (Closes: #239)
v. 0.1.1 - Fri May 25 2012 20:43 CEST
* Corrected symlink generation for manpages.
* Updated debian init script.
v. 0.1.0 - Thu May 24 2012 21:33 CEST
* Improved error handling
* Added common options to tools (Closes: #237, See: #239)
* Added status command to debian init script (Closes: #204)
* Check argument list to be present (Closes: #241)
* Added SHOWQUEUE command.
* Added support to import xspf playlists (Closes: #65)
v. 0.1rc7 - Sun May 13 2012 21:28 CEST
* Fixed warnings on AMD64 (Closes: #203)
* Added support to set audio info of codec helper (Closes: #200)
* Added support for multiple queues (Closes: #210, #211, #198)
* Added const keywords to client_str2acclev() and client_str2proto()
(Closes: #216)
* Support reading old stores (Closes: #221)
* CURRENT, DEFAULT and STARTUP pointers are now per queue (Closes: #223)
* Make global variables more local.
* Reduced memory usage (by ~24% on test setup).
* Updated plugin system (export public header with plugin API).
v. 0.1rc6 - Sat Mar 17 2012 13:12 CET
* Ported to RoarAudio 1.0* (Closes: #182)
* Fixed some compiler warnings.
* Added support to load plugins.
* Added some more const keywords.
* Made some global variables more local.
* Re-ported to win32.
* Increased maximum number of playlists to 64.
v. 0.1rc5 - Fri Sep 30 2011 14:07 CEST
* Some fixes to smooth usage on win32.
* Corrected license headers.
* Support to load playlist via command lion.
* Support playback while import.
v. 0.1rc4 - Tue Dec 21 2010 15:57 CET
* Corrected test for libuuid and libslp
* Added codec-helper directory with common Codec Helpers
* Moved rpld-* tools from RoaringBox package to this one.
* Added support for random EIs and random pointers.
* Store and restore volume via normal store directory (Closes: #67)
* Added support (currently write only) for XSPF playlists (See: #65)
v. 0.1rc3 - Thu Nov 18 2010 15:42 CET
* Set ownership and rights on UNIX sockets on our own,
no need to be set by init script anymore (Closes: #69)
* Do not kill process if pidfile does not exist or is empty (Closes: #70)
* Handle server side volume changes correctly (Closes: #68)
* Added support for --close-fh and --client-fh (Closes: #71)
* Added support for --no-listen
* Done some manpage updates.
* Avoid non-deletable pid-file
* Fixed a lot compiler warnings (-Wextra stuff only)
* Fixed spaces in IMPORT and EXPORT commands bug (Closes: #79)
* Set debug message prefix correctly
v. 0.1rc2 - Tue Nov 09 2010 17:05 CET
* Fixed OpenSLP support (cased when libroar not supporing SLP)
* Added non-fatal version of --restore (Closes: #58)
* Corrected text in Debian init script (Closes: #57)
* Reject to run as root. Fixes root exploit trigged by
very stupid users (Closes: #63)
v. 0.1rc1 - Fri Oct 01 2010 21:08 CEST
* Added history playlist
* Updated mpd protocol support a lot
v. 0.1rc0 - Sat Jul 24 2010 23:04 CEST
* Added manpage
* Added UNAUTH command in simple protocol
* Changed all internals from sysio to VIO
v. 0.1beta1 - Mon May 03 2010 22:12 CEST
* support for auto locating files if no filename is given
based on Tantalos
* Added support for reading meta data from roard
* started MPD protocol emulation
* wrote control files for Debian
v. 0.1beta0 - Sun Jan 10 2010 23:42 CET
* Start of project
* Support for multiple playlists
* Import/Export for RPLD, VCLT, M3U, PLS, Plain
* Support for UNIX/IPv4/DECnet sockets
* Support for Store and Restore
* Support for codec helper
* Support files for Debian like systems
* configure and install make target
* Support restore of UUID from VCLT playlists
* Support for two pointers: current playlist pointer,
default playlist pointer
* Support to store pointers
* PIDFile support
* support to pause streams
* support for Artist/Performer to be diffrent
* support annoucement via OpenSLP
rpld-0.1.9/Makefile 0000644 0001750 0001750 00000006330 12031301747 012244 0 ustar phi phi TARGET=rpld
FF_OBJS=fformat.o ff_vclt.o ff_plain.o ff_m3u.o ff_rpld.o ff_pls.o ff_xspf.o ff_uras.o
PROTO_OBJS=proto_simple.o proto_simple_vio.o proto_mpd.o
OBJS=rpld.o playlist.o client.o network.o backend.o playback.o store.o autoqueue.o yield.o rpldslp.o pointer.o plugin.o serverinfo.o ${FF_OBJS} ${PROTO_OBJS}
MANPAGES_1 = rpld.1
HEADERS = rpldplugin.h rpldnotify.h
TOOLS_DIR = tools
TOOLS_MAN1_BASENAME_0 = rpld-tools
TOOLS_MAN1_BASENAME_1 = rpld-deprecated
TOOLS_MAN1_BASENAME_2 = rpld-storemgr
TOOLS_MAN1_0 = $(TOOLS_DIR)/$(TOOLS_MAN1_BASENAME_0).1
TOOLS_MAN1_1 = $(TOOLS_DIR)/$(TOOLS_MAN1_BASENAME_1).1
TOOLS_MAN1_2 = $(TOOLS_DIR)/$(TOOLS_MAN1_BASENAME_2).1
TOOLS = $(TOOLS_DIR)/rpld-import $(TOOLS_DIR)/rpld-next $(TOOLS_DIR)/rpld-queueple $(TOOLS_DIR)/rpld-setpointer $(TOOLS_DIR)/rpld-listq $(TOOLS_DIR)/rpld-ctl $(TOOLS_DIR)/rpld-listplaylists $(TOOLS_DIR)/rpld-showplaying $(TOOLS_DIR)/rpld-storemgr
include Makefile.conf
#DEFINES = -DDEBUG
DEFINES += -DROAR_DBG_PREFIX=\"roarplaylistd\"
CFLAGS += -Wall $(Wextra) -g $(OPTI_O) $(DEFINES) $(INCLUDE) $(INCPATH)
LDFLAGS += -Wall $(Wextra) -g $(OPTI_O) $(LDPATH)
NETLIBS += $(lib_wsock32) $(lib_ws2_32)
LIBS += $(lib_roar) $(lib_slp) $(lib_xml2) $(NETLIBS)
all: $(TARGET)
clean:
rm -f $(TARGET) *.o
new: clean all
distclean: clean
rm -f Makefile.conf config.h config.log
$(TARGET): $(OBJS)
$(CC) $(LDFLAGS) -o $(TARGET) $(OBJS) $(LIBS)
prep-install-dirs:
mkdir -p '$(DESTDIR)$(PREFIX_BIN)'
mkdir -p '$(DESTDIR)$(PREFIX_LIB)'
mkdir -p '$(DESTDIR)$(PREFIX_INC)'
mkdir -p '$(DESTDIR)$(PREFIX_MAN)'
mkdir -p '$(DESTDIR)$(PREFIX_MAN)'/man1/
prep-install: all prep-install-dirs
install: prep-install install-rpld install-tools
install-rpld:
cp $(cp_v) $(TARGET) '$(DESTDIR)$(PREFIX_BIN)'
cp $(cp_v) $(MANPAGES_1) '$(DESTDIR)$(PREFIX_MAN)'/man1/
cp $(cp_v) $(HEADERS) '$(DESTDIR)$(PREFIX_INC)'
install-tools:
cp $(cp_v) $(TOOLS) '$(DESTDIR)$(PREFIX_BIN)'
cp $(cp_v) $(TOOLS_MAN1_0) '$(DESTDIR)$(PREFIX_MAN)'/man1/
cp $(cp_v) $(TOOLS_MAN1_1) '$(DESTDIR)$(PREFIX_MAN)'/man1/
cp $(cp_v) $(TOOLS_MAN1_2) '$(DESTDIR)$(PREFIX_MAN)'/man1/
while read fn fc tn tc; do ln -s ../man$$tc/$$tn.$$tc '$(DESTDIR)$(PREFIX_MAN)'/man$$fc/$$fn.$$fc 2> /dev/null; done < man-symlinks.src; true
semi-install: prep-install semi-install-rpld semi-install-tools
semi-install-rpld:
ln -fs `pwd`/$(TARGET) '$(DESTDIR)$(PREFIX_BIN)'
set -e; for i in $(MANPAGES_1); do ln -fs `pwd`/$$i '$(DESTDIR)$(PREFIX_MAN)'/man1/$$i; done
set -e; for i in $(HEADERS); do ln -fs `pwd`/$$i '$(DESTDIR)$(PREFIX_INC)'/$$i; done
semi-install-tools:
set -e; for i in $(TOOLS); do ln -fs `pwd`/$$i '$(DESTDIR)$(PREFIX_BIN)'; done
ln -fs `pwd`/$(TOOLS_MAN1_0) '$(DESTDIR)$(PREFIX_MAN)'/man1/$(TOOLS_MAN1_BASENAME_0).1
ln -fs `pwd`/$(TOOLS_MAN1_1) '$(DESTDIR)$(PREFIX_MAN)'/man1/$(TOOLS_MAN1_BASENAME_1).1
ln -fs `pwd`/$(TOOLS_MAN1_2) '$(DESTDIR)$(PREFIX_MAN)'/man1/$(TOOLS_MAN1_BASENAME_2).1
while read fn fc tn tc; do ln -s `pwd`/tools/$$tn.$$tc '$(DESTDIR)$(PREFIX_MAN)'/man$$fc/$$fn.$$fc 2> /dev/null; done < man-symlinks.src; true
uninstall:
rm -f '$(DESTDIR)$(PREFIX_BIN)/$(TARGET)'
.PHONY: all clean new distclean prep-install-dirs prep-install install semi-install uninstall
rpld-0.1.9/README 0000644 0001750 0001750 00000003560 12266601511 011470 0 ustar phi phi RoarAudio PlayList Daemon
-----------------------------
--- Build:
-- Build requirements:
In order to build the rpld you need to install RoarAudio and
it's devel packets.
In addition you should install libuuid from e2progs and it's
devel packet.
-- How to build:
$ ./configure
$ make
Install with:
$ make install
-- Codec Helper:
The Codec Helper is a small script which is used to decode stuff if codec is
unknown or unsupported by server. This is mostly used for non-free codecs which
can not be implemented by us. It is very strongly recommended to use a server
implementing the codecs you use and only use free codecs.
To use a Codec Helper copy one of the files in codec-helper/ to your normal
bin directory (/usr/bin, /usr/local/bin, ...) with the name 'rpld-codec-helper'.
Diffrent Codec Helper may require diffrent dependencies on installed tools.
--- Tested platforms:
OPERATING SYSTEM ARCH COMPILER TESTED M/STATUS COMMENT
AND VERSION VERSION
---------------------------------------------------------------------------------------------------
Debian Etch ix86 gcc 4.1.2 current s/OK
Debian Etch x86_64 gcc 4.1.2 0.1.6 s/OK
Debian Lenny ix86 gcc 4.3.2 0.1rc4 s/OK
Debian Wheezy x86_64 gcc 4.7.2 0.1.8 M/OK
Debian Sid ix86 gcc 4.6.1 0.1.1 M/OK
Debian Sid ix86 clang 2.7 0.1rc4 s/OK
Debian Sid x86_64 gcc 4.7.1 0.1.5 M/OK
FreeBSD 7.3 i386 gcc 4.2.1 0.1.7 s/OK
Wine 0.9.25 ix86 mingw 3.4.5 0.1.0 s/OK
OpenBSD 4.4 i386 gcc 3.3.5 0.1.2 s/OK
WinXP/MSys ix86 mingw 4.7.0 0.1.9 m/OK Automatic Build Bot.
Tested Version:
Current: Current as listed on Homepage
last: Last released version (This system is on release checklist)
*b*: Beta
Status: Maintenance/testing Status:
Maintenance: s = your are on your own, sources.
m = package in work, beta package
M = maintained
S = maintained source package
B = maintained binary package
rpld-0.1.9/TODO 0000644 0001750 0001750 00000000464 12023720156 011276 0 ustar phi phi More Tickets on BTS at: https://bts.keep-cool.org/
Things we need to do:
* (0.1) implement search
Things we should do:
* (0.1) support for MPD protocol (WIP)
* (0.1) something to detect playlist changes
* (0.1 #201) 'queue counter' for PLEs
Things it would be nice to have:
* (0.2 #302 #303) x-fader
rpld-0.1.9/autoqueue.c 0000644 0001750 0001750 00000013003 12266574300 012767 0 ustar phi phi //autoqueue.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
static inline int __autoqueue(pli_t queue, struct rpld_playlist * pl) {
struct rpld_playlist_entry * plent;
struct rpld_playlist_entry * copy;
struct rpld_playlist_search pls;
struct rpld_playlist_pointer * plp = NULL, * plp_copy = NULL;
int update_current = 0;
if ( rpld_pointer_is_set(POINTER_CURRENT, queue, -1) == 0 ) {
ROAR_DBG("autoqueue(void): no current pointer");
plp = rpld_pointer_get(POINTER_DEFAULT, queue, -1);
if ( plp != NULL ) {
ROAR_DBG("autoqueue(void): we have a default pointer at %p", plp);
if ( rpld_plp_copy(&plp_copy, plp) == -1 ) {
ROAR_DBG("autoqueue(void): copy of default pointer to current pointer failed");
return -1;
}
rpld_pointer_set(POINTER_CURRENT, queue, -1, plp_copy);
rpld_plp_unref(plp);
rpld_plp_unref(plp_copy);
#ifdef DEBUG
if ( rpld_pointer_is_set(POINTER_CURRENT, queue, -1) == 0 ) {
ROAR_DBG("autoqueue(void): still no current pointer");
}
} else {
ROAR_DBG("autoqueue(void): no default pointer");
#endif
}
}
plp = rpld_pointer_get(POINTER_CURRENT, queue, -1);
if ( plp != NULL ) {
ROAR_DBG("autoqueue(void): we have a current pointer at %p", plp);
update_current = 1;
}
if ( plp == NULL ) {
plp = rpld_pointer_get(POINTER_FALLBACK, queue, -1);
#ifdef DEBUG
if ( plp != NULL ) {
ROAR_DBG("autoqueue(void): we have a fallback pointer at %p", plp);
}
#endif
}
if ( plp == NULL ) {
ROAR_DBG("autoqueue(void): No pointers left to try. giving up.");
ROAR_DBG("autoqueue(void) = -1");
return -1;
}
if ( (plent = rpld_plp_search(plp)) == NULL ) {
rpld_plp_unref(plp);
return -1;
}
if ( (copy = rpld_ple_copy(plent)) == NULL ) {
rpld_plp_unref(plp);
return -1;
}
rpld_pl_push(pl, copy);
if ( update_current &&
!( plp->pls.type == RPLD_PL_ST_RANDOM ||
plp->pls.type == RPLD_PL_ST_RANDOM_LIKENESS ) ) {
if ( rpld_pointer_set(POINTER_CURRENT, queue, -1, NULL) == 0 ) {
if ( plent->list.next != NULL ) {
plent = plent->list.next;
memset(&pls, 0, sizeof(pls));
pls.type = RPLD_PL_ST_UUID;
memcpy(pls.subject.uuid, plent->uuid, sizeof(pls.subject.uuid));
plp_copy = rpld_plp_init(NULL, &pls);
rpld_pointer_set(POINTER_CURRENT, queue, -1, plp_copy);
rpld_plp_unref(plp_copy);
}
}
}
rpld_plp_unref(plp);
return 0;
}
static inline struct rpld_playlist_entry * __get_fallback(pli_t queue) {
struct rpld_playlist_entry * plent;
struct rpld_playlist_pointer * plp = NULL;
int err;
plp = rpld_pointer_get(POINTER_FALLBACK, queue, -1);
if ( plp == NULL )
return NULL;
plent = rpld_plp_search(plp);
err = roar_error;
rpld_plp_unref(plp);
roar_err_set(err);
return plent;
}
static inline void __go_back_in_time(pli_t queue, struct rpld_playlist * pl, struct rpld_playlist_entry ** plep, time_t now) {
struct rpld_playlist_entry * ple = *plep;
(void)pl;
// keep everything that is up to 5 secs too early.
if ( (ple->wallclock_start - 5) <= now )
return;
// TODO: Implement a way to upmove the CURRENT Pointer.
// This is a bit harder as we need to detect the inital point.
// That is doable in case it was inited using the DEFAULT pointer.
// But what about manually set pointer or other kind of pointer operations?
// for now we ignore that case and skip to the next try.
// if there is nothing else left we can still try the FALLBACK pointer before we keep the current title.
ple = __get_fallback(queue);
if ( ple != NULL ) {
rpld_ple_free(*plep);
*plep = ple;
return;
}
// ok, nothing left. We just return and keep the current one.
}
int autoqueue(pli_t queue) {
struct rpld_playlist * pl = rpld_pl_get_by_id(queue);
struct rpld_playlist_entry * ple = NULL;
time_t now = RPLD_PLE_WALLCLOCK_INVALID;
int ret = 0;
int err;
ROAR_DBG("autoqueue(void) = ?");
if ( pl == NULL ) {
ROAR_DBG("autoqueue(void) = -1");
return -1;
}
while (ret == 0 && ple == NULL) {
ret = __autoqueue(queue, pl);
err = roar_error;
if ( pl != NULL )
ple = rpld_pl_pop(pl);
if ( ple == NULL ) {
err = roar_error;
ret = -1;
} else if ( ple->wallclock_start == RPLD_PLE_WALLCLOCK_INVALID ) {
break;
} else {
if ( now == RPLD_PLE_WALLCLOCK_INVALID )
now = time(NULL);
if ( ((ple->wallclock_start + ple->length) < now) && !(ple->flags & RPLD_PLE_FLAG_UNSKIPABLE) ) {
rpld_ple_free(ple);
ple = NULL;
continue;
} else if ( ple->wallclock_start > now ) {
__go_back_in_time(queue, pl, &ple, now);
} else {
break;
}
}
}
if ( ple != NULL )
rpld_pl_push(pl, ple);
rpld_pl_unref(pl);
roar_err_set(err);
return ret;
}
//ll
rpld-0.1.9/autoqueue.h 0000644 0001750 0001750 00000001753 12266574301 013006 0 ustar phi phi //autoqueue.h:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef _RPLD_AUTOQUEUE_H_
#define _RPLD_AUTOQUEUE_H_
int autoqueue(pli_t queue);
#endif
//ll
rpld-0.1.9/backend.c 0000644 0001750 0001750 00000011305 12266574301 012345 0 ustar phi phi //backend.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2012-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
static struct roar_kstore * backend_store = NULL;
static int global_codecbl[PLAYBACK_MAX_CODECBL];
int backend_init(void) {
size_t i;
if ( backend_store != NULL )
return 0;
for (i = 0; i < PLAYBACK_MAX_CODECBL; i++) {
global_codecbl[i] = -1;
}
backend_store = roar_kstore_new(-1, (int(*)(void*))backend_ref, (int(*)(void*))backend_unref, NULL);
if ( backend_store == NULL )
return -1;
return 0;
}
int backend_free(void) {
if ( roar_kstore_unref(backend_store) == -1 )
return -1;
backend_store = NULL;
return 0;
}
struct rpld_backend * backend_get_connection(const char * name) {
return backend_get_connection2(name, 0);
}
struct rpld_backend * backend_get_connection2(const char * name, int allow_stub) {
struct rpld_backend * ret = NULL;
const char * server;
size_t i;
int err;
if ( name == NULL )
name = BACKEND_DEFAULT_NAME;
if ( backend_store != NULL ) {
ret = roar_kstore_get(backend_store, name);
if ( ret != NULL )
return ret;
}
ret = roar_mm_malloc(sizeof(struct rpld_backend));
if ( ret == NULL )
return NULL;
memset(ret, 0, sizeof(struct rpld_backend));
ret->refc = 1;
ret->flags = 0;
for (i = 0; i < PLAYBACK_MAX_CODECBL; i++) {
ret->codecbl[i] = -1;
}
if ( !strcmp(name, BACKEND_DEFAULT_NAME) ) {
server = NULL;
} else {
server = name;
}
if ( roar_simple_connect(&(ret->con), server, APPLICATION_NAME) == -1 ) {
if ( allow_stub ) {
roar_connect_none(&(ret->con));
} else {
err = roar_error;
roar_mm_free(ret);
roar_error = err;
return NULL;
}
} else {
ret->flags |= BACKEND_FLAG_CONNECTED;
}
if ( backend_store != NULL ) {
ROAR_DBG("backend_get_connection2(name=?, allow_stub=%i): name='%s'", allow_stub, name);
if ( roar_kstore_add(backend_store, ret, name) == -1 ) {
err = roar_error;
if ( ret->flags & BACKEND_FLAG_CONNECTED )
roar_disconnect(&(ret->con));
roar_mm_free(ret);
roar_error = err;
return NULL;
}
}
return ret;
}
int backend_ref(struct rpld_backend * backend) {
if ( backend == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
backend->refc++;
return 0;
}
int backend_unref(struct rpld_backend * backend) {
if ( backend == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
backend->refc--;
if ( backend->refc )
return 0;
if ( backend->flags & BACKEND_FLAG_CONNECTED )
roar_disconnect(&(backend->con));
roar_mm_free(backend);
return 0;
}
const char * backend_get_name(struct rpld_backend * backend) {
const char * ret;
if ( backend == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return NULL;
}
if ( !(backend->flags & BACKEND_FLAG_CONNECTED) )
return roar_kstore_name(backend_store, backend);
ret = roar_get_connection_server(&(backend->con));
if ( ret == NULL )
return BACKEND_DEFAULT_NAME;
return ret;
}
int backend_blacklist_codec(struct rpld_backend * backend, int codec) {
int i;
if ( backend == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
for (i = 0; i < PLAYBACK_MAX_CODECBL; i++) {
if ( backend->codecbl[i] == -1 ) {
backend->codecbl[i] = codec;
return 0;
}
}
roar_err_set(ROAR_ERROR_NOSPC);
return -1;
}
int backend_blacklist_codec_global(int codec) {
int i;
for (i = 0; i < PLAYBACK_MAX_CODECBL; i++) {
if ( global_codecbl[i] == -1 ) {
global_codecbl[i] = codec;
return 0;
}
}
roar_err_set(ROAR_ERROR_NOSPC);
return -1;
}
int backend_blacklist_check_codec(struct rpld_backend * backend, int codec) {
int i;
if ( backend == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
if ( codec == -1 ) {
roar_err_set(ROAR_ERROR_INVAL);
return 1;
}
for (i = 0; i < PLAYBACK_MAX_CODECBL; i++) {
if ( global_codecbl[i] == codec ) {
return 1;
}
}
for (i = 0; i < PLAYBACK_MAX_CODECBL; i++) {
if ( backend->codecbl[i] == codec ) {
return 1;
}
}
return 0;
}
//ll
rpld-0.1.9/backend.h 0000644 0001750 0001750 00000003471 12266574301 012357 0 ustar phi phi //backend.h:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2012-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef _RPLD_BACKEND_H_
#define _RPLD_BACKEND_H_
#define PLAYBACK_MAX_CODECBL 16
#define BACKEND_DEFAULT_NAME "+default"
#define BACKEND_FLAG_NONE 0x0000
#define BACKEND_FLAG_CONNECTED 0x0001
struct rpld_backend {
size_t refc;
int flags;
struct roar_connection con;
int codecbl[PLAYBACK_MAX_CODECBL];
};
int backend_init(void);
int backend_free(void);
struct rpld_backend * backend_get_connection(const char * name);
struct rpld_backend * backend_get_connection2(const char * name, int allow_stub);
int backend_ref(struct rpld_backend * backend);
int backend_unref(struct rpld_backend * backend);
const char * backend_get_name(struct rpld_backend * backend);
int backend_blacklist_codec(struct rpld_backend * backend, int codec);
int backend_blacklist_codec_global(int codec);
int backend_blacklist_check_codec(struct rpld_backend * backend, int codec);
#endif
//ll
rpld-0.1.9/client.c 0000644 0001750 0001750 00000033401 12266574302 012236 0 ustar phi phi //client.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
static const struct roar_dl_proto __proto_rpld = {
.proto = ROAR_PROTO_RPLD,
.description = "RPLD Simple",
.flags = ROAR_DL_PROTO_FLAGS_NONE,
.set_proto = NULL,
.unset_proto = NULL,
.handle = proto_simple_client_handle,
.flush = NULL,
.flushed = NULL,
.status = NULL
};
static const struct roar_dl_proto __proto_mpd = {
.proto = ROAR_PROTO_MPD,
.description = "MPD",
.flags = ROAR_DL_PROTO_FLAGS_NONE,
.set_proto = proto_mpd_client_set_proto,
.unset_proto = NULL,
.handle = proto_mpd_client_handle,
.flush = NULL,
.flushed = NULL,
.status = NULL
};
static struct rpld_proto g_proto[RPLD_PROTOS_MAX];
static struct rpld_client {
enum rpld_client_state state;
pli_t playlist;
pli_t queue; // which playlist is the main queue for this client?
struct rpld_playlist_pointer * tmpptr;
struct roar_vio_calls con;
enum rpld_client_acclev acclev;
char * name;
// for proto functions.
const struct rpld_proto * proto;
struct roar_buffer * obuffer;
void * userdata;
} g_clients[RPLD_CLIENTS_MAX];
static int plugin_callback(enum roar_dl_fnreg_action action, int fn, int subtype, const void * object, size_t objectlen, int version, int options, void * userdata, struct roar_dl_lhandle * lhandle) {
const struct roar_dl_proto * impl = object;
size_t i, j;
(void)fn, (void)subtype, (void)version, (void)options, (void)userdata;
ROAR_DBG("plugin_callback(action=%i, fn=%i, subtype=%i, object=%p, objectlen=%lu, version=%i, options=%i, userdata=%p, lhandle=%p) = ?", (int)action, fn, subtype, object, (long unsigned int)objectlen, version, options, userdata, lhandle);
if ( objectlen != ROAR_DL_PROTO_SIZE ) {
ROAR_WARN("plugin_callback(*): Library %p tries to register protocol with bad object length.", lhandle);
roar_err_set(ROAR_ERROR_BADLIB);
return -1;
}
switch (action) {
case ROAR_DL_FNREG:
for (i = 0; i < RPLD_PROTOS_MAX; i++) {
if ( g_proto[i].impl == NULL ) {
ROAR_DBG("plugin_callback(*): Registering as protocol number %u", (unsigned int)i);
memset(&(g_proto[i]), 0, sizeof(g_proto[i]));
g_proto[i].para = NULL;
g_proto[i].paralen = -1;
g_proto[i].pluginpara = NULL;
g_proto[i].lhandle = lhandle;
g_proto[i].impl = impl;
ROAR_DBG("plugin_callback(action=%i, fn=%i, subtype=%i, object=%p, objectlen=%lu, version=%i, options=%i, userdata=%p, lhandle=%p) = 0", (int)action, fn, subtype, object, (long unsigned int)objectlen, version, options, userdata, lhandle);
return 0;
}
}
break;
case ROAR_DL_FNUNREG:
for (i = 0; i < RPLD_PROTOS_MAX; i++) {
if ( g_proto[i].impl != NULL && g_proto[i].lhandle == lhandle ) {
for (j = 0; j < RPLD_CLIENTS_MAX; j++) {
if ( g_clients[j].state != CSTATE_UNUSED && g_clients[j].proto == &(g_proto[i]) ) {
client_delete(j);
}
}
g_proto[i].impl = NULL;
}
}
return 0;
break;
}
roar_err_set(ROAR_ERROR_NOSPC);
return -1;
}
static const struct roar_dl_fnreg __fnreg_proto = {
.fn = ROAR_DL_FN_PROTO,
.subtype = ROAR_DL_PROTO_SUBTYPE,
.version = ROAR_DL_PROTO_VERSION,
.callback = plugin_callback,
.userdata = NULL
};
static inline int __proto_run(int id, int (*func)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara)) {
const struct rpld_proto * proto = g_clients[id].proto;
int ret;
if ( func == NULL ) {
roar_err_set(ROAR_ERROR_NOSYS);
return -1;
}
if ( proto->lhandle != NULL )
roar_dl_context_restore(proto->lhandle);
ret = func(id, &(g_clients[id].con), &(g_clients[id].obuffer), &(g_clients[id].userdata), g_clients[id].proto->para, g_clients[id].proto->paralen, g_clients[id].proto->pluginpara);
if ( proto->lhandle != NULL )
roar_dl_context_store(proto->lhandle);
return ret;
}
#define PROTO_RUN(id,func) __proto_run((id), (g_clients[(id)].proto == NULL || \
g_clients[(id)].proto->impl->func == NULL) ? \
NULL : g_clients[(id)].proto->impl->func)
void client_init(void) {
size_t i;
memset(g_clients, 0, sizeof(g_clients));
for (i = 0; i < RPLD_PROTOS_MAX; i++)
g_proto[i].impl = NULL;
for (i = 0; i < RPLD_CLIENTS_MAX; i++)
g_clients[i].state = CSTATE_UNUSED;
ROAR_DL_RFNREG(ROAR_DL_HANDLE_APPLICATION, __fnreg_proto);
roar_dl_register_fn(ROAR_DL_HANDLE_APPLICATION, ROAR_DL_FN_PROTO, ROAR_DL_PROTO_SUBTYPE,
&__proto_rpld, sizeof(__proto_rpld), ROAR_DL_PROTO_VERSION, ROAR_DL_FNREG_OPT_NONE);
roar_dl_register_fn(ROAR_DL_HANDLE_APPLICATION, ROAR_DL_FN_PROTO, ROAR_DL_PROTO_SUBTYPE,
&__proto_mpd, sizeof(__proto_mpd), ROAR_DL_PROTO_VERSION, ROAR_DL_FNREG_OPT_NONE);
}
int client_new(struct roar_vio_calls ** vio) {
int i;
if ( vio == NULL )
return -1;
for (i = 0; i < RPLD_CLIENTS_MAX; i++) {
if ( g_clients[i].state == CSTATE_UNUSED ) {
g_clients[i].state = CSTATE_USED;
g_clients[i].playlist = 0; /* 0=main queue */
g_clients[i].queue = 0; /* 0=main queue */
g_clients[i].tmpptr = NULL;
g_clients[i].acclev = ACCLEV_ALL; // currently all clients have fill access rights
g_clients[i].name = NULL;
g_clients[i].proto = NULL;
g_clients[i].userdata = NULL;
g_clients[i].obuffer = NULL;
roar_vio_clear_calls(&(g_clients[i].con));
*vio = &(g_clients[i].con);
client_set_proto(i, ROAR_PROTO_RPLD);
return i;
}
}
return -1;
}
int client_delete(int id) {
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return -1;
if ( g_clients[id].state == CSTATE_UNUSED )
return 0;
g_clients[id].state = CSTATE_UNUSED;
PROTO_RUN(id, unset_proto);
if ( g_clients[id].userdata != NULL ) {
roar_mm_free(g_clients[id].userdata);
g_clients[id].userdata = NULL;
}
if ( g_clients[id].name != NULL )
roar_mm_free(g_clients[id].name);
g_clients[id].proto = NULL;
if ( g_clients[id].tmpptr != NULL ) {
rpld_plp_unref(g_clients[id].tmpptr);
g_clients[id].tmpptr = NULL;
}
roar_vio_close(&(g_clients[id].con));
return 0;
}
int client_get_proto(int id) {
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return RPLD_PROTO_UNUSED;
if ( g_clients[id].state == CSTATE_UNUSED )
return RPLD_PROTO_UNUSED;
if ( g_clients[id].proto == NULL )
return RPLD_PROTO_UNUSED;
return g_clients[id].proto->impl->proto;
}
int client_set_proto(int id, int proto) {
const struct rpld_proto * newproto = NULL;
size_t i;
int ret = 0;
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return -1;
if ( g_clients[id].state != CSTATE_USED )
return -1;
for (i = 0; i < (sizeof(g_proto)/sizeof(*g_proto)); i++) {
if ( g_proto[i].impl != NULL && g_proto[i].impl->proto == proto ) {
newproto = &(g_proto[i]);
break;
}
}
if ( newproto == NULL )
return -1;
PROTO_RUN(id, unset_proto);
if ( g_clients[id].userdata != NULL ) {
roar_mm_free(g_clients[id].userdata);
g_clients[id].userdata = NULL;
}
g_clients[id].proto = newproto;
if ( newproto->impl->set_proto != NULL )
ret = PROTO_RUN(id, set_proto);
return ret;
}
struct roar_vio_calls * client_get_vio(int id) {
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return NULL;
if ( g_clients[id].state == CSTATE_UNUSED )
return NULL;
return &(g_clients[id].con);
}
enum rpld_client_acclev client_get_acclev(int id) {
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return ACCLEV_ERR;
return g_clients[id].acclev;
}
int client_set_acclev(int id, enum rpld_client_acclev acclev, int setter) {
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return -1;
if ( setter != -1 ) {
if ( setter != id )
if ( setter < 0 || setter >= RPLD_CLIENTS_MAX )
return -1;
if ( acclev > g_clients[setter].acclev )
return -1;
}
g_clients[id].acclev = acclev;
return 0;
}
int client_inc_acclev(int id, int inc, int setter) {
int newlev;
enum rpld_client_acclev acclev;
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return -1;
if ( setter != id )
if ( setter < 0 || setter >= RPLD_CLIENTS_MAX )
return -1;
newlev = (int)g_clients[id].acclev + inc;
if ( newlev < 0 ) {
acclev = ACCLEV_NONE;
} else {
acclev = newlev;
}
if ( acclev > g_clients[setter].acclev )
return -1;
g_clients[id].acclev = acclev;
return 0;
}
int client_set_name(int id, const char * name) {
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return -1;
if ( name != NULL && name[0] == 0 )
name = NULL;
if ( g_clients[id].name != NULL )
roar_mm_free(g_clients[id].name);
if ( name == NULL ) {
g_clients[id].name = NULL;
} else {
g_clients[id].name = roar_mm_strdup(name);
}
return 0;
}
const char * client_get_name(int id) {
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return NULL;
return g_clients[id].name;
}
int client_set_playlist(int id, pli_t pl) {
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return -1;
g_clients[id].playlist = pl;
return 0;
}
pli_t client_get_playlist(int id) {
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return -1;
return g_clients[id].playlist;
}
int client_set_queue(int id, pli_t pl) {
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return -1;
// TODO: check if the playlist is a queue.
g_clients[id].queue = pl;
return 0;
}
pli_t client_get_queue(int id) {
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return -1;
return g_clients[id].queue;
}
int client_set_pointer(int id, int pointer, struct rpld_playlist_pointer * plp) {
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return -1;
if ( pointer != POINTER_TEMP ) {
roar_err_set(ROAR_ERROR_INVAL);
return -1;
}
if ( g_clients[id].tmpptr != NULL )
rpld_plp_unref(g_clients[id].tmpptr);
g_clients[id].tmpptr = plp;
if ( g_clients[id].tmpptr != NULL )
rpld_plp_ref(g_clients[id].tmpptr);
return 0;
}
struct rpld_playlist_pointer * client_get_pointer(int id, int pointer) {
struct rpld_playlist_pointer * ret;
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return NULL;
if ( pointer != POINTER_TEMP ) {
roar_err_set(ROAR_ERROR_INVAL);
return NULL;
}
ret = g_clients[id].tmpptr;
if ( ret == NULL ) {
roar_err_set(ROAR_ERROR_NOENT);
} else {
rpld_plp_ref(ret);
}
return ret;
}
static void __flush_client(int id, struct roar_vio_calls * vio, struct roar_buffer ** buffer) {
size_t len;
ssize_t ret;
void * buf;
if ( roar_buffer_get_datalen(*buffer, &buf, &len) == -1 )
return;
ret = roar_vio_write(vio, buf, len);
if ( ret < 1 ) {
client_delete(id);
return;
}
if ( ret == (ssize_t)len ) {
if ( roar_buffer_next(buffer) == -1 ) {
client_delete(id);
return;
}
} else {
if ( roar_buffer_set_offset(*buffer, ret) == -1 ) {
client_delete(id);
return;
}
}
roar_err_set(ROAR_ERROR_NONE);
}
int client_handle(int id, int eventsa) {
int ret = 0;
ROAR_DBG("client_handle(id=%i, eventsa=%i) = ?", id, eventsa);
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return -1;
if ( g_clients[id].state == CSTATE_UNUSED )
return -1;
roar_err_set(ROAR_ERROR_NONE);
if ( eventsa & ROAR_VIO_SELECT_READ ) {
ret = PROTO_RUN(id, handle);
}
if ( eventsa & ROAR_VIO_SELECT_WRITE ) {
if ( g_clients[id].proto->impl->flush != NULL ) {
PROTO_RUN(id, flush);
} else {
__flush_client(id, &(g_clients[id].con), &(g_clients[id].obuffer));
}
if ( g_clients[id].obuffer == NULL && g_clients[id].proto->impl->flushed != NULL ) {
PROTO_RUN(id, flushed);
}
}
ROAR_DBG("client_handle(id=%i, eventsa=%i) = %i", id, eventsa, ret);
return ret;
}
int client_get_eventsq(int id) {
int ret = ROAR_VIO_SELECT_READ;
if ( id < 0 || id >= RPLD_CLIENTS_MAX )
return ROAR_VIO_SELECT_NO_RETEST;
if ( g_clients[id].state == CSTATE_UNUSED )
return ROAR_VIO_SELECT_NO_RETEST;
if ( g_clients[id].obuffer != NULL )
ret |= ROAR_VIO_SELECT_WRITE;
return ret;
}
int client_str2proto(const char * str) {
if ( str == NULL || *str == 0 )
return -1;
if ( !strcasecmp(str, "simple") )
return ROAR_PROTO_RPLD;
if ( !strcasecmp(str, "rpld") )
return ROAR_PROTO_RPLD;
if ( !strcasecmp(str, "mpd") )
return ROAR_PROTO_MPD;
return roar_str2proto(str);
}
const char * client_proto2str(const int proto) {
switch (proto) {
case RPLD_PROTO_UNUSED: return "(unused client)"; break;
case ROAR_PROTO_RPLD: return "rpld"; break;
case ROAR_PROTO_MPD: return "mpd"; break;
default: return roar_proto2str(proto); break;
}
}
int client_str2acclev(const char * str) {
if ( !strcasecmp(str, "none") )
return ACCLEV_NONE;
if ( !strcasecmp(str, "conctl") )
return ACCLEV_CONCTL;
if ( !strcasecmp(str, "guest") )
return ACCLEV_GUEST;
if ( !strcasecmp(str, "user") )
return ACCLEV_USER;
if ( !strcasecmp(str, "all") )
return ACCLEV_ALL;
return -1;
}
const char * client_acclev2str(enum rpld_client_acclev acclev) {
switch (acclev) {
case ACCLEV_ERR: return "(error)"; break;
case ACCLEV_NONE: return "none"; break;
case ACCLEV_CONCTL: return "conctl"; break;
case ACCLEV_GUEST: return "guest"; break;
case ACCLEV_USER: return "user"; break;
case ACCLEV_ALL: return "all"; break;
default: return "(unknown acclev)"; break;
}
}
//ll
rpld-0.1.9/client.h 0000644 0001750 0001750 00000005370 12266574302 012247 0 ustar phi phi //client.h:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef _RPLD_CLIENT_H_
#define _RPLD_CLIENT_H_
#define RPLD_PROTO_UNUSED ROAR_PROTO_NONE
#define RPLD_PROTOS_MAX 8
#define RPLD_CLIENTS_MAX 8
// access level:
enum rpld_client_acclev {
ACCLEV_ERR = -1,
ACCLEV_NONE = 0, // no right to do anything
ACCLEV_CONCTL, // only allowed to do basic connection things: noop, quit, auth...
ACCLEV_GUEST, // guest connection (read only)
ACCLEV_USER, // normal user connect (read write)
ACCLEV_ALL // full (admin) access (read write ctl)
};
enum rpld_client_state {
CSTATE_ERROR = -1,
CSTATE_UNUSED = 0,
CSTATE_USED = 1
};
struct rpld_proto {
const struct roar_keyval * para;
ssize_t paralen;
struct roar_dl_librarypara * pluginpara;
struct roar_dl_lhandle * lhandle;
const struct roar_dl_proto * impl;
};
void client_init(void);
int client_new(struct roar_vio_calls ** vio);
int client_delete(int id);
int client_set_proto(int id, int proto);
int client_get_proto(int id);
struct roar_vio_calls * client_get_vio(int id);
enum rpld_client_acclev client_get_acclev(int id);
int client_set_acclev(int id, enum rpld_client_acclev acclev, int setter);
int client_inc_acclev(int id, int inc, int setter);
int client_set_name(int id, const char * name);
const char * client_get_name(int id);
int client_set_playlist(int id, pli_t pl);
pli_t client_get_playlist(int id);
int client_set_queue(int id, pli_t pl);
pli_t client_get_queue(int id);
int client_set_pointer(int id, int pointer, struct rpld_playlist_pointer * plp);
struct rpld_playlist_pointer * client_get_pointer(int id, int pointer);
int client_handle(int id, int eventsa);
int client_get_eventsq(int id);
int client_str2proto(const char * str);
const char * client_proto2str(const int proto);
int client_str2acclev(const char * str);
const char * client_acclev2str(enum rpld_client_acclev acclev);
#endif
//ll
rpld-0.1.9/configure 0000755 0001750 0001750 00000006757 12245102653 012532 0 ustar phi phi #!/bin/sh
# Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012
#
# This file is part of roard a part of RoarAudio,
# a cross-platform sound system for both, home and professional use.
# See README for details.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3
# as published by the Free Software Foundation.
#
# RoarAudio 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 software; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
# This code sets up $ROAR_BUILDSYSTEM_DIR
if [ "$1" = '--buildsystem' ]
then
ROAR_BUILDSYSTEM_DIR="$2"
shift 2
fi
if [ "$ROAR_BUILDSYSTEM_DIR" = '' ]
then
for dir in `roar-config --path prefix-buildsystem 2> /dev/null` \
/usr/lib/roaraudio/build-system/ \
/usr/local/lib/roaraudio/build-system/
do
if [ -d "$dir" ]
then
ROAR_BUILDSYSTEM_DIR="$dir"
break
fi
done
fi
if [ "$ROAR_BUILDSYSTEM_DIR" = '' ]
then
echo 'Can not find build system. Try --buildsystem /path/to/build-system/' >&2
exit 1
fi
# now we include the build system.
. "$ROAR_BUILDSYSTEM_DIR/configure.all"
# the real configure starts here:
# Bad libxml-2.0 hack:
CFLAGS="$CFLAGS -I/usr/include/libxml2"
test_libroar '1.0.11' || exit 1
test_pkgversion
test_buildstamp
test_cc
test_ranlib
test_pkgconfig
test_sysname
while [ "$1" != '' ]
do
parse_option "$@"
shift $SHIFT_COUNT
$HANDLED && continue;
case "$1" in
'--help')
write_help
echo 'OPTIONS:'
exit 0;
;;
*)
echo "Error: unknown option: $1" >&2;
echo "Try: $0 --help" >&2;
exit 1;
;;
esac;
shift;
done
open_configure_files
update_target
test_crosscompile
update_prefixes
update_ccft
update_cc
test_wextra
write_header _CONFIG_H_
test_bin_format
test_linkdeps
test_cp_v
echo -n 'checking for user id of root/superuser... '
if [ "$ROOT_UID" = '(none)' ]
then
echo "none (disabled by user)"
elif [ "$ROOT_UID" = '' ]
then
ROOT_USER='root'
ROOT_UID=`id -u $ROOT_USER`
if [ "$ROOT_UID" = '' ]
then
echo "none (please report this)"
else
echo "$ROOT_UID($ROOT_USER)"
echo "ROOT_UID=$ROOT_UID" >&4
fi
else
echo "$ROOT_UID"
echo "ROOT_UID=$ROOT_UID" >&4
fi
test_func_defmake HAVE_FUNC_UALARM ualarm 'ualarm(0, 0)' -- unistd.h
test_func_defmake HAVE_FUNC_SIGINTERRUPT siginterrupt 'siginterrupt(0, 0)' -- signal.h
test_lib_defmake HAVE_H_STDINT % stdint.h c -- stdint.h
test_lib_defmake HAVE_LIB_WSOCK32 % WinSockP0 wsock32 -- winsock2.h
test_lib_defmake HAVE_LIB_WS2_32 % WinSockP1 ws2_32 -- winsock2.h
test_lib_defmake HAVE_LIB_SLP % OpenSLP slp -- slp.h
test_lib_defmake HAVE_LIB_XML2 % libxml-2 xml2 -- libxml/tree.h libxml/parser.h libxml/xmlreader.h libxml/xpath.h libxml/xpathInternals.h libxml/uri.h
test_lib_defmake HAVE_LIB_ROAR % RoarAudio roar -- roaraudio.h
if [ "$?" != '0' ]
then
echo "Error: can not find libroar" >&2
exit 1
fi
write_vars_configh_literal ROOT_UID
write_vars_configh_string VERSION BUILD_STAMP DISTRIBUTION_VERSION_STRING
cleanup_ccft
write_footer
#ll
rpld-0.1.9/ff_m3u.c 0000644 0001750 0001750 00000005330 12266574302 012137 0 ustar phi phi //ff_m3u.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
int ff_m3u_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
const char * artist;
struct rpld_playlist_entry * cur = rpld_pl_get_first(pl);
(void)handle;
roar_vio_printf(vio, "#EXTM3U\n");
while ( cur != NULL ) {
artist = cur->meta.artist;
if ( *artist == 0 )
artist = cur->meta.performer;
roar_vio_printf(vio, "#EXTINF:%lu,%s - %s\n", (unsigned long)cur->length, artist, cur->meta.title);
roar_vio_printf(vio, "%s\n", rpld_ple_get_filename(cur, -1, NULL));
cur = cur->list.next;
}
return 0;
}
int ff_m3u_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
struct rpld_playlist_entry * plent = NULL;
char buf[1024];
char * s, * delm;
size_t len;
(void)handle;
while ((s = roar_vio_fgets(vio, buf, 1024)) != NULL ) {
len = strlen(s);
for (s += len - 1; *s == '\r' || *s == '\n'; s--)
*s = 0;
if ( !*buf )
continue;
if ( plent == NULL )
if ( (plent = rpld_ple_new()) == NULL )
return -1;
if ( buf[0] == '#' ) {
if ( !strcmp(buf, "#EXTM3U") )
continue;
if ( !strncmp(buf, "#EXTINF:", 8) ) {
s = strstr(buf+8, ",");
if ( s != NULL ) {
*s = 0;
s++;
}
if ( !strcmp(buf+8, "-1") ) {
plent->length = 0;
} else {
plent->length = atol(buf+8);
}
if ( (delm = strstr(s, " - ")) == NULL ) {
strncpy(plent->meta.title, s, sizeof(plent->meta.title));
} else {
*delm = 0;
delm += 3;
strncpy(plent->meta.artist, s, sizeof(plent->meta.artist));
strncpy(plent->meta.title, delm, sizeof(plent->meta.title));
}
}
continue;
}
rpld_ple_push_filename(plent, buf, RPLD_TYPE_UNKNOWN, 1);
rpld_pl_push(pl, plent);
plent = NULL;
}
if ( plent != NULL )
rpld_ple_free(plent);
return 0;
}
//ll
rpld-0.1.9/ff_plain.c 0000644 0001750 0001750 00000004014 12266574302 012534 0 ustar phi phi //ff_plain.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
int ff_plain_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
struct rpld_playlist_entry * cur = rpld_pl_get_first(pl);
const char * file;
(void)handle;
while ( cur != NULL ) {
file = rpld_ple_get_filename(cur, -1, NULL);
if ( file )
roar_vio_printf(vio, "%s\n", file);
cur = cur->list.next;
}
return 0;
}
int ff_plain_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
struct rpld_playlist_entry * plent;
char buf[1024];
char * s;
size_t len;
(void)handle;
ROAR_DBG("ff_plain_pl_import(handle=%p, vio=%p, pl=%p) = ?", handle, vio, pl);
while ((s = roar_vio_fgets(vio, buf, 1024)) != NULL ) {
len = strlen(s);
for (s += len - 1; *s == '\r' || *s == '\n'; s--)
*s = 0;
if ( !*buf )
continue;
ROAR_DBG("ff_plain_pl_import(*): s='%s'", buf);
if ( (plent = rpld_ple_new()) == NULL )
return -1;
rpld_ple_push_filename(plent, buf, RPLD_TYPE_UNKNOWN, 1);
rpld_pl_push(pl, plent);
}
ROAR_DBG("ff_plain_pl_import(handle=%p, vio=%p, pl=%p) = 0", handle, vio, pl);
return 0;
}
//ll
rpld-0.1.9/ff_pls.c 0000644 0001750 0001750 00000003555 12266574303 012241 0 ustar phi phi //ff_pls.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
int ff_pls_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
struct rpld_playlist_entry * cur = rpld_pl_get_first(pl);
size_t num = rpld_pl_num(pl);
unsigned long counter = 1;
(void)handle;
roar_vio_printf(vio, "[playlist]\n");
roar_vio_printf(vio, "NumberOfEntries=%lu\n", (unsigned long)num);
while ( cur != NULL ) {
// roar_vio_printf(vio, "#EXTINF:%i,%s - %s\n", cur->length, cur->meta.artist, cur->meta.title);
roar_vio_printf(vio, "File%lu=%s\n", counter, rpld_ple_get_filename(cur, -1, NULL));
if ( cur->meta.title[0] )
roar_vio_printf(vio, "Title%lu=%s\n", counter, cur->meta.title);
if ( cur->length )
roar_vio_printf(vio, "Length%lu=%lu\n", counter, (unsigned long)cur->length);
counter++;
cur = cur->list.next;
}
roar_vio_printf(vio, "Version=2\n");
return 0;
}
int ff_pls_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
//ll
rpld-0.1.9/ff_rpld.c 0000644 0001750 0001750 00000012237 12266574303 012401 0 ustar phi phi //ff_rpld.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
static char *_strtok(char *str, const char *delim) {
static char * next = NULL;
if ( str == NULL )
str = next;
if ( str == NULL )
return NULL;
next = strstr(str, delim);
if ( next != NULL ) {
*next = 0;
next++;
}
return str;
}
int ff_rpld_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
struct rpld_playlist_entry * plent = rpld_pl_get_first(pl);
char uuid[37];
(void)handle;
roar_uuid2str(uuid, plent->uuid, sizeof(uuid));
while ( plent != NULL ) {
roar_vio_printf(vio,
"%s=%s=%s=%s=%s=%s=%s=%s=long:0x%.16" __ll "X/short:0x%.8lX/uuid:%s=0x%.8lx/%i=%s(0x%x)=%f\n",
roar_codec2str(plent->codec),
rpld_ple_time_hr(plent),
plent->meta.album,
plent->meta.title,
plent->meta.artist,
plent->meta.performer,
plent->meta.version,
rpld_ple_get_filename(plent, -1, NULL),
(__longlong unsigned int)plent->global_tracknum,
(long unsigned int)plent->global_short_tracknum,
uuid,
(long unsigned int)plent->meta.discid,
plent->meta.tracknum,
roar_meta_strgenre(plent->meta.genre),
plent->meta.genre,
(double)plent->likeness
);
plent = plent->list.next;
}
return 0;
}
int ff_rpld_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
struct rpld_playlist_entry * plent_new;
char buf[1024];
char * s, * curtok;
size_t len;
(void)handle;
while ((s = roar_vio_fgets(vio, buf, 1024)) != NULL ) {
len = strlen(s);
ROAR_DBG("ff_rpld_pl_import(*) = ?");
for (s += len - 1; *s == '\r' || *s == '\n'; s--)
*s = 0;
if ( !*buf )
continue;
if ( (plent_new = rpld_ple_new()) == NULL )
return -1;
ROAR_DBG("ff_rpld_pl_import(*) = ?");
// TYPE aka CODEC:
if ( (curtok = _strtok(buf, "=")) == NULL ) {
rpld_ple_free(plent_new);
return -1;
}
plent_new->codec = roar_str2codec(curtok);
ROAR_DBG("ff_rpld_pl_import(*) = ?");
// LENGTH, we ignore this
if ( (curtok = _strtok(NULL, "=")) == NULL ) {
rpld_ple_free(plent_new);
return -1;
}
if ( strstr(curtok, ":") == NULL ) {
// parse SS
plent_new->length = atol(curtok);
} else {
// parse HH:MM:SS
rpld_ple_set_time_hr(plent_new, curtok);
}
ROAR_DBG("ff_rpld_pl_import(*) = ?");
// ALBUM
if ( (curtok = _strtok(NULL, "=")) == NULL ) {
rpld_ple_free(plent_new);
return -1;
}
strncpy(plent_new->meta.album, curtok, sizeof(plent_new->meta.album));
plent_new->meta.album[sizeof(plent_new->meta.album)-1] = 0;
ROAR_DBG("ff_rpld_pl_import(*) = ?");
// TITLE
if ( (curtok = _strtok(NULL, "=")) == NULL ) {
rpld_ple_free(plent_new);
return -1;
}
strncpy(plent_new->meta.title, curtok, sizeof(plent_new->meta.title));
plent_new->meta.title[sizeof(plent_new->meta.title)-1] = 0;
ROAR_DBG("ff_rpld_pl_import(*) = ?");
// ARTIST
if ( (curtok = _strtok(NULL, "=")) == NULL ) {
rpld_ple_free(plent_new);
return -1;
}
strncpy(plent_new->meta.artist, curtok, sizeof(plent_new->meta.artist));
plent_new->meta.artist[sizeof(plent_new->meta.artist)-1] = 0;
ROAR_DBG("ff_rpld_pl_import(*) = ?");
// PERFORMER
if ( (curtok = _strtok(NULL, "=")) == NULL ) {
rpld_ple_free(plent_new);
return -1;
}
strncpy(plent_new->meta.performer, curtok, sizeof(plent_new->meta.performer));
plent_new->meta.performer[sizeof(plent_new->meta.performer)-1] = 0;
ROAR_DBG("ff_rpld_pl_import(*) = ?");
// VERSION
if ( (curtok = _strtok(NULL, "=")) == NULL ) {
rpld_ple_free(plent_new);
return -1;
}
strncpy(plent_new->meta.version, curtok, sizeof(plent_new->meta.version));
plent_new->meta.version[sizeof(plent_new->meta.version)-1] = 0;
ROAR_DBG("ff_rpld_pl_import(*) = ?");
// FILE
if ( (curtok = _strtok(NULL, "=")) == NULL ) {
rpld_ple_free(plent_new);
return -1;
}
rpld_ple_push_filename(plent_new, curtok, RPLD_TYPE_UNKNOWN, 1);
ROAR_DBG("ff_rpld_pl_import(*) = ?");
rpld_pl_push(pl, plent_new);
}
return 0;
}
//ll
rpld-0.1.9/ff_uras.c 0000644 0001750 0001750 00000026306 12266574304 012415 0 ustar phi phi //ff_xspf.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
#ifdef HAVE_LIB_XML2
#include
#include
#include
#include
#include
#include
#include
static int ff_uras_write(void * context, const char * buffer, int len) {
return roar_vio_write(context, (void*)buffer, len);
}
static int ff_uras_read (void * context, char * buffer, int len) {
ssize_t ret = roar_vio_read(context, buffer, len);
ROAR_DBG("ff_uras_read(context=%p, buffer=%p, len=%i) = %i(?)", context, buffer, len, (int)ret);
return ret;
}
static xmlNodePtr new_text_node(xmlNodePtr parent, const char * name, const char * value) {
xmlNodePtr ret = xmlNewNode(NULL, (const xmlChar *)name);
if ( ret == NULL )
return NULL;
xmlAddChild(ret, xmlNewText((const xmlChar *)value));
xmlAddChild(parent, ret);
return ret;
}
static inline xmlNodePtr new_pos_node(xmlNodePtr parent, const char * name, rpld_mus_t pos) {
xmlNodePtr ret = xmlNewNode(NULL, (const xmlChar *)name);
char buf[80];
if ( ret == NULL )
return NULL;
if ( pos == -1 )
pos = 0;
snprintf(buf, sizeof(buf), "%ld", (long int)pos/1000);
xmlSetProp(ret, (xmlChar *)"pos", (const xmlChar *)buf);
xmlAddChild(parent, ret);
return ret;
}
int ff_uras_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
const struct roar_server_info * info = rpld_serverinfo_get();
struct rpld_playlist_entry * cur = rpld_pl_get_first(pl);
char buf[RPLD_MAX_PLF_LEN+64];
xmlDocPtr doc;
xmlNodePtr rootnode, track;
xmlOutputBufferPtr output;
ssize_t i;
struct roar_keyval * extra;
const char * file;
(void)handle;
output = xmlAllocOutputBuffer(NULL);
if ( output == NULL )
return -1;
output->context = vio;
output->writecallback = ff_uras_write;
output->closecallback = NULL;
doc = xmlNewDoc((xmlChar *)"1.0");
if ( doc == NULL )
return -1;
doc->charset = XML_CHAR_ENCODING_UTF8;
doc->encoding = xmlStrdup((xmlChar *)"UTF-8");
rootnode = xmlNewNode(NULL, (xmlChar *)"playlist");
xmlSetProp(rootnode, (xmlChar *)"uribase", (xmlChar *)"/");
xmlDocSetRootElement(doc, rootnode);
if ( rpld_pl_get_name(pl) != NULL ) {
new_text_node(rootnode, "name", rpld_pl_get_name(pl));
} else {
new_text_node(rootnode, "name", "default");
}
new_text_node(rootnode, "location", info->location == NULL ? "default" : info->location);
new_text_node(rootnode, "date", "default");
new_text_node(rootnode, "rgain", "ON");
new_text_node(rootnode, "resync", "ON");
while ( cur != NULL ) {
track = xmlNewNode(NULL, (xmlChar *)"track");
file = rpld_ple_get_filename(cur, -1, NULL);
if (file != NULL) {
xmlSetProp(track, (xmlChar *)"uri", (const xmlChar *)file);
}
if (cur->meta.title[0] != 0)
new_text_node(track, "name", cur->meta.title);
if (cur->meta.tracknum) {
snprintf(buf, sizeof(buf), "%d", (int)cur->meta.tracknum);
new_text_node(track, "tracknum", buf);
}
switch (cur->meta.genre) {
#ifdef ROAR_META_GENRE_META_OTHER
case ROAR_META_GENRE_META_OTHER:
new_text_node(track, "Type", "Nonsong");
break;
#endif
#ifdef ROAR_META_GENRE_META_COMMERCIAL
case ROAR_META_GENRE_META_COMMERCIAL:
new_text_node(track, "Type", "Comm");
break;
#endif
default:
new_text_node(track, "Type", "Song");
break;
}
if (cur->length) {
snprintf(buf, sizeof(buf), "%d", (int)cur->length);
new_text_node(track, "duration", buf);
}
new_pos_node(track, "start", cur->start);
new_pos_node(track, "end", cur->end);
for (i = 0; i < cur->meta.extra.kvlen; i++) {
extra = &(cur->meta.extra.kv[i]);
if ( extra->key == NULL || extra->value == NULL )
continue;
if ( !strcasecmp(extra->key, "X-URAS-START") ) {
new_text_node(track, "start", extra->value);
} else if ( !strcasecmp(extra->key, "X-URAS-MAPNUM") ) {
new_text_node(track, "mapnum", extra->value);
}
}
xmlAddChild(rootnode, track);
cur = cur->list.next;
}
xmlSaveFormatFileTo(output, doc, "UTF-8", 1);
xmlFreeDoc(doc);
return 0;
}
static void ff_uras_pl_import_track(struct rpld_playlist * pl, xmlNode * track, const char * uribase, int rgain) {
struct rpld_playlist_entry * plent = rpld_ple_new();
xmlNode * element;
const char * name;
const char * value;
char * dst;
size_t dst_len;
int tmp;
const char * start = NULL;
const char * mapnum = NULL;
char filenamebuffer[RPLD_MAX_PLF_LEN];
ROAR_DBG("ff_uras_pl_import_track(pl=%p, track=%p, uribase='%s') = ?", pl, track, uribase);
if ( plent == NULL )
return;
plent->rpg.mode = rgain ? ROAR_RPGMODE_TRACKALBUM : ROAR_RPGMODE_NONE;
value = (const char * /* libxml2 cast-hell */) xmlGetProp(track, (xmlChar *)"uri");
snprintf(filenamebuffer, sizeof(filenamebuffer)-1, "%s/%s", uribase, value);
rpld_ple_push_filename(plent, filenamebuffer, RPLD_TYPE_UNKNOWN, 1);
// guess codec:
// as per sepcs only ogg_vorbis and native flac is allowed.
value = strrchr(value, '.');
if ( value != NULL ) {
value++;
if ( !strcasecmp(value, "ogg") ) {
plent->codec = ROAR_CODEC_OGG_VORBIS;
} else if ( !strcasecmp(value, "flac") ) {
plent->codec = ROAR_CODEC_FLAC;
}
}
for (element = track->children; element != NULL; element = element->next) {
if ( element->type != XML_ELEMENT_NODE )
continue;
dst = NULL;
dst_len = 0;
name = (const char * /* libxml2 cast-hell */) element->name;
value = (const char * /* libxml2 cast-hell */) xmlNodeGetContent(element);
ROAR_DBG("ff_uras_pl_import_track(pl=%p, track=%p, uribase='%s'): name='%s', value='%s'", pl, track, uribase, name, value);
if (!strcmp(name, "tracknum")) {
plent->meta.tracknum = atoi(value);
} else if (!strcmp(name, "name")) {
dst = plent->meta.title;
dst_len = sizeof(plent->meta.title);
} else if (!strcmp(name, "trackNum")) {
if ( sscanf(value, "%d", &tmp) == 1 ) {
plent->meta.tracknum = tmp;
}
} else if (!strcmp(name, "mapnum")) {
mapnum = value;
} else if (!strcmp(name, "duration")) {
if ( sscanf(value, "%d", &tmp) == 1 ) {
plent->length = tmp;
}
} else if (!strcmp(name, "start") && xmlGetProp(element, (const xmlChar *)"pos") == NULL ) { // this is the start time of the track in wallclock time.
start = value;
} else if (!strcmp(name, "start") && xmlGetProp(element, (const xmlChar *)"pos") != NULL ) { // this is the start time of the content within the track.
value = (const char * /* libxml2 cast-hell */)xmlGetProp(element, (const xmlChar *)"pos");
if ( value == NULL ) {
ROAR_WARN("ff_uras_pl_import_track(pl=%p, track=%p, uribase='%s'): No Prop \"pos\" in \"start\" tag: Bad. Playlist file is corruped.", pl, track, uribase);
continue;
}
plent->start = 1000*atoi(value);
if ( plent->start == 0 )
plent->start = -1;
} else if (!strcmp(name, "end")) {
value = (const char * /* libxml2 cast-hell */)xmlGetProp(element, (const xmlChar *)"pos");
if ( value == NULL ) {
ROAR_WARN("ff_uras_pl_import_track(pl=%p, track=%p, uribase='%s'): No Prop \"pos\" in \"end\" tag: Bad. Playlist file is corruped.", pl, track, uribase);
continue;
}
plent->end = 1000*atoi(value);
if ( plent->end == 0 )
plent->end = -1;
} else if (!strcmp(name, "Type")) {
if ( 0 ) {
/* noop to ensure correct syntax */
#ifdef ROAR_META_GENRE_META_MUSIC
} else if ( !strcasecmp(value, "Song") ) {
plent->meta.genre = ROAR_META_GENRE_META_MUSIC;
#endif
#ifdef ROAR_META_GENRE_META_OTHER
} else if ( !strcasecmp(value, "Nonong") ) {
plent->meta.genre = ROAR_META_GENRE_META_OTHER;
#endif
#ifdef ROAR_META_GENRE_META_COMMERCIAL
} else if ( !strcasecmp(value, "Comm") ) {
plent->meta.genre = ROAR_META_GENRE_META_COMMERCIAL;
#endif
}
}
if ( dst != NULL ) {
ROAR_DBG("ff_uras_pl_import_track(pl=%p, track=%p): Copy '%s' to %p (element type: %s).", pl, track, value, dst, name);
strncpy(dst, value, dst_len);
dst[dst_len-1] = 0;
} else {
ROAR_DBG("ff_uras_pl_import_track(pl=%p, track=%p): no data to copy (element type: %s).", pl, track, name);
}
}
// push in, do this now so we can do more easy error handling in the next block:
rpld_pl_push(pl, plent);
plent->meta.extra.kv = roar_mm_malloc(sizeof(struct roar_keyval)*2);
if ( plent->meta.extra.kv == NULL )
return;
plent->meta.extra.kvlen = 2;
plent->meta.extra.kv[0].key = "X-URAS-START";
plent->meta.extra.kv[1].key = "X-URAS-MAPNUM";
if ( start == NULL )
start = "";
if ( mapnum == NULL )
mapnum = "";
plent->meta.extra.kv_storelen = roar_mm_strlen(start) + roar_mm_strlen(mapnum) + 2;
plent->meta.extra.kv_store = roar_mm_malloc(plent->meta.extra.kv_storelen);
if ( plent->meta.extra.kv_store == NULL ) {
roar_mm_free(plent->meta.extra.kv);
plent->meta.extra.kv = NULL;
plent->meta.extra.kvlen = -1;
return;
}
plent->meta.extra.kv[0].value = plent->meta.extra.kv_store;
plent->meta.extra.kv[1].value = plent->meta.extra.kv_store + roar_mm_strlen(start) + 1;
strcpy(plent->meta.extra.kv[0].value, start);
strcpy(plent->meta.extra.kv[1].value, mapnum);
}
int ff_uras_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
xmlDoc * doc;
xmlNode * main_element;
xmlNode * playlist_element;
const char * uribase = "/DUMMY/";
int rgain = 0;
const xmlChar * value;
(void)handle;
doc = xmlReadIO(ff_uras_read, NULL, vio, "__dummy.xml", NULL, XML_PARSE_RECOVER);
if ( doc == NULL )
return -1;
for (main_element = doc->children; main_element != NULL; main_element = main_element->next) {
if ( main_element->type != XML_ELEMENT_NODE )
continue;
if ( !!xmlStrcmp(main_element->name, (xmlChar *)"playlist") )
continue;
uribase = (const char * /* libxml2 cast-hell */) xmlGetProp(main_element, (xmlChar *)"uribase");
if ( uribase == NULL )
uribase = "/DUMMY/";
for (playlist_element = main_element->children; playlist_element != NULL; playlist_element = playlist_element->next) {
if ( playlist_element->type != XML_ELEMENT_NODE )
continue;
if ( !xmlStrcmp(playlist_element->name, (xmlChar *)"track") ) {
ff_uras_pl_import_track(pl, playlist_element, uribase, rgain);
} else if ( !xmlStrcmp(playlist_element->name, (xmlChar *)"rgain") ) {
value = xmlNodeGetContent(playlist_element);
if ( value == NULL )
continue;
rgain = !xmlStrcmp(value, (xmlChar *)"ON") ? 1 : 0;
// } else if ( !xmlStrcmp(playlist_element->name, (xmlChar *)"resync") ) {
}
}
}
xmlFreeDoc(doc);
return 0;
}
#endif
//ll
rpld-0.1.9/ff_vclt.c 0000644 0001750 0001750 00000016433 12266574304 012413 0 ustar phi phi //ff_vclt.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
int ff_vclt_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
struct rpld_playlist_entry * cur = rpld_pl_get_first(pl);
ssize_t i;
char uuid[37];
const char * filename;
const char * key;
enum rpld_filename_type filenametype;
ssize_t num;
(void)handle;
while ( cur != NULL ) {
roar_uuid2str(uuid, cur->uuid, sizeof(uuid));
roar_vio_printf(vio, "HASH={UUID}%s\n", uuid);
num = rpld_ple_num_filename(cur);
for (i = 0; i < num; i++) {
filename = rpld_ple_get_filename(cur, i, &filenametype);
if ( filename != NULL ) {
switch (filenametype) {
case RPLD_TYPE_STREAMURL: key = "STREAMURL"; break;
case RPLD_TYPE_FILENAME: key = "FILENAME"; break;
case RPLD_TYPE_FILEURL: key = "FILEURL"; break;
default: key = "FILENAME"; break;
}
roar_vio_printf(vio, "%s=%s\n", key, filename);
}
}
if ( cur->meta.album[0] )
roar_vio_printf(vio, "ALBUM=%s\n", cur->meta.album);
if ( cur->meta.title[0] )
roar_vio_printf(vio, "TITLE=%s\n", cur->meta.title);
if ( cur->meta.artist[0] )
roar_vio_printf(vio, "ARTIST=%s\n", cur->meta.artist);
if ( cur->meta.performer[0] )
roar_vio_printf(vio, "PERFORMER=%s\n", cur->meta.performer);
if ( cur->meta.version[0] )
roar_vio_printf(vio, "VERSION=%s\n", cur->meta.version);
if ( cur->meta.genre != -1 )
roar_vio_printf(vio, "GENRE=%s\n", roar_meta_strgenre(cur->meta.genre));
if ( cur->meta.tracknum )
roar_vio_printf(vio, "TRACKNUMBER=%i\n", cur->meta.tracknum);
if ( cur->meta.discid )
roar_vio_printf(vio, "DISCID=%.8x\n", cur->meta.discid);
if ( cur->length )
roar_vio_printf(vio, "LENGTH=%s\n", rpld_ple_time_hr(cur));
if ( cur->codec != -1 )
roar_vio_printf(vio, "SIGNALINFO=codec:%s\n", roar_codec2str(cur->codec));
if ( cur->wallclock_start != RPLD_PLE_WALLCLOCK_INVALID )
roar_vio_printf(vio, "X-RPLD-WALLCLOCK-START=%" __ll "i\n", (__longlong)cur->wallclock_start);
roar_vio_printf(vio, "LIKENESS=%f\n", (double)cur->likeness);
for (i = 0; i < cur->meta.extra.kvlen && cur->meta.extra.kv[i].key != NULL && cur->meta.extra.kv[i].value != NULL; i++) {
roar_vio_printf(vio, "%s=%s\n", cur->meta.extra.kv[i].key, cur->meta.extra.kv[i].value);
}
roar_vio_printf(vio, "==\n");
cur = cur->list.next;
}
return 0;
}
int ff_vclt_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
struct rpld_playlist_entry * plent = NULL;
struct roar_audio_info info;
char buf[1024];
char * s, * delm;
char * dst;
size_t dst_len;
size_t len;
int meta;
ssize_t extra_index = 0;
void * extra_buf;
ssize_t extra_len;
roar_uuid_t uuid;
enum rpld_filename_type filenametype;
(void)handle;
while ((s = roar_vio_fgets(vio, buf, sizeof(buf))) != NULL ) {
len = strlen(s);
for (s += len - 1; s > buf && (*s == '\r' || *s == '\n'); s--)
*s = 0;
if ( !*buf )
continue;
if ( !strcmp(buf, "==") ) {
if ( plent != NULL )
rpld_pl_push(pl, plent);
plent = NULL;
continue;
}
if ( (delm = strstr(buf, "=")) == NULL )
continue;
*delm = 0;
delm++;
if ( plent == NULL )
if ( (plent = rpld_ple_new()) == NULL )
return -1;
if ( !strcasecmp(buf, "X-RPLD-WALLCLOCK-START") ) {
plent->wallclock_start = atoi(delm);
continue;
}
meta = roar_meta_inttype(buf);
dst = NULL;
dst_len = 0;
switch (meta) {
case ROAR_META_TYPE_FILENAME:
case ROAR_META_TYPE_FILEURL:
case ROAR_META_TYPE_STREAMURL:
filenametype = rpld_ple_get_filenametype(buf);
rpld_ple_push_filename(plent, delm, filenametype, 0);
continue;
break;
case ROAR_META_TYPE_ALBUM:
dst = plent->meta.album;
dst_len = sizeof(plent->meta.album);
break;
case ROAR_META_TYPE_TITLE:
dst = plent->meta.title;
dst_len = sizeof(plent->meta.title);
break;
case ROAR_META_TYPE_ARTIST:
dst = plent->meta.artist;
dst_len = sizeof(plent->meta.artist);
break;
case ROAR_META_TYPE_PERFORMER:
dst = plent->meta.performer;
dst_len = sizeof(plent->meta.performer);
break;
case ROAR_META_TYPE_VERSION:
dst = plent->meta.version;
dst_len = sizeof(plent->meta.version);
break;
case ROAR_META_TYPE_LENGTH:
rpld_ple_set_time_hr(plent, delm);
continue;
break;
case ROAR_META_TYPE_AUDIOINFO:
if ( roar_meta_parse_audioinfo(&info, delm) != -1 ) {
plent->codec = info.codec;
}
continue;
break;
case ROAR_META_TYPE_TRACKNUMBER:
plent->meta.tracknum = atoi(delm);
continue;
break;
case ROAR_META_TYPE_GENRE:
plent->meta.genre = roar_meta_intgenre(delm);
continue;
break;
case ROAR_META_TYPE_DISCID:
sscanf(delm, "%8x", &(plent->meta.discid));
continue;
break;
#ifdef ROAR_META_TYPE_LIKENESS
case ROAR_META_TYPE_LIKENESS:
plent->likeness = atof(delm);
continue;
break;
#endif
case ROAR_META_TYPE_HASH:
if ( !strncasecmp(delm, "{UUID}", 6) ) {
if ( roar_str2uuid(uuid, delm+6) == 0 ) {
memcpy(plent->uuid, uuid, sizeof(plent->uuid));
}
}
continue;
break;
default:
if ( plent->meta.extra.kvlen == -1 )
plent->meta.extra.kvlen = 0;
if ( plent->meta.extra.kv_storelen == -1 )
plent->meta.extra.kv_storelen = 0;
if ( extra_index == plent->meta.extra.kvlen ) {
extra_buf = roar_mm_realloc(plent->meta.extra.kv, sizeof(struct roar_keyval)*(extra_index + 8));
if ( extra_buf == NULL )
continue;
plent->meta.extra.kvlen += 8;
plent->meta.extra.kv = extra_buf;
memset(extra_buf+sizeof(struct roar_keyval)*extra_index, 0, sizeof(struct roar_keyval)*8);
}
extra_len = roar_mm_strlen(buf) + roar_mm_strlen(delm) + 2;
extra_buf = roar_mm_realloc(plent->meta.extra.kv_store, plent->meta.extra.kv_storelen + extra_len);
if ( extra_buf == NULL )
continue;
plent->meta.extra.kv[extra_index].key = extra_buf + plent->meta.extra.kv_storelen;
strcpy(plent->meta.extra.kv[extra_index].key, buf);
plent->meta.extra.kv[extra_index].value = extra_buf + plent->meta.extra.kv_storelen + roar_mm_strlen(buf) + 1;
strcpy(plent->meta.extra.kv[extra_index].value, delm);
plent->meta.extra.kv_store = extra_buf;
plent->meta.extra.kv_storelen += extra_len;
continue;
break;
}
strncpy(dst, delm, dst_len);
dst[dst_len-1] = 0;
}
if ( plent != NULL )
rpld_pl_push(pl, plent);
return 0;
}
//ll
rpld-0.1.9/ff_xspf.c 0000644 0001750 0001750 00000026005 12266574304 012417 0 ustar phi phi //ff_xspf.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
#ifdef HAVE_LIB_XML2
#include
#include
#include
#include
#include
#include
#include
#define META_BASE_URL_PREFIX "http://roaraudio.keep-cool.org/spec/xspf/meta-"
#define META_BASE_URL_SUFFIX ".txt"
#define META_BASE_URL_STATIC(x) (META_BASE_URL_PREFIX x META_BASE_URL_SUFFIX)
#define META_BASE_URL META_BASE_URL_STATIC("%s")
static int ff_xspf_write(void * context, const char * buffer, int len) {
return roar_vio_write(context, (void*)buffer, len);
}
static int ff_xspf_read (void * context, char * buffer, int len) {
ssize_t ret = roar_vio_read(context, buffer, len);
ROAR_DBG("ff_xspf_read(context=%p, buffer=%p, len=%i) = %i(?)", context, buffer, len, (int)ret);
return ret;
}
static xmlNodePtr new_text_node(xmlNodePtr parent, const char * name, const char * value) {
xmlNodePtr ret = xmlNewNode(NULL, (const xmlChar *)name);
if ( ret == NULL )
return NULL;
xmlAddChild(ret, xmlNewText((const xmlChar *)value));
xmlAddChild(parent, ret);
return ret;
}
static xmlNodePtr new_meta_text_node(xmlNodePtr parent, const char * name, const char * value) {
xmlNodePtr ret = xmlNewNode(NULL, (const xmlChar *)"meta");
char buf[256];
if ( ret == NULL )
return NULL;
snprintf(buf, sizeof(buf), META_BASE_URL, name);
xmlSetProp(ret, (xmlChar *)"rel", (const xmlChar *)buf);
xmlAddChild(ret, xmlNewText((const xmlChar *)value));
xmlAddChild(parent, ret);
return ret;
}
static void __add_filenames(xmlNodePtr track, struct rpld_playlist_entry * cur) {
char buf[RPLD_MAX_PLF_LEN+64];
const char * filename;
xmlChar * location;
ssize_t i, num;
num = rpld_ple_num_filename(cur);
for (i = 0; i < num; i++) {
filename = rpld_ple_get_filename(cur, i, NULL);
if ( filename == NULL )
continue;
if ( isalpha(filename[0]) ) {
new_text_node(track, "location", filename);
} else {
location = xmlPathToURI((const xmlChar *)filename);
snprintf(buf, sizeof(buf), "file://%s", location);
xmlFree(location);
new_text_node(track, "location", buf);
}
}
}
int ff_xspf_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
struct rpld_playlist * parentpl;
struct rpld_playlist_entry * cur = rpld_pl_get_first(pl);
int parent = rpld_pl_get_parent(pl);
char buf[RPLD_MAX_PLF_LEN+64];
xmlDocPtr doc;
xmlNodePtr rootnode, tracklist, track;
xmlOutputBufferPtr output;
(void)handle;
output = xmlAllocOutputBuffer(NULL);
if ( output == NULL )
return -1;
output->context = vio;
output->writecallback = ff_xspf_write;
output->closecallback = NULL;
doc = xmlNewDoc((xmlChar *)"1.0");
if ( doc == NULL )
return -1;
doc->charset = XML_CHAR_ENCODING_UTF8;
doc->encoding = xmlStrdup((xmlChar *)"UTF-8");
rootnode = xmlNewNode(NULL, (xmlChar *)"playlist");
xmlSetProp(rootnode, (xmlChar *)"version", (xmlChar *)"1");
xmlSetProp(rootnode, (xmlChar *)"xmlns", (xmlChar *)"http://xspf.org/ns/0/");
xmlDocSetRootElement(doc, rootnode);
if ( rpld_pl_get_name(pl) != NULL )
new_text_node(rootnode, "title", rpld_pl_get_name(pl));
if (parent != 0 && parent != -1) {
snprintf(buf, sizeof(buf), "%d", parent);
new_meta_text_node(rootnode, "parent-playlist-id", buf);
parentpl = rpld_pl_get_by_id(parent);
new_meta_text_node(rootnode, "parent-playlist-name", rpld_pl_get_name(parentpl));
rpld_pl_unref(parentpl);
}
tracklist = xmlNewNode(NULL, (xmlChar *)"trackList");
xmlAddChild(rootnode, tracklist);
while ( cur != NULL ) {
track = xmlNewNode(NULL, (xmlChar *)"track");
__add_filenames(track, cur);
strcpy(buf, "tantalos://");
roar_uuid2str(buf+11, cur->uuid, sizeof(buf)-11);
new_text_node(track, "identifier", buf);
if (cur->meta.album[0] != 0)
new_text_node(track, "album", cur->meta.album);
if (cur->meta.title[0] != 0)
new_text_node(track, "title", cur->meta.title);
if (cur->meta.artist[0] != 0)
new_text_node(track, "creator", cur->meta.artist);
if (cur->meta.performer[0] != 0)
new_meta_text_node(track, "performer", cur->meta.performer);
if (cur->meta.version[0] != 0)
new_meta_text_node(track, "version", cur->meta.version);
if (cur->meta.tracknum) {
snprintf(buf, sizeof(buf), "%d", (int)cur->meta.tracknum);
new_text_node(track, "trackNum", buf);
}
if (cur->meta.discid != 0 && cur->meta.discid != (discid_t)-1) {
snprintf(buf, sizeof(buf), "0x%.8X", (int)cur->meta.discid);
new_meta_text_node(track, "discid", buf);
}
if (cur->meta.genre != -1)
new_meta_text_node(track, "genre", roar_meta_strgenre(cur->meta.genre));
if (cur->likeness) {
snprintf(buf, sizeof(buf), "%f", (double)cur->likeness);
new_meta_text_node(track, "likeness", buf);
}
if (cur->codec != -1) {
new_meta_text_node(track, "codec", roar_codec2str(cur->codec));
}
if (cur->length) {
snprintf(buf, sizeof(buf), "%d", (int)(cur->length * 1000));
new_text_node(track, "duration", buf);
}
xmlAddChild(tracklist, track);
cur = cur->list.next;
}
xmlSaveFormatFileTo(output, doc, "UTF-8", 1);
xmlFreeDoc(doc);
return 0;
}
static void ff_xspf_pl_import_track_parse_meta(struct rpld_playlist_entry * plent,
char ** dst, size_t * dst_len, const char ** value,
xmlNode * element) {
const char * name = (const char * /* libxml2 cast-hell */) xmlGetProp(element, (xmlChar *)"rel");
int tmp;
//Audacious: ???
if ( !strcmp(name, META_BASE_URL_STATIC("performer")) ) {
*dst = plent->meta.performer;
*dst_len = sizeof(plent->meta.performer);
} else if ( !strcmp(name, META_BASE_URL_STATIC("version")) ) {
*dst = plent->meta.version;
*dst_len = sizeof(plent->meta.version);
} else if ( !strcmp(name, META_BASE_URL_STATIC("discid")) ) {
if ( sscanf(*value, "0x%8x", &tmp) == 1 ) {
plent->meta.discid = tmp;
}
} else if ( !strcmp(name, META_BASE_URL_STATIC("genre")) ) {
plent->meta.genre = roar_meta_intgenre(*value);
} else if ( !strcmp(name, META_BASE_URL_STATIC("likeness")) ) {
plent->likeness = atof(*value);
} else if ( !strcmp(name, META_BASE_URL_STATIC("codec")) ) {
plent->codec = roar_str2codec(*value);
}
}
static void ff_xspf_pl_import_track(struct rpld_playlist * pl, xmlNode * track) {
struct rpld_playlist_entry * plent = rpld_ple_new();
int uuid_set = 0;
char buf[RPLD_MAX_PLF_LEN+64];
xmlNode * element;
const char * name;
const char * value;
char * dst;
size_t dst_len;
int tmp;
if ( plent == NULL )
return;
for (element = track->children; element != NULL; element = element->next) {
if ( element->type != XML_ELEMENT_NODE )
continue;
dst = NULL;
dst_len = 0;
name = (const char * /* libxml2 cast-hell */) element->name;
value = (const char * /* libxml2 cast-hell */) xmlNodeGetContent(element);
if (!strcmp(name, "location")) {
// TODO.
if ( !uuid_set && !strncmp(value, "tantalos://", 11) ) {
// For error checking see below.
value += 11;
roar_str2uuid(plent->uuid, value);
uuid_set = 1;
}
// Very ugly workaround as libxml2 has bad docs.
// Prey this will never explode.
if ( strlen(value) < (sizeof(buf)-1) ) {
(void)xmlURIUnescapeString(value, -1, buf);
buf[sizeof(buf)-1] = 0;
rpld_ple_push_filename(plent, buf, RPLD_TYPE_UNKNOWN, 0);
}
} else if (!strcmp(name, "identifier")) {
if ( !strncmp(value, "tantalos://", 11) ) {
value += 11;
// We can ignore errors here as uuid_parse() does not alter the UUID if parsing failed.
// This is the documented behavior. Hope nobody will break it somewhen...
roar_str2uuid(plent->uuid, value);
uuid_set = 1;
}
} else if (!strcmp(name, "title")) {
dst = plent->meta.title;
dst_len = sizeof(plent->meta.title);
} else if (!strcmp(name, "creator")) {
dst = plent->meta.artist;
dst_len = sizeof(plent->meta.artist);
} else if (!strcmp(name, "album")) {
dst = plent->meta.album;
dst_len = sizeof(plent->meta.album);
} else if (!strcmp(name, "trackNum")) {
if ( sscanf(value, "%d", &tmp) == 1 ) {
plent->meta.tracknum = tmp;
}
} else if (!strcmp(name, "duration")) {
if ( sscanf(value, "%d", &tmp) == 1 ) {
plent->length = tmp / 1000;
}
} else if (!strcmp(name, "meta")) {
ff_xspf_pl_import_track_parse_meta(plent, &dst, &dst_len, &value, element);
#if 0
// The following is not relevant for us.
} else if (!strcmp(name, "extension")) {
} else if (!strcmp(name, "link")) {
} else if (!strcmp(name, "annotation")) {
} else if (!strcmp(name, "info")) {
} else if (!strcmp(name, "image")) {
#endif
}
if ( dst != NULL ) {
ROAR_DBG("ff_xspf_pl_import_track(pl=%p, track=%p): Copy '%s' to %p (element type: %s).", pl, track, value, dst, name);
strncpy(dst, value, dst_len);
dst[dst_len-1] = 0;
} else {
ROAR_DBG("ff_xspf_pl_import_track(pl=%p, track=%p): no data to copy (element type: %s).", pl, track, name);
}
}
rpld_pl_push(pl, plent);
}
int ff_xspf_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) {
xmlDoc * doc;
xmlNode * main_element;
xmlNode * playlist_element;
xmlNode * tracklist_element;
(void)handle;
doc = xmlReadIO(ff_xspf_read, NULL, vio, "__dummy.xspf", NULL, XML_PARSE_RECOVER);
if ( doc == NULL )
return -1;
for (main_element = doc->children; main_element != NULL; main_element = main_element->next) {
if ( main_element->type != XML_ELEMENT_NODE )
continue;
if ( !!xmlStrcmp(main_element->name, (xmlChar *)"playlist") )
continue;
for (playlist_element = main_element->children; playlist_element != NULL; playlist_element = playlist_element->next) {
if ( playlist_element->type != XML_ELEMENT_NODE )
continue;
if ( !!xmlStrcmp(playlist_element->name, (xmlChar *)"trackList") )
continue;
for (tracklist_element = playlist_element->children; tracklist_element != NULL; tracklist_element = tracklist_element->next) {
if ( tracklist_element->type != XML_ELEMENT_NODE )
continue;
if ( !!xmlStrcmp(tracklist_element->name, (xmlChar *)"track") )
continue;
ff_xspf_pl_import_track(pl, tracklist_element);
}
}
}
xmlFreeDoc(doc);
return 0;
}
#endif
//ll
rpld-0.1.9/fformat.c 0000644 0001750 0001750 00000012337 12266574304 012425 0 ustar phi phi //fformat.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
static struct {
int id;
const char * name;
const char * ext;
} ff_plf[] = {
{RPLD_FF_PLF_RPLD, "rpld", "rpldpl"},
{RPLD_FF_PLF_VCLT, "vclt", "vclt" },
{RPLD_FF_PLF_PLS, "pls", "pls" },
{RPLD_FF_PLF_M3U, "m3u", "m3u" },
{RPLD_FF_PLF_XSPF, "xspf", "xspf" },
{RPLD_FF_PLF_PLAIN, "plain", NULL },
{RPLD_FF_PLF_URAS, "uras", "xml" },
{-1, NULL, NULL}
};
int fformat_str2plf(const char * str) {
int i;
if ( str == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
for (i = 0; ff_plf[i].id != -1; i++)
if ( !strcasecmp(str, ff_plf[i].name) )
return ff_plf[i].id;
roar_err_set(ROAR_ERROR_NOENT);
return -1;
}
const char * fformat_plf2str(int plf) {
int i;
for (i = 0; ff_plf[i].id != -1; i++)
if ( ff_plf[i].id == plf )
return ff_plf[i].name;
roar_err_set(ROAR_ERROR_NOENT);
return NULL;
}
static struct {
int format;
int (*open) (struct fformat_handle * handle);
void (*close )(struct fformat_handle * handle);
int (*pl_export)(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int (*pl_import)(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int (*pl_update)(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
} ff_handles[] = {
{RPLD_FF_PLF_VCLT, NULL, NULL, ff_vclt_pl_export, ff_vclt_pl_import, NULL},
{RPLD_FF_PLF_PLAIN, NULL, NULL, ff_plain_pl_export, ff_plain_pl_import, NULL},
{RPLD_FF_PLF_M3U, NULL, NULL, ff_m3u_pl_export, ff_m3u_pl_import, NULL},
{RPLD_FF_PLF_RPLD, NULL, NULL, ff_rpld_pl_export, ff_rpld_pl_import, NULL},
{RPLD_FF_PLF_PLS, NULL, NULL, ff_pls_pl_export, NULL, NULL},
#ifdef HAVE_LIB_XML2
{RPLD_FF_PLF_XSPF, NULL, NULL, ff_xspf_pl_export, ff_xspf_pl_import, NULL},
{RPLD_FF_PLF_URAS, NULL, NULL, ff_uras_pl_export, ff_uras_pl_import, NULL},
#endif
{-1, NULL, NULL, NULL, NULL, NULL}
};
struct fformat_handle * fformat_handle_new(int format) {
struct fformat_handle * ret;
int i;
for (i = 0; ff_handles[i].format != -1; i++) {
if ( ff_handles[i].format == format ) {
if ( (ret = roar_mm_malloc(sizeof(struct fformat_handle))) == NULL )
return NULL;
memset(ret, 0, sizeof(struct fformat_handle));
ret->format = format;
ret->table_id = i;
if ( ff_handles[i].open != NULL ) {
if ( ff_handles[i].open(ret) == -1 ) {
roar_mm_free(ret);
return NULL;
}
}
return ret;
}
}
return NULL;
}
void fformat_handle_close(struct fformat_handle * handle) {
if ( handle == NULL )
return;
if ( ff_handles[handle->table_id].close != NULL ) {
ff_handles[handle->table_id].close(handle);
}
roar_mm_free(handle);
}
int fformat_playlist_export(struct fformat_handle * handle,
struct roar_vio_calls * vio,
struct rpld_playlist * pl) {
if ( ff_handles[handle->table_id].pl_export == NULL )
return -1;
return ff_handles[handle->table_id].pl_export(handle, vio, pl);
}
int fformat_playlist_import(struct fformat_handle * handle,
struct roar_vio_calls * vio,
struct rpld_playlist * pl) {
struct rpld_playlist * tmp_pl;
int ret;
if ( ff_handles[handle->table_id].pl_import == NULL ) {
roar_err_set(ROAR_ERROR_NOTSUP);
return -1;
}
tmp_pl = rpld_pl_new();
if ( tmp_pl == NULL )
return -1;
yield_watchdog_stop();
yield_auto(RPLD_YIELD_START, RPLD_YIELD_TASK_PLAYBACK, RPLD_YIELD_TASK_NETWORK, RPLD_YIELD_NONBLOCK);
ret = ff_handles[handle->table_id].pl_import(handle, vio, tmp_pl);
yield_auto(RPLD_YIELD_STOP, RPLD_YIELD_TASK_PLAYBACK, RPLD_YIELD_TASK_NETWORK, RPLD_YIELD_NONBLOCK);
yield_watchdog_start();
if ( ret == 0 ) {
ret = rpld_pl_merge(pl, tmp_pl);
}
if ( ret == -1 ) {
rpld_pl_unref(tmp_pl);
}
return ret;
}
int fformat_playlist_update(struct fformat_handle * handle,
struct roar_vio_calls * vio,
struct rpld_playlist * pl) {
if ( ff_handles[handle->table_id].pl_update == NULL )
return -1;
return ff_handles[handle->table_id].pl_update(handle, vio, pl);
}
//ll
rpld-0.1.9/fformat.h 0000644 0001750 0001750 00000007422 12266574304 012431 0 ustar phi phi //fformat.h:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef _RPLD_FFORMAT_H_
#define _RPLD_FFORMAT_H_
#define RPLD_FF_PLF_NONE 0
#define RPLD_FF_PLF_RPLD 1
#define RPLD_FF_PLF_VCLT 2
#define RPLD_FF_PLF_PLS 3
#define RPLD_FF_PLF_M3U 4
#define RPLD_FF_PLF_XSPF 5
#define RPLD_FF_PLF_PLAIN 6
#define RPLD_FF_PLF_URAS 7
#define RPLD_FF_PLF_DEFAULT RPLD_FF_PLF_VCLT
struct fformat_handle {
int format;
int table_id;
};
int fformat_str2plf(const char * str);
const char * fformat_plf2str(int plf);
struct fformat_handle * fformat_handle_new(int format);
void fformat_handle_close(struct fformat_handle * handle);
int fformat_playlist_export(struct fformat_handle * handle,
struct roar_vio_calls * vio,
struct rpld_playlist * pl);
int fformat_playlist_import(struct fformat_handle * handle,
struct roar_vio_calls * vio,
struct rpld_playlist * pl);
int fformat_playlist_update(struct fformat_handle * handle,
struct roar_vio_calls * vio,
struct rpld_playlist * pl);
// prototypes for ff_*.c:
int ff_vclt_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_vclt_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_plain_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_plain_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_m3u_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_m3u_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_rpld_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_rpld_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_pls_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_pls_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_xspf_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_xspf_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_uras_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
int ff_uras_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl);
#endif
//ll
rpld-0.1.9/man-symlinks.src 0000644 0001750 0001750 00000000661 11757750155 013757 0 ustar phi phi rpld-ctl 1 rpld-tools 1
rpld-next 1 rpld-tools 1
rpld-listq 1 rpld-tools 1
rpld-import 1 rpld-tools 1
rpld-listplaylists 1 rpld-tools 1
rpld-queueple 1 rpld-tools 1
rpld-setpointer 1 rpld-tools 1
rpld-showplaying 1 rpld-tools 1
rpld-play 1 rpld-deprecated 1
rpld-prev 1 rpld-deprecated 1
rpld-stop 1 rpld-deprecated 1
rpld-store 1 rpld-deprecated 1
rpld-addplaylist 1 rpld-deprecated 1
rpld-delplaylist 1 rpld-deprecated 1
rpld-0.1.9/network.c 0000644 0001750 0001750 00000015066 12266574304 012462 0 ustar phi phi //network.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
#include
#include
#endif
#define _AS(x) (sizeof((x))/sizeof(*(x)))
static struct {
struct roar_vio_calls sock;
int proto;
const char * server;
enum rpld_client_acclev acclev;
} g_listen[RPLD_MAX_LISTEN];
int network_preinit(void) {
size_t i;
memset(g_listen, 0, sizeof(g_listen));
for (i = 0; i < _AS(g_listen); i++)
g_listen[i].proto = RPLD_PROTO_UNUSED;
return 0;
}
int network_add_server(const char * server, int port, int type, int proto, enum rpld_client_acclev acclev) {
char unixpath_buf[128];
size_t id;
if ( acclev == ACCLEV_ERR )
return -1;
for (id = 0; id < _AS(g_listen); id++)
if ( g_listen[id].proto == RPLD_PROTO_UNUSED )
break;
if ( id == _AS(g_listen) )
return -1;
if ( type == -1 ) {
type = ROAR_SOCKET_TYPE_UNKNOWN;
}
if ( type == ROAR_SOCKET_TYPE_UNKNOWN && server == NULL && port == -1 ) {
#ifdef ROAR_HAVE_UNIX
type = ROAR_SOCKET_TYPE_UNIX;
#elif defined(ROAR_HAVE_IPV4)
type = ROAR_SOCKET_TYPE_TCP;
#elif defined(ROAR_HAVE_LIBDNET)
type = ROAR_SOCKET_TYPE_DECNET;
#else
ROAR_ERR("network_add_server(*): Can not find any working default address familiy.");
return -1;
#endif
}
switch (type) {
case ROAR_SOCKET_TYPE_UNIX:
if ( server == NULL ) {
if ( roar_env_render_path_r(unixpath_buf, sizeof(unixpath_buf), RPLD_SOCKNAME_UNIX) != -1 ) {
server = unixpath_buf;
} else {
server = RPLD_SOCKNAME_UNIX_FALLBACK;
}
}
break;
case ROAR_SOCKET_TYPE_TCP:
if ( server == NULL )
server = RPLD_SOCKNAME_TCP;
if ( port == -1 )
port = RPLD_PORT;
case ROAR_SOCKET_TYPE_DECNET:
if ( server == NULL )
server = RPLD_SOCKNAME_DECNET;
if ( port == -1 )
port = 0;
break;
}
// TODO: FIXME: this code unlinks sockets that are aktive:
if ( roar_vio_open_socket_listen(&(g_listen[id].sock), type, server, port) == -1 ) {
if ( type == ROAR_SOCKET_TYPE_UNIX ) {
unlink(server);
if ( roar_vio_open_socket_listen(&(g_listen[id].sock), type, server, port) == -1 )
return -1;
}
}
#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
if ( type == ROAR_SOCKET_TYPE_UNIX ) {
if ( g_pwd != NULL || g_grp != NULL ) {
if ( chown(server, g_pwd != NULL ? g_pwd->pw_uid : (uid_t)-1, g_grp != NULL ? g_grp->gr_gid : (gid_t)-1) == -1 ) {
ROAR_WARN("Can not change ownership of socket: %s: %s", server, strerror(errno));
}
}
if ( chmod(server, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 ) {
ROAR_WARN("Can not change permissions of socket: %s: %s", server, strerror(errno));
}
}
#endif
g_listen[id].proto = proto;
g_listen[id].server = server;
g_listen[id].acclev = acclev;
return 0;
}
int network_init(void) {
return 0;
}
void network_uninit(void) {
size_t id;
for (id = 0; id < _AS(g_listen); id++) {
if ( g_listen[id].proto != RPLD_PROTO_UNUSED )
roar_vio_close(&(g_listen[id].sock));
if ( g_listen[id].server != NULL )
unlink(g_listen[id].server);
}
for (id = 0; id < RPLD_CLIENTS_MAX; id++) {
client_delete(id);
}
}
#define NUM_VIOS (RPLD_CLIENTS_MAX + RPLD_MAX_LISTEN)
void network_check(int block) {
struct roar_vio_selecttv tv;
struct roar_vio_select vios[NUM_VIOS];
struct roar_vio_calls * vio;
int id;
int i;
int clientid;
size_t num = 0;
size_t min_client;
ROAR_DBG("network_check(block=%i) = ?", block);
tv.sec = 0;
switch (block) {
case RPLD_YIELD_NONBLOCK:
tv.nsec = 32000;
break;
case RPLD_YIELD_BLOCK:
tv.nsec = 1024000;
break;
case RPLD_YIELD_LONGBLOCK:
tv.sec = 3600;
tv.nsec = 0;
break;
default:
tv.nsec = 1024000;
break;
}
ROAR_DBG("num=%lu", (unsigned long int)num);
for (i = 0; i < (int)_AS(g_listen); i++) {
if ( g_listen[i].proto == RPLD_PROTO_UNUSED )
continue;
vios[num].ud.si = i;
ROAR_VIO_SELECT_SETVIO(&(vios[num]), &(g_listen[i].sock), ROAR_VIO_SELECT_READ);
num++;
}
// ROAR_DBG("(int)(vios[0].vio->inst) = %i", (int)(vios[0].vio->inst));
ROAR_DBG("num=%lu", (unsigned long int)num);
min_client = num;
for (id = 0; id < RPLD_CLIENTS_MAX; id++) {
if ( (vio = client_get_vio(id)) != NULL ) {
vios[num].ud.si = id;
ROAR_VIO_SELECT_SETVIO(&(vios[num]), vio, client_get_eventsq(id));
num++;
}
}
ROAR_DBG("num=%lu", (unsigned long int)num);
if ( num == 0 ) {
rpld_exit();
return;
}
if ( block != RPLD_YIELD_NONBLOCK )
yield_watchdog_stop();
if ( roar_vio_select(vios, num, &tv, NULL) < 1 ) {
if ( block != RPLD_YIELD_NONBLOCK )
yield_watchdog_start();
ROAR_DBG("network_check(block=%i) = (void)", block);
return;
}
if ( block != RPLD_YIELD_NONBLOCK )
yield_watchdog_start();
// first handle clients so new clients may not break the list
for (i = min_client; i < NUM_VIOS && i < (int)num; i++) {
if ( vios[i].eventsa & (ROAR_VIO_SELECT_READ|ROAR_VIO_SELECT_WRITE) ) {
ROAR_DBG("network_check(block=%i): vios[i=%i].ud.si = %i", block, i, vios[i].ud.si);
// handle client
if ( client_handle(vios[i].ud.si, vios[i].eventsa) == -1 )
client_delete(vios[i].ud.si);
}
}
for (i = 0; i < (int)min_client && i < (int)num; i++) {
if ( !(vios[i].eventsa & ROAR_VIO_SELECT_READ) )
continue;
// handle listen socket
if ( (clientid = client_new(&vio)) == -1 ) {
continue;
}
if ( roar_vio_accept(vio, &(g_listen[vios[i].ud.si].sock)) == -1 ) {
roar_vio_clear_calls(vio);
client_delete(clientid);
continue;
}
if ( client_set_proto(clientid, g_listen[i].proto) == -1 ) {
client_delete(clientid);
}
if ( client_set_acclev(clientid, g_listen[i].acclev, -1) == -1 ) {
client_delete(clientid);
}
}
ROAR_DBG("network_check(block=%i) = (void)", block);
}
//ll
rpld-0.1.9/network.h 0000644 0001750 0001750 00000002702 12266574304 012460 0 ustar phi phi //network.h:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef _RPLD_NETWORK_H_
#define _RPLD_NETWORK_H_
#define RPLD_SOCKNAME_UNIX "~/.rpld"
#define RPLD_SOCKNAME_UNIX_FALLBACK "/tmp/.rpld"
#define RPLD_SOCKNAME_TCP "localhost"
#define RPLD_SOCKNAME_DECNET "::rpld"
#define RPLD_SOCKNAME RPLD_SOCKNAME_UNIX
#define RPLD_PORT 24148
#define RPLD_MAX_LISTEN 4
int network_preinit(void);
int network_add_server(const char * server, int port, int type, int proto, enum rpld_client_acclev acclev);
int network_init(void);
void network_uninit(void);
void network_check(int block);
#endif
//ll
rpld-0.1.9/playback.c 0000644 0001750 0001750 00000065567 12266574304 012572 0 ustar phi phi //playback.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
static struct rpld_queue * _get_queue(pli_t queue, struct rpld_playlist ** playlist) {
struct rpld_playlist * pl = rpld_pl_get_by_id(queue);
if ( pl == NULL ) {
roar_err_set(ROAR_ERROR_NOENT);
return NULL;
}
if ( pl->queue == NULL ) {
rpld_pl_unref(pl);
roar_err_set(ROAR_ERROR_TYPEMM);
return NULL;
}
*playlist = pl;
return pl->queue;
}
int playback_preinit(void) {
return 0;
}
int playback_init(void) {
ROAR_DBG("playback_init() = ?");
if ( playback_preinit() == -1 )
return -1;
ROAR_DBG("playback_init() = 0");
return 0;
}
void playback_uninit(void) {
size_t i;
for (i = 0; i < MAX_PLAYLISTS; i++) {
if ( g_playlists[i] == NULL )
continue;
if ( g_playlists[i]->queue == NULL )
continue;
playback_stop(g_playlists[i]->id, 0, 1);
}
}
void playback_set_role(pli_t queue, const int role) {
struct rpld_playlist * pl;
struct rpld_queue * plq = _get_queue(queue, &pl);
if ( plq == NULL )
return;
roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_ROLE, -1, queue, -1, role, -1, NULL, -1);
plq->role = role;
if ( !plq->playing ) {
rpld_pl_unref(pl);
return;
}
// set role on running stream:
if ( roar_stream_set_role(&(plq->backend->con),
&(plq->stream),
plq->role) == -1 ) {
ROAR_WARN("playback_set_role(queue=%i, role=%i): Can not set role for new stream to %s",
(int)queue, role, roar_role2str(plq->role));
}
rpld_pl_unref(pl);
}
struct roar_audio_info * playback_get_codechelper_info(void) {
static struct roar_audio_info ret = {
.rate = ROAR_RATE_DEFAULT,
.bits = ROAR_BITS_DEFAULT,
.channels = ROAR_CHANNELS_DEFAULT,
.codec = ROAR_CODEC_DEFAULT
};
return &ret;
}
static void _handle_queue_io(pli_t queue, struct rpld_queue * plq) {
char buf[2*1024];
ssize_t len;
int is_playing;
if ( (len = roar_vio_read(plq->io.fp, buf, sizeof(buf))) < 1 ) {
if ( len == -1 && roar_error == ROAR_ERROR_AGAIN )
return;
is_playing = playback_is_playing(queue);
playback_stop(queue, 0, 0);
playback_next(queue);
if ( is_playing )
playback_play(queue);
return;
}
if ( roar_vio_write(&(plq->io.stream), buf, len) != len ) {
is_playing = playback_is_playing(queue);
playback_stop(queue, 0, 0);
playback_next(queue);
if ( is_playing )
playback_play(queue);
return;
}
}
void playback_check(int block) {
struct roar_vio_select vioset[3*(MAX_PLAYLISTS/2)]; // we need 3 handles per queue
// and guess we have a max of MAX_PLAYLISTS/2 queues.
struct rpld_queue * plq;
struct rpld_playlist * pl;
struct roar_vio_selecttv tv;
size_t i;
size_t count = 0;
int is_playing = 0;
size_t left_handles = 0;
#ifdef ROAR_TARGET_WIN32
if ( block == RPLD_YIELD_NONBLOCK ) {
// we do not support non-blocking checks as win32 is totally broken. See below.
return;
}
#endif
if ( block == RPLD_YIELD_NONBLOCK ) {
block = 0;
} else {
block = 1;
}
for (i = 0; i < MAX_PLAYLISTS; i++) {
pl = g_playlists[i];
if ( pl == NULL )
continue;
plq = pl->queue;
if ( plq == NULL )
continue;
if ( !plq->playing )
continue;
ROAR_VIO_SELECT_SETVIO(&(vioset[count]), &(plq->io.stream), ROAR_VIO_SELECT_WRITE);
vioset[count].ud.vp = pl;
count++;
ROAR_VIO_SELECT_SETVIO(&(vioset[count]), plq->io.fp, ROAR_VIO_SELECT_READ);
vioset[count].ud.vp = pl;
count++;
left_handles += 2;
if ( plq->io.fp == &(plq->io.file) ) {
ROAR_VIO_SELECT_SETVIO(&(vioset[count]), &(plq->io.file), ROAR_VIO_SELECT_NONE|ROAR_VIO_SELECT_NO_RETEST);
} else {
ROAR_VIO_SELECT_SETVIO(&(vioset[count]), &(plq->io.file), ROAR_VIO_SELECT_READ);
left_handles++;
}
vioset[count].ud.vp = pl;
count++;
is_playing = 1;
}
if ( is_playing ) {
tv.sec = 0;
tv.nsec = 32*1000;
yield_watchdog_trigger();
if ( roar_vio_select(vioset, count, &tv, NULL) == -1 )
return;
yield_watchdog_trigger();
for (i = 0; i < count; i++) {
if ( vioset[i].eventsa & vioset[i].eventsq ) {
vioset[i].eventsq |= ROAR_VIO_SELECT_NO_RETEST;
left_handles--;
}
}
tv.sec = 0;
if ( block ) {
tv.nsec = 10*1000*1000;
} else {
tv.nsec = 32*1000;
}
ROAR_DBG("playback_check(void) = ?");
ROAR_DBG("playback_check(void) = ?");
yield_watchdog_trigger();
// if we have less than one handle we can not do anything anyway so we just return.
ROAR_DBG("playback_check(void) = ?");
if ( left_handles )
if ( roar_vio_select(vioset, count, &tv, NULL) == -1 )
return;
ROAR_DBG("playback_check(void) = ?");
yield_watchdog_trigger();
for (i = 0; i < count; i += 3) {
if ( !(vioset[i+0].eventsa & ROAR_VIO_SELECT_WRITE) )
continue;
if ( !(vioset[i+1].eventsa & ROAR_VIO_SELECT_READ) && !(vioset[i+2].eventsa & ROAR_VIO_SELECT_READ) )
continue;
pl = vioset[i].ud.vp;
_handle_queue_io(pl->id, pl->queue);
}
ROAR_DBG("playback_check(void) = ?");
} else {
ROAR_DBG("playback_check(void) = ?");
roar_usleep(10000);
}
ROAR_DBG("playback_check(void) = (void)");
}
#if defined(HAVE_FUNC_UALARM) && defined(HAVE_FUNC_SIGINTERRUPT)
static void _sighandler_dummy(int sig) {
(void)sig;
}
#endif
int playback_add_queue(struct rpld_playlist * pl, const char * backend, int mixer, struct rpld_playlist * history) {
struct rpld_queue * queue;
int err;
if ( pl == NULL || history == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
if ( pl->queue != NULL ) {
roar_err_set(ROAR_ERROR_BUSY);
return -1;
}
queue = roar_mm_malloc(sizeof(*queue));
if ( queue == NULL )
return -1;
memset(queue, 0, sizeof(*queue));
queue->refc = 1;
queue->playing = 0;
queue->role = ROAR_ROLE_MUSIC;
queue->volume_mono = 65535;
queue->ple_mduc = 0;
queue->mixer = mixer;
queue->history = history;
queue->backend = backend_get_connection(backend);
if ( queue->backend == NULL ) {
err = roar_error;
roar_mm_free(queue);
roar_error = err;
return -1;
}
rpld_pl_ref(history);
pl->queue = queue;
return 0;
}
int playback_del_queue(struct rpld_playlist * pl) {
struct rpld_queue * plq;
if ( pl == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
if ( (plq = pl->queue) == NULL ) {
roar_err_set(ROAR_ERROR_TYPEMM);
return -1;
}
if ( plq->playing )
if ( playback_stop(rpld_pl_get_id(pl), 0, 1) == -1 )
return -1;
pl->queue = NULL;
rpld_pl_unref(plq->history);
backend_unref(plq->backend);
roar_mm_free(plq);
return 0;
}
int playback_has_queue(pli_t queue) {
struct rpld_playlist * pl = rpld_pl_get_by_id(queue);
int ret;
if ( pl == NULL )
return -1;
ret = pl->queue == NULL ? 0 : 1;
rpld_pl_unref(pl);
return ret;
}
int playback_set_pointer(pli_t queue, int pointer, struct rpld_playlist_pointer * plp) {
struct rpld_playlist * pl = rpld_pl_get_by_id(queue);
struct rpld_playlist_pointer ** cpointer;
if ( pl == NULL )
return -1;
if ( pl->queue == NULL ) {
rpld_pl_unref(pl);
roar_err_set(ROAR_ERROR_TYPEMM);
return -1;
}
switch (pointer) {
case POINTER_DEFAULT:
cpointer = &(pl->queue->pointers.defaultptr);
break;
case POINTER_CURRENT:
cpointer = &(pl->queue->pointers.currentptr);
break;
case POINTER_STARTUP:
cpointer = &(pl->queue->pointers.startupptr);
break;
case POINTER_FALLBACK:
cpointer = &(pl->queue->pointers.fallbackptr);
break;
default:
rpld_pl_unref(pl);
roar_err_set(ROAR_ERROR_INVAL);
return -1;
break;
}
if ( *cpointer != NULL ) {
rpld_plp_unref(*cpointer);
*cpointer = NULL;
}
*cpointer = plp;
if ( plp != NULL )
rpld_plp_ref(plp);
rpld_pl_unref(pl);
return 0;
}
struct rpld_playlist_pointer * playback_get_pointer(pli_t queue, int pointer) {
struct rpld_playlist * pl = rpld_pl_get_by_id(queue);
struct rpld_playlist_pointer * ret = NULL;
if ( pl == NULL )
return NULL;
if ( pl->queue == NULL ) {
rpld_pl_unref(pl);
roar_err_set(ROAR_ERROR_TYPEMM);
return NULL;
}
switch (pointer) {
case POINTER_DEFAULT:
ret = pl->queue->pointers.defaultptr;
break;
case POINTER_CURRENT:
ret = pl->queue->pointers.currentptr;
break;
case POINTER_STARTUP:
ret = pl->queue->pointers.startupptr;
break;
case POINTER_FALLBACK:
ret = pl->queue->pointers.fallbackptr;
break;
default:
roar_err_set(ROAR_ERROR_INVAL);
break;
}
rpld_pl_unref(pl);
if ( ret == NULL ) {
roar_err_set(ROAR_ERROR_NOENT);
} else {
rpld_plp_ref(ret);
}
return ret;
}
void playback_play_all(void) {
size_t i;
roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_PLAY, -1, -1, -1, -1, -1, NULL, -1);
for (i = 0; i < MAX_PLAYLISTS; i++) {
if ( g_playlists[i] == NULL )
continue;
if ( g_playlists[i]->queue == NULL )
continue;
playback_play(rpld_pl_get_id(g_playlists[i]));
}
}
void playback_stop_all(size_t offset, int kick) {
size_t i;
roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_STOP, -1, -1, -1, offset, kick, NULL, -1);
for (i = 0; i < MAX_PLAYLISTS; i++) {
if ( g_playlists[i] == NULL )
continue;
if ( g_playlists[i]->queue == NULL )
continue;
playback_stop(rpld_pl_get_id(g_playlists[i]), offset, kick);
}
}
int playback_is_playing_any(void) {
size_t i;
for (i = 0; i < MAX_PLAYLISTS; i++) {
if ( g_playlists[i] == NULL )
continue;
if ( g_playlists[i]->queue == NULL )
continue;
if ( playback_is_playing(rpld_pl_get_id(g_playlists[i])) )
return 1;
}
return 0;
}
int playback_play(pli_t queue) {
struct rpld_playlist * pl = rpld_pl_get_by_id(queue);
struct roar_audio_info * codechelper_info = playback_get_codechelper_info();
struct rpld_playlist_entry * plent;
int codec;
ssize_t magic_len = 0;
char magic[64];
const char * content_type;
struct rpld_queue * plq;
const char * filename = NULL;
ssize_t filenamecount;
ssize_t i;
int err;
int ret;
ROAR_DBG("playback_play(void) = ?");
if ( pl == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
if ( (plq = pl->queue) == NULL ) {
rpld_pl_unref(pl);
roar_err_set(ROAR_ERROR_TYPEMM);
return -1;
}
if ( plq->playing ) {
rpld_pl_unref(pl);
return 0;
}
if ( !(plq->backend->flags & BACKEND_FLAG_CONNECTED) ) {
rpld_pl_unref(pl);
roar_err_set(ROAR_ERROR_NOTCONN);
return -1;
}
ROAR_DBG("playback_play(void) = ?");
if ( (plent = rpld_pl_get_first(pl)) == NULL ) {
// retry with autoqueue
if ( autoqueue(queue) == -1 ) {
rpld_pl_unref(pl);
return -1;
}
if ( (plent = rpld_pl_get_first(pl)) == NULL ) {
rpld_pl_unref(pl);
return -1;
}
}
ROAR_DBG("playback_play(void) = ?");
filenamecount = rpld_ple_num_filename(plent);
ret = -1;
err = ROAR_ERROR_NOENT;
ROAR_DBG("playback_play(void) = ?");
for (i = 0; ret == -1 && i < filenamecount; i++) {
filename = rpld_ple_get_filename(plent, i, NULL);
if ( filename == NULL ) {
err = roar_error;
continue;
}
yield_auto(RPLD_YIELD_PAUSE, 0, 0, 0);
#if defined(HAVE_FUNC_UALARM) && defined(HAVE_FUNC_SIGINTERRUPT)
//signal(SIGALRM, SIG_IGN);
signal(SIGALRM, _sighandler_dummy);
siginterrupt(SIGALRM, 0);
ualarm(1000*1000, 0);
#endif
ret = roar_vio_open_dstr_simple(&(plq->io.file), filename, ROAR_VIOF_READ|ROAR_VIOF_NONBLOCK);
err = roar_error;
yield_auto(RPLD_YIELD_UNPAUSE, 0, 0, 0);
}
if ( ret == -1 ) {
rpld_pl_unref(pl);
roar_err_set(err);
ROAR_WARN("playback_play(void): Can not open file: %s: %s", filename, roar_error2str(roar_error));
return -1;
}
ROAR_DBG("playback_play(void) = ?");
plq->io.fp = &(plq->io.file);
/* TODO: FIXME: do a better check for streams than checking for :// ! */
// try to guess the type by magic.
if ( (codec = plent->codec) == -1 && strstr(filename, "://") == NULL ) {
if ( (magic_len = roar_vio_read(&(plq->io.file), magic, 64)) < 1 ) {
err = roar_error;
roar_vio_close(&(plq->io.file));
rpld_pl_unref(pl);
roar_err_set(err);
return -1;
}
codec = roar_file_codecdetect(magic, magic_len);
if ( codec == -1 ) {
if ( roar_vio_lseek(&(plq->io.file), 0, SEEK_SET) == (off_t)-1 ) {
err = roar_error;
roar_vio_close(&(plq->io.file));
rpld_pl_unref(pl);
roar_err_set(err);
return -1;
}
}
}
ROAR_DBG("playback_play(void): codec=%i", codec);
// try to read the magic from filesystem or stream headers.
if ( codec == -1 ) {
if ( roar_vio_ctl(&(plq->io.file), ROAR_VIO_CTL_GET_MIMETYPE, &content_type) != -1 ) {
codec = roar_mime2codec(content_type);
}
}
ROAR_DBG("playback_play(void): codec=%i", codec);
// test if we need the codec helper for this kind of stream.
if ( backend_blacklist_check_codec(plq->backend, codec) ) {
codec = -1;
}
// open stream...
if ( codec != -1 ) {
if ( roar_vio_simple_new_stream_obj(&(plq->io.stream),
&(plq->backend->con),
&(plq->stream),
ROAR_RATE_DEFAULT, ROAR_CHANNELS_DEFAULT, ROAR_BITS_DEFAULT,
codec, ROAR_DIR_PLAY, plq->mixer
) == -1 ) {
ROAR_DBG("playback_play(void): codec=%i->-1", codec);
codec = -1; // we try the helper in case roard does not know about this codec...
}
}
ROAR_DBG("playback_play(void): codec=%i", codec);
if ( codec == -1 ) {
if ( roar_vio_simple_new_stream_obj(&(plq->io.stream),
&(plq->backend->con),
&(plq->stream),
codechelper_info->rate, codechelper_info->channels,
codechelper_info->bits, codechelper_info->codec,
ROAR_DIR_PLAY, plq->mixer
) == -1 ) {
err = roar_error;
roar_vio_close(&(plq->io.file));
rpld_pl_unref(pl);
roar_err_set(err);
ROAR_DBG("playback_play(void) = -1");
return -1;
}
}
ROAR_DBG("playback_play(void) = ?");
if ( codec == -1 ) {
if ( roar_vio_open_cmd(&(plq->io.filter), &(plq->io.file),
"rpld-codec-helper", NULL,
0) == -1 ) {
err = roar_error;
roar_vio_close(&(plq->io.file));
roar_vio_close(&(plq->io.stream));
rpld_pl_unref(pl);
roar_err_set(err);
ROAR_DBG("playback_play(void) = -1");
return -1;
}
plq->io.fp = &(plq->io.filter);
} else {
if ( magic_len > 0 ) {
if ( roar_vio_write(&(plq->io.stream), magic, magic_len) != magic_len ) {
err = roar_error;
roar_vio_close(&(plq->io.file));
roar_vio_close(&(plq->io.stream));
rpld_pl_unref(pl);
roar_err_set(err);
ROAR_DBG("playback_play(void) = -1");
return -1;
}
}
}
ROAR_DBG("playback_play(void) = ?");
memcpy(&(plq->ple), plent, sizeof(plq->ple));
plq->ple_mduc = 1;
plq->playing = 1;
roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_PLAY, -1, queue, -1, -1, -1, NULL, -1);
// set rpg data:
// only set in case non-default parameters are requested.
if ( plent->rpg.mode != ROAR_RPGMODE_DEFAULT ) {
if ( roar_stream_set_rpg(&(plq->backend->con), &(plq->stream), &(plent->rpg)) == -1 ) {
ROAR_WARN("playback_play(queue=%u): Can not set RPG settings: %s", (unsigned)queue, roar_errorstring);
}
}
// set role for new stream:
playback_set_role(queue, plq->role);
// set volume for next track:
playback_set_volume(queue);
rpld_pl_unref(pl);
ROAR_DBG("playback_play(void) = 0");
return 0;
}
int playback_next(pli_t queue) {
struct rpld_playlist * pl = rpld_pl_get_by_id(queue);
struct rpld_queue * plq;
struct rpld_playlist_entry * old;
int was_playing;
ssize_t histsize;
// we implement this by stoping the current song,
// hoping to the next and restart playing if we was playing.
if ( pl == NULL )
return -1;
if ( (plq = pl->queue) == NULL ) {
rpld_pl_unref(pl);
roar_err_set(ROAR_ERROR_TYPEMM);
return -1;
}
roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_NEXT, -1, queue, -1, -1, -1, NULL, -1);
was_playing = plq->playing;
if ( playback_stop(queue, 0, 1) == -1 ) {
rpld_pl_unref(pl);
return -1;
}
// get next element, if there is none try autoqueue.
if ( (old = rpld_pl_shift(pl)) == NULL )
if ( autoqueue(queue) != -1 )
old = rpld_pl_shift(pl);
if ( old != NULL ) {
rpld_pl_add(plq->history, old, -1);
histsize = rpld_pl_get_histsize(plq->history);
if ( histsize != -1 ) {
while ( (ssize_t)rpld_pl_num(plq->history) > histsize ) {
old = rpld_pl_pop(plq->history);
if ( old != NULL )
rpld_ple_free(old);
}
}
}
if ( was_playing )
return playback_play(queue);
rpld_pl_unref(pl);
return 0;
}
int playback_prev(pli_t queue) {
struct rpld_playlist * pl = rpld_pl_get_by_id(queue);
struct rpld_queue * plq;
struct rpld_playlist_entry * old;
int was_playing;
if ( pl == NULL )
return -1;
if ( (plq = pl->queue) == NULL ) {
rpld_pl_unref(pl);
roar_err_set(ROAR_ERROR_TYPEMM);
return -1;
}
roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_PREV, -1, queue, -1, -1, -1, NULL, -1);
was_playing = plq->playing;
old = rpld_pl_shift(plq->history);
if ( old == NULL ) {
rpld_pl_unref(pl);
return -1;
}
if ( playback_stop(queue, 0, 1) == -1 ) {
rpld_pl_add(plq->history, old, -1);
rpld_pl_unref(pl);
return -1;
}
rpld_pl_add(pl, old, -1);
rpld_pl_unref(pl);
if ( was_playing )
return playback_play(queue);
return 0;
}
int playback_stop(pli_t queue, size_t offset, int kick) {
struct rpld_playlist * pl;
struct rpld_queue * plq = _get_queue(queue, &pl);
if ( plq == NULL )
return -1;
if ( !plq->playing ) {
rpld_pl_unref(pl);
return 0;
}
roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_STOP, -1, queue, -1, offset, kick, NULL, -1);
// first we kick, than we close the IO handles to avoid race conditions.
roar_kick(&(plq->backend->con),
ROAR_OT_STREAM,
roar_stream_get_id(&(plq->stream)));
roar_vio_close(&(plq->io.stream));
roar_vio_close(plq->io.fp);
plq->playing = 0;
memset(&(plq->ple), 0, sizeof(plq->ple));
plq->ple_mduc = 0;
rpld_pl_unref(pl);
ROAR_DBG("playback_stop(offset=%i, kick=%i) = 0", offset, kick);
return 0;
}
int playback_pause(pli_t queue, int how) {
struct rpld_playlist * pl;
struct rpld_queue * plq = _get_queue(queue, &pl);
struct roar_stream_info info;
int reset = -1;
if ( plq == NULL )
return -1;
if ( !plq->playing ) {
rpld_pl_unref(pl);
return -1;
}
switch (how) {
case PLAYBACK_PAUSE_TRUE:
reset = ROAR_SET_FLAG;
break;
case PLAYBACK_PAUSE_FALSE:
reset = ROAR_RESET_FLAG;
break;
case PLAYBACK_PAUSE_TOGGLE:
#ifdef ROAR_FT_FUNC_SET_FLAGS2
#ifdef ROAR_FT_SONAME_LIBROAR2
#define _set_flags roar_stream_set_flags
#else
#define _set_flags roar_stream_set_flags2
#endif
if ( _set_flags(&(plq->backend->con),
&(plq->stream),
ROAR_FLAG_PAUSE, ROAR_TOGGLE_FLAG) == 0 ) {
rpld_pl_unref(pl);
return 0;
}
#endif
if ( roar_stream_get_info(&(plq->backend->con),
&(plq->stream),
&info) == -1 ) {
rpld_pl_unref(pl);
return -1;
}
if ( info.flags & ROAR_FLAG_PAUSE ) {
reset = ROAR_RESET_FLAG;
} else {
reset = ROAR_SET_FLAG;
}
break;
}
#ifdef ROAR_FT_FUNC_SET_FLAGS2
return _set_flags(&(plq->backend->con),
&(plq->stream),
ROAR_FLAG_PAUSE, reset);
#else
return roar_stream_set_flags(&(plq->backend->con),
&(plq->stream),
ROAR_FLAG_PAUSE, reset);
#endif
rpld_pl_unref(pl);
roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_PAUSE, -1, queue, -1, how, -1, NULL, -1);
}
int playback_is_playing(pli_t queue) {
struct rpld_playlist * pl;
struct rpld_queue * plq = _get_queue(queue, &pl);
int ret;
if ( plq == NULL )
return 0;
ret = plq->playing;
rpld_pl_unref(pl);
return ret;
}
char * playback_stream_identifier(pli_t queue) {
struct rpld_playlist * pl;
struct rpld_queue * plq = _get_queue(queue, &pl);
static char buf[32];
if ( plq == NULL )
return 0;
if ( !plq->playing ) {
rpld_pl_unref(pl);
return NULL;
}
snprintf(buf, sizeof(buf), "%i", roar_stream_get_id(&(plq->stream)));
buf[sizeof(buf)-1] = 0;
rpld_pl_unref(pl);
return buf;
}
int playback_is_pause(pli_t queue) {
struct rpld_playlist * pl;
struct rpld_queue * plq = _get_queue(queue, &pl);
struct roar_stream_info info;
if ( plq == NULL )
return PLAYBACK_PAUSE_FALSE;
if ( !plq->playing ) {
rpld_pl_unref(pl);
return PLAYBACK_PAUSE_FALSE;
}
if ( roar_stream_get_info(&(plq->backend->con),
&(plq->stream),
&info) == -1 ) {
rpld_pl_unref(pl);
return PLAYBACK_PAUSE_FALSE;
}
rpld_pl_unref(pl);
if ( info.flags & ROAR_FLAG_PAUSE )
return PLAYBACK_PAUSE_TRUE;
return PLAYBACK_PAUSE_FALSE;
}
int playback_set_volume(pli_t queue) {
struct rpld_playlist * pl;
struct rpld_queue * plq = _get_queue(queue, &pl);
struct roar_mixer_settings mixer;
int id; // stream ID
int channels; // nummber of channels
int i;
if ( plq == NULL )
return -1;
// it's an error to enforce a volume in case we are not playing
if ( !plq->playing ) {
rpld_pl_unref(pl);
return -1;
}
id = roar_stream_get_id(&(plq->stream));
if ( roar_get_vol(&(plq->backend->con), id, &mixer, &channels) == -1 ) {
rpld_pl_unref(pl);
return -1;
}
mixer.scale = 65535;
mixer.rpg_mul = 1;
mixer.rpg_div = 1;
for (i = 0; i < channels; i++)
mixer.mixer[i] = plq->volume_mono;
#ifdef ROAR_FT_SONAME_LIBROAR2
if ( roar_set_vol(&(plq->backend->con), id,
&mixer, channels, ROAR_SET_VOL_ALL) == -1 ) {
channels = 1;
if ( roar_set_vol(&(plq->backend->con), id,
&mixer, channels, ROAR_SET_VOL_UNMAPPED) == -1 ) {
rpld_pl_unref(pl);
return -1;
}
}
#else
if ( roar_set_vol(&(plq->backend->con), id, &mixer, channels) == -1 ) {
rpld_pl_unref(pl);
return -1;
}
#endif
rpld_pl_unref(pl);
return 0;
}
int playback_set_volume_mu16(pli_t queue, uint16_t mono) {
struct rpld_playlist * pl;
struct rpld_queue * plq = _get_queue(queue, &pl);
if ( plq == NULL )
return -1;
plq->volume_mono = mono;
roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_VOLUME, -1, queue, -1, mono, -1, NULL, -1);
// if we are not playing we are done
if ( !plq->playing ) {
rpld_pl_unref(pl);
return 0;
}
rpld_pl_unref(pl);
return playback_set_volume(queue);
}
int playback_set_volume_mpc(pli_t queue, int pc) {
uint16_t u16 = pc * 655;
// correct maximum
if ( u16 > 65480 )
u16 = 65535;
return playback_set_volume_mu16(queue, u16);
}
uint16_t playback_get_volume_mu16(pli_t queue) {
struct rpld_playlist * pl;
struct rpld_queue * plq = _get_queue(queue, &pl);
struct roar_mixer_settings mixer;
uint32_t s = 0;
int channels; // nummber of channels
int id; // stream ID
int i;
if ( plq == NULL )
return 65535;
if ( !plq->playing ) {
rpld_pl_unref(pl);
return plq->volume_mono;
}
id = roar_stream_get_id(&(plq->stream));
if ( roar_get_vol(&(plq->backend->con), id, &mixer, &channels) == -1 ) {
rpld_pl_unref(pl);
return plq->volume_mono;
}
for (i = 0; i < channels; i++) {
s += mixer.mixer[i];
}
if ( mixer.scale != 65535 ) {
s = (float)s / (float)(mixer.scale * channels / 65535.);
} else {
s /= channels;
}
plq->volume_mono = s;
rpld_pl_unref(pl);
return s;
}
int playback_get_volume_mpc(pli_t queue) {
return playback_get_volume_mu16(queue) / 655;
}
const struct roar_stream * playback_get_stream (pli_t queue) {
struct rpld_playlist * pl;
struct rpld_queue * plq = _get_queue(queue, &pl);
static struct roar_stream stream;
// TODO: FIXME: Why don't we just returen the stream object from the plq?
if ( plq == NULL )
return NULL;
if ( !plq->playing ) {
rpld_pl_unref(pl);
return NULL;
}
if ( roar_get_stream(&(plq->backend->con),
&stream,
roar_stream_get_id(&(plq->stream))) == -1 ) {
rpld_pl_unref(pl);
return NULL;
}
rpld_pl_unref(pl);
return &stream;
}
struct rpld_playlist_entry * playback_get_ple (pli_t queue) {
struct rpld_playlist * pl;
struct rpld_queue * plq = _get_queue(queue, &pl);
struct rpld_playlist_entry * plent;
struct roar_meta meta;
int types[ROAR_META_MAX_PER_STREAM];
int i;
int len;
char * metadata;
size_t metalen;
if ( plq == NULL )
return NULL;
if ( !plq->playing ) {
rpld_pl_unref(pl);
return NULL;
}
plent = &(plq->ple);
if ( (len = roar_stream_meta_list(&(plq->backend->con),
&(plq->stream),
types, ROAR_META_MAX_PER_STREAM)) != -1 ) {
for (i = 0; i < len; i++) {
metalen = 0;
metadata = NULL;
switch (types[i]) {
case ROAR_META_TYPE_ALBUM:
metadata = plent->meta.album;
metalen = sizeof(plent->meta.album);
break;
case ROAR_META_TYPE_TITLE:
metadata = plent->meta.title;
metalen = sizeof(plent->meta.title);
break;
case ROAR_META_TYPE_ARTIST:
metadata = plent->meta.artist;
metalen = sizeof(plent->meta.artist);
break;
case ROAR_META_TYPE_PERFORMER:
metadata = plent->meta.performer;
metalen = sizeof(plent->meta.performer);
break;
case ROAR_META_TYPE_VERSION:
metadata = plent->meta.version;
metalen = sizeof(plent->meta.version);
break;
/*
TODO: FIXME: add support for this
case ROAR_META_TYPE_TRACKNUMBER:
plent->meta.tracknum = atoi(delm);
continue;
break;
case ROAR_META_TYPE_GENRE:
plent->meta.genre = roar_meta_intgenre(delm);
continue;
break;
case ROAR_META_TYPE_DISCID:
sscanf(delm, "%8x", &(plent->meta.discid));
continue;
break;
*/
default:
metalen = 0;
continue;
break;
}
if ( metalen != 0 ) {
meta.type = types[i];
if ( roar_stream_meta_get(&(plq->backend->con),
&(plq->stream),
&meta) != -1 ) {
plq->ple_mduc++;
strncpy(metadata, meta.value, metalen);
metadata[metalen-1] = 0;
roar_meta_free(&meta);
}
}
}
}
rpld_pl_unref(pl);
return plent;
}
size_t playback_get_mduc(pli_t queue) {
struct rpld_playlist * pl;
struct rpld_queue * plq = _get_queue(queue, &pl);
size_t ret;
if ( plq == NULL )
return 0;
ret = plq->ple_mduc;
rpld_pl_unref(pl);
return ret;
}
//ll
rpld-0.1.9/playback.h 0000644 0001750 0001750 00000006472 12266574305 012566 0 ustar phi phi //playback.h:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef _RPLD_PLAYBACK_H_
#define _RPLD_PLAYBACK_H_
#define PLAYBACK_PAUSE_TRUE 1
#define PLAYBACK_PAUSE_FALSE 0
#define PLAYBACK_PAUSE_TOGGLE 2
struct rpld_queue {
size_t refc;
int playing;
size_t stop_offset;
int kick_on_stop;
int role; // conf.
int mixer; // conf.
struct rpld_playlist * history; // conf.
struct rpld_backend * backend; // conf.
struct roar_stream stream;
struct {
struct roar_vio_calls file;
struct roar_vio_calls stream;
struct roar_vio_calls filter;
struct roar_vio_calls * fp;
} io;
uint16_t volume_mono; // conf., scale is 2^16-1
struct rpld_playlist_entry ple;
size_t ple_mduc;
struct {
struct rpld_playlist_pointer * currentptr;
struct rpld_playlist_pointer * defaultptr;
struct rpld_playlist_pointer * startupptr;
struct rpld_playlist_pointer * fallbackptr;
} pointers;
};
int playback_preinit(void);
int playback_init(void);
void playback_uninit(void);
void playback_set_role(pli_t queue, const int role);
struct roar_audio_info * playback_get_codechelper_info(void);
void playback_check(int block);
int playback_add_queue(struct rpld_playlist * pl, const char * backend, int mixer, struct rpld_playlist * history);
int playback_del_queue(struct rpld_playlist * pl);
int playback_has_queue(pli_t queue);
int playback_set_pointer(pli_t queue, int pointer, struct rpld_playlist_pointer * plp);
struct rpld_playlist_pointer * playback_get_pointer(pli_t queue, int pointer);
// start or stop all queues.
void playback_play_all(void);
void playback_stop_all(size_t offset, int kick);
// test if at least one queue is playing.
int playback_is_playing_any(void);
int playback_play(pli_t queue);
int playback_next(pli_t queue);
int playback_prev(pli_t queue);
int playback_stop(pli_t queue, size_t offset, int kick);
int playback_pause(pli_t queue, int how);
int playback_is_playing(pli_t queue);
char * playback_stream_identifier(pli_t queue);
int playback_is_pause(pli_t queue);
int playback_set_volume(pli_t queue);
int playback_set_volume_mu16(pli_t queue, uint16_t mono); /* relative to 2^16-1 */
int playback_set_volume_mpc(pli_t queue, int pc); /* in % */
uint16_t playback_get_volume_mu16(pli_t queue);
int playback_get_volume_mpc(pli_t queue);
const struct roar_stream * playback_get_stream (pli_t queue);
struct rpld_playlist_entry * playback_get_ple (pli_t queue);
size_t playback_get_mduc(pli_t queue);
#endif
//ll
rpld-0.1.9/playlist.c 0000644 0001750 0001750 00000073535 12266574305 012640 0 ustar phi phi //playlist.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
#include
struct rpld_playlist * g_playlists[MAX_PLAYLISTS];
struct rpld_playlist_entry * rpld_ple_new (void) {
struct rpld_playlist_entry * plent = roar_mm_malloc(sizeof(struct rpld_playlist_entry));
static uint64_t counter = 0;
unsigned char rand_data = roar_random_uint16() & 0xFF;
if ( plent == NULL )
return NULL;
memset(plent, 0, sizeof(struct rpld_playlist_entry));
plent->global_tracknum = (((ei_t )getpid() & 0xFF) << 56) |
(((uint64_t)RPLD_PL_MAGIC) << 48) |
(counter << 8) |
rand_data;
plent->global_short_tracknum = (((ei_short_t)getpid() & 0xFF) << 24) ^ (counter & 0x00FF0000) >> 16;
plent->global_short_tracknum |= (counter & 0xFFFF) << 8;
plent->global_short_tracknum |= rand_data ^ RPLD_PL_MAGIC;
plent->flags = RPLD_PLE_FLAG_UNSKIPABLE;
plent->start = -1;
plent->end = -1;
plent->wallclock_start = RPLD_PLE_WALLCLOCK_INVALID;
plent->rpg.mode = ROAR_RPGMODE_DEFAULT;
plent->rpg.mul = 1;
plent->rpg.div = 1;
plent->codec = -1;
plent->io.filenames = NULL;
plent->io.num = 0;
plent->io.slots = 0;
plent->meta.genre = -1;
plent->meta.extra.kv = NULL;
plent->meta.extra.kvlen = -1;
plent->meta.extra.kv_store = NULL;
plent->meta.extra.kv_storelen = -1;
plent->likeness = 1;
roar_uuid_gen_random(plent->uuid);
counter++;
return plent;
}
void rpld_ple_free (struct rpld_playlist_entry * plent) {
ssize_t i;
if ( plent == NULL )
return;
if ( plent->meta.extra.kv_store != NULL )
roar_mm_free(plent->meta.extra.kv_store);
if ( plent->meta.extra.kv != NULL )
roar_mm_free(plent->meta.extra.kv);
if ( plent->io.filenames != NULL ) {
for (i = 0; i < plent->io.num; i++ )
roar_mm_free(plent->io.filenames[i].filename);
roar_mm_free(plent->io.filenames);
}
memset(plent, 0, sizeof(*plent));
strncpy(plent->meta.title, "<<>>", sizeof(plent->meta.title));
roar_mm_free(plent);
}
static inline struct rpld_filename * __copy_filenames(const struct rpld_filename * src, ssize_t len) {
struct rpld_filename * ret;
ssize_t i;
int err;
if ( len < 1 )
return NULL;
ret = roar_mm_malloc(sizeof(struct rpld_filename)*len);
if ( ret == NULL )
return NULL;
for (i = 0; i < len; i++) {
ret[i] = src[i];
ret[i].filename = roar_mm_strdup(src[i].filename);
if ( ret[i].filename == NULL ) {
err = roar_error;
for (i--; i >= 0; i--)
roar_mm_free(ret[i].filename);
roar_mm_free(ret);
roar_err_set(err);
return NULL;
}
}
return ret;
}
struct rpld_playlist_entry * rpld_ple_copy (struct rpld_playlist_entry * plent) {
struct rpld_playlist_entry * ret = NULL;
ei_t trknl;
ei_short_t trkns;
int err;
if ( plent == NULL )
return NULL;
if ( (ret = rpld_ple_new()) == NULL )
return NULL;
trknl = ret->global_tracknum;
trkns = ret->global_short_tracknum;
memcpy(ret, plent, sizeof(struct rpld_playlist_entry));
memset(&(ret->list), 0, sizeof(ret->list));
memset(&(ret->meta.extra), 0, sizeof(ret->meta.extra));
ret->global_tracknum = trknl;
ret->global_short_tracknum = trkns;
ret->meta.extra.kv_store = roar_keyval_copy(&(ret->meta.extra.kv), plent->meta.extra.kv, plent->meta.extra.kvlen);
ret->meta.extra.kv_storelen = -1;
if ( ret->meta.extra.kv_store != NULL )
ret->meta.extra.kvlen = plent->meta.extra.kvlen;
ret->io.filenames = __copy_filenames(plent->io.filenames, plent->io.num);
if ( ret->io.filenames == NULL ) {
err = roar_error;
rpld_ple_free(ret);
roar_err_set(err);
}
return ret;
}
struct rpld_playlist_entry * rpld_ple_cut_out_next (struct rpld_playlist_entry * plent) {
struct rpld_playlist_entry * next;
if ( plent == NULL )
return NULL;
// test if there is a next element in chain:
if ( (next = plent->list.next) == NULL )
return NULL;
plent->list.next = next->list.next;
memset(&(next->list), 0, sizeof(next->list));
return next;
}
const char * rpld_ple_time_hr (const struct rpld_playlist_entry * plent) {
static char buf[32];
struct tm tm;
time_t length = plent->length;
tm.tm_hour = length / 3600;
length = length % 3600;
tm.tm_min = length / 60;
length = length % 60;
tm.tm_sec = length;
snprintf(buf, 31, "%.2u:%.2u:%.2u", tm.tm_hour, tm.tm_min, tm.tm_sec);
buf[31] = 0;
return buf;
}
int rpld_ple_set_time_hr (struct rpld_playlist_entry * plent, char * time) {
char * cur;
char * next;
time_t length = 0;
if ( plent == NULL || time == NULL )
return -1;
cur = time;
while ( cur != NULL ) {
next = strstr(cur, ":");
if ( next != NULL ) {
*next = 0;
next++;
}
length *= 60;
length += atol(cur);
cur = next;
}
plent->length = length;
return 0;
}
enum rpld_filename_type rpld_ple_get_filenametype(const char * type) {
const struct {
const enum rpld_filename_type type;
const char * name;
} names[] = {
{RPLD_TYPE_ERROR, "error"},
{RPLD_TYPE_UNKNOWN, "unknown"},
{RPLD_TYPE_AUTOLOCATE, "autolocate"},
{RPLD_TYPE_STREAMURL, "streamurl"},
{RPLD_TYPE_FILENAME, "filename"},
{RPLD_TYPE_FILEURL, "fileurl"}
};
size_t i;
if ( type == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return RPLD_TYPE_ERROR;
}
for (i = 0; i < (sizeof(names)/sizeof(*names)); i++) {
if ( !!strcasecmp(names[i].name, type) )
continue;
roar_err_set(ROAR_ERROR_NONE);
return names[i].type;
}
roar_err_set(ROAR_ERROR_NOENT);
return RPLD_TYPE_ERROR;
}
int rpld_ple_push_filename(struct rpld_playlist_entry * plent, const char * filename, enum rpld_filename_type type, int clear) {
const char * tantalos;
void * tmp;
ssize_t i;
ROAR_DBG("rpld_ple_push_filename(plent=%p, filename='%s', type=%i, clear=%i) = ?", plent, filename, (int)type, clear);
if ( plent == NULL || filename == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
switch (type) {
case RPLD_TYPE_ERROR:
roar_err_set(ROAR_ERROR_INVAL);
return -1;
break;
case RPLD_TYPE_UNKNOWN:
if ( !strncmp(filename, "tantalos://", 11) ) {
type = RPLD_TYPE_AUTOLOCATE;
} else if ( !strncmp(filename, "file://", 7) ) {
type = RPLD_TYPE_FILENAME;
} else if ( !strncmp(filename, "icy://", 6) ) {
type = RPLD_TYPE_STREAMURL;
}
break;
#ifndef DEBUG
default:
/* make gcc not warn about missing cases */
break;
#endif
}
tantalos = rpld_ple_get_filename(plent, plent->io.num, NULL);
if ( tantalos != NULL ) {
if ( !strcmp(tantalos, filename) ) {
roar_err_set(ROAR_ERROR_ALREADY);
return -1;
}
}
for (i = 0; i < plent->io.num; i++) {
if ( !strcmp(plent->io.filenames[i].filename, filename) && plent->io.filenames[i].type == type ) {
roar_err_set(ROAR_ERROR_ALREADY);
return -1;
}
}
ROAR_DBG("rpld_ple_push_filename(plent=%p, filename='%s', type=%i, clear=%i) = ?", plent, filename, (int)type, clear);
if ( plent->io.slots == plent->io.num ) {
tmp = roar_mm_realloc(plent->io.filenames, (plent->io.slots + 8)*sizeof(*plent->io.filenames));
if ( tmp == NULL )
return -1;
plent->io.slots += 8;
plent->io.filenames = tmp;
}
ROAR_DBG("rpld_ple_push_filename(plent=%p, filename='%s', type=%i, clear=%i) = ?", plent, filename, (int)type, clear);
if ( clear ) {
for (i = 0; i < plent->io.num; i++)
roar_mm_free(plent->io.filenames[plent->io.num].filename);
plent->io.num = 0;
}
plent->io.filenames[plent->io.num].filename = roar_mm_strdup(filename);
plent->io.filenames[plent->io.num].type = type;
plent->io.num++;
ROAR_DBG("rpld_ple_push_filename(plent=%p, filename='%s', type=%i, clear=%i) = 0", plent, filename, (int)type, clear);
return 0;
}
const char * rpld_ple_get_filename(struct rpld_playlist_entry * plent, ssize_t index, enum rpld_filename_type * type) {
ssize_t max_index;
char uuid[37];
ROAR_DBG("rpld_ple_get_filename(plent=%p, index=%lli, type=%p) = ?", plent, (long long int)index, type);
if ( plent == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return NULL;
}
max_index = rpld_ple_num_filename(plent);
if ( max_index == -1 )
return NULL;
max_index--;
if ( index == -1 )
index = 0;
if ( index < 0 ) {
roar_err_set(ROAR_ERROR_INVAL);
return NULL;
} else if ( index == max_index ) {
roar_uuid2str(uuid, plent->uuid, sizeof(uuid));
snprintf(plent->io.tantalos, sizeof(plent->io.tantalos), "tantalos://%s", uuid);
plent->io.tantalos[sizeof(plent->io.tantalos)-1] = 0;
if ( type != NULL )
*type = RPLD_TYPE_AUTOLOCATE;
return plent->io.tantalos;
} else if ( index >= max_index ) {
roar_err_set(ROAR_ERROR_NOENT);
return NULL;
}
if ( type != NULL )
*type = plent->io.filenames[index].type;
ROAR_DBG("rpld_ple_get_filename(plent=%p, index=%lli, type=%p) = ?", plent, (long long int)index, type);
(void)(volatile typeof(plent->io.filenames[index]))plent->io.filenames[index];
return plent->io.filenames[index].filename;
}
ssize_t rpld_ple_num_filename(const struct rpld_playlist_entry * plent) {
if ( plent == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
return plent->io.num + 1;
}
static inline int __iscasein(const char * haystack, const char * needle) {
size_t i, j;
int lower_first = tolower(*needle);
// consider the following magic.
for (i = 0; haystack[i]; i++) {
if ( tolower(haystack[i]) == lower_first ) {
for (j = 0; haystack[i+j] && needle[j]; j++)
if ( tolower(haystack[i+j]) != tolower(needle[j]) )
break;
if ( !needle[j] )
return 1;
}
}
return 0;
}
int rpld_ple_filter (struct rpld_playlist_entry * plent, const void * needle, const char * key, int options) {
const char * barn[8];
const char ** haystacks;
ssize_t haystackcount = 0;
ssize_t filenamecount = -1;
ssize_t i, j;
ssize_t needlelen;
int ret = 0;
union {
const ei_t * ei;
const ei_short_t * ei_short;
const roar_uuid_t * uuid;
const discid_t * discid;
const int * si;
const char * str;
const void * vp;
} subject;
subject.vp = needle;
// a key of NULL is valid and means 'search in all keys'.
if ( plent == NULL || needle == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
// if no sources are given this doesn't match.
if ( !(options & (RPLD_PLE_FILTER_NORMKEY|RPLD_PLE_FILTER_EXTKEY)) )
return 0;
if ( options & RPLD_PLE_FILTER_BNEEDLE ) {
// we can not do a binary search on non-binary data.
if ( options & RPLD_PLE_FILTER_EXTKEY ) {
roar_err_set(ROAR_ERROR_INVAL);
return -1;
}
// key needs to be given as we use it as type in binary mode.
if ( key == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
if ( !strcasecmp(key, "long") ) {
return *subject.ei == plent->global_tracknum ? 1 : 0;
} else if ( !strcasecmp(key, "short") ) {
return *subject.ei_short == plent->global_short_tracknum ? 1 : 0;
} else if ( !strcasecmp(key, "uuid") ) {
return roar_uuid_eq(*subject.uuid, plent->uuid);
} else if ( !strcasecmp(key, "discid") ) {
return *subject.discid == plent->meta.discid ? 1 : 0;
} else if ( !strcasecmp(key, "genre") ) {
return *subject.si == plent->meta.genre ? 1 : 0;
} else if ( !strcasecmp(key, "tracknum") || !strcasecmp(key, "tracknumber") ) {
return *subject.si == plent->meta.tracknum ? 1 : 0;
} else {
roar_err_set(ROAR_ERROR_NOTSUP);
return -1;
}
}
// first count how many keys we need to search:
if ( options & RPLD_PLE_FILTER_NORMKEY ) {
#define _ck(keyname) if ( key == NULL || !strcasecmp(key, (keyname)) ) { haystackcount++; }
_ck("album")
_ck("title")
_ck("artist")
_ck("performer")
_ck("version")
#undef _ck
if ( key == NULL || !strcasecmp(key, "filename") ) {
filenamecount = rpld_ple_num_filename(plent);
if ( filenamecount > 0 )
haystackcount += filenamecount;
}
}
if ( (options & RPLD_PLE_FILTER_EXTKEY) && plent->meta.extra.kv != NULL )
for (i = 0; i < plent->meta.extra.kvlen; i++)
if ( plent->meta.extra.kv[i].key != NULL && (key == NULL || !strcasecmp(plent->meta.extra.kv[i].key, key)) )
haystackcount++;
// now allocate space for all the hay:
if ( haystackcount <= (ssize_t)(sizeof(barn)/sizeof(*barn)) ) {
haystacks = barn;
} else {
haystacks = roar_mm_malloc(haystackcount*sizeof(*haystacks));
if ( haystacks == NULL )
return -1;
}
// Build the list of haystacks:
j = 0;
if ( options & RPLD_PLE_FILTER_NORMKEY ) {
#define _ck(keyname,member) if ( key == NULL || !strcasecmp(key, (keyname)) ) { haystacks[j++] = plent->member; }
_ck("album", meta.album)
_ck("title", meta.title)
_ck("artist", meta.artist)
_ck("performer", meta.performer)
_ck("version", meta.version)
#undef _ck
if ( key == NULL || !strcasecmp(key, "filename") ) {
for (i = 0; i < filenamecount; i++) {
haystacks[j++] = rpld_ple_get_filename(plent, i, NULL);
}
}
}
if ( (options & RPLD_PLE_FILTER_EXTKEY) && plent->meta.extra.kv != NULL )
for (i = 0; i < plent->meta.extra.kvlen; i++)
if ( plent->meta.extra.kv[i].key != NULL && (key == NULL || !strcasecmp(plent->meta.extra.kv[i].key, key)) )
haystacks[j++] = plent->meta.extra.kv[i].value;
// now do the search:
// TODO: this should be optimized.
needlelen = roar_mm_strlen(subject.str);
for (i = 0; !ret && i < haystackcount; i++) {
if ( haystacks[i] == NULL )
continue;
if ( (options & RPLD_PLE_FILTER_ANCHORB) & (options & RPLD_PLE_FILTER_ANCHORE) ) {
if ( options & RPLD_PLE_FILTER_CASE ) {
if ( !strcmp(haystacks[i], subject.str) )
ret = 1;
} else {
if ( !strcasecmp(haystacks[i], subject.str) )
ret = 1;
}
} else if ( options & RPLD_PLE_FILTER_ANCHORB ) {
if ( options & RPLD_PLE_FILTER_CASE ) {
if ( !strncmp(haystacks[i], subject.str, needlelen) )
ret = 1;
} else {
if ( !strncasecmp(haystacks[i], subject.str, needlelen) )
ret = 1;
}
} else if ( options & RPLD_PLE_FILTER_ANCHORE ) {
j = roar_mm_strlen(haystacks[i]);
if ( needlelen > j )
continue;
if ( options & RPLD_PLE_FILTER_CASE ) {
if ( !strcmp(haystacks[i] + j - needlelen, subject.str) )
ret = 1;
} else {
if ( !strcasecmp(haystacks[i] + j - needlelen, subject.str) )
ret = 1;
}
} else {
if ( options & RPLD_PLE_FILTER_CASE ) {
if ( strstr(haystacks[i], subject.str) != NULL )
ret = 1;
} else {
ret = __iscasein(haystacks[i], subject.str);
}
}
}
// Free space space we alloced because barn was too small.
if ( haystacks != barn )
roar_mm_free(haystacks);
return ret;
}
struct rpld_playlist * rpld_pl_new (void) {
struct rpld_playlist * pl = roar_mm_malloc(sizeof(struct rpld_playlist));
if ( pl == NULL )
return NULL;
memset(pl, 0, sizeof(struct rpld_playlist));
pl->refc = 1;
pl->histsize = -1;
return pl;
}
int rpld_pl_ref (struct rpld_playlist * pl) {
if ( pl == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
pl->refc++;
return 0;
}
int rpld_pl_unref (struct rpld_playlist * pl) {
if ( pl == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
pl->refc--;
if ( pl->refc == 1 && pl->name == NULL ) {
if ( rpld_pl_unregister(pl) == 0 )
return 0;
}
if ( pl->refc )
return 0;
rpld_pl_flush(pl);
if ( pl->queue != NULL )
playback_del_queue(pl);
if ( pl->id )
rpld_pl_unregister(pl);
if ( pl->name != NULL )
roar_mm_free(pl->name);
roar_mm_free(pl);
return 0;
}
void rpld_pl_push (struct rpld_playlist * pl, struct rpld_playlist_entry * plent) {
struct rpld_playlist_entry * next = pl->first;
struct rpld_playlist_entry * last;
if ( next == NULL ) {
pl->first = plent;
} else {
while (next != NULL) {
last = next;
next = next->list.next;
}
last->list.next = plent;
}
pl->likeness_hint += plent->likeness;
pl->size_hint++;
}
void rpld_pl_add (struct rpld_playlist * pl, struct rpld_playlist_entry * plent, ssize_t pos) {
struct rpld_playlist_entry * next = pl->first;
struct rpld_playlist_entry * last;
if ( pos == -1 ) {
plent->list.next = pl->first;
pl->first = plent;
pl->likeness_hint += plent->likeness;
pl->size_hint++;
return;
}
if ( pos < 0 )
return;
pl->likeness_hint += plent->likeness;
pl->size_hint++;
if ( next == NULL ) {
pl->first = plent;
} else {
while (next != NULL) {
// printf("pos=%lu, next=%p\n", (unsigned long)pos, next);
if ( pos == 0 ) {
plent->list.next = next->list.next;
next->list.next = plent;
return;
}
pos--;
last = next;
next = next->list.next;
}
last->list.next = plent;
}
}
struct rpld_playlist_entry * rpld_pl_get_first(struct rpld_playlist * pl) {
if ( pl == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return NULL;
}
if ( pl->flags & RPLD_PL_FLAG_VIRTUAL ) {
return pl->first->list.next;
} else {
return pl->first;
}
}
struct rpld_playlist_entry * rpld_pl_shift (struct rpld_playlist * pl) {
struct rpld_playlist_entry * first = pl->first;
if ( pl->first == NULL ) {
roar_err_set(ROAR_ERROR_NOENT);
return NULL;
} else {
if ( pl->flags & RPLD_PL_FLAG_VIRTUAL ) {
first = first->list.next;
pl->first->list.next = first->list.next;
} else {
pl->first = first->list.next;
}
pl->likeness_hint -= first->likeness;
pl->size_hint--;
memset(&(first->list), 0, sizeof(first->list));
return first;
}
}
struct rpld_playlist_entry * rpld_pl_pop (struct rpld_playlist * pl) {
struct rpld_playlist_entry * cur = pl->first;
struct rpld_playlist_entry * old = NULL;
struct rpld_playlist_entry * next;
if ( pl->flags & RPLD_PL_FLAG_VIRTUAL ) {
old = cur;
cur = cur->list.next;
}
if ( cur == NULL ) {
roar_err_set(ROAR_ERROR_NOENT);
return NULL;
}
while ((next = cur->list.next) != NULL) {
old = cur;
cur = next;
}
if ( old == NULL ) {
pl->first = NULL;
} else {
old->list.next = NULL;
}
pl->likeness_hint -= cur->likeness;
pl->size_hint--;
return cur;
}
void rpld_pl_flush (struct rpld_playlist * pl) {
struct rpld_playlist_entry * next = pl->first;
struct rpld_playlist_entry * cur;
while (next != NULL) {
cur = next;
next = next->list.next;
rpld_ple_free(cur);
}
pl->first = NULL;
if ( pl->flags & RPLD_PL_FLAG_VIRTUAL )
pl->flags -= RPLD_PL_FLAG_VIRTUAL;
pl->size_hint = 0;
pl->likeness_hint = 0;
}
static float rand_float(float max);
static size_t rand_size_t(size_t max) {
/*
size_t ret = rand() * max;
ROAR_DBG("rand_size_t(max=%zu) = ?", max);
return ret / RAND_MAX;
*/
return rand_float((float)max);
}
static float rand_float(float max) {
const float range = 65535.;
float ret = (float)roar_random_uint16();
ret *= max;
ROAR_DBG("rand_size_t(max=%f) = ?", (double)max);
return ret / range;
}
struct rpld_playlist_entry * rpld_pl_search (struct rpld_playlist * pl,
struct rpld_playlist_search * search,
struct rpld_playlist_entry * pmatch) {
struct rpld_playlist_entry * cur = NULL;
struct rpld_playlist_entry * prev = NULL;
size_t counter = 0;
float likeness = 0.0;
size_t target_num = 0;
float target_likeness = 0.0;
if ( pl == NULL || search == NULL )
return NULL;
ROAR_DBG("rpld_pl_search(*) = ?");
ROAR_DBG("rpld_pl_search(*): pl ID=%i", rpld_pl_get_id(pl));
switch (search->type) {
case RPLD_PL_ST_NUM:
target_num = search->subject.num;
break;
case RPLD_PL_ST_LIKENESS:
target_likeness = search->subject.likeness;
break;
case RPLD_PL_ST_RANDOM:
target_num = rand_size_t(pl->size_hint);
break;
case RPLD_PL_ST_RANDOM_LIKENESS:
target_likeness = rand_float(pl->likeness_hint);
break;
}
if ( search->options & RPLD_PL_SO_PREVIOUS ) {
if ( rpld_pl_virtual(pl, RPLD_PL_VIRT_CREATE) != 0 )
return NULL;
}
ROAR_DBG("rpld_pl_search(*) = ?");
cur = pl->first;
if ( pl->flags & RPLD_PL_FLAG_VIRTUAL ) {
prev = cur;
cur = cur->list.next;
}
if ( pmatch != NULL ) {
prev = pmatch;
cur = prev->list.next;
}
ROAR_DBG("rpld_pl_search(*) = ?");
#define _match() \
if ( search->options & RPLD_PL_SO_PREVIOUS ) { \
return prev; \
} else { \
return cur; \
}
while (cur != NULL) {
likeness += cur->likeness;
switch (search->type) {
case RPLD_PL_ST_TRACKNUM_LONG:
if ( cur->global_tracknum == search->subject.long_tracknum ) {
_match();
}
break;
case RPLD_PL_ST_TRACKNUM_SHORT:
if ( cur->global_short_tracknum == search->subject.short_tracknum ) {
_match();
}
break;
case RPLD_PL_ST_UUID:
if ( roar_uuid_eq(cur->uuid, search->subject.uuid) ) {
_match();
}
break;
case RPLD_PL_ST_NUM:
case RPLD_PL_ST_RANDOM:
if ( counter == target_num ) {
_match();
}
break;
case RPLD_PL_ST_LIKENESS:
case RPLD_PL_ST_RANDOM_LIKENESS:
if ( likeness >= target_likeness ) {
_match();
}
break;
default: return NULL;
}
prev = cur;
cur = cur->list.next;
counter++;
}
#undef _match
// update _hints:
if ( pmatch == NULL ) {
pl->size_hint = counter;
pl->likeness_hint = likeness;
}
// if we did not found any entry, but on random search we need to re-search with updated hints:
if ( pmatch == NULL && counter > 0 ) {
if ( search->type == RPLD_PL_ST_RANDOM || search->type == RPLD_PL_ST_RANDOM_LIKENESS ) {
return rpld_pl_search(pl, search, pmatch);
}
}
ROAR_DBG("rpld_pl_search(*) = ?");
return NULL;
}
int rpld_pl_virtual (struct rpld_playlist * pl, int virt) {
struct rpld_playlist_entry * plent;
if ( pl == NULL )
return -1;
switch (virt) {
case RPLD_PL_VIRT_KEEP:
return 0;
break;
case RPLD_PL_VIRT_DELETE:
if ( !(pl->flags & RPLD_PL_FLAG_VIRTUAL) )
return 0;
plent = pl->first;
pl->first = plent->list.next;
rpld_ple_free(plent);
pl->flags -= RPLD_PL_FLAG_VIRTUAL;
return 0;
break;
case RPLD_PL_VIRT_CREATE:
if ( pl->flags & RPLD_PL_FLAG_VIRTUAL )
return 0;
plent = rpld_ple_new();
if ( plent == NULL )
return -1;
plent->list.next = pl->first;
pl->first = plent;
pl->flags |= RPLD_PL_FLAG_VIRTUAL;
return 0;
break;
}
return -1;
}
int rpld_pl_merge (struct rpld_playlist * pl, struct rpld_playlist * tm) {
struct rpld_playlist_entry * ple;
ROAR_DBG("rpld_pl_merge(pl=%p, tm=%p) = ?", pl, tm);
if ( pl == NULL || tm == NULL )
return -1;
rpld_pl_unregister(tm);
if ( rpld_pl_virtual(tm, RPLD_PL_VIRT_DELETE) == -1 ) {
return -1;
}
ple = tm->first;
tm->first = NULL;
if ( ple != NULL ) {
rpld_pl_push(pl, ple);
pl->size_hint += tm->size_hint - 1;
pl->likeness_hint += tm->likeness_hint - ple->likeness;
}
rpld_pl_unref(tm);
return 0;
}
int rpld_pl_set_name (struct rpld_playlist * pl, const char * name) {
if ( pl == NULL )
return -1;
if ( pl->name != NULL )
roar_mm_free(pl->name);
if ( name == NULL ) {
pl->name = NULL;
return 0;
}
pl->name = roar_mm_strdup(name);
if ( pl->name != NULL )
return 0;
return -1;
}
char * rpld_pl_get_name (struct rpld_playlist * pl) {
if ( pl == NULL )
return NULL;
return pl->name;
}
int rpld_pl_set_id (struct rpld_playlist * pl, pli_t id) {
if ( pl == NULL )
return -1;
pl->id = id;
return 0;
}
pli_t rpld_pl_get_id (struct rpld_playlist * pl) {
if ( pl == NULL )
return 0;
return pl->id;
}
int rpld_pl_set_parent(struct rpld_playlist * pl, pli_t parent) {
if ( pl == NULL )
return -1;
pl->parent = parent;
return 0;
}
pli_t rpld_pl_get_parent(struct rpld_playlist * pl) {
if ( pl == NULL )
return 0;
return pl->parent;
}
int rpld_pl_set_histsize(struct rpld_playlist * pl, ssize_t size) {
if ( pl == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
// this may be reported as warning on some platforms.
// if you split such a case please open a ticket at our bug tracker
// or contact us via some other way. Thanks.
if ( size < -1 )
size = -1;
pl->histsize = size;
return 0;
}
ssize_t rpld_pl_get_histsize(struct rpld_playlist * pl) {
if ( pl == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
if ( pl->histsize == -1 ) {
roar_err_set(ROAR_ERROR_TYPEMM);
return -1;
}
return pl->histsize;
}
int rpld_pl_register (struct rpld_playlist * pl) {
static pli_t counter = 0;
int i;
if ( pl == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
for (i = 0; i < MAX_PLAYLISTS; i++) {
if ( g_playlists[i] == NULL ) {
counter++;
g_playlists[i] = pl;
rpld_pl_ref(pl);
// TODO: support tables sizes > 256 entrys
return rpld_pl_set_id(pl, (counter << 8) | i);
}
}
return -1;
}
int rpld_pl_register_id(struct rpld_playlist * pl, pli_t id) {
int index = id % MAX_PLAYLISTS;
if ( pl == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
if ( g_playlists[index] != NULL ) {
roar_err_set(ROAR_ERROR_EXIST);
return -1;
}
g_playlists[index] = pl;
rpld_pl_ref(pl);
return rpld_pl_set_id(pl, id);
}
int rpld_pl_unregister(struct rpld_playlist * pl) {
int index;
if ( pl == NULL )
return -1;
index = pl->id % MAX_PLAYLISTS;
if ( g_playlists[index] != pl )
return -1;
rpld_pl_unref(g_playlists[index]);
g_playlists[index] = NULL;
return 0;
}
struct rpld_playlist * rpld_pl_get_by_id (pli_t id) {
struct rpld_playlist * ret = g_playlists[id % MAX_PLAYLISTS];
ROAR_DBG("rpld_pl_get_by_id(id=%i) = ?", (int)id);
if ( ret == NULL ) {
roar_err_set(ROAR_ERROR_NOENT);
return NULL;
}
rpld_pl_ref(ret);
return ret;
}
struct rpld_playlist * rpld_pl_get_by_name(const char * name) {
struct rpld_playlist * c;
int i;
if ( name == NULL )
return NULL;
for (i = 0; i < MAX_PLAYLISTS; i++) {
c = g_playlists[i];
if ( c != NULL ) {
if ( c->name != NULL && !strcmp(c->name, name) ) {
rpld_pl_ref(c);
return c;
}
}
}
return NULL;
}
size_t rpld_pl_num (struct rpld_playlist * pl) {
struct rpld_playlist_entry * cur, * next;
size_t count = 0;
if ( pl == NULL )
return 0;
cur = rpld_pl_get_first(pl);
while ( cur != NULL ) {
count++;
next = cur->list.next;
if ( next == cur ) {
ROAR_ERR("rpld_pl_num(pl=%p): Application error: PLE %p points to itself as next.", pl, cur);
roar_panic(ROAR_FATAL_ERROR_MEMORY_CORRUPTION, NULL);
return count;
}
cur = next;
}
return count;
}
struct rpld_playlist_pointer * rpld_plp_init (struct rpld_playlist * pl,
struct rpld_playlist_search * pls) {
struct rpld_playlist_pointer * plp = roar_mm_malloc(sizeof(struct rpld_playlist_pointer));
if ( plp == NULL )
return NULL;
memset(plp, 0, sizeof(struct rpld_playlist_pointer));
plp->refc = 1;
if ( pl != NULL ) {
plp->hint.pl = pl;
rpld_pl_ref(pl);
}
if ( pls != NULL ) {
memcpy(&(plp->pls), pls, sizeof(struct rpld_playlist_search));
}
return plp;
}
int rpld_plp_ref (struct rpld_playlist_pointer * plp) {
if ( plp == NULL )
return -1;
plp->refc++;
return 0;
}
int rpld_plp_unref (struct rpld_playlist_pointer * plp) {
if ( plp == NULL )
return -1;
plp->refc--;
if ( plp->refc )
return 0;
if ( plp->hint.pl != NULL )
rpld_pl_unref(plp->hint.pl);
roar_mm_free(plp);
return 0;
}
struct rpld_playlist_entry * rpld_plp_search (struct rpld_playlist_pointer * plp) {
struct rpld_playlist_entry * ple;
struct rpld_playlist * pl;
int i;
ROAR_DBG("rpld_plp_search(*) = ?");
if ( plp == NULL )
return NULL;
if ( plp->hint.pl != NULL ) {
ROAR_DBG("rpld_plp_search(*): We have a playlist hint");
return rpld_pl_search(plp->hint.pl, &(plp->pls), NULL);
}
if ( plp->pls.type == RPLD_PL_ST_RANDOM || plp->pls.type == RPLD_PL_ST_RANDOM_LIKENESS ) {
ROAR_DBG("rpld_plp_search(*): We have a random search.");
pl = rpld_pl_get_by_id(plp->pls.subject.pl);
ple = rpld_pl_search(pl, &(plp->pls), NULL);
rpld_pl_unref(pl);
return ple;
}
ROAR_DBG("rpld_plp_search(*): No Playlist hint, searching...");
// add some way to search multiple playlists
for (i = 0; i < MAX_PLAYLISTS; i++) {
if ( rpld_pl_get_histsize(g_playlists[i]) != -1 )
continue;
if ( g_playlists[i] != NULL ) {
if ( (ple = rpld_pl_search(g_playlists[i], &(plp->pls), NULL)) != NULL )
return ple;
}
}
ROAR_DBG("rpld_plp_search(*): No matches found.");
ROAR_DBG("rpld_plp_search(*) = NULL");
return NULL;
}
int rpld_plp_copy (struct rpld_playlist_pointer ** dst,
struct rpld_playlist_pointer * src) {
if ( dst == NULL || src == NULL )
return -1;
if ( *dst != NULL )
if ( rpld_plp_unref(*dst) == -1 )
return -1;
if ( (*dst = rpld_plp_init(src->hint.pl, &(src->pls))) == NULL )
return -1;
return 0;
}
//ll
rpld-0.1.9/playlist.h 0000644 0001750 0001750 00000022173 12266574305 012635 0 ustar phi phi //playlist.h:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef _RPLD_PLAYLIST_H_
#define _RPLD_PLAYLIST_H_
#define MAX_PLAYLISTS 64
#define RPLD_MAX_PLF_LEN 1024
#define RPLD_META_SHORT_LEN 384 /* 1024*3/8, well above the 255/256 limit of some applications */
#define RPLD_PL_MAGIC 0xD9
typedef unsigned int pli_t;
typedef uint64_t ei_t;
typedef uint32_t ei_short_t;
typedef uint32_t discid_t;
// PLE flags:
#define RPLD_PLE_FLAG_NONE 0x0000
#define RPLD_PLE_FLAG_UNSKIPABLE 0x0001
// PLE Wallclock time parameters:
#define RPLD_PLE_WALLCLOCK_INVALID ((time_t)770248800L)
// PLE filter options:
#define RPLD_PLE_FILTER_NONE 0x0000
#define RPLD_PLE_FILTER_NORMKEY 0x0001 /* search in normal keys */
#define RPLD_PLE_FILTER_EXTKEY 0x0002 /* search in extra keys */
#define RPLD_PLE_FILTER_CASE 0x0004 /* search case sensetive */
#define RPLD_PLE_FILTER_ANCHORB 0x0008 /* "begin" anchor: ^ */
#define RPLD_PLE_FILTER_ANCHORE 0x0010 /* "end" anchor: $ */
#define RPLD_PLE_FILTER_BNEEDLE 0x0020 /* needle is binary (uuid, GTN, ...) */
// ???:
#define RPLD_PL_FLAG_NONE 0x0000
#define RPLD_PL_FLAG_VIRTUAL 0x0001
#define RPLD_PL_FLAG_UNLINKED 0x0002
#define RPLD_PL_VIRT_DELETE -1
#define RPLD_PL_VIRT_KEEP 0
#define RPLD_PL_VIRT_CREATE +1
// PlayList SearchType
#define RPLD_PL_ST_NONE 0
#define RPLD_PL_ST_TRACKNUM_LONG 1
#define RPLD_PL_ST_TRACKNUM_SHORT 2
#define RPLD_PL_ST_UUID 3
#define RPLD_PL_ST_NUM 4
#define RPLD_PL_ST_LIKENESS 5
#define RPLD_PL_ST_RANDOM 6
#define RPLD_PL_ST_RANDOM_LIKENESS 7
// PlayList SearchOptions
#define RPLD_PL_SO_NONE 0x0000
#define RPLD_PL_SO_PREVIOUS 0x0001
typedef int_least32_t rpld_mus_t;
enum rpld_filename_type {
RPLD_TYPE_ERROR = -1,
RPLD_TYPE_UNKNOWN = 0,
RPLD_TYPE_AUTOLOCATE = 1,
RPLD_TYPE_STREAMURL,
RPLD_TYPE_FILENAME,
RPLD_TYPE_FILEURL
};
struct rpld_filename {
char * filename;
enum rpld_filename_type type;
};
struct rpld_playlist_entry {
/*
trancknum:
11223344 AABBCCDD
11 8 Bit -> PID & 0xFF
22 8 Bit -> Magic
3344 AABBCC 40 Bit -> counter
DD 8 Bit -> RAND()
short:
11223344
11 8 Bit -> (PID & 0xFF) ^ ((counter & 0x00FF0000) >> 16)
2233 16 Bit -> counter & 0xFFFF
44 8 Bit -> RAND() ^ Magic
*/
ei_t global_tracknum;
ei_short_t global_short_tracknum;
roar_uuid_t uuid;
unsigned int flags;
time_t length;
rpld_mus_t start; // start time (within the resource) in ms.
rpld_mus_t end; // end time (within the resource) in ms.
time_t wallclock_start;
struct roar_stream_rpg rpg;
int codec;
struct {
struct rpld_filename * filenames;
ssize_t num;
ssize_t slots;
char tantalos[48];
} io;
struct {
char album[RPLD_META_SHORT_LEN];
char title[RPLD_META_SHORT_LEN];
char artist[RPLD_MAX_PLF_LEN];
char performer[RPLD_MAX_PLF_LEN];
char version[RPLD_META_SHORT_LEN];
int genre;
int tracknum;
discid_t discid;
struct {
struct roar_keyval * kv;
ssize_t kvlen;
void * kv_store;
ssize_t kv_storelen;
} extra;
} meta;
struct {
struct rpld_playlist_entry * next;
} list;
float likeness;
};
struct rpld_playlist {
size_t refc;
struct rpld_playlist_entry * first;
char * name;
pli_t id;
pli_t parent;
unsigned int flags;
volatile size_t transactions;
int policy;
size_t size_hint;
float likeness_hint;
struct rpld_queue * queue;
ssize_t histsize;
};
struct rpld_playlist_search {
int type;
union {
ei_t long_tracknum;
ei_short_t short_tracknum;
roar_uuid_t uuid;
size_t num;
float likeness;
pli_t pl;
} subject;
unsigned int options;
};
struct rpld_playlist_pointer {
size_t refc;
struct rpld_playlist_search pls;
struct {
struct rpld_playlist * pl;
struct rpld_playlist_entry * ple;
} hint;
};
extern struct rpld_playlist * g_playlists[MAX_PLAYLISTS];
struct rpld_playlist_entry * rpld_ple_new (void);
void rpld_ple_free (struct rpld_playlist_entry * plent);
struct rpld_playlist_entry * rpld_ple_copy (struct rpld_playlist_entry * plent);
struct rpld_playlist_entry * rpld_ple_cut_out_next (struct rpld_playlist_entry * plent);
const char * rpld_ple_time_hr (const struct rpld_playlist_entry * plent);
int rpld_ple_set_time_hr (struct rpld_playlist_entry * plent, char * time);
enum rpld_filename_type rpld_ple_get_filenametype(const char * type);
int rpld_ple_push_filename(struct rpld_playlist_entry * plent, const char * filename, enum rpld_filename_type type, int clear);
const char * rpld_ple_get_filename(struct rpld_playlist_entry * plent, ssize_t index, enum rpld_filename_type * type);
ssize_t rpld_ple_num_filename(const struct rpld_playlist_entry * plent);
// SEARCHPLE {"search string"|0xdiscid|uuid} [{AS|IN} {ALL|TITLE|ARTIST|VERSION|FILENAME|DISCID|UUID|TAG:"Tagname"}] [FROM {"Name"|ID|ANY}]
int rpld_ple_filter (struct rpld_playlist_entry * plent, const void * needle, const char * key, int options);
struct rpld_playlist * rpld_pl_new (void);
int rpld_pl_ref (struct rpld_playlist * pl);
int rpld_pl_unref (struct rpld_playlist * pl);
void rpld_pl_push (struct rpld_playlist * pl, struct rpld_playlist_entry * plent);
void rpld_pl_add (struct rpld_playlist * pl, struct rpld_playlist_entry * plent, ssize_t pos);
struct rpld_playlist_entry * rpld_pl_get_first(struct rpld_playlist * pl);
struct rpld_playlist_entry * rpld_pl_shift (struct rpld_playlist * pl);
struct rpld_playlist_entry * rpld_pl_pop (struct rpld_playlist * pl);
void rpld_pl_flush (struct rpld_playlist * pl);
struct rpld_playlist_entry * rpld_pl_search (struct rpld_playlist * pl,
struct rpld_playlist_search * search,
struct rpld_playlist_entry * pmatch);
int rpld_pl_virtual (struct rpld_playlist * pl, int virt);
int rpld_pl_merge (struct rpld_playlist * pl, struct rpld_playlist * tm);
int rpld_pl_set_name (struct rpld_playlist * pl, const char * name);
char * rpld_pl_get_name (struct rpld_playlist * pl);
int rpld_pl_set_id (struct rpld_playlist * pl, pli_t id);
pli_t rpld_pl_get_id (struct rpld_playlist * pl);
int rpld_pl_set_parent(struct rpld_playlist * pl, pli_t parent);
pli_t rpld_pl_get_parent(struct rpld_playlist * pl);
int rpld_pl_set_histsize(struct rpld_playlist * pl, ssize_t size);
ssize_t rpld_pl_get_histsize(struct rpld_playlist * pl);
int rpld_pl_register (struct rpld_playlist * pl);
int rpld_pl_register_id(struct rpld_playlist * pl, pli_t id);
int rpld_pl_unregister(struct rpld_playlist * pl);
struct rpld_playlist * rpld_pl_get_by_id (pli_t id);
struct rpld_playlist * rpld_pl_get_by_name(const char * name);
size_t rpld_pl_num (struct rpld_playlist * pl);
struct rpld_playlist_pointer * rpld_plp_init (struct rpld_playlist * pl,
struct rpld_playlist_search * pls);
int rpld_plp_ref (struct rpld_playlist_pointer * plp);
int rpld_plp_unref (struct rpld_playlist_pointer * plp);
int rpld_plp_copy (struct rpld_playlist_pointer ** dst,
struct rpld_playlist_pointer * src);
struct rpld_playlist_entry * rpld_plp_search (struct rpld_playlist_pointer * plp);
#endif
//ll
rpld-0.1.9/plugin.c 0000644 0001750 0001750 00000053441 12266574305 012267 0 ustar phi phi //plugin.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
#ifdef SUPPORT_PLUGIN
#include "rpldplugin.h"
static struct roar_plugincontainer * g_plugin_container = NULL;
static ssize_t _config_get_limit(rpldph_config_key_t key) {
switch (key) {
// invalid keys:
case RPLDPH_CONFIG_KEY_DEFAULT_BACKEND:
case RPLDPH_CONFIG_KEY_APPNAME:
roar_err_set(ROAR_ERROR_TYPEMM);
return -1;
break;
// valid keys:
case RPLDPH_CONFIG_KEY_MAX_CLIENTS: return RPLD_CLIENTS_MAX; break;
case RPLDPH_CONFIG_KEY_MAX_PLAYLISTS: return MAX_PLAYLISTS; break;
case RPLDPH_CONFIG_KEY_MAX_LISTENS: return RPLD_MAX_LISTEN; break;
case RPLDPH_CONFIG_KEY_MAX_CODECBL: return PLAYBACK_MAX_CODECBL; break;
case RPLDPH_CONFIG_KEY_MAX_POINTER: return POINTER_NUM; break;
case RPLDPH_CONFIG_KEY_DEFAULT_PLF: return RPLD_FF_PLF_DEFAULT; break;
case RPLDPH_CONFIG_KEY_APPVENDOR: return ROAR_VID_ROARAUDIO; break;
}
roar_err_set(ROAR_ERROR_NOENT);
return -1;
}
static const char * _config_get_value(rpldph_config_key_t key) {
switch (key) {
// invalid keys:
case RPLDPH_CONFIG_KEY_MAX_CLIENTS:
case RPLDPH_CONFIG_KEY_MAX_PLAYLISTS:
case RPLDPH_CONFIG_KEY_MAX_LISTENS:
case RPLDPH_CONFIG_KEY_MAX_CODECBL:
case RPLDPH_CONFIG_KEY_MAX_POINTER:
roar_err_set(ROAR_ERROR_TYPEMM);
return NULL;
break;
// valid keys:
case RPLDPH_CONFIG_KEY_DEFAULT_BACKEND: return BACKEND_DEFAULT_NAME; break;
case RPLDPH_CONFIG_KEY_APPNAME: return APPLICATION_NAME; break;
case RPLDPH_CONFIG_KEY_APPVENDOR: return ROAR_VSTR_ROARAUDIO; break;
case RPLDPH_CONFIG_KEY_DEFAULT_PLF: return "vclt"; break; // TODO: FIXME: use a global const here.
}
roar_err_set(ROAR_ERROR_NOENT);
return NULL;
}
static void * _mm_calloc(size_t nmemb, size_t size) {
return roar_mm_calloc(nmemb, size);
}
static void * _mm_malloc(size_t size) {
return roar_mm_malloc(size);
}
static void * _mm_realloc(void *ptr, size_t size) {
return roar_mm_realloc(ptr, size);
}
static char * _mm_strdup(const char *s) {
return roar_mm_strdup(s);
}
static int _error_get(void) {
return roar_error;
}
#define __ple_check(ret) if ( plent == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return (ret); }
static int _ple_set_res (struct rpld_playlist_entry * plent, const char * file, int codec, time_t length) {
__ple_check(-1)
if ( file == NULL )
file = "";
rpld_ple_push_filename(plent, file, RPLD_TYPE_UNKNOWN, 1);
plent->codec = codec;
plent->length = length;
return 0;
}
static int _ple_set_meta (struct rpld_playlist_entry * plent, struct roar_keyval * kv, ssize_t len) {
struct roar_keyval * c;
ssize_t i;
if ( plent == NULL || kv == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
for (i = 0; len == -1 ? (kv[i].key != NULL || kv[i].value != NULL) : i < len; i++) {
c = &(kv[i]);
if ( 0 ) {
#define _handle_meta_type(type) } else if ( !strcasecmp(c->key, #type) ) { \
strncpy(plent->meta.type, c->value == NULL ? "" : c->value, sizeof(plent->meta.type));
#ifdef __RPLD__FIX_VIM_SYNTAX_HIGHLIGHT__
}
#endif
_handle_meta_type(album)
_handle_meta_type(title)
_handle_meta_type(artist)
_handle_meta_type(performer)
_handle_meta_type(version)
}
}
return 0;
}
static const char * _ple_get_meta (struct rpld_playlist_entry * plent, const char * key) {
const struct roar_keyval * kv;
__ple_check(NULL)
if ( !strcasecmp(key, "album") )
return plent->meta.album;
if ( !strcasecmp(key, "title") )
return plent->meta.title;
if ( !strcasecmp(key, "artist") )
return plent->meta.artist;
if ( !strcasecmp(key, "performer") )
return plent->meta.performer;
if ( !strcasecmp(key, "version") )
return plent->meta.version;
if ( plent->meta.extra.kv != NULL ) {
kv = roar_keyval_lookup(plent->meta.extra.kv, key, plent->meta.extra.kvlen, 0);
if ( kv != NULL )
return kv->value;
}
roar_err_set(ROAR_ERROR_NOENT);
return NULL;
}
static int _ple_set_meta_int(struct rpld_playlist_entry * plent, const char * key, rpld_maxint_t val) {
__ple_check(-1)
if ( !strcasecmp(key, "length") ) {
plent->length = val;
} else if ( !strcasecmp(key, "codec") ) {
plent->codec = val;
} else if ( !strcasecmp(key, "genre") ) {
plent->meta.genre = val;
} else if ( !strcasecmp(key, "tracknum") || !strcasecmp(key, "tracknumber") ) {
plent->meta.tracknum = val;
} else if ( !strcasecmp(key, "discid") ) {
plent->meta.discid = val;
} else {
roar_err_set(ROAR_ERROR_NOTSUP);
return -1;
}
return 0;
}
static rpld_maxint_t _ple_get_meta_int(struct rpld_playlist_entry * plent, const char * key) {
__ple_check((rpld_maxint_t)-1)
if ( !strcasecmp(key, "length") )
return plent->length;
if ( !strcasecmp(key, "codec") )
return plent->codec;
if ( !strcasecmp(key, "genre") )
return plent->meta.genre;
if ( !strcasecmp(key, "tracknum") || !strcasecmp(key, "tracknumber") )
return plent->meta.tracknum;
if ( !strcasecmp(key, "discid") )
return (uint32_t)plent->meta.discid;
roar_err_set(ROAR_ERROR_NOENT);
return (rpld_maxint_t)-1;
}
static int _ple_get_codec (struct rpld_playlist_entry * plent) {
__ple_check(-1)
return plent->codec;
}
static time_t _ple_get_length (struct rpld_playlist_entry * plent) {
__ple_check((time_t)-1)
return plent->length;
}
static int _ple_set_uuid (struct rpld_playlist_entry * plent, const char * uuid) {
if ( plent == NULL || uuid == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
if ( roar_str2uuid(plent->uuid, uuid) == 0 )
return 0;
roar_err_set(ROAR_ERROR_ILLSEQ);
return -1;
}
static const char * _ple_get_uuid (struct rpld_playlist_entry * plent, char * buf) {
static char buffer[37];
__ple_check(NULL)
if ( buf == NULL )
buf = buffer;
roar_uuid2str(buf, plent->uuid, sizeof(buffer));
return buf;
}
static int _ple_set_likeness(struct rpld_playlist_entry * plent, float likeness) {
__ple_check(-1)
plent->likeness = likeness;
return 0;
}
static int _ple_inc_likeness(struct rpld_playlist_entry * plent, float likeness) {
__ple_check(-1)
plent->likeness += likeness;
return 0;
}
static float _ple_get_likeness(struct rpld_playlist_entry * plent) {
__ple_check(-1)
return plent->likeness;
}
static struct rpld_playlist_entry * _ple_get_next (struct rpld_playlist_entry * plent) {
__ple_check(NULL)
return plent->list.next;
}
static int _ple_set_offset(struct rpld_playlist_entry * plent, int_least32_t start, int_least32_t end) {
__ple_check(-1)
plent->start = start;
plent->end = end;
return 0;
}
static int _ple_get_offset(struct rpld_playlist_entry * plent, int_least32_t * start, int_least32_t * end) {
__ple_check(-1)
if ( start != NULL )
*start = plent->start;
if ( end != NULL )
*end = plent->end;
return 0;
}
#define _begin(ret) \
struct rpld_playlist * playlist = rpld_pl_get_by_id(pl); \
int err; \
if ( playlist == NULL ) \
return (ret);
#define _return \
err = roar_error; \
rpld_pl_unref(playlist); \
roar_err_set(err); \
return ret;
static rpld_pli_t _playlist_new (const char * name, rpld_pli_t parent) {
struct rpld_playlist * playlist;
rpld_pli_t ret;
if ( name == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return RPLD_PLI_INVALID;
}
playlist = rpld_pl_new();
if ( playlist == NULL )
return RPLD_PLI_INVALID;
rpld_pl_set_name(playlist, name);
if ( parent != RPLD_PLI_INVALID )
rpld_pl_set_parent(playlist, parent);
rpld_pl_register(playlist);
ret = rpld_pl_get_id(playlist);
rpld_pl_unref(playlist);
return ret;
}
static void _playlist_free (rpld_pli_t pl) {
struct rpld_playlist * playlist = rpld_pl_get_by_id(pl);
if ( playlist == NULL )
return;
rpld_pl_set_name(playlist, NULL);
rpld_pl_unref(playlist);
}
static int _playlist_flush(rpld_pli_t pl) {
const int ret = 0;
_begin(-1)
rpld_pl_flush(playlist);
_return
}
static int _playlist_merge(rpld_pli_t pl, rpld_pli_t tm) {
struct rpld_playlist * playlist_tm;
int ret;
_begin(-1)
playlist_tm = rpld_pl_get_by_id(tm);
if ( playlist_tm == NULL ) {
ret = -1;
_return
}
ret = rpld_pl_merge(playlist, playlist_tm);
err = roar_error;
rpld_pl_unref(playlist_tm);
roar_err_set(err);
_return
}
static int _playlist_set_name(rpld_pli_t pl, const char * name) {
int ret;
_begin(-1)
ret = rpld_pl_set_name(playlist, name);
_return
}
static const char * _playlist_get_name(rpld_pli_t pl) {
const char * ret;
_begin(NULL)
ret = rpld_pl_get_name(playlist);
_return
}
static int _playlist_set_parent(rpld_pli_t pl, rpld_pli_t parent) {
int ret;
_begin(-1)
ret = rpld_pl_set_parent(playlist, parent);
_return
}
static rpld_pli_t _playlist_get_parent(rpld_pli_t pl) {
rpld_pli_t ret;
_begin(RPLD_PLI_INVALID)
ret = rpld_pl_get_parent(playlist);
_return
}
static rpld_pli_t _playlist_get_by_name(const char * name) {
struct rpld_playlist * playlist = rpld_pl_get_by_name(name);
int err;
rpld_pli_t ret;
if ( playlist == NULL )
return RPLD_PLI_INVALID;
ret = rpld_pl_get_id(playlist);
_return
}
static ssize_t _playlist_get_num(rpld_pli_t pl) {
ssize_t ret;
_begin(-1)
ret = rpld_pl_num(playlist);
_return
}
static int _playlist_push (rpld_pli_t pl, struct rpld_playlist_entry * plent) {
const int ret = 0;
_begin(-1)
rpld_pl_push(playlist, plent);
_return
}
static struct rpld_playlist_entry * _playlist_pop (rpld_pli_t pl) {
struct rpld_playlist_entry * ret;
_begin(NULL)
ret = rpld_pl_pop(playlist);
_return
}
static struct rpld_playlist_entry * _playlist_shift (rpld_pli_t pl) {
struct rpld_playlist_entry * ret;
_begin(NULL)
ret = rpld_pl_shift(playlist);
_return
}
static int _playlist_add (rpld_pli_t pl, struct rpld_playlist_entry * plent, ssize_t pos) {
const int ret = 0;
_begin(-1)
rpld_pl_add(playlist, plent, pos);
_return
}
static int _playlist_unshift (rpld_pli_t pl, struct rpld_playlist_entry * plent) {
return _playlist_add(pl, plent, -1);
}
static struct rpld_playlist_entry * _playlist_get_first(rpld_pli_t pl) {
struct rpld_playlist_entry * ret;
_begin(NULL)
ret = rpld_pl_get_first(playlist);
_return
}
static int _history_set_size(rpld_pli_t history, ssize_t size) {
struct rpld_playlist * pl = rpld_pl_get_by_id(history);
int ret;
int err;
if ( pl == NULL )
return -1;
ret = rpld_pl_set_histsize(pl, size);
err = roar_error;
rpld_pl_unref(pl);
roar_err_set(err);
return ret;
}
static ssize_t _history_get_size(rpld_pli_t history) {
struct rpld_playlist * pl = rpld_pl_get_by_id(history);
ssize_t ret;
int err;
if ( pl == NULL )
return -1;
ret = rpld_pl_get_histsize(pl);
err = roar_error;
rpld_pl_unref(pl);
roar_err_set(err);
return ret;
}
static struct rpld_playlist_pointer * _plp_new (rpld_pli_t playlist, const char * type, const void * argp) {
struct rpld_playlist_search pls;
union {
const void * vp;
const size_t * num;
const float * likeness;
const char * uuid;
} arg = {.vp = argp};
struct rpld_playlist * pl;
struct rpld_playlist_pointer * ret;
int err;
if ( type == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return NULL;
}
memset(&pls, 0, sizeof(pls));
if ( !strcasecmp(type, "num") ) {
pls.type = RPLD_PL_ST_NUM;
} else if ( !strcasecmp(type, "uuid") ) {
pls.type = RPLD_PL_ST_UUID;
} else if ( !strcasecmp(type, "likeness") ) {
pls.type = RPLD_PL_ST_LIKENESS;
} else if ( !strcasecmp(type, "random") ) {
pls.type = RPLD_PL_ST_RANDOM;
} else if ( !strcasecmp(type, "randomlike") ) {
pls.type = RPLD_PL_ST_RANDOM_LIKENESS;
} else {
roar_err_set(ROAR_ERROR_NOTSUP);
return NULL;
}
switch (pls.type) {
case RPLD_PL_ST_UUID:
case RPLD_PL_ST_NUM:
case RPLD_PL_ST_LIKENESS:
if ( argp == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return NULL;
}
break;
case RPLD_PL_ST_RANDOM:
case RPLD_PL_ST_RANDOM_LIKENESS:
if ( playlist == RPLD_PLI_INVALID ) {
roar_err_set(ROAR_ERROR_INVAL);
return NULL;
}
break;
}
switch (pls.type) {
case RPLD_PL_ST_UUID:
if ( roar_str2uuid(pls.subject.uuid, arg.uuid) != 0 ) {
roar_err_set(ROAR_ERROR_ILLSEQ);
return NULL;
}
break;
case RPLD_PL_ST_NUM:
pls.subject.num = *arg.num;
break;
case RPLD_PL_ST_LIKENESS:
pls.subject.likeness = *arg.likeness;
break;
case RPLD_PL_ST_RANDOM:
case RPLD_PL_ST_RANDOM_LIKENESS:
pls.subject.pl = playlist;
break;
}
pl = rpld_pl_get_by_id(playlist); // we can ignore errors here as rpld_plp_init() can handle NULL.
ret = rpld_plp_init(pl, &pls);
err = roar_error;
if ( pl != NULL )
rpld_pl_unref(pl);
roar_err_set(err);
return ret;
}
static int _playback_stop(rpld_pli_t queue) {
return playback_stop(queue, 0, 1);
}
static int _playback_pause(rpld_pli_t queue, rpldph_bool_t how) {
switch (how) {
case RPLDPH_FALSE: return playback_pause(queue, PLAYBACK_PAUSE_FALSE); break;
case RPLDPH_TRUE: return playback_pause(queue, PLAYBACK_PAUSE_TRUE); break;
case RPLDPH_TOGGLE: return playback_pause(queue, PLAYBACK_PAUSE_TOGGLE); break;
case RPLDPH_ASK:
case RPLDPH_ERROR:
// don't do anything, run into the error case below.
break;
}
roar_err_set(ROAR_ERROR_BADRQC);
return -1;
}
static rpldph_bool_t _playback_is_playing(rpld_pli_t queue) {
switch (playback_is_playing(queue)) {
case 0: return RPLDPH_FALSE; break;
case 1: return RPLDPH_TRUE; break;
default: return RPLDPH_ERROR; break;
}
}
static rpldph_bool_t _playback_is_paused (rpld_pli_t queue) {
switch (playback_is_pause(queue)) {
case PLAYBACK_PAUSE_FALSE: return RPLDPH_FALSE; break;
case PLAYBACK_PAUSE_TRUE: return RPLDPH_TRUE; break;
default: return RPLDPH_ERROR; break;
}
}
static rpldph_bool_t _playback_is_queue (rpld_pli_t queue) {
struct rpld_playlist * pl = rpld_pl_get_by_id(queue);
rpldph_bool_t ret;
if ( pl == NULL )
return RPLDPH_ERROR;
if ( pl->queue == NULL ) {
ret = RPLDPH_FALSE;
} else {
ret = RPLDPH_TRUE;
}
rpld_pl_unref(pl);
return ret;
}
static float _playback_get_volume(rpld_pli_t queue) {
float ret = playback_get_volume_mu16(queue);
return ret / 65535.;
}
static int _playback_set_volume(rpld_pli_t queue, float volume) {
if ( volume < 0. || volume > 65535. ) {
roar_err_set(ROAR_ERROR_RANGE);
return -1;
}
volume *= 65535.;
return playback_set_volume_mu16(queue, (uint16_t)volume);
}
struct roar_connection * _backend_get_con(struct rpld_backend * backend) {
if ( backend == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return NULL;
}
if ( !(backend->flags & BACKEND_FLAG_CONNECTED) ) {
roar_err_set(ROAR_ERROR_NOTCONN);
return NULL;
}
if ( roar_connectionref(&(backend->con)) == -1 )
return NULL;
return &(backend->con);
}
static int _fformat_playlist_export(rpld_fformat_t handle,
struct roar_vio_calls * vio,
rpld_pli_t pl) {
struct rpld_playlist * realpl;
int ret;
realpl = rpld_pl_get_by_id(pl);
if ( realpl == NULL )
return -1;
ret = fformat_playlist_export((struct fformat_handle *)handle, vio, realpl);
rpld_pl_unref(realpl);
return ret;
}
static int _fformat_playlist_import(rpld_fformat_t handle,
struct roar_vio_calls * vio,
rpld_pli_t pl) {
struct rpld_playlist * realpl;
int ret;
realpl = rpld_pl_get_by_id(pl);
if ( realpl == NULL )
return -1;
ret = fformat_playlist_import((struct fformat_handle *)handle, vio, realpl);
rpld_pl_unref(realpl);
return ret;
}
static inline void _yield_ay(enum yield_auto cmd) {
yield_auto(cmd, RPLD_YIELD_TASK_NONE, RPLD_YIELD_TASK_ALL, RPLD_YIELD_NONBLOCK);
}
static void _yield_ay_trigger(void) {
_yield_ay(RPLD_YIELD_TRIGGER);
}
static void _yield_ay_pause(void) {
_yield_ay(RPLD_YIELD_PAUSE);
}
static void _yield_ay_unpause(void) {
_yield_ay(RPLD_YIELD_UNPAUSE);
}
static struct __rpldph_binargv __binargv = {
.functions = {
.config = {
._get_limit = _config_get_limit,
._get_value = _config_get_value,
},
.memory = {
._calloc = _mm_calloc,
._malloc = _mm_malloc,
._free = roar_mm_free_retvoid,
._realloc = _mm_realloc,
._strdup = _mm_strdup
},
.error = {
._get = _error_get,
._set = roar_err_set,
._error2str = roar_error2str,
},
.control = {
._exit = rpld_exit,
._serverinfo = rpld_serverinfo_get
},
.ple = {
._new = rpld_ple_new,
._free = rpld_ple_free,
._copy = rpld_ple_copy,
._set_res = _ple_set_res,
._set_meta = _ple_set_meta,
._get_meta = _ple_get_meta,
._set_meta_int = _ple_set_meta_int,
._get_meta_int = _ple_get_meta_int,
._get_codec = _ple_get_codec,
._get_length = _ple_get_length,
._set_uuid = _ple_set_uuid,
._get_uuid = _ple_get_uuid,
._set_likeness = _ple_set_likeness,
._inc_likeness = _ple_inc_likeness,
._get_likeness = _ple_get_likeness,
._get_next = _ple_get_next,
._set_offset = _ple_set_offset,
._get_offset = _ple_get_offset
},
.playlist = {
._new = _playlist_new,
._free = _playlist_free,
._flush = _playlist_flush,
._merge = _playlist_merge,
._set_name = _playlist_set_name,
._get_name = _playlist_get_name,
._set_parent = _playlist_set_parent,
._get_parent = _playlist_get_parent,
._get_by_name = _playlist_get_by_name,
._get_num = _playlist_get_num,
._push = _playlist_push,
._unshift = _playlist_unshift,
._pop = _playlist_pop,
._shift = _playlist_shift,
._add = _playlist_add,
._get_first = _playlist_get_first
},
.history = {
._set_size = _history_set_size,
._get_size = _history_get_size
},
.plp = {
._new = _plp_new,
._ref = rpld_plp_ref,
._unref = rpld_plp_unref,
._copy = rpld_plp_copy,
._search = rpld_plp_search
},
.playback = {
._play = playback_play,
._next = playback_next,
._prev = playback_prev,
._stop = _playback_stop,
._pause = _playback_pause,
._is_playing = _playback_is_playing,
._is_paused = _playback_is_paused,
._is_queue = _playback_is_queue,
._get_volume = _playback_get_volume,
._set_volume = _playback_set_volume,
._get_ple = playback_get_ple,
._get_mduc = playback_get_mduc,
._get_stream = playback_get_stream
},
.store = {
._save = store,
._load = restore
},
.backend = {
._get_connection = backend_get_connection,
._ref = backend_ref,
._unref = backend_unref,
._get_name = backend_get_name,
._get_con = _backend_get_con,
._blacklist_codec = backend_blacklist_codec,
._blacklist_codec_global = backend_blacklist_codec_global,
._blacklist_check_codec = backend_blacklist_check_codec
},
.client = {
._set_name = client_set_name,
._get_name = client_get_name,
._set_playlist = client_set_playlist,
._get_playlist = client_get_playlist,
._set_queue = client_set_queue,
._get_queue = client_get_queue,
._str2proto = client_str2proto,
._proto2str = client_proto2str
},
.fformat = {
._str2plf = fformat_str2plf,
._plf2str = fformat_plf2str,
._handle_new = (rpld_fformat_t (*)(int format))fformat_handle_new,
._handle_close = (void (*)(rpld_fformat_t handle))fformat_handle_close,
._playlist_export = _fformat_playlist_export,
._playlist_import = _fformat_playlist_import
},
.pointer = {
._get_name = rpld_pointer_get_name,
._parse_name = rpld_pointer_parse_name,
._is_set = rpld_pointer_is_set,
._get = rpld_pointer_get,
._get_by_name = rpld_pointer_get_by_name,
._set = rpld_pointer_set,
._set_by_name = rpld_pointer_set_by_name,
._search = rpld_pointer_search,
},
.yield = {
._ay_trigger = _yield_ay_trigger,
._ay_pause = _yield_ay_pause,
._ay_unpause = _yield_ay_unpause,
._watchdog_trigger = yield_watchdog_trigger
}
}
};
int rpld_plugin_init(void) {
struct roar_dl_librarypara * plugin_para;
int err;
if ( g_plugin_container != NULL ) {
roar_err_set(ROAR_ERROR_ALREADY);
return -1;
}
plugin_para = roar_dl_para_new(NULL, &__binargv, RPLDPH_APPNAME, RPLDPH_ABIVERSION);
g_plugin_container = roar_plugincontainer_new(plugin_para);
err = roar_error;
roar_dl_para_unref(plugin_para);
if ( g_plugin_container == NULL ) {
roar_err_set(err);
return -1;
} else {
return 0;
}
}
int rpld_plugin_free(void) {
if ( g_plugin_container == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
rpld_plugin_appsched(ROAR_DL_APPSCHED_FREE);
roar_plugincontainer_unref(g_plugin_container);
g_plugin_container = NULL;
return 0;
}
int rpld_plugin_load(const char * plugin, const char * args) {
struct roar_dl_librarypara * plugin_para = NULL;
int ret;
if ( args != NULL )
plugin_para = roar_dl_para_new(args, &__binargv, RPLDPH_APPNAME, RPLDPH_ABIVERSION);
ret = roar_plugincontainer_load(g_plugin_container, plugin, plugin_para);
if ( plugin_para != NULL )
roar_dl_para_unref(plugin_para);
return ret;
}
int rpld_plugin_appsched(enum roar_dl_appsched_trigger trigger) {
return roar_plugincontainer_appsched_trigger(g_plugin_container, trigger);
}
#endif
//ll
rpld-0.1.9/plugin.h 0000644 0001750 0001750 00000002276 12266574305 012274 0 ustar phi phi //plugin.h:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef _RPLD_PLUGIN_H_
#define _RPLD_PLUGIN_H_
#ifdef ROAR_FT_SONAME_LIBROAR2
#define SUPPORT_PLUGIN
int rpld_plugin_init(void);
int rpld_plugin_free(void);
int rpld_plugin_load(const char * plugin, const char * args);
int rpld_plugin_appsched(enum roar_dl_appsched_trigger trigger);
#endif
#endif
//ll
rpld-0.1.9/pointer.c 0000644 0001750 0001750 00000013212 12266574305 012441 0 ustar phi phi //pointer.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
enum rpld_pointertype {
PT_GLOBAL = 0,
PT_QUEUE,
PT_CLIENT
};
struct rpld_pointerarray {
const char * name;
enum rpld_pointertype type;
struct rpld_playlist_pointer * pointer;
};
struct rpld_pointerarray g_pointer[POINTER_NUM] = {
{"DEFAULT", PT_QUEUE, NULL},
{"CURRENT", PT_QUEUE, NULL},
{"STARTUP", PT_QUEUE, NULL},
{"TEMP", PT_CLIENT, NULL},
{"FALLBACK", PT_QUEUE, NULL}
};
#define _chargs(ret) if ( pointer < 0 || pointer >= POINTER_NUM ) { roar_err_set(ROAR_ERROR_INVAL); return (ret); }
char * rpld_pointer_get_name(const int pointer, pli_t queue, const int client) {
char * ret;
const char * pointer_name;
_chargs(NULL);
pointer_name = g_pointer[pointer].name;
#define _SIZE 32
ret = roar_mm_malloc(_SIZE);
if ( queue == (pli_t)-1 && client == -1 ) {
snprintf(ret, _SIZE, "%s", pointer_name);
} else if ( queue == (pli_t)-1 ) {
snprintf(ret, _SIZE, "%s[:%i]", pointer_name, client);
} else if ( client == -1 ) {
snprintf(ret, _SIZE, "%s[%i]", pointer_name, (int)queue);
} else {
snprintf(ret, _SIZE, "%s[%i:%i]", pointer_name, (int)queue, client);
}
return ret;
}
int rpld_pointer_parse_name(int * pointer, pli_t * queue, int * client, int client_hint, const char * name) {
size_t i;
size_t namelen;
const char * client_info;
if ( queue == NULL || pointer == NULL || client == NULL || name == NULL ) {
roar_err_set(ROAR_ERROR_FAULT);
return -1;
}
*queue = (pli_t)-1;
*pointer = -1;
*client = client_hint;
if ( client_hint != -1 ) {
*queue = client_get_queue(client_hint);
}
for (i = 0; i < POINTER_NUM; i++) {
namelen = roar_mm_strlen(g_pointer[i].name);
if ( !strncasecmp(g_pointer[i].name, name, namelen) ) {
if ( name[namelen] == 0 ) {
*pointer = i;
return 0;
} else if ( name[namelen] == '[' ) {
*pointer = i;
client_info = strstr(name + namelen + 1, ":");
ROAR_DBG("rpld_pointer_parse_name(*): client_info=%p'%s'", client_info, client_info);
if ( client_info != NULL )
*client = atoi(client_info + 1);
if ( name[namelen+1] == ':' ) {
*queue = client_get_queue(*client);
} else {
*queue = atoi(name + namelen + 1);
}
return 0;
} else {
roar_err_set(ROAR_ERROR_ILLSEQ);
return -1;
}
}
}
roar_err_set(ROAR_ERROR_NOENT);
return -1;
}
int rpld_pointer_is_set(const int pointer, pli_t queue, const int client) {
struct rpld_playlist_pointer * plp;
int ret;
_chargs(-1);
plp = rpld_pointer_get(pointer, queue, client);
ret = plp == NULL ? 0 : 1;
rpld_plp_unref(plp);
return ret;
}
struct rpld_playlist_pointer * rpld_pointer_get(const int pointer, pli_t queue, const int client) {
struct rpld_playlist_pointer * ret = NULL;
_chargs(NULL);
roar_err_set(ROAR_ERROR_NOTSUP);
switch (g_pointer[pointer].type) {
case PT_GLOBAL:
ret = g_pointer[pointer].pointer;
if ( ret == NULL ) {
roar_err_set(ROAR_ERROR_NOENT);
} else {
rpld_plp_ref(g_pointer[pointer].pointer);
}
break;
case PT_CLIENT:
ret = client_get_pointer(client, pointer);
break;
case PT_QUEUE:
ret = playback_get_pointer(queue, pointer);
break;
}
return ret;
}
struct rpld_playlist_pointer * rpld_pointer_get_by_name(const char * name, int client_hint) {
pli_t queue;
int pointer, client;
if ( rpld_pointer_parse_name(&pointer, &queue, &client, client_hint, name) == -1 )
return NULL;
return rpld_pointer_get(pointer, queue, client);
}
int rpld_pointer_set(const int pointer, pli_t queue, const int client, struct rpld_playlist_pointer * plp) {
_chargs(-1);
roar_err_set(ROAR_ERROR_NOTSUP);
switch (g_pointer[pointer].type) {
case PT_GLOBAL:
if ( g_pointer[pointer].pointer != NULL ) {
rpld_plp_unref(g_pointer[pointer].pointer);
g_pointer[pointer].pointer = NULL;
}
if ( plp != NULL )
rpld_plp_ref(plp);
g_pointer[pointer].pointer = plp;
return 0;
break;
case PT_CLIENT:
return client_set_pointer(client, pointer, plp);
break;
case PT_QUEUE:
return playback_set_pointer(queue, pointer, plp);
break;
}
return -1;
}
int rpld_pointer_set_by_name(const char * name, int client_hint, struct rpld_playlist_pointer * plp) {
pli_t queue;
int pointer, client;
if ( rpld_pointer_parse_name(&pointer, &queue, &client, client_hint, name) == -1 )
return -1;
return rpld_pointer_set(pointer, queue, client, plp);
}
struct rpld_playlist_entry * rpld_pointer_search(const int pointer, pli_t queue, const int client) {
struct rpld_playlist_pointer * plp = rpld_pointer_get(pointer, queue, client);
struct rpld_playlist_entry * ret;
if ( plp == NULL )
return NULL;
ret = rpld_plp_search(plp);
rpld_plp_unref(plp);
return ret;
}
//ll
rpld-0.1.9/pointer.h 0000644 0001750 0001750 00000004011 12266574305 012443 0 ustar phi phi //pointer.h:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef _RPLD_POINTER_H_
#define _RPLD_POINTER_H_
#define POINTER_DEFAULT 0
#define POINTER_CURRENT 1
#define POINTER_STARTUP 2
#define POINTER_TEMP 3
#define POINTER_FALLBACK 4
#define POINTER_NUM 5
char * rpld_pointer_get_name(const int pointer, pli_t queue, const int client);
int rpld_pointer_parse_name(int * pointer, pli_t * queue, int * client, int client_hint, const char * name);
int rpld_pointer_is_set(const int pointer, pli_t queue, const int client);
struct rpld_playlist_pointer * rpld_pointer_get(const int pointer, pli_t queue, const int client);
struct rpld_playlist_pointer * rpld_pointer_get_by_name(const char * name, int client_hint);
int rpld_pointer_set(const int pointer, pli_t queue, const int client, struct rpld_playlist_pointer * plp);
int rpld_pointer_set_by_name(const char * name, int client_hint, struct rpld_playlist_pointer * plp);
struct rpld_playlist_entry * rpld_pointer_search(const int pointer, pli_t queue, const int client);
#endif
//ll
rpld-0.1.9/proto_mpd.c 0000644 0001750 0001750 00000030006 12266574306 012765 0 ustar phi phi //proto_mpd.c:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2014
*
* This file is part of RoarAudio PlayList Daemon,
* a playlist management daemon for RoarAudio.
* See README for details.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* RoarAudio 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "rpld.h"
#define YES 1
#define NO 0
#define ND -1
static struct {
int auth;
char * cmd;
} _commands[] = {
{NO, "setvol"},
{NO, "stop"},
{NO, "play"},
{NO, "playid"},
{NO, "next"},
{NO, "previous"},
{NO, "status"},
{NO, "ping"},
{NO, "close"},
{NO, "commands"},
{NO, "notcommands"},
{NO, "outputs"},
{NO, "urlhandlers"},
{NO, "currentsong"},
{NO, "playlistid"},
{NO, "stats"},
/* not supported commands: */
{ND, "disableoutput"},
{ND, "enableoutput"},
{ND, "kill"},
{ND, "update"},
{ND, "tagtypes"},
{ND, "find"},
{ND, "list"},
{ND, "listall"},
{ND, "listallinfo"},
{ND, "lsinfo"},
{ND, "search"},
{ND, "count"},
{ND, "add"},
{ND, "addid"},
{ND, "clear"},
{ND, "delete"},
{ND, "deleteid"},
{ND, "load"},
{ND, "rename"},
{ND, "move"},
{ND, "moveid"},
{ND, "playlist"},
{ND, "playlistinfo"},
{ND, "plchanges"},
{ND, "plchangesposid"},
{ND, "rm"},
{ND, "save"},
{ND, "shuffle"},
{ND, "swap"},
{ND, "swapid"},
{ND, "listplaylist"},
{ND, "listplaylistinfo"},
{ND, "playlistadd"},
{ND, "playlistclear"},
{ND, "playlistdelete"},
{ND, "playlistmove"},
{ND, "playlistfind"},
{ND, "playlistsearch"},
{ND, "crossfade"},
{ND, "random"},
{ND, "repeat"},
{ND, "seek"},
{ND, "seekid"},
{ND, "setvol"},
{ND, "volume"},
{ND, "clearerror"},
{ND, "password"},
{NO, NULL}
};
static char * _dequote (char * str) {
ssize_t len;
if ( str == NULL )
return NULL;
if ( *str != '"' )
return str;
str++;
len = strlen(str);
str[len-1] = 0;
return str;
}
static void _print_handlers(struct roar_vio_calls * vio) {
char * h[] = {
"file",
"fh",
"socket",
"http",
"gopher",
"icy",
"tantalos",
NULL
};
int i;
for (i = 0; h[i] != NULL; i++)
roar_vio_printf(vio, "handler: %s://\n", h[i]);
}
struct rpld_playlist_entry * proto_mpd_parse_id(int client, char * args) {
struct rpld_playlist_search pls;
struct rpld_playlist_entry * ret;
int i;
int bit31;
(void)client;
memset(&pls, 0, sizeof(pls));
pls.type = RPLD_PL_ST_TRACKNUM_SHORT;
pls.subject.short_tracknum = atol(args);
for (bit31 = 0; bit31 == 0 || bit31 == 1; bit31++) {
pls.subject.short_tracknum |= bit31 ? ((uint32_t)1<<31) : 0;
for (i = 0; i < MAX_PLAYLISTS; i++) {
if ( g_playlists[i] != NULL ) {
if ( (ret = rpld_pl_search(g_playlists[i], &pls, NULL)) != NULL )
return ret;
}
}
}
return NULL;
}
#define _pk(k, kt, v) roar_vio_printf(vio, k ": " kt "\n", (v))
#define _pks(k, v) _pk(k, "%s", v)
int proto_mpd_print_song (int id, struct roar_vio_calls * vio, struct rpld_proto_mpd_error * error, struct rpld_playlist_entry * ple, ssize_t pos) {
uint32_t songid;
/*
Xfile: 2007-omc3-203_orange_sofa-the_one_you_need.ogg
XTime: 209
XAlbum: open music contest #3: "by perseverance the snail reached art" (black disc)
XArtist: orange sofa
Date: 2007
Disc: 2
XGenre: Creative Commons
XTitle: the one you need
XTrack: 03
Pos: 0
Id: 0
*/
(void)id;
(void)error;
if ( ple == NULL )
return -1;
_pks("file", rpld_ple_get_filename(ple, -1, NULL));
if ( ple->length )
_pk("Time", "%lu", (long unsigned int)ple->length);
if ( ple->meta.album[0] != 0 )
_pks("Album", ple->meta.album);
if ( ple->meta.artist[0] != 0 )
_pks("Artist", ple->meta.artist);
_pks("Genre", roar_meta_strgenre(ple->meta.genre));
if ( ple->meta.title[0] != 0 )
_pks("Title", ple->meta.title);
if ( ple->meta.tracknum )
_pk("Track", "%i", ple->meta.tracknum);
if ( pos != -1 )
_pk("Pos", "%lu", (long unsigned int)pos);
songid = ple->global_short_tracknum & (uint32_t)0x7FFFFFFF;
_pk("Id", "%lu", (long unsigned int)songid);
return 0;
}
int proto_mpd_client_set_proto(int id, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen, struct roar_dl_librarypara * pluginpara) {
#define NEW_CLIENT_STRING "OK MPD " RPLD_PROTO_MPD_VERSION "\n"
(void)id, (void)obuffer, (void)userdata, (void)para, (void)paralen, (void)pluginpara;
if ( roar_vio_puts(vio, NEW_CLIENT_STRING) != (sizeof(NEW_CLIENT_STRING)-1) )
return -1;
return 0;
}
int proto_mpd_client_handle(int id, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen, struct roar_dl_librarypara * pluginpara) {
struct rpld_proto_mpd_error error;
ssize_t len;
char * args;
int ret;
char buffer[1024];
(void)obuffer, (void)userdata, (void)para, (void)paralen, (void)pluginpara;
if ( vio == NULL )
return -1;
if ( (len = roar_vio_read(vio, buffer, 1023)) < 1 )
return -1;
if ( buffer[len-1] != '\n' )
return -1;
if ( len > 1 && buffer[len-2] == '\r' ) {
len -= 2;
} else {
len--;
}
buffer[len] = 0;
if ( (args = strstr(buffer, " ")) != NULL ) {
*args = 0;
args++;
}
error.error = RPLD_PROTO_MPD_ACK_ERROR_UNKNOWN;
error.offset = 0;
error.cmd = buffer;
error.msg = "Unknown error";
ret = proto_mpd_pcmd(id, vio, &error, buffer, args);
if ( error.error == RPLD_PROTO_MPD_ACK_ERROR_DISCONNECT )
return -1;
if ( ret == -1 ) {
//ACK [5@2] {} unknown command "pay"
roar_vio_printf(vio, "ACK [%i@%i] {%s} %s\n", error.error, error.offset, error.cmd, error.msg);
} else {
if ( roar_vio_puts(vio, "OK\n") != 3 )
return -1;
}
return 0;
}
#define NULL_OK 0
#define NULL_NOT_OK 1
#define _CK_ARGS(ok) if ( (ok) && args == NULL ) { \
error->error = RPLD_PROTO_MPD_ACK_ERROR_UNKNOWN; \
error->msg = "Protocol error"; \
return -1; \
}
int proto_mpd_pcmd(int id, struct roar_vio_calls * vio, struct rpld_proto_mpd_error * error, char * cmd, char * args) {
pli_t queue = client_get_queue(id);
struct rpld_playlist * pl;
struct rpld_playlist_entry * plent;
const struct roar_stream * s;
ssize_t pos = 0;
int i;
ROAR_DBG("proto_mpd_pcmd(id=%i, vio=%p, error=%p, cmd='%s', args='%s') = ?", id, vio, error, cmd, args);
// handle null-string-command:
if ( *cmd == 0 )
return 0;
/* basic commands */
if ( !strcasecmp(cmd, "close") ) {
_CK_ARGS(NULL_OK);
error->error = RPLD_PROTO_MPD_ACK_ERROR_DISCONNECT;
return 0;
} else if ( !strcasecmp(cmd, "ping") ) {
_CK_ARGS(NULL_OK);
return 0;
/* status commands */
} else if ( !strcasecmp(cmd, "stats") ) {
_CK_ARGS(NULL_OK);
/*
artists: 1
albums: 1
songs: 1
uptime: 6562
playtime: 82
db_playtime: 209
db_update: 1264178670
*/
return 0; // send no info at the moment
} else if ( !strcasecmp(cmd, "status") ) {
_CK_ARGS(NULL_OK);
roar_vio_printf(vio, "volume: %i\n", playback_get_volume_mpc(queue));
roar_vio_printf(vio, "repeat: 0\n");
roar_vio_printf(vio, "random: 0\n");
roar_vio_printf(vio, "playlist: 0\n");
roar_vio_printf(vio, "playlistlength: 0\n"); // count global number of PLEs
roar_vio_printf(vio, "xfade: 0\n");
if ( playback_is_playing(queue) ) {
if ( playback_is_pause(queue) == PLAYBACK_PAUSE_TRUE ) {
roar_vio_printf(vio, "state: pause\n");
} else {
roar_vio_printf(vio, "state: play\n");
}
if ( (plent = playback_get_ple(queue)) != NULL && (s = playback_get_stream(queue)) != NULL ) {
roar_vio_printf(vio, "song: 0\n");
roar_vio_printf(vio, "songid: %u\n", plent->global_short_tracknum & (uint32_t)0x7FFFFFFF);
roar_vio_printf(vio, "time: %u:%u\n", (int)((float)s->pos/(s->info.rate*s->info.channels)), (unsigned)plent->length);
roar_vio_printf(vio, "audio: %i:%i:%i\n", s->info.rate, s->info.bits, s->info.channels);
}
} else {
roar_vio_printf(vio, "state: stop\n");
}
return 0;
} else if ( !strcasecmp(cmd, "outputs") ) {
_CK_ARGS(NULL_OK);
roar_vio_printf(vio, "outputid: 0\n");
roar_vio_printf(vio, "outputname: RoarAudio output\n");
roar_vio_printf(vio, "outputenabled: 1\n");
return 0;
} else if ( !strcasecmp(cmd, "urlhandlers") ) {
_CK_ARGS(NULL_OK);
_print_handlers(vio);
return 0;
/* playback commands */
} else if ( !strcasecmp(cmd, "next") ) {
_CK_ARGS(NULL_OK);
if ( playback_next(queue) != -1 )
return 0;
return -1;
} else if ( !strcasecmp(cmd, "previous") ) {
_CK_ARGS(NULL_OK);
if ( playback_prev(queue) != -1 )
return 0;
return -1;
} else if ( !strcasecmp(cmd, "play") || !strcasecmp(cmd, "playid") ) {
_CK_ARGS(NULL_OK);
args = _dequote(args);
if ( args != NULL && !strcmp(args, "-1") )
args = NULL;
if ( args != NULL ) {
plent = proto_mpd_parse_id(id, args);
if ( plent == NULL ) {
error->msg = "Song not found";
return -1;
}
plent = rpld_ple_copy(plent);
if ( plent == NULL ) {
error->msg = "Can not copy playlist entry into queue";
return -1;
}
pl = rpld_pl_get_by_id(queue);
if ( pl != NULL ) {
rpld_pl_add(pl, plent, 0);
rpld_pl_unref(pl);
}
playback_next(queue);
}
if ( playback_play(queue) != -1 )
return 0;
return -1;
} else if ( !strcasecmp(cmd, "stop") ) {
_CK_ARGS(NULL_OK);
if ( playback_stop(queue, 0, 1) != -1 )
return 0;
return -1;
} else if ( !strcasecmp(cmd, "setvol") ) {
_CK_ARGS(NULL_NOT_OK);
args = _dequote(args);
if ( playback_set_volume_mpc(queue, atoi(args)) == -1 )
return -1;
return 0;
} else if ( !strcasecmp(cmd, "pause") ) {
_CK_ARGS(NULL_OK);
args = _dequote(args);
i = PLAYBACK_PAUSE_TOGGLE;
if ( args != NULL ) {
if ( atoi(args) ) {
i = PLAYBACK_PAUSE_TRUE;
} else {
i = PLAYBACK_PAUSE_FALSE;
}
}
if ( playback_pause(queue, i) != -1 )
return 0;
return -1;
/* plylist commands */
} else if ( !strcasecmp(cmd, "currentsong") ) {
_CK_ARGS(NULL_OK);
if ( playback_is_playing(queue) ) {
plent = playback_get_ple(queue);
} else {
pl = rpld_pl_get_by_id(queue);
if ( pl == NULL ) {
plent = NULL;
} else {
plent = rpld_pl_get_first(pl);
rpld_pl_unref(pl);
}
}
if ( plent == NULL ) {
error->error = RPLD_PROTO_MPD_ACK_ERROR_UNKNOWN; // FIXME
error->msg = "Can not find current song";
return -1;
}
return proto_mpd_print_song(id, vio, error, plent, 0);
} else if ( !strcasecmp(cmd, "playlistid") ) {
_CK_ARGS(NULL_OK);
ROAR_DBG("proto_mpd_pcmd(id=%i, ...): cmd='%s', args='%s'", id, cmd, args);
args = _dequote(args);
if ( args != NULL && !strcmp(args, "-1") )
args = NULL;
if ( args != NULL ) {
plent = proto_mpd_parse_id(id, args);
if ( plent == NULL ) {
error->msg = "Song not found";
return -1;
}
proto_mpd_print_song(id, vio, error, plent, pos++);
return 0;
}
for (i = 0; i < MAX_PLAYLISTS; i++) {
pl = rpld_pl_get_by_id(i);
plent = rpld_pl_get_first(pl);
while (plent != NULL) {
proto_mpd_print_song(id, vio, error, plent, pos++);
plent = plent->list.next;
}
rpld_pl_unref(pl);
}
return 0;
/* control commands */
} else if ( !strcasecmp(cmd, "commands") ) {
_CK_ARGS(NULL_OK);
for (i = 0; _commands[i].cmd != NULL; i++) {
if ( _commands[i].auth == NO )
roar_vio_printf(vio, "command: %s\n", _commands[i].cmd);
}
return 0;
} else if ( !strcasecmp(cmd, "notcommands") ) {
_CK_ARGS(NULL_OK);
for (i = 0; _commands[i].cmd != NULL; i++) {
if ( _commands[i].auth != NO )
roar_vio_printf(vio, "command: %s\n", _commands[i].cmd);
}
return 0;
}
error->error = RPLD_PROTO_MPD_ACK_ERROR_UNKNOWN;
error->msg = "Unsupported command";
return -1;
}
//ll
rpld-0.1.9/proto_mpd.h 0000644 0001750 0001750 00000004675 12266574306 013007 0 ustar phi phi //proto_mpd.h:
/*
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2014
* Copyright (C) Warren Dukes