Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 3 | #include <assert.h> |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 4 | #include <video.h> |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame^] | 5 | #include <ast_video_types.hpp> |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 6 | #include <iostream> |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame^] | 7 | #include <vector> |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 8 | |
| 9 | namespace AstVideo { |
| 10 | class VideoPuller { |
| 11 | public: |
| 12 | VideoPuller() : image_info(){}; |
| 13 | |
| 14 | void initialize() { |
| 15 | std::cout << "Opening /dev/video\n"; |
| 16 | video_fd = open("/dev/video", O_RDWR); |
| 17 | if (!video_fd) { |
| 18 | std::cout << "Failed to open /dev/video\n"; |
| 19 | // TODO(Ed) throw exception? |
| 20 | } else { |
| 21 | std::cout << "Opened successfully\n"; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | RawVideoBuffer read_video() { |
| 26 | assert(video_fd != 0); |
| 27 | RawVideoBuffer raw; |
| 28 | |
| 29 | IMAGE_INFO image_info{}; |
| 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 = 0; |
| 33 | image_info.parameter.features.h = 0; |
| 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 = |
| 38 | reinterpret_cast<unsigned char *>(raw.buffer.data()); |
| 39 | image_info.crypttype = -1; |
| 40 | std::cout << "Writing\n"; |
| 41 | |
| 42 | int status; |
| 43 | /* |
| 44 | status = write(video_fd, reinterpret_cast<char*>(&image_info), |
| 45 | sizeof(image_info)); |
| 46 | if (status != sizeof(image_info)) { |
| 47 | std::cout << "Write failed. Return: " << status << "\n"; |
| 48 | perror("perror output:"); |
| 49 | } |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame^] | 50 | |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 51 | std::cout << "Write done\n"; |
| 52 | */ |
| 53 | std::cout << "Reading\n"; |
| 54 | status = read(video_fd, reinterpret_cast<char *>(&image_info), |
| 55 | sizeof(image_info)); |
| 56 | std::cout << "Reading\n"; |
| 57 | |
| 58 | if (status != 0) { |
| 59 | std::cout << "Read failed with status " << status << "\n"; |
| 60 | } |
| 61 | |
| 62 | raw.buffer.resize(image_info.len); |
| 63 | |
| 64 | raw.height = image_info.parameter.features.h; |
| 65 | raw.width = image_info.parameter.features.w; |
| 66 | if (image_info.parameter.features.jpg_fmt == 422) { |
| 67 | raw.mode = YuvMode::YUV420; |
| 68 | } else { |
| 69 | raw.mode = YuvMode::YUV444; |
| 70 | } |
| 71 | return raw; |
| 72 | } |
| 73 | |
| 74 | private: |
| 75 | int video_fd; |
| 76 | IMAGE_INFO image_info; |
| 77 | }; |
| 78 | } |