comparator.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /*
  2. * Copyright (c) 2019, 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. #include <stdarg.h>
  26. #include <string.h>
  27. #include "main_helper.h"
  28. extern ComparatorImpl binComparatorImpl;
  29. extern ComparatorImpl yuvComparatorImpl;
  30. static BOOL NullComparator_Create(
  31. ComparatorImpl* impl,
  32. char* path
  33. )
  34. {
  35. UNREFERENCED_PARAMETER(impl);
  36. UNREFERENCED_PARAMETER(path);
  37. return TRUE;
  38. }
  39. static BOOL NullComparator_Destroy(
  40. ComparatorImpl* impl
  41. )
  42. {
  43. UNREFERENCED_PARAMETER(impl);
  44. return TRUE;
  45. }
  46. static BOOL NullComparator_Compare(
  47. ComparatorImpl* impl,
  48. void* data,
  49. PhysicalAddress size
  50. )
  51. {
  52. UNREFERENCED_PARAMETER(impl);
  53. UNREFERENCED_PARAMETER(data);
  54. UNREFERENCED_PARAMETER(size);
  55. return TRUE;
  56. }
  57. static BOOL NullComparator_Configure(
  58. ComparatorImpl* impl,
  59. ComparatorConfType cmd,
  60. void* val
  61. )
  62. {
  63. UNREFERENCED_PARAMETER(impl);
  64. UNREFERENCED_PARAMETER(cmd);
  65. UNREFERENCED_PARAMETER(val);
  66. return TRUE;
  67. }
  68. static BOOL NullComparator_Rewind(
  69. ComparatorImpl* impl
  70. )
  71. {
  72. UNREFERENCED_PARAMETER(impl);
  73. return TRUE;
  74. }
  75. ComparatorImpl nullComparatorImpl = {
  76. NULL,
  77. NULL,
  78. 0,
  79. 0,
  80. NullComparator_Create,
  81. NullComparator_Destroy,
  82. NullComparator_Compare,
  83. NullComparator_Configure,
  84. NullComparator_Rewind
  85. };
  86. BOOL BinComparator_Create(
  87. ComparatorImpl* impl,
  88. char* path
  89. );
  90. BOOL BinComparator_Destroy(
  91. ComparatorImpl* impl
  92. );
  93. BOOL BinComparator_Compare(
  94. ComparatorImpl* impl,
  95. void* data,
  96. PhysicalAddress size
  97. );
  98. BOOL BinComparator_Configure(
  99. ComparatorImpl* impl,
  100. ComparatorConfType type,
  101. void* val
  102. );
  103. BOOL YUVComparator_Create(
  104. ComparatorImpl* impl,
  105. char* path
  106. );
  107. BOOL YUVComparator_Destroy(
  108. ComparatorImpl* impl
  109. );
  110. BOOL YUVComparator_Compare(
  111. ComparatorImpl* impl,
  112. void* data,
  113. PhysicalAddress size
  114. );
  115. BOOL YUVComparator_Configure(
  116. ComparatorImpl* impl,
  117. ComparatorConfType cmd,
  118. void* val
  119. );
  120. BOOL YUVComparator_Rewind(
  121. ComparatorImpl* impl
  122. );
  123. Comparator Comparator_Create(
  124. Uint32 type,
  125. char* goldenPath,
  126. ...
  127. )
  128. {
  129. /*lint -esym(438, ap) */
  130. AbstractComparator* comp;
  131. ComparatorImpl* impl = NULL;
  132. va_list ap;
  133. BOOL success = FALSE;
  134. char* p;
  135. if (type != NO_COMPARE && goldenPath == NULL) {
  136. VLOG(ERR, "%s:%d golden path is NULL\n", __FUNCTION__, __LINE__);
  137. return NULL;
  138. }
  139. switch (type) {
  140. case NO_COMPARE:
  141. impl = (ComparatorImpl*)osal_malloc(sizeof(ComparatorImpl));
  142. osal_memset((void*)impl, 0x00, sizeof(ComparatorImpl));
  143. impl->Create = NullComparator_Create;
  144. impl->Compare = NullComparator_Compare;
  145. impl->Destroy = NullComparator_Destroy;
  146. impl->Configure = NullComparator_Configure;
  147. impl->Rewind = NullComparator_Rewind;
  148. success = impl->Create(impl, goldenPath);
  149. break;
  150. case YUV_COMPARE:
  151. impl = (ComparatorImpl*)osal_malloc(sizeof(ComparatorImpl));
  152. osal_memset((void*)impl, 0x00, sizeof(ComparatorImpl));
  153. impl->Create = YUVComparator_Create;
  154. impl->Compare = YUVComparator_Compare;
  155. impl->Destroy = YUVComparator_Destroy;
  156. impl->Configure = YUVComparator_Configure;
  157. impl->Rewind = YUVComparator_Rewind;
  158. if ((success=impl->Create(impl, goldenPath)) == TRUE) {
  159. PictureInfo picInfo;
  160. va_start(ap, goldenPath);
  161. picInfo.width = va_arg(ap, Uint32);
  162. picInfo.height = va_arg(ap, Uint32);
  163. picInfo.format = (FrameBufferFormat)va_arg(ap, Uint32);
  164. picInfo.cbcrInterleave = va_arg(ap, BOOL);
  165. picInfo.isVp9 = va_arg(ap, BOOL);
  166. va_end(ap);
  167. impl->Configure(impl, COMPARATOR_CONF_SET_PICINFO, (void*)&picInfo);
  168. }
  169. break;
  170. case STREAM_COMPARE:
  171. impl = osal_malloc(sizeof(ComparatorImpl));
  172. osal_memset((void*)impl, 0x00, sizeof(ComparatorImpl));
  173. impl->Create = BinComparator_Create;
  174. impl->Compare = BinComparator_Compare;
  175. impl->Destroy = BinComparator_Destroy;
  176. impl->Configure = BinComparator_Configure;
  177. impl->filename = (char*)osal_malloc(512);
  178. va_start(ap, goldenPath);
  179. p = va_arg(ap, char*);
  180. va_end(ap);
  181. strcpy(impl->filename, p);
  182. success = impl->Create(impl, goldenPath);
  183. break;
  184. default:
  185. VLOG(ERR, "Invalid comparison type:%d\n", type);
  186. return NULL;
  187. }
  188. if (success == FALSE)
  189. return NULL;
  190. comp = (AbstractComparator*)osal_malloc(sizeof(AbstractComparator));
  191. impl->curIndex = 0;
  192. comp->impl = impl;
  193. comp->totalFrames = impl->numOfFrames;
  194. return comp;
  195. /*lint +esym(438, ap) */
  196. }
  197. BOOL Comparator_Destroy(
  198. Comparator comp
  199. )
  200. {
  201. ComparatorImpl* impl = NULL;
  202. AbstractComparator* absComp = (AbstractComparator*)comp;
  203. if (comp == NULL) {
  204. VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
  205. return FALSE;
  206. }
  207. impl = absComp->impl;
  208. if (impl->filename) osal_free(impl->filename);
  209. impl->Destroy(impl);
  210. osal_free(impl);
  211. osal_free(comp);
  212. return TRUE;
  213. }
  214. BOOL Comparator_Act(
  215. Comparator comp,
  216. void* data,
  217. Uint32 size
  218. )
  219. {
  220. ComparatorImpl* impl = NULL;
  221. AbstractComparator* absComp = (AbstractComparator*)comp;
  222. if (comp == NULL) {
  223. VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
  224. return FALSE;
  225. }
  226. impl = absComp->impl;
  227. impl->curIndex++;
  228. if (impl->usePrevDataOneTime == TRUE)
  229. impl->curIndex--;
  230. return impl->Compare(impl, data, size);
  231. }
  232. BOOL Comparator_CheckFrameCount(
  233. Comparator comp
  234. )
  235. {
  236. ComparatorImpl* impl = NULL;
  237. AbstractComparator* absComp = (AbstractComparator*)comp;
  238. BOOL match = TRUE;
  239. if (absComp == NULL) {
  240. VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
  241. return FALSE;
  242. }
  243. impl = absComp->impl;
  244. if (impl->curIndex != absComp->totalFrames) {
  245. VLOG(ERR, "MISMATCH FRAME COUNT: GOLDEN(%d) DECODED(%d)\n",
  246. impl->numOfFrames, impl->curIndex);
  247. match = FALSE;
  248. }
  249. return match;
  250. }
  251. Uint32 Comparator_GetFrameCount(
  252. Comparator comp
  253. )
  254. {
  255. ComparatorImpl* impl = NULL;
  256. AbstractComparator* absComp = (AbstractComparator*)comp;
  257. if (absComp == NULL) {
  258. VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
  259. return FALSE;
  260. }
  261. impl = absComp->impl;
  262. return impl->numOfFrames;
  263. }
  264. /* \brief When scan mode is enable, Comparator_Act() tries to find data matched with decoded result
  265. * by scanning all data
  266. */
  267. BOOL Comparator_SetScanMode(
  268. Comparator comp,
  269. BOOL enable
  270. )
  271. {
  272. AbstractComparator* absComp = (AbstractComparator*)comp;
  273. ComparatorImpl* impl = NULL;
  274. if (absComp == NULL) {
  275. return FALSE;
  276. }
  277. impl = absComp->impl;
  278. impl->enableScanMode = enable;
  279. return TRUE;
  280. }
  281. BOOL Comparator_Rewind(
  282. Comparator comp
  283. )
  284. {
  285. AbstractComparator* absComp = (AbstractComparator*)comp;
  286. ComparatorImpl* impl = NULL;
  287. if (absComp == NULL) {
  288. return FALSE;
  289. }
  290. impl = absComp->impl;
  291. absComp->totalFrames += impl->numOfFrames;
  292. return impl->Rewind(impl);
  293. }
  294. BOOL Comparator_CheckEOF(
  295. Comparator comp
  296. )
  297. {
  298. ComparatorImpl* impl = NULL;
  299. AbstractComparator* absComp = (AbstractComparator*)comp;
  300. BOOL match = TRUE;
  301. if (comp == NULL) {
  302. VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
  303. return FALSE;
  304. }
  305. impl = absComp->impl;
  306. if (impl->eof == FALSE) {
  307. VLOG(ERR, "It is not the end of file.\n");
  308. match = FALSE;
  309. }
  310. return match;
  311. }
  312. BOOL Comparator_Configure(
  313. Comparator comp,
  314. ComparatorConfType cmd,
  315. void* val
  316. )
  317. {
  318. ComparatorImpl* impl = NULL;
  319. AbstractComparator* absComp = (AbstractComparator*)comp;
  320. if (comp == NULL) {
  321. VLOG(ERR, "%s:%d Invalid handle\n", __FUNCTION__, __LINE__);
  322. return FALSE;
  323. }
  324. impl = absComp->impl;
  325. impl->Configure(impl, cmd, val);
  326. return TRUE;
  327. }