[vlc-commits] macosx: use a modern system sleep prevention mechanism for the 64bit builds ( close #7391)

Felix Paul Kühne git at videolan.org
Mon Aug 27 10:15:36 CEST 2012


vlc/vlc-2.0 | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Sun Aug 26 19:50:24 2012 +0200| [89ab9f180ecd30977a15eb52ffe58c8b72b0fb72] | committer: Felix Paul Kühne

macosx: use a modern system sleep prevention mechanism for the 64bit builds (close #7391)

This is a manual backport of 4a47fcb16. Regrettably, this API was introduced in 10.6 so there is no way to make it work for the legacy 32bit platforms.

The benefit of this approach is that VLC can differenciate between system and screen sleep, so it can allow the system to turn off the screen while playing audio-only media.

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=89ab9f180ecd30977a15eb52ffe58c8b72b0fb72
---

 NEWS                      |    3 +++
 modules/gui/macosx/intf.h |    9 +++++++++
 modules/gui/macosx/intf.m |   24 ++++++++++++++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/NEWS b/NEWS
index 64b1a0b..bc605dc 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,9 @@ Mac OS X:
  * Deactivate CoreAnimation effects on Leopard
  * Fix menus display and behaviour
  * Fix various crashes and small issues
+ * Improve system sleep behavior when playing audio-only media. The screen is
+   allowed to sleep while the system is kept awake for the play time.
+   Requires OS X 10.6 or later and a 64bit-capable Mac.
 
 Miscellaneous:
  * Fix Notify (D-Bus) plugin deadlock.
diff --git a/modules/gui/macosx/intf.h b/modules/gui/macosx/intf.h
index 412d2ed..93c20ad 100644
--- a/modules/gui/macosx/intf.h
+++ b/modules/gui/macosx/intf.h
@@ -41,6 +41,10 @@
 #import "misc.h"
 #import "MainWindow.h"
 
+#ifdef __x86_64__
+#import <IOKit/pwr_mgt/IOPMLib.h>           /* for sleep prevention */
+#endif
+
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
@@ -146,6 +150,11 @@ struct intf_sys_t
     SPMediaKeyTap * o_mediaKeyController;
 
     NSArray *o_usedHotkeys;
+
+#ifdef __x86_64__
+    /* sleep management */
+    IOPMAssertionID systemSleepAssertionID;
+#endif
 }
 
 + (VLCMain *)sharedInstance;
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index 2b3f5cd..d5c8494 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -1554,6 +1554,7 @@ unsigned int CocoaKeyToVLC( unichar i_key )
 {
     [o_mainwindow updateTimeSlider];
 
+#ifndef __x86_64__
     input_thread_t * p_input;
     p_input = pl_CurrentInput( p_intf );
     if( p_input )
@@ -1562,6 +1563,7 @@ unsigned int CocoaKeyToVLC( unichar i_key )
             UpdateSystemActivity( UsrActivity );
         vlc_object_release( p_input );
     }
+#endif
 }
 
 - (void)updateVolume
@@ -1597,6 +1599,22 @@ unsigned int CocoaKeyToVLC( unichar i_key )
         int state = var_GetInteger( p_input, "state" );
         if( state == PLAYING_S )
         {
+#ifdef __x86_64__
+            /* prevent the system from sleeping */
+            IOReturn success;
+            CFStringRef reasonForActivity= CFStringCreateWithCString( kCFAllocatorDefault, _("VLC media playback"), kCFStringEncodingUTF8 );
+            if ( [self activeVideoPlayback] )
+                success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
+            else
+                success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
+            CFRelease( reasonForActivity );
+
+            if (success == kIOReturnSuccess)
+                msg_Dbg( VLCIntf, "prevented sleep through IOKit (%i)", systemSleepAssertionID);
+            else
+                msg_Warn( VLCIntf, "failed to prevent system sleep through IOKit");
+#endif
+
             [[self mainMenu] setPause];
             [o_mainwindow setPause];
         }
@@ -1606,6 +1624,12 @@ unsigned int CocoaKeyToVLC( unichar i_key )
                 [o_mainmenu setSubmenusEnabled: FALSE];
             [[self mainMenu] setPlay];
             [o_mainwindow setPlay];
+
+#ifdef __x86_64__
+            /* allow the system to sleep again */
+            msg_Dbg( VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID );
+            IOPMAssertionRelease( systemSleepAssertionID );
+#endif
         }
         vlc_object_release( p_input );
     }



More information about the vlc-commits mailing list