1 /* 2 * Copyright 2015 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 #ifndef AAUDIO_AUDIO_STREAM_BUILDER_H 18 #define AAUDIO_AUDIO_STREAM_BUILDER_H 19 20 #include <stdint.h> 21 22 #include <aaudio/AAudio.h> 23 24 #include "AAudioStreamParameters.h" 25 #include "AudioStream.h" 26 27 namespace aaudio { 28 29 /** 30 * Factory class for an AudioStream. 31 */ 32 class AudioStreamBuilder : public AAudioStreamParameters { 33 public: 34 AudioStreamBuilder() = default; 35 36 ~AudioStreamBuilder() = default; 37 isSharingModeMatchRequired()38 bool isSharingModeMatchRequired() const { 39 return mSharingModeMatchRequired; 40 } 41 setSharingModeMatchRequired(bool required)42 AudioStreamBuilder* setSharingModeMatchRequired(bool required) { 43 mSharingModeMatchRequired = required; 44 return this; 45 } 46 getPerformanceMode()47 int32_t getPerformanceMode() const { 48 return mPerformanceMode; 49 } 50 setPerformanceMode(aaudio_performance_mode_t performanceMode)51 AudioStreamBuilder* setPerformanceMode(aaudio_performance_mode_t performanceMode) { 52 mPerformanceMode = performanceMode; 53 return this; 54 } 55 getDataCallbackProc()56 AAudioStream_dataCallback getDataCallbackProc() const { 57 return mDataCallbackProc; 58 } 59 setDataCallbackProc(AAudioStream_dataCallback proc)60 AudioStreamBuilder* setDataCallbackProc(AAudioStream_dataCallback proc) { 61 mDataCallbackProc = proc; 62 return this; 63 } 64 getDataCallbackUserData()65 void *getDataCallbackUserData() const { 66 return mDataCallbackUserData; 67 } 68 setDataCallbackUserData(void * userData)69 AudioStreamBuilder* setDataCallbackUserData(void *userData) { 70 mDataCallbackUserData = userData; 71 return this; 72 } 73 getErrorCallbackProc()74 AAudioStream_errorCallback getErrorCallbackProc() const { 75 return mErrorCallbackProc; 76 } 77 setErrorCallbackProc(AAudioStream_errorCallback proc)78 AudioStreamBuilder* setErrorCallbackProc(AAudioStream_errorCallback proc) { 79 mErrorCallbackProc = proc; 80 return this; 81 } 82 setErrorCallbackUserData(void * userData)83 AudioStreamBuilder* setErrorCallbackUserData(void *userData) { 84 mErrorCallbackUserData = userData; 85 return this; 86 } 87 getErrorCallbackUserData()88 void *getErrorCallbackUserData() const { 89 return mErrorCallbackUserData; 90 } 91 getFramesPerDataCallback()92 int32_t getFramesPerDataCallback() const { 93 return mFramesPerDataCallback; 94 } 95 setFramesPerDataCallback(int32_t sizeInFrames)96 AudioStreamBuilder* setFramesPerDataCallback(int32_t sizeInFrames) { 97 mFramesPerDataCallback = sizeInFrames; 98 return this; 99 } 100 setPrivacySensitiveRequest(bool privacySensitive)101 AudioStreamBuilder* setPrivacySensitiveRequest(bool privacySensitive) { 102 mPrivacySensitiveReq = 103 privacySensitive ? PRIVACY_SENSITIVE_ENABLED : PRIVACY_SENSITIVE_DISABLED; 104 return this; 105 } 106 107 aaudio_result_t build(AudioStream **streamPtr); 108 109 virtual aaudio_result_t validate() const override; 110 111 112 void logParameters() const; 113 114 // Mark the stream so it can be deleted. 115 static void stopUsingStream(AudioStream *stream); 116 117 private: 118 // Extract a raw pointer that we can pass to a 'C' app. 119 static AudioStream *startUsingStream(android::sp<AudioStream> &spAudioStream); 120 121 bool mSharingModeMatchRequired = false; // must match sharing mode requested 122 aaudio_performance_mode_t mPerformanceMode = AAUDIO_PERFORMANCE_MODE_NONE; 123 124 AAudioStream_dataCallback mDataCallbackProc = nullptr; // external callback functions 125 void *mDataCallbackUserData = nullptr; 126 int32_t mFramesPerDataCallback = AAUDIO_UNSPECIFIED; // frames 127 128 AAudioStream_errorCallback mErrorCallbackProc = nullptr; 129 void *mErrorCallbackUserData = nullptr; 130 131 enum { 132 PRIVACY_SENSITIVE_DEFAULT = -1, 133 PRIVACY_SENSITIVE_DISABLED = 0, 134 PRIVACY_SENSITIVE_ENABLED = 1, 135 }; 136 typedef int32_t privacy_sensitive_t; 137 privacy_sensitive_t mPrivacySensitiveReq = PRIVACY_SENSITIVE_DEFAULT; 138 }; 139 140 } /* namespace aaudio */ 141 142 #endif //AAUDIO_AUDIO_STREAM_BUILDER_H 143