Class AudioFormatMatcher

java.lang.Object
org.openhab.core.audio.utils.AudioFormatMatcher

@NonNullByDefault public final class AudioFormatMatcher extends Object
Utility class for audio format negotiation and matching between audio sources, sinks, and voice services.
Author:
Florian Hotze - Initial contribution
  • Method Details

    • isPcmCodec

      public static boolean isPcmCodec(@Nullable String codec)
      Returns whether the given codec is a PCM codec.
      Parameters:
      codec - a codec
      Returns:
      true if the codec is a PCM codec, false otherwise
    • getPreferredFormat

      public static @Nullable AudioFormat getPreferredFormat(Set<AudioFormat> audioFormats)
      Determines a preferred concrete audio format from a set of supported formats. Prefers PCM (uncontainerized signed PCM) over WAVE container formats and fills default attributes if abstract.
      Parameters:
      audioFormats - set of candidate audio formats
      Returns:
      a preferred concrete audio format, or null if none could be determined
    • isPcmFormat

      public static boolean isPcmFormat(AudioFormat format)
    • isWaveFormat

      public static boolean isWaveFormat(AudioFormat format)
    • getBestMatch

      public static @Nullable AudioFormat getBestMatch(Set<AudioFormat> inputs, Set<AudioFormat> outputs)
      Determines the best matching audio format between inputs and outputs without transcoding.
      Parameters:
      inputs - candidate input formats
      outputs - candidate output formats
      Returns:
      the best matching audio format, or null if incompatible
    • getBestMatchWithTranscoding

      public static @Nullable AudioFormat getBestMatchWithTranscoding(Set<AudioFormat> sourceSupportedFormats, Set<AudioFormat> targetSupportedFormats)
      Determines the best matching audio format between source formats and target formats, taking transcoding capabilities into account.
      Parameters:
      sourceSupportedFormats - candidate source formats
      targetSupportedFormats - candidate target formats
      Returns:
      a format suitable for the source (and transcoding if needed), or null if none