📄 param.c
字号:
/*===========================================================================* * param.c * * Procedures to read in parameter file * *===========================================================================*//* COPYRIGHT INFORMATION IS AT THE END OF THIS FILE */#define _XOPEN_SOURCE 1 /* This makes sure popen() is in stdio.h. In GNU libc 2.1.3, _POSIX_C_SOURCE = 2 is sufficient, but on AIX 4.3, the higher level _XOPEN_SOURCE is required. 2000.09.09 *//*==============* * HEADER FILES * *==============*/#include <assert.h>#include <string.h>#include <ctype.h>#include <stdio.h>#include "nstring.h"#include "mallocvar.h"#include "all.h"#include "mtypes.h"#include "mpeg.h"#include "motion_search.h"#include "prototypes.h"#include "parallel.h"#include "readframe.h"#include "fsize.h"#include "frames.h"#include "jpeg.h"#include "input.h"#include "frametype.h"#include "param.h"#include "rate.h"#include "opts.h"/*===========* * CONSTANTS * *===========*/#define INPUT_ENTRY_BLOCK_SIZE 128#define FIRST_OPTION 0#define OPTION_GOP 0#define OPTION_PATTERN 1#define OPTION_PIXEL 2#define OPTION_PQSCALE 3#define OPTION_OUTPUT 4#define OPTION_RANGE 5#define OPTION_PSEARCH_ALG 6#define OPTION_IQSCALE 7#define OPTION_INPUT_DIR 8#define OPTION_INPUT_CONVERT 9#define OPTION_INPUT 10#define OPTION_BQSCALE 11#define OPTION_BASE_FORMAT 12#define OPTION_SPF 13#define OPTION_BSEARCH_ALG 14#define OPTION_REF_FRAME 15#define LAST_OPTION 15/* put any non-required options after LAST_OPTION */#define OPTION_RESIZE 16#define OPTION_IO_CONVERT 17#define OPTION_SLAVE_CONVERT 18#define OPTION_IQTABLE 19#define OPTION_NIQTABLE 20#define OPTION_FRAME_RATE 21#define OPTION_ASPECT_RATIO 22#define OPTION_YUV_SIZE 23#define OPTION_SPECIFICS 24#define OPTION_DEFS_SPECIFICS 25#define OPTION_BUFFER_SIZE 26#define OPTION_BIT_RATE 27#define OPTION_USER_DATA 28#define OPTION_YUV_FORMAT 29#define OPTION_GAMMA 30#define OPTION_PARALLEL 31#define OPTION_FRAME_INPUT 32#define OPTION_GOP_INPUT 33#define NUM_OPTIONS 33/*=======================* * STRUCTURE DEFINITIONS * *=======================*/typedef struct InputFileEntryStruct { char left[256]; char right[256]; boolean glob; /* if FALSE, left is complete name */ int startID; int endID; int skip; int numPadding; /* -1 if there is none */ int numFiles; boolean repeat;} InputFileEntry;/*==================* * GLOBAL VARIABLES * *==================*/extern char currentPath[MAXPATHLEN];char outputFileName[256];int outputWidth, outputHeight;char inputConversion[1024];char ioConversion[1024];char slaveConversion[1024];char yuvConversion[256];char specificsFile[256],specificsDefines[1024]="";boolean GammaCorrection=FALSE;float GammaValue;char userDataFileName[256]={0};boolean specificsOn = FALSE;char currentGOPPath[MAXPATHLEN];char currentFramePath[MAXPATHLEN];boolean keepTempFiles;static const char * const optionText[LAST_OPTION+1] = { "GOP_SIZE", "PATTERN", "PIXEL", "PQSCALE", "OUTPUT", "RANGE", "PSEARCH_ALG", "IQSCALE", "INPUT_DIR", "INPUT_CONVERT", "INPUT", "BQSCALE", "BASE_FILE_FORMAT", "SLICES_PER_FRAME", "BSEARCH_ALG", "REFERENCE_FRAME"};static boolean optionSeen[NUM_OPTIONS+1]; /* optionSeen[x] means we have seen option x in the parameter file we've been reading. */int numMachines;char machineName[MAX_MACHINES][256];char userName[MAX_MACHINES][256];char executable[MAX_MACHINES][1024];char remoteParamFile[MAX_MACHINES][1024];boolean remote[MAX_MACHINES];int mult_seq_headers = 0; /* 0 for none, N for header/N GOPs *//*===========================================================================* * * SkipSpacesTabs * * skip all spaces and tabs * * RETURNS: point to next character not a space or tab * * SIDE EFFECTS: none * *===========================================================================*/static const char *SkipSpacesTabs(const char * const start) { const char * p; for (p = start; *p == ' ' || *p == '\t'; ++p); return p;}/*===========================================================================* * * GetAspectRatio * * take a character string with the pixel aspect ratio * and returns the correct aspect ratio code for use in the Sequence header * * RETURNS: aspect ratio code as per MPEG-I spec * * SIDE EFFECTS: none * *===========================================================================*/static intGetAspectRatio(const char * const p){ float ratio; int ttRatio; int retval; sscanf(p, "%f", &ratio); ttRatio = (int)(0.5+ratio*10000.0); if ( ttRatio == 10000 ) retval = 1; else if ( ttRatio == 6735 ) retval = 2; else if ( ttRatio == 7031 ) retval = 3; else if ( ttRatio == 7615 ) retval = 4; else if ( ttRatio == 8055 ) retval = 5; else if ( ttRatio == 8437 ) retval = 6; else if ( ttRatio == 8935 ) retval = 7; else if ( ttRatio == 9157 ) retval = 8; else if ( ttRatio == 9815 ) retval = 9; else if ( ttRatio == 10255 ) retval = 10; else if ( ttRatio == 10695 ) retval = 11; else if ( ttRatio == 10950 ) retval = 12; else if ( ttRatio == 11575 ) retval = 13; else if ( ttRatio == 12015 ) retval = 14; else { fprintf(stderr,"INVALID ASPECT RATIO: %s frames/sec\n", p); exit(1); } return retval;}/*===========================================================================* * * ReadMachineNames * * read a list of machine names for parallel execution * * RETURNS: nothing * * SIDE EFFECTS: machine info updated * *===========================================================================*/static voidReadMachineNames(FILE * const fpointer){ char input[256]; const char *charPtr; while ( (fgets(input, 256, fpointer) != NULL) && (strncmp(input, "END_PARALLEL", 12) != 0) ) { if ( input[0] == '#' || input[0] == '\n') { continue; } if ( strncmp(input, "REMOTE", 6) == 0 ) { charPtr = SkipSpacesTabs(&input[6]); remote[numMachines] = TRUE; sscanf(charPtr, "%s %s %s %s", machineName[numMachines], userName[numMachines], executable[numMachines], remoteParamFile[numMachines]); } else { remote[numMachines] = FALSE; sscanf(input, "%s %s %s", machineName[numMachines], userName[numMachines], executable[numMachines]); } numMachines++; }}/*===========================================================================* * * GetFrameRate * * take a character string with the input frame rate * and return the correct frame rate code for use in the Sequence header * * RETURNS: frame rate code as per MPEG-I spec * * SIDE EFFECTS: none * *===========================================================================*/static intGetFrameRate(const char * const p){ float rate; int thouRate; int retval; sscanf(p, "%f", &rate); thouRate = (int)(0.5+1000.0*rate); if ( thouRate == 23976 ) retval = 1; else if ( thouRate == 24000 ) retval = 2; else if ( thouRate == 25000 ) retval = 3; else if ( thouRate == 29970 ) retval = 4; else if ( thouRate == 30000 ) retval = 5; else if ( thouRate == 50000 ) retval = 6; else if ( thouRate == 59940 ) retval = 7; else if ( thouRate == 60000 ) retval = 8; else { fprintf(stderr,"INVALID FRAME RATE: %s frames/sec\n", p); exit(1); } return retval;}static voidmergeInputSource(struct inputSource * const baseSourceP, struct inputSource * const addedSourceP) { unsigned int i; baseSourceP->ifArraySize += addedSourceP->numInputFileEntries; REALLOCARRAY_NOFAIL(baseSourceP->inputFileEntries, baseSourceP->ifArraySize); for (i = 0; i < addedSourceP->numInputFileEntries; ++i) baseSourceP->inputFileEntries[baseSourceP->numInputFileEntries++] = addedSourceP->inputFileEntries[i]; free(addedSourceP); /* Note the space allocated for the *addedSourceP input file entries themselves is still allocated, and used by *baseSourceP. */}/* Forward declaration for recursively called function */static voidReadInputFileNames(FILE * const fpointer, const char * const endInput, struct inputSource * const inputSourceP);static voidexpandBackTickLine(const char * const input, struct inputSource * const inputSourceP) { FILE *fp; char cmd[300]; const char * start; const char * end; char cdcmd[110]; start = &input[1]; end = &input[strlen(input)-1]; while (*end != '`') { end--; } end--; if (optionSeen[OPTION_INPUT_DIR]) sprintf(cdcmd,"cd %s;",currentPath); else strcpy(cdcmd,""); { char tmp[300]; strncpy(tmp,start,end-start+1); sprintf(cmd,"(%s %s)", cdcmd, tmp); } fp = popen(cmd, "r"); if (fp == NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -