| 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> | 
| Eric Tan | 7b65115 | 2018-07-13 10:17:19 -0700 | [diff] [blame] | 21 | #include <string> | 
| Andy Hung | 2e2c0bb | 2018-06-11 19:13:11 -0700 | [diff] [blame] | 22 | #include <audio_utils/TimestampVerifier.h> | 
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 23 | #include "Configuration.h" | 
| Glenn Kasten | 045ee7e | 2015-02-17 16:22:04 -0800 | [diff] [blame] | 24 | #include "FastThreadDumpState.h" | 
| Glenn Kasten | 04333cd | 2015-02-17 16:23:03 -0800 | [diff] [blame] | 25 | #include "FastMixerState.h" | 
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 26 |  | 
|  | 27 | namespace android { | 
|  | 28 |  | 
|  | 29 | // Describes the underrun status for a single "pull" attempt | 
|  | 30 | enum FastTrackUnderrunStatus { | 
|  | 31 | UNDERRUN_FULL,      // framesReady() is full frame count, no underrun | 
|  | 32 | UNDERRUN_PARTIAL,   // framesReady() is non-zero but < full frame count, partial underrun | 
|  | 33 | UNDERRUN_EMPTY,     // framesReady() is zero, total underrun | 
|  | 34 | }; | 
|  | 35 |  | 
|  | 36 | // Underrun counters are not reset to zero for new tracks or if track generation changes. | 
|  | 37 | // This packed representation is used to keep the information atomic. | 
|  | 38 | union FastTrackUnderruns { | 
|  | 39 | FastTrackUnderruns() { mAtomic = 0; | 
| Glenn Kasten | 91164e7 | 2016-03-15 15:55:01 -0700 | [diff] [blame] | 40 | static_assert(sizeof(FastTrackUnderruns) == sizeof(uint32_t), "FastTrackUnderrun"); } | 
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 41 | FastTrackUnderruns(const FastTrackUnderruns& copyFrom) : mAtomic(copyFrom.mAtomic) { } | 
|  | 42 | FastTrackUnderruns& operator=(const FastTrackUnderruns& rhs) | 
|  | 43 | { if (this != &rhs) mAtomic = rhs.mAtomic; return *this; } | 
|  | 44 | struct { | 
|  | 45 | #define UNDERRUN_BITS 10 | 
|  | 46 | #define UNDERRUN_MASK ((1 << UNDERRUN_BITS) - 1) | 
|  | 47 | uint32_t mFull    : UNDERRUN_BITS; // framesReady() is full frame count | 
|  | 48 | uint32_t mPartial : UNDERRUN_BITS; // framesReady() is non-zero but < full frame count | 
|  | 49 | uint32_t mEmpty   : UNDERRUN_BITS; // framesReady() is zero | 
|  | 50 | FastTrackUnderrunStatus mMostRecent : 2;    // status of most recent framesReady() | 
|  | 51 | }        mBitFields; | 
|  | 52 | private: | 
|  | 53 | uint32_t mAtomic; | 
|  | 54 | }; | 
|  | 55 |  | 
|  | 56 | // Represents the dump state of a fast track | 
|  | 57 | struct FastTrackDump { | 
|  | 58 | FastTrackDump() : mFramesReady(0) { } | 
|  | 59 | /*virtual*/ ~FastTrackDump() { } | 
| Glenn Kasten | e4a7ce2 | 2015-03-03 11:23:17 -0800 | [diff] [blame] | 60 | FastTrackUnderruns  mUnderruns; | 
|  | 61 | size_t              mFramesReady;        // most recent value only; no long-term statistics kept | 
| Andy Hung | b54c854 | 2016-09-21 12:55:15 -0700 | [diff] [blame] | 62 | int64_t             mFramesWritten;      // last value from track | 
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 63 | }; | 
|  | 64 |  | 
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 65 | struct FastMixerDumpState : FastThreadDumpState { | 
| Glenn Kasten | fbdb2ac | 2015-03-02 14:47:19 -0800 | [diff] [blame] | 66 | FastMixerDumpState(); | 
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 67 | /*virtual*/ ~FastMixerDumpState(); | 
|  | 68 |  | 
| Eric Tan | 7b65115 | 2018-07-13 10:17:19 -0700 | [diff] [blame] | 69 | void dump(int fd) const;             // should only be called on a stable copy, not the original | 
|  | 70 | std::string getJsonString() const;   // should only be called on a stable copy, not the original | 
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 71 |  | 
| Andy Hung | f6ab58d | 2018-05-25 12:50:39 -0700 | [diff] [blame] | 72 | double   mLatencyMs = 0.;   // measured latency, default of 0 if no valid timestamp read. | 
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 73 | uint32_t mWriteSequence;    // incremented before and after each write() | 
|  | 74 | uint32_t mFramesWritten;    // total number of frames written successfully | 
|  | 75 | uint32_t mNumTracks;        // total number of active fast tracks | 
|  | 76 | uint32_t mWriteErrors;      // total number of write() errors | 
|  | 77 | uint32_t mSampleRate; | 
|  | 78 | size_t   mFrameCount; | 
|  | 79 | uint32_t mTrackMask;        // mask of active tracks | 
|  | 80 | FastTrackDump   mTracks[FastMixerState::kMaxFastTracks]; | 
| Andy Hung | 2e2c0bb | 2018-06-11 19:13:11 -0700 | [diff] [blame] | 81 |  | 
|  | 82 | // For timestamp statistics. | 
|  | 83 | TimestampVerifier<int64_t /* frame count */, int64_t /* time ns */> mTimestampVerifier; | 
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 84 | }; | 
|  | 85 |  | 
|  | 86 | }   // android | 
|  | 87 |  | 
|  | 88 | #endif  // ANDROID_AUDIO_FAST_MIXER_DUMP_STATE_H |