#include "mv_private.h"
#include <mv_common.h>
+#include <MediaSource.h>
#include <memory>
#include <unistd.h>
#include <opencv2/core.hpp>
LOGE("Failed to create dfs adaptation : %s", e.what());
return MEDIA_VISION_ERROR_OUT_OF_MEMORY;
} catch (const std::runtime_error &e) {
- LOGE("Failed to bind %s adpator", e.what());
+ LOGE("Failed to bind %s adaptor", e.what());
return MEDIA_VISION_ERROR_INVALID_OPERATION;
}
}
}
if (!mDfsAdaptor) {
- LOGE("Invalid Opertation. Do Configure first.");
+ LOGE("Invalid Operation. Do Configure first.");
return MEDIA_VISION_ERROR_INVALID_OPERATION;
}
return MEDIA_VISION_ERROR_NONE;
}
-
+/*
+* Get buffer data from mv_source.
+* For now it only support no-stride image, or stride with nv12 format
+* TODO: zero-copy, multi-planar image handle
+*/
void Mv3d::GetBufferFromSource(mv_source_h source,
unsigned char*& buffer,
unsigned int& width,
int& type,
size_t& stride)
{
- unsigned char* _buffer = nullptr;
- unsigned int _bufferSize = 0;
- unsigned int _width = 0;
- unsigned int _height = 0;
- mv_colorspace_e _colorSpace = MEDIA_VISION_COLORSPACE_INVALID;
-
- int ret = mv_source_get_buffer(source, &_buffer, &_bufferSize);
- if (ret != MEDIA_VISION_ERROR_NONE)
- throw std::runtime_error("invalid buffer pointer");
-
- ret = mv_source_get_width(source, &_width);
- if (ret != MEDIA_VISION_ERROR_NONE)
- throw std::runtime_error("invalid width");
-
- ret = mv_source_get_height(source, &_height);
- if (ret != MEDIA_VISION_ERROR_NONE)
- throw std::runtime_error("invalid height");
-
- ret = mv_source_get_colorspace(source, &_colorSpace);
- if (ret != MEDIA_VISION_ERROR_NONE)
+ MediaVision::Common::MediaSource *mediaSource = static_cast<MediaVision::Common::MediaSource *>(source);
+ auto *_buffer = mediaSource->getBuffer();
+ auto _bufferSize = mediaSource->getBufferSize();
+ width = mediaSource->getWidth();
+ height = mediaSource->getHeight();
+ stride = mediaSource->getWidthStride();
+ switch (mediaSource->getColorspace()) {
+ case MEDIA_VISION_COLORSPACE_RGB888:
+ type = DFS_DATA_TYPE_UINT8C3;
+ break;
+ case MEDIA_VISION_COLORSPACE_I420:
+ case MEDIA_VISION_COLORSPACE_NV12:
+ case MEDIA_VISION_COLORSPACE_NV21:
+ type = DFS_DATA_TYPE_UINT8C1;
+ break;
+ default: //NOT tested
throw std::runtime_error("invalid color space");
+ }
- buffer = new unsigned char [_bufferSize];
- memcpy(buffer, _buffer, _bufferSize);
- width = _width;
- height = _height;
- type = _colorSpace == MEDIA_VISION_COLORSPACE_RGB888 ?
- DFS_DATA_TYPE_UINT8C3 :
- DFS_DATA_TYPE_UINT8C1;
- stride = _bufferSize / _height;
+ if (width != stride && type == DFS_DATA_TYPE_UINT8C1) {
+ //copy only Y channel
+ _bufferSize = width * height;
+ buffer = new unsigned char[_bufferSize];
+ for (unsigned int i = 0; i < height; i++) {
+ memcpy(buffer + i * width, _buffer + i * stride, width);
+ }
+ } else {
+ buffer = new unsigned char[_bufferSize];
+ memcpy(buffer, _buffer, _bufferSize);
+ }
}
void Mv3d::GetDfsDataFromSources(mv_source_h baseSource,