diff options
-rw-r--r-- | libhwjpeg/ExynosJpegEncoderForCamera.cpp | 27 | ||||
-rw-r--r-- | libhwjpeg/LibScalerForJpeg.cpp | 39 | ||||
-rw-r--r-- | libhwjpeg/include/LibScalerForJpeg.h | 26 |
3 files changed, 57 insertions, 35 deletions
diff --git a/libhwjpeg/ExynosJpegEncoderForCamera.cpp b/libhwjpeg/ExynosJpegEncoderForCamera.cpp index a05f70a..8d72eac 100644 --- a/libhwjpeg/ExynosJpegEncoderForCamera.cpp +++ b/libhwjpeg/ExynosJpegEncoderForCamera.cpp @@ -581,41 +581,36 @@ bool ExynosJpegEncoderForCamera::GenerateThumbnailImage() ALOGD("Generating thumbnail image: %dx%d -> %dx%d", main_width, main_height, m_nThumbWidth, m_nThumbHeight); - int len_srcbufs[3] = {0, 0, 0}; - void *srcbufs[3] = {NULL, NULL, NULL}; - int memtype; + bool okay = false; if (checkInBufType() == JPEG_BUF_TYPE_USER_PTR) { char *bufs[3]; + int len_srcbufs[3]; + if (getInBuf(bufs, len_srcbufs, 3) < 0) { ALOGE("Failed to retrieve the main image buffers"); return false; } - memtype = V4L2_MEMORY_USERPTR; - srcbufs[0] = reinterpret_cast<void *>(bufs[0]); - srcbufs[1] = reinterpret_cast<void *>(bufs[1]); - srcbufs[2] = reinterpret_cast<void *>(bufs[2]); + + okay = m_pLibScaler.SetSrcImage(main_width, main_height, v4l2Format, bufs); } else { // mainbuftype == JPEG_BUF_TYPE_DMA_BUF int bufs[3]; + int len_srcbufs[3]; + if (getInBuf(bufs, len_srcbufs, 3) < 0) { ALOGE("Failed to retrieve the main image buffers"); return false; } - memtype = V4L2_MEMORY_DMABUF; - srcbufs[0] = reinterpret_cast<void *>(bufs[0]); - srcbufs[1] = reinterpret_cast<void *>(bufs[1]); - srcbufs[2] = reinterpret_cast<void *>(bufs[2]); + okay = m_pLibScaler.SetSrcImage(main_width, main_height, v4l2Format, bufs); } - void *dstbuf[3] = {NULL, NULL, NULL}; - dstbuf[0] = reinterpret_cast<void *>(m_fdIONThumbImgBuffer); - - if (!m_pLibScaler.SetSrcImage(main_width, main_height, v4l2Format, srcbufs, memtype)) { + if (!okay) { ALOGE("Failed to configure the main image format to LibScalerForJpeg"); return false; } + if (!m_pLibScaler.SetDstImage(m_nThumbWidth, m_nThumbHeight, - GetThumbnailFormat(v4l2Format), dstbuf, V4L2_MEMORY_DMABUF)) { + GetThumbnailFormat(v4l2Format), m_fdIONThumbImgBuffer)) { ALOGE("Failed to configure the target image format to LibScalerForJpeg"); return false; } diff --git a/libhwjpeg/LibScalerForJpeg.cpp b/libhwjpeg/LibScalerForJpeg.cpp index 90f5079..21e8e88 100644 --- a/libhwjpeg/LibScalerForJpeg.cpp +++ b/libhwjpeg/LibScalerForJpeg.cpp @@ -59,19 +59,17 @@ LibScalerForJpeg::~LibScalerForJpeg() bool LibScalerForJpeg::SetImage( v4l2_format &m_fmt, v4l2_buffer &m_buf, v4l2_plane m_planes[SCALER_MAX_PLANES], - unsigned int width, unsigned int height, unsigned int v4l2_format, - void *addrs[SCALER_MAX_PLANES], int mem_type) + unsigned int width, unsigned int height, unsigned int v4l2_format, unsigned int memtype) { /* Format information update*/ if ((m_needReqbuf == true) || (m_fmt.fmt.pix_mp.pixelformat != v4l2_format || m_fmt.fmt.pix_mp.width != width || m_fmt.fmt.pix_mp.height != height || - m_buf.memory != static_cast<v4l2_memory>(mem_type))) { + m_buf.memory != memtype)) { m_fmt.fmt.pix_mp.pixelformat = v4l2_format; m_fmt.fmt.pix_mp.width = width; m_fmt.fmt.pix_mp.height = height; - m_buf.memory = static_cast<v4l2_memory>(mem_type); // The driver returns the number and length of planes through TRY_FMT. if (ioctl(m_fdScaler, VIDIOC_TRY_FMT, &m_fmt) < 0) { @@ -85,19 +83,44 @@ bool LibScalerForJpeg::SetImage( /* Buffer information update*/ m_buf.index = 0; m_buf.length = m_fmt.fmt.pix_mp.num_planes; + m_buf.memory = memtype; for (unsigned long i = 0; i < m_buf.length; i++) { m_planes[i].length = m_fmt.fmt.pix_mp.plane_fmt[i].sizeimage; m_planes[i].bytesused = m_planes[i].length; - if (m_buf.memory == V4L2_MEMORY_DMABUF) - m_planes[i].m.fd = static_cast<__s32>(reinterpret_cast<long>(addrs[i])); - else - m_planes[i].m.userptr = reinterpret_cast<unsigned long>(addrs[i]); } return true; } +bool LibScalerForJpeg::SetImage( + v4l2_format &m_fmt, v4l2_buffer &m_buf, v4l2_plane m_planes[SCALER_MAX_PLANES], + unsigned int width, unsigned int height, unsigned int v4l2_format, + int buf[SCALER_MAX_PLANES]) +{ + if (!SetImage(m_fmt, m_buf, m_planes, width, height, v4l2_format, V4L2_MEMORY_DMABUF)) + return false; + + for (unsigned long i = 0; i < m_buf.length; i++) + m_planes[i].m.fd = buf[i]; + + return true; +} + +bool LibScalerForJpeg::SetImage( + v4l2_format &m_fmt, v4l2_buffer &m_buf, v4l2_plane m_planes[SCALER_MAX_PLANES], + unsigned int width, unsigned int height, unsigned int v4l2_format, + char *addrs[SCALER_MAX_PLANES]) +{ + SetImage(m_fmt, m_buf, m_planes, width, height, v4l2_format, V4L2_MEMORY_USERPTR); + return false; + + for (unsigned long i = 0; i < m_buf.length; i++) + m_planes[i].m.userptr = reinterpret_cast<unsigned long>(addrs[i]); + + return true; +} + bool LibScalerForJpeg::SetFormat() { if (ioctl(m_fdScaler, VIDIOC_S_FMT, &m_srcFmt) < 0) { diff --git a/libhwjpeg/include/LibScalerForJpeg.h b/libhwjpeg/include/LibScalerForJpeg.h index e739b35..99863fe 100644 --- a/libhwjpeg/include/LibScalerForJpeg.h +++ b/libhwjpeg/include/LibScalerForJpeg.h @@ -10,18 +10,13 @@ public: LibScalerForJpeg(); ~LibScalerForJpeg(); - bool SetSrcImage( - unsigned int width, unsigned int height, unsigned int v4l2_format, - void *addrs[SCALER_MAX_PLANES], int mem_type) { - return SetImage(m_srcFmt, m_srcBuf, m_srcPlanes, - width, height, v4l2_format, addrs, mem_type); + template <class T> + bool SetSrcImage(unsigned int width, unsigned int height, unsigned int v4l2_format, T buf[SCALER_MAX_PLANES]) { + return SetImage(m_srcFmt, m_srcBuf, m_srcPlanes, width, height, v4l2_format, buf); } - bool SetDstImage( - unsigned int width, unsigned int height, unsigned int v4l2_format, - void *addrs[SCALER_MAX_PLANES], int mem_type) { - return SetImage(m_dstFmt, m_dstBuf, m_dstPlanes, - width, height, v4l2_format, addrs, mem_type); + bool SetDstImage(unsigned int width, unsigned int height, unsigned int v4l2_format, int buf) { + return SetImage(m_dstFmt, m_dstBuf, m_dstPlanes, width, height, v4l2_format, &buf); } bool RunStream(); @@ -39,7 +34,16 @@ private: bool SetImage( v4l2_format &m_fmt, v4l2_buffer &m_buf, v4l2_plane m_planes[SCALER_MAX_PLANES], unsigned int width, unsigned int height, unsigned int v4l2_format, - void *addrs[SCALER_MAX_PLANES], int mem_type); + char *addrs[SCALER_MAX_PLANES]); + + bool SetImage( + v4l2_format &m_fmt, v4l2_buffer &m_buf, v4l2_plane m_planes[SCALER_MAX_PLANES], + unsigned int width, unsigned int height, unsigned int v4l2_format, + int buf[SCALER_MAX_PLANES]); + + bool SetImage( + v4l2_format &m_fmt, v4l2_buffer &m_buf, v4l2_plane m_planes[SCALER_MAX_PLANES], + unsigned int width, unsigned int height, unsigned int v4l2_format, unsigned int memtype); bool SetFormat(); bool ReqBufs(int count = 1); |