00001
00032 #include "llmediaimplexample1.h"
00033 #include "llmediaimplregister.h"
00034
00035
00036 static LLMediaImplRegister sLLMediaImplExample1Reg( "LLMediaImplExample1", new LLMediaImplExample1Maker() );
00037
00038 #include <iostream>
00039
00040 #include <time.h>
00041
00043
00044 LLMediaImplExample1Maker::LLMediaImplExample1Maker()
00045 {
00046
00047 mSchema.push_back( "example1" );
00048 }
00049
00051
00052 LLMediaImplExample1::LLMediaImplExample1() :
00053 mMediaPixels( 0 )
00054 {
00055 setRequestedMediaSize( 400, 200 );
00056 setMediaDepth( 3 );
00057
00058 srand( (unsigned int)(time( NULL )) );
00059 }
00060
00062
00063 bool LLMediaImplExample1::startup( LLMediaManagerData* init_data )
00064 {
00065 return true;
00066 }
00067
00069
00070 bool LLMediaImplExample1::closedown()
00071 {
00072 return true;
00073 }
00074
00076
00077 bool LLMediaImplExample1::init()
00078 {
00079 int buffer_size = getMediaBufferSize();
00080
00081 mMediaPixels = new unsigned char[ buffer_size ];
00082
00083 memset( mMediaPixels, 0xAA, buffer_size );
00084
00085 return true;
00086 }
00087
00089
00090 bool LLMediaImplExample1::navigateTo( const std::string url )
00091 {
00092 std::cout << "LLMediaImplExample1::navigateTo" << std::endl;
00093
00094 setStatus( LLMediaBase::STATUS_NAVIGATING );
00095
00096
00097 LLMediaEvent event( this );
00098 mEventEmitter.update( &LLMediaObserver::onMediaSizeChange, event );
00099
00100 return true;
00101 }
00102
00104
00105 std::string LLMediaImplExample1::getVersion()
00106 {
00107 std::string version_string = "[" + sLLMediaImplExample1Reg.getImplName() + "] - " + "1.0.0.0";
00108
00109 return version_string;
00110 }
00111
00113
00114 bool LLMediaImplExample1::updateMedia()
00115 {
00116 if ( mMediaPixels && getStatus() == LLMediaBase::STATUS_STARTED )
00117 {
00118
00119 static time_t t = time( 0 ) - 4;
00120
00121
00122 if ( time( 0 ) - t > 1 )
00123 {
00124
00125 const int num_squares = rand() % 20 + 4;
00126 int sqr1_r = rand() % 0x80;
00127 int sqr1_g = rand() % 0x80;
00128 int sqr1_b = rand() % 0x80;
00129 int sqr2_r = rand() % 0x80;
00130 int sqr2_g = rand() % 0x80;
00131 int sqr2_b = rand() % 0x80;
00132
00133 for ( int y1 = 0; y1 < num_squares; ++y1 )
00134 {
00135 for ( int x1 = 0; x1 < num_squares; ++x1 )
00136 {
00137 int px_start = getMediaWidth() * x1 / num_squares;
00138 int px_end = ( getMediaWidth() * ( x1 + 1 ) ) / num_squares;
00139 int py_start = getMediaHeight() * y1 / num_squares;
00140 int py_end = ( getMediaHeight() * ( y1 + 1 ) ) / num_squares;
00141
00142 for( int y2 = py_start; y2 < py_end; ++y2 )
00143 {
00144 for( int x2 = px_start; x2 < px_end; ++x2 )
00145 {
00146 int rowspan = getMediaWidth() * getMediaDepth();
00147
00148 if ( ( y1 % 2 ) ^ ( x1 % 2 ) )
00149 {
00150 mMediaPixels[ y2 * rowspan + x2 * getMediaDepth() + 0 ] = sqr1_r;
00151 mMediaPixels[ y2 * rowspan + x2 * getMediaDepth() + 1 ] = sqr1_g;
00152 mMediaPixels[ y2 * rowspan + x2 * getMediaDepth() + 2 ] = sqr1_b;
00153 }
00154 else
00155 {
00156 mMediaPixels[ y2 * rowspan + x2 * getMediaDepth() + 0 ] = sqr2_r;
00157 mMediaPixels[ y2 * rowspan + x2 * getMediaDepth() + 1 ] = sqr2_g;
00158 mMediaPixels[ y2 * rowspan + x2 * getMediaDepth() + 2 ] = sqr2_b;
00159 };
00160 };
00161 };
00162 };
00163 };
00164
00165
00166 LLMediaEvent event( this );
00167 mEventEmitter.update( &LLMediaObserver::onMediaContentsChange, event );
00168
00169
00170 t = time( 0 );
00171
00172 return true;
00173 };
00174 };
00175
00176
00177 updateCommand();
00178
00179 return false;
00180 }
00181
00183
00184 unsigned char* LLMediaImplExample1::getMediaData()
00185 {
00186 return mMediaPixels;
00187 }
00188
00190
00191 bool LLMediaImplExample1::reset()
00192 {
00193 if ( mMediaPixels )
00194 {
00195 delete [] mMediaPixels;
00196 };
00197
00198 return true;
00199 }
00200
00202
00203 bool LLMediaImplExample1::mouseMove( int x_pos, int y_pos )
00204 {
00205 if ( mMediaPixels && getStatus() == LLMediaBase::STATUS_STARTED )
00206 {
00207 int base_pos = x_pos * getMediaDepth() + y_pos * getMediaDepth() * getMediaWidth();
00208
00209 mMediaPixels[ base_pos + 0 ] = rand() % 0x80 + 0x80;
00210 mMediaPixels[ base_pos + 1 ] = rand() % 0x80 + 0x80;
00211 mMediaPixels[ base_pos + 2 ] = rand() % 0x80 + 0x80;
00212
00213
00214 LLMediaEvent event( this );
00215 mEventEmitter.update( &LLMediaObserver::onMediaContentsChange, event );
00216 };
00217
00218 return true;
00219 }
00220
00221
00223
00224 bool LLMediaImplExample1::setRequestedMediaSize( int width, int height )
00225 {
00226
00227 return setMediaSize(width, height);
00228 }