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_OBOESTREAM_H 18 #define MEGA_COMMON_OBOESTREAM_H 19 20 #include <cstdint> 21 #include <mutex> 22 23 #include <StreamBase.h> 24 25 class OboeStream: public StreamBase { 26 public: 27 static Result OboeErrorToMegaAudioError(oboe::Result oboeError); 28 29 virtual Result startStream() override; 30 31 virtual Result stopStream() override; 32 33 virtual Result closeStream() override; 34 35 virtual Result teardownStream() override; 36 37 // Oboe-specific 38 oboe::StreamState getState() const; 39 40 int getLastErrorCallbackResult(); 41 42 StreamBase::Result getTimeStamp(oboe::FrameTimestamp* timeStamp); 43 44 int32_t getRoutedDeviceId(); 45 46 int32_t getSharingMode(); 47 int32_t getChannelCount(); 48 49 bool isMMap(); 50 51 protected: OboeStream(int32_t subtype)52 OboeStream(int32_t subtype) : mSubtype(subtype), mStreamStarted(false) {} 53 54 // determine native back-end to use. 55 // either SUB_TYPE_OBOE_DEFAULT, SUB_TYPE_OBOE_AAUDIO or SUB_TYPE_OBOE_OPENSL_ES 56 int32_t mSubtype; 57 58 // Oboe Audio Stream 59 std::shared_ptr<oboe::AudioStream> mAudioStream; 60 bool mStreamStarted; 61 62 std::mutex mStreamLock; 63 64 oboe::AudioStreamBuilder mBuilder; 65 66 private: 67 Result teardownStream_l(); 68 }; 69 70 #endif //MEGA_COMMON_OBOESTREAM_H 71