CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Recorder
CarlaRecorderFrames.cpp
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#include "
CarlaRecorderFrames.h
"
8
#include "
CarlaRecorder.h
"
9
#include "
CarlaRecorderHelpers.h
"
10
11
void
CarlaRecorderFrame::Read
(std::istream &InFile)
12
{
13
ReadValue<CarlaRecorderFrame>
(InFile, *
this
);
14
}
15
16
void
CarlaRecorderFrame::Write
(std::ostream &OutFile)
17
{
18
WriteValue<CarlaRecorderFrame>
(OutFile, *
this
);
19
}
20
21
// ---------------------------------------------
22
23
CarlaRecorderFrames::CarlaRecorderFrames
(
void
)
24
{
25
Reset
();
26
}
27
28
void
CarlaRecorderFrames::Reset
(
void
)
29
{
30
Frame
.
Id
= 0;
31
Frame
.
DurationThis
= 0.0f;
32
Frame
.
Elapsed
= 0.0f;
33
OffsetPreviousFrame
= 0;
34
}
35
36
void
CarlaRecorderFrames::SetFrame
(
double
DeltaSeconds)
37
{
38
if
(
Frame
.
Id
== 0)
39
{
40
Frame
.
Elapsed
= 0.0f;
41
Frame
.
DurationThis
= 0.0f;
42
}
43
else
44
{
45
Frame
.
DurationThis
= DeltaSeconds;
46
Frame
.
Elapsed
+= DeltaSeconds;
47
}
48
49
++
Frame
.
Id
;
50
}
51
52
void
CarlaRecorderFrames::WriteStart
(std::ostream &OutFile)
53
{
54
std::streampos Pos, Offset;
55
double
Dummy = -1.0f;
56
57
// write the packet id
58
WriteValue<char>
(OutFile,
static_cast<
char
>
(
CarlaRecorderPacketId::FrameStart
));
59
60
// write the packet size
61
uint32_t Total =
sizeof
(
CarlaRecorderFrame
);
62
WriteValue<uint32_t>
(OutFile, Total);
63
64
// write frame record
65
WriteValue<uint64_t>
(OutFile,
Frame
.
Id
);
66
Offset = OutFile.tellp();
67
WriteValue<double>
(OutFile, Dummy);
68
WriteValue<double>
(OutFile,
Frame
.
Elapsed
);
69
70
// we need to write this duration to previous frame
71
if
(
OffsetPreviousFrame
> 0)
72
{
73
Pos = OutFile.tellp();
74
OutFile.seekp(
OffsetPreviousFrame
, std::ios::beg);
75
WriteValue<double>
(OutFile,
Frame
.
DurationThis
);
76
OutFile.seekp(Pos, std::ios::beg);
77
}
78
79
// save position for next actualization
80
OffsetPreviousFrame
= Offset;
81
}
82
83
void
CarlaRecorderFrames::WriteEnd
(std::ostream &OutFile)
84
{
85
// write the packet id
86
WriteValue<char>
(OutFile,
static_cast<
char
>
(
CarlaRecorderPacketId::FrameEnd
));
87
88
// write the packet size (0)
89
uint32_t Total = 0;
90
WriteValue<uint32_t>
(OutFile, Total);
91
}
CarlaRecorderFrames.h
CarlaRecorderHelpers.h
WriteValue
void WriteValue(std::ostream &OutFile, const T &InObj)
Definition
CarlaRecorderHelpers.h:21
ReadValue
void ReadValue(std::istream &InFile, T &OutObj)
Definition
CarlaRecorderHelpers.h:60
CarlaRecorder.h
CarlaRecorderPacketId::FrameStart
@ FrameStart
Definition
CarlaRecorder.h:51
CarlaRecorderPacketId::FrameEnd
@ FrameEnd
Definition
CarlaRecorder.h:52
CarlaRecorderFrames::Reset
void Reset()
Definition
CarlaRecorderFrames.cpp:28
CarlaRecorderFrames::SetFrame
void SetFrame(double DeltaSeconds)
Definition
CarlaRecorderFrames.cpp:36
CarlaRecorderFrames::WriteEnd
void WriteEnd(std::ostream &OutFile)
Definition
CarlaRecorderFrames.cpp:83
CarlaRecorderFrames::WriteStart
void WriteStart(std::ostream &OutFile)
Definition
CarlaRecorderFrames.cpp:52
CarlaRecorderFrames::OffsetPreviousFrame
std::streampos OffsetPreviousFrame
Definition
CarlaRecorderFrames.h:41
CarlaRecorderFrames::Frame
CarlaRecorderFrame Frame
Definition
CarlaRecorderFrames.h:40
CarlaRecorderFrames::CarlaRecorderFrames
CarlaRecorderFrames(void)
Definition
CarlaRecorderFrames.cpp:23
CarlaRecorderFrame
Definition
CarlaRecorderFrames.h:13
CarlaRecorderFrame::Elapsed
double Elapsed
Definition
CarlaRecorderFrames.h:16
CarlaRecorderFrame::DurationThis
double DurationThis
Definition
CarlaRecorderFrames.h:15
CarlaRecorderFrame::Id
uint64_t Id
Definition
CarlaRecorderFrames.h:14
CarlaRecorderFrame::Write
void Write(std::ostream &OutFile)
Definition
CarlaRecorderFrames.cpp:16
CarlaRecorderFrame::Read
void Read(std::istream &InFile)
Definition
CarlaRecorderFrames.cpp:11
Generated by
1.18.0