blob: de75fdf407356080ddf7307fe17a64f9fefbe071 [file] [log] [blame]
Ed Tanous93f987d2017-04-17 17:52:36 -07001#pragma once
2
Ed Tanous93f987d2017-04-17 17:52:36 -07003#include <assert.h>
Ed Tanousd5f39992017-04-18 13:41:22 -07004//#include <video.h>
Ed Tanous1ff48782017-04-18 12:45:08 -07005#include <ast_video_types.hpp>
Ed Tanous93f987d2017-04-17 17:52:36 -07006#include <iostream>
Ed Tanous1ff48782017-04-18 12:45:08 -07007#include <vector>
Ed Tanous93f987d2017-04-17 17:52:36 -07008
9namespace AstVideo {
10class VideoPuller {
Ed Tanousd5f39992017-04-18 13:41:22 -070011 //
12 // Cursor struct is used in User Mode
13 //
14 typedef struct _cursor_attribution_tag {
15 unsigned int posX;
16 unsigned int posY;
17 unsigned int cur_width;
18 unsigned int cur_height;
19 unsigned int cur_type; // 0:mono 1:color 2:disappear cursor
20 unsigned int cur_change_flag;
21 } AST_CUR_ATTRIBUTION_TAG;
22
23 //
24 // For storing Cursor Information
25 //
26 typedef struct _cursor_tag {
27 AST_CUR_ATTRIBUTION_TAG attr;
28 // unsigned char icon[MAX_CUR_OFFSETX*MAX_CUR_OFFSETY*2];
29 unsigned char *icon; //[64*64*2];
30 } AST_CURSOR_TAG;
31
32 //
33 // For select image format, i.e. 422 JPG420, 444 JPG444, lumin/chrom table, 0
34 // ~ 11, low to high
35 //
36 typedef struct _video_features {
37 short jpg_fmt; // 422:JPG420, 444:JPG444
38 short lumin_tbl;
39 short chrom_tbl;
40 short tolerance_noise;
41 int w;
42 int h;
43 unsigned char *buf;
44 } FEATURES_TAG;
45
46 //
47 // For configure video engine control registers
48 //
49 typedef struct _image_info {
50 short do_image_refresh; // Action 0:motion 1:fullframe 2:quick cursor
51 char qc_valid; // quick cursor enable/disable
52 unsigned int len;
53 int crypttype;
54 char cryptkey[16];
55 union {
56 FEATURES_TAG features;
57 AST_CURSOR_TAG cursor_info;
58 } parameter;
59 } IMAGE_INFO;
60
Ed Tanous93f987d2017-04-17 17:52:36 -070061 public:
62 VideoPuller() : image_info(){};
63
64 void initialize() {
65 std::cout << "Opening /dev/video\n";
66 video_fd = open("/dev/video", O_RDWR);
67 if (!video_fd) {
68 std::cout << "Failed to open /dev/video\n";
69 // TODO(Ed) throw exception?
70 } else {
71 std::cout << "Opened successfully\n";
72 }
73 }
74
75 RawVideoBuffer read_video() {
76 assert(video_fd != 0);
77 RawVideoBuffer raw;
78
Ed Tanous93f987d2017-04-17 17:52:36 -070079 image_info.do_image_refresh = 1; // full frame refresh
80 image_info.qc_valid = 0; // quick cursor disabled
81 image_info.parameter.features.w = 0;
82 image_info.parameter.features.h = 0;
83 image_info.parameter.features.chrom_tbl = 0; // level
84 image_info.parameter.features.lumin_tbl = 0;
85 image_info.parameter.features.jpg_fmt = 1;
86 image_info.parameter.features.buf =
87 reinterpret_cast<unsigned char *>(raw.buffer.data());
88 image_info.crypttype = -1;
89 std::cout << "Writing\n";
90
91 int status;
92 /*
93 status = write(video_fd, reinterpret_cast<char*>(&image_info),
94 sizeof(image_info));
95 if (status != sizeof(image_info)) {
96 std::cout << "Write failed. Return: " << status << "\n";
97 perror("perror output:");
98 }
Ed Tanous1ff48782017-04-18 12:45:08 -070099
Ed Tanous93f987d2017-04-17 17:52:36 -0700100 std::cout << "Write done\n";
101 */
102 std::cout << "Reading\n";
103 status = read(video_fd, reinterpret_cast<char *>(&image_info),
104 sizeof(image_info));
105 std::cout << "Reading\n";
106
107 if (status != 0) {
108 std::cout << "Read failed with status " << status << "\n";
109 }
110
111 raw.buffer.resize(image_info.len);
112
113 raw.height = image_info.parameter.features.h;
114 raw.width = image_info.parameter.features.w;
115 if (image_info.parameter.features.jpg_fmt == 422) {
116 raw.mode = YuvMode::YUV420;
117 } else {
118 raw.mode = YuvMode::YUV444;
119 }
120 return raw;
121 }
122
123 private:
124 int video_fd;
125 IMAGE_INFO image_info;
126};
127}