Implementation of FPS monitor in Mixer (fixed dt precision) and Plot

monitor of FPS in toolbox.
This commit is contained in:
brunoherbelin
2020-06-27 12:19:33 +02:00
parent 6e2c0cb338
commit 44901f6756
5 changed files with 46 additions and 12 deletions

View File

@@ -74,7 +74,7 @@ void FrameBuffer::init()
// attach the 2D texture to intermediate FBO
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureid_, 0);
Log::Info("New FBO %d Multi Sampling ", framebufferid_);
// Log::Info("New FBO %d Multi Sampling ", framebufferid_);
}
else {
@@ -82,7 +82,7 @@ void FrameBuffer::init()
// direct attach the 2D texture to FBO
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureid_, 0);
Log::Info("New FBO %d Single Sampling ", framebufferid_);
// Log::Info("New FBO %d Single Sampling ", framebufferid_);
}
checkFramebufferStatus();

View File

@@ -583,7 +583,11 @@ void MediaPlayer::update()
{
glBindTexture(GL_TEXTURE_2D, textureindex_);
// use dual Pixel Buffer Object
if (pbo_size_ > 0) {
// In dual PBO mode, increment current index first then get the next index
pbo_index_ = (pbo_index_ + 1) % 2;
pbo_next_index_ = (pbo_index_ + 1) % 2;
// bind PBO to read pixels
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_[pbo_index_]);
@@ -597,6 +601,7 @@ void MediaPlayer::update()
// See http://www.songho.ca/opengl/gl_pbo.html#map for more details
glBufferData(GL_PIXEL_UNPACK_BUFFER, pbo_size_, 0, GL_STREAM_DRAW);
// map the buffer object into client's memory
// GLubyte* ptr = (GLubyte*) glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, pbo_size_, GL_MAP_WRITE_BIT|GL_MAP_INVALIDATE_BUFFER_BIT);
GLubyte* ptr = (GLubyte*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
if (ptr) {
// update data directly on the mapped buffer
@@ -608,10 +613,6 @@ void MediaPlayer::update()
}
// done with PBO
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
// In dual PBO mode, increment current index first then get the next index
pbo_index_ = (pbo_index_ + 1) % 2;
pbo_next_index_ = (pbo_index_ + 1) % 2;
}
else
// without PBO, use standard opengl (slower)

View File

@@ -139,7 +139,7 @@ static void saveSession(const std::string& filename, Session *session)
sessionThreadActive_ = false;
}
Mixer::Mixer() : session_(nullptr), back_session_(nullptr), current_view_(nullptr)
Mixer::Mixer() : session_(nullptr), back_session_(nullptr), current_view_(nullptr), fps_(60.f)
{
// unsused initial empty session
session_ = new Session;
@@ -183,7 +183,10 @@ void Mixer::update()
if (update_time_ == GST_CLOCK_TIME_NONE)
update_time_ = gst_util_get_timestamp ();
gint64 current_time = gst_util_get_timestamp ();
float dt = static_cast<float>( GST_TIME_AS_MSECONDS(current_time - update_time_) ) * 0.001f;
// dt is in mulisecond, with fractional precision (from micro seconds)
float dt = static_cast<float>( GST_TIME_AS_USECONDS(current_time - update_time_) * 0.001f);
if (dt > 0.1f)
fps_ = 0.9f * fps_ + 100.f / dt;
update_time_ = current_time;
// insert source candidate for this session
@@ -402,7 +405,6 @@ void Mixer::setCurrentSource(SourceList::iterator it)
// show status as current
(*current_source_)->setMode(Source::CURRENT);
Log::Info("setCurrentSource");
}
}

View File

@@ -38,6 +38,7 @@ public:
// draw session and current view
void draw();
inline float frameRate() const { return fps_;}
// creation of sources
Source * createSourceFile (std::string path);
@@ -96,7 +97,7 @@ protected:
View *current_view_;
gint64 update_time_;
float fps_;
};
#endif // MIXER_H

View File

@@ -692,8 +692,37 @@ void ToolBox::Render()
ImGui::EndMenuBar();
}
ImGui::End(); // "v-mix"
ImVec2 plot_size = ImGui::GetContentRegionAvail();
plot_size.y *= 0.5;
static float mixer_framerate_values[120] = {60.f};
static float io_framerate_values[120] = {60.f};
static int values_offset = 0;
values_offset = (values_offset+1) % IM_ARRAYSIZE(mixer_framerate_values);
mixer_framerate_values[values_offset] = Mixer::manager().frameRate();
io_framerate_values[values_offset] = ImGui::GetIO().Framerate;
// plot FPS graph
{
float average = 0.0f;
for (int n = 0; n < IM_ARRAYSIZE(mixer_framerate_values); n++)
average += mixer_framerate_values[n];
average /= (float)IM_ARRAYSIZE(mixer_framerate_values);
char overlay[32];
sprintf(overlay, "Mixer FPS %.2f", average);
ImGui::PlotLines("LinesMixer", mixer_framerate_values, IM_ARRAYSIZE(mixer_framerate_values), values_offset, overlay, 40.0f, 65.0f, plot_size);
}
{
float average = 0.0f;
for (int n = 0; n < IM_ARRAYSIZE(mixer_framerate_values); n++)
average += mixer_framerate_values[n];
average /= (float)IM_ARRAYSIZE(mixer_framerate_values);
char overlay[32];
sprintf(overlay, "Render FPS %.2f", average);
ImGui::PlotLines("LinesRender", io_framerate_values, IM_ARRAYSIZE(io_framerate_values), values_offset, overlay, 40.0f, 65.0f, plot_size);
}
ImGui::End(); // "v-mix"
// About and other utility windows
if (show_icons_window)
@@ -702,6 +731,7 @@ void ToolBox::Render()
ImGui::ShowDemoWindow(&show_demo_window);
}
//static void Square(ImGuiSizeCallbackData* data) {
@@ -742,7 +772,7 @@ void UserInterface::RenderPreview()
draw_list->AddRectFilled(draw_pos, ImVec2(draw_pos.x + width, draw_pos.y + ImGui::GetTextLineHeightWithSpacing()), IM_COL32(55, 55, 55, 200));
ImGui::SetCursorScreenPos(draw_pos);
ImGui::Text(" %d x %d px, %.1f fps", output->width(), output->height(), ImGui::GetIO().Framerate );
ImGui::Text(" %d x %d px, %.1f fps", output->width(), output->height(), Mixer::manager().frameRate() );
}
ImGui::End();