summaryrefslogtreecommitdiff
path: root/src/android/jpeg
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/jpeg')
-rw-r--r--src/android/jpeg/encoder.h7
-rw-r--r--src/android/jpeg/encoder_jea.cpp56
-rw-r--r--src/android/jpeg/encoder_jea.h31
-rw-r--r--src/android/jpeg/encoder_libjpeg.cpp15
-rw-r--r--src/android/jpeg/encoder_libjpeg.h5
-rw-r--r--src/android/jpeg/exif.cpp15
-rw-r--r--src/android/jpeg/exif.h7
-rw-r--r--src/android/jpeg/meson.build14
-rw-r--r--src/android/jpeg/post_processor_jpeg.cpp15
-rw-r--r--src/android/jpeg/post_processor_jpeg.h2
-rw-r--r--src/android/jpeg/thumbnailer.cpp2
-rw-r--r--src/android/jpeg/thumbnailer.h2
12 files changed, 142 insertions, 29 deletions
diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h
index b974d367..ed033c19 100644
--- a/src/android/jpeg/encoder.h
+++ b/src/android/jpeg/encoder.h
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2020, Google Inc.
*
- * encoder.h - Image encoding interface
+ * Image encoding interface
*/
#pragma once
@@ -12,14 +12,15 @@
#include <libcamera/framebuffer.h>
#include <libcamera/stream.h>
+#include "../camera_request.h"
+
class Encoder
{
public:
virtual ~Encoder() = default;
virtual int configure(const libcamera::StreamConfiguration &cfg) = 0;
- virtual int encode(const libcamera::FrameBuffer &source,
- libcamera::Span<uint8_t> destination,
+ virtual int encode(Camera3RequestDescriptor::StreamBuffer *buffer,
libcamera::Span<const uint8_t> exifData,
unsigned int quality) = 0;
};
diff --git a/src/android/jpeg/encoder_jea.cpp b/src/android/jpeg/encoder_jea.cpp
new file mode 100644
index 00000000..25dc4317
--- /dev/null
+++ b/src/android/jpeg/encoder_jea.cpp
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Google Inc.
+ *
+ * JPEG encoding using CrOS JEA
+ */
+
+#include "encoder_jea.h"
+
+#include "libcamera/internal/mapped_framebuffer.h"
+
+#include <cros-camera/camera_mojo_channel_manager_token.h>
+
+#include "../cros_mojo_token.h"
+#include "../hal_framebuffer.h"
+
+EncoderJea::EncoderJea() = default;
+
+EncoderJea::~EncoderJea() = default;
+
+int EncoderJea::configure(const libcamera::StreamConfiguration &cfg)
+{
+ size_ = cfg.size;
+
+ if (jpegCompressor_)
+ return 0;
+
+ if (gCrosMojoToken == nullptr)
+ return -ENOTSUP;
+
+ jpegCompressor_ = cros::JpegCompressor::GetInstance(gCrosMojoToken);
+
+ return 0;
+}
+
+int EncoderJea::encode(Camera3RequestDescriptor::StreamBuffer *buffer,
+ libcamera::Span<const uint8_t> exifData,
+ unsigned int quality)
+{
+ if (!jpegCompressor_)
+ return -ENOTSUP;
+
+ uint32_t outDataSize = 0;
+ const HALFrameBuffer *fb =
+ dynamic_cast<const HALFrameBuffer *>(buffer->srcBuffer);
+
+ if (!jpegCompressor_->CompressImageFromHandle(fb->handle(),
+ *buffer->camera3Buffer,
+ size_.width, size_.height,
+ quality, exifData.data(),
+ exifData.size(),
+ &outDataSize))
+ return -EBUSY;
+
+ return outDataSize;
+}
diff --git a/src/android/jpeg/encoder_jea.h b/src/android/jpeg/encoder_jea.h
new file mode 100644
index 00000000..91115d2e
--- /dev/null
+++ b/src/android/jpeg/encoder_jea.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Google Inc.
+ *
+ * JPEG encoding using CrOS JEA
+ */
+
+#pragma once
+
+#include <libcamera/geometry.h>
+
+#include <cros-camera/jpeg_compressor.h>
+
+#include "encoder.h"
+
+class EncoderJea : public Encoder
+{
+public:
+ EncoderJea();
+ ~EncoderJea();
+
+ int configure(const libcamera::StreamConfiguration &cfg) override;
+ int encode(Camera3RequestDescriptor::StreamBuffer *buffer,
+ libcamera::Span<const uint8_t> exifData,
+ unsigned int quality) override;
+
+private:
+ libcamera::Size size_;
+
+ std::unique_ptr<cros::JpegCompressor> jpegCompressor_;
+};
diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp
index fd62bd9c..7fc6287e 100644
--- a/src/android/jpeg/encoder_libjpeg.cpp
+++ b/src/android/jpeg/encoder_libjpeg.cpp
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2020, Google Inc.
*
- * encoder_libjpeg.cpp - JPEG encoding using libjpeg native API
+ * JPEG encoding using libjpeg native API
*/
#include "encoder_libjpeg.h"
@@ -24,6 +24,8 @@
#include "libcamera/internal/formats.h"
#include "libcamera/internal/mapped_framebuffer.h"
+#include "../camera_buffer.h"
+
using namespace libcamera;
LOG_DECLARE_CATEGORY(JPEG)
@@ -178,17 +180,20 @@ void EncoderLibJpeg::compressNV(const std::vector<Span<uint8_t>> &planes)
}
}
-int EncoderLibJpeg::encode(const FrameBuffer &source, Span<uint8_t> dest,
- Span<const uint8_t> exifData, unsigned int quality)
+int EncoderLibJpeg::encode(Camera3RequestDescriptor::StreamBuffer *buffer,
+ libcamera::Span<const uint8_t> exifData,
+ unsigned int quality)
{
- MappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read);
+ MappedFrameBuffer frame(buffer->srcBuffer,
+ MappedFrameBuffer::MapFlag::Read);
if (!frame.isValid()) {
LOG(JPEG, Error) << "Failed to map FrameBuffer : "
<< strerror(frame.error());
return frame.error();
}
- return encode(frame.planes(), dest, exifData, quality);
+ return encode(frame.planes(), buffer->dstBuffer->plane(0),
+ exifData, quality);
}
int EncoderLibJpeg::encode(const std::vector<Span<uint8_t>> &src,
diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h
index 1b3ac067..4ac85c22 100644
--- a/src/android/jpeg/encoder_libjpeg.h
+++ b/src/android/jpeg/encoder_libjpeg.h
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2020, Google Inc.
*
- * encoder_libjpeg.h - JPEG encoding using libjpeg
+ * JPEG encoding using libjpeg
*/
#pragma once
@@ -22,8 +22,7 @@ public:
~EncoderLibJpeg();
int configure(const libcamera::StreamConfiguration &cfg) override;
- int encode(const libcamera::FrameBuffer &source,
- libcamera::Span<uint8_t> destination,
+ int encode(Camera3RequestDescriptor::StreamBuffer *buffer,
libcamera::Span<const uint8_t> exifData,
unsigned int quality) override;
int encode(const std::vector<libcamera::Span<uint8_t>> &planes,
diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp
index 3220b458..b8c871df 100644
--- a/src/android/jpeg/exif.cpp
+++ b/src/android/jpeg/exif.cpp
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2020, Google Inc.
*
- * exif.cpp - EXIF tag creation using libexif
+ * EXIF tag creation using libexif
*/
#include "exif.h"
@@ -430,16 +430,13 @@ void Exif::setOrientation(int orientation)
setShort(EXIF_IFD_0, EXIF_TAG_ORIENTATION, value);
}
-/*
- * The thumbnail data should remain valid until the Exif object is destroyed.
- * Failing to do so, might result in no thumbnail data being set even after a
- * call to Exif::setThumbnail().
- */
-void Exif::setThumbnail(Span<const unsigned char> thumbnail,
+void Exif::setThumbnail(std::vector<unsigned char> &&thumbnail,
Compression compression)
{
- data_->data = const_cast<unsigned char *>(thumbnail.data());
- data_->size = thumbnail.size();
+ thumbnailData_ = std::move(thumbnail);
+
+ data_->data = thumbnailData_.data();
+ data_->size = thumbnailData_.size();
setShort(EXIF_IFD_0, EXIF_TAG_COMPRESSION, compression);
}
diff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h
index 2ff8fb78..446d53f3 100644
--- a/src/android/jpeg/exif.h
+++ b/src/android/jpeg/exif.h
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2020, Google Inc.
*
- * exif.h - EXIF tag creator using libexif
+ * EXIF tag creator using libexif
*/
#pragma once
@@ -10,6 +10,7 @@
#include <chrono>
#include <string>
#include <time.h>
+#include <vector>
#include <libexif/exif-data.h>
@@ -60,7 +61,7 @@ public:
void setOrientation(int orientation);
void setSize(const libcamera::Size &size);
- void setThumbnail(libcamera::Span<const unsigned char> thumbnail,
+ void setThumbnail(std::vector<unsigned char> &&thumbnail,
Compression compression);
void setTimestamp(time_t timestamp, std::chrono::milliseconds msec);
@@ -106,4 +107,6 @@ private:
unsigned char *exifData_;
unsigned int size_;
+
+ std::vector<unsigned char> thumbnailData_;
};
diff --git a/src/android/jpeg/meson.build b/src/android/jpeg/meson.build
new file mode 100644
index 00000000..3402e614
--- /dev/null
+++ b/src/android/jpeg/meson.build
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: CC0-1.0
+
+android_hal_sources += files([
+ 'encoder_libjpeg.cpp',
+ 'exif.cpp',
+ 'post_processor_jpeg.cpp',
+ 'thumbnailer.cpp'
+])
+
+platform = get_option('android_platform')
+if platform == 'cros'
+ android_hal_sources += files(['encoder_jea.cpp'])
+ android_deps += [dependency('libcros_camera')]
+endif
diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp
index d72ebc3c..89b8a401 100644
--- a/src/android/jpeg/post_processor_jpeg.cpp
+++ b/src/android/jpeg/post_processor_jpeg.cpp
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2020, Google Inc.
*
- * post_processor_jpeg.cpp - JPEG Post Processor
+ * JPEG Post Processor
*/
#include "post_processor_jpeg.h"
@@ -12,7 +12,11 @@
#include "../camera_device.h"
#include "../camera_metadata.h"
#include "../camera_request.h"
+#if defined(OS_CHROMEOS)
+#include "encoder_jea.h"
+#else /* !defined(OS_CHROMEOS) */
#include "encoder_libjpeg.h"
+#endif
#include "exif.h"
#include <libcamera/base/log.h>
@@ -46,7 +50,11 @@ int PostProcessorJpeg::configure(const StreamConfiguration &inCfg,
thumbnailer_.configure(inCfg.size, inCfg.pixelFormat);
+#if defined(OS_CHROMEOS)
+ encoder_ = std::make_unique<EncoderJea>();
+#else /* !defined(OS_CHROMEOS) */
encoder_ = std::make_unique<EncoderLibJpeg>();
+#endif
return encoder_->configure(inCfg);
}
@@ -166,7 +174,7 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu
std::vector<unsigned char> thumbnail;
generateThumbnail(source, thumbnailSize, quality, &thumbnail);
if (!thumbnail.empty())
- exif.setThumbnail(thumbnail, Exif::Compression::JPEG);
+ exif.setThumbnail(std::move(thumbnail), Exif::Compression::JPEG);
}
resultMetadata->addEntry(ANDROID_JPEG_THUMBNAIL_SIZE, data, 2);
@@ -194,8 +202,7 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu
const uint8_t quality = ret ? *entry.data.u8 : 95;
resultMetadata->addEntry(ANDROID_JPEG_QUALITY, quality);
- int jpeg_size = encoder_->encode(source, destination->plane(0),
- exif.data(), quality);
+ int jpeg_size = encoder_->encode(streamBuffer, exif.data(), quality);
if (jpeg_size < 0) {
LOG(JPEG, Error) << "Failed to encode stream image";
processComplete.emit(streamBuffer, PostProcessor::Status::Error);
diff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h
index 98309b01..6fe21457 100644
--- a/src/android/jpeg/post_processor_jpeg.h
+++ b/src/android/jpeg/post_processor_jpeg.h
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2020, Google Inc.
*
- * post_processor_jpeg.h - JPEG Post Processor
+ * JPEG Post Processor
*/
#pragma once
diff --git a/src/android/jpeg/thumbnailer.cpp b/src/android/jpeg/thumbnailer.cpp
index 41c71c76..adafc468 100644
--- a/src/android/jpeg/thumbnailer.cpp
+++ b/src/android/jpeg/thumbnailer.cpp
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2020, Google Inc.
*
- * thumbnailer.cpp - Simple image thumbnailer
+ * Simple image thumbnailer
*/
#include "thumbnailer.h"
diff --git a/src/android/jpeg/thumbnailer.h b/src/android/jpeg/thumbnailer.h
index d933cf0e..1b836e59 100644
--- a/src/android/jpeg/thumbnailer.h
+++ b/src/android/jpeg/thumbnailer.h
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2020, Google Inc.
*
- * thumbnailer.h - Simple image thumbnailer
+ * Simple image thumbnailer
*/
#pragma once