Streamer.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef MEDIA_STREAMER_C_DEFINED
00039 #define MEDIA_STREAMER_C_DEFINED
00040
00041 #include "Media/Streamer.H"
00042
00043 #include "Component/ModelManager.H"
00044 #include "Media/FrameSeries.H"
00045 #include "Raster/GenericFrame.H"
00046 #include "Raster/Raster.H"
00047 #include "Util/Pause.H"
00048 #include "Util/csignals.H"
00049
00050
00051 Streamer::Streamer(const char* name)
00052 :
00053 itsManager(new ModelManager(name)),
00054 itsIfs(new InputFrameSeries(*itsManager)),
00055 itsOfs(new OutputFrameSeries(*itsManager))
00056 {
00057 itsManager->addSubComponent(itsIfs);
00058 itsManager->addSubComponent(itsOfs);
00059 }
00060
00061
00062 Streamer::~Streamer()
00063 {}
00064
00065
00066 int Streamer::run(const int argc, const char** argv,
00067 const char* extraArgsDescription,
00068 const int minExtraArgs, const int maxExtraArgs)
00069 {
00070 try
00071 {
00072 return this->tryRun(argc, argv, extraArgsDescription,
00073 minExtraArgs, maxExtraArgs);
00074 }
00075 catch (...)
00076 {
00077 REPORT_CURRENT_EXCEPTION;
00078 }
00079
00080 return 1;
00081 }
00082
00083
00084 int Streamer::tryRun(const int argc, const char** argv,
00085 const char* extraArgsDescription,
00086 const int minExtraArgs, const int maxExtraArgs)
00087 {
00088 volatile int signum = 0;
00089 catchsignals(&signum);
00090
00091 if (itsManager->parseCommandLine(argc, argv, extraArgsDescription,
00092 minExtraArgs, maxExtraArgs) == false)
00093 return(1);
00094
00095 this->handleExtraArgs(*itsManager);
00096
00097 itsManager->start();
00098
00099 itsIfs->startStream();
00100
00101 int c = 0;
00102
00103 PauseWaiter p;
00104
00105 while (true)
00106 {
00107 if (signum != 0)
00108 {
00109 LINFO("quitting because %s was caught", signame(signum));
00110 return -1;
00111 }
00112
00113 if (itsOfs->becameVoid())
00114 {
00115 LINFO("quitting because output stream was closed or became void");
00116 return 0;
00117 }
00118
00119 if (p.checkPause())
00120 continue;
00121
00122 const FrameState is = itsIfs->updateNext();
00123 if (is == FRAME_COMPLETE)
00124 break;
00125
00126 GenericFrame input = itsIfs->readFrame();
00127 if (!input.initialized())
00128 break;
00129
00130 const FrameState os = itsOfs->updateNext();
00131
00132 this->onFrame(input, *itsOfs, itsIfs->frame());
00133
00134 if (os == FRAME_FINAL)
00135 break;
00136
00137 LDEBUG("frame %d", c++);
00138
00139 if (itsIfs->shouldWait() || itsOfs->shouldWait())
00140 Raster::waitForKey();
00141 }
00142
00143 itsManager->stop();
00144
00145 return 0;
00146 }
00147
00148
00149 void Streamer::addComponent(const nub::ref<ModelComponent>& c)
00150 {
00151 itsManager->addSubComponent(c);
00152 }
00153
00154
00155 OptionManager& Streamer::getManager()
00156 {
00157 return *itsManager;
00158 }
00159
00160
00161 void Streamer::handleExtraArgs(const ModelManager& mgr)
00162 {
00163
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173 #endif // MEDIA_STREAMER_C_DEFINED