summaryrefslogtreecommitdiff
path: root/libhwjpeg
diff options
context:
space:
mode:
authorCho KyongHo <pullip.cho@samsung.com>2019-08-14 17:13:47 +0900
committerCho KyongHo <pullip.cho@samsung.com>2020-02-20 21:34:34 -0800
commita6b44cc59409195144498eb568742a59983c2571 (patch)
tree8ca60c3938933e2194976931bfb9607a6d56890a /libhwjpeg
parente926c5b48784a36a4be9483f5798563adc2a0103 (diff)
libhwjpeg: use buffer size instead of payload
ExynosJpegEncoderForCamera has the lengths of mage buffers to LibScalerForJpeg but it does not get informed about the lengths. Instead LibScalerForJpeg feeds VIDIOC_QBUF the required payloads of images studied by VIDOC_S_FMT as the buffer length which is not the length of the buffer. Change-Id: Id51f3a6e4f701fdb5f33bf84d17045448ab5f97a Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
Diffstat (limited to 'libhwjpeg')
-rw-r--r--libhwjpeg/ExynosJpegEncoderForCamera.cpp16
-rw-r--r--libhwjpeg/LibScalerForJpeg.cpp55
-rw-r--r--libhwjpeg/include/LibScalerForJpeg.h19
3 files changed, 53 insertions, 37 deletions
diff --git a/libhwjpeg/ExynosJpegEncoderForCamera.cpp b/libhwjpeg/ExynosJpegEncoderForCamera.cpp
index bb4dc2c..39e877e 100644
--- a/libhwjpeg/ExynosJpegEncoderForCamera.cpp
+++ b/libhwjpeg/ExynosJpegEncoderForCamera.cpp
@@ -595,24 +595,24 @@ bool ExynosJpegEncoderForCamera::GenerateThumbnailImage()
bool okay = false;
if (checkInBufType() == JPEG_BUF_TYPE_USER_PTR) {
- char *bufs[3];
- int len_srcbufs[3];
+ char *bufs[SCALER_MAX_PLANES];
+ int len_srcbufs[SCALER_MAX_PLANES];
- if (getInBuf(bufs, len_srcbufs, 3) < 0) {
+ if (getInBuf(bufs, len_srcbufs, SCALER_MAX_PLANES) < 0) {
ALOGE("Failed to retrieve the main image buffers");
return false;
}
- okay = m_pLibScaler.RunStream(bufs, m_fdIONThumbImgBuffer);
+ okay = m_pLibScaler.RunStream(bufs, len_srcbufs, m_fdIONThumbImgBuffer, m_szIONThumbImgBuffer);
} else { // mainbuftype == JPEG_BUF_TYPE_DMA_BUF
- int bufs[3];
- int len_srcbufs[3];
+ int bufs[SCALER_MAX_PLANES];
+ int len_srcbufs[SCALER_MAX_PLANES];
- if (getInBuf(bufs, len_srcbufs, 3) < 0) {
+ if (getInBuf(bufs, len_srcbufs, SCALER_MAX_PLANES) < 0) {
ALOGE("Failed to retrieve the main image buffers");
return false;
}
- okay = m_pLibScaler.RunStream(bufs, m_fdIONThumbImgBuffer);
+ okay = m_pLibScaler.RunStream(bufs, len_srcbufs, m_fdIONThumbImgBuffer, m_szIONThumbImgBuffer);
}
if (!okay) {
diff --git a/libhwjpeg/LibScalerForJpeg.cpp b/libhwjpeg/LibScalerForJpeg.cpp
index 3dc1e0a..10c7b76 100644
--- a/libhwjpeg/LibScalerForJpeg.cpp
+++ b/libhwjpeg/LibScalerForJpeg.cpp
@@ -19,7 +19,6 @@
#include "LibScalerForJpeg.h"
#define SCALER_DEV_NODE "/dev/video50"
-#define SCALER_MAX_PLANES 3
static const char *getBufTypeString(unsigned int buftype)
{
@@ -55,20 +54,20 @@ LibScalerForJpeg::~LibScalerForJpeg()
ALOGD("LibScalerForJpeg Destroyed: %p", this);
}
-bool LibScalerForJpeg::RunStream(int srcBuf[], int dstBuf)
+bool LibScalerForJpeg::RunStream(int srcBuf[SCALER_MAX_PLANES], int srcLen[SCALER_MAX_PLANES], int dstBuf, size_t dstLen)
{
if (!mSrcImage.begin(V4L2_MEMORY_DMABUF) || !mDstImage.begin(V4L2_MEMORY_DMABUF))
return false;
- return queue(srcBuf, dstBuf);
+ return queue(srcBuf, srcLen, dstBuf, dstLen);
}
-bool LibScalerForJpeg::RunStream(char *srcBuf[], int dstBuf)
+bool LibScalerForJpeg::RunStream(char *srcBuf[SCALER_MAX_PLANES], int srcLen[SCALER_MAX_PLANES], int dstBuf, size_t dstLen)
{
if (!mSrcImage.begin(V4L2_MEMORY_USERPTR) || !mDstImage.begin(V4L2_MEMORY_DMABUF))
return false;
- return queue(srcBuf, dstBuf);
+ return queue(srcBuf, srcLen, dstBuf, dstLen);
}
bool LibScalerForJpeg::Image::set(unsigned int width, unsigned int height, unsigned int format)
@@ -103,10 +102,6 @@ bool LibScalerForJpeg::Image::set(unsigned int width, unsigned int height, unsig
memoryType = 0; // new reqbufs is required.
- planeCount = fmt.fmt.pix_mp.num_planes;
- for (unsigned int i = 0; i < planeCount; i++)
- planeLength[i] = fmt.fmt.pix_mp.plane_fmt[i].sizeimage;
-
return true;
}
@@ -161,7 +156,29 @@ bool LibScalerForJpeg::Image::cancelBuffer()
return true;
}
-bool LibScalerForJpeg::Image::queueBuffer(int buf[])
+bool LibScalerForJpeg::Image::queueBuffer(int buf, size_t len)
+{
+ v4l2_buffer buffer{};
+ v4l2_plane plane[SCALER_MAX_PLANES];
+
+ memset(&plane, 0, sizeof(plane));
+
+ buffer.type = bufferType;
+ buffer.memory = memoryType;
+ buffer.length = 1;
+ buffer.m.planes = plane;
+ plane[0].m.fd = buf;
+ plane[0].length = len;
+
+ if (ioctl(mDevFd, VIDIOC_QBUF, &buffer) < 0) {
+ ALOGERR("Failed to QBUF for %s", getBufTypeString(bufferType));
+ return false;
+ }
+
+ return true;
+}
+
+bool LibScalerForJpeg::Image::queueBuffer(int buf[SCALER_MAX_PLANES], int len[SCALER_MAX_PLANES])
{
v4l2_buffer buffer{};
v4l2_plane plane[SCALER_MAX_PLANES];
@@ -170,11 +187,10 @@ bool LibScalerForJpeg::Image::queueBuffer(int buf[])
buffer.type = bufferType;
buffer.memory = memoryType;
- buffer.length = planeCount;
- for (unsigned int i = 0; i < planeCount; i++) {
+ buffer.length = SCALER_MAX_PLANES;
+ for (unsigned int i = 0; i < SCALER_MAX_PLANES; i++) {
plane[i].m.fd = buf[i];
- plane[i].length = planeLength[i];
- plane[i].bytesused = planeLength[i];
+ plane[i].length = len[i];
}
buffer.m.planes = plane;
@@ -186,7 +202,7 @@ bool LibScalerForJpeg::Image::queueBuffer(int buf[])
return true;
}
-bool LibScalerForJpeg::Image::queueBuffer(char *buf[])
+bool LibScalerForJpeg::Image::queueBuffer(char *buf[SCALER_MAX_PLANES], int len[SCALER_MAX_PLANES])
{
v4l2_buffer buffer{};
v4l2_plane plane[SCALER_MAX_PLANES];
@@ -195,11 +211,10 @@ bool LibScalerForJpeg::Image::queueBuffer(char *buf[])
buffer.type = bufferType;
buffer.memory = memoryType;
- buffer.length = planeCount;
- for (unsigned int i = 0; i < planeCount; i++) {
+ buffer.length = SCALER_MAX_PLANES;
+ for (unsigned int i = 0; i < SCALER_MAX_PLANES; i++) {
plane[i].m.userptr = reinterpret_cast<unsigned long>(buf[i]);
- plane[i].length = planeLength[i];
- plane[i].bytesused = planeLength[i];
+ plane[i].length = len[i];
}
buffer.m.planes = plane;
@@ -220,7 +235,7 @@ bool LibScalerForJpeg::Image::dequeueBuffer()
buffer.type = bufferType;
buffer.memory = memoryType;
- buffer.length = planeCount;
+ buffer.length = SCALER_MAX_PLANES;
buffer.m.planes = plane;
diff --git a/libhwjpeg/include/LibScalerForJpeg.h b/libhwjpeg/include/LibScalerForJpeg.h
index bbc6eec..2d6001f 100644
--- a/libhwjpeg/include/LibScalerForJpeg.h
+++ b/libhwjpeg/include/LibScalerForJpeg.h
@@ -5,6 +5,8 @@
#include <tuple>
+#define SCALER_MAX_PLANES 3
+
class LibScalerForJpeg {
public:
LibScalerForJpeg();
@@ -18,8 +20,8 @@ public:
return mDstImage.set(width, height, v4l2_format);
}
- bool RunStream(int srcBuf[], int dstBuf);
- bool RunStream(char *srcBuf[], int dstBuf);
+ bool RunStream(int srcBuf[SCALER_MAX_PLANES], int srcLen[SCALER_MAX_PLANES], int dstBuf, size_t dstLen);
+ bool RunStream(char *srcBuf[SCALER_MAX_PLANES], int srcLen[SCALER_MAX_PLANES], int dstBuf, size_t dstLen);
private:
int m_fdScaler = -1;
@@ -30,8 +32,6 @@ private:
unsigned int height;
unsigned int format;
unsigned int memoryType = 0;
- unsigned int planeCount = 1;
- unsigned int planeLength[3] = {0, 0, 0};
const unsigned int bufferType;
Image(unsigned int w, unsigned int h, unsigned int f, unsigned int buftype)
@@ -44,17 +44,18 @@ private:
bool same(unsigned int w, unsigned int h, unsigned int f) { return width == w && height == h && format == f; }
bool begin(unsigned int memtype);
bool cancelBuffer();
- bool queueBuffer(char *buf[]);
- bool queueBuffer(int buf[]);
+ bool queueBuffer(char *buf[SCALER_MAX_PLANES], int len[SCALER_MAX_PLANES]);
+ bool queueBuffer(int buf[SCALER_MAX_PLANES], int len[SCALER_MAX_PLANES]);
+ bool queueBuffer(int buf, size_t len);
bool dequeueBuffer();
};
template<class T>
- bool queue(T srcBuf, int dstBuf) {
- if (!mSrcImage.queueBuffer(srcBuf))
+ bool queue(T srcBuf[SCALER_MAX_PLANES], int srcLen[SCALER_MAX_PLANES], int dstBuf, size_t dstLen) {
+ if (!mSrcImage.queueBuffer(srcBuf, srcLen))
return false;
- if (!mDstImage.queueBuffer(&dstBuf)) {
+ if (!mDstImage.queueBuffer(dstBuf, dstLen)) {
mSrcImage.cancelBuffer();
return false;
}