blob: 50889c9bbedacd51ba8dc026135c4b1658cc114a (
plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
#include <video.h>
#include <iomanip>
#include <iostream>
#include <chrono>
#include <thread>
#include <vector>
#include <fstream>
#include <fcntl.h>
#include <unistd.h>
namespace AstVideo {
class VideoPuller {
public:
VideoPuller() {}
void initialize() {
std::cout << "Opening /dev/video\n";
video_fd = open("/dev/video", O_RDWR);
if (!video_fd) {
std::cout << "Failed to open /dev/video\n";
} else {
std::cout << "Opened successfully\n";
}
std::vector<unsigned char> buffer(1024 * 1024, 0);
IMAGE_INFO image_info{};
image_info.do_image_refresh = 1; // full frame refresh
image_info.qc_valid = 0; // quick cursor disabled
image_info.parameter.features.w = 800;
image_info.parameter.features.h = 600;
image_info.parameter.features.chrom_tbl = 0; // level
image_info.parameter.features.lumin_tbl = 0;
image_info.parameter.features.jpg_fmt = 1;
image_info.parameter.features.buf = buffer.data();
image_info.crypttype = -1;
std::cout << "Writing\n";
int status;
status = write(video_fd, reinterpret_cast<char*>(&image_info),
sizeof(image_info));
if (status != 0) {
std::cout << "Write failed. Return: " << status <<"\n";
perror("perror output:");
}
std::cout << "Write done\n";
//std::this_thread::sleep_for(std::chrono::milliseconds(2000));
std::cout << "Reading\n";
status = read(video_fd, reinterpret_cast<char*>(&image_info), sizeof(image_info));
std::cout << "Reading\n";
if (status != 0) {
std::cout << "Read failed with status " << status << "\n";
}
auto pt = reinterpret_cast<char*>(&image_info);
for (int i = 0; i < sizeof(image_info); i++) {
std::cout << std::hex << std::setfill('0') << std::setw(2)
<< int(*(pt + i)) << " ";
}
std::cout << "\nprinting buffer\n";
for(int i = 0; i < 512; i++){
if (i % 16 == 0){
std::cout << "\n";
}
std::cout << std::hex << std::setfill('0') << std::setw(2)
<< int(buffer[i]) << " ";
}
buffer.resize(image_info.len);
std::ofstream f("/tmp/screen.jpg",std::ios::out | std::ios::binary);
f.write(reinterpret_cast<char*>(buffer.data()), buffer.size());
std::cout << "\n";
std::cout << "typedef struct _video_features {\n";
std::cout << "short jpg_fmt: " << image_info.parameter.features.jpg_fmt
<< "\n";
std::cout << "short lumin_tbl;" << image_info.parameter.features.lumin_tbl
<< "\n";
std::cout << "short chrom_tbl;" << image_info.parameter.features.chrom_tbl
<< "\n";
std::cout << "short tolerance_noise;"
<< image_info.parameter.features.tolerance_noise << "\n";
std::cout << "int w; 0X" << image_info.parameter.features.w << "\n";
std::cout << "int h; 0X" << image_info.parameter.features.h << "\n";
std::cout << "void* buf; 0X" << static_cast<void*>(image_info.parameter.features.buf) << "\n";
// std::cout << "unsigned char *buf;" << image_info.parameter.features.buf
// << "\n";
std::cout << "} FEATURES_TAG;\n";
std::cout << "typedef struct _image_info {";
std::cout << "short do_image_refresh;" << image_info.do_image_refresh
<< "\n";
std::cout << "char qc_valid;" << image_info.qc_valid << "\n";
std::cout << "unsigned int len;" << image_info.len << "\n";
std::cout << "int crypttype;" << image_info.crypttype << "\n";
std::cout << "char cryptkey[16];" << image_info.cryptkey << "\n";
std::cout << "union {\n";
std::cout << " FEATURES_TAG features;\n";
std::cout << " AST_CURSOR_TAG cursor_info;\n";
std::cout << "} parameter;\n";
std::cout << "} IMAGE_INFO;\n";
std::cout << std::endl;
close(video_fd);
}
int video_fd;
};
}
int main() {
AstVideo::VideoPuller p;
p.initialize();
return 1;
}
|