[Approved] Framegrabber improvement - Capture from UI when Video is minimized or running in Mini-display (1 Viewer)

popy

MP Donator
  • Premium Supporter
  • July 3, 2011
    617
    141
    thx, for testing and your feedback.
    I have done this in one of the first patches. The plugin tries to subscribe to an event in an try catch. When something goes wrong it uses the old event.
    Now we have just one event. Ill must test if the old code also works with one event but different parameters.
    If not, ill think we must add some MP installation version check and try to use the right event.

    Will look at it later this evening and come back here.

    pOpY
     

    popy

    MP Donator
  • Premium Supporter
  • July 3, 2011
    617
    141
    Not so easy as i thought :(
    I have tried it that way:
    • make enum private and copied it to the plugin.cs
    • define FrameSource parameter as int and optional like this:
    Code:
     private void AtmolightPlugin_OnNewFrame(short width, short height, short arWidth, short arHeight, uint pSurface, int iFrameSource = (int)FrameSource.NotSupported)

    doesnt work with old v1.11pre -> MP does close without any exception message in the error log :(
    I have also read some reports from other C# users says that the delegate itself must contain the optional parameter. Older MP versions doesnt have this needed parameter optional declared, so ill think we have to go the other way and check which MP version the user has installed and then subscribe to the correct delegate method. We then need 2 methods, one with the new FrameSource and the old one without it.

    Will try it tomorrow
    pOpY
     
    Last edited:

    Lightning303

    MP Donator
  • Premium Supporter
  • September 12, 2009
    798
    577
    Home Country
    Germany Germany
    I played around a bit and tried my hand with overloading the AtmolightPlugin_OnNewFrame method. However it seems that the enum crashes MP when its not present (MP before your changes) in MP. Not sure if this can be worked around. But if we/you would to use an int instead of an enum in the FrameGrabber as you said in your post, its not a big problem to implement.

    Code:
        private void AtmolightPlugin_OnNewFrame(short width, short height, short arWidth, short arHeight, uint pSurface, int FrameSource)
        {
          if (coreObject.GetCurrentEffect() != ContentEffect.MediaPortalLiveMode || !coreObject.IsConnected() || !coreObject.IsAtmoLightOn() || width == 0 || height == 0)
          {
            return;
          }
    
          //Drop any frames?
          if (Settings.trueGrabbing)
          {
            //GUI grabbing while video is minimized activated
            if (g_Player.Playing && (!GUIGraphicsContext.IsFullScreenVideo) && (FrameSource == 1))
            {
              //Drop Video frames when user has set TrueGrabbing & video is playing minimized -> just GUI frames will pass
              return;
            }
          }
          else
          {
            //GUI grabbing while video is minimized deactivated
            if ((g_Player.Playing) && (FrameSource == 0))
            {
              //Drop GUI frames when user has NOT set TrueGrabbing & video is playing -> just video frames will pass
             
              return;
            }
          }
          AtmolightPlugin_OnNewFrame(width, height, arWidth, arHeight, pSurface);
        }

    The original AtmolightPlugin_OnNewFrame stays untouched (no FrameSource parameter and no frame elimination code). Then new MP versions will use the above method that will forward the frames to the old method, and old MP versions will directly use the old method as before.
     

    popy

    MP Donator
  • Premium Supporter
  • July 3, 2011
    617
    141
    I played around a bit and tried my hand with overloading the AtmolightPlugin_OnNewFrame method. However it seems that the enum crashes MP when its not present (MP before your changes) in MP. Not sure if this can be worked around. But if we/you would to use an int instead of an enum in the FrameGrabber as you said in your post, its not a big problem to implement.

    Code:
        private void AtmolightPlugin_OnNewFrame(short width, short height, short arWidth, short arHeight, uint pSurface, int FrameSource)
        {
          if (coreObject.GetCurrentEffect() != ContentEffect.MediaPortalLiveMode || !coreObject.IsConnected() || !coreObject.IsAtmoLightOn() || width == 0 || height == 0)
          {
            return;
          }
    
          //Drop any frames?
          if (Settings.trueGrabbing)
          {
            //GUI grabbing while video is minimized activated
            if (g_Player.Playing && (!GUIGraphicsContext.IsFullScreenVideo) && (FrameSource == 1))
            {
              //Drop Video frames when user has set TrueGrabbing & video is playing minimized -> just GUI frames will pass
              return;
            }
          }
          else
          {
            //GUI grabbing while video is minimized deactivated
            if ((g_Player.Playing) && (FrameSource == 0))
            {
              //Drop GUI frames when user has NOT set TrueGrabbing & video is playing -> just video frames will pass
           
              return;
            }
          }
          AtmolightPlugin_OnNewFrame(width, height, arWidth, arHeight, pSurface);
        }

    The original AtmolightPlugin_OnNewFrame stays untouched (no FrameSource parameter and no frame elimination code). Then new MP versions will use the above method that will forward the frames to the old method, and old MP versions will directly use the old method as before.

    I ahve also tried it this way but cant get the "old" pre v1.11 get to work.
    the new one works.
    the exception what is thrown by the old MP isnt in the error.log i have found it in event viewer:

    Code:
    Anwendung: MediaPortal.exe
    Frameworkversion: v4.0.30319
    Beschreibung: Der Prozess wurde aufgrund einer unbehandelten Ausnahme beendet.
    Ausnahmeinformationen: System.AccessViolationException
    Stapel:
       bei AtmoLight.Plugin.VideoSurfaceToRGBSurfaceExt(IntPtr, Int32, Int32, IntPtr, Int32, Int32)
       bei AtmoLight.Plugin.AtmolightPlugin_OnNewFrame(Int16, Int16, Int16, Int16, UInt32)
       bei AtmoLight.Plugin.AtmolightPlugin_OnNewFrame(Int16, Int16, Int16, Int16, UInt32, Int32)
       bei MediaPortal.FrameGrabber.OnFrame(Int16, Int16, Int16, Int16, UInt32)
       bei MediaPortal.FrameGrabber.OnFrame(Microsoft.DirectX.Direct3D.Surface)
       bei MediaPortal.FrameGrabber.OnFrame()
       bei MediaPortalApp.Render(Single)
       bei MediaPortal.D3D.FullRender()
       bei MediaPortal.D3D.OnIdle(System.Object, System.EventArgs)
       bei System.Windows.Forms.Application+ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32)
       bei System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)
       bei System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
       bei System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
       bei System.Windows.Forms.Application.Run(System.Windows.Forms.Form)
       bei MediaPortalApp.Main(System.String[])

    it seems that AtmoDXUtil.dll is causing now an issue!?
    but when ill copy over the new core.dll & mediaportal.exe the plugin works.

    Do you have any idea?
    Can you try the new patches on your machine?
    attached my current patches of MP & plugin.

    pOpY
     

    Attachments

    • Atmolight_DEV_Framegrabber_improvements_gui_capture_v6.patch
      5 KB
    • Mediaportal_1.11pre_gui_capture_v4.patch
      7.1 KB

    popy

    MP Donator
  • Premium Supporter
  • July 3, 2011
    617
    141
    Update: Ill think it has todo with overloading the function:
    • When ill compile the plugin against the 1.11pre core -> it works with it but not with the new core :(
    • When ill compile the plugin against the new core -> it works with it but not with the old 1.11pre core :(
    Any idea?

    popY
     

    Lightning303

    MP Donator
  • Premium Supporter
  • September 12, 2009
    798
    577
    Home Country
    Germany Germany
    As i said, no idea if and how it would work with keeping the enum. But if you get rid of the enum completly and use an int, or bool or whatever, it works without any porblems (no default values for parameters).
    No idea about the AtmoDX, maybe it gets wrong parameters for some reason?
     

    popy

    MP Donator
  • Premium Supporter
  • July 3, 2011
    617
    141
    Have tried with an int but also doesnt work.
    Can you please provide me your patches so i also can test.

    pOpY
     

    Lightning303

    MP Donator
  • Premium Supporter
  • September 12, 2009
    798
    577
    Home Country
    Germany Germany
    Have tried with an int but also doesnt work.
    Can you please provide me your patches so i also can test.

    pOpY

    Sorry, my mistake, even with an int i get problems. I mixed something up it seems :(.
     

    popy

    MP Donator
  • Premium Supporter
  • July 3, 2011
    617
    141
    N. P.

    So it seems the only way to keep compatibility is to make an second event, but this is not the best for the core performance because on every frame it has to do two null checks.

    I'll think it's better to stay on the last patches and write down in the release notes that there is no compatibility.

    What's your thinkings about that ?

    pOpY
     

    Lightning303

    MP Donator
  • Premium Supporter
  • September 12, 2009
    798
    577
    Home Country
    Germany Germany
    I agree that keeping one event is the better way, even if we loose compability. Maybe there is a way to still keep compability, but my C# knowledge leaves me at this point.
    I also double checked ViewModeSwitcher that this plugin wont be effected, and made sure the Auto3D plugin is not effected aswell. As both use GrabCurrentImage instead of the event, all should be fine :). But im going to actually test those thing in the next few days.
     

    Users who are viewing this thread

    Top Bottom