FastMixerState.cpp 2.3 KB

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