Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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_DUMP_STATE_H |
| 18 | #define ANDROID_AUDIO_FAST_MIXER_DUMP_STATE_H |
| 19 | |
Glenn Kasten | 04333cd | 2015-02-17 16:23:03 -0800 | [diff] [blame] | 20 | #include <stdint.h> |
Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 21 | #include "Configuration.h" |
Glenn Kasten | 045ee7e | 2015-02-17 16:22:04 -0800 | [diff] [blame] | 22 | #include "FastThreadDumpState.h" |
Glenn Kasten | 04333cd | 2015-02-17 16:23:03 -0800 | [diff] [blame] | 23 | #include "FastMixerState.h" |
Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | // Describes the underrun status for a single "pull" attempt |
| 28 | enum FastTrackUnderrunStatus { |
| 29 | UNDERRUN_FULL, // framesReady() is full frame count, no underrun |
| 30 | UNDERRUN_PARTIAL, // framesReady() is non-zero but < full frame count, partial underrun |
| 31 | UNDERRUN_EMPTY, // framesReady() is zero, total underrun |
| 32 | }; |
| 33 | |
| 34 | // Underrun counters are not reset to zero for new tracks or if track generation changes. |
| 35 | // This packed representation is used to keep the information atomic. |
| 36 | union FastTrackUnderruns { |
| 37 | FastTrackUnderruns() { mAtomic = 0; |
| 38 | COMPILE_TIME_ASSERT_FUNCTION_SCOPE(sizeof(FastTrackUnderruns) == sizeof(uint32_t)); } |
| 39 | FastTrackUnderruns(const FastTrackUnderruns& copyFrom) : mAtomic(copyFrom.mAtomic) { } |
| 40 | FastTrackUnderruns& operator=(const FastTrackUnderruns& rhs) |
| 41 | { if (this != &rhs) mAtomic = rhs.mAtomic; return *this; } |
| 42 | struct { |
| 43 | #define UNDERRUN_BITS 10 |
| 44 | #define UNDERRUN_MASK ((1 << UNDERRUN_BITS) - 1) |
| 45 | uint32_t mFull : UNDERRUN_BITS; // framesReady() is full frame count |
| 46 | uint32_t mPartial : UNDERRUN_BITS; // framesReady() is non-zero but < full frame count |
| 47 | uint32_t mEmpty : UNDERRUN_BITS; // framesReady() is zero |
| 48 | FastTrackUnderrunStatus mMostRecent : 2; // status of most recent framesReady() |
| 49 | } mBitFields; |
| 50 | private: |
| 51 | uint32_t mAtomic; |
| 52 | }; |
| 53 | |
| 54 | // Represents the dump state of a fast track |
| 55 | struct FastTrackDump { |
| 56 | FastTrackDump() : mFramesReady(0) { } |
| 57 | /*virtual*/ ~FastTrackDump() { } |
| 58 | FastTrackUnderruns mUnderruns; |
| 59 | size_t mFramesReady; // most recent value only; no long-term statistics kept |
| 60 | }; |
| 61 | |
| 62 | // The FastMixerDumpState keeps a cache of FastMixer statistics that can be logged by dumpsys. |
| 63 | // Each individual native word-sized field is accessed atomically. But the |
| 64 | // overall structure is non-atomic, that is there may be an inconsistency between fields. |
| 65 | // No barriers or locks are used for either writing or reading. |
| 66 | // Only POD types are permitted, and the contents shouldn't be trusted (i.e. do range checks). |
| 67 | // It has a different lifetime than the FastMixer, and so it can't be a member of FastMixer. |
| 68 | struct FastMixerDumpState : FastThreadDumpState { |
Glenn Kasten | fbdb2ac | 2015-03-02 14:47:19 -0800 | [diff] [blame^] | 69 | FastMixerDumpState(); |
Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 70 | /*virtual*/ ~FastMixerDumpState(); |
| 71 | |
| 72 | void dump(int fd) const; // should only be called on a stable copy, not the original |
| 73 | |
| 74 | uint32_t mWriteSequence; // incremented before and after each write() |
| 75 | uint32_t mFramesWritten; // total number of frames written successfully |
| 76 | uint32_t mNumTracks; // total number of active fast tracks |
| 77 | uint32_t mWriteErrors; // total number of write() errors |
| 78 | uint32_t mSampleRate; |
| 79 | size_t mFrameCount; |
| 80 | uint32_t mTrackMask; // mask of active tracks |
| 81 | FastTrackDump mTracks[FastMixerState::kMaxFastTracks]; |
Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | } // android |
| 85 | |
| 86 | #endif // ANDROID_AUDIO_FAST_MIXER_DUMP_STATE_H |