movie_item.cc
上传用户:psq1974
上传日期:2007-01-06
资源大小:1195k
文件大小:2k
源码类别:

mpeg/mp3

开发平台:

C/C++

  1. /* Copyright (C) 1998, 1999 State University of New York at Stony Brook
  2.    Author: Andrew V. Shuvalov ( andrew@ecsl.cs.sunysb.edu )
  3.    Software license is located in file "COPYING"
  4. */
  5. #include "movie_item.h"
  6. const MovieFile *MovieItem::findFileByTime( const struct tm &_t ) const
  7. {
  8.   time_t _t_t = mktime( (struct tm *)&_t );
  9.   for( int i = 0; i < movieFiles.size(); i++ )
  10.     {
  11.       const MovieFile &mf = movieFiles[i];
  12.       time_t t = mktime( (struct tm *) &mf.stop );
  13.       if( t < _t_t )
  14. continue;
  15.       time_t t0 = mktime( (struct tm *) &mf.start );
  16.       if( t0 > _t_t )
  17. return NULL;
  18.       return &mf;
  19.     }
  20.   return NULL;
  21. }
  22. void MovieItem::findFileListByTime( const struct tm &_t, MovieFilesT &mfs ) 
  23.   const
  24. {
  25.   const MovieFile *mf = findFileByTime( _t );
  26.   if( !mf )
  27.     return;
  28.   for( int i = 0; i < movieFiles.size(); i++ )
  29.     {
  30.       if( mf != &movieFiles[i] )
  31. continue;
  32.       // copy this file and all next files to mfs
  33.       for( int j = i; j < movieFiles.size(); j++ )
  34. mfs.push_back( movieFiles[j] );
  35.       break;
  36.     }
  37. }
  38. void MovieItem::addMovieFile( const string &fname, int id, 
  39.       const string &ipaddr, int control_port,
  40.       const struct tm &start, const struct tm &stop )
  41. {
  42.   movieFiles.push_back( MovieFile( fname, id, ipaddr, control_port, 
  43.    start, stop ));
  44. }
  45. void MovieItem::filterBestPushServ( const vector< string > &best_ips )
  46. {
  47.   MovieFilesT::iterator it;
  48.   vector< string >::const_iterator s_it;
  49.   string chosen_ip;
  50.   
  51.   for( s_it = best_ips.begin(); s_it != best_ips.end(); s_it++ )
  52.     {
  53.       for( it = movieFiles.begin(); it != movieFiles.end(); it++ )
  54. {
  55.   MovieFile &mf = *it;
  56.   if( mf.ip_is_equal( *s_it ) )
  57.     {
  58.       chosen_ip = *s_it;
  59.       break;
  60.     }
  61. }
  62.       if( chosen_ip.length() )
  63. break;
  64.     }
  65.   // if no preferred ip found just pickup the random one 
  66.   if( !chosen_ip.length() )
  67.     {
  68.       int i = rand() % movieFiles.size();
  69.       chosen_ip = movieFiles[ i ].ipaddress;
  70.     }
  71.   // now drop out everything that is not this selected ip address
  72.   for( it = movieFiles.begin(); it != movieFiles.end(); it++ )
  73.     {
  74.       // i know that not efficient, but this is interactive
  75.       if( false == (*it).ip_is_equal( chosen_ip ) )
  76. it = movieFiles.erase( it );
  77.     }
  78. }