moonlight-stream / moonlight-qt

GameStream client for PCs (Windows, Mac, Linux, and Steam Link)
GNU General Public License v3.0
10.65k stars 621 forks source link

After upgrading SDL2 from 2.0.22-2 to 2.24.0-1, get crackling noise when running Moonlight #858

Closed NebuPookins closed 2 years ago

NebuPookins commented 2 years ago

Describe the bug

I'm running Archlinux. I performed a system upgrade today, and there were no updates to Moonlight, but there was an update to the SDL2 library. After the update, whenever I connect to another machine via Moonlight, all audio produced by my machine becomes very crackly, including audio produced by other apps. For example, I can have a YouTube video running in the background, and as long as Moonlight isn't connected to another machine , the audio is fine. As soon as I connect to my remote desktop, the audio becomes crackly.

If I rollback the update to the SDL2 library, I am able to use Moonlight just fine with no audio distortion.

I'm not sure if this problem is specific to the way Moonlight is calling the SDL2 APIs. I was not able to reproduce the issue when using snes9x-gtk nor supertuxkart which I believe also use SDL2.

Steps to reproduce

Client PC details (please complete the following information)

Server PC details (please complete the following information)

Moonlight Logs (please attach)

With the SDL2 2.0.24.0-1 (problem is present):

00:00:47 - SDL Info (0): Found host supported resolution: 1920x1080
00:00:47 - Qt Info: Executing request: "https://192.168.1.111:47984/resume?uniqueid=0123456789ABCDEF&uuid=7dc15b31618f432db88b11a6de10bb22&rikey=5d5e351f8468e1ee59bcc70e214afe8a&rikeyid=-1510896658&surroundAudioInfo=196610"
00:00:48 - Qt Info: Resume response: "<?xml version=\"1.0\" encoding=\"UTF-16\"?><root protocol_version=\"0.1\" query=\"resume\" status_code=\"200\" status_message=\"OK\"><DisplayHeight>1080</DisplayHeight><DisplayWidth>1920</DisplayWidth><HdrMode>0</HdrMode><RefreshRate>60</RefreshRate><avkey>ok</avkey><gamesession>79cde68e8043527d1ef62fd45deeba29</gamesession><resume>1</resume><rikey>ok</rikey><sessionUrl0>rtsp://192.168.1.111:48010</sessionUrl0></root>"
00:00:48 - Qt Info: Found matching interface: "enp27s0" "00:D8:61:4F:E3:11" QFlags<QNetworkInterface::InterfaceFlag>(IsUp|IsRunning|CanBroadcast|CanMulticast)
00:00:48 - Qt Info: Interface Type: QNetworkInterface::Ethernet
00:00:48 - Qt Info: Interface MTU: 1500
00:00:48 - SDL Info (0): RTSP port: 48010
00:00:48 - SDL Info (0): Initializing platform...
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Resolving host name...
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Initializing audio stream...
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Starting RTSP handshake...
00:00:48 - SDL Info (0): Audio port: 48000
00:00:48 - SDL Info (0): Video port: 47998
00:00:48 - SDL Info (0): Control port: 47999
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Initializing control stream...
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Initializing video stream...
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Initializing input stream...
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Starting control stream...
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Starting video stream...
00:00:48 - SDL Info (0): Video stream is 1920x1080x60 (format 0x100)
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Starting audio stream...
00:00:48 - SDL Info (0): Desired audio buffer: 240 samples (960 bytes)
00:00:48 - SDL Info (0): Obtained audio buffer: 240 samples (960 bytes)
00:00:48 - SDL Info (0): Audio stream has 2 channels
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Starting input stream...
00:00:48 - SDL Info (0): Received first audio packet after 0 ms
00:00:48 - SDL Info (0): Initial audio resync period: 510 milliseconds
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Qt UI screen is at (1920,1080)
00:00:48 - SDL Info (0): SDL found matching display 0
00:00:48 - SDL Info (0): Received first video packet after 0 ms
00:00:48 - SDL Info (0): Gamepad 0 (player 0) is: Microsoft Xbox One S (haptic capabilities: 0x10000) (mapping: 030000005e040000ea02000008040000 -> 030000005e040000ea02000008040000,Microsoft Xbox One S,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,)
00:00:48 - SDL Info (0): Recreating renderer for window event: 1 (0 0)
00:00:48 - SDL Warn (0): Disabling V-sync because refresh rate limit exceeded
00:00:48 - SDL Info (0): V-sync disabled
00:00:48 - SDL Info (0): Initialized VAAPI 1.15
00:00:48 - SDL Info (0): Driver: Mesa Gallium driver 22.1.6 for AMD Radeon RX 580 Series (polaris10, LLVM 14.0.6, DRM 3.47, 5.19.3-arch1-1)
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Format 0x3231564e -> nv12.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Format 0x30313050 -> p010le.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Format 0x36313050 -> unknown.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Format 0x30323449 -> yuv420p.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Format 0x32315659 -> yuv420p.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Format 0x56595559 -> unknown.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Format 0x32595559 -> yuyv422.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Format 0x59565955 -> uyvy422.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Format 0x41524742 -> bgra.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Format 0x41424752 -> rgba.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Format 0x58524742 -> bgr0.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Format 0x58424752 -> rgb0.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] VAAPI driver: Mesa Gallium driver 22.1.6 for AMD Radeon RX 580 Series (polaris10, LLVM 14.0.6, DRM 3.47, 5.19.3-arch1-1).
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a4401b780] Driver not found in known nonstandard list, using standard behaviour.
00:00:48 - SDL Info (0): Selected overlay subpicture format: BGRA8888
00:00:48 - SDL Info (0): VAAPI driver supports exporting DRM PRIME surface handles with separate layers
00:00:48 - SDL Info (0): Color buffer is: R8G8B8A0
00:00:48 - SDL Info (0): Using VAAPI accelerated renderer on x11
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] nal_unit_type: 32(VPS), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] nal_unit_type: 33(SPS), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] nal_unit_type: 34(PPS), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] nal_unit_type: 21(CRA_NUT), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Decoding VPS
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Main profile bitstream
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Decoding SPS
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Main profile bitstream
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Decoding VUI
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Decoding PPS
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Format vaapi chosen by get_format().
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Format vaapi requires hwaccel initialisation.
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Considering format 0x3231564e -> nv12.
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Picked nv12 (0x3231564e) as best match for yuv420p.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x1.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Direct mapping disabled: deriving image does not work: 1 (operation failed).
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x2.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x3.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x4.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x5.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x6.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x7.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x8.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x9.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0xa.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0xb.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0xc.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0xd.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0xe.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0xf.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x10.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x11.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x12.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x13.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3a4488ed40] Created surface 0x14.
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Decode context initialised: 0x15/0x16.
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Output frame with POC 3.
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Param buffer (type 0, 604 bytes) is 0x17.
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Slice 0 param buffer (264 bytes) is 0x18.
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Slice 0 data buffer (237 bytes) is 0x19.
00:00:48 - FFmpeg: [hevc @ 0x7f3a4488bcc0] Decode to surface 0x14.
00:00:48 - SDL Info (0): Video decode unit queue overflow
00:00:48 - SDL Info (0): IDR frame request sent
00:00:48 - SDL Info (0): Initialized VAAPI 1.15
00:00:48 - SDL Info (0): Driver: Mesa Gallium driver 22.1.6 for AMD Radeon RX 580 Series (polaris10, LLVM 14.0.6, DRM 3.47, 5.19.3-arch1-1)
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Format 0x3231564e -> nv12.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Format 0x30313050 -> p010le.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Format 0x36313050 -> unknown.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Format 0x30323449 -> yuv420p.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Format 0x32315659 -> yuv420p.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Format 0x56595559 -> unknown.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Format 0x32595559 -> yuyv422.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Format 0x59565955 -> uyvy422.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Format 0x41524742 -> bgra.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Format 0x41424752 -> rgba.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Format 0x58524742 -> bgr0.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Format 0x58424752 -> rgb0.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] VAAPI driver: Mesa Gallium driver 22.1.6 for AMD Radeon RX 580 Series (polaris10, LLVM 14.0.6, DRM 3.47, 5.19.3-arch1-1).
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f3a44d8c480] Driver not found in known nonstandard list, using standard behaviour.
00:00:48 - SDL Info (0): Selected overlay subpicture format: BGRA8888
00:00:48 - SDL Info (0): VAAPI driver supports exporting DRM PRIME surface handles with separate layers
00:00:48 - SDL Info (0): Color buffer is: R8G8B8A0
00:00:48 - SDL Info (0): Frame pacing disabled: target 30 Hz with 60 FPS stream
00:00:48 - SDL Info (0): Using VAAPI accelerated renderer on x11
00:00:48 - SDL Info (0): FFmpeg-based video decoder chosen
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] nal_unit_type: 32(VPS), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] nal_unit_type: 33(SPS), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] nal_unit_type: 34(PPS), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] nal_unit_type: 19(IDR_W_RADL), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Decoding VPS
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Main profile bitstream
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Decoding SPS
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Main profile bitstream
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Decoding VUI
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Decoding PPS
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Format vaapi chosen by get_format().
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Format vaapi requires hwaccel initialisation.
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Considering format 0x3231564e -> nv12.
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Picked nv12 (0x3231564e) as best match for yuv420p.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x1.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Direct mapping disabled: deriving image does not work: 1 (operation failed).
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x2.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x3.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x4.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x5.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x6.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x7.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x8.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x9.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0xa.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0xb.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0xc.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0xd.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0xe.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0xf.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x10.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x11.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x12.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x13.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f3aec01aac0] Created surface 0x14.
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Decode context initialised: 0x15/0x16.
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Output frame with POC 0.
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Param buffer (type 0, 604 bytes) is 0x17.
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Slice 0 param buffer (264 bytes) is 0x18.
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Slice 0 data buffer (50569 bytes) is 0x19.
00:00:48 - FFmpeg: [hevc @ 0x7f3a442eb0c0] Decode to surface 0x14.
00:00:48 - SDL Info (0): Dropping window event during flush: 1 (0 0)
00:00:48 - SDL Info (0): Dropping window event during flush: 6 (1627 348)
00:00:48 - SDL Info (0): EGLRenderer: EGLImage pixel format: 23
00:00:48 - Qt Info: Found "egl_nv12.vert" at ":/data/egl_nv12.vert"
00:00:48 - Qt Info: Found "egl_nv12.frag" at ":/data/egl_nv12.frag"
00:00:48 - Qt Info: Found "egl_overlay.vert" at ":/data/egl_overlay.vert"
00:00:48 - Qt Info: Found "egl_overlay.frag" at ":/data/egl_overlay.frag"
00:00:48 - SDL Info (0): Requesting IDR frame on behalf of DR
00:00:48 - SDL Info (0): IDR frame request sent

With SDL 2.0.22-2 (problem is absent):

00:00:47 - SDL Info (0): Found host supported resolution: 1920x1080
00:00:47 - Qt Info: Executing request: "https://192.168.1.111:47984/resume?uniqueid=0123456789ABCDEF&uuid=92a6759b1f3a40b98771861ca4a23dc6&rikey=a6620ec7a90a7a14e9657fccb2bcb7ad&rikeyid=-401265758&surroundAudioInfo=196610"
00:00:47 - Qt Info: Resume response: "<?xml version=\"1.0\" encoding=\"UTF-16\"?><root protocol_version=\"0.1\" query=\"resume\" status_code=\"200\" status_message=\"OK\"><DisplayHeight>1080</DisplayHeight><DisplayWidth>1920</DisplayWidth><HdrMode>0</HdrMode><RefreshRate>60</RefreshRate><avkey>ok</avkey><gamesession>79cde68e8043527d1ef62fd45deeba29</gamesession><resume>1</resume><rikey>ok</rikey><sessionUrl0>rtsp://192.168.1.111:48010</sessionUrl0></root>"
00:00:47 - Qt Info: Found matching interface: "enp27s0" "00:D8:61:4F:E3:11" QFlags<QNetworkInterface::InterfaceFlag>(IsUp|IsRunning|CanBroadcast|CanMulticast)
00:00:47 - Qt Info: Interface Type: QNetworkInterface::Ethernet
00:00:47 - Qt Info: Interface MTU: 1500
00:00:47 - SDL Info (0): RTSP port: 48010
00:00:47 - SDL Info (0): Initializing platform...
00:00:47 - SDL Info (0): done
00:00:47 - SDL Info (0): Resolving host name...
00:00:47 - SDL Info (0): done
00:00:47 - SDL Info (0): Initializing audio stream...
00:00:47 - SDL Info (0): done
00:00:47 - SDL Info (0): Starting RTSP handshake...
00:00:48 - SDL Info (0): Audio port: 48000
00:00:48 - SDL Info (0): Video port: 47998
00:00:48 - SDL Info (0): Control port: 47999
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Initializing control stream...
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Initializing video stream...
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Initializing input stream...
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Starting control stream...
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Starting video stream...
00:00:48 - SDL Info (0): Video stream is 1920x1080x60 (format 0x100)
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Starting audio stream...
00:00:48 - SDL Info (0): Desired audio buffer: 240 samples (960 bytes)
00:00:48 - SDL Info (0): Obtained audio buffer: 240 samples (960 bytes)
00:00:48 - SDL Info (0): Audio stream has 2 channels
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Starting input stream...
00:00:48 - SDL Info (0): Received first audio packet after 0 ms
00:00:48 - SDL Info (0): Initial audio resync period: 530 milliseconds
00:00:48 - SDL Info (0): done
00:00:48 - SDL Info (0): Qt UI screen is at (1920,1080)
00:00:48 - SDL Info (0): SDL found matching display 0
00:00:48 - SDL Info (0): Received first video packet after 0 ms
00:00:48 - SDL Info (0): Gamepad 0 (player 0) is: Microsoft Xbox One S (haptic capabilities: 0x10000) (mapping: 030000005e040000ea02000008040000 -> 030000005e040000ea02000008040000,Microsoft Xbox One S,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,)
00:00:48 - SDL Info (0): Recreating renderer for window event: 1 (0 0)
00:00:48 - SDL Warn (0): Disabling V-sync because refresh rate limit exceeded
00:00:48 - SDL Info (0): V-sync disabled
00:00:48 - SDL Info (0): Initialized VAAPI 1.15
00:00:48 - SDL Info (0): Driver: Mesa Gallium driver 22.1.6 for AMD Radeon RX 580 Series (polaris10, LLVM 14.0.6, DRM 3.47, 5.19.3-arch1-1)
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Format 0x3231564e -> nv12.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Format 0x30313050 -> p010le.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Format 0x36313050 -> unknown.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Format 0x30323449 -> yuv420p.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Format 0x32315659 -> yuv420p.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Format 0x56595559 -> unknown.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Format 0x32595559 -> yuyv422.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Format 0x59565955 -> uyvy422.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Format 0x41524742 -> bgra.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Format 0x41424752 -> rgba.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Format 0x58524742 -> bgr0.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Format 0x58424752 -> rgb0.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] VAAPI driver: Mesa Gallium driver 22.1.6 for AMD Radeon RX 580 Series (polaris10, LLVM 14.0.6, DRM 3.47, 5.19.3-arch1-1).
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e401c940] Driver not found in known nonstandard list, using standard behaviour.
00:00:48 - SDL Info (0): Selected overlay subpicture format: BGRA8888
00:00:48 - SDL Info (0): VAAPI driver supports exporting DRM PRIME surface handles with separate layers
00:00:48 - SDL Info (0): Color buffer is: R8G8B8A0
00:00:48 - SDL Info (0): Using VAAPI accelerated renderer on x11
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] nal_unit_type: 32(VPS), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] nal_unit_type: 33(SPS), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] nal_unit_type: 34(PPS), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] nal_unit_type: 21(CRA_NUT), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Decoding VPS
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Main profile bitstream
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Decoding SPS
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Main profile bitstream
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Decoding VUI
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Decoding PPS
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Format vaapi chosen by get_format().
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Format vaapi requires hwaccel initialisation.
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Considering format 0x3231564e -> nv12.
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Picked nv12 (0x3231564e) as best match for yuv420p.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x1.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Direct mapping disabled: deriving image does not work: 1 (operation failed).
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x2.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x3.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x4.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x5.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x6.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x7.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x8.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x9.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0xa.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0xb.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0xc.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0xd.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0xe.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0xf.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x10.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x11.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x12.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x13.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f80e450f4c0] Created surface 0x14.
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Decode context initialised: 0x15/0x16.
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Output frame with POC 3.
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Param buffer (type 0, 604 bytes) is 0x17.
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Slice 0 param buffer (264 bytes) is 0x18.
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Slice 0 data buffer (237 bytes) is 0x19.
00:00:48 - FFmpeg: [hevc @ 0x7f80e48392c0] Decode to surface 0x14.
00:00:48 - SDL Info (0): Initialized VAAPI 1.15
00:00:48 - SDL Info (0): Driver: Mesa Gallium driver 22.1.6 for AMD Radeon RX 580 Series (polaris10, LLVM 14.0.6, DRM 3.47, 5.19.3-arch1-1)
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Format 0x3231564e -> nv12.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Format 0x30313050 -> p010le.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Format 0x36313050 -> unknown.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Format 0x30323449 -> yuv420p.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Format 0x32315659 -> yuv420p.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Format 0x56595559 -> unknown.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Format 0x32595559 -> yuyv422.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Format 0x59565955 -> uyvy422.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Format 0x41524742 -> bgra.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Format 0x41424752 -> rgba.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Format 0x58524742 -> bgr0.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Format 0x58424752 -> rgb0.
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] VAAPI driver: Mesa Gallium driver 22.1.6 for AMD Radeon RX 580 Series (polaris10, LLVM 14.0.6, DRM 3.47, 5.19.3-arch1-1).
00:00:48 - FFmpeg: [AVHWDeviceContext @ 0x7f80e4784140] Driver not found in known nonstandard list, using standard behaviour.
00:00:48 - SDL Info (0): Selected overlay subpicture format: BGRA8888
00:00:48 - SDL Info (0): Video decode unit queue overflow
00:00:48 - SDL Info (0): IDR frame request sent
00:00:48 - SDL Info (0): VAAPI driver supports exporting DRM PRIME surface handles with separate layers
00:00:48 - SDL Info (0): Color buffer is: R8G8B8A0
00:00:48 - SDL Info (0): Frame pacing disabled: target 30 Hz with 60 FPS stream
00:00:48 - SDL Info (0): Using VAAPI accelerated renderer on x11
00:00:48 - SDL Info (0): FFmpeg-based video decoder chosen
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] nal_unit_type: 32(VPS), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] nal_unit_type: 33(SPS), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] nal_unit_type: 34(PPS), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] nal_unit_type: 19(IDR_W_RADL), nuh_layer_id: 0, temporal_id: 0
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Decoding VPS
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Main profile bitstream
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Decoding SPS
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Main profile bitstream
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Decoding VUI
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Decoding PPS
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Format vaapi chosen by get_format().
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Format vaapi requires hwaccel initialisation.
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Considering format 0x3231564e -> nv12.
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Picked nv12 (0x3231564e) as best match for yuv420p.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x1.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Direct mapping disabled: deriving image does not work: 1 (operation failed).
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x2.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x3.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x4.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x5.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x6.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x7.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x8.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x9.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0xa.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0xb.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0xc.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0xd.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0xe.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0xf.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x10.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x11.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x12.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x13.
00:00:48 - FFmpeg: [AVHWFramesContext @ 0x7f803c1798c0] Created surface 0x14.
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Decode context initialised: 0x15/0x16.
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Output frame with POC 0.
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Param buffer (type 0, 604 bytes) is 0x17.
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Slice 0 param buffer (264 bytes) is 0x18.
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Slice 0 data buffer (50599 bytes) is 0x19.
00:00:48 - FFmpeg: [hevc @ 0x7f80e4402d00] Decode to surface 0x14.
00:00:48 - SDL Info (0): EGLRenderer: EGLImage pixel format: 23
00:00:48 - Qt Info: Found "egl_nv12.vert" at ":/data/egl_nv12.vert"
00:00:48 - Qt Info: Found "egl_nv12.frag" at ":/data/egl_nv12.frag"
00:00:48 - Qt Info: Found "egl_overlay.vert" at ":/data/egl_overlay.vert"
00:00:48 - Qt Info: Found "egl_overlay.frag" at ":/data/egl_overlay.frag"
00:00:48 - SDL Info (0): Dropping window event during flush: 1 (0 0)
00:00:48 - SDL Info (0): Dropping window event during flush: 6 (1627 277)
00:00:48 - SDL Info (0): Requesting IDR frame on behalf of DR
00:00:48 - SDL Info (0): IDR frame request sent
cgutman commented 2 years ago

What audio output device are you using? Is the issue specific to one type of output (ex: Bluetooth vs HDMI vs headphones)?

I know SDL 2.24 had changes to the PulseAudio backend, but I'm not sure how one application would affect everything on the system.

NebuPookins commented 2 years ago

I have two audio devices, and the issue occurs with both of them.

  1. Ellesmere HDMI Audio [Radeon Rx 470/480/570/580/590] Digital Surround 5.1 (HDMI 5)
  2. Family 17h (Models 00h-0fh) HD Audio Controller Analog Stereo

The issue only affects apps that are playing audio on the same device as Moonlight. For example, if YouTube is outputting audio to the Family 17h device, and Moonlight is configured to use the Ellesmere HDMI Audio device, then YouTube's audio will not be distorted. If I switch Moonlight over to use the Family 17h device, YouTube's audio will become distorted. If I switch Moonlight back to Ellesmere HDMI Audio, YouTube's audio will become clear again.

NebuPookins commented 2 years ago

I'm able to reproduce the problem with the following program. Compiling and running this program causes audio in other apps (e.g. Youtube) to become distorted when SDL 2.24.0-1 is installed. There is no audio distortion if 2.0.22-2 is installed.

#include <SDL2/SDL.h>
#include <stdio.h>

int main(int argc, char* args[]) {
    int initResult = SDL_Init(SDL_INIT_AUDIO);
    if (initResult < 0) {
        printf("SDL could not initialize: %s\n", SDL_GetError());
        return -1;
    }

    SDL_AudioSpec want, have;
    SDL_zero(want);
    want.freq = 48000;
    want.format = AUDIO_S16;
    want.channels = 2;
    want.samples = 240;

    SDL_AudioDeviceID dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
    printf("Waiting to continue...");
    getchar();
    SDL_Quit();
}
NebuPookins commented 2 years ago

Because the program to reproduce the issue is so simple, I'm guessing this is a bug in SDL and not Moonlight. I've filed a issue with SDL at https://github.com/libsdl-org/SDL/issues/6121

NebuPookins commented 2 years ago

It looks like the issue is related to the number of samples requested at https://github.com/moonlight-stream/moonlight-qt/blob/master/app/streaming/audio/renderers/sdlaud.cpp#L29-L33

If you request a value that's too low like 240, this does something "globally" which causes audio from other programs to become choppy. If you request a value that's too big like 4096, then audio in other programs are fine, but audio produced by Moonlight (originating from the remote PC) becomes choppy, I guess because whatever logic there is in Moonlight does not fill the buffer quickly enough.

I'm not sure where the value 240 comes from, perhaps https://github.com/moonlight-stream/moonlight-qt/blob/master/app/streaming/audio/audio.cpp#L94

If I set the samples to 480, I get no audio problems in Moonlight nor in other programs, so I've made the following workaround in https://github.com/moonlight-stream/moonlight-qt/blob/master/app/streaming/audio/renderers/sdlaud.cpp#L29-L33

diff --git a/app/streaming/audio/renderers/sdlaud.cpp b/app/streaming/audio/renderers/sdlaud.cpp
index 0d931a43..85da4a6a 100644
--- a/app/streaming/audio/renderers/sdlaud.cpp
+++ b/app/streaming/audio/renderers/sdlaud.cpp
@@ -1,5 +1,5 @@
 #include "sdl.h"
-
+#include <algorithm>
 #include <Limelight.h>
 #include <SDL.h>

@@ -30,7 +30,7 @@ bool SdlAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION*
     // frames contain a non-power of 2 number of samples,
     // so the slop would require buffering another full frame.
     // Specifying non-Po2 seems to work for our supported platforms.
-    want.samples = opusConfig->samplesPerFrame;
+    want.samples = std::max(480, opusConfig->samplesPerFrame);

     m_FrameSize = opusConfig->samplesPerFrame * sizeof(short) * opusConfig->channelCount;

I'm not sure if this is a change worth merging in, or if there was a specific reason 480 is "too big" and you really want to stick with 240.

cgutman commented 2 years ago

@NebuPookins Huge thanks for your investigation and creating a test case for SDL.

I think I never saw this because I run Fedora which use Pipewire instead of PulseAudio.