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