[libcamera-devel,v2,1/7] qcam: Tie FrameBufferAllocator to stream life

Message ID 20200214001810.19302-2-kieran.bingham@ideasonboard.com
State Accepted
Headers show
Series
  • qcam: Provide an initial toolbar
Related show

Commit Message

Kieran Bingham Feb. 14, 2020, 12:18 a.m. UTC
The FrameBufferAllocator must be deleted and reconstructed before performing
any reconfiguration of the stream.

Construct the allocator at startCapture, and destroy it during stopCapture so
that we can successfully stop and restart the stream.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

---
v2:
  - Remove unnecessary braces
  - Clean up in start_capture() error path.

 src/qcam/main_window.cpp | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Patch

diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index 70a3e61c66d8..db14245d7f51 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -36,10 +36,8 @@  MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)
 	adjustSize();
 
 	ret = openCamera(cm);
-	if (!ret) {
-		allocator_ = FrameBufferAllocator::create(camera_);
+	if (!ret)
 		ret = startCapture();
-	}
 
 	if (ret < 0)
 		QTimer::singleShot(0, QCoreApplication::instance(),
@@ -50,7 +48,6 @@  MainWindow::~MainWindow()
 {
 	if (camera_) {
 		stopCapture();
-		delete allocator_;
 		camera_->release();
 		camera_.reset();
 	}
@@ -171,6 +168,7 @@  int MainWindow::startCapture()
 
 	adjustSize();
 
+	allocator_ = FrameBufferAllocator::create(camera_);
 	ret = allocator_->allocate(stream);
 	if (ret < 0) {
 		std::cerr << "Failed to allocate capture buffers" << std::endl;
@@ -236,6 +234,9 @@  error:
 	}
 	mappedBuffers_.clear();
 
+	delete allocator_;
+	allocator_ = nullptr;
+
 	return ret;
 }
 
@@ -255,6 +256,8 @@  void MainWindow::stopCapture()
 	}
 	mappedBuffers_.clear();
 
+	delete allocator_;
+
 	isCapturing_ = false;
 
 	config_.reset();