Home | History | Annotate | Download | only in oboeservice
      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_MMAP_H
     18 #define AAUDIO_AAUDIO_SERVICE_STREAM_MMAP_H
     19 
     20 #include <atomic>
     21 
     22 #include <android-base/unique_fd.h>
     23 #include <media/audiohal/StreamHalInterface.h>
     24 #include <media/MmapStreamCallback.h>
     25 #include <media/MmapStreamInterface.h>
     26 #include <utils/RefBase.h>
     27 #include <utils/String16.h>
     28 #include <utils/Vector.h>
     29 
     30 #include "binding/AAudioServiceMessage.h"
     31 #include "AAudioServiceStreamBase.h"
     32 #include "binding/AudioEndpointParcelable.h"
     33 #include "SharedMemoryProxy.h"
     34 #include "TimestampScheduler.h"
     35 #include "utility/MonotonicCounter.h"
     36 
     37 
     38 namespace aaudio {
     39 
     40 
     41 /**
     42  * These corresponds to an EXCLUSIVE mode MMAP client stream.
     43  * It has exclusive use of one AAudioServiceEndpointMMAP to communicate with the underlying
     44  * device or port.
     45  */
     46 class AAudioServiceStreamMMAP : public AAudioServiceStreamBase {
     47 
     48 public:
     49     AAudioServiceStreamMMAP(android::AAudioService &aAudioService,
     50                             bool inService);
     51     virtual ~AAudioServiceStreamMMAP() = default;
     52 
     53     aaudio_result_t open(const aaudio::AAudioStreamRequest &request) override;
     54 
     55     /**
     56      * Stop the flow of data so that start() can resume without loss of data.
     57      *
     58      * This is not guaranteed to be synchronous but it currently is.
     59      * An AAUDIO_SERVICE_EVENT_PAUSED will be sent to the client when complete.
     60     */
     61     aaudio_result_t pause() override;
     62 
     63     aaudio_result_t stop() override;
     64 
     65     aaudio_result_t startClient(const android::AudioClient& client,
     66                                 audio_port_handle_t *clientHandle) override;
     67 
     68     aaudio_result_t stopClient(audio_port_handle_t clientHandle) override;
     69 
     70     aaudio_result_t close() override;
     71 
     72     const char *getTypeText() const override { return "MMAP"; }
     73 
     74 protected:
     75 
     76     aaudio_result_t getAudioDataDescription(AudioEndpointParcelable &parcelable) override;
     77 
     78     aaudio_result_t getFreeRunningPosition(int64_t *positionFrames, int64_t *timeNanos) override;
     79 
     80     aaudio_result_t getHardwareTimestamp(int64_t *positionFrames, int64_t *timeNanos) override;
     81 
     82     /**
     83      * Device specific startup.
     84      * @return AAUDIO_OK or negative error.
     85      */
     86     aaudio_result_t startDevice() override;
     87 
     88 private:
     89 
     90     bool                     mInService = false;
     91 };
     92 
     93 } // namespace aaudio
     94 
     95 #endif //AAUDIO_AAUDIO_SERVICE_STREAM_MMAP_H
     96