blob: 50889c9bbedacd51ba8dc026135c4b1658cc114a [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;
Ed Tanous7d3dba42017-04-05 13:04:39 -070042
Ed Tanousb4d29f42017-03-24 16:39:25 -070043 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 Tanous7d3dba42017-04-05 13:04:39 -070049
Ed Tanousb4d29f42017-03-24 16:39:25 -070050 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 Tanous56795222017-04-06 13:27:25 -070067
Ed Tanous7d3dba42017-04-05 13:04:39 -070068 std::cout << "\nprinting buffer\n";
69
Ed Tanous56795222017-04-06 13:27:25 -070070 for(int i = 0; i < 512; i++){
Ed Tanousb4d29f42017-03-24 16:39:25 -070071 if (i % 16 == 0){
72 std::cout << "\n";
73 }
74 std::cout << std::hex << std::setfill('0') << std::setw(2)
75 << int(buffer[i]) << " ";
76 }
Ed Tanous7d3dba42017-04-05 13:04:39 -070077
Ed Tanousb4d29f42017-03-24 16:39:25 -070078 buffer.resize(image_info.len);
Ed Tanous1ccd57c2017-03-21 13:15:58 -070079
Ed Tanousb4d29f42017-03-24 16:39:25 -070080 std::ofstream f("/tmp/screen.jpg",std::ios::out | std::ios::binary);
81
82 f.write(reinterpret_cast<char*>(buffer.data()), buffer.size());
83
Ed Tanous1ccd57c2017-03-21 13:15:58 -070084 std::cout << "\n";
85
86 std::cout << "typedef struct _video_features {\n";
Ed Tanousb4d29f42017-03-24 16:39:25 -070087 std::cout << "short jpg_fmt: " << image_info.parameter.features.jpg_fmt
88 << "\n";
89 std::cout << "short lumin_tbl;" << image_info.parameter.features.lumin_tbl
90 << "\n";
91 std::cout << "short chrom_tbl;" << image_info.parameter.features.chrom_tbl
92 << "\n";
93 std::cout << "short tolerance_noise;"
94 << image_info.parameter.features.tolerance_noise << "\n";
95 std::cout << "int w; 0X" << image_info.parameter.features.w << "\n";
96 std::cout << "int h; 0X" << image_info.parameter.features.h << "\n";
97
98 std::cout << "void* buf; 0X" << static_cast<void*>(image_info.parameter.features.buf) << "\n";
99 // std::cout << "unsigned char *buf;" << image_info.parameter.features.buf
100 // << "\n";
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700101 std::cout << "} FEATURES_TAG;\n";
102
103 std::cout << "typedef struct _image_info {";
Ed Tanousb4d29f42017-03-24 16:39:25 -0700104 std::cout << "short do_image_refresh;" << image_info.do_image_refresh
105 << "\n";
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700106 std::cout << "char qc_valid;" << image_info.qc_valid << "\n";
107 std::cout << "unsigned int len;" << image_info.len << "\n";
108 std::cout << "int crypttype;" << image_info.crypttype << "\n";
109 std::cout << "char cryptkey[16];" << image_info.cryptkey << "\n";
110 std::cout << "union {\n";
111 std::cout << " FEATURES_TAG features;\n";
112 std::cout << " AST_CURSOR_TAG cursor_info;\n";
113 std::cout << "} parameter;\n";
114 std::cout << "} IMAGE_INFO;\n";
115 std::cout << std::endl;
Ed Tanousb4d29f42017-03-24 16:39:25 -0700116
117 close(video_fd);
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700118 }
Ed Tanousb4d29f42017-03-24 16:39:25 -0700119 int video_fd;
Ed Tanous1ccd57c2017-03-21 13:15:58 -0700120};
121}
122
123int main() {
124 AstVideo::VideoPuller p;
125 p.initialize();
126
127 return 1;
128}