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_SHARED_MEMORY_PROXY_H
     18 #define AAUDIO_SHARED_MEMORY_PROXY_H
     19 
     20 #include <stdint.h>
     21 #include <cutils/ashmem.h>
     22 #include <sys/mman.h>
     23 
     24 #include <aaudio/AAudio.h>
     25 
     26 namespace aaudio {
     27 
     28 /**
     29  * Proxy for sharing memory between two file descriptors.
     30  */
     31 class SharedMemoryProxy {
     32 public:
     33     SharedMemoryProxy() {}
     34 
     35     ~SharedMemoryProxy();
     36 
     37     aaudio_result_t open(int fd, int32_t capacityInBytes);
     38 
     39     int getFileDescriptor() const {
     40         return mProxyFileDescriptor;
     41     }
     42 
     43 private:
     44     int            mOriginalFileDescriptor = -1;
     45     int            mProxyFileDescriptor = -1;
     46     uint8_t       *mOriginalSharedMemory = nullptr;
     47     uint8_t       *mProxySharedMemory = nullptr;
     48     int32_t        mSharedMemorySizeInBytes = 0;
     49 };
     50 
     51 } /* namespace aaudio */
     52 
     53 #endif //AAUDIO_SHARED_MEMORY_PROXY_H
     54