videosurface.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. #include "videosurface.h"
  5. #include <QtGui>
  6. #include "qnativecamera.h"
  7. /*!
  8. \class VideoSurface
  9. \brief Receives the frames from the camera.
  10. */
  11. /*!
  12. Constructor.
  13. */
  14. VideoSurface::VideoSurface(FrameObserver *frameObserver, QObject *parent)
  15. : QAbstractVideoSurface(parent),
  16. m_frameObserver(frameObserver)
  17. {
  18. setError(QAbstractVideoSurface::NoError);
  19. }
  20. /*!
  21. Destructor.
  22. */
  23. VideoSurface::~VideoSurface()
  24. {
  25. }
  26. /*!
  27. Sets the list of supported pixel formats that we are intrested of.
  28. */
  29. QList<QVideoFrame::PixelFormat> VideoSurface::supportedPixelFormats(
  30. QAbstractVideoBuffer::HandleType handleType) const
  31. {
  32. Q_UNUSED(handleType);
  33. return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_ARGB32;
  34. }
  35. /*!
  36. Starts the receiving of the frames for the view finder.
  37. */
  38. bool VideoSurface::start(const QVideoSurfaceFormat &format)
  39. {
  40. if (isActive()) {
  41. stop();
  42. }
  43. if (format.frameSize().isEmpty()) {
  44. return false;
  45. }
  46. if (error() == QAbstractVideoSurface::NoError) {
  47. return QAbstractVideoSurface::start(format);
  48. }
  49. else {
  50. stop();
  51. }
  52. return false;
  53. }
  54. /*!
  55. Handles the just taken frame from camera and passes it to the observer.
  56. Returning false will stop the surface.
  57. */
  58. bool VideoSurface::present(const QVideoFrame &frame)
  59. {
  60. return m_frameObserver->updateFrame(frame);
  61. }