From b0e27fe79ba477055ce7d7deab212f1449c062ac Mon Sep 17 00:00:00 2001 From: Maksym Veremeyenko Date: Thu, 28 Jul 2011 23:21:55 -0700 Subject: [PATCH] Make scheduling priority of decklink lib thread adjustable. Uses existing mlt_consumer priority property, but also responds to special "max" and "min" values. --- src/modules/decklink/consumer_decklink.cpp | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/modules/decklink/consumer_decklink.cpp b/src/modules/decklink/consumer_decklink.cpp index 88c1cb97..e6323a18 100644 --- a/src/modules/decklink/consumer_decklink.cpp +++ b/src/modules/decklink/consumer_decklink.cpp @@ -57,6 +57,7 @@ private: bool m_terminate_on_pause; uint32_t m_preroll; uint32_t m_acnt; + bool m_reprio; IDeckLinkDisplayMode* getDisplayMode() { @@ -237,6 +238,7 @@ public: } m_preroll = preroll; + m_reprio = false; // preroll frames for( i = 0; i < preroll; i++ ) @@ -439,6 +441,43 @@ public: virtual HRESULT STDMETHODCALLTYPE ScheduledFrameCompleted( IDeckLinkVideoFrame* completedFrame, BMDOutputFrameCompletionResult completed ) { + if( !m_reprio ) + { + mlt_properties properties = MLT_CONSUMER_PROPERTIES( getConsumer() ); + + if ( mlt_properties_get( properties, "priority" ) ) + { + int r; + pthread_t thread; + pthread_attr_t tattr; + struct sched_param param; + + pthread_attr_init(&tattr); + pthread_attr_setschedpolicy(&tattr, SCHED_FIFO); + + if ( !strcmp( "max", mlt_properties_get( properties, "priority" ) ) ) + param.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1; + else if ( !strcmp( "min", mlt_properties_get( properties, "priority" ) ) ) + param.sched_priority = sched_get_priority_min(SCHED_FIFO) + 1; + else + param.sched_priority = mlt_properties_get_int( properties, "priority" ); + + pthread_attr_setschedparam(&tattr, ¶m); + + thread = pthread_self(); + + r = pthread_setschedparam(thread, SCHED_FIFO, ¶m); + if( r ) + mlt_log_verbose( getConsumer(), + "ScheduledFrameCompleted: pthread_setschedparam retured %d\n", r); + else + mlt_log_verbose( getConsumer(), + "ScheduledFrameCompleted: param.sched_priority=%d\n", param.sched_priority); + }; + + m_reprio = true; + }; + uint32_t cnt; m_deckLinkOutput->GetBufferedAudioSampleFrameCount( &cnt ); if ( cnt != m_acnt ) -- 2.39.2