Hi,

this patch helps to set highest priority to decklink driver callback thread. it help to avoid dropped frames in some cases caused by multiple encoding thread with same standard priority.

--
________________________________________
Maksym Veremeyenko


>From 14269c11ac75b59da4cf0b14d0b825992cf4614c Mon Sep 17 00:00:00 2001
From: Maksym Veremeyenko <ve...@m1stereo.tv>
Date: Thu, 4 Jul 2013 12:42:00 +0300
Subject: [PATCH 2/2] priority changing of decklink callback thread, ported from decklink consumer

---
 src/modules/decklink/producer_decklink.cpp |   38 ++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/modules/decklink/producer_decklink.cpp b/src/modules/decklink/producer_decklink.cpp
index 5145612..7c19b05 100644
--- a/src/modules/decklink/producer_decklink.cpp
+++ b/src/modules/decklink/producer_decklink.cpp
@@ -43,6 +43,7 @@ private:
 	int              m_colorspace;
 	int              m_vancLines;
 	mlt_cache        m_cache;
+	bool             m_reprio;
 
 	BMDDisplayMode getDisplayMode( mlt_profile profile, int vancLines )
 	{
@@ -357,6 +358,43 @@ public:
 			IDeckLinkVideoInputFrame* video,
 			IDeckLinkAudioInputPacket* audio )
 	{
+		if( !m_reprio )
+		{
+			mlt_properties properties = MLT_CONSUMER_PROPERTIES( getProducer() );
+
+			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, &param);
+
+				thread = pthread_self();
+
+				r = pthread_setschedparam(thread, SCHED_FIFO, &param);
+				if( r )
+					mlt_log_verbose( getProducer(),
+						"VideoInputFrameArrived: pthread_setschedparam returned %d\n", r);
+				else
+					mlt_log_verbose( getProducer(),
+						"VideoInputFrameArrived: param.sched_priority=%d\n", param.sched_priority);
+			};
+
+			m_reprio = true;
+		};
+
 		if ( mlt_properties_get_int( MLT_PRODUCER_PROPERTIES( getProducer() ), "preview" ) &&
 			mlt_producer_get_speed( getProducer() ) == 0.0 && !mlt_deque_count( m_queue ))
 		{
-- 
1.7.1

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Mlt-devel mailing list
Mlt-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlt-devel

Reply via email to