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