|
MythTV
0.26-pre
|
00001 // -*- Mode: c++ -*- 00002 00003 // C++ headers 00004 #include <iostream> 00005 using namespace std; 00006 00007 // Qt headers 00008 #include <QCoreApplication> 00009 #include <QString> 00010 #include <QtCore> 00011 #include <QtGui> 00012 00013 // MythTV headers 00014 #include "mythccextractorplayer.h" 00015 #include "commandlineparser.h" 00016 #include "mythcontext.h" 00017 #include "mythversion.h" 00018 #include "programinfo.h" 00019 #include "ringbuffer.h" 00020 #include "exitcodes.h" 00021 00022 namespace { 00023 void cleanup() 00024 { 00025 delete gContext; 00026 gContext = NULL; 00027 } 00028 00029 class CleanupGuard 00030 { 00031 public: 00032 typedef void (*CleanupFunc)(); 00033 00034 public: 00035 CleanupGuard(CleanupFunc cleanFunction) : 00036 m_cleanFunction(cleanFunction) {} 00037 00038 ~CleanupGuard() 00039 { 00040 m_cleanFunction(); 00041 } 00042 00043 private: 00044 CleanupFunc m_cleanFunction; 00045 }; 00046 } 00047 00048 static int RunCCExtract(const ProgramInfo &program_info) 00049 { 00050 if (!program_info.IsLocal()) 00051 { 00052 QString msg = 00053 QString("Only locally accessible files are supported (%1).") 00054 .arg(program_info.GetPathname()); 00055 cerr << qPrintable(msg) << endl; 00056 return GENERIC_EXIT_INVALID_CMDLINE; 00057 } 00058 00059 QString filename = program_info.GetPathname(); 00060 if (!QFile::exists(filename)) 00061 { 00062 cerr << qPrintable( 00063 QString("Could not open input file (%1).").arg(filename)) << endl; 00064 return GENERIC_EXIT_INVALID_CMDLINE; 00065 } 00066 00067 RingBuffer *tmprbuf = RingBuffer::Create(filename, false); 00068 if (!tmprbuf) 00069 { 00070 cerr << qPrintable(QString("Unable to create RingBuffer for %1") 00071 .arg(filename)) << endl; 00072 return GENERIC_EXIT_PERMISSIONS_ERROR; 00073 } 00074 00075 00076 PlayerFlags flags = (PlayerFlags)(kVideoIsNull | kAudioMuted | 00077 kDecodeNoLoopFilter | kDecodeFewBlocks | 00078 /* Disabled due to libav bug 297 */ 00079 /* kDecodeLowRes | */ 00080 kDecodeSingleThreaded | 00081 kDecodeNoDecode); 00082 MythCCExtractorPlayer *ccp = new MythCCExtractorPlayer(flags, true, filename); 00083 PlayerContext *ctx = new PlayerContext(kCCExtractorInUseID); 00084 ctx->SetPlayingInfo(&program_info); 00085 ctx->SetRingBuffer(tmprbuf); 00086 ctx->SetPlayer(ccp); 00087 00088 ccp->SetPlayerInfo(NULL, NULL, ctx); 00089 if (ccp->OpenFile() < 0) 00090 { 00091 cerr << "Failed to open " << qPrintable(filename) << endl; 00092 return GENERIC_EXIT_NOT_OK; 00093 } 00094 if (!ccp->run()) 00095 { 00096 cerr << "Failed to decode " << qPrintable(filename) << endl; 00097 return GENERIC_EXIT_NOT_OK; 00098 } 00099 00100 delete ctx; 00101 00102 return GENERIC_EXIT_OK; 00103 } 00104 00105 int main(int argc, char *argv[]) 00106 { 00107 QCoreApplication a(argc, argv); 00108 00109 bool useDB = false; 00110 00111 QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHCCEXTRACTOR); 00112 00113 MythCCExtractorCommandLineParser cmdline; 00114 if (!cmdline.Parse(argc, argv)) 00115 { 00116 cmdline.PrintHelp(); 00117 return GENERIC_EXIT_INVALID_CMDLINE; 00118 } 00119 00120 int retval = cmdline.ConfigureLogging("none"); 00121 if (retval != GENERIC_EXIT_OK) 00122 return retval; 00123 00124 if (cmdline.toBool("showhelp")) 00125 { 00126 cmdline.PrintHelp(); 00127 return GENERIC_EXIT_OK; 00128 } 00129 00130 if (cmdline.toBool("showversion")) 00131 { 00132 cmdline.PrintVersion(); 00133 return GENERIC_EXIT_OK; 00134 } 00135 00136 QString infile = cmdline.toString("inputfile"); 00137 if (infile.isEmpty()) 00138 { 00139 cerr << "The input file --infile is required" << endl; 00140 return GENERIC_EXIT_INVALID_CMDLINE; 00141 } 00142 00143 CleanupGuard callCleanup(cleanup); 00144 00145 gContext = new MythContext(MYTH_BINARY_VERSION); 00146 if (!gContext->Init( 00147 false/*use gui*/, false/*prompt for backend*/, 00148 false/*bypass auto discovery*/, !useDB/*ignoreDB*/)) 00149 { 00150 cerr << "Failed to init MythContext, exiting." << endl; 00151 return GENERIC_EXIT_NO_MYTHCONTEXT; 00152 } 00153 00154 ProgramInfo pginfo(infile); 00155 return RunCCExtract(pginfo); 00156 } 00157 00158 00159 /* vim: set expandtab tabstop=4 shiftwidth=4: */
1.7.6.1