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 mSampleRate(0), 41 mRouteDeviceId(ROUTING_DEVICE_NONE), 42 mBufferSizeInFrames(-1) {} ~StreamBase()43 virtual ~StreamBase() {} 44 45 // 46 // Attributes 47 // 48 static const int32_t ROUTING_DEVICE_NONE = -1; getRoutedDeviceId()49 int32_t getRoutedDeviceId() const { return mRouteDeviceId; } 50 getNumBufferFrames()51 int32_t getNumBufferFrames() const { return mBufferSizeInFrames; } 52 53 // 54 // State 55 // 56 57 /** 58 * Deinitializes the stream. 59 * Concrete subclasses should stop the stream (is not already stopped) and deallocate any 60 * resources being used by the stream. 61 * The stream cannot be started again without another call to setupAudioStream(). 62 * 63 * The expectation is that this method will be synchronous in concrete subclasses. 64 * @return ERROR_NONE if successful, otherwise an error code 65 */ 66 virtual Result teardownStream() = 0; 67 68 /** 69 * Begin the playback/recording process. 70 * 71 * In concrete subclasses, this may be either synchronous or asynchronous. 72 * @return ERROR_NONE if successful, otherwise an error code 73 */ 74 virtual Result startStream() = 0; 75 76 /** 77 * Stop the playback/recording process. 78 * 79 * In concrete subclasses, this may be either synchronous or asynchronous. 80 */ 81 virtual Result stopStream() = 0; 82 83 protected: 84 // Audio attributes 85 int32_t mChannelCount; 86 int32_t mSampleRate; 87 int32_t mRouteDeviceId; 88 int32_t mBufferSizeInFrames; 89 90 // from org.hyphonate.megaaudio.common.BuilderBase 91 static const int32_t SUB_TYPE_OBOE_AAUDIO = 0x0001; 92 static const int32_t SUB_TYPE_OBOE_OPENSL_ES = 0x0002; 93 }; 94 95 #endif // MEGA_COMMON_STREAMBASE_H 96 97