NvBufSurface.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 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: nvbufsurface Wrapper Class</b>
  31. *
  32. * @b Description: This file declares a wrapper class for nvbufsurface.
  33. * @{
  34. */
  35. #ifndef __NV_BUF_SURFACE_H__
  36. #define __NV_BUF_SURFACE_H__
  37. #include <errno.h>
  38. #include <fstream>
  39. #include <iostream>
  40. #include <linux/videodev2.h>
  41. #include <malloc.h>
  42. #include <pthread.h>
  43. #include <string.h>
  44. #include <unistd.h>
  45. #include <fcntl.h>
  46. #include <poll.h>
  47. #include "nvbufsurface.h"
  48. #include "nvbufsurftransform.h"
  49. /**
  50. * @brief This derived class defines a wrapper class for nvbufsurface and nvbuftransform.
  51. *
  52. * Defines a helper class that provides common functionality for nvbufsurface.
  53. * It includes the file descriptor (FD) of the device
  54. * and other helper methods, such as Destroy nvbufsurface,
  55. * create nvbufsurface, buffer transform.
  56. */
  57. class NvBufSurf
  58. {
  59. public:
  60. typedef struct {
  61. /** width of source rectangle coordinates of input buffers for transformation. */
  62. uint32_t src_width;
  63. /** height of source rectangle coordinates of input buffers for transformation. */
  64. uint32_t src_height;
  65. /** top of source rectangle coordinates of input buffers for transformation. */
  66. uint32_t src_top;
  67. /** left of source rectangle coordinates of input buffers for transformation. */
  68. uint32_t src_left;
  69. /** width of destination rectangle coordinates of input buffers for transformation. */
  70. uint32_t dst_width;
  71. /** height of destination rectangle coordinates of input buffers for transformation. */
  72. uint32_t dst_height;
  73. /** top of destination rectangle coordinates of input buffers for transformation. */
  74. uint32_t dst_top;
  75. /** left of destination rectangle coordinates of input buffers for transformation. */
  76. uint32_t dst_left;
  77. /** flag to indicate which of the transform parameters are valid. */
  78. NvBufSurfTransform_Transform_Flag flag;
  79. /** flip method. */
  80. NvBufSurfTransform_Flip flip;
  81. /** transform filter. */
  82. NvBufSurfTransform_Inter filter;
  83. } NvCommonTransformParams;
  84. typedef struct {
  85. /** Holds the width of the buffer. */
  86. uint32_t width;
  87. /** Holds the height of the buffer. */
  88. uint32_t height;
  89. /** Holds the color format of the buffer. */
  90. NvBufSurfaceColorFormat colorFormat;
  91. /** Holds the surface layout. May be Block Linear (BL) or Pitch Linear (PL).
  92. For a dGPU, only PL is valid. */
  93. NvBufSurfaceLayout layout;
  94. /** Holds the type of memory to be allocated. */
  95. NvBufSurfaceMemType memType;
  96. /** Holds tag to associate with the buffer. */
  97. NvBufSurfaceTag memtag;
  98. } NvCommonAllocateParams;
  99. /* Destroys a hardware buffer. */
  100. static int NvDestroy(int fd);
  101. /* Allocates a hardware buffer */
  102. static int NvAllocate(NvCommonAllocateParams *allocateParams, uint32_t numBuffers, int *fd);
  103. /* Transforms one DMA buffer to another DMA buffer. */
  104. static int NvTransform(NvCommonTransformParams *transformParams, int src_fd, int dst_fd);
  105. static int NvTransformAsync(NvCommonTransformParams *transformParams, NvBufSurfTransformSyncObj_t *sync_obj, int src_fd, int dst_fd);
  106. };
  107. /** @} */
  108. #endif