libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo es el conjunto de objetos y funciones, que permiten ejecutar las operaciones básicas de la plataforma Moldeo, y que compone su núcleo.
moVideoManager.cpp
Ir a la documentación de este archivo.
1 /*******************************************************************************
2 
3  moVideoManager.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28 
29 
30 *******************************************************************************/
31 
32 #include "moVideoManager.h"
33 
34 #ifndef MO_DIRECTSHOW
35 #ifndef MO_QUICKTIME
36 // #define MO_GSTREAMER 1
37 #endif // MO_QUICKTIME
38 #endif // MO_DIRECTSHOW
39 
40 #include "moArray.h"
41 moDefineDynamicArray(moCircularVideoBuffers)
42 moDefineDynamicArray(moVideoFrames)
43 moDefineDynamicArray(moVideoBuffers)
44 moDefineDynamicArray(moLiveSystemPtrs)
45 moDefineDynamicArray(moVideoBufferPaths)
46 
47 #include "FreeImage.h"
48 
49 //===========================================
50 //
51 // moVideoFrame
52 //
53 //===========================================
54 
56  m_FrameSize = 0;
57  hmem = NULL;
58  options = 0;
59  fif = (int)FIF_UNKNOWN;
60 }
61 
63  Finish();
64 }
65 
69  return m_bInitialized;
70 }
71 
72 //FreeImage_SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FIMEMORY *stream, int flags FI_DEFAULT(0));
74 moVideoFrame::Init( moText bufferformat, moBitmap* pImageResult ) {
75 
76  FIBITMAP* _pImageResult = (FIBITMAP*)pImageResult;
77 
78  if (!hmem) {
79  hmem = FreeImage_OpenMemory();
80  }
81  if (hmem) {
82 
83  if ( bufferformat == moText("JPG")) {
84  fif = FIF_JPEG;
85  options = JPEG_QUALITYNORMAL;
86  } else if ( bufferformat == moText("JPGSUPERB") ) {
87  fif = FIF_JPEG;
88  options = JPEG_QUALITYSUPERB;
89  } else if ( bufferformat == moText("JPGBAD") ) {
90  fif = FIF_JPEG;
91  options = JPEG_QUALITYBAD;
92  } else if ( bufferformat == moText("JPGAVERAGE") ) {
93  fif = FIF_JPEG;
94  options = JPEG_QUALITYAVERAGE;
95  } else if ( bufferformat == moText("JPGGOOD") ) {
96  fif = FIF_JPEG;
97  options = JPEG_QUALITYGOOD;
98  } else if ( bufferformat == moText("TGA") ) {
99  fif = FIF_TARGA;
100  options = 0;
101  } else if ( bufferformat == moText("PNG") ) {
102  fif = FIF_PNG;
103  options = 0;
104  } else {
105  MODebug2->Error( moText("moVideoFrame::Init")
106  + moText(" bufferformat unsupported!!") );
107  return false;
108  }
109  FreeImage_SaveToMemory( (FREE_IMAGE_FORMAT)fif, _pImageResult, (FIMEMORY*)hmem, options );
110  m_FrameSize = FreeImage_TellMemory((FIMEMORY*)hmem);
111  if (m_FrameSize==0) {
112  MODebug2->Error( moText("moVideoFrame::Init")
113  + moText(" Couldn't save image to memory, format may be unsupported or image is empty!") );
114  MODebug2->Error( moText("bufferformat:") + bufferformat);
115  MODebug2->Error( moText("Width:") + IntToStr(FreeImage_GetWidth(_pImageResult)) );
116  MODebug2->Error( moText("Height:") + IntToStr(FreeImage_GetHeight(_pImageResult)) );
117 
118  return false;
119  }
120  }
121  return Init();
122 }
123 
124 MOboolean
126 
127  if (hmem) {
128  FreeImage_CloseMemory( (FIMEMORY*)hmem );
129  hmem = NULL;
130  }
131 
132  m_FrameSize = 0;
133  hmem = NULL;
134  fif = (int)FIF_UNKNOWN;
135 
136  return true;
137 }
138 
139 
140 //===========================================
141 //
142 // moVideoBuffer
143 //
144 //===========================================
145 
147  m_pResourceManager = NULL;
149 
150  m_XSource = 0;
151  m_YSource = 0;
152  m_SourceWidth = 0;
153  m_SourceHeight = 0;
154 }
155 
157  Finish();
158 }
159 
161 
162  if (!m_pResourceManager)
163  return false;
164 
165  return true;
166 }
167 
168 MOboolean
169 moVideoBuffer::Init( moText bufferpath, moText bufferformat, moResourceManager* p_pResourceManager, MOuint width, MOuint height, MOuint xsource, MOuint ysource, MOuint sourcewidth, MOuint sourceheight, MOint interpolation, MOint interpolationjump, MOint interpolationtime ) {
170  m_pResourceManager = p_pResourceManager;
171 
172  m_BufferPath = bufferpath;
173  m_BufferFormat = bufferformat;
174  m_XSource = xsource;
175  m_YSource = ysource;
176  m_SourceWidth = sourcewidth;
177  m_SourceHeight = sourceheight;
178 
179  BuildEmpty( width, height);
180 
181  SetInterpolation( interpolationjump, interpolationtime );
182  ActivateInterpolation( interpolation );
183 
184  /*
185  moShaderManager* SM = m_pResourceManager->GetShaderMan();
186  moTextureManager* TM = m_pResourceManager->GetTextureMan();
187 
188  m_pShaderCopy = SM->GetShader(SM->GetShaderIndex(moText("shaders/Copy.cfg"),true) );
189  */
190  m_Frames.Init( 0, NULL);
191 
192  return Init();
193 }
194 
196  for(MOuint i=0; i<m_Frames.Count(); i++) {
197  moVideoFrame* pVideoFrame = m_Frames[i];
198  if (pVideoFrame)
199  pVideoFrame->Finish();
200  delete pVideoFrame;
201  }
202  m_Frames.Empty();
203  m_pResourceManager = NULL;
204  return true;
205 }
206 
207 MOboolean
208 moVideoBuffer::LoadImage( moBitmap* pImage, int indeximage ) {
209 
210  FIBITMAP* _pImage = (FIBITMAP*)pImage;
211  FIBITMAP* pImageResult = NULL;
212  FIBITMAP* pImageCropped = NULL;
213  FIBITMAP* pImageScaled = NULL;
214 
215  if ( m_width!=FreeImage_GetWidth(_pImage) || m_height!=FreeImage_GetHeight(_pImage) ) {
216  //CROP MODE
217  pImageCropped = FreeImage_Copy( _pImage, m_XSource , m_YSource , m_XSource + m_SourceWidth , m_YSource+m_SourceHeight );
218  pImageResult = pImageCropped;
219 
220  } else pImageResult = _pImage;
221 
222  //RESCALE
223  if ( m_width != m_SourceWidth || m_height != m_SourceHeight ) {
224  /*
225  FILTER_BOX Box, pulse, Fourier window, 1st order (constant) B-Spline
226  FILTER_BILINEAR Bilinear filter
227  FILTER_BSPLINE 4th order (cubic) B-Spline
228  FILTER_BICUBIC Mitchell and Netravali's two-param cubic filter
229  FILTER_CATMULLROM Catmull-Rom spline, Overhauser spline
230  FILTER_LANCZOS3
231  */
232  pImageScaled = FreeImage_Rescale( pImageResult, m_width, m_height, FILTER_BICUBIC );
233  if (pImageScaled) {
234  FreeImage_Unload(pImageResult);
235  pImageResult = pImageScaled;
236  }
237  }
238 
239  moVideoFrame* pVideoFrame = NULL;
240 
241  if (indeximage==-1 || indeximage == (int)m_Frames.Count() ) {
242  pVideoFrame = new moVideoFrame();
243  if (pVideoFrame) {
244  pVideoFrame->Init( m_BufferFormat, pImageResult );
245  m_Frames.Add(pVideoFrame);
246  }
247  } else if ( indeximage < (int)m_Frames.Count() ) {
248  pVideoFrame = m_Frames.Get(indeximage);
249  if (pVideoFrame) {
250  pVideoFrame->Finish();
251  pVideoFrame->Init( m_BufferFormat, pImageResult );
252  }
253  }
254 
255  if (pImageResult!=_pImage)
256  FreeImage_Unload(pImageResult);
257 
258  m_nFrames = m_Frames.Count();
259  m_fFramesPerSecond = 25.0;
260 
261  return (pVideoFrame!=NULL);
262 }
263 /*
264 MOboolean moVideoBuffer::LoadFromVideo( moText p_moviefile ) {
265  //
266  return true;
267 }
268 */
269 /*
270 */
272 
273  if ( p_i<m_Frames.Count()) {
274 
275  moVideoFrame* pVideoFrame = m_Frames[p_i];
276 
277  if (pVideoFrame) {
278 
279  FIBITMAP *pImage;
280  //FIMEMORY *hmem;
281 
282  MOuint p_format;
283 
284  //MOint FrameSize =
285  FreeImage_TellMemory((FIMEMORY*)pVideoFrame->hmem);
286  FreeImage_SeekMemory( (FIMEMORY*)pVideoFrame->hmem, 0L, SEEK_SET);
287 
288  //hmem = FreeImage_OpenMemory( pVideoFrame->hmem, pVideoFrame->m_FrameSize);
289  //FreeImage_TellMemory(VideoFrame->hmem);
290  // load an image from the memory stream
291  pImage = FreeImage_LoadFromMemory( (FREE_IMAGE_FORMAT)pVideoFrame->fif, (FIMEMORY*)pVideoFrame->hmem, 0);
292 
293  if (pImage) {
294  switch (FreeImage_GetBPP(pImage))
295  {
296  case 8: // 8 bit, indexed or grayscale
297  m_param.internal_format = GL_RGB;
298  p_format = GL_LUMINANCE;
299  break;
300  case 16: // 16 bits
301  break;
302  case 24: // 24 bits
303  m_param.internal_format = GL_RGB;
304 #ifndef OPENGLESV2
305  if (FreeImage_GetBlueMask(pImage) == 0x000000FF) p_format = GL_BGR;
306  else
307 #endif
308  p_format = GL_RGB;
309  break;
310  case 32: // 32 bits
311  m_param.internal_format = GL_RGBA;
312 #ifndef OPENGLESV2
313  if (FreeImage_GetBlueMask(pImage) == 0x000000FF) p_format = GL_BGRA_EXT;
314  else
315 #endif
316  p_format = GL_RGBA;
317  break;
318  default:
319  break;
320  }
321  SetBuffer( m_width, m_height, FreeImage_GetBits(pImage), p_format);
322  FreeImage_Unload( pImage );
323 
324  this->m_ActualFrame = p_i;
325 
326  } else MODebug2->Error( moText("moVideoBuffer::GetFrame") +
327  moText("Couldn't load image from memory, texture name: ") +
328  moText(this->GetName())
329  );
330  }
331  }
332 
333 }
334 
335 //===========================================
336 //
337 // moCircularVideoBuffer
338 //
339 //===========================================
340 
342  m_pResourceManager = NULL;
344 
345  m_WriteIndex = 0;
346  m_ReadIndex = 0;
347  m_XSource = 0;
348  m_YSource = 0;
349  m_SourceWidth = 0;
350  m_SourceHeight = 0;
351 }
352 
354  Finish();
355 }
356 
358 
359  if (!m_pResourceManager)
360  return false;
361 
362  return true;
363 }
364 
365 MOboolean
366 moCircularVideoBuffer::Init( moText videoinput, moText bufferformat, moResourceManager* p_pResourceManager, MOint frames, MOint width, MOint height, MOint xsource, MOint ysource, MOint sourcewidth, MOint sourceheight ) {
367  m_pResourceManager = p_pResourceManager;
368 
369  m_VideoInput = videoinput;
370  m_BufferFormat = bufferformat;
371  m_XSource = xsource;
372  m_YSource = ysource;
373  m_SourceWidth = sourcewidth;
374  m_SourceHeight = sourceheight;
375 
376  BuildEmpty( width, height);
377 
378 
379  //DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Allocate(int width, int height, int bpp, unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0));
380 
381  FIBITMAP* pBlack;
382  pBlack = FreeImage_Allocate( width, height, 24 );
383 
384  for(MOint i=0; i<frames; i++) {
385  moVideoFrame* pVideoFrame = new moVideoFrame();
386  if (pVideoFrame) {
387  pVideoFrame->Init( bufferformat, pBlack );
388  m_Frames.Add(pVideoFrame);
389  }
390  }
391 
392  m_nFrames = m_Frames.Count();
393  MODebug2->Message("moCircularVideoBuffer::Init > m_nFrames: " + IntToStr(m_nFrames));
394 
395  return Init();
396 }
397 
399  for(MOuint i=0; i<m_Frames.Count(); i++) {
400  moVideoFrame* pVideoFrame = m_Frames[i];
401  if (pVideoFrame)
402  pVideoFrame->Finish();
403  delete pVideoFrame;
404  }
405  m_Frames.Empty();
406  m_pResourceManager = NULL;
407  return true;
408 }
409 
410 MOboolean
412 
413 
414  FIBITMAP* pImage = NULL;
415  moBucket* pBucket = NULL;
416 
417  if (!pvideosample) return false;
418 
419 //DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertFromRawBits(
420  //BYTE *bits, int width, int height, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown FI_DEFAULT(FALSE));
421  pBucket = (moBucket*)pvideosample->m_pSampleBuffer;
422  if (!pBucket) return false;
423  pImage = FreeImage_ConvertFromRawBits( pBucket->GetBuffer(),
424  pvideosample->m_VideoFormat.m_Width,
425  pvideosample->m_VideoFormat.m_Height,
426  pvideosample->m_VideoFormat.m_Width*3,
427  24,
428  0xFF0000,
429  0x00FF00,
430  0x0000FF);
431 
432  if (pImage==NULL) return false;
433 
434  FIBITMAP* pImageResult = NULL;
435  FIBITMAP* pImageCropped = NULL;
436  FIBITMAP* pImageScaled = NULL;
437 /*
438  MODebug2->Message("moCircularVideoBuffer::LoadSample > "
439  +moText("m_width:") + IntToStr(m_width)
440  +"m_height:" + IntToStr(m_height)
441  +"m_XSource:" + IntToStr(m_XSource)
442  +"m_YSource:" + IntToStr(m_YSource)
443  +"m_SourceWidth:" + IntToStr(m_SourceWidth)
444  +"m_SourceHeight:" + IntToStr(m_SourceHeight) );
445  MODebug2->Message("moCircularVideoBuffer::LoadSample > Width loaded:" + IntToStr(FreeImage_GetWidth(pImage)) );
446  MODebug2->Message("moCircularVideoBuffer::LoadSample > Height loaded:" + IntToStr(FreeImage_GetHeight(pImage)) );
447  //MODebug2->Message("moCircularVideoBuffer::LoadSample > :" + IntToStr(FreeImage_GetInfo(pImage)) );
448 */
449  int w = FreeImage_GetWidth(pImage);
450  int h = FreeImage_GetHeight(pImage);
451 
452  pImageResult = pImage;
453  bool validcrop = false;
454  bool validscale = false;
455  validcrop = (m_width!=w) || (m_height!=h);
456  validcrop = validcrop && (m_XSource<w) && (m_XSource>=0) && (m_YSource<h) && (m_YSource>=0);
457  validcrop = validcrop && (m_SourceWidth>=0) && (m_SourceHeight>=0);
458  validcrop = validcrop && ( momin(m_XSource + m_SourceWidth,w) <= w) && (momin(m_YSource + m_SourceHeight,h) <= h);
459 
460  validscale = ((m_width!=w) || (m_height!=h)) && ((m_width != m_SourceWidth) || (m_height != m_SourceHeight));
461 
462  if ( validcrop ) {
463  //CROP MODE
464  pImageCropped = FreeImage_Copy( pImage, m_XSource , m_YSource , momin(m_XSource + m_SourceWidth,w) , momin(m_YSource + m_SourceHeight,h) );
465  pImageResult = pImageCropped;
466  //MODebug2->Message("moCircularVideoBuffer::LoadSample > Image Cropped W:" + IntToStr(FreeImage_GetWidth(pImageResult)) );
467  validscale = ((m_width!=FreeImage_GetWidth(pImageCropped)) || (m_height!=FreeImage_GetHeight(pImageCropped)));
468  }
469 
471  if ( validscale ) {
472  /*
473  FILTER_BOX Box, pulse, Fourier window, 1st order (constant) B-Spline
474  FILTER_BILINEAR Bilinear filter
475  FILTER_BSPLINE 4th order (cubic) B-Spline
476  FILTER_BICUBIC Mitchell and Netravali's two-param cubic filter
477  FILTER_CATMULLROM Catmull-Rom spline, Overhauser spline
478  FILTER_LANCZOS3
479  */
480  pImageScaled = FreeImage_Rescale( pImageResult, m_width, m_height, FILTER_BICUBIC );
481  if (pImageScaled) {
482  FreeImage_Unload(pImageResult);
483  pImageResult = pImageScaled;
484  }
485  //MODebug2->Message("moCircularVideoBuffer::LoadSample > Image Scaled W:" + IntToStr(FreeImage_GetWidth(pImageScaled)) );
486  }
487 
488  //aqui cambia
489  m_WriteIndex++;
490 
491  //Circularity
492  if ( m_WriteIndex>= (MOint)m_Frames.Count() ) {
493  m_WriteIndex = 0;
494  }
495 
496  m_ReadIndex = m_WriteIndex;
497 
498  moVideoFrame* pVideoFrame = m_Frames[m_WriteIndex];
499  if (pVideoFrame) {
500  pVideoFrame->Finish();
501  pVideoFrame->Init( m_BufferFormat, pImageResult );
502  }
503 
504  if (pImageResult!=pImage)
505  FreeImage_Unload(pImageResult);
506 
507  FreeImage_Unload(pImage);
508 
509  m_fFramesPerSecond = 25.0;
510 
511  return (pVideoFrame!=NULL);
512 }
513 /*
514 MOboolean moVideoBuffer::LoadFromVideo( moText p_moviefile ) {
515  //
516  return true;
517 }
518 */
519 /*
520 */
522  //MODebug2->Message("moCircularVideoBuffer::GetFrame > Reading image from circularvideobuffer"+IntToStr(p_i));
523  if ( p_i<m_Frames.Count()) {
524 
525  MOint ddd = ( m_ReadIndex - (int)p_i);
526  if (ddd<0) ddd = m_Frames.Count() + ddd;
527  p_i = ddd % m_Frames.Count();
528 
529  moVideoFrame* pVideoFrame = m_Frames[p_i];
530 
531  if (pVideoFrame) {
532 
533  FIBITMAP *pImage;
534  //FIMEMORY *hmem;
535 
536  MOuint p_format;
537 
538  //MOint FrameSize =
539  //MODebug2->Message("moCircularVideoBuffer::GetFrame > Loading image to texture from circularvideobuffer"+IntToStr(p_i));
540  FreeImage_TellMemory((FIMEMORY*)pVideoFrame->hmem);
541  FreeImage_SeekMemory( (FIMEMORY*)pVideoFrame->hmem, 0L, SEEK_SET);
542 
543  //hmem = FreeImage_OpenMemory( pVideoFrame->hmem, pVideoFrame->m_FrameSize);
544  //FreeImage_TellMemory(VideoFrame->hmem);
545  // load an image from the memory stream
546  pImage = FreeImage_LoadFromMemory( (FREE_IMAGE_FORMAT)pVideoFrame->fif, (FIMEMORY*)pVideoFrame->hmem, 0);
547 
548  switch (FreeImage_GetBPP(pImage))
549  {
550  case 8: // 8 bit, indexed or grayscale
551  m_param.internal_format = GL_RGB;
552  p_format = GL_LUMINANCE;
553  break;
554  case 16: // 16 bits
555  break;
556  case 24: // 24 bits
557  m_param.internal_format = GL_RGB;
558 #ifndef OPENGLESV2
559  //if (FreeImage_GetBlueMask(pImage) == 0x000000FF) p_format = GL_BGR;
560  //else
561 #endif
562  p_format = GL_RGB;
563  break;
564  case 32: // 32 bits
565  m_param.internal_format = GL_RGBA;
566 #ifndef OPENGLESV2
567  if (FreeImage_GetBlueMask(pImage) == 0x000000FF) p_format = GL_BGRA_EXT;
568  else
569 #endif
570 p_format = GL_RGBA;
571  break;
572  default:
573  break;
574  }
575  SetBuffer( m_width, m_height, FreeImage_GetBits(pImage), p_format);
576  FreeImage_Unload( pImage );
577  }
578  }
579 
580 }
581 
582 
583 void moCircularVideoBuffer::StartRecording( long at_position ) {
584  if (at_position!=-1 && at_position>=0 && at_position<(long)m_Frames.Count()) {
585  m_WriteIndex = at_position;
586  }
587  if (!m_RecTimer.Started()) {
588  m_RecTimer.Start();
589  } else {
590  m_RecTimer.Continue();
591  }
592 }
593 
595  m_RecTimer.Pause();
596 }
597 
599  m_RecTimer.Continue();
600 }
601 
602 void moCircularVideoBuffer::JumpRecording( long at_position ) {
603  //m_RecTimer.Start();
604  //chequear
605  if ( at_position>=0 && at_position<(long)m_Frames.Count()) {
606  m_WriteIndex = at_position;
607  }
608 }
609 
611  m_RecTimer.Stop();
612 }
613 
615  return m_RecTimer.Started();
616 }
617 
619  return m_WriteIndex;
620 }
621 
622 
623 //===========================================
624 //
625 // moVideoBufferPath
626 //
627 //===========================================
628 
630  m_ImagesProcessed = 0;
631  m_ActualImage = 0;
632  m_pResourceManager = NULL;
633  m_pDirectory = NULL;
634  m_bLoadCompleted = false;
635  m_TotalFiles = 0;
636 
637 }
638 
640  Finish();
641 }
642 
644 
645  m_bInitialized = true;
646 
647  return m_bInitialized;
648 }
649 
650 MOboolean
651 moVideoBufferPath::Init( moResourceManager* pResources, moText videobufferpath ) {
652 
653  m_pResourceManager = pResources;
654 
655  if (!m_pResourceManager)
656  return false;
657 
658  m_VideoBufferPath = videobufferpath;
659 
660  m_CompletePath = m_pResourceManager->GetDataMan()->GetDataPath() + moSlash + (moText)m_VideoBufferPath;;
661 
662  m_pDirectory = m_pResourceManager->GetFileMan()->GetDirectory( m_CompletePath );
663 
664  if (m_pDirectory) this->m_TotalFiles = (MOint)m_pDirectory->GetFiles().Count();
665 
666  return Init();
667 }
668 
670 
671  m_VideoBuffers.Empty();
672 
673  return true;
674 }
675 
676 MOboolean
678  return m_bLoadCompleted;
679 }
680 
682  return this->m_VideoBufferPath;
683 }
684 
686  return this->m_CompletePath;
687 }
688 
689 
691  return this->m_TotalFiles;
692 }
693 
695  return this->m_ImagesProcessed;
696 }
697 
699  return this->m_ActualImage;
700 }
701 
703 
704  //carga los frames desde los archivos
705  moFile* pFile;
706 
707  MOint counter = 0;
708 
709  if (!m_pDirectory) return false;
710 
711  this->m_TotalFiles = (MOint)m_pDirectory->GetFiles().Count();
712 
713  if (m_ActualImage>=(MOint)m_pDirectory->GetFiles().Count()) {
714  m_bLoadCompleted = true;
715  return true;
716  }
717 
718  if (m_ActualImage==0)
719  pFile = m_pDirectory->FindFirst();
720  else
721  pFile = m_pDirectory->Find(m_ActualImage);
722 
723  if (pFile)
724  do {
725  if ( pFile->GetType()==MO_FILETYPE_LOCAL && pFile->Exists()) {
726 
727  //LOAD AND UNCOMPRESS IMAGE
728  FREE_IMAGE_FORMAT fif;
729  fif = FreeImage_GetFileType( pFile->GetCompletePath(), 0);
730 
731  if( fif == FIF_UNKNOWN ) {
732  // try to guess the file format from the file extension
733  fif = FreeImage_GetFIFFromFilename(pFile->GetCompletePath());
734  }
735 
736  if( (fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif) ) {
737  //decodificamos el archivo
738  FIBITMAP* pImage;
739  pImage = FreeImage_Load( fif, pFile->GetCompletePath(), 0);
740 
741  //ONCE LOADED SAVE ON EVERY VIDEOBUFFER
742  if (pImage) {
743 
744  for(MOuint b = 0; b<m_VideoBuffers.Count(); b++) {
745 
746  moVideoBuffer* pVideoBuffer = m_VideoBuffers[b];
747 
748  if (pVideoBuffer)
749  pVideoBuffer->LoadImage( pImage, m_ActualImage );
750  }
751  FreeImage_Unload(pImage);
752  pImage = NULL;
753  m_ImagesProcessed++;
754  //MODebug2->Message( "image processed: "+pFile->GetCompletePath());
755  }
756  }
757  }
758 
759  m_ActualImage++;
760  counter++;
761  if (counter==maxfiles && maxfiles!=(-1))
762  break;
763 
764  } while ( (pFile = m_pDirectory->FindNext()) );
765 
766  return true;
767 }
768 
769 
770 //===========================================
771 //
772 // moVideoManager
773 //
774 //===========================================
775 
777 {
778  SetType( MO_OBJECT_RESOURCE );
779  SetResourceType( MO_RESOURCETYPE_VIDEO );
780 
781  SetName("videomanager");
782  SetLabelName("videomanager");
783 
784  m_pLiveSystems = NULL;
785 }
786 
788 {
789  Finish();
790 }
791 
793 {
794  moCaptureDevices* pPreferredDevices;
795  MOuint preferreddevices;
796  MOuint autoreconnect;
797  MOuint nvalues;
798  moText confignamecompleto;
799 
800  m_bAutoReconnect = false;
801 
802  // Loading config file.
803  if (!m_pResourceManager) return false;
804 
806 
807  m_pLiveSystems = new moLiveSystems();
808  m_pLiveSystems->Init(0, NULL);
809 
810 
811 
812  if (m_Config.IsConfigLoaded()) {
813 
814  moText msg = "In moVideoManager::Init from config file ***********************\n";
815  msg+= moText("Initializing Live...\n");
816  MODebug2->Message( msg );
817 
818  preferreddevices = m_Config.GetParamIndex("preferreddevices");//FIREWIRE, WEBCAMS, LIVEVIDEO[movie]
819  autoreconnect = m_Config.GetParamIndex("autoreconnect");//FIREWIRE, WEBCAMS, LIVEVIDEO[movie]
820  //MOuint videoin = m_Config.GetParamIndex("videoin");
821 
822  // moText videoinname;
823 
824 /*
825  MODebug2->Message( "VideoManager:: Generating videoin textures" );
826  for(MOuint i=0; i<m_Config.GetValuesCount(videoin); i++ ) {
827  videoinname = m_Config.GetParam(videoin).GetValue(i).GetSubValue(0).Text();
828  if(videoinname!=moText("")) {
829  int tid = m_pResourceManager->GetTextureMan()->AddTexture( MO_TYPE_TEXTURE, videoinname);
830  if(tid>-1) Images.Add( m_pResourceManager->GetTextureMan()->GetTexture(tid));
831  MODebug2->Message( moText("VideoManager:: Added ") + moText(videoinname) );
832  }
833  }
834  */
836  m_bAutoReconnect = (bool) m_Config.GetParam((MOint)autoreconnect).GetValue().GetSubValue().Int();
837 
839  pPreferredDevices = new moCaptureDevices();
840 
841  nvalues = m_Config.GetValuesCount( preferreddevices );
842  m_Config.SetCurrentParamIndex(preferreddevices);
843  /*
844  MO_LIVE_LABELNAME 0
845  MO_LIVE_DEVICENAME 1
846  MO_LIVE_COLORMODE 2
847  MO_LIVE_WIDTH 3
848  MO_LIVE_HEIGHT 4
849  MO_LIVE_BITCOUNT 5
850  MO_LIVE_SCALE_WIDTH 6
851  MO_LIVE_SCALE_HEIGHT 7
852  MO_LIVE_FLIPH 8
853  MO_LIVE_FLIPV 9
854  */
855  MODebug2->Message(moText("Setting preferred devices"));
856  for( MOuint i = 0; i < nvalues; i++) {
857 
858  m_Config.SetCurrentValueIndex(preferreddevices, i);
859 
860  MOint srcw(0),srch(0),srcbpp(0),flH(0),flV(0);
861  MOint ncount = m_Config.GetParam().GetValue().GetSubValueCount();
862 
863 
864  ( MO_LIVE_WIDTH < ncount ) ? srcw = m_Config.GetParam().GetValue().GetSubValue(MO_LIVE_WIDTH).Int() : srcw = 0;
865  ( MO_LIVE_HEIGHT < ncount ) ? srch = m_Config.GetParam().GetValue().GetSubValue(MO_LIVE_HEIGHT).Int() : srch = 0;
866  ( MO_LIVE_BITCOUNT < ncount ) ? srcbpp = m_Config.GetParam().GetValue().GetSubValue(MO_LIVE_BITCOUNT).Int() : srcbpp = 0;
867  ( MO_LIVE_FLIPH < ncount ) ? flH = m_Config.GetParam().GetValue().GetSubValue(MO_LIVE_FLIPH).Int() : flH = 0;
868  ( MO_LIVE_FLIPV < ncount ) ? flV = m_Config.GetParam().GetValue().GetSubValue(MO_LIVE_FLIPV).Int() : flV = 0;
869 
870  moVideoFormat VF;
871  moCaptureDevice CD( m_Config.GetParam().GetValue().GetSubValue(MO_LIVE_DEVICENAME).Text(), moText(""), moText(""), 0, srcw, srch, srcbpp, flH, flV );
872 
873  CD.SetLabelName( m_Config.GetParam().GetValue().GetSubValue(MO_LIVE_LABELNAME).Text() );
874 
875  VF.m_Width = m_Config.GetParam().GetValue().GetSubValue(MO_LIVE_SCALEWIDTH).Int();
876  VF.m_Height = m_Config.GetParam().GetValue().GetSubValue(MO_LIVE_SCALEHEIGHT).Int();
877  VF.m_BitCount = m_Config.GetParam().GetValue().GetSubValue(MO_LIVE_BITCOUNT).Int();
878 
879  VF.m_ColorMode = (moColorMode)m_Config.GetParam().GetValue().GetSubValue(MO_LIVE_COLORMODE).Int();
880 
881  CD.SetVideoFormat( VF );
882  CD.SetPreffered( true );
883 
884  pPreferredDevices->Add( CD );
885  MODebug2->Message(moText("Added preferred device setting: Device Name: ")+CD.GetName());
886  //for( int k = 1; k < m_Config.GetParam().GetSubCount(); k++);
887  }
888 
889 
890 
891  //INITIALIZING LiveSystems
892 
893  //try to connect to all predefined
894 
895 
896  MODebug2->Message(moText("Finally load live systems grabber for each device...."));
897 
898 
899  if (!m_pLiveSystems) return false;
900 
901  m_pLiveSystems->GetVideoFramework()->SetPreferredDevices( pPreferredDevices );
902 
903  GetCaptureDevices();
904 
905  for( int c=0; c<(int)m_CaptureDevices.Count(); c++) {
906  moCaptureDevice CapDev = m_CaptureDevices.Get(c);
907  if (CapDev.IsPreferred()) {
908  moCamera* Cam = CreateCamera( CapDev );
909  if (Cam==NULL) MODebug2->Error("moVideoManager::Init > could not create Camera: " + CapDev.GetName()+ " Label: " + CapDev.GetLabelName() );
910  }
911 
912  }
913 
914  //if ( m_pLiveSystems->LoadLiveSystems( pPreferredDevices ) ) {
915  //los inicializa...
916  // for( MOuint i = 0; i < m_pLiveSystems->Count(); i++) {
917 
918  // moLiveSystemPtr pLS = m_pLiveSystems->Get(i);
919 
920  // if (pLS && pLS->GetCaptureDevice().IsPresent()) {
921 
922  // if (pLS->Init()) {
923 
924  // MODebug2->Message( moText(pLS->GetCaptureDevice().GetName()) + " initialized");
925 
926 /*
927  if ( pLS->GetVideoGraph()->GetVideoFormat().m_WaitForFormat == false && 1==2 ) {
928 
929  moBucketsPool* pBucketsPool = pLS->GetBucketsPool();
930 
931  if ( pBucketsPool!=NULL ) {
932 
933  if ( pBucketsPool->IsFull() ) {
934 
935  moBucket* pbucket = pBucketsPool->RetreiveBucket();
936 
937  if ( pbucket && pLS->GetVideoGraph() ) {
938 
939  //moVideoSample* pSample = new moVideoSample( pLS->GetVideoGraph()->GetVideoFormat(), (MOpointer) pbucket );
940 
942  pLS->GetVideoGraph()->GetState();
943 
944  //if( pSample!=NULL ) {
945 
946  //moTexture * ts =(moTexture*)Images[i];
947  moTexture* ts = pLS->GetTexture();
948 
949  if(ts!=NULL)
950  {
951 
952  if ((ts->GetGLId() <= 0) || (ts->GetWidth() != pLS->GetVideoGraph()->GetVideoFormat().m_Width))
953  {
954  if (ts->GetGLId() != 0) ts->Finish();
955  ts->BuildEmpty(pLS->GetVideoGraph()->GetVideoFormat().m_Width, pLS->GetVideoGraph()->GetVideoFormat().m_Height);
956  }
957 
958  MOubyte* pbuffer = pbucket->GetBuffer();
959 
960  if (pbuffer) {
961  pbucket->Lock();
962  ts->SetBuffer( pbuffer, GL_BGR_EXT);
963  pbucket->Unlock();
964  }
965  }
966 
967 
968  }
969 
970  }
971  }
972  }*/
973  // }
974  // }
975 
976  // }
977 
978 
979  //} else MODebug2->Error(moText("Error. No livesystems loaded??...."));
980 
981 
982  MOuint circularbuffer = m_Config.GetParamIndex("circularbuffer");
983 
984  moText videobufferinput;
985  moText videobuffername;
986  moText videobufferformat;
987  MOint xsource, ysource, width, height, sourcewidth, sourceheight, frames;
988  MOint interpolation, interpolation_jump, interpolation_time;
989 
990  if (circularbuffer>0)
991  for(MOuint i=0; i<m_Config.GetValuesCount(circularbuffer); i++ ) {
992 
993  videobufferinput = m_Config.GetParam(circularbuffer).GetValue(i).GetSubValue(MO_VIDEO_CIRCULARBUFFERINPUT).Text();
994  videobuffername = m_Config.GetParam(circularbuffer).GetValue(i).GetSubValue(MO_VIDEO_CIRCULARBUFFERNAME).Text();
995  videobufferformat = m_Config.GetParam(circularbuffer).GetValue(i).GetSubValue(MO_VIDEO_CIRCULARBUFFERFORMAT).Text();
996 
997  frames = m_Config.GetParam(circularbuffer).GetValue(i).GetSubValue(MO_VIDEO_CIRCULARBUFFERFRAMES).Int();
998  width = m_Config.GetParam(circularbuffer).GetValue(i).GetSubValue(MO_VIDEO_CIRCULARWIDTH).Int();
999  height = m_Config.GetParam(circularbuffer).GetValue(i).GetSubValue(MO_VIDEO_CIRCULARHEIGHT).Int();
1000  xsource = m_Config.GetParam(circularbuffer).GetValue(i).GetSubValue(MO_VIDEO_CIRCULARSOURCEXOFFSET).Int();
1001  ysource = m_Config.GetParam(circularbuffer).GetValue(i).GetSubValue(MO_VIDEO_CIRCULARSOURCEYOFFSET).Int();
1002  sourcewidth = m_Config.GetParam(circularbuffer).GetValue(i).GetSubValue(MO_VIDEO_CIRCULARSOURCEWIDTH).Int();
1003  sourceheight = m_Config.GetParam(circularbuffer).GetValue(i).GetSubValue(MO_VIDEO_CIRCULARSOURCEHEIGHT).Int();
1004 
1005  MODebug2->Message("moVideoManager::Init > CircularVideoBuffer");
1006  MODebug2->Message("moVideoManager::Init > videobufferinput:" + videobufferinput);
1007  MODebug2->Message("moVideoManager::Init > videobuffername:" + videobuffername);
1008  MODebug2->Message("moVideoManager::Init > videobufferformat:" + videobufferformat);
1009  MODebug2->Message("moVideoManager::Init > frames:" + IntToStr(frames));
1010  MODebug2->Message("moVideoManager::Init > width:" + IntToStr(width));
1011  MODebug2->Message("moVideoManager::Init > height:" + IntToStr(height));
1012  MODebug2->Message("moVideoManager::Init > xsource:" + IntToStr(xsource));
1013  MODebug2->Message("moVideoManager::Init > ysource:" + IntToStr(ysource));
1014  MODebug2->Message("moVideoManager::Init > sourcewidth:" + IntToStr(sourcewidth));
1015  MODebug2->Message("moVideoManager::Init > sourceheight:" + IntToStr(sourceheight));
1016 
1017  if(videobufferinput!=moText("")) {
1018  moCircularVideoBuffer* pCircularBuffer = NULL;
1019  int tid = m_pResourceManager->GetTextureMan()->AddTexture( MO_TYPE_CIRCULARVIDEOBUFFER, videobuffername );
1020  if(tid>-1) {
1021  pCircularBuffer = (moCircularVideoBuffer*) m_pResourceManager->GetTextureMan()->GetTexture(tid);
1022  }
1023  if (pCircularBuffer) {
1024  pCircularBuffer->Init( videobufferinput, videobufferformat, GetResourceManager(), frames, width, height, xsource, ysource, sourcewidth, sourceheight);
1025  m_CircularVideoBuffers.Add(pCircularBuffer);
1026  pCircularBuffer->StartRecording();
1027  }
1028  }
1029 
1030  }
1031 
1032  MOuint videobuffer = m_Config.GetParamIndex("videobuffer");
1033 
1034  moText videobufferpath;
1035  //moText videobuffername;
1036  //moText videobufferformat;
1037  //MOint xsource, ysource, width, height, sourcewidth, sourceheight;
1038  if (videobuffer>0)
1039  for(MOuint i=0; i<m_Config.GetValuesCount(videobuffer); i++ ) {
1040 
1041  videobufferpath = m_Config.GetParam(videobuffer).GetValue(i).GetSubValue(0).Text();
1042 
1043  moVideoBufferPath* pVideoBufferPath = new moVideoBufferPath();
1044 
1045  if (pVideoBufferPath) {
1046 
1047  pVideoBufferPath->Init( GetResourceManager(), videobufferpath );
1048  m_VideoBufferPaths.Add(pVideoBufferPath);
1049 
1050  for(MOuint j=0; j < ( m_Config.GetParam(videobuffer).GetValue(i).GetSubValueCount() - 1 ) / 11; j++) {
1051 
1052  videobuffername = m_Config.GetParam(videobuffer).GetValue(i).GetSubValue(j*11+MO_VIDEO_BUFFERNAME).Text();
1053  videobufferformat = m_Config.GetParam(videobuffer).GetValue(i).GetSubValue(j*11+MO_VIDEO_BUFFERFORMAT).Text();
1054 
1055  width = m_Config.GetParam(videobuffer).GetValue(i).GetSubValue(j*11+MO_VIDEO_WIDTH).Int();
1056  height = m_Config.GetParam(videobuffer).GetValue(i).GetSubValue(j*11+MO_VIDEO_HEIGHT).Int();
1057  xsource = m_Config.GetParam(videobuffer).GetValue(i).GetSubValue(j*11+MO_VIDEO_SOURCEXOFFSET).Int();
1058  ysource = m_Config.GetParam(videobuffer).GetValue(i).GetSubValue(j*11+MO_VIDEO_SOURCEYOFFSET).Int();
1059  sourcewidth = m_Config.GetParam(videobuffer).GetValue(i).GetSubValue(j*11+MO_VIDEO_SOURCEWIDTH).Int();
1060  sourceheight = m_Config.GetParam(videobuffer).GetValue(i).GetSubValue(j*11+MO_VIDEO_SOURCEHEIGHT).Int();
1061 
1062  interpolation = m_Config.GetParam(videobuffer).GetValue(i).GetSubValue(j*11+MO_VIDEO_SOURCEINTERPOLATION).Int();
1063  interpolation_jump = m_Config.GetParam(videobuffer).GetValue(i).GetSubValue(j*11+MO_VIDEO_SOURCEINTERPOLATIONJUMP).Int();
1064  interpolation_time = m_Config.GetParam(videobuffer).GetValue(i).GetSubValue(j*11+MO_VIDEO_SOURCEINTERPOLATIONTIME).Int();
1065 
1066  if(videobufferpath!=moText("")) {
1067  moVideoBuffer* pVideoBuffer = NULL;
1068  int tid = m_pResourceManager->GetTextureMan()->AddTexture( MO_TYPE_VIDEOBUFFER, videobuffername );
1069  if(tid>-1) {
1070  pVideoBuffer = (moVideoBuffer*) m_pResourceManager->GetTextureMan()->GetTexture(tid);
1071  }
1072  if (pVideoBuffer) {
1073  pVideoBuffer->Init( videobufferpath, videobufferformat, GetResourceManager(), width, height, xsource, ysource, sourcewidth, sourceheight, interpolation, interpolation_jump, interpolation_time);
1074  pVideoBufferPath->m_VideoBuffers.Add(pVideoBuffer);
1075  }
1076  }
1077  }
1078  }
1079  }
1080 
1081  delete pPreferredDevices;
1082 
1083  } else {
1084 
1088 
1089  }
1090 
1091 
1092  m_bLoading = true;
1093  m_bInitialized = true;
1094 
1095  return true;
1096 }
1097 
1099 {
1100 
1101  if (devcode == 0 ) {
1102  if (state==MO_ON) {
1103  GetCaptureDevices(true);
1104  }
1105  }
1106  return true;
1107 }
1108 
1110 {
1111 
1112  //devcode ahora deberia ser:
1113  //LIVESYSTEM01 0
1114  //LIVESYSTEM02 1
1115  //LIVESYSTEM03 2
1116  //LIVESYSTEM04 3
1117  if (m_pLiveSystems) {
1118 
1119  return m_pLiveSystems->GetStatus( devcode );
1120 
1121  }
1122 
1123  return 0;
1124  //return(-1);
1125 }
1126 
1127 //in this device, GetValue returns the size of the buffer corresponding of a sample of the actual devicecode
1129 {
1130  if( m_pLiveSystems) {
1131 
1132  moLiveSystemPtr pLS = m_pLiveSystems->Get( devcode );
1133 
1134  if (pLS) {
1135 
1136  moVideoGraph* pVideoGraph = pLS->GetVideoGraph();
1137 
1138  if (pVideoGraph) {
1139 
1140  return pVideoGraph->GetVideoFormat().m_BufferSize;
1141 
1142  }
1143 
1144  }
1145  }
1146 
1147  return(-1);
1148 }
1149 
1151 {
1152  //SNAPSHOTS
1153  if (m_pLiveSystems) {
1154  //recorre los livesystems, y por cada nombre....chequea el codigo
1155  for(MOuint i =0; i< m_pLiveSystems->Count(); i++) {
1156  moLiveSystemPtr pLS = m_pLiveSystems->Get(i);
1157  if (pLS) {
1158  if ( pLS->GetLabelName() == strcod ) {
1159  return i;
1160  }
1161  }
1162  }
1163  }
1164 
1165  return(-1);
1166 }
1167 
1169  if (m_pLiveSystems) {
1170  return m_pLiveSystems->Get(cam_idx);
1171  }
1172  return NULL;
1173 }
1174 
1175 moCamera*
1177 
1178  MODebug2->Message("moVideoManager::CreateCamera > " + p_CapDev.GetLabelName()+" for device:"+p_CapDev.GetName()
1179  +" path:"+p_CapDev.GetPath()+
1180  +" (Width)x(Height):" + IntToStr(p_CapDev.GetSourceWidth())+"x" + IntToStr(p_CapDev.GetSourceHeight()) );
1181 
1182  moCaptureDevice cap=p_CapDev;
1183  //cap.m_SourceWidth = 640;
1184  //cap.m_SourceHeight = 480;
1185 
1187  moLiveSystem* pLS = new moLiveSystem(cap);
1189 
1190  if (!pLS) return NULL;
1191 
1192  if (!pLS->Init()) return NULL;
1193 
1194  MODebug2->Message( moText("moVideoManager::CreateCamera > Capture Device "));
1195  MODebug2->Message( moText("moVideoManager::CreateCamera > Capture Device ")
1196  + pLS->GetCaptureDevice().GetName()
1197  + " initialized");
1198 
1199  int mid = TMan->AddTexture( MO_TYPE_TEXTURE, pLS->GetLabelName() );
1200 
1201  moTexture * ts = NULL;
1202 
1203  if (mid>-1) ts = TMan->GetTexture(mid);
1204 
1205  if(ts)
1206  {
1207  pLS->SetTexture(ts);
1208  MODebug2->Message("moVideoManager::CreateCamera > texture added ok: " + ts->GetName() );
1209  } else {
1210  MODebug2->Error("moVideoManager::CreateCamera > texture not added. " +ts->GetName() );
1211  }
1212 
1213 /*
1214  if ( pLS->GetVideoGraph()->GetVideoFormat().m_WaitForFormat == false && 1==2 ) {
1215 
1216  moBucketsPool* pBucketsPool = pLS->GetBucketsPool();
1217 
1218  if ( pBucketsPool==NULL ) return NULL;
1219 
1220  if ( pBucketsPool->IsFull() ) {
1221 
1222  moBucket* pbucket = pBucketsPool->RetreiveBucket();
1223 
1224  if ( pbucket && pLS->GetVideoGraph() ) {
1225 
1226  //moVideoSample* pSample = new moVideoSample( pLS->GetVideoGraph()->GetVideoFormat(), (MOpointer) pbucket );
1227 
1229  pLS->GetVideoGraph()->GetState();
1230 
1231 
1232  int mid = TMan->AddTexture( MO_TYPE_TEXTURE, pLS->GetLabelName() );
1233  moTexture * ts = NULL;
1234  if (mid>-1) ts = TMan->GetTexture(mid);
1235  pLS->SetTexture(ts);
1236  if(ts!=NULL)
1237  {
1238  MODebug2->Log("moVideoManager::CreateCamera > texture added ok: " + ts->GetName() );
1239  if ((ts->GetGLId() <= 0) || (ts->GetWidth() != pLS->GetVideoGraph()->GetVideoFormat().m_Width))
1240  {
1241  if (ts->GetGLId() != 0) ts->Finish();
1242  ts->BuildEmpty(pLS->GetVideoGraph()->GetVideoFormat().m_Width, pLS->GetVideoGraph()->GetVideoFormat().m_Height);
1243  }
1244 
1245  MOubyte* pbuffer = pbucket->GetBuffer();
1246 
1247  if (pbuffer) {
1248  pbucket->Lock();
1249  ts->SetBuffer( pbuffer, GL_BGR_EXT);
1250  pbucket->Unlock();
1251  }
1252 
1253  }
1254  }
1255  }
1256  }
1257  */
1258 
1259  m_pLiveSystems->Add( pLS );
1260  MODebug2->Message( moText("Added LiveSystem: Label Name: ") + pLS->GetCaptureDevice().GetLabelName()
1261  + moText(" Device Name:") + pLS->GetCaptureDevice().GetName() );
1262 
1263  return (moCamera*)pLS;
1264 }
1265 
1266 moCamera*
1267 moVideoManager::GetCameraByName( const moText& camera, bool load, moCaptureDevice customCD ) {
1268 
1269  moCamera* Cam = NULL;
1270 
1272  MODebug2->Message("*******************************************");
1273  MODebug2->Message("Searching camera");
1274  MODebug2->Message("*******************************************");
1275  MODebug2->Message("moVideoManager::GetCameraByName > Check if we have the camera loaded");
1276  if (m_pLiveSystems) {
1277  for( int c=0; c<(int)m_pLiveSystems->Count(); c++ ) {
1278  Cam = m_pLiveSystems->Get(c);
1279  if (Cam) {
1280  if (Cam->GetCaptureDevice().GetLabelName()==camera
1281  ||
1282  Cam->GetCaptureDevice().GetName()==camera
1283  ||
1284  Cam->GetCaptureDevice().GetPath()==camera
1285  ||
1286  ( camera=="default" && c>=0 && Cam->GetVideoGraph() )
1287  ) {
1288  MODebug2->Message("moVideoManager::GetCameraByName > camera already loaded, returning: "+camera);
1289  return Cam;
1290  }
1291  }
1292  }
1293  }
1294 
1295 
1296  std::string rtsp = (char*)camera;
1297  MODebug2->Message("*******************************************");
1298  MODebug2->Message("Searching capture devices");
1299  MODebug2->Message("Capture devices#: "+IntToStr(m_CaptureDevices.Count()) );
1300  MODebug2->Message("*******************************************");
1301  MODebug2->Message("moVideoManager::GetCameraByName > founded: camera: " + camera );
1303  for(int d=0;d<(int)m_CaptureDevices.Count();d++) {
1304 
1305  moCaptureDevice m_CapDev = m_CaptureDevices[d];
1306 
1307  if (m_CapDev.GetName()==camera
1308  ||
1309  m_CapDev.GetLabelName()==camera
1310  ||
1311  m_CapDev.GetPath()==camera
1312  ||
1313  ( camera=="default" && d>=0 && m_CapDev.IsPresent() )
1314  ) {
1316  MODebug2->Message("moVideoManager::GetCameraByName > founded: camera: " + camera );
1317  if (load) {
1318  moCaptureDevice newCD = m_CapDev;
1319 
1321  //chequear video format
1322  newCD.GetVideoFormat().m_Width = 256;
1323  newCD.GetVideoFormat().m_Height = 256;
1324  //newCD.GetVideoFormat().m_ColorMode = (moColorMode) ;
1325  newCD.GetVideoFormat().m_BitCount = 24;
1326  newCD.GetVideoFormat().m_ColorMode = (moColorMode) 0;
1327 
1328  }
1329 
1330  // apply custom capture device values from customCD
1331  MODebug2->Message("moVideoManager::GetCameraByName > customCD: WxH:"+IntToStr(customCD.m_SourceWidth) + "x" + IntToStr(customCD.m_SourceHeight));
1332 
1333  if ( /*customCD.GetLabelName()!=""
1334  && */(customCD.GetVideoFormat().m_Width>0
1335  && customCD.GetVideoFormat().m_Height>0)
1336  || (
1337  customCD.m_SourceWidth>0
1338  &&
1339  customCD.m_SourceHeight>0
1340  ) ) {
1341  newCD = customCD;
1342  newCD.SetName( m_CapDev.GetName() );
1343  newCD.SetLabelName( m_CapDev.GetLabelName() );
1345  moMathi mathI;
1346  if ( !mathI.IsPowerOfTwo( newCD.GetVideoFormat().m_Width ) ) {
1348  }
1349  if ( !mathI.IsPowerOfTwo( newCD.GetVideoFormat().m_Height ) ) {
1351  }
1352  }
1353  }
1354  if ( newCD.GetName()=="default" && camera!="default") {
1355  newCD.SetName(camera);
1356  }
1357  Cam = CreateCamera( newCD );
1358  return Cam;
1359  }
1360  }
1361  }
1362 
1363  if ( rtsp.find("rtsp")==0 || rtsp.find("RTSP")==0
1364  || rtsp.find("http")==0 || rtsp.find("HTTP")==0
1365  || rtsp.find("https")==0 || rtsp.find("HTTPS")==0 ) {
1366  MODebug2->Message("###########################################");
1367  MODebug2->Message("Adding rtsp/http stream as CaptureDevice...");
1368  MODebug2->Message("###########################################");
1369  moCaptureDevice m_StreamDev;
1370  m_StreamDev.SetName(camera);
1371  m_StreamDev.SetLabelName( moText("LIVEIN")+IntToStr(m_CaptureDevices.Count()) );
1372  m_StreamDev.m_Path = camera;
1373 
1374  m_StreamDev.GetVideoFormat() = customCD.GetVideoFormat();
1375  //m_StreamDev.GetVideoFormat().m_Height = 256;
1376  //newCD.GetVideoFormat().m_ColorMode = (moColorMode) ;
1377  //newCD.GetVideoFormat().m_BitCount = 24;
1378  //newCD.GetVideoFormat().m_ColorMode = (moColorMode) 0;
1379 
1380 
1381  m_CaptureDevices.Add(m_StreamDev);
1382  Cam = CreateCamera( m_StreamDev );
1383  return Cam;
1384  }
1385 
1386  return NULL;
1387 }
1388 
1390  if (m_pLiveSystems)
1391  return m_pLiveSystems->Count();
1392  return 0;
1393 }
1394 
1395 const moTextArray&
1397 
1399  return m_CameraDevices;
1403 }
1404 
1405 const moCaptureDevices&
1407  if (m_pLiveSystems && m_pLiveSystems->GetVideoFramework()) {
1408  if (reload) {
1409  m_CaptureDevices = (*m_pLiveSystems->GetVideoFramework()->LoadCaptureDevices());
1410  } /*else m_CaptureDevices = (*m_pLiveSystems->GetVideoFramework()->GetCaptureDevices());*/
1411  }
1412  return m_CaptureDevices;
1413 }
1414 
1416  return m_CircularVideoBuffers.GetRef(cb_idx);
1417 }
1418 
1420  return m_CircularVideoBuffers.Count();
1421 }
1422 
1424  return m_VideoBufferPaths.GetRef(vb_idx);
1425 }
1426 
1428  return m_VideoBufferPaths.Count();
1429 }
1430 
1432 
1433  moVideoBuffer* pVideoBuffer = NULL;
1434 
1435  moVideoBufferPath* pVideoBufferPath = m_VideoBufferPaths.GetRef(vb_idx);
1436 
1437  if (pVideoBufferPath) {
1438  if (pVideoBufferPath->m_VideoBuffers.Count()>0) {
1439  pVideoBuffer = pVideoBufferPath->m_VideoBuffers.GetRef(0);
1440  }
1441  }
1442  return pVideoBuffer;
1443 }
1444 
1446  return m_VideoBufferPaths.Count();
1447 }
1448 
1449 #include <gst/gst.h>
1450 
1452 
1453  moText timecodestr;
1454  MOulonglong years,oneyear;
1455  MOulonglong days,oneday;
1456  MOulonglong hours,onehour;
1457  MOulonglong minutes,oneminute;
1458  MOulonglong seconds,onesecond;
1459  MOulonglong miliseconds,onemilisecond;
1460  //MOulonglong nanos;
1461 
1462  //nanos = 0;
1463  onemilisecond = GST_MSECOND;
1464  onesecond = GST_SECOND;
1465  oneminute = 60 * onesecond;
1466  onehour = 60 * oneminute;
1467  oneday = 24 * onehour;
1468  oneyear = 365 * oneday;
1469 
1470  years = duration / oneyear; duration = duration - years * oneyear;
1471  days = duration / oneday; duration = duration - days * oneday;
1472  hours = duration / onehour; duration = duration - hours * onehour;
1473  minutes = duration / oneminute; duration = duration - minutes * oneminute;
1474  seconds = duration / onesecond; duration = duration - seconds * onesecond;
1475  miliseconds = duration / onemilisecond; duration = duration - miliseconds * onemilisecond;
1476  //nanos = duration - seconds * onesecond;
1477  timecodestr = "";
1478  if (years>0) timecodestr = IntToStr(years) + " years ";
1479  if (days>0) timecodestr+= IntToStr(days) + " days ";
1480  if (hours>0) { timecodestr+= IntToStr(hours,2) + ":"; }
1481  else { timecodestr+= "00:"; }
1482  if (minutes>0) { timecodestr+= IntToStr(minutes,2) + ":"; }
1483  else { timecodestr+= "00:"; }
1484  if (seconds>0) { timecodestr+= IntToStr(seconds,2) + "."; }
1485  else { timecodestr+= "00."; }
1486  if (miliseconds>0) { timecodestr+= IntToStr(miliseconds/10,2); }
1487  else { timecodestr+= "00"; }
1488  return timecodestr;
1489 }
1490 
1491 moText moVideoManager::FramesToTimecode( MOulonglong duration, double framespersecond ) {
1492 
1493  moText timecodestr;
1494  double years,oneyear;
1495  double days,oneday;
1496  double hours,onehour;
1497  double minutes,oneminute;
1498  double seconds,onesecond;
1499  double miliseconds,onemilisecond;
1500  //double nanos;
1501  double frames,durationF;
1502 
1503  //nanos = 0;
1504  onemilisecond = framespersecond/1000.0f;
1505  onesecond = framespersecond;
1506  oneminute = 60 * onesecond;
1507  onehour = 60 * oneminute;
1508  oneday = 24 * onehour;
1509  oneyear = 365 * oneday;
1510  durationF = duration;
1511 
1512  years = moMathd::Floor(durationF / oneyear); duration = duration - (long)(years * oneyear);durationF=duration;
1513  days = moMathd::Floor(durationF / oneday); duration = duration - (long)(days * oneday);durationF=duration;
1514  hours = moMathd::Floor(durationF / onehour); duration = duration - (long)(hours * onehour);durationF=duration;
1515  minutes = moMathd::Floor(durationF / oneminute); duration = duration - (long)(minutes * oneminute);durationF=duration;
1516  seconds = moMathd::Floor(durationF / onesecond); duration = duration - (long)(seconds * onesecond);durationF=duration;
1517  frames = moMathd::Floor(durationF); duration = duration - (long)(frames*1.0);durationF=duration;
1518  miliseconds = moMathd::Floor(durationF / onemilisecond); duration = duration - (long)(miliseconds * onemilisecond);durationF=duration;
1519 
1520  //nanos = duration - seconds * onesecond;
1521  timecodestr = "";
1522  if (years>0) timecodestr = IntToStr((long)years) + " years ";
1523  if (days>0) timecodestr+= IntToStr((long)days) + " days ";
1524  if (hours>0) { timecodestr+= IntToStr((long)hours) + ":"; }
1525  else { timecodestr+= "00:"; }
1526  if (minutes>0) { timecodestr+= IntToStr((long)minutes,2) + ":"; }
1527  else { timecodestr+= "00:"; }
1528  if (seconds>0) {timecodestr+= IntToStr((long)seconds,2) + ":"; }
1529  else { timecodestr+= "00:"; }
1530  if (frames>0) { timecodestr+= IntToStr((long)frames,2) + "."; }
1531  else { timecodestr+= "00."; }
1532  if (miliseconds>0) { timecodestr+= IntToStr((int)miliseconds); }
1533  else { timecodestr+= "000"; }
1534 
1535  return timecodestr;
1536 
1537 }
1538 
1539 
1540 //esto se ejecuta por cada CICLO PRINCIPAL DE moConsole(frame)
1541 //por ahora no nos sirve de nada, porque no mandamos events....ni procesamos events...
1542 //al menos que Ligia...o algun device especial(nada mas el hecho de que se haya
1543 //enchufado la camara por ejemplo
1544 //podriamos poner una funcion aqui de reconocimiento de DV....
1546 {
1547  moBucket *pbucket = NULL;
1548  moEvent *actual,*tmp;
1549  moLiveSystemPtr pLS;
1550  moVideoSample* pSample = NULL;
1551  MOubyte* pbuffer = NULL;
1552 
1553  if(!m_pLiveSystems) return;
1554 
1555  if ( GetId() == MO_MOLDEOOBJECT_UNDEFINED_ID ) return;
1556 
1557  if (m_bAutoReconnect) {
1558  m_pLiveSystems->UpdateLiveSystems();
1559  }
1560 
1561  actual = p_EventList->First;
1562  //recorremos todos los events y parseamos el resultado
1563  //borrando aquellos que ya usamos
1564  while(actual!=NULL) {
1565  if(actual->deviceid == GetId() ) {
1566  pLS = m_pLiveSystems->Get(actual->devicecode);
1567  if ( pLS!=NULL ) {
1568  moBucketsPool* pBucketsPool = pLS->GetBucketsPool();
1569  if ( pBucketsPool!=NULL ) {
1570  pBucketsPool->DestroyRetreivedBucket();
1571  }
1572  pSample = (moVideoSample*)actual->pointer;
1573  delete pSample;
1574  pSample = NULL;
1575  }
1576  tmp = actual->next;
1577  p_EventList->Delete(actual);
1578  actual = tmp;
1579  } else actual = actual->next;//no es el que necesitamos...
1580  }
1581 
1582  //aquí moLive da de alta en la lista un evento con su id, devicecode, size y pointer
1583  //a cada vez que tiene un Bucket lleno....
1584  for( MOuint i =0; i< m_pLiveSystems->Count(); i++) {
1585 
1586  pLS = m_pLiveSystems->Get(i);
1587 
1588  if ( pLS!=NULL ) {
1589 
1590  moBucketsPool* pBucketsPool = pLS->GetBucketsPool();
1591 
1592  if ( pBucketsPool!=NULL ) {
1593 
1594  if ( pBucketsPool->IsFull() ) {
1595 
1596  pbucket = pBucketsPool->RetreiveBucket();
1597 
1598  if ( pbucket && pLS->GetVideoGraph() ) {
1599 
1600  pSample = new moVideoSample( pLS->GetVideoGraph()->GetVideoFormat(), (MOpointer) pbucket );
1601 
1603  pLS->GetVideoGraph()->GetState();
1604 
1605  if( pSample!=NULL ) {
1606  //moTexture * ts =(moTexture*)Images[i];
1607  moTexture* ts = (moTexture*) pLS->GetTexture();
1608 
1609  if(ts!=NULL)
1610  {
1611 
1612  if ((ts->GetGLId() == 0) || (ts->GetWidth() != pSample->m_VideoFormat.m_Width))
1613  {
1614  if (ts->GetGLId() != 0) ts->Finish();
1615  ts->BuildEmpty( pSample->m_VideoFormat.m_Width, pSample->m_VideoFormat.m_Height );
1616  }
1617 
1618  pbuffer = pbucket->GetBuffer();
1619 
1620  if (pbuffer) {
1621  pbucket->Lock();
1622 
1623 
1624  moVideoFormat vf = pSample->m_VideoFormat;
1625 
1626  if (vf.m_BitCount>0 && vf.m_BitCount<=64) {
1627 
1628  if (vf.m_RedMask==255 && vf.m_BufferSize>0) {
1630  int bypp = (vf.m_BitCount>>3);
1631  for( int a=0; a<(int)vf.m_BufferSize; a+=bypp ) {
1632  BYTE* pix = &pbuffer[a];
1633  BYTE u = pix[0];
1634  pix[0] = pix[2];
1635  pix[2] = u;
1636  }
1637  }
1638 
1639  ts->SetBuffer( pbuffer, GL_RGB);
1640 
1641  } else {
1642  //MODebug2->Error("moVideoManager::Update > error");
1643 #ifndef OPENGLESV2
1644 #ifdef MO_MACOSX
1645  ts->SetBuffer( pbuffer, GL_RGB);
1646 #else
1647  #ifdef GSTVERSION
1648  ts->SetBuffer( pbuffer, GL_RGB);
1649  #else
1650  ts->SetBuffer( pbuffer, GL_BGR_EXT);
1651  #endif
1652 #endif
1653 #else
1654  ts->SetBuffer( pbuffer, GL_RGB);
1655 #endif
1656 
1657  }
1658 
1659  pbucket->Unlock();
1660  }
1661 
1662  //Update Circular buffers
1663  bool circularvbuf_check = (m_CircularVideoBuffers.Count()==0);
1664  for( MOuint c=0; c<m_CircularVideoBuffers.Count(); c++) {
1665 
1666  moCircularVideoBuffer* pCircularVideoBuffer;
1667  pCircularVideoBuffer = m_CircularVideoBuffers[c];
1668  if (pCircularVideoBuffer &&
1669  pCircularVideoBuffer->GetVideoInput() == ts->GetName() ) {
1670  circularvbuf_check = true;
1671  if (pCircularVideoBuffer->IsRecording()) {
1672  pCircularVideoBuffer->LoadSample( pSample );
1673  }
1674  }
1675 
1676  }
1677  if (circularvbuf_check==false) {
1678  MODebug2->Warning( moText("moVideoManager::Update > ") + ts->GetName() +
1679  moText(" texture not used in any circular video buffers."));
1680  } else {
1681  //MODebug2->Message( moText("moVideoManager::Update > ") + ts->GetName() + moText(" used.") );
1682 
1683  }
1684 
1685  }
1686 
1687  //post to other moldeo objects
1688 
1689  //p_EventList->Add( GetId(), i, -1, (unsigned char*)pSample);
1690  delete pSample;
1691 
1692  //MODebug2->Push( moText("moVideoManager::Update Video Sample") );
1693 
1694  }
1695  pBucketsPool->DestroyRetreivedBucket();
1696 
1697  }
1698 
1699  }
1700 
1701  }
1702 
1703  }
1704  }
1705 
1706  for( MOuint c=0; c<m_CircularVideoBuffers.Count(); c++) {
1707 
1708  moCircularVideoBuffer* pCircularVideoBuffer;
1709  pCircularVideoBuffer = m_CircularVideoBuffers[c];
1710 
1711  if (pCircularVideoBuffer) {
1712  if (pCircularVideoBuffer->IsRecording()) {
1713 
1714  //MODebug2->Message("moVideoManager::Update > Check CVBs");
1715  //pCircularVideoBuffer->LoadSample( pSample );
1716  }
1717  }
1718 
1719  }
1720 
1721 
1722  //LOADING ROUTINE
1723  for(MOuint k=0; k<m_VideoBufferPaths.Count(); k++) {
1724 
1725  moVideoBufferPath* pVideoBufferPath = m_VideoBufferPaths[k];
1726 
1727  if (pVideoBufferPath && !pVideoBufferPath->LoadCompleted()) {
1728  pVideoBufferPath->UpdateImages( 1 );
1729  if ( (pVideoBufferPath->GetImagesProcessed() % 100) == 0) {
1730  MODebug2->Message( pVideoBufferPath->GetPath() + moText(":") + IntToStr(pVideoBufferPath->GetImagesProcessed()));
1731  }
1732  if (pVideoBufferPath->LoadCompleted()) {
1733  MODebug2->Message( "LoadCompleted:" + pVideoBufferPath->GetPath() + moText(":") + IntToStr(pVideoBufferPath->GetImagesProcessed()));
1734  }
1735  }
1736 
1737 
1738 
1739  }
1740 }
1741 
1742 //================================
1743 // Solo soporta 4 camaras DV, 4 webcams, o 2 videos en vivo
1744 //================================
1746 
1747  moBucket *pbucket;
1748 
1749  if (m_pLiveSystems) {
1750 
1751  moLiveSystemPtr pLS = m_pLiveSystems->Get( devcode );
1752 
1753  if (pLS) {
1754  if( pLS->GetBucketsPool() != NULL ) {
1755  pbucket = pLS->GetBucketsPool()->RetreivedBucket();
1756  if(pbucket!=NULL) {
1757  moVideoSample* pSample = NULL;
1758  pSample = pLS->GetVideoSample();
1759  if (pSample!=NULL) {
1760  pSample->SetVideoSample( pLS->GetVideoGraph()->GetVideoFormat(), (MOpointer) pbucket->GetBuffer());
1761  return (MOpointer)pSample;
1762  }
1763  }
1764  }
1765  }
1766 
1767  }
1768 
1769  return NULL;
1770 }
1771 
1772 
1774 {
1775  if (m_pLiveSystems) {
1776  m_pLiveSystems->UnloadLiveSystems();
1777  delete m_pLiveSystems;
1778  m_pLiveSystems = NULL;
1779  }
1780  for(MOuint k=0;k<m_VideoBufferPaths.Count();k++) {
1781  moVideoBufferPath* pVideoBufferPath = m_VideoBufferPaths[k];
1782  if (pVideoBufferPath) {
1783  pVideoBufferPath->Finish();
1784  delete pVideoBufferPath;
1785  }
1786  }
1787  m_VideoBufferPaths.Empty();
1788  return true;
1789 }
1790 
1791 
1792 
1793 //=============================================================================================
1794 //
1795 //=============================================================================================
1796 
1797 
1799 
1800  m_pBucketsPool = NULL;
1801  m_pVideoGraph = NULL;
1802  m_pVideoSample = NULL;
1803 
1804  m_Type = LST_UNKNOWN;
1805 
1806 }
1807 
1808 
1810  Finish();
1811 }
1812 
1813 
1815 
1816  m_pBucketsPool = NULL;
1817  m_pVideoGraph = NULL;
1818  m_pVideoSample = NULL;
1819  m_pTexture = NULL;
1820 
1821  m_CaptureDevice = p_capdev;
1822 
1823  //en fuincion del device path: elegimos este
1824  if ( p_capdev.GetPath() != moText("") ) {
1825  m_Type = LST_VIDEOCAMERA;
1826  }
1827 }
1828 
1829 bool
1831 
1832  if ( m_pBucketsPool!=NULL ) Finish();
1833 
1834  m_pBucketsPool = new moBucketsPool();
1835 
1836  #ifdef MO_WIN32
1837  #ifdef MO_DIRECTSHOW
1838  moDsGraph* pDsGraph;
1839  pDsGraph = new moDsGraph();
1840  m_pVideoGraph = (moVideoGraph*) pDsGraph;
1841  #else
1842  moGsGraph* pGsGraph;
1843  pGsGraph = new moGsGraph();
1844  m_pVideoGraph = (moVideoGraph*) pGsGraph;
1845  #endif
1846  #else
1847  moGsGraph* pGsGraph;
1848  pGsGraph = new moGsGraph();
1849  m_pVideoGraph = (moVideoGraph*) pGsGraph;
1850  //ETC...
1851  #endif
1852 
1853  if ( m_pVideoGraph ) {
1854  if (m_pVideoGraph->InitGraph()) {
1855  if( m_pVideoGraph->BuildLiveGraph( m_pBucketsPool , m_CaptureDevice ) ) {
1856  m_CaptureDevice.SetVideoFormat( m_pVideoGraph->GetVideoFormat() );
1857  m_pVideoGraph->Play();
1858  //printf("Device initialized.....\n");
1859  m_pVideoSample = new moVideoSample( m_pVideoGraph->GetVideoFormat(), NULL );
1860  } else Finish();
1861  } else Finish();
1862  } else Finish();
1863 
1864 
1865 
1866  return (m_pBucketsPool && m_pVideoGraph && m_pVideoSample);
1867 
1868 }
1869 
1870 void
1872  if (m_pVideoGraph!=NULL) {
1873  m_pVideoGraph->FinishGraph();
1874  delete m_pVideoGraph;
1875  m_pVideoGraph = NULL;
1876  }
1877 
1878  if (m_pBucketsPool!=NULL) {
1879  delete m_pBucketsPool;
1880  m_pBucketsPool = NULL;
1881  }
1882 
1883  if (m_pVideoSample) {
1884  delete m_pVideoSample;
1885  m_pVideoSample = NULL;
1886  }
1887 }
1888 
1889 void
1891  m_pTexture = p_Texture;
1892 }
1893 
1894 void
1896  m_Type = p_Type;
1897 }
1898 
1901  return m_Type;
1902 }
1903 
1904 moText
1906  return m_CaptureDevice.GetLabelName();
1907 }
1908 
1909 moText
1911  return m_CaptureDevice.GetName();
1912 }
1913 
1914 moVideoGraph*
1916 
1917  return (moVideoGraph*)m_pVideoGraph;
1918 
1919 }
1920 
1923 
1924  return m_pVideoSample;
1925 
1926 }
1927 
1928 
1929 moTexture*
1931  return m_pTexture;
1932 }
1933 
1934 void
1936  m_CaptureDevice = p_capdev;
1937 }
1938 
1941  return m_CaptureDevice;
1942 }
1943 
1946  return m_pBucketsPool;
1947 }
1948 
1949 //=============================================================================================
1950 //
1951 //=============================================================================================
1952 
1954 
1955  m_pVideoFramework = NULL;
1956 
1957  #ifdef MO_DIRECTSHOW
1958  m_pVideoFramework = (moVideoFramework*) new moDsFramework();
1959  #endif
1960 
1961  #ifdef MO_GSTREAMER
1962  m_pVideoFramework = new moGsFramework();
1963  #endif
1964 
1965  #ifdef MO_QUICKTIME
1966  m_pVideoFramework = (moVideoFramework*) new moQtFramework();
1967  #endif
1968 }
1969 
1970 
1972  if (m_pVideoFramework!=NULL) {
1973  delete m_pVideoFramework;
1974  m_pVideoFramework = NULL;
1975  }
1976 }
1977 
1978 bool
1979 moLiveSystems::LoadLiveSystems( moCaptureDevices* p_pPreferredDevices ) {
1980 
1981  moText CodeStr;
1982 
1983  //genera los descriptores de dispositivos de captura...
1984  m_pVideoFramework->SetPreferredDevices( p_pPreferredDevices );
1985 
1986  moCaptureDevices* pCapDevs = m_pVideoFramework->LoadCaptureDevices();
1987 
1991  /*
1992  for( i = 0; i < (int)pCapDevs->Count(); i++) {
1993  moLiveSystemPtr pLS = new moLiveSystem( pCapDevs->Get(i) );
1994  if (pLS) {
1995 
1996  Add( pLS );
1997  moDebugManager::Message( moText("Added LiveSystem: CodeName:") + (moText)CodeStr + moText(" Device Name:") + pCapDevs->Get(i).GetName() );
1998  }
1999  }
2000 */
2001  //y el resto de los sistemas los inicializamos vacios
2002  /*
2003  for( i = pCapDevs->Count(); i < 7; i++) {
2004  moCaptureDevice Cap( moText(""), moText(""), moText("") );
2005  Cap.Present(false);
2006  moLiveSystemPtr pLS = new moLiveSystem( Cap );
2007  if (pLS) {
2008  Add( pLS );
2009  }
2010  }
2011 */
2012  return ( pCapDevs->Count() > 0 );
2013 
2014 }
2015 
2016 bool
2018 
2019  moCaptureDevices* pCapDevs = m_pVideoFramework->UpdateCaptureDevices();
2020 
2021  int oldCount = Count();
2022 
2023  for( MOuint i = 0; i < pCapDevs->Count(); i++) {
2024 
2025  if ( pCapDevs->Get(i).IsPresent() ) {
2026 
2027  moLiveSystemPtr pLS = Get(i);
2028 
2029  if ( pLS!=NULL ) {
2030  if ( pLS->GetCaptureDevice().GetPath() == moText("") &&
2031  !pLS->GetCaptureDevice().IsPresent() ) {
2032 
2033  //NEW ONE!!!!!!!!!!
2034  pLS->SetCaptureDevice( pCapDevs->Get(i) );
2035  //Check if it is really present...maybe it was unplugged entering this loop...
2036  if (m_pVideoFramework->CheckCaptureDevice( i )) {
2037  m_pVideoFramework->SetPreferredFormat( pCapDevs->Get(i) );
2038  pLS->Init();
2039  }
2040 
2041 
2042 
2043  } else if ( pLS->GetCaptureDevice().GetPath() == pCapDevs->Get(i).GetPath() &&
2044  !pLS->GetCaptureDevice().IsPresent()) {
2045  //RECONNECT: OLD ONE
2046  if (m_pVideoFramework->CheckCaptureDevice( i )) {
2047  moCaptureDevice Cap;
2048  Cap = pLS->GetCaptureDevice();
2049  Cap.Present(true);
2050  pLS->SetCaptureDevice( Cap );
2051  pLS->Init();
2052  }
2053  }
2054  }
2055 
2056  /*
2057  if (i>=Count()) {
2058  //ITS A NEW ONE!!! ADD A LIVESYSTEM TO HANDLE IT
2059  moLiveSystemPtr pLS = new moLiveSystem( pCapDevs->Get(i) );
2060  if (pLS) {
2061 
2062  moText CodeStr = "LIVE";
2063  CodeStr+= IntToStr(i);
2064 
2065  pLS->SetCodeName( CodeStr );
2066 
2067  Add( pLS );//beware, count = count + 1
2068  pLS->Init();
2069  }
2070  } else {
2071 
2072  //IT'S AN OLD ONE, BUT MAYBE WASNT CONNECTED BEFORE
2073  moLiveSystemPtr pLS = Get(i);
2074  if ( pLS!=NULL ) {
2075  if ( !pLS->GetVideoGraph()->IsRunning() ) {
2076  //Check if it is really present...maybe it was unplugged entering this loop...
2077  if (m_VideoFramework.CheckCaptureDevice( i )) {
2078  pLS->Init();
2079  } else {
2080  pLS->Finish();
2081  }
2082  }
2083  }
2084 
2085  } */
2086  } else {
2087 
2088  //UNCONNECT IT !!
2089  if ( i<Count() ) {
2090  moLiveSystemPtr pLS = Get(i);
2091  if ( pLS!=NULL && pLS->GetCaptureDevice().IsPresent() ) {
2092  if (pLS->GetVideoGraph()!=NULL) {
2093  if ( !pLS->GetVideoGraph()->IsRunning() ) {
2094  pLS->Finish();//we will reconnect it later if the device is present again
2095  moCaptureDevice Cap;
2096  Cap = pLS->GetCaptureDevice();
2097  Cap.Present(false);
2098  pLS->SetCaptureDevice( Cap );
2099 
2100  }
2101  }
2102  }
2103  }
2104 
2105  }
2106  }
2107 
2108 
2109  return ( (int)Count() > oldCount );
2110 
2111 }
2112 
2113 bool
2115 
2116  moLiveSystemPtr pLS = NULL;
2117 
2118  m_pVideoFramework->CleanCaptureDevices();
2119 
2120  for( MOuint i= 0; i< Count(); i++ ) {
2121  pLS = Get(i);
2122  if (pLS!=NULL) {
2123  pLS->Finish();
2124  delete pLS;
2125  pLS = NULL;
2126  }
2127  }
2128  Empty();
2129  return (Count()==0);
2130 }
2131 
2134 
2135  return m_pVideoFramework;
2136 
2137 }
2138 
2139 bool
2141 
2142  moLiveSystemPtr pLS;
2143  pLS = Get( p_devcode );
2144  if (pLS!=NULL) {
2145  if (p_devcode==0) {
2146  return pLS->GetCaptureDevice().IsPresent();
2147  }
2148  return pLS->GetCaptureDevice().IsPresent();
2149  }
2150  return false;
2151 
2152 }
2153 
2154 
2155 //===========================================
2156 //
2157 // moVideoIn
2158 //
2159 //===========================================
2160 
2162 
2163 }
2164 
2166 
2167 }
2168 
2169 MOboolean
2171  return true;
2172 }
2173 
2174 MOboolean
2176  return true;
2177 }
2178 
2179 
2180 //===========================================
2181 //
2182 // moVideoOut
2183 //
2184 //===========================================
2185 
2186 
2188 
2189 }
2190 
2192 
2193 }
2194 
2195 
2196 MOboolean
2198  return true;
2199 }
2200 
2201 MOboolean
2203  return true;
2204 }
2205 
2206 
2207 
virtual MOboolean Finish()
void moBitmap
Definition: moTexture.h:44
#define MO_VIDEO_SOURCEINTERPOLATIONJUMP
virtual void JumpRecording(long at_position)
virtual MOboolean Finish()
Finaliza el objeto, libera recursos.
MOint m_SourceWidth
PUERTO DEL DISPOSITIVO.
Definition: moVideoGraph.h:475
virtual MOboolean Finish()
moEvent * next
Definition: moEventList.h:60
moFileType GetType()
Definition: moFile.cpp:442
virtual void SetInterpolation(MOuint p_FrameJump, MOuint p_InterpolationTime)
Definition: moTexture.cpp:1636
buffer de texturas
Definition: moTexture.h:59
moEvent * First
Definition: moEventList.h:145
moText GetLabelName()
moVideoFormat GetVideoFormat()
Devuelve el formato de video.
Clase Evento.
Definition: moEventList.h:56
moBucketsPool * GetBucketsPool()
int GetSourceHeight() const
Devuelve el alto de la imagen de origen.
Definition: moVideoGraph.h:438
const moCaptureDevices & GetCaptureDevices(bool reload=true)
#define MO_VIDEO_HEIGHT
void Error(moText p_text)
Anuncia y registra un error.
Definition: moAbstract.cpp:79
GLint internal_format
Definition: moTypes.h:546
bool DestroyRetreivedBucket()
Definition: moBuckets.cpp:246
#define MO_VIDEO_CIRCULARSOURCEWIDTH
#define MO_VIDEO_BUFFERFORMAT
Plataforma de reproducción de video, actualmente GStreamer para todas las plataformas.
Definition: moVideoGraph.h:496
MOuint m_BufferSize
Definition: moVideoGraph.h:208
#define MO_VIDEO_CIRCULARBUFFERFORMAT
MOint deviceid
Definition: moEventList.h:62
MOpointer pointer
Definition: moEventList.h:68
MOuint m_RedMask
Definition: moVideoGraph.h:211
moColorMode
Formatos de codificacion de color.
Definition: moVideoGraph.h:123
moVideoSample * GetVideoSample()
#define MO_LIVE_SCALEWIDTH
MOboolean Delete(moEvent *ev)
MOswitch GetStatus(MOdevcode)
moDefineDynamicArray(moCircularVideoBuffers) moDefineDynamicArray(moVideoFrames) moDefineDynamicArray(moVideoBuffers) moDefineDynamicArray(moLiveSystemPtrs) moDefineDynamicArray(moVideoBufferPaths) moVideoFrame
moCamera * GetCameraByName(const moText &camera, bool load=false, moCaptureDevice customCD=moCaptureDevice())
#define MO_VIDEO_WIDTH
moColorMode m_ColorMode
Definition: moVideoGraph.h:202
virtual bool IsRunning()=0
Está corriendo.
#define MO_VIDEO_CIRCULARSOURCEHEIGHT
moRenderManager * GetRenderMan()
#define MOboolean
Definition: moTypes.h:385
void SetCaptureDevice(moCaptureDevice p_capdev)
MOboolean IsTextureNonPowerOf2Disabled() const
virtual long GetRecordPosition()
virtual MOboolean Finish()
void SetType(moLiveSystemType p_Type)
virtual MOboolean Init()
Inicializa el objeto.
#define MO_VIDEO_CIRCULARWIDTH
virtual ~moLiveSystem()
MOfloat m_fFramesPerSecond
Definition: moTexture.h:706
bool Unlock()
Libera el acceso al buffer interno.
Definition: moBuckets.cpp:49
MOswitch SetStatus(MOdevcode, MOswitch)
MOint AddTexture(MOuint p_type, moText p_name, moTexParam p_tex_param=MODefTex2DParams)
moCaptureDevice GetCaptureDevice()
moText m_BufferFormat
MOboolean BuildEmpty(MOuint p_width, MOuint p_height)
Definition: moTexture.cpp:113
virtual bool IsRecording()
#define MO_LIVE_BITCOUNT
#define MO_LIVE_LABELNAME
bool Lock()
Paraliza el acceso al buffer interno.
Definition: moBuckets.cpp:45
#define MO_VIDEO_SOURCEINTERPOLATIONTIME
#define MO_LIVE_HEIGHT
#define MO_VIDEO_SOURCEXOFFSET
void Warning(moText p_text)
Anuncia y registra un llamado de atencion.
Definition: moAbstract.cpp:97
#define MO_VIDEO_CIRCULARBUFFERFRAMES
virtual void GetFrame(MOuint p_i)
moLiveSystemType GetType()
virtual void PauseRecording()
#define MOswitch
Definition: moTypes.h:386
const moText & GetName() const
Devuelve el nombre del dispositivo.
Definition: moVideoGraph.h:380
#define MO_LIVE_SCALEHEIGHT
moBitmapFormat fif
#define MO_LIVE_COLORMODE
MOboolean Exists()
Definition: moFile.cpp:436
static double Floor(double fValue)
Definition: moMath.h:190
virtual MOboolean Init()
Inicializa el objeto.
virtual MOboolean Init()
moVideoFormat & GetVideoFormat()
Devuelve el formato de video del dispositivo.
Definition: moVideoGraph.h:400
moText GetName() const
Definition: moTexture.h:245
virtual moText GetVideoInput()
Lista de eventos.
Definition: moEventList.h:139
clase de para manejar textos
Definition: moText.h:75
moTexture * GetTexture(MOuint p_moid)
MOuint m_SourceWidth
moResourceManager * m_pResourceManager
virtual MOboolean ActivateInterpolation(MOboolean activate=true)
Definition: moTexture.cpp:1741
virtual MOboolean Init()
Inicializa el objeto.
Grafo de reproducción de video.
Definition: moVideoGraph.h:584
#define MOdevcode
Definition: moTypes.h:412
Dispositivo de entrada/salida, típicamente, interfaces humanas de IO y datos ( teclado, mouse, tableta, tcp, udp, serial )
Definition: moTypes.h:532
moVideoFramework * GetVideoFramework()
Muestra de video o cuadro.
Definition: moVideoGraph.h:290
moCamera * GetCamera(int cam_idx)
MOboolean UpdateImages(MOint maxfiles=-1)
#define MO_LIVE_DEVICENAME
moText0 moText
Definition: moText.h:291
Buffer de imágenes para video.
virtual ~moVideoBufferPath()
Sistema de tratamiento de una señal en vivo de video.
void SetLabelName(const moText &p_labelname)
Fija el nombre de código del dispositivo.
Definition: moVideoGraph.h:423
Clase de manipulación para el cuadro de un video en memoria.
virtual moStreamState GetState()
Estado de la reproducción.
GStreamer Graph Class.
Definition: moGsGraph.h:151
virtual MOboolean Init()
Inicializa el objeto.
void Present(bool p=true)
Fija la presencia del dispositivo.
Definition: moVideoGraph.h:413
#define MO_VIDEO_SOURCEHEIGHT
static moText FramesToTimecode(MOulonglong duration, double framespersecond)
#define MOint
Definition: moTypes.h:388
#define MO_MOLDEOOBJECT_UNDEFINED_ID
moFileArray & GetFiles()
Definition: moFile.cpp:381
virtual MOboolean Finish()
Definition: moTexture.cpp:101
virtual ~moLiveSystems()
moFileManager * GetFileMan()
void SetName(moText p_name)
Definition: moTexture.h:250
int GetSourceWidth() const
Devuelve el ancho de la imagen de origen.
Definition: moVideoGraph.h:433
#define MO_VIDEO_SOURCEINTERPOLATION
static moText NanosecondsToTimecode(MOulonglong duration)
const moText & GetLabelName() const
Devuelve el nombre de código del dispositivo.
Definition: moVideoGraph.h:428
Sistema de tratamiento de señales en vivo de video.
virtual void StartRecording(long at_position=-1)
moTexture * GetTexture()
MOboolean LoadCompleted()
static MOuint NextPowerOf2(MOuint p_seed)
Definition: moTexture.cpp:758
#define MO_VIDEO_CIRCULARBUFFERNAME
clase base para el manejo de una textura
Definition: moTexture.h:78
Administrador de moBucket &#39;s.
Definition: moBuckets.h:152
moDirectory * GetDirectory(moText p_Path)
moText GetCompletePath()
Get inmediate folder name: return "PP" for "PP/myFileName.txt".
Definition: moFile.cpp:538
Administrador de recursos.
película
Definition: moTexture.h:56
bool IsPresent() const
Señala y verifica si está presente el dispositivo.
Definition: moVideoGraph.h:418
virtual void StopRecording()
virtual ~moVideoFrame()
virtual MOboolean Finish()
Finaliza el objeto, libera recursos.
MOint GetValue(MOdevcode)
virtual MOboolean Init()
Inicializa el objeto.
virtual void GetFrame(MOuint p_i)
MOuint m_ActualFrame
Definition: moTexture.h:711
#define MO_VIDEO_CIRCULARSOURCEXOFFSET
void * m_pSampleBuffer
Formato de video de la muestra.
Definition: moVideoGraph.h:327
MOuint m_width
Definition: moTexture.h:405
static moDebug * MODebug2
Clase de impresión de errores para depuración.
Definition: moAbstract.h:225
void SetVideoSample(moVideoFormat p_videoformat, MOpointer p_buffer)
Fija el formato de video y puntero al buffer de datos.
Definition: moVideoGraph.h:321
MOint devicecode
Definition: moEventList.h:63
moDataManager * GetDataMan()
#define MO_LIVE_WIDTH
virtual MOboolean Init()
Inicializa el objeto.
MOuint GetWidth() const
Definition: moTexture.h:256
Definición de un dispositivo de video, generalmente uno de captura de video, o camara.
Definition: moVideoGraph.h:336
moCamera * CreateCamera(const moCaptureDevice &p_CapDev)
virtual void Update(moEventList *p_EventList)
moTextureType m_type
Definition: moTexture.h:399
Espacio en memoria para compartir datos entre objetos.
Definition: moBuckets.h:53
#define MO_VIDEO_CIRCULARSOURCEYOFFSET
const moTextArray & GetCameraNames()
MOlong m_FrameSize
#define MO_VIDEO_CIRCULARBUFFERINPUT
virtual MOboolean Finish()
Finaliza el objeto, libera recursos.
MOpointer GetPointer(MOdevcode devcode)
#define MOulonglong
Definition: moTypes.h:394
#define MO_ON
Definition: moTypes.h:365
moMemory * hmem
bool IsPowerOfTwo(int iValue)
Definition: moMath.h:297
MOuint GetGLId() const
Definition: moTexture.h:224
#define MO_VIDEO_SOURCEYOFFSET
void SetName(const moText &p_name)
Definition: moVideoGraph.h:375
MOdevcode GetCode(moText)
moVideoGraph * GetVideoGraph()
moText GetDataPath()
virtual ~moVideoBuffer()
Definition: moMath.h:64
#define MOuint
Definition: moTypes.h:387
moLiveSystemType
virtual MOboolean LoadSample(moVideoSample *pvideosample)
#define MO_LIVE_FLIPV
LIBMOLDEO_API moText0 IntToStr(int a)
Definition: moText.cpp:1070
virtual void ContinueRecording()
MOubyte * GetBuffer()
Devuelve el puntero al buffer de datos.
Definition: moBuckets.cpp:58
int GetCircularVideoBufferCount()
moBucket * RetreiveBucket()
Definition: moBuckets.cpp:207
MOuint m_BitCount
Definition: moVideoGraph.h:207
moCircularVideoBuffer * GetCircularVideoBuffer(int cb_idx)
bool GetStatus(MOdevcode p_devcode)
MOuint m_height
Definition: moTexture.h:406
Formato de video.
Definition: moVideoGraph.h:155
una textura asociada a una animación de cuadros
Definition: moTexture.h:553
void SetVideoFormat(moGstCaps *caps, moGstBuffer *buffer=NULL)
MOboolean m_bInitialized
Valor de inicialización.
Definition: moAbstract.h:223
moBucket * RetreivedBucket()
Definition: moBuckets.cpp:242
virtual ~moVideoManager()
MOboolean LoadImage(moBitmap *pImage, int indeximage=-1)
virtual MOboolean Finish()
Finaliza el objeto, libera recursos.
virtual ~moVideoIn()
moVideoFrames m_Frames
Buffer Circular de imágenes para video.
moText GetDeviceName()
MOuint m_SourceHeight
void Message(moText p_text)
Anuncia un mensaje al usuario además de guardarlo en el log de texto.
Definition: moAbstract.cpp:114
bool LoadLiveSystems(moCaptureDevices *p_pPreferredDevices)
#define MO_LIVE_FLIPH
virtual MOboolean Init()
#define MO_VIDEO_CIRCULARHEIGHT
#define MOpointer
Definition: moTypes.h:409
void SetTexture(moTexture *p_Texture)
virtual ~moVideoOut()
#define MOubyte
Definition: moTypes.h:399
moVideoFormat m_VideoFormat
Definition: moVideoGraph.h:326
#define MO_VIDEO_SOURCEWIDTH
moVideoBuffers m_VideoBuffers
moVideoBufferPath * GetVideoBufferPath(int vb_idx)
moVideoBuffer * GetVideoBuffer(int vb_idx)
moTextureManager * GetTextureMan()
const moText & GetPath() const
Devuelve el camino al dispositivo.
Definition: moVideoGraph.h:390
MOboolean SetBuffer(const GLvoid *p_buffer, GLenum p_format=GL_RGBA, GLenum p_type=GL_UNSIGNED_BYTE)
Definition: moTexture.cpp:388
moText m_Path
Descripción del dispositivo.
Definition: moVideoGraph.h:471
#define MO_VIDEO_BUFFERNAME
moTexParam m_param
Definition: moTexture.h:404