home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 2
Plugin Development
AtmoLight 2.1.0.0 for MediaPortal2 [2015-01-21]
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Lightning303" data-source="post: 1077360" data-attributes="member: 97876"><p>Thanks, this helped a lot, however im not quite there yet.</p><p></p><p>i now have the following:</p><p>[CODE=C#] private SharpDX.Direct3D9.Surface rgbSurface;</p><p> private IPlayerManager pm;</p><p> private ISharpDXVideoPlayer player;</p><p></p><p> private void MyThread()</p><p> {</p><p> while (ServiceRegistration.Get<IPlayerContextManager>().IsVideoContextActive)</p><p> {</p><p> try</p><p> {</p><p> pm = ServiceRegistration.Get<IPlayerManager>();</p><p> pm.ForEach(psc =></p><p> {</p><p> player = psc.CurrentPlayer as ISharpDXVideoPlayer;</p><p> if (player == null || player.Surface == null)</p><p> return;</p><p></p><p> rgbSurface = player.Surface;</p><p> });</p><p></p><p> Rectangle rect = new Rectangle(0, 0, AtmoLightObject.captureWidth, AtmoLightObject.captureHeight);</p><p></p><p> Stopwatch stopwatch = new Stopwatch();</p><p> stopwatch.Start();</p><p> </p><p> DataStream stream = SharpDX.Direct3D9.Surface.ToStream(rgbSurface, SharpDX.Direct3D9.ImageFileFormat.Bmp, rect);</p><p> stopwatch.Stop();</p><p> Log.Error("Time: {0}", stopwatch.Elapsed);</p><p></p><p> BinaryReader reader = new BinaryReader(stream);</p><p> stream.Position = 0; // ensure that what start at the beginning of the stream.</p><p> reader.ReadBytes(14); // skip bitmap file info header</p><p> byte[] bmiInfoHeader = reader.ReadBytes(4 + 4 + 4 + 2 + 2 + 4 + 4 + 4 + 4 + 4 + 4);</p><p></p><p> int rgbL = (int)(stream.Length - stream.Position);</p><p> int rgb = (int)(rgbL / (AtmoLightObject.captureWidth * AtmoLightObject.captureHeight));</p><p></p><p> byte[] pixelData = reader.ReadBytes((int)(stream.Length - stream.Position));</p><p></p><p> byte[] h1pixelData = new byte[AtmoLightObject.captureWidth * rgb];</p><p> byte[] h2pixelData = new byte[AtmoLightObject.captureWidth * rgb];</p><p> //now flip horizontally, we do it always to prevent microstudder</p><p> int i;</p><p> for (i = 0; i < ((AtmoLightObject.captureHeight / 2) - 1); i++)</p><p> {</p><p> Array.Copy(pixelData, i * AtmoLightObject.captureWidth * rgb, h1pixelData, 0, AtmoLightObject.captureWidth * rgb);</p><p> Array.Copy(pixelData, (AtmoLightObject.captureHeight - i - 1) * AtmoLightObject.captureWidth * rgb, h2pixelData, 0, AtmoLightObject.captureWidth * rgb);</p><p> Array.Copy(h1pixelData, 0, pixelData, (AtmoLightObject.captureHeight - i - 1) * AtmoLightObject.captureWidth * rgb, AtmoLightObject.captureWidth * rgb);</p><p> Array.Copy(h2pixelData, 0, pixelData, i * AtmoLightObject.captureWidth * rgb, AtmoLightObject.captureWidth * rgb);</p><p> }</p><p></p><p> AtmoLightObject.SetPixelData(bmiInfoHeader, pixelData);</p><p></p><p> stream.Close();</p><p> stream.Dispose();</p><p></p><p> }</p><p> catch (Exception ex)</p><p> {</p><p> Log.Error("ex: {0}", ex.Message);</p><p> }</p><p> }</p><p> System.Threading.Thread.Sleep(10);</p><p> }[/CODE]</p><p></p><p>With this, i was able to get the surface. However using the ToStream method has 2 problems for me. First, the surface gets cropped to the rect size instead of resized, and it takes 500ms (atleast on my laptop) to convert the surface to stream. So i checked the mp1 implementation again and there is a step to resize the surface before converting it to stream, so i tried that aswell.</p><p>Thats however also where i now fail.</p><p></p><p>I tried:</p><p>[CODE=C#]private SharpDX.Direct3D9.Device sharpDXDevice;</p><p></p><p>private void MyThread()</p><p>{</p><p>sharpDXDevice = SkinContext.Device;</p><p> while...</p><p>...</p><p> sharpDXDevice.StretchRectangle(rgbSurface, null, rgbSurface, rect, SharpDX.Direct3D9.TextureFilter.None);</p><p> DataStream stream = SharpDX.Direct3D9.Surface.ToStream(rgbSurface, SharpDX.Direct3D9.ImageFileFormat.Bmp);</p><p>...</p><p>}[/CODE]</p><p></p><p>but that just gets me exceptions.</p><p></p><p>[code][ERROR] - AtmoLight: ex: HRESULT: [0x8876086C], Module: [SharpDX.Direct3D9], ApiCode: [D3DERR_INVALIDCALL/InvalidCall], Message: Unknown[/code]</p><p></p><p>Maybe you have an idea? Im just hitting walls again <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite3" alt=":(" title="Frown :(" loading="lazy" data-shortname=":(" />.</p><p></p><p>Thanks!</p></blockquote><p></p>
[QUOTE="Lightning303, post: 1077360, member: 97876"] Thanks, this helped a lot, however im not quite there yet. i now have the following: [CODE=C#] private SharpDX.Direct3D9.Surface rgbSurface; private IPlayerManager pm; private ISharpDXVideoPlayer player; private void MyThread() { while (ServiceRegistration.Get<IPlayerContextManager>().IsVideoContextActive) { try { pm = ServiceRegistration.Get<IPlayerManager>(); pm.ForEach(psc => { player = psc.CurrentPlayer as ISharpDXVideoPlayer; if (player == null || player.Surface == null) return; rgbSurface = player.Surface; }); Rectangle rect = new Rectangle(0, 0, AtmoLightObject.captureWidth, AtmoLightObject.captureHeight); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); DataStream stream = SharpDX.Direct3D9.Surface.ToStream(rgbSurface, SharpDX.Direct3D9.ImageFileFormat.Bmp, rect); stopwatch.Stop(); Log.Error("Time: {0}", stopwatch.Elapsed); BinaryReader reader = new BinaryReader(stream); stream.Position = 0; // ensure that what start at the beginning of the stream. reader.ReadBytes(14); // skip bitmap file info header byte[] bmiInfoHeader = reader.ReadBytes(4 + 4 + 4 + 2 + 2 + 4 + 4 + 4 + 4 + 4 + 4); int rgbL = (int)(stream.Length - stream.Position); int rgb = (int)(rgbL / (AtmoLightObject.captureWidth * AtmoLightObject.captureHeight)); byte[] pixelData = reader.ReadBytes((int)(stream.Length - stream.Position)); byte[] h1pixelData = new byte[AtmoLightObject.captureWidth * rgb]; byte[] h2pixelData = new byte[AtmoLightObject.captureWidth * rgb]; //now flip horizontally, we do it always to prevent microstudder int i; for (i = 0; i < ((AtmoLightObject.captureHeight / 2) - 1); i++) { Array.Copy(pixelData, i * AtmoLightObject.captureWidth * rgb, h1pixelData, 0, AtmoLightObject.captureWidth * rgb); Array.Copy(pixelData, (AtmoLightObject.captureHeight - i - 1) * AtmoLightObject.captureWidth * rgb, h2pixelData, 0, AtmoLightObject.captureWidth * rgb); Array.Copy(h1pixelData, 0, pixelData, (AtmoLightObject.captureHeight - i - 1) * AtmoLightObject.captureWidth * rgb, AtmoLightObject.captureWidth * rgb); Array.Copy(h2pixelData, 0, pixelData, i * AtmoLightObject.captureWidth * rgb, AtmoLightObject.captureWidth * rgb); } AtmoLightObject.SetPixelData(bmiInfoHeader, pixelData); stream.Close(); stream.Dispose(); } catch (Exception ex) { Log.Error("ex: {0}", ex.Message); } } System.Threading.Thread.Sleep(10); }[/CODE] With this, i was able to get the surface. However using the ToStream method has 2 problems for me. First, the surface gets cropped to the rect size instead of resized, and it takes 500ms (atleast on my laptop) to convert the surface to stream. So i checked the mp1 implementation again and there is a step to resize the surface before converting it to stream, so i tried that aswell. Thats however also where i now fail. I tried: [CODE=C#]private SharpDX.Direct3D9.Device sharpDXDevice; private void MyThread() { sharpDXDevice = SkinContext.Device; while... ... sharpDXDevice.StretchRectangle(rgbSurface, null, rgbSurface, rect, SharpDX.Direct3D9.TextureFilter.None); DataStream stream = SharpDX.Direct3D9.Surface.ToStream(rgbSurface, SharpDX.Direct3D9.ImageFileFormat.Bmp); ... }[/CODE] but that just gets me exceptions. [code][ERROR] - AtmoLight: ex: HRESULT: [0x8876086C], Module: [SharpDX.Direct3D9], ApiCode: [D3DERR_INVALIDCALL/InvalidCall], Message: Unknown[/code] Maybe you have an idea? Im just hitting walls again :(. Thanks! [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 2
Plugin Development
AtmoLight 2.1.0.0 for MediaPortal2 [2015-01-21]
Contact us
RSS
Top
Bottom