Grabber.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #include <hyperion/Grabber.h>
  2. #include <hyperion/GrabberWrapper.h>
  3. Grabber::Grabber(const QString& grabberName, int cropLeft, int cropRight, int cropTop, int cropBottom)
  4. : _grabberName(grabberName)
  5. , _log(Logger::getInstance(_grabberName.toUpper()))
  6. , _useImageResampler(true)
  7. , _videoMode(VideoMode::VIDEO_2D)
  8. , _videoStandard(VideoStandard::NO_CHANGE)
  9. , _pixelDecimation(GrabberWrapper::DEFAULT_PIXELDECIMATION)
  10. , _flipMode(FlipMode::NO_CHANGE)
  11. , _width(0)
  12. , _height(0)
  13. , _fps(GrabberWrapper::DEFAULT_RATE_HZ)
  14. , _fpsSoftwareDecimation(0)
  15. , _input(-1)
  16. , _cropLeft(0)
  17. , _cropRight(0)
  18. , _cropTop(0)
  19. , _cropBottom(0)
  20. , _isEnabled(true)
  21. , _isDeviceInError(false)
  22. {
  23. Grabber::setCropping(cropLeft, cropRight, cropTop, cropBottom);
  24. }
  25. void Grabber::setEnabled(bool enable)
  26. {
  27. Info(_log,"Capture interface is now %s", enable ? "enabled" : "disabled");
  28. _isEnabled = enable;
  29. }
  30. void Grabber::setInError(const QString& errorMsg)
  31. {
  32. _isDeviceInError = true;
  33. _isEnabled = false;
  34. Error(_log, "Grabber disabled, device '%s' signals error: '%s'", QSTRING_CSTR(_grabberName), QSTRING_CSTR(errorMsg));
  35. }
  36. void Grabber::setVideoMode(VideoMode mode)
  37. {
  38. Info(_log,"Set videomode to %s", QSTRING_CSTR(videoMode2String(mode)));
  39. _videoMode = mode;
  40. if ( _useImageResampler )
  41. {
  42. _imageResampler.setVideoMode(_videoMode);
  43. }
  44. }
  45. void Grabber::setVideoStandard(VideoStandard videoStandard)
  46. {
  47. if (_videoStandard != videoStandard) {
  48. _videoStandard = videoStandard;
  49. }
  50. }
  51. bool Grabber::setPixelDecimation(int pixelDecimation)
  52. {
  53. if (_pixelDecimation != pixelDecimation)
  54. {
  55. Info(_log,"Set image size decimation to %d", pixelDecimation);
  56. _pixelDecimation = pixelDecimation;
  57. if ( _useImageResampler )
  58. {
  59. _imageResampler.setHorizontalPixelDecimation(pixelDecimation);
  60. _imageResampler.setVerticalPixelDecimation(pixelDecimation);
  61. }
  62. return true;
  63. }
  64. return false;
  65. }
  66. void Grabber::setFlipMode(FlipMode mode)
  67. {
  68. Info(_log,"Set flipmode to %s", QSTRING_CSTR(flipModeToString(mode)));
  69. _flipMode = mode;
  70. if ( _useImageResampler )
  71. {
  72. _imageResampler.setFlipMode(_flipMode);
  73. }
  74. }
  75. void Grabber::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
  76. {
  77. if (_width>0 && _height>0)
  78. {
  79. if (cropLeft + cropRight >= _width || cropTop + cropBottom >= _height)
  80. {
  81. Error(_log, "Rejecting invalid crop values: left: %d, right: %d, top: %d, bottom: %d, higher than height/width %d/%d", cropLeft, cropRight, cropTop, cropBottom, _height, _width);
  82. return;
  83. }
  84. }
  85. _cropLeft = cropLeft;
  86. _cropRight = cropRight;
  87. _cropTop = cropTop;
  88. _cropBottom = cropBottom;
  89. if ( _useImageResampler )
  90. {
  91. _imageResampler.setCropping(cropLeft, cropRight, cropTop, cropBottom);
  92. }
  93. else
  94. {
  95. _imageResampler.setCropping(0, 0, 0, 0);
  96. }
  97. if (cropLeft > 0 || cropRight > 0 || cropTop > 0 || cropBottom > 0)
  98. {
  99. Info(_log, "Cropping image: width=%d height=%d; crop: left=%d right=%d top=%d bottom=%d ", _width, _height, cropLeft, cropRight, cropTop, cropBottom);
  100. }
  101. }
  102. bool Grabber::setInput(int input)
  103. {
  104. if((input >= 0) && (_input != input))
  105. {
  106. _input = input;
  107. return true;
  108. }
  109. return false;
  110. }
  111. bool Grabber::setWidthHeight(int width, int height)
  112. {
  113. bool rc (false);
  114. // eval changes with crop
  115. if ( (width>0 && height>0) && (_width != width || _height != height) )
  116. {
  117. if (_cropLeft + _cropRight >= width || _cropTop + _cropBottom >= height)
  118. {
  119. Error(_log, "Rejecting invalid width/height values as it collides with image cropping: width: %d, height: %d", width, height);
  120. rc = false;
  121. }
  122. else
  123. {
  124. Debug(_log, "Set new width: %d, height: %d for capture", width, height);
  125. _width = width;
  126. _height = height;
  127. rc = true;
  128. }
  129. }
  130. return rc;
  131. }
  132. bool Grabber::setFramerate(int fps)
  133. {
  134. Debug(_log,"Set new frames per second to: %i fps, current fps: %i", fps, _fps);
  135. if((fps > 0) && (_fps != fps))
  136. {
  137. Info(_log,"Set new frames per second to: %i fps", fps);
  138. _fps = fps;
  139. return true;
  140. }
  141. return false;
  142. }
  143. void Grabber::setFpsSoftwareDecimation(int decimation)
  144. {
  145. if((_fpsSoftwareDecimation != decimation))
  146. {
  147. _fpsSoftwareDecimation = decimation;
  148. if(decimation > 0){
  149. Debug(_log,"Skip %i frame per second", decimation);
  150. }
  151. }
  152. }