From 932e23af03416e53595564a986809c1a302c32fc Mon Sep 17 00:00:00 2001 From: sean yu <55464069+hexbabe@users.noreply.github.com> Date: Thu, 5 Feb 2026 13:30:34 -0500 Subject: [PATCH] Add conditional build tag to exclude microphones for camera-only builds (#679) * Add tag * Add nomicrophone build tag for optional microphone support - Changed from platform-specific (!windows) to opt-out build tag (!nomicrophone) - Microphone support included by default (non-breaking) - Use -tags nomicrophone to exclude when malgo deps unavailable - Useful for cross-compilation and minimal builds - Renamed microphone_windows.go to microphone_stub.go for clarity * Update README --- README.md | 10 ++++++++++ pkg/driver/microphone/microphone.go | 3 +++ pkg/driver/microphone/microphone_stub.go | 15 +++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 pkg/driver/microphone/microphone_stub.go diff --git a/README.md b/README.md index 1f1daac..456d4e1 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,16 @@ go get -u github.com/pion/mediadevices ``` +### Build Tags + +`mediadevices` provides a `nomicrophone` build tag. Use this tag to build without microphone support. This is particularly useful for: +- Cross-compilation where CGO dependencies like `malgo` are unavailable. +- Projects where audio is not required. + +```bash +go build -tags nomicrophone +``` + ### Usage The following snippet shows how to capture a camera stream and store a frame as a jpeg image: diff --git a/pkg/driver/microphone/microphone.go b/pkg/driver/microphone/microphone.go index 6bfbf56..26c85d7 100644 --- a/pkg/driver/microphone/microphone.go +++ b/pkg/driver/microphone/microphone.go @@ -1,3 +1,6 @@ +//go:build !nomicrophone +// +build !nomicrophone + package microphone import ( diff --git a/pkg/driver/microphone/microphone_stub.go b/pkg/driver/microphone/microphone_stub.go new file mode 100644 index 0000000..34eec05 --- /dev/null +++ b/pkg/driver/microphone/microphone_stub.go @@ -0,0 +1,15 @@ +//go:build nomicrophone +// +build nomicrophone + +package microphone + +// This stub file is used when building with the 'nomicrophone' build tag. +// Use this when cross-compiling or when malgo (miniaudio) dependencies are not available. +// +// To build without microphone support: +// go build -tags nomicrophone +// +// This is particularly useful for: +// - Cross-compilation where CGO dependencies are unavailable +// - Environments without audio system development libraries +// - Minimal builds that only need camera/video support