[vlc-commits] macosx: implement audio device selection using the new aout core API ( close #8036)
Felix Paul Kühne
git at videolan.org
Thu Jan 24 14:21:26 CET 2013
vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Thu Jan 24 14:21:04 2013 +0100| [2f3a48156f657cfb6d38556274d4b164a36a6d00] | committer: Felix Paul Kühne
macosx: implement audio device selection using the new aout core API (close #8036)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2f3a48156f657cfb6d38556274d4b164a36a6d00
---
modules/gui/macosx/MainMenu.h | 4 ++-
modules/gui/macosx/MainMenu.m | 76 ++++++++++++++++++++++++++++++++++++-----
modules/gui/macosx/intf.m | 8 +----
3 files changed, 71 insertions(+), 17 deletions(-)
diff --git a/modules/gui/macosx/MainMenu.h b/modules/gui/macosx/MainMenu.h
index 6f8e805..fccc800 100644
--- a/modules/gui/macosx/MainMenu.h
+++ b/modules/gui/macosx/MainMenu.h
@@ -1,7 +1,7 @@
/*****************************************************************************
* MainMenu.h: MacOS X interface module
*****************************************************************************
- * Copyright (C) 2011-2012 Felix Paul Kühne
+ * Copyright (C) 2011-2013 Felix Paul Kühne
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
@@ -237,6 +237,8 @@
- (void)updatePlaybackRate;
- (IBAction)toggleAtoBloop:(id)sender;
+- (IBAction)toggleAudioDevice:(id)sender;
+
- (IBAction)toggleFullscreen:(id)sender;
- (IBAction)resizeVideoWindow:(id)sender;
- (IBAction)floatOnTop:(id)sender;
diff --git a/modules/gui/macosx/MainMenu.m b/modules/gui/macosx/MainMenu.m
index e9c6546..dfec4d0 100644
--- a/modules/gui/macosx/MainMenu.m
+++ b/modules/gui/macosx/MainMenu.m
@@ -1,7 +1,7 @@
/*****************************************************************************
* MainMenu.m: MacOS X interface module
*****************************************************************************
- * Copyright (C) 2011-2012 Felix Paul Kühne
+ * Copyright (C) 2011-2013 Felix Paul Kühne
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
@@ -261,6 +261,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
var: "intf-add" selector: @selector(toggleVar:)];
[self setupExtensionsMenu];
+
+ [self refreshAudioDeviceList];
}
- (void)initStrings
@@ -507,9 +509,6 @@ static VLCMainMenu *_o_sharedInstance = nil;
[self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
var: "stereo-mode" selector: @selector(toggleVar:)];
- [self setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
- var: "audio-device" selector: @selector(toggleVar:)];
-
[self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
var: "visual" selector: @selector(toggleVar:)];
vlc_object_release(p_aout);
@@ -587,7 +586,6 @@ static VLCMainMenu *_o_sharedInstance = nil;
[o_mi_deinterlace setEnabled: b_enabled];
[o_mi_deinterlace_mode setEnabled: b_enabled];
[o_mi_ffmpeg_pp setEnabled: b_enabled];
- [o_mi_device setEnabled: b_enabled];
[o_mi_screen setEnabled: b_enabled];
[o_mi_aspect_ratio setEnabled: b_enabled];
[o_mi_crop setEnabled: b_enabled];
@@ -719,6 +717,70 @@ static VLCMainMenu *_o_sharedInstance = nil;
}
#pragma mark -
+#pragma mark audio menu
+- (void)refreshAudioDeviceList
+{
+ char **ids, **names;
+ char *currentDevice;
+
+ [o_mu_device removeAllItems];
+
+ audio_output_t * p_aout = getAout();
+ if (!p_aout)
+ return;
+
+ int n = aout_DevicesList(p_aout, &ids, &names);
+ if (n == -1)
+ return;
+
+ currentDevice = aout_DeviceGet(p_aout);
+
+ NSMenuItem * o_mi_tmp;
+ o_mi_tmp = [o_mu_device addItemWithTitle:_NS("Default") action:@selector(toggleAudioDevice:) keyEquivalent:@""];
+ [o_mi_tmp setTarget:self];
+ if (!currentDevice)
+ [o_mi_tmp setState:NSOnState];
+
+ for (NSUInteger x = 0; x < n; x++) {
+ o_mi_tmp = [o_mu_device addItemWithTitle:[NSString stringWithFormat:@"%s", names[x]] action:@selector(toggleAudioDevice:) keyEquivalent:@""];
+ [o_mi_tmp setTarget:self];
+ [o_mi_tmp setTag:[[NSString stringWithFormat:@"%s", ids[x]] intValue]];
+ if (currentDevice) {
+ if (!strcmp(ids[x], currentDevice))
+ [o_mi_tmp setState: NSOnState];
+ }
+ }
+ vlc_object_release(p_aout);
+
+ for (NSUInteger x = 0; x < n; x++) {
+ free(ids[x]);
+ free(names[x]);
+ }
+ free(ids);
+ free(names);
+
+ [o_mu_device setAutoenablesItems:YES];
+ [o_mi_device setEnabled:YES];
+}
+
+- (IBAction)toggleAudioDevice:(id)sender
+{
+ audio_output_t * p_aout = getAout();
+
+ int returnValue = 0;
+
+ if ([sender tag] > 0)
+ aout_DeviceSet(p_aout, [[NSString stringWithFormat:@"%li", [sender tag]] UTF8String]);
+ else
+ aout_DeviceSet(p_aout, NULL);
+
+ if (returnValue != 0)
+ msg_Warn(VLCIntf, "failed to set audio device %li", [sender tag]);
+
+ [self refreshAudioDeviceList];
+}
+
+#pragma mark -
#pragma mark video menu
- (IBAction)toggleFullscreen:(id)sender
@@ -1214,10 +1276,6 @@ static VLCMainMenu *_o_sharedInstance = nil;
if (!strcmp([menuContent name], "fullscreen") || !strcmp([menuContent name], "video-on-top"))
var_Set(pl_Get(VLCIntf), [menuContent name] , [menuContent value]);
- /* save our audio device across multiple sessions */
- if (!strcmp([menuContent name], "audio-device"))
- config_PutInt(VLCIntf, "macosx-audio-device", [menuContent value].i_int);
-
p_object = [menuContent vlcObject];
if (p_object != NULL) {
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index b891ea3..b16c1fd 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -1,7 +1,7 @@
/*****************************************************************************
* intf.m: MacOS X interface module
*****************************************************************************
- * Copyright (C) 2002-2012 VLC authors and VideoLAN
+ * Copyright (C) 2002-2013 VLC authors and VideoLAN
* $Id$
*
* Authors: Jon Lech Johansen <jon-vl at nanocrew.net>
@@ -712,12 +712,6 @@ static VLCMain *_o_sharedMainInstance = nil;
b_nativeFullscreenMode = var_InheritBool(p_intf, "macosx-nativefullscreenmode");
#endif
- /* recover stored audio device, if set
- * in case it was unplugged in the meantime, auhal will fall back on the default */
- int i_value = config_GetInt(p_intf, "macosx-audio-device");
- if (i_value > 0)
- var_SetInteger(pl_Get(VLCIntf), "audio-device", i_value);
-
if (config_GetInt(VLCIntf, "macosx-icon-change")) {
/* After day 354 of the year, the usual VLC cone is replaced by another cone
* wearing a Father Xmas hat.
More information about the vlc-commits
mailing list