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
23namespace android {
24
25FastTrack::FastTrack() :
26    mBufferProvider(NULL), mVolumeProvider(NULL),
27    mChannelMask(AUDIO_CHANNEL_OUT_STEREO), mFormat(AUDIO_FORMAT_INVALID), mGeneration(0)
28{
29}
30
31FastTrack::~FastTrack()
32{
33}
34
35FastMixerState::FastMixerState() : FastThreadState(),
36    // mFastTracks
37    mFastTracksGen(0), mTrackMask(0), mOutputSink(NULL), mOutputSinkGen(0),
38    mFrameCount(0), mTeeSink(NULL)
39{
40    int ok = pthread_once(&sMaxFastTracksOnce, sMaxFastTracksInit);
41    if (ok != 0) {
42        ALOGE("%s pthread_once failed: %d", __func__, ok);
43    }
44}
45
46FastMixerState::~FastMixerState()
47{
48}
49
50// static
51unsigned FastMixerState::sMaxFastTracks = kDefaultFastTracks;
52
53// static
54pthread_once_t FastMixerState::sMaxFastTracksOnce = PTHREAD_ONCE_INIT;
55
56// static
57const 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
72void 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