-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecode_streamdump_main.cpp
64 lines (48 loc) · 1.12 KB
/
decode_streamdump_main.cpp
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
#include <stdio.h>
#include <string.h>
#include <fstream>
#include "decode_video.hpp"
struct DummyDroneData : public DroneDataInterface
{
virtual void add_video_frame(uint8_t* data, int y_stride, int width, int height)
{
FILE *pFile;
char szFilename[32];
int y;
// Open file
sprintf(szFilename, "frame%d.ppm", frame_count);
pFile=fopen(szFilename, "wb");
if(pFile==NULL)
return;
// Write header
fprintf(pFile, "P6\n%d %d\n255\n", width, height);
// Write pixel data
for(y=0; y<height; y++)
fwrite(data+y*y_stride, 1, width*3, pFile);
// Close file
fclose(pFile);
frame_count++;
}
virtual void add_telemetry_data(const payload_t& payload) {}
int frame_count = 0;
};
int main(int argc, const char** argv)
{
using std::ifstream;
constexpr int BUFSIZE = 1024;
uint8_t buf[BUFSIZE];
if (argc != 2)
{
printf("Usage: %s infile\n", argv[0]);
exit(1);
}
VideoTelemetryParser parser;
DummyDroneData dd;
ifstream f(argv[1], std::ios::binary);
while (f.good())
{
f.read(reinterpret_cast<char*>(buf), BUFSIZE);
size_t n_read = f.gcount();
parser.consume_data(buf, n_read, &dd);
}
}