1 /* 2 * Copyright (C) 2020 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 STAGEFRIGHT_CODEC2_ALLOCATION_ION_H_ 18 #define STAGEFRIGHT_CODEC2_ALLOCATION_ION_H_ 19 20 #include <C2Buffer.h> 21 22 namespace android { 23 24 struct C2HandleIon : public C2Handle { 25 // ion handle owns ionFd(!) and bufferFd C2HandleIonC2HandleIon26 C2HandleIon(int bufferFd, size_t size) 27 : C2Handle(cHeader), 28 mFds{ bufferFd }, 29 mInts{ int(size & 0xFFFFFFFF), int((uint64_t(size) >> 32) & 0xFFFFFFFF), kMagic } { } 30 31 static bool IsValid(const C2Handle * const o); 32 33 // deprecated isValidC2HandleIon34 static bool isValid(const C2Handle * const o) { return IsValid(o); } 35 bufferFdC2HandleIon36 int bufferFd() const { return mFds.mBuffer; } sizeC2HandleIon37 size_t size() const { 38 return size_t(unsigned(mInts.mSizeLo)) 39 | size_t(uint64_t(unsigned(mInts.mSizeHi)) << 32); 40 } 41 42 protected: 43 struct { 44 int mBuffer; // shared ion buffer 45 } mFds; 46 struct { 47 int mSizeLo; // low 32-bits of size 48 int mSizeHi; // high 32-bits of size 49 int mMagic; 50 } mInts; 51 52 private: 53 typedef C2HandleIon _type; 54 enum { 55 kMagic = '\xc2io\x00', 56 numFds = sizeof(mFds) / sizeof(int), 57 numInts = sizeof(mInts) / sizeof(int), 58 version = sizeof(C2Handle) 59 }; 60 //constexpr static C2Handle cHeader = { version, numFds, numInts, {} }; 61 const static C2Handle cHeader; 62 }; 63 } // namespace android 64 65 #endif // STAGEFRIGHT_CODEC2_ALLOCATION_ION_H_ 66