cnstream_common_pri.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*************************************************************************
  2. * Copyright (C) [2021] by Cambricon, Inc. All rights reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. * THE SOFTWARE.
  19. *************************************************************************/
  20. #ifndef CNSTREAM_COMMON_PRI_HPP_
  21. #define CNSTREAM_COMMON_PRI_HPP_
  22. #include <string.h>
  23. #include <unistd.h>
  24. #include <string>
  25. #include <vector>
  26. #if defined(__GNUC__) || defined(__clang__)
  27. #define CNS_DEPRECATED __attribute__((deprecated))
  28. #elif defined(_MSC_VER)
  29. #define CNS_DEPRECATED __declspec(deprecated)
  30. #else
  31. #error You need to implement CNS_DEPRECATED for this compiler
  32. #define CNS_DEPRECATED
  33. #endif
  34. #if defined(__GNUC__)
  35. #define CNS_IGNORE_DEPRECATED_PUSH \
  36. _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
  37. #define CNS_IGNORE_DEPRECATED_POP _Pragma("GCC diagnostic pop")
  38. #elif defined(__clang__)
  39. #define CNS_IGNORE_DEPRECATED_PUSH \
  40. _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
  41. #define CNS_IGNORE_DEPRECATED_POP _Pragma("clang diagnostic pop")
  42. #elif defined(_MSC_VER) && _MSC_VER >= 1400
  43. #define CNS_IGNORE_DEPRECATED_PUSH \
  44. __pragma(warning(push)) __pragma(warning(disable : 4996)) #define CNS_IGNORE_DEPRECATED_POP __pragma(warning(pop))
  45. #else
  46. #error You need to implement CNS_IGNORE_DEPRECATED_PUSH and \
  47. CNS_IGNORE_DEPRECATED_POP for this compiler
  48. #define CNS_IGNORE_DEPRECATED_PUSH
  49. #define CNS_IGNORE_DEPRECATED_POP
  50. #endif
  51. namespace cnstream {
  52. /*!
  53. * @enum CNPixelFormat
  54. *
  55. * @brief Enumeration variables describing the picture formats
  56. */
  57. enum class CNPixelFormat {
  58. YUV420P = 0, /*!< The format with planar Y4-U1-V1, I420 */
  59. RGB24, /*!< The format with packed R8G8B8 */
  60. BGR24, /*!< The format with packed B8G8R8 */
  61. NV21, /*!< The format with semi-Planar Y4-V1U1 */
  62. NV12, /*!< The format with semi-Planar Y4-U1V1 */
  63. I422, /*!< The format with semi-Planar I422 */
  64. I444, /*!< The format with semi-Planar I444 */
  65. };
  66. /*!
  67. * @enum CNCodecType
  68. *
  69. * @brief Enumeration variables describing the codec types
  70. */
  71. enum class CNCodecType {
  72. H264 = 0, /*!< The H264 codec type */
  73. HEVC, /*!< The HEVC codec type */
  74. MPEG4, /*!< The MPEG4 codec type */
  75. JPEG /*!< The JPEG codec type */
  76. };
  77. /*!
  78. * @class NonCopyable
  79. *
  80. * @brief NonCopyable is the abstraction of the class which has no ability to do copy and assign. It is always be used
  81. * as the base class to disable copy and assignment.
  82. */
  83. class NonCopyable {
  84. protected:
  85. /*!
  86. * @brief Constructs an instance with empty value.
  87. *
  88. * @param None.
  89. *
  90. * @return None.
  91. */
  92. NonCopyable() = default;
  93. /*!
  94. * @brief Destructs an instance.
  95. *
  96. * @param None.
  97. *
  98. * @return None.
  99. */
  100. ~NonCopyable() = default;
  101. private:
  102. NonCopyable(const NonCopyable&) = delete;
  103. NonCopyable(NonCopyable&&) = delete;
  104. NonCopyable& operator=(const NonCopyable&) = delete;
  105. NonCopyable& operator=(NonCopyable&&) = delete;
  106. };
  107. constexpr size_t INVALID_MODULE_ID = (size_t)(-1);
  108. constexpr uint32_t INVALID_STREAM_IDX = (uint32_t)(-1);
  109. static constexpr uint32_t MAX_STREAM_NUM = 128; /*!< The streams at most allowed. */
  110. #define CNS_JSON_DIR_PARAM_NAME "json_file_dir"
  111. /**
  112. * @brief Profiler configuration title in JSON configuration file.
  113. **/
  114. static constexpr char kProfilerConfigName[] = "profiler_config";
  115. /**
  116. * @brief Subgraph node item prefix.
  117. **/
  118. static constexpr char kSubgraphConfigPrefix[] = "subgraph:";
  119. /**
  120. *
  121. * @brief Judges if the configuration item name represents a subgraph.
  122. *
  123. * @param[in] item_name The item name.
  124. *
  125. * @return Returns true if the ``item_name`` represents a subgraph. Otherwise, returns false.
  126. **/
  127. inline bool IsSubgraphItem(const std::string &item_name) {
  128. return item_name.size() > strlen(kSubgraphConfigPrefix) &&
  129. kSubgraphConfigPrefix == item_name.substr(0, strlen(kSubgraphConfigPrefix));
  130. }
  131. /**
  132. * @brief Checks one stream whether reaches EOS.
  133. *
  134. * @param[in] stream_id The identifier of a stream.
  135. * @param[in] sync The mode of checking the status. True means checking in synchronized mode while False represents
  136. * for asynchronous.
  137. *
  138. * @return Returns true if the EOS reached, otherwise returns false.
  139. *
  140. * @note It's used for removing sources forcedly.
  141. */
  142. bool CheckStreamEosReached(const std::string &stream_id, bool sync = true);
  143. /**
  144. * @brief Checks one stream whether reaches EOS.
  145. *
  146. * @param[in] stream_id The identifier of a stream.
  147. * @param[in] value The status of a stream.
  148. *
  149. * @return No return value.
  150. *
  151. * @note It's used for removing sources forcedly.
  152. */
  153. void SetStreamRemoved(const std::string &stream_id, bool value = true);
  154. /**
  155. * @brief Checks whether a stream is removed.
  156. *
  157. * @param[in] stream_id The identifier of a stream.
  158. *
  159. * @return Returns true if the stream is removed, otherwise returns false.
  160. *
  161. * @note It's used for removing sources forcedly.
  162. */
  163. bool IsStreamRemoved(const std::string &stream_id);
  164. inline std::vector<std::string> StringSplit(const std::string& s, char c) {
  165. std::stringstream ss(s);
  166. std::string piece;
  167. std::vector<std::string> result;
  168. while (std::getline(ss, piece, c)) {
  169. result.push_back(piece);
  170. }
  171. return result;
  172. }
  173. } // namespace cnstream
  174. #endif // CNSTREAM_COMMON_PRI_HPP_