blob: f529301fe98ae3a45ce65d50594592fc9360d190 [file] [log] [blame]
Chong Zhang6d332d22016-09-07 12:06:50 -07001/*
2 * Copyright (C) 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 _OMX_FENCE_PARCELABLE_
18#define _OMX_FENCE_PARCELABLE_
19
20#include <binder/Parcel.h>
21
22namespace android {
23
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080024struct OMXFenceParcelable;
25
26// This is needed temporarily for the OMX HIDL transition.
27namespace hardware {
28 struct hidl_handle;
29namespace media { namespace omx { namespace V1_0 { namespace implementation {
30 void wrapAs(::android::OMXFenceParcelable* l,
31 ::android::hardware::hidl_handle const& t);
32 bool convertTo(::android::OMXFenceParcelable* l,
33 ::android::hardware::hidl_handle const& t);
34}}}}}
35
Chong Zhang6d332d22016-09-07 12:06:50 -070036struct OMXFenceParcelable : public Parcelable {
37 OMXFenceParcelable() : mFenceFd(-1) {}
38 OMXFenceParcelable(int fenceFd) : mFenceFd(fenceFd) {}
39
40 int get() const { return mFenceFd; }
41
42 status_t readFromParcel(const Parcel* parcel) override;
43 status_t writeToParcel(Parcel* parcel) const override;
44
45private:
46 // Disable copy ctor and operator=
47 OMXFenceParcelable(const OMXFenceParcelable &);
48 OMXFenceParcelable &operator=(const OMXFenceParcelable &);
49
50 int mFenceFd;
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080051
52 // This is needed temporarily for OMX HIDL transition.
53 friend void (::android::hardware::media::omx::V1_0::implementation::
54 wrapAs)(OMXFenceParcelable* l,
55 ::android::hardware::hidl_handle const& t);
56 friend bool (::android::hardware::media::omx::V1_0::implementation::
57 convertTo)(OMXFenceParcelable* l,
58 ::android::hardware::hidl_handle const& t);
Chong Zhang6d332d22016-09-07 12:06:50 -070059};
60
61inline status_t OMXFenceParcelable::readFromParcel(const Parcel* parcel) {
62 int32_t haveFence;
63 status_t err = parcel->readInt32(&haveFence);
64 if (err == OK && haveFence) {
65 int fd = ::dup(parcel->readFileDescriptor());
66 if (fd < 0) {
67 return fd;
68 }
69 mFenceFd = fd;
70 }
71 return err;
72}
73
74inline status_t OMXFenceParcelable::writeToParcel(Parcel* parcel) const {
75 status_t err = parcel->writeInt32(mFenceFd >= 0);
76 if (err == OK && mFenceFd >= 0) {
77 err = parcel->writeFileDescriptor(mFenceFd, true /* takeOwnership */);
78 }
79 return err;
80}
81
82} // namespace android
83
84#endif // _OMX_FENCE_PARCELABLE_