mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-14 05:12:25 +08:00

* feat: added glslang and spirv-core for handling shaders, should provide better results than current systems
* fix: brought back proper include placement, should fix some shaders not working
* chore: dial down required version to 330
* fix: crash when taking screenshot
* fix: use glReadnPixels for X11 copying to be more memory safe
* chore: reverted part of last commit
* chore: delay initialization of browser until it's used once
* chore: do not initialize web browser unless explicitly needed
* chore: cleanup filesystem functions to use containers directly
* chore: memory cleanup fixes
* chore: fix glReadPixels for older opengl versions
* chore: remove shader patches as they shouldn't be needed anymore
* chore: initialise variables
* chore: update deps, actions and readme
* chore: make use of custon glslang and SPIRV-Cross
* Revert "chore: update deps, actions and readme"
This reverts commit c3fbc9340b
.
* chore: update actions to include submodules
* chore: do not depend on SPIRV-Tools
* fix: added log10 macro
* feat: update to latest glslang (swizzle and vec2/vec3/vec4 implicit casting to float)
* revert: delayed initialization of cef was causing issues, reverted
* chore: re-organized web wallpaper support to use custom scheme and better handle multiprocessing
* chore: make use of external repos for all deps instead of copying things manually and more cleanup work
* chore: wrong include file used in CGLSLContext.cpp
* chore: fix wayland generation folder not being present
* feat: somewhat support TEXB0004
* chore: improve function call matching and fallback to more lax method if no function is found
* chore: changed shader compilation slightly so they're passed onto glsl just once
* feat: swap android's fft implementation (which wasn't right) with kissfft's and fix update frequency issues
* chore: added missing dependency
* chore: added missing dep to PKGBUILD
* feat: add testing tools to run over all backgrounds and getting output data
* chore: jail CDirectory to the basepath and prevent accessing data outside of the main directory
* chore: process script now scales the previews so the html file is not too big
* chore: add showcase gallery to the README.md
* chore: update README
* chore: some readability improvements on code
* chore: fix segfault after code cleanup
* chore: make use of std::filesystem::canonical instead of basepath and slight typing changes on texture objects
* chore: fix path detection being wrong, make use of std::filesystem::path on CContainers
* chore: cleanup of the core part of the project
* chore: bring back std::move and make some methods const where it makes sense
* feat: added a pretty printer for easier debug and comparison between different versions of linux-wallpaperengine
* chore: refactored shader compilation code once more to be easier to follow and fixed the longstanding bug of #include not being added in the right place
* chore: more debug info for the pretty printer
* fix: some textures applied were not the right ones
* chore: properly set combos based on textures
* feat: take into account project properties for shader values
feat: proper parsing of combo values in shaders
fix: shader units weren't linked as they should
chore: more support for detecting shader things automatically
* fix: blending mode for passes using the wrong value
fix: shader uniforms from project properties should now be taken into account
* chore: use ubuntu 22 and ubuntu 24 as builders, ubuntu 20 is retired
* chore: use ubuntu 22 and ubuntu 24 as builders, ubuntu 20 is retired
* chore: hopefully fix github actions build
* refactor: simplified working with properties, constants and shader variables
* chore: remove a couple of todos that aren't needed anymore
* chore: simplify the texture detection a little bit, still work left to do
* fix: regression on texture setup not working properly
* fix: filenames with dots were not being handled properly
* chore: remove some uselesss messages
* chore: fixed std::string json values not casting anything to it as it was assumed
* fix: null user value for constants means it cannot be modified by the user
* chore: remove exception when a shader constant uses a non-existant property
* fix: angles can be an user setting too, also added detection for animation frames to show a warning
* fix: ensure variable information is not commented out by a line comment
* fix: shader includes weren't being processed properly
* chore: update to latest glslang and SPIRV-Cross to support non-integer array indices
* chore: make use of auto where it made sense
* feat: make use of in/out promotion on glslang-WallpaperEngine
feat: use glslang-WallpaperEngine linkin process as an extra validation
* chore: improve scripts for running the app
* chore: hide background structure dump behind a command-line switch
* chore: rewritten bloom effect as a json object inside C++ so it's easier to follow
* chore: removed deprecated parameters and switched to argparse instead of getopt
fix: clamping mode wasn't applied by background properly, only globally
* chore: removed help prompt from the output unless actually required
* fix: web subprocesses weren't launching due to parameter's parsing, temporal fix
* feat: added material command copy support
* feat: do not initialize some subsystems if they're disabled or not used by backgrounds
* chore: ignore type in combos as only seems to be used in the editor
* chore: update to latest glslang-WallpaperEngine changes
* chore: delete uniforms if they already exist before setting
* chore: more cleanup and fixes
* chore: more cleanup and fixes
* chore: more cleanup and fixes
* chore: update file functions to make use of shared_ptr/unique_ptr instead of copying things around
* chore: more changes to unique_ptr and shared_ptr
* chore: more changes to unique_ptr and shared_ptr
* chore: more changes to unique_ptr and shared_ptr
feat: improved render initialization process to make it easier and simpler to add new drivers (no more #ifdef in CWallpaperApplication.cpp)
* chore: change all is/as castings to use typeid so no string comparison takes place
* chore: more cleanup, default initialization of values wherever possible
* chore: moved more things to std::unique_ptr and std::shared_ptr
* chore: moved more things to std::unique_ptr and std::shared_ptr
* fix: browser context usage crashed the app
* chore: the setting controls fullscreen detection creation the same way audio works
* fix: ensure that at least one frame is rendered before detecting fullscreen windows
* chore: slight changes to output and documentation to properly reflect current build configuration
* chore: fix mipmap texture creation
* chore: fix pass uniforms not taking into account fragment shader's uniforms
chore: keep processed code in the shader sent to opengl so it appears on RenderDoc
* chore: formating issues by codefactor
* chore: do not use new to allocate the pretty printer
* fix: strchr wasn't properly done for window geometry
* chore: add recording mode for status page generation
* chore: update .gitignore
* chore: update script to make use of video generation instead of the old python scripts
* chore: also copy project.json so it can be used on the site too
* fix: regression on invisible images not being rendered
* feat: add option to disable camera parallax
* chore: add the reversing tools I have locally
* chore: mention some of the common issues in the README.md
* chore: take submodules into account for archlinux
* chore: missed cd "$pkgname" in arch's prepare step
193 lines
5.9 KiB
C++
193 lines
5.9 KiB
C++
#if DEMOMODE
|
|
|
|
// this file is horrible, but doesn't need to be anything good as it's only used internally
|
|
|
|
#include "recording.h"
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <ctime>
|
|
#include <iostream>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
extern "C" {
|
|
#include <libavcodec/avcodec.h>
|
|
#include <libavformat/avformat.h>
|
|
#include <libswscale/swscale.h>
|
|
#include <libavutil/imgutils.h>
|
|
}
|
|
|
|
const int FPS = 30;
|
|
const int FRAME_COUNT = FPS * 5;
|
|
int WIDTH = 0;
|
|
int HEIGHT = 0;
|
|
int SOURCE_WIDTH = 0;
|
|
int SOURCE_HEIGHT = 0;
|
|
|
|
int64_t frame_count = 0;
|
|
|
|
// Global variables to hold encoder context and output stream
|
|
const AVCodec *video_codec = nullptr;
|
|
AVCodecContext *video_codec_context = nullptr;
|
|
AVFormatContext *format_context = nullptr;
|
|
AVStream *video_stream = nullptr;
|
|
SwsContext *sws_context = nullptr;
|
|
AVFrame *video_frame = nullptr;
|
|
AVFrame* rgb_frame = nullptr;
|
|
|
|
int init_encoder(const char *output_file, int sourceWidth, int sourceHeight) {
|
|
float factor = 512.0f / (float) sourceWidth;
|
|
SOURCE_WIDTH = sourceWidth;
|
|
SOURCE_HEIGHT = sourceHeight;
|
|
WIDTH = (float) sourceWidth * factor;
|
|
HEIGHT = (float) sourceHeight * factor;
|
|
|
|
avformat_network_init();
|
|
|
|
// Initialize the output format context
|
|
if (avformat_alloc_output_context2(&format_context, nullptr, "webm", output_file) < 0) {
|
|
std::cerr << "Error initializing format context" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
// Video codec: VP8
|
|
video_codec = avcodec_find_encoder(AV_CODEC_ID_VP9);
|
|
if (!video_codec) {
|
|
std::cerr << "VP8 codec not found!" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
video_codec_context = avcodec_alloc_context3(video_codec);
|
|
if (!video_codec_context) {
|
|
std::cerr << "Error allocating video codec context" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
video_codec_context->bit_rate = 4000000;
|
|
video_codec_context->width = WIDTH;
|
|
video_codec_context->height = HEIGHT;
|
|
video_codec_context->pix_fmt = AV_PIX_FMT_YUV420P;
|
|
video_codec_context->time_base = (AVRational){1, FPS};
|
|
video_codec_context->framerate = (AVRational){FPS, 1};
|
|
video_codec_context->gop_size = 12;
|
|
video_codec_context->max_b_frames = 1;
|
|
video_codec_context->qmin = 10;
|
|
video_codec_context->qmax = 40;
|
|
|
|
if (avcodec_open2(video_codec_context, video_codec, nullptr) < 0) {
|
|
std::cerr << "Error opening VP8 codec" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
// Create the video stream in the format context
|
|
video_stream = avformat_new_stream(format_context, video_codec);
|
|
if (!video_stream) {
|
|
std::cerr << "Error creating video stream" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
// Copy codec parameters from the codec context to the stream
|
|
if (avcodec_parameters_from_context(video_stream->codecpar, video_codec_context) < 0) {
|
|
std::cerr << "Error copying codec parameters to stream" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
video_stream->time_base = video_codec_context->time_base;
|
|
|
|
// Open output file for writing
|
|
if (avio_open(&format_context->pb, output_file, AVIO_FLAG_WRITE) < 0) {
|
|
std::cerr << "Error opening output file" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
// Write file header
|
|
if (avformat_write_header(format_context, nullptr) < 0) {
|
|
std::cerr << "Error writing file header" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
// Allocate video frame
|
|
video_frame = av_frame_alloc();
|
|
video_frame->format = AV_PIX_FMT_YUV420P;
|
|
video_frame->width = WIDTH;
|
|
video_frame->height = HEIGHT;
|
|
av_frame_get_buffer(video_frame, 0);
|
|
|
|
rgb_frame = av_frame_alloc();
|
|
|
|
rgb_frame->format = AV_PIX_FMT_RGB24;
|
|
rgb_frame->width = SOURCE_WIDTH;
|
|
rgb_frame->height = SOURCE_HEIGHT;
|
|
|
|
// Set up YUV conversion context (RGB to YUV)
|
|
sws_context = sws_getContext(SOURCE_WIDTH, SOURCE_HEIGHT, AV_PIX_FMT_RGB24,
|
|
WIDTH, HEIGHT, AV_PIX_FMT_YUV420P,
|
|
SWS_BICUBIC, nullptr, nullptr, nullptr);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int write_video_frame(const uint8_t *rgb_data) {
|
|
av_image_fill_arrays(rgb_frame->data, rgb_frame->linesize, rgb_data, AV_PIX_FMT_RGB24, SOURCE_WIDTH, SOURCE_HEIGHT, 1);
|
|
|
|
sws_scale(sws_context, rgb_frame->data, rgb_frame->linesize, 0, SOURCE_HEIGHT, video_frame->data, video_frame->linesize);
|
|
|
|
// Send the frame to the encoder
|
|
int ret = avcodec_send_frame(video_codec_context, video_frame);
|
|
if (ret < 0) {
|
|
std::cerr << "Error sending video frame: " << ret << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
AVPacket packet;
|
|
av_init_packet(&packet);
|
|
packet.data = nullptr;
|
|
packet.size = 0;
|
|
|
|
// Receive the encoded packet from the encoder
|
|
ret = avcodec_receive_packet(video_codec_context, &packet);
|
|
if (ret < 0) {
|
|
std::cerr << "Error receiving video packet: " << ret << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
packet.stream_index = video_stream->index;
|
|
// Set the PTS and DTS values
|
|
packet.pts = av_rescale_q(frame_count, video_codec_context->time_base, video_stream->time_base);
|
|
packet.dts = packet.pts; // For simplicity, you can set DTS equal to PTS for now
|
|
packet.duration = av_rescale_q(1, video_codec_context->time_base, video_stream->time_base);
|
|
|
|
// Increment frame counter
|
|
frame_count++;
|
|
// Write the encoded video packet to the file
|
|
ret = av_interleaved_write_frame(format_context, &packet);
|
|
if (ret < 0) {
|
|
std::cerr << "Error writing video packet: " << ret << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
// Ensure that the packet is freed
|
|
av_packet_unref(&packet);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int close_encoder() {
|
|
// Write any remaining frames (flush encoder)
|
|
avcodec_flush_buffers(video_codec_context);
|
|
|
|
// Write the trailer
|
|
av_write_trailer(format_context);
|
|
|
|
// Clean up
|
|
avcodec_free_context(&video_codec_context);
|
|
avformat_free_context(format_context);
|
|
av_frame_free(&video_frame);
|
|
sws_freeContext(sws_context);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#endif /* DEMOMODE */ |