qnativecamera.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #ifndef QNATIVECAMERA_H
  2. #define QNATIVECAMERA_H
  3. #include <QDeclarativeItem>
  4. #include <QVideoFrame>
  5. #include <QCamera>
  6. #include <QSize>
  7. #include <QCameraImageCapture>
  8. #include <QMediaRecorder>
  9. #include "qdll_global.h"
  10. class VideoSurface;
  11. // Observer design pattern to provide the view finder frame for the CustomCamera
  12. // object.
  13. class QDLLSHARED_EXPORT FrameObserver
  14. {
  15. public:
  16. virtual bool updateFrame(const QVideoFrame &frame) = 0;
  17. };
  18. class QDLLSHARED_EXPORT QNativeCamera : public QDeclarativeItem, FrameObserver
  19. //class QNativeCamera : public QDeclarativeItem, FrameObserver
  20. {
  21. Q_OBJECT
  22. Q_ENUMS(State)
  23. // State properties
  24. Q_PROPERTY(State cameraState READ cameraState NOTIFY cameraStateChanged)
  25. // Devices properties
  26. Q_PROPERTY(QStringList availableDevices READ availableDevices)
  27. Q_PROPERTY(QString currentDevice READ currentDevice NOTIFY currentDeviceChanged)
  28. Q_PROPERTY(bool frontCamera READ frontCamera NOTIFY frontCameraChanged)
  29. Q_PROPERTY(QSize resolution READ resolution WRITE setResolution NOTIFY resolutionChanged)
  30. Q_PROPERTY(qreal exposureCompensation READ exposureCompensation WRITE setExposureCompensation NOTIFY exposureCompensationChanged)
  31. public:
  32. enum State {
  33. ActiveState = QCamera::ActiveState,
  34. LoadedState = QCamera::LoadedState,
  35. UnloadedState = QCamera::UnloadedState
  36. };
  37. explicit QNativeCamera(QDeclarativeItem *parent = 0);
  38. ~QNativeCamera();
  39. QStringList availableDevices() const;
  40. virtual void paint(QPainter *painter,
  41. const QStyleOptionGraphicsItem *option,
  42. QWidget *widget);
  43. virtual bool updateFrame(const QVideoFrame &frame);
  44. QSize resolution();
  45. void setResolution(QSize& value);
  46. qreal exposureCompensation();
  47. void setExposureCompensation(qreal);
  48. protected:
  49. void destroyResources();
  50. State cameraState() const;
  51. QString currentDevice() const;
  52. bool frontCamera() const;
  53. signals:
  54. void resolutionChanged(QSize resolution);
  55. void digitalZoomChanged();
  56. void maximumDigitalZoomChanged();
  57. void exposureCompensationChanged();
  58. void exposureModeChanged();
  59. void supportedExposureModesChanged();
  60. void flashModeChanged();
  61. void supportedFlashModesChanged();
  62. void locked();
  63. void lockFailed();
  64. void isoValueChanged();
  65. void supportedIsoValuesChanged();
  66. void imageSaved(const QString &fileName);
  67. void cameraStateChanged();
  68. void whiteBalanceModeChanged();
  69. void supportedWhiteBalanceModesChanged();
  70. //void sharpeningLevelChanged();
  71. //void contrastChanged();
  72. void currentDeviceChanged();
  73. void frontCameraChanged();
  74. //void imageAnalyzerChanged();
  75. public slots:
  76. void start(const QString &device);
  77. void stop();
  78. void cameraStateChanged(QCamera::State state);
  79. void handleImageSaved(int id, const QString &fileName);
  80. virtual void captureImage();
  81. virtual void imageAvailable(int,QVideoFrame);
  82. virtual void imageCaptured ( int id, const QImage & preview );
  83. virtual void imageExposed(int);
  84. void emitImageSavedSignal();
  85. protected:
  86. qreal m_exposureCompensation;
  87. protected:
  88. QCamera *m_camera; // Owned
  89. QString m_currentDevice;
  90. bool m_frontCamera;
  91. // Still image capturing
  92. QCameraImageCapture *m_cameraImageCapture; // Owned
  93. // Video capturing
  94. QMediaRecorder *m_mediaRecorder; // Owned
  95. // For showing view finder image
  96. VideoSurface *m_videoSurface; // Owned
  97. // For storing the latest frame
  98. unsigned int m_processedFrameCounter;
  99. unsigned int m_incomingFrameCounter;
  100. QImage m_imageFrame;
  101. // File to be opened in the gallery.
  102. QString m_galleryImage;
  103. QSize m_resolution;
  104. };
  105. #endif // QNATIVECAMERA_H