FastMixerState.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2012 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef ANDROID_AUDIO_FAST_MIXER_STATE_H
  17. #define ANDROID_AUDIO_FAST_MIXER_STATE_H
  18. #include <audio_utils/minifloat.h>
  19. #include <system/audio.h>
  20. #include <media/AudioMixer.h>
  21. #include <media/ExtendedAudioBufferProvider.h>
  22. #include <media/nbaio/NBAIO.h>
  23. #include <media/nblog/NBLog.h>
  24. #include "FastThreadState.h"
  25. namespace android {
  26. struct FastMixerDumpState;
  27. class VolumeProvider {
  28. public:
  29. // The provider implementation is responsible for validating that the return value is in range.
  30. virtual gain_minifloat_packed_t getVolumeLR() = 0;
  31. protected:
  32. VolumeProvider() { }
  33. virtual ~VolumeProvider() { }
  34. };
  35. // Represents the state of a fast track
  36. struct FastTrack {
  37. FastTrack();
  38. /*virtual*/ ~FastTrack();
  39. ExtendedAudioBufferProvider* mBufferProvider; // must be NULL if inactive, or non-NULL if active
  40. VolumeProvider* mVolumeProvider; // optional; if NULL then full-scale
  41. audio_channel_mask_t mChannelMask; // AUDIO_CHANNEL_OUT_MONO or AUDIO_CHANNEL_OUT_STEREO
  42. audio_format_t mFormat; // track format
  43. int mGeneration; // increment when any field is assigned
  44. bool mHapticPlaybackEnabled = false; // haptic playback is enabled or not
  45. AudioMixer::haptic_intensity_t mHapticIntensity = AudioMixer::HAPTIC_SCALE_MUTE; // intensity of
  46. // haptic data
  47. };
  48. // Represents a single state of the fast mixer
  49. struct FastMixerState : FastThreadState {
  50. FastMixerState();
  51. /*virtual*/ ~FastMixerState();
  52. // These are the minimum, maximum, and default values for maximum number of fast tracks
  53. static const unsigned kMinFastTracks = 2;
  54. static const unsigned kMaxFastTracks = 32;
  55. static const unsigned kDefaultFastTracks = 8;
  56. static unsigned sMaxFastTracks; // Configured maximum number of fast tracks
  57. static pthread_once_t sMaxFastTracksOnce; // Protects initializer for sMaxFastTracks
  58. // all pointer fields use raw pointers; objects are owned and ref-counted by the normal mixer
  59. FastTrack mFastTracks[kMaxFastTracks];
  60. int mFastTracksGen; // increment when any mFastTracks[i].mGeneration is incremented
  61. unsigned mTrackMask; // bit i is set if and only if mFastTracks[i] is active
  62. NBAIO_Sink* mOutputSink; // HAL output device, must already be negotiated
  63. int mOutputSinkGen; // increment when mOutputSink is assigned
  64. size_t mFrameCount; // number of frames per fast mix buffer
  65. audio_channel_mask_t mSinkChannelMask; // If not AUDIO_CHANNEL_NONE, specifies sink channel
  66. // mask when it cannot be directly calculated from
  67. // channel count
  68. // Extends FastThreadState::Command
  69. static const Command
  70. // The following commands also process configuration changes, and can be "or"ed:
  71. MIX = 0x8, // mix tracks
  72. WRITE = 0x10, // write to output sink
  73. MIX_WRITE = 0x18; // mix tracks and write to output sink
  74. // never returns NULL; asserts if command is invalid
  75. static const char *commandToString(Command command);
  76. // initialize sMaxFastTracks
  77. static void sMaxFastTracksInit();
  78. }; // struct FastMixerState
  79. } // namespace android
  80. #endif // ANDROID_AUDIO_FAST_MIXER_STATE_H