vformat.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*************************************************************************
  2. * Copyright (C) [2019] 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. /**
  21. * @file vformat.h
  22. *
  23. * This file contains a declaration of structures used in decode and encode.
  24. */
  25. #ifndef EASYCODEC_VFORMAT_H_
  26. #define EASYCODEC_VFORMAT_H_
  27. #include <cstdint>
  28. #define CN_MAXIMUM_PLANE 3
  29. namespace edk {
  30. /**
  31. * @brief Structure to describe resolution of video or image.
  32. */
  33. struct Geometry {
  34. unsigned int w; ///< width in pixel
  35. unsigned int h; ///< height in pixel
  36. };
  37. /**
  38. * @brief Enumeration to describe image colorspace.
  39. */
  40. enum class PixelFmt {
  41. NV12 = 0, ///< NV12, YUV family
  42. NV21, ///< NV21, YUV family
  43. I420,
  44. YV12,
  45. YUYV,
  46. UYVY,
  47. YVYU,
  48. VYUY,
  49. P010,
  50. YUV420_10BIT,
  51. YUV444_10BIT,
  52. ARGB,
  53. ABGR,
  54. BGRA,
  55. RGBA,
  56. AYUV,
  57. RGB565,
  58. RAW, ///< No format
  59. TOTAL_COUNT
  60. };
  61. /**
  62. * @brief Enumeration to describe data codec type
  63. * @note Type contains both video and image
  64. */
  65. enum class CodecType {
  66. MPEG2 = 0,
  67. MPEG4, ///< MPEG4 video codec standard
  68. H264, ///< H.264 video codec standard
  69. H265, ///< H.265 video codec standard, aka HEVC
  70. VP8,
  71. VP9,
  72. AVS,
  73. MJPEG, ///< Motion JPEG video codec standard
  74. JPEG ///< JPEG image format
  75. };
  76. enum class ColorStd {
  77. ITU_BT_709 = 0, ///< ITU BT 709 color standard
  78. ITU_BT_601, ///< ITU BT.601 color standard
  79. ITU_BT_2020, ///< ITU BT 2020 color standard
  80. ITU_BT_601_ER, ///< ITU BT 601 color standard extend range
  81. ITU_BT_709_ER, ///< ITU BT 709 color standard extend range
  82. COLOR_STANDARD_INVALID,
  83. };
  84. /**
  85. * @brief Structure contains raw data and informations
  86. * @note Used as output in decode and input in encode
  87. */
  88. struct CnFrame {
  89. /**
  90. * Used to release buffer in EasyDecode::ReleaseBuffer
  91. * when frame memory from decoder will not be used. Useless in encoder.
  92. */
  93. uint64_t buf_id{0};
  94. /// Presentation time stamp
  95. uint64_t pts{0};
  96. /// Frame height in pixel
  97. uint32_t height{0};
  98. /// Frame width in pixel
  99. uint32_t width{0};
  100. /// Frame data size, unit: byte
  101. uint64_t frame_size{0};
  102. /// Frame color space, @see edk::PixelFmt
  103. PixelFmt pformat{PixelFmt::NV12};
  104. /// Color standard
  105. ColorStd color_std{ColorStd::ITU_BT_709};
  106. /// MLU device identification
  107. int device_id{0};
  108. /// MLU channel in which memory stored
  109. int channel_id{0};
  110. /// If use cpu decode
  111. bool cpu_decode{false};
  112. /// Plane count for this frame
  113. uint32_t n_planes{0};
  114. /// Frame strides for each plane
  115. uint32_t strides[CN_MAXIMUM_PLANE]{0, 0, 0};
  116. /// Frame data pointer
  117. void* ptrs[CN_MAXIMUM_PLANE]{nullptr, nullptr, nullptr};
  118. };
  119. /**
  120. * @brief Encode bitstream slice type.
  121. */
  122. enum class BitStreamSliceType { SPS_PPS, FRAME };
  123. /**
  124. * @brief Structure contains encoded data and informations
  125. * @note Used as output in encode and input in decode
  126. */
  127. struct CnPacket {
  128. /**
  129. * Used to release buffer in EasyEncode::ReleaseBuffer
  130. * when memory from encoder will not be used. Useless in decoder.
  131. */
  132. uint64_t buf_id{0};
  133. /// Frame data pointer
  134. void* data{nullptr};
  135. /// Frame length, unit pixel
  136. uint64_t length{0};
  137. /// Presentation time stamp
  138. uint64_t pts{0};
  139. /// Video codec type, @see edk::CodecType
  140. CodecType codec_type{CodecType::H264};
  141. /// Bitstream slice type, only used in EasyEncode, @see edk::BitStreamSliceType
  142. BitStreamSliceType slice_type{BitStreamSliceType::FRAME};
  143. };
  144. } // namespace edk
  145. #endif // EASYCODEC_VFORMAT_H_