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 #define LOG_TAG "FastMixerState"
18 //#define LOG_NDEBUG 0
19
20 #include <cutils/properties.h>
21 #include "FastMixerState.h"
22
23 namespace android {
24
FastMixerState()25 FastMixerState::FastMixerState() : FastThreadState()
26 {
27 const int ok = pthread_once(&sMaxFastTracksOnce, sMaxFastTracksInit);
28 if (ok != 0) {
29 ALOGE("%s pthread_once failed: %d", __func__, ok);
30 }
31 }
32
33 // static
34 unsigned FastMixerState::sMaxFastTracks = kDefaultFastTracks;
35
36 // static
37 pthread_once_t FastMixerState::sMaxFastTracksOnce = PTHREAD_ONCE_INIT;
38
39 // static
commandToString(Command command)40 const char *FastMixerState::commandToString(Command command)
41 {
42 const char *str = FastThreadState::commandToString(command);
43 if (str != nullptr) {
44 return str;
45 }
46 switch (command) {
47 case FastMixerState::MIX: return "MIX";
48 case FastMixerState::WRITE: return "WRITE";
49 case FastMixerState::MIX_WRITE: return "MIX_WRITE";
50 }
51 LOG_ALWAYS_FATAL("%s", __func__);
52 }
53
54 // static
sMaxFastTracksInit()55 void FastMixerState::sMaxFastTracksInit()
56 {
57 char value[PROPERTY_VALUE_MAX];
58 if (property_get("ro.audio.max_fast_tracks", value, nullptr /* default_value */) > 0) {
59 char *endptr;
60 const auto ul = strtoul(value, &endptr, 0);
61 if (*endptr == '\0' && kMinFastTracks <= ul && ul <= kMaxFastTracks) {
62 sMaxFastTracks = (unsigned) ul;
63 }
64 }
65 ALOGI("sMaxFastTracks = %u", sMaxFastTracks);
66 }
67
68 } // namespace android
69