aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmedia/llmediaimplexample2.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llmedia/llmediaimplexample2.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/llmedia/llmediaimplexample2.cpp')
-rw-r--r--linden/indra/llmedia/llmediaimplexample2.cpp195
1 files changed, 195 insertions, 0 deletions
diff --git a/linden/indra/llmedia/llmediaimplexample2.cpp b/linden/indra/llmedia/llmediaimplexample2.cpp
new file mode 100644
index 0000000..dc20e03
--- /dev/null
+++ b/linden/indra/llmedia/llmediaimplexample2.cpp
@@ -0,0 +1,195 @@
1/**
2 * @file llmediaimplexample2.cpp
3 * @brief Example 2 of a media impl concrete class
4 *
5 * $LicenseInfo:firstyear=2007&license=viewergpl$
6 *
7 * Copyright (c) 2007-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#include "llmediaimplexample2.h"
33#include "llmediaimplregister.h"
34
35// register this impl with media manager factory
36static LLMediaImplRegister sLLMediaImplExample2Reg( "LLMediaImplExample2", new LLMediaImplExample2Maker() );
37
38#include <iostream>
39#include <time.h>
40
41///////////////////////////////////////////////////////////////////////////////
42//
43LLMediaImplExample2Maker::LLMediaImplExample2Maker()
44{
45 // Register to handle the scheme
46 mSchema.push_back( "example2" );
47}
48
49///////////////////////////////////////////////////////////////////////////////
50//
51LLMediaImplExample2::LLMediaImplExample2() :
52 mMediaPixels( 0 )
53{
54 setRequestedMediaSize( 500, 500 );
55 setMediaDepth( 3 );
56
57 mXpos = ( getMediaWidth() / 2 ) + rand() % ( getMediaWidth() / 16 ) - ( getMediaWidth() / 32 );
58 mYpos = ( getMediaHeight() / 2 ) + rand() % ( getMediaHeight() / 16 ) - ( getMediaHeight() / 32 );
59
60 srand( (unsigned int)(time( NULL )) );
61}
62
63////////////////////////////////////////////////////////////////////////////////
64// (static) super-initialization - called once at application startup
65bool LLMediaImplExample2::startup( LLMediaManagerData* init_data )
66{
67 return true;
68}
69
70////////////////////////////////////////////////////////////////////////////////
71// (static) super-uninitialization - called once at application closedown
72bool LLMediaImplExample2::closedown()
73{
74 return true;
75}
76
77////////////////////////////////////////////////////////////////////////////////
78// virtual
79bool LLMediaImplExample2::init()
80{
81 int buffer_size = getMediaBufferSize();
82
83 mMediaPixels = new unsigned char[ buffer_size ];
84
85 memset( mMediaPixels, 0x00, buffer_size );
86
87 return true;
88}
89
90////////////////////////////////////////////////////////////////////////////////
91// virtual
92bool LLMediaImplExample2::navigateTo( const std::string url )
93{
94 std::cout << "LLMediaImplExample2::navigateTo" << std::endl;
95
96 setStatus( LLMediaBase::STATUS_NAVIGATING );
97
98 // force a size change event for new URL
99 LLMediaEvent event( this );
100 mEventEmitter.update( &LLMediaObserver::onMediaSizeChange, event );
101
102 return true;
103}
104
105////////////////////////////////////////////////////////////////////////////////
106// virtual
107std::string LLMediaImplExample2::getVersion()
108{
109 std::string version_string = "[" + sLLMediaImplExample2Reg.getImplName() + "] - " + "1.0.0.0";
110
111 return version_string;
112}
113
114////////////////////////////////////////////////////////////////////////////////
115// virtual
116bool LLMediaImplExample2::updateMedia()
117{
118 if ( mMediaPixels && getStatus() == LLMediaBase::STATUS_STARTED )
119 {
120 static int x_inc = rand() % 5 + 2;
121 static int y_inc = rand() % 5 + 2;
122 int block_size = 32;
123
124 for( int y = 0; y < block_size; ++y )
125 {
126 for( int x = 0; x < block_size; ++x )
127 {
128 int rowspan = getMediaWidth() * getMediaDepth();
129 mMediaPixels[ ( mXpos + x ) * getMediaDepth() + ( mYpos + y ) * rowspan + 0 ] = 0;
130 mMediaPixels[ ( mXpos + x ) * getMediaDepth() + ( mYpos + y ) * rowspan + 1 ] = 0;
131 mMediaPixels[ ( mXpos + x ) * getMediaDepth() + ( mYpos + y ) * rowspan + 2 ] = 0;
132 };
133 };
134
135 if ( mXpos + x_inc < 0 || mXpos + x_inc >= getMediaWidth() - block_size )
136 x_inc =- x_inc;
137
138 if ( mYpos + y_inc < 0 || mYpos + y_inc >= getMediaHeight() - block_size )
139 y_inc =- y_inc;
140
141 mXpos += x_inc;
142 mYpos += y_inc;
143
144 unsigned char col_r = rand() % 0xff;
145 unsigned char col_g = rand() % 0xff;
146 unsigned char col_b = rand() % 0xff;
147
148 for( int y = 0; y < block_size; ++y )
149 {
150 for( int x = 0; x < block_size; ++x )
151 {
152 int rowspan = getMediaWidth() * getMediaDepth();
153 mMediaPixels[ ( mXpos + x ) * getMediaDepth() + ( mYpos + y ) * rowspan + 0 ] = col_r;
154 mMediaPixels[ ( mXpos + x ) * getMediaDepth() + ( mYpos + y ) * rowspan + 1 ] = col_g;
155 mMediaPixels[ ( mXpos + x ) * getMediaDepth() + ( mYpos + y ) * rowspan + 2 ] = col_b;
156 };
157 };
158
159 // emit an event to say that something in the media stream changed
160 LLMediaEvent event( this );
161 mEventEmitter.update( &LLMediaObserver::onMediaContentsChange, event );
162 };
163
164 // update the command (e.g. transport controls) state
165 updateCommand();
166
167 return false;
168}
169
170////////////////////////////////////////////////////////////////////////////////
171// virtual
172unsigned char* LLMediaImplExample2::getMediaData()
173{
174 return mMediaPixels;
175}
176
177////////////////////////////////////////////////////////////////////////////////
178// virtual
179bool LLMediaImplExample2::reset()
180{
181 if ( mMediaPixels )
182 {
183 delete [] mMediaPixels;
184 };
185
186 return true;
187}
188
189////////////////////////////////////////////////////////////////////////////////
190// virtual
191bool LLMediaImplExample2::setRequestedMediaSize( int width, int height )
192{
193 // we accept any size:
194 return setMediaSize(width, height);
195}