blob: 8f1d2fa35d705223437164ce1214f215f01d51e3 [file] [log] [blame]
shubangd49681e2020-02-17 21:32:30 -08001/*
2 * Copyright 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 _ANDROID_MEDIA_MEDIACODECLINEARBLOCK_H_
18#define _ANDROID_MEDIA_MEDIACODECLINEARBLOCK_H_
19
20#include <C2Buffer.h>
21#include <binder/MemoryHeapBase.h>
22#include <hidl/HidlSupport.h>
23#include <media/MediaCodecBuffer.h>
24
25namespace android {
26
27struct JMediaCodecLinearBlock {
28 std::shared_ptr<C2Buffer> mBuffer;
29 std::shared_ptr<C2ReadView> mReadonlyMapping;
30
31 std::shared_ptr<C2LinearBlock> mBlock;
32 std::shared_ptr<C2WriteView> mReadWriteMapping;
33
Wonsik Kimf7069ce2020-05-13 17:15:47 -070034 sp<IMemory> mMemory;
35 sp<hardware::HidlMemory> mHidlMemory;
36 ssize_t mHidlMemoryOffset;
37 size_t mHidlMemorySize;
shubangd49681e2020-02-17 21:32:30 -080038
39 sp<MediaCodecBuffer> mLegacyBuffer;
40
41 std::once_flag mCopyWarningFlag;
42
43 std::shared_ptr<C2Buffer> toC2Buffer(size_t offset, size_t size) {
44 if (mBuffer) {
45 if (mBuffer->data().type() != C2BufferData::LINEAR) {
46 return nullptr;
47 }
48 C2ConstLinearBlock block = mBuffer->data().linearBlocks().front();
49 if (offset == 0 && size == block.capacity()) {
50 return mBuffer;
51 }
52 return C2Buffer::CreateLinearBuffer(block.subBlock(offset, size));
53 }
54 if (mBlock) {
55 return C2Buffer::CreateLinearBuffer(mBlock->share(offset, size, C2Fence{}));
56 }
57 return nullptr;
58 }
59
60 sp<hardware::HidlMemory> toHidlMemory() {
Wonsik Kimf7069ce2020-05-13 17:15:47 -070061 if (mHidlMemory) {
62 return mHidlMemory;
shubangd49681e2020-02-17 21:32:30 -080063 }
64 return nullptr;
65 }
66};
67
68} // namespace android
69
Wonsik Kimf7069ce2020-05-13 17:15:47 -070070#endif // _ANDROID_MEDIA_MEDIACODECLINEARBLOCK_H_