// Need for a colorspace
#include <mv_common.h>
#include <stddef.h>
+#include <vector>
/**
* @file MediaSource.h
* @brief This file contains the MediaSource class.
{
namespace Common
{
+struct Plane {
+ unsigned char *buffer { nullptr };
+ unsigned int imageSize { 0 };
+ unsigned int bytePerLine { 0 };
+};
+
/**
* @class MediaSource
* @brief The Media Source container
{
public:
/**
- * @brief Creates a MediaSource.
- * @details Default parameters values of the MediaSource will be: zero for
- * width, height and buffer size; NULL for buffer;
- * MEDIA_VISION_COLORSPACE_INVALID for colorspace.
- *
- * @since_tizen @if MOBILE 2.4 @else 3.0 @endif
- *
- * @see MediaSource::~MediaSource()
- */
- MediaSource();
-
- /**
* @brief Destroys the MediaSource and releases all its resources.
*
* @since_tizen @if MOBILE 2.4 @else 3.0 @endif
*/
mv_colorspace_e getColorspace(void) const;
-protected:
- unsigned char *m_pBuffer; /**< The data buffer */
-
- unsigned int m_bufferSize; /**< The buffer size */
-
- unsigned int m_width; /**< The image width */
-
- unsigned int m_height; /**< The image height */
-
- mv_colorspace_e m_colorspace; /**< The image colorspace */
+private:
+ std::vector<Plane> _plane;
+ unsigned int _width { 0 }; /**< The image width */
+ unsigned int _height { 0 }; /**< The image height */
+ mv_colorspace_e _colorspace { MEDIA_VISION_COLORSPACE_INVALID }; /**< The image colorspace */
+ bool _isRef { false };
};
} /* Common */
{
namespace Common
{
-MediaSource::MediaSource()
- : m_pBuffer(NULL), m_bufferSize(0), m_width(0), m_height(0), m_colorspace(MEDIA_VISION_COLORSPACE_INVALID)
-{}
-
MediaSource::~MediaSource()
{
clear();
LOGD("Call clear() first for media source %p", this);
clear();
- m_pBuffer = new (std::nothrow) unsigned char[bufferSize];
- if (m_pBuffer == NULL) {
+ Plane plane;
+ auto &pBuffer = plane.buffer;
+ auto &pImageSize = plane.imageSize;
+
+ pBuffer = new (std::nothrow) unsigned char[bufferSize];
+ if (pBuffer == NULL) {
LOGE("Memory allocating for buffer in media source %p failed!", this);
return false;
}
LOGD("Assign new size of the internal buffer of media source %p. "
"New size is %ui.",
this, bufferSize);
- m_bufferSize = bufferSize;
+ pImageSize = bufferSize;
LOGD("Assign new size (%ui x %ui) of the internal buffer image for "
"the media source %p",
width, height, this);
- m_width = width;
- m_height = height;
+ _width = width;
+ _height = height;
LOGD("Assign new colorspace (%i) of the internal buffer image for "
"the media source %p",
colorspace, this);
- m_colorspace = colorspace;
+ _colorspace = colorspace;
+
+ _plane.push_back(plane);
return true;
}
void MediaSource::clear(void)
{
- if (m_pBuffer != NULL) {
- LOGD("Delete internal buffer for media source %p", this);
- delete[] m_pBuffer;
+ if (!_isRef) {
+ for (const auto &p : _plane) {
+ delete[] p.buffer;
+ }
}
- LOGD("Set defaults for media source %p : buffer = NULL; "
- "bufferSize = 0; width = 0; height = 0; "
- "colorspace = MEDIA_VISION_COLORSPACE_INVALID",
- this);
- m_pBuffer = NULL;
- m_bufferSize = 0;
- m_width = 0;
- m_height = 0;
- m_colorspace = MEDIA_VISION_COLORSPACE_INVALID;
+ _plane.clear();
+ _width = 0;
+ _height = 0;
+ _colorspace = MEDIA_VISION_COLORSPACE_INVALID;
+ _isRef = false;
}
bool MediaSource::fill(const unsigned char *buffer, unsigned int bufferSize, unsigned int width, unsigned int height,
LOGD("Call clear() first for media source %p", this);
clear();
+ Plane plane;
+ auto &pBuffer = plane.buffer;
+ auto &pImageSize = plane.imageSize;
+
LOGD("Allocate memory [%i] for buffer in media source %p", bufferSize, this);
LOGD("Assign new size (%ui x %ui) of the internal buffer image for "
"the media source %p",
LOGD("Assign new colorspace (%i) of the internal buffer image for "
"the media source %p",
colorspace, this);
- m_pBuffer = new (std::nothrow) unsigned char[bufferSize];
- if (m_pBuffer == NULL) {
+ pBuffer = new (std::nothrow) unsigned char[bufferSize];
+ if (pBuffer == NULL) {
LOGE("Memory allocating for buffer in media source %p failed!", this);
return false;
}
LOGD("Copy data from external buffer (%p) to the internal buffer (%p) of "
"media source %p",
- buffer, m_pBuffer, this);
- std::memcpy(m_pBuffer, buffer, bufferSize);
+ buffer, pBuffer, this);
+ std::memcpy(pBuffer, buffer, bufferSize);
LOGD("Assign new size of the internal buffer of media source %p. "
"New size is %ui.",
this, bufferSize);
- m_bufferSize = bufferSize;
+ pImageSize = bufferSize;
LOGD("Assign new size (%ui x %ui) of the internal buffer image for "
"the media source %p",
width, height, this);
- m_width = width;
- m_height = height;
+ _width = width;
+ _height = height;
LOGD("Assign new colorspace (%i) of the internal buffer image for "
"the media source %p",
colorspace, this);
- m_colorspace = colorspace;
+ _colorspace = colorspace;
+ _plane.push_back(plane);
return true;
}
return false;
}
- if (m_pBuffer == NULL) {
- LOGE("m_pBuffer is NULL");
+ if (_plane.empty()) {
+ LOGE("_plane is empty");
return false;
}
+ auto &pBuffer = _plane.back().buffer;
+
LOGD("Allocate memory [%i] for buffer in media source %p", bufferSize, this);
LOGD("Assign new size (%ui x %ui) of the internal buffer image for "
"the media source %p",
LOGD("Copy data from external buffer (%p) to the internal buffer (%p + %zd) of "
"media source %p",
- buffer, m_pBuffer, offset, this);
- std::memcpy(m_pBuffer + offset, buffer, bufferSize);
+ buffer, pBuffer, offset, this);
+ std::memcpy(pBuffer + offset, buffer, bufferSize);
LOGD("size is %ui x %ui [%ui] on buffer(%p).", width, height, bufferSize, this);
unsigned char *MediaSource::getBuffer(void) const
{
- return m_pBuffer;
+ if (_plane.empty())
+ return nullptr;
+ return _plane[0].buffer;
}
unsigned int MediaSource::getBufferSize(void) const
{
- return m_bufferSize;
+ if (_plane.empty())
+ return 0;
+ return _plane[0].imageSize;
}
unsigned int MediaSource::getWidth(void) const
{
- return m_width;
+ return _width;
}
unsigned int MediaSource::getHeight(void) const
{
- return m_height;
+ return _height;
}
mv_colorspace_e MediaSource::getColorspace(void) const
{
- return m_colorspace;
+ return _colorspace;
}
} /* Common */