| 1 | /******************************************************** |
| 2 | |
| 3 | AVI player |
| 4 | Copyright 2000 Eugene Kuznetsov ([email protected]) |
| 5 | |
| 6 | *********************************************************/ |
| 7 | |
| 8 | #include "playercontrol.h" |
| 9 | |
| 10 | #include "version.h" |
| 11 | #include "avm_args.h" |
| 12 | #include "avm_output.h" |
| 13 | #include "avm_except.h" |
| 14 | #include "configfile.h" |
| 15 | |
| 16 | #include <qapplication.h> |
| 17 | #include <qtextcodec.h> |
| 18 | #include <qtimer.h> |
| 19 | |
| 20 | #include <signal.h> |
| 21 | #include <unistd.h> |
| 22 | #include <sys/time.h> |
| 23 | #include <fcntl.h> |
| 24 | #ifdef __FreeBSD__ |
| 25 | #include <floatingpoint.h> |
| 26 | #endif |
| 27 | #ifdef __NetBSD__ |
| 28 | #include <ieeefp.h> |
| 29 | #endif |
| 30 | |
| 31 | #include <string.h> |
| 32 | #include <stdlib.h> // atoi |
| 33 | #include <stdio.h> |
| 34 | |
| 35 | PlayerControl *m; |
| 36 | |
| 37 | extern void killer(int); |
| 38 | extern const char* g_pcProgramName; |
| 39 | |
| 40 | int main(int argc, char* argv[]) |
| 41 | { |
| 42 | #if defined(__FreeBSD__) || defined(__NetBSD__) |
| 43 | fpsetmask(fpgetmask() & ~(FP_X_DZ|FP_X_INV)); |
| 44 | #endif |
| 45 | if (GetAvifileVersion() != AVIFILE_VERSION) |
| 46 | { |
| 47 | fprintf(stderr, "This binary was compiled for Avifile ver. %x " |
| 48 | ", but the library is ver. %x.\nAborting...\n", |
| 49 | GetAvifileVersion(), AVIFILE_VERSION); |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | char* acodec = 0; |
| 54 | char* vcodec = 0; |
| 55 | char* subname = 0; |
| 56 | AviPlayerInitParams apip; |
| 57 | apip.x = apip.y = 0x7fffffff; |
| 58 | |
| 59 | const avm::Args::Option sizesubopts[] = |
| 60 | { |
| 61 | avm::ARGSOPTION("i", "width", "w", "window width", &apip.width, 8, 8192), |
| 62 | avm::ARGSOPTION("i", "height", "h", "window height", &apip.height, 2, 8192), |
| 63 | avm::ARGSOPTION("i", "x", "x", "window position x", &apip.x, -8192, 8192), |
| 64 | avm::ARGSOPTION("i", "y", "y", "window position y", &apip.y, -8192, 8192), |
| 65 | avm::ARGSOPTION("#",,,) |
| 66 | }; |
| 67 | |
| 68 | const avm::Args::Option opts[] = |
| 69 | { |
| 70 | avm::ARGSOPTION("b", "auto", "a", "use autoquality for postprocessing", &apip.quiet), |
| 71 | avm::ARGSOPTION("o", "size", "s", "set windows size", &sizesubopts), |
| 72 | avm::ARGSOPTION("d", "seek", "", "seek to given position", &apip.seek), |
| 73 | avm::ARGSOPTION("c", "video-codec", "vc", "preferred video codec (use help for select)", &vcodec), |
| 74 | avm::ARGSOPTION("c", "audio-codec", "ac", "preferred audio codec (use help for select)", &acodec), |
| 75 | //avm::ARGSOPTION("i", "shift", "", "shift frame buffer by <%d> bytes [%d, %d]", &shift, -8192, 8192), |
| 76 | //avm::ARGSOPTION("b", "nogui", "", "start playing without gui", &apip.nogui), |
| 77 | avm::ARGSOPTION("b", "fullscreen", "f", "start playing in fullscreen", &apip.fullscreen), |
| 78 | avm::ARGSOPTION("b", "maximize", "m", "start playing in maximized", &apip.maximize), |
| 79 | avm::ARGSOPTION("b", "quiet", "q", "be quiet", &apip.quiet), |
| 80 | avm::ARGSOPTION("s", "subtitle", "sub", "subtitle filename", &subname), |
| 81 | //{ "b", "verbose", "t", "be verbose", &verbose), |
| 82 | //{ "b", "version", "v", "show version"), |
| 83 | avm::ARGSOPTION("c", "codec", "c", "use with help for more info"), |
| 84 | avm::ARGSOPTION("h",,,), |
| 85 | avm::ARGSOPTION("O",,,, avm::IAviPlayer::getOptions()), |
| 86 | avm::ARGSOPTION("#",,,) |
| 87 | }; |
| 88 | |
| 89 | int rc=0; // remote control support over stdin/stdout |
| 90 | avm::Args(opts, &argc, argv, |
| 91 | " [options] [<audio/video/subtitle-files>\n Options:", |
| 92 | g_pcProgramName); |
| 93 | |
| 94 | #if 0 |
| 95 | printf("Parsed opts: left args: %d\n" |
| 96 | "Size w:%d h:%d x:%d y:%d\n" |
| 97 | "Auto %d\n" |
| 98 | "Seek %f\n" |
| 99 | "Fullscreen %d Maximize %d Quiet %d\n" |
| 100 | "VideoCodec %s AudioCodec %s\n" |
| 101 | "Subtitle %s\n", argc, |
| 102 | apip.width, apip.height, apip.x, apip.y, |
| 103 | apip.autoq, apip.seek, |
| 104 | apip.fullscreen, apip.maximize, apip.quiet, |
| 105 | vcodec, acodec, subname |
| 106 | ); |
| 107 | #endif |
| 108 | if (acodec) { apip.acodec = acodec; free(acodec); } |
| 109 | if (vcodec) { apip.vcodec = vcodec; free(vcodec); } |
| 110 | if (subname) { apip.subname = subname; free(subname); } |
| 111 | |
| 112 | for (int i = 1; i < argc; i++) |
| 113 | { |
| 114 | if (argv[i][0] != '-') |
| 115 | { |
| 116 | /* static const char* sfx[] = { ".txt", ".sub", ".smi", ".srt", 0 }; |
| 117 | const char** arr = sfx; |
| 118 | while (*arr) |
| 119 | { |
| 120 | int l = strlen(argv[i]); |
| 121 | if (l > 4 && strncasecmp(argv[i] + l - 4, *arr, 4) == 0 |
| 122 | && |
| 123 | { |
| 124 | avm::string subname(m_Filename.c_str(), m_Filename.size() - 4); |
| 125 | } |
| 126 | |
| 127 | }*/ |
| 128 | apip.urls.push_back(argv[i]); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // if (apip.urls.size() > 1) |
| 133 | // apip.subname = apip.urls.back(); |
| 134 | |
| 135 | if (apip.quiet) |
| 136 | avm::AvmOutput()->resetDebugLevels(-1); |
| 137 | |
| 138 | /* |
| 139 | if (!strcmp(argv[i], "--rc") || !strcmp(argv[i], "-rc") || !strcmp(argv[i], "-r")) |
| 140 | { |
| 141 | rc=1; |
| 142 | // non-buffered stdout |
| 143 | setvbuf (stdout, (char *)NULL, _IOLBF, 0); |
| 144 | } |
| 145 | else if (!strcmp(argv[i], "--quality") || !strcmp(argv[i], "-q")) |
| 146 | { |
| 147 | if (++i >= argc) |
| 148 | { |
| 149 | Usage(); |
| 150 | return -1; |
| 151 | } |
| 152 | if (!strcmp(argv[i], "auto") || !strcmp(argv[i], "a")) |
| 153 | apip.quality = 11; |
| 154 | else |
| 155 | { |
| 156 | apip.quality = atoi(argv[i]); |
| 157 | printf("quality setting %d is not yet implemented...\n", use_quality); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | */ |
| 162 | QApplication a(argc, argv); |
| 163 | //QApplication a(argc, argv, false);//, !apip.nogui); |
| 164 | a.setDefaultCodec( QTextCodec::codecForLocale() ); |
| 165 | |
| 166 | m = new PlayerControl();//, !apip.nogui); |
| 167 | a.setMainWidget( m->getWidget() ); |
| 168 | |
| 169 | if (apip.urls.size()) |
| 170 | m->initPlayer(apip); |
| 171 | else |
| 172 | m->openSlot(); |
| 173 | |
| 174 | // signal(SIGINT, killer); |
| 175 | #if 0 |
| 176 | QTimer t; |
| 177 | if(rc) |
| 178 | { |
| 179 | QObject::connect(&t, SIGNAL(timeout()), m, SLOT(remote_command())); |
| 180 | sleep (2); |
| 181 | t.start(100); |
| 182 | } |
| 183 | #endif |
| 184 | a.exec(); |
| 185 | delete m; |
| 186 | return 0; |
| 187 | } |