diff options
Diffstat (limited to 'core/include/chre/core/audio_request_manager.h')
-rw-r--r-- | core/include/chre/core/audio_request_manager.h | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/core/include/chre/core/audio_request_manager.h b/core/include/chre/core/audio_request_manager.h index da44c4ce..b53ceede 100644 --- a/core/include/chre/core/audio_request_manager.h +++ b/core/include/chre/core/audio_request_manager.h @@ -20,7 +20,6 @@ #include <cstdint> #include "chre/core/nanoapp.h" -#include "chre/core/settings.h" #include "chre/platform/platform_audio.h" #include "chre/util/dynamic_vector.h" #include "chre/util/non_copyable.h" @@ -103,13 +102,42 @@ class AudioRequestManager : public NonCopyable { void logStateToBuffer(DebugDumpWrapper &debugDump) const; /** - * Invoked when the host notifies CHRE that microphone access has been - * disabled via the user settings. + * A convenience function to convert sample count and sample rate into a time + * duration. It is illegal to call this function with a rate of zero. * - * @param setting The setting that changed. - * @param state The new setting state. + * @param sampleCount The number of samples to convert to time at the provided + * rate. + * @param sampleRate The rate to perform the time conversion at. + * @return The duration of time for these two parameters. */ - void onSettingChanged(Setting setting, SettingState state); + static constexpr Nanoseconds getDurationFromSampleCountAndRate( + uint32_t sampleCount, uint32_t sampleRate) { + // This function will overflow with high sample counts but does work for + // reasonable expected values. + // + // Example: 22050 * 1000000000 / 44100 = 500000000ns + return Nanoseconds((sampleCount * kOneSecondInNanoseconds) / sampleRate); + } + + /** + * A convenience function to convert sample rate and duration into a sample + * count. This can be used by platform implementations to ensure that the + * computed buffer sizes match those expected by CHRE. + * + * @param sampleRate The sample rate of the audio source. + * @param duration The duration of the buffer delivered. + * @return The number of samples given this configuration. + */ + static constexpr uint32_t getSampleCountFromRateAndDuration( + uint32_t sampleRate, Nanoseconds duration) { + // This function will overflow at high sample rates or extremely high + // durations, but does work for reasonable expected values. + // + // Example: 44100 * 60 seconds (in nanoseconds) fits into a uint64_t as an + // intermediate value before casting to uint32_t. + return static_cast<uint32_t>((sampleRate * duration.toRawNanoseconds()) / + kOneSecondInNanoseconds); + } /** * @return the instance of platform audio to allow platform-specific @@ -337,9 +365,8 @@ class AudioRequestManager : public NonCopyable { * the supplied handle with the current availability of the source. * * @param handle The handle for the audio source that is changing. - * @param suspended Boolean value that indicates if the source is suspended */ - void postAudioSamplingChangeEvents(uint32_t handle, bool suspended); + void postAudioSamplingChangeEvents(uint32_t handle); /** * Posts a CHRE_EVENT_AUDIO_SAMPLING_CHANGE event to the specified nanoapp. @@ -348,10 +375,9 @@ class AudioRequestManager : public NonCopyable { * @param handle The handle for the audio source that is changing. * @param available true if audio is available for the supplied handle, false * otherwise. - * @param suspended Boolean value that indicates if the source is suspended */ void postAudioSamplingChangeEvent(uint32_t instanceId, uint32_t handle, - bool available, bool suspended); + bool available); /** * Posts the provided audio data event to a nanoapp with the given instance ID |