reserve 100 video stashes temporary fix
This commit is contained in:
parent
30e6c970d3
commit
d7f1877cbe
|
@ -7,6 +7,7 @@ Recorder::Recorder(Node* parent) : Node(parent)
|
|||
get_delegate().subscribe(&Recorder::respond, this);
|
||||
animation.play();
|
||||
Mix_SetPostMix(&process_audio, this);
|
||||
video_stashes.reserve(100);
|
||||
}
|
||||
|
||||
float Recorder::get_frame_length()
|
||||
|
@ -86,7 +87,9 @@ void Recorder::grab_stash()
|
|||
void Recorder::write_most_recent_frames()
|
||||
{
|
||||
make_directory();
|
||||
write_stash_frames(false, 0);
|
||||
write_stash_frames(&most_recent_stash.pixel_buffers,
|
||||
&most_recent_stash.flipped,
|
||||
most_recent_stash.frame_offset);
|
||||
open_audio_file();
|
||||
while (not most_recent_stash.audio_buffers.empty())
|
||||
{
|
||||
|
@ -154,10 +157,13 @@ void Recorder::add_frame()
|
|||
video_stashes.back().flipped.push_back(get_root()->is_gl_context);
|
||||
if (video_stashes.back().pixel_buffers.size() * get_frame_length() > max_length)
|
||||
{
|
||||
std::function<void(bool, int)> f =
|
||||
std::function<void(std::vector<unsigned char*>*, std::vector<bool>*, int)> f =
|
||||
std::bind(&Recorder::write_stash_frames, this,
|
||||
std::placeholders::_1, std::placeholders::_2);
|
||||
std::thread writing(f, true, video_stashes.size() - 1);
|
||||
std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3);
|
||||
std::thread writing(f, &video_stashes.back().pixel_buffers,
|
||||
&video_stashes.back().flipped,
|
||||
video_stashes.back().frame_offset);
|
||||
writing.detach();
|
||||
video_stashes.push_back(
|
||||
Stash(video_stashes.back().frame_offset +
|
||||
|
@ -206,32 +212,23 @@ void Recorder::make_directory()
|
|||
current_video_directory = directory;
|
||||
}
|
||||
|
||||
void Recorder::write_stash_frames(bool is_video, int index)
|
||||
void Recorder::write_stash_frames(
|
||||
std::vector<unsigned char*>* pixel_buffers, std::vector<bool>* flipped,
|
||||
int frame_offset)
|
||||
{
|
||||
int frame_offset = is_video ? video_stashes[index].frame_offset : 0;
|
||||
SDL_Log("Writing stash index %i to %s...", index, current_video_directory.c_str());
|
||||
SDL_Log("Writing stash offset %i to %s...", frame_offset, current_video_directory.c_str());
|
||||
SDL_Surface* frame;
|
||||
GifWriter gif_writer;
|
||||
int gif_frame_length = get_configuration()["recording"]["gif-frame-length"];
|
||||
fs::path gif_path = sfw::get_next_file_name(
|
||||
current_video_directory, 3, "gif-", ".gif");
|
||||
float elapsed = 0, last_gif_write = 0, gif_write_overflow = 0;
|
||||
for (int ii = frame_offset;
|
||||
not (is_video ? video_stashes[index].pixel_buffers.empty() :
|
||||
most_recent_stash.pixel_buffers.empty()); ii++)
|
||||
SDL_Log("Pixel buffers size %zu", pixel_buffers->size());
|
||||
for (int ii = frame_offset; not pixel_buffers->empty(); ii++)
|
||||
{
|
||||
if (is_video)
|
||||
{
|
||||
frame = get_display().get_screen_surface_from_pixels(
|
||||
video_stashes[index].pixel_buffers.front(),
|
||||
video_stashes[index].flipped.front());
|
||||
}
|
||||
else
|
||||
{
|
||||
frame = get_display().get_screen_surface_from_pixels(
|
||||
most_recent_stash.pixel_buffers.front(),
|
||||
most_recent_stash.flipped.front());
|
||||
}
|
||||
frame = get_display().get_screen_surface_from_pixels(
|
||||
pixel_buffers->front(), flipped->front());
|
||||
get_root()->log_surface_format(frame, "got");
|
||||
std::stringstream name;
|
||||
name << sfw::pad(ii, 5) << ".png";
|
||||
fs::path path = current_video_directory / name.str();
|
||||
|
@ -255,22 +252,9 @@ void Recorder::write_stash_frames(bool is_video, int index)
|
|||
frame->w, frame->h, gif_frame_length / 10);
|
||||
}
|
||||
elapsed += get_frame_length();
|
||||
if (is_video)
|
||||
{
|
||||
delete[] video_stashes[index].pixel_buffers.front();
|
||||
video_stashes[index].pixel_buffers.erase(
|
||||
video_stashes[index].pixel_buffers.begin());
|
||||
video_stashes[index].flipped.erase(
|
||||
video_stashes[index].flipped.begin());
|
||||
}
|
||||
else
|
||||
{
|
||||
delete[] most_recent_stash.pixel_buffers.front();
|
||||
most_recent_stash.pixel_buffers.erase(
|
||||
most_recent_stash.pixel_buffers.begin());
|
||||
most_recent_stash.flipped.erase(
|
||||
most_recent_stash.flipped.begin());
|
||||
}
|
||||
delete[] pixel_buffers->front();
|
||||
pixel_buffers->erase(pixel_buffers->begin());
|
||||
flipped->erase(flipped->begin());
|
||||
SDL_FreeSurface(frame);
|
||||
}
|
||||
GifEnd(&gif_writer);
|
||||
|
@ -307,7 +291,9 @@ void Recorder::end_recording()
|
|||
|
||||
void Recorder::finish_writing_video()
|
||||
{
|
||||
write_stash_frames(true, video_stashes.size() - 1);
|
||||
write_stash_frames(
|
||||
&video_stashes.back().pixel_buffers, &video_stashes.back().flipped,
|
||||
video_stashes.back().frame_offset);
|
||||
int count;
|
||||
while (true)
|
||||
{
|
||||
|
|
|
@ -54,7 +54,8 @@ struct Recorder : Node
|
|||
void add_frame();
|
||||
int get_memory_size();
|
||||
void make_directory();
|
||||
void write_stash_frames(bool, int);
|
||||
void write_stash_frames(
|
||||
std::vector<unsigned char*>*, std::vector<bool>*, int);
|
||||
void keep_stash();
|
||||
void end_recording();
|
||||
void finish_writing_video();
|
||||
|
|
Loading…
Reference in New Issue