NvUtils.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2016-2022, 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. /**
  29. * @file
  30. * <b>NVIDIA Multimedia API: Utility Functions</b>
  31. *
  32. * @b Description: This file declares the video frame utility functions.
  33. */
  34. /**
  35. * @defgroup l4t_mm_nvutils_group Video Read/Write
  36. * @ingroup l4t_mm_nvvideo_group
  37. *
  38. * Utility functions for reading video frames from a file to the buffer
  39. * structure and for writing from the buffer structure to a file.
  40. *
  41. * @{
  42. */
  43. #ifndef __NV_UTILS_H_
  44. #define __NV_UTILS_H_
  45. #include <fstream>
  46. #include "NvBuffer.h"
  47. /**
  48. * @brief Reads a video frame from a file to the buffer structure.
  49. *
  50. * This function reads data from the file into the buffer, one data plane
  51. * at a time. For each data plane, the number of bytes read is:
  52. *
  53. * @code stride * height @endcode
  54. * or
  55. * @code width * height * bytes_per_pixel @endcode
  56. *
  57. * @param[in] stream A pointer to the input file stream.
  58. * @param[in] buffer A reference to the buffer object into which data is read.
  59. * @return 0 if successful, or -1 otherwise.
  60. */
  61. int read_video_frame(std::ifstream * stream, NvBuffer & buffer);
  62. /**
  63. * @brief Writes a video frame from the buffer structure to a file.
  64. *
  65. * This function writes data to the file from the buffer, one plane at a time.
  66. * For each data plane, the number of bytes written is:
  67. *
  68. * @code stride * height @endcode
  69. * or
  70. * @code width * height * bytes_per_pixel @endcode
  71. *
  72. * @param[in] stream A pointer to the output file stream.
  73. * @param[in] buffer A reference to the buffer object from which
  74. * data is written.
  75. * @return 0 if successful, or -1 otherwise.
  76. */
  77. int write_video_frame(std::ofstream * stream, NvBuffer & buffer);
  78. /**
  79. * @brief Reads a plane of data from a file to the buffer.
  80. *
  81. * @param[in] dmabuf_fd The DMABUF file descriptor of the buffer.
  82. * @param[in] plane Index of the video frame plane.
  83. * @param[in] stream A pointer to the intput file stream.
  84. * @return 0 if successful, or -1 otherwise.
  85. */
  86. int read_dmabuf(int dmabuf_fd, unsigned int plane, std::ifstream * stream);
  87. /**
  88. * @brief Writes a plane of data from the buffer to a file.
  89. *
  90. * @param[in] dmabuf_fd The DMABUF file descriptor of the buffer.
  91. * @param[in] plane Index of the video frame plane.
  92. * @param[in] stream A pointer to the output file stream.
  93. * @return 0 if successful, or -1 otherwise.
  94. */
  95. int dump_dmabuf(int dmabuf_fd, unsigned int plane, std::ofstream * stream);
  96. /**
  97. * @brief Parses the reference recon file to write the Y, U and V checksums.
  98. *
  99. * This function parses Y, U and V checksums from the reference recon file.
  100. *
  101. * @param[in] stream A pointer to the input recon file stream.
  102. * @param[in] recon_params A pointer to an array in which to store
  103. * the parsed Y, U and V strings.
  104. * @return 0 for success, -1 otherwise.
  105. */
  106. int parse_csv_recon_file(std::ifstream * stream, std::string * recon_params);
  107. /** @} */
  108. #endif