summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJayant Chowdhary <jchowdhary@google.com>2022-05-02 22:05:28 +0000
committerJayant Chowdhary <jchowdhary@google.com>2022-05-02 22:31:31 +0000
commit4593bfbd28b9f9b735d16d618290451067ad9ffe (patch)
tree232b37cabf2f15fb8917a3b5242664a962c70cf0
parent63d72717c628a34e3eea4a910c004f80dabf7f78 (diff)
downloadcamera-4593bfbd28b9f9b735d16d618290451067ad9ffe.tar.gz
Make CameraBlob consistent with AIDL definition.
Bug: 229688810 Test: GCA (basic validity) Test: atest DngCreatorTest#testRaw16JpegConsistency Change-Id: Ia009a62beee0bbc786172d1eb8b689e0b3d4c118 Signed-off-by: Jayant Chowdhary <jchowdhary@google.com>
-rw-r--r--common/hal/utils/camera_blob.h60
-rw-r--r--devices/EmulatedCamera/hwl/JpegCompressor.cpp15
2 files changed, 68 insertions, 7 deletions
diff --git a/common/hal/utils/camera_blob.h b/common/hal/utils/camera_blob.h
new file mode 100644
index 0000000..f038b55
--- /dev/null
+++ b/common/hal/utils/camera_blob.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HARDWARE_GOOGLE_CAMERA_HAL_UTILS_CAMERA_BLOB_H_
+#define HARDWARE_GOOGLE_CAMERA_HAL_UTILS_CAMERA_BLOB_H_
+
+#include <cstdint>
+
+namespace android {
+namespace google_camera_hal {
+
+/**
+ * CameraBlob:
+ *
+ * Transport header for camera blob types; generally compressed JPEG buffers in
+ * output streams.
+ *
+ * To capture JPEG images, a stream is created using the pixel format
+ * HAL_PIXEL_FORMAT_BLOB and dataspace HAL_DATASPACE_V0_JFIF. The buffer size
+ * for the stream is calculated by the framework, based on the static metadata
+ * field android.jpeg.maxSize. Since compressed JPEG images are of variable
+ * size, the HAL needs to include the final size of the compressed image using
+ * this structure inside the output stream buffer. The camera blob ID field must
+ * be set to CameraBlobId::JPEG.
+ *
+ * The transport header must be at the end of the JPEG output stream
+ * buffer. That means the jpegBlobId must start at byte[buffer_size -
+ * sizeof(CameraBlob)], where the buffer_size is the size of gralloc
+ * buffer. Any HAL using this transport header must account for it in
+ * android.jpeg.maxSize. The JPEG data itself starts at the beginning of the
+ * buffer and must be blobSize bytes long.
+ *
+ * Copied from hardware/interfaces/camera/device/aidl/CameraBlobId.aidl
+ */
+enum CameraBlobId : uint32_t {
+ JPEG = 0x00FF,
+};
+
+struct CameraBlob {
+ CameraBlobId blob_id;
+ uint32_t blob_size;
+};
+
+} // namespace google_camera_hal
+} // namespace android
+
+#endif // HARDWARE_GOOGLE_CAMERA_HAL_UTILS_CAMERA_BLOB_H_
diff --git a/devices/EmulatedCamera/hwl/JpegCompressor.cpp b/devices/EmulatedCamera/hwl/JpegCompressor.cpp
index c1ae8ea..582c92f 100644
--- a/devices/EmulatedCamera/hwl/JpegCompressor.cpp
+++ b/devices/EmulatedCamera/hwl/JpegCompressor.cpp
@@ -19,14 +19,16 @@
#include "JpegCompressor.h"
+#include <camera_blob.h>
#include <cutils/properties.h>
-#include <hardware/camera3.h>
#include <libyuv.h>
#include <utils/Log.h>
#include <utils/Trace.h>
namespace android {
+using google_camera_hal::CameraBlob;
+using google_camera_hal::CameraBlobId;
using google_camera_hal::ErrorCode;
using google_camera_hal::MessageType;
using google_camera_hal::NotifyMessage;
@@ -204,13 +206,12 @@ void JpegCompressor::CompressYUV420(std::unique_ptr<JpegYUV420Job> job) {
}
auto jpeg_header_offset =
- job->output->plane.img.buffer_size - sizeof(struct camera3_jpeg_blob);
+ job->output->plane.img.buffer_size - sizeof(struct CameraBlob);
if (jpeg_header_offset > encoded_size) {
- struct camera3_jpeg_blob* blob =
- reinterpret_cast<struct camera3_jpeg_blob*>(job->output->plane.img.img +
- jpeg_header_offset);
- blob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID;
- blob->jpeg_size = encoded_size;
+ struct CameraBlob* blob = reinterpret_cast<struct CameraBlob*>(
+ job->output->plane.img.img + jpeg_header_offset);
+ blob->blob_id = CameraBlobId::JPEG;
+ blob->blob_size = encoded_size;
} else {
ALOGW("%s: No space for jpeg header at offset: %u and jpeg size: %u",
__FUNCTION__, static_cast<unsigned>(jpeg_header_offset),