summaryrefslogtreecommitdiff
path: root/test/libtest
AgeCommit message (Expand)Author
2020-12-09libcamera: v4l2_device: Return a unique pointer from fromEntityName()Laurent Pinchart
2020-09-21test: Include specific headers instead of libcamera.hLaurent Pinchart
2020-08-25meson: Remove -Wno-unused-parameterLaurent Pinchart
2020-05-16libcamera: Move internal headers to include/libcamera/internal/Laurent Pinchart
2020-05-13licenses: License all meson files under CC0-1.0Laurent Pinchart
2020-04-30libcamera: v4l2_pixelformat: Move DRM/V4L2 format conversionLaurent Pinchart
2020-03-19libcamera: v4l2_videodevice: Rename toV4L2Fourcc to toV4L2PixelFormatLaurent Pinchart
2020-03-18libcamera: v4l2_videodevice: Rename exportBuffers() to allocateBuffers()Laurent Pinchart
2020-03-18test: libtest: buffer_source: Close video device right after allocationLaurent Pinchart
2020-03-18tests: remove IPA_PROXY_PATH environment variableKaaira Gupta
2020-03-06test: Extract BufferSource class out of camera tests to libtestNiklas Söderlund
2020-02-24tests: Remove IPA_MODULE_PATH environment variableKieran Bingham
2019-11-20test: Extract CameraTest class out of camera tests to libtestLaurent Pinchart
2019-11-18libcamera: Remove space between empty curly bracketsLaurent Pinchart
2019-07-12libcamera: add IPA proxyPaul Elder
2019-06-05libcamera: ipa_manager: implement class for managing IPA modulesPaul Elder
2019-05-23meson: Create and use a dependency for libcamera and its headersLaurent Pinchart
2019-01-02test: Move include definitions to libtestKieran Bingham
2019-01-01test: libtest: Return all non-zero init valuesKieran Bingham
2019-01-01test: libtest: Add test return codesKieran Bingham
2019-01-01test: Move test objects to libtestKieran Bingham
/ #include "../camera_buffer.h" #include <libcamera/base/log.h> #include "cros-camera/camera_buffer_manager.h" using namespace libcamera; LOG_DECLARE_CATEGORY(HAL) class CameraBuffer::Private : public Extensible::Private { LIBCAMERA_DECLARE_PUBLIC(CameraBuffer) public: Private(CameraBuffer *cameraBuffer, buffer_handle_t camera3Buffer, PixelFormat pixelFormat, const Size &size, int flags); ~Private(); bool isValid() const { return registered_; } unsigned int numPlanes() const; Span<uint8_t> plane(unsigned int plane); unsigned int stride(unsigned int plane) const; unsigned int offset(unsigned int plane) const; unsigned int size(unsigned int plane) const; size_t jpegBufferSize(size_t maxJpegBufferSize) const; private: void map(); cros::CameraBufferManager *bufferManager_; buffer_handle_t handle_; unsigned int numPlanes_; bool mapped_; bool registered_; union { void *addr; android_ycbcr ycbcr; } mem; }; CameraBuffer::Private::Private([[maybe_unused]] CameraBuffer *cameraBuffer, buffer_handle_t camera3Buffer, [[maybe_unused]] PixelFormat pixelFormat, [[maybe_unused]] const Size &size, [[maybe_unused]] int flags) : handle_(camera3Buffer), numPlanes_(0), mapped_(false), registered_(false) { bufferManager_ = cros::CameraBufferManager::GetInstance(); if (!bufferManager_) { LOG(HAL, Fatal) << "Failed to get cros CameraBufferManager instance"; return; } int ret = bufferManager_->Register(camera3Buffer); if (ret) { LOG(HAL, Error) << "Failed registering a buffer: " << ret; return; } registered_ = true; numPlanes_ = bufferManager_->GetNumPlanes(camera3Buffer); } CameraBuffer::Private::~Private() { int ret; if (mapped_) { ret = bufferManager_->Unlock(handle_); if (ret != 0) LOG(HAL, Error) << "Failed to unlock buffer: " << strerror(-ret); } if (registered_) { ret = bufferManager_->Deregister(handle_); if (ret != 0) LOG(HAL, Error) << "Failed to deregister buffer: " << strerror(-ret); } } unsigned int CameraBuffer::Private::numPlanes() const { return bufferManager_->GetNumPlanes(handle_); } Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane) { if (!mapped_) map(); if (!mapped_) return {}; void *addr; switch (numPlanes()) { case 1: addr = mem.addr; break; default: switch (plane) { case 0: addr = mem.ycbcr.y; break; case 1: addr = mem.ycbcr.cb; break; case 2: addr = mem.ycbcr.cr; break; } } return { static_cast<uint8_t *>(addr), bufferManager_->GetPlaneSize(handle_, plane) }; } unsigned int CameraBuffer::Private::stride(unsigned int plane) const { return cros::CameraBufferManager::GetPlaneStride(handle_, plane); } unsigned int CameraBuffer::Private::offset(unsigned int plane) const { return cros::CameraBufferManager::GetPlaneOffset(handle_, plane); } unsigned int CameraBuffer::Private::size(unsigned int plane) const { return cros::CameraBufferManager::GetPlaneSize(handle_, plane); } size_t CameraBuffer::Private::jpegBufferSize([[maybe_unused]] size_t maxJpegBufferSize) const { return bufferManager_->GetPlaneSize(handle_, 0); } void CameraBuffer::Private::map() { int ret; switch (numPlanes_) { case 1: { ret = bufferManager_->Lock(handle_, 0, 0, 0, 0, 0, &mem.addr); if (ret) { LOG(HAL, Error) << "Single plane buffer mapping failed"; return; } break; } case 2: case 3: { ret = bufferManager_->LockYCbCr(handle_, 0, 0, 0, 0, 0, &mem.ycbcr); if (ret) { LOG(HAL, Error) << "YCbCr buffer mapping failed"; return; } break; } default: LOG(HAL, Error) << "Invalid number of planes: " << numPlanes_; return; } mapped_ = true; return; } PUBLIC_CAMERA_BUFFER_IMPLEMENTATION