23.07.11 00:45, Dan Dennedy написав(ла):
2011/7/22 Maksym Veremeyenko<ve...@m1stereo.tv>:
[...]
priority of this thread could be inherited from priority of initialization
code, so another possible solution is:

1. save current thread priority>
2. set new priority from mlt_property_get_int(properties, "priority")
3. init decklink
4. restore origin prio

what do you thing about this?

I am a little worried if we know exactly when the thread inside
decklink starts and therefore when to do step 4.
that was really hard, so i leaved with minor changes - priority is set from *priority* properties. That make possible to adjust priority from melted shell:

USET U0 consumer.priority=max

also reworked patch against melted to makes it process priority configurable...

--
________________________________________
Maksym Veremeyenko
>From 12acf8721e2c61c8adb050b304a807a9033e42f0 Mon Sep 17 00:00:00 2001
From: Maksym Veremeyenko <ve...@m1stereo.tv>
Date: Mon, 25 Jul 2011 14:58:33 +0300
Subject: [PATCH] change DriverNotificationThreadFunction priority by setting
 consumer.priority properties

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

diff --git a/src/modules/decklink/consumer_decklink.cpp b/src/modules/decklink/consumer_decklink.cpp
index 88c1cb9..e6323a1 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, &param);
+
+				thread = pthread_self();
+
+				r = pthread_setschedparam(thread, SCHED_FIFO, &param);
+				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 )
-- 
1.7.4.4

>From 1d60ad636101422dace6fdc698e979ed002209f7 Mon Sep 17 00:00:00 2001
From: Maksym Veremeyenko <ve...@m1stereo.tv>
Date: Mon, 25 Jul 2011 15:08:47 +0300
Subject: [PATCH] use -prio to set melted process priority

---
 src/melted/melted.c |   26 ++++++++++++++++++++------
 1 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/melted/melted.c b/src/melted/melted.c
index be019ec..f52e836 100644
--- a/src/melted/melted.c
+++ b/src/melted/melted.c
@@ -58,7 +58,7 @@ static void main_cleanup( )
 
 void usage( char *app )
 {
-	fprintf( stderr, "Usage: %s [-test] [-port NNNN] [-c config-file]\n", app );
+	fprintf( stderr, "Usage: %s [-prio NNNN|max] [-test] [-port NNNN] [-c config-file]\n", app );
 	exit( 0 );
 }
 
@@ -71,7 +71,6 @@ int main( int argc, char **argv )
 	int index = 0;
 	int background = 1;
 	struct timespec tm = { 1, 0 };
-	struct sched_param scp;
 	mvcp_status_t status;
 	struct {
 		int clip_index;
@@ -79,11 +78,24 @@ int main( int argc, char **argv )
 	} asrun[ MAX_UNITS ];
 	const char *config_file = "/etc/melted.conf";
 
-	// Use realtime scheduling if possible
-	memset( &scp, '\0', sizeof( scp ) );
-	scp.sched_priority = sched_get_priority_max( SCHED_FIFO ) - 1;
 #ifndef __DARWIN__
-	sched_setscheduler( 0, SCHED_FIFO, &scp );
+	for ( index = 1; index < argc; index ++ )
+	{
+		if ( !strcmp( argv[ index ], "-prio" ) )
+		{
+			struct sched_param scp;
+			char* prio = argv[ ++ index ];
+
+			memset( &scp, 0, sizeof( scp ) );
+
+			if( !strcmp( prio, "max" ) )
+				scp.sched_priority = sched_get_priority_max( SCHED_FIFO ) - 1;
+			else
+				scp.sched_priority = atoi(prio);
+
+			sched_setscheduler( 0, SCHED_FIFO, &scp );
+		}
+	}
 #endif
 
 	mlt_factory_init( NULL );
@@ -100,6 +112,8 @@ int main( int argc, char **argv )
 			background = 0;
 		else if ( !strcmp( argv[ index ], "-c" ) )
 			config_file = argv[ ++ index ];
+		else if ( !strcmp( argv[ index ], "-prio" ) )
+			index++;
 		else
 			usage( argv[ 0 ] );
 	}
-- 
1.7.4.4

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Mlt-devel mailing list
Mlt-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlt-devel

Reply via email to