blob: 69c2e4e87ba0ee8ccae89cdfefd73098745131da [file] [log] [blame]
Glenn Kasten22340022014-04-07 12:04:41 -07001/*
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 Kasten04333cd2015-02-17 16:23:03 -080020#include <stdint.h>
Eric Tan7b651152018-07-13 10:17:19 -070021#include <string>
Andy Hung2e2c0bb2018-06-11 19:13:11 -070022#include <audio_utils/TimestampVerifier.h>
Eric Tan1882f162018-08-02 18:05:39 -070023#include <json/json.h>
Glenn Kasten22340022014-04-07 12:04:41 -070024#include "Configuration.h"
Glenn Kasten045ee7e2015-02-17 16:22:04 -080025#include "FastThreadDumpState.h"
Glenn Kasten04333cd2015-02-17 16:23:03 -080026#include "FastMixerState.h"
Glenn Kasten22340022014-04-07 12:04:41 -070027
28namespace android {
29
30// Describes the underrun status for a single "pull" attempt
31enum FastTrackUnderrunStatus {
32 UNDERRUN_FULL, // framesReady() is full frame count, no underrun
33 UNDERRUN_PARTIAL, // framesReady() is non-zero but < full frame count, partial underrun
34 UNDERRUN_EMPTY, // framesReady() is zero, total underrun
35};
36
37// Underrun counters are not reset to zero for new tracks or if track generation changes.
38// This packed representation is used to keep the information atomic.
39union FastTrackUnderruns {
40 FastTrackUnderruns() { mAtomic = 0;
Glenn Kasten91164e72016-03-15 15:55:01 -070041 static_assert(sizeof(FastTrackUnderruns) == sizeof(uint32_t), "FastTrackUnderrun"); }
Glenn Kasten22340022014-04-07 12:04:41 -070042 FastTrackUnderruns(const FastTrackUnderruns& copyFrom) : mAtomic(copyFrom.mAtomic) { }
43 FastTrackUnderruns& operator=(const FastTrackUnderruns& rhs)
44 { if (this != &rhs) mAtomic = rhs.mAtomic; return *this; }
45 struct {
46#define UNDERRUN_BITS 10
47#define UNDERRUN_MASK ((1 << UNDERRUN_BITS) - 1)
48 uint32_t mFull : UNDERRUN_BITS; // framesReady() is full frame count
49 uint32_t mPartial : UNDERRUN_BITS; // framesReady() is non-zero but < full frame count
50 uint32_t mEmpty : UNDERRUN_BITS; // framesReady() is zero
51 FastTrackUnderrunStatus mMostRecent : 2; // status of most recent framesReady()
52 } mBitFields;
53private:
54 uint32_t mAtomic;
55};
56
57// Represents the dump state of a fast track
58struct FastTrackDump {
59 FastTrackDump() : mFramesReady(0) { }
60 /*virtual*/ ~FastTrackDump() { }
Glenn Kastene4a7ce22015-03-03 11:23:17 -080061 FastTrackUnderruns mUnderruns;
62 size_t mFramesReady; // most recent value only; no long-term statistics kept
Andy Hungb54c8542016-09-21 12:55:15 -070063 int64_t mFramesWritten; // last value from track
Glenn Kasten22340022014-04-07 12:04:41 -070064};
65
Glenn Kasten22340022014-04-07 12:04:41 -070066struct FastMixerDumpState : FastThreadDumpState {
Glenn Kastenfbdb2ac2015-03-02 14:47:19 -080067 FastMixerDumpState();
Glenn Kasten22340022014-04-07 12:04:41 -070068 /*virtual*/ ~FastMixerDumpState();
69
Eric Tan7b651152018-07-13 10:17:19 -070070 void dump(int fd) const; // should only be called on a stable copy, not the original
Eric Tan1882f162018-08-02 18:05:39 -070071 Json::Value getJsonDump() const; // should only be called on a stable copy, not the original
Glenn Kasten22340022014-04-07 12:04:41 -070072
Andy Hungf6ab58d2018-05-25 12:50:39 -070073 double mLatencyMs = 0.; // measured latency, default of 0 if no valid timestamp read.
Glenn Kasten22340022014-04-07 12:04:41 -070074 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];
Andy Hung2e2c0bb2018-06-11 19:13:11 -070082
83 // For timestamp statistics.
84 TimestampVerifier<int64_t /* frame count */, int64_t /* time ns */> mTimestampVerifier;
Glenn Kasten22340022014-04-07 12:04:41 -070085};
86
87} // android
88
89#endif // ANDROID_AUDIO_FAST_MIXER_DUMP_STATE_H