📄 config.cc
字号:
//// Copyright (c) 2003 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card.// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//------------------------------------------------------------------------------#include "config.h"#include "Config.h"#include "Util.h"#include <cstdio>#include <cstring>#include <getopt.h>#include <sys/stat.h>//------------------------------------------------------------------------------using dvd::demux::DSI;//------------------------------------------------------------------------------extern "C" {char* get_path(char* filename);}//------------------------------------------------------------------------------namespace {char* trimstr(char* str){ size_t length = strlen(str); if (length==0) return str; char* start = str; while(*start==' ') ++start; char* end = str + length - 1; while(end>start && (*end==' ' || *end=='\n')) --end; *(end+1) = '\0'; return start;}void str2bool(const char* str, bool& var){ if (strcasecmp(str, "yes")==0 || strcasecmp(str, "true")) { var = true; } else if (strcasecmp(str, "no") || strcasecmp(str, "false")) { var = false; }}DSI::timeOffset_t str2timeOffset(const char* str, DSI::timeOffset_t defaultOffset){ static const struct { const char* str; DSI::timeOffset_t to; } str2to[] = { { "0.5", DSI::TO_0_5 }, { "1", DSI::TO_1 }, { "1.5", DSI::TO_1_5 }, { "2", DSI::TO_2 }, { "2.5", DSI::TO_2_5 }, { "3", DSI::TO_3 }, { "3.5", DSI::TO_3_5 }, { "4", DSI::TO_4 }, { "4.5", DSI::TO_4_5 }, { "5", DSI::TO_5 }, { "5.5", DSI::TO_5_5 }, { "6", DSI::TO_6 }, { "6.5", DSI::TO_6_5 }, { "7", DSI::TO_7 }, { "7.5", DSI::TO_7_5 }, { "10", DSI::TO_10 }, { "30", DSI::TO_30 }, { "60", DSI::TO_60 }, { "120", DSI::TO_120 }, { 0, DSI::TO_120 } }; for(size_t i = 0; str2to[i].str!=0; ++i) { if (!strcmp(str2to[i].str, str)) return str2to[i].to; } fprintf(stderr, "Unknown time offset: '%s', using default\n", str); return defaultOffset;}}//------------------------------------------------------------------------------void Config::usage(bool iserror){ FILE* f = iserror ? stderr : stdout; if (iserror) fprintf(f, "\n"); fprintf(f, "Usage: dxr3player [<options>]\n\n"); fprintf(f, "Options:\n\n"); fprintf(f, " -h: print this help and exit\n"); fprintf(f, " -a: keep the default aspect ratio\n"); fprintf(f, " -t: keep the default TV standard\n"); fprintf(f, " -d dvd use <dvd> as the default DVD device\n"); fprintf(f, " -e: eject DVD\n"); fprintf(f, " -m microcode: upload microcode from the file <microcode>\n"); fprintf(f, " -f scrfreq: set the SCR frequence to <scrfreq>/1000\n"); fprintf(f, " -s size: the reader buffer size\n"); fprintf(f, " -l lang: set the default language to the 2-letter code\n"); fprintf(f, " -A lang: set the forced audio language to the 2-letter code \n"); fprintf(f, " -A stream: set the forced audio stream to the given number\n"); fprintf(f, " -S lang: set the forced subpicture language to the 2-letter code\n"); fprintf(f, " -S stream: set the forced subpicture stream to the given number\n"); fprintf(f, " -D pcm|ac3: set the audio output to digital mode\n"); fprintf(f, " -V: use verbose logging\n"); fprintf(f, " -L filename: log also into the given file\n"); fprintf(f, " -i directory: find data files in the given directory\n"); fprintf(f, " -o <offset>: the offset of the audio timestamps\n"); fprintf(f, " -r <region>: the region to use\n");#ifdef USE_JOYSTICK fprintf(f, " -j <joystick>:the device file of the joystick to use\n");#endif fprintf(f, " -x: quit when an EXIT instruction is hit\n"); fprintf(f, " -O: use an OSS soundcard (/dev/dsp) for DXR3-based playback\n");}//------------------------------------------------------------------------------bool Config::initialize(int argc, char* argv[]){ Config& config = getInstance(); bool isok = config.setupFromFile(); if (!isok) return false; isok = config.setupFromCommandLine(argc, argv); if (!isok) return false;#ifndef NO_DVD_KEY_CACHE mkdir(get_path(0), 0755);#endif config.print(); return true;}//------------------------------------------------------------------------------//------------------------------------------------------------------------------Config::Config() : keepStandard(false), keepAspectRatio(false), dvdPath(0), ejectDVD(false), uploadMicrocode(false), microcodeFileName(0), scrFrequency(defaultSCRFrequency), readerBufferSize(defaultReaderBufferSize), defaultLanguageCode(Util::getLanguageCode("en")), audioMode(AM_ANALOGUE), verboseLogging(false), logFileName(0), dataDirectory("/usr/lib/dxr3player"), forcedDisplayFormat(DF_NONE), audioOffset(0),#ifdef USE_JOYSTICK js("/dev/js0"),#endif forcedAudioStream( (unsigned)-1 ), forcedAudioLanguage(0xffff), forcedSPUStream( (unsigned)-1 ), forcedSPULanguage(0xffff), region(0), quitOnExit(false), defaultVolume(50), defaultBrightness(50), defaultContrast(50), defaultSaturation(50), initialWindowWidth(720 * 4 / 3), initialWindowHeight(0), saveDirectory(get_path("saved")), useOSSSoundcard(false), repeatProgramThreshold(2147483647), fast2Offset(DSI::TO_3), fast3Offset(DSI::TO_7){}//------------------------------------------------------------------------------Config::~Config(){ free(const_cast<char*>(saveDirectory)); free(const_cast<char*>(dvdPath)); free(const_cast<char*>(microcodeFileName)); free(const_cast<char*>(logFileName));}//------------------------------------------------------------------------------bool Config::setupFromCommandLine(int argc, char* argv[]){ unsigned u; int opt; while( (opt=getopt(argc, argv, "htad:em:f:s:l:D:VL:i:o:j:A:S:r:Ox"))!=-1 ) { switch(opt) { case 'h': usage(false); return false; case 't': keepStandard = true; break; case 'a': keepAspectRatio = true; break; case 'd': dvdPath = strdup(optarg); break; case 'e': ejectDVD = 1; break; case 'm': uploadMicrocode = 1; microcodeFileName = strdup(optarg); break; case 'f': scrFrequency = static_cast<size_t>(atoi(optarg)); break; case 's': readerBufferSize = static_cast<size_t>(atoi(optarg)); break; case 'l': u = Util::getLanguageCode(optarg); if (u==0xffff) { fprintf(stderr, "Invalid language code!\n"); usage(true); return false; } else { defaultLanguageCode = u; } break; case 'A': u = Util::getLanguageCode(optarg); if (u==0xffff) { char* endptr; long x = strtol(optarg, &endptr, 10); if (*endptr=='\0' && x>=0 && x<8) { forcedAudioStream = (unsigned)x; } else { fprintf(stderr, "Invalid audio language code/stream number!\n"); usage(true); return false; } } else { forcedAudioLanguage = u; } break; case 'S': u = Util::getLanguageCode(optarg); if (u==0xffff) { char* endptr; long x = strtol(optarg, &endptr, 10); if (*endptr=='\0' && x>=0 && x<31) { forcedSPUStream = (unsigned)x; } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -