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 | |
Glenn Kasten | 09474df | 2012-05-10 14:48:07 -0700 | [diff] [blame] | 20 | #include <utils/Debug.h> |
Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 21 | #if 1 // FIXME move to where used |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 22 | extern "C" { |
| 23 | #include "../private/bionic_futex.h" |
| 24 | } |
Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 25 | #endif |
Glenn Kasten | f7160b5 | 2014-03-18 17:01:15 -0700 | [diff] [blame] | 26 | #include "FastThread.h" |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 27 | #include "StateQueue.h" |
| 28 | #include "FastMixerState.h" |
Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 29 | #include "FastMixerDumpState.h" |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 33 | class AudioMixer; |
| 34 | |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 35 | typedef StateQueue<FastMixerState> FastMixerStateQueue; |
| 36 | |
Glenn Kasten | f7160b5 | 2014-03-18 17:01:15 -0700 | [diff] [blame] | 37 | class FastMixer : public FastThread { |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 38 | |
| 39 | public: |
Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 40 | FastMixer(); |
| 41 | virtual ~FastMixer(); |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 42 | |
Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 43 | FastMixerStateQueue* sq(); |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 44 | |
| 45 | private: |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 46 | FastMixerStateQueue mSQ; |
| 47 | |
Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 48 | // callouts |
| 49 | virtual const FastThreadState *poll(); |
| 50 | virtual void setLog(NBLog::Writer *logWriter); |
| 51 | virtual void onIdle(); |
| 52 | virtual void onExit(); |
| 53 | virtual bool isSubClassCommand(FastThreadState::Command command); |
| 54 | virtual void onStateChange(); |
| 55 | virtual void onWork(); |
| 56 | |
| 57 | // FIXME these former local variables need comments and to be renamed to have "m" prefix |
| 58 | static const FastMixerState initial; |
| 59 | FastMixerState preIdle; // copy of state before we went into idle |
| 60 | long slopNs; // accumulated time we've woken up too early (> 0) or too late (< 0) |
| 61 | int fastTrackNames[FastMixerState::kMaxFastTracks]; // handles used by mixer to identify tracks |
| 62 | int generations[FastMixerState::kMaxFastTracks]; // last observed mFastTracks[i].mGeneration |
| 63 | NBAIO_Sink *outputSink; |
| 64 | int outputSinkGen; |
| 65 | AudioMixer* mixer; |
| 66 | short *mixBuffer; |
| 67 | enum {UNDEFINED, MIXED, ZEROED} mixBufferState; |
| 68 | NBAIO_Format format; |
| 69 | unsigned sampleRate; |
| 70 | int fastTracksGen; |
| 71 | FastMixerDumpState dummyDumpState; |
| 72 | uint32_t totalNativeFramesWritten; // copied to dumpState->mFramesWritten |
| 73 | |
| 74 | // next 2 fields are valid only when timestampStatus == NO_ERROR |
| 75 | AudioTimestamp timestamp; |
| 76 | uint32_t nativeFramesWrittenButNotPresented; |
| 77 | |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 78 | }; // class FastMixer |
| 79 | |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 80 | } // namespace android |
| 81 | |
| 82 | #endif // ANDROID_AUDIO_FAST_MIXER_H |