Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_BINDING_AUDIO_ENDPOINT_PARCELABLE_H |
| 18 | #define ANDROID_BINDING_AUDIO_ENDPOINT_PARCELABLE_H |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | //#include <sys/mman.h> |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 23 | #include <aaudio/Endpoint.h> |
Phil Burk | e72481c | 2017-08-08 13:20:45 -0700 | [diff] [blame] | 24 | #include <android-base/unique_fd.h> |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 25 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 26 | #include "binding/AAudioServiceDefinitions.h" |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 27 | #include "binding/RingBufferParcelable.h" |
| 28 | |
| 29 | using android::status_t; |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 30 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 31 | namespace aaudio { |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Container for information about the message queues plus |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 35 | * general stream information needed by AAudio clients. |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 36 | * It contains no addresses, just sizes, offsets and file descriptors for |
| 37 | * shared memory that can be passed through Binder. |
| 38 | */ |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 39 | class AudioEndpointParcelable { |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 40 | public: |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 41 | AudioEndpointParcelable() = default; |
| 42 | |
| 43 | // Ctor/assignment from a parcelable representation. |
| 44 | // Since the parcelable object owns unique FDs (for shared memory blocks), move semantics are |
| 45 | // provided to avoid the need to dupe. |
jiabin | d5bd06a | 2021-04-27 22:04:08 +0000 | [diff] [blame] | 46 | explicit AudioEndpointParcelable(Endpoint&& parcelable); |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 47 | AudioEndpointParcelable& operator=(Endpoint&& parcelable); |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Add the file descriptor to the table. |
| 51 | * @return index in table or negative error |
| 52 | */ |
Phil Burk | e72481c | 2017-08-08 13:20:45 -0700 | [diff] [blame] | 53 | int32_t addFileDescriptor(const android::base::unique_fd& fd, int32_t sizeInBytes); |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 54 | |
jiabin | f7f0615 | 2021-11-22 18:10:14 +0000 | [diff] [blame] | 55 | /** |
| 56 | * Close current data file descriptor. The duplicated file descriptor will be close. |
| 57 | */ |
| 58 | void closeDataFileDescriptor(); |
| 59 | |
| 60 | /** |
| 61 | * Update current data file descriptor with given endpoint parcelable. |
| 62 | * @param endpointParcelable an endpoint parcelable that contains new data file |
| 63 | * descriptor information |
jiabin | fc791ee | 2023-02-15 19:43:40 +0000 | [diff] [blame^] | 64 | * @return AAUDIO_OK if the data file descriptor updates successfully. |
| 65 | * AAUDIO_ERROR_OUT_OF_RANGE if there is not enough space for the shared memory. |
jiabin | f7f0615 | 2021-11-22 18:10:14 +0000 | [diff] [blame] | 66 | */ |
jiabin | fc791ee | 2023-02-15 19:43:40 +0000 | [diff] [blame^] | 67 | aaudio_result_t updateDataFileDescriptor(AudioEndpointParcelable* endpointParcelable); |
jiabin | f7f0615 | 2021-11-22 18:10:14 +0000 | [diff] [blame] | 68 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 69 | aaudio_result_t resolve(EndpointDescriptor *descriptor); |
jiabin | f7f0615 | 2021-11-22 18:10:14 +0000 | [diff] [blame] | 70 | aaudio_result_t resolveDataQueue(RingBufferDescriptor *descriptor); |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 71 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 72 | aaudio_result_t close(); |
| 73 | |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 74 | void dump(); |
| 75 | |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 76 | // Extract a parcelable representation of this object. |
| 77 | // Since our shared memory objects own a unique FD, move semantics are provided to avoid the |
| 78 | // need to dupe. |
| 79 | Endpoint parcelable()&&; |
| 80 | |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 81 | public: // TODO add getters |
| 82 | // Set capacityInFrames to zero if Queue is unused. |
| 83 | RingBufferParcelable mUpMessageQueueParcelable; // server to client |
| 84 | RingBufferParcelable mDownMessageQueueParcelable; // to server |
| 85 | RingBufferParcelable mUpDataQueueParcelable; // eg. record, could share same queue |
| 86 | RingBufferParcelable mDownDataQueueParcelable; // eg. playback |
| 87 | |
| 88 | private: |
jiabin | fc791ee | 2023-02-15 19:43:40 +0000 | [diff] [blame^] | 89 | // Return the first available shared memory position. Return -1 if all shared memories are |
| 90 | // in use. |
| 91 | int32_t getNextAvailableSharedMemoryPosition() const; |
Phil Burk | a5891f4 | 2018-03-12 17:21:11 -0700 | [diff] [blame] | 92 | |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 93 | SharedMemoryParcelable mSharedMemories[MAX_SHARED_MEMORIES]; |
| 94 | }; |
| 95 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 96 | } /* namespace aaudio */ |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 97 | |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 98 | #endif //ANDROID_BINDING_AUDIO_ENDPOINT_PARCELABLE_H |