1c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk/*
2c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * Copyright (C) 2017 The Android Open Source Project
3c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk *
4c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * Licensed under the Apache License, Version 2.0 (the "License");
5c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * you may not use this file except in compliance with the License.
6c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * You may obtain a copy of the License at
7c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk *
8c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk *      http://www.apache.org/licenses/LICENSE-2.0
9c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk *
10c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * Unless required by applicable law or agreed to in writing, software
11c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * distributed under the License is distributed on an "AS IS" BASIS,
12c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * See the License for the specific language governing permissions and
14c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * limitations under the License.
15c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk */
16c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
17c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#ifndef AAUDIO_SHARED_MEMORY_PROXY_H
18c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#define AAUDIO_SHARED_MEMORY_PROXY_H
19c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
20c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#include <stdint.h>
21c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#include <cutils/ashmem.h>
22c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#include <sys/mman.h>
23c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
24a4eb0d86a29be2763be5fac51727858d5095794bPhil Burk#include <aaudio/AAudio.h>
25c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
26c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burknamespace aaudio {
27c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
28c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk/**
29c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * Proxy for sharing memory between two file descriptors.
30c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk */
31c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burkclass SharedMemoryProxy {
32c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burkpublic:
33c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    SharedMemoryProxy() {}
34c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
35c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    ~SharedMemoryProxy();
36c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
37c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    aaudio_result_t open(int fd, int32_t capacityInBytes);
38c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
39c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    int getFileDescriptor() const {
40c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk        return mProxyFileDescriptor;
41c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    }
42c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
43c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burkprivate:
44c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    int            mOriginalFileDescriptor = -1;
45c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    int            mProxyFileDescriptor = -1;
46c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    uint8_t       *mOriginalSharedMemory = nullptr;
47c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    uint8_t       *mProxySharedMemory = nullptr;
48c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    int32_t        mSharedMemorySizeInBytes = 0;
49c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk};
50c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
51c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk} /* namespace aaudio */
52c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
53c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#endif //AAUDIO_SHARED_MEMORY_PROXY_H
54