summaryrefslogtreecommitdiff
path: root/src/lib/grok_context.h
blob: a8a0d07299befcaedfb34a98ea4d46f61cbf1cb3 (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
117
118
119
120
121
122
123
/*
    Copyright (C) 2023 Grok Image Compression Inc.

    This file is part of DCP-o-matic.

    DCP-o-matic is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DCP-o-matic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.

*/


#pragma once


#include "config.h"
#include "dcp_video.h"
#include "dcpomatic_assert.h"
#include "dcpomatic_log.h"
#include "grok_messenger.h"
#include "log.h"
#include "writer.h"


class Film;


static std::mutex launchMutex;


namespace grk_plugin {


struct GrokLogger : public MessengerLogger
{
	explicit GrokLogger(const std::string& preamble);
	virtual ~GrokLogger() = default;

	void info(const char* fmt, ...) override;
	void warn(const char* fmt, ...) override;
	void error(const char* fmt, ...) override;
};


struct GrokInitializer
{
	GrokInitializer();
	~GrokInitializer() = default;
};


class FrameProxy
{
public:
	FrameProxy();
	FrameProxy(int index, Eyes eyes, DCPVideo dcpv);

	int index() const {
		return _index;
	}

	Eyes eyes() const {
		return _eyes;
	}

	DCPVideo const& vf() const {
		return _vf;
	}

private:
	int _index;
	Eyes _eyes;
	DCPVideo _vf;
};


struct DcpomaticContext
{
	DcpomaticContext(
		std::shared_ptr<const Film> film_,
		Writer& writer_,
		EventHistory& history_,
		const boost::optional<boost::filesystem::path>& location_
		);

	void set_dimensions(uint32_t w, uint32_t h);

	std::shared_ptr<const Film> film;
	Writer& writer;
	EventHistory& history;
	boost::optional<boost::filesystem::path> location;
	uint32_t width;
	uint32_t height;
};


class GrokContext
{
public:
	explicit GrokContext(const DcpomaticContext& dcpomaticContext);
	~GrokContext();

	bool launch(DCPVideo dcpv, int device);
	bool schedule_compress(const DCPVideo& vf);
	void shutdown();
	void frame_done();

private:
	DcpomaticContext _dcpomatic_context;
	ScheduledMessenger<FrameProxy>* _messenger;
	bool _launched;
};

} // namespace grk_plugin