1 #include <cstdio>
2 #include <fstream>
3 #include <unistd.h>
5 #include <kms++.h>
6 #include <kms++util.h>
8 using namespace std;
9 using namespace kms;
11 static void read_frame(ifstream& is, DumbFramebuffer* fb, Crtc* crtc, Plane* plane)
12 {
13 for (unsigned i = 0; i < fb->num_planes(); ++i)
14 is.read((char*)fb->map(i), fb->size(i));
16 unsigned w = min(crtc->width(), fb->width());
17 unsigned h = min(crtc->height(), fb->height());
19 int r = crtc->set_plane(plane, *fb,
20 0, 0, w, h,
21 0, 0, fb->width(), fb->height());
23 ASSERT(r == 0);
24 }
26 int main(int argc, char** argv)
27 {
28 if (argc != 5) {
29 printf("Usage: %s <file> <width> <height> <fourcc>\n", argv[0]);
30 return -1;
31 }
33 string filename = argv[1];
34 uint32_t w = stoi(argv[2]);
35 uint32_t h = stoi(argv[3]);
36 string modestr = argv[4];
38 auto pixfmt = FourCCToPixelFormat(modestr);
41 ifstream is(filename, ifstream::binary);
43 is.seekg(0, std::ios::end);
44 unsigned fsize = is.tellg();
45 is.seekg(0);
48 Card card;
50 auto conn = card.get_first_connected_connector();
51 auto crtc = conn->get_current_crtc();
53 auto fb = new DumbFramebuffer(card, w, h, pixfmt);
55 Plane* plane = 0;
57 for (Plane* p : crtc->get_possible_planes()) {
58 if (p->plane_type() != PlaneType::Overlay)
59 continue;
61 if (!p->supports_format(pixfmt))
62 continue;
64 plane = p;
65 break;
66 }
68 FAIL_IF(!plane, "available plane not found");
71 unsigned frame_size = 0;
72 for (unsigned i = 0; i < fb->num_planes(); ++i)
73 frame_size += fb->size(i);
75 unsigned num_frames = fsize / frame_size;
76 printf("file size %u, frame size %u, frames %u\n", fsize, frame_size, num_frames);
78 for (unsigned i = 0; i < num_frames; ++i) {
79 printf("frame %d\n", i);
80 read_frame(is, fb, crtc, plane);
81 usleep(1000*50);
82 }
84 printf("press enter to exit\n");
86 is.close();
88 getchar();
90 delete fb;
91 }