meta.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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) 2020 Intel Corporation
  6. #ifndef OPENCV_GAPI_GSTREAMING_META_HPP
  7. #define OPENCV_GAPI_GSTREAMING_META_HPP
  8. #include <opencv2/gapi/gopaque.hpp>
  9. #include <opencv2/gapi/gcall.hpp>
  10. #include <opencv2/gapi/gkernel.hpp>
  11. #include <opencv2/gapi/gtype_traits.hpp>
  12. namespace cv {
  13. namespace gapi {
  14. namespace streaming {
  15. // FIXME: the name is debatable
  16. namespace meta_tag {
  17. static constexpr const char * timestamp = "org.opencv.gapi.meta.timestamp";
  18. static constexpr const char * seq_id = "org.opencv.gapi.meta.seq_id";
  19. } // namespace meta_tag
  20. namespace detail {
  21. struct GMeta {
  22. static const char *id() {
  23. return "org.opencv.streaming.meta";
  24. }
  25. // A universal yield for meta(), same as in GDesync
  26. template<typename... R, int... IIs>
  27. static std::tuple<R...> yield(cv::GCall &call, cv::detail::Seq<IIs...>) {
  28. return std::make_tuple(cv::detail::Yield<R>::yield(call, IIs)...);
  29. }
  30. // Also a universal outMeta stub here
  31. static GMetaArgs getOutMeta(const GMetaArgs &args, const GArgs &) {
  32. return args;
  33. }
  34. };
  35. } // namespace detail
  36. template<typename T, typename G>
  37. cv::GOpaque<T> meta(G g, const std::string &tag) {
  38. using O = cv::GOpaque<T>;
  39. cv::GKernel k{
  40. detail::GMeta::id() // kernel id
  41. , tag // kernel tag. Use meta tag here
  42. , &detail::GMeta::getOutMeta // outMeta callback
  43. , {cv::detail::GTypeTraits<O>::shape} // output Shape
  44. , {cv::detail::GTypeTraits<G>::op_kind} // input data kinds
  45. , {cv::detail::GObtainCtor<O>::get()} // output template ctors
  46. };
  47. cv::GCall call(std::move(k));
  48. call.pass(g);
  49. return std::get<0>(detail::GMeta::yield<O>(call, cv::detail::MkSeq<1>::type()));
  50. }
  51. template<typename G>
  52. cv::GOpaque<int64_t> timestamp(G g) {
  53. return meta<int64_t>(g, meta_tag::timestamp);
  54. }
  55. template<typename G>
  56. cv::GOpaque<int64_t> seq_id(G g) {
  57. return meta<int64_t>(g, meta_tag::seq_id);
  58. }
  59. template<typename G>
  60. cv::GOpaque<int64_t> seqNo(G g) {
  61. // Old name, compatibility only
  62. return seq_id(g);
  63. }
  64. } // namespace streaming
  65. } // namespace gapi
  66. } // namespace cv
  67. #endif // OPENCV_GAPI_GSTREAMING_META_HPP