Home | History | Annotate | Download | only in binding
      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 <android-base/unique_fd.h>
     24 #include <binder/Parcel.h>
     25 #include <binder/Parcelable.h>
     26 
     27 #include "binding/AAudioServiceDefinitions.h"
     28 #include "binding/RingBufferParcelable.h"
     29 
     30 using android::status_t;
     31 using android::Parcel;
     32 using android::Parcelable;
     33 
     34 namespace aaudio {
     35 
     36 /**
     37  * Container for information about the message queues plus
     38  * general stream information needed by AAudio clients.
     39  * It contains no addresses, just sizes, offsets and file descriptors for
     40  * shared memory that can be passed through Binder.
     41  */
     42 class AudioEndpointParcelable : public Parcelable {
     43 public:
     44     AudioEndpointParcelable();
     45     virtual ~AudioEndpointParcelable();
     46 
     47     /**
     48      * Add the file descriptor to the table.
     49      * @return index in table or negative error
     50      */
     51     int32_t addFileDescriptor(const android::base::unique_fd& fd, int32_t sizeInBytes);
     52 
     53     virtual status_t writeToParcel(Parcel* parcel) const override;
     54 
     55     virtual status_t readFromParcel(const Parcel* parcel) override;
     56 
     57     aaudio_result_t resolve(EndpointDescriptor *descriptor);
     58 
     59     aaudio_result_t close();
     60 
     61     void dump();
     62 
     63 public: // TODO add getters
     64     // Set capacityInFrames to zero if Queue is unused.
     65     RingBufferParcelable    mUpMessageQueueParcelable;   // server to client
     66     RingBufferParcelable    mDownMessageQueueParcelable; // to server
     67     RingBufferParcelable    mUpDataQueueParcelable;      // eg. record, could share same queue
     68     RingBufferParcelable    mDownDataQueueParcelable;    // eg. playback
     69 
     70 private:
     71     aaudio_result_t         validate() const;
     72 
     73     int32_t                 mNumSharedMemories = 0;
     74     SharedMemoryParcelable  mSharedMemories[MAX_SHARED_MEMORIES];
     75 };
     76 
     77 } /* namespace aaudio */
     78 
     79 #endif //ANDROID_BINDING_AUDIO_ENDPOINT_PARCELABLE_H
     80