comparator.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. // SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause
  2. //--=========================================================================--
  3. // This file is a part of VPU Reference API project
  4. //-----------------------------------------------------------------------------
  5. //
  6. // This confidential and proprietary software may be used only
  7. // as authorized by a licensing agreement from Chips&Media Inc.
  8. // In the event of publication, the following notice is applicable:
  9. //
  10. // (C) COPYRIGHT CHIPS&MEDIA INC.
  11. // ALL RIGHTS RESERVED
  12. //
  13. // The entire notice above must be reproduced on all authorized
  14. // copies.
  15. //
  16. //--=========================================================================--
  17. #include <stdarg.h>
  18. #include "main_helper.h"
  19. #include "../misc/skip.h"
  20. extern ComparatorImpl binComparatorImpl;
  21. extern ComparatorImpl yuvComparatorImpl;
  22. static BOOL NullComparator_Create(
  23. ComparatorImpl* impl,
  24. char* path
  25. )
  26. {
  27. UNREFERENCED_PARAMETER(impl);
  28. UNREFERENCED_PARAMETER(path);
  29. return TRUE;
  30. }
  31. static BOOL NullComparator_Destroy(
  32. ComparatorImpl* impl
  33. )
  34. {
  35. UNREFERENCED_PARAMETER(impl);
  36. return TRUE;
  37. }
  38. static BOOL NullComparator_Compare(
  39. ComparatorImpl* impl,
  40. void* data,
  41. Uint32 size
  42. )
  43. {
  44. UNREFERENCED_PARAMETER(impl);
  45. UNREFERENCED_PARAMETER(data);
  46. UNREFERENCED_PARAMETER(size);
  47. return TRUE;
  48. }
  49. static BOOL NullComparator_Configure(
  50. ComparatorImpl* impl,
  51. ComparatorConfType cmd,
  52. void* val
  53. )
  54. {
  55. UNREFERENCED_PARAMETER(impl);
  56. UNREFERENCED_PARAMETER(cmd);
  57. UNREFERENCED_PARAMETER(val);
  58. return TRUE;
  59. }
  60. static BOOL NullComparator_Rewind(
  61. ComparatorImpl* impl
  62. )
  63. {
  64. UNREFERENCED_PARAMETER(impl);
  65. return TRUE;
  66. }
  67. ComparatorImpl nullComparatorImpl = {
  68. NULL,
  69. NULL,
  70. 0,
  71. 0,
  72. NullComparator_Create,
  73. NullComparator_Destroy,
  74. NullComparator_Compare,
  75. NullComparator_Configure,
  76. NullComparator_Rewind
  77. };
  78. BOOL BinComparator_Create(
  79. ComparatorImpl* impl,
  80. char* path
  81. );
  82. BOOL BinComparator_Destroy(
  83. ComparatorImpl* impl
  84. );
  85. BOOL BinComparator_Compare(
  86. ComparatorImpl* impl,
  87. void* data,
  88. Uint32 size
  89. );
  90. BOOL BinComparator_Configure(
  91. ComparatorImpl* impl,
  92. ComparatorConfType type,
  93. void* val
  94. );
  95. BOOL YUVComparator_Create(
  96. ComparatorImpl* impl,
  97. char* path
  98. );
  99. BOOL YUVComparator_Destroy(
  100. ComparatorImpl* impl
  101. );
  102. BOOL YUVComparator_Compare(
  103. ComparatorImpl* impl,
  104. void* data,
  105. Uint32 size
  106. );
  107. BOOL YUVComparator_Configure(
  108. ComparatorImpl* impl,
  109. ComparatorConfType cmd,
  110. void* val
  111. );
  112. BOOL YUVComparator_Rewind(
  113. ComparatorImpl* impl
  114. );
  115. Comparator Comparator_Create(
  116. Uint32 type,
  117. char* goldenPath,
  118. ...
  119. )
  120. {
  121. /*lint -esym(438, ap) */
  122. AbstractComparator* comp;
  123. ComparatorImpl* impl = NULL;
  124. va_list ap;
  125. BOOL success = FALSE;
  126. if (type != NO_COMPARE && goldenPath == NULL) {
  127. VLOG(ERR, "%s:%d golden path is NULL\n", __FUNCTION__, __LINE__);
  128. return NULL;
  129. }
  130. switch (type) {
  131. case NO_COMPARE:
  132. impl = (ComparatorImpl*)osal_malloc(sizeof(ComparatorImpl));
  133. osal_memset((void*)impl, 0x00, sizeof(ComparatorImpl));
  134. impl->Create = NullComparator_Create;
  135. impl->Compare = NullComparator_Compare;
  136. impl->Destroy = NullComparator_Destroy;
  137. impl->Configure = NullComparator_Configure;
  138. impl->Rewind = NullComparator_Rewind;
  139. success = impl->Create(impl, goldenPath);
  140. break;
  141. case YUV_COMPARE:
  142. impl = (ComparatorImpl*)osal_malloc(sizeof(ComparatorImpl));
  143. osal_memset((void*)impl, 0x00, sizeof(ComparatorImpl));
  144. impl->Create = YUVComparator_Create;
  145. impl->Compare = YUVComparator_Compare;
  146. impl->Destroy = YUVComparator_Destroy;
  147. impl->Configure = YUVComparator_Configure;
  148. impl->Rewind = YUVComparator_Rewind;
  149. if ((success=impl->Create(impl, goldenPath)) == TRUE) {
  150. PictureInfo picInfo;
  151. va_start(ap, goldenPath);
  152. picInfo.width = va_arg(ap, Uint32);
  153. picInfo.height = va_arg(ap, Uint32);
  154. picInfo.format = (FrameBufferFormat)va_arg(ap, Uint32);
  155. picInfo.cbcrInterleave = va_arg(ap, BOOL);
  156. picInfo.isVp9 = va_arg(ap, BOOL);
  157. va_end(ap);
  158. impl->Configure(impl, COMPARATOR_CONF_SET_PICINFO, (void*)&picInfo);
  159. }
  160. break;
  161. case STREAM_COMPARE:
  162. impl = osal_malloc(sizeof(ComparatorImpl));
  163. osal_memset((void*)impl, 0x00, sizeof(ComparatorImpl));
  164. impl->Create = &BinComparator_Create;
  165. impl->Compare = &BinComparator_Compare;
  166. impl->Destroy = &BinComparator_Destroy;
  167. impl->Configure = &BinComparator_Configure;
  168. va_start(ap, goldenPath);
  169. impl->filename = va_arg(ap, char*);
  170. va_end(ap);
  171. success = impl->Create(impl, goldenPath);
  172. break;
  173. default:
  174. VLOG(ERR, "Invalid comparison type:%d\n", type);
  175. return NULL;
  176. }
  177. if (success == FALSE)
  178. return NULL;
  179. comp = (AbstractComparator*)osal_malloc(sizeof(AbstractComparator));
  180. impl->curIndex = 0;
  181. comp->impl = impl;
  182. comp->totalFrames = impl->numOfFrames;
  183. return comp;
  184. /*lint +esym(438, ap) */
  185. }
  186. BOOL Comparator_Destroy(
  187. Comparator comp
  188. )
  189. {
  190. ComparatorImpl* impl = NULL;
  191. AbstractComparator* absComp = (AbstractComparator*)comp;
  192. if (comp == NULL) {
  193. VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
  194. return FALSE;
  195. }
  196. impl = absComp->impl;
  197. impl->Destroy(impl);
  198. osal_free(impl);
  199. return TRUE;
  200. }
  201. BOOL Comparator_Act(
  202. Comparator comp,
  203. void* data,
  204. Uint32 size
  205. )
  206. {
  207. ComparatorImpl* impl = NULL;
  208. AbstractComparator* absComp = (AbstractComparator*)comp;
  209. if (comp == NULL) {
  210. VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
  211. return FALSE;
  212. }
  213. impl = absComp->impl;
  214. impl->curIndex++;
  215. if (impl->usePrevDataOneTime == TRUE)
  216. impl->curIndex--;
  217. return impl->Compare(impl, data, size);
  218. }
  219. BOOL Comparator_CheckFrameCount(
  220. Comparator comp
  221. )
  222. {
  223. ComparatorImpl* impl = NULL;
  224. AbstractComparator* absComp = (AbstractComparator*)comp;
  225. BOOL match = TRUE;
  226. if (comp == NULL) {
  227. VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
  228. return FALSE;
  229. }
  230. impl = absComp->impl;
  231. if (impl->curIndex != absComp->totalFrames) {
  232. VLOG(ERR, "MISMATCH FRAME COUNT: GOLDEN(%d) DECODED(%d)\n",
  233. impl->numOfFrames, impl->curIndex);
  234. match = FALSE;
  235. }
  236. return match;
  237. }
  238. /* \brief When scan mode is enable, Comparator_Act() tries to find data matched with decoded result
  239. * by scanning all data
  240. */
  241. BOOL Comparator_SetScanMode(
  242. Comparator comp,
  243. BOOL enable
  244. )
  245. {
  246. AbstractComparator* absComp = (AbstractComparator*)comp;
  247. ComparatorImpl* impl = NULL;
  248. if (absComp == NULL) {
  249. return FALSE;
  250. }
  251. impl = absComp->impl;
  252. impl->enableScanMode = enable;
  253. return TRUE;
  254. }
  255. BOOL Comparator_Rewind(
  256. Comparator comp
  257. )
  258. {
  259. AbstractComparator* absComp = (AbstractComparator*)comp;
  260. ComparatorImpl* impl = NULL;
  261. if (absComp == NULL) {
  262. return FALSE;
  263. }
  264. impl = absComp->impl;
  265. absComp->totalFrames += impl->numOfFrames;
  266. return impl->Rewind(impl);
  267. }
  268. BOOL Comparator_CheckEOF(
  269. Comparator comp
  270. )
  271. {
  272. ComparatorImpl* impl = NULL;
  273. AbstractComparator* absComp = (AbstractComparator*)comp;
  274. BOOL match = TRUE;
  275. if (comp == NULL) {
  276. VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
  277. return FALSE;
  278. }
  279. impl = absComp->impl;
  280. if (impl->eof == FALSE) {
  281. VLOG(ERR, "It is not the end of file.\n");
  282. match = FALSE;
  283. }
  284. return match;
  285. }