blob: c67698c480056d2430c4c69ad9ac320851a7c981 [file] [log] [blame]
shubang69397a92020-02-17 23:13:35 -08001/*
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
22namespace android {
23
24struct C2HandleIon : public C2Handle {
25 // ion handle owns ionFd(!) and bufferFd
26 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
John Stultz653ddd12020-09-19 05:26:24 +000031 static bool IsValid(const C2Handle * const o);
32
33 // deprecated
34 static bool isValid(const C2Handle * const o) { return IsValid(o); }
shubang69397a92020-02-17 23:13:35 -080035
36 int bufferFd() const { return mFds.mBuffer; }
37 size_t size() const {
38 return size_t(unsigned(mInts.mSizeLo))
39 | size_t(uint64_t(unsigned(mInts.mSizeHi)) << 32);
40 }
41
42protected:
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
52private:
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_