-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathPacketLogger.h
58 lines (45 loc) · 1.01 KB
/
PacketLogger.h
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
#pragma once
#include "concurrency/MpmcQueue.h"
#include <thread>
namespace memory
{
class Packet;
}
namespace logger
{
struct PacketLogItem
{
PacketLogItem();
PacketLogItem(const memory::Packet& packet, uint64_t receiveTime);
uint64_t receiveTimestamp;
uint32_t transmitTimestamp; // 24 bit
uint32_t ssrc;
uint16_t sequenceNumber;
uint16_t size;
};
class PacketLoggerThread
{
public:
PacketLoggerThread(FILE* logFile, size_t backlogSize);
~PacketLoggerThread();
void post(const memory::Packet& item, uint64_t receiveTime);
void stop();
private:
void run();
std::atomic_bool _running;
concurrency::MpmcQueue<PacketLogItem> _logQueue;
FILE* _logFile;
std::unique_ptr<std::thread> _thread;
};
class PacketLogReader
{
public:
explicit PacketLogReader(FILE* logFile);
~PacketLogReader();
bool getNext(PacketLogItem& item);
void rewind();
bool isOpen() const { return _logFile != nullptr; }
private:
FILE* _logFile;
};
} // namespace logger