-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease_embedded.cpp
More file actions
92 lines (74 loc) · 2.92 KB
/
Copy pathrelease_embedded.cpp
File metadata and controls
92 lines (74 loc) · 2.92 KB
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
89
90
91
92
#include <QApplication>
#include <QWidget>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <stdexcept>
#include <utility>
#include <vector>
#include "frame_player_widget.hpp"
#include "generated/embedded_video_cache.hpp"
namespace {
using Rectangle = VIDEO::FramePlayerWidget::Rectangle;
using Frame = VIDEO::FramePlayerWidget::Frame;
std::int32_t readInt32LE(const unsigned char *data, std::size_t size, std::size_t &offset) {
if (offset + 4 > size) {
throw std::runtime_error("unexpected end of embedded cache data");
}
const std::uint32_t value =
static_cast<std::uint32_t>(data[offset]) |
(static_cast<std::uint32_t>(data[offset + 1]) << 8) |
(static_cast<std::uint32_t>(data[offset + 2]) << 16) |
(static_cast<std::uint32_t>(data[offset + 3]) << 24);
offset += 4;
return static_cast<std::int32_t>(value);
}
std::vector<Frame> parseFrames() {
std::vector<Frame> frames;
std::size_t offset = 0;
while (offset < BAD_APPLE_EMBEDDED::kVideoCacheSize) {
const int rectangleCount = readInt32LE(
BAD_APPLE_EMBEDDED::kVideoCache,
BAD_APPLE_EMBEDDED::kVideoCacheSize,
offset
);
if (rectangleCount < 0) {
throw std::runtime_error("embedded cache contains a negative rectangle count");
}
Frame frame;
frame.reserve(static_cast<std::size_t>(rectangleCount));
for (int i = 0; i < rectangleCount; ++i) {
const int row = readInt32LE(BAD_APPLE_EMBEDDED::kVideoCache, BAD_APPLE_EMBEDDED::kVideoCacheSize, offset);
const int col = readInt32LE(BAD_APPLE_EMBEDDED::kVideoCache, BAD_APPLE_EMBEDDED::kVideoCacheSize, offset);
const int height = readInt32LE(BAD_APPLE_EMBEDDED::kVideoCache, BAD_APPLE_EMBEDDED::kVideoCacheSize, offset);
const int width = readInt32LE(BAD_APPLE_EMBEDDED::kVideoCache, BAD_APPLE_EMBEDDED::kVideoCacheSize, offset);
frame.push_back({{row, col}, {height, width}});
}
frames.push_back(std::move(frame));
}
return frames;
}
int frameDelayMs() {
return std::max(1, static_cast<int>(1000.0 / std::max(BAD_APPLE_EMBEDDED::kVideoFps, 1.0)));
}
}
int main(int argc, char *argv[]) {
#ifdef __linux__
qputenv("QT_QPA_PLATFORM", "xcb");
#endif
QApplication app(argc, argv);
try {
auto *player = new VIDEO::FramePlayerWidget(
parseFrames(),
QSize(BAD_APPLE_EMBEDDED::kVideoWidth, BAD_APPLE_EMBEDDED::kVideoHeight),
frameDelayMs()
);
player->setAttribute(Qt::WA_DeleteOnClose);
player->start();
} catch (const std::exception &ex) {
std::cerr << ex.what() << '\n';
return 1;
}
return app.exec();
}