00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef CAST_SINK_H
00030 #define CAST_SINK_H
00031
00032 #ifndef __cplusplus
00033 #error This is a C++ include file
00034 #endif
00035
00036
00037
00038
00039 #include "Ref.h"
00040 #include "Reporter.h"
00041 #include "Sink.h"
00042 #include "TcpSocket.h"
00043 #include "BufferedSink.h"
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00062 class CastSink : public Sink, public virtual Reporter
00063 {
00064 private:
00065
00069 Ref<TcpSocket> socket;
00070
00074 Ref<BufferedSink> bufferedSink;
00075
00079 Ref<Sink> streamDump;
00080
00084 unsigned int bufferDuration;
00085
00089 char * password;
00090
00094 char * name;
00095
00099 char * url;
00100
00104 char * genre;
00105
00109 unsigned int bitRate;
00110
00114 bool isPublic;
00115
00130 void
00131 init ( TcpSocket * socket,
00132 Sink * streamDump,
00133 const char * password,
00134 unsigned int bitRate,
00135 const char * name,
00136 const char * url,
00137 const char * genre,
00138 bool isPublic,
00139 unsigned int bufferDuration )
00140 throw ( Exception );
00141
00147 void
00148 strip ( void ) throw ( Exception );
00149
00150
00151 protected:
00152
00158 inline
00159 CastSink ( void ) throw ( Exception )
00160 {
00161 throw Exception( __FILE__, __LINE__);
00162 }
00163
00170 virtual bool
00171 sendLogin ( void ) throw ( Exception ) = 0;
00172
00178 inline Sink *
00179 getSink ( void ) const throw ()
00180 {
00181 return bufferedSink.get();
00182 }
00183
00189 inline TcpSocket *
00190 getSocket ( void ) const throw ()
00191 {
00192 return socket.get();
00193 }
00194
00195
00196 public:
00197
00213 inline
00214 CastSink ( TcpSocket * socket,
00215 const char * password,
00216 unsigned int bitRate,
00217 const char * name = 0,
00218 const char * url = 0,
00219 const char * genre = 0,
00220 bool isPublic = false,
00221 Sink * streamDump = 0,
00222 unsigned int bufferDuration = 10 )
00223 throw ( Exception )
00224 {
00225 init( socket,
00226 streamDump,
00227 password,
00228 bitRate,
00229 name,
00230 url,
00231 genre,
00232 isPublic,
00233 bufferDuration );
00234 }
00235
00241 inline
00242 CastSink( const CastSink & cs ) throw ( Exception )
00243 : Sink( cs )
00244 {
00245 init( cs.socket.get(),
00246 cs.streamDump.get(),
00247 cs.password,
00248 cs.bitRate,
00249 cs.name,
00250 cs.url,
00251 cs.genre,
00252 cs.isPublic,
00253 cs.bufferDuration );
00254 }
00255
00261 inline virtual
00262 ~CastSink( void ) throw ( Exception )
00263 {
00264 strip();
00265 }
00266
00274 inline virtual CastSink &
00275 operator= ( const CastSink & cs ) throw ( Exception )
00276 {
00277 if ( this != &cs ) {
00278 strip();
00279 Sink::operator=( cs );
00280 init( cs.socket.get(),
00281 cs.streamDump.get(),
00282 cs.password,
00283 cs.bitRate,
00284 cs.name,
00285 cs.url,
00286 cs.genre,
00287 cs.isPublic,
00288 cs.bufferDuration );
00289 }
00290 return *this;
00291 }
00292
00300 virtual bool
00301 open ( void ) throw ( Exception );
00302
00308 inline virtual bool
00309 isOpen ( void ) const throw ()
00310 {
00311 return bufferedSink != NULL ? bufferedSink->isOpen() : false;
00312 }
00313
00324 inline virtual bool
00325 canWrite ( unsigned int sec,
00326 unsigned int usec ) throw ( Exception )
00327 {
00328 return getSink()->canWrite( sec, usec);
00329 }
00330
00339 inline virtual unsigned int
00340 write ( const void * buf,
00341 unsigned int len ) throw ( Exception )
00342 {
00343 if ( streamDump != 0 ) {
00344 streamDump->write( buf, len);
00345 }
00346
00347 return getSink()->write( buf, len);
00348 }
00349
00355 inline virtual void
00356 flush ( void ) throw ( Exception )
00357 {
00358 if ( streamDump != 0 ) {
00359 streamDump->flush();
00360 }
00361
00362 return getSink()->flush();
00363 }
00364
00370 inline virtual void
00371 close ( void ) throw ( Exception )
00372 {
00373 if ( streamDump != 0 ) {
00374 streamDump->close();
00375 }
00376
00377 return getSink()->close();
00378 }
00379
00385 inline const char *
00386 getPassword ( void ) const throw ()
00387 {
00388 return password;
00389 }
00390
00396 inline const char *
00397 getName ( void ) const throw ()
00398 {
00399 return name;
00400 }
00401
00407 inline const char *
00408 getUrl ( void ) const throw ()
00409 {
00410 return url;
00411 }
00412
00418 inline const char *
00419 getGenre ( void ) const throw ()
00420 {
00421 return genre;
00422 }
00423
00429 inline unsigned int
00430 getBitRate ( void ) const throw ()
00431 {
00432 return bitRate;
00433 }
00434
00440 inline bool
00441 getIsPublic ( void ) const throw ()
00442 {
00443 return isPublic;
00444 }
00445
00451 inline unsigned int
00452 getBufferDuration ( void ) const throw ()
00453 {
00454 return bufferDuration;
00455 }
00456 };
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466 #endif
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500