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