| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 { |
| 28 |
std::vector<std::string> mCodecNames; |
| 29 |
|
| 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 |
|
| 36 |
sp<IMemory> mMemory; |
| 37 |
sp<hardware::HidlMemory> mHidlMemory; |
| 38 |
ssize_t mHidlMemoryOffset; |
| 39 |
size_t mHidlMemorySize; |
| 40 |
|
| 41 |
sp<MediaCodecBuffer> mLegacyBuffer; |
| 42 |
|
| 43 |
std::once_flag mCopyWarningFlag; |
| 44 |
|
| 45 |
std::shared_ptr<C2Buffer> toC2Buffer(size_t offset, size_t size) const { |
| 46 |
if (mBuffer) { |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
if (mBuffer->data().type() != C2BufferData::LINEAR) { |
| 51 |
return nullptr; |
| 52 |
} |
| 53 |
C2ConstLinearBlock block = mBuffer->data().linearBlocks().front(); |
| 54 |
if (offset == 0 && size == block.capacity()) { |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
return std::make_shared<C2Buffer>(*mBuffer); |
| 60 |
} |
| 61 |
|
| 62 |
std::shared_ptr<C2Buffer> buffer = |
| 63 |
C2Buffer::CreateLinearBuffer(block.subBlock(offset, size)); |
| 64 |
for (const std::shared_ptr<const C2Info> &info : mBuffer->info()) { |
| 65 |
std::shared_ptr<C2Param> param = std::move(C2Param::Copy(*info)); |
| 66 |
buffer->setInfo(std::static_pointer_cast<C2Info>(param)); |
| 67 |
} |
| 68 |
return buffer; |
| 69 |
} |
| 70 |
if (mBlock) { |
| 71 |
return C2Buffer::CreateLinearBuffer(mBlock->share(offset, size, C2Fence{})); |
| 72 |
} |
| 73 |
return nullptr; |
| 74 |
} |
| 75 |
|
| 76 |
sp<hardware::HidlMemory> toHidlMemory() const { |
| 77 |
if (mHidlMemory) { |
| 78 |
return mHidlMemory; |
| 79 |
} |
| 80 |
return nullptr; |
| 81 |
} |
| 82 |
|
| 83 |
size_t capacity() const { |
| 84 |
if (mBlock) { |
| 85 |
return mBlock->capacity(); |
| 86 |
} |
| 87 |
if (mMemory) { |
| 88 |
return mMemory->size(); |
| 89 |
} |
| 90 |
return 0; |
| 91 |
} |
| 92 |
}; |
| 93 |
|
| 94 |
} |
| 95 |
|
| 96 |
#endif |