Change MediaSource structure
authorKwanghoon Son <k.son@samsung.com>
Fri, 24 Mar 2023 01:29:04 +0000 (10:29 +0900)
committerKwanghoon Son <k.son@samsung.com>
Fri, 7 Apr 2023 08:53:23 +0000 (17:53 +0900)
- New struct plane
- Change member variable naming
- Remove unnecessary logd

Change-Id: Ibf545039a125894a104a3fb34edebe39798847f7
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
mv_common/include/MediaSource.h
mv_common/src/MediaSource.cpp

index 69c1ca7..0a05b49 100644 (file)
@@ -20,6 +20,7 @@
 // Need for a colorspace
 #include <mv_common.h>
 #include <stddef.h>
+#include <vector>
 /**
  * @file MediaSource.h
  * @brief This file contains the MediaSource class.
@@ -29,6 +30,12 @@ namespace MediaVision
 {
 namespace Common
 {
+struct Plane {
+       unsigned char *buffer { nullptr };
+       unsigned int imageSize { 0 };
+       unsigned int bytePerLine { 0 };
+};
+
 /**
  * @class   MediaSource
  * @brief   The Media Source container
@@ -39,18 +46,6 @@ class MediaSource
 {
 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
@@ -161,16 +156,12 @@ public:
         */
        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 */
index 84d815b..44b3a4b 100644 (file)
@@ -25,10 +25,6 @@ namespace MediaVision
 {
 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();
@@ -42,8 +38,12 @@ bool MediaSource::alloc(unsigned int bufferSize, unsigned int width, unsigned in
        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;
        }
@@ -51,37 +51,36 @@ bool MediaSource::alloc(unsigned int bufferSize, unsigned int width, unsigned in
        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,
@@ -93,6 +92,10 @@ bool MediaSource::fill(const unsigned char *buffer, unsigned int bufferSize, uns
        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",
@@ -100,32 +103,33 @@ bool MediaSource::fill(const unsigned char *buffer, unsigned int bufferSize, uns
        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;
 }
@@ -138,11 +142,13 @@ bool MediaSource::fill(const unsigned char *buffer, unsigned int bufferSize, uns
                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",
@@ -150,8 +156,8 @@ bool MediaSource::fill(const unsigned char *buffer, unsigned int bufferSize, uns
 
        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);
 
@@ -160,27 +166,31 @@ bool MediaSource::fill(const unsigned char *buffer, unsigned int bufferSize, uns
 
 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 */