00001
00017 #include "vetMultiplexer.h"
00018
00019
00024 vetMultiplexer::vetMultiplexer(vetMultiplexerParameters* initParams) : vetFilter()
00025 {
00026 INFO("vetMultiplexer::vetMultiplexer(..* initParams) : vetFilter() [CONTRUCTOR]")
00027
00028 inputs = NULL;
00029 outputs = NULL;
00030
00031 reset();
00032
00033 setParameters(initParams);
00034 }
00035
00039 vetMultiplexer::~vetMultiplexer()
00040 {
00041 INFO("vetMultiplexer::~vetMultiplexer() [DESTRUCTOR]")
00042
00043 delete inputs;
00044 delete outputs;
00045
00046 if (myParams != NULL)
00047 delete myParams;
00048 myParams = NULL;
00049 }
00050
00056 VETRESULT vetMultiplexer::reset()
00057 {
00058 INFO("VETRESULT vetMultiplexer::reset() [SET DEFAULT PARAMETERS]")
00059
00060 setName("Multiplexer");
00061 setDescription("Link some sources with some outputs");
00062 setVersion(1.0);
00063
00064 if ( inputs != NULL )
00065 delete inputs;
00066
00067 if ( outputs != NULL )
00068 delete outputs;
00069
00070 inputs = new vetInput*[VET_MP_INPUTS_MAX];
00071 outputs = new vetOutput*[VET_MP_OUTPUTS_MAX];
00072
00073 for (int i=0; i<VET_MP_INPUTS_MAX; i++)
00074 inputs[i] = NULL;
00075 for (int j=0; j<VET_MP_OUTPUTS_MAX; j++)
00076 outputs[j] = NULL;
00077
00078 inputCurrent = 0;
00079 outputCurrent = 0;
00080 inputCount = 0;
00081 outputCount = 0;
00082
00083 return VETRET_OK;
00084 }
00085
00086
00096 VETRESULT vetMultiplexer::setParameters (vetMultiplexerParameters* initParams)
00097 {
00098 if ( initParams == NULL )
00099 myParams = new vetMultiplexerParameters();
00100 else
00101 myParams = initParams;
00102
00103 return VETRET_OK;
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 VETRESULT vetMultiplexer::run(long cycles)
00118 {
00119 DEBUGMSG("VETRESULT vetMultiplexer::run(long cycles)", cycles)
00120
00121 if ( inputs[inputCurrent] == NULL || outputs[outputCurrent] == NULL )
00122 return VETRET_ILLEGAL_USE;
00123
00124 if ( cycles == 0)
00125 cycles = VET_MP_LOOP_MAX;
00126
00127 if ( isBufferYUV() )
00128 {
00129 for (long i=0; i < cycles; i++)
00130 {
00131 *inputs[inputCurrent] >> *bufferYUV;
00132 *outputs[outputCurrent] << *bufferYUV;
00133 }
00134 }
00135
00136 else if ( isBufferRGB() )
00137 {
00138 for (long i=0; i < cycles; i++)
00139 {
00140 *inputs[inputCurrent] >> *bufferRGB;
00141 *outputs[outputCurrent] << *bufferRGB;
00142 }
00143 }
00144
00145 else
00146 {
00147 for (long i=0; i < cycles; i++)
00148 {
00149 *inputs[inputCurrent] >> *bufferTuC;
00150 *outputs[outputCurrent] << *bufferTuC;
00151 }
00152 }
00153
00154 return VETRET_OK;
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00181 VETRESULT vetMultiplexer::importFrom(vetFrameYUV420& img)
00182 {
00183 DEBUGMSG("VETRESULT vetMultiplexer::importFrom(vetFrameYUV420& img) [reading data]", outputCurrent)
00184
00185 *outputs[outputCurrent] << img;
00186 return VETRET_OK;
00187 }
00188
00199 VETRESULT vetMultiplexer::importFrom(vetFrameRGB24& img)
00200 {
00201 DEBUGMSG("VETRESULT vetMultiplexer::importFrom(vetFrameRGB24& img) [reading data]", outputCurrent)
00202
00203 *outputs[outputCurrent] << img;
00204 return VETRET_OK;
00205 }
00206
00217 VETRESULT vetMultiplexer::importFrom(vetFrameT<unsigned char>& img)
00218 {
00219 DEBUGMSG("VETRESULT vetMultiplexer::importFrom(vetFrameT& img) [reading data]", outputCurrent)
00220
00221 *outputs[outputCurrent] << img;
00222 return VETRET_OK;
00223 }
00224
00236 VETRESULT vetMultiplexer::extractTo(vetFrameYUV420& img)
00237 {
00238 DEBUGMSG("VETRESULT vetMultiplexer::extractTo(vetFrameYUV420& img) [pushing data]", inputCurrent)
00239
00240 *inputs[inputCurrent] >> img;
00241 return VETRET_OK;
00242 }
00243
00255 VETRESULT vetMultiplexer::extractTo(vetFrameRGB24& img)
00256 {
00257 DEBUGMSG("VETRESULT vetMultiplexer::extractTo(vetFrameRGB24& img) [pushing data]", inputCurrent)
00258
00259 *inputs[inputCurrent] >> img;
00260 return VETRET_OK;
00261 }
00262
00274 VETRESULT vetMultiplexer::extractTo(vetFrameT<unsigned char>& img)
00275 {
00276 DEBUGMSG("VETRESULT vetMultiplexer::extractTo(vetFrameT& img) [pushing data]", inputCurrent)
00277
00278 *inputs[inputCurrent] >> img;
00279 return VETRET_OK;
00280 }
00281
00282
00283
00284
00285
00294 VETRESULT vetMultiplexer::addInput(vetInput* newInput)
00295 {
00296 DEBUGMSG("VETRESULT vetMultiplexer::addInput(vetInput* newInput)", inputCount)
00297
00298 if ( newInput == NULL )
00299 return VETRET_PARAM_ERR;
00300
00301 if ( inputCount >= VET_MP_INPUTS_MAX )
00302 return VETRET_ILLEGAL_USE;
00303
00304 inputs[inputCount++] = newInput;
00305
00306 return VETRET_OK;
00307 }
00308
00318 VETRESULT vetMultiplexer::removeInput(vetInput* oldInput)
00319 {
00320 DEBUGMSG("VETRESULT vetMultiplexer::removeInput(vetInput* oldInput)", inputCount)
00321
00322 if ( oldInput == NULL )
00323 return VETRET_PARAM_ERR;
00324
00325 int iter = 0;
00326 while ( iter < inputCount )
00327 {
00328 if ( inputs[iter] == oldInput )
00329 return removeInput(iter);
00330 iter++;
00331 }
00332
00333 return VETRET_OK;
00334 }
00335
00345 VETRESULT vetMultiplexer::removeInput(int id)
00346 {
00347 DEBUGMSG("VETRESULT vetMultiplexer::removeInput(int id)", id)
00348
00349 if ( id < 0 || id >= inputCount )
00350 return VETRET_PARAM_ERR;
00351
00352
00353 for (int i=id; i<inputCount-1; i++) {
00354 inputs[i] = inputs[i+1];
00355 }
00356
00357 inputs[inputCount--] = NULL;
00358
00359 return VETRET_OK;
00360 }
00361
00370 VETRESULT vetMultiplexer::addOutput(vetOutput* newOutput)
00371 {
00372 DEBUGMSG("VETRESULT vetMultiplexer::addOutput(vetOutput* newOutput)", outputCount)
00373
00374 if ( newOutput == NULL )
00375 return VETRET_PARAM_ERR;
00376
00377 if ( outputCount >= VET_MP_OUTPUTS_MAX )
00378 return VETRET_ILLEGAL_USE;
00379
00380 outputs[outputCount++] = newOutput;
00381
00382 return VETRET_OK;
00383 }
00384
00394 VETRESULT vetMultiplexer::removeOutput(vetOutput* oldOutput)
00395 {
00396 DEBUGMSG("VETRESULT vetMultiplexer::removeOutput(vetOutput* oldOutput)", outputCount)
00397
00398 if ( oldOutput == NULL )
00399 return VETRET_PARAM_ERR;
00400
00401 if ( outputCount >= VET_MP_OUTPUTS_MAX )
00402 return VETRET_ILLEGAL_USE;
00403
00404 int iter = 0;
00405 while ( iter < outputCount )
00406 {
00407 if ( outputs[iter] == oldOutput )
00408 return removeOutput(iter);
00409 iter++;
00410 }
00411
00412 return VETRET_PARAM_ERR;
00413 }
00414
00424 VETRESULT vetMultiplexer::removeOutput(int id)
00425 {
00426 DEBUGMSG("VETRESULT vetMultiplexer::removeOutput(int id)", id)
00427
00428 if ( id < 0 || id >= outputCount )
00429 return VETRET_PARAM_ERR;
00430
00431
00432 for (int i=id; i<outputCount-1; i++) {
00433 outputs[i] = outputs[i+1];
00434 }
00435
00436 outputs[outputCount--] = NULL;
00437
00438 return VETRET_OK;
00439 }
00440
00448 VETRESULT vetMultiplexer::setCurrentInput(int id)
00449 {
00450 DEBUGMSG("VETRESULT vetMultiplexer::setCurrentInput(int id)", id)
00451
00452 if ( id < 0 || id >= inputCount )
00453 return VETRET_PARAM_ERR;
00454
00455 if ( inputs[id] == NULL )
00456 return VETRET_PARAM_ERR;
00457
00458 inputCurrent = id;
00459
00460 return VETRET_OK;
00461 }
00462
00471 VETRESULT vetMultiplexer::setCurrentInput(vetInput& currIn)
00472 {
00473 INFO("VETRESULT vetMultiplexer::setCurrentInput(vetInput& currSource)")
00474
00475 if ( &currIn == NULL )
00476 return VETRET_PARAM_ERR;
00477
00478 int iter = 0;
00479 while ( iter < inputCount )
00480 {
00481 if ( inputs[iter] == &currIn ) {
00482 inputCurrent = iter;
00483 return VETRET_OK;
00484 }
00485 iter++;
00486 }
00487
00488 return VETRET_PARAM_ERR;
00489 }
00490
00498 VETRESULT vetMultiplexer::setCurrentOutput(int id)
00499 {
00500 DEBUGMSG("VETRESULT vetMultiplexer::setCurrentOutput(int id)", id)
00501
00502 if ( id < 0 || id >= outputCount )
00503 return VETRET_PARAM_ERR;
00504
00505 if ( outputs[id] == NULL )
00506 return VETRET_PARAM_ERR;
00507
00508 outputCurrent = id;
00509
00510 return VETRET_OK;
00511 }
00512
00521 VETRESULT vetMultiplexer::setCurrentOutput(vetOutput& currOut)
00522 {
00523 INFO("VETRESULT vetMultiplexer::setCurrentOutput(vetOutput& currOut)")
00524
00525 if ( &currOut == NULL )
00526 return VETRET_PARAM_ERR;
00527
00528 int iter = 0;
00529 while ( iter < outputCount )
00530 {
00531 if ( outputs[iter] == &currOut ) {
00532 outputCurrent = iter;
00533 return VETRET_OK;
00534 }
00535 iter++;
00536 }
00537
00538 return VETRET_PARAM_ERR;
00539 }
00540
00542
00543
00544
00545
00546
00547
00548
00550
00551
00552 vetMultiplexerParameters::vetMultiplexerParameters()
00553 {
00554
00555 }
00556
00557 void vetMultiplexerParameters::reset()
00558 {
00559 runMode = 0;
00560 }
00561
00562
00563 int vetMultiplexerParameters::saveToStreamXML(FILE *fp)
00564 {
00565 return VETRET_NOT_IMPLEMENTED;
00566 }
00567
00568
00569 int vetMultiplexerParameters::loadFromStreamXML(FILE *fp)
00570 {
00571 return VETRET_NOT_IMPLEMENTED;
00572 }