AAudioServiceStreamShared.h revision c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fb
1/* 2 * Copyright (C) 2017 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_AAUDIO_SERVICE_STREAM_SHARED_H 18#define AAUDIO_AAUDIO_SERVICE_STREAM_SHARED_H 19 20#include "fifo/FifoBuffer.h" 21#include "binding/AAudioServiceMessage.h" 22#include "binding/AAudioStreamRequest.h" 23#include "binding/AAudioStreamConfiguration.h" 24 25#include "AAudioService.h" 26#include "AAudioServiceStreamBase.h" 27 28namespace aaudio { 29 30// We expect the queue to only have a few commands. 31// This should be way more than we need. 32#define QUEUE_UP_CAPACITY_COMMANDS (128) 33 34class AAudioEndpointManager; 35class AAudioServiceEndpoint; 36class SharedRingBuffer; 37 38/** 39 * One of these is created for every MODE_SHARED stream in the AAudioService. 40 * 41 * Each Shared stream will register itself with an AAudioServiceEndpoint when it is opened. 42 */ 43class AAudioServiceStreamShared : public AAudioServiceStreamBase { 44 45public: 46 AAudioServiceStreamShared(android::AAudioService &aAudioService); 47 virtual ~AAudioServiceStreamShared(); 48 49 aaudio_result_t open(const aaudio::AAudioStreamRequest &request, 50 aaudio::AAudioStreamConfiguration &configurationOutput) override; 51 52 /** 53 * Start the flow of audio data. 54 * 55 * This is not guaranteed to be synchronous but it currently is. 56 * An AAUDIO_SERVICE_EVENT_STARTED will be sent to the client when complete. 57 */ 58 aaudio_result_t start() override; 59 60 /** 61 * Stop the flow of data so that start() can resume without loss of data. 62 * 63 * This is not guaranteed to be synchronous but it currently is. 64 * An AAUDIO_SERVICE_EVENT_PAUSED will be sent to the client when complete. 65 */ 66 aaudio_result_t pause() override; 67 68 /** 69 * Discard any data held by the underlying HAL or Service. 70 * 71 * This is not guaranteed to be synchronous but it currently is. 72 * An AAUDIO_SERVICE_EVENT_FLUSHED will be sent to the client when complete. 73 */ 74 aaudio_result_t flush() override; 75 76 aaudio_result_t close() override; 77 78 android::FifoBuffer *getDataFifoBuffer() { return mAudioDataQueue->getFifoBuffer(); } 79 80 void onStop(); 81 82 void onDisconnect(); 83 84protected: 85 86 aaudio_result_t getDownDataDescription(AudioEndpointParcelable &parcelable) override; 87 88 aaudio_result_t getFreeRunningPosition(int64_t *positionFrames, int64_t *timeNanos) override; 89 90private: 91 android::AAudioService &mAudioService; 92 AAudioServiceEndpoint *mServiceEndpoint = nullptr; 93 SharedRingBuffer *mAudioDataQueue; 94}; 95 96} /* namespace aaudio */ 97 98#endif //AAUDIO_AAUDIO_SERVICE_STREAM_SHARED_H 99