svvitch
digital signage player
|
00001 #include "ComContent.h" 00002 00003 00004 ComContent::ComContent(Renderer& renderer, int splitType, float x, float y, float w, float h): 00005 Content(renderer, splitType, x, y, w, h), _ole(NULL), _controlSite(NULL), _texture(NULL), _surface(NULL), 00006 _phase(-1) 00007 { 00008 } 00009 00010 ComContent::‾ComContent() { 00011 } 00012 00013 void ComContent::invalidateRect(int x, int y, int w, int h) { 00014 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00015 _invalidateRects.push(Rect(x, y, w, h)); 00016 } 00017 00018 bool ComContent::hasInvalidateRect() { 00019 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00020 return !_invalidateRects.empty(); 00021 } 00022 00023 Rect ComContent::popInvalidateRect() { 00024 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00025 Rect rect = _invalidateRects.front(); 00026 _invalidateRects.pop(); 00027 return rect; 00028 } 00029 00030 bool ComContent::open(const MediaItemPtr media, const int offset) { 00031 _controlSite = new ControlSite(this); 00032 _controlSite->AddRef(); 00033 _texture = _renderer.createTexture(_w, _h, D3DFMT_A8R8G8B8); 00034 if (_texture) { 00035 _renderer.colorFill(_texture, 0x00000000); 00036 _log.information(Poco::format("com component texture: %.0hfx%.0hf", _w, _h)); 00037 _texture->GetSurfaceLevel(0, &_surface); 00038 } 00039 00040 set("alpha", 1.0f); 00041 _duration = media->duration() * 60 / 1000; 00042 _current = 0; 00043 _mediaID = media->id(); 00044 return true; 00045 } 00046 00047 void ComContent::play() { 00048 _playing = true; 00049 _playTimer.start(); 00050 } 00051 00052 void ComContent::stop() { 00053 _playing = false; 00054 if (_phase >= 0) { 00055 if (_thread.isRunning())_thread.join(); 00056 releaseComComponents(); 00057 } 00058 } 00059 00060 bool ComContent::useFastStop() { 00061 return true; 00062 } 00063 00064 const bool ComContent::playing() const { 00065 return _playing; 00066 } 00067 00068 const bool ComContent::finished() { 00069 switch (_phase) { 00070 case 0: 00071 case 1: 00072 case 2: 00073 if (_duration > 0) { 00074 return _playTimer.getTime() >= 1000 * _duration / 60; 00075 } 00076 break; 00077 case 3: 00078 return true; 00079 } 00080 return false; 00081 } 00082 00083 void ComContent::close() { 00084 stop(); 00085 _mediaID.clear(); 00086 SAFE_RELEASE(_surface); 00087 SAFE_RELEASE(_texture); 00088 SAFE_RELEASE(_controlSite); 00089 } 00090 00091 void ComContent::process(const DWORD& frame) { 00092 switch (_phase) { 00093 case 0: // 初期化フェーズ 00094 if (_playing && !_mediaID.empty()) createComComponents(); 00095 break; 00096 case 1: // 初期化済 00097 if (_playing && !_mediaID.empty()) { 00098 _worker = this; 00099 _thread.start(*_worker); 00100 _phase = 2; 00101 } 00102 break; 00103 case 2: // 再生中 00104 _current = _playTimer.getTime() * 60 / 1000; 00105 break; 00106 case 3: // リリース済 00107 break; 00108 } 00109 unsigned long cu = _playTimer.getTime() / 1000; 00110 unsigned long re = _duration / 60 - cu; 00111 string t1 = Poco::format("%02lu:%02lu:%02lu.%02d", cu / 3600, cu / 60, cu % 60, 0); 00112 string t2 = Poco::format("%02lu:%02lu:%02lu.%02d", re / 3600, re / 60, re % 60, 0); 00113 set("time", Poco::format("%s %s", t1, t2)); 00114 set("time_current", t1); 00115 if (_duration > 0) { 00116 set("time_remain", t2); 00117 } else { 00118 set("time_remain", "--:--:--.--"); 00119 } 00120 set("status", Poco::format("%03.2hfms", _avgTime)); 00121 } 00122 00123 00124 void ComContent::draw(const DWORD& frame) { 00125 switch (_phase) { 00126 case 2: 00127 case 3: 00128 if (_texture) { 00129 float alpha = getF("alpha"); 00130 DWORD col = ((DWORD)(0xff * alpha) << 24) | 0xffffff; 00131 int cw = config().splitSize.cx; 00132 int ch = config().splitSize.cy; 00133 LPDIRECT3DDEVICE9 device = _renderer.get3DDevice(); 00134 switch (config().splitType) { 00135 case 1: 00136 { 00137 } 00138 break; 00139 case 2: 00140 { 00141 // device->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE); 00142 // RECT scissorRect; 00143 // device->GetScissorRect(&scissorRect); 00144 device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); 00145 device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); 00146 device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); 00147 device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); 00148 int sw = _w / cw; 00149 int sh = _h / ch; 00150 for (int sy = 0; sy < sh; sy++) { 00151 for (int sx = 0; sx < sw; sx++) { 00152 int dx = (sx / config().splitCycles) * cw; 00153 int dy = (config().splitCycles - (sx % config().splitCycles) - 1) * ch; 00154 // RECT rect = {dx, dy, dx + cww, dy + chh}; 00155 // device->SetScissorRect(&rect); 00156 if (_background) { 00157 _renderer.drawTexture(dx + _x, dy + _y, cw, ch, sx * cw, sy * ch, cw, ch, NULL, 0, _background, _background, _background, _background); 00158 } 00159 _renderer.drawTexture(dx + _x, dy + _y, cw, ch, sx * cw, sy * ch, cw, ch, _texture, 0, col, col, col, col); 00160 } 00161 } 00162 device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); 00163 device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); 00164 // device->SetScissorRect(&scissorRect); 00165 } 00166 break; 00167 default: 00168 if (_background) { 00169 _renderer.drawTexture(_x, _y, _w, _h, NULL, 0, _background, _background, _background, _background); 00170 } 00171 _renderer.drawTexture(_x, _y, _texture, 0, col, col, col, col); 00172 } 00173 } 00174 break; 00175 } 00176 }