blob: 2e52bd5ca52efcee8a798085cdcdecc6dac6747c (
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2020, Raspberry Pi (Trading) Ltd.
*
* rpi_stream.cpp - Raspberry Pi device stream abstraction class.
*/
#include "rpi_stream.h"
#include "libcamera/internal/log.h"
namespace libcamera {
LOG_DEFINE_CATEGORY(RPISTREAM)
namespace RPi {
V4L2VideoDevice *RPiStream::dev() const
{
return dev_.get();
}
std::string RPiStream::name() const
{
return name_;
}
void RPiStream::reset()
{
external_ = false;
internalBuffers_.clear();
}
bool RPiStream::isImporter() const
{
return importOnly_;
}
void RPiStream::setExternal(bool external)
{
external_ = external;
}
bool RPiStream::isExternal() const
{
/*
* Import streams cannot be external.
*
* RAW capture is a special case where we simply copy the RAW
* buffer out of the request. All other buffer handling happens
* as if the stream is internal.
*/
return external_ && !importOnly_;
}
void RPiStream::setExternalBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers)
{
externalBuffers_ = buffers;
}
const std::vector<std::unique_ptr<FrameBuffer>> *RPiStream::getBuffers() const
{
return external_ ? externalBuffers_ : &internalBuffers_;
}
bool RPiStream::findFrameBuffer(FrameBuffer *buffer) const
{
auto start = external_ ? externalBuffers_->begin() : internalBuffers_.begin();
auto end = external_ ? externalBuffers_->end() : internalBuffers_.end();
if (importOnly_)
return false;
if (std::find_if(start, end,
[buffer](std::unique_ptr<FrameBuffer> const &ref) { return ref.get() == buffer; }) != end)
return true;
return false;
}
int RPiStream::importBuffers(unsigned int count)
{
return dev_->importBuffers(count);
}
int RPiStream::allocateBuffers(unsigned int count)
{
return dev_->allocateBuffers(count, &internalBuffers_);
}
int RPiStream::queueBuffers()
{
if (external_)
return 0;
for (auto &b : internalBuffers_) {
int ret = dev_->queueBuffer(b.get());
if (ret) {
LOG(RPISTREAM, Error) << "Failed to queue buffers for "
<< name_;
return ret;
}
}
return 0;
}
void RPiStream::releaseBuffers()
{
dev_->releaseBuffers();
if (!external_ && !importOnly_)
internalBuffers_.clear();
}
} /* namespace RPi */
} /* namespace libcamera */
|