Skip to content

Commit 0788a2a

Browse files
committed
Merge branch 'master' into next
2 parents 3771a85 + d8629f4 commit 0788a2a

39 files changed

+325
-201
lines changed

include/libcamera/base/thread.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99

1010
#include <memory>
11+
#include <string>
1112
#include <sys/types.h>
1213
#include <thread>
1314

@@ -30,7 +31,7 @@ class ThreadMain;
3031
class Thread
3132
{
3233
public:
33-
Thread();
34+
Thread(std::string name = {});
3435
virtual ~Thread();
3536

3637
void start();
@@ -74,8 +75,9 @@ class Thread
7475
void moveObject(Object *object, ThreadData *currentData,
7576
ThreadData *targetData);
7677

78+
std::string name_;
7779
std::thread thread_;
78-
ThreadData *data_;
80+
std::unique_ptr<ThreadData> data_;
7981
};
8082

8183
} /* namespace libcamera */

include/libcamera/base/utils.h

Lines changed: 14 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -77,69 +77,29 @@ using time_point = std::chrono::steady_clock::time_point;
7777
struct timespec duration_to_timespec(const duration &value);
7878
std::string time_point_to_string(const time_point &time);
7979

80-
#ifndef __DOXYGEN__
81-
struct _hex {
80+
namespace details {
81+
82+
struct hex {
8283
uint64_t v;
8384
unsigned int w;
8485
};
8586

86-
std::basic_ostream<char, std::char_traits<char>> &
87-
operator<<(std::basic_ostream<char, std::char_traits<char>> &stream, const _hex &h);
88-
#endif
89-
90-
template<typename T,
91-
std::enable_if_t<std::is_integral<T>::value> * = nullptr>
92-
_hex hex(T value, unsigned int width = 0);
93-
94-
#ifndef __DOXYGEN__
95-
template<>
96-
inline _hex hex<int8_t>(int8_t value, unsigned int width)
97-
{
98-
return { static_cast<uint64_t>(value), width ? width : 2 };
99-
}
100-
101-
template<>
102-
inline _hex hex<uint8_t>(uint8_t value, unsigned int width)
103-
{
104-
return { static_cast<uint64_t>(value), width ? width : 2 };
105-
}
106-
107-
template<>
108-
inline _hex hex<int16_t>(int16_t value, unsigned int width)
109-
{
110-
return { static_cast<uint64_t>(value), width ? width : 4 };
111-
}
112-
113-
template<>
114-
inline _hex hex<uint16_t>(uint16_t value, unsigned int width)
115-
{
116-
return { static_cast<uint64_t>(value), width ? width : 4 };
117-
}
118-
119-
template<>
120-
inline _hex hex<int32_t>(int32_t value, unsigned int width)
87+
template<typename T>
88+
constexpr unsigned int hex_width()
12189
{
122-
return { static_cast<uint64_t>(value), width ? width : 8 };
90+
return sizeof(T) * 2;
12391
}
12492

125-
template<>
126-
inline _hex hex<uint32_t>(uint32_t value, unsigned int width)
127-
{
128-
return { static_cast<uint64_t>(value), width ? width : 8 };
129-
}
93+
std::basic_ostream<char, std::char_traits<char>> &
94+
operator<<(std::basic_ostream<char, std::char_traits<char>> &stream, const hex &h);
13095

131-
template<>
132-
inline _hex hex<int64_t>(int64_t value, unsigned int width)
133-
{
134-
return { static_cast<uint64_t>(value), width ? width : 16 };
135-
}
96+
} /* namespace details */
13697

137-
template<>
138-
inline _hex hex<uint64_t>(uint64_t value, unsigned int width)
98+
template<typename T, std::enable_if_t<std::is_integral_v<T>> * = nullptr>
99+
details::hex hex(T value, unsigned int width = details::hex_width<T>())
139100
{
140-
return { static_cast<uint64_t>(value), width ? width : 16 };
101+
return { static_cast<std::make_unsigned_t<T>>(value), width };
141102
}
142-
#endif
143103

144104
size_t strlcpy(char *dst, const char *src, size_t size);
145105

@@ -355,18 +315,10 @@ class enumerate_adapter
355315
} /* namespace details */
356316

357317
template<typename T>
358-
auto enumerate(T &iterable) -> details::enumerate_adapter<decltype(iterable.begin())>
359-
{
360-
return { std::begin(iterable), std::end(iterable) };
361-
}
362-
363-
#ifndef __DOXYGEN__
364-
template<typename T, size_t N>
365-
auto enumerate(T (&iterable)[N]) -> details::enumerate_adapter<T *>
318+
auto enumerate(T &iterable)
366319
{
367-
return { std::begin(iterable), std::end(iterable) };
320+
return details::enumerate_adapter{ std::begin(iterable), std::end(iterable) };
368321
}
369-
#endif
370322

371323
class Duration : public std::chrono::duration<double, std::nano>
372324
{

include/libcamera/internal/control_serializer.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ class ControlSerializer
4747
static void store(const ControlValue &value, ByteStreamBuffer &buffer);
4848
static void store(const ControlInfo &info, ByteStreamBuffer &buffer);
4949

50+
void populateControlValueEntry(struct ipa_control_value_entry &entry,
51+
const ControlValue &value,
52+
uint32_t offset);
53+
5054
ControlValue loadControlValue(ByteStreamBuffer &buffer,
51-
bool isArray = false, unsigned int count = 1);
52-
ControlInfo loadControlInfo(ByteStreamBuffer &buffer);
55+
ControlType type,
56+
bool isArray, unsigned int count);
5357

5458
unsigned int serial_;
5559
unsigned int serialSeed_;

include/libcamera/ipa/ipa_controls.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace libcamera {
1515
extern "C" {
1616
#endif
1717

18-
#define IPA_CONTROLS_FORMAT_VERSION 1
18+
#define IPA_CONTROLS_FORMAT_VERSION 2
1919

2020
enum ipa_controls_id_map_type {
2121
IPA_CONTROL_ID_MAP_CONTROLS,
@@ -34,20 +34,25 @@ struct ipa_controls_header {
3434
};
3535

3636
struct ipa_control_value_entry {
37-
uint32_t id;
3837
uint8_t type;
3938
uint8_t is_array;
4039
uint16_t count;
4140
uint32_t offset;
4241
uint32_t padding[1];
42+
uint32_t reserved;
43+
};
44+
45+
struct ipa_control_list_entry {
46+
uint32_t id;
47+
struct ipa_control_value_entry value;
4348
};
4449

4550
struct ipa_control_info_entry {
4651
uint32_t id;
4752
uint32_t type;
48-
uint32_t offset;
4953
uint8_t direction;
5054
uint8_t padding[3];
55+
uint32_t reserved;
5156
};
5257

5358
#ifdef __cplusplus

src/android/camera_hal_manager.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void CameraHalManager::cameraAdded(std::shared_ptr<Camera> cam)
125125
* Now check if this is an external camera and assign
126126
* its id accordingly.
127127
*/
128-
if (cameraLocation(cam.get()) == properties::CameraLocationExternal) {
128+
if (cam->properties().get(properties::Location) == properties::CameraLocationExternal) {
129129
isCameraExternal = true;
130130
id = nextExternalCameraId_;
131131
} else {
@@ -227,11 +227,6 @@ void CameraHalManager::cameraRemoved(std::shared_ptr<Camera> cam)
227227
LOG(HAL, Debug) << "Camera ID: " << id << " removed successfully.";
228228
}
229229

230-
int32_t CameraHalManager::cameraLocation(const Camera *cam)
231-
{
232-
return cam->properties().get(properties::Location).value_or(-1);
233-
}
234-
235230
CameraDevice *CameraHalManager::cameraDeviceFromHalId(unsigned int id)
236231
{
237232
auto iter = std::find_if(cameras_.begin(), cameras_.end(),

src/android/camera_hal_manager.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ class CameraHalManager
4848

4949
CameraHalManager();
5050

51-
static int32_t cameraLocation(const libcamera::Camera *cam);
52-
5351
void cameraAdded(std::shared_ptr<libcamera::Camera> cam);
5452
void cameraRemoved(std::shared_ptr<libcamera::Camera> cam);
5553

src/gstreamer/gstlibcamerapad.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,13 @@ void gst_libcamera_pad_set_video_info(GstPad *pad, const GstVideoInfo *info)
192192
Stream *
193193
gst_libcamera_pad_get_stream(GstPad *pad)
194194
{
195-
auto *self = GST_LIBCAMERA_PAD(pad);
196-
197-
if (self->pool)
198-
return gst_libcamera_pool_get_stream(self->pool);
195+
return static_cast<Stream *>(gst_pad_get_element_private(pad));
196+
}
199197

200-
return nullptr;
198+
void
199+
gst_libcamera_pad_set_stream(GstPad *pad, Stream *stream)
200+
{
201+
gst_pad_set_element_private(pad, stream);
201202
}
202203

203204
void

src/gstreamer/gstlibcamerapad.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ void gst_libcamera_pad_set_video_info(GstPad *pad, const GstVideoInfo *info);
3333

3434
libcamera::Stream *gst_libcamera_pad_get_stream(GstPad *pad);
3535

36+
void gst_libcamera_pad_set_stream(GstPad *pad, libcamera::Stream *stream);
37+
3638
void gst_libcamera_pad_set_latency(GstPad *pad, GstClockTime latency);

src/gstreamer/gstlibcamerasrc.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ struct RequestWrap {
4848
RequestWrap(std::unique_ptr<Request> request);
4949
~RequestWrap();
5050

51-
void attachBuffer(Stream *stream, GstBuffer *buffer);
52-
GstBuffer *detachBuffer(Stream *stream);
51+
void attachBuffer(GstPad *srcpad, GstBuffer *buffer);
52+
GstBuffer *detachBuffer(GstPad *srcpad);
5353

5454
std::unique_ptr<Request> request_;
55-
std::map<Stream *, GstBuffer *> buffers_;
55+
std::map<GstPad *, GstBuffer *> buffers_;
5656

5757
GstClockTime latency_;
5858
GstClockTime pts_;
@@ -65,32 +65,33 @@ RequestWrap::RequestWrap(std::unique_ptr<Request> request)
6565

6666
RequestWrap::~RequestWrap()
6767
{
68-
for (std::pair<Stream *const, GstBuffer *> &item : buffers_) {
68+
for (std::pair<GstPad *const, GstBuffer *> &item : buffers_) {
6969
if (item.second)
7070
gst_buffer_unref(item.second);
7171
}
7272
}
7373

74-
void RequestWrap::attachBuffer(Stream *stream, GstBuffer *buffer)
74+
void RequestWrap::attachBuffer(GstPad *srcpad, GstBuffer *buffer)
7575
{
7676
FrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer(buffer);
77+
Stream *stream = gst_libcamera_pad_get_stream(srcpad);
7778

7879
request_->addBuffer(stream, fb);
7980

80-
auto item = buffers_.find(stream);
81+
auto item = buffers_.find(srcpad);
8182
if (item != buffers_.end()) {
8283
gst_buffer_unref(item->second);
8384
item->second = buffer;
8485
} else {
85-
buffers_[stream] = buffer;
86+
buffers_[srcpad] = buffer;
8687
}
8788
}
8889

89-
GstBuffer *RequestWrap::detachBuffer(Stream *stream)
90+
GstBuffer *RequestWrap::detachBuffer(GstPad *srcpad)
9091
{
9192
GstBuffer *buffer = nullptr;
9293

93-
auto item = buffers_.find(stream);
94+
auto item = buffers_.find(srcpad);
9495
if (item != buffers_.end()) {
9596
buffer = item->second;
9697
item->second = nullptr;
@@ -189,7 +190,6 @@ int GstLibcameraSrcState::queueRequest()
189190
std::make_unique<RequestWrap>(std::move(request));
190191

191192
for (GstPad *srcpad : srcpads_) {
192-
Stream *stream = gst_libcamera_pad_get_stream(srcpad);
193193
GstLibcameraPool *pool = gst_libcamera_pad_get_pool(srcpad);
194194
GstBuffer *buffer;
195195
GstFlowReturn ret;
@@ -204,7 +204,7 @@ int GstLibcameraSrcState::queueRequest()
204204
return -ENOBUFS;
205205
}
206206

207-
wrap->attachBuffer(stream, buffer);
207+
wrap->attachBuffer(srcpad, buffer);
208208
}
209209

210210
GST_TRACE_OBJECT(src_, "Requesting buffers");
@@ -354,10 +354,10 @@ int GstLibcameraSrcState::processRequest()
354354
for (gsize i = 0; i < srcpads_.size(); i++) {
355355
GstPad *srcpad = srcpads_[i];
356356
Stream *stream = gst_libcamera_pad_get_stream(srcpad);
357-
GstBuffer *buffer = wrap->detachBuffer(stream);
357+
GstBuffer *buffer = wrap->detachBuffer(srcpad);
358358

359359
FrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer(buffer);
360-
const StreamConfiguration &stream_cfg = config_->at(i);
360+
const StreamConfiguration &stream_cfg = stream->configuration();
361361
GstBufferPool *video_pool = gst_libcamera_pad_get_video_pool(srcpad);
362362

363363
if (video_pool) {
@@ -574,12 +574,8 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad,
574574
gst_buffer_pool_set_config(GST_BUFFER_POOL_CAST(pool), config);
575575
}
576576

577-
if (!gst_buffer_pool_set_active(pool, true)) {
578-
GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,
579-
("Failed to active buffer pool"),
580-
("gst_libcamera_src_negotiate() failed."));
577+
if (!gst_buffer_pool_set_active(pool, true))
581578
return { nullptr, -EINVAL };
582-
}
583579

584580
return { std::exchange(pool, nullptr), 0 };
585581
}
@@ -680,8 +676,12 @@ gst_libcamera_src_negotiate(GstLibcameraSrc *self)
680676
std::tie(video_pool, ret) =
681677
gst_libcamera_create_video_pool(self, srcpad,
682678
caps, &info);
683-
if (ret)
679+
if (ret) {
680+
GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,
681+
("Failed to create video pool: %s", g_strerror(-ret)),
682+
("gst_libcamera_src_negotiate() failed."));
684683
return false;
684+
}
685685
}
686686

687687
GstLibcameraPool *pool = gst_libcamera_pool_new(self->allocator,
@@ -692,6 +692,9 @@ gst_libcamera_src_negotiate(GstLibcameraSrc *self)
692692
gst_libcamera_pad_set_pool(srcpad, pool);
693693
gst_libcamera_pad_set_video_pool(srcpad, video_pool);
694694

695+
/* Associate the configured stream with the source pad. */
696+
gst_libcamera_pad_set_stream(srcpad, stream_cfg.stream());
697+
695698
/* Clear all reconfigure flags. */
696699
gst_pad_check_reconfigure(srcpad);
697700
}
@@ -888,6 +891,7 @@ gst_libcamera_src_task_leave([[maybe_unused]] GstTask *task,
888891
for (GstPad *srcpad : state->srcpads_) {
889892
gst_libcamera_pad_set_latency(srcpad, GST_CLOCK_TIME_NONE);
890893
gst_libcamera_pad_set_pool(srcpad, nullptr);
894+
gst_libcamera_pad_set_stream(srcpad, nullptr);
891895
}
892896
}
893897

src/ipa/ipu3/ipu3.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <libcamera/base/file.h>
2222
#include <libcamera/base/log.h>
23+
#include <libcamera/base/span.h>
2324
#include <libcamera/base/utils.h>
2425

2526
#include <libcamera/control_ids.h>
@@ -280,10 +281,9 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,
280281
uint64_t frameSize = lineLength * frameHeights[i];
281282
frameDurations[i] = frameSize / (sensorInfo.pixelRate / 1000000U);
282283
}
283-
284284
controls[&controls::FrameDurationLimits] = ControlInfo(frameDurations[0],
285285
frameDurations[1],
286-
frameDurations[2]);
286+
Span<const int64_t, 2>{ { frameDurations[2], frameDurations[2] } });
287287

288288
controls.merge(context_.ctrlMap);
289289
*ipaControls = ControlInfoMap(std::move(controls), controls::controls);

0 commit comments

Comments
 (0)