00001 00032 #include "llmediaimplexample2.h" 00033 #include "llmediaimplregister.h" 00034 00035 // register this impl with media manager factory 00036 static LLMediaImplRegister sLLMediaImplExample2Reg( "LLMediaImplExample2", new LLMediaImplExample2Maker() ); 00037 00038 #include <iostream> 00039 #include <time.h> 00040 00042 // 00043 LLMediaImplExample2Maker::LLMediaImplExample2Maker() 00044 { 00045 // Register to handle the scheme 00046 mSchema.push_back( "example2" ); 00047 } 00048 00050 // 00051 LLMediaImplExample2::LLMediaImplExample2() : 00052 mMediaPixels( 0 ) 00053 { 00054 setRequestedMediaSize( 500, 500 ); 00055 setMediaDepth( 3 ); 00056 00057 mXpos = ( getMediaWidth() / 2 ) + rand() % ( getMediaWidth() / 16 ) - ( getMediaWidth() / 32 ); 00058 mYpos = ( getMediaHeight() / 2 ) + rand() % ( getMediaHeight() / 16 ) - ( getMediaHeight() / 32 ); 00059 00060 srand( (unsigned int)(time( NULL )) ); 00061 } 00062 00064 // (static) super-initialization - called once at application startup 00065 bool LLMediaImplExample2::startup( LLMediaManagerData* init_data ) 00066 { 00067 return true; 00068 } 00069 00071 // (static) super-uninitialization - called once at application closedown 00072 bool LLMediaImplExample2::closedown() 00073 { 00074 return true; 00075 } 00076 00078 // virtual 00079 bool LLMediaImplExample2::init() 00080 { 00081 int buffer_size = getMediaBufferSize(); 00082 00083 mMediaPixels = new unsigned char[ buffer_size ]; 00084 00085 memset( mMediaPixels, 0x00, buffer_size ); 00086 00087 return true; 00088 } 00089 00091 // virtual 00092 bool LLMediaImplExample2::navigateTo( const std::string url ) 00093 { 00094 std::cout << "LLMediaImplExample2::navigateTo" << std::endl; 00095 00096 setStatus( LLMediaBase::STATUS_NAVIGATING ); 00097 00098 // force a size change event for new URL 00099 LLMediaEvent event( this ); 00100 mEventEmitter.update( &LLMediaObserver::onMediaSizeChange, event ); 00101 00102 return true; 00103 } 00104 00106 // virtual 00107 std::string LLMediaImplExample2::getVersion() 00108 { 00109 std::string version_string = "[" + sLLMediaImplExample2Reg.getImplName() + "] - " + "1.0.0.0"; 00110 00111 return version_string; 00112 } 00113 00115 // virtual 00116 bool LLMediaImplExample2::updateMedia() 00117 { 00118 if ( mMediaPixels && getStatus() == LLMediaBase::STATUS_STARTED ) 00119 { 00120 static int x_inc = rand() % 5 + 2; 00121 static int y_inc = rand() % 5 + 2; 00122 int block_size = 32; 00123 00124 for( int y = 0; y < block_size; ++y ) 00125 { 00126 for( int x = 0; x < block_size; ++x ) 00127 { 00128 int rowspan = getMediaWidth() * getMediaDepth(); 00129 mMediaPixels[ ( mXpos + x ) * getMediaDepth() + ( mYpos + y ) * rowspan + 0 ] = 0; 00130 mMediaPixels[ ( mXpos + x ) * getMediaDepth() + ( mYpos + y ) * rowspan + 1 ] = 0; 00131 mMediaPixels[ ( mXpos + x ) * getMediaDepth() + ( mYpos + y ) * rowspan + 2 ] = 0; 00132 }; 00133 }; 00134 00135 if ( mXpos + x_inc < 0 || mXpos + x_inc >= getMediaWidth() - block_size ) 00136 x_inc =- x_inc; 00137 00138 if ( mYpos + y_inc < 0 || mYpos + y_inc >= getMediaHeight() - block_size ) 00139 y_inc =- y_inc; 00140 00141 mXpos += x_inc; 00142 mYpos += y_inc; 00143 00144 unsigned char col_r = rand() % 0xff; 00145 unsigned char col_g = rand() % 0xff; 00146 unsigned char col_b = rand() % 0xff; 00147 00148 for( int y = 0; y < block_size; ++y ) 00149 { 00150 for( int x = 0; x < block_size; ++x ) 00151 { 00152 int rowspan = getMediaWidth() * getMediaDepth(); 00153 mMediaPixels[ ( mXpos + x ) * getMediaDepth() + ( mYpos + y ) * rowspan + 0 ] = col_r; 00154 mMediaPixels[ ( mXpos + x ) * getMediaDepth() + ( mYpos + y ) * rowspan + 1 ] = col_g; 00155 mMediaPixels[ ( mXpos + x ) * getMediaDepth() + ( mYpos + y ) * rowspan + 2 ] = col_b; 00156 }; 00157 }; 00158 00159 // emit an event to say that something in the media stream changed 00160 LLMediaEvent event( this ); 00161 mEventEmitter.update( &LLMediaObserver::onMediaContentsChange, event ); 00162 }; 00163 00164 // update the command (e.g. transport controls) state 00165 updateCommand(); 00166 00167 return false; 00168 } 00169 00171 // virtual 00172 unsigned char* LLMediaImplExample2::getMediaData() 00173 { 00174 return mMediaPixels; 00175 } 00176 00178 // virtual 00179 bool LLMediaImplExample2::reset() 00180 { 00181 if ( mMediaPixels ) 00182 { 00183 delete [] mMediaPixels; 00184 }; 00185 00186 return true; 00187 } 00188 00190 // virtual 00191 bool LLMediaImplExample2::setRequestedMediaSize( int width, int height ) 00192 { 00193 // we accept any size: 00194 return setMediaSize(width, height); 00195 }