Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

CastSink.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 
00003    Copyright (c) 2000 Tyrell Corporation. All rights reserved.
00004 
00005    Tyrell DarkIce
00006 
00007    File     : CastSink.cpp
00008    Version  : $Revision: 1.9 $
00009    Author   : $Author: darkeye $
00010    Location : $Source: /cvsroot/darkice/darkice/src/CastSink.cpp,v $
00011    
00012    Copyright notice:
00013 
00014     This program is free software; you can redistribute it and/or
00015     modify it under the terms of the GNU General Public License  
00016     as published by the Free Software Foundation; either version 2
00017     of the License, or (at your option) any later version.
00018    
00019     This program is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of 
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00022     GNU General Public License for more details.
00023    
00024     You should have received a copy of the GNU General Public License
00025     along with this program; if not, write to the Free Software
00026     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028 ------------------------------------------------------------------------------*/
00029 
00030 /* ============================================================ include files */
00031 
00032 #include "Util.h"
00033 #include "Exception.h"
00034 #include "CastSink.h"
00035 
00036 
00037 /* ===================================================  local data structures */
00038 
00039 
00040 /* ================================================  local constants & macros */
00041 
00042 /*------------------------------------------------------------------------------
00043  *  File identity
00044  *----------------------------------------------------------------------------*/
00045 static const char fileid[] = "$Id: CastSink.cpp,v 1.9 2002/04/09 13:10:43 darkeye Exp $";
00046 
00047 
00048 /* ===============================================  local function prototypes */
00049 
00050 
00051 /* =============================================================  module code */
00052 
00053 /*------------------------------------------------------------------------------
00054  *  Initialize the object
00055  *----------------------------------------------------------------------------*/
00056 void
00057 CastSink :: init (  TcpSocket             * socket,
00058                     Sink                  * streamDump,
00059                     const char            * password,
00060                     unsigned int            bitRate,
00061                     const char            * name,
00062                     const char            * url,
00063                     const char            * genre,
00064                     bool                    isPublic,
00065                     unsigned int            bufferDuration )
00066                                                         throw ( Exception )
00067 {
00068     this->socket         = socket;
00069     this->streamDump     = streamDump;
00070     this->password       = password       ? Util::strDup( password) : 0;
00071     this->bitRate        = bitRate;
00072     this->name           = name           ? Util::strDup( name)     : 0;
00073     this->url            = url            ? Util::strDup( url)      : 0;
00074     this->genre          = genre          ? Util::strDup( genre)    : 0;
00075     this->isPublic       = isPublic;
00076     this->bufferDuration = bufferDuration;
00077 
00078     int       bufferSize = bitRate ? (bitRate * 1024 / 8) * bufferDuration
00079                                    : (128 * 1024 / 8) * bufferDuration;
00080 
00081     bufferedSink = socket ?  new BufferedSink( socket, bufferSize)
00082                           : 0;
00083 }
00084 
00085 
00086 /*------------------------------------------------------------------------------
00087  *  De-initialize the object
00088  *----------------------------------------------------------------------------*/
00089 void
00090 CastSink :: strip ( void )                          throw ( Exception )
00091 {
00092     if ( isOpen() ) {
00093         close();
00094     }
00095 
00096     if ( password ) {
00097         delete[] password;
00098     }
00099     if ( name ) {
00100         delete[] name;
00101     }
00102     if ( url ) {
00103         delete[] url;
00104     }
00105     if ( genre ) {
00106         delete[] genre;
00107     }
00108 }
00109 
00110 
00111 /*------------------------------------------------------------------------------
00112  *  Open the connection
00113  *----------------------------------------------------------------------------*/
00114 bool
00115 CastSink :: open ( void )                       throw ( Exception )
00116 {
00117     if ( isOpen() ) {
00118         return false;
00119     }
00120 
00121     if ( !bufferedSink->open() ) {
00122         return false;
00123     }
00124 
00125     if ( !sendLogin() ) {
00126         close();
00127         return false;
00128     }
00129 
00130     if ( streamDump != 0 ) {
00131         if ( !streamDump->isOpen() ) {
00132             if ( !streamDump->open() ) {
00133                 reportEvent( 2, "can't open stream dump");
00134             }
00135         }
00136     }
00137     
00138     return true;
00139 }
00140 
00141 
00142 
00143 /*------------------------------------------------------------------------------
00144  
00145   $Source: /cvsroot/darkice/darkice/src/CastSink.cpp,v $
00146 
00147   $Log: CastSink.cpp,v $
00148   Revision 1.9  2002/04/09 13:10:43  darkeye
00149   resolved memory leak issue introduced in 0.9
00150 
00151   Revision 1.8  2002/03/28 16:40:55  darkeye
00152   slight changes to allow for variable bitrate streams
00153   (where the value of bitrate is 0)
00154 
00155   Revision 1.7  2002/02/28 09:49:25  darkeye
00156   added possibility to save the encoded stream to a local file only
00157   (no streaming server needed)
00158 
00159   Revision 1.6  2002/02/20 11:54:11  darkeye
00160   added local dump file possibility
00161 
00162   Revision 1.5  2001/09/09 11:27:31  darkeye
00163   added support for ShoutCast servers
00164 
00165   Revision 1.4  2001/08/29 21:08:30  darkeye
00166   made some description options in the darkice config file optional
00167 
00168   Revision 1.3  2000/11/12 14:54:50  darkeye
00169   added kdoc-style documentation comments
00170 
00171   Revision 1.2  2000/11/10 20:14:11  darkeye
00172   added support for remote dump file
00173 
00174   Revision 1.1.1.1  2000/11/05 10:05:48  darkeye
00175   initial version
00176 
00177   
00178 ------------------------------------------------------------------------------*/
00179 

Generated on Thu Apr 14 13:59:12 2005 for DarkIce by  doxygen 1.4.1