Skip to content

Conversation

@t-miya
Copy link
Contributor

@t-miya t-miya commented Dec 24, 2025

#130 関連の修正です。
音声録音フラグの操作だけではマイクインジケータ消灯に不十分だったため追加の対応となります。

AudioDeviceIOS の pauseRecording/resumeRecording 内で
`VoiceProcessingAudioUnit:: SetMicrophoneMute(:) の実行により AudioDevice への音声入力を無効化/有効化するようにします。

iOS の AudioUnit の制約により、SetMicrophoneMute 実行時は AudioUnit の状態が
未初期化(VoiceProcessingAudioUnit::kUninitialized) である必要があるため、
pauseRecording/resumeRecording 内で AudioUnit の 停止 -> 未初期化処理 -> SetMicrophoneMute -> 初期化処理 -> 起動
というフローで処理します。

@t-miya t-miya requested a review from melpon December 24, 2025 09:56
+ if (audio_unit_->GetState() == VoiceProcessingAudioUnit::kStarted) {
+ if (!audio_unit_->Stop()) {
+ RTC_LOG(LS_WARNING) << "PauseRecording failed to stop audio unit";
+ return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

結局停止してない(recording_ フラグが落ちてない)のに戻り値を 0 として返すのは微妙そう

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReinitAudioUnitForMicrophoneMute で切り出した部分は正常成功時以外はエラーログと -1 で返すようにしました

+ }
+ // audio_unit_->SetMicrophoneMute 実行のため AudioUnit を一度初期化解除します
+ // SetMicrophoneMute(true) 実行後に再度 AudioUnit の初期化を行います
+ if (audio_unit_ && audio_unit_->GetState() >= VoiceProcessingAudioUnit::kUninitialized) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このあたり、Stop, Uninitialize, SetMicrophoneMute(value), Initialize, Start を行う部分を関数にまとめた方が良さそう。

Copy link
Contributor Author

@t-miya t-miya Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private 関数 AudioDeviceIOS::SetMicrophoneMute(Bool) で処理を切り出します
int32_t SetMicrophoneMute(bool enable) override; で定義済みだったため別名にします

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int32_t ReinitAudioUnitForMicrophoneMute(bool) で切り出しました

@t-miya
Copy link
Contributor Author

t-miya commented Dec 25, 2025

pause/resume でそれぞれ実行していた AudioUnit の再初期化 ~ SetMicrophonemute 呼び出し を ReinitAudioUnitForMicrophoneMute 関数に切り出して共通化しました

@t-miya

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@t-miya

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@t-miya

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

+int32_t AudioDeviceModuleIOS::PauseRecording() {
+ RTC_DLOG(LS_INFO) << __FUNCTION__;
+ CHECKinitialized_();
+ if (!Recording()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StopRecording() と同様の早期リターン用のチェックを追加しました

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

audio_device_module_ios.mm:655-667 を見る限り StopRecording() に早期リターンは無いみたいです。

+ RTC_DLOG(LS_INFO) << __FUNCTION__;
+ CHECKinitialized_();
+ int32_t result = audio_device_->ResumeRecording();
+ if (Recording()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StartRecording() と同様の早期リターン用のチェックを追加しました

@t-miya

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@t-miya

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@t-miya

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@t-miya

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@t-miya

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@t-miya

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@t-miya

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@t-miya

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@t-miya

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@t-miya
Copy link
Contributor Author

t-miya commented Dec 25, 2025

@melpon
対応完了しましたのでレビューお願いします🙇

+ RTC_LOG(LS_WARNING) << "PauseRecording called while not recording";
+ return 0;
+ }
+ // マイクミュートを有効化します
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

マイクミュートの有効化、日本語として分かりにくいので「マイクミュートにします」だけで良さそう

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

マイクミュートします に修正しました

+ RTC_LOG(LS_WARNING) << "ResumeRecording called while recording";
+ return 0;
+ }
+ // マイクミュートを無効化します
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こっちも「マイクミュートを解除します」で良さそう

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

マイクミュートを解除します に修正しました

+int32_t AudioDeviceModuleIOS::PauseRecording() {
+ RTC_DLOG(LS_INFO) << __FUNCTION__;
+ CHECKinitialized_();
+ if (!Recording()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

audio_device_module_ios.mm:655-667 を見る限り StopRecording() に早期リターンは無いみたいです。

@t-miya
Copy link
Contributor Author

t-miya commented Dec 26, 2025

失礼しました StopRecording にはなかったです。ただこの早期リターン自体はやっておいてもいいかなと思いますが

@melpon
Copy link
Contributor

melpon commented Dec 26, 2025

  • Pause 時に録音中でなかったり、Resume 時に録音中だったりということは正常なケースとして想定していないように見える
  • その場合に何もせずに return するのが正しいとは思えない。せめてログは吐いておくべき
  • また、ReportError() 関数も呼ばれないことになるので、一貫したエラー処理にならない

ということで、ここで早期リターンをする必要は無さそう。

@t-miya
Copy link
Contributor Author

t-miya commented Dec 26, 2025

なるほど。ログを出さないのたしかに。削除します

Copy link
Contributor

@melpon melpon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よさそう

@t-miya
Copy link
Contributor Author

t-miya commented Dec 26, 2025

ありがとうございます🙇

@t-miya t-miya merged commit b336e9c into feature/m143.7499 Dec 26, 2025
14 checks passed
@t-miya t-miya deleted the feature/ios-audio-hard-mute branch December 26, 2025 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants