1 /* 2 * Copyright 2020 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 MEGA_COMMON_STREAMBASE_H 18 #define MEGA_COMMON_STREAMBASE_H 19 20 #include <cstdint> 21 22 class AudioSink; 23 24 class StreamBase { 25 public: 26 // 27 // Error Codes 28 // These values must be kept in sync with the equivalent symbols in 29 // org.hyphonate.megaaudio.common.Streambase.java 30 // 31 enum Result { 32 OK = 0, 33 ERROR_UNKNOWN = -1, 34 ERROR_UNSUPPORTED = -2, 35 ERROR_INVALID_STATE = -3 36 }; 37 StreamBase()38 StreamBase() : 39 mChannelCount(0), 40 mChannelMask(0), 41 mNumExchangeChannels(0), 42 mSampleRate(0), 43 mRouteDeviceId(ROUTING_DEVICE_NONE), 44 mBufferSizeInFrames(-1) {} ~StreamBase()45 virtual ~StreamBase() {} 46 47 // 48 // Attributes 49 // 50 static const int32_t ROUTING_DEVICE_NONE = -1; 51 52 static const int32_t SHARING_MODE_INVALID = -1; 53 getNumBufferFrames()54 int32_t getNumBufferFrames() const { return mBufferSizeInFrames; } 55 56 // 57 // State 58 // 59 60 /** 61 * Deinitializes the stream. 62 * Concrete subclasses should stop the stream (is not already stopped) and deallocate any 63 * resources being used by the stream. 64 * The stream cannot be started again without another call to setupAudioStream(). 65 * 66 * The expectation is that this method will be synchronous in concrete subclasses. 67 * @return ERROR_NONE if successful, otherwise an error code 68 */ 69 virtual Result teardownStream() = 0; 70 71 /** 72 * Begin the playback/recording process. 73 * 74 * In concrete subclasses, this may be either synchronous or asynchronous. 75 * @return ERROR_NONE if successful, otherwise an error code 76 */ 77 virtual Result startStream() = 0; 78 79 /** 80 * Stop the playback/recording process. 81 * 82 * In concrete subclasses, this may be either synchronous or asynchronous. 83 */ 84 virtual Result stopStream() = 0; 85 86 protected: 87 // Audio attributes 88 int32_t mChannelCount; 89 int32_t mChannelMask; 90 int32_t mNumExchangeChannels; // this may be mChannelCount or the number of channels 91 // associated with mChannelMask 92 int32_t mSampleRate; 93 int32_t mRouteDeviceId; 94 int32_t mBufferSizeInFrames; 95 96 // from org.hyphonate.megaaudio.common.BuilderBase 97 static const int32_t SUB_TYPE_OBOE_AAUDIO = 0x0001; 98 static const int32_t SUB_TYPE_OBOE_OPENSL_ES = 0x0002; 99 }; 100 101 #endif // MEGA_COMMON_STREAMBASE_H 102 103