Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 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 | |
| 17 | #ifndef ANDROID_AUDIO_FAST_MIXER_H |
| 18 | #define ANDROID_AUDIO_FAST_MIXER_H |
| 19 | |
| 20 | #include <utils/Thread.h> |
| 21 | extern "C" { |
| 22 | #include "../private/bionic_futex.h" |
| 23 | } |
| 24 | #include "StateQueue.h" |
| 25 | #include "FastMixerState.h" |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | typedef StateQueue<FastMixerState> FastMixerStateQueue; |
| 30 | |
| 31 | class FastMixer : public Thread { |
| 32 | |
| 33 | public: |
| 34 | FastMixer() : Thread(false /*canCallJava*/) { } |
| 35 | virtual ~FastMixer() { } |
| 36 | |
| 37 | FastMixerStateQueue* sq() { return &mSQ; } |
| 38 | |
| 39 | private: |
| 40 | virtual bool threadLoop(); |
| 41 | FastMixerStateQueue mSQ; |
| 42 | |
| 43 | }; // class FastMixer |
| 44 | |
Glenn Kasten | 288ed21 | 2012-04-25 17:52:27 -0700 | [diff] [blame^] | 45 | // Represents the dump state of a fast track |
| 46 | struct FastTrackDump { |
| 47 | FastTrackDump() : mUnderruns(0) { } |
| 48 | /*virtual*/ ~FastTrackDump() { } |
| 49 | uint32_t mUnderruns; // Underrun status, represented as follows: |
| 50 | // bit 0 == 0 means not currently in underrun |
| 51 | // bit 0 == 1 means currently in underrun |
| 52 | // bits 1 to 31 == total number of underruns |
| 53 | // Not reset to zero for new tracks or if track generation changes. |
| 54 | // This representation is used to keep the information atomic. |
| 55 | }; |
| 56 | |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 57 | // The FastMixerDumpState keeps a cache of FastMixer statistics that can be logged by dumpsys. |
Glenn Kasten | 288ed21 | 2012-04-25 17:52:27 -0700 | [diff] [blame^] | 58 | // Each individual native word-sized field is accessed atomically. But the |
| 59 | // overall structure is non-atomic, that is there may be an inconsistency between fields. |
| 60 | // No barriers or locks are used for either writing or reading. |
| 61 | // Only POD types are permitted, and the contents shouldn't be trusted (i.e. do range checks). |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 62 | // It has a different lifetime than the FastMixer, and so it can't be a member of FastMixer. |
| 63 | struct FastMixerDumpState { |
| 64 | FastMixerDumpState(); |
| 65 | /*virtual*/ ~FastMixerDumpState(); |
| 66 | |
| 67 | void dump(int fd); |
| 68 | |
| 69 | FastMixerState::Command mCommand; // current command |
| 70 | uint32_t mWriteSequence; // incremented before and after each write() |
| 71 | uint32_t mFramesWritten; // total number of frames written successfully |
| 72 | uint32_t mNumTracks; // total number of active fast tracks |
| 73 | uint32_t mWriteErrors; // total number of write() errors |
| 74 | uint32_t mUnderruns; // total number of underruns |
| 75 | uint32_t mOverruns; // total number of overruns |
Glenn Kasten | 21e8c50 | 2012-04-12 09:39:42 -0700 | [diff] [blame] | 76 | uint32_t mSampleRate; |
| 77 | size_t mFrameCount; |
Glenn Kasten | 288ed21 | 2012-04-25 17:52:27 -0700 | [diff] [blame^] | 78 | struct timespec mMeasuredWarmupTs; // measured warmup time |
| 79 | uint32_t mWarmupCycles; // number of loop cycles required to warmup |
| 80 | FastTrackDump mTracks[FastMixerState::kMaxFastTracks]; |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 81 | #ifdef FAST_MIXER_STATISTICS |
| 82 | // cycle times in seconds |
| 83 | float mMean; |
| 84 | float mMinimum; |
| 85 | float mMaximum; |
| 86 | float mStddev; |
| 87 | #endif |
| 88 | }; |
| 89 | |
| 90 | } // namespace android |
| 91 | |
| 92 | #endif // ANDROID_AUDIO_FAST_MIXER_H |