srs-control
0.2.2
Toggle main menu visibility
Loading...
Searching...
No Matches
FrameCountChecker.cpp
Go to the documentation of this file.
1
#include "
FrameCountChecker.hpp
"
2
#include "
srs/converters/DataConvertOptions.hpp
"
3
#include "
srs/data/SRSDataStructs.hpp
"
4
#include "
srs/utils/CommonAlias.hpp
"
5
#include "
srs/workflow/BaseTask.hpp
"
6
#include <atomic>
7
#include <cstddef>
8
#include <cstdint>
9
#include <expected>
10
#include <fmt/base.h>
11
#include <zpp_bits.h>
12
13
namespace
srs::sink
14
{
15
FrameCountChecker::FrameCountChecker
(std::size_t n_lines)
16
:
SinkTask
{
"FrameCountChecker"
,
process
::
DataConvertOptions
::raw, n_lines }
17
{
18
}
19
20
auto
FrameCountChecker::extract_frame_counter
(
InputType
binary_data) ->
RunResult
21
{
22
23
auto
deserialize_to = zpp::bits::in{ binary_data, zpp::bits::endian::network{}, zpp::bits::no_size{} };
24
auto
read_bytes = binary_data.size() *
sizeof
(
BufferElementType
);
25
auto
header =
ReceiveDataHeader
{};
26
constexpr
auto
header_bytes =
sizeof
(header);
27
if
(read_bytes <= header_bytes)
28
{
29
return
std::unexpected{
"Deserialization: The size of the binary data is too small!"
};
30
}
31
auto
err = deserialize_to(header);
32
33
if
(zpp::bits::failure(err))
34
{
35
return
std::unexpected{
"FrameCountChecker failed to deserialize the header"
};
36
}
37
return
header.frame_counter;
38
}
39
40
void
FrameCountChecker::register_frame_counter
(int64_t frame_counter)
41
{
42
auto
last_value =
last_frame_counter_
.load();
43
while
(
true
)
44
{
45
auto
diff = frame_counter - last_value;
46
auto
insert_value = (diff > 0) ? frame_counter : last_value;
47
if
(
last_frame_counter_
.compare_exchange_weak(last_value, insert_value))
48
{
49
if
(diff > 1)
50
{
51
frame_drop_counter_
+= (diff - 1);
52
}
53
else
if
(diff < 0)
54
{
55
--
frame_drop_counter_
;
56
}
57
break
;
58
}
59
}
60
}
61
62
auto
FrameCountChecker::analyze_frame_counter
(
InputType
binary_data) ->
RunResult
63
{
64
auto
frame_counter =
extract_frame_counter
(binary_data);
65
66
if
(frame_counter)
67
{
68
register_frame_counter
(frame_counter.value());
69
}
70
71
return
frame_counter;
72
}
73
74
FrameCountChecker::~FrameCountChecker
() {}
75
}
// namespace srs::sink
BaseTask.hpp
CommonAlias.hpp
DataConvertOptions.hpp
FrameCountChecker.hpp
SRSDataStructs.hpp
DataConvertOptions
DataConvertOptions
Definition
DataConvertOptions.hpp:14
srs::process::BaseTask< std::string_view, int64_t >::InputType
std::string_view InputType
Definition
BaseTask.hpp:27
srs::process::BaseTask< std::string_view, int64_t >::RunResult
std::expected< OutputType, std::string_view > RunResult
Definition
BaseTask.hpp:32
srs::process::SinkTask< DataWriterOption::no_output, std::string_view, int64_t >::SinkTask
SinkTask(std::string_view name, DataConvertOptions prev_convert, std::size_t n_lines=1)
Definition
BaseTask.hpp:109
srs::sink::FrameCountChecker::extract_frame_counter
auto extract_frame_counter(InputType binary_data) -> RunResult
Definition
FrameCountChecker.cpp:20
srs::sink::FrameCountChecker::~FrameCountChecker
~FrameCountChecker()
Definition
FrameCountChecker.cpp:74
srs::sink::FrameCountChecker::analyze_frame_counter
auto analyze_frame_counter(InputType binary_data) -> RunResult
Definition
FrameCountChecker.cpp:62
srs::sink::FrameCountChecker::frame_drop_counter_
std::atomic< int64_t > frame_drop_counter_
Definition
FrameCountChecker.hpp:40
srs::sink::FrameCountChecker::last_frame_counter_
std::atomic< int64_t > last_frame_counter_
Definition
FrameCountChecker.hpp:39
srs::sink::FrameCountChecker::register_frame_counter
void register_frame_counter(int64_t frame_counter)
Definition
FrameCountChecker.cpp:40
srs::sink::FrameCountChecker::FrameCountChecker
FrameCountChecker(std::size_t n_lines)
Definition
FrameCountChecker.cpp:15
srs::process
Definition
ConverterConcepts.hpp:6
srs::sink
Definition
BinaryFileWriter.cpp:16
srs::BufferElementType
char BufferElementType
Definition
CommonAlias.hpp:15
srs::ReceiveDataHeader
Definition
SRSDataStructs.hpp:15
backend
srs
sinks
FrameCountChecker.cpp
Impressum
Datenschutzerklärung
Generated by
1.17.0