summaryrefslogtreecommitdiff
path: root/utils/kmscapture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/kmscapture.cpp')
-rw-r--r--utils/kmscapture.cpp69
1 files changed, 32 insertions, 37 deletions
diff --git a/utils/kmscapture.cpp b/utils/kmscapture.cpp
index a36b355..099d40f 100644
--- a/utils/kmscapture.cpp
+++ b/utils/kmscapture.cpp
@@ -11,8 +11,8 @@
#include <kms++/kms++.h>
#include <kms++util/kms++util.h>
-#define CAMERA_BUF_QUEUE_SIZE 3
-#define MAX_CAMERA 9
+#define CAMERA_BUF_QUEUE_SIZE 3
+#define MAX_CAMERA 9
using namespace std;
using namespace kms;
@@ -33,12 +33,13 @@ public:
CameraPipeline(const CameraPipeline& other) = delete;
CameraPipeline& operator=(const CameraPipeline& other) = delete;
- void show_next_frame(AtomicReq &req);
+ void show_next_frame(AtomicReq& req);
int fd() const { return m_fd; }
void start_streaming();
+
private:
DmabufFramebuffer* GetDmabufFrameBuffer(Card& card, uint32_t i, PixelFormat pixfmt);
- int m_fd; /* camera file descriptor */
+ int m_fd; /* camera file descriptor */
Crtc* m_crtc;
Plane* m_plane;
BufferProvider m_buffer_provider;
@@ -50,7 +51,7 @@ private:
uint32_t m_out_x, m_out_y;
};
-static int buffer_export(int v4lfd, enum v4l2_buf_type bt, uint32_t index, int *dmafd)
+static int buffer_export(int v4lfd, enum v4l2_buf_type bt, uint32_t index, int* dmafd)
{
struct v4l2_exportbuffer expbuf;
@@ -77,12 +78,12 @@ DmabufFramebuffer* CameraPipeline::GetDmabufFrameBuffer(Card& card, uint32_t i,
const PixelFormatInfo& format_info = get_pixel_format_info(pixfmt);
ASSERT(format_info.num_planes == 1);
- vector<int> fds { dmafd };
- vector<uint32_t> pitches { m_in_width * (format_info.planes[0].bitspp / 8) };
- vector<uint32_t> offsets { 0 };
+ vector<int> fds{ dmafd };
+ vector<uint32_t> pitches{ m_in_width * (format_info.planes[0].bitspp / 8) };
+ vector<uint32_t> offsets{ 0 };
return new DmabufFramebuffer(card, m_in_width, m_in_height, pixfmt,
- fds, pitches, offsets);
+ fds, pitches, offsets);
}
bool inline better_size(struct v4l2_frmsize_discrete* v4ldisc,
@@ -96,17 +97,16 @@ bool inline better_size(struct v4l2_frmsize_discrete* v4ldisc,
return false;
}
-CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc *crtc, Plane* plane, uint32_t x, uint32_t y,
+CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc* crtc, Plane* plane, uint32_t x, uint32_t y,
uint32_t iw, uint32_t ih, PixelFormat pixfmt,
BufferProvider buffer_provider)
: m_fd(cam_fd), m_crtc(crtc), m_buffer_provider(buffer_provider), m_prev_fb_index(-1)
{
-
int r;
uint32_t best_w = 320;
uint32_t best_h = 240;
- struct v4l2_frmsizeenum v4lfrms = { };
+ struct v4l2_frmsizeenum v4lfrms = {};
v4lfrms.pixel_format = (uint32_t)pixfmt;
while (ioctl(m_fd, VIDIOC_ENUM_FRAMESIZES, &v4lfrms) == 0) {
if (v4lfrms.type != V4L2_FRMSIZE_TYPE_DISCRETE) {
@@ -137,7 +137,7 @@ CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc *crtc, Plane* plane,
printf("Capture: %ux%u\n", best_w, best_h);
- struct v4l2_format v4lfmt = { };
+ struct v4l2_format v4lfmt = {};
v4lfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
r = ioctl(m_fd, VIDIOC_G_FMT, &v4lfmt);
ASSERT(r == 0);
@@ -156,7 +156,7 @@ CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc *crtc, Plane* plane,
else
v4l_mem = V4L2_MEMORY_DMABUF;
- struct v4l2_requestbuffers v4lreqbuf = { };
+ struct v4l2_requestbuffers v4lreqbuf = {};
v4lreqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
v4lreqbuf.memory = v4l_mem;
v4lreqbuf.count = CAMERA_BUF_QUEUE_SIZE;
@@ -164,12 +164,12 @@ CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc *crtc, Plane* plane,
ASSERT(r == 0);
ASSERT(v4lreqbuf.count == CAMERA_BUF_QUEUE_SIZE);
- struct v4l2_buffer v4lbuf = { };
+ struct v4l2_buffer v4lbuf = {};
v4lbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
v4lbuf.memory = v4l_mem;
for (unsigned i = 0; i < CAMERA_BUF_QUEUE_SIZE; i++) {
- Framebuffer *fb;
+ Framebuffer* fb;
if (m_buffer_provider == BufferProvider::V4L2)
fb = GetDmabufFrameBuffer(card, i, pixfmt);
@@ -192,7 +192,7 @@ CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc *crtc, Plane* plane,
// set the FB when page flipping
AtomicReq req(card);
- Framebuffer *fb = m_fb[0];
+ Framebuffer* fb = m_fb[0];
req.add(m_plane, "CRTC_ID", m_crtc->id());
req.add(m_plane, "FB_ID", fb->id());
@@ -237,7 +237,7 @@ void CameraPipeline::show_next_frame(AtomicReq& req)
else
v4l_mem = V4L2_MEMORY_DMABUF;
- struct v4l2_buffer v4l2buf = { };
+ struct v4l2_buffer v4l2buf = {};
v4l2buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
v4l2buf.memory = v4l_mem;
r = ioctl(m_fd, VIDIOC_DQBUF, &v4l2buf);
@@ -248,7 +248,7 @@ void CameraPipeline::show_next_frame(AtomicReq& req)
unsigned fb_index = v4l2buf.index;
- Framebuffer *fb = m_fb[fb_index];
+ Framebuffer* fb = m_fb[fb_index];
req.add(m_plane, "FB_ID", fb->id());
@@ -261,7 +261,6 @@ void CameraPipeline::show_next_frame(AtomicReq& req)
v4l2buf.m.fd = m_fb[m_prev_fb_index]->prime_fd(0);
r = ioctl(m_fd, VIDIOC_QBUF, &v4l2buf);
ASSERT(r == 0);
-
}
m_prev_fb_index = fb_index;
@@ -269,7 +268,7 @@ void CameraPipeline::show_next_frame(AtomicReq& req)
static bool is_capture_dev(int fd)
{
- struct v4l2_capability cap = { };
+ struct v4l2_capability cap = {};
int r = ioctl(fd, VIDIOC_QUERYCAP, &cap);
ASSERT(r == 0);
return cap.capabilities & V4L2_CAP_VIDEO_CAPTURE;
@@ -280,19 +279,18 @@ std::vector<std::string> glob(const std::string& pat)
glob_t glob_result;
glob(pat.c_str(), 0, NULL, &glob_result);
vector<string> ret;
- for(unsigned i = 0; i < glob_result.gl_pathc; ++i)
+ for (unsigned i = 0; i < glob_result.gl_pathc; ++i)
ret.push_back(string(glob_result.gl_pathv[i]));
globfree(&glob_result);
return ret;
}
static const char* usage_str =
- "Usage: kmscapture [OPTIONS]\n\n"
- "Options:\n"
- " -s, --single Single camera mode. Open only /dev/video0\n"
- " --buffer-type=<drm|v4l> Use DRM or V4L provided buffers. Default: DRM\n"
- " -h, --help Print this help\n"
- ;
+ "Usage: kmscapture [OPTIONS]\n\n"
+ "Options:\n"
+ " -s, --single Single camera mode. Open only /dev/video0\n"
+ " --buffer-type=<drm|v4l> Use DRM or V4L provided buffers. Default: DRM\n"
+ " -h, --help Print this help\n";
int main(int argc, char** argv)
{
@@ -300,12 +298,10 @@ int main(int argc, char** argv)
bool single_cam = false;
OptionSet optionset = {
- Option("s|single", [&]()
- {
+ Option("s|single", [&]() {
single_cam = true;
}),
- Option("|buffer-type=", [&](string s)
- {
+ Option("|buffer-type=", [&](string s) {
if (s == "v4l")
buffer_provider = BufferProvider::V4L2;
else if (s == "drm")
@@ -313,8 +309,7 @@ int main(int argc, char** argv)
else
FAIL("Invalid buffer provider: %s", s.c_str());
}),
- Option("h|help", [&]()
- {
+ Option("h|help", [&]() {
puts(usage_str);
exit(-1);
}),
@@ -334,7 +329,7 @@ int main(int argc, char** argv)
auto conn = card.get_first_connected_connector();
auto crtc = conn->get_current_crtc();
printf("Display: %dx%d\n", crtc->width(), crtc->height());
- printf("Buffer provider: %s\n", buffer_provider == BufferProvider::V4L2? "V4L" : "DRM");
+ printf("Buffer provider: %s\n", buffer_provider == BufferProvider::V4L2 ? "V4L" : "DRM");
vector<int> camera_fds;
@@ -389,10 +384,10 @@ int main(int argc, char** argv)
for (unsigned i = 0; i < nr_cameras; i++) {
fds[i].fd = cameras[i]->fd();
- fds[i].events = POLLIN;
+ fds[i].events = POLLIN;
}
fds[nr_cameras].fd = 0;
- fds[nr_cameras].events = POLLIN;
+ fds[nr_cameras].events = POLLIN;
for (auto cam : cameras)
cam->start_streaming();