Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 1 | #include <video.h> |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 2 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 3 | #include <iomanip> |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 4 | #include <iostream> |
| 5 | #include <chrono> |
| 6 | #include <thread> |
| 7 | #include <vector> |
| 8 | #include <fstream> |
| 9 | #include <fcntl.h> |
| 10 | #include <unistd.h> |
| 11 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 12 | |
| 13 | namespace AstVideo { |
| 14 | class VideoPuller { |
| 15 | public: |
| 16 | VideoPuller() {} |
| 17 | |
| 18 | void initialize() { |
| 19 | std::cout << "Opening /dev/video\n"; |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 20 | video_fd = open("/dev/video", O_RDWR); |
| 21 | if (!video_fd) { |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 22 | std::cout << "Failed to open /dev/video\n"; |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 23 | } else { |
| 24 | std::cout << "Opened successfully\n"; |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 25 | } |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 26 | |
| 27 | std::vector<unsigned char> buffer(1024 * 1024, 0); |
| 28 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 29 | IMAGE_INFO image_info{}; |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 30 | 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 Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 40 | |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 41 | 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 Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 48 | } |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 49 | */ |
| 50 | std::cout << "Write done\n"; |
| 51 | //std::this_thread::sleep_for(std::chrono::milliseconds(2000)); |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 52 | |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 53 | 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 Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 61 | auto pt = reinterpret_cast<char*>(&image_info); |
| 62 | |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 63 | 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 Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 66 | } |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 67 | 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 Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 78 | |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 79 | 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 Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 83 | std::cout << "\n"; |
| 84 | |
| 85 | std::cout << "typedef struct _video_features {\n"; |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 86 | 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 Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 100 | std::cout << "} FEATURES_TAG;\n"; |
| 101 | |
| 102 | std::cout << "typedef struct _image_info {"; |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 103 | std::cout << "short do_image_refresh;" << image_info.do_image_refresh |
| 104 | << "\n"; |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 105 | 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 Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 115 | |
| 116 | close(video_fd); |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 117 | } |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame^] | 118 | int video_fd; |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 119 | }; |
| 120 | } |
| 121 | |
| 122 | int main() { |
| 123 | AstVideo::VideoPuller p; |
| 124 | p.initialize(); |
| 125 | |
| 126 | return 1; |
| 127 | } |