nvosd.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * Copyright (c) 2016-2023, 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. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in
  11. * the documentation and/or other materials provided with the
  12. * distribution.
  13. * 3. The names of its contributors may not be used to endorse or promote
  14. * products derived from this software without specific prior written
  15. * permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  23. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /**
  30. * @file
  31. * <b>NVIDIA Multimedia Utilities: On-Screen Display Manager</b>
  32. *
  33. * This file defines the NvOSD library to be used to draw rectangles and text over the frame
  34. * for given parameters.
  35. */
  36. /**
  37. * @defgroup ee_nvosd_group On-Screen Display Manager
  38. * Defines the NvOSD library to be used to draw rectangles and text over the frame
  39. * for given parameters.
  40. * @ingroup common_utility_group
  41. * @{
  42. */
  43. #ifndef __NVOSD_DEFS__
  44. #define __NVOSD_DEFS__
  45. #ifdef __cplusplus
  46. extern "C"
  47. {
  48. #endif
  49. #define NVOSD_MAX_NUM_RECTS 128
  50. #define MAX_BG_CLR 20
  51. /**
  52. * Holds the color parameters of the box or text to be overlayed.
  53. */
  54. typedef struct _NvOSD_ColorParams {
  55. double red; /**< Holds red component of color.
  56. Value must be in the range 0-1. */
  57. double green; /**< Holds green component of color.
  58. Value must be in the range 0-1.*/
  59. double blue; /**< Holds blue component of color.
  60. Value must be in the range 0-1.*/
  61. double alpha; /**< Holds alpha component of color.
  62. Value must be in the range 0-1.*/
  63. }NvOSD_ColorParams;
  64. /**
  65. * Holds the font parameters of the text to be overlayed.
  66. */
  67. typedef struct _NvOSD_FontParams {
  68. char * font_name; /**< Holds pointer to the string containing
  69. font name. */
  70. unsigned int font_size; /**< Holds size of the font. */
  71. NvOSD_ColorParams font_color; /**< Holds font color. */
  72. }NvOSD_FontParams;
  73. /**
  74. * Holds the text parameters of the text to be overlayed.
  75. */
  76. typedef struct _NvOSD_TextParams {
  77. char * display_text; /**< Holds the text to be overlayed. */
  78. unsigned int x_offset; /**< Holds horizontal offset w.r.t top left pixel of
  79. the frame. */
  80. unsigned int y_offset; /**< Holds vertical offset w.r.t top left pixel of
  81. the frame. */
  82. NvOSD_FontParams font_params; /**< font_params. */
  83. int set_bg_clr; /**< Boolean to indicate text has background color. */
  84. NvOSD_ColorParams text_bg_clr; /**< Background color for text. */
  85. }NvOSD_TextParams;
  86. typedef struct _NvOSD_Color_info {
  87. int id;
  88. NvOSD_ColorParams color;
  89. }NvOSD_Color_info;
  90. /**
  91. * Holds the box parameters of the box to be overlayed.
  92. */
  93. typedef struct _NvOSD_RectParams {
  94. unsigned int left; /**< Holds left coordinate of the box in pixels. */
  95. unsigned int top; /**< Holds top coordinate of the box in pixels. */
  96. unsigned int width; /**< Holds width of the box in pixels. */
  97. unsigned int height; /**< Holds height of the box in pixels. */
  98. unsigned int border_width; /**< Holds border_width of the box in pixels. */
  99. NvOSD_ColorParams border_color; /**< Holds color params of the border
  100. of the box. */
  101. unsigned int has_bg_color; /**< Holds boolean value indicating whether box
  102. has background color. */
  103. unsigned int reserved; /** Reserved field for future usage.
  104. For internal purpose only */
  105. NvOSD_ColorParams bg_color; /**< Holds background color of the box. */
  106. int has_color_info;
  107. int color_id;
  108. }NvOSD_RectParams;
  109. /**
  110. * Holds the box parameters of the line to be overlayed.
  111. */
  112. typedef struct _NvOSD_LineParams {
  113. unsigned int x1; /**< Holds left coordinate of the box in pixels. */
  114. unsigned int y1; /**< Holds top coordinate of the box in pixels. */
  115. unsigned int x2; /**< Holds width of the box in pixels. */
  116. unsigned int y2; /**< Holds height of the box in pixels. */
  117. unsigned int line_width; /**< Holds border_width of the box in pixels. */
  118. NvOSD_ColorParams line_color; /**< Holds color params of the border
  119. of the box. */
  120. } NvOSD_LineParams;
  121. /**
  122. * Holds the arrow parameters to be overlayed.
  123. */
  124. typedef struct _NvOSD_ArrowParams {
  125. unsigned int x1; /**< Holds start horizontal coordinate in pixels. */
  126. unsigned int y1; /**< Holds start vertical coordinate in pixels. */
  127. unsigned int x2; /**< Holds end horizontal coordinate in pixels. */
  128. unsigned int y2; /**< Holds end vertical coordinate in pixels. */
  129. unsigned int arrow_width; /**< Holds arrow_width in pixels. */
  130. unsigned int start_arrow_head; /** Holds boolean value indicating whether
  131. arrow head is at start or at end.
  132. Setting to value 1 indicates arrow head is
  133. at start. Otherwise it is at end. */
  134. NvOSD_ColorParams arrow_color; /**< Holds color params of the arrow box. */
  135. unsigned int reserved; /**< reserved field for future usage.
  136. For internal purpose only. */
  137. }NvOSD_ArrowParams;
  138. /**
  139. * Holds the circle parameters to be overlayed.
  140. */
  141. typedef struct _NvOSD_CircleParams {
  142. unsigned int xc; /**< Holds start horizontal coordinate in pixels. */
  143. unsigned int yc; /**< Holds start vertical coordinate in pixels. */
  144. unsigned int radius; /**< Holds radius of circle in pixels. */
  145. NvOSD_ColorParams circle_color; /**< Holds color params of the arrow box. */
  146. unsigned int reserved; /**< reserved field for future usage.
  147. For internal purpose only. */
  148. }NvOSD_CircleParams;
  149. /**
  150. * List modes used to overlay boxes and text.
  151. */
  152. typedef enum{
  153. MODE_CPU, /**< Selects CPU for OSD processing.
  154. Works with RGBA data only */
  155. MODE_GPU, /**< Selects GPU for OSD processing.
  156. Yet to be implemented */
  157. MODE_HW /**< Selects NV HW engine for rectangle draw and mask.
  158. This mode works with both YUV and RGB data.
  159. It does not consider alpha parameter.
  160. Not applicable for drawing text. */
  161. } NvOSD_Mode;
  162. /**
  163. * Creates NvOSD context.
  164. *
  165. * @returns A pointer to NvOSD context, NULL in case of failure.
  166. */
  167. void *nvosd_create_context(void);
  168. /**
  169. * Destroys NvOSD context.
  170. *
  171. * @param[in] nvosd_ctx A pointer to NvOSD context.
  172. */
  173. void nvosd_destroy_context(void *nvosd_ctx);
  174. /**
  175. * Sets clock parameters for the given context.
  176. *
  177. * The clock is overlayed when nvosd_put_text() is called.
  178. * If no other text is to be overlayed, nvosd_put_text must be called with
  179. * @a num_strings as 0 and @a text_params_list as NULL.
  180. *
  181. * @param[in] nvosd_ctx A pointer to NvOSD context.
  182. * @param[in] clk_params A pointer to NvOSD_TextParams structure for the clock
  183. * to be overlayed; NULL to disable the clock.
  184. */
  185. void nvosd_set_clock_params(void *nvosd_ctx, NvOSD_TextParams *clk_params);
  186. /**
  187. * Overlays clock and given text at given location on a buffer.
  188. *
  189. * To overlay the clock, you must set clock params using
  190. * nvosd_set_clock_params().
  191. * You must ensure that the length of @a text_params_list is at least
  192. * @a num_strings.
  193. *
  194. * @note Currently only #MODE_CPU is supported. Specifying other modes wil have
  195. * no effect.
  196. *
  197. * @param[in] nvosd_ctx A pointer to NvOSD context.
  198. * @param[in] mode Mode selection to draw the text.
  199. * @param[in] fd DMABUF FD of buffer on which text is to be overlayed.
  200. * @param[in] num_strings Number of strings to be overlayed.
  201. * @param[in] text_params_list A pointer to an array of NvOSD_TextParams
  202. * structure for the clock and text to be overlayed.
  203. *
  204. * @returns 0 for success, -1 for failure.
  205. */
  206. int nvosd_put_text(void *nvosd_ctx, NvOSD_Mode mode, int fd, int num_strings,
  207. NvOSD_TextParams *text_params_list);
  208. /**
  209. * Overlays boxes at given location on a buffer.
  210. *
  211. * Boxes can be configured with:
  212. * a. Only border
  213. * To draw boxes with only border, you must set @a border_width and set
  214. * @a has_bg_color to 0 for the given box.
  215. * b. Border and background color
  216. * To draw boxes with border and background color, you must set @a
  217. * border_width and set @a has_bg_color to 1, and specify background color
  218. * parameters for the given box.
  219. * c. Solid fill acting as mask region
  220. * To draw boxes with solid fill acting as mask region, you must set @a
  221. * border_width to 0 and @a has_bg_color to 1 for the given box.
  222. *
  223. *
  224. * You must ensure that the length of @a rect_params_list is at least
  225. * @a num_rects.
  226. *
  227. * @param[in] nvosd_ctx A pointer to NvOSD context.
  228. * @param[in] mode Mode selection to draw the boxes.
  229. * @param[in] fd DMABUF FD of buffer on which boxes are to be overlayed.
  230. * @param[in] num_rects Number of boxes to be overlayed.
  231. * @param[in] rect_params_list A pointer to an array of NvOSD_TextParams
  232. * structure for the clock and text to be overlayed.
  233. *
  234. * @returns 0 for success, -1 for failure.
  235. */
  236. int nvosd_draw_rectangles(void *nvosd_ctx, NvOSD_Mode mode, int fd,
  237. int num_rects, NvOSD_RectParams *rect_params_list);
  238. int nvosd_init_colors_for_hw_blend(void *nvosd_ctx, NvOSD_Color_info * color_info,
  239. int num_classes);
  240. int nvosd_draw_arrows(void *nvosd_ctx, NvOSD_Mode mode, int fd,
  241. int num_arrows, NvOSD_ArrowParams *arrow_params_list);
  242. int nvosd_draw_circles(void *nvosd_ctx, NvOSD_Mode mode, int fd,
  243. int num_circles, NvOSD_CircleParams *circle_params_list);
  244. int nvosd_draw_lines(void *nvosd_ctx, NvOSD_Mode mode, int fd,
  245. int num_lines, NvOSD_LineParams *line_params_list);
  246. int nvosd_gpu_apply(void *nvosd_ctx, int fd);
  247. #ifdef __cplusplus
  248. }
  249. #endif
  250. /** @} */
  251. #endif