queue_source.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2023 Intel Corporation
  6. #ifndef OPENCV_GAPI_STREAMING_QUEUE_SOURCE_HPP
  7. #define OPENCV_GAPI_STREAMING_QUEUE_SOURCE_HPP
  8. #include <memory> // shared_ptr
  9. #include <type_traits> // is_base_of
  10. #include <opencv2/gapi/garg.hpp> // GRunArgs
  11. #include <opencv2/gapi/gmetaarg.hpp> // GMetaArg + all descr_of
  12. #include <opencv2/gapi/streaming/source.hpp> // IStreamSource
  13. namespace cv {
  14. namespace gapi {
  15. namespace wip {
  16. struct Data; // fwd-declare to avoid circular? header dependencies
  17. class GAPI_EXPORTS QueueSourceBase: public cv::gapi::wip::IStreamSource {
  18. class Priv;
  19. std::shared_ptr<Priv> m_priv;
  20. // FIXME: Need to understand how it works with IStreamSource's shared_from_this
  21. // Can we avoid having too many shared_ptrs here?
  22. public:
  23. explicit QueueSourceBase(const cv::GMetaArg &m);
  24. void push(Data &&data);
  25. virtual bool pull(Data &data) override;
  26. virtual void halt() override;
  27. virtual GMetaArg descr_of() const override;
  28. virtual ~QueueSourceBase() = default;
  29. };
  30. /**
  31. * @brief Queued streaming pipeline source.
  32. *
  33. */
  34. template<class T>
  35. class QueueSource final: public QueueSourceBase
  36. {
  37. public:
  38. using Meta = decltype(cv::descr_of(T{}));
  39. explicit QueueSource(Meta m) : QueueSourceBase(GMetaArg{m}) {
  40. }
  41. void push(T t) {
  42. QueueSourceBase::push(Data{t});
  43. }
  44. };
  45. class GAPI_EXPORTS QueueInput {
  46. std::vector<std::shared_ptr<QueueSourceBase> > m_sources;
  47. public:
  48. explicit QueueInput(const cv::GMetaArgs &args);
  49. void push(cv::GRunArgs &&ins);
  50. operator cv::GRunArgs();
  51. };
  52. } // namespace wip
  53. } // namespace gapi
  54. } // namespace cv
  55. #endif // OPENCV_GAPI_STREAMING_SOURCE_HPP