]> git.sesse.net Git - nageru/blobdiff - mixer.cpp
Make it possible to set input Y'CbCr interpretation on the command line.
[nageru] / mixer.cpp
index 3a14a757431a88b2924a3430dcbf922fe1b3e73c..1a76ac39c5c4226bab61b22b7af0f0ae0f841c18 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -206,13 +206,16 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards)
          mixer_surface(create_surface(format)),
          h264_encoder_surface(create_surface(format)),
          decklink_output_surface(create_surface(format)),
+         ycbcr_interpretation(global_flags.ycbcr_interpretation),
          audio_mixer(num_cards)
 {
        CHECK(init_movit(MOVIT_SHADER_DIR, MOVIT_DEBUG_OFF));
        check_error();
 
        // This nearly always should be true.
-       global_flags.can_disable_srgb_decoder = epoxy_has_gl_extension("GL_EXT_texture_sRGB_decode");
+       global_flags.can_disable_srgb_decoder =
+               epoxy_has_gl_extension("GL_EXT_texture_sRGB_decode") &&
+               epoxy_has_gl_extension("GL_ARB_sampler_objects");
 
        // Since we allow non-bouncing 4:2:2 YCbCrInputs, effective subpixel precision
        // will be halved when sampling them, and we need to compensate here.
@@ -1079,6 +1082,17 @@ void Mixer::render_one_frame(int64_t duration)
                printf("Timecode: '%s'\n", timecode_text.c_str());
        }
 
+       // Update Y'CbCr settings for all cards.
+       {
+               unique_lock<mutex> lock(card_mutex);
+               for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
+                       YCbCrInterpretation *interpretation = &ycbcr_interpretation[card_index];
+                       input_state.ycbcr_coefficients_auto[card_index] = interpretation->ycbcr_coefficients_auto;
+                       input_state.ycbcr_coefficients[card_index] = interpretation->ycbcr_coefficients;
+                       input_state.full_range[card_index] = interpretation->full_range;
+               }
+       }
+
        // Get the main chain from the theme, and set its state immediately.
        Theme::Chain theme_main_chain = theme->get_chain(0, pts(), global_flags.width, global_flags.height, input_state);
        EffectChain *chain = theme_main_chain.chain;
@@ -1280,6 +1294,18 @@ void Mixer::channel_clicked(int preview_num)
        theme->channel_clicked(preview_num);
 }
 
+YCbCrInterpretation Mixer::get_input_ycbcr_interpretation(unsigned card_index) const
+{
+       unique_lock<mutex> lock(card_mutex);
+       return ycbcr_interpretation[card_index];
+}
+
+void Mixer::set_input_ycbcr_interpretation(unsigned card_index, const YCbCrInterpretation &interpretation)
+{
+       unique_lock<mutex> lock(card_mutex);
+       ycbcr_interpretation[card_index] = interpretation;
+}
+
 void Mixer::start_mode_scanning(unsigned card_index)
 {
        assert(card_index < num_cards);
@@ -1325,10 +1351,12 @@ void Mixer::OutputChannel::output_frame(DisplayFrame frame)
                }
                ready_frame = frame;
                has_ready_frame = true;
-       }
 
-       if (new_frame_ready_callback) {
-               new_frame_ready_callback();
+               // Call the callbacks under the mutex (they should be short),
+               // so that we don't race against a callback removal.
+               for (const auto &key_and_callback : new_frame_ready_callbacks) {
+                       key_and_callback.second();
+               }
        }
 
        // Reduce the number of callbacks by filtering duplicates. The reason
@@ -1395,9 +1423,16 @@ bool Mixer::OutputChannel::get_display_frame(DisplayFrame *frame)
        return true;
 }
 
-void Mixer::OutputChannel::set_frame_ready_callback(Mixer::new_frame_ready_callback_t callback)
+void Mixer::OutputChannel::add_frame_ready_callback(void *key, Mixer::new_frame_ready_callback_t callback)
 {
-       new_frame_ready_callback = callback;
+       unique_lock<mutex> lock(frame_mutex);
+       new_frame_ready_callbacks[key] = callback;
+}
+
+void Mixer::OutputChannel::remove_frame_ready_callback(void *key)
+{
+       unique_lock<mutex> lock(frame_mutex);
+       new_frame_ready_callbacks.erase(key);
 }
 
 void Mixer::OutputChannel::set_transition_names_updated_callback(Mixer::transition_names_updated_callback_t callback)