-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathrpicam_hello.cpp
More file actions
72 lines (60 loc) · 1.62 KB
/
rpicam_hello.cpp
File metadata and controls
72 lines (60 loc) · 1.62 KB
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
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (C) 2020, Raspberry Pi (Trading) Ltd.
*
* rpicam_hello.cpp - libcamera "hello world" app.
*/
#include <chrono>
#include "core/options.hpp"
#include "core/rpicam_app.hpp"
using namespace std::placeholders;
// The main event loop for the application.
static void event_loop(RPiCamApp &app)
{
Options const *options = app.GetOptions();
app.OpenCamera();
app.ConfigureViewfinder();
app.StartCamera();
auto start_time = std::chrono::high_resolution_clock::now();
for (unsigned int count = 0;; count++)
{
RPiCamApp::Msg msg = app.Wait();
if (msg.type == RPiCamApp::MsgType::Timeout)
{
LOG_ERROR("ERROR: Device timeout detected, attempting a restart!!!");
app.StopCamera();
app.StartCamera();
continue;
}
if (msg.type == RPiCamApp::MsgType::Quit)
return;
else if (msg.type != RPiCamApp::MsgType::RequestComplete)
throw std::runtime_error("unrecognised message!");
LOG(2, "Viewfinder frame " << count);
auto now = std::chrono::high_resolution_clock::now();
if (options->Get().timeout && (now - start_time) > options->Get().timeout.value)
return;
CompletedRequestPtr &completed_request = std::get<CompletedRequestPtr>(msg.payload);
app.ShowPreview(completed_request, app.ViewfinderStream());
}
}
int main(int argc, char *argv[])
{
try
{
RPiCamApp app;
Options *options = app.GetOptions();
if (options->Parse(argc, argv))
{
if (options->Get().verbose >= 2)
options->Get().Print();
event_loop(app);
}
}
catch (std::exception const &e)
{
LOG_ERROR("ERROR: *** " << e.what() << " ***");
return -1;
}
return 0;
}