main_multi_instance_test.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause
  2. /*
  3. * Copyright (c) 2018, Chips&Media
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <stdio.h>
  27. #include <stdint.h>
  28. #include <string.h>
  29. #include <time.h>
  30. #include <getopt.h>
  31. #include "main_helper.h"
  32. #include "jpulog.h"
  33. #include "cnm_fpga.h"
  34. #ifdef PLATFORM_LINUX
  35. #include <pthread.h>
  36. #include <unistd.h>
  37. #endif
  38. #ifdef PLATFORM_NON_OS
  39. #error "Not support multi-instance test in non-os platform"
  40. #endif
  41. extern BOOL TestDecoder(DecConfigParam *param);
  42. extern BOOL TestEncoder(EncConfigParam *param);
  43. #define CFG_DIR "./cfg"
  44. #define YUV_DIR "./yuv"
  45. static void Help(const char *programName)
  46. {
  47. JLOG(INFO, "------------------------------------------------------------------------------\n");
  48. JLOG(INFO, " CODAJ12 Multi Instance test\n");
  49. JLOG(INFO, "\tAll rights reserved by Chips&Media(C)\n");
  50. JLOG(INFO, "\tSample program controlling the Chips&Media VPU\n");
  51. JLOG(INFO, "------------------------------------------------------------------------------\n");
  52. JLOG(INFO, "%s [option] --input <stream list file, aka cmd file>\n", programName);
  53. JLOG(INFO, "-h help\n");
  54. JLOG(INFO, "-v print version information\n");
  55. JLOG(INFO, "-f conformance test without reset CNM FPGA\n");
  56. JLOG(INFO, "--input bitstream(decoder) or cfg(encoder) path\n");
  57. JLOG(INFO, "--output yuv(decoder) or bitstream(encoder) path\n");
  58. JLOG(INFO, "--enable-sync sync control by a user\n");
  59. }
  60. static void SetDecDefaultValues(DecConfigParam* decCfg)
  61. {
  62. if (decCfg->bsSize == 0) {
  63. decCfg->bsSize = 2*1024*1024;
  64. }
  65. }
  66. static void SetEncDefaultValues(EncConfigParam* encCfg)
  67. {
  68. if (strstr(encCfg->cfgFileName, "12b")) {
  69. encCfg->extendedSequential = 1;
  70. }
  71. else {
  72. encCfg->extendedSequential = 0;
  73. }
  74. if (strstr(encCfg->cfgFileName, "_tiled")) {
  75. encCfg->tiledModeEnable = TRUE;
  76. }
  77. else {
  78. encCfg->tiledModeEnable = FALSE;
  79. }
  80. encCfg->bsSize = 2*1024*1024;
  81. if (strlen(encCfg->strCfgDir) == 0) {
  82. strcpy(encCfg->strCfgDir, CFG_DIR);
  83. }
  84. if (strlen(encCfg->strYuvDir) == 0) {
  85. strcpy(encCfg->strYuvDir, YUV_DIR);
  86. }
  87. }
  88. static Int32 MultiInstanceTest(TestMultiConfig* multiConfig)
  89. {
  90. Int32 result = 0; // success = 0
  91. Uint32 i = 0;
  92. pthread_t thread_id[MAX_NUM_INSTANCE];
  93. void* ret[MAX_NUM_INSTANCE];
  94. for (i=0; i<multiConfig->numInstances; i++) {
  95. switch (multiConfig->type[i]) {
  96. case JPU_DECODER:
  97. pthread_create(&thread_id[i], NULL, (void*)TestDecoder, (void*)&multiConfig->u[i].decConfig);
  98. break;
  99. case JPU_ENCODER:
  100. pthread_create(&thread_id[i], NULL, (void*)TestEncoder, (void*)&multiConfig->u[i].encConfig);
  101. break;
  102. default:
  103. JLOG(INFO, "<%s:%d> Unknown type: %d\n", __FUNCTION__, __LINE__, multiConfig->type[i]);
  104. break;
  105. }
  106. usleep(10 * 1000);
  107. }
  108. for (i=0; i < multiConfig->numInstances; i++) {
  109. pthread_join(thread_id[i], &ret[i]);
  110. }
  111. for (i=0; i < multiConfig->numInstances; i++) {
  112. printf("thread return = %ld\n", (intptr_t)ret[i]);
  113. if ((intptr_t)ret[i] != 1) { // success = 1
  114. result = 1;
  115. }
  116. }
  117. return result;
  118. }
  119. int main(int argc, char **argv)
  120. {
  121. TestMultiConfig multiConfig;
  122. Int32 opt, i;
  123. int l;
  124. char* tempArg;
  125. char* optString = "e:h";
  126. struct option options[] = {
  127. /* -------------------- common ------------------- */
  128. { "aclk", required_argument, NULL, 0 }, /* single parameter */
  129. { "cclk", required_argument, NULL, 0 }, /* single parameter */
  130. { "rdelay", required_argument, NULL, 0 }, /* single parameter */
  131. { "wdelay", required_argument, NULL, 0 }, /* single parameter */
  132. { "instance-num", required_argument, NULL, 0 }, /* single parameter */
  133. { "cfg-dir", required_argument, NULL, 0 }, /* single parameter for encoder */
  134. { "yuv-dir", required_argument, NULL, 0 }, /* single parameter for encoder */
  135. { "input", required_argument, NULL, 0 },
  136. { "output", required_argument, NULL, 0 },
  137. { "stream-endian", required_argument, NULL, 0 },
  138. { "frame-endian", required_argument, NULL, 0 },
  139. { "pixelj", required_argument, NULL, 0 },
  140. { "bs-size", required_argument, NULL, 0 },
  141. /* -------------------- decoder ------------------- */
  142. { "format", required_argument, NULL, 0 },
  143. { "rotation", required_argument, NULL, 0 },
  144. { "mirror", required_argument, NULL, 0 },
  145. /* -------------------- encoder --------------------*/
  146. { "slice-height", required_argument, NULL, 0 },
  147. { "enable-slice-intr", required_argument, NULL, 0 },
  148. { "enable-tiledMode", required_argument, NULL, 0 },
  149. { NULL, 0, NULL, 0 },
  150. };
  151. memset((void*)&multiConfig, 0x00, sizeof(multiConfig));
  152. for(i = 0; i < MAX_NUM_INSTANCE; i++) {
  153. multiConfig.type[i] = JPU_NONE;
  154. multiConfig.u[i].decConfig.subsample = FORMAT_MAX;
  155. }
  156. multiConfig.devConfig.aclk = ACLK_MIN;
  157. multiConfig.devConfig.cclk = CCLK_MIN;
  158. while ((opt=getopt_long(argc, argv, optString, options, &l)) != -1) {
  159. switch (opt) {
  160. case 'e':
  161. tempArg = strtok(optarg, ",");
  162. for(i = 0; i < MAX_NUM_INSTANCE; i++) {
  163. multiConfig.type[i] = (JPUComponentType)atoi(tempArg);
  164. tempArg = strtok(NULL, ",");
  165. if (tempArg == NULL)
  166. break;
  167. }
  168. break;
  169. case 'h':
  170. Help(argv[0]);
  171. return 0;
  172. case 0:
  173. if (ParseMultiLongOptions(&multiConfig, options[l].name, optarg) == FALSE) {
  174. Help(argv[0]);
  175. return 0;
  176. }
  177. break;
  178. default:
  179. JLOG(ERR, "%s\n", optarg);
  180. return 1;
  181. }
  182. }
  183. for (i = 0; i < multiConfig.numInstances; i++) {
  184. if (multiConfig.type[i] == JPU_DECODER) {
  185. SetDecDefaultValues(&multiConfig.u[i].decConfig);
  186. }
  187. else if (multiConfig.type[i] == JPU_ENCODER) {
  188. SetEncDefaultValues(&multiConfig.u[i].encConfig);
  189. }
  190. else {
  191. JLOG(ERR, "%s:%d Unknown type: %d\n", __FUNCTION__, __LINE__, multiConfig.type[i]);
  192. }
  193. }
  194. InitLog("ErrorLog.txt");
  195. JPU_Init();
  196. if (MultiInstanceTest(&multiConfig) != 0) {
  197. JLOG(ERR, "Failed to MultiInstanceTest()\n");
  198. DeInitLog();
  199. return 1;
  200. }
  201. JPU_DeInit();
  202. return 0;
  203. }