blob: a69f47b72bc7cbe8b9d8fb55c0e42c72aa5342c1 [file] [log] [blame]
Ed Tanouse2fc45a2017-04-26 09:19:10 -07001#include <fcntl.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <unistd.h>
Ed Tanous1abe55e2018-09-05 08:30:59 -07005
Ed Tanouse2fc45a2017-04-26 09:19:10 -07006#include <ast_jpeg_decoder.hpp>
7#include <ast_video_puller.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05008
Ed Tanouse2fc45a2017-04-26 09:19:10 -07009#include <chrono>
10#include <fstream>
11#include <iomanip>
12#include <iostream>
13#include <thread>
14#include <vector>
Ed Tanous1abe55e2018-09-05 08:30:59 -070015
Ed Tanouse2fc45a2017-04-26 09:19:10 -070016#include <gmock/gmock.h>
17#include <gtest/gtest.h>
18
Ed Tanous1abe55e2018-09-05 08:30:59 -070019TEST(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 Tanouse2fc45a2017-04-26 09:19:10 -070028 }
Ed Tanous1abe55e2018-09-05 08:30:59 -070029 else
30 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -050031 FILE* fp =
Ed Tanous1abe55e2018-09-05 08:30:59 -070032 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 Tanouse2fc45a2017-04-26 09:19:10 -070050
Gunnar Mills1214b7e2020-06-04 10:11:30 -050051 FILE* fp = fopen("/tmp/screendata.bin", "wb");
Ed Tanous1abe55e2018-09-05 08:30:59 -070052 fwrite(out.buffer.data(), sizeof(char), out.buffer.size(), fp);
Patrick Venture6141c8b2018-10-16 13:11:39 -070053 fclose(fp);
Ed Tanouse2fc45a2017-04-26 09:19:10 -070054
Ed Tanous1abe55e2018-09-05 08:30:59 -070055 ast_video::AstJpegDecoder d;
56 d.decode(out.buffer, out.width, out.height, out.mode, out.ySelector,
57 out.uvSelector);
Ed Tanouse2fc45a2017-04-26 09:19:10 -070058}