Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
google
GitHub Repository: google/crosvm
Path: blob/main/metrics_events/src/sys/windows.rs
5394 views
1
// Copyright 2024 The ChromiumOS Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
use serde::Deserialize;
6
use serde::Serialize;
7
8
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
9
pub struct WaveFormatDetails {
10
// Format requested by WASAPI `GetMixFormat` system call.
11
pub requested: Option<WaveFormat>,
12
// Originally the requested wave format that's modified by the emulator. Only
13
// populated if the emulator decides the requested wave format should not be
14
// used.
15
pub modified: Option<WaveFormat>,
16
// Format that is valid and closest matching to the modified format, if the
17
// modified was rejected. Should only be populated if modified is also
18
// non-null and was rejected by WASAPI `IsFormatSupported` system call.
19
pub closest_matched: Option<WaveFormat>,
20
}
21
22
// Defines the format of waveformat audio data. This information is used by
23
// WASAPI to determine how to process the audio playback data coming from the
24
// emulator.
25
//
26
// The fields in the structure come from WAVEFORMATEXTENSIBLE of win32 api.
27
// https://docs.microsoft.com/en-us/windows/win32/api/mmreg/ns-mmreg-waveformatextensible
28
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
29
pub struct WaveFormat {
30
// Ex. 65534 (Maps to WAVE_FORMAT_EXTENSIBLE)
31
pub format_tag: i32,
32
// Number of channels.
33
pub channels: i32,
34
// Sample rate in Hz. Ex: 48000
35
pub samples_per_sec: i32,
36
// Required average data-transfer rate for the format tag. Usually this will
37
// be samples_per_sec * block_align, since the format tag is usually
38
// WAVE_FORMAT_IEEE_FLOAT or it's extensible and SubFormat is
39
// KSDATAFORMAT_SUBTYPE_IEEE_FLOAT.
40
pub avg_bytes_per_sec: i32,
41
// Minimum atomic unit of data based on the format_tag. Usually this will
42
// just be bits_per_samples * channels.
43
pub block_align: i32,
44
// Bits used per sample. Must be a multiple of 8.
45
pub bits_per_sample: i32,
46
// Size in bytes of extra information appended to WAVEFORMATEX struct.
47
pub size_bytes: i32,
48
49
// The next fields are part of the WAVEFORMATEXTENSIBLE struct. They will only
50
// be non-null if format_tag is WAVE_FORMAT_EXTENSIBLE.
51
52
// Bit depth. Can be any value. Ex. bits_per_sample is 24,
53
// but samples is 20. Note: This value is a union, so it could mean something
54
// slightly different, but most likely won't. Refer to doc for more info.
55
pub samples: Option<i32>,
56
// Bitmask mapping channels in stream to speaker positions.
57
// Ex. 3 ( SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT )
58
pub channel_mask: Option<i64>,
59
// Similar to format_tag, but for WAVEFORMATEXTENSIBLE structs.
60
pub sub_format: Option<WaveFormatSubFormat>,
61
}
62
63
// Subformat GUID mapping:
64
// https://github.com/retep998/winapi-rs/blob/2f76bdea3a79817ccfab496fbd1786d5a697387b/src/shared/ksmedia.rs
65
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
66
pub enum WaveFormatSubFormat {
67
Invalid,
68
Analog,
69
Pcm,
70
IeeeFloat,
71
Drm,
72
ALaw,
73
MuLaw,
74
Adpcm,
75
Mpeg,
76
}
77
78