yuv_feeder.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (c) 2018, Chips&Media
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef __JPU_YUV_FEEDER_H__
  26. #define __JPU_YUV_FEEDER_H__
  27. #ifdef USE_FEEDING_METHOD_BUFFER
  28. #include "codaj12/jpuapi/jpuapi.h"
  29. #include "codaj12/sample/helper/datastructure.h"
  30. #else
  31. #include "jpuapi.h"
  32. #include "datastructure.h"
  33. #endif
  34. #define SOURCE_YUV 0
  35. typedef void* YuvFeeder;
  36. typedef struct YuvFeederListenerArg {
  37. Uint32 currentRow; /* Updated by caller */
  38. Uint32 height; /* Updated by caller */
  39. void* context;
  40. } YuvFeederListenerArg;
  41. typedef void (*YuvFeederListener)(YuvFeederListenerArg*);
  42. typedef enum {
  43. YUV_FEEDER_MODE_NORMAL,
  44. YUV_FEEDER_MODE_THREAD
  45. } YuvFeederMode;
  46. typedef struct SliceNotifyParam {
  47. Uint32 rows;
  48. BOOL notify;
  49. void* arg; /* You can access this variable at YuvFeederListernerArg::arg */
  50. } SliceNotifyParam;
  51. typedef enum {
  52. /* The yuv feeder will notify a client when a slice is filled
  53. * The rows of a slice must be multiple of 8(400,422,444) or 16(420)
  54. * Argument is a pointer value that has the number of height of the slice.
  55. * This command is valid when handle is created with with YUV_FEEDER_MODE_THREAD.
  56. */
  57. YUV_FEEDER_CMD_SET_SLICE_NOTIFY,
  58. } YuvFeederCmd;
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif /* __cplusplus */
  62. typedef struct {
  63. Uint32 width;
  64. Uint32 height;
  65. Uint32 bpp;
  66. BOOL bigEndian;
  67. BOOL lsbJustification; /* Little endian basis */
  68. Uint32 chromaInterleaved; /* 0: planara, 1: semi-planar(NV12, NV16,..), 2: semi-planar(NV21, NV61,...) */
  69. Uint32 packedFormat; /* YUV422: YUYV, UYVY, ... */
  70. FrameFormat format;
  71. } YuvAttr;
  72. typedef void* YuvFeederContext;
  73. struct YuvFeederImpl;
  74. typedef struct {
  75. struct YuvFeederImpl* impl;
  76. void* thread;
  77. BOOL threadStop;
  78. YuvFeederListener listener;
  79. Uint32 fbEndian;
  80. Queue* fbQueue;
  81. Uint32 sliceHeight;
  82. void* sliceNotiCtx;
  83. YuvAttr attr;
  84. } AbstractYuvFeeder;
  85. typedef struct YuvFeederImpl {
  86. void* context;
  87. BOOL (*Create)(AbstractYuvFeeder* feeder, const char* path);
  88. Int32 (*Feed)(AbstractYuvFeeder* feeder, FrameBuffer* fb, Uint32 endian);
  89. BOOL (*Destroy)(AbstractYuvFeeder* feeder);
  90. BOOL (*Configure)(AbstractYuvFeeder* feeder, Uint32 cmd, void* arg);
  91. } YuvFeederImpl;
  92. extern YuvFeeder YuvFeeder_Create(
  93. YuvFeederMode mode,
  94. const char* path,
  95. YuvAttr attr,
  96. Uint32 fbEndian,
  97. YuvFeederListener listener
  98. );
  99. extern BOOL YuvFeeder_Destroy(
  100. YuvFeeder feeder
  101. );
  102. extern BOOL YuvFeeder_Feed(
  103. YuvFeeder feeder,
  104. FrameBuffer* fb
  105. );
  106. extern BOOL YuvFeeder_Configure(
  107. YuvFeeder feeder,
  108. YuvFeederCmd cmd,
  109. void* arg
  110. );
  111. #ifdef __cplusplus
  112. }
  113. #endif /* __cplusplus */
  114. #endif /* __JPU_YUV_FEEDER_H__ */