// Copyright 2024 The ChromiumOS Authors1// Use of this source code is governed by a BSD-style license that can be2// found in the LICENSE file.34use serde::Deserialize;5use serde::Serialize;67#[derive(Clone, Debug, Serialize, Deserialize, Default)]8pub struct WaveFormatDetails {9// Format requested by WASAPI `GetMixFormat` system call.10pub requested: Option<WaveFormat>,11// Originally the requested wave format that's modified by the emulator. Only12// populated if the emulator decides the requested wave format should not be13// used.14pub modified: Option<WaveFormat>,15// Format that is valid and closest matching to the modified format, if the16// modified was rejected. Should only be populated if modified is also17// non-null and was rejected by WASAPI `IsFormatSupported` system call.18pub closest_matched: Option<WaveFormat>,19}2021// Defines the format of waveformat audio data. This information is used by22// WASAPI to determine how to process the audio playback data coming from the23// emulator.24//25// The fields in the structure come from WAVEFORMATEXTENSIBLE of win32 api.26// https://docs.microsoft.com/en-us/windows/win32/api/mmreg/ns-mmreg-waveformatextensible27#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]28pub struct WaveFormat {29// Ex. 65534 (Maps to WAVE_FORMAT_EXTENSIBLE)30pub format_tag: i32,31// Number of channels.32pub channels: i32,33// Sample rate in Hz. Ex: 4800034pub samples_per_sec: i32,35// Required average data-transfer rate for the format tag. Usually this will36// be samples_per_sec * block_align, since the format tag is usually37// WAVE_FORMAT_IEEE_FLOAT or it's extensible and SubFormat is38// KSDATAFORMAT_SUBTYPE_IEEE_FLOAT.39pub avg_bytes_per_sec: i32,40// Minimum atomic unit of data based on the format_tag. Usually this will41// just be bits_per_samples * channels.42pub block_align: i32,43// Bits used per sample. Must be a multiple of 8.44pub bits_per_sample: i32,45// Size in bytes of extra information appended to WAVEFORMATEX struct.46pub size_bytes: i32,4748// The next fields are part of the WAVEFORMATEXTENSIBLE struct. They will only49// be non-null if format_tag is WAVE_FORMAT_EXTENSIBLE.5051// Bit depth. Can be any value. Ex. bits_per_sample is 24,52// but samples is 20. Note: This value is a union, so it could mean something53// slightly different, but most likely won't. Refer to doc for more info.54pub samples: Option<i32>,55// Bitmask mapping channels in stream to speaker positions.56// Ex. 3 ( SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT )57pub channel_mask: Option<i64>,58// Similar to format_tag, but for WAVEFORMATEXTENSIBLE structs.59pub sub_format: Option<WaveFormatSubFormat>,60}6162// Subformat GUID mapping:63// https://github.com/retep998/winapi-rs/blob/2f76bdea3a79817ccfab496fbd1786d5a697387b/src/shared/ksmedia.rs64#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]65pub enum WaveFormatSubFormat {66Invalid,67Analog,68Pcm,69IeeeFloat,70Drm,71ALaw,72MuLaw,73Adpcm,74Mpeg,75}767778