blob: c0e1d8353025f69f4c405a4e6eba4ba32d51c5e7 [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
31 static bool isValid(const C2Handle * const o);
32
33 int bufferFd() const { return mFds.mBuffer; }
34 size_t size() const {
35 return size_t(unsigned(mInts.mSizeLo))
36 | size_t(uint64_t(unsigned(mInts.mSizeHi)) << 32);
37 }
38
39protected:
40 struct {
41 int mBuffer; // shared ion buffer
42 } mFds;
43 struct {
44 int mSizeLo; // low 32-bits of size
45 int mSizeHi; // high 32-bits of size
46 int mMagic;
47 } mInts;
48
49private:
50 typedef C2HandleIon _type;
51 enum {
52 kMagic = '\xc2io\x00',
53 numFds = sizeof(mFds) / sizeof(int),
54 numInts = sizeof(mInts) / sizeof(int),
55 version = sizeof(C2Handle)
56 };
57 //constexpr static C2Handle cHeader = { version, numFds, numInts, {} };
58 const static C2Handle cHeader;
59};
60} // namespace android
61
62#endif // STAGEFRIGHT_CODEC2_ALLOCATION_ION_H_