diff options
author | Michelle Yang <micya@google.com> | 2023-03-13 23:14:02 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2023-03-13 23:14:02 +0000 |
commit | 1c916b400b8a0f2c2d070237c4e17d820c859bf4 (patch) | |
tree | e24c95921d29301a76a3b9e601399c28b5702822 | |
parent | e6f8ced56ecc80b00288a21576d376dc02caee7c (diff) | |
parent | d72a4d972173a78f5d7fd1599cde2d4dac756a86 (diff) |
Merge "libhwjpeg: Add advisory lock" into udc-dev
-rw-r--r-- | libhwjpeg/Android.bp | 1 | ||||
-rw-r--r-- | libhwjpeg/ExynosJpegEncoder.cpp | 9 | ||||
-rw-r--r-- | libhwjpeg/FileLock.cpp | 13 | ||||
-rw-r--r-- | libhwjpeg/hwjpeg-v4l2.cpp | 11 | ||||
-rw-r--r-- | libhwjpeg/include/ExynosJpegApi.h | 5 | ||||
-rw-r--r-- | libhwjpeg/include/FileLock.h | 16 | ||||
-rw-r--r-- | libhwjpeg/include/exynos-hwjpeg.h | 11 |
7 files changed, 65 insertions, 1 deletions
diff --git a/libhwjpeg/Android.bp b/libhwjpeg/Android.bp index b7dd526..86dc84d 100644 --- a/libhwjpeg/Android.bp +++ b/libhwjpeg/Android.bp @@ -10,6 +10,7 @@ cc_library_shared { "AppMarkerWriter.cpp", "ExynosJpegEncoder.cpp", "ExynosJpegEncoderForCamera.cpp", + "FileLock.cpp", "hwjpeg-base.cpp", "hwjpeg-v4l2.cpp", "libhwjpeg-exynos.cpp", diff --git a/libhwjpeg/ExynosJpegEncoder.cpp b/libhwjpeg/ExynosJpegEncoder.cpp index f25d9b4..d833ca7 100644 --- a/libhwjpeg/ExynosJpegEncoder.cpp +++ b/libhwjpeg/ExynosJpegEncoder.cpp @@ -19,6 +19,15 @@ #include <linux/videodev2.h> #include "hwjpeg-internal.h" + +int ExynosJpegEncoder::lock() { + return m_hwjpeg.lock(); +} + +int ExynosJpegEncoder::unlock() { + return m_hwjpeg.unlock(); +} + int ExynosJpegEncoder::setJpegConfig(void *pConfig) { ExynosJpegEncoder *that = reinterpret_cast<ExynosJpegEncoder *>(pConfig); diff --git a/libhwjpeg/FileLock.cpp b/libhwjpeg/FileLock.cpp new file mode 100644 index 0000000..6e8ecbd --- /dev/null +++ b/libhwjpeg/FileLock.cpp @@ -0,0 +1,13 @@ +#include "FileLock.h" + +#include <bits/lockf.h> + +FileLock::FileLock(int fd) : fd_(fd) {} + +int FileLock::lock() { + return lockf(fd_, F_LOCK, 0); +} + +int FileLock::unlock() { + return lockf(fd_, F_ULOCK, 0); +} diff --git a/libhwjpeg/hwjpeg-v4l2.cpp b/libhwjpeg/hwjpeg-v4l2.cpp index b822e24..c364554 100644 --- a/libhwjpeg/hwjpeg-v4l2.cpp +++ b/libhwjpeg/hwjpeg-v4l2.cpp @@ -22,7 +22,8 @@ #include "hwjpeg-internal.h" #include "log/log_main.h" -CHWJpegV4L2Compressor::CHWJpegV4L2Compressor() : CHWJpegCompressor("/dev/video12") { +CHWJpegV4L2Compressor::CHWJpegV4L2Compressor() + : CHWJpegCompressor("/dev/video12"), file_lock_(FileLock(GetDeviceFD())) { memset(&m_v4l2Format, 0, sizeof(m_v4l2Format)); memset(&m_v4l2SrcBuffer, 0, sizeof(m_v4l2SrcBuffer)); memset(&m_v4l2DstBuffer, 0, sizeof(m_v4l2DstBuffer)); @@ -69,6 +70,14 @@ CHWJpegV4L2Compressor::~CHWJpegV4L2Compressor() { ALOGD("CHWJpegV4L2Compressor Destroyed: %p, FD %d", this, GetDeviceFD()); } +int CHWJpegV4L2Compressor::lock() { + return file_lock_.lock(); +} + +int CHWJpegV4L2Compressor::unlock() { + return file_lock_.unlock(); +} + bool CHWJpegV4L2Compressor::SetChromaSampFactor(unsigned int horizontal, unsigned int vertical) { __s32 value; switch ((horizontal << 4) | vertical) { diff --git a/libhwjpeg/include/ExynosJpegApi.h b/libhwjpeg/include/ExynosJpegApi.h index 6addf51..dcf06b3 100644 --- a/libhwjpeg/include/ExynosJpegApi.h +++ b/libhwjpeg/include/ExynosJpegApi.h @@ -114,6 +114,11 @@ public: } virtual ~ExynosJpegEncoder() { destroy(); } + // Acquire exclusive lock to V4L2 device. This is a blocking call. + int lock(); + // Release exclusive lock to V4L2 device. + int unlock(); + // Return 0 on success, -1 on error int flagCreate() { return m_hwjpeg.Okay() ? 0 : -1; } virtual int create(void) { return flagCreate(); } diff --git a/libhwjpeg/include/FileLock.h b/libhwjpeg/include/FileLock.h new file mode 100644 index 0000000..b308aa7 --- /dev/null +++ b/libhwjpeg/include/FileLock.h @@ -0,0 +1,16 @@ +#include "android-base/thread_annotations.h" + +// Encapsulates advisory file lock for a given field descriptor +class CAPABILITY("mutex") FileLock { +public: + FileLock(int fd); + ~FileLock() = default; + + // Acquires advisory file lock. This will block. + int lock() ACQUIRE(); + // Releases advisory file lock. + int unlock() RELEASE(); + +private: + int fd_; +};
\ No newline at end of file diff --git a/libhwjpeg/include/exynos-hwjpeg.h b/libhwjpeg/include/exynos-hwjpeg.h index 3d3d7e5..45114b5 100644 --- a/libhwjpeg/include/exynos-hwjpeg.h +++ b/libhwjpeg/include/exynos-hwjpeg.h @@ -26,6 +26,9 @@ #error VIDEO_MAX_PLANES should not be smaller than 6 #endif +#include "FileLock.h" +#include "android-base/thread_annotations.h" + // Exynos JPEG specific device capabilities // Defined in the driver. Not in videodev2.h #define V4L2_CAP_EXYNOS_JPEG_DECOMPRESSION 0x0100 @@ -581,6 +584,8 @@ class CHWJpegV4L2Compressor : public CHWJpegCompressor, private CHWJpegFlagManag bool m_bEnableHWFC; + FileLock file_lock_; + bool IsB2BCompression() { return (TO_SEC_IMG_SIZE(m_v4l2Format.fmt.pix_mp.width) + TO_SEC_IMG_SIZE(m_v4l2Format.fmt.pix_mp.height)) != 0; @@ -601,6 +606,12 @@ public: CHWJpegV4L2Compressor(); virtual ~CHWJpegV4L2Compressor(); + // Acquires exclusive lock to V4L2 device. This must be called before starting image + // configuration. This is a blocking call. + int lock(); + // Releases exclusive lock to V4L2 device. This should be called after encoding is complete. + int unlock(); + unsigned int GetHWDelay() { return m_uiHWDelay; } // SetChromaSampFactor can be called during streaming |