blob: dbccb1086a55d0aa76f6b684115b4fa923e31601 [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
Glenn Kasten60fd12a2017-02-21 13:06:16 -080017#define LOG_TAG "FastMixerState"
18//#define LOG_NDEBUG 0
19
Glenn Kastendc2c50b2016-04-21 08:13:14 -070020#include <cutils/properties.h>
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070021#include "FastMixerState.h"
22
23namespace android {
24
25FastTrack::FastTrack() :
Andy Hungf0859f32023-05-25 16:28:04 -070026 mBufferProvider(nullptr), mVolumeProvider(nullptr),
Andy Hunge8a1ced2014-05-09 15:02:21 -070027 mChannelMask(AUDIO_CHANNEL_OUT_STEREO), mFormat(AUDIO_FORMAT_INVALID), mGeneration(0)
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070028{
29}
30
Glenn Kastenf7160b52014-03-18 17:01:15 -070031FastMixerState::FastMixerState() : FastThreadState(),
Glenn Kasten22340022014-04-07 12:04:41 -070032 // mFastTracks
Andy Hungf0859f32023-05-25 16:28:04 -070033 mFastTracksGen(0), mTrackMask(0), mOutputSink(nullptr), mOutputSinkGen(0),
Andy Hung8946a282018-04-19 20:04:56 -070034 mFrameCount(0)
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070035{
Andy Hungf0859f32023-05-25 16:28:04 -070036 const int ok = pthread_once(&sMaxFastTracksOnce, sMaxFastTracksInit);
Glenn Kastendc2c50b2016-04-21 08:13:14 -070037 if (ok != 0) {
38 ALOGE("%s pthread_once failed: %d", __func__, ok);
39 }
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070040}
41
Glenn Kastend702a562015-03-02 15:51:38 -080042// static
Glenn Kastendc2c50b2016-04-21 08:13:14 -070043unsigned FastMixerState::sMaxFastTracks = kDefaultFastTracks;
44
45// static
46pthread_once_t FastMixerState::sMaxFastTracksOnce = PTHREAD_ONCE_INIT;
47
48// static
Glenn Kastend702a562015-03-02 15:51:38 -080049const char *FastMixerState::commandToString(Command command)
50{
51 const char *str = FastThreadState::commandToString(command);
Andy Hungf0859f32023-05-25 16:28:04 -070052 if (str != nullptr) {
Glenn Kastend702a562015-03-02 15:51:38 -080053 return str;
54 }
55 switch (command) {
56 case FastMixerState::MIX: return "MIX";
57 case FastMixerState::WRITE: return "WRITE";
58 case FastMixerState::MIX_WRITE: return "MIX_WRITE";
59 }
60 LOG_ALWAYS_FATAL("%s", __func__);
61}
62
Glenn Kastendc2c50b2016-04-21 08:13:14 -070063// static
64void FastMixerState::sMaxFastTracksInit()
65{
66 char value[PROPERTY_VALUE_MAX];
Andy Hungf0859f32023-05-25 16:28:04 -070067 if (property_get("ro.audio.max_fast_tracks", value, nullptr /* default_value */) > 0) {
Glenn Kastendc2c50b2016-04-21 08:13:14 -070068 char *endptr;
Andy Hungf0859f32023-05-25 16:28:04 -070069 const unsigned long ul = strtoul(value, &endptr, 0);
Glenn Kastendc2c50b2016-04-21 08:13:14 -070070 if (*endptr == '\0' && kMinFastTracks <= ul && ul <= kMaxFastTracks) {
71 sMaxFastTracks = (unsigned) ul;
72 }
73 }
74 ALOGI("sMaxFastTracks = %u", sMaxFastTracks);
75}
76
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070077} // namespace android