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

Rick164

MP Donator
  • Premium Supporter
  • January 7, 2006
    1,335
    1,005
    Home Country
    Netherlands Netherlands
    Hi,

    Since upgrading to 1.12 switching default audio devices makes the sound stop working after doing it more than once by the looks of it.

    EDIT : JIRA : https://issues.team-mediaportal.com/browse/MP1-4657

    Steps to reproduce

    - Watching movie on TV with AVR audio, which is current default audio device.
    - Stop movie and decide to listen with bluetooth audio device, turning it on makes it the default audio device.
    - Watch movie and sound works on bluetooth device
    - Stop movie and turn off bluetooth device, default audio device returns to AVR like in step 1 (double checked in Windows)
    - Watch movie, no sound coming out of speakers but do see it receiving a stream on the AVR display (PCM lights up) just with no actual sound.

    Only solution is to restart Mediaportal, prior to 1.12 this worked flawlessly.

    Attached the debug log while doing the noted steps.

    System info

    Mediaportal 1.12 final (same results with pre-release)
    Windows 8.1 x64
    NVIDIA GeForce GTX 970
    Denon AVR (LAV filters with bitstreaming enabled)
    Sony Headset but tested with other bluetooth audio devices.
    Generic bluetooth dongle

    Audio settings

    audioSettings.png
     
    Last edited by a moderator:

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    Hi :)
    So you change audio device playback from windows right ?
    I didn't have Bluetooth stuff, so i can't test but it's surely related to the change made for MP on resume, i didn't remember exactly but i think i store or get the audio device from the start of MP so maybe after changing it, it make it something not good, it seems that i didn't notice something wrong in log.
    So hard to tell but it's surely related to the MP1-4578.
     

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    I'm looking the branch and i have add :
    if (GUIGraphicsContext.DeviceAudioConnected)

    So it's when audio is connected / detected so maybe when changing audio device, it's removed but not connected or too late or something.
    That's not easy :( and i fear that if we remove this kind of check, it will break resume but i'm not 100% sure)
     

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    Ok i notice from log :
    Main: Audio Renderer Headphones (2- SBH80 Stereo) removed
    It the last line related to audio device.

    So it happen when you turned off the bluetooth device.

    And after that you start to play again and sound should go on AVR but it seems that like MP didn't detect the audio device back, you will get no more sound.

    It point to the fact that MP react on windows message but only if it receive it lol

    I already try to handle such of deconnection when it's only from going to standby or wakeup but it was not working correctly.

    So in final what happen here is :

    1- Windows send new audio device is there (AVR) but also give that bluetooth device is removed and if the message of the remove is done after AVR is there ->
    MP think that audio device is removed.
    2- Or from log MP didn't detect the change of audio device (the endpoint from windows).
    3- I'm pretty sure that if you turn off your AVR and turn ON it, MP will handle the new audio device arrival.

    So what is the best way to change that ? (no handling the audio device added/removed) ?
    I can or maybe you can comment out some line in MP code to confirm that :)

    I will go to comment out this line : 2079 in \mediaportal\MediaPortal.Application\MediaPortal.cs from case DBT_DEVICEREMOVECOMPLETE:

    GUIGraphicsContext.DeviceAudioConnected = false;

    Like this it will not handle the removed device.
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    So it's when audio is connected / detected so maybe when changing audio device, it's removed but not connected or too late or something.
    Surely you can't do it successfully like that, because you are not considering the situation where more than one audio renderer is available (like Rick164 has).

    I mean: connection of the BT headphones does not mean that the AVR is disconnected.

    So, actual sequence is:
    1. MP start - AVR available.
    2. BT headphones turned on - AVR and BT headphones available.
    3. BT headphones turned off - AVR available [still!!!]
    ...but with your code it seems like at step 3 you think the AVR is disconnected. That is a bug.
     

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    Thanks ;)
    We can see how a real dev is lol.

    That's good explanation, when i have rework this, i would like to keep the trace of each audio device, like this, like you said, when BT is removed, AVR should be kept etc.
    But i didn't succeed.
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    Looking at this commit:
    https://github.com/MediaPortal/MediaPortal-1/commit/3d5e0517c62c304bd5c11de89043519a4db24f3e

    Perhaps the easiest to solve the problem would be to change GUIGraphicsContext.DeviceAudioConnected from bool to byte/ushort/uint. Each time an audio renderer is connected, increase the value by 1; each time an audio renderer is disconnected, decrease the value by 1. If the value is 0, there is no audio device available. The value should never be allowed to go negative.
     

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    Great : it's related to mp1-4578 :
    SHA-1: 31efbcc27be16d42376fffdff755673cfec48990
    * MP1-4578 : Fix rare exception when audio device is removed and cleanup code

    In fact most of code are in mediaportal.cs :
    https://github.com/MediaPortal/MediaPortal-1/commit/31efbcc27be16d42376fffdff755673cfec48990

    Sorry, i most use tortoisegit to show diff between commit and rarely use github (i notice also that on force push, the change are not visible).

    Here it's the merging branch :
    https://github.com/MediaPortal/MediaPortal-1/commit/5165570b70109677e17924e56f3aa7f54ed7ffc8

    Look for : GUIGraphicsContext.DeviceAudioConnected

    I didn't succeed to keep track of first audio device (devicename) etc.
    What i have in mind is to store device name into a table and when remove, remove it from that table and new device added etc. and do something like if () to compare if device is available or not

    It seems too complex when i try to explain it and even more complex for me to code it lol
     

    Users who are viewing this thread

    Top Bottom