blob: 7880a6bd87e0b00c5ad3bc0835c7dc9e1db6f9c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2022, Google Inc.
*
* encoder_jea.cpp - 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;
}
|