-
Notifications
You must be signed in to change notification settings - Fork 1
/
decode_video.hpp
89 lines (74 loc) · 2.21 KB
/
decode_video.hpp
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
86
87
88
#pragma once
#include <stdint.h>
#include <vector>
extern "C" // forward declare the ffmpeg pointer types
{
struct AVCodec;
struct AVCodecContext;
struct AVCodecParserContext;
struct AVFrame;
struct AVPacket;
struct SwsContext;
};
struct payload_t
{
uint8_t type;
uint8_t counter;
uint32_t value;
uint32_t timestamp;
uint32_t maybe_timestamp_high;
bool operator==(const payload_t& other)
{
return
this->type == other.type &&
this->counter == other.counter &&
this->value == other.value &&
this->timestamp == other.timestamp &&
this->maybe_timestamp_high == other.maybe_timestamp_high;
}
};
struct DroneDataInterface
{
virtual void add_video_frame(uint8_t* data, int y_stride, int width, int height) = 0;
virtual void add_telemetry_data(const payload_t& payload) = 0;
};
struct [[deprecated]] DroneDataBase : public DroneDataInterface
{
virtual void add_video_frame(uint8_t* data, int y_stride, int width, int height) = 0;
virtual void add_telemetry_data(const payload_t& payload)
{
switch (payload.type)
{
case 0xA1: telemetry_alti.emplace_back(payload); break;
case 0xA0: telemetry_batt.emplace_back(payload); break;
default: telemetry_other.emplace_back(payload); break;
}
}
std::vector<payload_t> telemetry_batt;
std::vector<payload_t> telemetry_alti;
std::vector<payload_t> telemetry_other;
};
struct VideoTelemetryParser
{
VideoTelemetryParser();
~VideoTelemetryParser();
void consume_data(const uint8_t* data, size_t data_size, DroneDataInterface* drone_data);
private:
int parse_telemetry(const uint8_t* data, size_t data_size, DroneDataInterface* drone_data, bool sync);
int parse_video(const uint8_t* data, size_t data_size, DroneDataInterface* drone_data);
// these are initialized in the constructor
const AVCodec* codec;
AVCodecParserContext* parser;
AVCodecContext* c;
AVFrame* frame;
AVFrame* rgbframe;
AVPacket *pkt;
// this can only be initialized when the frame size is known.
// initialization is deferred to the decode step.
SwsContext* sws_ctx = NULL;
uint32_t parse_state = 0xdeadbeef;
bool parser_suppress = false;
static constexpr size_t TELEMETRY_BUFFER_LENGTH = 45;
uint8_t telemetry_buffer[TELEMETRY_BUFFER_LENGTH];
size_t telemetry_buf_idx = 0;
};