AtmoLight 2.1.0.0 for MediaPortal2 [2015-01-21] (2 Viewers)

Lightning303

MP Donator
  • Premium Supporter
  • September 12, 2009
    798
    577
    Home Country
    Germany Germany
    In principle you are on the right way, but you cannot access the player itself via ServiceRegistration, because MP2 handles two or even more players concurrently. You need to use the IPlayerManger service to get the active instances. Look into the StatsRenderer plugin, it also enumerates players.

    I think the StatsRenderer approach might even work better: you could get the full screen once it is rendered from backbuffer. Then it doesnt matter if one or more videos are playing, and also if fullscreen, window or PiP is used. Check the plugin code, it directly hooks into render events.

    Thanks, this helped a lot, however im not quite there yet.

    i now have the following:
    Code:
        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);
        }

    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:
    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);
    ...
    }

    but that just gets me exceptions.

    Code:
    [ERROR] - AtmoLight: ex: HRESULT: [0x8876086C], Module: [SharpDX.Direct3D9], ApiCode: [D3DERR_INVALIDCALL/InvalidCall], Message: Unknown

    Maybe you have an idea? Im just hitting walls again :(.

    Thanks!
     

    Lightning303

    MP Donator
  • Premium Supporter
  • September 12, 2009
    798
    577
    Home Country
    Germany Germany
    Hey :)
    @BassFan helped me a lot today pointing out mistakes i did and explained a lot of directx/sharpdx related stuff.
    Thank you so much for that @BassFan!
    So we figured it out :). We are now using the device from the player and generate a destination surface before hand.

    At the moment the plugin does:
    - Start AtmoWin on MP2 start and switch leds off.
    - When video is started, change to MP live view and cahnge colors (60hz polling atm)
    - When video stops switch leds off
    - Close AtmoWin on MP2 exit

    Source: https://github.com/ambilight-4-mediaportal/AtmoLight/tree/FEAT_MediaPortal2_Plugin

    And a test version for those who want :)
    https://ambilight-4-mediaportal.goo...ease/AtmoLight 2/AtmoLight_2.0.0.0_Alpha2.rar
     
    Last edited:

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    Great progress!
    Two notes about handling the resources:
    All MP2 skinengine controls implement methods (De)AllocateResources for creating and releasing DX resources. If you create surfaces yourself, you need to handle this also.
    Have you already considered what should happen in PiP mode? Will both players be processed?

    At least the 2nd point could be nicely solved if you get the bitmap from the backbuffer of the render target. This would allow event based handling instead of polling.
    Ah, another point:
    MP2 supports 3D render modes (ie. SBS), then rendering happens in two passes and you could get the bitmap only for first half-frame.
     

    Lightning303

    MP Donator
  • Premium Supporter
  • September 12, 2009
    798
    577
    Home Country
    Germany Germany
    All MP2 skinengine controls implement methods (De)AllocateResources for creating and releasing DX resources. If you create surfaces yourself, you need to handle this also.
    Yeah, @BassFan made me aware of this also, i just fixed it. Thanks :)


    Have you already considered what should happen in PiP mode? Will both players be processed?
    At least the 2nd point could be nicely solved if you get the bitmap from the backbuffer of the render target. This would allow event based handling instead of polling.
    Atm MP2 crashes with pip, as the polling thread is started twice and so on. I think the best solution would be to have this event based like in mp1 and not with polling. Also the perfect solution i think would be to use a surface of the whole UI instead of just a player, if this is possible. Im not sure if it is, i think you hinted that it is, but i could be wrong. Lots of new stuff for me, so this will take me some time.


    Ah, another point:
    MP2 supports 3D render modes (ie. SBS), then rendering happens in two passes and you could get the bitmap only for first half-frame.
    Im not sure if i understand right, but if you are saying in 3d mode i only get e.g. the left picture (sbs) then this should work out of the box?!
    In mp1, when 3d sbs is enabled atmolight only takes half of the picture as source material.

    https://github.com/ambilight-4-medi...in/AtmoLight.MediaPortal1/Plugin.cs#L504-L508
     
    Last edited:

    Lightning303

    MP Donator
  • Premium Supporter
  • September 12, 2009
    798
    577
    Home Country
    Germany Germany
    Atm MP2 crashes with pip, as the polling thread is started twice and so on. I think the best solution would be to have this event based like in mp1 and not with polling. Also the perfect solution i think would be to use a surface of the whole UI instead of just a player, if this is possible. Im not sure if it is, i think you hinted that it is, but i could be wrong. Lots of new stuff for me, so this will take me some time.

    Ok, i figured that out ;P.
    Thanks to the StatisticsRenderer plugin from you :)

    Now im using a handler and hook into SkinContext.DeviceSceneEnd.
    When the handler is called i do my calculations. This makes it possible to have the leds show the whole ui. Something i always wanted to do in MP1.

    Commit: https://github.com/ambilight-4-mediaportal/AtmoLight/commit/963afa05224683abe91ba53c78791a8c721a2fa6
    Testversion: https://ambilight-4-mediaportal.goo...ease/AtmoLight 2/AtmoLight_2.0.0.0_Alpha3.rar
     
    Last edited:

    kilik360

    MP Donator
  • Premium Supporter
  • September 3, 2010
    576
    235
    Home Country
    Canada Canada
    Great work Lightning303 ! I did some test today with V.3.

    - Atmowin starts when MP2 starts (y)
    - Atmolight is working with the UI (y)
    - Atmolight works with videos, series, movies and photos (y)
    - Atmowin quit when I quit MP2 (y)

    Keep up the good work !
     
    Last edited:

    Lightning303

    MP Donator
  • Premium Supporter
  • September 12, 2009
    798
    577
    Home Country
    Germany Germany
    Great work Lightning303 ! I did some test today with V.3.

    - Atmowin starts when MP2 starts (y)
    - Atmolight is working with the UI (y)
    - Atmolight works with videos, series, movies and photos (y)
    - Atmowin quit when I quit MP2 (y)

    Keep up the good work !

    Thanks!
    Its nice to get some feedback. Sadly you are only the second person to give me any on a test version. :(
     

    Schicksal

    Portal Pro
    February 7, 2010
    800
    29
    Home Country
    Germany Germany
    I don't know how many people are using MP2 and have an atmolight at home.
    I didn't use MP2 yet because of a missing Atmolight plugin ... and time :)
    Perhaps in the middle of may...
     

    Lightning303

    MP Donator
  • Premium Supporter
  • September 12, 2009
    798
    577
    Home Country
    Germany Germany
    I don't know how many people are using MP2 and have an atmolight at home.
    I didn't use MP2 yet because of a missing Atmolight plugin ... and time :)
    Perhaps in the middle of may...

    Thats true, but its a chicken and egg problem isnt it? ;).

    Also, new test version.

    https://ambilight-4-mediaportal.googlecode.com/git/MPEI Release/AtmoLight 2/AtmoLight_2.0.0.0_Alpha4.rar

    Code:
    Version 2.0.0.0 Alpha 4
    - Changed UICapture to use player surface on videoplayback (faster and no blackbar problems)
    - Added settings
    - Added automatic mode
        * Video effect, Music effect and Menu effect
        * Timeframe where leds should be off (exclude time)
        * Manual Mode (currently no way to change effects manually)
    - Added Low CPU feature

    After starting this version the first time with mediaportal 2, it will create a new settings file. You can find it under C:\ProgramData\Team MediaPortal\MP2-Client\Config\{USER_NAME}\. At the moment you have to change the config manually. But in general its the same setup as with the mp1 plugin, just that not everything is implemented yet.
     
    Last edited:

    kilik360

    MP Donator
  • Premium Supporter
  • September 3, 2010
    576
    235
    Home Country
    Canada Canada
    Ho yeah, I'll take a look to your baby. I think you already are at the beta stage of this plugin. I use V3 since Saturday and I didn't see anything wrong !;)

    Will test V4 and let you know.
     

    Users who are viewing this thread

    Top Bottom