summaryrefslogtreecommitdiffhomepage
path: root/video-ps3eye/module.hpp
blob: 955463d6e4930d214ff893ebd065c8f9f562bc96 (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
#pragma once

#include "video/camera.hpp"
#include "shm-layout.hpp"
#include "compat/shm.h"
#include "options/options.hpp"
#include "compat/macros1.h"
#include "compat/timer.hpp"
#include "ui_dialog.h"

#include <QProcess>
#include <QTimer>

using namespace options;

using video::impl::camera;
using video::impl::camera_;
using video::frame;

struct settings final
{
    bundle b = make_bundle("video-ps3eye");
    shm_wrapper shm { "ps3eye-driver-shm", nullptr, sizeof(ps3eye::shm) };

    value<slider_value> exposure{b, "exposure", {255, 0, 255}};
    value<slider_value> gain{b, "gain", {30, 0, 63}};

    void set_exposure();
    void set_gain();
    void apply();
};

class dialog final : public QWidget
{
    Q_OBJECT
    Ui_Dialog ui;
    settings s;

    QTimer t;

    shm_wrapper shm { "ps3eye-driver-shm", nullptr, sizeof(ps3eye::shm) };

    void do_ok() { s.b->save(); s.apply(); close(); }
    void do_cancel() { s.b->reload(); s.apply(); close(); }

protected:
    void closeEvent(QCloseEvent*) override { do_cancel(); deleteLater(); }

public:
    explicit dialog(QWidget* parent = nullptr);
};

struct ps3eye_camera final : video::impl::camera
{
    QProcess wrapper;
    shm_wrapper shm { "ps3eye-driver-shm", nullptr, sizeof(ps3eye::shm) };
    settings s;
    frame fr;
    Timer t;
    unsigned char data[640 * 480 * 3] = {};
    int framerate = 30, sleep_ms = 1;
    bool open = false;
    unsigned timecode = 0;

    ps3eye_camera();
    ~ps3eye_camera() override;

    bool start(info& args) override;
    void stop() override;
    bool is_open() override { return open; }

    std::tuple<const frame&, bool> get_frame() override;
    [[nodiscard]] bool show_dialog() override;
};

struct ps3eye_camera_ final : video::impl::camera_
{
    std::vector<QString> camera_names() const override;
    std::unique_ptr<camera> make_camera(const QString& name) override;
    bool show_dialog(const QString& camera_name) override;
    bool can_show_dialog(const QString& camera_name) override;
};