📄 main.c
字号:
if (envp->videoAlg == MPEG4) { argv[3] = malloc(strlen("data/videos/demo.mpeg4") + 1); if (argv[3] == NULL) { return FAILURE; } strcpy(argv[3], "data/videos/demo.mpeg4"); argv[4] = malloc(strlen("-s") + 1); if (argv[4] == NULL) { return FAILURE; } strcpy(argv[4], "-s"); argv[5] = malloc(strlen("data/sounds/demompeg4.g711") + 1); if (argv[5] == NULL) { return FAILURE; } strcpy(argv[5], "data/sounds/demompeg4.g711"); } else { argv[3] = malloc(strlen("data/videos/demo.264") + 1); if (argv[3] == NULL) { return FAILURE; } strcpy(argv[3], "data/videos/demo.264"); argv[4] = malloc(strlen("-s") + 1); if (argv[4] == NULL) { return FAILURE; } strcpy(argv[4], "-s"); argv[5] = malloc(strlen("data/sounds/demo264.g711") + 1); if (argv[5] == NULL) { return FAILURE; } strcpy(argv[5], "data/sounds/demo264.g711"); } argv[6] = malloc(strlen("-b") + 1); if (argv[6] == NULL) { return FAILURE; } strcpy(argv[6], "-b"); if (envp->videoBps == HIGH) { argv[7] = malloc(strlen("4194304") + 1); // 4M bits/s if (argv[7] == NULL) { return FAILURE; } strcpy(argv[7], "4194304"); } else { argv[7] = malloc(strlen("1572864" + 1)); // 1.5M bits/s if (argv[7] == NULL) { return FAILURE; } strcpy(argv[7], "1572864"); } argv[8] = NULL; if (execv("./encode", argv) == -1) { return FAILURE; } break; /* Launch decode demo */ case DEC: argv[0] = malloc(strlen("./decode" + 1)); if (argv[0] == NULL) { return FAILURE; } strcpy(argv[0], "./decode"); argv[1] = malloc(strlen("-i" + 1)); if (argv[1] == NULL) { return FAILURE; } strcpy(argv[1], "-i"); argv[2] = malloc(strlen("-v") + 1); if (argv[2] == NULL) { return FAILURE; } strcpy(argv[2], "-v"); argv[3] = malloc(strlen(envp->videoFile) + 1); if (argv[3] == NULL) { return FAILURE; } strcpy(argv[3], envp->videoFile); extension = rindex(envp->soundFile, '.'); if (extension == NULL) { // shouldn't happen ERR("Sound file without extension (%s)\n", envp->soundFile); return FAILURE; } if (strcmp(extension, ".g711") == 0) { argv[4] = malloc(strlen("-s") + 1); if (argv[4] == NULL) { return FAILURE; } strcpy(argv[4], "-s"); } else { argv[4] = malloc(strlen("-a") + 1); if (argv[4] == NULL) { return FAILURE; } strcpy(argv[4], "-a"); } argv[5] = malloc(strlen(envp->soundFile) + 1); if (argv[5] == NULL) { return FAILURE; } strcpy(argv[5], envp->soundFile); argv[6] = malloc(strlen("-l" + 1)); if (argv[6] == NULL) { return FAILURE; } strcpy(argv[6], "-l"); argv[7] = NULL; if (execv("./decode", argv) == -1) { return FAILURE; } break; /* Launch third party demo */ case THIRDPARTY: printf("Executing in %s\n", envp->thirdPartyCmdPath + 1); if (chdir(envp->thirdPartyCmdPath) == 0) { if (execl("app.sh", NULL) == -1) { return FAILURE; } } else { ERR("Failed to chdir to %s\n", envp->thirdPartyCmdPath); } break; } return SUCCESS; // Should never reach}/****************************************************************************** * showDemoInterface ******************************************************************************/int showDemoInterface(DemoEnv *envp, int *quitPtr){ int ret = SUCCESS; switch (envp->demoSelect) { case ENCDEC: ret = encodeDecodeFxn(envp); if (ret == SUCCESS) { *quitPtr = TRUE; launch = TRUE; } break; case ENC: ret = encodeFxn(envp); if (ret == SUCCESS) { *quitPtr = TRUE; launch = TRUE; } break; case DEC: ret = decodeFxn(envp); if (ret == SUCCESS) { *quitPtr = TRUE; launch = TRUE; } break; case THIRDPARTY: ret = thirdPartyFxn(envp); if (ret == SUCCESS) { *quitPtr = TRUE; launch = TRUE; } break; } return ret;}/****************************************************************************** * usage ******************************************************************************/static void usage(void){ printf("Usage: interface [options]\n\n" "Options:\n" "-l | --level Level to start interface at (0-2) [0]\n" "-h | --help Print this message\n\n" "Levels available:\n" " 0 - Start at the beginning [default]\n" " 1 - Skip the initial remote control help screen\n" " 2 - Go directly to the decode demo interface\n\n");}/****************************************************************************** * parseArgs ******************************************************************************/static void parseArgs(int argc, char *argv[], DemoEnv *envp){ const char shortOptions[] = "l:h"; const struct option longOptions[] = { {"level", required_argument, NULL, 'l'}, {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0} }; int index; int c; for (;;) { c = getopt_long(argc, argv, shortOptions, longOptions, &index); if (c == -1) { break; } switch (c) { case 0: break; case 'l': startLevel = atoi(optarg); if (startLevel < 0 || startLevel > 2) { fprintf(stderr, "Only start level 0-2 supported\n"); exit(EXIT_FAILURE); } break; case 'h': usage(); exit(EXIT_SUCCESS); default: usage(); exit(EXIT_FAILURE); } }}/****************************************************************************** * main ******************************************************************************/int main(int argc, char *argv[]){ int status = EXIT_SUCCESS; int ret = SUCCESS; enum InitLevels initLevel = 0; int quit = 0; int screenFd; DemoEnv env; /* Parse the arguments given to the app and set the app environment */ parseArgs(argc, argv, &env); printf("Demo interface started at level %d.\n", startLevel); pthread_mutex_init(&dataMutex, NULL); screenFd = screenInit(); if (screenFd == -1) { CLEANUP(EXIT_FAILURE); } if (setOsdTransparency(0x77) == -1) { CLEANUP(EXIT_FAILURE); } initLevel = SCREENINITIALIZED; if (startLevel == 0) { if (startupFxn(&env) == NOSELECTION) { CLEANUP(EXIT_SUCCESS); } } while (!quit) { /* No transparency on main menu */ if (setOsdTransparency(0x77) == -1) { BREAK_LOOP(EXIT_FAILURE); } /* Let the user select a demo */ ret = menuFxn(&env); if (ret == FAILURE) { BREAK_LOOP(EXIT_FAILURE); } if (ret == NOSELECTION) { BREAK_LOOP(EXIT_SUCCESS); } /* Show the selected demo interface */ ret = showDemoInterface(&env, &quit); if (ret == FAILURE) { BREAK_LOOP(EXIT_FAILURE); } if (ret == PLAYBACK) { env.demoSelect = DEC; if (showDemoInterface(&env, &quit) == FAILURE) { BREAK_LOOP(EXIT_FAILURE); } } }cleanup: if (initLevel >= SCREENINITIALIZED) { close(screenFd); } if (status == EXIT_SUCCESS && launch && launchDemo(&env) == FAILURE) { status = FAILURE; } pthread_mutex_destroy(&dataMutex); exit(status);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -