Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
- 変更対象外の API
- `ctx.end()`, `ctx.save()` , `ctx.restore()` は単語なので変更なし
- @voluntas @torikizi
- [ADD] macOS でオーディオデバイス選択機能を追加
- `--audio-input-device` オプションでオーディオ入力デバイスを指定可能にする
- `--audio-output-device` オプションでオーディオ出力デバイスを指定可能にする
- デバイスはインデックス番号またはデバイス名(完全一致、大文字小文字を区別しない)で指定可能
- @voluntas
- [ADD] macOS で `--list-devices` オプションを追加
- 利用可能なオーディオデバイスとビデオデバイスの一覧を表示する機能
- @voluntas
- [FIX] Ubuntu 環境のカメラで MJPEG より YUV が優先されてしまうのを修正
- @melpon
- [FIX] Ayame モードで `--video-codec-type` / `--audio-codec-type` が大小文字の不一致で無視される問題を修正
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
76 changes: 75 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#include <SDL3/SDL_main.h>

// WebRTC
#if defined(__APPLE__)
#include <api/audio/create_audio_device_module.h>
#include <api/environment/environment_factory.h>
#include <modules/audio_device/include/audio_device.h>
#endif
#include <api/make_ref_counted.h>
#include <rtc_base/log_sinks.h>
#include <rtc_base/ref_counted_object.h>
Expand Down Expand Up @@ -80,6 +85,65 @@ static void ListVideoDevices() {
std::cout << sora::FormatV4L2Devices(*devices);
}

#elif defined(__APPLE__)

static void ListDevices() {
// オーディオデバイス一覧
auto adm = webrtc::CreateAudioDeviceModule(
webrtc::CreateEnvironment(),
webrtc::AudioDeviceModule::kPlatformDefaultAudio);
if (!adm) {
std::cerr << "Failed to create AudioDeviceModule" << std::endl;
return;
}

if (adm->Init() != 0) {
std::cerr << "AudioDeviceModule::Init failed" << std::endl;
return;
}

auto print_audio_devices = [&](bool is_input) {
const char* title =
is_input ? "=== Available audio input devices ==="
: "=== Available audio output devices ===";
std::cout << title << std::endl;
std::cout << std::endl;

int16_t device_count =
is_input ? adm->RecordingDevices() : adm->PlayoutDevices();
if (device_count <= 0) {
std::cout << " (none)" << std::endl << std::endl;
return;
}

for (uint16_t i = 0; i < static_cast<uint16_t>(device_count); ++i) {
char name[webrtc::kAdmMaxDeviceNameSize] = {0};
char guid[webrtc::kAdmMaxGuidSize] = {0};
int32_t result = is_input ? adm->RecordingDeviceName(i, name, guid)
: adm->PlayoutDeviceName(i, name, guid);
if (result != 0) {
std::cout << " [" << i << "] <failed to read device name>" << std::endl;
continue;
}
std::cout << " [" << i << "] " << name;
if (guid[0] != '\0') {
std::cout << " (" << guid << ")";
}
std::cout << std::endl;
}
std::cout << std::endl;
};

print_audio_devices(true);
print_audio_devices(false);

// ビデオデバイス一覧
std::cout << "=== Available video devices ===" << std::endl;
std::cout << std::endl;
MacCapturer::ListDevices();
std::cout << std::endl;
}

#endif

int main(int argc, char* argv[]) {
Expand Down Expand Up @@ -107,9 +171,15 @@ int main(int argc, char* argv[]) {
ListVideoDevices();
return 0;
}
#elif defined(__APPLE__)
if (args.list_devices) {
ListDevices();
return 0;
}
#else
if (args.list_devices) {
std::cerr << "--list-devices is only supported on Linux" << std::endl;
std::cerr << "--list-devices is not supported on this platform"
<< std::endl;
return 1;
}
#endif
Expand Down Expand Up @@ -235,6 +305,10 @@ int main(int argc, char* argv[]) {

rtcm_config.no_video_device = args.no_video_device;
rtcm_config.no_audio_device = args.no_audio_device;
#if defined(__APPLE__)
rtcm_config.audio_input_device = args.audio_input_device;
rtcm_config.audio_output_device = args.audio_output_device;
#endif

rtcm_config.fixed_resolution = args.fixed_resolution;
rtcm_config.simulcast = args.sora_simulcast;
Expand Down
4 changes: 4 additions & 0 deletions src/momo_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ struct MomoArgs {
// libcamera のコントロール設定。key value の形式で指定する。
std::vector<std::pair<std::string, std::string>> libcamera_controls;
std::string video_device = "";
#if defined(__APPLE__)
std::string audio_input_device = "";
std::string audio_output_device = "";
#endif
std::string resolution = "VGA";
int framerate = 30;
bool fixed_resolution = false;
Expand Down
Loading
Loading