shubang | d49681e | 2020-02-17 21:32:30 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | namespace android { |
| 26 | |
| 27 | struct JMediaCodecLinearBlock { |
Wonsik Kim | 8569a66 | 2022-05-24 14:16:44 -0700 | [diff] [blame] | 28 | std::vector<std::string> mCodecNames; |
| 29 | |
shubang | d49681e | 2020-02-17 21:32:30 -0800 | [diff] [blame] | 30 | std::shared_ptr<C2Buffer> mBuffer; |
| 31 | std::shared_ptr<C2ReadView> mReadonlyMapping; |
| 32 | |
| 33 | std::shared_ptr<C2LinearBlock> mBlock; |
| 34 | std::shared_ptr<C2WriteView> mReadWriteMapping; |
| 35 | |
Wonsik Kim | f7069ce | 2020-05-13 17:15:47 -0700 | [diff] [blame] | 36 | sp<IMemory> mMemory; |
| 37 | sp<hardware::HidlMemory> mHidlMemory; |
| 38 | ssize_t mHidlMemoryOffset; |
| 39 | size_t mHidlMemorySize; |
shubang | d49681e | 2020-02-17 21:32:30 -0800 | [diff] [blame] | 40 | |
| 41 | sp<MediaCodecBuffer> mLegacyBuffer; |
| 42 | |
| 43 | std::once_flag mCopyWarningFlag; |
| 44 | |
Wonsik Kim | 8569a66 | 2022-05-24 14:16:44 -0700 | [diff] [blame] | 45 | std::shared_ptr<C2Buffer> toC2Buffer(size_t offset, size_t size) const { |
shubang | d49681e | 2020-02-17 21:32:30 -0800 | [diff] [blame] | 46 | if (mBuffer) { |
| 47 | if (mBuffer->data().type() != C2BufferData::LINEAR) { |
| 48 | return nullptr; |
| 49 | } |
| 50 | C2ConstLinearBlock block = mBuffer->data().linearBlocks().front(); |
| 51 | if (offset == 0 && size == block.capacity()) { |
| 52 | return mBuffer; |
| 53 | } |
Ray Lee | 73b682f6 | 2020-12-04 09:08:07 +0000 | [diff] [blame] | 54 | |
| 55 | std::shared_ptr<C2Buffer> buffer = |
| 56 | C2Buffer::CreateLinearBuffer(block.subBlock(offset, size)); |
| 57 | for (const std::shared_ptr<const C2Info> &info : mBuffer->info()) { |
| 58 | std::shared_ptr<C2Param> param = std::move(C2Param::Copy(*info)); |
| 59 | buffer->setInfo(std::static_pointer_cast<C2Info>(param)); |
| 60 | } |
| 61 | return buffer; |
shubang | d49681e | 2020-02-17 21:32:30 -0800 | [diff] [blame] | 62 | } |
| 63 | if (mBlock) { |
| 64 | return C2Buffer::CreateLinearBuffer(mBlock->share(offset, size, C2Fence{})); |
| 65 | } |
| 66 | return nullptr; |
| 67 | } |
| 68 | |
Wonsik Kim | 8569a66 | 2022-05-24 14:16:44 -0700 | [diff] [blame] | 69 | sp<hardware::HidlMemory> toHidlMemory() const { |
Wonsik Kim | f7069ce | 2020-05-13 17:15:47 -0700 | [diff] [blame] | 70 | if (mHidlMemory) { |
| 71 | return mHidlMemory; |
shubang | d49681e | 2020-02-17 21:32:30 -0800 | [diff] [blame] | 72 | } |
| 73 | return nullptr; |
| 74 | } |
Wonsik Kim | 8569a66 | 2022-05-24 14:16:44 -0700 | [diff] [blame] | 75 | |
| 76 | size_t capacity() const { |
| 77 | if (mBlock) { |
| 78 | return mBlock->capacity(); |
| 79 | } |
| 80 | if (mMemory) { |
| 81 | return mMemory->size(); |
| 82 | } |
| 83 | return 0; |
| 84 | } |
shubang | d49681e | 2020-02-17 21:32:30 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } // namespace android |
| 88 | |
Wonsik Kim | f7069ce | 2020-05-13 17:15:47 -0700 | [diff] [blame] | 89 | #endif // _ANDROID_MEDIA_MEDIACODECLINEARBLOCK_H_ |