source.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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) 2019 Intel Corporation
  6. #ifndef OPENCV_GAPI_STREAMING_SOURCE_HPP
  7. #define OPENCV_GAPI_STREAMING_SOURCE_HPP
  8. #include <memory> // shared_ptr
  9. #include <type_traits> // is_base_of
  10. #include <opencv2/gapi/gmetaarg.hpp> // GMetaArg
  11. namespace cv {
  12. namespace gapi {
  13. namespace wip {
  14. struct Data; // "forward-declaration" of GRunArg
  15. /**
  16. * @brief Abstract streaming pipeline source.
  17. *
  18. * Implement this interface if you want customize the way how data is
  19. * streaming into GStreamingCompiled.
  20. *
  21. * Objects implementing this interface can be passed to
  22. * GStreamingCompiled using setSource() with cv::gin(). Regular
  23. * compiled graphs (GCompiled) don't support input objects of this
  24. * type.
  25. *
  26. * Default cv::VideoCapture-based implementation is available, see
  27. * cv::gapi::wip::GCaptureSource.
  28. *
  29. * @note stream sources are passed to G-API via shared pointers, so
  30. * please use ptr() when passing a IStreamSource implementation to
  31. * cv::gin().
  32. */
  33. class IStreamSource: public std::enable_shared_from_this<IStreamSource>
  34. {
  35. public:
  36. using Ptr = std::shared_ptr<IStreamSource>;
  37. Ptr ptr() { return shared_from_this(); }
  38. virtual bool pull(Data &data) = 0;
  39. virtual GMetaArg descr_of() const = 0;
  40. virtual ~IStreamSource() = default;
  41. };
  42. template<class T, class... Args>
  43. IStreamSource::Ptr inline make_src(Args&&... args)
  44. {
  45. static_assert(std::is_base_of<IStreamSource, T>::value,
  46. "T must implement the cv::gapi::IStreamSource interface!");
  47. auto src_ptr = std::make_shared<T>(std::forward<Args>(args)...);
  48. return src_ptr->ptr();
  49. }
  50. } // namespace wip
  51. } // namespace gapi
  52. } // namespace cv
  53. #endif // OPENCV_GAPI_STREAMING_SOURCE_HPP