ShayBox / Mon2Cam

Workaround for multi-monitor Discord screensharing
MIT License
337 stars 33 forks source link

NaN index of audio source #48

Closed jedenastka closed 3 years ago

jedenastka commented 3 years ago

For some reason, the index of any audio sources I have is shown as NaN, making it so I can't select it.

My system:

~/programy/Mon2Cam/src $ inxi -Fx
System:
  Host: pecet Kernel: 5.8.0-8.1-liquorix-amd64 x86_64 bits: 64 
  compiler: N/A Desktop: KDE Plasma 5.19.5 
  Distro: Debian GNU/Linux bullseye/sid 
Machine:
  Type: Desktop System: Dell product: OptiPlex 790 v: 01 
  serial: <superuser/root required> 
  Mobo: Dell model: 0J3C2F v: A00 serial: <superuser/root required> 
  BIOS: Dell v: A07 date: 09/10/2011 
CPU:
  Info: Quad Core model: Intel Core i5-2400 bits: 64 type: MCP 
  arch: Sandy Bridge rev: 7 L2 cache: 6144 KiB 
  flags: avx lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx 
  bogomips: 24742 
  Speed: 2456 MHz min/max: 1600/3101 MHz Core speeds (MHz): 1: 2826 2: 2285 
  3: 2588 4: 3239 
Graphics:
  Device-1: NVIDIA GK106 [GeForce GTX 660] vendor: Micro-Star MSI 
  driver: nvidia v: 450.66 bus ID: 03:00.0 
  Display: x11 server: X.Org 1.20.8 driver: nvidia resolution: 1280x1024 
  OpenGL: renderer: GeForce GTX 660/PCIe/SSE2 v: 4.6.0 NVIDIA 450.66 
  direct render: Yes 
Audio:
  Device-1: Intel 6 Series/C200 Series Family High Definition Audio 
  vendor: Dell driver: snd_hda_intel v: kernel bus ID: 00:1b.0 
  Device-2: NVIDIA GK106 HDMI Audio vendor: Micro-Star MSI 
  driver: snd_hda_intel v: kernel bus ID: 03:00.1 
  Device-3: Logitech Webcam C270 type: USB driver: snd-usb-audio,uvcvideo 
  bus ID: 2-1.2:4 
  Sound Server: ALSA v: k5.8.0-8.1-liquorix-amd64 
Network:
  Device-1: Intel 82579LM Gigabit Network vendor: Dell driver: e1000e 
  v: 3.2.6-k port: 4040 bus ID: 00:19.0 
  IF: eno1 state: up speed: 100 Mbps duplex: full mac: 18:03:73:b0:66:be 
Drives:
  Local Storage: total: 1.02 TiB used: 725.01 GiB (69.5%) 
  ID-1: /dev/sda vendor: Seagate model: ST1000DM003-1SB10C size: 931.51 GiB 
  ID-2: /dev/sdb vendor: GOODRAM model: N/A size: 111.79 GiB 
Partition:
  ID-1: / size: 58.81 GiB used: 37.80 GiB (64.3%) fs: ext4 dev: /dev/sdb3 
  ID-2: /home size: 901.04 GiB used: 687.21 GiB (76.3%) fs: ext4 
  dev: /dev/sda1 
Swap:
  ID-1: swap-1 type: partition size: 15.09 GiB used: 0 KiB (0.0%) 
  dev: /dev/sda5 
Sensors:
  System Temperatures: cpu: 47.0 C mobo: N/A gpu: nvidia temp: 47 C 
  Fan Speeds (RPM): N/A gpu: nvidia fan: 33% 
Info:
  Processes: 248 Uptime: 1h 01m Memory: 7.73 GiB used: 2.32 GiB (29.9%) 
  Init: systemd runlevel: 5 Compilers: gcc: 10.2.0 clang: 9.0.1-14 
  Packages: 4164 Shell: Zsh v: 5.8 inxi: 3.1.06 
~/programy/Mon2Cam/src $ 

Log (trying VLC here):

~/programy/Mon2Cam/src $ ~/programy/deno run -A -r -q --unstable --no-check mod.ts -r 1920:1080 -b -s
NaN: VLC media player (LibVLC 3.0.11.1)
Choose which applications you want to route(space separated list):

ParsedOutputElement { index: -1, arguments: {}, properties: {} }
ParsedOutputElement {
  index: NaN,
  arguments: {
    Stan: "SUSPENDED",
    Nazwa: "VirtualSinkMIC.7.monitor",
    Opis: "Monitor of Mon2CamMicrophoneSink",
    Sterownik: "module-null-sink.c",
    "Okre��lenie pr��bki": "s16le 2 k 44100���Hz",
    "Mapa kana����w": "front-left,front-right",
    "W��a��ciciel modu��u": "34",
    Wyciszenie: "nie",
    "Poziom g��o��no��ci": "front-left",
    "G��o��no���� podstawowa": "65536 / 100% / 0,00 dB",
    "Monitor odp��ywu": "VirtualSinkMIC.7",
    "Op����nienie": "0���us, skonfigurowano 0���us"
  },
  properties: {
    "device.description": '"Monitor of Mon2CamMicrophoneSink"',
    "device.class": '"monitor"',
    "device.icon_name": '"audio-input-microphone"'
  }
}
INFO No valid sources found
WARN No applications, nor any sources passed. Why are you using the sound flag?
~/programy/Mon2Cam/src $ 
botiapa commented 3 years ago

Could you run Mon2Cam with the -v (verbose) flag, and post the results?

jedenastka commented 3 years ago

Here you are, sorry for late response:

~/programy/Mon2Cam/src $ ~/programy/deno run -A -r -q --unstable mod.ts -v -r 1920:1080 -b -s
DEBUG Starting Mon2Cam with the following options: Options {
  framerate: 60,
  device: 50,
  resolution: "1920:1080",
  ffmpeg: [],
  border: true,
  sound: true,
  wayland: false,
  loggerOptions: { verbose: true },
  execOptions: { verbose: true, output: 3 }
}
DEBUG Checking if V4L2 device exists
DEBUG V4L2 device found with id 50

Exec Context: c811e248-8c27-4dd6-8eba-f96edd290a04
    Exec Options:  { verbose: true, output: 3 }
    Exec Command: pactl list sink-inputs
    Exec Command Splits:  [pactl,list,sink-inputs]
    Exec Result:  { code: 0, success: true },
 output: "110. odp��yw wej��cia
        Sterownik: protocol-native.c
        W��a��ciciel modu��u: 9
        Klient: 125
        Odp��yw: 0
        Okre��lenie pr��bki: s16le 2 k 48000���Hz
        Mapa kana����w: front-left,front-right
        Format: pcm, format.sample_format = "\"s16le\""  format.channels = "2"  format.rate = "48000"  format.channel_map = "\"front-left,front-right\""
        Zakorkowane: nie
        Wyciszenie: nie
        Poziom g��o��no��ci: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
                          balans 0,00
        Op����nienie bufora: 35875���us
        Op����nienie odp��ywu: 90440���us
        Metoda resamplingu: nie dotyczy
        W��a��ciwo��ci:
                media.name = "'Panda Eyes & Teminite - Adventure Time' autorstwa 'OfficialPandaEyes'"
                application.name = "strawberry"
                native-protocol.peer = "UNIX socket client"
                native-protocol.version = "33"
                media.role = "music"
                application.process.id = "14325"
                application.process.user = "grzesiek11"
                application.process.host = "pecet"
                application.process.binary = "strawberry"
                application.language = "pl_PL.UTF-8"
                window.x11.display = ":0"
                application.process.machine_id = "92d06525e6514bd4bdccd0fed88afa08"
                application.process.session_id = "3"
                module-stream-restore.id = "sink-input-by-media-role:music"
                media.title = "Panda Eyes & Teminite - Adventure Time"
                media.artist = "OfficialPandaEyes""
Exec Context: c811e248-8c27-4dd6-8eba-f96edd290a04

NaN: strawberry
Choose which applications you want to route(space separated list):
NaN
DEBUG Exiting
PANIC You need to pass a space separated list e.g.:"3 14"
~/programy/Mon2Cam/src $ 
botiapa commented 3 years ago

Hmm weird, for some reason the command's output is translated to your language. I'm not sure how we can disable this.

botiapa commented 3 years ago

Could you run pactl list sink-inputs but with the LANG environment variable set to en_US.UTF8?

Edit: Nevermind, it seems to disrespect this variable it seems.

ShayBox commented 3 years ago

LANG=C pactl is usually the lang most systems have generated

jedenastka commented 3 years ago

LANG= worked, as usual:

~ $ LANG= pactl list sink-inputs
Sink Input #5
        Driver: protocol-native.c
        Owner Module: 9
        Client: 20
        Sink: 0
        Sample Specification: s16le 2ch 48000Hz
        Channel Map: front-left,front-right
        Format: pcm, format.sample_format = "\"s16le\""  format.channels = "2"  format.rate = "48000"  format.channel_map = "\"front-left,front-right\""
        Corked: no
        Mute: no
        Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        Buffer Latency: 105916 usec
        Sink Latency: 83389 usec
        Resample method: n/a
        Properties:
                media.name = "'TheFatRat & Slaydit - Solitude' autorstwa 'TheFatRat'"
                application.name = "strawberry"
                native-protocol.peer = "UNIX socket client"
                native-protocol.version = "33"
                media.role = "music"
                application.process.id = "3349"
                application.process.user = "grzesiek11"
                application.process.host = "pecet"
                application.process.binary = "strawberry"
                application.language = "pl_PL.UTF-8"
                window.x11.display = ":0"
                application.process.machine_id = "92d06525e6514bd4bdccd0fed88afa08"
                application.process.session_id = "3"
                module-stream-restore.id = "sink-input-by-media-role:music"
                media.title = "TheFatRat & Slaydit - Solitude"
                media.artist = "TheFatRat"
~ $ 
jedenastka commented 3 years ago

Oh! I found the problem. It's actually the language, not anything else. I ran LANG= ~/programy/deno run -A -r -q --unstable mod.ts -v -r 1920:1080 -b -s and it works as intended!

Maybe the code has trouble parsing non-ASCII characters (we have quite a lot of them in Polish - ęóąśłżźćń) or non-English languages at all?

I noticed that the output of pactl in my native language does indeed give the right Unicode characters and not :

~/programy/Mon2Cam/src $ pactl list sink-inputs      
5. odpływ wejścia
        Sterownik: protocol-native.c
        Właściciel modułu: 9
        Klient: 20
        Odpływ: 0
        Określenie próbki: s16le 2 k 48000 Hz
        Mapa kanałów: front-left,front-right
        Format: pcm, format.sample_format = "\"s16le\""  format.channels = "2"  format.rate = "48000"  format.channel_map = "\"front-left,front-right\""
        Zakorkowane: nie
        Wyciszenie: nie
        Poziom głośności: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
                          balans 0,00
        Opóźnienie bufora: 42083 us
        Opóźnienie odpływu: 89540 us
        Metoda resamplingu: nie dotyczy
        Właściwości:
                media.name = "'TheFatRat & Phaera - Sunlight' autorstwa 'TheFatRat'"
                application.name = "strawberry"
                native-protocol.peer = "UNIX socket client"
                native-protocol.version = "33"
                media.role = "music"
                application.process.id = "3349"
                application.process.user = "grzesiek11"
                application.process.host = "pecet"
                application.process.binary = "strawberry"
                application.language = "pl_PL.UTF-8"
                window.x11.display = ":0"
                application.process.machine_id = "92d06525e6514bd4bdccd0fed88afa08"
                application.process.session_id = "3"
                module-stream-restore.id = "sink-input-by-media-role:music"
                media.title = "TheFatRat & Phaera - Sunlight"
                media.artist = "TheFatRat"
~/programy/Mon2Cam/src $ 

So the problem isn't in pactl itself.

botiapa commented 3 years ago

Yeah, the program can only parse the english version. Glad it worked out.

TODO: Add LANG= before commands, so this doesn't happen.

ShayBox commented 3 years ago

Just Deno.env.set("LANG", ""); might work for the entire program, testing needs to be done

ShayBox commented 3 years ago

I'll setup an arch vm with non english lang to reproduce and test this

ShayBox commented 3 years ago

I pushed a change that should fix non English lang systems