FrameConsumer.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of NVIDIA CORPORATION nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  24. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #ifndef _EGLSTREAM_FRAME_CONSUMER_H
  29. #define _EGLSTREAM_FRAME_CONSUMER_H
  30. #include "Frame.h"
  31. namespace EGLStream
  32. {
  33. /**
  34. * A FrameConsumer object acts as a consumer endpoint to an OutputStream or
  35. * EGLStream, provided during creation, and exposes interfaces to return
  36. * Frame objects that provide various image reading interfaces.
  37. *
  38. * Destroying a Consumer will disconnect the consumer from the EGLStream, but
  39. * Frame objects returned by IFrameConsumer::acquireFrame will persist until
  40. * the application explicitly destroys those objects.
  41. */
  42. class FrameConsumer : public Argus::InterfaceProvider, public Argus::Destructable
  43. {
  44. public:
  45. /**
  46. * Creates a new FrameConsumer to read frames from an Argus OutputStream.
  47. *
  48. * @param[in] outputStream The output stream to read from.
  49. * @param[out] status An optional pointer to return an error status code.
  50. *
  51. * @returns A new FrameConsumer object, or NULL on error.
  52. */
  53. static FrameConsumer* create(Argus::OutputStream* outputStream,
  54. Argus::Status* status = NULL);
  55. /**
  56. * Creates a new FrameConsumer to read frames from an EGLStream.
  57. *
  58. * @param[in] eglDisplay The EGLDisplay the stream belongs to.
  59. * @param[in] eglDisplay The EGLStream to connect to.
  60. * @param[out] status An optional pointer to return an error status code.
  61. *
  62. * @returns A new FrameConsumer object, or NULL on error.
  63. */
  64. static FrameConsumer* create(EGLDisplay eglDisplay,
  65. EGLStreamKHR eglStream,
  66. Argus::Status* status = NULL);
  67. protected:
  68. ~FrameConsumer() {}
  69. };
  70. /**
  71. * @class IFrameConsumer
  72. *
  73. * Exposes the methods used to acquire Frames from a FrameConsumer.
  74. */
  75. DEFINE_UUID(Argus::InterfaceID, IID_FRAME_CONSUMER, b94a7bd1,c3c8,11e5,a837,08,00,20,0c,9a,66);
  76. class IFrameConsumer : public Argus::Interface
  77. {
  78. public:
  79. static const Argus::InterfaceID& id() { return IID_FRAME_CONSUMER; }
  80. /**
  81. * Acquires a new frame from the FrameConsumer, returning a Frame object. This Frame object
  82. * behaves as its own entity, and may persist even after the FrameConsumer is destroyed.
  83. * It is the application's responsibility to destroy any Frame returned by this method.
  84. *
  85. * Destroying a Frame causes all resources held by that frame to be returned to the EGLStream
  86. * producer so that they may be used to produce another frame. If too many Frames are held
  87. * by the consumer, or these frames are acquired at a slower rate than the producer is
  88. * producing frames, it may be possible to stall the producer. Frame objects should always be
  89. * be destroyed as soon as possible to minimize resource overhead.
  90. *
  91. * If NULL is returned and the status code is STATUS_DISCONNECTED, the producer has
  92. * disconnected from the stream and no more frames can ever be acquired from this consumer.
  93. *
  94. * @param[in] timeout The timeout (in nanoseconds) to wait for a frame if one isn't available.
  95. * @param[out] status An optional pointer to return an error status code.
  96. *
  97. * @returns A pointer to the frame acquired from the stream, or NULL on error.
  98. */
  99. virtual Frame* acquireFrame(uint64_t timeout = Argus::TIMEOUT_INFINITE,
  100. Argus::Status* status = NULL) = 0;
  101. protected:
  102. ~IFrameConsumer() {}
  103. };
  104. } // namespace EGLStream
  105. #endif // _EGLSTREAM_FRAME_CONSUMER_H