1. //解析.cfg文件
    2. static void app_parse_cfg_file(AppObj *obj, vx_char *cfg_file_name)
    3. {
    4. FILE *fp = fopen(cfg_file_name, "r");
    5. vx_char line_str[1024];
    6. vx_char *token;
    7. if(fp==NULL)
    8. {
    9. printf("# ERROR: Unable to open config file [%s]\n", cfg_file_name);
    10. exit(0);
    11. }
    12. while(fgets(line_str, sizeof(line_str), fp)!=NULL)
    13. {
    14. vx_char s[]=" \t";
    15. if (strchr(line_str, '#'))
    16. {
    17. continue;
    18. }
    19. /* get the first token */
    20. token = strtok(line_str, s);
    21. if(token != NULL)
    22. {
    23. if(strcmp(token, "tidl_config")==0)
    24. {
    25. token = strtok(NULL, s);
    26. if(token != NULL)
    27. {
    28. token[strlen(token)-1]=0;
    29. strcpy(obj->tidlObj.config_file_path, token);
    30. }
    31. }
    32. else
    33. if(strcmp(token, "tidl_network")==0)
    34. {
    35. token = strtok(NULL, s);
    36. if(token != NULL)
    37. {
    38. token[strlen(token)-1]=0;
    39. strcpy(obj->tidlObj.network_file_path, token);
    40. /* for testing if relevant */
    41. if(strstr(obj->tidlObj.network_file_path, "u16") != NULL)
    42. {
    43. obj->test_case = 1;
    44. }
    45. else
    46. {
    47. obj->test_case = 0;
    48. }
    49. }
    50. }
    51. else
    52. if(strcmp(token, "input_file_path")==0)
    53. {
    54. token = strtok(NULL, s);
    55. if(token != NULL)
    56. {
    57. token[strlen(token)-1]=0;
    58. strcpy(obj->input_file_path, token);
    59. }
    60. }
    61. else
    62. if(strcmp(token, "output_file_path")==0)
    63. {
    64. token = strtok(NULL, s);
    65. if(token != NULL)
    66. {
    67. token[strlen(token)-1]=0;
    68. strcpy(obj->output_file_path, token);
    69. }
    70. }
    71. else
    72. if(strcmp(token, "start_frame")==0)
    73. {
    74. token = strtok(NULL, s);
    75. if(token != NULL)
    76. {
    77. obj->start_frame = atoi(token);
    78. }
    79. }
    80. else
    81. if(strcmp(token, "num_frames")==0)
    82. {
    83. token = strtok(NULL, s);
    84. if(token != NULL)
    85. {
    86. obj->num_frames = atoi(token);
    87. }
    88. }
    89. else
    90. if(strcmp(token, "in_size")==0)
    91. {
    92. vx_int32 width, height;
    93. token = strtok(NULL, s);
    94. if(token != NULL)
    95. {
    96. width = atoi(token);
    97. obj->scalerObj.input.width = width;
    98. token = strtok(NULL, s);
    99. if(token != NULL)
    100. {
    101. if (token[strlen(token)-1] == '\n')
    102. token[strlen(token)-1]=0;
    103. height = atoi(token);
    104. obj->scalerObj.input.height = height;
    105. }
    106. }
    107. }
    108. else
    109. if(strcmp(token, "dl_size")==0)
    110. {
    111. vx_int32 width, height;
    112. token = strtok(NULL, s);
    113. if(token != NULL)
    114. {
    115. width = atoi(token);
    116. obj->scalerObj.output1.width = width;
    117. token = strtok(NULL, s);
    118. if(token != NULL)
    119. {
    120. if(token[strlen(token)-1] == '\n')
    121. token[strlen(token)-1]=0;
    122. height = atoi(token);
    123. obj->scalerObj.output1.height = height;
    124. }
    125. }
    126. }
    127. else
    128. if(strcmp(token, "out_size")==0)
    129. {
    130. vx_int32 width, height;
    131. token = strtok(NULL, s);
    132. if(token != NULL)
    133. {
    134. width = atoi(token);
    135. obj->scalerObj.output2.width = width;
    136. token = strtok(NULL, s);
    137. if(token != NULL)
    138. {
    139. if(token[strlen(token)-1] == '\n')
    140. token[strlen(token)-1]=0;
    141. height = atoi(token);
    142. obj->scalerObj.output2.height = height;
    143. }
    144. }
    145. }
    146. else
    147. if(strcmp(token, "num_classes")==0)
    148. {
    149. token = strtok(NULL, s);
    150. if(token != NULL)
    151. {
    152. obj->postProcObj.viz_params.num_classes[0] = atoi(token);
    153. }
    154. }
    155. else
    156. if(strcmp(token, "en_out_img_write")==0)
    157. {
    158. token = strtok(NULL, s);
    159. if(token != NULL)
    160. {
    161. obj->en_out_img_write = atoi(token);
    162. }
    163. }
    164. else
    165. if(strcmp(token, "display_option")==0)
    166. {
    167. token = strtok(NULL, s);
    168. if(token != NULL)
    169. {
    170. obj->displayObj.display_option = atoi(token);
    171. }
    172. }
    173. else
    174. if(strcmp(token, "delay_in_msecs")==0)
    175. {
    176. token = strtok(NULL, s);
    177. if(token != NULL)
    178. {
    179. token[strlen(token)-1]=0;
    180. obj->delay_in_msecs = atoi(token);
    181. if(obj->delay_in_msecs > 2000)
    182. obj->delay_in_msecs = 2000;
    183. }
    184. }
    185. else
    186. if(strcmp(token, "num_iterations")==0)
    187. {
    188. token = strtok(NULL, s);
    189. if(token != NULL)
    190. {
    191. token[strlen(token)-1]=0;
    192. obj->num_iterations = atoi(token);
    193. if(obj->num_iterations == 0)
    194. obj->num_iterations = 1;
    195. }
    196. }
    197. else
    198. if(strcmp(token, "is_interactive")==0)
    199. {
    200. token = strtok(NULL, s);
    201. if(token != NULL)
    202. {
    203. token[strlen(token)-1]=0;
    204. obj->is_interactive = atoi(token);
    205. if(obj->is_interactive > 1)
    206. obj->is_interactive = 1;
    207. }
    208. }
    209. }
    210. }
    211. fclose(fp);
    212. }