[solved] Audio switching bug in Mediaportal 1.12 (1 Viewer)

Sebastiii

Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    I just retry with myvideo :)
    It stay to count #8 when audio device is added or removed. So maybe it happen only in movpic and TVS ?
     

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    Hmm just tested on TVS (not latest version) and keep as non watched.
     

    Rick164

    MP Donator
  • Premium Supporter
  • January 7, 2006
    1,335
    1,005
    Home Country
    Netherlands Netherlands
    Just tried it again and indeed with tvseries it stays as non-watched, not sure why it happened before but will see if it can be reproduced.
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    Here is the patch :)
    I think it looks mostly okay.

    Sometimes you could use -- or ++ instead of:
    Code:
    GUIGraphicsContext.DeviceAudioConnected = GUIGraphicsContext.DeviceAudioConnected + 1;

    Just a bit shorter. :)

    Also, a small tweak:
    Code:
    public static int DeviceAudioConnected
    {
      get { return _deviceAudioConnected; }
      set
      {
        if (value > _deviceAudioConnected)
        {
          _deviceAudioConnected = value;
          Log.Debug("GraphicContext: device audio connected - Count {0}", _deviceAudioConnected);
        }
        else if (value < _deviceAudioConnected)
        {
          _deviceAudioConnected = value < 0 ? 0 : value;
          Log.Debug("GraphicContext: device audio removed - Count {0}", _deviceAudioConnected);
        }
      }
    }

    This fixes:
    • don't log if value is not changing (should not happen, but good to handle all possibilities)
    • log if device is removed, even if _deviceAudioConnected is 0

    It seems the main thing is to finish DetectedFirstAudioStart?
     

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    I have thinking of -- or ++ when i just look the patch again :) -> will change to it :)
    Thanks for your code will use it too :p

    About DetectedFirstAudioStart, i have added it to enable the _deviceAudioConnected count to at least the value = 1 when starting MP.
    Because MP on start didn't know if audio device is present or not, it assume it is present and init the device.

    The best way would be to detect all audio device on start and increment the value, like this when current audio device is removed it decrease the value accordingly.

    So like i don't how to setup that, i use a bool to tell MP that it's the first boot.

    Not sure if you follow me lol
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    Not sure if you follow me lol
    Yes, I understand. :)

    Based on this code:
    https://github.com/MediaPortal/Medi.../MediaPortal.Application/MediaPortal.cs#L2071

    ...in DirectShow I would do it like this:
    Code:
    _deviceAudioConnected = 0;
    DsDevice[] devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSAudio);    // KSCATEGORY_AUDIO
    if (devices != null)
    {
      _deviceAudioConnected += devices.Length;
      foreach (DsDevice d in devices)
      {
        d.Dispose();
      }
    }
    devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSRender);    // KSCATEGORY_RENDER
    if (devices != null)
    {
      _deviceAudioConnected += devices.Length;
      foreach (DsDevice d in devices)
      {
        d.Dispose();
      }
    }
    devices = DsDevice.GetDevicesOfCat(RDP_REMOTE_AUDIO);
    if (devices != null)
    {
      _deviceAudioConnected += devices.Length;
      foreach (DsDevice d in devices)
      {
        d.Dispose();
      }
    }
    
    Log.Debug("Main: audio renderer count at startup = {0}", _deviceAudioConnected);

    Surely there are other ways to do it with WMI/WQL etc.
     

    azzuro

    Test Group
  • Team MediaPortal
  • May 10, 2007
    9,950
    5,620
    France - IDF
    Home Country
    France France
    Thank you men. I cant test on my side if this can solve my resume issue.

    Sebastiii: im at amboise. Lol my wife offers me hostel night. At chissay en touraine. Lol prepar the beer. I coming lol
     

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    Not sure if you follow me lol
    Yes, I understand. :)

    Based on this code:
    https://github.com/MediaPortal/Medi.../MediaPortal.Application/MediaPortal.cs#L2071

    ...in DirectShow I would do it like this:
    Code:
    _deviceAudioConnected = 0;
    DsDevice[] devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSAudio);    // KSCATEGORY_AUDIO
    if (devices != null)
    {
      _deviceAudioConnected += devices.Length;
      foreach (DsDevice d in devices)
      {
        d.Dispose();
      }
    }
    devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSRender);    // KSCATEGORY_RENDER
    if (devices != null)
    {
      _deviceAudioConnected += devices.Length;
      foreach (DsDevice d in devices)
      {
        d.Dispose();
      }
    }
    devices = DsDevice.GetDevicesOfCat(RDP_REMOTE_AUDIO);
    if (devices != null)
    {
      _deviceAudioConnected += devices.Length;
      foreach (DsDevice d in devices)
      {
        d.Dispose();
      }
    }
    
    Log.Debug("Main: audio renderer count at startup = {0}", _deviceAudioConnected);

    Surely there are other ways to do it with WMI/WQL etc.

    Oh oh :) that's good :) let's try it :)
     

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    I have apply your change mm :) and when i was debugging, i need to change back to :
    GUIGraphicsContext.DeviceAudioConnected = GUIGraphicsContext.DeviceAudioConnected - 1;
    and
    GUIGraphicsContext.DeviceAudioConnected = GUIGraphicsContext.DeviceAudioConnected + 1;

    Instead of

    GUIGraphicsContext.DeviceAudioConnected = GUIGraphicsContext.DeviceAudioConnected++;
    and
    GUIGraphicsContext.DeviceAudioConnected = GUIGraphicsContext.DeviceAudioConnected--;

    With ++ or -- , it foes something wrong :
    For ex :

    It should remove -1 and it does that : remove + add so in final the count didn't decrease.
    The same happen when audio device is added.

    No clue why right now :) i continue testing by keeping +1 and -1 for now.
     

    Users who are viewing this thread

    Top Bottom