/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef CAMERA_DEMO_TEST_H #define CAMERA_DEMO_TEST_H #include #include #include #include #include #include #include #include "display_type.h" #include "ibuffer.h" #include "ibuffer_pool.h" #include "surface.h" #include "ibuffer_consumer_listener.h" namespace OHOS::CameraUtest { using namespace OHOS::Camera; class BufferManagerTest : public testing::Test { public: static void SetUpTestCase(void); static void TearDownTestCase(void); void SetUp(void); void TearDown(void); public: class Stream { public: Stream() = default; ~Stream() = default; bool Init(OHOS::sptr& producer); void StartStream(); void StopStream(); void EnqueueBufferNonBlock(); void DequeueBuffer(std::shared_ptr& buffer); std::shared_ptr GetBufferPool() const; int64_t GetPoolId() const { return bufferPoolId_; } private: void StartInnerStream() const; void StartExternalStream(); private: std::mutex lock_; OHOS::sptr producer_ = nullptr; uint32_t width_ = 1920; uint32_t height_ = 1080; uint32_t queueSize_ = 7; uint64_t usage_ = CAMERA_USAGE_SW_WRITE_OFTEN | CAMERA_USAGE_SW_READ_OFTEN | CAMERA_USAGE_MEM_DMA; uint32_t format_ = CAMERA_FORMAT_YCBCR_420_SP; int64_t bufferPoolId_ = -1; std::shared_ptr bufferPool_ = nullptr; std::vector, std::shared_ptr>> bufferVec_ = {}; int32_t releaseFence_ = 0; std::vector deletingBuffers_ = {}; OHOS::BufferRequestConfig requestConfig_ = {}; OHOS::BufferFlushConfig flushConfig_ = {}; }; class TestBufferConsumerListener: public IBufferConsumerListener { public: TestBufferConsumerListener() { } ~TestBufferConsumerListener() { } void OnBufferAvailable() { } }; class Node { public: explicit Node(const std::string name) { name_ = name; } virtual ~Node() = default; virtual void Connect(std::shared_ptr& nextNode); virtual void Deliver(std::shared_ptr& buffer); virtual void Receive(std::shared_ptr& buffer); virtual void Process(std::shared_ptr& buffer); public: std::string name_ = ""; std::shared_ptr nextNode_ = nullptr; private: Node() = default; }; class SinkNode : public Node { public: SinkNode(const std::string name) : Node(name) {} ~SinkNode() {} void Deliver(std::shared_ptr& buffer) override; void BindCallback(std::function&)> callback); private: std::function&)> callback_ = nullptr; }; class SourceNode : public Node { public: SourceNode(const std::string name) : Node(name) {} void Process(std::shared_ptr& buffer) override; ~SourceNode() {} private: int cacheSize_ = 3; std::list> cache_ = {}; }; class Pipeline { public: Pipeline() = default; ~Pipeline() = default; bool AddStream(std::shared_ptr& stream); void StartStream(); void StopStream(); private: void CollectBuffers(); void DeliverBuffer(); void DeliverBuffer(std::shared_ptr& buffer); bool BuildPipeline(); private: bool running = true; std::mutex streamLock_; std::thread* collectThread_ = nullptr; std::shared_ptr sourceNode_ = nullptr; uint64_t frameNumber = 0; struct LocalStream { std::mutex deviceLock_; std::shared_ptr stream_ = nullptr; std::thread* deliverThread_ = nullptr; std::list> deviceBufferList_ = {}; }; std::shared_ptr localStream_ = nullptr; }; }; } // namespace OHOS::CameraUtest #endif // CAMERA_DEMO_TEST_H