]> git.sesse.net Git - nageru/commitdiff
A little refactoring in render_one_frame().
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 2 Apr 2016 15:10:15 +0000 (17:10 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 2 Apr 2016 15:10:15 +0000 (17:10 +0200)
mixer.cpp
mixer.h

index 52d285ce632e9e922cd48337cdcd91a2c1a2e4ef..e04b36dde7e6b0f0f4e26db4085f97c91d1f7429 100644 (file)
--- 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 f1e5fa2bc6498a6c0b6935bd349a381453dc3060..e27d2299bae5d2746b0478491a450c7421f8dabb 100644 (file)
--- 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);