CRioMMObject Class Reference

#include <RioMMObject.h>

Inherited by CRioMMIntSimul, CRioMMKeywords, CRioMMMp3, CRioMMSlideShow, CRioMMTopics, and CRioMMVideo.

Data Structures

struct  RTT

Public Member Functions

 CRioMMObject (char *, unsigned int, RioBlock, struct timeval average_RTT)
virtual ~CRioMMObject ()
int Open (RioAccess, CRioStream *)
bool Read (int, RioBlock, RioStreamType traffic=UNICASTTRAFFIC, int ip=0, int port=0)
bool MulticastRead (RioBlock block, RioStreamType traffic)
 Este metodo faz pedido de blocos para o grupo, diferentemente da ReadBlock, que faz pedido de bloco para um unico usuario (unicast).
void Getmyaddr (int *my_address, int *my_port)
virtual void Prefetch (void)
virtual bool WaitPrefetch (void)
int CanStart (void)
void AllocMedia (int)
bool AddMedia (CRioMMObject *)
void SetBufferStatus (RioBlock, int)
int GetBufferStatus (RioBlock)
char * GetName (void)
void PlayThreadMutexLock (string msg="")
void PlayThreadMutexUnlock (string msg="")
void PlayThreadReleaseCondition (string msg="")
void PlayThreadWaitCondition (string msg="")
int PlayThreadWaitCondition (struct timespec *t, string msg="")
virtual void Play (void)=0
virtual void Stop (void)=0
virtual void Pause (void)=0
virtual void FastRewind (void)=0
virtual void FastForward (void)=0
virtual void SyncMedia (void *)
virtual int Close (void)
virtual void GoTo (RioBlock)=0
virtual int init (void)=0
virtual RioBlock GetCurrentPosition (void)=0
virtual RioBlock GetTotalPositions (void)=0
virtual void inputLog (int, unsigned int=0, unsigned int=0)
virtual unsigned int getCurrentPlayingBlock ()
CRioObjectGetObject ()
int GetNBuffers ()
int GetFullBuffers ()
int GetNMedias ()
CRioMMObjectGetMedia (unsigned)
virtual int ProcessSignal (int, void *)

Static Public Member Functions

static void CallBack (struct RioRequest *request)

Data Fields

int group_block
struct RTT calculete_RTT [30]
unsigned int RTT_average
unsigned int RTT_window
struct timeval sum_RTT

Protected Attributes

CRioObject Object
CRioStream Stream
RioAccess Access
char MMObjectName [MAXPATHSIZE]
pthread_mutex_t PlayThreadMutex
pthread_cond_t PlayThreadCondition
CRioMMObject ** Media
unsigned int nMedias
unsigned int CurMedia
int * BufferStatus
RioRequestRequest
unsigned int BlockSize
RioObjectSize ObjSize
RioBlock TotalBlocks
RioBlock CurrentBlock
RioBlock nBuffers
struct timeval average_RTT
int fullBuffers
BufferStreambufferStream

Detailed Description

Definition at line 52 of file RioMMObject.h.


Constructor & Destructor Documentation

CRioMMObject::CRioMMObject ( char *  mmObjectName,
unsigned int  blocksize,
RioBlock  numBuffers,
struct timeval  average_RTT 
)

Definition at line 41 of file RioMMObject.cpp.

00043 {
00044     fullBuffers        = 0;
00045     CurrentBlock       = 0;
00046     TotalBlocks        = 0;
00047     nMedias            = 0;
00048     CurMedia           = 0;
00049     BlockSize          = blocksize;
00050     group_block        = -1;
00051     Media              = NULL;
00052     ObjSize            = 0;
00053     bufferStream       = NULL;
00054     RTT_average        = 0;
00055     RTT_window         = 0;
00056     gettimeofday( &sum_RTT, 0 );
00057 
00058     nBuffers           = numBuffers;
00059     Request            = new RioRequest[ nBuffers ];
00060     BufferStatus       = new int [nBuffers];
00061 
00062     memcpy( &(this->average_RTT), &average_RTT, sizeof( struct timeval ) );
00063 
00064     for( unsigned int i = 0; i < nBuffers; i++ )
00065     {
00066         Request[i].Size             = BlockSize;
00067         Request[i].Block            = 0;
00068         Request[i].threadid         = 0;
00069         Request[i].session          = 0;
00070         Request[i].fragsnumber      = 0;
00071         Request[i].reqid            = 0;
00072         Request[i].Status           = RIO_REQUEST_FREE;
00073         Request[i].Buffer           = new char[BlockSize];
00074         Request[i].User             = (void*) i;
00075         Request[i].Who              = this;
00076         BufferStatus[i]             = BUFFEREMPTY;
00077         Request[i].CallBackFunction = CRioMMObject::CallBack;
00078     }
00079 
00080     for( unsigned int i = 0; i < 30; i++ )
00081     {
00082          calculete_RTT[ i ].block = 0;
00083     }
00084 
00085     strcpy( MMObjectName, mmObjectName );
00086 
00087     #ifdef RIO_EMUL
00088     duration      = NULL;
00089     finalize_emul = false;
00090     for(int i = 0; i < 15000; i++) clrblk( i );
00091     #endif
00092 
00093     pthread_mutex_init( &PlayThreadMutex, NULL );
00094     pthread_cond_init( &PlayThreadCondition, NULL );
00095 
00096     srand( time( NULL ) );
00097 }

CRioMMObject::~CRioMMObject (  )  [virtual]

Definition at line 100 of file RioMMObject.cpp.

00101 {
00102     if( Request )
00103     {
00104         for( RioBlock i = 0; i < nBuffers; i++ )
00105         {
00106             // FIXME: O Buffer deve ser desalocado, mas se for desalocado neste
00107             // ponto a RioNeti pode tentar escrever no buffer e acontece
00108             // um Segmentation fault.
00109             //if( Request[i].Buffer )
00110                 //delete [](char*)Request[i].Buffer;
00111         }
00112         delete[] Request;
00113     }
00114     delete[] BufferStatus;
00115 
00116     if( nMedias )
00117     {
00118        for( unsigned int i = 0; i < nMedias; i++ )
00119            delete Media[i];
00120         delete[] Media;
00121     }
00122 }


Member Function Documentation

bool CRioMMObject::AddMedia ( CRioMMObject media  ) 

Definition at line 408 of file RioMMObject.cpp.

00409 {
00410     bool status;
00411 
00412     status = false;
00413     if( CurMedia < nMedias )
00414     {
00415         Media[ CurMedia++ ] = media;
00416         status = true;
00417     }
00418 
00419     return( status );
00420 }

void CRioMMObject::AllocMedia ( int  qtdMedias  ) 

Definition at line 396 of file RioMMObject.cpp.

00397 {
00398     if( nMedias )
00399         delete[] Media;
00400 
00401     CurMedia = 0;
00402     nMedias  = qtdMedias;
00403     if( nMedias )
00404         Media = new CRioMMObject *[ nMedias ];
00405 }

void CRioMMObject::CallBack ( struct RioRequest request  )  [static]

Reimplemented in CRioMMVideo.

Definition at line 485 of file RioMMObject.cpp.

00486 {
00487     CRioMMObject *ptr;
00488 
00489     #ifdef RIO_DEBUG2
00490     RioErr << "[RioMMObject] CallBack" << endl;
00491     #endif
00492 
00493     //FIXME: If I test it now, the player will block cause
00494     //       it is not ready to skip blocks right now.
00495     //    if( request->Result )
00496     {
00497         #ifdef RANDOM_LOSS
00498         if( rand()<(RAND_MAX/2) )
00499         {
00500         }
00501         else
00502         #endif
00503         {
00504             ptr = (CRioMMObject *)request->Who;
00505             ptr->SetBufferStatus( (int) (long long int) request->User, BUFFERFULL );
00506 
00507             #ifdef RIO_DEBUG2
00508             RioErr << "(Callback) BLOCK: " << request->User << endl;
00509             #endif
00510         }
00511     }
00512 }

int CRioMMObject::CanStart ( void   ) 

Definition at line 389 of file RioMMObject.cpp.

00390 {
00391     int status = Stream.CanStart();
00392 
00393     return status;
00394 }

int CRioMMObject::Close ( void   )  [virtual]

Definition at line 202 of file RioMMObject.cpp.

00203 {
00204     int closed;
00205 
00206     #ifndef RIO_EMUL
00207     for( unsigned int i = 0; i < nMedias; i++ )
00208         Media[i]->Close();
00209     #endif
00210 
00211     closed = Object.Close();
00212 
00213     #ifdef RIO_DEBUG2
00214     RioErr << "[CRioMMObject] Object Close [" << closed << "]" << endl;
00215     #endif
00216 
00217     return( closed );
00218 }

virtual void CRioMMObject::FastForward ( void   )  [pure virtual]
virtual void CRioMMObject::FastRewind ( void   )  [pure virtual]
int CRioMMObject::GetBufferStatus ( RioBlock  block  ) 

Definition at line 474 of file RioMMObject.cpp.

00475 {
00476     return( BufferStatus[ block % nBuffers ] );
00477 }

unsigned int CRioMMObject::getCurrentPlayingBlock (  )  [virtual]

Reimplemented in CRioMMVideo.

Definition at line 530 of file RioMMObject.cpp.

00531 {
00532     return 0;
00533 }

virtual RioBlock CRioMMObject::GetCurrentPosition ( void   )  [pure virtual]
int CRioMMObject::GetFullBuffers (  ) 

Definition at line 479 of file RioMMObject.cpp.

00480 {
00481     return fullBuffers;
00482 }

CRioMMObject * CRioMMObject::GetMedia ( unsigned  n  ) 

Definition at line 520 of file RioMMObject.cpp.

00521 {
00522     return Media[ n ];
00523 }

void CRioMMObject::Getmyaddr ( int *  my_address,
int *  my_port 
)

Definition at line 124 of file RioMMObject.cpp.

00125 {
00126      Object.Getmyaddr( my_address, my_port );
00127 }

char * CRioMMObject::GetName ( void   ) 

Definition at line 156 of file RioMMObject.cpp.

00157 {
00158     return( MMObjectName );
00159 }

int CRioMMObject::GetNBuffers (  ) 

Definition at line 150 of file RioMMObject.cpp.

00151 {
00152     return nBuffers;
00153 }

int CRioMMObject::GetNMedias (  ) 

Definition at line 515 of file RioMMObject.cpp.

00516 {
00517     return nMedias;
00518 }

CRioObject * CRioMMObject::GetObject (  ) 

Definition at line 162 of file RioMMObject.cpp.

00163 {
00164     return( &Object );
00165 }

virtual RioBlock CRioMMObject::GetTotalPositions ( void   )  [pure virtual]
virtual void CRioMMObject::GoTo ( RioBlock   )  [pure virtual]

Implemented in CRioMMMp3, CRioMMSlideShow, and CRioMMVideo.

virtual int CRioMMObject::init ( void   )  [pure virtual]
void CRioMMObject::inputLog ( int  action,
unsigned int  block = 0,
unsigned int  size = 0 
) [virtual]

Reimplemented in CRioMMVideo.

Definition at line 526 of file RioMMObject.cpp.

00527 {
00528 }

bool CRioMMObject::MulticastRead ( RioBlock  block,
RioStreamType  traffic 
)

Este metodo faz pedido de blocos para o grupo, diferentemente da ReadBlock, que faz pedido de bloco para um unico usuario (unicast).

Definition at line 224 of file RioMMObject.cpp.

00225 {
00226     bool status = false;
00227     int sendack = 0;
00228 
00229     #ifdef RIO_DEBUG2
00230     RioErr << "[RioMMObject MulticastRead] Pedido realizado para bloco "
00231            << block << " traffic: " << traffic << endl;
00232     #endif
00233 
00234     RioResult hResult = Object.MulticastStreamRead( block, sendack, traffic );
00235 
00236     if( FAILED( hResult ) )
00237     {
00238         RioErr << "[CRioMMObject] \tUnexpected MMObject error "
00239                << "while reading object." << endl;
00240     }
00241     else
00242     {
00243         status = true;
00244     }
00245 
00246     #ifdef RIO_EMUL
00247     if( tstblk( block ) )
00248     {
00249         RioErr << "[RioMMObject MulticastRead] Bloco " << block << " requisitado "
00250                << "mais de uma vez" << endl;
00251     }
00252     else
00253     {
00254         setblk( block );
00255     }
00256     #endif
00257 
00258     return( status );
00259 }

int CRioMMObject::Open ( RioAccess  access,
CRioStream Stream 
)

Definition at line 168 of file RioMMObject.cpp.

00169 {
00170     int rc;
00171 
00172     Access = access;
00173 
00174     ofstream m_log;
00175 
00176     rc = Object.Open( MMObjectName, Access, average_RTT, (int) nBuffers,
00177                       Stream, m_log);
00178 
00179     if( rc >= 0 )
00180     {
00181         // Find out total block number
00182         rc = Object.GetSize( &ObjSize );
00183         TotalBlocks = (int)(( (ObjSize - 1)/BlockSize ) + 1);
00184     }
00185     #ifdef RIO_DEBUG2
00186     else
00187     {
00188         RioErr << "[RioMMObject] Open: N�o foi poss�vel abrir objeto "
00189                << MMObjectName <<  ":" << GetErrorDescription( rc ) << endl;
00190     }
00191     #endif
00192 
00193     #ifndef RIO_EMUL
00194     for( unsigned int i = 0; i < nMedias; i++ )
00195         Media[i]->Open( Access, Stream );
00196     #endif
00197 
00198     return( rc );
00199 }

virtual void CRioMMObject::Pause ( void   )  [pure virtual]
virtual void CRioMMObject::Play ( void   )  [pure virtual]
void CRioMMObject::PlayThreadMutexLock ( string  msg = ""  ) 

Definition at line 535 of file RioMMObject.cpp.

00536 {
00537     #ifdef RIO_DEBUG2
00538     if( msg.length() )
00539         RioErr << "[PlayThreadMutexLock] " << msg << "... " << endl;
00540     #endif
00541 
00542     pthread_mutex_lock( &PlayThreadMutex );
00543 
00544     #ifdef RIO_DEBUG2
00545     if( msg.length() )
00546         RioErr << "..." << msg << " OK!" << endl;
00547     #endif
00548 }

void CRioMMObject::PlayThreadMutexUnlock ( string  msg = ""  ) 

Definition at line 550 of file RioMMObject.cpp.

00551 {
00552     #ifdef RIO_DEBUG2
00553     if( msg.length() )
00554         RioErr << "[PlayThreadMutexUnlock] " << msg << endl;
00555     #endif
00556 
00557     pthread_mutex_unlock( &PlayThreadMutex );
00558 }

void CRioMMObject::PlayThreadReleaseCondition ( string  msg = ""  ) 

Definition at line 593 of file RioMMObject.cpp.

00594 {
00595     pthread_cond_broadcast( &PlayThreadCondition );
00596 }

int CRioMMObject::PlayThreadWaitCondition ( struct timespec *  t,
string  msg = "" 
)

Definition at line 575 of file RioMMObject.cpp.

00576 {
00577     #ifdef RIO_DEBUG2
00578     if( msg.length() )
00579         RioErr << "[PlayThreadWaitCondition] " << msg << "... " << endl;
00580     #endif
00581 
00582     int rc = pthread_cond_timedwait( &PlayThreadCondition, 
00583                                      &PlayThreadMutex, t );
00584 
00585     #ifdef RIO_DEBUG2
00586     if( msg.length() )
00587         RioErr << "..." << msg << " OK!" << endl;
00588     #endif
00589 
00590     return rc;
00591 }

void CRioMMObject::PlayThreadWaitCondition ( string  msg = ""  ) 

Definition at line 560 of file RioMMObject.cpp.

00561 {
00562     #ifdef RIO_DEBUG2
00563     if( msg.length() )
00564         RioErr << "[PlayThreadWaitCondition] " << msg << "... " << endl;
00565     #endif
00566 
00567     pthread_cond_wait( &PlayThreadCondition, &PlayThreadMutex );
00568 
00569     #ifdef RIO_DEBUG2
00570     if( msg.length() )
00571         RioErr << "..." << msg << " OK!" << endl;
00572     #endif
00573 }

void CRioMMObject::Prefetch ( void   )  [virtual]

Reimplemented in CRioMMVideo.

Definition at line 330 of file RioMMObject.cpp.

00331 {
00332     RioBlock Block = 0;
00333     bool status    = true;
00334 
00335     while( Block < nBuffers )
00336     {
00337         status = status && Read( (int)Block, Block );
00338         Block++;
00339     }
00340 
00341     for( unsigned int i = 0; i < nMedias; i++ )
00342         Media[i]->Prefetch();
00343 }

int CRioMMObject::ProcessSignal ( int  sig,
void *  data 
) [virtual]

Reimplemented in CRioMMBrowser, CRioMMTgif, and CRioMMVideo.

Definition at line 452 of file RioMMObject.cpp.

00453 {
00454     return( 0 );
00455 }

bool CRioMMObject::Read ( int  buffer,
RioBlock  block,
RioStreamType  traffic = UNICASTTRAFFIC,
int  ip = 0,
int  port = 0 
)

Definition at line 262 of file RioMMObject.cpp.

00264 {
00265     bool status = false;
00266     int sendack = 0;
00267 
00268     if( block < TotalBlocks )
00269     {
00270         Request[buffer].Block  = block;
00271         Request[buffer].Result = S_OK;
00272         Request[buffer].Status = RIO_REQUEST_FREE;
00273         Request[buffer].Who    = this;
00274         Request[buffer].reqid  = -1;
00275         Request[buffer].Size   = BlockSize;
00276 
00277         #ifdef RIO_DEBUG2
00278         RioErr << "[RioMMObject Read] Pedido realizado para bloco " << block
00279                << " traffic: ";
00280         if( traffic == UNICASTTRAFFIC )
00281             RioErr << "UNICAST";
00282         else
00283             RioErr << "MULTICAST";
00284 
00285         RioErr << ", port " << port << endl;
00286         #endif
00287 
00288         //Object � do tipo RioObject
00289         RioResult hResult = Object.StreamRead( &Request[buffer], sendack,
00290                                                traffic, ip, port );
00291 
00292         if( FAILED( hResult ) )
00293         {
00294             #ifdef RIO_DEBUG2
00295             RioErr << "[CRioMMObject] \tUnexpected MMObject error "
00296                    << "while reading object." << endl;
00297             #endif
00298 
00299             status = false;
00300             //abort();
00301         }
00302         else
00303         {
00304             status = true;
00305         }
00306 
00307         if( ( bufferStream != NULL ) && ( traffic == UNICASTTRAFFIC ) )
00308 
00309         {
00310             bufferStream->setUnicast( block );
00311         }
00312 
00313         #ifdef RIO_EMUL
00314         if( tstblk( block ) )
00315         {
00316             RioErr << "[RioMMObject Read] Bloco " << block << " requisitado "
00317                    << "mais de uma vez" << endl;
00318         }
00319         else
00320         {
00321             setblk( block );
00322         }
00323         #endif
00324     }
00325 
00326     return( status );
00327 }

void CRioMMObject::SetBufferStatus ( RioBlock  block,
int  status 
)

Definition at line 457 of file RioMMObject.cpp.

00458 {
00459     PlayThreadMutexLock( "sebufst1" );
00460 
00461     BufferStatus[ block % nBuffers ] = status;
00462     if( status == BUFFERFULL )
00463     {
00464         fullBuffers++;
00465         PlayThreadReleaseCondition( "sebufst1" );
00466     }
00467     else
00468         fullBuffers--;
00469 
00470     PlayThreadMutexUnlock( "sebufst1" );
00471 }

void CRioMMObject::Stop ( void   )  [pure virtual]

Implemented in CRioMMBrowser, CRioMMEmbed, CRioMMIntSimul, CRioMMKeywords, CRioMMMp3, CRioMMSlideShow, CRioMMTgif, CRioMMTopics, and CRioMMVideo.

Definition at line 430 of file RioMMObject.cpp.

00431 {
00432     unsigned int i;
00433 
00434     for( i = 0; i < nBuffers; i++ )
00435     {
00436         Request[i].User = (void*) i;
00437         BufferStatus[i] = BUFFEREMPTY;
00438     }
00439 
00440     #ifndef RIO_EMUL
00441     for( i = 0; i < nMedias; i++ )
00442         Media[i]->Stop();
00443     #endif
00444 }

void CRioMMObject::SyncMedia ( void *  param  )  [virtual]

Reimplemented in CRioMMIntSimul, and CRioMMSlideShow.

Definition at line 423 of file RioMMObject.cpp.

00424 {
00425     for( unsigned int i = 0; i < nMedias; i++ )
00426         Media[i]->SyncMedia( param );
00427 }

bool CRioMMObject::WaitPrefetch ( void   )  [virtual]

Reimplemented in CRioMMVideo.

Definition at line 346 of file RioMMObject.cpp.

00347 {
00348     bool         WaitingPrefetch;
00349     unsigned int numPrefetchBlocks;
00350 
00351     PlayThreadMutexLock( "ROwtpr1" );
00352 
00353     numPrefetchBlocks = (nBuffers < TotalBlocks) ? nBuffers : TotalBlocks;
00354 
00355     do
00356     {
00357         WaitingPrefetch = false;
00358         for( unsigned int i = 0; i < numPrefetchBlocks; i++ )
00359         {
00360             if( BufferStatus[i] == BUFFEREMPTY )
00361             {
00362                 #ifdef RIO_DEBUG2
00363                 RioErr << "WaitPrefetch - Buffer Empty. Posicao: " << i << endl;
00364                 #endif
00365 
00366                 WaitingPrefetch = true;
00367             }
00368         }
00369 
00370         if( WaitingPrefetch )
00371             PlayThreadWaitCondition( "ROwtpr1" );
00372     }
00373     while( WaitingPrefetch );
00374 
00375     PlayThreadMutexUnlock( "ROwtpr1" );
00376 
00377     #ifdef RIO_DEBUG2
00378     RioErr << "Saindo da waitprefetch " << endl;
00379     #endif
00380 
00381     #ifndef RIO_EMUL
00382     for( unsigned int i = 0; i < nMedias; i++ )
00383         Media[i]->WaitPrefetch();
00384     #endif
00385 
00386     return( true );
00387 }


Field Documentation

Definition at line 58 of file RioMMObject.h.

struct timeval CRioMMObject::average_RTT [protected]

Definition at line 77 of file RioMMObject.h.

unsigned int CRioMMObject::BlockSize [protected]

Definition at line 67 of file RioMMObject.h.

int* CRioMMObject::BufferStatus [protected]

Definition at line 65 of file RioMMObject.h.

Definition at line 79 of file RioMMObject.h.

Definition at line 183 of file RioMMObject.h.

unsigned int CRioMMObject::CurMedia [protected]

Definition at line 64 of file RioMMObject.h.

Definition at line 70 of file RioMMObject.h.

int CRioMMObject::fullBuffers [protected]

Definition at line 78 of file RioMMObject.h.

Definition at line 83 of file RioMMObject.h.

Definition at line 62 of file RioMMObject.h.

char CRioMMObject::MMObjectName[MAXPATHSIZE] [protected]

Definition at line 59 of file RioMMObject.h.

Definition at line 71 of file RioMMObject.h.

unsigned int CRioMMObject::nMedias [protected]

Definition at line 63 of file RioMMObject.h.

Definition at line 56 of file RioMMObject.h.

Definition at line 68 of file RioMMObject.h.

pthread_cond_t CRioMMObject::PlayThreadCondition [protected]

Definition at line 61 of file RioMMObject.h.

pthread_mutex_t CRioMMObject::PlayThreadMutex [protected]

Definition at line 60 of file RioMMObject.h.

Definition at line 66 of file RioMMObject.h.

Definition at line 184 of file RioMMObject.h.

Definition at line 185 of file RioMMObject.h.

Reimplemented in CRioMMVideo.

Definition at line 57 of file RioMMObject.h.

struct timeval CRioMMObject::sum_RTT

Definition at line 186 of file RioMMObject.h.

Definition at line 69 of file RioMMObject.h.


The documentation for this class was generated from the following files:
Generated on Wed Jul 4 16:03:32 2012 for RIO by  doxygen 1.6.3