Skip to content

Commit

Permalink
changed, only change main thread scheduling for video playback
Browse files Browse the repository at this point in the history
  • Loading branch information
davilla committed Sep 4, 2011
1 parent a1b4c52 commit 3f0ccc5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 50 deletions.
13 changes: 10 additions & 3 deletions xbmc/Application.cpp
Expand Up @@ -254,11 +254,13 @@
#ifdef HAS_XRANDR
#include "windowing/X11/XRandR.h"
#endif
#ifdef __APPLE__
#if !defined(__arm__)

#ifdef TARGET_DARWIN_OSX
#include "CocoaInterface.h"
#include "XBMCHelper.h"
#endif
#ifdef TARGET_DARWIN
#include "DarwinUtils.h"
#endif

#ifdef HAS_DVD_DRIVE
Expand Down Expand Up @@ -4400,6 +4402,9 @@ bool CApplication::OnMessage(CGUIMessage& message)

case GUI_MSG_PLAYBACK_STARTED:
{
#ifdef TARGET_DARWIN
DarwinSetScheduling(message.GetMessage());
#endif
// Update our infoManager with the new details etc.
if (m_nextPlaylistItem >= 0)
{ // we've started a previously queued item
Expand Down Expand Up @@ -4486,7 +4491,9 @@ bool CApplication::OnMessage(CGUIMessage& message)
if (m_pKaraokeMgr )
m_pKaraokeMgr->Stop();
#endif

#ifdef TARGET_DARWIN
DarwinSetScheduling(message.GetMessage());
#endif
// first check if we still have items in the stack to play
if (message.GetMessage() == GUI_MSG_PLAYBACK_ENDED)
{
Expand Down
1 change: 1 addition & 0 deletions xbmc/osx/DarwinUtils.h
Expand Up @@ -33,6 +33,7 @@ extern "C"
int GetDarwinExecutablePath(char* path, uint32_t *pathsize);
bool DarwinHasVideoToolboxDecoder(void);
int DarwinBatteryLevel(void);
void DarwinSetScheduling(int message);
#ifdef __cplusplus
}
#endif
Expand Down
41 changes: 37 additions & 4 deletions xbmc/osx/DarwinUtils.mm
Expand Up @@ -21,12 +21,15 @@

#define BOOL XBMC_BOOL
#include "system.h"
#include "Application.h"
#include "DllPaths.h"
#include "GUIUserMessages.h"
#include "utils/log.h"

#undef BOOL

#if defined(__APPLE__)
#if defined(__arm__)
#if defined(TARGET_DARWIN)
#if defined(TARGET_DARWIN_IOS)
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <mach/mach_host.h>
Expand All @@ -44,7 +47,7 @@
bool DarwinIsAppleTV2(void)
{
static int result = -1;
#if defined(__APPLE__) && defined(__arm__)
#if defined(TARGET_DARWIN_IOS)
if( result == -1 )
{
char buffer[512];
Expand All @@ -66,7 +69,7 @@ float GetIOSVersion(void)
{
CCocoaAutoPool pool;
float version;
#if defined(__arm__)
#if defined(TARGET_DARWIN_IOS)
version = [[[UIDevice currentDevice] systemVersion] floatValue];
#else
version = 0.0f;
Expand Down Expand Up @@ -262,4 +265,34 @@ int DarwinBatteryLevel(void)
return batteryLevel * 100;
}

void DarwinSetScheduling(int message)
{
int policy;
struct sched_param param;
pthread_t this_pthread_self = pthread_self();

int32_t result = pthread_getschedparam(this_pthread_self, &policy, &param );

policy = SCHED_OTHER;
thread_extended_policy_data_t theFixedPolicy={true};

switch(message)
{
case GUI_MSG_PLAYBACK_STARTED:
if (g_application.IsPlayingVideo())
{
policy = SCHED_RR;
theFixedPolicy.timeshare = false;
}
break;
}

result = thread_policy_set(pthread_mach_thread_np(this_pthread_self),
THREAD_EXTENDED_POLICY,
(thread_policy_t)&theFixedPolicy,
THREAD_EXTENDED_POLICY_COUNT);

result = pthread_setschedparam(this_pthread_self, policy, &param );
}

#endif
22 changes: 0 additions & 22 deletions xbmc/osx/atv2/XBMCEAGLView.mm
Expand Up @@ -251,28 +251,6 @@ - (void) runAnimation:(id) arg
{
CCocoaAutoPool outerpool;

[NSThread setThreadPriority:0.9];
/*
// Changing to SCHED_RR is safe under OSX, you don't need elevated privileges and the
// OSX scheduler will monitor SCHED_RR threads and drop to SCHED_OTHER if it detects
// the thread running away. OSX automatically does this with the CoreAudio audio
// device handler thread.
int32_t result;
thread_extended_policy_data_t theFixedPolicy;
// make thread fixed, set to 'true' for a non-fixed thread
theFixedPolicy.timeshare = false;
result = thread_policy_set(pthread_mach_thread_np(pthread_self()), THREAD_EXTENDED_POLICY,
(thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT);
int policy;
struct sched_param param;
result = pthread_getschedparam(pthread_self(), &policy, &param );
// change from default SCHED_OTHER to SCHED_RR
policy = SCHED_RR;
result = pthread_setschedparam(pthread_self(), policy, &param );
*/
// signal we are alive
NSConditionLock* myLock = arg;
[myLock lock];
Expand Down
21 changes: 0 additions & 21 deletions xbmc/osx/ios/XBMCEAGLView.mm
Expand Up @@ -275,27 +275,6 @@ - (void) runAnimation:(id) arg
{
CCocoaAutoPool outerpool;

[NSThread setThreadPriority:0.9];
/*
// Changing to SCHED_RR is safe under OSX, you don't need elevated privileges and the
// OSX scheduler will monitor SCHED_RR threads and drop to SCHED_OTHER if it detects
// the thread running away. OSX automatically does this with the CoreAudio audio
// device handler thread.
int32_t result;
thread_extended_policy_data_t theFixedPolicy;
// make thread fixed, set to 'true' for a non-fixed thread
theFixedPolicy.timeshare = false;
result = thread_policy_set(pthread_mach_thread_np(pthread_self()), THREAD_EXTENDED_POLICY,
(thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT);
int policy;
struct sched_param param;
result = pthread_getschedparam(pthread_self(), &policy, &param );
// change from default SCHED_OTHER to SCHED_RR
policy = SCHED_RR;
result = pthread_setschedparam(pthread_self(), policy, &param );
*/
// signal we are alive
NSConditionLock* myLock = arg;
[myLock lock];
Expand Down

0 comments on commit 3f0ccc5

Please sign in to comment.