main_multi_instance_test.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. #include <stdio.h>
  26. #include <stdint.h>
  27. #include <string.h>
  28. #include <time.h>
  29. #include <getopt.h>
  30. #include "main_helper.h"
  31. #include "jpulog.h"
  32. #include "cnm_fpga.h"
  33. #ifdef PLATFORM_LINUX
  34. #include <pthread.h>
  35. #include <unistd.h>
  36. #endif
  37. #ifdef PLATFORM_NON_OS
  38. #error "Not support multi-instance test in non-os platform"
  39. #endif
  40. extern BOOL TestDecoder(DecConfigParam *param);
  41. extern BOOL TestEncoder(EncConfigParam *param);
  42. #define CFG_DIR "./cfg"
  43. #define YUV_DIR "./yuv"
  44. static void Help(const char *programName)
  45. {
  46. JLOG(INFO, "------------------------------------------------------------------------------\n");
  47. JLOG(INFO, " CODAJ12 Multi Instance test\n");
  48. JLOG(INFO, "\tAll rights reserved by Chips&Media(C)\n");
  49. JLOG(INFO, "\tSample program controlling the Chips&Media VPU\n");
  50. JLOG(INFO, "------------------------------------------------------------------------------\n");
  51. JLOG(INFO, "%s [option] --input <stream list file, aka cmd file>\n", programName);
  52. JLOG(INFO, "-h help\n");
  53. JLOG(INFO, "-v print version information\n");
  54. JLOG(INFO, "-f conformance test without reset CNM FPGA\n");
  55. JLOG(INFO, "--input bitstream(decoder) or cfg(encoder) path\n");
  56. JLOG(INFO, "--output yuv(decoder) or bitstream(encoder) path\n");
  57. JLOG(INFO, "--enable-sync sync control by a user\n");
  58. }
  59. static void SetDecDefaultValues(DecConfigParam* decCfg)
  60. {
  61. if (decCfg->bsSize == 0) {
  62. decCfg->bsSize = 2*1024*1024;
  63. }
  64. }
  65. static void SetEncDefaultValues(EncConfigParam* encCfg)
  66. {
  67. if (strstr(encCfg->cfgFileName, "12b")) {
  68. encCfg->extendedSequential = 1;
  69. }
  70. else {
  71. encCfg->extendedSequential = 0;
  72. }
  73. if (strstr(encCfg->cfgFileName, "_tiled")) {
  74. encCfg->tiledModeEnable = TRUE;
  75. }
  76. else {
  77. encCfg->tiledModeEnable = FALSE;
  78. }
  79. encCfg->bsSize = 2*1024*1024;
  80. if (strlen(encCfg->strCfgDir) == 0) {
  81. strcpy(encCfg->strCfgDir, CFG_DIR);
  82. }
  83. if (strlen(encCfg->strYuvDir) == 0) {
  84. strcpy(encCfg->strYuvDir, YUV_DIR);
  85. }
  86. }
  87. static Int32 MultiInstanceTest(TestMultiConfig* multiConfig)
  88. {
  89. Int32 result = 0; // success = 0
  90. Uint32 i = 0;
  91. pthread_t thread_id[MAX_NUM_INSTANCE];
  92. void* ret[MAX_NUM_INSTANCE];
  93. for (i=0; i<multiConfig->numInstances; i++) {
  94. switch (multiConfig->type[i]) {
  95. case JPU_DECODER:
  96. pthread_create(&thread_id[i], NULL, (void*)TestDecoder, (void*)&multiConfig->u[i].decConfig);
  97. break;
  98. case JPU_ENCODER:
  99. pthread_create(&thread_id[i], NULL, (void*)TestEncoder, (void*)&multiConfig->u[i].encConfig);
  100. break;
  101. default:
  102. JLOG(INFO, "<%s:%d> Unknown type: %d\n", __FUNCTION__, __LINE__, multiConfig->type[i]);
  103. break;
  104. }
  105. usleep(10 * 1000);
  106. }
  107. for (i=0; i < multiConfig->numInstances; i++) {
  108. pthread_join(thread_id[i], &ret[i]);
  109. }
  110. for (i=0; i < multiConfig->numInstances; i++) {
  111. printf("thread return = %ld\n", (intptr_t)ret[i]);
  112. if ((intptr_t)ret[i] != 1) { // success = 1
  113. result = 1;
  114. }
  115. }
  116. return result;
  117. }
  118. int main(int argc, char **argv)
  119. {
  120. TestMultiConfig multiConfig;
  121. Int32 opt, i;
  122. int l;
  123. char* tempArg;
  124. char* optString = "e:h";
  125. struct option options[] = {
  126. /* -------------------- common ------------------- */
  127. { "aclk", required_argument, NULL, 0 }, /* single parameter */
  128. { "cclk", required_argument, NULL, 0 }, /* single parameter */
  129. { "rdelay", required_argument, NULL, 0 }, /* single parameter */
  130. { "wdelay", required_argument, NULL, 0 }, /* single parameter */
  131. { "instance-num", required_argument, NULL, 0 }, /* single parameter */
  132. { "cfg-dir", required_argument, NULL, 0 }, /* single parameter for encoder */
  133. { "yuv-dir", required_argument, NULL, 0 }, /* single parameter for encoder */
  134. { "input", required_argument, NULL, 0 },
  135. { "output", required_argument, NULL, 0 },
  136. { "stream-endian", required_argument, NULL, 0 },
  137. { "frame-endian", required_argument, NULL, 0 },
  138. { "pixelj", required_argument, NULL, 0 },
  139. { "bs-size", required_argument, NULL, 0 },
  140. /* -------------------- decoder ------------------- */
  141. { "format", required_argument, NULL, 0 },
  142. { "rotation", required_argument, NULL, 0 },
  143. { "mirror", required_argument, NULL, 0 },
  144. /* -------------------- encoder --------------------*/
  145. { "slice-height", required_argument, NULL, 0 },
  146. { "enable-slice-intr", required_argument, NULL, 0 },
  147. { "enable-tiledMode", required_argument, NULL, 0 },
  148. { NULL, 0, NULL, 0 },
  149. };
  150. memset((void*)&multiConfig, 0x00, sizeof(multiConfig));
  151. for(i = 0; i < MAX_NUM_INSTANCE; i++) {
  152. multiConfig.type[i] = JPU_NONE;
  153. multiConfig.u[i].decConfig.subsample = FORMAT_MAX;
  154. }
  155. multiConfig.devConfig.aclk = ACLK_MIN;
  156. multiConfig.devConfig.cclk = CCLK_MIN;
  157. while ((opt=getopt_long(argc, argv, optString, options, &l)) != -1) {
  158. switch (opt) {
  159. case 'e':
  160. tempArg = strtok(optarg, ",");
  161. for(i = 0; i < MAX_NUM_INSTANCE; i++) {
  162. multiConfig.type[i] = (JPUComponentType)atoi(tempArg);
  163. tempArg = strtok(NULL, ",");
  164. if (tempArg == NULL)
  165. break;
  166. }
  167. break;
  168. case 'h':
  169. Help(argv[0]);
  170. return 0;
  171. case 0:
  172. if (ParseMultiLongOptions(&multiConfig, options[l].name, optarg) == FALSE) {
  173. Help(argv[0]);
  174. return 0;
  175. }
  176. break;
  177. default:
  178. JLOG(ERR, "%s\n", optarg);
  179. return 1;
  180. }
  181. }
  182. for (i = 0; i < multiConfig.numInstances; i++) {
  183. if (multiConfig.type[i] == JPU_DECODER) {
  184. SetDecDefaultValues(&multiConfig.u[i].decConfig);
  185. }
  186. else if (multiConfig.type[i] == JPU_ENCODER) {
  187. SetEncDefaultValues(&multiConfig.u[i].encConfig);
  188. }
  189. else {
  190. JLOG(ERR, "%s:%d Unknown type: %d\n", __FUNCTION__, __LINE__, multiConfig.type[i]);
  191. }
  192. }
  193. InitLog("ErrorLog.txt");
  194. JPU_Init();
  195. if (MultiInstanceTest(&multiConfig) != 0) {
  196. JLOG(ERR, "Failed to MultiInstanceTest()\n");
  197. DeInitLog();
  198. return 1;
  199. }
  200. JPU_DeInit();
  201. return 0;
  202. }