Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
b8f53a6
macOS でオーディオデバイス選択機能を追加する
voluntas Oct 14, 2025
98687fc
コスメ
voluntas Oct 14, 2025
b69b90f
macOS の --list-devices でビデオデバイス一覧も表示するようにする
voluntas Oct 14, 2025
b39d7ea
macOS オーディオデバイス選択のドキュメントとコードの整合性を取る
voluntas Oct 14, 2025
b2a3b49
Linux でオーディオデバイス一覧機能を追加する
voluntas Oct 14, 2025
b6e066e
Linux でオーディオシステムが利用できない場合もビデオデバイス一覧を表示するようにする
voluntas Oct 14, 2025
7c391a1
ざっくり linux device について追加する
voluntas Oct 14, 2025
32a0c84
Linux でオーディオデバイス選択機能を追加し PulseAudio API に統一する
voluntas Oct 15, 2025
9d0ecfc
PipeWire について追記する
voluntas Oct 15, 2025
e642a6d
Linux でのデバイスアクセスに関するドキュメントを削除する
voluntas Oct 15, 2025
bddec80
Merge branch 'develop' into feature/macos-audio-device-selection
voluntas Oct 15, 2025
ad3e6c5
video だけでなく audio も表示するのを明記
voluntas Oct 16, 2025
7138b7a
Merge branch 'develop' into feature/macos-audio-device-selection
voluntas Oct 16, 2025
fb81afa
Merge branch 'feature/macos-audio-device-selection' into feature/linu…
voluntas Oct 16, 2025
b1d7dc8
Merge branch 'feature/linux-audio-device-selection' of github.com:shi…
voluntas Oct 16, 2025
d2a014c
音声デバイス指定のセクションを追加する
voluntas Oct 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@
- 変更対象外の API
- `ctx.end()`, `ctx.save()` , `ctx.restore()` は単語なので変更なし
- @voluntas @torikizi
- [ADD] macOS でオーディオデバイス選択機能を追加
- `--audio-input-device` オプションでオーディオ入力デバイスを指定可能にする
- `--audio-output-device` オプションでオーディオ出力デバイスを指定可能にする
- デバイスはインデックス番号またはデバイス名(完全一致、大文字小文字を区別しない)で指定可能
- @voluntas
- [ADD] macOS で `--list-devices` オプションを追加
- 利用可能なオーディオデバイスとビデオデバイスの一覧を表示する機能
- @voluntas
- [ADD] Linux で `--list-devices` オプションにオーディオデバイス一覧表示を追加
- 既存のビデオデバイス一覧に加えて、オーディオ入力デバイスとオーディオ出力デバイスの一覧も表示するようにする
- @voluntas
- [ADD] Linux でオーディオデバイス選択機能を追加
- `--audio-input-device` オプションでオーディオ入力デバイスを指定可能にする
- `--audio-output-device` オプションでオーディオ出力デバイスを指定可能にする
- デバイスはインデックス番号またはデバイス名(完全一致、大文字小文字を区別しない)で指定可能
- PulseAudio API を使用
- pipewire-pulse 経由を想定
- @voluntas
- [UPDATE] Linux のオーディオデバイス選択を PulseAudio API に統一する
- ALSA 専用のデバイス選択コードを削除
- Ubuntu ビルドで `-DUSE_LINUX_PULSE_AUDIO=ON` を有効化
- AudioLayer を明示的に `kLinuxPulseAudio` に指定
- @voluntas
- [FIX] Ubuntu 環境のカメラで MJPEG より YUV が優先されてしまうのを修正
- @melpon
- [FIX] Ayame モードで `--video-codec-type` / `--audio-codec-type` が大小文字の不一致で無視される問題を修正
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ Momo は Sora モード利用時にクライアント証明書に対応してい

Momo は OpenH264 を利用して H.264 のソフトウェアのエンコード/デコードを行うことができます。

### 音声デバイス指定

Momo は Linux (Ubuntu / Raspberry Pi OS) と macOS で音声入力、音声出力デバイスを指定することができます。

Linux については [doc/LINUX_AUDIO_DEVICES.md](doc/LINUX_AUDIO_DEVICES.md) をご確認ください。

## 動画

[WebRTC Native Client Momo と Jetson Nano で 4K@30 配信](https://www.youtube.com/watch?v=z05bWtsgDPY)
Expand Down Expand Up @@ -202,6 +208,9 @@ limitations under the License.

**こちらに掲載していない機能でも対応できる場合がありますのでまずはお問い合わせください**

- Windows 11 x86_64 での `--list-devices` オプション対応
- Windows 11 x86_64 での `--audio-input-device` オプション対応
- Windows 11 x86_64 での `--audio-output-device` オプション対応
- Windows 11 arm64
- Ubuntu 20.04 arm64 (NVIDIA Jetson JetPack 5)

Expand Down
256 changes: 256 additions & 0 deletions doc/LINUX_AUDIO_DEVICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
# Linux での音声デバイスアクセス

## 概要

Linux 環境で momo を使用して音声デバイスにアクセスするには、PipeWire と適切なユーザー権限が必要です。

momo は PulseAudio API 経由で音声デバイスにアクセスします。最近の Ubuntu 環境では PipeWire が PulseAudio 互換レイヤー(pipewire-pulse)を提供しているため、PipeWire 経由で動作します。

## 必要なソフトウェア

### PipeWire のインストール

```bash
sudo apt install pipewire pipewire-pulse wireplumber
```

Ubuntu 24.04 以降では PipeWire がデフォルトでインストールされています。

### PipeWire の起動

systemd 経由で起動する場合:

```bash
systemctl --user start pipewire pipewire-pulse wireplumber
```

### インストール確認

PipeWire と pipewire-pulse がインストールされているか確認:

```bash
systemctl --user status pipewire pipewire-pulse wireplumber
```

正常に動作している場合、3 つのサービスすべてが `Active: active (running)` と表示されます:

```
● pipewire.service - PipeWire Multimedia Service
Active: active (running) since ...

● pipewire-pulse.service - PipeWire PulseAudio
Active: active (running) since ...

● wireplumber.service - Multimedia Service Session Manager
Active: active (running) since ...
```

pipewire-pulse が動作していない場合、momo は音声デバイスにアクセスできません。

## ユーザー権限の設定

Linux では、音声デバイスへのアクセスにグループ権限が必要です。

### 必要なグループ

- `audio`: 音声デバイス(`/dev/snd/*` など)へのアクセスに必要

### グループへの参加

```bash
sudo usermod -a -G audio $USER
```

### 権限の確認

デバイスファイルの権限を確認:

```bash
ls -l /dev/snd/
```

典型的な出力例:

```
crw-rw---- 1 root audio 116, 0 Oct 15 10:00 /dev/snd/controlC0
```

この例では、`audio` グループに所属するユーザーのみが読み書き可能です。

### 現在のグループの確認

```bash
groups
```

### グループ権限の反映

グループに参加した後は、以下のいずれかの方法で権限を反映させる必要があります:

1. ログアウトして再ログイン(推奨)
2. 新しいシェルセッションを開始:

```bash
newgrp audio
```

3. 一時的にグループ権限で実行:

```bash
sg audio -c 'コマンド'
```

## 音声デバイス一覧の確認

### momo でのデバイス確認

```bash
./momo --list-devices
```

正常に動作している場合の出力例:

```
=== Available audio input devices ===

[0] default: Insta360 Link Mono
[1] HyperX QuadCast S Analog Stereo
[2] Yamaha YVC-200 Mono

=== Available audio output devices ===

[0] default: Yamaha YVC-200 Mono
[1] HyperX QuadCast S Analog Stereo
```

### pactl でのデバイス確認

音声入力デバイス:

```bash
pactl list sources short
```

音声出力デバイス:

```bash
pactl list sinks short
```

### カーネルが認識しているサウンドカード

```bash
cat /proc/asound/cards
```

### PipeWire の状態確認

```bash
pw-cli ls Node
```

## 音声デバイスの選択

### デバイスの指定方法

音声入力デバイスと音声出力デバイスを指定できます:

```bash
./momo --audio-input-device 1 --audio-output-device 0 ...
```

デバイスは以下の方法で指定できます:

- インデックス番号: `--audio-input-device 1`
- デバイス名: `--audio-input-device "HyperX QuadCast S Analog Stereo"`

## トラブルシューティング

### 音声デバイスが表示されない

**症状:**

```
Warning: AudioDeviceModule::Init failed (error code: -1). Audio device enumeration is not available.
Note: This may occur if PulseAudio or ALSA is not running.
```

**原因と対処:**

1. PipeWire または pipewire-pulse が起動していない

```bash
systemctl --user start pipewire pipewire-pulse wireplumber
```

2. ユーザーが `audio` グループに所属していない

```bash
sudo usermod -a -G audio $USER
# ログアウトして再ログイン、または newgrp audio
```

3. PipeWire がハードウェアを認識していない

```bash
systemctl --user restart pipewire pipewire-pulse wireplumber
```

### Dummy デバイスしか表示されない

**原因:**

- PipeWire がハードウェアデバイスを認識していない
- ユーザー権限の問題

**対処:**

1. グループ権限を確認:

```bash
groups
# audio が含まれているか確認
```

2. PipeWire を適切な権限で再起動:

```bash
sg audio -c 'systemctl --user restart pipewire pipewire-pulse wireplumber'
```

3. デバイスが認識されているか確認:

```bash
cat /proc/asound/cards
pw-cli ls Node
```

### 音声デバイスが動作しない

**対処:**

1. PipeWire のログを確認:

```bash
journalctl --user -u pipewire -f
journalctl --user -u pipewire-pulse -f
```

2. pactl でデバイスの状態を確認:

```bash
pactl list sources
pactl list sinks
```

3. デバイスファイルのアクセス権を確認:

```bash
ls -l /dev/snd/
```

## 参考情報

- PipeWire: <https://pipewire.org/>
- WirePlumber: <https://pipewire.pages.freedesktop.org/wireplumber/>
- PulseAudio API: <https://www.freedesktop.org/wiki/Software/PulseAudio/>
7 changes: 7 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,13 @@ def _build(args):
cmake_args.append("-DUSE_FAKE_CAPTURE_DEVICE=ON")
cmake_args.append(f"-DBlend2D_ROOT={cmake_path(os.path.join(install_dir, 'blend2d'))}")

# PulseAudio (Ubuntu のみ)
if platform.target.package_name in (
"ubuntu-22.04_x86_64",
"ubuntu-24.04_x86_64",
):
cmake_args.append("-DUSE_LINUX_PULSE_AUDIO=ON")

cmd(["cmake", BASE_DIR] + cmake_args)
cmd(
[
Expand Down
3 changes: 3 additions & 0 deletions src/mac_helper/mac_capturer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class MacCapturer : public sora::ScalableVideoTrackSource,

void OnFrame(const webrtc::VideoFrame& frame) override;

// デバイス一覧を表示
static void ListDevices();

private:
void Destroy();

Expand Down
11 changes: 11 additions & 0 deletions src/mac_helper/mac_capturer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "mac_capturer.h"

#include <iostream>

// WebRTC
#include <rtc_base/logging.h>

Expand Down Expand Up @@ -117,6 +119,15 @@ - (void)capturer:(RTCVideoCapturer*)capturer
device);
}

void MacCapturer::ListDevices() {
NSArray<AVCaptureDevice*>* devices = captureDevices();
[devices enumerateObjectsUsingBlock:^(AVCaptureDevice* device, NSUInteger i,
BOOL* stop) {
std::cout << " [" << i << "] " << [device.localizedName UTF8String]
<< std::endl;
}];
}

AVCaptureDevice* MacCapturer::FindVideoDevice(
const std::string& specifiedVideoDevice) {
// Device の決定ロジックは ffmpeg の avfoundation と同じ仕様にする
Expand Down
Loading