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 teardownStream() override; 30 31 virtual Result startStream() override; 32 virtual Result stopStream() override; 33 34 // Oboe-specific 35 oboe::StreamState getState() const; 36 37 int getLastErrorCallbackResult(); 38 39 StreamBase::Result getTimeStamp(oboe::FrameTimestamp* timeStamp); 40 41 int32_t getRoutedDeviceId(); 42 43 int32_t getSharingMode(); 44 int32_t getChannelCount(); 45 46 bool isMMap(); 47 48 protected: OboeStream(int32_t subtype)49 OboeStream(int32_t subtype) : mSubtype(subtype), mStreamStarted(false) {} 50 51 // determine native back-end to use. 52 // either SUB_TYPE_OBOE_DEFAULT, SUB_TYPE_OBOE_AAUDIO or SUB_TYPE_OBOE_OPENSL_ES 53 int32_t mSubtype; 54 55 // Oboe Audio Stream 56 std::shared_ptr<oboe::AudioStream> mAudioStream; 57 bool mStreamStarted; 58 59 std::mutex mStreamLock; 60 61 Result teardownStream_l(); 62 }; 63 64 #endif //MEGA_COMMON_OBOESTREAM_H 65