Ed Tanous | e2fc45a | 2017-04-26 09:19:10 -0700 | [diff] [blame] | 1 | #include <fcntl.h> |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <unistd.h> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 5 | |
Ed Tanous | e2fc45a | 2017-04-26 09:19:10 -0700 | [diff] [blame] | 6 | #include <ast_jpeg_decoder.hpp> |
| 7 | #include <ast_video_puller.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 8 | |
Ed Tanous | e2fc45a | 2017-04-26 09:19:10 -0700 | [diff] [blame] | 9 | #include <chrono> |
| 10 | #include <fstream> |
| 11 | #include <iomanip> |
| 12 | #include <iostream> |
| 13 | #include <thread> |
| 14 | #include <vector> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 15 | |
Ed Tanous | e2fc45a | 2017-04-26 09:19:10 -0700 | [diff] [blame] | 16 | #include <gmock/gmock.h> |
| 17 | #include <gtest/gtest.h> |
| 18 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 19 | TEST(AstvideoPuller, BasicRead) |
| 20 | { |
| 21 | ast_video::RawVideoBuffer out; |
| 22 | bool have_hardware = false; |
| 23 | if (access("/dev/video", F_OK) != -1) |
| 24 | { |
| 25 | ast_video::SimpleVideoPuller p; |
| 26 | p.initialize(); |
| 27 | out = p.readVideo(); |
Ed Tanous | e2fc45a | 2017-04-26 09:19:10 -0700 | [diff] [blame] | 28 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 29 | else |
| 30 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 31 | FILE* fp = |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 32 | fopen("test_resources/ubuntu_444_800x600_0chrom_0lum.bin", "rb"); |
| 33 | if (fp) |
| 34 | { |
| 35 | size_t newLen = fread(out.buffer.data(), sizeof(char), |
| 36 | out.buffer.size() * sizeof(long), fp); |
| 37 | if (ferror(fp) != 0) |
| 38 | { |
| 39 | fputs("Error reading file", stderr); |
| 40 | } |
| 41 | fclose(fp); |
| 42 | out.buffer.resize(newLen); |
| 43 | out.mode = ast_video::YuvMode::YUV444; |
| 44 | out.width = 800; |
| 45 | out.height = 600; |
| 46 | out.ySelector = 0; |
| 47 | out.uvSelector = 0; |
| 48 | } |
| 49 | } |
Ed Tanous | e2fc45a | 2017-04-26 09:19:10 -0700 | [diff] [blame] | 50 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 51 | FILE* fp = fopen("/tmp/screendata.bin", "wb"); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 52 | fwrite(out.buffer.data(), sizeof(char), out.buffer.size(), fp); |
Patrick Venture | 6141c8b | 2018-10-16 13:11:39 -0700 | [diff] [blame] | 53 | fclose(fp); |
Ed Tanous | e2fc45a | 2017-04-26 09:19:10 -0700 | [diff] [blame] | 54 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 55 | ast_video::AstJpegDecoder d; |
| 56 | d.decode(out.buffer, out.width, out.height, out.mode, out.ySelector, |
| 57 | out.uvSelector); |
Ed Tanous | e2fc45a | 2017-04-26 09:19:10 -0700 | [diff] [blame] | 58 | } |