Repository navigation
Expand file tree
/
Copy pathInferenceSession.h
More file actions
77 lines (59 loc) · 2.05 KB
/
Copy pathInferenceSession.h
File metadata and controls
77 lines (59 loc) · 2.05 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
73
74
75
76
77
/* Inference Session
*
* From: https://github.com/PokemonAutomation/
*
*/
#ifndef PokemonAutomation_CommonTools_InferenceSession_H
#define PokemonAutomation_CommonTools_InferenceSession_H
#include <chrono>
#include <vector>
#include <map>
#include <atomic>
#include "Common/Cpp/CancellableScope.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/InferenceCallbacks/InferenceCallback.h"
namespace PokemonAutomation{
class VideoStream;
//
// On construction, all the callbacks are attached to inference threads and
// begin running at their specified period.
//
// Upon destruction, all callbacks are removed from the inference threads and
// stop running.
//
// When a callback returns true or throws an exception, "scope.cancel()" will
// be called.
//
// "triggered_ptr()/triggered_index()" gives the first callback that
// returned true. If nothing has returned true, it is null or -1 respectively.
//
// Note that the callbacks will continue running even if one of them has
// returned true. So it is expected that the object will be destructed soon
// after "scope.cancel()" is called.
//
class InferenceSession : public Cancellable::CancelListener{
public:
InferenceSession(
Cancellable& scope, VideoStream& stream,
const std::vector<PeriodicInferenceCallback>& callbacks,
std::chrono::milliseconds default_video_period = std::chrono::milliseconds(50),
std::chrono::milliseconds default_audio_period = std::chrono::milliseconds(20)
);
~InferenceSession();
InferenceCallback* triggered_ptr() const;
int triggered_index() const;
private:
void clear() noexcept;
virtual void on_cancellable_cancel(
Cancellable& cancellable,
std::exception_ptr reason
) override;
private:
Cancellable& m_scope;
VideoStream& m_stream;
VideoOverlaySet m_overlays;
std::map<InferenceCallback*, size_t> m_map;
std::atomic<InferenceCallback*> m_triggered;
};
}
#endif