This commit was manufactured by cvs2svn to create tag 'darkice-0_5'.
This commit is contained in:
		
							parent
							
								
									afaafb9422
								
							
						
					
					
						commit
						08bd0b4272
					
				| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					DarkIce is being written by:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Akos Maroy, <darkeye@users.sourceforge.net>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					with contributions by:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Jim Crilly, <JCrilly@MSA.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,345 @@
 | 
				
			||||||
 | 
					All source code in the src directory is covered under the
 | 
				
			||||||
 | 
					GNU General Public License (GNU GPL).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							    GNU GENERAL PUBLIC LICENSE
 | 
				
			||||||
 | 
							       Version 2, June 1991
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
 | 
				
			||||||
 | 
					     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
				
			||||||
 | 
					 Everyone is permitted to copy and distribute verbatim copies
 | 
				
			||||||
 | 
					 of this license document, but changing it is not allowed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								    Preamble
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The licenses for most software are designed to take away your
 | 
				
			||||||
 | 
					freedom to share and change it.  By contrast, the GNU General Public
 | 
				
			||||||
 | 
					License is intended to guarantee your freedom to share and change free
 | 
				
			||||||
 | 
					software--to make sure the software is free for all its users.  This
 | 
				
			||||||
 | 
					General Public License applies to most of the Free Software
 | 
				
			||||||
 | 
					Foundation's software and to any other program whose authors commit to
 | 
				
			||||||
 | 
					using it.  (Some other Free Software Foundation software is covered by
 | 
				
			||||||
 | 
					the GNU Library General Public License instead.)  You can apply it to
 | 
				
			||||||
 | 
					your programs, too.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  When we speak of free software, we are referring to freedom, not
 | 
				
			||||||
 | 
					price.  Our General Public Licenses are designed to make sure that you
 | 
				
			||||||
 | 
					have the freedom to distribute copies of free software (and charge for
 | 
				
			||||||
 | 
					this service if you wish), that you receive source code or can get it
 | 
				
			||||||
 | 
					if you want it, that you can change the software or use pieces of it
 | 
				
			||||||
 | 
					in new free programs; and that you know you can do these things.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  To protect your rights, we need to make restrictions that forbid
 | 
				
			||||||
 | 
					anyone to deny you these rights or to ask you to surrender the rights.
 | 
				
			||||||
 | 
					These restrictions translate to certain responsibilities for you if you
 | 
				
			||||||
 | 
					distribute copies of the software, or if you modify it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  For example, if you distribute copies of such a program, whether
 | 
				
			||||||
 | 
					gratis or for a fee, you must give the recipients all the rights that
 | 
				
			||||||
 | 
					you have.  You must make sure that they, too, receive or can get the
 | 
				
			||||||
 | 
					source code.  And you must show them these terms so they know their
 | 
				
			||||||
 | 
					rights.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  We protect your rights with two steps: (1) copyright the software, and
 | 
				
			||||||
 | 
					(2) offer you this license which gives you legal permission to copy,
 | 
				
			||||||
 | 
					distribute and/or modify the software.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Also, for each author's protection and ours, we want to make certain
 | 
				
			||||||
 | 
					that everyone understands that there is no warranty for this free
 | 
				
			||||||
 | 
					software.  If the software is modified by someone else and passed on, we
 | 
				
			||||||
 | 
					want its recipients to know that what they have is not the original, so
 | 
				
			||||||
 | 
					that any problems introduced by others will not reflect on the original
 | 
				
			||||||
 | 
					authors' reputations.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Finally, any free program is threatened constantly by software
 | 
				
			||||||
 | 
					patents.  We wish to avoid the danger that redistributors of a free
 | 
				
			||||||
 | 
					program will individually obtain patent licenses, in effect making the
 | 
				
			||||||
 | 
					program proprietary.  To prevent this, we have made it clear that any
 | 
				
			||||||
 | 
					patent must be licensed for everyone's free use or not licensed at all.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The precise terms and conditions for copying, distribution and
 | 
				
			||||||
 | 
					modification follow.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							    GNU GENERAL PUBLIC LICENSE
 | 
				
			||||||
 | 
					   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  0. This License applies to any program or other work which contains
 | 
				
			||||||
 | 
					a notice placed by the copyright holder saying it may be distributed
 | 
				
			||||||
 | 
					under the terms of this General Public License.  The "Program", below,
 | 
				
			||||||
 | 
					refers to any such program or work, and a "work based on the Program"
 | 
				
			||||||
 | 
					means either the Program or any derivative work under copyright law:
 | 
				
			||||||
 | 
					that is to say, a work containing the Program or a portion of it,
 | 
				
			||||||
 | 
					either verbatim or with modifications and/or translated into another
 | 
				
			||||||
 | 
					language.  (Hereinafter, translation is included without limitation in
 | 
				
			||||||
 | 
					the term "modification".)  Each licensee is addressed as "you".
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Activities other than copying, distribution and modification are not
 | 
				
			||||||
 | 
					covered by this License; they are outside its scope.  The act of
 | 
				
			||||||
 | 
					running the Program is not restricted, and the output from the Program
 | 
				
			||||||
 | 
					is covered only if its contents constitute a work based on the
 | 
				
			||||||
 | 
					Program (independent of having been made by running the Program).
 | 
				
			||||||
 | 
					Whether that is true depends on what the Program does.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  1. You may copy and distribute verbatim copies of the Program's
 | 
				
			||||||
 | 
					source code as you receive it, in any medium, provided that you
 | 
				
			||||||
 | 
					conspicuously and appropriately publish on each copy an appropriate
 | 
				
			||||||
 | 
					copyright notice and disclaimer of warranty; keep intact all the
 | 
				
			||||||
 | 
					notices that refer to this License and to the absence of any warranty;
 | 
				
			||||||
 | 
					and give any other recipients of the Program a copy of this License
 | 
				
			||||||
 | 
					along with the Program.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You may charge a fee for the physical act of transferring a copy, and
 | 
				
			||||||
 | 
					you may at your option offer warranty protection in exchange for a fee.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  2. You may modify your copy or copies of the Program or any portion
 | 
				
			||||||
 | 
					of it, thus forming a work based on the Program, and copy and
 | 
				
			||||||
 | 
					distribute such modifications or work under the terms of Section 1
 | 
				
			||||||
 | 
					above, provided that you also meet all of these conditions:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    a) You must cause the modified files to carry prominent notices
 | 
				
			||||||
 | 
					    stating that you changed the files and the date of any change.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    b) You must cause any work that you distribute or publish, that in
 | 
				
			||||||
 | 
					    whole or in part contains or is derived from the Program or any
 | 
				
			||||||
 | 
					    part thereof, to be licensed as a whole at no charge to all third
 | 
				
			||||||
 | 
					    parties under the terms of this License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    c) If the modified program normally reads commands interactively
 | 
				
			||||||
 | 
					    when run, you must cause it, when started running for such
 | 
				
			||||||
 | 
					    interactive use in the most ordinary way, to print or display an
 | 
				
			||||||
 | 
					    announcement including an appropriate copyright notice and a
 | 
				
			||||||
 | 
					    notice that there is no warranty (or else, saying that you provide
 | 
				
			||||||
 | 
					    a warranty) and that users may redistribute the program under
 | 
				
			||||||
 | 
					    these conditions, and telling the user how to view a copy of this
 | 
				
			||||||
 | 
					    License.  (Exception: if the Program itself is interactive but
 | 
				
			||||||
 | 
					    does not normally print such an announcement, your work based on
 | 
				
			||||||
 | 
					    the Program is not required to print an announcement.)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					These requirements apply to the modified work as a whole.  If
 | 
				
			||||||
 | 
					identifiable sections of that work are not derived from the Program,
 | 
				
			||||||
 | 
					and can be reasonably considered independent and separate works in
 | 
				
			||||||
 | 
					themselves, then this License, and its terms, do not apply to those
 | 
				
			||||||
 | 
					sections when you distribute them as separate works.  But when you
 | 
				
			||||||
 | 
					distribute the same sections as part of a whole which is a work based
 | 
				
			||||||
 | 
					on the Program, the distribution of the whole must be on the terms of
 | 
				
			||||||
 | 
					this License, whose permissions for other licensees extend to the
 | 
				
			||||||
 | 
					entire whole, and thus to each and every part regardless of who wrote it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Thus, it is not the intent of this section to claim rights or contest
 | 
				
			||||||
 | 
					your rights to work written entirely by you; rather, the intent is to
 | 
				
			||||||
 | 
					exercise the right to control the distribution of derivative or
 | 
				
			||||||
 | 
					collective works based on the Program.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					In addition, mere aggregation of another work not based on the Program
 | 
				
			||||||
 | 
					with the Program (or with a work based on the Program) on a volume of
 | 
				
			||||||
 | 
					a storage or distribution medium does not bring the other work under
 | 
				
			||||||
 | 
					the scope of this License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  3. You may copy and distribute the Program (or a work based on it,
 | 
				
			||||||
 | 
					under Section 2) in object code or executable form under the terms of
 | 
				
			||||||
 | 
					Sections 1 and 2 above provided that you also do one of the following:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    a) Accompany it with the complete corresponding machine-readable
 | 
				
			||||||
 | 
					    source code, which must be distributed under the terms of Sections
 | 
				
			||||||
 | 
					    1 and 2 above on a medium customarily used for software interchange; or,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    b) Accompany it with a written offer, valid for at least three
 | 
				
			||||||
 | 
					    years, to give any third party, for a charge no more than your
 | 
				
			||||||
 | 
					    cost of physically performing source distribution, a complete
 | 
				
			||||||
 | 
					    machine-readable copy of the corresponding source code, to be
 | 
				
			||||||
 | 
					    distributed under the terms of Sections 1 and 2 above on a medium
 | 
				
			||||||
 | 
					    customarily used for software interchange; or,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    c) Accompany it with the information you received as to the offer
 | 
				
			||||||
 | 
					    to distribute corresponding source code.  (This alternative is
 | 
				
			||||||
 | 
					    allowed only for noncommercial distribution and only if you
 | 
				
			||||||
 | 
					    received the program in object code or executable form with such
 | 
				
			||||||
 | 
					    an offer, in accord with Subsection b above.)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The source code for a work means the preferred form of the work for
 | 
				
			||||||
 | 
					making modifications to it.  For an executable work, complete source
 | 
				
			||||||
 | 
					code means all the source code for all modules it contains, plus any
 | 
				
			||||||
 | 
					associated interface definition files, plus the scripts used to
 | 
				
			||||||
 | 
					control compilation and installation of the executable.  However, as a
 | 
				
			||||||
 | 
					special exception, the source code distributed need not include
 | 
				
			||||||
 | 
					anything that is normally distributed (in either source or binary
 | 
				
			||||||
 | 
					form) with the major components (compiler, kernel, and so on) of the
 | 
				
			||||||
 | 
					operating system on which the executable runs, unless that component
 | 
				
			||||||
 | 
					itself accompanies the executable.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If distribution of executable or object code is made by offering
 | 
				
			||||||
 | 
					access to copy from a designated place, then offering equivalent
 | 
				
			||||||
 | 
					access to copy the source code from the same place counts as
 | 
				
			||||||
 | 
					distribution of the source code, even though third parties are not
 | 
				
			||||||
 | 
					compelled to copy the source along with the object code.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  4. You may not copy, modify, sublicense, or distribute the Program
 | 
				
			||||||
 | 
					except as expressly provided under this License.  Any attempt
 | 
				
			||||||
 | 
					otherwise to copy, modify, sublicense or distribute the Program is
 | 
				
			||||||
 | 
					void, and will automatically terminate your rights under this License.
 | 
				
			||||||
 | 
					However, parties who have received copies, or rights, from you under
 | 
				
			||||||
 | 
					this License will not have their licenses terminated so long as such
 | 
				
			||||||
 | 
					parties remain in full compliance.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  5. You are not required to accept this License, since you have not
 | 
				
			||||||
 | 
					signed it.  However, nothing else grants you permission to modify or
 | 
				
			||||||
 | 
					distribute the Program or its derivative works.  These actions are
 | 
				
			||||||
 | 
					prohibited by law if you do not accept this License.  Therefore, by
 | 
				
			||||||
 | 
					modifying or distributing the Program (or any work based on the
 | 
				
			||||||
 | 
					Program), you indicate your acceptance of this License to do so, and
 | 
				
			||||||
 | 
					all its terms and conditions for copying, distributing or modifying
 | 
				
			||||||
 | 
					the Program or works based on it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  6. Each time you redistribute the Program (or any work based on the
 | 
				
			||||||
 | 
					Program), the recipient automatically receives a license from the
 | 
				
			||||||
 | 
					original licensor to copy, distribute or modify the Program subject to
 | 
				
			||||||
 | 
					these terms and conditions.  You may not impose any further
 | 
				
			||||||
 | 
					restrictions on the recipients' exercise of the rights granted herein.
 | 
				
			||||||
 | 
					You are not responsible for enforcing compliance by third parties to
 | 
				
			||||||
 | 
					this License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  7. If, as a consequence of a court judgment or allegation of patent
 | 
				
			||||||
 | 
					infringement or for any other reason (not limited to patent issues),
 | 
				
			||||||
 | 
					conditions are imposed on you (whether by court order, agreement or
 | 
				
			||||||
 | 
					otherwise) that contradict the conditions of this License, they do not
 | 
				
			||||||
 | 
					excuse you from the conditions of this License.  If you cannot
 | 
				
			||||||
 | 
					distribute so as to satisfy simultaneously your obligations under this
 | 
				
			||||||
 | 
					License and any other pertinent obligations, then as a consequence you
 | 
				
			||||||
 | 
					may not distribute the Program at all.  For example, if a patent
 | 
				
			||||||
 | 
					license would not permit royalty-free redistribution of the Program by
 | 
				
			||||||
 | 
					all those who receive copies directly or indirectly through you, then
 | 
				
			||||||
 | 
					the only way you could satisfy both it and this License would be to
 | 
				
			||||||
 | 
					refrain entirely from distribution of the Program.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If any portion of this section is held invalid or unenforceable under
 | 
				
			||||||
 | 
					any particular circumstance, the balance of the section is intended to
 | 
				
			||||||
 | 
					apply and the section as a whole is intended to apply in other
 | 
				
			||||||
 | 
					circumstances.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					It is not the purpose of this section to induce you to infringe any
 | 
				
			||||||
 | 
					patents or other property right claims or to contest validity of any
 | 
				
			||||||
 | 
					such claims; this section has the sole purpose of protecting the
 | 
				
			||||||
 | 
					integrity of the free software distribution system, which is
 | 
				
			||||||
 | 
					implemented by public license practices.  Many people have made
 | 
				
			||||||
 | 
					generous contributions to the wide range of software distributed
 | 
				
			||||||
 | 
					through that system in reliance on consistent application of that
 | 
				
			||||||
 | 
					system; it is up to the author/donor to decide if he or she is willing
 | 
				
			||||||
 | 
					to distribute software through any other system and a licensee cannot
 | 
				
			||||||
 | 
					impose that choice.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This section is intended to make thoroughly clear what is believed to
 | 
				
			||||||
 | 
					be a consequence of the rest of this License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  8. If the distribution and/or use of the Program is restricted in
 | 
				
			||||||
 | 
					certain countries either by patents or by copyrighted interfaces, the
 | 
				
			||||||
 | 
					original copyright holder who places the Program under this License
 | 
				
			||||||
 | 
					may add an explicit geographical distribution limitation excluding
 | 
				
			||||||
 | 
					those countries, so that distribution is permitted only in or among
 | 
				
			||||||
 | 
					countries not thus excluded.  In such case, this License incorporates
 | 
				
			||||||
 | 
					the limitation as if written in the body of this License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  9. The Free Software Foundation may publish revised and/or new versions
 | 
				
			||||||
 | 
					of the General Public License from time to time.  Such new versions will
 | 
				
			||||||
 | 
					be similar in spirit to the present version, but may differ in detail to
 | 
				
			||||||
 | 
					address new problems or concerns.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Each version is given a distinguishing version number.  If the Program
 | 
				
			||||||
 | 
					specifies a version number of this License which applies to it and "any
 | 
				
			||||||
 | 
					later version", you have the option of following the terms and conditions
 | 
				
			||||||
 | 
					either of that version or of any later version published by the Free
 | 
				
			||||||
 | 
					Software Foundation.  If the Program does not specify a version number of
 | 
				
			||||||
 | 
					this License, you may choose any version ever published by the Free Software
 | 
				
			||||||
 | 
					Foundation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  10. If you wish to incorporate parts of the Program into other free
 | 
				
			||||||
 | 
					programs whose distribution conditions are different, write to the author
 | 
				
			||||||
 | 
					to ask for permission.  For software which is copyrighted by the Free
 | 
				
			||||||
 | 
					Software Foundation, write to the Free Software Foundation; we sometimes
 | 
				
			||||||
 | 
					make exceptions for this.  Our decision will be guided by the two goals
 | 
				
			||||||
 | 
					of preserving the free status of all derivatives of our free software and
 | 
				
			||||||
 | 
					of promoting the sharing and reuse of software generally.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								    NO WARRANTY
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
 | 
				
			||||||
 | 
					FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
 | 
				
			||||||
 | 
					OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
 | 
				
			||||||
 | 
					PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
 | 
				
			||||||
 | 
					OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 | 
				
			||||||
 | 
					MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
 | 
				
			||||||
 | 
					TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
 | 
				
			||||||
 | 
					PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
 | 
				
			||||||
 | 
					REPAIR OR CORRECTION.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
 | 
				
			||||||
 | 
					WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
 | 
				
			||||||
 | 
					REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
 | 
				
			||||||
 | 
					INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
 | 
				
			||||||
 | 
					OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
 | 
				
			||||||
 | 
					TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
 | 
				
			||||||
 | 
					YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
 | 
				
			||||||
 | 
					PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
 | 
				
			||||||
 | 
					POSSIBILITY OF SUCH DAMAGES.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							     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
 | 
				
			||||||
 | 
					convey the exclusion of warranty; and each file should have at least
 | 
				
			||||||
 | 
					the "copyright" line and a pointer to where the full notice is found.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <one line to give the program's name and a brief idea of what it does.>
 | 
				
			||||||
 | 
					    Copyright (C) <year>  <name of author>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					    it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					    the Free Software Foundation; either version 2 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Also add information on how to contact you by electronic and paper mail.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If the program is interactive, make it output a short notice like this
 | 
				
			||||||
 | 
					when it starts in an interactive mode:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Gnomovision version 69, Copyright (C) year  name of author
 | 
				
			||||||
 | 
					    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
 | 
				
			||||||
 | 
					    This is free software, and you are welcome to redistribute it
 | 
				
			||||||
 | 
					    under certain conditions; type `show c' for details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The hypothetical commands `show w' and `show c' should show the appropriate
 | 
				
			||||||
 | 
					parts of the General Public License.  Of course, the commands you use may
 | 
				
			||||||
 | 
					be called something other than `show w' and `show c'; they could even be
 | 
				
			||||||
 | 
					mouse-clicks or menu items--whatever suits your program.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You should also get your employer (if you work as a programmer) or your
 | 
				
			||||||
 | 
					school, if any, to sign a "copyright disclaimer" for the program, if
 | 
				
			||||||
 | 
					necessary.  Here is a sample; alter the names:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
 | 
				
			||||||
 | 
					  `Gnomovision' (which makes passes at compilers) written by James Hacker.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <signature of Ty Coon>, 1 April 1989
 | 
				
			||||||
 | 
					  Ty Coon, President of Vice
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This General Public License does not permit incorporating your program into
 | 
				
			||||||
 | 
					proprietary programs.  If your program is a subroutine library, you may
 | 
				
			||||||
 | 
					consider it more useful to permit linking proprietary applications with the
 | 
				
			||||||
 | 
					library.  If this is what you want to do, use the GNU Library General
 | 
				
			||||||
 | 
					Public License instead of this License.
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					09-09-2001: DarkIce 0.5 released
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    o added support for ShoutCast servers
 | 
				
			||||||
 | 
					    o removed local copy of SGI STL, uses STL of the C++ compiler
 | 
				
			||||||
 | 
					    o compiles with gcc3-c++
 | 
				
			||||||
 | 
					    o added man page darkice.cfg.5
 | 
				
			||||||
 | 
					    o bugfix: config files can have comments before the first section
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					02-09-2001: DarkIce 0.4 released
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    o support for external command line encoder removed, replaced
 | 
				
			||||||
 | 
					      with using lame as a shared object or statically linked library
 | 
				
			||||||
 | 
					    o added darkice man page
 | 
				
			||||||
 | 
					    o created RPM packages
 | 
				
			||||||
 | 
					    o DarkIce no longer reports an error if the sound card recording
 | 
				
			||||||
 | 
					      sample rate could not be set to the exact specified amount
 | 
				
			||||||
 | 
					      (e.g. the sound card reports 44101 Hz instead of 44100 Hz)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					26-08-2001: DarkIce 0.3.1 released
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    o support for unlimited time encoding
 | 
				
			||||||
 | 
					      thanks to Jim Crilly, <JCrilly@MSA.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					20-12-2000: DarkIce 0.3 released
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    o added POSIX real-time scheduling
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					18-11-2000: DarkIce 0.2 released
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    o code cleanup
 | 
				
			||||||
 | 
					    o first real tests made
 | 
				
			||||||
 | 
					    o added verbosity command line option
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					13-11-2000: DarkIce 0.1 released
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,273 @@
 | 
				
			||||||
 | 
					DarkIce installation notes
 | 
				
			||||||
 | 
					==========================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Installing Lame
 | 
				
			||||||
 | 
					---------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To install DarkIce, you need the lame 3.89 or later libraries already
 | 
				
			||||||
 | 
					installed on your system. If you already have done this, skip to the next
 | 
				
			||||||
 | 
					section.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Compiling Lame is a tricky issue. Please refer to Lame online resources
 | 
				
			||||||
 | 
					for details. Here are steps I took to compile lame 3.89 on my RedHat 7.1
 | 
				
			||||||
 | 
					system.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					First make sure you have the compatibility compiler packages installed
 | 
				
			||||||
 | 
					on your system, compat-egcs in particular. This provides an older, not
 | 
				
			||||||
 | 
					so much tweaked version of gcc/egcs that is able to compile Lame properly.
 | 
				
			||||||
 | 
					To check this condition easily, try:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rpm -q compat-egcs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for this command I get the response:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					compat-egcs-6.2-1.1.2.14
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Grab the latest lame source tarball from
 | 
				
			||||||
 | 
					ftp://lame.sourceforge.net/pub/lame/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					I took lame lame3.89beta.tar.gz. Go to the directory where you saved it,
 | 
				
			||||||
 | 
					and issue the following commands:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tar xfz lame3.89beta.tar.gz
 | 
				
			||||||
 | 
					cd lame-3.89
 | 
				
			||||||
 | 
					export CC=kgcc
 | 
				
			||||||
 | 
					./configure
 | 
				
			||||||
 | 
					make
 | 
				
			||||||
 | 
					make install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For the last step, you need to be root or have write permissions in the
 | 
				
			||||||
 | 
					target directories, usually directories under /usr/local.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Installing DarkIce
 | 
				
			||||||
 | 
					------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If you're reading this, you probably have downloaded and extracted the
 | 
				
			||||||
 | 
					DarkIce tarball. Go to the directory you extracted it, and try:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					./configure --help
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This will give you all the compile configuration options. Options of
 | 
				
			||||||
 | 
					particlar interest are:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  --with-lame-prefix=DIR  alternate location for lame [/usr]
 | 
				
			||||||
 | 
					                          files looked for: LAME-PREFIX/lib/libmp3lame.a
 | 
				
			||||||
 | 
					                                            LAME-PREFIX/include/lame/lame.h
 | 
				
			||||||
 | 
					  --enable-static         link everything into the executable statically [no]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Use --with-lame-prefix to specify a location for the Lame libraries and
 | 
				
			||||||
 | 
					include files other than /usr/local. Typicall Lame is installed into
 | 
				
			||||||
 | 
					this location. Should you have it somewhere else, this option gives you
 | 
				
			||||||
 | 
					the possibility to notify DarkIce of Lame's location.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Use --enable-static to build a statically linked executable. This is good
 | 
				
			||||||
 | 
					if you plan to deploy DarkIce on a system where either the Lame shared
 | 
				
			||||||
 | 
					object is not installed or its location is unknown. In general it is a
 | 
				
			||||||
 | 
					better idea to link dynamically (not using this option).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If chosing the default compile options, with lame installed under /usr/local,
 | 
				
			||||||
 | 
					compilation is done as follows:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					./configure --with-lame-prefix=/usr/local
 | 
				
			||||||
 | 
					make
 | 
				
			||||||
 | 
					make install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For the last step, you need to be root or have write permissions in the
 | 
				
			||||||
 | 
					target directories, usually directories under /usr/local.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Now you should have DarkIce installed. For documentation, try
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					man darkice
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To try out the program, try
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					darkice -h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Here follows the stock text for autoconf installation procedures:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Basic Installation
 | 
				
			||||||
 | 
					==================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   These are generic installation instructions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   The `configure' shell script attempts to guess correct values for
 | 
				
			||||||
 | 
					various system-dependent variables used during compilation.  It uses
 | 
				
			||||||
 | 
					those values to create a `Makefile' in each directory of the package.
 | 
				
			||||||
 | 
					It may also create one or more `.h' files containing system-dependent
 | 
				
			||||||
 | 
					definitions.  Finally, it creates a shell script `config.status' that
 | 
				
			||||||
 | 
					you can run in the future to recreate the current configuration, a file
 | 
				
			||||||
 | 
					`config.cache' that saves the results of its tests to speed up
 | 
				
			||||||
 | 
					reconfiguring, and a file `config.log' containing compiler output
 | 
				
			||||||
 | 
					(useful mainly for debugging `configure').
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   If you need to do unusual things to compile the package, please try
 | 
				
			||||||
 | 
					to figure out how `configure' could check whether to do them, and mail
 | 
				
			||||||
 | 
					diffs or instructions to the address given in the `README' so they can
 | 
				
			||||||
 | 
					be considered for the next release.  If at some point `config.cache'
 | 
				
			||||||
 | 
					contains results you don't want to keep, you may remove or edit it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   The file `configure.in' is used to create `configure' by a program
 | 
				
			||||||
 | 
					called `autoconf'.  You only need `configure.in' if you want to change
 | 
				
			||||||
 | 
					it or regenerate `configure' using a newer version of `autoconf'.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The simplest way to compile this package is:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  1. `cd' to the directory containing the package's source code and type
 | 
				
			||||||
 | 
					     `./configure' to configure the package for your system.  If you're
 | 
				
			||||||
 | 
					     using `csh' on an old version of System V, you might need to type
 | 
				
			||||||
 | 
					     `sh ./configure' instead to prevent `csh' from trying to execute
 | 
				
			||||||
 | 
					     `configure' itself.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     Running `configure' takes awhile.  While running, it prints some
 | 
				
			||||||
 | 
					     messages telling which features it is checking for.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  2. Type `make' to compile the package.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  3. Optionally, type `make check' to run any self-tests that come with
 | 
				
			||||||
 | 
					     the package.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  4. Type `make install' to install the programs and any data files and
 | 
				
			||||||
 | 
					     documentation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  5. You can remove the program binaries and object files from the
 | 
				
			||||||
 | 
					     source code directory by typing `make clean'.  To also remove the
 | 
				
			||||||
 | 
					     files that `configure' created (so you can compile the package for
 | 
				
			||||||
 | 
					     a different kind of computer), type `make distclean'.  There is
 | 
				
			||||||
 | 
					     also a `make maintainer-clean' target, but that is intended mainly
 | 
				
			||||||
 | 
					     for the package's developers.  If you use it, you may have to get
 | 
				
			||||||
 | 
					     all sorts of other programs in order to regenerate files that came
 | 
				
			||||||
 | 
					     with the distribution.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Compilers and Options
 | 
				
			||||||
 | 
					=====================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Some systems require unusual options for compilation or linking that
 | 
				
			||||||
 | 
					the `configure' script does not know about.  You can give `configure'
 | 
				
			||||||
 | 
					initial values for variables by setting them in the environment.  Using
 | 
				
			||||||
 | 
					a Bourne-compatible shell, you can do that on the command line like
 | 
				
			||||||
 | 
					this:
 | 
				
			||||||
 | 
					     CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Or on systems that have the `env' program, you can do it like this:
 | 
				
			||||||
 | 
					     env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Compiling For Multiple Architectures
 | 
				
			||||||
 | 
					====================================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   You can compile the package for more than one kind of computer at the
 | 
				
			||||||
 | 
					same time, by placing the object files for each architecture in their
 | 
				
			||||||
 | 
					own directory.  To do this, you must use a version of `make' that
 | 
				
			||||||
 | 
					supports the `VPATH' variable, such as GNU `make'.  `cd' to the
 | 
				
			||||||
 | 
					directory where you want the object files and executables to go and run
 | 
				
			||||||
 | 
					the `configure' script.  `configure' automatically checks for the
 | 
				
			||||||
 | 
					source code in the directory that `configure' is in and in `..'.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   If you have to use a `make' that does not supports the `VPATH'
 | 
				
			||||||
 | 
					variable, you have to compile the package for one architecture at a time
 | 
				
			||||||
 | 
					in the source code directory.  After you have installed the package for
 | 
				
			||||||
 | 
					one architecture, use `make distclean' before reconfiguring for another
 | 
				
			||||||
 | 
					architecture.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Installation Names
 | 
				
			||||||
 | 
					==================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   By default, `make install' will install the package's files in
 | 
				
			||||||
 | 
					`/usr/local/bin', `/usr/local/man', etc.  You can specify an
 | 
				
			||||||
 | 
					installation prefix other than `/usr/local' by giving `configure' the
 | 
				
			||||||
 | 
					option `--prefix=PATH'.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   You can specify separate installation prefixes for
 | 
				
			||||||
 | 
					architecture-specific files and architecture-independent files.  If you
 | 
				
			||||||
 | 
					give `configure' the option `--exec-prefix=PATH', the package will use
 | 
				
			||||||
 | 
					PATH as the prefix for installing programs and libraries.
 | 
				
			||||||
 | 
					Documentation and other data files will still use the regular prefix.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   In addition, if you use an unusual directory layout you can give
 | 
				
			||||||
 | 
					options like `--bindir=PATH' to specify different values for particular
 | 
				
			||||||
 | 
					kinds of files.  Run `configure --help' for a list of the directories
 | 
				
			||||||
 | 
					you can set and what kinds of files go in them.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   If the package supports it, you can cause programs to be installed
 | 
				
			||||||
 | 
					with an extra prefix or suffix on their names by giving `configure' the
 | 
				
			||||||
 | 
					option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Optional Features
 | 
				
			||||||
 | 
					=================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Some packages pay attention to `--enable-FEATURE' options to
 | 
				
			||||||
 | 
					`configure', where FEATURE indicates an optional part of the package.
 | 
				
			||||||
 | 
					They may also pay attention to `--with-PACKAGE' options, where PACKAGE
 | 
				
			||||||
 | 
					is something like `gnu-as' or `x' (for the X Window System).  The
 | 
				
			||||||
 | 
					`README' should mention any `--enable-' and `--with-' options that the
 | 
				
			||||||
 | 
					package recognizes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   For packages that use the X Window System, `configure' can usually
 | 
				
			||||||
 | 
					find the X include and library files automatically, but if it doesn't,
 | 
				
			||||||
 | 
					you can use the `configure' options `--x-includes=DIR' and
 | 
				
			||||||
 | 
					`--x-libraries=DIR' to specify their locations.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Specifying the System Type
 | 
				
			||||||
 | 
					==========================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   There may be some features `configure' can not figure out
 | 
				
			||||||
 | 
					automatically, but needs to determine by the type of host the package
 | 
				
			||||||
 | 
					will run on.  Usually `configure' can figure that out, but if it prints
 | 
				
			||||||
 | 
					a message saying it can not guess the host type, give it the
 | 
				
			||||||
 | 
					`--host=TYPE' option.  TYPE can either be a short name for the system
 | 
				
			||||||
 | 
					type, such as `sun4', or a canonical name with three fields:
 | 
				
			||||||
 | 
					     CPU-COMPANY-SYSTEM
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					See the file `config.sub' for the possible values of each field.  If
 | 
				
			||||||
 | 
					`config.sub' isn't included in this package, then this package doesn't
 | 
				
			||||||
 | 
					need to know the host type.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   If you are building compiler tools for cross-compiling, you can also
 | 
				
			||||||
 | 
					use the `--target=TYPE' option to select the type of system they will
 | 
				
			||||||
 | 
					produce code for and the `--build=TYPE' option to select the type of
 | 
				
			||||||
 | 
					system on which you are compiling the package.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Sharing Defaults
 | 
				
			||||||
 | 
					================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   If you want to set default values for `configure' scripts to share,
 | 
				
			||||||
 | 
					you can create a site shell script called `config.site' that gives
 | 
				
			||||||
 | 
					default values for variables like `CC', `cache_file', and `prefix'.
 | 
				
			||||||
 | 
					`configure' looks for `PREFIX/share/config.site' if it exists, then
 | 
				
			||||||
 | 
					`PREFIX/etc/config.site' if it exists.  Or, you can set the
 | 
				
			||||||
 | 
					`CONFIG_SITE' environment variable to the location of the site script.
 | 
				
			||||||
 | 
					A warning: not all `configure' scripts look for a site script.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Operation Controls
 | 
				
			||||||
 | 
					==================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   `configure' recognizes the following options to control how it
 | 
				
			||||||
 | 
					operates.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`--cache-file=FILE'
 | 
				
			||||||
 | 
					     Use and save the results of the tests in FILE instead of
 | 
				
			||||||
 | 
					     `./config.cache'.  Set FILE to `/dev/null' to disable caching, for
 | 
				
			||||||
 | 
					     debugging `configure'.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`--help'
 | 
				
			||||||
 | 
					     Print a summary of the options to `configure', and exit.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`--quiet'
 | 
				
			||||||
 | 
					`--silent'
 | 
				
			||||||
 | 
					`-q'
 | 
				
			||||||
 | 
					     Do not print messages saying which checks are being made.  To
 | 
				
			||||||
 | 
					     suppress all normal output, redirect it to `/dev/null' (any error
 | 
				
			||||||
 | 
					     messages will still be shown).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`--srcdir=DIR'
 | 
				
			||||||
 | 
					     Look for the package's source code in directory DIR.  Usually
 | 
				
			||||||
 | 
					     `configure' can determine that directory automatically.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`--version'
 | 
				
			||||||
 | 
					     Print the version of Autoconf used to generate the `configure'
 | 
				
			||||||
 | 
					     script, and exit.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`configure' also accepts some other, not widely useful, options.
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,16 @@
 | 
				
			||||||
 | 
					KDOC_DIR=kdoc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					SUBDIRS = src man
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sysconf_DATA = darkice.cfg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					EXTRA_DIST = $(KDOC_DIR) darkice.cfg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$(KDOC_DIR): kdocs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					kdocs: src kdocs_clean
 | 
				
			||||||
 | 
						cd src; kdoc --private --strip-h-path --name DarkIce --outputdir ../$(KDOC_DIR)/ *.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					kdocs_clean:
 | 
				
			||||||
 | 
						rm -rf $(KDOC_DIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,25 @@
 | 
				
			||||||
 | 
					02-09-2001, Akos Maroy, darkeye@users.sourceforge.net
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Released version 0.4. See ChangeLog for changes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					26-08-2001, Akos Maroy, darkeye@users.sourceforge.net
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Released version 0.3.1. See ChangeLog for changes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					20-12-2000, Akos Maroy, darkeye@users.sourceforge.net
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Released version 0.3. See ChangeLog for changes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					18-11-2000, Akos Maroy, darkeye@users.sourceforge.net
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Released version 0.2. See ChangeLog for changes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					13-11-2000, Akos Maroy, darkeye@users.sourceforge.net
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Initial release. Supports the lame encoder.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,31 @@
 | 
				
			||||||
 | 
					DarkIce 0.4 live audio streamer, http://darkice.sourceforge.net
 | 
				
			||||||
 | 
					Copyright (c) 2000-2001, Tyrell Hungary, http://tyrell.hu
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Contents
 | 
				
			||||||
 | 
					--------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. Compiling and installing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. Compiling and installing
 | 
				
			||||||
 | 
					---------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					On how to compile and install, please read the file INSTALL. If you're
 | 
				
			||||||
 | 
					impatient, try:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					./configure
 | 
				
			||||||
 | 
					make
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The executable built is src/darkice.
 | 
				
			||||||
 | 
					To install, try as root:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					make install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For documentation, try:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					man darkice
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,9 @@
 | 
				
			||||||
 | 
					o change Ref to follow inheritance
 | 
				
			||||||
 | 
					o make a master config file, and a small one ?
 | 
				
			||||||
 | 
					o add support for VBR encoding
 | 
				
			||||||
 | 
					o reconnect to server if connection is dropped
 | 
				
			||||||
 | 
					o add support for multiple servers for one stream ?
 | 
				
			||||||
 | 
					o libtoolize ?
 | 
				
			||||||
 | 
					o add IceCast 2 support w/ ogg vorbis
 | 
				
			||||||
 | 
					o revisit real-time scheduling and one-thread-per-connection
 | 
				
			||||||
 | 
					o look into performance
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,53 @@
 | 
				
			||||||
 | 
					dnl acinclude.m4. Change *this* file to add new or change macros.
 | 
				
			||||||
 | 
					dnl When changes have been made, delete aclocal.m4 and run
 | 
				
			||||||
 | 
					dnl "aclocal".
 | 
				
			||||||
 | 
					dnl
 | 
				
			||||||
 | 
					dnl DO NOT change aclocal.m4 !
 | 
				
			||||||
 | 
					dnl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dnl * LA_SEARCH_FILE(variable, filename, PATH)
 | 
				
			||||||
 | 
					dnl * Search "filename" in the specified "PATH", "variable" will 
 | 
				
			||||||
 | 
					dnl * contain the full pathname or the empty string
 | 
				
			||||||
 | 
					dnl * PATH is space-separated list of directories.
 | 
				
			||||||
 | 
					dnl * by Florian Bomers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AC_DEFUN(LA_SEARCH_FILE,[
 | 
				
			||||||
 | 
					  $1=
 | 
				
			||||||
 | 
					  dnl hack: eliminate line feeds in $2
 | 
				
			||||||
 | 
					  for FILE in $2; do
 | 
				
			||||||
 | 
					    for DIR in $3; do
 | 
				
			||||||
 | 
					      dnl use PATH in order
 | 
				
			||||||
 | 
					      if test ".$1"="." && test -f "$DIR/$FILE"; then
 | 
				
			||||||
 | 
					        $1=$DIR
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
 | 
					    done
 | 
				
			||||||
 | 
					  done
 | 
				
			||||||
 | 
					])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dnl * LA_SEARCH_LIB(lib-variable, include-variable, lib-filename, header-filename, prefix)
 | 
				
			||||||
 | 
					dnl * looks for "lib-filename" and "header-filename" in the area of "prefix".
 | 
				
			||||||
 | 
					dnl * if found, "lib-variable" and "include-variable" are set to the
 | 
				
			||||||
 | 
					dnl * respective paths.
 | 
				
			||||||
 | 
					dnl * prefix is a single path
 | 
				
			||||||
 | 
					dnl * libs are searched in prefix, prefix/lib
 | 
				
			||||||
 | 
					dnl * headers are searched in prefix, prefix/include,
 | 
				
			||||||
 | 
					dnl * 
 | 
				
			||||||
 | 
					dnl * If one of them is not found, both "lib-variable", "include-variable" are 
 | 
				
			||||||
 | 
					dnl * set to the empty string.
 | 
				
			||||||
 | 
					dnl *
 | 
				
			||||||
 | 
					dnl * TODO: assert function call to verify lib
 | 
				
			||||||
 | 
					dnl *
 | 
				
			||||||
 | 
					dnl * by Florian Bomers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AC_DEFUN(LA_SEARCH_LIB,[
 | 
				
			||||||
 | 
					  dnl look for lib
 | 
				
			||||||
 | 
					  LA_SEARCH_FILE($1, $3, $5 $5/lib )
 | 
				
			||||||
 | 
					  dnl look for header.
 | 
				
			||||||
 | 
					  LA_SEARCH_FILE($2, $4, $5 $5/include )
 | 
				
			||||||
 | 
					  if test ".$1" = "." || test ".$2" = "."; then
 | 
				
			||||||
 | 
					    $1=
 | 
				
			||||||
 | 
					    $2=
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,62 @@
 | 
				
			||||||
 | 
					dnl Process this file with autoconf to produce a configure script.
 | 
				
			||||||
 | 
					AC_INIT(src/DarkIce.cpp)
 | 
				
			||||||
 | 
					AM_INIT_AUTOMAKE(darkice, 0.5)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AM_CONFIG_HEADER(config.h)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AC_PROG_CXX
 | 
				
			||||||
 | 
					AC_PROG_INSTALL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dnl AC_STDC_HEADERS
 | 
				
			||||||
 | 
					AC_HAVE_HEADERS(errno.h fcntl.h stdio.h stdlib.h string.h unistd.h limits.h)
 | 
				
			||||||
 | 
					AC_HAVE_HEADERS(getopt.h signal.h time.h sys/time.h sys/types.h sys/soundcard.h)
 | 
				
			||||||
 | 
					AC_HAVE_HEADERS(netdb.h netinet/in.h sys/ioctl.h sys/socket.h sys/stat.h)
 | 
				
			||||||
 | 
					AC_HAVE_HEADERS(sched.h)
 | 
				
			||||||
 | 
					AC_HEADER_SYS_WAIT()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AC_TYPE_PID_T()
 | 
				
			||||||
 | 
					AC_TYPE_SIZE_T()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AC_SUBST(LAME_INCFLAGS)
 | 
				
			||||||
 | 
					AC_SUBST(LAME_LDFLAGS)
 | 
				
			||||||
 | 
					AC_SUBST(LINK_STATIC)
 | 
				
			||||||
 | 
					AC_SUBST(VERSION)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dnl checkin for lame library
 | 
				
			||||||
 | 
					AC_MSG_CHECKING(lame library)
 | 
				
			||||||
 | 
					AC_ARG_WITH(lame-prefix,
 | 
				
			||||||
 | 
					[  --with-lame-prefix=DIR  alternate location for lame [/usr]
 | 
				
			||||||
 | 
					                          files looked for: LAME-PREFIX/lib/libmp3lame.a
 | 
				
			||||||
 | 
					                                            LAME-PREFIX/include/lame/lame.h],
 | 
				
			||||||
 | 
					  CONFIG_LAME_PREFIX="${withval}", CONFIG_LAME_PREFIX="/usr")
 | 
				
			||||||
 | 
					  if test "x${CONFIG_LAME_PREFIX}" != "x" ; then
 | 
				
			||||||
 | 
					    # look for lame lib. This overrides any standard location
 | 
				
			||||||
 | 
					    LA_SEARCH_LIB(LAME_LIB_LOC, LAME_INC_LOC, libmp3lame.a, lame/lame.h, ${CONFIG_LAME_PREFIX})
 | 
				
			||||||
 | 
					    if test "x${LAME_LIB_LOC}" != "x" ; then
 | 
				
			||||||
 | 
					      AC_DEFINE(HAVE_LAME_LIB, 1, build with lame library calls)
 | 
				
			||||||
 | 
					      if test "x${LAME_INC_LOC}" != "x/usr/include" ; then
 | 
				
			||||||
 | 
					          LAME_INCFLAGS="-I${LAME_INC_LOC}"
 | 
				
			||||||
 | 
					          LAME_LDFLAGS="-Wl,--rpath -Wl,${LAME_LIB_LOC} -lmp3lame"
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					          LAME_LDFLAGS="-lmp3lame"
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
 | 
					      AC_MSG_RESULT( "lame found at ${LAME_LIB_LOC}")
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      AC_MSG_ERROR( "lame library not found")
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AC_ARG_ENABLE( static,
 | 
				
			||||||
 | 
					[  --enable-static         link everything into the executable statically [no]],
 | 
				
			||||||
 | 
					  CONFIG_LINK_STATIC="${enableval}", CONFIG_LINK_STATIC="")
 | 
				
			||||||
 | 
					  if test "${CONFIG_LINK_STATIC}" == "yes" ; then
 | 
				
			||||||
 | 
					    LINK_STATIC="--static"
 | 
				
			||||||
 | 
					    AC_MSG_RESULT( "creating statically linked executable")
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    LINK_STATIC=""
 | 
				
			||||||
 | 
					    AC_MSG_RESULT( "creating dinamically linked executable")
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AC_OUTPUT(Makefile src/Makefile man/Makefile)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,56 @@
 | 
				
			||||||
 | 
					# sample DarkIce configuration file, edit for your needs before using
 | 
				
			||||||
 | 
					# see the darkice.cfg man page for details
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# this section describes general aspects of the live streaming session
 | 
				
			||||||
 | 
					[general]
 | 
				
			||||||
 | 
					duration        = 60        # duration of encoding, in seconds. 0 means forever
 | 
				
			||||||
 | 
					bufferSecs      = 5         # size of internal slip buffer, in seconds
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# this section describes the audio input that will be streamed
 | 
				
			||||||
 | 
					[input]
 | 
				
			||||||
 | 
					device          = /dev/dsp  # OSS DSP soundcard device for the audio input
 | 
				
			||||||
 | 
					sampleRate      = 22050     # sample rate in Hz. try 11025, 22050 or 44100
 | 
				
			||||||
 | 
					bitsPerSample   = 16        # bits per sample. try 16
 | 
				
			||||||
 | 
					channel         = 2         # channels. 1 = mono, 2 = stereo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# this section describes a streaming connection to an IceCast server
 | 
				
			||||||
 | 
					# there may be up to 8 of these sections, named [icecast-0] ... [icecast-7]
 | 
				
			||||||
 | 
					# these can be mixed with [shoutcast-x] sections
 | 
				
			||||||
 | 
					[icecast-0]
 | 
				
			||||||
 | 
					bitrate         = 96        # bitrate of the mp3 stream sent to the server
 | 
				
			||||||
 | 
					server          = yp.yourserver.com
 | 
				
			||||||
 | 
					                            # host name of the server
 | 
				
			||||||
 | 
					port            = 8000      # port of the IceCast server, usually 8000
 | 
				
			||||||
 | 
					password        = hackme    # source password to the IceCast server
 | 
				
			||||||
 | 
					mountPoint      = sample96  # mount point of this stream on the IceCast server
 | 
				
			||||||
 | 
					name            = DarkIce trial
 | 
				
			||||||
 | 
					                            # name of the stream
 | 
				
			||||||
 | 
					description     = This is only a trial
 | 
				
			||||||
 | 
					                            # description of the stream
 | 
				
			||||||
 | 
					url             = http://www.yourserver.com
 | 
				
			||||||
 | 
					                            # URL related to the stream
 | 
				
			||||||
 | 
					genre           = my own    # genre of the stream
 | 
				
			||||||
 | 
					public          = yes       # advertise this stream?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# this section describes a streaming connection to a ShoutCast server
 | 
				
			||||||
 | 
					# there may be up to 8 of these sections, named [shoutcast-0] ... [shoutcast-7]
 | 
				
			||||||
 | 
					# these can be mixed with [icecast-x] sections
 | 
				
			||||||
 | 
					[shoutcast-0]
 | 
				
			||||||
 | 
					bitrate         = 96        # bitrate of the mp3 stream sent to the server
 | 
				
			||||||
 | 
					server          = yp.yourserver.com
 | 
				
			||||||
 | 
					                            # host name of the server
 | 
				
			||||||
 | 
					port            = 8001      # source port of the ShoutCast server, usually 8001
 | 
				
			||||||
 | 
					password        = hackme    # source password to the ShoutCast server
 | 
				
			||||||
 | 
					name            = DarkIce trial
 | 
				
			||||||
 | 
					                            # name of the stream
 | 
				
			||||||
 | 
					url             = http://www.yourserver.com
 | 
				
			||||||
 | 
					                            # URL related to the stream
 | 
				
			||||||
 | 
					genre           = my own    # genre of the stream
 | 
				
			||||||
 | 
					public          = yes       # advertise this stream?
 | 
				
			||||||
 | 
					irc             = irc.yourserver.com
 | 
				
			||||||
 | 
					                            # IRC info related to the stream
 | 
				
			||||||
 | 
					aim             = aim here  # AIM info related to the stream
 | 
				
			||||||
 | 
					icq             = I see you too
 | 
				
			||||||
 | 
					                            # ICQ info related to the stream
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,251 @@
 | 
				
			||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# install - install a program, script, or datafile
 | 
				
			||||||
 | 
					# This comes from X11R5 (mit/util/scripts/install.sh).
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Copyright 1991 by the Massachusetts Institute of Technology
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Permission to use, copy, modify, distribute, and sell this software and its
 | 
				
			||||||
 | 
					# documentation for any purpose is hereby granted without fee, provided that
 | 
				
			||||||
 | 
					# the above copyright notice appear in all copies and that both that
 | 
				
			||||||
 | 
					# copyright notice and this permission notice appear in supporting
 | 
				
			||||||
 | 
					# documentation, and that the name of M.I.T. not be used in advertising or
 | 
				
			||||||
 | 
					# publicity pertaining to distribution of the software without specific,
 | 
				
			||||||
 | 
					# written prior permission.  M.I.T. makes no representations about the
 | 
				
			||||||
 | 
					# suitability of this software for any purpose.  It is provided "as is"
 | 
				
			||||||
 | 
					# without express or implied warranty.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Calling this script install-sh is preferred over install.sh, to prevent
 | 
				
			||||||
 | 
					# `make' implicit rules from creating a file called install from it
 | 
				
			||||||
 | 
					# when there is no Makefile.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# This script is compatible with the BSD install script, but was written
 | 
				
			||||||
 | 
					# from scratch.  It can only install one file at a time, a restriction
 | 
				
			||||||
 | 
					# shared with many OS's install programs.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# set DOITPROG to echo to test this script
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Don't use :- since 4.3BSD and earlier shells don't like it.
 | 
				
			||||||
 | 
					doit="${DOITPROG-}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# put in absolute paths if you don't have them in your path; or use env. vars.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					mvprog="${MVPROG-mv}"
 | 
				
			||||||
 | 
					cpprog="${CPPROG-cp}"
 | 
				
			||||||
 | 
					chmodprog="${CHMODPROG-chmod}"
 | 
				
			||||||
 | 
					chownprog="${CHOWNPROG-chown}"
 | 
				
			||||||
 | 
					chgrpprog="${CHGRPPROG-chgrp}"
 | 
				
			||||||
 | 
					stripprog="${STRIPPROG-strip}"
 | 
				
			||||||
 | 
					rmprog="${RMPROG-rm}"
 | 
				
			||||||
 | 
					mkdirprog="${MKDIRPROG-mkdir}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					transformbasename=""
 | 
				
			||||||
 | 
					transform_arg=""
 | 
				
			||||||
 | 
					instcmd="$mvprog"
 | 
				
			||||||
 | 
					chmodcmd="$chmodprog 0755"
 | 
				
			||||||
 | 
					chowncmd=""
 | 
				
			||||||
 | 
					chgrpcmd=""
 | 
				
			||||||
 | 
					stripcmd=""
 | 
				
			||||||
 | 
					rmcmd="$rmprog -f"
 | 
				
			||||||
 | 
					mvcmd="$mvprog"
 | 
				
			||||||
 | 
					src=""
 | 
				
			||||||
 | 
					dst=""
 | 
				
			||||||
 | 
					dir_arg=""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					while [ x"$1" != x ]; do
 | 
				
			||||||
 | 
					    case $1 in
 | 
				
			||||||
 | 
						-c) instcmd="$cpprog"
 | 
				
			||||||
 | 
						    shift
 | 
				
			||||||
 | 
						    continue;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-d) dir_arg=true
 | 
				
			||||||
 | 
						    shift
 | 
				
			||||||
 | 
						    continue;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-m) chmodcmd="$chmodprog $2"
 | 
				
			||||||
 | 
						    shift
 | 
				
			||||||
 | 
						    shift
 | 
				
			||||||
 | 
						    continue;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-o) chowncmd="$chownprog $2"
 | 
				
			||||||
 | 
						    shift
 | 
				
			||||||
 | 
						    shift
 | 
				
			||||||
 | 
						    continue;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-g) chgrpcmd="$chgrpprog $2"
 | 
				
			||||||
 | 
						    shift
 | 
				
			||||||
 | 
						    shift
 | 
				
			||||||
 | 
						    continue;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-s) stripcmd="$stripprog"
 | 
				
			||||||
 | 
						    shift
 | 
				
			||||||
 | 
						    continue;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-t=*) transformarg=`echo $1 | sed 's/-t=//'`
 | 
				
			||||||
 | 
						    shift
 | 
				
			||||||
 | 
						    continue;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
 | 
				
			||||||
 | 
						    shift
 | 
				
			||||||
 | 
						    continue;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						*)  if [ x"$src" = x ]
 | 
				
			||||||
 | 
						    then
 | 
				
			||||||
 | 
							src=$1
 | 
				
			||||||
 | 
						    else
 | 
				
			||||||
 | 
							# this colon is to work around a 386BSD /bin/sh bug
 | 
				
			||||||
 | 
							:
 | 
				
			||||||
 | 
							dst=$1
 | 
				
			||||||
 | 
						    fi
 | 
				
			||||||
 | 
						    shift
 | 
				
			||||||
 | 
						    continue;;
 | 
				
			||||||
 | 
					    esac
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ x"$src" = x ]
 | 
				
			||||||
 | 
					then
 | 
				
			||||||
 | 
						echo "install:	no input file specified"
 | 
				
			||||||
 | 
						exit 1
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
						true
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ x"$dir_arg" != x ]; then
 | 
				
			||||||
 | 
						dst=$src
 | 
				
			||||||
 | 
						src=""
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if [ -d $dst ]; then
 | 
				
			||||||
 | 
							instcmd=:
 | 
				
			||||||
 | 
							chmodcmd=""
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							instcmd=mkdir
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
 | 
				
			||||||
 | 
					# might cause directories to be created, which would be especially bad 
 | 
				
			||||||
 | 
					# if $src (and thus $dsttmp) contains '*'.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if [ -f $src -o -d $src ]
 | 
				
			||||||
 | 
						then
 | 
				
			||||||
 | 
							true
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							echo "install:  $src does not exist"
 | 
				
			||||||
 | 
							exit 1
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if [ x"$dst" = x ]
 | 
				
			||||||
 | 
						then
 | 
				
			||||||
 | 
							echo "install:	no destination specified"
 | 
				
			||||||
 | 
							exit 1
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							true
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# If destination is a directory, append the input filename; if your system
 | 
				
			||||||
 | 
					# does not like double slashes in filenames, you may need to add some logic
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if [ -d $dst ]
 | 
				
			||||||
 | 
						then
 | 
				
			||||||
 | 
							dst="$dst"/`basename $src`
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							true
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## this sed command emulates the dirname command
 | 
				
			||||||
 | 
					dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Make sure that the destination directory exists.
 | 
				
			||||||
 | 
					#  this part is taken from Noah Friedman's mkinstalldirs script
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Skip lots of stat calls in the usual case.
 | 
				
			||||||
 | 
					if [ ! -d "$dstdir" ]; then
 | 
				
			||||||
 | 
					defaultIFS='	
 | 
				
			||||||
 | 
					'
 | 
				
			||||||
 | 
					IFS="${IFS-${defaultIFS}}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					oIFS="${IFS}"
 | 
				
			||||||
 | 
					# Some sh's can't handle IFS=/ for some reason.
 | 
				
			||||||
 | 
					IFS='%'
 | 
				
			||||||
 | 
					set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
 | 
				
			||||||
 | 
					IFS="${oIFS}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pathcomp=''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					while [ $# -ne 0 ] ; do
 | 
				
			||||||
 | 
						pathcomp="${pathcomp}${1}"
 | 
				
			||||||
 | 
						shift
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if [ ! -d "${pathcomp}" ] ;
 | 
				
			||||||
 | 
					        then
 | 
				
			||||||
 | 
							$mkdirprog "${pathcomp}"
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							true
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pathcomp="${pathcomp}/"
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ x"$dir_arg" != x ]
 | 
				
			||||||
 | 
					then
 | 
				
			||||||
 | 
						$doit $instcmd $dst &&
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
 | 
				
			||||||
 | 
						if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
 | 
				
			||||||
 | 
						if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
 | 
				
			||||||
 | 
						if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# If we're going to rename the final executable, determine the name now.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if [ x"$transformarg" = x ] 
 | 
				
			||||||
 | 
						then
 | 
				
			||||||
 | 
							dstfile=`basename $dst`
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							dstfile=`basename $dst $transformbasename | 
 | 
				
			||||||
 | 
								sed $transformarg`$transformbasename
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# don't allow the sed command to completely eliminate the filename
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if [ x"$dstfile" = x ] 
 | 
				
			||||||
 | 
						then
 | 
				
			||||||
 | 
							dstfile=`basename $dst`
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							true
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Make a temp file name in the proper directory.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						dsttmp=$dstdir/#inst.$$#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Move or copy the file name to the temp name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						$doit $instcmd $src $dsttmp &&
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						trap "rm -f ${dsttmp}" 0 &&
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# and set any options; do chmod last to preserve setuid bits
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# If any of these fail, we abort the whole thing.  If we want to
 | 
				
			||||||
 | 
					# ignore errors from any of these, just make sure not to ignore
 | 
				
			||||||
 | 
					# errors from the above "$doit $instcmd $src $dsttmp" command.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
 | 
				
			||||||
 | 
						if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
 | 
				
			||||||
 | 
						if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
 | 
				
			||||||
 | 
						if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Now rename the file to the real destination.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						$doit $rmcmd -f $dstdir/$dstfile &&
 | 
				
			||||||
 | 
						$doit $mvcmd $dsttmp $dstdir/$dstfile 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fi &&
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit 0
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					man_MANS = darkice.1 darkice.cfg.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					EXTRA_DIST = ${man_MANS}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,97 @@
 | 
				
			||||||
 | 
					.TH darkice 1 "September 09, 2001" "DarkIce" "DarkIce live audio streamer"
 | 
				
			||||||
 | 
					.SH NAME
 | 
				
			||||||
 | 
					darkice \- an icecast / shoutcast live audio streamer
 | 
				
			||||||
 | 
					.SH SYNOPSIS
 | 
				
			||||||
 | 
					.B darkice
 | 
				
			||||||
 | 
					[options] -c config.file
 | 
				
			||||||
 | 
					.SH DESCRIPTION
 | 
				
			||||||
 | 
					.PP
 | 
				
			||||||
 | 
					.B DarkIce
 | 
				
			||||||
 | 
					is an
 | 
				
			||||||
 | 
					.B IceCast
 | 
				
			||||||
 | 
					and
 | 
				
			||||||
 | 
					.B ShoutCast
 | 
				
			||||||
 | 
					live audio streamer. It takes audio input from a
 | 
				
			||||||
 | 
					sound card, encodes it into mp3, and sends the stream to one or more
 | 
				
			||||||
 | 
					.B IceCast
 | 
				
			||||||
 | 
					and / or
 | 
				
			||||||
 | 
					.B ShoutCast
 | 
				
			||||||
 | 
					servers.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.B DarkIce
 | 
				
			||||||
 | 
					uses
 | 
				
			||||||
 | 
					.SM POSIX
 | 
				
			||||||
 | 
					real-time scheduling to keep up with sound card input.
 | 
				
			||||||
 | 
					.SM POSIX
 | 
				
			||||||
 | 
					real-time scheduling is only available if the program is run as root.
 | 
				
			||||||
 | 
					Therefore it is recommended that
 | 
				
			||||||
 | 
					.B DarkIce
 | 
				
			||||||
 | 
					is run as root.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.B DarkIce
 | 
				
			||||||
 | 
					uses the
 | 
				
			||||||
 | 
					.B Lame
 | 
				
			||||||
 | 
					mp3 encoder as a library to encode audio intput to mp3.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.SH OPTIONS
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.BI "\-c " config.file
 | 
				
			||||||
 | 
					.br
 | 
				
			||||||
 | 
					.ns
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.BI \-\-config= config.file
 | 
				
			||||||
 | 
					Specifies what configuration file to use.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.BI "\-v " n
 | 
				
			||||||
 | 
					.br
 | 
				
			||||||
 | 
					.ns
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.BI \-\-verbosity= n
 | 
				
			||||||
 | 
					Sets the verbosity level, between 0 and 10. 0 is silent, 10 is loud.
 | 
				
			||||||
 | 
					Defaults to 1.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.BI "\-h "
 | 
				
			||||||
 | 
					.br
 | 
				
			||||||
 | 
					.ns
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.BI \-\-help
 | 
				
			||||||
 | 
					Prints the help page and exists.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.SH BUGS
 | 
				
			||||||
 | 
					.PP
 | 
				
			||||||
 | 
					Lots of bugs.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.SH "SEE ALSO"
 | 
				
			||||||
 | 
					darkice.cfg(5)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.SH AUTHOR
 | 
				
			||||||
 | 
					Akos Maroy
 | 
				
			||||||
 | 
					.I <darkeye@users.sourceforge.net>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.SH ACKNOWLEDGEMENTS
 | 
				
			||||||
 | 
					Some contributions by Jim Crilly
 | 
				
			||||||
 | 
					.I <JCrilly@MSA.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.SH LINKS
 | 
				
			||||||
 | 
					Project homepage:
 | 
				
			||||||
 | 
					.I http://darkice.sourceforge.net/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.B IceCast
 | 
				
			||||||
 | 
					homepage:
 | 
				
			||||||
 | 
					.I http://www.icecast.org/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.B ShoutCast
 | 
				
			||||||
 | 
					homepage:
 | 
				
			||||||
 | 
					.I http://www.shoutcast.com/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.B Lame
 | 
				
			||||||
 | 
					homepage:
 | 
				
			||||||
 | 
					.I http://www.mp3dev.org/mp3/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,343 @@
 | 
				
			||||||
 | 
					.TH darkice.cfg 5 "September 9, 2001" "DarkIce" "DarkIce live audio streamer"
 | 
				
			||||||
 | 
					.SH NAME
 | 
				
			||||||
 | 
					darkice.cfg \- configuration file for darkice
 | 
				
			||||||
 | 
					.SH DESCRIPTION
 | 
				
			||||||
 | 
					.PP
 | 
				
			||||||
 | 
					The configuration file consists of sections, with key = value pairs
 | 
				
			||||||
 | 
					inside each secion:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.nf
 | 
				
			||||||
 | 
					[section1]
 | 
				
			||||||
 | 
					# this is a whole line comment
 | 
				
			||||||
 | 
					key = value
 | 
				
			||||||
 | 
					an ugly key name = long value    # this end is a comment too
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[section2]
 | 
				
			||||||
 | 
					# this is a whole line comment in section 2
 | 
				
			||||||
 | 
					key = value
 | 
				
			||||||
 | 
					an ugly key name = long value    # this end is a comment too
 | 
				
			||||||
 | 
					.fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					A proper
 | 
				
			||||||
 | 
					.B DarkIce
 | 
				
			||||||
 | 
					configuration file contains the following sections:
 | 
				
			||||||
 | 
					.nf
 | 
				
			||||||
 | 
					[general]
 | 
				
			||||||
 | 
					[input]
 | 
				
			||||||
 | 
					[icecast-0] ... [icecast-7]
 | 
				
			||||||
 | 
					[shoutcast-0] ... [shoutcast-7]
 | 
				
			||||||
 | 
					.fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The order of the sections is not important. Sections [general] and [input]
 | 
				
			||||||
 | 
					are required, and at least one of [icecast-x] or [shoutcast-x] is needed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					In particular, the following sections and values are recognized:
 | 
				
			||||||
 | 
					.PP
 | 
				
			||||||
 | 
					.B [general]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This section describes general operational parameters (required).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Required values:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I duration
 | 
				
			||||||
 | 
					Time for DarkIce to run, in seconds.  If 0, run forever.
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I bufferSecs
 | 
				
			||||||
 | 
					Data read from the sound card is buffered before sent to
 | 
				
			||||||
 | 
					the mp3 encoder. Each buffer will be able to hold this
 | 
				
			||||||
 | 
					many seconds of samples.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PP
 | 
				
			||||||
 | 
					.B [input]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This section describes the input (required).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Required values:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I device
 | 
				
			||||||
 | 
					OSS DSP audio device to record from (e.g. /dev/dsp)
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I sampleRate
 | 
				
			||||||
 | 
					The sample rate to record with, samples per second
 | 
				
			||||||
 | 
					(e.g. 44100 for 44.1kHz CD-quality audio, 22050 for 22kHz or 11025
 | 
				
			||||||
 | 
					for 11kHz)
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I bitsPerSample
 | 
				
			||||||
 | 
					Number of bits to use for each sample (e.g. 8 bits or 16 bits)
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I channel
 | 
				
			||||||
 | 
					Number of channels to record (e.g. 1 for mono, 2 for stereo)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PP
 | 
				
			||||||
 | 
					.B [icecast-x]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This section describes an output to an
 | 
				
			||||||
 | 
					.B IceCast
 | 
				
			||||||
 | 
					server, while encoding
 | 
				
			||||||
 | 
					with a lame encoder. There may be at most 8 outputs, numbered from 0 ... 7.
 | 
				
			||||||
 | 
					The number is included in the section name (e.g. [icecast-0] ... [icecast-7]).
 | 
				
			||||||
 | 
					The stream will be reachable at
 | 
				
			||||||
 | 
					.I http://<server>:<port>/<mountPoint>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Required values:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I bitrate
 | 
				
			||||||
 | 
					Bit rate to encode to in kBits / sec (e.g. 96)
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I server
 | 
				
			||||||
 | 
					The
 | 
				
			||||||
 | 
					.B IceCast
 | 
				
			||||||
 | 
					server's name (e.g. yp.yourserver.com)
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I port
 | 
				
			||||||
 | 
					The port to connect to the IceCast server (e.g. 8000)
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I password
 | 
				
			||||||
 | 
					The password to use to connect to the
 | 
				
			||||||
 | 
					.B IceCast
 | 
				
			||||||
 | 
					server
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I mountPoint
 | 
				
			||||||
 | 
					Mount point for the stream on the server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PP
 | 
				
			||||||
 | 
					Optional values:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I name
 | 
				
			||||||
 | 
					Name of the stream
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I description
 | 
				
			||||||
 | 
					Description of the stream
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I url
 | 
				
			||||||
 | 
					Url related to the stream
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I genre
 | 
				
			||||||
 | 
					Genre of the stream
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I public
 | 
				
			||||||
 | 
					"yes" or "no", wether the stream is public
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I remoteDumpFile 
 | 
				
			||||||
 | 
					The file the
 | 
				
			||||||
 | 
					.B IceCast
 | 
				
			||||||
 | 
					server should dump the contents of
 | 
				
			||||||
 | 
					this stream on its side.
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I lowpass
 | 
				
			||||||
 | 
					Lowpass filter setting for the lame encoder. If not set,
 | 
				
			||||||
 | 
					the encoder's default behaviour is used
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I highpass
 | 
				
			||||||
 | 
					Highpass filter setting for the lame encoder. If not set,
 | 
				
			||||||
 | 
					the encoder's default behaviour is used
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PP
 | 
				
			||||||
 | 
					.B [shoutcast-x]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This section describes an output to a
 | 
				
			||||||
 | 
					.B ShoutCast
 | 
				
			||||||
 | 
					server, while encoding
 | 
				
			||||||
 | 
					with a lame encoder. There may be at most 8 outputs, numbered from 0 ... 7.
 | 
				
			||||||
 | 
					The number is included in the section name
 | 
				
			||||||
 | 
					(e.g. [shoutcast-0] ... [shoutcast-7]).
 | 
				
			||||||
 | 
					The stream will be reachable at
 | 
				
			||||||
 | 
					.I http://<server>:<port-1>/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Required values:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I bitrate
 | 
				
			||||||
 | 
					Bit rate to encode to in kBits / sec (e.g. 96)
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I server
 | 
				
			||||||
 | 
					The
 | 
				
			||||||
 | 
					.B ShoutCast
 | 
				
			||||||
 | 
					server's name (e.g. yp.yourserver.com)
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I port
 | 
				
			||||||
 | 
					The source port to connect to the ShoutCast server (e.g. 8001)
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I password
 | 
				
			||||||
 | 
					The password to use to connect to the
 | 
				
			||||||
 | 
					.B ShoutCast
 | 
				
			||||||
 | 
					server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PP
 | 
				
			||||||
 | 
					Optional values:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I name
 | 
				
			||||||
 | 
					Name of the stream
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I url
 | 
				
			||||||
 | 
					Url related to the stream
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I genre
 | 
				
			||||||
 | 
					Genre of the stream
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I public
 | 
				
			||||||
 | 
					"yes" or "no", wether the stream is public
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I irc
 | 
				
			||||||
 | 
					IRC information related to the stream
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I aim
 | 
				
			||||||
 | 
					AIM information related to the stream
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I icq
 | 
				
			||||||
 | 
					ICQ information related to the stream
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I lowpass
 | 
				
			||||||
 | 
					Lowpass filter setting for the lame encoder. If not set,
 | 
				
			||||||
 | 
					the encoder's default behaviour is used
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.I highpass
 | 
				
			||||||
 | 
					Highpass filter setting for the lame encoder. If not set,
 | 
				
			||||||
 | 
					the encoder's default behaviour is used
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PP
 | 
				
			||||||
 | 
					A sample configuration file follows. This file makes
 | 
				
			||||||
 | 
					.B DarkIce
 | 
				
			||||||
 | 
					stream for 1 minute (60 seconds) from the audio device
 | 
				
			||||||
 | 
					.I /dev/dsp
 | 
				
			||||||
 | 
					at 22kHz, 16 bit stereo.
 | 
				
			||||||
 | 
					It will build up a connection to the
 | 
				
			||||||
 | 
					.B IceCast
 | 
				
			||||||
 | 
					server yp.yourserver.com on port 8000 with the password "hackme".
 | 
				
			||||||
 | 
					The stream will be encoded to 96 kb/s mp3, and will be reachable at
 | 
				
			||||||
 | 
					.I http://yp.yourserver.com:8000/live96
 | 
				
			||||||
 | 
					to mp3 players.
 | 
				
			||||||
 | 
					The encoding session will be stored by
 | 
				
			||||||
 | 
					.B IceCast
 | 
				
			||||||
 | 
					in the file
 | 
				
			||||||
 | 
					.I /tmp/live96.mp3
 | 
				
			||||||
 | 
					on the server side.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.nf
 | 
				
			||||||
 | 
					[general]
 | 
				
			||||||
 | 
					duration        = 60
 | 
				
			||||||
 | 
					bufferSecs      = 5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[input]
 | 
				
			||||||
 | 
					device          = /dev/dsp
 | 
				
			||||||
 | 
					sampleRate      = 22050
 | 
				
			||||||
 | 
					bitsPerSample   = 16
 | 
				
			||||||
 | 
					channel         = 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[icecast-0]
 | 
				
			||||||
 | 
					bitrate         = 96
 | 
				
			||||||
 | 
					server          = yp.yourserver.com
 | 
				
			||||||
 | 
					port            = 8000
 | 
				
			||||||
 | 
					password        = hackme
 | 
				
			||||||
 | 
					mountPoint      = live96
 | 
				
			||||||
 | 
					name            = DarkIce trial
 | 
				
			||||||
 | 
					description     = This is only a trial
 | 
				
			||||||
 | 
					url             = http://www.yourserver.com
 | 
				
			||||||
 | 
					genre           = live
 | 
				
			||||||
 | 
					public          = no
 | 
				
			||||||
 | 
					remoteDumpFile  = /tmp/live96.mp3
 | 
				
			||||||
 | 
					.fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PP
 | 
				
			||||||
 | 
					A bit more complicated sample follows. This one makes
 | 
				
			||||||
 | 
					.B DarkIce
 | 
				
			||||||
 | 
					stream for 1 hour (3600 seconds) from the audio device
 | 
				
			||||||
 | 
					.I /dev/dsp
 | 
				
			||||||
 | 
					at 22kHz, 16 bit stereo.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					It will build up a connection to an
 | 
				
			||||||
 | 
					.B IceCast
 | 
				
			||||||
 | 
					server yp.your-ice-server.com on port 8000 with the password "ice-hackme".
 | 
				
			||||||
 | 
					The sound for this stream will be cut at 10500 Hz from above.
 | 
				
			||||||
 | 
					The stream will be encoded to 96 kb/s mp3, and will be reachable at
 | 
				
			||||||
 | 
					.I http://yp.your-ice-server.com:8000/live96
 | 
				
			||||||
 | 
					to mp3 players.
 | 
				
			||||||
 | 
					The encoding session will be stored by
 | 
				
			||||||
 | 
					.B IceCast
 | 
				
			||||||
 | 
					in the file
 | 
				
			||||||
 | 
					.I /tmp/live96.mp3
 | 
				
			||||||
 | 
					on the server side.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					It will also connect to a
 | 
				
			||||||
 | 
					.I ShoutCast
 | 
				
			||||||
 | 
					server at yp.your-shout-server.com on port 8001 with the password "shout-hackme"
 | 
				
			||||||
 | 
					This stream will be encoded to 128 kb/s mp3, and will be reachable at
 | 
				
			||||||
 | 
					.I http://yp.your-shout-server.com:8000
 | 
				
			||||||
 | 
					to mp3 players.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.nf
 | 
				
			||||||
 | 
					[general]
 | 
				
			||||||
 | 
					duration        = 3600
 | 
				
			||||||
 | 
					bufferSecs      = 5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[input]
 | 
				
			||||||
 | 
					device          = /dev/dsp
 | 
				
			||||||
 | 
					sampleRate      = 22050
 | 
				
			||||||
 | 
					bitsPerSample   = 16
 | 
				
			||||||
 | 
					channel         = 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[icecast-0]
 | 
				
			||||||
 | 
					bitrate         = 96
 | 
				
			||||||
 | 
					lowpass         = 10500
 | 
				
			||||||
 | 
					server          = yp.your-ice-server.com
 | 
				
			||||||
 | 
					port            = 8000
 | 
				
			||||||
 | 
					password        = ice-hackme
 | 
				
			||||||
 | 
					mountPoint      = live96
 | 
				
			||||||
 | 
					name            = DarkIce trial
 | 
				
			||||||
 | 
					description     = This is only a trial
 | 
				
			||||||
 | 
					url             = http://www.yourserver.com
 | 
				
			||||||
 | 
					genre           = live
 | 
				
			||||||
 | 
					public          = yes
 | 
				
			||||||
 | 
					remoteDumpFile  = /tmp/live96.mp3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[shoutcast-0]
 | 
				
			||||||
 | 
					bitrate         = 128
 | 
				
			||||||
 | 
					server          = yp.your-shout-server.com
 | 
				
			||||||
 | 
					port            = 8001
 | 
				
			||||||
 | 
					password        = shout-hackme
 | 
				
			||||||
 | 
					name            = DarkIce trial
 | 
				
			||||||
 | 
					url             = http://www.yourserver.com
 | 
				
			||||||
 | 
					genre           = live
 | 
				
			||||||
 | 
					public          = yes
 | 
				
			||||||
 | 
					irc             = irc.yourserver.com
 | 
				
			||||||
 | 
					aim             = aim here
 | 
				
			||||||
 | 
					icq             = I see you too
 | 
				
			||||||
 | 
					.fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.SH BUGS
 | 
				
			||||||
 | 
					.PP
 | 
				
			||||||
 | 
					Lots of bugs.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.SH "SEE ALSO"
 | 
				
			||||||
 | 
					darkice(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.SH AUTHOR
 | 
				
			||||||
 | 
					Akos Maroy
 | 
				
			||||||
 | 
					.I <darkeye@users.sourceforge.net>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.SH LINKS
 | 
				
			||||||
 | 
					Project homepage:
 | 
				
			||||||
 | 
					.I http://darkice.sourceforge.net/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.B IceCast
 | 
				
			||||||
 | 
					homepage:
 | 
				
			||||||
 | 
					.I http://www.icecast.org/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.B ShoutCast
 | 
				
			||||||
 | 
					homepage:
 | 
				
			||||||
 | 
					.I http://www.shoutcast.com/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.B Lame
 | 
				
			||||||
 | 
					homepage:
 | 
				
			||||||
 | 
					.I http://www.mp3dev.org/mp3/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,190 @@
 | 
				
			||||||
 | 
					#! /bin/sh
 | 
				
			||||||
 | 
					# Common stub for a few missing GNU programs while installing.
 | 
				
			||||||
 | 
					# Copyright (C) 1996, 1997 Free Software Foundation, Inc.
 | 
				
			||||||
 | 
					# Franc,ois Pinard <pinard@iro.umontreal.ca>, 1996.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					# it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					# the Free Software Foundation; either version 2, 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, write to the Free Software
 | 
				
			||||||
 | 
					# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 | 
				
			||||||
 | 
					# 02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if test $# -eq 0; then
 | 
				
			||||||
 | 
					  echo 1>&2 "Try \`$0 --help' for more information"
 | 
				
			||||||
 | 
					  exit 1
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					case "$1" in
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  -h|--h|--he|--hel|--help)
 | 
				
			||||||
 | 
					    echo "\
 | 
				
			||||||
 | 
					$0 [OPTION]... PROGRAM [ARGUMENT]...
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
 | 
				
			||||||
 | 
					error status if there is no known handling for PROGRAM.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Options:
 | 
				
			||||||
 | 
					  -h, --help      display this help and exit
 | 
				
			||||||
 | 
					  -v, --version   output version information and exit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Supported PROGRAM values:
 | 
				
			||||||
 | 
					  aclocal      touch file \`aclocal.m4'
 | 
				
			||||||
 | 
					  autoconf     touch file \`configure'
 | 
				
			||||||
 | 
					  autoheader   touch file \`config.h.in'
 | 
				
			||||||
 | 
					  automake     touch all \`Makefile.in' files
 | 
				
			||||||
 | 
					  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
 | 
				
			||||||
 | 
					  flex         create \`lex.yy.c', if possible, from existing .c
 | 
				
			||||||
 | 
					  lex          create \`lex.yy.c', if possible, from existing .c
 | 
				
			||||||
 | 
					  makeinfo     touch the output file
 | 
				
			||||||
 | 
					  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]"
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
 | 
				
			||||||
 | 
					    echo "missing - GNU libit 0.0"
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  -*)
 | 
				
			||||||
 | 
					    echo 1>&2 "$0: Unknown \`$1' option"
 | 
				
			||||||
 | 
					    echo 1>&2 "Try \`$0 --help' for more information"
 | 
				
			||||||
 | 
					    exit 1
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  aclocal)
 | 
				
			||||||
 | 
					    echo 1>&2 "\
 | 
				
			||||||
 | 
					WARNING: \`$1' is missing on your system.  You should only need it if
 | 
				
			||||||
 | 
					         you modified \`acinclude.m4' or \`configure.in'.  You might want
 | 
				
			||||||
 | 
					         to install the \`Automake' and \`Perl' packages.  Grab them from
 | 
				
			||||||
 | 
					         any GNU archive site."
 | 
				
			||||||
 | 
					    touch aclocal.m4
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  autoconf)
 | 
				
			||||||
 | 
					    echo 1>&2 "\
 | 
				
			||||||
 | 
					WARNING: \`$1' is missing on your system.  You should only need it if
 | 
				
			||||||
 | 
					         you modified \`configure.in'.  You might want to install the
 | 
				
			||||||
 | 
					         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
 | 
				
			||||||
 | 
					         archive site."
 | 
				
			||||||
 | 
					    touch configure
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  autoheader)
 | 
				
			||||||
 | 
					    echo 1>&2 "\
 | 
				
			||||||
 | 
					WARNING: \`$1' is missing on your system.  You should only need it if
 | 
				
			||||||
 | 
					         you modified \`acconfig.h' or \`configure.in'.  You might want
 | 
				
			||||||
 | 
					         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
 | 
				
			||||||
 | 
					         from any GNU archive site."
 | 
				
			||||||
 | 
					    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' configure.in`
 | 
				
			||||||
 | 
					    test -z "$files" && files="config.h"
 | 
				
			||||||
 | 
					    touch_files=
 | 
				
			||||||
 | 
					    for f in $files; do
 | 
				
			||||||
 | 
					      case "$f" in
 | 
				
			||||||
 | 
					      *:*) touch_files="$touch_files "`echo "$f" |
 | 
				
			||||||
 | 
									       sed -e 's/^[^:]*://' -e 's/:.*//'`;;
 | 
				
			||||||
 | 
					      *) touch_files="$touch_files $f.in";;
 | 
				
			||||||
 | 
					      esac
 | 
				
			||||||
 | 
					    done
 | 
				
			||||||
 | 
					    touch $touch_files
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  automake)
 | 
				
			||||||
 | 
					    echo 1>&2 "\
 | 
				
			||||||
 | 
					WARNING: \`$1' is missing on your system.  You should only need it if
 | 
				
			||||||
 | 
					         you modified \`Makefile.am', \`acinclude.m4' or \`configure.in'.
 | 
				
			||||||
 | 
					         You might want to install the \`Automake' and \`Perl' packages.
 | 
				
			||||||
 | 
					         Grab them from any GNU archive site."
 | 
				
			||||||
 | 
					    find . -type f -name Makefile.am -print |
 | 
				
			||||||
 | 
						   sed 's/\.am$/.in/' |
 | 
				
			||||||
 | 
						   while read f; do touch "$f"; done
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  bison|yacc)
 | 
				
			||||||
 | 
					    echo 1>&2 "\
 | 
				
			||||||
 | 
					WARNING: \`$1' is missing on your system.  You should only need it if
 | 
				
			||||||
 | 
					         you modified a \`.y' file.  You may need the \`Bison' package
 | 
				
			||||||
 | 
					         in order for those modifications to take effect.  You can get
 | 
				
			||||||
 | 
					         \`Bison' from any GNU archive site."
 | 
				
			||||||
 | 
					    rm -f y.tab.c y.tab.h
 | 
				
			||||||
 | 
					    if [ $# -ne 1 ]; then
 | 
				
			||||||
 | 
					        eval LASTARG="\${$#}"
 | 
				
			||||||
 | 
						case "$LASTARG" in
 | 
				
			||||||
 | 
						*.y)
 | 
				
			||||||
 | 
						    SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
 | 
				
			||||||
 | 
						    if [ -f "$SRCFILE" ]; then
 | 
				
			||||||
 | 
						         cp "$SRCFILE" y.tab.c
 | 
				
			||||||
 | 
						    fi
 | 
				
			||||||
 | 
						    SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
 | 
				
			||||||
 | 
						    if [ -f "$SRCFILE" ]; then
 | 
				
			||||||
 | 
						         cp "$SRCFILE" y.tab.h
 | 
				
			||||||
 | 
						    fi
 | 
				
			||||||
 | 
						  ;;
 | 
				
			||||||
 | 
						esac
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					    if [ ! -f y.tab.h ]; then
 | 
				
			||||||
 | 
						echo >y.tab.h
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					    if [ ! -f y.tab.c ]; then
 | 
				
			||||||
 | 
						echo 'main() { return 0; }' >y.tab.c
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  lex|flex)
 | 
				
			||||||
 | 
					    echo 1>&2 "\
 | 
				
			||||||
 | 
					WARNING: \`$1' is missing on your system.  You should only need it if
 | 
				
			||||||
 | 
					         you modified a \`.l' file.  You may need the \`Flex' package
 | 
				
			||||||
 | 
					         in order for those modifications to take effect.  You can get
 | 
				
			||||||
 | 
					         \`Flex' from any GNU archive site."
 | 
				
			||||||
 | 
					    rm -f lex.yy.c
 | 
				
			||||||
 | 
					    if [ $# -ne 1 ]; then
 | 
				
			||||||
 | 
					        eval LASTARG="\${$#}"
 | 
				
			||||||
 | 
						case "$LASTARG" in
 | 
				
			||||||
 | 
						*.l)
 | 
				
			||||||
 | 
						    SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
 | 
				
			||||||
 | 
						    if [ -f "$SRCFILE" ]; then
 | 
				
			||||||
 | 
						         cp "$SRCFILE" lex.yy.c
 | 
				
			||||||
 | 
						    fi
 | 
				
			||||||
 | 
						  ;;
 | 
				
			||||||
 | 
						esac
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					    if [ ! -f lex.yy.c ]; then
 | 
				
			||||||
 | 
						echo 'main() { return 0; }' >lex.yy.c
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  makeinfo)
 | 
				
			||||||
 | 
					    echo 1>&2 "\
 | 
				
			||||||
 | 
					WARNING: \`$1' is missing on your system.  You should only need it if
 | 
				
			||||||
 | 
					         you modified a \`.texi' or \`.texinfo' file, or any other file
 | 
				
			||||||
 | 
					         indirectly affecting the aspect of the manual.  The spurious
 | 
				
			||||||
 | 
					         call might also be the consequence of using a buggy \`make' (AIX,
 | 
				
			||||||
 | 
					         DU, IRIX).  You might want to install the \`Texinfo' package or
 | 
				
			||||||
 | 
					         the \`GNU make' package.  Grab either from any GNU archive site."
 | 
				
			||||||
 | 
					    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
 | 
				
			||||||
 | 
					    if test -z "$file"; then
 | 
				
			||||||
 | 
					      file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
 | 
				
			||||||
 | 
					      file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					    touch $file
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  *)
 | 
				
			||||||
 | 
					    echo 1>&2 "\
 | 
				
			||||||
 | 
					WARNING: \`$1' is needed, and you do not seem to have it handy on your
 | 
				
			||||||
 | 
					         system.  You might have modified some files without having the
 | 
				
			||||||
 | 
					         proper tools for further handling them.  Check the \`README' file,
 | 
				
			||||||
 | 
					         it often tells you about the needed prerequirements for installing
 | 
				
			||||||
 | 
					         this package.  You may also peek at any GNU archive site, in case
 | 
				
			||||||
 | 
					         some other package would contain this missing \`$1' program."
 | 
				
			||||||
 | 
					    exit 1
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					esac
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit 0
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,40 @@
 | 
				
			||||||
 | 
					#! /bin/sh
 | 
				
			||||||
 | 
					# mkinstalldirs --- make directory hierarchy
 | 
				
			||||||
 | 
					# Author: Noah Friedman <friedman@prep.ai.mit.edu>
 | 
				
			||||||
 | 
					# Created: 1993-05-16
 | 
				
			||||||
 | 
					# Public domain
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# $Id$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					errstatus=0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for file
 | 
				
			||||||
 | 
					do
 | 
				
			||||||
 | 
					   set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
 | 
				
			||||||
 | 
					   shift
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   pathcomp=
 | 
				
			||||||
 | 
					   for d
 | 
				
			||||||
 | 
					   do
 | 
				
			||||||
 | 
					     pathcomp="$pathcomp$d"
 | 
				
			||||||
 | 
					     case "$pathcomp" in
 | 
				
			||||||
 | 
					       -* ) pathcomp=./$pathcomp ;;
 | 
				
			||||||
 | 
					     esac
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     if test ! -d "$pathcomp"; then
 | 
				
			||||||
 | 
					        echo "mkdir $pathcomp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        mkdir "$pathcomp" || lasterr=$?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if test ! -d "$pathcomp"; then
 | 
				
			||||||
 | 
					  	  errstatus=$lasterr
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					     fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     pathcomp="$pathcomp/"
 | 
				
			||||||
 | 
					   done
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit $errstatus
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# mkinstalldirs ends here
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,148 @@
 | 
				
			||||||
 | 
					#-------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#  Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#  Tyrell DarkIce
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#  File     : darkice.spec
 | 
				
			||||||
 | 
					#  Version  : $Revision$
 | 
				
			||||||
 | 
					#  Author   : $Author$
 | 
				
			||||||
 | 
					#  Location : $Source$
 | 
				
			||||||
 | 
					#  
 | 
				
			||||||
 | 
					#  Abstract : 
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#   Specification file to build RPM packages of DarkIce
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#  Copyright notice:
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#   This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					#   modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					#   as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					#   of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					#  
 | 
				
			||||||
 | 
					#   This 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, write to the Free Software
 | 
				
			||||||
 | 
					#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#-------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ===================================================================== preamble
 | 
				
			||||||
 | 
					Summary : DarkIce live IceCast / ShoutCast streamer
 | 
				
			||||||
 | 
					Name: darkice
 | 
				
			||||||
 | 
					Vendor: Tyrell Hungary
 | 
				
			||||||
 | 
					Packager: Akos Maroy <darkeye@tyrell.hu>
 | 
				
			||||||
 | 
					Version: 0.5
 | 
				
			||||||
 | 
					Release: 1
 | 
				
			||||||
 | 
					Copyright: GPL
 | 
				
			||||||
 | 
					Group: Applications/Multimedia
 | 
				
			||||||
 | 
					Source: ftp://darkice.sourceforge.net/pub/darkice/%{version}/darkice-%{version}.tar.gz
 | 
				
			||||||
 | 
					URL: http://darkice.sourceforge.net/
 | 
				
			||||||
 | 
					Provides: darkice
 | 
				
			||||||
 | 
					BuildRoot: %{_tmppath}/%{name}-%{version}-root
 | 
				
			||||||
 | 
					Prefix: /usr
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%description
 | 
				
			||||||
 | 
					DarkIce is an IceCast / ShoutCast live audio streamer. It takes audio input
 | 
				
			||||||
 | 
					from a sound card, encodes it into  mp3, and sends the stream to one or more
 | 
				
			||||||
 | 
					IceCast and/or ShoutCast servers.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# =========================================================== static sub-package
 | 
				
			||||||
 | 
					%package static
 | 
				
			||||||
 | 
					Summary: %{summary} static version
 | 
				
			||||||
 | 
					Group: Applications/Multimedia
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%description static
 | 
				
			||||||
 | 
					DarkIce is an IceCast / ShoutCast live audio streamer. It takes audio input
 | 
				
			||||||
 | 
					from a sound card, encodes it into  mp3, and sends the stream to one or more
 | 
				
			||||||
 | 
					IceCast and/or ShoutCast servers.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This is the statically linked version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# =================================================================== prep stage
 | 
				
			||||||
 | 
					%prep
 | 
				
			||||||
 | 
					%setup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ================================================================== build stage
 | 
				
			||||||
 | 
					%build
 | 
				
			||||||
 | 
					# first build the static executable
 | 
				
			||||||
 | 
					%configure --enable-static
 | 
				
			||||||
 | 
					make all
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					mv src/darkice src/darkice.static
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# there is no need to clean, as the object files are the same for the static
 | 
				
			||||||
 | 
					# and dynamic builds
 | 
				
			||||||
 | 
					#make distclean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# secondly build the dynamic executable
 | 
				
			||||||
 | 
					%configure
 | 
				
			||||||
 | 
					make all
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ================================================================ install stage
 | 
				
			||||||
 | 
					%install
 | 
				
			||||||
 | 
					%makeinstall
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# copy the static executable as well
 | 
				
			||||||
 | 
					cp src/darkice.static $RPM_BUILD_ROOT/%{_bindir}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ========================================================== pre-install scripts
 | 
				
			||||||
 | 
					%pre
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ========================================================= post-install scripts
 | 
				
			||||||
 | 
					%post
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ======================================================================== clean
 | 
				
			||||||
 | 
					%clean
 | 
				
			||||||
 | 
					rm -rf $RPM_BUILD_ROOT
 | 
				
			||||||
 | 
					make clean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# =========================================================== main package files
 | 
				
			||||||
 | 
					%files
 | 
				
			||||||
 | 
					%defattr (-, root, root)
 | 
				
			||||||
 | 
					%doc COPYING ChangeLog README TODO
 | 
				
			||||||
 | 
					%config %{_sysconfdir}/darkice.cfg
 | 
				
			||||||
 | 
					%{_bindir}/darkice
 | 
				
			||||||
 | 
					%{_mandir}/man1/darkice.1*
 | 
				
			||||||
 | 
					%{_mandir}/man5/darkice.cfg.5*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ===================================================== static sub-package files
 | 
				
			||||||
 | 
					%files static
 | 
				
			||||||
 | 
					%defattr (-, root, root)
 | 
				
			||||||
 | 
					%doc COPYING ChangeLog README TODO
 | 
				
			||||||
 | 
					%config %{_sysconfdir}/darkice.cfg
 | 
				
			||||||
 | 
					%{_bindir}/darkice.static
 | 
				
			||||||
 | 
					%{_mandir}/man1/darkice.1*
 | 
				
			||||||
 | 
					%{_mandir}/man5/darkice.cfg.5*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# =================================================================== change log
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#   $Log$
 | 
				
			||||||
 | 
					#   Revision 1.4  2001/09/09 12:26:33  darkeye
 | 
				
			||||||
 | 
					#   updated to reflect that DarkIce is now both an IceCast and ShoutCast streamer
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#   Revision 1.3  2001/09/09 11:48:09  darkeye
 | 
				
			||||||
 | 
					#   added man page darkice.cfg.5
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#   Revision 1.2  2001/09/02 14:44:14  darkeye
 | 
				
			||||||
 | 
					#   added system level configuration file
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#   Revision 1.1  2001/09/02 12:46:05  darkeye
 | 
				
			||||||
 | 
					#   added RPM package creation scripts
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,143 @@
 | 
				
			||||||
 | 
					#-------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#  Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#  Tyrell DarkIce
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#  File     : lame.spec
 | 
				
			||||||
 | 
					#  Version  : $Revision$
 | 
				
			||||||
 | 
					#  Author   : $Author$
 | 
				
			||||||
 | 
					#  Location : $Source$
 | 
				
			||||||
 | 
					#  
 | 
				
			||||||
 | 
					#  Abstract : 
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#   Specification file to build RPM packages of lame.
 | 
				
			||||||
 | 
					#   Builds a proper lame executable on a RedHat 7.1 system.
 | 
				
			||||||
 | 
					#   Based on the official lame RPM spec file by
 | 
				
			||||||
 | 
					#   cefiar <cefiar1@optushome.com.au>
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#  Copyright notice:
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#   This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					#   modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					#   as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					#   of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					#  
 | 
				
			||||||
 | 
					#   This 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, write to the Free Software
 | 
				
			||||||
 | 
					#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#-------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ================================================================= local macros
 | 
				
			||||||
 | 
					%define name lame
 | 
				
			||||||
 | 
					%define ver 3.89
 | 
				
			||||||
 | 
					%define quality beta
 | 
				
			||||||
 | 
					%define rel 2
 | 
				
			||||||
 | 
					%define prefix /usr
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ===================================================================== preamble
 | 
				
			||||||
 | 
					Summary : LAME Ain't an MP3 Encoder
 | 
				
			||||||
 | 
					Name: %{name}
 | 
				
			||||||
 | 
					Version: %{ver}%{quality}
 | 
				
			||||||
 | 
					Release: %{rel}
 | 
				
			||||||
 | 
					Copyright: LGPL
 | 
				
			||||||
 | 
					Vendor: The LAME Project
 | 
				
			||||||
 | 
					Packager: Akos Maroy <darkeye@tyrell.hu>
 | 
				
			||||||
 | 
					URL: http://www.mp3dev.org/mp3/
 | 
				
			||||||
 | 
					Group: Applications/Multimedia
 | 
				
			||||||
 | 
					Source: ftp://lame.sourceforge.net/pub/lame/src/%{name}%{ver}%{quality}.tar.gz
 | 
				
			||||||
 | 
					BuildRoot: %{_tmppath}/%{name}-%{ver}-root
 | 
				
			||||||
 | 
					Prefix: %{prefix}
 | 
				
			||||||
 | 
					Provides: lame
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%description
 | 
				
			||||||
 | 
					LAME is an educational tool to be used for learning about MP3 encoding.  The
 | 
				
			||||||
 | 
					goal of the LAME project is to use the open source model to improve the
 | 
				
			||||||
 | 
					psycho acoustics, noise shaping and speed of MP3.  Another goal of the LAME
 | 
				
			||||||
 | 
					project is to use these improvements for the basis of a  patent free audio
 | 
				
			||||||
 | 
					compression codec for the GNU project.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This build is optimized for %{_target}.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ============================================================ devel sub-package
 | 
				
			||||||
 | 
					%package devel
 | 
				
			||||||
 | 
					Summary: Shared and static libraries for LAME.
 | 
				
			||||||
 | 
					Group: Development/Libraries
 | 
				
			||||||
 | 
					Requires: %{name} = %{version}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%description devel
 | 
				
			||||||
 | 
					LAME is an educational tool to be used for learning about MP3 encoding.
 | 
				
			||||||
 | 
					This package contains both the shared and the static libraries from the
 | 
				
			||||||
 | 
					LAME project.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You will also need to install the main lame package in order to install
 | 
				
			||||||
 | 
					these libraries.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This build is optimized for %{_target}.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# =================================================================== prep stage
 | 
				
			||||||
 | 
					%prep
 | 
				
			||||||
 | 
					%setup -n %{name}-%{ver}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ================================================================== build stage
 | 
				
			||||||
 | 
					%build
 | 
				
			||||||
 | 
					export CC=gcc3
 | 
				
			||||||
 | 
					export CFLAGS="-O9"
 | 
				
			||||||
 | 
					%configure --with-fileio=lame   \
 | 
				
			||||||
 | 
					           --without-vorbis     \
 | 
				
			||||||
 | 
					           --disable-gtktest    \
 | 
				
			||||||
 | 
					           --enable-nasm        \
 | 
				
			||||||
 | 
					           --enable-expopt=full
 | 
				
			||||||
 | 
					make
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ================================================================ install stage
 | 
				
			||||||
 | 
					%install
 | 
				
			||||||
 | 
					%makeinstall
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ======================================================================== clean
 | 
				
			||||||
 | 
					%clean
 | 
				
			||||||
 | 
					rm -rf $RPM_BUILD_ROOT
 | 
				
			||||||
 | 
					make clean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# =========================================================== main package files
 | 
				
			||||||
 | 
					%files
 | 
				
			||||||
 | 
					%defattr (-,root,root)
 | 
				
			||||||
 | 
					%doc LICENSE USAGE COPYING TODO README*
 | 
				
			||||||
 | 
					%doc doc/html
 | 
				
			||||||
 | 
					%{_bindir}/lame
 | 
				
			||||||
 | 
					%{_mandir}/man1/lame.1*
 | 
				
			||||||
 | 
					%{_libdir}/libmp3lame.so.*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ====================================================== devel sub-package files
 | 
				
			||||||
 | 
					%files devel
 | 
				
			||||||
 | 
					%defattr (-,root,root)
 | 
				
			||||||
 | 
					%doc API HACKING STYLEGUIDE
 | 
				
			||||||
 | 
					%{_includedir}/lame/lame.h
 | 
				
			||||||
 | 
					%{_libdir}/libmp3lame.la
 | 
				
			||||||
 | 
					%{_libdir}/libmp3lame.a
 | 
				
			||||||
 | 
					%{_libdir}/libmp3lame.so
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# =================================================================== change log
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#   $Log$
 | 
				
			||||||
 | 
					#   Revision 1.2  2001/09/09 09:06:26  darkeye
 | 
				
			||||||
 | 
					#   lame RPM is now created with gcc3 and full optimizations
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#   Revision 1.1  2001/09/02 12:46:05  darkeye
 | 
				
			||||||
 | 
					#   added RPM package creation scripts
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,370 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : AudioEncoder.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $AudioEncoder$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef AUDIO_ENCODER_H
 | 
				
			||||||
 | 
					#define AUDIO_ENCODER_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Referable.h"
 | 
				
			||||||
 | 
					#include "AudioSource.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  An audio encoder
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class AudioEncoder : public virtual Referable
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Sample rate of the input.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int        inSampleRate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Number of bits per sample of the input.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int        inBitsPerSample;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Number of channels of the input.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int        inChannel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Bit rate of the output. (bits/sec)
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int        outBitrate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Sample rate of the output.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int        outSampleRate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Number of channels of the output.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int        outChannel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Initialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param inSampleRate sample rate of the input.
 | 
				
			||||||
 | 
					         *  @param inBitsPerSample number of bits per sample of the input.
 | 
				
			||||||
 | 
					         *  @param inChannel number of channels  of the input.
 | 
				
			||||||
 | 
					         *  @param outBitrate bit rate of the output.
 | 
				
			||||||
 | 
					         *  @param outSampleRate sample rate of the output.
 | 
				
			||||||
 | 
					         *  @param outChannel number of channels of the output.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        init (      unsigned int    inSampleRate,
 | 
				
			||||||
 | 
					                    unsigned int    inBitsPerSample,
 | 
				
			||||||
 | 
					                    unsigned int    inChannel,
 | 
				
			||||||
 | 
					                    unsigned int    outBitrate,
 | 
				
			||||||
 | 
					                    unsigned int    outSampleRate,
 | 
				
			||||||
 | 
					                    unsigned int    outChannel )        throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            this->inSampleRate     = inSampleRate;
 | 
				
			||||||
 | 
					            this->inBitsPerSample  = inBitsPerSample;
 | 
				
			||||||
 | 
					            this->inChannel        = inChannel;
 | 
				
			||||||
 | 
					            this->outBitrate       = outBitrate;
 | 
				
			||||||
 | 
					            this->outSampleRate    = outSampleRate;
 | 
				
			||||||
 | 
					            this->outChannel       = outChannel;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  De-iitialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        strip ( void )                                  throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        AudioEncoder ( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param inSampleRate sample rate of the input.
 | 
				
			||||||
 | 
					         *  @param inBitsPerSample number of bits per sample of the input.
 | 
				
			||||||
 | 
					         *  @param inChannel number of channels  of the input.
 | 
				
			||||||
 | 
					         *  @param outBitrate bit rate of the output (bits/sec).
 | 
				
			||||||
 | 
					         *  @param outSampleRate sample rate of the output.
 | 
				
			||||||
 | 
					         *                       If 0, inSampleRate is used.
 | 
				
			||||||
 | 
					         *  @param outChannel number of channels of the output.
 | 
				
			||||||
 | 
					         *                    If 0, inChannel is used.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        AudioEncoder (  unsigned int    inSampleRate,
 | 
				
			||||||
 | 
					                        unsigned int    inBitsPerSample,
 | 
				
			||||||
 | 
					                        unsigned int    inChannel, 
 | 
				
			||||||
 | 
					                        unsigned int    outBitrate,
 | 
				
			||||||
 | 
					                        unsigned int    outSampleRate = 0,
 | 
				
			||||||
 | 
					                        unsigned int    outChannel    = 0 )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init ( inSampleRate,
 | 
				
			||||||
 | 
					                   inBitsPerSample,
 | 
				
			||||||
 | 
					                   inChannel, 
 | 
				
			||||||
 | 
					                   outBitrate,
 | 
				
			||||||
 | 
					                   outSampleRate ? outSampleRate : inSampleRate,
 | 
				
			||||||
 | 
					                   outChannel    ? outChannel    : inChannel );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param as get input sample rate, bits per sample and channels
 | 
				
			||||||
 | 
					         *            from this AudioSource.
 | 
				
			||||||
 | 
					         *  @param outBitrate bit rate of the output (bits/sec).
 | 
				
			||||||
 | 
					         *  @param outSampleRate sample rate of the output.
 | 
				
			||||||
 | 
					         *                       If 0, input sample rate is used.
 | 
				
			||||||
 | 
					         *  @param outChannel number of channels of the output.
 | 
				
			||||||
 | 
					         *                    If 0, input channel is used.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        AudioEncoder (  const AudioSource     * as,
 | 
				
			||||||
 | 
					                        unsigned int            outBitrate,
 | 
				
			||||||
 | 
					                        unsigned int            outSampleRate = 0,
 | 
				
			||||||
 | 
					                        unsigned int            outChannel    = 0 )
 | 
				
			||||||
 | 
					                                                        throw ( Exception)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( as->getSampleRate(),
 | 
				
			||||||
 | 
					                  as->getBitsPerSample(),
 | 
				
			||||||
 | 
					                  as->getChannel(), 
 | 
				
			||||||
 | 
					                  outBitrate,
 | 
				
			||||||
 | 
					                  outSampleRate ? outSampleRate : as->getSampleRate(),
 | 
				
			||||||
 | 
					                  outChannel    ? outChannel    : as->getChannel() );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param encoder the AudioEncoder to copy.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        AudioEncoder (  const AudioEncoder &    encoder )   throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init ( encoder.inSampleRate,
 | 
				
			||||||
 | 
					                   encoder.inBitsPerSample,
 | 
				
			||||||
 | 
					                   encoder.inChannel,
 | 
				
			||||||
 | 
					                   encoder.outBitrate,
 | 
				
			||||||
 | 
					                   encoder.outSampleRate,
 | 
				
			||||||
 | 
					                   encoder.outChannel );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param encoder the AudioEncoder to assign this to.
 | 
				
			||||||
 | 
					         *  @return a reference to this AudioEncoder.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual AudioEncoder &
 | 
				
			||||||
 | 
					        operator= ( const AudioEncoder &        encoder )   throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( this != &encoder ) {
 | 
				
			||||||
 | 
					                strip();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                init ( encoder.inSampleRate,
 | 
				
			||||||
 | 
					                       encoder.inBitsPerSample,
 | 
				
			||||||
 | 
					                       encoder.inChannel,
 | 
				
			||||||
 | 
					                       encoder.outBitrate,
 | 
				
			||||||
 | 
					                       encoder.outSampleRate,
 | 
				
			||||||
 | 
					                       encoder.outChannel );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return *this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~AudioEncoder ( void )          throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            strip();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the number of channels of the input.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the number of channels  of the input.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline int
 | 
				
			||||||
 | 
					        getInChannel ( void ) const         throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return inChannel;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the sample rate of the input.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the sample rate of the input.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline int
 | 
				
			||||||
 | 
					        getInSampleRate ( void ) const      throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return inSampleRate;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the number of bits per sample of the input.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the number of bits per sample of the input.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline int
 | 
				
			||||||
 | 
					        getInBitsPerSample ( void ) const   throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return inBitsPerSample;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the number of channels of the output.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the number of channels of the output.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline int
 | 
				
			||||||
 | 
					        getOutChannel ( void ) const        throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return outChannel;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the sample rate of the output.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the sample rate of the output.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline int
 | 
				
			||||||
 | 
					        getOutSampleRate ( void ) const     throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return outSampleRate;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the bit rate of the output. (bits/sec)
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the bit rate of the output.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline int
 | 
				
			||||||
 | 
					        getOutBitrate ( void ) const        throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return outBitrate;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check wether encoding is in progress.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if encoding is in progress, false otherwise.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        isRunning ( void ) const           throw ()                 = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Start encoding. This function returns as soon as possible,
 | 
				
			||||||
 | 
					         *  with encoding started in the background.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if encoding has started, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        start ( void )                      throw ( Exception )     = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Stop encoding. Stops the encoding running in the background.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual void
 | 
				
			||||||
 | 
					        stop ( void )                       throw ( Exception )     = 0;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* AUDIO_ENCODER_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/12 14:54:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:47  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,234 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : AudioSource.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef AUDIO_SOURCE_H
 | 
				
			||||||
 | 
					#define AUDIO_SOURCE_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Source.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  Audio data input
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class AudioSource : public Source
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Number of channels of the audio source
 | 
				
			||||||
 | 
					         *  (e.g. 1 for mono, 2 for stereo, etc.)
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int    channel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Samples per second (e.g. 44100 for 44.1kHz CD quality)
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int    sampleRate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Bits per sample (e.g. 8 bits, 16 bits, etc.)
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int    bitsPerSample;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Initialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sampleRate samples per second.
 | 
				
			||||||
 | 
					         *  @param bitsPerSample bits per sample.
 | 
				
			||||||
 | 
					         *  @param channel number of channels of the audio source.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        init (   unsigned int   sampleRate,
 | 
				
			||||||
 | 
					                 unsigned int   bitsPerSample,
 | 
				
			||||||
 | 
					                 unsigned int   channel )               throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            this->sampleRate     = sampleRate;
 | 
				
			||||||
 | 
					            this->bitsPerSample  = bitsPerSample;
 | 
				
			||||||
 | 
					            this->channel        = channel;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  De-initialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        strip ( void )                                  throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor.
 | 
				
			||||||
 | 
					         *  Because all values have defaults, this is also the default
 | 
				
			||||||
 | 
					         *  constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sampleRate samples per second (e.g. 44100 for 44.1kHz).
 | 
				
			||||||
 | 
					         *  @param bitsPerSample bits per sample (e.g. 16 bits).
 | 
				
			||||||
 | 
					         *  @param channel number of channels of the audio source
 | 
				
			||||||
 | 
					         *                 (e.g. 1 for mono, 2 for stereo, etc.).
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        AudioSource (   unsigned int    sampleRate    = 44100,
 | 
				
			||||||
 | 
					                        unsigned int    bitsPerSample = 16,
 | 
				
			||||||
 | 
					                        unsigned int    channel       = 2 )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init ( sampleRate, bitsPerSample, channel);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param source the object to copy.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        AudioSource (   const AudioSource &     as )    throw ( Exception )
 | 
				
			||||||
 | 
					            : Source( as )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init ( as.sampleRate, as.bitsPerSample, as.channel);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual inline
 | 
				
			||||||
 | 
					        ~AudioSource ( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param as the object to assign to this one.
 | 
				
			||||||
 | 
					         *  @return a reference to this object.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual AudioSource &
 | 
				
			||||||
 | 
					        operator= (     const AudioSource &     as )    throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( this != &as ) {
 | 
				
			||||||
 | 
					                strip();
 | 
				
			||||||
 | 
					                Source::operator=( as );
 | 
				
			||||||
 | 
					                init ( as.sampleRate, as.bitsPerSample, as.channel);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return *this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the number of channels for this AudioSource.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the number of channels.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        getChannel ( void ) const           throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return channel;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the sample rate per seconds for this AudioSource.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the sample rate per seconds.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        getSampleRate ( void ) const        throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return sampleRate;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the number of bits per sample for this AudioSource.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the number of bits per sample.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        getBitsPerSample ( void ) const     throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return bitsPerSample;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* AUDIO_SOURCE_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/12 13:31:40  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 17:37:24  darkeye
 | 
				
			||||||
 | 
					  removed clone() functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:47  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,392 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : BufferedSink.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					     the buffer is filled like this:
 | 
				
			||||||
 | 
					     
 | 
				
			||||||
 | 
					     buffer                                         bufferEnd
 | 
				
			||||||
 | 
					      |                                                    |
 | 
				
			||||||
 | 
					      +----------+--------------------------+--------------+
 | 
				
			||||||
 | 
					                 |<---- valid data -------->|
 | 
				
			||||||
 | 
					                outp                       inp 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     buffer                                         bufferEnd
 | 
				
			||||||
 | 
					      |                                                    |
 | 
				
			||||||
 | 
					      +----------------+--------------+--------------------+
 | 
				
			||||||
 | 
					      -- valid data -->|              |--- valid data ----->
 | 
				
			||||||
 | 
					                      inp            outp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_STRING_H
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need string.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					#include "BufferedSink.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					BufferedSink :: init (  Sink          * sink,
 | 
				
			||||||
 | 
					                        unsigned int    size,
 | 
				
			||||||
 | 
					                        unsigned int    chunkSize )     throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !sink ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no sink");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this->sink         = sink;                    // create a reference
 | 
				
			||||||
 | 
					    this->chunkSize    = chunkSize ? chunkSize : 1;
 | 
				
			||||||
 | 
					    this->bufferSize   = size;
 | 
				
			||||||
 | 
					    // make bufferSize a multiple of chunkSize
 | 
				
			||||||
 | 
					    this->bufferSize  -= this->bufferSize % this->chunkSize;
 | 
				
			||||||
 | 
					    this->peak         = 0;
 | 
				
			||||||
 | 
					    this->misalignment = 0;
 | 
				
			||||||
 | 
					    this->buffer       = new unsigned char[bufferSize];
 | 
				
			||||||
 | 
					    this->bufferEnd    = buffer + bufferSize;
 | 
				
			||||||
 | 
					    this->inp          = buffer;
 | 
				
			||||||
 | 
					    this->outp         = buffer;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Copy Constructor
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					BufferedSink :: BufferedSink (  const BufferedSink &  buffer )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    init( buffer.sink.get(), buffer.bufferSize, buffer.chunkSize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this->peak         = buffer.peak;
 | 
				
			||||||
 | 
					    this->misalignment = buffer.misalignment;
 | 
				
			||||||
 | 
					    memcpy( this->buffer, buffer.buffer, this->bufferSize);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  De-initalize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					BufferedSink :: strip ( void )                      throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( isOpen() ) {
 | 
				
			||||||
 | 
					        close();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    sink = 0;                                   // delete the reference
 | 
				
			||||||
 | 
					    delete buffer;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Assignment operator
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					BufferedSink &
 | 
				
			||||||
 | 
					BufferedSink :: operator= (     const BufferedSink &  buffer )
 | 
				
			||||||
 | 
					                                                    throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( this != &buffer ) {
 | 
				
			||||||
 | 
					        strip();
 | 
				
			||||||
 | 
					        Sink::operator=( buffer );
 | 
				
			||||||
 | 
					        init( buffer.sink.get(), buffer.bufferSize, buffer.chunkSize);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        this->peak         = buffer.peak;
 | 
				
			||||||
 | 
					        this->misalignment = buffer.misalignment;
 | 
				
			||||||
 | 
					        memcpy( this->buffer, buffer.buffer, this->bufferSize);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return *this;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Store bufferSize bytes into the buffer
 | 
				
			||||||
 | 
					 *  All data is consumed. The return value is less then bufferSize only
 | 
				
			||||||
 | 
					 *  if the BufferedSink's internal buffer is smaller than bufferSize,
 | 
				
			||||||
 | 
					 *  thus can't hold that much
 | 
				
			||||||
 | 
					 *  The data to be stored is treated as parts with chunkSize size
 | 
				
			||||||
 | 
					 *  Only full chunkSize sized parts are stored
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					unsigned int
 | 
				
			||||||
 | 
					BufferedSink :: store (     const void    * buffer,
 | 
				
			||||||
 | 
					                            unsigned int    bufferSize )    throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    const unsigned char   * buf;
 | 
				
			||||||
 | 
					    unsigned int            size;
 | 
				
			||||||
 | 
					    unsigned int            i;
 | 
				
			||||||
 | 
					    unsigned char         * oldInp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !buffer ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "buffer is null");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !bufferSize ) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    oldInp = inp;
 | 
				
			||||||
 | 
					    buf    = (const unsigned char *) buffer;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    // adjust so it is a multiple of chunkSize
 | 
				
			||||||
 | 
					    bufferSize -= bufferSize % chunkSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // cut the front of the supplied buffer if it wouldn't fit
 | 
				
			||||||
 | 
					    if ( bufferSize > this->bufferSize ) {
 | 
				
			||||||
 | 
					        size  = this->bufferSize - 1;
 | 
				
			||||||
 | 
					        size -= size % chunkSize;       // keep it a multiple of chunkSize
 | 
				
			||||||
 | 
					        buf  += bufferSize - size;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        size = bufferSize;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // copy the data into the buffer
 | 
				
			||||||
 | 
					    i = bufferEnd - inp;
 | 
				
			||||||
 | 
					    if ( (i % chunkSize) != 0 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "copy quantity not aligned", i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( size <= i ) {
 | 
				
			||||||
 | 
					        // the place between inp and bufferEnd is
 | 
				
			||||||
 | 
					        // big enough to hold the data
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        memcpy( inp, buf, size);
 | 
				
			||||||
 | 
					        inp = slidePointer( inp, size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // adjust outp, lose the data that was overwritten, if any
 | 
				
			||||||
 | 
					        if ( outp > oldInp && outp <= inp ) {
 | 
				
			||||||
 | 
					            outp = slidePointer( inp, chunkSize);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        // the place between inp and bufferEnd is not
 | 
				
			||||||
 | 
					        // big enough to hold the data
 | 
				
			||||||
 | 
					        // writing will take place in two turns, once from
 | 
				
			||||||
 | 
					        // inp -> bufferEnd, then from buffer ->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        memcpy( inp, buf, i);
 | 
				
			||||||
 | 
					        i = size - i;
 | 
				
			||||||
 | 
					        if ( (i % chunkSize) != 0 ) {
 | 
				
			||||||
 | 
					            throw Exception(__FILE__, __LINE__, "copy quantity not aligned", i);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        memcpy( this->buffer, buf, i);
 | 
				
			||||||
 | 
					        inp = slidePointer( this->buffer, i);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // adjust outp, lose the data that was overwritten, if any
 | 
				
			||||||
 | 
					        if ( outp <= oldInp ) {
 | 
				
			||||||
 | 
					            if ( outp < inp ) {
 | 
				
			||||||
 | 
					                outp = slidePointer( inp, chunkSize);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            outp = slidePointer( inp, chunkSize);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    updatePeak();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( ((inp - this->buffer) % chunkSize) != 0 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "inp not aligned", inp - this->buffer);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( ((outp - this->buffer) % chunkSize) != 0 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "outp not aligned", outp - this->buffer);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return size;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Write some data to the sink
 | 
				
			||||||
 | 
					 *  if len == 0, try to flush the buffer
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					unsigned int
 | 
				
			||||||
 | 
					BufferedSink :: write (    const void    * buf,
 | 
				
			||||||
 | 
					                           unsigned int    len )       throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unsigned int    length;
 | 
				
			||||||
 | 
					    unsigned int    soFar;
 | 
				
			||||||
 | 
					    unsigned char * b = (unsigned char *) buf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !buf ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "buf is null");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !isOpen() ) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !align() ) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // make it a multiple of chunkSize
 | 
				
			||||||
 | 
					    len -= len % chunkSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // try to write data from the buffer first, if any
 | 
				
			||||||
 | 
					    if ( inp != outp ) {
 | 
				
			||||||
 | 
					        unsigned int    size  = 0;
 | 
				
			||||||
 | 
					        unsigned int    total = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( outp > inp ) {
 | 
				
			||||||
 | 
					            // valuable data is between outp -> bufferEnd and buffer -> inp
 | 
				
			||||||
 | 
					            // try to write the outp -> bufferEnd
 | 
				
			||||||
 | 
					            // the rest will be written in the next if
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            size    = bufferEnd - outp - 1;
 | 
				
			||||||
 | 
					            size   -= size % chunkSize;
 | 
				
			||||||
 | 
					            soFar   = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            while ( outp > inp && soFar < size && sink->canWrite( 0, 0) ) {
 | 
				
			||||||
 | 
					                length  = sink->write( outp + soFar, size - soFar);
 | 
				
			||||||
 | 
					                outp    = slidePointer( outp, length);
 | 
				
			||||||
 | 
					                soFar  += length;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            total += soFar;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( outp < inp ) {
 | 
				
			||||||
 | 
					            // valuable data is between outp and inp
 | 
				
			||||||
 | 
					            // if the previous if wrote all data from the end
 | 
				
			||||||
 | 
					            // this part will write the rest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            size    = inp - outp;
 | 
				
			||||||
 | 
					            soFar   = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            while ( soFar < size && sink->canWrite( 0, 0) ) {
 | 
				
			||||||
 | 
					                length  = sink->write( outp + soFar, size - soFar);
 | 
				
			||||||
 | 
					                outp    = slidePointer( outp, length);
 | 
				
			||||||
 | 
					                soFar  += length;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            total += soFar;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        while ( (outp - buffer) % chunkSize ) {
 | 
				
			||||||
 | 
					            slidePointer( outp, 1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // calulate the misalignment to chunkSize boundaries
 | 
				
			||||||
 | 
					        misalignment = (chunkSize - (total % chunkSize)) % chunkSize;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !align() ) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // the internal buffer is empty, try to write the fresh data
 | 
				
			||||||
 | 
					    soFar = 0;
 | 
				
			||||||
 | 
					    if ( inp != outp ) {
 | 
				
			||||||
 | 
					        while ( soFar < len && sink->canWrite( 0, 0) ) {
 | 
				
			||||||
 | 
					            soFar += sink->write( b + soFar, len - soFar);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    length = soFar;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // calulate the misalignment to chunkSize boundaries
 | 
				
			||||||
 | 
					    misalignment = (chunkSize - (length % chunkSize)) % chunkSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( length < len ) {
 | 
				
			||||||
 | 
					        // if not all fresh could be written, store the remains
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        store( b + length, len - length);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // tell them we ate everything up to chunkSize alignment
 | 
				
			||||||
 | 
					    return len;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Close the sink, lose all pending data
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					BufferedSink :: close ( void )                      throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !isOpen() ) {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    flush();
 | 
				
			||||||
 | 
					    sink->close();
 | 
				
			||||||
 | 
					    inp = outp = buffer;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.5  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/11 12:33:13  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/10 20:16:21  darkeye
 | 
				
			||||||
 | 
					  first real tests with multiple streaming
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 14:08:27  darkeye
 | 
				
			||||||
 | 
					  changed builting to an automake / autoconf environment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:48  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,412 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : BufferedSink.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef BUFFERED_SINK_H
 | 
				
			||||||
 | 
					#define BUFFERED_SINK_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Ref.h"
 | 
				
			||||||
 | 
					#include "Reporter.h"
 | 
				
			||||||
 | 
					#include "Sink.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  A Sink First-In First-Out buffer.
 | 
				
			||||||
 | 
					 *  This buffer can always be written to, it overwrites any
 | 
				
			||||||
 | 
					 *  data contained if needed.
 | 
				
			||||||
 | 
					 *  The class is not thread-safe.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class BufferedSink : public Sink, public virtual Reporter
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The buffer.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned char     * buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The end of the buffer.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned char     * bufferEnd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The size of the buffer.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int        bufferSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The highest usage of the buffer.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int        peak;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  All data written to this BufferedSink is handled by chuncks
 | 
				
			||||||
 | 
					         *  of this size.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int        chunkSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Number of bytes the underlying stream is misaligned with
 | 
				
			||||||
 | 
					         *  chunkSize. (It needs this many bytes more to be aligned.)
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int        misalignment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Start of free territory in buffer.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned char     * inp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Start of sensible data in buffer.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned char     * outp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The underlying Sink.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        Ref<Sink>           sink;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Initialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sink the Sink to attach this BufferedSink to.
 | 
				
			||||||
 | 
					         *  @param size the size of the internal buffer to use.
 | 
				
			||||||
 | 
					         *  @param chunkSize size of chunks to handle data in.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        init (  Sink              * sink,
 | 
				
			||||||
 | 
					                unsigned int        size,
 | 
				
			||||||
 | 
					                unsigned int        chunkSize )         throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  De-initialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        strip ( void )                                  throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Slide a pointer in the internal buffer by offset. If the pointer
 | 
				
			||||||
 | 
					         *  would reach beyond the end of the buffer, it goes wraps around.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param p the pointer to slide.
 | 
				
			||||||
 | 
					         *  @param offset the amount to slide with.
 | 
				
			||||||
 | 
					         *  @return pointer p + offset, wrapped around if needed.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned char *
 | 
				
			||||||
 | 
					        slidePointer (
 | 
				
			||||||
 | 
					                        unsigned char * p,
 | 
				
			||||||
 | 
					                        unsigned int    offset )        throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            p += offset;
 | 
				
			||||||
 | 
					            while ( p >= bufferEnd ) {
 | 
				
			||||||
 | 
					                p -= bufferSize;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return p;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Update the peak buffer usage indicator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @see #peak
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        updatePeak ( void )                             throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            unsigned int    u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            u = outp <= inp ? inp - outp : (bufferEnd - outp) + (inp - buffer);
 | 
				
			||||||
 | 
					            if ( peak < u ) {
 | 
				
			||||||
 | 
					                reportEvent( 4, "BufferedSink, new peak:", peak);
 | 
				
			||||||
 | 
					                reportEvent( 4, "BufferedSink, remaining:", bufferSize - peak);
 | 
				
			||||||
 | 
					                peak = u;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  If the underlying Sink is misaligned on chunkSize, write as
 | 
				
			||||||
 | 
					         *  many 0s as needed to get it aligned.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @see #misalignment
 | 
				
			||||||
 | 
					         *  @see #chunkSize
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline bool
 | 
				
			||||||
 | 
					        align ( void )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            char    b[] = { 0 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            while ( misalignment ) {
 | 
				
			||||||
 | 
					                if ( sink->canWrite( 0, 0) ) {
 | 
				
			||||||
 | 
					                    unsigned int    ret;
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                    if ( !(ret = sink->write( b, 1)) ) {
 | 
				
			||||||
 | 
					                        return false;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    --misalignment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    return false;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *  
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        BufferedSink ( void )                       throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the size of the buffer.
 | 
				
			||||||
 | 
					         *  
 | 
				
			||||||
 | 
					         *  @return the size of the buffer.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        getSize ( void ) const                      throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return bufferSize;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Store data in the internal buffer. If there is not enough space,
 | 
				
			||||||
 | 
					         *  discard all in the buffer and the beginning of the supplied
 | 
				
			||||||
 | 
					         *  buffer if needed.
 | 
				
			||||||
 | 
					         *  
 | 
				
			||||||
 | 
					         *  @param buffer the data to store.
 | 
				
			||||||
 | 
					         *  @param bufferSize the amount of data to store in bytes.
 | 
				
			||||||
 | 
					         *  @return number of bytes really stored.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int
 | 
				
			||||||
 | 
					        store (     const void    * buffer,
 | 
				
			||||||
 | 
					                    unsigned int    bufferSize )    throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor by an underlying Sink, buffer size and chunk size.
 | 
				
			||||||
 | 
					         *  
 | 
				
			||||||
 | 
					         *  @param sink the Sink to attach this BufferSink to.
 | 
				
			||||||
 | 
					         *  @param size the size of the buffer to use for buffering.
 | 
				
			||||||
 | 
					         *  @param chunkSize hanlde all data in write() as chunks of
 | 
				
			||||||
 | 
					         *                   chunkSize
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline 
 | 
				
			||||||
 | 
					        BufferedSink (  Sink              * sink,
 | 
				
			||||||
 | 
					                        unsigned int        size,
 | 
				
			||||||
 | 
					                        unsigned int        chunkSize = 1 ) throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( sink, size, chunkSize);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy constructor.
 | 
				
			||||||
 | 
					         *  
 | 
				
			||||||
 | 
					         *  @param buffer the object to copy.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        BufferedSink (  const BufferedSink &  buffer )  throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *  
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~BufferedSink ( void )                          throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            strip();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *  
 | 
				
			||||||
 | 
					         *  @param bs the object to assign to this one.
 | 
				
			||||||
 | 
					         *  @return a reference to this object.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual BufferedSink &
 | 
				
			||||||
 | 
					        operator= ( const BufferedSink &    bs )        throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the peak usage of the internal buffer.
 | 
				
			||||||
 | 
					         *  
 | 
				
			||||||
 | 
					         *  @return the peak usage of the internal buffer.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        getPeak ( void ) const                          throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return peak;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Open the BufferedSink. Opens the underlying Sink.
 | 
				
			||||||
 | 
					         *  
 | 
				
			||||||
 | 
					         *  @return true if opening was successful, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual bool
 | 
				
			||||||
 | 
					        open ( void )                                   throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return sink->open();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if a BufferedSink is open.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if the BufferedSink is open, false otherwise.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual bool
 | 
				
			||||||
 | 
					        isOpen ( void ) const                           throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return sink->isOpen();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the BufferedSink is ready to accept data.
 | 
				
			||||||
 | 
					         *  Always returns true immediately.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sec the maximum seconds to block.
 | 
				
			||||||
 | 
					         *  @param usec micro seconds to block after the full seconds.
 | 
				
			||||||
 | 
					         *  @return true
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual bool
 | 
				
			||||||
 | 
					        canWrite (     unsigned int    sec,
 | 
				
			||||||
 | 
					                       unsigned int    usec )           throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Write data to the BufferedSink.
 | 
				
			||||||
 | 
					         *  Always reads the maximum number of chunkSize chunks buf
 | 
				
			||||||
 | 
					         *  holds. If the data can not be written to the underlying
 | 
				
			||||||
 | 
					         *  stream, it is buffered. If the buffer overflows, the oldest
 | 
				
			||||||
 | 
					         *  data is discarded.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param buf the data to write.
 | 
				
			||||||
 | 
					         *  @param len number of bytes to write from buf.
 | 
				
			||||||
 | 
					         *  @return the number of bytes written (may be less than len).
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual unsigned int
 | 
				
			||||||
 | 
					        write (    const void    * buf,
 | 
				
			||||||
 | 
					                   unsigned int    len )                throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Flush all data that was written to the BufferedSink to the
 | 
				
			||||||
 | 
					         *  underlying Sink.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual void
 | 
				
			||||||
 | 
					        flush ( void )                                  throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            unsigned char   b[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            write( b, 0);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Close the BufferedSink. Closes the underlying Sink.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual void
 | 
				
			||||||
 | 
					        close ( void )                                  throw ( Exception );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* BUFFERED_SINK_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.5  2000/11/15 18:08:42  darkeye
 | 
				
			||||||
 | 
					  added multiple verbosity-level event reporting and verbosity command
 | 
				
			||||||
 | 
					  line option
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/11 12:33:13  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/10 20:16:21  darkeye
 | 
				
			||||||
 | 
					  first real tests with multiple streaming
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 17:37:24  darkeye
 | 
				
			||||||
 | 
					  removed clone() functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:48  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,151 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : CastSink.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Util.h"
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					#include "CastSink.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					CastSink :: init (  TcpSocket             * socket,
 | 
				
			||||||
 | 
					                    const char            * password,
 | 
				
			||||||
 | 
					                    unsigned int            bitRate,
 | 
				
			||||||
 | 
					                    const char            * name,
 | 
				
			||||||
 | 
					                    const char            * url,
 | 
				
			||||||
 | 
					                    const char            * genre,
 | 
				
			||||||
 | 
					                    bool                    isPublic,
 | 
				
			||||||
 | 
					                    unsigned int            bufferDuration )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    this->socket         = socket;
 | 
				
			||||||
 | 
					    this->password       = Util::strDup( password);
 | 
				
			||||||
 | 
					    this->bitRate        = bitRate;
 | 
				
			||||||
 | 
					    this->name           = name           ? Util::strDup( name) : 0;
 | 
				
			||||||
 | 
					    this->url            = url            ? Util::strDup( url) : 0;
 | 
				
			||||||
 | 
					    this->genre          = genre          ? Util::strDup( genre) : 0;
 | 
				
			||||||
 | 
					    this->isPublic       = isPublic;
 | 
				
			||||||
 | 
					    this->bufferDuration = bufferDuration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    bufferedSink = new BufferedSink( socket,
 | 
				
			||||||
 | 
					                                     (bitRate * 1024 / 8) * bufferDuration);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  De-initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					CastSink :: strip ( void )                          throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( isOpen() ) {
 | 
				
			||||||
 | 
					        close();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    delete[] password;
 | 
				
			||||||
 | 
					    if ( name ) {
 | 
				
			||||||
 | 
					        delete[] name;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( url ) {
 | 
				
			||||||
 | 
					        delete[] url;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( genre ) {
 | 
				
			||||||
 | 
					        delete[] genre;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Open the connection
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					CastSink :: open ( void )                       throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( isOpen() ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !bufferedSink->open() ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !sendLogin() ) {
 | 
				
			||||||
 | 
					        close();
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.5  2001/09/09 11:27:31  darkeye
 | 
				
			||||||
 | 
					  added support for ShoutCast servers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2001/08/29 21:08:30  darkeye
 | 
				
			||||||
 | 
					  made some description options in the darkice config file optional
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/12 14:54:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/10 20:14:11  darkeye
 | 
				
			||||||
 | 
					  added support for remote dump file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:48  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,470 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : CastSink.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef CAST_SINK_H
 | 
				
			||||||
 | 
					#define CAST_SINK_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Ref.h"
 | 
				
			||||||
 | 
					#include "Sink.h"
 | 
				
			||||||
 | 
					#include "TcpSocket.h"
 | 
				
			||||||
 | 
					#include "BufferedSink.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  Data output to a ShoutCast / IceCast / etc. server
 | 
				
			||||||
 | 
					 *  This is an abstract class. A subclass should override at least
 | 
				
			||||||
 | 
					 *  the sendLogin() function.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class CastSink : public Sink
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The socket connection to the server.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        Ref<TcpSocket>      socket;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The BufferedSink encapsulating the socket connection to the server.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        Ref<BufferedSink>   bufferedSink;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Duration of the BufferedSink buffer in seconds.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int        bufferDuration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Password to the server.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char              * password;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Name of the stream.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char              * name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  URL associated with the stream.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char              * url;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Genre of the stream.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char              * genre;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Bitrate of the stream (e.g. mp3 bitrate).
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int        bitRate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Is the stream public?
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        bool                isPublic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Initalize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param socket socket connection to the server.
 | 
				
			||||||
 | 
					         *  @param password password to the server.
 | 
				
			||||||
 | 
					         *  @param name name of the stream.
 | 
				
			||||||
 | 
					         *  @param url URL associated with the stream.
 | 
				
			||||||
 | 
					         *  @param genre genre of the stream.
 | 
				
			||||||
 | 
					         *  @param bitRate bitrate of the stream (e.g. mp3 bitrate).
 | 
				
			||||||
 | 
					         *  @param isPublic is the stream public?
 | 
				
			||||||
 | 
					         *  @param bufferDuration duration of the BufferedSink buffer
 | 
				
			||||||
 | 
					         *                        in seconds.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        init (  TcpSocket             * socket,
 | 
				
			||||||
 | 
					                const char            * password,
 | 
				
			||||||
 | 
					                unsigned int            bitRate,
 | 
				
			||||||
 | 
					                const char            * name,
 | 
				
			||||||
 | 
					                const char            * url,
 | 
				
			||||||
 | 
					                const char            * genre,
 | 
				
			||||||
 | 
					                bool                    isPublic,
 | 
				
			||||||
 | 
					                unsigned int            bufferDuration )
 | 
				
			||||||
 | 
					                                                    throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  De-initalize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        strip ( void )                              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        CastSink ( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Log in to the server using the socket avialable.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if login was successful, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        sendLogin ( void )              throw ( Exception )         = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the Sink underneath this CastSink.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return pointer to the Sink underneath this CastSink.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline Sink *
 | 
				
			||||||
 | 
					        getSink ( void ) const                      throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return bufferedSink.get();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the TcpSocket underneath this CastSink.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return pointer to the TcpSocket underneath this CastSink.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline TcpSocket *
 | 
				
			||||||
 | 
					        getSocket ( void ) const                    throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return socket.get();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param socket socket connection to the server.
 | 
				
			||||||
 | 
					         *  @param password password to the server.
 | 
				
			||||||
 | 
					         *  @param name name of the stream.
 | 
				
			||||||
 | 
					         *  @param url URL associated with the stream.
 | 
				
			||||||
 | 
					         *  @param genre genre of the stream.
 | 
				
			||||||
 | 
					         *  @param bitRate bitrate of the stream (e.g. mp3 bitrate).
 | 
				
			||||||
 | 
					         *  @param isPublic is the stream public?
 | 
				
			||||||
 | 
					         *  @param bufferDuration duration of the BufferedSink buffer
 | 
				
			||||||
 | 
					         *                        in seconds.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        CastSink (  TcpSocket         * socket,
 | 
				
			||||||
 | 
					                    const char        * password,
 | 
				
			||||||
 | 
					                    unsigned int        bitRate,
 | 
				
			||||||
 | 
					                    const char        * name           = 0,
 | 
				
			||||||
 | 
					                    const char        * url            = 0,
 | 
				
			||||||
 | 
					                    const char        * genre          = 0,
 | 
				
			||||||
 | 
					                    bool                isPublic       = false,
 | 
				
			||||||
 | 
					                    unsigned int        bufferDuration = 10 )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( socket,
 | 
				
			||||||
 | 
					                  password,
 | 
				
			||||||
 | 
					                  bitRate,
 | 
				
			||||||
 | 
					                  name,
 | 
				
			||||||
 | 
					                  url,
 | 
				
			||||||
 | 
					                  genre,
 | 
				
			||||||
 | 
					                  isPublic,
 | 
				
			||||||
 | 
					                  bufferDuration );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param cs the CastSink to copy.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        CastSink(   const CastSink &    cs )        throw ( Exception )
 | 
				
			||||||
 | 
					                : Sink( cs )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( cs.socket.get(),
 | 
				
			||||||
 | 
					                  cs.password,
 | 
				
			||||||
 | 
					                  cs.bitRate,
 | 
				
			||||||
 | 
					                  cs.name,
 | 
				
			||||||
 | 
					                  cs.url,
 | 
				
			||||||
 | 
					                  cs.genre,
 | 
				
			||||||
 | 
					                  cs.isPublic,
 | 
				
			||||||
 | 
					                  cs.bufferDuration );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~CastSink( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            strip();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param cs the CastSink to assign this to.
 | 
				
			||||||
 | 
					         *  @return a reference to this CastSink.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual CastSink &
 | 
				
			||||||
 | 
					        operator= ( const CastSink &    cs )        throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( this != &cs ) {
 | 
				
			||||||
 | 
					                strip();
 | 
				
			||||||
 | 
					                Sink::operator=( cs );
 | 
				
			||||||
 | 
					                init( cs.socket.get(),
 | 
				
			||||||
 | 
					                      cs.password,
 | 
				
			||||||
 | 
					                      cs.bitRate,
 | 
				
			||||||
 | 
					                      cs.name,
 | 
				
			||||||
 | 
					                      cs.url,
 | 
				
			||||||
 | 
					                      cs.genre,
 | 
				
			||||||
 | 
					                      cs.isPublic,
 | 
				
			||||||
 | 
					                      cs.bufferDuration );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return *this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Open the CastSink.
 | 
				
			||||||
 | 
					         *  Logs in to the server.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if opening was successfull, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        open ( void )                               throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the CastSink is open.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if the CastSink is open, false otherwise.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual bool
 | 
				
			||||||
 | 
					        isOpen ( void ) const                       throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return bufferedSink->isOpen();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the CastSink is ready to accept data.
 | 
				
			||||||
 | 
					         *  Blocks until the specified time for data to be available.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sec the maximum seconds to block.
 | 
				
			||||||
 | 
					         *  @param usec micro seconds to block after the full seconds.
 | 
				
			||||||
 | 
					         *  @return true if the CastSink is ready to accept data,
 | 
				
			||||||
 | 
					         *          false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual bool
 | 
				
			||||||
 | 
					        canWrite (     unsigned int    sec,
 | 
				
			||||||
 | 
					                       unsigned int    usec )       throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return getSink()->canWrite( sec, usec);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Write data to the CastSink.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param buf the data to write.
 | 
				
			||||||
 | 
					         *  @param len number of bytes to write from buf.
 | 
				
			||||||
 | 
					         *  @return the number of bytes written (may be less than len).
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual unsigned int
 | 
				
			||||||
 | 
					        write (        const void    * buf,
 | 
				
			||||||
 | 
					                       unsigned int    len )        throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return getSink()->write( buf, len);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Flush all data that was written to the CastSink to the server.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual void
 | 
				
			||||||
 | 
					        flush ( void )                              throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return getSink()->flush();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Close the CastSink.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual void
 | 
				
			||||||
 | 
					        close ( void )                              throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return getSink()->close();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the password to the server.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the password to the server.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getPassword ( void ) const                  throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return password;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the name of the stream.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the name of the stream.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getName ( void ) const                      throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return name;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the URL associated with the stream.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the URL associated with the stream.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getUrl ( void ) const                       throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return url;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the genre of the stream.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the genre of the stream.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getGenre ( void ) const                     throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return genre;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the bitrate of the stream (e.g. mp3 bitrate).
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the bitrate of the stream (e.g. mp3 bitrate).
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        getBitRate ( void ) const                   throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return bitRate;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get wether this stream is public.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if the stream is public, false otherwise.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline bool
 | 
				
			||||||
 | 
					        getIsPublic ( void ) const                  throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return isPublic;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the duration of the BufferedSink buffer in seconds.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the the duration of the BufferedSink buffer in seconds.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        getBufferDuration ( void ) const            throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return bufferDuration;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* CAST_SINK_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.6  2001/09/09 11:27:31  darkeye
 | 
				
			||||||
 | 
					  added support for ShoutCast servers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.5  2001/08/29 21:08:30  darkeye
 | 
				
			||||||
 | 
					  made some description options in the darkice config file optional
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/12 14:54:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/10 20:14:11  darkeye
 | 
				
			||||||
 | 
					  added support for remote dump file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 17:37:24  darkeye
 | 
				
			||||||
 | 
					  removed clone() functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:48  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,194 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell Config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Config.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <iterator>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <iostream.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Config.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Max line size
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#define LINE_SIZE       256
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Get a value for a key
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					const ConfigSection *
 | 
				
			||||||
 | 
					Config :: get (  const char    * key ) const            throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !key ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no key");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TableType::const_iterator   it = table.find( key);
 | 
				
			||||||
 | 
					    if ( it == table.end() ) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return &(it->second);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Add a configuration line
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					Config :: addLine (  const char    * line )          throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !line ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no line");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::string::size_type  ix;
 | 
				
			||||||
 | 
					    std::string             str( line);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* delete everything after the first # */
 | 
				
			||||||
 | 
					    if ( (ix = str.find( '#')) != str.npos ) {
 | 
				
			||||||
 | 
					        str.erase( ix);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    /* eat up all white space from the front */
 | 
				
			||||||
 | 
					    if ( (ix = str.find_first_not_of( ' ')) != str.npos ) {
 | 
				
			||||||
 | 
					        str.erase( 0, ix);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    /* eat up all white space from the end */
 | 
				
			||||||
 | 
					    if ( (ix = str.find_last_not_of( ' ')) != str.npos ) {
 | 
				
			||||||
 | 
					        str.erase( ix + 1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !str.length() ) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( str[0] == '[' && str[str.size()-1] == ']' ) {
 | 
				
			||||||
 | 
					        // a new section starts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        std::string                             section( str, 1, str.size()-2);
 | 
				
			||||||
 | 
					        ConfigSection                           cSection;
 | 
				
			||||||
 | 
					        std::pair<const std::string, ConfigSection>
 | 
				
			||||||
 | 
					                                                element( section, cSection);
 | 
				
			||||||
 | 
					        std::pair<TableType::iterator, bool>    res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        res = table.insert( element);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        currentSection = section;
 | 
				
			||||||
 | 
					        return res.second;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        // it's a line for the current section
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        TableType::iterator     it = table.find( currentSection);
 | 
				
			||||||
 | 
					        if ( it == table.end() ) {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__, "no current section");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return it->second.addLine( line);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Add a configuration line
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					Config :: read (    istream &     is  )                 throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char            line[LINE_SIZE];
 | 
				
			||||||
 | 
					    unsigned int    num;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for ( num = 0; !is.fail() && !is.eof(); ++num ) {
 | 
				
			||||||
 | 
					        is.getline( line, LINE_SIZE);
 | 
				
			||||||
 | 
					        if ( is.eof() ) {
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        } else if ( is.fail() ) {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__, "line too long", num);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        addLine( line);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.5  2001/09/09 11:26:43  darkeye
 | 
				
			||||||
 | 
					  full line comments skipped earlier: commens allowed before the first secion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2001/09/05 20:11:15  darkeye
 | 
				
			||||||
 | 
					  removed dependency on locally stored SGI STL header files
 | 
				
			||||||
 | 
					  now compiler-supplied C++ library STL header files are used
 | 
				
			||||||
 | 
					  compiles under GNU C++ 3
 | 
				
			||||||
 | 
					  hash_map (an SGI extension to STL) replaced with map
 | 
				
			||||||
 | 
					  std:: namespace prefix added to all STL class references
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/13 18:46:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1  2000/11/08 17:29:50  darkeye
 | 
				
			||||||
 | 
					  added configuration file reader
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 14:08:27  darkeye
 | 
				
			||||||
 | 
					  changed builting to an automake / autoconf environment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:49  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,237 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell Config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Config.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef CONFIG_H
 | 
				
			||||||
 | 
					#define CONFIG_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <map>
 | 
				
			||||||
 | 
					#include <string>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <iostream.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Referable.h"
 | 
				
			||||||
 | 
					#include "ConfigSection.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  A configuration file representation. The file is of the syntax:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  <pre>
 | 
				
			||||||
 | 
					 *  [section1]
 | 
				
			||||||
 | 
					 *  # this is a whole line comment
 | 
				
			||||||
 | 
					 *  key = value
 | 
				
			||||||
 | 
					 *  an ugly key name = long value    # this end is a comment too
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  [section2]
 | 
				
			||||||
 | 
					 *  # this is a whole line comment in section 2
 | 
				
			||||||
 | 
					 *  key = value
 | 
				
			||||||
 | 
					 *  an ugly key name = long value    # this end is a comment too
 | 
				
			||||||
 | 
					 *  </pre>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  also empty lines are ignored and all white space is removed
 | 
				
			||||||
 | 
					 *  from the front and end of keys / values
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Knwon problem: you can't use '#' in any part of a key / value pair
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class Config : public virtual Referable
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Type declaration of the hash table type.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        typedef std::map<std::string, ConfigSection>    TableType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Hash table holding the configuration sections.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @see ConfigSection
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        TableType                                   table;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Hash table holding the configuration sections.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @see ConfigSection
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        std::string                                 currentSection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Config ( void )                             throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor based on an input stream.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param is configuration will be read from this input stream
 | 
				
			||||||
 | 
					         *            until end of stream is reached.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Config (    istream   & is )                throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            read( is );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~Config ( void )                            throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*  TODO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Config ( const Config   & di )            throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        inline Config &
 | 
				
			||||||
 | 
					        operator= ( const Config   * di )          throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Delete the configuration information stored in the object.
 | 
				
			||||||
 | 
					         *  Resets the object to a clean state.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual void
 | 
				
			||||||
 | 
					        reset ( void )                                  throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            table.clear();
 | 
				
			||||||
 | 
					            currentSection = "";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Read a line of confiugration information.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param line the line to read.
 | 
				
			||||||
 | 
					         *  @return true if the line was correct, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        addLine (   const char    * line )              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Read a line of confiugration information.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param line the line to read.
 | 
				
			||||||
 | 
					         *  @return true if the line was correct, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual void
 | 
				
			||||||
 | 
					        read (   istream &    is )                      throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get a ConfigSection by name.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param key the name of the ConfigSection
 | 
				
			||||||
 | 
					         *  @return the ConfigSection requested, or NULL if it doesn't exists.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual const ConfigSection *
 | 
				
			||||||
 | 
					        get (   const char    * key ) const             throw ( Exception );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* CONFIG_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.4  2001/09/05 20:11:15  darkeye
 | 
				
			||||||
 | 
					  removed dependency on locally stored SGI STL header files
 | 
				
			||||||
 | 
					  now compiler-supplied C++ library STL header files are used
 | 
				
			||||||
 | 
					  compiles under GNU C++ 3
 | 
				
			||||||
 | 
					  hash_map (an SGI extension to STL) replaced with map
 | 
				
			||||||
 | 
					  std:: namespace prefix added to all STL class references
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/13 18:46:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/09 22:07:19  darkeye
 | 
				
			||||||
 | 
					  added constructor with istream
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1  2000/11/08 17:29:50  darkeye
 | 
				
			||||||
 | 
					  added configuration file reader
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:50  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,204 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell ConfigSection
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : ConfigSection.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <iterator>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <iostream.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "ConfigSection.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Add a key / value pair
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					ConfigSection :: add (   const char    * key,
 | 
				
			||||||
 | 
					                         const char    * value )            throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !key || !value ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no key or value");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::pair<const std::string, std::string>   element( key, value);
 | 
				
			||||||
 | 
					    std::pair<TableType::iterator, bool>        res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    res = table.insert( element);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return res.second;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Get a value for a key
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					const char *
 | 
				
			||||||
 | 
					ConfigSection :: get (  const char    * key ) const         throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !key ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no key");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TableType::const_iterator   it = table.find( key);
 | 
				
			||||||
 | 
					    if ( it == table.end() ) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return it->second.c_str();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Get a value for a key, in the key does not exist, throw an exception
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					const char *
 | 
				
			||||||
 | 
					ConfigSection :: getForSure (   const char    * key,
 | 
				
			||||||
 | 
					                                const char    * message1 = 0,
 | 
				
			||||||
 | 
					                                const char    * message2 = 0,
 | 
				
			||||||
 | 
					                                int             code     = 0 ) const
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    const char      * value;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( !(value = get( key)) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, key, message1, message2, code);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Add a configuration line
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					ConfigSection :: addLine (  const char    * line )          throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !line ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no line");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::string::size_type  ix;
 | 
				
			||||||
 | 
					    std::string             str( line);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* delete everything after the first # */
 | 
				
			||||||
 | 
					    if ( (ix = str.find( '#')) != str.npos ) {
 | 
				
			||||||
 | 
					        str.erase( ix);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    /* eat up all white space from the front */
 | 
				
			||||||
 | 
					    if ( (ix = str.find_first_not_of( ' ')) != str.npos ) {
 | 
				
			||||||
 | 
					        str.erase( 0, ix);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    /* eat up all white space from the end */
 | 
				
			||||||
 | 
					    if ( (ix = str.find_last_not_of( ' ')) != str.npos ) {
 | 
				
			||||||
 | 
					        str.erase( ix + 1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( !str.length() ) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* find the '=' delimiter between key and value */
 | 
				
			||||||
 | 
					    if ( (ix = str.find( '=')) == str.npos ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::string     key( str, 0, ix);
 | 
				
			||||||
 | 
					    std::string     value( str, ix + 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* eat up all white space from the front of value */
 | 
				
			||||||
 | 
					    if ( (ix = value.find_first_not_of( ' ')) != value.npos ) {
 | 
				
			||||||
 | 
					        value.erase( 0, ix);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    /* eat up all white space from the end of key */
 | 
				
			||||||
 | 
					    if ( (ix = key.find_last_not_of( ' ')) != key.npos ) {
 | 
				
			||||||
 | 
					        key.erase( ix + 1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* now add the new key / value pair */
 | 
				
			||||||
 | 
					    return add( key.c_str(), value.c_str());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.6  2001/09/09 11:26:43  darkeye
 | 
				
			||||||
 | 
					  full line comments skipped earlier: commens allowed before the first secion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.5  2001/09/05 20:11:15  darkeye
 | 
				
			||||||
 | 
					  removed dependency on locally stored SGI STL header files
 | 
				
			||||||
 | 
					  now compiler-supplied C++ library STL header files are used
 | 
				
			||||||
 | 
					  compiles under GNU C++ 3
 | 
				
			||||||
 | 
					  hash_map (an SGI extension to STL) replaced with map
 | 
				
			||||||
 | 
					  std:: namespace prefix added to all STL class references
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/13 18:46:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/09 22:08:17  darkeye
 | 
				
			||||||
 | 
					  added function getForSure
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1  2000/11/08 17:29:50  darkeye
 | 
				
			||||||
 | 
					  added configuration file reader
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 14:08:27  darkeye
 | 
				
			||||||
 | 
					  changed builting to an automake / autoconf environment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:49  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,212 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell ConfigSection
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : ConfigSection.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef CONFIG_SECTION_H
 | 
				
			||||||
 | 
					#define CONFIG_SECTION_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <map>
 | 
				
			||||||
 | 
					#include <string>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Referable.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  A configuration file representation. The file is of the syntax:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  <pre>
 | 
				
			||||||
 | 
					 *  # this is a whole line comment
 | 
				
			||||||
 | 
					 *  key = value
 | 
				
			||||||
 | 
					 *  an ugly key name = long value    # this end is a comment too
 | 
				
			||||||
 | 
					 *  </pre>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  also empty lines are ignored and all white space is removed
 | 
				
			||||||
 | 
					 *  from the front and end of keys / values
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Knwon problem: you can't use '#' in any part of a key / value pair
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class ConfigSection : public virtual Referable
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Type of the hash table used in this class.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        typedef std::map<std::string, std::string>      TableType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Hash table holding the configuration information.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        TableType                               table;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        ConfigSection ( void )                            throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~ConfigSection ( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* TODO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        ConfigSection ( const ConfigSection   & di )            throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        inline ConfigSection &
 | 
				
			||||||
 | 
					        operator= ( const ConfigSection   * di )          throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Add a key / value pair to the configuration information.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param key the key to add the value by
 | 
				
			||||||
 | 
					         *  @param value the value to add for the key
 | 
				
			||||||
 | 
					         *  @return true if adding was successful, false otherwise
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        add (   const char    * key,
 | 
				
			||||||
 | 
					                const char    * value )                 throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get a value for a key.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param key the key to get the value for
 | 
				
			||||||
 | 
					         *  @return the value for the key, or NULL if the key doesn't exist.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual const char *
 | 
				
			||||||
 | 
					        get (   const char    * key ) const             throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get a value for a key, or throw an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param key the key to get the value for
 | 
				
			||||||
 | 
					         *  @param message1 message part 1 of the Exception to be thrown.
 | 
				
			||||||
 | 
					         *  @param message2 message part 2 of the Exception to be thrown.
 | 
				
			||||||
 | 
					         *  @param code error code of the Exception to be thrown.
 | 
				
			||||||
 | 
					         *  @return the value for the key. The return value is never NULL.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual const char *
 | 
				
			||||||
 | 
					        getForSure (    const char    * key,
 | 
				
			||||||
 | 
					                        const char    * message1 = 0,
 | 
				
			||||||
 | 
					                        const char    * message2 = 0,
 | 
				
			||||||
 | 
					                        int             code     = 0 ) const
 | 
				
			||||||
 | 
					                                                        throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Add a line of configuration information.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param line the line to add.
 | 
				
			||||||
 | 
					         *  @return true if a new key was added, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        addLine (   const char    * line )              throw ( Exception );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* CONFIG_SECTION_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.4  2001/09/05 20:11:15  darkeye
 | 
				
			||||||
 | 
					  removed dependency on locally stored SGI STL header files
 | 
				
			||||||
 | 
					  now compiler-supplied C++ library STL header files are used
 | 
				
			||||||
 | 
					  compiles under GNU C++ 3
 | 
				
			||||||
 | 
					  hash_map (an SGI extension to STL) replaced with map
 | 
				
			||||||
 | 
					  std:: namespace prefix added to all STL class references
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/13 18:46:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/09 22:08:17  darkeye
 | 
				
			||||||
 | 
					  added function getForSure
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1  2000/11/08 17:29:50  darkeye
 | 
				
			||||||
 | 
					  added configuration file reader
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:50  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,359 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Connector.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					#include "Connector.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					Connector :: init ( Source          * source )        throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    this->source   = source;
 | 
				
			||||||
 | 
					    this->sinks    = 0;
 | 
				
			||||||
 | 
					    this->numSinks = 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  De-initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					Connector :: strip ( void )                             throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    source = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( sinks ) {
 | 
				
			||||||
 | 
					        unsigned int    u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for ( u = 0; u < numSinks; ++u ) {
 | 
				
			||||||
 | 
					            sinks[u] = 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        delete[] sinks;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Constructor
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					Connector :: Connector (    const Connector &   connector ) throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unsigned int    u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    init( connector.source.get());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for ( u = 0; u < connector.numSinks; ++u ) {
 | 
				
			||||||
 | 
					        attach( connector.sinks[u].get() );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Assignment operator
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					Connector &
 | 
				
			||||||
 | 
					Connector :: operator= (    const Connector &   connector ) throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( this != &connector ) {
 | 
				
			||||||
 | 
					        unsigned int    u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* first free everything */
 | 
				
			||||||
 | 
					        strip();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* then fill in */
 | 
				
			||||||
 | 
					        init( connector.source.get() );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for ( u = 0; u < connector.numSinks; ++u ) {
 | 
				
			||||||
 | 
					            attach( connector.sinks[u].get() );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return *this;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Attach a sink to the connector
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					Connector :: attach (   Sink              * sink )          throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !sinks ) {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        numSinks = 1;
 | 
				
			||||||
 | 
					        sinks    = new Ref<Sink>[1];
 | 
				
			||||||
 | 
					        sinks[0] = sink;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        unsigned int    u;
 | 
				
			||||||
 | 
					        Ref<Sink>     * s = new Ref<Sink>[numSinks + 1];
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        for ( u = 0; u < numSinks; ++u ) {
 | 
				
			||||||
 | 
					            s[u] = sinks[u].get();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        s[numSinks] = sink;
 | 
				
			||||||
 | 
					        delete[] sinks;
 | 
				
			||||||
 | 
					        sinks = s;
 | 
				
			||||||
 | 
					        ++numSinks;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Detach a sink to the connector
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					Connector :: detach (   Sink              * sink )          throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( numSinks == 0 ) {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    } else if ( numSinks == 1 ) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        sinks[0] = 0;
 | 
				
			||||||
 | 
					        delete[] sinks;
 | 
				
			||||||
 | 
					        sinks    = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					        unsigned int    u;
 | 
				
			||||||
 | 
					        unsigned int    v;
 | 
				
			||||||
 | 
					        unsigned int    ix;
 | 
				
			||||||
 | 
					        Ref<Sink>     * s;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ix = numSinks;
 | 
				
			||||||
 | 
					        for ( u = 0; u < numSinks; ++u ) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if ( sinks[u].get() == sink ) {
 | 
				
			||||||
 | 
					                ix = u;
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( ix == numSinks ) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        s = new Ref<Sink>[numSinks - 1];
 | 
				
			||||||
 | 
					        for ( u = 0, v = 0; u < numSinks; ++u ) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if ( u != ix ) {
 | 
				
			||||||
 | 
					                s[v++] = sinks[u];
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        sinks[ix] = 0;
 | 
				
			||||||
 | 
					        delete[] sinks;
 | 
				
			||||||
 | 
					        sinks = s;
 | 
				
			||||||
 | 
					        --numSinks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Open the source and all the sinks if needed
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					Connector :: open ( void )                          throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unsigned int        u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !source->isOpen() ) {
 | 
				
			||||||
 | 
					        if ( !source->open() ) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for ( u = 0; u < numSinks; ++u ) {
 | 
				
			||||||
 | 
					        if ( !sinks[u]->isOpen() ) {
 | 
				
			||||||
 | 
					            if ( !sinks[u]->open() ) {
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* if not all could be opened, close those that were */
 | 
				
			||||||
 | 
					    if ( u < numSinks ) {
 | 
				
			||||||
 | 
					        unsigned int        v;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for ( v = 0; v < u; ++v ) {
 | 
				
			||||||
 | 
					            sinks[v]->close();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        source->close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Transfer some data from the source to the sink
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					unsigned int
 | 
				
			||||||
 | 
					Connector :: transfer ( unsigned long       bytes,
 | 
				
			||||||
 | 
					                        unsigned int        bufSize,
 | 
				
			||||||
 | 
					                        unsigned int        sec,
 | 
				
			||||||
 | 
					                        unsigned int        usec )      throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unsigned int    u;
 | 
				
			||||||
 | 
					    unsigned long   b;
 | 
				
			||||||
 | 
					    unsigned char   buf[bufSize];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( numSinks == 0 ) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( bufSize == 0 ) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    reportEvent( 6, "Connector :: tranfer, bytes", bytes);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    for ( b = 0; !bytes || b < bytes; ) {
 | 
				
			||||||
 | 
					        unsigned int    d = 0;
 | 
				
			||||||
 | 
					        unsigned int    e = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( source->canRead( sec, usec) ) {
 | 
				
			||||||
 | 
					            d = source->read( buf, bufSize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /* check for EOF */
 | 
				
			||||||
 | 
					            if ( d == 0 ) {
 | 
				
			||||||
 | 
					                reportEvent( 3, "Connector :: transfer, EOF");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for ( u = 0; u < numSinks; ++u ) {
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                if ( sinks[u]->canWrite( sec, usec) ) {
 | 
				
			||||||
 | 
					                    e = sinks[u]->write( buf, d);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    sinks[u]->close();
 | 
				
			||||||
 | 
					                    detach( sinks[u].get() );
 | 
				
			||||||
 | 
					                    /* with the call to detach, numSinks gets 1 lower,
 | 
				
			||||||
 | 
					                     * and the next sink comes to sinks[u] */
 | 
				
			||||||
 | 
					                    --u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    reportEvent( 5,
 | 
				
			||||||
 | 
					                         "Connector :: transfer, sink removed, remaining", u);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if ( numSinks == 0 ) {
 | 
				
			||||||
 | 
					                        reportEvent( 4, "Connector :: transfer, no more sinks");
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            b += d;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            reportEvent( 3, "Connector :: transfer, can't read");
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return b;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Close the source and all the sinks if needed
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					Connector :: close ( void )                         throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unsigned int        u;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    source->close();
 | 
				
			||||||
 | 
					    for ( u = 0; u < numSinks; ++u ) {
 | 
				
			||||||
 | 
					        sinks[u]->close();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.6  2001/08/26 20:44:30  darkeye
 | 
				
			||||||
 | 
					  removed external command-line encoder support
 | 
				
			||||||
 | 
					  replaced it with a shared-object support for lame with the possibility
 | 
				
			||||||
 | 
					  of static linkage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.5  2001/08/26 08:43:13  darkeye
 | 
				
			||||||
 | 
					  added support for unlimited time encoding
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/15 18:37:37  darkeye
 | 
				
			||||||
 | 
					  changed the transferable number of bytes to unsigned long
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/15 18:08:43  darkeye
 | 
				
			||||||
 | 
					  added multiple verbosity-level event reporting and verbosity command
 | 
				
			||||||
 | 
					  line option
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/13 18:46:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:49  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,282 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Connector.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef CONNECTOR_H
 | 
				
			||||||
 | 
					#define CONNECTOR_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Referable.h"
 | 
				
			||||||
 | 
					#include "Ref.h"
 | 
				
			||||||
 | 
					#include "Reporter.h"
 | 
				
			||||||
 | 
					#include "Source.h"
 | 
				
			||||||
 | 
					#include "Sink.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  Connects a source to one or more sinks.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class Connector : public virtual Referable, public virtual Reporter
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The source to read from.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        Ref<Source>     source;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The sinks to connect the source to.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        Ref<Sink>     * sinks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Total number of sinks.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int    numSinks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Initialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param source the source to read from.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        init (  Source            * source )        throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  De-initialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        strip ( void )                              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Connector ( void )                          throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor based on a Source.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param source the source to connect to the sinks.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Connector (     Source        * source )    throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( source);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor based on a Source and a Sink.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param source the source to connect to the sinks.
 | 
				
			||||||
 | 
					         *  @param sink a sink to connect to the source.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Connector ( Source            * source,
 | 
				
			||||||
 | 
					                    Sink              * sink )        throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( source);
 | 
				
			||||||
 | 
					            attach( sink);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param connector the object to copy.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        Connector ( const Connector &   connector )     throw ( Exception );
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~Connector( void )                              throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            strip();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param connector the object to assign to this one.
 | 
				
			||||||
 | 
					         *  @return a reference to this object.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual Connector &
 | 
				
			||||||
 | 
					        operator= ( const Connector &   connector )     throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the number of Sinks in the Connector.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the number of Sinks in the Connector.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        getNumSinks ( void ) const              throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return numSinks;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Attach a Sink to the Source of this Connector.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sink the Sink to attach.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        attach (    Sink          * sink )              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Detach an already attached Sink from the Source of this Connector.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sink the Sink to detach.
 | 
				
			||||||
 | 
					         *  @return true if the detachment was successful, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        bool
 | 
				
			||||||
 | 
					        detach (    Sink          * sink )          throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Open the connector. Opens the Source and the Sinks if necessary.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if opening was successful, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        bool
 | 
				
			||||||
 | 
					        open ( void )                                   throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Transfer a given amount of data from the Source to all the
 | 
				
			||||||
 | 
					         *  Sinks attached.
 | 
				
			||||||
 | 
					         *  If an attached Sink closes or encounteres an error during the
 | 
				
			||||||
 | 
					         *  process, it is detached and the function carries on with the
 | 
				
			||||||
 | 
					         *  rest of the Sinks. If no Sinks remain, or an error is encountered
 | 
				
			||||||
 | 
					         *  with the Source, the function returns prematurely.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param bytes the amount of data to transfer, in bytes.
 | 
				
			||||||
 | 
					         *               If 0, transfer forever.
 | 
				
			||||||
 | 
					         *  @param bufSize the size of the buffer to use for transfering.
 | 
				
			||||||
 | 
					         *                 This amount of data is read from the Source and
 | 
				
			||||||
 | 
					         *                 written to each Sink on each turn.
 | 
				
			||||||
 | 
					         *  @param sec the number of seconds to wait for the Source to have
 | 
				
			||||||
 | 
					         *             data available in each turn, and the number of seconds
 | 
				
			||||||
 | 
					         *             to wait for the Sinks to accept data.
 | 
				
			||||||
 | 
					         *  @param usec the number of micros seconds to wait for the Source to
 | 
				
			||||||
 | 
					         *             have data available in each turn, and the number of
 | 
				
			||||||
 | 
					         *             micro seconds to wait for the Sinks to accept data.
 | 
				
			||||||
 | 
					         *  @return the number of bytes read from the Source.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int
 | 
				
			||||||
 | 
					        transfer (  unsigned long       bytes,
 | 
				
			||||||
 | 
					                    unsigned int        bufSize,
 | 
				
			||||||
 | 
					                    unsigned int        sec,
 | 
				
			||||||
 | 
					                    unsigned int        usec )          throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Close the Connector. The Source and all Sinks are closed.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        close ( void )                                  throw ( Exception );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* CONNECTOR_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.5  2001/08/26 20:44:30  darkeye
 | 
				
			||||||
 | 
					  removed external command-line encoder support
 | 
				
			||||||
 | 
					  replaced it with a shared-object support for lame with the possibility
 | 
				
			||||||
 | 
					  of static linkage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/15 18:37:37  darkeye
 | 
				
			||||||
 | 
					  changed the transferable number of bytes to unsigned long
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/15 18:08:43  darkeye
 | 
				
			||||||
 | 
					  added multiple verbosity-level event reporting and verbosity command
 | 
				
			||||||
 | 
					  line option
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/13 18:46:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:49  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,543 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : DarkIce.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_STDLIB_H
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need stdlib.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_UNISTD_H
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need unistd.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_SYS_TYPES_H
 | 
				
			||||||
 | 
					#include <sys/types.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need sys/types.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_SYS_WAIT_H
 | 
				
			||||||
 | 
					#include <sys/wait.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need sys/wait.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_ERRNO_H
 | 
				
			||||||
 | 
					#include <errno.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need errno.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_SCHED_H
 | 
				
			||||||
 | 
					#include <sched.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need sched.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Util.h"
 | 
				
			||||||
 | 
					#include "IceCast.h"
 | 
				
			||||||
 | 
					#include "ShoutCast.h"
 | 
				
			||||||
 | 
					#include "DarkIce.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Make sure wait-related stuff is what we expect
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef WEXITSTATUS
 | 
				
			||||||
 | 
					# define WEXITSTATUS(stat_val)      ((unsigned)(stat_val) >> 8)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifndef WIFEXITED
 | 
				
			||||||
 | 
					# define WIFEXITED(stat_val)        (((stat_val) & 255) == 0)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					DarkIce :: init ( const Config      & config )              throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unsigned int             bufferSecs;
 | 
				
			||||||
 | 
					    const ConfigSection    * cs;
 | 
				
			||||||
 | 
					    const char             * str;
 | 
				
			||||||
 | 
					    unsigned int             sampleRate;
 | 
				
			||||||
 | 
					    unsigned int             bitsPerSample;
 | 
				
			||||||
 | 
					    unsigned int             channel;
 | 
				
			||||||
 | 
					    const char             * device;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // the [general] section
 | 
				
			||||||
 | 
					    if ( !(cs = config.get( "general")) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no section [general] in config");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    str = cs->getForSure( "duration", " missing in section [general]");
 | 
				
			||||||
 | 
					    duration = Util::strToL( str);
 | 
				
			||||||
 | 
					    str = cs->getForSure( "bufferSecs", " missing in section [general]");
 | 
				
			||||||
 | 
					    bufferSecs = Util::strToL( str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // the [input] section
 | 
				
			||||||
 | 
					    if ( !(cs = config.get( "input")) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no section [general] in config");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    str = cs->getForSure( "sampleRate", " missing in section [input]");
 | 
				
			||||||
 | 
					    sampleRate = Util::strToL( str);
 | 
				
			||||||
 | 
					    str = cs->getForSure( "bitsPerSample", " missing in section [input]");
 | 
				
			||||||
 | 
					    bitsPerSample = Util::strToL( str);
 | 
				
			||||||
 | 
					    str = cs->getForSure( "channel", " missing in section [input]");
 | 
				
			||||||
 | 
					    channel = Util::strToL( str);
 | 
				
			||||||
 | 
					    device = cs->getForSure( "device", " missing in section [input]");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dsp             = new OssDspSource( device,
 | 
				
			||||||
 | 
					                                        sampleRate,
 | 
				
			||||||
 | 
					                                        bitsPerSample,
 | 
				
			||||||
 | 
					                                        channel );
 | 
				
			||||||
 | 
					    encConnector    = new Connector( dsp.get());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    configIceCast( config, bufferSecs);
 | 
				
			||||||
 | 
					    configShoutCast( config, bufferSecs);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Look for the IceCast stream outputs in the config file
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					DarkIce :: configIceCast (  const Config      & config,
 | 
				
			||||||
 | 
					                            unsigned int        bufferSecs  )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // look for IceCast encoder output streams,
 | 
				
			||||||
 | 
					    // sections [icecast-0], [icecast-1], ...
 | 
				
			||||||
 | 
					    char            stream[]        = "icecast- ";
 | 
				
			||||||
 | 
					    size_t          streamLen       = Util::strLen( stream);
 | 
				
			||||||
 | 
					    unsigned int    u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for ( u = 0; u < maxOutput; ++u ) {
 | 
				
			||||||
 | 
					        const ConfigSection    * cs;
 | 
				
			||||||
 | 
					        const char             * str;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // ugly hack to change the section name to "stream0", "stream1", etc.
 | 
				
			||||||
 | 
					        stream[streamLen-1] = '0' + u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( !(cs = config.get( stream)) ) {
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        unsigned int    bitrate         = 0;
 | 
				
			||||||
 | 
					        const char    * server          = 0;
 | 
				
			||||||
 | 
					        unsigned int    port            = 0;
 | 
				
			||||||
 | 
					        const char    * password        = 0;
 | 
				
			||||||
 | 
					        const char    * mountPoint      = 0;
 | 
				
			||||||
 | 
					        const char    * remoteDumpFile  = 0;
 | 
				
			||||||
 | 
					        const char    * name            = 0;
 | 
				
			||||||
 | 
					        const char    * description     = 0;
 | 
				
			||||||
 | 
					        const char    * url             = 0;
 | 
				
			||||||
 | 
					        const char    * genre           = 0;
 | 
				
			||||||
 | 
					        bool            isPublic        = false;
 | 
				
			||||||
 | 
					        unsigned int    lowpass         = 0;
 | 
				
			||||||
 | 
					        unsigned int    highpass        = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        str         = cs->getForSure("bitrate", " missing in section ", stream);
 | 
				
			||||||
 | 
					        bitrate     = Util::strToL( str);
 | 
				
			||||||
 | 
					        server      = cs->getForSure( "server", " missing in section ", stream);
 | 
				
			||||||
 | 
					        str         = cs->getForSure( "port", " missing in section ", stream);
 | 
				
			||||||
 | 
					        port        = Util::strToL( str);
 | 
				
			||||||
 | 
					        password    = cs->getForSure("password"," missing in section ",stream);
 | 
				
			||||||
 | 
					        mountPoint  = cs->getForSure( "mountPoint",
 | 
				
			||||||
 | 
					                                      " missing in section ",
 | 
				
			||||||
 | 
					                                      stream);
 | 
				
			||||||
 | 
					        remoteDumpFile = cs->get( "remoteDumpFile");
 | 
				
			||||||
 | 
					        name        = cs->get( "name");
 | 
				
			||||||
 | 
					        description = cs->get("description");
 | 
				
			||||||
 | 
					        url         = cs->get( "url");
 | 
				
			||||||
 | 
					        genre       = cs->get( "genre");
 | 
				
			||||||
 | 
					        str         = cs->get( "public");
 | 
				
			||||||
 | 
					        isPublic    = str ? (Util::strEq( str, "yes") ? true : false) : false;
 | 
				
			||||||
 | 
					        str         = cs->get( "lowpass");
 | 
				
			||||||
 | 
					        lowpass     = str ? Util::strToL( str) : 0;
 | 
				
			||||||
 | 
					        str         = cs->get( "highpass");
 | 
				
			||||||
 | 
					        highpass    = str ? Util::strToL( str) : 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // go on and create the things
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // encoder related stuff
 | 
				
			||||||
 | 
					        unsigned int bs = bufferSecs *
 | 
				
			||||||
 | 
					                          (dsp->getBitsPerSample() / 8) *
 | 
				
			||||||
 | 
					                          dsp->getChannel() *
 | 
				
			||||||
 | 
					                          dsp->getSampleRate();
 | 
				
			||||||
 | 
					        reportEvent( 6, "using buffer size", bs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // streaming related stuff
 | 
				
			||||||
 | 
					        lameLibOuts[u].socket = new TcpSocket( server, port);
 | 
				
			||||||
 | 
					        lameLibOuts[u].server = new IceCast( lameLibOuts[u].socket.get(),
 | 
				
			||||||
 | 
					                                             password,
 | 
				
			||||||
 | 
					                                             mountPoint,
 | 
				
			||||||
 | 
					                                             bitrate,
 | 
				
			||||||
 | 
					                                             name,
 | 
				
			||||||
 | 
					                                             description,
 | 
				
			||||||
 | 
					                                             url,
 | 
				
			||||||
 | 
					                                             genre,
 | 
				
			||||||
 | 
					                                             isPublic,
 | 
				
			||||||
 | 
					                                             remoteDumpFile );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        lameLibOuts[u].encoder = new LameLibEncoder(lameLibOuts[u].server.get(),
 | 
				
			||||||
 | 
					                                                    dsp.get(),
 | 
				
			||||||
 | 
					                                                    bitrate,
 | 
				
			||||||
 | 
					                                                    dsp->getSampleRate(),
 | 
				
			||||||
 | 
					                                                    dsp->getChannel(),
 | 
				
			||||||
 | 
					                                                    lowpass,
 | 
				
			||||||
 | 
					                                                    highpass );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        encConnector->attach( lameLibOuts[u].encoder.get());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    noLameLibOuts = u;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Look for the ShoutCast stream outputs in the config file
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					DarkIce :: configShoutCast (    const Config      & config,
 | 
				
			||||||
 | 
					                                unsigned int        bufferSecs  )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // look for IceCast encoder output streams,
 | 
				
			||||||
 | 
					    // sections [shoutcast-0], [shoutcast-1], ...
 | 
				
			||||||
 | 
					    char            stream[]        = "shoutcast- ";
 | 
				
			||||||
 | 
					    size_t          streamLen       = Util::strLen( stream);
 | 
				
			||||||
 | 
					    unsigned int    u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for ( u = 0; u < maxOutput; ++u ) {
 | 
				
			||||||
 | 
					        const ConfigSection    * cs;
 | 
				
			||||||
 | 
					        const char             * str;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // ugly hack to change the section name to "stream0", "stream1", etc.
 | 
				
			||||||
 | 
					        stream[streamLen-1] = '0' + u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( !(cs = config.get( stream)) ) {
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        unsigned int    bitrate         = 0;
 | 
				
			||||||
 | 
					        const char    * server          = 0;
 | 
				
			||||||
 | 
					        unsigned int    port            = 0;
 | 
				
			||||||
 | 
					        const char    * password        = 0;
 | 
				
			||||||
 | 
					        const char    * name            = 0;
 | 
				
			||||||
 | 
					        const char    * url             = 0;
 | 
				
			||||||
 | 
					        const char    * genre           = 0;
 | 
				
			||||||
 | 
					        bool            isPublic        = false;
 | 
				
			||||||
 | 
					        unsigned int    lowpass         = 0;
 | 
				
			||||||
 | 
					        unsigned int    highpass        = 0;
 | 
				
			||||||
 | 
					        const char    * irc             = 0;
 | 
				
			||||||
 | 
					        const char    * aim             = 0;
 | 
				
			||||||
 | 
					        const char    * icq             = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        str         = cs->getForSure("bitrate", " missing in section ", stream);
 | 
				
			||||||
 | 
					        bitrate     = Util::strToL( str);
 | 
				
			||||||
 | 
					        server      = cs->getForSure( "server", " missing in section ", stream);
 | 
				
			||||||
 | 
					        str         = cs->getForSure( "port", " missing in section ", stream);
 | 
				
			||||||
 | 
					        port        = Util::strToL( str);
 | 
				
			||||||
 | 
					        password    = cs->getForSure("password"," missing in section ",stream);
 | 
				
			||||||
 | 
					        name        = cs->get( "name");
 | 
				
			||||||
 | 
					        url         = cs->get( "url");
 | 
				
			||||||
 | 
					        genre       = cs->get( "genre");
 | 
				
			||||||
 | 
					        str         = cs->get( "public");
 | 
				
			||||||
 | 
					        isPublic    = str ? (Util::strEq( str, "yes") ? true : false) : false;
 | 
				
			||||||
 | 
					        str         = cs->get( "lowpass");
 | 
				
			||||||
 | 
					        lowpass     = str ? Util::strToL( str) : 0;
 | 
				
			||||||
 | 
					        str         = cs->get( "highpass");
 | 
				
			||||||
 | 
					        highpass    = str ? Util::strToL( str) : 0;
 | 
				
			||||||
 | 
					        irc         = cs->get( "irc");
 | 
				
			||||||
 | 
					        aim         = cs->get( "aim");
 | 
				
			||||||
 | 
					        icq         = cs->get( "icq");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // go on and create the things
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // encoder related stuff
 | 
				
			||||||
 | 
					        unsigned int bs = bufferSecs *
 | 
				
			||||||
 | 
					                          (dsp->getBitsPerSample() / 8) *
 | 
				
			||||||
 | 
					                          dsp->getChannel() *
 | 
				
			||||||
 | 
					                          dsp->getSampleRate();
 | 
				
			||||||
 | 
					        reportEvent( 6, "using buffer size", bs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // streaming related stuff
 | 
				
			||||||
 | 
					        lameLibOuts[u].socket = new TcpSocket( server, port);
 | 
				
			||||||
 | 
					        lameLibOuts[u].server = new ShoutCast( lameLibOuts[u].socket.get(),
 | 
				
			||||||
 | 
					                                               password,
 | 
				
			||||||
 | 
					                                               bitrate,
 | 
				
			||||||
 | 
					                                               name,
 | 
				
			||||||
 | 
					                                               url,
 | 
				
			||||||
 | 
					                                               genre,
 | 
				
			||||||
 | 
					                                               isPublic,
 | 
				
			||||||
 | 
					                                               irc,
 | 
				
			||||||
 | 
					                                               aim,
 | 
				
			||||||
 | 
					                                               icq );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        lameLibOuts[u].encoder = new LameLibEncoder(lameLibOuts[u].server.get(),
 | 
				
			||||||
 | 
					                                                    dsp.get(),
 | 
				
			||||||
 | 
					                                                    bitrate,
 | 
				
			||||||
 | 
					                                                    dsp->getSampleRate(),
 | 
				
			||||||
 | 
					                                                    dsp->getChannel(),
 | 
				
			||||||
 | 
					                                                    lowpass,
 | 
				
			||||||
 | 
					                                                    highpass );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        encConnector->attach( lameLibOuts[u].encoder.get());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    noLameLibOuts = u;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Set POSIX real-time scheduling, if super-user
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					DarkIce :: setRealTimeScheduling ( void )               throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    uid_t   euid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    euid = geteuid();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( euid == 0 ) {
 | 
				
			||||||
 | 
					        int                 high_priority;
 | 
				
			||||||
 | 
					        struct sched_param  param;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* store the old scheduling parameters */
 | 
				
			||||||
 | 
					        if ( (origSchedPolicy = sched_getscheduler(0)) == -1 ) {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__, "sched_getscheduler", errno);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( sched_getparam( 0, ¶m) == -1 ) {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        origSchedPriority = param.sched_priority;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        /* set SCHED_FIFO with max - 1 priority */
 | 
				
			||||||
 | 
					        if ( (high_priority = sched_get_priority_max(SCHED_FIFO)) == -1 ) {
 | 
				
			||||||
 | 
					            throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        reportEvent( 8, "scheduler high priority", high_priority);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        param.sched_priority = high_priority - 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( sched_setscheduler( 0, SCHED_FIFO, ¶m) == -1 ) {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__, "sched_setscheduler", errno);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* ask the new priortiy and report it */
 | 
				
			||||||
 | 
					        if ( sched_getparam( 0, ¶m) == -1 ) {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        reportEvent( 1,
 | 
				
			||||||
 | 
					                     "Using POSIX real-time scheduling, priority",
 | 
				
			||||||
 | 
					                     param.sched_priority );
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        reportEvent( 1,
 | 
				
			||||||
 | 
					        "Not running as super-user, unable to use POSIX real-time scheduling" );
 | 
				
			||||||
 | 
					        reportEvent( 1,
 | 
				
			||||||
 | 
					        "It is recommended that you run this program as super-user");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Set the original scheduling of the process, the one prior to the
 | 
				
			||||||
 | 
					 *  setRealTimeScheduling call.
 | 
				
			||||||
 | 
					 *  WARNING: make sure you don't call this before setRealTimeScheduling!!
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					DarkIce :: setOriginalScheduling ( void )               throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    uid_t   euid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    euid = geteuid();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( euid == 0 ) {
 | 
				
			||||||
 | 
					        struct sched_param  param;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( sched_getparam( 0, ¶m) == -1 ) {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        param.sched_priority = origSchedPriority;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( sched_setscheduler( 0, origSchedPolicy, ¶m) == -1 ) {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__, "sched_setscheduler", errno);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        reportEvent( 5, "reverted to original scheduling");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Run the encoder
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					DarkIce :: encode ( void )                          throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unsigned int       len;
 | 
				
			||||||
 | 
					    unsigned long      bytes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !encConnector->open() ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "can't open connector");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    bytes = dsp->getSampleRate() *
 | 
				
			||||||
 | 
					            (dsp->getBitsPerSample() / 8UL) *
 | 
				
			||||||
 | 
					            dsp->getChannel() *
 | 
				
			||||||
 | 
					            duration;
 | 
				
			||||||
 | 
					                                                
 | 
				
			||||||
 | 
					    len = encConnector->transfer( bytes, 4096, 1, 0 );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    reportEvent( 1, len, "bytes transfered to the encoders");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    encConnector->close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Run
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					int
 | 
				
			||||||
 | 
					DarkIce :: run ( void )                             throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    reportEvent( 3, "encoding");
 | 
				
			||||||
 | 
					    setRealTimeScheduling();
 | 
				
			||||||
 | 
					    encode();
 | 
				
			||||||
 | 
					    setOriginalScheduling();
 | 
				
			||||||
 | 
					    reportEvent( 3, "encoding ends");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.17  2001/09/09 11:27:31  darkeye
 | 
				
			||||||
 | 
					  added support for ShoutCast servers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.16  2001/09/05 20:11:15  darkeye
 | 
				
			||||||
 | 
					  removed dependency on locally stored SGI STL header files
 | 
				
			||||||
 | 
					  now compiler-supplied C++ library STL header files are used
 | 
				
			||||||
 | 
					  compiles under GNU C++ 3
 | 
				
			||||||
 | 
					  hash_map (an SGI extension to STL) replaced with map
 | 
				
			||||||
 | 
					  std:: namespace prefix added to all STL class references
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.15  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.14  2001/08/29 21:08:30  darkeye
 | 
				
			||||||
 | 
					  made some description options in the darkice config file optional
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.13  2001/08/26 20:44:30  darkeye
 | 
				
			||||||
 | 
					  removed external command-line encoder support
 | 
				
			||||||
 | 
					  replaced it with a shared-object support for lame with the possibility
 | 
				
			||||||
 | 
					  of static linkage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.12  2000/12/20 12:36:47  darkeye
 | 
				
			||||||
 | 
					  added POSIX real-time scheduling
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.11  2000/11/18 11:13:27  darkeye
 | 
				
			||||||
 | 
					  removed direct reference to cout, except from main.cpp
 | 
				
			||||||
 | 
					  all class use the Reporter interface to report events
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.10  2000/11/17 15:50:48  darkeye
 | 
				
			||||||
 | 
					  added -Wall flag to compiler and eleminated new warnings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.9  2000/11/15 18:37:37  darkeye
 | 
				
			||||||
 | 
					  changed the transferable number of bytes to unsigned long
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.8  2000/11/15 18:08:43  darkeye
 | 
				
			||||||
 | 
					  added multiple verbosity-level event reporting and verbosity command
 | 
				
			||||||
 | 
					  line option
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.7  2000/11/13 19:38:55  darkeye
 | 
				
			||||||
 | 
					  moved command line parameter parsing from DarkIce.cpp to main.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.6  2000/11/13 18:46:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.5  2000/11/10 20:16:21  darkeye
 | 
				
			||||||
 | 
					  first real tests with multiple streaming
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/09 22:09:46  darkeye
 | 
				
			||||||
 | 
					  added multiple outputs
 | 
				
			||||||
 | 
					  added configuration reading
 | 
				
			||||||
 | 
					  added command line processing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/08 17:29:50  darkeye
 | 
				
			||||||
 | 
					  added configuration file reader
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 14:08:27  darkeye
 | 
				
			||||||
 | 
					  changed builting to an automake / autoconf environment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:49  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,321 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : DarkIce.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef DARK_ICE_H
 | 
				
			||||||
 | 
					#define DARK_ICE_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_UNISTD_H
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need unistd.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <iostream.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Referable.h"
 | 
				
			||||||
 | 
					#include "Reporter.h"
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					#include "Ref.h"
 | 
				
			||||||
 | 
					#include "OssDspSource.h"
 | 
				
			||||||
 | 
					#include "BufferedSink.h"
 | 
				
			||||||
 | 
					#include "Connector.h"
 | 
				
			||||||
 | 
					#include "LameLibEncoder.h"
 | 
				
			||||||
 | 
					#include "TcpSocket.h"
 | 
				
			||||||
 | 
					#include "CastSink.h"
 | 
				
			||||||
 | 
					#include "Config.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  Program main object.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class DarkIce : public virtual Referable, public virtual Reporter
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The maximum number of supported outputs.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        static const unsigned int       maxOutput = 8;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Type describing each lame library output.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        typedef struct {
 | 
				
			||||||
 | 
					            Ref<LameLibEncoder>     encoder;
 | 
				
			||||||
 | 
					            Ref<TcpSocket>          socket;
 | 
				
			||||||
 | 
					            Ref<CastSink>           server;
 | 
				
			||||||
 | 
					        } LameLibOutput;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The lame library outputs.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        LameLibOutput           lameLibOuts[maxOutput];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Number of lame library outputs.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int            noLameLibOuts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Duration of playing, in seconds.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int            duration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The dsp to record from.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        Ref<OssDspSource>       dsp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The encoding Connector, connecting the dsp to the encoders.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        Ref<Connector>          encConnector;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Original scheduling policy
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        int                     origSchedPolicy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Original scheduling priority
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        int                     origSchedPriority;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Initialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param config the config Object to read initialization
 | 
				
			||||||
 | 
					         *                information from.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        init (  const Config   & config )            throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Look for the icecast stream outputs from the config file.
 | 
				
			||||||
 | 
					         *  Called from init()
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param config the config Object to read initialization
 | 
				
			||||||
 | 
					         *                information from.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        configIceCast (  const Config   & config,
 | 
				
			||||||
 | 
					                         unsigned int     bufferSecs  )     throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Look for the shoutcast stream outputs from the config file.
 | 
				
			||||||
 | 
					         *  Called from init()
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param config the config Object to read initialization
 | 
				
			||||||
 | 
					         *                information from.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        configShoutCast (   const Config   & config,
 | 
				
			||||||
 | 
					                            unsigned int     bufferSecs )   throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Set POSIX real-time scheduling for the encoding process,
 | 
				
			||||||
 | 
					         *  if user permissions enable it.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        setRealTimeScheduling ( void )              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Set the scheduling that was before setting real-time scheduling.
 | 
				
			||||||
 | 
					         *  This function must be called _only_ after setRealTimeScheduling.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        setOriginalScheduling ( void )              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Start encoding. Spawns all encoders, opens the dsp and
 | 
				
			||||||
 | 
					         *  starts sending data to the encoders.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return if encoding was successful.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        bool
 | 
				
			||||||
 | 
					        encode ( void )                             throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Start shouting. fork()-s a process for each output, reads
 | 
				
			||||||
 | 
					         *  the output of the encoders and sends them to an IceCast server.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return if shouting was successful.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        bool
 | 
				
			||||||
 | 
					        shout ( unsigned int )                      throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        DarkIce ( void )                            throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor based on a configuration object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param config the config Object to read initialization
 | 
				
			||||||
 | 
					         *                information from.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        DarkIce (   const Config  & config )       throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( config);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~DarkIce ( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* TODO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        DarkIce ( const DarkIce   & di )            throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        inline DarkIce &
 | 
				
			||||||
 | 
					        operator= ( const DarkIce   * di )          throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Run the process of recording / encoding / sending to the servers.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return 0 on success
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual int
 | 
				
			||||||
 | 
					        run ( void )                                throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* DARK_ICE_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.10  2001/09/09 11:27:31  darkeye
 | 
				
			||||||
 | 
					  added support for ShoutCast servers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.9  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.8  2001/08/26 20:44:30  darkeye
 | 
				
			||||||
 | 
					  removed external command-line encoder support
 | 
				
			||||||
 | 
					  replaced it with a shared-object support for lame with the possibility
 | 
				
			||||||
 | 
					  of static linkage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.7  2000/12/20 12:36:47  darkeye
 | 
				
			||||||
 | 
					  added POSIX real-time scheduling
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.6  2000/11/15 18:08:43  darkeye
 | 
				
			||||||
 | 
					  added multiple verbosity-level event reporting and verbosity command
 | 
				
			||||||
 | 
					  line option
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.5  2000/11/13 19:38:55  darkeye
 | 
				
			||||||
 | 
					  moved command line parameter parsing from DarkIce.cpp to main.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/13 18:46:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/10 20:16:21  darkeye
 | 
				
			||||||
 | 
					  first real tests with multiple streaming
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/09 22:09:46  darkeye
 | 
				
			||||||
 | 
					  added multiple outputs
 | 
				
			||||||
 | 
					  added configuration reading
 | 
				
			||||||
 | 
					  added command line processing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:50  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,223 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Exception.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_STRING_H
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need string.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Constructor
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					Exception :: Exception (    const char            * file,
 | 
				
			||||||
 | 
					                            unsigned int            line,
 | 
				
			||||||
 | 
					                            const char            * description1,
 | 
				
			||||||
 | 
					                            const char            * description2,
 | 
				
			||||||
 | 
					                            int                     code = 0 )      throw ()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    size_t      len = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( description1 ) {
 | 
				
			||||||
 | 
					        len += strlen( description1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( description2 ) {
 | 
				
			||||||
 | 
					        len += strlen( description2);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( len ) {
 | 
				
			||||||
 | 
					        char        str[len+1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        str[0] = '\0';
 | 
				
			||||||
 | 
					        if ( description1 ) {
 | 
				
			||||||
 | 
					            strcat( str, description1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if ( description2 ) {
 | 
				
			||||||
 | 
					            strcat( str, description2);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        init( file, line, str, code);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        init( file, line, 0, code);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Constructor
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					Exception :: Exception (    const char            * file,
 | 
				
			||||||
 | 
					                            unsigned int            line,
 | 
				
			||||||
 | 
					                            const char            * description1,
 | 
				
			||||||
 | 
					                            const char            * description2,
 | 
				
			||||||
 | 
					                            const char            * description3,
 | 
				
			||||||
 | 
					                            int                     code = 0 )      throw ()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    size_t      len = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( description1 ) {
 | 
				
			||||||
 | 
					        len += strlen( description1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( description2 ) {
 | 
				
			||||||
 | 
					        len += strlen( description2);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( description3 ) {
 | 
				
			||||||
 | 
					        len += strlen( description3);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( len ) {
 | 
				
			||||||
 | 
					        char        str[len+1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        str[0] = '\0';
 | 
				
			||||||
 | 
					        if ( description1 ) {
 | 
				
			||||||
 | 
					            strcat( str, description1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if ( description2 ) {
 | 
				
			||||||
 | 
					            strcat( str, description2);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if ( description3 ) {
 | 
				
			||||||
 | 
					            strcat( str, description3);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        init( file, line, str, code);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        init( file, line, 0, code);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Initialize the class
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					Exception :: init ( const char            * file,
 | 
				
			||||||
 | 
					                    unsigned int            line,
 | 
				
			||||||
 | 
					                    const char            * description  = 0,
 | 
				
			||||||
 | 
					                    int                     code         = 0 )  throw ()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !file ) {
 | 
				
			||||||
 | 
					        this->file = 0;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        size_t  len;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        len        = strlen( file ) + 1;
 | 
				
			||||||
 | 
					        this->file = new char[len];
 | 
				
			||||||
 | 
					        if ( this->file ) {
 | 
				
			||||||
 | 
					            memcpy( this->file, file, len);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !description ) {
 | 
				
			||||||
 | 
					        this->description = 0;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        size_t  len;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        len               = strlen( description ) + 1;
 | 
				
			||||||
 | 
					        this->description = new char[len];
 | 
				
			||||||
 | 
					        if ( this->description ) {
 | 
				
			||||||
 | 
					            memcpy( this->description, description, len);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this->line = line;
 | 
				
			||||||
 | 
					    this->code = code;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  De-initialize the class
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					Exception :: strip ( void )                         throw ()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( description ) {
 | 
				
			||||||
 | 
					        delete[] description;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( file ) {
 | 
				
			||||||
 | 
					        delete[] file;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.5  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/11 12:33:13  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/09 22:05:44  darkeye
 | 
				
			||||||
 | 
					  added multiple-string constructors
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 14:08:27  darkeye
 | 
				
			||||||
 | 
					  changed builting to an automake / autoconf environment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:50  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,322 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Exception.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef EXCEPTION_H
 | 
				
			||||||
 | 
					#define EXCEPTION_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <iostream.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  An exception class.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  This class should not depend on any other class
 | 
				
			||||||
 | 
					 *  should not throw any exceptions itself.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Typical usage:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  <pre>
 | 
				
			||||||
 | 
					 *  throw Exception( __FILE__, __LINE__, "describe the exception", code);
 | 
				
			||||||
 | 
					 *  </pre>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class Exception
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Source file the exception was thrown in.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char          * file;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Line number in the source file the exception was thrown in.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int    line;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Textual description of the exception.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char          * description;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Numerical error code.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        int             code;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Initalize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param file the source file the exception was thrown in.
 | 
				
			||||||
 | 
					         *  @param line the line in the source file.
 | 
				
			||||||
 | 
					         *  @param description textual description of the exception.
 | 
				
			||||||
 | 
					         *  @param code numerical error code.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        init (  const char            * file,
 | 
				
			||||||
 | 
					                unsigned int            line,
 | 
				
			||||||
 | 
					                const char            * description,
 | 
				
			||||||
 | 
					                int                     code )              throw ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  De-initalize the object.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        strip ()                                            throw ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Exception ( void )                                  throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( 0, 0, 0, 0);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy constructor.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Exception ( const Exception &   e )                 throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( e.file, e.line, e.description, e.code);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Construct by a description and error code.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param description textual description of the exception.
 | 
				
			||||||
 | 
					         *  @param code numerical error code.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Exception ( const char            * description,
 | 
				
			||||||
 | 
					                    int                     code = 0 )      throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( 0, 0, description, code);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Construct by source file information, a description and error code.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param file the source file the exception was thrown in.
 | 
				
			||||||
 | 
					         *  @param line the line in the source file.
 | 
				
			||||||
 | 
					         *  @param description textual description of the exception.
 | 
				
			||||||
 | 
					         *  @param code numerical error code.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Exception ( const char            * file,
 | 
				
			||||||
 | 
					                    unsigned int            line,
 | 
				
			||||||
 | 
					                    const char            * description  = 0,
 | 
				
			||||||
 | 
					                    int                     code = 0 )          throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( file, line, description, code);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Construct by source file information, a description and error code.
 | 
				
			||||||
 | 
					         *  The description is constructed from two strings, any of which
 | 
				
			||||||
 | 
					         *  may be NULL.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param file the source file the exception was thrown in.
 | 
				
			||||||
 | 
					         *  @param line the line in the source file.
 | 
				
			||||||
 | 
					         *  @param description1 textual description of the exception part 1.
 | 
				
			||||||
 | 
					         *  @param description2 textual description of the exception part 2.
 | 
				
			||||||
 | 
					         *  @param code numerical error code.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        Exception ( const char            * file,
 | 
				
			||||||
 | 
					                    unsigned int            line,
 | 
				
			||||||
 | 
					                    const char            * description1,
 | 
				
			||||||
 | 
					                    const char            * description2,
 | 
				
			||||||
 | 
					                    int                     code = 0 )          throw ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Construct by source file information, a description and error code.
 | 
				
			||||||
 | 
					         *  The description is constructed from three strings, any of
 | 
				
			||||||
 | 
					         *  which may be NULL.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param file the source file the exception was thrown in.
 | 
				
			||||||
 | 
					         *  @param line the line in the source file.
 | 
				
			||||||
 | 
					         *  @param description1 textual description of the exception part 1.
 | 
				
			||||||
 | 
					         *  @param description2 textual description of the exception part 2.
 | 
				
			||||||
 | 
					         *  @param description3 textual description of the exception part 3.
 | 
				
			||||||
 | 
					         *  @param code numerical error code.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        Exception ( const char            * file,
 | 
				
			||||||
 | 
					                    unsigned int            line,
 | 
				
			||||||
 | 
					                    const char            * description1,
 | 
				
			||||||
 | 
					                    const char            * description2,
 | 
				
			||||||
 | 
					                    const char            * description3,
 | 
				
			||||||
 | 
					                    int                     code = 0 )          throw ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Desctructor.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        ~Exception ( void )                                 throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            strip();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param e the Exception to assign this to.
 | 
				
			||||||
 | 
					         *  @return a reference to this Exception.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline Exception &
 | 
				
			||||||
 | 
					        operator= ( const Exception &   e )                 throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( this != &e ) {
 | 
				
			||||||
 | 
					                strip();
 | 
				
			||||||
 | 
					                init( e.file, e.line, e.description, e.code);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return *this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Return the textual description of the Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the textual description of the Exception.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getDescription( void ) const                        throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return description;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Return the line number in the source file this Exception was
 | 
				
			||||||
 | 
					         *  thrown in.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the line number in the source file this Exception was
 | 
				
			||||||
 | 
					         *          thrown in.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        getLine ( void ) const                              throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return line;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Return the source file this Exception was thrown in.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the source file this Exception was thrown in.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getFile ( void ) const                              throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return file;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Return the numerical code of the Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the numerical code of the Exception.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline int
 | 
				
			||||||
 | 
					        getCode ( void ) const                              throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return code;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  Print an Exception to an ostream.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @param os the output stream to print to.
 | 
				
			||||||
 | 
					 *  @param e the Exception to print.
 | 
				
			||||||
 | 
					 *  @return a reference to the supplied output stream.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					inline ostream &
 | 
				
			||||||
 | 
					operator<< (        ostream &           os,
 | 
				
			||||||
 | 
					                    const Exception &   e )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    os << e.getFile() << ":" << e.getLine() << ": "
 | 
				
			||||||
 | 
					       << e.getDescription() << " [" << e.getCode() << "]";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return os;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* EXCEPTION_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.5  2000/11/17 15:33:54  darkeye
 | 
				
			||||||
 | 
					  bug fix: ostream << operator overload didn't return the ostream
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/11 12:33:13  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/09 22:05:44  darkeye
 | 
				
			||||||
 | 
					  added multiple-string constructors
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 14:08:27  darkeye
 | 
				
			||||||
 | 
					  changed builting to an automake / autoconf environment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:50  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,239 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : IceCast.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_STDIO_H
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need stdio.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_STRING_H
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need string.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					#include "Source.h"
 | 
				
			||||||
 | 
					#include "Sink.h"
 | 
				
			||||||
 | 
					#include "Util.h"
 | 
				
			||||||
 | 
					#include "IceCast.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Size of string conversion buffer
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#define STRBUF_SIZE         32
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					IceCast :: init (   const char            * mountPoint,
 | 
				
			||||||
 | 
					                    const char            * description,
 | 
				
			||||||
 | 
					                    const char            * remoteDumpFile )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    this->mountPoint     = Util::strDup( mountPoint);
 | 
				
			||||||
 | 
					    this->description    = description    ? Util::strDup( description) : 0;
 | 
				
			||||||
 | 
					    this->remoteDumpFile = remoteDumpFile ? Util::strDup( remoteDumpFile) : 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  De-initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					IceCast :: strip ( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    delete[] mountPoint;
 | 
				
			||||||
 | 
					    if ( description ) {
 | 
				
			||||||
 | 
					        delete[] description;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( remoteDumpFile ) {
 | 
				
			||||||
 | 
					        delete[] remoteDumpFile;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Log in to the IceCast server
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					IceCast :: sendLogin ( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Sink          * sink   = getSink();
 | 
				
			||||||
 | 
					    Source        * source = getSocket();
 | 
				
			||||||
 | 
					    const char    * str;
 | 
				
			||||||
 | 
					    char            resp[STRBUF_SIZE];
 | 
				
			||||||
 | 
					    unsigned int    len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !source->isOpen() ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( !sink->isOpen() ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* send the request, a string like:
 | 
				
			||||||
 | 
					     * "SOURCE <password> /<mountpoint>\n" */
 | 
				
			||||||
 | 
					    str = "SOURCE ";
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    str = getPassword();
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    str = " /";
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    str = getMountPoint();
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    str = "\n";
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* send the x-audiocast headers */
 | 
				
			||||||
 | 
					    if ( getName() ) {
 | 
				
			||||||
 | 
					        str = "x-audiocast-name: ";
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					        str = getName();
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( getDescription() ) {
 | 
				
			||||||
 | 
					        str = "\nx-audiocast-description: ";
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					        str = getDescription();
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( getUrl() ) {
 | 
				
			||||||
 | 
					        str = "\nx-audiocast-url: ";
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					        str = getUrl();
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( getGenre() ) {
 | 
				
			||||||
 | 
					        str = "\nx-audiocast-genre: ";
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					        str = getGenre();
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    str = "\nx-audiocast-bitrate: ";
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    if ( snprintf( resp, STRBUF_SIZE, "%d", getBitRate()) == -1 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "snprintf overflow");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    sink->write( resp, strlen( resp));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    str = "\nx-audiocast-public: ";
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    str = getIsPublic() ? "yes" : "no";
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( getRemoteDumpFile() ) {
 | 
				
			||||||
 | 
					        str = "\nx-audiocast-dumpfile: ";
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					        str = getRemoteDumpFile();
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    str = "\n\n";
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    sink->flush();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* read the anticipated response: "OK" */
 | 
				
			||||||
 | 
					    len = source->read( resp, STRBUF_SIZE);
 | 
				
			||||||
 | 
					    if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* suck anything that the other side has to say */
 | 
				
			||||||
 | 
					    while ( source->canRead( 0, 0) && 
 | 
				
			||||||
 | 
					           (len = source->read( resp, STRBUF_SIZE)) ) {
 | 
				
			||||||
 | 
					        ;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.7  2001/09/09 11:27:31  darkeye
 | 
				
			||||||
 | 
					  added support for ShoutCast servers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.6  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.5  2001/08/29 21:08:30  darkeye
 | 
				
			||||||
 | 
					  made some description options in the darkice config file optional
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/12 14:54:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/10 20:14:11  darkeye
 | 
				
			||||||
 | 
					  added support for remote dump file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 14:08:28  darkeye
 | 
				
			||||||
 | 
					  changed builting to an automake / autoconf environment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:52  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,284 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : IceCast.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef ICE_CAST_H
 | 
				
			||||||
 | 
					#define ICE_CAST_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Sink.h"
 | 
				
			||||||
 | 
					#include "TcpSocket.h"
 | 
				
			||||||
 | 
					#include "CastSink.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  Class representing output to an IceCast server with
 | 
				
			||||||
 | 
					 *  x-audiocast login
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class IceCast : public CastSink
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Mount point of the stream on the server.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char              * mountPoint;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Remote dump file if any.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char              * remoteDumpFile;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Description of the stream.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char              * description;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Initalize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param mountPoint mount point of the stream on the server.
 | 
				
			||||||
 | 
					         *  @param remoteDumpFile remote dump file (may be NULL).
 | 
				
			||||||
 | 
					         *  @param description description of the stream.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        init (  const char            * mountPoint,
 | 
				
			||||||
 | 
					                const char            * description,
 | 
				
			||||||
 | 
					                const char            * remoteDumpFile )
 | 
				
			||||||
 | 
					                                                    throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  De-initalize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        strip ( void )                              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        IceCast ( void )                            throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Log in to the server using the socket avialable.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if login was successful, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        sendLogin ( void )              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param socket socket connection to the server.
 | 
				
			||||||
 | 
					         *  @param password password to the server.
 | 
				
			||||||
 | 
					         *  @param mountPoint mount point of the stream on the server.
 | 
				
			||||||
 | 
					         *  @param remoteDumpFile remote dump file (may be NULL).
 | 
				
			||||||
 | 
					         *  @param name name of the stream.
 | 
				
			||||||
 | 
					         *  @param description description of the stream.
 | 
				
			||||||
 | 
					         *  @param url URL associated with the stream.
 | 
				
			||||||
 | 
					         *  @param genre genre of the stream.
 | 
				
			||||||
 | 
					         *  @param bitRate bitrate of the stream (e.g. mp3 bitrate).
 | 
				
			||||||
 | 
					         *  @param isPublic is the stream public?
 | 
				
			||||||
 | 
					         *  @param bufferDuration duration of the BufferedSink buffer
 | 
				
			||||||
 | 
					         *                        in seconds.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        IceCast (   TcpSocket         * socket,
 | 
				
			||||||
 | 
					                    const char        * password,
 | 
				
			||||||
 | 
					                    const char        * mountPoint,
 | 
				
			||||||
 | 
					                    unsigned int        bitRate,
 | 
				
			||||||
 | 
					                    const char        * name           = 0,
 | 
				
			||||||
 | 
					                    const char        * description    = 0,
 | 
				
			||||||
 | 
					                    const char        * url            = 0,
 | 
				
			||||||
 | 
					                    const char        * genre          = 0,
 | 
				
			||||||
 | 
					                    bool                isPublic       = false,
 | 
				
			||||||
 | 
					                    const char        * remoteDumpFile = 0,
 | 
				
			||||||
 | 
					                    unsigned int        bufferDuration = 10 )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					              : CastSink( socket,
 | 
				
			||||||
 | 
					                          password,
 | 
				
			||||||
 | 
					                          bitRate,
 | 
				
			||||||
 | 
					                          name,
 | 
				
			||||||
 | 
					                          url,
 | 
				
			||||||
 | 
					                          genre,
 | 
				
			||||||
 | 
					                          isPublic,
 | 
				
			||||||
 | 
					                          bufferDuration )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( mountPoint, description, remoteDumpFile);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param cs the IceCast to copy.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        IceCast(   const IceCast &    cs )        throw ( Exception )
 | 
				
			||||||
 | 
					                : CastSink( cs )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( cs.getMountPoint(),
 | 
				
			||||||
 | 
					                  cs.getDescription(),
 | 
				
			||||||
 | 
					                  cs.getRemoteDumpFile() );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~IceCast( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            strip();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param cs the IceCast to assign this to.
 | 
				
			||||||
 | 
					         *  @return a reference to this IceCast.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual IceCast &
 | 
				
			||||||
 | 
					        operator= ( const IceCast &    cs )        throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( this != &cs ) {
 | 
				
			||||||
 | 
					                strip();
 | 
				
			||||||
 | 
					                CastSink::operator=( cs );
 | 
				
			||||||
 | 
					                init( cs.getMountPoint(),
 | 
				
			||||||
 | 
					                      cs.getDescription(),
 | 
				
			||||||
 | 
					                      cs.getRemoteDumpFile() );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return *this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the mount point of the stream on the server.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the mount point of the stream on the server.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getMountPoint ( void ) const                throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return mountPoint;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the remote dump file if any.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the remote dump file. May be NULL.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getRemoteDumpFile ( void ) const            throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return remoteDumpFile;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the description of the stream.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the description of the stream.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getDescription ( void ) const               throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return description;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* ICE_CAST_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.6  2001/09/09 11:27:31  darkeye
 | 
				
			||||||
 | 
					  added support for ShoutCast servers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.5  2001/08/29 21:08:30  darkeye
 | 
				
			||||||
 | 
					  made some description options in the darkice config file optional
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/12 14:54:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/10 20:14:11  darkeye
 | 
				
			||||||
 | 
					  added support for remote dump file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 17:37:24  darkeye
 | 
				
			||||||
 | 
					  removed clone() functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:52  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,413 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : LameLibEncoder.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_STRING_H
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need string.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					#include "Util.h"
 | 
				
			||||||
 | 
					#include "LameLibEncoder.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Open an encoding session
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					LameLibEncoder :: open ( void )
 | 
				
			||||||
 | 
					                                                            throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( isOpen() ) {
 | 
				
			||||||
 | 
					        close();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    lameGlobalFlags = lame_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // ugly lame returns -1 in a pointer on allocation errors
 | 
				
			||||||
 | 
					    if ( !lameGlobalFlags || ((int)lameGlobalFlags) == -1 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "lame lib init error",
 | 
				
			||||||
 | 
					                         (int) lameGlobalFlags);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( 0 > lame_set_num_channels( lameGlobalFlags, getInChannel()) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "lame lib setting channels error",
 | 
				
			||||||
 | 
					                         getInChannel() );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( 0 > lame_set_mode( lameGlobalFlags,
 | 
				
			||||||
 | 
					                            getInChannel() == 1 ? MONO : JOINT_STEREO) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "lame lib setting mode error",
 | 
				
			||||||
 | 
					                         JOINT_STEREO );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    reportEvent( 5, "set lame mode", lame_get_mode( lameGlobalFlags));
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    reportEvent( 5,
 | 
				
			||||||
 | 
					                 "set lame channels",
 | 
				
			||||||
 | 
					                 lame_get_num_channels( lameGlobalFlags));
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( 0 > lame_set_in_samplerate( lameGlobalFlags, getInSampleRate()) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "lame lib setting input sample rate error",
 | 
				
			||||||
 | 
					                         getInSampleRate() );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    reportEvent( 5,
 | 
				
			||||||
 | 
					                 "set lame in sample rate",
 | 
				
			||||||
 | 
					                 lame_get_in_samplerate( lameGlobalFlags));
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( 0 > lame_set_out_samplerate( lameGlobalFlags, getOutSampleRate()) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "lame lib setting output sample rate error",
 | 
				
			||||||
 | 
					                         getOutSampleRate() );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    reportEvent( 5,
 | 
				
			||||||
 | 
					                 "set lame out sample rate",
 | 
				
			||||||
 | 
					                 lame_get_out_samplerate( lameGlobalFlags));
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( 0 > lame_set_brate( lameGlobalFlags, getOutBitrate()) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "lame lib setting output bit rate error",
 | 
				
			||||||
 | 
					                         getOutBitrate() );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    reportEvent( 5, "set lame bit rate", lame_get_brate( lameGlobalFlags));
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( lowpass ) {
 | 
				
			||||||
 | 
					        if ( 0 > lame_set_lowpassfreq( lameGlobalFlags, lowpass) ) {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                             "lame lib setting lowpass frequency error",
 | 
				
			||||||
 | 
					                             lowpass );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        reportEvent( 5,
 | 
				
			||||||
 | 
					                     "set lame lowpass frequency",
 | 
				
			||||||
 | 
					                     lame_get_lowpassfreq( lameGlobalFlags));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( highpass ) {
 | 
				
			||||||
 | 
					        if ( 0 > lame_set_highpassfreq( lameGlobalFlags, highpass) ) {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                             "lame lib setting highpass frequency error",
 | 
				
			||||||
 | 
					                             lowpass );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        reportEvent( 5,
 | 
				
			||||||
 | 
					                     "set lame highpass frequency",
 | 
				
			||||||
 | 
					                     lame_get_highpassfreq( lameGlobalFlags));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // not configurable lame settings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( 0 > lame_set_quality( lameGlobalFlags, 2) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "lame lib setting quality error",
 | 
				
			||||||
 | 
					                         2 );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    reportEvent( 5, "set lame quality", lame_get_quality( lameGlobalFlags));
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( 0 > lame_set_exp_nspsytune( lameGlobalFlags, 1) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "lame lib setting  psycho acoustic model error");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    reportEvent( 5,
 | 
				
			||||||
 | 
					                 "set lame psycho acoustic model",
 | 
				
			||||||
 | 
					                 lame_get_exp_nspsytune( lameGlobalFlags));
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( 0 > lame_set_error_protection( lameGlobalFlags, 1) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "lame lib setting error protection error",
 | 
				
			||||||
 | 
					                         1 );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    reportEvent( 5,
 | 
				
			||||||
 | 
					                 "set lame error protection",
 | 
				
			||||||
 | 
					                 lame_get_error_protection( lameGlobalFlags));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // let lame init its own params based on our settings
 | 
				
			||||||
 | 
					    if ( 0 > lame_init_params( lameGlobalFlags) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "lame lib initializing params error" );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    lame_print_config( lameGlobalFlags);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // open the underlying sink
 | 
				
			||||||
 | 
					    if ( !sink->open() ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "lame lib opening underlying sink error");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Convert an unsigned char buffer holding 8 bit PCM values with channels
 | 
				
			||||||
 | 
					 *  interleaved to two short int buffers (one for each channel)
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					LameLibEncoder :: conv8 (   unsigned char     * pcmBuffer,
 | 
				
			||||||
 | 
					                            unsigned int        lenPcmBuffer,
 | 
				
			||||||
 | 
					                            short int         * leftBuffer,
 | 
				
			||||||
 | 
					                            short int         * rightBuffer,
 | 
				
			||||||
 | 
					                            unsigned int        channels )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( channels == 1 ) {
 | 
				
			||||||
 | 
					        unsigned int    i, j;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for ( i = 0, j = 0; i < lenPcmBuffer; ) {
 | 
				
			||||||
 | 
					            unsigned short int  value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            value       = pcmBuffer[i++];
 | 
				
			||||||
 | 
					            leftBuffer[j] = (short int) value;
 | 
				
			||||||
 | 
					            ++j;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        unsigned int    i, j;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for ( i = 0, j = 0; i < lenPcmBuffer; ) {
 | 
				
			||||||
 | 
					            unsigned short int  value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            value  = pcmBuffer[i++];
 | 
				
			||||||
 | 
					            leftBuffer[j] = (short int) value;
 | 
				
			||||||
 | 
					            value  = pcmBuffer[i++];
 | 
				
			||||||
 | 
					            rightBuffer[j] = (short int) value;
 | 
				
			||||||
 | 
					            ++j;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Convert an unsigned char buffer holding 16 bit PCM values with channels
 | 
				
			||||||
 | 
					 *  interleaved to two short int buffers (one for each channel)
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					LameLibEncoder :: conv16 (  unsigned char     * pcmBuffer,
 | 
				
			||||||
 | 
					                            unsigned int        lenPcmBuffer,
 | 
				
			||||||
 | 
					                            short int         * leftBuffer,
 | 
				
			||||||
 | 
					                            short int         * rightBuffer,
 | 
				
			||||||
 | 
					                            unsigned int        channels )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( channels == 1 ) {
 | 
				
			||||||
 | 
					        unsigned int    i, j;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for ( i = 0, j = 0; i < lenPcmBuffer; ) {
 | 
				
			||||||
 | 
					            unsigned short int   value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            value  = pcmBuffer[i++];
 | 
				
			||||||
 | 
					            value += pcmBuffer[i++] << 8;
 | 
				
			||||||
 | 
					            leftBuffer[j] = (short int) value;
 | 
				
			||||||
 | 
					            ++j;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        unsigned int    i, j;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for ( i = 0, j = 0; i < lenPcmBuffer; ) {
 | 
				
			||||||
 | 
					            unsigned short int   value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            value  = pcmBuffer[i++];
 | 
				
			||||||
 | 
					            value += pcmBuffer[i++] << 8;
 | 
				
			||||||
 | 
					            leftBuffer[j] = (short int) value;
 | 
				
			||||||
 | 
					            value  = pcmBuffer[i++];
 | 
				
			||||||
 | 
					            value += pcmBuffer[i++] << 8;
 | 
				
			||||||
 | 
					            rightBuffer[j] = (short int) value;
 | 
				
			||||||
 | 
					            ++j;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Write data to the encoder
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					unsigned int
 | 
				
			||||||
 | 
					LameLibEncoder :: write (   const void    * buf,
 | 
				
			||||||
 | 
					                            unsigned int    len )           throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !isOpen() ) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    unsigned int    bitsPerSample = getInBitsPerSample();
 | 
				
			||||||
 | 
					    unsigned int    channels      = getInChannel();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( channels != 1 && channels != 2 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "unsupported number of channels for the encoder",
 | 
				
			||||||
 | 
					                         channels );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					    unsigned int    sampleSize = (bitsPerSample / 8) * channels;
 | 
				
			||||||
 | 
					    unsigned char * b = (unsigned char*) buf;
 | 
				
			||||||
 | 
					    unsigned int    processed = len - (len % sampleSize);
 | 
				
			||||||
 | 
					    unsigned int    nSamples = processed / sampleSize;
 | 
				
			||||||
 | 
					    short int       leftBuffer[nSamples];
 | 
				
			||||||
 | 
					    short int       rightBuffer[nSamples];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( bitsPerSample == 8 ) {
 | 
				
			||||||
 | 
					        conv8( b, processed, leftBuffer, rightBuffer, channels);
 | 
				
			||||||
 | 
					    } else if ( bitsPerSample == 16 ) {
 | 
				
			||||||
 | 
					        conv16( b, processed, leftBuffer, rightBuffer, channels);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                        "unsupported number of bits per sample for the encoder",
 | 
				
			||||||
 | 
					                         bitsPerSample );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // data chunk size estimate according to lame documentation
 | 
				
			||||||
 | 
					    unsigned int    mp3Size = (unsigned int) (1.25 * nSamples + 7200);
 | 
				
			||||||
 | 
					    unsigned char   mp3Buf[mp3Size];
 | 
				
			||||||
 | 
					    int             ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ret = lame_encode_buffer( lameGlobalFlags,
 | 
				
			||||||
 | 
					                              leftBuffer,
 | 
				
			||||||
 | 
					                              channels == 2 ? rightBuffer : leftBuffer,
 | 
				
			||||||
 | 
					                              nSamples,
 | 
				
			||||||
 | 
					                              mp3Buf,
 | 
				
			||||||
 | 
					                              mp3Size );
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( ret < 0 ) {
 | 
				
			||||||
 | 
					        reportEvent( 3, "lame encoding error", ret);
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    unsigned int    written = sink->write( mp3Buf, ret);
 | 
				
			||||||
 | 
					    // just let go data that could not be written
 | 
				
			||||||
 | 
					    if ( written < (unsigned int) ret ) {
 | 
				
			||||||
 | 
					        reportEvent( 2,
 | 
				
			||||||
 | 
					                     "couldn't write all from encoder to underlying sink",
 | 
				
			||||||
 | 
					                     ret - written);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return processed;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Flush the data from the encoder
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					LameLibEncoder :: flush ( void )
 | 
				
			||||||
 | 
					                                                            throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !isOpen() ) {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // data chunk size estimate according to lame documentation
 | 
				
			||||||
 | 
					    unsigned int    mp3Size = 7200;
 | 
				
			||||||
 | 
					    unsigned char   mp3Buf[mp3Size];
 | 
				
			||||||
 | 
					    int             ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ret = lame_encode_flush( lameGlobalFlags, mp3Buf, mp3Size );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    unsigned int    written = sink->write( mp3Buf, ret);
 | 
				
			||||||
 | 
					    // just let go data that could not be written
 | 
				
			||||||
 | 
					    if ( written < (unsigned int) ret ) {
 | 
				
			||||||
 | 
					        reportEvent( 2,
 | 
				
			||||||
 | 
					                     "couldn't write all from encoder to underlying sink",
 | 
				
			||||||
 | 
					                     ret - written);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Close the encoding session
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					LameLibEncoder :: close ( void )                    throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( isOpen() ) {
 | 
				
			||||||
 | 
					        flush();
 | 
				
			||||||
 | 
					        lame_close( lameGlobalFlags);
 | 
				
			||||||
 | 
					        lameGlobalFlags = 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.5  2001/09/02 09:54:12  darkeye
 | 
				
			||||||
 | 
					  fixed typos in CVS substition keywords
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2001/08/31 20:09:05  darkeye
 | 
				
			||||||
 | 
					  added funcitons conv8() and conv16()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2001/08/29 21:06:16  darkeye
 | 
				
			||||||
 | 
					  added real support for 8 / 16 bit mono / stereo input
 | 
				
			||||||
 | 
					  (8 bit input still has to be spread on 16 bit words)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1  2001/08/26 20:44:30  darkeye
 | 
				
			||||||
 | 
					  removed external command-line encoder support
 | 
				
			||||||
 | 
					  replaced it with a shared-object support for lame with the possibility
 | 
				
			||||||
 | 
					  of static linkage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,487 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : LameLibEncoder.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef LAME_LIB_ENCODER_H
 | 
				
			||||||
 | 
					#define LAME_LIB_ENCODER_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_LAME_LIB
 | 
				
			||||||
 | 
					#include <lame/lame.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need lame/lame.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Ref.h"
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					#include "Reporter.h"
 | 
				
			||||||
 | 
					#include "AudioEncoder.h"
 | 
				
			||||||
 | 
					#include "Sink.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  A class representing the lame encoder linked as a shared object or as
 | 
				
			||||||
 | 
					 *  a static library.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class LameLibEncoder : public AudioEncoder, public virtual Reporter,
 | 
				
			||||||
 | 
					                       public Sink
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Lame library global flags
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        lame_global_flags             * lameGlobalFlags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The Sink to dump mp3 data to
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        Ref<Sink>                       sink;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Highpass filter. Sound frequency in Hz, from where up the
 | 
				
			||||||
 | 
					         *  input is cut.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int                    lowpass;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Lowpass filter. Sound frequency in Hz, from where down the
 | 
				
			||||||
 | 
					         *  input is cut.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int                    highpass;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Initialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sink the sink to send mp3 output to
 | 
				
			||||||
 | 
					         *  @param lowpass frequency threshold for the lowpass filter.
 | 
				
			||||||
 | 
					         *                 Input above this frequency is cut.
 | 
				
			||||||
 | 
					         *                 If 0, lame's default values are used,
 | 
				
			||||||
 | 
					         *                 which depends on the out sample rate.
 | 
				
			||||||
 | 
					         *  @param highpass frequency threshold for the highpass filter.
 | 
				
			||||||
 | 
					         *                  Input below this frequency is cut.
 | 
				
			||||||
 | 
					         *                  If 0, lame's default values are used,
 | 
				
			||||||
 | 
					         *                  which depends on the out sample rate.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        init ( Sink           * sink,
 | 
				
			||||||
 | 
					               unsigned int     lowpass,
 | 
				
			||||||
 | 
					               unsigned int     highpass )                  throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            this->sink     = sink;
 | 
				
			||||||
 | 
					            this->lowpass  = lowpass;
 | 
				
			||||||
 | 
					            this->highpass = highpass;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if ( getInBitsPerSample() != 16 && getInBitsPerSample() != 8 ) {
 | 
				
			||||||
 | 
					                throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                                 "specified bits per sample not supported",
 | 
				
			||||||
 | 
					                                 getInBitsPerSample() );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if ( getOutSampleRate() != getInSampleRate() ) {
 | 
				
			||||||
 | 
					                throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                              "different in and out sample rate not supported");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if ( getInChannel() != getOutChannel() ) {
 | 
				
			||||||
 | 
					                throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                                 "different in and out channels not supported");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  De-initialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        strip ( void )                                  throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Convert a char buffer holding 8 bit PCM values to a short buffer
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param pcmBuffer buffer holding 8 bit PCM audio values,
 | 
				
			||||||
 | 
					         *                   channels are interleaved
 | 
				
			||||||
 | 
					         *  @param lenPcmBuffer length of pcmBuffer
 | 
				
			||||||
 | 
					         *  @param leftBuffer put the left channel here (must be big enough)
 | 
				
			||||||
 | 
					         *  @param rightBuffer put the right channel here (if mono, not
 | 
				
			||||||
 | 
					         *                     touched, must be big enough)
 | 
				
			||||||
 | 
					         *  @param channels number of channels (1 = mono, 2 = stereo)
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        conv8 (     unsigned char     * pcmBuffer,
 | 
				
			||||||
 | 
					                    unsigned int        lenPcmBuffer,
 | 
				
			||||||
 | 
					                    short int         * leftBuffer,
 | 
				
			||||||
 | 
					                    short int         * rightBuffer,
 | 
				
			||||||
 | 
					                    unsigned int        channels );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Convert a char buffer holding 16 bit PCM values to a short buffer
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param pcmBuffer buffer holding 16 bit PCM audio values,
 | 
				
			||||||
 | 
					         *                   channels are interleaved
 | 
				
			||||||
 | 
					         *  @param lenPcmBuffer length of pcmBuffer
 | 
				
			||||||
 | 
					         *  @param leftBuffer put the left channel here (must be big enough)
 | 
				
			||||||
 | 
					         *  @param rightBuffer put the right channel here (if mono, not
 | 
				
			||||||
 | 
					         *                     touched, must be big enough)
 | 
				
			||||||
 | 
					         *  @param channels number of channels (1 = mono, 2 = stereo)
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        conv16 (    unsigned char     * pcmBuffer,
 | 
				
			||||||
 | 
					                    unsigned int        lenPcmBuffer,
 | 
				
			||||||
 | 
					                    short int         * leftBuffer,
 | 
				
			||||||
 | 
					                    short int         * rightBuffer,
 | 
				
			||||||
 | 
					                    unsigned int        channels );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        LameLibEncoder ( void )                         throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sink the sink to send mp3 output to
 | 
				
			||||||
 | 
					         *  @param inSampleRate sample rate of the input.
 | 
				
			||||||
 | 
					         *  @param inBitsPerSample number of bits per sample of the input.
 | 
				
			||||||
 | 
					         *  @param inChannel number of channels  of the input.
 | 
				
			||||||
 | 
					         *  @param outBitrate bit rate of the output (bits/sec).
 | 
				
			||||||
 | 
					         *  @param outSampleRate sample rate of the output.
 | 
				
			||||||
 | 
					         *                       If 0, inSampleRate is used.
 | 
				
			||||||
 | 
					         *  @param outChannel number of channels of the output.
 | 
				
			||||||
 | 
					         *                    If 0, inChannel is used.
 | 
				
			||||||
 | 
					         *  @param lowpass frequency threshold for the lowpass filter.
 | 
				
			||||||
 | 
					         *                 Input above this frequency is cut.
 | 
				
			||||||
 | 
					         *                 If 0, lame's default values are used,
 | 
				
			||||||
 | 
					         *                 which depends on the out sample rate.
 | 
				
			||||||
 | 
					         *  @param highpass frequency threshold for the highpass filter.
 | 
				
			||||||
 | 
					         *                  Input below this frequency is cut.
 | 
				
			||||||
 | 
					         *                  If 0, lame's default values are used,
 | 
				
			||||||
 | 
					         *                  which depends on the out sample rate.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        LameLibEncoder (    Sink          * sink,
 | 
				
			||||||
 | 
					                            unsigned int    inSampleRate,
 | 
				
			||||||
 | 
					                            unsigned int    inBitsPerSample,
 | 
				
			||||||
 | 
					                            unsigned int    inChannel,
 | 
				
			||||||
 | 
					                            unsigned int    outBitrate,
 | 
				
			||||||
 | 
					                            unsigned int    outSampleRate = 0,
 | 
				
			||||||
 | 
					                            unsigned int    outChannel    = 0,
 | 
				
			||||||
 | 
					                            unsigned int    lowpass       = 0,
 | 
				
			||||||
 | 
					                            unsigned int    highpass      = 0 )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					                    : AudioEncoder ( inSampleRate,
 | 
				
			||||||
 | 
					                                     inBitsPerSample,
 | 
				
			||||||
 | 
					                                     inChannel, 
 | 
				
			||||||
 | 
					                                     outBitrate,
 | 
				
			||||||
 | 
					                                     outSampleRate,
 | 
				
			||||||
 | 
					                                     outChannel )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( sink, lowpass, highpass );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sink the sink to send mp3 output to
 | 
				
			||||||
 | 
					         *  @param as get input sample rate, bits per sample and channels
 | 
				
			||||||
 | 
					         *            from this AudioSource.
 | 
				
			||||||
 | 
					         *  @param outBitrate bit rate of the output (bits/sec).
 | 
				
			||||||
 | 
					         *  @param outSampleRate sample rate of the output.
 | 
				
			||||||
 | 
					         *                       If 0, input sample rate is used.
 | 
				
			||||||
 | 
					         *  @param outChannel number of channels of the output.
 | 
				
			||||||
 | 
					         *                    If 0, input channel is used.
 | 
				
			||||||
 | 
					         *  @param lowpass frequency threshold for the lowpass filter.
 | 
				
			||||||
 | 
					         *                 Input above this frequency is cut.
 | 
				
			||||||
 | 
					         *                 If 0, lame's default values are used,
 | 
				
			||||||
 | 
					         *                 which depends on the out sample rate.
 | 
				
			||||||
 | 
					         *  @param highpass frequency threshold for the highpass filter.
 | 
				
			||||||
 | 
					         *                  Input below this frequency is cut.
 | 
				
			||||||
 | 
					         *                  If 0, lame's default values are used,
 | 
				
			||||||
 | 
					         *                  which depends on the out sample rate.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        LameLibEncoder (    Sink                  * sink,
 | 
				
			||||||
 | 
					                            const AudioSource     * as,
 | 
				
			||||||
 | 
					                            unsigned int            outBitrate,
 | 
				
			||||||
 | 
					                            unsigned int            outSampleRate = 0,
 | 
				
			||||||
 | 
					                            unsigned int            outChannel    = 0,
 | 
				
			||||||
 | 
					                            unsigned int            lowpass       = 0,
 | 
				
			||||||
 | 
					                            unsigned int            highpass      = 0 )
 | 
				
			||||||
 | 
					                                                            throw ( Exception )
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					                    : AudioEncoder ( as,
 | 
				
			||||||
 | 
					                                     outBitrate,
 | 
				
			||||||
 | 
					                                     outSampleRate,
 | 
				
			||||||
 | 
					                                     outChannel )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( sink, lowpass, highpass );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param encoder the LameLibEncoder to copy.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        LameLibEncoder (  const LameLibEncoder &    encoder )
 | 
				
			||||||
 | 
					                                                            throw ( Exception )
 | 
				
			||||||
 | 
					                    : AudioEncoder( encoder )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( encoder.sink.get(), encoder.lowpass, encoder.highpass );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~LameLibEncoder ( void )                            throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( isOpen() ) {
 | 
				
			||||||
 | 
					                close();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            strip();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param encoder the LameLibEncoder to assign this to.
 | 
				
			||||||
 | 
					         *  @return a reference to this LameLibEncoder.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual LameLibEncoder &
 | 
				
			||||||
 | 
					        operator= ( const LameLibEncoder &      encoder )   throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( this != &encoder ) {
 | 
				
			||||||
 | 
					                strip();
 | 
				
			||||||
 | 
					                AudioEncoder::operator=( encoder);
 | 
				
			||||||
 | 
					                init( encoder.sink.get(), encoder.lowpass, encoder.highpass );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return *this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the version string of the underlying lame library.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the version string of the underlying lame library.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getLameVersion( void )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return get_lame_version();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check wether encoding is in progress.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if encoding is in progress, false otherwise.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual bool
 | 
				
			||||||
 | 
					        isRunning ( void ) const           throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return isOpen();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Start encoding. This function returns as soon as possible,
 | 
				
			||||||
 | 
					         *  with encoding started in the background.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if encoding has started, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual bool
 | 
				
			||||||
 | 
					        start ( void )                      throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return open();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Stop encoding. Stops the encoding running in the background.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual void
 | 
				
			||||||
 | 
					        stop ( void )                       throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return close();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Open an encoding session.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if opening was successfull, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        open ( void )                               throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the encoding session is open.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if the encoding session is open, false otherwise.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual bool
 | 
				
			||||||
 | 
					        isOpen ( void ) const                       throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return lameGlobalFlags != 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the encoder is ready to accept data.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sec the maximum seconds to block.
 | 
				
			||||||
 | 
					         *  @param usec micro seconds to block after the full seconds.
 | 
				
			||||||
 | 
					         *  @return true if the encoder is ready to accept data,
 | 
				
			||||||
 | 
					         *          false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual bool
 | 
				
			||||||
 | 
					        canWrite (     unsigned int    sec,
 | 
				
			||||||
 | 
					                       unsigned int    usec )       throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( !isOpen() ) {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Write data to the encoder.
 | 
				
			||||||
 | 
					         *  Buf is expected to be a sequence of big-endian 16 bit values,
 | 
				
			||||||
 | 
					         *  with left and right channels interleaved. Len is the number of
 | 
				
			||||||
 | 
					         *  bytes, must be a multiple of 4.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param buf the data to write.
 | 
				
			||||||
 | 
					         *  @param len number of bytes to write from buf.
 | 
				
			||||||
 | 
					         *  @return the number of bytes written (may be less than len).
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual unsigned int
 | 
				
			||||||
 | 
					        write (        const void    * buf,
 | 
				
			||||||
 | 
					                       unsigned int    len )        throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Flush all data that was written to the encoder to the underlying
 | 
				
			||||||
 | 
					         *  connection.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual void
 | 
				
			||||||
 | 
					        flush ( void )                              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Close the encoding session.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual void
 | 
				
			||||||
 | 
					        close ( void )                              throw ( Exception );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* LAME_LIB_ENCODER_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.5  2001/09/02 09:54:12  darkeye
 | 
				
			||||||
 | 
					  fixed typos in CVS substition keywords
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2001/08/31 20:09:05  darkeye
 | 
				
			||||||
 | 
					  added funcitons conv8() and conv16()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2001/08/29 21:06:16  darkeye
 | 
				
			||||||
 | 
					  added real support for 8 / 16 bit mono / stereo input
 | 
				
			||||||
 | 
					  (8 bit input still has to be spread on 16 bit words)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1  2001/08/26 20:44:30  darkeye
 | 
				
			||||||
 | 
					  removed external command-line encoder support
 | 
				
			||||||
 | 
					  replaced it with a shared-object support for lame with the possibility
 | 
				
			||||||
 | 
					  of static linkage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,41 @@
 | 
				
			||||||
 | 
					bin_PROGRAMS = darkice
 | 
				
			||||||
 | 
					INCLUDES = @LAME_INCFLAGS@
 | 
				
			||||||
 | 
					CXXFLAGS = -O2 -Wall -DVERSION="@VERSION@"
 | 
				
			||||||
 | 
					LDADD = @LAME_LDFLAGS@ @LINK_STATIC@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					darkice_SOURCES =   AudioEncoder.h\
 | 
				
			||||||
 | 
					                    AudioSource.h\
 | 
				
			||||||
 | 
					                    BufferedSink.cpp\
 | 
				
			||||||
 | 
					                    BufferedSink.h\
 | 
				
			||||||
 | 
					                    CastSink.cpp\
 | 
				
			||||||
 | 
					                    CastSink.h\
 | 
				
			||||||
 | 
					                    Connector.cpp\
 | 
				
			||||||
 | 
					                    Connector.h\
 | 
				
			||||||
 | 
					                    DarkIce.cpp\
 | 
				
			||||||
 | 
					                    DarkIce.h\
 | 
				
			||||||
 | 
					                    Exception.cpp\
 | 
				
			||||||
 | 
					                    Exception.h\
 | 
				
			||||||
 | 
					                    IceCast.cpp\
 | 
				
			||||||
 | 
					                    IceCast.h\
 | 
				
			||||||
 | 
					                    ShoutCast.cpp\
 | 
				
			||||||
 | 
					                    ShoutCast.h\
 | 
				
			||||||
 | 
					                    LameLibEncoder.cpp\
 | 
				
			||||||
 | 
					                    LameLibEncoder.h\
 | 
				
			||||||
 | 
					                    OssDspSource.cpp\
 | 
				
			||||||
 | 
					                    OssDspSource.h\
 | 
				
			||||||
 | 
					                    Ref.h\
 | 
				
			||||||
 | 
					                    Referable.h\
 | 
				
			||||||
 | 
					                    Sink.h\
 | 
				
			||||||
 | 
					                    Source.h\
 | 
				
			||||||
 | 
					                    TcpSocket.cpp\
 | 
				
			||||||
 | 
					                    TcpSocket.h\
 | 
				
			||||||
 | 
					                    Util.cpp\
 | 
				
			||||||
 | 
					                    Util.h\
 | 
				
			||||||
 | 
					                    ConfigSection.h\
 | 
				
			||||||
 | 
					                    ConfigSection.cpp\
 | 
				
			||||||
 | 
					                    Config.h\
 | 
				
			||||||
 | 
					                    Config.cpp\
 | 
				
			||||||
 | 
					                    Reporter.h\
 | 
				
			||||||
 | 
					                    Reporter.cpp\
 | 
				
			||||||
 | 
					                    main.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,302 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : OssDspSource.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_UNISTD_H
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need unistd.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_SYS_TYPES_H
 | 
				
			||||||
 | 
					#include <sys/types.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need sys/types.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_SYS_STAT_H
 | 
				
			||||||
 | 
					#include <sys/stat.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need sys/stat.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_FCNTL_H
 | 
				
			||||||
 | 
					#include <fcntl.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need fcntl.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_SYS_TIME_H
 | 
				
			||||||
 | 
					#include <sys/time.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need sys/time.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_SYS_IOCTL_H
 | 
				
			||||||
 | 
					#include <sys/ioctl.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need sys/ioctl.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_SYS_SOUNDCARD_H
 | 
				
			||||||
 | 
					#include <sys/soundcard.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need sys/soundcard.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Util.h"
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					#include "OssDspSource.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					OssDspSource :: init (  const char      * name )    throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    fileName       = Util::strDup( name);
 | 
				
			||||||
 | 
					    fileDescriptor = 0;
 | 
				
			||||||
 | 
					    running        = false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  De-initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					OssDspSource :: strip ( void )                      throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( isOpen() ) {
 | 
				
			||||||
 | 
					        close();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    delete[] fileName;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Open the audio source
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					OssDspSource :: open ( void )                       throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int             format;
 | 
				
			||||||
 | 
					    int             i;
 | 
				
			||||||
 | 
					    unsigned int    u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( isOpen() ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    switch ( getBitsPerSample() ) {
 | 
				
			||||||
 | 
					        case 8:
 | 
				
			||||||
 | 
					            format = AFMT_U8;
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        case 16:
 | 
				
			||||||
 | 
					            format = AFMT_S16_LE;
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					        default:
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( (fileDescriptor = ::open( fileName, O_RDONLY)) == -1 ) {
 | 
				
			||||||
 | 
					        fileDescriptor = 0;
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    i = format;
 | 
				
			||||||
 | 
					    if ( ioctl( fileDescriptor, SNDCTL_DSP_SETFMT, &i) == -1 ||
 | 
				
			||||||
 | 
					         i != format ) {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        close();
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "can't set format", i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    u = getChannel();
 | 
				
			||||||
 | 
					    if ( ioctl( fileDescriptor, SNDCTL_DSP_CHANNELS, &u) == -1 ||
 | 
				
			||||||
 | 
					         u != getChannel() ) {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        close();
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "can't set channels", u);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    u = getSampleRate();
 | 
				
			||||||
 | 
					    if ( ioctl( fileDescriptor, SNDCTL_DSP_SPEED, &u) == -1 ) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        close();
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                         "can't set soundcard recording sample rate", u);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( u != getSampleRate() ) {
 | 
				
			||||||
 | 
					        reportEvent( 2, "sound card recording sample rate set to ", u,
 | 
				
			||||||
 | 
					                        " while trying to set it to ", getSampleRate());
 | 
				
			||||||
 | 
					        reportEvent( 2, "this is probably not a problem, but a slight "
 | 
				
			||||||
 | 
					                        "drift in the sound card driver");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Check wether read() would return anything
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					OssDspSource :: canRead ( unsigned int    sec,
 | 
				
			||||||
 | 
					                          unsigned int    usec )    throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    fd_set              fdset;
 | 
				
			||||||
 | 
					    struct timeval      tv;
 | 
				
			||||||
 | 
					    int                 ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !isOpen() ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !running ) {
 | 
				
			||||||
 | 
					        /* ugly workaround to get the dsp into recording state */
 | 
				
			||||||
 | 
					        unsigned char   b[getChannel()*getBitsPerSample()/8];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        read( b, getChannel()*getBitsPerSample()/8);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    FD_ZERO( &fdset);
 | 
				
			||||||
 | 
					    FD_SET( fileDescriptor, &fdset);
 | 
				
			||||||
 | 
					    tv.tv_sec  = sec;
 | 
				
			||||||
 | 
					    tv.tv_usec = usec;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ret = select( fileDescriptor + 1, &fdset, NULL, NULL, &tv);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( ret == -1 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "select error");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ret > 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Read from the audio source
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					unsigned int
 | 
				
			||||||
 | 
					OssDspSource :: read (    void          * buf,
 | 
				
			||||||
 | 
					                          unsigned int    len )     throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ssize_t     ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !isOpen() ) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ret = ::read( fileDescriptor, buf, len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( ret == -1 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "read error");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    running = true;
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Close the audio source
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					OssDspSource :: close ( void )                  throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !isOpen() ) {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ::close( fileDescriptor);
 | 
				
			||||||
 | 
					    fileDescriptor = 0;
 | 
				
			||||||
 | 
					    running        = false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.8  2001/09/02 14:08:40  darkeye
 | 
				
			||||||
 | 
					  setting the sound card recording sample rate is now more relaxed
 | 
				
			||||||
 | 
					  there is no error reported if the sample rate is not exactly the same
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.7  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.6  2000/12/01 15:03:28  darkeye
 | 
				
			||||||
 | 
					  bug fix in error reporting
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.5  2000/11/17 15:50:48  darkeye
 | 
				
			||||||
 | 
					  added -Wall flag to compiler and eleminated new warnings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/13 20:05:07  darkeye
 | 
				
			||||||
 | 
					  changed to workaround to start recording so that it reads one sample
 | 
				
			||||||
 | 
					  per channel, as opposed to only one sample (which misalignes the channels)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/12 13:31:40  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 14:08:28  darkeye
 | 
				
			||||||
 | 
					  changed builting to an automake / autoconf environment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:53  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,269 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : OssDspSource.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef OSS_DSP_SOURCE_H
 | 
				
			||||||
 | 
					#define OSS_DSP_SOURCE_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Reporter.h"
 | 
				
			||||||
 | 
					#include "AudioSource.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  An audio input based on /dev/dsp-like raw devices
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class OssDspSource : public AudioSource, public virtual Reporter
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The file name of the OSS DSP device (e.g. /dev/dsp or /dev/dsp0).
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char      * fileName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The low-level file descriptor of the OSS DSP device.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        int         fileDescriptor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Indicates wether the low-level OSS DSP device is in a recording
 | 
				
			||||||
 | 
					         *  state.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        bool        running;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        OssDspSource ( void )                       throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Initialize the object
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param name the file name of the OSS DSP device.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        init (  const char    * name )              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  De-iitialize the object
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        strip ( void )                              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param name the file name of the OSS DSP device
 | 
				
			||||||
 | 
					         *              (e.g. /dev/dsp or /dev/dsp0).
 | 
				
			||||||
 | 
					         *  @param sampleRate samples per second (e.g. 44100 for 44.1kHz).
 | 
				
			||||||
 | 
					         *  @param bitsPerSample bits per sample (e.g. 16 bits).
 | 
				
			||||||
 | 
					         *  @param channel number of channels of the audio source
 | 
				
			||||||
 | 
					         *                 (e.g. 1 for mono, 2 for stereo, etc.).
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        OssDspSource (  const char    * name,
 | 
				
			||||||
 | 
					                        int             sampleRate    = 44100,
 | 
				
			||||||
 | 
					                        int             bitsPerSample = 16,
 | 
				
			||||||
 | 
					                        int             channel       = 2 )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    : AudioSource( sampleRate, bitsPerSample, channel)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( name);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param source the object to copy.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        OssDspSource (  const OssDspSource &    ds )    throw ( Exception )
 | 
				
			||||||
 | 
					                    : AudioSource( ds )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( ds.fileName);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~OssDspSource ( void )                          throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            strip();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param ds the object to assign to this one.
 | 
				
			||||||
 | 
					         *  @return a reference to this object.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual OssDspSource &
 | 
				
			||||||
 | 
					        operator= (     const OssDspSource &     ds )   throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( this != &ds ) {
 | 
				
			||||||
 | 
					                strip();
 | 
				
			||||||
 | 
					                AudioSource::operator=( ds);
 | 
				
			||||||
 | 
					                init( ds.fileName);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return *this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Open the OssDspSource.
 | 
				
			||||||
 | 
					         *  This does not put the OSS DSP device into recording mode.
 | 
				
			||||||
 | 
					         *  To start getting samples, call either canRead() or read().
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if opening was successful, false otherwise
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         *  
 | 
				
			||||||
 | 
					         *  @see #canRead
 | 
				
			||||||
 | 
					         *  @see #read
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        open ( void )                                   throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the OssDspSource is open.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if the OssDspSource is open, false otherwise.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual bool
 | 
				
			||||||
 | 
					        isOpen ( void ) const                           throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return fileDescriptor != 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the OssDspSource can be read from.
 | 
				
			||||||
 | 
					         *  Blocks until the specified time for data to be available.
 | 
				
			||||||
 | 
					         *  Puts the OSS DSP device into recording mode.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sec the maximum seconds to block.
 | 
				
			||||||
 | 
					         *  @param usec micro seconds to block after the full seconds.
 | 
				
			||||||
 | 
					         *  @return true if the OssDspSource is ready to be read from,
 | 
				
			||||||
 | 
					         *          false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        canRead (               unsigned int    sec,
 | 
				
			||||||
 | 
					                                unsigned int    usec )  throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Read from the OssDspSource.
 | 
				
			||||||
 | 
					         *  Puts the OSS DSP device into recording mode.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param buf the buffer to read into.
 | 
				
			||||||
 | 
					         *  @param len the number of bytes to read into buf
 | 
				
			||||||
 | 
					         *  @return the number of bytes read (may be less than len).
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual unsigned int
 | 
				
			||||||
 | 
					        read (                  void          * buf,
 | 
				
			||||||
 | 
					                                unsigned int    len )   throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Close the OssDspSource.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual void
 | 
				
			||||||
 | 
					        close ( void )                                  throw ( Exception );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* OSS_DSP_SOURCE_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.4  2001/09/02 14:08:40  darkeye
 | 
				
			||||||
 | 
					  setting the sound card recording sample rate is now more relaxed
 | 
				
			||||||
 | 
					  there is no error reported if the sample rate is not exactly the same
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/12 13:31:40  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 17:37:24  darkeye
 | 
				
			||||||
 | 
					  removed clone() functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:53  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,288 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Ref.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef REF_H
 | 
				
			||||||
 | 
					#define REF_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  Java-like object reference class.
 | 
				
			||||||
 | 
					 *  Objects used with this reference class have to be descandents
 | 
				
			||||||
 | 
					 *  of class Referable.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  sample usage:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  <pre>
 | 
				
			||||||
 | 
					 *  #include "Ref.h"
 | 
				
			||||||
 | 
					 *  #include "Referable.h"
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  class  A : public virtual Referable;
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  ...
 | 
				
			||||||
 | 
					 *   
 | 
				
			||||||
 | 
					 *  A        * a = new A();
 | 
				
			||||||
 | 
					 *  Ref<A>     ref1 = a;       // 1 reference to a
 | 
				
			||||||
 | 
					 *  Ref<A>     ref2 = ref1;    // 2 references to a
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  ref1 = 0;      // 1 reference to a
 | 
				
			||||||
 | 
					 *  ref2 = 0;      // at this point object a is destroyed
 | 
				
			||||||
 | 
					 *  </pre>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Based on Tima Saarinen's work,
 | 
				
			||||||
 | 
					 *  http://gamma.nic.fi/~timosa/comp/refcount.html
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @ref Referable
 | 
				
			||||||
 | 
					 *  
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					template <class T>
 | 
				
			||||||
 | 
					class Ref
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The object referenced by this Ref.
 | 
				
			||||||
 | 
					         *  Must be a descandant of Referable.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        T* object;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Ref ( void )                            throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            object = NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param other the Ref to copy.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Ref ( const Ref<T> &    other )         throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            object = NULL;
 | 
				
			||||||
 | 
					            set( other.object);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor based on an object to reference.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param obj the object to reference.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Ref ( T   * obj )                       throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            object = obj;
 | 
				
			||||||
 | 
					            obj->increaseReferenceCount();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~Ref ( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            set( 0 );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Operator overload to make the reference seem like a pointer.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the pointer to the object referenced.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline T*
 | 
				
			||||||
 | 
					        operator->() const                      throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( !object ) {
 | 
				
			||||||
 | 
					                throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                                 "reference to NULL object");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return object;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param other the Ref to assign to this one.
 | 
				
			||||||
 | 
					         *  @return a reference to this Ref.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline Ref<T> &
 | 
				
			||||||
 | 
					        operator= ( Ref<T>  other )             throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            set( other.object);
 | 
				
			||||||
 | 
					            return *this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param obj pointer to the object to assign to this Ref.
 | 
				
			||||||
 | 
					         *  @return a reference to this Ref.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline Ref<T> &
 | 
				
			||||||
 | 
					        operator= ( T*  obj )                   throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            set( obj);
 | 
				
			||||||
 | 
					            return *this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Set the object referenced.
 | 
				
			||||||
 | 
					         *  Deletes the old referenced object is this was it's last reference.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param newobj pointer to the object to reference by this Ref.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        set ( T*    newobj )                    throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            // If equal do nothing
 | 
				
			||||||
 | 
					            if ( newobj == object ) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Increase reference count
 | 
				
			||||||
 | 
					            if ( newobj ) {
 | 
				
			||||||
 | 
					                newobj->increaseReferenceCount();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Decrease the reference count of the old referable
 | 
				
			||||||
 | 
					            if ( object ) {
 | 
				
			||||||
 | 
					                if ( object->decreaseReferenceCount() == 0 ) {
 | 
				
			||||||
 | 
					                    delete object;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Assign
 | 
				
			||||||
 | 
					            object = newobj;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Return object pointer. This method should be used with
 | 
				
			||||||
 | 
					         *  care because it breaks the encapsulation.
 | 
				
			||||||
 | 
					         *  Typically this method is needed for the method calls
 | 
				
			||||||
 | 
					         *  which require literal object pointer.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  It may not be bad idea to pass the Ref
 | 
				
			||||||
 | 
					         *  objects as method arguments.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return Object pointer or NULL.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline T*
 | 
				
			||||||
 | 
					        get ( void ) const                      throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return object;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Equality operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param other the Ref to compare this with.
 | 
				
			||||||
 | 
					         *  @return true is the two Refs refer to the same object,
 | 
				
			||||||
 | 
					         *          false otherwise.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline bool
 | 
				
			||||||
 | 
					        operator== ( const Ref<T> &   other ) const     throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return object == other.object;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Unequality operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param other the Ref to compare this with.
 | 
				
			||||||
 | 
					         *  @return false is the two Refs refer to the same object,
 | 
				
			||||||
 | 
					         *          true otherwise.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline bool
 | 
				
			||||||
 | 
					        operator!= ( const Ref<T> &   other ) const     throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return object != other.object;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* REF_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/11 14:55:31  darkeye
 | 
				
			||||||
 | 
					  minor bugfix
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/11 12:33:13  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:54  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,185 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Referable.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef REFERABLE_H
 | 
				
			||||||
 | 
					#define REFERABLE_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  Base class for an object for which references can be made
 | 
				
			||||||
 | 
					 *  with the reference class Ref.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  usage:
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 *  <pre>
 | 
				
			||||||
 | 
					 *  class A : public virtual Referable
 | 
				
			||||||
 | 
					 *  {
 | 
				
			||||||
 | 
					 *     ...
 | 
				
			||||||
 | 
					 *  };
 | 
				
			||||||
 | 
					 *  </pre>
 | 
				
			||||||
 | 
					 *  
 | 
				
			||||||
 | 
					 *  @ref Ref
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class Referable
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Number of references to the object.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned int    referenceCount;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Maximum number of references before an overflow occurs.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        static const
 | 
				
			||||||
 | 
					        unsigned int    maxCount = ~((unsigned int)0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Referable ( void )                              throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            referenceCount = 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Desctructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~Referable ( void )                             throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( referenceCount > 0 ) {
 | 
				
			||||||
 | 
					                throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                                 "reference count positive in destructor",
 | 
				
			||||||
 | 
					                                 referenceCount);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Increase reference count.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the new reference count.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        increaseReferenceCount ( void )                 throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( referenceCount >= maxCount ) {
 | 
				
			||||||
 | 
					                throw Exception( __FILE__,
 | 
				
			||||||
 | 
					                                 __LINE__,
 | 
				
			||||||
 | 
					                                 "reference count overflow",
 | 
				
			||||||
 | 
					                                 referenceCount );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return ++referenceCount;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Decrease reference count.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the new reference count.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        decreaseReferenceCount ( void )                 throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( referenceCount == 0 ) {
 | 
				
			||||||
 | 
					                throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                                 "reference count underflow",
 | 
				
			||||||
 | 
					                                 referenceCount );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return --referenceCount;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the reference count.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the reference count.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        getReferenceCount ( void ) const                throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return referenceCount;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* REFERABLE_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/11 12:33:13  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:54  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,74 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell Reporter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Reporter.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <iostream.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Reporter.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Initial values for static members of the class
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					unsigned int    Reporter::verbosity = 1;
 | 
				
			||||||
 | 
					ostream       * Reporter::os        = &cout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.1  2000/11/16 08:48:43  darkeye
 | 
				
			||||||
 | 
					  added multiple verbosity-level event reporting and verbosity command
 | 
				
			||||||
 | 
					  line option
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,337 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell Reporter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Reporter.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef REPORTER_H
 | 
				
			||||||
 | 
					#define REPORTER_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_UNISTD_H
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need unistdt.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_TIME_H
 | 
				
			||||||
 | 
					#include <time.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need time.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <iostream.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  Class for reporting events. All objects of this class share
 | 
				
			||||||
 | 
					 *  the same verbosity level. Typical usage is to inherit this class
 | 
				
			||||||
 | 
					 *  and use the report() function to report events. Only reports
 | 
				
			||||||
 | 
					 *  which are of suffucient importance are really reported.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  The default verbosity is 1, and the default ostream is cout.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 *  Known problems: this class is not thread-safe.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class Reporter
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Verbosity level shared among all Reporter objects
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        static unsigned int     verbosity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  The output stream to report to.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        static ostream        * os;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Print timestamp for every report only if verbosity level
 | 
				
			||||||
 | 
					         *  is above this value.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        static const unsigned int   prefixVerbosity = 3;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Print a prefix to each report.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        printPrefix( void )                         throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( verbosity > prefixVerbosity ) {
 | 
				
			||||||
 | 
					                char    str[32];
 | 
				
			||||||
 | 
					                time_t  now;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                now = time(NULL);
 | 
				
			||||||
 | 
					                strftime( str, 32, "%H:%M:%S: ", localtime(&now) );
 | 
				
			||||||
 | 
					                (*(Reporter::os)) << str;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~Reporter ( void )                                  throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            (Reporter::os)->flush();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Set the verbosity level. This sets the verbosity for all
 | 
				
			||||||
 | 
					         *  Reporter objects.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param verbosity the new verbosity level.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        setReportVerbosity ( unsigned int     verbosity )   throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Reporter::verbosity = verbosity;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the verbosity level.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the current verbosity level.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        getReportVerbosity ( void )                         throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return Reporter::verbosity;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Set the output stream to report to. This setting effects all
 | 
				
			||||||
 | 
					         *  Reporter objects.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param os the output stream
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        setReportOutputStream ( ostream   & os )            throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Reporter::os = &os;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the output stream to report to.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the output stream
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline ostream &
 | 
				
			||||||
 | 
					        getReportOutputStream ( void )                      throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return *(Reporter::os);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Report an event with a given verbosity.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param verbosity the importance of the event, with 0 being
 | 
				
			||||||
 | 
					         *                   the most important.
 | 
				
			||||||
 | 
					         *  @param t the object to report. Must have an
 | 
				
			||||||
 | 
					         *           <code>ostream & operator<<( ostream&, const T)</code>
 | 
				
			||||||
 | 
					         *           operator overload.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        template<class T>
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        reportEvent ( unsigned int  verbosity,
 | 
				
			||||||
 | 
					                      const T       t )                     throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( Reporter::verbosity >= verbosity ) {
 | 
				
			||||||
 | 
					                printPrefix();
 | 
				
			||||||
 | 
					                (*(Reporter::os)) << t <<  endl;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Report an event with a given verbosity.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param verbosity the importance of the event, with 0 being
 | 
				
			||||||
 | 
					         *                   the most important.
 | 
				
			||||||
 | 
					         *  @param t the object 1 to report. Must have an
 | 
				
			||||||
 | 
					         *           <code>ostream & operator<<( ostream&, const T)</code>
 | 
				
			||||||
 | 
					         *           operator overload.
 | 
				
			||||||
 | 
					         *  @param u the object 2 to report. Must have an
 | 
				
			||||||
 | 
					         *           <code>ostream & operator<<( ostream&, const U)</code>
 | 
				
			||||||
 | 
					         *           operator overload.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        template<class T, class U>
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        reportEvent ( unsigned int  verbosity,
 | 
				
			||||||
 | 
					                      const T       t,
 | 
				
			||||||
 | 
					                      const U       u )                     throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( Reporter::verbosity >= verbosity ) {
 | 
				
			||||||
 | 
					                printPrefix();
 | 
				
			||||||
 | 
					                (*(Reporter::os)) << t << " "
 | 
				
			||||||
 | 
					                                  << u <<  endl;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Report an event with a given verbosity.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param verbosity the importance of the event, with 0 being
 | 
				
			||||||
 | 
					         *                   the most important.
 | 
				
			||||||
 | 
					         *  @param t the object 1 to report. Must have an
 | 
				
			||||||
 | 
					         *           <code>ostream & operator<<( ostream&, const T)</code>
 | 
				
			||||||
 | 
					         *           operator overload.
 | 
				
			||||||
 | 
					         *  @param u the object 2 to report. Must have an
 | 
				
			||||||
 | 
					         *           <code>ostream & operator<<( ostream&, const U)</code>
 | 
				
			||||||
 | 
					         *           operator overload.
 | 
				
			||||||
 | 
					         *  @param v the object 3 to report. Must have an
 | 
				
			||||||
 | 
					         *           <code>ostream & operator<<( ostream&, const V)</code>
 | 
				
			||||||
 | 
					         *           operator overload.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        template<class T, class U, class V>
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        reportEvent ( unsigned int  verbosity,
 | 
				
			||||||
 | 
					                      const T       t,
 | 
				
			||||||
 | 
					                      const U       u,
 | 
				
			||||||
 | 
					                      const V       v )                     throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( Reporter::verbosity >= verbosity ) {
 | 
				
			||||||
 | 
					                printPrefix();
 | 
				
			||||||
 | 
					                (*(Reporter::os)) << t << " "
 | 
				
			||||||
 | 
					                                  << u << " "
 | 
				
			||||||
 | 
					                                  << v <<  endl;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Report an event with a given verbosity.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param verbosity the importance of the event, with 0 being
 | 
				
			||||||
 | 
					         *                   the most important.
 | 
				
			||||||
 | 
					         *  @param t the object 1 to report. Must have an
 | 
				
			||||||
 | 
					         *           <code>ostream & operator<<( ostream&, const T)</code>
 | 
				
			||||||
 | 
					         *           operator overload.
 | 
				
			||||||
 | 
					         *  @param u the object 2 to report. Must have an
 | 
				
			||||||
 | 
					         *           <code>ostream & operator<<( ostream&, const U)</code>
 | 
				
			||||||
 | 
					         *           operator overload.
 | 
				
			||||||
 | 
					         *  @param v the object 3 to report. Must have an
 | 
				
			||||||
 | 
					         *           <code>ostream & operator<<( ostream&, const V)</code>
 | 
				
			||||||
 | 
					         *           operator overload.
 | 
				
			||||||
 | 
					         *  @param w the object 4 to report. Must have an
 | 
				
			||||||
 | 
					         *           <code>ostream & operator<<( ostream&, const W)</code>
 | 
				
			||||||
 | 
					         *           operator overload.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        template<class T, class U, class V, class W>
 | 
				
			||||||
 | 
					        inline void
 | 
				
			||||||
 | 
					        reportEvent ( unsigned int  verbosity,
 | 
				
			||||||
 | 
					                      const T       t,
 | 
				
			||||||
 | 
					                      const U       u,
 | 
				
			||||||
 | 
					                      const V       v,
 | 
				
			||||||
 | 
					                      const W       w )                     throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( Reporter::verbosity >= verbosity ) {
 | 
				
			||||||
 | 
					                printPrefix();
 | 
				
			||||||
 | 
					                (*(Reporter::os)) << t << " "
 | 
				
			||||||
 | 
					                                  << u << " "
 | 
				
			||||||
 | 
					                                  << v << " "
 | 
				
			||||||
 | 
					                                  << w <<  endl;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* REPORTER_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.5  2001/09/05 20:11:15  darkeye
 | 
				
			||||||
 | 
					  removed dependency on locally stored SGI STL header files
 | 
				
			||||||
 | 
					  now compiler-supplied C++ library STL header files are used
 | 
				
			||||||
 | 
					  compiles under GNU C++ 3
 | 
				
			||||||
 | 
					  hash_map (an SGI extension to STL) replaced with map
 | 
				
			||||||
 | 
					  std:: namespace prefix added to all STL class references
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/12/20 12:47:40  darkeye
 | 
				
			||||||
 | 
					  added prefixVerbosity value. in a low verbosity setting no time-stamp
 | 
				
			||||||
 | 
					  prefix is displayed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/18 11:12:01  darkeye
 | 
				
			||||||
 | 
					  added timestamp display, removed process id display in reports
 | 
				
			||||||
 | 
					  changed reportEvent functions to template functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1  2000/11/16 08:48:43  darkeye
 | 
				
			||||||
 | 
					  added multiple verbosity-level event reporting and verbosity command
 | 
				
			||||||
 | 
					  line option
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,224 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : ShoutCast.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_STDIO_H
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need stdio.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_STRING_H
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need string.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					#include "Source.h"
 | 
				
			||||||
 | 
					#include "Sink.h"
 | 
				
			||||||
 | 
					#include "Util.h"
 | 
				
			||||||
 | 
					#include "ShoutCast.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Size of string conversion buffer
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#define STRBUF_SIZE         32
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					ShoutCast :: init ( const char            * irc,
 | 
				
			||||||
 | 
					                    const char            * aim,
 | 
				
			||||||
 | 
					                    const char            * icq )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    this->irc    = irc   ? Util::strDup( irc) : 0;
 | 
				
			||||||
 | 
					    this->aim    = aim   ? Util::strDup( aim) : 0;
 | 
				
			||||||
 | 
					    this->icq    = icq   ? Util::strDup( icq) : 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  De-initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					ShoutCast :: strip ( void )                             throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( irc ) {
 | 
				
			||||||
 | 
					        delete[] irc;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( aim ) {
 | 
				
			||||||
 | 
					        delete[] aim;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( icq ) {
 | 
				
			||||||
 | 
					        delete[] icq;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Log in to the ShoutCast server using the icy login scheme
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					ShoutCast :: sendLogin ( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Sink          * sink   = getSink();
 | 
				
			||||||
 | 
					    Source        * source = getSocket();
 | 
				
			||||||
 | 
					    const char    * str;
 | 
				
			||||||
 | 
					    char            resp[STRBUF_SIZE];
 | 
				
			||||||
 | 
					    unsigned int    len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !source->isOpen() ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ( !sink->isOpen() ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* first line is the password in itself */
 | 
				
			||||||
 | 
					    str = getPassword();
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    str = "\n";
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    sink->flush();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* send the icy headers */
 | 
				
			||||||
 | 
					    if ( getName() ) {
 | 
				
			||||||
 | 
					        str = "icy-name:";
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					        str = getName();
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( getUrl() ) {
 | 
				
			||||||
 | 
					        str = "\nicy-url:";
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					        str = getUrl();
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( getGenre() ) {
 | 
				
			||||||
 | 
					        str = "\nicy-genre:";
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					        str = getGenre();
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( getIrc() ) {
 | 
				
			||||||
 | 
					        str = "\nicy-irc:";
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					        str = getIrc();
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( getAim() ) {
 | 
				
			||||||
 | 
					        str = "\nicy-aim:";
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					        str = getAim();
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( getIcq() ) {
 | 
				
			||||||
 | 
					        str = "\nicy-icq:";
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					        str = getIcq();
 | 
				
			||||||
 | 
					        sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    str = "\nicy-br:";
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    if ( snprintf( resp, STRBUF_SIZE, "%d", getBitRate()) == -1 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "snprintf overflow");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    sink->write( resp, strlen( resp));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    str = "\nicy-pub:";
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    str = getIsPublic() ? "yes" : "no";
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    str = "\n\n";
 | 
				
			||||||
 | 
					    sink->write( str, strlen( str));
 | 
				
			||||||
 | 
					    sink->flush();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* read the anticipated response: "OK" */
 | 
				
			||||||
 | 
					    len = source->read( resp, STRBUF_SIZE);
 | 
				
			||||||
 | 
					    if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* suck anything that the other side has to say */
 | 
				
			||||||
 | 
					    while ( source->canRead( 0, 0) && 
 | 
				
			||||||
 | 
					           (len = source->read( resp, STRBUF_SIZE)) ) {
 | 
				
			||||||
 | 
					        ;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.1  2001/09/09 11:27:31  darkeye
 | 
				
			||||||
 | 
					  added support for ShoutCast servers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,266 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : ShoutCast.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef SHOUT_CAST_H
 | 
				
			||||||
 | 
					#define SHOUT_CAST_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Sink.h"
 | 
				
			||||||
 | 
					#include "TcpSocket.h"
 | 
				
			||||||
 | 
					#include "CastSink.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  Class representing output to a ShoutCast server with
 | 
				
			||||||
 | 
					 *  icy login
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class ShoutCast : public CastSink
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  IRC info string for the stream
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char              * irc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  AIM info string for the stream
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char              * aim;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  ICQ info string for the stream
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char              * icq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Initalize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param irc IRC info string for the stream.
 | 
				
			||||||
 | 
					         *  @param aim AIM info string for the stream.
 | 
				
			||||||
 | 
					         *  @param icq ICQ info string for the stream.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        init (  const char            * irc,
 | 
				
			||||||
 | 
					                const char            * aim,
 | 
				
			||||||
 | 
					                const char            * icq )
 | 
				
			||||||
 | 
					                                                    throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  De-initalize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        strip ( void )                              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        ShoutCast ( void )                            throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Log in to the server using the socket avialable.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if login was successful, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        sendLogin ( void )              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param socket socket connection to the server.
 | 
				
			||||||
 | 
					         *  @param password password to the server.
 | 
				
			||||||
 | 
					         *  @param name name of the stream.
 | 
				
			||||||
 | 
					         *  @param url URL associated with the stream.
 | 
				
			||||||
 | 
					         *  @param genre genre of the stream.
 | 
				
			||||||
 | 
					         *  @param bitRate bitrate of the stream (e.g. mp3 bitrate).
 | 
				
			||||||
 | 
					         *  @param isPublic is the stream public?
 | 
				
			||||||
 | 
					         *  @param irc IRC info string for the stream.
 | 
				
			||||||
 | 
					         *  @param aim AIM info string for the stream.
 | 
				
			||||||
 | 
					         *  @param icq ICQ info string for the stream.
 | 
				
			||||||
 | 
					         *  @param bufferDuration duration of the BufferedSink buffer
 | 
				
			||||||
 | 
					         *                        in seconds.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        ShoutCast ( TcpSocket         * socket,
 | 
				
			||||||
 | 
					                    const char        * password,
 | 
				
			||||||
 | 
					                    unsigned int        bitRate,
 | 
				
			||||||
 | 
					                    const char        * name           = 0,
 | 
				
			||||||
 | 
					                    const char        * url            = 0,
 | 
				
			||||||
 | 
					                    const char        * genre          = 0,
 | 
				
			||||||
 | 
					                    bool                isPublic       = false,
 | 
				
			||||||
 | 
					                    const char        * irc            = 0,
 | 
				
			||||||
 | 
					                    const char        * aim            = 0,
 | 
				
			||||||
 | 
					                    const char        * icq            = 0,
 | 
				
			||||||
 | 
					                    unsigned int        bufferDuration = 10 )
 | 
				
			||||||
 | 
					                                                        throw ( Exception )
 | 
				
			||||||
 | 
					              : CastSink( socket,
 | 
				
			||||||
 | 
					                          password,
 | 
				
			||||||
 | 
					                          bitRate,
 | 
				
			||||||
 | 
					                          name,
 | 
				
			||||||
 | 
					                          url,
 | 
				
			||||||
 | 
					                          genre,
 | 
				
			||||||
 | 
					                          isPublic,
 | 
				
			||||||
 | 
					                          bufferDuration )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( irc, aim, icq);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param cs the ShoutCast to copy.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        ShoutCast(   const ShoutCast &    cs )        throw ( Exception )
 | 
				
			||||||
 | 
					                : CastSink( cs )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( cs.getIrc(), cs.getAim(), cs.getIcq());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~ShoutCast( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            strip();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param cs the ShoutCast to assign this to.
 | 
				
			||||||
 | 
					         *  @return a reference to this ShoutCast.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual ShoutCast &
 | 
				
			||||||
 | 
					        operator= ( const ShoutCast &    cs )        throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if ( this != &cs ) {
 | 
				
			||||||
 | 
					                strip();
 | 
				
			||||||
 | 
					                CastSink::operator=( cs );
 | 
				
			||||||
 | 
					                init( cs.getIrc(), cs.getAim(), cs.getIcq());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return *this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the IRC info string for the stream.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the IRC info string for the stream.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getIrc ( void ) const                   throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return irc;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the AIM info string for the stream.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the AIM info string for the stream.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getAim ( void ) const                   throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return aim;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the ICQ info string for the stream.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the ICQ info string for the stream.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getIcq ( void ) const                   throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return icq;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* SHOUT_CAST_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.1  2001/09/09 11:27:31  darkeye
 | 
				
			||||||
 | 
					  added support for ShoutCast servers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,198 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Sink.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef SINK_H
 | 
				
			||||||
 | 
					#define SINK_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Referable.h"
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  A general data sink
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class Sink : public virtual Referable
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Sink ( void )                                   throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sink the Sink to copy.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Sink (      const Sink &    sink )              throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sink the Sink to assign this to.
 | 
				
			||||||
 | 
					         *  @return a reference to this Sink.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual Sink &
 | 
				
			||||||
 | 
					        operator= ( const Sink &    sink )              throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return *this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~Sink ( void )                                  throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Open the sink.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if opening was successfull, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        open ( void )                               throw ( Exception )    = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the Sink is open.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if the Sink is open, false otherwise.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        isOpen ( void ) const                       throw ()    = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the Sink is ready to accept data.
 | 
				
			||||||
 | 
					         *  Blocks until the specified time for data to be available.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sec the maximum seconds to block.
 | 
				
			||||||
 | 
					         *  @param usec micro seconds to block after the full seconds.
 | 
				
			||||||
 | 
					         *  @return true if the Sink is ready to accept data, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        canWrite (              unsigned int    sec,
 | 
				
			||||||
 | 
					                                unsigned int    usec )  throw ( Exception ) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Write data to the Sink.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param buf the data to write.
 | 
				
			||||||
 | 
					         *  @param len number of bytes to write from buf.
 | 
				
			||||||
 | 
					         *  @return the number of bytes written (may be less than len).
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual unsigned int
 | 
				
			||||||
 | 
					        write (                 const void    * buf,
 | 
				
			||||||
 | 
					                                unsigned int    len )   throw ( Exception ) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Flush all data that was written to the Sink to the underlying
 | 
				
			||||||
 | 
					         *  construct.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual void
 | 
				
			||||||
 | 
					        flush ( void )                                  throw ( Exception ) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Close the Sink.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual void
 | 
				
			||||||
 | 
					        close ( void )                                  throw ( Exception ) = 0;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* SINK_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/12 14:54:25  darkeye
 | 
				
			||||||
 | 
					  added Exception to throws clause for the destructor and assignment operator
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/12 13:31:16  darkeye
 | 
				
			||||||
 | 
					  minor change in documentation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/11 12:33:13  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:54  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,186 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Source.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef SOURCE_H
 | 
				
			||||||
 | 
					#define SOURCE_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Referable.h"
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  A general data source
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class Source : public virtual Referable
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Source ( void )                             throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param source the object to copy.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Source (    const Source &  source )        throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param source the object to assign to this one.
 | 
				
			||||||
 | 
					         *  @return a reference to this object.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual Source &
 | 
				
			||||||
 | 
					        operator= ( const Source &  source )        throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return *this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~Source ( void )                            throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Open the Source.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if opening was successful, false otherwise
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        open ( void )                           throw ( Exception )     = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the Source is open.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if the Source is open, false otherwise.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        isOpen ( void ) const                   throw ()                = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the Source can be read from.
 | 
				
			||||||
 | 
					         *  Blocks until the specified time for data to be available.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sec the maximum seconds to block.
 | 
				
			||||||
 | 
					         *  @param usec micro seconds to block after the full seconds.
 | 
				
			||||||
 | 
					         *  @return true if the Source is ready to be read from,
 | 
				
			||||||
 | 
					         *          false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        canRead (  unsigned int    sec,
 | 
				
			||||||
 | 
					                   unsigned int    usec )       throw ( Exception )     = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Read from the Source.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param buf the buffer to read into.
 | 
				
			||||||
 | 
					         *  @param len the number of bytes to read into buf
 | 
				
			||||||
 | 
					         *  @return the number of bytes read (may be less than len).
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual unsigned int
 | 
				
			||||||
 | 
					        read (     void          * buf,
 | 
				
			||||||
 | 
					                   unsigned int    len )        throw ( Exception )     = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Close the Source.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual void
 | 
				
			||||||
 | 
					        close ( void )                          throw ( Exception )     = 0;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* SOURCE_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/12 13:31:40  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:54  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,368 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : TcpSocket.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_STRING_H
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need string.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_SYS_TYPES_H
 | 
				
			||||||
 | 
					#include <sys/types.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need sys/types.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_ERRNO_H
 | 
				
			||||||
 | 
					#include <errno.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need errno.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_SYS_SOCKET_H
 | 
				
			||||||
 | 
					#include <sys/socket.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need sys/socket.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_NETINET_IN_H
 | 
				
			||||||
 | 
					#include <netinet/in.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need netinet/in.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_NETDB_H
 | 
				
			||||||
 | 
					#include <netdb.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need netdb.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_UNISTD_H
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need unistd.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_SYS_TIME_H
 | 
				
			||||||
 | 
					#include <sys/time.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need sys/time.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Util.h"
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					#include "TcpSocket.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					TcpSocket :: init (   const char    * host,
 | 
				
			||||||
 | 
					                      unsigned short  port )          throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    this->host   = Util::strDup( host);
 | 
				
			||||||
 | 
					    this->port   = port;
 | 
				
			||||||
 | 
					    this->sockfd = 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  De-initialize the object
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					TcpSocket :: strip ( void)                           throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( isOpen() ) {
 | 
				
			||||||
 | 
					        close();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    delete[] host;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Copy Constructor
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					TcpSocket :: TcpSocket (  const TcpSocket &    ss )    throw ( Exception )
 | 
				
			||||||
 | 
					                : Source( ss), Sink( ss )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int     fd;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    init( ss.host, ss.port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( (fd = ss.sockfd ? dup( ss.sockfd) : 0) == -1 ) {
 | 
				
			||||||
 | 
					        strip();
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "dup failure");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    sockfd = fd;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Assignment operator
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					TcpSocket &
 | 
				
			||||||
 | 
					TcpSocket :: operator= (  const TcpSocket &    ss )   throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( this != &ss ) {
 | 
				
			||||||
 | 
					        int     fd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* first strip */
 | 
				
			||||||
 | 
					        strip();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* then build up */
 | 
				
			||||||
 | 
					        Sink::operator=( ss );
 | 
				
			||||||
 | 
					        Source::operator=( ss );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        init( ss.host, ss.port);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if ( (fd = ss.sockfd ? dup( ss.sockfd) : 0) == -1 ) {
 | 
				
			||||||
 | 
					            strip();
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__, "dup failure");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        sockfd = fd;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return *this;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Open the file
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					TcpSocket :: open ( void )                       throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    struct sockaddr_in      addr;
 | 
				
			||||||
 | 
					    struct hostent        * pHostEntry;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( isOpen() ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !(pHostEntry = gethostbyname( host)) ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "gethostbyname error", errno);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( (sockfd = socket( AF_INET, SOCK_STREAM,  IPPROTO_TCP)) == -1 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "socket error", errno);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    memset( &addr, 0, sizeof(addr));
 | 
				
			||||||
 | 
					    addr.sin_family      = AF_INET;
 | 
				
			||||||
 | 
					    addr.sin_port        = htons(port);
 | 
				
			||||||
 | 
					    addr.sin_addr.s_addr = *((long*) pHostEntry->h_addr_list[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( connect( sockfd, (struct sockaddr*)&addr, sizeof(addr)) == -1 ) {
 | 
				
			||||||
 | 
					        ::close( sockfd);
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "connect error", errno);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Check wether read() would return anything
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					TcpSocket :: canRead (      unsigned int    sec,
 | 
				
			||||||
 | 
					                            unsigned int    usec )      throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    fd_set              fdset;
 | 
				
			||||||
 | 
					    struct timeval      tv;
 | 
				
			||||||
 | 
					    int                 ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !isOpen() ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    FD_ZERO( &fdset);
 | 
				
			||||||
 | 
					    FD_SET( sockfd, &fdset);
 | 
				
			||||||
 | 
					    tv.tv_sec  = sec;
 | 
				
			||||||
 | 
					    tv.tv_usec = usec;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ret = select( sockfd + 1, &fdset, NULL, NULL, &tv);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( ret == -1 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "select error");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ret > 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Read from the socket
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					unsigned int
 | 
				
			||||||
 | 
					TcpSocket :: read (     void          * buf,
 | 
				
			||||||
 | 
					                        unsigned int    len )       throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int         ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !isOpen() ) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ret = recv( sockfd, buf, len, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( ret == -1 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "recv error", errno);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Check wether read() would return anything
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					TcpSocket :: canWrite (    unsigned int    sec,
 | 
				
			||||||
 | 
					                            unsigned int    usec )      throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    fd_set              fdset;
 | 
				
			||||||
 | 
					    struct timeval      tv;
 | 
				
			||||||
 | 
					    int                 ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !isOpen() ) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    FD_ZERO( &fdset);
 | 
				
			||||||
 | 
					    FD_SET( sockfd, &fdset);
 | 
				
			||||||
 | 
					    tv.tv_sec  = sec;
 | 
				
			||||||
 | 
					    tv.tv_usec = usec;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ret = select( sockfd + 1, NULL, &fdset, NULL, &tv);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ( ret == -1 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "select error");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ret > 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Write to the socket
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					unsigned int
 | 
				
			||||||
 | 
					TcpSocket :: write (    const void    * buf,
 | 
				
			||||||
 | 
					                        unsigned int    len )       throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int         ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !isOpen() ) {
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//    ret = send( sockfd, buf, len, MSG_DONTWAIT);
 | 
				
			||||||
 | 
					    ret = send( sockfd, buf, len, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( ret == -1 ) {
 | 
				
			||||||
 | 
					        if ( errno == EAGAIN ) {
 | 
				
			||||||
 | 
					            ret = 0;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__, "send error", errno);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Close the socket
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					TcpSocket :: close ( void )                          throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !isOpen() ) {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    flush();
 | 
				
			||||||
 | 
					    ::close( sockfd);
 | 
				
			||||||
 | 
					    sockfd = 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.5  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/17 15:50:48  darkeye
 | 
				
			||||||
 | 
					  added -Wall flag to compiler and eleminated new warnings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/12 14:54:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 14:08:28  darkeye
 | 
				
			||||||
 | 
					  changed builting to an automake / autoconf environment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:55  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,297 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : TcpSocket.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef TCP_SOCKET_H
 | 
				
			||||||
 | 
					#define TCP_SOCKET_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Source.h"
 | 
				
			||||||
 | 
					#include "Sink.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  A TCP network socket
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class TcpSocket : public Source, public Sink
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Name of the host this socket connects to.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        char              * host;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Port to connect to.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        unsigned short      port;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Low-level socket descriptor.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        int                 sockfd;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Initialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param host name of the host this socket connects to.
 | 
				
			||||||
 | 
					         *  @param port port to connect to.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        init (  const char        * host,
 | 
				
			||||||
 | 
					                unsigned short      port )              throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  De-initialize the object.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        void
 | 
				
			||||||
 | 
					        strip ( void )                                  throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        TcpSocket ( void )                             throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param host name of the host this socket connects to.
 | 
				
			||||||
 | 
					         *  @param port port to connect to.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        TcpSocket(   const char        * host,
 | 
				
			||||||
 | 
					                     unsigned short      port )         throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            init( host, port);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy constructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param ss the TcpSocket to copy.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        TcpSocket(   const TcpSocket &    ss )        throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual
 | 
				
			||||||
 | 
					        ~TcpSocket( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            strip();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param ss the TcpSocket to assign this to.
 | 
				
			||||||
 | 
					         *  @return a reference to this TcpSocket.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual TcpSocket &
 | 
				
			||||||
 | 
					        operator= ( const TcpSocket &    ss )        throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the host this socket connects to.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the host this socket connects to.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline const char *
 | 
				
			||||||
 | 
					        getHost ( void ) const                      throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return host;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Get the port this socket connects to.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return the port this socket connects to.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline unsigned int
 | 
				
			||||||
 | 
					        getPort ( void ) const                      throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return port;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Open the TcpSocket.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if opening was successfull, false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        open ( void )                               throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the TcpSocket is open.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @return true if the TcpSocket is open, false otherwise.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual bool
 | 
				
			||||||
 | 
					        isOpen ( void ) const                       throw ()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return sockfd != 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the TcpScoket can be read from.
 | 
				
			||||||
 | 
					         *  Blocks until the specified time for data to be available.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sec the maximum seconds to block.
 | 
				
			||||||
 | 
					         *  @param usec micro seconds to block after the full seconds.
 | 
				
			||||||
 | 
					         *  @return true if the TcpSocket is ready to be read from,
 | 
				
			||||||
 | 
					         *          false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        canRead (      unsigned int    sec,
 | 
				
			||||||
 | 
					                       unsigned int    usec )       throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Read from the TcpSocket.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param buf the buffer to read into.
 | 
				
			||||||
 | 
					         *  @param len the number of bytes to read into buf
 | 
				
			||||||
 | 
					         *  @return the number of bytes read (may be less than len).
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual unsigned int
 | 
				
			||||||
 | 
					        read (         void          * buf,
 | 
				
			||||||
 | 
					                       unsigned int    len )        throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Check if the TcpSocket is ready to accept data.
 | 
				
			||||||
 | 
					         *  Blocks until the specified time for data to be available.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param sec the maximum seconds to block.
 | 
				
			||||||
 | 
					         *  @param usec micro seconds to block after the full seconds.
 | 
				
			||||||
 | 
					         *  @return true if the TcpSocket is ready to accept data,
 | 
				
			||||||
 | 
					         *          false otherwise.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual bool
 | 
				
			||||||
 | 
					        canWrite (     unsigned int    sec,
 | 
				
			||||||
 | 
					                       unsigned int    usec )       throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Write data to the TcpSocket.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param buf the data to write.
 | 
				
			||||||
 | 
					         *  @param len number of bytes to write from buf.
 | 
				
			||||||
 | 
					         *  @return the number of bytes written (may be less than len).
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual unsigned int
 | 
				
			||||||
 | 
					        write (        const void    * buf,
 | 
				
			||||||
 | 
					                       unsigned int    len )        throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Flush all data that was written to the TcpSocket to the underlying
 | 
				
			||||||
 | 
					         *  connection.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline virtual void
 | 
				
			||||||
 | 
					        flush ( void )                              throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Close the TcpSocket.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual void
 | 
				
			||||||
 | 
					        close ( void )                              throw ( Exception );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* TCP_SOCKET_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/12 14:54:50  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 17:37:24  darkeye
 | 
				
			||||||
 | 
					  removed clone() functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:55  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,209 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Util.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_STRING_H
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need string.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_STDLIB_H
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need stdlib.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_LIMITS_H
 | 
				
			||||||
 | 
					#include <limits.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need limits.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Calculate the length of a zero-terminated C string,
 | 
				
			||||||
 | 
					 *  w/o the zero-termination
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					unsigned int
 | 
				
			||||||
 | 
					Util :: strLen( const char    * str )                   throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    size_t      len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !str ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no str");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    len = strlen( str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return len;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Copy the contents of a string into another
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					Util :: strCpy (    char          * dest,
 | 
				
			||||||
 | 
					                    const char    * src )               throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !dest || !src ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no src or dest");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    strcpy( dest, src);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Concatenate the contents of a string onto another
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					Util :: strCat (    char          * dest,
 | 
				
			||||||
 | 
					                    const char    * src )               throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !dest || !src ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no src or dest");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    strcat( dest, src);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Duplicate a string by allocating space with new[]
 | 
				
			||||||
 | 
					 *  The returned string must be freed with delete[]
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					char *
 | 
				
			||||||
 | 
					Util :: strDup( const char    * str )                   throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    size_t      len;
 | 
				
			||||||
 | 
					    char      * s;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !str ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no str");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    len = strlen( str) + 1;
 | 
				
			||||||
 | 
					    s   = new char[len];
 | 
				
			||||||
 | 
					    memcpy( s, str, len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return s;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Check wether two strings are equal
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					bool
 | 
				
			||||||
 | 
					Util :: strEq( const char    * str1,
 | 
				
			||||||
 | 
					               const char    * str2 )                   throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( !str1 || !str2 ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no str1 or no str2");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return !strcmp( str1, str2);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Convert a string to a long integer
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					long int
 | 
				
			||||||
 | 
					Util :: strToL( const char    * str,
 | 
				
			||||||
 | 
					                int             base )                  throw ( Exception )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    long int    val;
 | 
				
			||||||
 | 
					    char      * s;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( !str ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "no str");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    val = strtol( str, &s, base);
 | 
				
			||||||
 | 
					    if ( s == str || val == LONG_MIN || val == LONG_MAX ) {
 | 
				
			||||||
 | 
					        throw Exception( __FILE__, __LINE__, "number conversion error");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return val;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.6  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.5  2000/11/12 13:31:40  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/09 22:04:33  darkeye
 | 
				
			||||||
 | 
					  added functions strLen strCpy and strCat
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/09 06:44:21  darkeye
 | 
				
			||||||
 | 
					  added strEq and strToL functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/05 14:08:28  darkeye
 | 
				
			||||||
 | 
					  changed builting to an automake / autoconf environment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:55  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,222 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : Util.h
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef UTIL_H
 | 
				
			||||||
 | 
					#define UTIL_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
 | 
					#error This is a C++ include file
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================================ constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =================================================================== macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================== data types */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *  Widely used utilities.
 | 
				
			||||||
 | 
					 *  This class can not be instantiated, but contains useful (?) static
 | 
				
			||||||
 | 
					 *  functions.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Typical usage:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  <pre>
 | 
				
			||||||
 | 
					 *  #include "Util.h"
 | 
				
			||||||
 | 
					 *  
 | 
				
			||||||
 | 
					 *  char  * str = Util::strDup( otherStr);
 | 
				
			||||||
 | 
					 *  </pre>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  @author  $Author$
 | 
				
			||||||
 | 
					 *  @version $Revision$
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class Util
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Default constructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Util ( void )                           throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy constructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        Util ( const Util &   e )               throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Destructor. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline
 | 
				
			||||||
 | 
					        ~Util ( void )                          throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Assignment operator. Always throws an Exception.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param u the object to assign to this one.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        inline Util &
 | 
				
			||||||
 | 
					        operator= ( const Util &   u )          throw ( Exception )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Determine a C string's length.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param str a zero-terminated C string.
 | 
				
			||||||
 | 
					         *  @return length of str
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        static unsigned int
 | 
				
			||||||
 | 
					        strLen (        const char    * str )       throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Copy a C string into another.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param dest place for the copy. Storage size must be at least
 | 
				
			||||||
 | 
					         *              Util::strLen(src) + 1 long.
 | 
				
			||||||
 | 
					         *  @param str the string to copy.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        static void
 | 
				
			||||||
 | 
					        strCpy (    char          * dest,
 | 
				
			||||||
 | 
					                    const char    * src )           throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Concatenate a string to another's end.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param dest the string to concatenate to.
 | 
				
			||||||
 | 
					         *              Storage size of dest must be at least
 | 
				
			||||||
 | 
					         *              Util::strLen(dest) + Util::strLen(src) + 1 long.
 | 
				
			||||||
 | 
					         *  @param str the string to concatenate.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        static void
 | 
				
			||||||
 | 
					        strCat (    char          * dest,
 | 
				
			||||||
 | 
					                    const char    * src )           throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Duplicate a string by allocating space with new[].
 | 
				
			||||||
 | 
					         *  The returned string must be freed with delete[].
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param str the string to duplicate.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        static char *
 | 
				
			||||||
 | 
					        strDup (        const char    * str )       throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Determine wether two string are equal.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param str1 one of the strings.
 | 
				
			||||||
 | 
					         *  @param str2 the other string.
 | 
				
			||||||
 | 
					         *  @return true if the two strings are equal, false othersize.
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        static bool
 | 
				
			||||||
 | 
					        strEq ( const char    * str1,
 | 
				
			||||||
 | 
					                const char    * str2 )               throw ( Exception );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         *  Convert a string to long.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         *  @param str the string to convert.
 | 
				
			||||||
 | 
					         *  @param base numeric base of number in str.
 | 
				
			||||||
 | 
					         *  @return the value of str as a long int
 | 
				
			||||||
 | 
					         *  @exception Exception
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        static long int
 | 
				
			||||||
 | 
					        strToL ( const char    * str,
 | 
				
			||||||
 | 
					                 int             base = 10 )         throw ( Exception );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================= external data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ====================================================== function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /* UTIL_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/12 13:31:40  darkeye
 | 
				
			||||||
 | 
					  added kdoc-style documentation comments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/09 22:04:33  darkeye
 | 
				
			||||||
 | 
					  added functions strLen strCpy and strCat
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/09 06:44:21  darkeye
 | 
				
			||||||
 | 
					  added strEq and strToL functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:55  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,202 @@
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright (c) 2000 Tyrell Corporation. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Tyrell DarkIce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   File     : main.cpp
 | 
				
			||||||
 | 
					   Version  : $Revision$
 | 
				
			||||||
 | 
					   Author   : $Author$
 | 
				
			||||||
 | 
					   Location : $Source$
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   Abstract : 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Program entry point
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Copyright notice:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					    modify it under the terms of the GNU General Public License  
 | 
				
			||||||
 | 
					    as published by the Free Software Foundation; either version 2
 | 
				
			||||||
 | 
					    of the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    This 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, write to the Free Software
 | 
				
			||||||
 | 
					    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ============================================================ include files */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_GETOPT_H
 | 
				
			||||||
 | 
					#include <getopt.h>
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#error need getopt.h
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <iostream.h>
 | 
				
			||||||
 | 
					#include <fstream.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Ref.h"
 | 
				
			||||||
 | 
					#include "Exception.h"
 | 
				
			||||||
 | 
					#include "Util.h"
 | 
				
			||||||
 | 
					#include "DarkIce.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===================================================  local data structures */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ================================================  local constants & macros */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  File identity
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static const char fileid[] = "$Id$";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===============================================  local function prototypes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Show program usage
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					showUsage (     ostream   & os );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =============================================================  module code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Program entry point
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					int
 | 
				
			||||||
 | 
					main (
 | 
				
			||||||
 | 
					    int     argc,
 | 
				
			||||||
 | 
					    char  * argv[] )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int     res = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    cout << "DarkIce " << VERSION
 | 
				
			||||||
 | 
					         << " live audio streamer, http://darkice.sourceforge.net" << endl;
 | 
				
			||||||
 | 
					    cout << "Copyright (c) 2000-2001, Tyrell Hungary, http://tyrell.hu" << endl;
 | 
				
			||||||
 | 
					    cout << endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					        const char    * configFileName = 0;
 | 
				
			||||||
 | 
					        unsigned int    verbosity      = 1;
 | 
				
			||||||
 | 
					        int             i;
 | 
				
			||||||
 | 
					        const char      opts[] = "hc:v:";
 | 
				
			||||||
 | 
					        static struct option long_options[] = {
 | 
				
			||||||
 | 
					            { "config", 1, 0, 'c'},
 | 
				
			||||||
 | 
					            { "help", 0, 0, 'h'},
 | 
				
			||||||
 | 
					            { "verbosity", 1, 0, 'v'},
 | 
				
			||||||
 | 
					            { 0, 0, 0, 0}
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        while ( (i = getopt_long( argc, argv, opts, long_options, 0)) != -1 ) {
 | 
				
			||||||
 | 
					            switch ( i ) {
 | 
				
			||||||
 | 
					                case 'c':
 | 
				
			||||||
 | 
					                    configFileName = optarg;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                case 'v':
 | 
				
			||||||
 | 
					                    verbosity = Util::strToL( optarg);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                default:
 | 
				
			||||||
 | 
					                case ':':
 | 
				
			||||||
 | 
					                case '?':
 | 
				
			||||||
 | 
					                case 'h':
 | 
				
			||||||
 | 
					                    showUsage( cout);
 | 
				
			||||||
 | 
					                    return 1;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( !configFileName ) {
 | 
				
			||||||
 | 
					            showUsage( cout);
 | 
				
			||||||
 | 
					            throw Exception( __FILE__, __LINE__,
 | 
				
			||||||
 | 
					                             "no configuration file specified");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        cout << "Using config file: " << configFileName << endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ifstream            configFile( configFileName);
 | 
				
			||||||
 | 
					        Config              config( configFile);
 | 
				
			||||||
 | 
					        Ref<DarkIce>        di = new DarkIce( config);
 | 
				
			||||||
 | 
					        di->setReportVerbosity( verbosity );
 | 
				
			||||||
 | 
					        di->setReportOutputStream( cout );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        res = di->run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    } catch ( Exception   & e ) {
 | 
				
			||||||
 | 
					        cout << "DarkIce: " << e << endl << flush;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return res;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 *  Show program usage
 | 
				
			||||||
 | 
					 *----------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					showUsage (     ostream   & os )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    os
 | 
				
			||||||
 | 
					    << "usage: darkice -c config.file"
 | 
				
			||||||
 | 
					    << endl
 | 
				
			||||||
 | 
					    << endl
 | 
				
			||||||
 | 
					    << "options:"
 | 
				
			||||||
 | 
					    << endl
 | 
				
			||||||
 | 
					    << "   -c, --config=config.file    use configuration file config.file"
 | 
				
			||||||
 | 
					    << endl
 | 
				
			||||||
 | 
					    << "   -v, --verbosity=number      verbosity level (0 = silent, 10 = loud)"
 | 
				
			||||||
 | 
					    << endl
 | 
				
			||||||
 | 
					    << "   -h, --help                  print this message and exit"
 | 
				
			||||||
 | 
					    << endl
 | 
				
			||||||
 | 
					    << endl;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  $Source$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $Log$
 | 
				
			||||||
 | 
					  Revision 1.8  2001/09/02 12:24:29  darkeye
 | 
				
			||||||
 | 
					  now displays usage info when no command line parameters given
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.7  2001/08/30 17:25:56  darkeye
 | 
				
			||||||
 | 
					  renamed configure.h to config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.6  2001/08/26 08:43:13  darkeye
 | 
				
			||||||
 | 
					  added support for unlimited time encoding
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.5  2000/11/15 18:08:43  darkeye
 | 
				
			||||||
 | 
					  added multiple verbosity-level event reporting and verbosity command
 | 
				
			||||||
 | 
					  line option
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.4  2000/11/13 20:21:29  darkeye
 | 
				
			||||||
 | 
					  added program version display on startup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.3  2000/11/13 19:38:55  darkeye
 | 
				
			||||||
 | 
					  moved command line parameter parsing from DarkIce.cpp to main.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.2  2000/11/08 17:29:50  darkeye
 | 
				
			||||||
 | 
					  added configuration file reader
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Revision 1.1.1.1  2000/11/05 10:05:52  darkeye
 | 
				
			||||||
 | 
					  initial version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					------------------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					timestamp
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#   Update the automake / autoconf configuration
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rm -f config.cache config.log config.status
 | 
				
			||||||
 | 
					rm -f configure config.h aclocal.m4
 | 
				
			||||||
 | 
					rm -f Makefile Makefile.in */Makefile */Makefile.in
 | 
				
			||||||
 | 
					autoheader && automake && aclocal && autoconf && ./configure
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue