1 /*------------------------------------------------------------------------------
2 
3    Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved.
4 
5    Tyrell DarkIce
6 
7    File     : IceCast2.h
8    Version  : $Revision$
9    Author   : $Author$
10    Location : $HeadURL$
11 
12    Copyright notice:
13 
14     This program is free software; you can redistribute it and/or
15     modify it under the terms of the GNU General Public License
16     as published by the Free Software Foundation; either version 3
17     of the License, or (at your option) any later version.
18 
19     This program is distributed in the hope that it will be useful,
20     but WITHOUT ANY WARRANTY; without even the implied warranty of
21     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22     GNU General Public License for more details.
23 
24     You should have received a copy of the GNU General Public License
25     along with this program; if not, write to the Free Software
26     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27 
28 ------------------------------------------------------------------------------*/
29 #ifndef ICE_CAST2_H
30 #define ICE_CAST2_H
31 
32 #ifndef __cplusplus
33 #error This is a C++ include file
34 #endif
35 
36 
37 /* ============================================================ include files */
38 
39 #include "Sink.h"
40 #include "TcpSocket.h"
41 #include "CastSink.h"
42 
43 
44 /* ================================================================ constants */
45 
46 
47 /* =================================================================== macros */
48 
49 
50 /* =============================================================== data types */
51 
52 /**
53  *  Class representing output to an IceCast2 server with
54  *  ice login
55  *
56  *  @author  $Author$
57  *  @version $Revision$
58  */
59 class IceCast2 : public CastSink
60 {
61     public:
62 
63         /**
64          *  Type for specifying the format of the stream.
65          */
66        enum StreamFormat { mp3, mp2, oggVorbis, oggOpus, aac, aacp };
67 
68 
69     private:
70 
71         /**
72          *  The format of the stream.
73          */
74         StreamFormat        format;
75 
76         /**
77          *  Mount point of the stream on the server.
78          */
79         char              * mountPoint;
80 
81         /**
82          *  Description of the stream.
83          */
84         char              * description;
85 
86         /**
87          *  Initalize the object.
88          *
89          *  @param mountPoint mount point of the stream on the server.
90          *  @param remoteDumpFile remote dump file (may be NULL).
91          *  @param description description of the stream.
92          *  @exception Exception
93          */
94         void
95         init (  StreamFormat            format,
96                 const char            * mountPoint,
97                 const char            * description )
98                                                     throw ( Exception );
99 
100         /**
101          *  De-initalize the object.
102          *
103          *  @exception Exception
104          */
105         void
106         strip ( void )                              throw ( Exception );
107 
108 
109     protected:
110 
111         /**
112          *  Default constructor. Always throws an Exception.
113          *
114          *  @exception Exception
115          */
116         inline
IceCast2(void)117         IceCast2 ( void )                            throw ( Exception )
118         {
119             throw Exception( __FILE__, __LINE__);
120         }
121 
122         /**
123          *  Log in to the server using the socket avialable.
124          *
125          *  @return true if login was successful, false otherwise.
126          *  @exception Exception
127          */
128         virtual bool
129         sendLogin ( void )              throw ( Exception );
130 
131 
132     public:
133 
134         /**
135          *  Constructor.
136          *
137          *  @param socket socket connection to the server.
138          *  @param password password to the server.
139          *  @param mountPoint mount point of the stream on the server.
140          *  @param format the format of the stream.
141          *  @param name name of the stream.
142          *  @param description description of the stream.
143          *  @param url URL associated with the stream.
144          *  @param genre genre of the stream.
145          *  @param bitRate bitrate of the stream (e.g. mp3 bitrate).
146          *  @param isPublic is the stream public?
147          *  @param streamDump an optional sink to dump the binary stream
148          *                    data to.
149          *  @param bufferDuration duration of the BufferedSink buffer
150          *                        in seconds.
151          *  @exception Exception
152          */
153         inline
154         IceCast2 (  TcpSocket         * socket,
155                     const char        * password,
156                     const char        * mountPoint,
157                     StreamFormat        format,
158                     unsigned int        bitRate,
159                     const char        * name           = 0,
160                     const char        * description    = 0,
161                     const char        * url            = 0,
162                     const char        * genre          = 0,
163                     bool                isPublic       = false,
164                     Sink              * streamDump     = 0 )
throw(Exception)165                                                         throw ( Exception )
166               : CastSink( socket,
167                           password,
168                           bitRate,
169                           name,
170                           url,
171                           genre,
172                           isPublic,
173                           streamDump )
174         {
175             init( format, mountPoint, description);
176         }
177 
178         /**
179          *  Copy constructor.
180          *
181          *  @param cs the IceCast2 to copy.
182          */
183         inline
throw(Exception)184         IceCast2(   const IceCast2 &    cs )        throw ( Exception )
185                 : CastSink( cs )
186         {
187             init( cs.getFormat(),
188                   cs.getMountPoint(),
189                   cs.getDescription() );
190         }
191 
192         /**
193          *  Destructor.
194          *
195          *  @exception Exception
196          */
197         inline virtual
~IceCast2(void)198         ~IceCast2( void )                           throw ( Exception )
199         {
200             strip();
201         }
202 
203         /**
204          *  Assignment operator.
205          *
206          *  @param cs the IceCast2 to assign this to.
207          *  @return a reference to this IceCast2.
208          *  @exception Exception
209          */
210         inline virtual IceCast2 &
throw(Exception)211         operator= ( const IceCast2 &    cs )        throw ( Exception )
212         {
213             if ( this != &cs ) {
214                 strip();
215                 CastSink::operator=( cs );
216                 init( cs.getFormat(),
217                       cs.getMountPoint(),
218                       cs.getDescription() );
219             }
220             return *this;
221         }
222 
223         /**
224          *  Get the format of the stream.
225          *
226          *  @return the format of the stream.
227          */
228         inline StreamFormat
getFormat(void)229         getFormat ( void ) const                    throw ()
230         {
231             return format;
232         }
233 
234         /**
235          *  Get the mount point of the stream on the server.
236          *
237          *  @return the mount point of the stream on the server.
238          */
239         inline const char *
getMountPoint(void)240         getMountPoint ( void ) const                throw ()
241         {
242             return mountPoint;
243         }
244 
245         /**
246          *  Get the description of the stream.
247          *
248          *  @return the description of the stream.
249          */
250         inline const char *
getDescription(void)251         getDescription ( void ) const               throw ()
252         {
253             return description;
254         }
255 
256 };
257 
258 
259 /* ================================================= external data structures */
260 
261 
262 /* ====================================================== function prototypes */
263 
264 
265 
266 #endif  /* ICE_CAST2_H */
267 
268