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 
FastTrack()25 FastTrack::FastTrack() :
26     mBufferProvider(NULL), mVolumeProvider(NULL),
27     mChannelMask(AUDIO_CHANNEL_OUT_STEREO), mFormat(AUDIO_FORMAT_INVALID), mGeneration(0)
28 {
29 }
30 
~FastTrack()31 FastTrack::~FastTrack()
32 {
33 }
34 
FastMixerState()35 FastMixerState::FastMixerState() : FastThreadState(),
36     // mFastTracks
37     mFastTracksGen(0), mTrackMask(0), mOutputSink(NULL), mOutputSinkGen(0),
38     mFrameCount(0)
39 {
40     int ok = pthread_once(&sMaxFastTracksOnce, sMaxFastTracksInit);
41     if (ok != 0) {
42         ALOGE("%s pthread_once failed: %d", __func__, ok);
43     }
44 }
45 
~FastMixerState()46 FastMixerState::~FastMixerState()
47 {
48 }
49 
50 // static
51 unsigned FastMixerState::sMaxFastTracks = kDefaultFastTracks;
52 
53 // static
54 pthread_once_t FastMixerState::sMaxFastTracksOnce = PTHREAD_ONCE_INIT;
55 
56 // static
commandToString(Command command)57 const char *FastMixerState::commandToString(Command command)
58 {
59     const char *str = FastThreadState::commandToString(command);
60     if (str != NULL) {
61         return str;
62     }
63     switch (command) {
64     case FastMixerState::MIX:       return "MIX";
65     case FastMixerState::WRITE:     return "WRITE";
66     case FastMixerState::MIX_WRITE: return "MIX_WRITE";
67     }
68     LOG_ALWAYS_FATAL("%s", __func__);
69 }
70 
71 // static
sMaxFastTracksInit()72 void FastMixerState::sMaxFastTracksInit()
73 {
74     char value[PROPERTY_VALUE_MAX];
75     if (property_get("ro.audio.max_fast_tracks", value, NULL) > 0) {
76         char *endptr;
77         unsigned long ul = strtoul(value, &endptr, 0);
78         if (*endptr == '\0' && kMinFastTracks <= ul && ul <= kMaxFastTracks) {
79             sMaxFastTracks = (unsigned) ul;
80         }
81     }
82     ALOGI("sMaxFastTracks = %u", sMaxFastTracks);
83 }
84 
85 }   // namespace android
86