From a43cd0787ec6042f24ee6bea7d9cbc8ce0579f17 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 2 Apr 2016 17:10:15 +0200 Subject: [PATCH] A little refactoring in render_one_frame(). --- mixer.cpp | 119 ++++++++++++++++++++++++++++-------------------------- mixer.h | 1 + 2 files changed, 63 insertions(+), 57 deletions(-) diff --git a/mixer.cpp b/mixer.cpp index 52d285c..e04b36d 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -713,66 +713,10 @@ void Mixer::thread_func() } } - // Get the main chain from the theme, and set its state immediately. - Theme::Chain theme_main_chain = theme->get_chain(0, pts(), WIDTH, HEIGHT, input_state); - EffectChain *chain = theme_main_chain.chain; - theme_main_chain.setup_chain(); - //theme_main_chain.chain->enable_phase_timing(true); - - GLuint y_tex, cbcr_tex; - bool got_frame = h264_encoder->begin_frame(&y_tex, &cbcr_tex); - assert(got_frame); - - // Render main chain. - GLuint cbcr_full_tex = resource_pool->create_2d_texture(GL_RG8, WIDTH, HEIGHT); - GLuint rgba_tex = resource_pool->create_2d_texture(GL_RGB565, WIDTH, HEIGHT); // Saves texture bandwidth, although dithering gets messed up. - GLuint fbo = resource_pool->create_fbo(y_tex, cbcr_full_tex, rgba_tex); - check_error(); - chain->render_to_fbo(fbo, WIDTH, HEIGHT); - resource_pool->release_fbo(fbo); - - subsample_chroma(cbcr_full_tex, cbcr_tex); - resource_pool->release_2d_texture(cbcr_full_tex); - - // Set the right state for rgba_tex. - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glBindTexture(GL_TEXTURE_2D, rgba_tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - RefCountedGLsync fence(GL_SYNC_GPU_COMMANDS_COMPLETE, /*flags=*/0); - check_error(); - - const int64_t av_delay = TIMEBASE / 10; // Corresponds to the fixed delay in resampling_queue.h. TODO: Make less hard-coded. - h264_encoder->end_frame(fence, pts_int + av_delay, theme_main_chain.input_frames); + render_one_frame(); ++frame; pts_int += new_frames[master_card_index].length; - // The live frame just shows the RGBA texture we just rendered. - // It owns rgba_tex now. - DisplayFrame live_frame; - live_frame.chain = display_chain.get(); - live_frame.setup_chain = [this, rgba_tex]{ - display_input->set_texture_num(rgba_tex); - }; - live_frame.ready_fence = fence; - live_frame.input_frames = {}; - live_frame.temp_textures = { rgba_tex }; - output_channel[OUTPUT_LIVE].output_frame(live_frame); - - // Set up preview and any additional channels. - for (int i = 1; i < theme->get_num_channels() + 2; ++i) { - DisplayFrame display_frame; - Theme::Chain chain = theme->get_chain(i, pts(), WIDTH, HEIGHT, input_state); // FIXME: dimensions - display_frame.chain = chain.chain; - display_frame.setup_chain = chain.setup_chain; - display_frame.ready_fence = fence; - display_frame.input_frames = chain.input_frames; - display_frame.temp_textures = {}; - output_channel[i].output_frame(display_frame); - } - clock_gettime(CLOCK_MONOTONIC, &now); double elapsed = now.tv_sec - start.tv_sec + 1e-9 * (now.tv_nsec - start.tv_nsec); @@ -808,6 +752,67 @@ void Mixer::thread_func() resource_pool->clean_context(); } +void Mixer::render_one_frame() +{ + // Get the main chain from the theme, and set its state immediately. + Theme::Chain theme_main_chain = theme->get_chain(0, pts(), WIDTH, HEIGHT, input_state); + EffectChain *chain = theme_main_chain.chain; + theme_main_chain.setup_chain(); + //theme_main_chain.chain->enable_phase_timing(true); + + GLuint y_tex, cbcr_tex; + bool got_frame = h264_encoder->begin_frame(&y_tex, &cbcr_tex); + assert(got_frame); + + // Render main chain. + GLuint cbcr_full_tex = resource_pool->create_2d_texture(GL_RG8, WIDTH, HEIGHT); + GLuint rgba_tex = resource_pool->create_2d_texture(GL_RGB565, WIDTH, HEIGHT); // Saves texture bandwidth, although dithering gets messed up. + GLuint fbo = resource_pool->create_fbo(y_tex, cbcr_full_tex, rgba_tex); + check_error(); + chain->render_to_fbo(fbo, WIDTH, HEIGHT); + resource_pool->release_fbo(fbo); + + subsample_chroma(cbcr_full_tex, cbcr_tex); + resource_pool->release_2d_texture(cbcr_full_tex); + + // Set the right state for rgba_tex. + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindTexture(GL_TEXTURE_2D, rgba_tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + RefCountedGLsync fence(GL_SYNC_GPU_COMMANDS_COMPLETE, /*flags=*/0); + check_error(); + + const int64_t av_delay = TIMEBASE / 10; // Corresponds to the fixed delay in resampling_queue.h. TODO: Make less hard-coded. + h264_encoder->end_frame(fence, pts_int + av_delay, theme_main_chain.input_frames); + + // The live frame just shows the RGBA texture we just rendered. + // It owns rgba_tex now. + DisplayFrame live_frame; + live_frame.chain = display_chain.get(); + live_frame.setup_chain = [this, rgba_tex]{ + display_input->set_texture_num(rgba_tex); + }; + live_frame.ready_fence = fence; + live_frame.input_frames = {}; + live_frame.temp_textures = { rgba_tex }; + output_channel[OUTPUT_LIVE].output_frame(live_frame); + + // Set up preview and any additional channels. + for (int i = 1; i < theme->get_num_channels() + 2; ++i) { + DisplayFrame display_frame; + Theme::Chain chain = theme->get_chain(i, pts(), WIDTH, HEIGHT, input_state); // FIXME: dimensions + display_frame.chain = chain.chain; + display_frame.setup_chain = chain.setup_chain; + display_frame.ready_fence = fence; + display_frame.input_frames = chain.input_frames; + display_frame.temp_textures = {}; + output_channel[i].output_frame(display_frame); + } +} + void Mixer::audio_thread_func() { while (!should_quit) { diff --git a/mixer.h b/mixer.h index f1e5fa2..e27d229 100644 --- a/mixer.h +++ b/mixer.h @@ -336,6 +336,7 @@ private: FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format); void place_rectangle(movit::Effect *resample_effect, movit::Effect *padding_effect, float x0, float y0, float x1, float y1); void thread_func(); + void render_one_frame(); void audio_thread_func(); void process_audio_one_frame(int64_t frame_pts_int, int num_samples); void subsample_chroma(GLuint src_tex, GLuint dst_dst); -- 2.39.2