Monday, March 11, 2013

Last time I was showing three problems with the conversion from a gst buffer data to QImage.
The code snipped was:

And the problems were:
  • The mutex might be not optimally designed since it's a producer newSample() and a consumer getFrame()
  • The QImage construction should be done with const data since the data is not intended to get changed
  • A serious problem is that the data of the QImage must remain valid also if the image is used from the Display class. This is not given here since the lifetime of the GstBuffer is unknown

I was trying to solve the simplest first: construct for const data. The difference as described in the Qt documentation is
Unlike the similar QImage constructor that takes a non-const data buffer, this version will never alter the contents of the buffer. For example, calling QImage::bits() will return a deep copy of the image, rather than the buffer passed to the constructor. This allows for the efficiency of constructing a QImage from raw data, without the possibility of the raw data being changed.

For a solution I intended to use the const_cast operator. And it seems it is working fine:


The other two are somewhat more complex to solve. I will continue with the lifetime of the gstBuffer.

No comments:

Post a Comment