blob: 5237a1ab646c5b9a2d6b6fc3e7163ebad14feaf9 [file] [log] [blame]
Phil Burk828bea52017-01-03 17:22:09 -08001/*
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 Burk5204d312017-05-04 17:16:13 -070017#ifndef ANDROID_BINDING_AUDIO_ENDPOINT_PARCELABLE_H
18#define ANDROID_BINDING_AUDIO_ENDPOINT_PARCELABLE_H
Phil Burk828bea52017-01-03 17:22:09 -080019
20#include <stdint.h>
21
22//#include <sys/mman.h>
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070023#include <aaudio/Endpoint.h>
Phil Burke72481c2017-08-08 13:20:45 -070024#include <android-base/unique_fd.h>
Phil Burk828bea52017-01-03 17:22:09 -080025
Phil Burk5ed503c2017-02-01 09:38:15 -080026#include "binding/AAudioServiceDefinitions.h"
Phil Burk828bea52017-01-03 17:22:09 -080027#include "binding/RingBufferParcelable.h"
28
29using android::status_t;
Phil Burk828bea52017-01-03 17:22:09 -080030
Phil Burk5ed503c2017-02-01 09:38:15 -080031namespace aaudio {
Phil Burk828bea52017-01-03 17:22:09 -080032
33/**
34 * Container for information about the message queues plus
Phil Burk5ed503c2017-02-01 09:38:15 -080035 * general stream information needed by AAudio clients.
Phil Burk828bea52017-01-03 17:22:09 -080036 * It contains no addresses, just sizes, offsets and file descriptors for
37 * shared memory that can be passed through Binder.
38 */
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070039class AudioEndpointParcelable {
Phil Burk828bea52017-01-03 17:22:09 -080040public:
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070041 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.
46 AudioEndpointParcelable(Endpoint&& parcelable);
47 AudioEndpointParcelable& operator=(Endpoint&& parcelable);
Phil Burk828bea52017-01-03 17:22:09 -080048
49 /**
50 * Add the file descriptor to the table.
51 * @return index in table or negative error
52 */
Phil Burke72481c2017-08-08 13:20:45 -070053 int32_t addFileDescriptor(const android::base::unique_fd& fd, int32_t sizeInBytes);
Phil Burk828bea52017-01-03 17:22:09 -080054
Phil Burk5ed503c2017-02-01 09:38:15 -080055 aaudio_result_t resolve(EndpointDescriptor *descriptor);
Phil Burk828bea52017-01-03 17:22:09 -080056
Phil Burkc0c70e32017-02-09 13:18:38 -080057 aaudio_result_t close();
58
Phil Burk828bea52017-01-03 17:22:09 -080059 void dump();
60
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070061 // Extract a parcelable representation of this object.
62 // Since our shared memory objects own a unique FD, move semantics are provided to avoid the
63 // need to dupe.
64 Endpoint parcelable()&&;
65
Phil Burk828bea52017-01-03 17:22:09 -080066public: // TODO add getters
67 // Set capacityInFrames to zero if Queue is unused.
68 RingBufferParcelable mUpMessageQueueParcelable; // server to client
69 RingBufferParcelable mDownMessageQueueParcelable; // to server
70 RingBufferParcelable mUpDataQueueParcelable; // eg. record, could share same queue
71 RingBufferParcelable mDownDataQueueParcelable; // eg. playback
72
73private:
Phil Burka5891f42018-03-12 17:21:11 -070074 aaudio_result_t validate() const;
75
Phil Burk828bea52017-01-03 17:22:09 -080076 int32_t mNumSharedMemories = 0;
77 SharedMemoryParcelable mSharedMemories[MAX_SHARED_MEMORIES];
78};
79
Phil Burk5ed503c2017-02-01 09:38:15 -080080} /* namespace aaudio */
Phil Burk828bea52017-01-03 17:22:09 -080081
Phil Burk5204d312017-05-04 17:16:13 -070082#endif //ANDROID_BINDING_AUDIO_ENDPOINT_PARCELABLE_H