blob: 64171ac55b0709340a987e6070b4654a767d31a9 [file] [log] [blame]
Glenn Kasten97b5d0d2012-03-23 18:54:19 -07001/*
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_STATE_H
18#define ANDROID_AUDIO_FAST_MIXER_STATE_H
19
20#include "AudioBufferProvider.h"
21#include "NBAIO.h"
22
23namespace android {
24
25struct FastMixerDumpState;
26
27class VolumeProvider {
28public:
29 // Return the track volume in U4_12 format: left in lower half, right in upper half. The
30 // provider implementation is responsible for validating that the return value is in range.
31 virtual uint32_t getVolumeLR() = 0;
32protected:
33 VolumeProvider() { }
34 virtual ~VolumeProvider() { }
35};
36
37// Represents the state of a fast track
38struct FastTrack {
39 FastTrack();
40 /*virtual*/ ~FastTrack();
41
42 AudioBufferProvider* mBufferProvider; // must not be NULL
43 VolumeProvider* mVolumeProvider; // optional; if NULL then full-scale
44 int mGeneration; // increment when any field is assigned
45};
46
47// Represents a single state of the fast mixer
48struct FastMixerState {
49 FastMixerState();
50 /*virtual*/ ~FastMixerState();
51
52 static const unsigned kMaxFastTracks = 8; // must be between 2 and 32 inclusive
53
54 // all pointer fields use raw pointers; objects are owned and ref-counted by the normal mixer
55 FastTrack mFastTracks[kMaxFastTracks];
56 int mFastTracksGen; // increment when any mFastTracks[i].mGeneration is incremented
57 unsigned mTrackMask; // bit i is set if and only if mFastTracks[i] != NULL
58 NBAIO_Sink* mOutputSink; // HAL output device, must already be negotiated
59 int mOutputSinkGen; // increment when mOutputSink is assigned
60 size_t mFrameCount; // number of frames per fast mix buffer
61 enum Command {
62 INITIAL = 0, // used only for the initial state
63 HOT_IDLE = 1, // do nothing
64 COLD_IDLE = 2, // wait for the futex
65 IDLE = 3, // either HOT_IDLE or COLD_IDLE
66 EXIT = 4, // exit from thread
67 // The following commands also process configuration changes, and can be "or"ed:
68 MIX = 0x8, // mix tracks
69 WRITE = 0x10, // write to output sink
70 MIX_WRITE = 0x18, // mix tracks and write to output sink
71 } mCommand;
72 int32_t* mColdFutexAddr; // for COLD_IDLE only, pointer to the associated futex
73 unsigned mColdGen; // increment when COLD_IDLE is requested so it's only performed once
74 // This might be a one-time configuration rather than per-state
75 FastMixerDumpState* mDumpState; // if non-NULL, then update dump state periodically
76}; // struct FastMixerState
77
78} // namespace android
79
80#endif // ANDROID_AUDIO_FAST_MIXER_STATE_H