diff --git a/utils/kmsview.cpp b/utils/kmsview.cpp
index aae7e80d9b9dfa2828206a3472943c364608e90b..b59e004bda4273f36d418e95a53a93f2186b3dea 100644 (file)
--- a/utils/kmsview.cpp
+++ b/utils/kmsview.cpp
#include <fstream>
#include <unistd.h>
#include <fstream>
#include <unistd.h>
-#include "kms++.h"
-
-#include "test.h"
+#include <kms++.h>
+#include <kms++util.h>
+#include <opts.h>
using namespace std;
using namespace kms;
using namespace std;
using namespace kms;
@@ -24,21 +24,54 @@ static void read_frame(ifstream& is, DumbFramebuffer* fb, Crtc* crtc, Plane* pla
ASSERT(r == 0);
}
ASSERT(r == 0);
}
+static const char* usage_str =
+ "Usage: kmsview [-t <ms>] <file> <width> <height> <fourcc>\n\n"
+ "Options:\n"
+ " -t, --time Milliseconds to sleep between frames\n"
+ ;
+
+static void usage()
+{
+ puts(usage_str);
+}
+
int main(int argc, char** argv)
{
int main(int argc, char** argv)
{
- if (argc != 5) {
- printf("Usage: %s <file> <width> <height> <fourcc>\n", argv[0]);
- return -1;
+ uint32_t time = 0;
+ string dev_path = "/dev/dri/card0";
+
+ OptionSet optionset = {
+ Option("|device=", [&dev_path](string s)
+ {
+ dev_path = s;
+ }),
+ Option("t|time=", [&time](const string& str)
+ {
+ time = stoul(str);
+ }),
+ Option("h|help", []()
+ {
+ usage();
+ exit(-1);
+ }),
+ };
+
+ optionset.parse(argc, argv);
+
+ vector<string> params = optionset.params();
+
+ if (params.size() != 4) {
+ usage();
+ exit(-1);
}
}
- string filename = argv[1];
- uint32_t w = stoi(argv[2]);
- uint32_t h = stoi(argv[3]);
- string modestr = argv[4];
+ string filename = params[0];
+ uint32_t w = stoi(params[1]);
+ uint32_t h = stoi(params[2]);
+ string modestr = params[3];
auto pixfmt = FourCCToPixelFormat(modestr);
auto pixfmt = FourCCToPixelFormat(modestr);
-
ifstream is(filename, ifstream::binary);
is.seekg(0, std::ios::end);
ifstream is(filename, ifstream::binary);
is.seekg(0, std::ios::end);
is.seekg(0);
is.seekg(0);
- Card card;
+ Card card(dev_path);
auto conn = card.get_first_connected_connector();
auto crtc = conn->get_current_crtc();
auto conn = card.get_first_connected_connector();
auto crtc = conn->get_current_crtc();
printf("file size %u, frame size %u, frames %u\n", fsize, frame_size, num_frames);
for (unsigned i = 0; i < num_frames; ++i) {
printf("file size %u, frame size %u, frames %u\n", fsize, frame_size, num_frames);
for (unsigned i = 0; i < num_frames; ++i) {
- printf("frame %d\n", i);
+ printf("frame %d", i); fflush(stdout);
read_frame(is, fb, crtc, plane);
read_frame(is, fb, crtc, plane);
- usleep(1000*50);
+ if (!time) {
+ getchar();
+ } else {
+ usleep(time * 1000);
+ printf("\n");
+ }
}
}
- printf("press enter to exit\n");
-
is.close();
is.close();
- getchar();
+ if (time) {
+ printf("press enter to exit\n");
+ getchar();
+ }
delete fb;
}
delete fb;
}