Repository navigation
Expand file tree
/
Copy pathObs_NumberHelper.cpp
More file actions
85 lines (64 loc) · 2.25 KB
/
Copy pathObs_NumberHelper.cpp
File metadata and controls
85 lines (64 loc) · 2.25 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
78
79
80
81
82
83
84
85
/*
obs-websocket
Copyright (C) 2016-2021 Stephane Lepin <[email protected]>
Copyright (C) 2020-2021 Kyle Manning <[email protected]>
This program 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.
This program 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 this program. If not, see <https://www.gnu.org/licenses/>
*/
#include <stdint.h>
#include <util/util_uint64.h>
#include "Obs.h"
#include "plugin-macros.generated.h"
uint64_t Utils::Obs::NumberHelper::GetOutputDuration(obs_output_t *output)
{
if (!output || !obs_output_active(output))
return 0;
video_t *video = obs_output_video(output);
uint64_t frameTimeNs = video_output_get_frame_time(video);
int totalFrames = obs_output_get_total_frames(output);
return util_mul_div64(totalFrames, frameTimeNs, 1000000ULL);
}
size_t Utils::Obs::NumberHelper::GetSceneCount()
{
OBSCanvasAutoRelease canvas = obs_get_main_canvas();
return GetCanvasSceneCount(canvas);
}
size_t Utils::Obs::NumberHelper::GetCanvasSceneCount(obs_canvas_t *canvas)
{
size_t ret = 0;
auto sceneEnumProc = [](void *param, obs_source_t *scene) {
auto ret = static_cast<size_t *>(param);
if (obs_source_is_group(scene))
return true;
(*ret)++;
return true;
};
obs_canvas_enum_scenes(canvas, sceneEnumProc, &ret);
return ret;
}
size_t Utils::Obs::NumberHelper::GetSourceFilterIndex(obs_source_t *source, obs_source_t *filter)
{
struct FilterSearch {
obs_source_t *filter;
bool found;
size_t index;
};
auto search = [](obs_source_t *, obs_source_t *filter, void *priv_data) {
auto filterSearch = static_cast<FilterSearch *>(priv_data);
if (filter == filterSearch->filter)
filterSearch->found = true;
if (!filterSearch->found)
filterSearch->index++;
};
FilterSearch filterSearch = {filter, 0, 0};
obs_source_enum_filters(source, search, &filterSearch);
return filterSearch.index;
}