Loading media/omx/1.0/vts/functional/common/Android.bp +20 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,21 @@ cc_library_static { "android.hidl.memory@1.0", "android.hardware.media.omx@1.0", "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.allocator@3.0", "android.hardware.graphics.common@1.0", "android.hardware.graphics.common@1.1", "android.hardware.graphics.common@1.2", "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@3.0", ], export_static_lib_headers: [ "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.allocator@3.0", "android.hardware.graphics.common@1.0", "android.hardware.graphics.common@1.1", "android.hardware.graphics.common@1.2", "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@3.0", ], } Loading @@ -40,7 +55,12 @@ cc_defaults { static_libs: [ "VtsHalMediaOmxV1_0CommonUtil", "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.allocator@3.0", "android.hardware.graphics.common@1.0", "android.hardware.graphics.common@1.1", "android.hardware.graphics.common@1.2", "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@3.0", "android.hardware.graphics.bufferqueue@1.0", "android.hardware.graphics.common@1.0", "android.hardware.media.omx@1.0", Loading media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp +98 −56 Original line number Diff line number Diff line Loading @@ -22,8 +22,11 @@ #include <android-base/logging.h> #include <android/hardware/graphics/allocator/2.0/IAllocator.h> #include <android/hardware/graphics/allocator/3.0/IAllocator.h> #include <android/hardware/graphics/mapper/2.0/IMapper.h> #include <android/hardware/graphics/mapper/2.0/types.h> #include <android/hardware/graphics/mapper/3.0/IMapper.h> #include <android/hardware/graphics/mapper/3.0/types.h> #include <android/hardware/media/omx/1.0/IOmx.h> #include <android/hardware/media/omx/1.0/IOmxNode.h> #include <android/hardware/media/omx/1.0/IOmxObserver.h> Loading @@ -31,7 +34,9 @@ #include <android/hidl/allocator/1.0/IAllocator.h> #include <android/hidl/memory/1.0/IMapper.h> #include <android/hidl/memory/1.0/IMemory.h> #include <cutils/atomic.h> #include <atomic> #include <variant> using ::android::hardware::graphics::common::V1_0::BufferUsage; using ::android::hardware::graphics::common::V1_0::PixelFormat; Loading Loading @@ -195,67 +200,104 @@ void allocateGraphicBuffers(sp<IOmxNode> omxNode, OMX_U32 portIndex, BufferInfo* buffer, uint32_t nFrameWidth, uint32_t nFrameHeight, int32_t* nStride, int format) { android::hardware::media::omx::V1_0::Status status; sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator = struct AllocatorV2 : public GrallocV2 { sp<IAllocator> mAllocator; sp<IMapper> mMapper; AllocatorV2(sp<IAllocator>&& allocator, sp<IMapper>&& mapper) : mAllocator{std::move(allocator)}, mMapper{std::move(mapper)} {} AllocatorV2() = default; }; struct AllocatorV3 : public GrallocV3 { sp<IAllocator> mAllocator; sp<IMapper> mMapper; AllocatorV3(sp<IAllocator>&& allocator, sp<IMapper>&& mapper) : mAllocator{std::move(allocator)}, mMapper{std::move(mapper)} {} AllocatorV3() = default; }; std::variant<AllocatorV2, AllocatorV3> grallocVar; sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper2{}; sp<android::hardware::graphics::mapper::V3_0::IMapper> mapper3{}; sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator2{}; sp<android::hardware::graphics::allocator::V3_0::IAllocator> allocator3 = android::hardware::graphics::allocator::V3_0::IAllocator::getService(); if (allocator3) { mapper3 = android::hardware::graphics::mapper::V3_0::IMapper::getService(); ASSERT_NE(nullptr, mapper3.get()); grallocVar.emplace<AllocatorV3>(std::move(allocator3), std::move(mapper3)); } else { allocator2 = android::hardware::graphics::allocator::V2_0::IAllocator::getService(); ASSERT_NE(nullptr, allocator.get()); sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper = ASSERT_NE(nullptr, allocator2.get()); mapper2 = android::hardware::graphics::mapper::V2_0::IMapper::getService(); ASSERT_NE(mapper.get(), nullptr); android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo descriptorInfo; uint32_t usage; ASSERT_NE(nullptr, allocator2.get()); grallocVar.emplace<AllocatorV2>(std::move(allocator2), std::move(mapper2)); } descriptorInfo.width = nFrameWidth; descriptorInfo.height = nFrameHeight; descriptorInfo.layerCount = 1; descriptorInfo.format = static_cast<PixelFormat>(format); descriptorInfo.usage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN); omxNode->getGraphicBufferUsage( android::hardware::media::omx::V1_0::Status status{}; uint64_t usage{}; ASSERT_TRUE(omxNode->getGraphicBufferUsage( portIndex, [&status, &usage](android::hardware::media::omx::V1_0::Status _s, uint32_t _n1) { status = _s; usage = _n1; }); if (status == android::hardware::media::omx::V1_0::Status::OK) { descriptorInfo.usage |= usage; } }).isOk()); ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); static std::atomic_int32_t bufferIdCounter{0}; std::visit([buffer, nFrameWidth, nFrameHeight, format, usage, nStride](auto&& gralloc) { using Gralloc = std::remove_reference_t<decltype(gralloc)>; using Descriptor = typename Gralloc::Descriptor; using DescriptorInfo = typename Gralloc::DescriptorInfo; using Error = typename Gralloc::Error; using Format = typename Gralloc::Format; using Usage = typename Gralloc::Usage; Error error{}; Descriptor descriptor{}; ::android::hardware::hidl_vec<uint32_t> descriptor; android::hardware::graphics::mapper::V2_0::Error error; mapper->createDescriptor( descriptorInfo, [&error, &descriptor]( android::hardware::graphics::mapper::V2_0::Error _s, ::android::hardware::hidl_vec<uint32_t> _n1) { DescriptorInfo descriptorInfo{}; descriptorInfo.width = nFrameWidth; descriptorInfo.height = nFrameHeight; descriptorInfo.layerCount = 1; descriptorInfo.format = static_cast<Format>(format); descriptorInfo.usage = usage | Usage(BufferUsage::CPU_READ_OFTEN); gralloc.mMapper->createDescriptor(descriptorInfo, [&error, &descriptor]( Error _s, const Descriptor& _n1) { error = _s; descriptor = _n1; }); ASSERT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); ASSERT_EQ(error, Error::NONE); static volatile int32_t nextId = 0; uint64_t id = static_cast<uint64_t>(getpid()) << 32; allocator->allocate( gralloc.mAllocator->allocate( descriptor, 1, [&](android::hardware::graphics::mapper::V2_0::Error _s, uint32_t _n1, [&](Error _s, uint32_t _n1, const ::android::hardware::hidl_vec< ::android::hardware::hidl_handle>& _n2) { ASSERT_EQ(android::hardware::graphics::mapper::V2_0::Error::NONE, _s); ASSERT_EQ(Error::NONE, _s); *nStride = _n1; buffer->omxBuffer.nativeHandle = _n2[0]; buffer->omxBuffer.attr.anwBuffer.width = nFrameWidth; buffer->omxBuffer.attr.anwBuffer.height = nFrameHeight; buffer->omxBuffer.attr.anwBuffer.stride = _n1; buffer->omxBuffer.attr.anwBuffer.format = descriptorInfo.format; buffer->omxBuffer.attr.anwBuffer.usage = descriptorInfo.usage; buffer->omxBuffer.attr.anwBuffer.format = static_cast<PixelFormat>(descriptorInfo.format); buffer->omxBuffer.attr.anwBuffer.usage = static_cast<uint32_t>(descriptorInfo.usage); buffer->omxBuffer.attr.anwBuffer.layerCount = descriptorInfo.layerCount; buffer->omxBuffer.attr.anwBuffer.id = id | static_cast<uint32_t>(android_atomic_inc(&nextId)); (static_cast<uint64_t>(getpid()) << 32) | bufferIdCounter.fetch_add(1, std::memory_order_relaxed); }); }, grallocVar); } // allocate buffers needed on a component port Loading media/omx/1.0/vts/functional/common/media_hidl_test_common.h +40 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,16 @@ #endif #include <getopt.h> #include <android/hardware/graphics/allocator/2.0/IAllocator.h> #include <android/hardware/graphics/allocator/3.0/IAllocator.h> #include <android/hardware/graphics/common/1.0/types.h> #include <android/hardware/graphics/common/1.1/types.h> #include <android/hardware/graphics/common/1.2/types.h> #include <android/hardware/graphics/mapper/2.0/IMapper.h> #include <android/hardware/graphics/mapper/2.0/types.h> #include <android/hardware/graphics/mapper/3.0/IMapper.h> #include <android/hardware/graphics/mapper/3.0/types.h> #include <media/stagefright/foundation/ALooper.h> #include <utils/Condition.h> #include <utils/List.h> Loading Loading @@ -288,6 +298,36 @@ Return<android::hardware::media::omx::V1_0::Status> setPortConfig( /* * common functions declarations */ struct GrallocV2 { using Format = android::hardware::graphics::common::V1_0::PixelFormat; using Usage = android::hardware::hidl_bitfield< android::hardware::graphics::common::V1_0::BufferUsage>; using IAllocator = android::hardware::graphics::allocator::V2_0::IAllocator; using IMapper = android::hardware::graphics::mapper::V2_0::IMapper; using Error = android::hardware::graphics::mapper::V2_0::Error; using Descriptor = android::hardware::graphics::mapper::V2_0::BufferDescriptor; using YCbCrLayout = android::hardware::graphics::mapper::V2_0::YCbCrLayout; using DescriptorInfo = IMapper::BufferDescriptorInfo; using Rect = IMapper::Rect; }; struct GrallocV3 { using Format = android::hardware::graphics::common::V1_2::PixelFormat; using Usage = android::hardware::hidl_bitfield< android::hardware::graphics::common::V1_2::BufferUsage>; using IAllocator = android::hardware::graphics::allocator::V3_0::IAllocator; using IMapper = android::hardware::graphics::mapper::V3_0::IMapper; using Error = android::hardware::graphics::mapper::V3_0::Error; using Descriptor = android::hardware::graphics::mapper::V3_0::BufferDescriptor; using YCbCrLayout = android::hardware::graphics::mapper::V3_0::YCbCrLayout; using DescriptorInfo = IMapper::BufferDescriptorInfo; using Rect = IMapper::Rect; }; Return<android::hardware::media::omx::V1_0::Status> setRole( sp<IOmxNode> omxNode, const char* role); Loading media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp +202 −130 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ using ::android::sp; #include <media_video_hidl_test_common.h> #include <system/window.h> #include <fstream> #include <variant> static ComponentTestEnvironment* gEnv = nullptr; Loading Loading @@ -364,6 +365,61 @@ Return<void> DummyBufferSource::onInputBufferEmptied( return Void(); }; // Variant of mappers struct MapperV2 : public GrallocV2 { sp<IMapper> mMapper; MapperV2(sp<IMapper>&& mapper): mMapper{std::move(mapper)} {} MapperV2() = default; android::hardware::Return<void> lock( void* buffer, Usage usage, const Rect& rect, const android::hardware::hidl_handle& handle, Error* error, void** data) { return mMapper->lock(buffer, usage, rect, handle, [error, data](Error e, void* d) { *error = e; *data = d; }); } }; struct MapperV3 : public GrallocV3 { sp<IMapper> mMapper; MapperV3(sp<IMapper>&& mapper): mMapper{std::move(mapper)} {} MapperV3() = default; android::hardware::Return<void> lock( void* buffer, Usage usage, const Rect& rect, const android::hardware::hidl_handle& handle, Error* error, void** data) { return mMapper->lock(buffer, usage, rect, handle, [error, data](Error e, void* d, int32_t, int32_t) { *error = e; *data = d; }); } }; using MapperVar = std::variant<MapperV2, MapperV3>; // Initializes the MapperVar by trying services of different versions. bool initialize(MapperVar& mapperVar) { sp<android::hardware::graphics::mapper::V3_0::IMapper> mapper3 = android::hardware::graphics::mapper::V3_0::IMapper::getService(); if (mapper3) { mapperVar.emplace<MapperV3>(std::move(mapper3)); return true; } sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper2 = android::hardware::graphics::mapper::V2_0::IMapper::getService(); if (mapper2) { mapperVar.emplace<MapperV2>(std::move(mapper2)); return true; } return false; } // request VOP refresh void requestIDR(sp<IOmxNode> omxNode, OMX_U32 portIndex) { android::hardware::media::omx::V1_0::Status status; Loading Loading @@ -574,15 +630,23 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer, int colorFormatConversion(BufferInfo* buffer, void* buff, PixelFormat format, std::ifstream& eleStream) { sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper = android::hardware::graphics::mapper::V2_0::IMapper::getService(); EXPECT_NE(mapper.get(), nullptr); if (mapper.get() == nullptr) return 1; MapperVar mapperVar; if (!initialize(mapperVar)) { EXPECT_TRUE(false) << "failed to obtain mapper service"; return 1; } return std::visit([buffer, buff, format, &eleStream](auto&& mapper) -> int { using Gralloc = std::remove_reference_t<decltype(mapper)>; using Error = typename Gralloc::Error; using Rect = typename Gralloc::Rect; using Usage = typename Gralloc::Usage; using YCbCrLayout = typename Gralloc::YCbCrLayout; android::hardware::hidl_handle fence; android::hardware::graphics::mapper::V2_0::IMapper::Rect rect; android::hardware::graphics::mapper::V2_0::YCbCrLayout ycbcrLayout; android::hardware::graphics::mapper::V2_0::Error error; Rect rect; YCbCrLayout ycbcrLayout; Error error; rect.left = 0; rect.top = 0; rect.width = buffer->omxBuffer.attr.anwBuffer.width; Loading @@ -590,16 +654,19 @@ int colorFormatConversion(BufferInfo* buffer, void* buff, PixelFormat format, if (format == PixelFormat::YV12 || format == PixelFormat::YCRCB_420_SP || format == PixelFormat::YCBCR_420_888) { mapper->lockYCbCr( buff, buffer->omxBuffer.attr.anwBuffer.usage, rect, fence, [&](android::hardware::graphics::mapper::V2_0::Error _e, android::hardware::graphics::mapper::V2_0::YCbCrLayout _n1) { mapper.mMapper->lockYCbCr( buff, static_cast<Usage>( buffer->omxBuffer.attr.anwBuffer.usage), rect, fence, [&](Error _e, const YCbCrLayout& _n1) { error = _e; ycbcrLayout = _n1; }); EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) EXPECT_EQ(error, Error::NONE); if (error != Error::NONE) return 1; int size = ((rect.width * rect.height * 3) >> 1); Loading Loading @@ -641,27 +708,26 @@ int colorFormatConversion(BufferInfo* buffer, void* buff, PixelFormat format, delete[] img; mapper->unlock(buff, [&](android::hardware::graphics::mapper::V2_0::Error _e, android::hardware::hidl_handle _n1) { mapper.mMapper->unlock(buff, [&](Error _e, const android::hardware::hidl_handle& _n1) { error = _e; fence = _n1; }); EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) EXPECT_EQ(error, Error::NONE); if (error != Error::NONE) return 1; } else { void* data; mapper->lock(buff, buffer->omxBuffer.attr.anwBuffer.usage, rect, fence, [&](android::hardware::graphics::mapper::V2_0::Error _e, void* _n1) { error = _e; data = _n1; }); EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) mapper.lock( buff, buffer->omxBuffer.attr.anwBuffer.usage, rect, fence, &error, &data); EXPECT_EQ(error, Error::NONE); if (error != Error::NONE) return 1; if (format == PixelFormat::BGRA_8888) { Loading @@ -676,48 +742,54 @@ int colorFormatConversion(BufferInfo* buffer, void* buff, PixelFormat format, return 1; } mapper->unlock(buff, [&](android::hardware::graphics::mapper::V2_0::Error _e, android::hardware::hidl_handle _n1) { mapper.mMapper->unlock( buff, [&](Error _e, const android::hardware::hidl_handle& _n1) { error = _e; fence = _n1; }); EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) EXPECT_EQ(error, Error::NONE); if (error != Error::NONE) return 1; } return 0; }, mapperVar); } int fillGraphicBuffer(BufferInfo* buffer, PixelFormat format, std::ifstream& eleStream) { sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper = android::hardware::graphics::mapper::V2_0::IMapper::getService(); EXPECT_NE(mapper.get(), nullptr); if (mapper.get() == nullptr) return 1; MapperVar mapperVar; if (!initialize(mapperVar)) { EXPECT_TRUE(false) << "failed to obtain mapper service"; return 1; } return std::visit([buffer, format, &eleStream](auto&& mapper) -> int { using Gralloc = std::remove_reference_t<decltype(mapper)>; using Error = typename Gralloc::Error; void* buff = nullptr; android::hardware::graphics::mapper::V2_0::Error error; mapper->importBuffer( Error error; mapper.mMapper->importBuffer( buffer->omxBuffer.nativeHandle, [&](android::hardware::graphics::mapper::V2_0::Error _e, void* _n1) { [&](Error _e, void* _n1) { error = _e; buff = _n1; }); EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) EXPECT_EQ(error, Error::NONE); if (error != Error::NONE) return 1; if (colorFormatConversion(buffer, buff, format, eleStream)) return 1; error = mapper->freeBuffer(buff); EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) error = mapper.mMapper->freeBuffer(buff); EXPECT_EQ(error, Error::NONE); if (error != Error::NONE) return 1; return 0; }, mapperVar); } int dispatchGraphicBuffer(sp<IOmxNode> omxNode, Loading Loading
media/omx/1.0/vts/functional/common/Android.bp +20 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,21 @@ cc_library_static { "android.hidl.memory@1.0", "android.hardware.media.omx@1.0", "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.allocator@3.0", "android.hardware.graphics.common@1.0", "android.hardware.graphics.common@1.1", "android.hardware.graphics.common@1.2", "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@3.0", ], export_static_lib_headers: [ "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.allocator@3.0", "android.hardware.graphics.common@1.0", "android.hardware.graphics.common@1.1", "android.hardware.graphics.common@1.2", "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@3.0", ], } Loading @@ -40,7 +55,12 @@ cc_defaults { static_libs: [ "VtsHalMediaOmxV1_0CommonUtil", "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.allocator@3.0", "android.hardware.graphics.common@1.0", "android.hardware.graphics.common@1.1", "android.hardware.graphics.common@1.2", "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@3.0", "android.hardware.graphics.bufferqueue@1.0", "android.hardware.graphics.common@1.0", "android.hardware.media.omx@1.0", Loading
media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp +98 −56 Original line number Diff line number Diff line Loading @@ -22,8 +22,11 @@ #include <android-base/logging.h> #include <android/hardware/graphics/allocator/2.0/IAllocator.h> #include <android/hardware/graphics/allocator/3.0/IAllocator.h> #include <android/hardware/graphics/mapper/2.0/IMapper.h> #include <android/hardware/graphics/mapper/2.0/types.h> #include <android/hardware/graphics/mapper/3.0/IMapper.h> #include <android/hardware/graphics/mapper/3.0/types.h> #include <android/hardware/media/omx/1.0/IOmx.h> #include <android/hardware/media/omx/1.0/IOmxNode.h> #include <android/hardware/media/omx/1.0/IOmxObserver.h> Loading @@ -31,7 +34,9 @@ #include <android/hidl/allocator/1.0/IAllocator.h> #include <android/hidl/memory/1.0/IMapper.h> #include <android/hidl/memory/1.0/IMemory.h> #include <cutils/atomic.h> #include <atomic> #include <variant> using ::android::hardware::graphics::common::V1_0::BufferUsage; using ::android::hardware::graphics::common::V1_0::PixelFormat; Loading Loading @@ -195,67 +200,104 @@ void allocateGraphicBuffers(sp<IOmxNode> omxNode, OMX_U32 portIndex, BufferInfo* buffer, uint32_t nFrameWidth, uint32_t nFrameHeight, int32_t* nStride, int format) { android::hardware::media::omx::V1_0::Status status; sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator = struct AllocatorV2 : public GrallocV2 { sp<IAllocator> mAllocator; sp<IMapper> mMapper; AllocatorV2(sp<IAllocator>&& allocator, sp<IMapper>&& mapper) : mAllocator{std::move(allocator)}, mMapper{std::move(mapper)} {} AllocatorV2() = default; }; struct AllocatorV3 : public GrallocV3 { sp<IAllocator> mAllocator; sp<IMapper> mMapper; AllocatorV3(sp<IAllocator>&& allocator, sp<IMapper>&& mapper) : mAllocator{std::move(allocator)}, mMapper{std::move(mapper)} {} AllocatorV3() = default; }; std::variant<AllocatorV2, AllocatorV3> grallocVar; sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper2{}; sp<android::hardware::graphics::mapper::V3_0::IMapper> mapper3{}; sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator2{}; sp<android::hardware::graphics::allocator::V3_0::IAllocator> allocator3 = android::hardware::graphics::allocator::V3_0::IAllocator::getService(); if (allocator3) { mapper3 = android::hardware::graphics::mapper::V3_0::IMapper::getService(); ASSERT_NE(nullptr, mapper3.get()); grallocVar.emplace<AllocatorV3>(std::move(allocator3), std::move(mapper3)); } else { allocator2 = android::hardware::graphics::allocator::V2_0::IAllocator::getService(); ASSERT_NE(nullptr, allocator.get()); sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper = ASSERT_NE(nullptr, allocator2.get()); mapper2 = android::hardware::graphics::mapper::V2_0::IMapper::getService(); ASSERT_NE(mapper.get(), nullptr); android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo descriptorInfo; uint32_t usage; ASSERT_NE(nullptr, allocator2.get()); grallocVar.emplace<AllocatorV2>(std::move(allocator2), std::move(mapper2)); } descriptorInfo.width = nFrameWidth; descriptorInfo.height = nFrameHeight; descriptorInfo.layerCount = 1; descriptorInfo.format = static_cast<PixelFormat>(format); descriptorInfo.usage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN); omxNode->getGraphicBufferUsage( android::hardware::media::omx::V1_0::Status status{}; uint64_t usage{}; ASSERT_TRUE(omxNode->getGraphicBufferUsage( portIndex, [&status, &usage](android::hardware::media::omx::V1_0::Status _s, uint32_t _n1) { status = _s; usage = _n1; }); if (status == android::hardware::media::omx::V1_0::Status::OK) { descriptorInfo.usage |= usage; } }).isOk()); ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK); static std::atomic_int32_t bufferIdCounter{0}; std::visit([buffer, nFrameWidth, nFrameHeight, format, usage, nStride](auto&& gralloc) { using Gralloc = std::remove_reference_t<decltype(gralloc)>; using Descriptor = typename Gralloc::Descriptor; using DescriptorInfo = typename Gralloc::DescriptorInfo; using Error = typename Gralloc::Error; using Format = typename Gralloc::Format; using Usage = typename Gralloc::Usage; Error error{}; Descriptor descriptor{}; ::android::hardware::hidl_vec<uint32_t> descriptor; android::hardware::graphics::mapper::V2_0::Error error; mapper->createDescriptor( descriptorInfo, [&error, &descriptor]( android::hardware::graphics::mapper::V2_0::Error _s, ::android::hardware::hidl_vec<uint32_t> _n1) { DescriptorInfo descriptorInfo{}; descriptorInfo.width = nFrameWidth; descriptorInfo.height = nFrameHeight; descriptorInfo.layerCount = 1; descriptorInfo.format = static_cast<Format>(format); descriptorInfo.usage = usage | Usage(BufferUsage::CPU_READ_OFTEN); gralloc.mMapper->createDescriptor(descriptorInfo, [&error, &descriptor]( Error _s, const Descriptor& _n1) { error = _s; descriptor = _n1; }); ASSERT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); ASSERT_EQ(error, Error::NONE); static volatile int32_t nextId = 0; uint64_t id = static_cast<uint64_t>(getpid()) << 32; allocator->allocate( gralloc.mAllocator->allocate( descriptor, 1, [&](android::hardware::graphics::mapper::V2_0::Error _s, uint32_t _n1, [&](Error _s, uint32_t _n1, const ::android::hardware::hidl_vec< ::android::hardware::hidl_handle>& _n2) { ASSERT_EQ(android::hardware::graphics::mapper::V2_0::Error::NONE, _s); ASSERT_EQ(Error::NONE, _s); *nStride = _n1; buffer->omxBuffer.nativeHandle = _n2[0]; buffer->omxBuffer.attr.anwBuffer.width = nFrameWidth; buffer->omxBuffer.attr.anwBuffer.height = nFrameHeight; buffer->omxBuffer.attr.anwBuffer.stride = _n1; buffer->omxBuffer.attr.anwBuffer.format = descriptorInfo.format; buffer->omxBuffer.attr.anwBuffer.usage = descriptorInfo.usage; buffer->omxBuffer.attr.anwBuffer.format = static_cast<PixelFormat>(descriptorInfo.format); buffer->omxBuffer.attr.anwBuffer.usage = static_cast<uint32_t>(descriptorInfo.usage); buffer->omxBuffer.attr.anwBuffer.layerCount = descriptorInfo.layerCount; buffer->omxBuffer.attr.anwBuffer.id = id | static_cast<uint32_t>(android_atomic_inc(&nextId)); (static_cast<uint64_t>(getpid()) << 32) | bufferIdCounter.fetch_add(1, std::memory_order_relaxed); }); }, grallocVar); } // allocate buffers needed on a component port Loading
media/omx/1.0/vts/functional/common/media_hidl_test_common.h +40 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,16 @@ #endif #include <getopt.h> #include <android/hardware/graphics/allocator/2.0/IAllocator.h> #include <android/hardware/graphics/allocator/3.0/IAllocator.h> #include <android/hardware/graphics/common/1.0/types.h> #include <android/hardware/graphics/common/1.1/types.h> #include <android/hardware/graphics/common/1.2/types.h> #include <android/hardware/graphics/mapper/2.0/IMapper.h> #include <android/hardware/graphics/mapper/2.0/types.h> #include <android/hardware/graphics/mapper/3.0/IMapper.h> #include <android/hardware/graphics/mapper/3.0/types.h> #include <media/stagefright/foundation/ALooper.h> #include <utils/Condition.h> #include <utils/List.h> Loading Loading @@ -288,6 +298,36 @@ Return<android::hardware::media::omx::V1_0::Status> setPortConfig( /* * common functions declarations */ struct GrallocV2 { using Format = android::hardware::graphics::common::V1_0::PixelFormat; using Usage = android::hardware::hidl_bitfield< android::hardware::graphics::common::V1_0::BufferUsage>; using IAllocator = android::hardware::graphics::allocator::V2_0::IAllocator; using IMapper = android::hardware::graphics::mapper::V2_0::IMapper; using Error = android::hardware::graphics::mapper::V2_0::Error; using Descriptor = android::hardware::graphics::mapper::V2_0::BufferDescriptor; using YCbCrLayout = android::hardware::graphics::mapper::V2_0::YCbCrLayout; using DescriptorInfo = IMapper::BufferDescriptorInfo; using Rect = IMapper::Rect; }; struct GrallocV3 { using Format = android::hardware::graphics::common::V1_2::PixelFormat; using Usage = android::hardware::hidl_bitfield< android::hardware::graphics::common::V1_2::BufferUsage>; using IAllocator = android::hardware::graphics::allocator::V3_0::IAllocator; using IMapper = android::hardware::graphics::mapper::V3_0::IMapper; using Error = android::hardware::graphics::mapper::V3_0::Error; using Descriptor = android::hardware::graphics::mapper::V3_0::BufferDescriptor; using YCbCrLayout = android::hardware::graphics::mapper::V3_0::YCbCrLayout; using DescriptorInfo = IMapper::BufferDescriptorInfo; using Rect = IMapper::Rect; }; Return<android::hardware::media::omx::V1_0::Status> setRole( sp<IOmxNode> omxNode, const char* role); Loading
media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp +202 −130 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ using ::android::sp; #include <media_video_hidl_test_common.h> #include <system/window.h> #include <fstream> #include <variant> static ComponentTestEnvironment* gEnv = nullptr; Loading Loading @@ -364,6 +365,61 @@ Return<void> DummyBufferSource::onInputBufferEmptied( return Void(); }; // Variant of mappers struct MapperV2 : public GrallocV2 { sp<IMapper> mMapper; MapperV2(sp<IMapper>&& mapper): mMapper{std::move(mapper)} {} MapperV2() = default; android::hardware::Return<void> lock( void* buffer, Usage usage, const Rect& rect, const android::hardware::hidl_handle& handle, Error* error, void** data) { return mMapper->lock(buffer, usage, rect, handle, [error, data](Error e, void* d) { *error = e; *data = d; }); } }; struct MapperV3 : public GrallocV3 { sp<IMapper> mMapper; MapperV3(sp<IMapper>&& mapper): mMapper{std::move(mapper)} {} MapperV3() = default; android::hardware::Return<void> lock( void* buffer, Usage usage, const Rect& rect, const android::hardware::hidl_handle& handle, Error* error, void** data) { return mMapper->lock(buffer, usage, rect, handle, [error, data](Error e, void* d, int32_t, int32_t) { *error = e; *data = d; }); } }; using MapperVar = std::variant<MapperV2, MapperV3>; // Initializes the MapperVar by trying services of different versions. bool initialize(MapperVar& mapperVar) { sp<android::hardware::graphics::mapper::V3_0::IMapper> mapper3 = android::hardware::graphics::mapper::V3_0::IMapper::getService(); if (mapper3) { mapperVar.emplace<MapperV3>(std::move(mapper3)); return true; } sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper2 = android::hardware::graphics::mapper::V2_0::IMapper::getService(); if (mapper2) { mapperVar.emplace<MapperV2>(std::move(mapper2)); return true; } return false; } // request VOP refresh void requestIDR(sp<IOmxNode> omxNode, OMX_U32 portIndex) { android::hardware::media::omx::V1_0::Status status; Loading Loading @@ -574,15 +630,23 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer, int colorFormatConversion(BufferInfo* buffer, void* buff, PixelFormat format, std::ifstream& eleStream) { sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper = android::hardware::graphics::mapper::V2_0::IMapper::getService(); EXPECT_NE(mapper.get(), nullptr); if (mapper.get() == nullptr) return 1; MapperVar mapperVar; if (!initialize(mapperVar)) { EXPECT_TRUE(false) << "failed to obtain mapper service"; return 1; } return std::visit([buffer, buff, format, &eleStream](auto&& mapper) -> int { using Gralloc = std::remove_reference_t<decltype(mapper)>; using Error = typename Gralloc::Error; using Rect = typename Gralloc::Rect; using Usage = typename Gralloc::Usage; using YCbCrLayout = typename Gralloc::YCbCrLayout; android::hardware::hidl_handle fence; android::hardware::graphics::mapper::V2_0::IMapper::Rect rect; android::hardware::graphics::mapper::V2_0::YCbCrLayout ycbcrLayout; android::hardware::graphics::mapper::V2_0::Error error; Rect rect; YCbCrLayout ycbcrLayout; Error error; rect.left = 0; rect.top = 0; rect.width = buffer->omxBuffer.attr.anwBuffer.width; Loading @@ -590,16 +654,19 @@ int colorFormatConversion(BufferInfo* buffer, void* buff, PixelFormat format, if (format == PixelFormat::YV12 || format == PixelFormat::YCRCB_420_SP || format == PixelFormat::YCBCR_420_888) { mapper->lockYCbCr( buff, buffer->omxBuffer.attr.anwBuffer.usage, rect, fence, [&](android::hardware::graphics::mapper::V2_0::Error _e, android::hardware::graphics::mapper::V2_0::YCbCrLayout _n1) { mapper.mMapper->lockYCbCr( buff, static_cast<Usage>( buffer->omxBuffer.attr.anwBuffer.usage), rect, fence, [&](Error _e, const YCbCrLayout& _n1) { error = _e; ycbcrLayout = _n1; }); EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) EXPECT_EQ(error, Error::NONE); if (error != Error::NONE) return 1; int size = ((rect.width * rect.height * 3) >> 1); Loading Loading @@ -641,27 +708,26 @@ int colorFormatConversion(BufferInfo* buffer, void* buff, PixelFormat format, delete[] img; mapper->unlock(buff, [&](android::hardware::graphics::mapper::V2_0::Error _e, android::hardware::hidl_handle _n1) { mapper.mMapper->unlock(buff, [&](Error _e, const android::hardware::hidl_handle& _n1) { error = _e; fence = _n1; }); EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) EXPECT_EQ(error, Error::NONE); if (error != Error::NONE) return 1; } else { void* data; mapper->lock(buff, buffer->omxBuffer.attr.anwBuffer.usage, rect, fence, [&](android::hardware::graphics::mapper::V2_0::Error _e, void* _n1) { error = _e; data = _n1; }); EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) mapper.lock( buff, buffer->omxBuffer.attr.anwBuffer.usage, rect, fence, &error, &data); EXPECT_EQ(error, Error::NONE); if (error != Error::NONE) return 1; if (format == PixelFormat::BGRA_8888) { Loading @@ -676,48 +742,54 @@ int colorFormatConversion(BufferInfo* buffer, void* buff, PixelFormat format, return 1; } mapper->unlock(buff, [&](android::hardware::graphics::mapper::V2_0::Error _e, android::hardware::hidl_handle _n1) { mapper.mMapper->unlock( buff, [&](Error _e, const android::hardware::hidl_handle& _n1) { error = _e; fence = _n1; }); EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) EXPECT_EQ(error, Error::NONE); if (error != Error::NONE) return 1; } return 0; }, mapperVar); } int fillGraphicBuffer(BufferInfo* buffer, PixelFormat format, std::ifstream& eleStream) { sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper = android::hardware::graphics::mapper::V2_0::IMapper::getService(); EXPECT_NE(mapper.get(), nullptr); if (mapper.get() == nullptr) return 1; MapperVar mapperVar; if (!initialize(mapperVar)) { EXPECT_TRUE(false) << "failed to obtain mapper service"; return 1; } return std::visit([buffer, format, &eleStream](auto&& mapper) -> int { using Gralloc = std::remove_reference_t<decltype(mapper)>; using Error = typename Gralloc::Error; void* buff = nullptr; android::hardware::graphics::mapper::V2_0::Error error; mapper->importBuffer( Error error; mapper.mMapper->importBuffer( buffer->omxBuffer.nativeHandle, [&](android::hardware::graphics::mapper::V2_0::Error _e, void* _n1) { [&](Error _e, void* _n1) { error = _e; buff = _n1; }); EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) EXPECT_EQ(error, Error::NONE); if (error != Error::NONE) return 1; if (colorFormatConversion(buffer, buff, format, eleStream)) return 1; error = mapper->freeBuffer(buff); EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) error = mapper.mMapper->freeBuffer(buff); EXPECT_EQ(error, Error::NONE); if (error != Error::NONE) return 1; return 0; }, mapperVar); } int dispatchGraphicBuffer(sp<IOmxNode> omxNode, Loading