[MP1-4838] Volume control no longer functions properly when changing audio device (1 Viewer)

Rick164

Super User
  • Team MediaPortal
  • Super User
  • January 7, 2006
    1,335
    1,005
    Netherlands Netherlands
    Country flag
    Hi,

    Been debugging an issue with @Virtual in the AudioSwitcher topic and is as follows:

    - Start Mediaportal with volume control set to master:




    - Test out volume control via keyboard for instance ( + -), will notice your audio device changing volume from sys tray.
    - Let Mediaportal run and change your default Windows audio device to something else either via AudioSwitcher plugin or Windows sound panel.
    - Test out volume control via keyboard, will notice your volume changing on your old Windows audio device instead and keep the current one as-is.

    Now so far it can be inconsistent and looking over the code below can't find any red flags, best guess is that we only set the audio device on startup and hook that up to volume control but don't check for changes afterwards (during volume events).
    While it works fine during playback you do lose Mediaportal volume control, anyone have any idea what is causing this?

    https://github.com/MediaPortal/MediaPortal-1/blob/master/mediaportal/Core/Player/VolumeHandler.cs

    Added Installer to Jira : https://issues.team-mediaportal.com/browse/MP1-4838 :p
    Thanks @Rick164
     
    Last edited by a moderator:

    Stéphane Lenclud

    Development Group
  • Team MediaPortal
  • April 29, 2013
    2,569
    1,293
    Germany Germany
    Country flag
    Best guess is that we only set the audio device on startup and hook that up to volume control but don't check for changes afterwards (during volume events).
    It seems so.
    That's unlikely to be an issue when using an HID remote or HID multimedia keyboard since we don't do anything other than letting the system do volume changes for us.
     

    Rick164

    Super User
  • Team MediaPortal
  • Super User
  • January 7, 2006
    1,335
    1,005
    Netherlands Netherlands
    Country flag
    Yeah that's how I do it at the moment for family and here via Flirc + Harmony which will be either via its bluetooth keyboard or emulated key press.
     

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,448
    10,276
    France
    France France
    Country flag
    In mediaportal.cs we have that : I think it's here the init is done : line 3123

    VolumeHandler.CreateInstance();
    GUIGraphicsContext.VolumeHandler = VolumeHandler.Instance;

    If we are looking in \mediaportal\Core\DShowNET\Helper\DirectShowUtil.cs line 905

    C#:
    try
                      {
                        // vh.Volume = 19660500 that means Audio endpoint device are not available.
                        if (GUIGraphicsContext.VolumeHandler != null && GUIGraphicsContext.VolumeHandler.Volume == 19660500) // Check if new audio device is connected
                        {
                          Log.Debug("DirectShowUtil: need dispose volume handler value {0}", GUIGraphicsContext.VolumeHandler.Volume);
                          VolumeHandler.Dispose();
                          GUIGraphicsContext.VolumeHandler = VolumeHandler.Instance;
                        }
                        if (GUIGraphicsContext.VolumeHandler != null && GUIGraphicsContext.VolumeHandler.Volume != 19660500 && GUIGraphicsContext.DeviceAudioConnected > 0)
                        {
                          Log.Debug("DirectShowUtil: volume handler value {0}", GUIGraphicsContext.VolumeHandler.Volume);
                          Log.Debug("DirectShowUtil: build the graph for PIN : {0}", pinName);
                          hr = graphBuilder.Render(pins[0]);
                        }
                      }
                      catch (Exception exception)
                      {
                        Log.Warn("DirectShowUtil: Could not initialize volume handler (don't connect Audio Pin) : {0}", exception.Message);
                      }
    That part does a reinit, maybe it's possible to reinit differently elsewhere ?
     

    Rick164

    Super User
  • Team MediaPortal
  • Super User
  • January 7, 2006
    1,335
    1,005
    Netherlands Netherlands
    Country flag
    Looked at that and seems we can create a new volume instance but does only help with OSD display but not for the actual volume, think we need a way to re-init it in DirectShowUtil or some event that will trigger if audio device changes (no longer primary).

    Ideally the volume control should always change it's default Windows audio device if set to "Default direct sound device" but not sure if that can be done easily.

    Code:
        private void SetPlaybackDevice(CoreAudioDevice device)
        {
          try
          {
            Log.Debug($"Audio Switcher - setting default playback device to: {device.FullName}");
            device.SetAsDefault();
            Log.Debug($"Device audio connected: {GUIGraphicsContext.DeviceAudioConnected}");
    
            if (Settings.LAVbitstreamPerDevice)
            {
              SetLavBitstreamSettings(device.FullName);
            }
    
            Log.Debug("Resetting volume control");
            Thread.Sleep(1000);
            VolumeHandler.Dispose();
            Thread.Sleep(1000);
            VolumeHandler.CreateInstance();
            Log.Debug("Volume control reset");
          }
          catch (Exception ex)
          {
            Log.Error("Error occured during SetPlaybackDevice()");
            Log.Error(ex.Message);
          }
        }
     

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,448
    10,276
    France
    France France
    Country flag
    So ideally we should kept some volume instance value before the change and restore it on new instance :)
    But i think we need also to do : GUIGraphicsContext.VolumeHandler = VolumeHandler.Instance;
    What do you think ?

    Edit : we need to get and restore GUIGraphicsContext.VolumeHandler.Volume i think.
     
    Last edited:

    Rick164

    Super User
  • Team MediaPortal
  • Super User
  • January 7, 2006
    1,335
    1,005
    Netherlands Netherlands
    Country flag
    Agree, we need to tie up the new instance however requires:

    - A way of knowing if it has changed and update accordingly
    - Change volume on the default Windows device if user has set video audio device to Default or new option in GUI where you can select which device to use like with video audio renderer (default directsound / device X etc..)

    Now the Win32 audio API is pretty hard to deal with and couldn't find any clear examples for events so far, this was one of the reasons I went with AudioSwitcher core API which has easy control and can be events driven (also async for most parts in latest beta)
    Integration with that probably won't work well with Mediaportal but the developer is very helpful as he wrote the wrapper for the Win32 audio API so might possibly have a solution so we could ask him on Github :)
     

    Stéphane Lenclud

    Development Group
  • Team MediaPortal
  • April 29, 2013
    2,569
    1,293
    Germany Germany
    Country flag

    Stéphane Lenclud

    Development Group
  • Team MediaPortal
  • April 29, 2013
    2,569
    1,293
    Germany Germany
    Country flag
    I've just cleaned up my usage of CScore to handle volume changes and default device change notification.
    It's now implemented in that AudioManager class. That could be a useful reference if ever we need to implement something similar in MP1.
     

    mm1352000

    Development Group
  • Team MediaPortal
  • September 1, 2008
    21,571
    8,219
    New Zealand New Zealand
    Country flag
    @Rick164
    If you're going down the path of investigating proper handling for audio device changes, I think our current code that tracks audio device connection/disconnection could do with a bit of love. Specifically:
    • Find an alternative way to enumerate audio devices at startup that doesn't require DirectShow (ie. replace -->this<--)
    • When an audio device is removed, detect whether that device was being used as the audio renderer for the playing media. Only stop playback if the device is being used. It might be possible to detect this better with a completely different method such as with DirectShow graph events (eg. this one).
     

    Users Who Are Viewing This Thread (Users: 0, Guests: 1)

    OP Similar threads Forum Replies Date
    ajs [Proposal] Improving the MP1 Small Splash Screen, providing nicer Image :) MediaPortal 1 3
    ajs [News] MediaPortal 1.26 Pre-Release ready for testing! News and Announcements 0
    C Hauppauge HVR-1265 -- does it work with MP1? MediaPortal 1 Talk 1
    ajs MP2Web - MP1 compatibility MediaPortal 1 20
    T MadVR + LAV Filters, Perfect in MPC-BE, Bad in MP1 MediaPortal 1 Talk 13
    P MP2: US user, OTA - can NOT get SchedulesDirect plugin to work on MP1 or MP2 --> how do I get OTA schedule? General 5
    framug [solved] Some changes/fix in MP1 configuration client and server Submit: code patches (MediaPortal/TV-Server/etc.) 14
    S TV-Server MP1 - Automatic search doesn't work Installation, configuration support 2
    C Streaming/transcoding MP2 vs MP1? General 4
    ajs [fixed] 5015: Improving the MP1 installer, providing nicer GUI :) MediaPortal 1 138
    C Streaming to clients over Wifi. MP1 or MP2? Newcomers Forum 0
    S Shortcuts MP1 My Recorded & TV Guide General 10
    azzuro [WiP] MP1-4999 - Big changes with many related change at once by Sebastiii MediaPortal 1 22
    ajs [WiP] MP1 X64 Version MediaPortal 1 70
    joecrow How about a Launcher plugin for MP1? MediaPortal 1 6
    wizard123 [solved] MP1 Build help MediaPortal 1 21
    ajs [News] MediaPortal 1 - 1.24 Released! News and Announcements 3
    CyberSimian [fixed] MP1-4990 : Improve horizontal scrolling in the EPG MediaPortal 1 10
    azzuro [WiP] MP1-5019: Replace MySQL with MariaDB MediaPortal 1 40
    catalpa Umsteiger von MP1: Schwierigkeiten Allgemeines Support- und Diskussionsforum 17
    CyberSimian [solved] MP1-4976 Built-in skin variables for current date MediaPortal 1 8
    rbo [solved] Umsteiger MP1 zu MP2 Allgemeines Support- und Diskussionsforum 67
    azzuro [Info] MP2 TVE inside MP1 repo MediaPortal 2 12
    G MP1 TV Server "failed to upgrade the database" using MS Sql Server Installation, configuration support 3
    lisag Can I get MP1 to open in the Recorded TV screen? MediaPortal 1 Talk 2
    Similar threads

























    Top Bottom