shitty initial commit
This commit is contained in:
56
src/window/main.cpp
Normal file
56
src/window/main.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include "VideoPlayer.h"
|
||||
#include "X11Window.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " <path_to_video>" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Initialize the VideoPlayer with the provided video path
|
||||
VideoPlayer videoPlayer(argv[1]);
|
||||
uint8_t* frameData = nullptr;
|
||||
int width = 0, height = 0;
|
||||
|
||||
// Lambda for rendering a frame
|
||||
auto renderFrame = [&](Display* display, Window window, GC gc) {
|
||||
if (videoPlayer.getNextFrame(frameData, width, height)) {
|
||||
// Create XImage using BGRA data from VideoPlayer
|
||||
XImage* xImage = XCreateImage(
|
||||
display,
|
||||
DefaultVisual(display, DefaultScreen(display)),
|
||||
24, // depth
|
||||
ZPixmap,
|
||||
0,
|
||||
reinterpret_cast<char*>(frameData),
|
||||
width,
|
||||
height,
|
||||
32,
|
||||
width * 4
|
||||
);
|
||||
if (!xImage) {
|
||||
std::cerr << "Error creating XImage from frame data." << std::endl;
|
||||
return;
|
||||
}
|
||||
XPutImage(display, window, gc, xImage, 0, 0, 0, 0, width, height);
|
||||
XFlush(display);
|
||||
|
||||
// Clean up the XImage resource, not the frameData
|
||||
XDestroyImage(xImage);
|
||||
|
||||
// Wait ~25 FPS
|
||||
usleep(40000);
|
||||
}
|
||||
};
|
||||
|
||||
// Create the X11 window and run the event loop
|
||||
X11Window window(640, 480, renderFrame);
|
||||
window.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user