blob: 6e53f217fc59a682e4f9c1eb4dad388fa643c413 [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
Glenn Kasten21e8c502012-04-12 09:39:42 -070020#include <system/audio.h>
Glenn Kastenfc7992b2012-08-29 11:10:32 -070021#include <media/ExtendedAudioBufferProvider.h>
22#include <media/nbaio/NBAIO.h>
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070023
24namespace android {
25
26struct FastMixerDumpState;
27
28class VolumeProvider {
29public:
30 // Return the track volume in U4_12 format: left in lower half, right in upper half. The
31 // provider implementation is responsible for validating that the return value is in range.
32 virtual uint32_t getVolumeLR() = 0;
33protected:
34 VolumeProvider() { }
35 virtual ~VolumeProvider() { }
36};
37
38// Represents the state of a fast track
39struct FastTrack {
40 FastTrack();
41 /*virtual*/ ~FastTrack();
42
Glenn Kasten288ed212012-04-25 17:52:27 -070043 ExtendedAudioBufferProvider* mBufferProvider; // must be NULL if inactive, or non-NULL if active
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070044 VolumeProvider* mVolumeProvider; // optional; if NULL then full-scale
Glenn Kasten21e8c502012-04-12 09:39:42 -070045 unsigned mSampleRate; // optional; if zero then use mixer sample rate
46 audio_channel_mask_t mChannelMask; // AUDIO_CHANNEL_OUT_MONO or AUDIO_CHANNEL_OUT_STEREO
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070047 int mGeneration; // increment when any field is assigned
48};
49
50// Represents a single state of the fast mixer
51struct FastMixerState {
52 FastMixerState();
53 /*virtual*/ ~FastMixerState();
54
55 static const unsigned kMaxFastTracks = 8; // must be between 2 and 32 inclusive
56
57 // all pointer fields use raw pointers; objects are owned and ref-counted by the normal mixer
58 FastTrack mFastTracks[kMaxFastTracks];
59 int mFastTracksGen; // increment when any mFastTracks[i].mGeneration is incremented
Glenn Kasten288ed212012-04-25 17:52:27 -070060 unsigned mTrackMask; // bit i is set if and only if mFastTracks[i] is active
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070061 NBAIO_Sink* mOutputSink; // HAL output device, must already be negotiated
62 int mOutputSinkGen; // increment when mOutputSink is assigned
63 size_t mFrameCount; // number of frames per fast mix buffer
64 enum Command {
65 INITIAL = 0, // used only for the initial state
66 HOT_IDLE = 1, // do nothing
67 COLD_IDLE = 2, // wait for the futex
68 IDLE = 3, // either HOT_IDLE or COLD_IDLE
69 EXIT = 4, // exit from thread
70 // The following commands also process configuration changes, and can be "or"ed:
71 MIX = 0x8, // mix tracks
72 WRITE = 0x10, // write to output sink
73 MIX_WRITE = 0x18, // mix tracks and write to output sink
74 } mCommand;
75 int32_t* mColdFutexAddr; // for COLD_IDLE only, pointer to the associated futex
76 unsigned mColdGen; // increment when COLD_IDLE is requested so it's only performed once
77 // This might be a one-time configuration rather than per-state
78 FastMixerDumpState* mDumpState; // if non-NULL, then update dump state periodically
Glenn Kastenfbae5da2012-05-21 09:17:20 -070079 NBAIO_Sink* mTeeSink; // if non-NULL, then duplicate write()s to this non-blocking sink
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070080}; // struct FastMixerState
81
82} // namespace android
83
84#endif // ANDROID_AUDIO_FAST_MIXER_STATE_H