AtmoLight 2.1.0.0 for MediaPortal2 [2015-01-21] | Page 2

Discussion in 'Plugin Development' started by Rick164, April 22, 2014.

  1. Lightning303
    • Premium Supporter

    Lightning303 MP Donator

    Joined:
    September 12, 2009
    Messages:
    798
    Likes Received:
    384
    Gender:
    Male
    Ratings:
    +578 / 0
    Home Country:
    Germany Germany
    Show System Specs
    Thanks, this helped a lot, however im not quite there yet.



    i now have the following:
    Code (C):
    1.     private SharpDX.Direct3D9.Surface rgbSurface;
    2.     private IPlayerManager pm;
    3.     private ISharpDXVideoPlayer player;
    4.  
    5.     private void MyThread()
    6.     {
    7.       while (ServiceRegistration.Get<IPlayerContextManager>().IsVideoContextActive)
    8.       {
    9.         try
    10.         {
    11.           pm = ServiceRegistration.Get<IPlayerManager>();
    12.           pm.ForEach(psc =>
    13.           {
    14.             player = psc.CurrentPlayer as ISharpDXVideoPlayer;
    15.             if (player == null || player.Surface == null)
    16.               return;
    17.  
    18.             rgbSurface = player.Surface;
    19.           });
    20.  
    21.           Rectangle rect = new Rectangle(0, 0, AtmoLightObject.captureWidth, AtmoLightObject.captureHeight);
    22.  
    23.           Stopwatch stopwatch = new Stopwatch();
    24.           stopwatch.Start();
    25.        
    26.           DataStream stream = SharpDX.Direct3D9.Surface.ToStream(rgbSurface, SharpDX.Direct3D9.ImageFileFormat.Bmp, rect);
    27.           stopwatch.Stop();
    28.           Log.Error("Time: {0}", stopwatch.Elapsed);
    29.  
    30.           BinaryReader reader = new BinaryReader(stream);
    31.           stream.Position = 0; // ensure that what start at the beginning of the stream.
    32.           reader.ReadBytes(14); // skip bitmap file info header
    33.           byte[] bmiInfoHeader = reader.ReadBytes(4 + 4 + 4 + 2 + 2 + 4 + 4 + 4 + 4 + 4 + 4);
    34.  
    35.           int rgbL = (int)(stream.Length - stream.Position);
    36.           int rgb = (int)(rgbL / (AtmoLightObject.captureWidth * AtmoLightObject.captureHeight));
    37.  
    38.           byte[] pixelData = reader.ReadBytes((int)(stream.Length - stream.Position));
    39.  
    40.           byte[] h1pixelData = new byte[AtmoLightObject.captureWidth * rgb];
    41.           byte[] h2pixelData = new byte[AtmoLightObject.captureWidth * rgb];
    42.           //now flip horizontally, we do it always to prevent microstudder
    43.           int i;
    44.           for (i = 0; i < ((AtmoLightObject.captureHeight / 2) - 1); i++)
    45.           {
    46.             Array.Copy(pixelData, i * AtmoLightObject.captureWidth * rgb, h1pixelData, 0, AtmoLightObject.captureWidth * rgb);
    47.             Array.Copy(pixelData, (AtmoLightObject.captureHeight - i - 1) * AtmoLightObject.captureWidth * rgb, h2pixelData, 0, AtmoLightObject.captureWidth * rgb);
    48.             Array.Copy(h1pixelData, 0, pixelData, (AtmoLightObject.captureHeight - i - 1) * AtmoLightObject.captureWidth * rgb, AtmoLightObject.captureWidth * rgb);
    49.             Array.Copy(h2pixelData, 0, pixelData, i * AtmoLightObject.captureWidth * rgb, AtmoLightObject.captureWidth * rgb);
    50.           }
    51.  
    52.           AtmoLightObject.SetPixelData(bmiInfoHeader, pixelData);
    53.  
    54.           stream.Close();
    55.           stream.Dispose();
    56.  
    57.         }
    58.         catch (Exception ex)
    59.         {
    60.           Log.Error("ex: {0}", ex.Message);
    61.         }
    62.       }
    63.       System.Threading.Thread.Sleep(10);
    64.     }
    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):
    1. private SharpDX.Direct3D9.Device sharpDXDevice;
    2.  
    3. private void MyThread()
    4. {
    5. sharpDXDevice = SkinContext.Device;
    6.   while...
    7. ...
    8.           sharpDXDevice.StretchRectangle(rgbSurface, null, rgbSurface, rect, SharpDX.Direct3D9.TextureFilter.None);
    9.           DataStream stream = SharpDX.Direct3D9.Surface.ToStream(rgbSurface, SharpDX.Direct3D9.ImageFileFormat.Bmp);
    10. ...
    11. }
    but that just gets me exceptions.

    Code (Text):
    1. [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!
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Lightning303
    • Premium Supporter

    Lightning303 MP Donator

    Joined:
    September 12, 2009
    Messages:
    798
    Likes Received:
    384
    Gender:
    Male
    Ratings:
    +578 / 0
    Home Country:
    Germany Germany
    Show System Specs
    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: April 27, 2014
    • Thank You! Thank You! x 3
    • Like Like x 2
  4. morpheus_xx
    • Team MediaPortal

    morpheus_xx Lead Dev MP2

    Joined:
    March 24, 2007
    Messages:
    11,065
    Likes Received:
    4,760
    Ratings:
    +6,814 / 11
    Home Country:
    Germany Germany
    Show System Specs
    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.
     
  5. Lightning303
    • Premium Supporter

    Lightning303 MP Donator

    Joined:
    September 12, 2009
    Messages:
    798
    Likes Received:
    384
    Gender:
    Male
    Ratings:
    +578 / 0
    Home Country:
    Germany Germany
    Show System Specs
    Yeah, @BassFan made me aware of this also, i just fixed it. Thanks :)


    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.


    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: April 24, 2014
  6. Lightning303
    • Premium Supporter

    Lightning303 MP Donator

    Joined:
    September 12, 2009
    Messages:
    798
    Likes Received:
    384
    Gender:
    Male
    Ratings:
    +578 / 0
    Home Country:
    Germany Germany
    Show System Specs
    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: April 27, 2014
    • Like Like x 4
  7. kilik360
    • Premium Supporter

    kilik360 MP Donator

    Joined:
    September 3, 2010
    Messages:
    574
    Likes Received:
    155
    Ratings:
    +239 / 2
    Home Country:
    Canada Canada
    Show System Specs
    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: April 26, 2014
    • Like Like x 3
    • Thank You! Thank You! x 1
  8. Lightning303
    • Premium Supporter

    Lightning303 MP Donator

    Joined:
    September 12, 2009
    Messages:
    798
    Likes Received:
    384
    Gender:
    Male
    Ratings:
    +578 / 0
    Home Country:
    Germany Germany
    Show System Specs
    Thanks!
    Its nice to get some feedback. Sadly you are only the second person to give me any on a test version. :(
     
  9. Schicksal

    Schicksal Portal Pro

    Joined:
    February 7, 2010
    Messages:
    800
    Likes Received:
    24
    Gender:
    Male
    Occupation:
    graphic
    Ratings:
    +29 / 0
    Home Country:
    Germany Germany
    Show System Specs
    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...
     
    • Informative Informative x 1
  10. Lightning303
    • Premium Supporter

    Lightning303 MP Donator

    Joined:
    September 12, 2009
    Messages:
    798
    Likes Received:
    384
    Gender:
    Male
    Ratings:
    +578 / 0
    Home Country:
    Germany Germany
    Show System Specs
    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 (Text):
    1. Version 2.0.0.0 Alpha 4
    2. - Changed UICapture to use player surface on videoplayback (faster and no blackbar problems)
    3. - Added settings
    4. - Added automatic mode
    5.     * Video effect, Music effect and Menu effect
    6.     * Timeframe where leds should be off (exclude time)
    7.     * Manual Mode (currently no way to change effects manually)
    8. - 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: April 29, 2014
    • Like Like x 1
    • Thank You! Thank You! x 1
  11. kilik360
    • Premium Supporter

    kilik360 MP Donator

    Joined:
    September 3, 2010
    Messages:
    574
    Likes Received:
    155
    Ratings:
    +239 / 2
    Home Country:
    Canada Canada
    Show System Specs
    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.
     
    • Like Like x 2
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!