blob: 2259b8c8bc3644cf9a774511dafd8a1f4d9e3387 [file] [log] [blame]
Ed Tanous1ccd57c2017-03-21 13:15:58 -07001#include <video.h>
Ed Tanousb4d29f42017-03-24 16:39:25 -07002
Ed Tanous1ccd57c2017-03-21 13:15:58 -07003#include <iomanip>
Ed Tanousb4d29f42017-03-24 16:39:25 -07004#include <iostream>
5#include <chrono>
6#include <thread>
7#include <vector>
8#include <fstream>
9#include <fcntl.h>
10#include <unistd.h>
11
Ed Tanous1ccd57c2017-03-21 13:15:58 -070012
13namespace AstVideo {
14class VideoPuller {
15 public:
16 VideoPuller() {}
17
18 void initialize() {
19 std::cout << "Opening /dev/video\n";
Ed Tanousb4d29f42017-03-24 16:39:25 -070020 video_fd = open("/dev/video", O_RDWR);
21 if (!video_fd) {
Ed Tanous1ccd57c2017-03-21 13:15:58 -070022 std::cout << "Failed to open /dev/video\n";
Ed Tanousb4d29f42017-03-24 16:39:25 -070023 } else {
24 std::cout << "Opened successfully\n";
Ed Tanous1ccd57c2017-03-21 13:15:58 -070025 }
Ed Tanousb4d29f42017-03-24 16:39:25 -070026
27 std::vector<unsigned char> buffer(1024 * 1024, 0);
28
Ed Tanous1ccd57c2017-03-21 13:15:58 -070029 IMAGE_INFO image_info{};
Ed Tanousb4d29f42017-03-24 16:39:25 -070030 image_info.do_image_refresh = 1; // full frame refresh
31 image_info.qc_valid = 0; // quick cursor disabled
32 image_info.parameter.features.w = 800;
33 image_info.parameter.features.h = 600;
34 image_info.parameter.features.chrom_tbl = 0; // level
35 image_info.parameter.features.lumin_tbl = 0;
36 image_info.parameter.features.jpg_fmt = 1;
37 image_info.parameter.features.buf = buffer.data();
38 image_info.crypttype = -1;
39 std::cout << "Writing\n";
Ed Tanous1ccd57c2017-03-21 13:15:58 -070040
Ed Tanousb4d29f42017-03-24 16:39:25 -070041 int status;
42 /*
43 status = write(video_fd, reinterpret_cast<char*>(&image_info),
44 sizeof(image_info));
45 if (status != 0) {
46 std::cout << "Write failed. Return: " << status <<"\n";
47 perror("perror output:");
Ed Tanous1ccd57c2017-03-21 13:15:58 -070048 }
Ed Tanousb4d29f42017-03-24 16:39:25 -070049 */
50 std::cout << "Write done\n";
51 //std::this_thread::sleep_for(std::chrono::milliseconds(2000));
Ed Tanous1ccd57c2017-03-21 13:15:58 -070052
Ed Tanousb4d29f42017-03-24 16:39:25 -070053 std::cout << "Reading\n";
54 status = read(video_fd, reinterpret_cast<char*>(&image_info), sizeof(image_info));
55 std::cout << "Reading\n";
56
57 if (status != 0) {
58 std::cout << "Read failed with status " << status << "\n";
59 }
60
Ed Tanous1ccd57c2017-03-21 13:15:58 -070061 auto pt = reinterpret_cast<char*>(&image_info);
62
Ed Tanousb4d29f42017-03-24 16:39:25 -070063 for (int i = 0; i < sizeof(image_info); i++) {
64 std::cout << std::hex << std::setfill('0') << std::setw(2)
65 << int(*(pt + i)) << " ";
Ed Tanous1ccd57c2017-03-21 13:15:58 -070066 }
Ed Tanousb4d29f42017-03-24 16:39:25 -070067 std::cout << "\n";
68 /*
69 for(int i = 0; i < 1024; i++){
70 if (i % 16 == 0){
71 std::cout << "\n";
72 }
73 std::cout << std::hex << std::setfill('0') << std::setw(2)
74 << int(buffer[i]) << " ";
75 }
76 */
77 buffer.resize(image_info.len);
Ed Tanous1ccd57c2017-03-21 13:15:58 -070078
Ed Tanousb4d29f42017-03-24 16:39:25 -070079 std::ofstream f("/tmp/screen.jpg",std::ios::out | std::ios::binary);
80
81 f.write(reinterpret_cast<char*>(buffer.data()), buffer.size());
82
Ed Tanous1ccd57c2017-03-21 13:15:58 -070083 std::cout << "\n";
84
85 std::cout << "typedef struct _video_features {\n";
Ed Tanousb4d29f42017-03-24 16:39:25 -070086 std::cout << "short jpg_fmt: " << image_info.parameter.features.jpg_fmt
87 << "\n";
88 std::cout << "short lumin_tbl;" << image_info.parameter.features.lumin_tbl
89 << "\n";
90 std::cout << "short chrom_tbl;" << image_info.parameter.features.chrom_tbl
91 << "\n";
92 std::cout << "short tolerance_noise;"
93 << image_info.parameter.features.tolerance_noise << "\n";
94 std::cout << "int w; 0X" << image_info.parameter.features.w << "\n";
95 std::cout << "int h; 0X" << image_info.parameter.features.h << "\n";
96
97 std::cout << "void* buf; 0X" << static_cast<void*>(image_info.parameter.features.buf) << "\n";
98 // std::cout << "unsigned char *buf;" << image_info.parameter.features.buf
99 // << "\n";
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700100 std::cout << "} FEATURES_TAG;\n";
101
102 std::cout << "typedef struct _image_info {";
Ed Tanousb4d29f42017-03-24 16:39:25 -0700103 std::cout << "short do_image_refresh;" << image_info.do_image_refresh
104 << "\n";
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700105 std::cout << "char qc_valid;" << image_info.qc_valid << "\n";
106 std::cout << "unsigned int len;" << image_info.len << "\n";
107 std::cout << "int crypttype;" << image_info.crypttype << "\n";
108 std::cout << "char cryptkey[16];" << image_info.cryptkey << "\n";
109 std::cout << "union {\n";
110 std::cout << " FEATURES_TAG features;\n";
111 std::cout << " AST_CURSOR_TAG cursor_info;\n";
112 std::cout << "} parameter;\n";
113 std::cout << "} IMAGE_INFO;\n";
114 std::cout << std::endl;
Ed Tanousb4d29f42017-03-24 16:39:25 -0700115
116 close(video_fd);
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700117 }
Ed Tanousb4d29f42017-03-24 16:39:25 -0700118 int video_fd;
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700119};
120}
121
122int main() {
123 AstVideo::VideoPuller p;
124 p.initialize();
125
126 return 1;
127}