• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef ANDROID_BINDING_AUDIO_ENDPOINT_PARCELABLE_H
18 #define ANDROID_BINDING_AUDIO_ENDPOINT_PARCELABLE_H
19 
20 #include <stdint.h>
21 
22 //#include <sys/mman.h>
23 #include <aaudio/Endpoint.h>
24 #include <android-base/unique_fd.h>
25 
26 #include "binding/AAudioServiceDefinitions.h"
27 #include "binding/RingBufferParcelable.h"
28 
29 using android::status_t;
30 
31 namespace aaudio {
32 
33 /**
34  * Container for information about the message queues plus
35  * general stream information needed by AAudio clients.
36  * It contains no addresses, just sizes, offsets and file descriptors for
37  * shared memory that can be passed through Binder.
38  */
39 class AudioEndpointParcelable {
40 public:
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.
46     explicit AudioEndpointParcelable(Endpoint&& parcelable);
47     AudioEndpointParcelable& operator=(Endpoint&& parcelable);
48 
49     /**
50      * Add the file descriptor to the table.
51      * @return index in table or negative error
52      */
53     int32_t addFileDescriptor(const android::base::unique_fd& fd, int32_t sizeInBytes);
54 
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
64      */
65     void updateDataFileDescriptor(AudioEndpointParcelable* endpointParcelable);
66 
67     aaudio_result_t resolve(EndpointDescriptor *descriptor);
68     aaudio_result_t resolveDataQueue(RingBufferDescriptor *descriptor);
69 
70     aaudio_result_t close();
71 
72     void dump();
73 
74     // Extract a parcelable representation of this object.
75     // Since our shared memory objects own a unique FD, move semantics are provided to avoid the
76     // need to dupe.
77     Endpoint parcelable()&&;
78 
79 public: // TODO add getters
80     // Set capacityInFrames to zero if Queue is unused.
81     RingBufferParcelable    mUpMessageQueueParcelable;   // server to client
82     RingBufferParcelable    mDownMessageQueueParcelable; // to server
83     RingBufferParcelable    mUpDataQueueParcelable;      // eg. record, could share same queue
84     RingBufferParcelable    mDownDataQueueParcelable;    // eg. playback
85 
86 private:
87     aaudio_result_t         validate() const;
88 
89     int32_t                 mNumSharedMemories = 0;
90     SharedMemoryParcelable  mSharedMemories[MAX_SHARED_MEMORIES];
91 };
92 
93 } /* namespace aaudio */
94 
95 #endif //ANDROID_BINDING_AUDIO_ENDPOINT_PARCELABLE_H
96