[vlc-commits] macosx: modernize renderer handling
Felix Paul Kühne
git at videolan.org
Mon Mar 11 11:14:25 CET 2019
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Mon Mar 11 11:13:47 2019 +0100| [c3dc355fa16b7314a469e762b885dbdb3194e3c3] | committer: Felix Paul Kühne
macosx: modernize renderer handling
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c3dc355fa16b7314a469e762b885dbdb3194e3c3
---
modules/gui/macosx/menus/VLCMainMenu.m | 1 +
.../gui/macosx/menus/renderers/VLCRendererItem.h | 9 ++++---
.../gui/macosx/menus/renderers/VLCRendererItem.m | 6 +++--
.../menus/renderers/VLCRendererMenuController.m | 22 +++++----------
modules/gui/macosx/playlist/VLCPlayerController.h | 13 +++++++++
modules/gui/macosx/playlist/VLCPlayerController.m | 31 ++++++++++++++++++++--
6 files changed, 59 insertions(+), 23 deletions(-)
diff --git a/modules/gui/macosx/menus/VLCMainMenu.m b/modules/gui/macosx/menus/VLCMainMenu.m
index f96363a09d..5f91103146 100644
--- a/modules/gui/macosx/menus/VLCMainMenu.m
+++ b/modules/gui/macosx/menus/VLCMainMenu.m
@@ -25,6 +25,7 @@
#import <vlc_common.h>
#import <vlc_input.h>
+#import <vlc_playlist_legacy.h>
#import "coreinteraction/VLCCoreInteraction.h"
#import "coreinteraction/VLCVideoFilterHelper.h"
diff --git a/modules/gui/macosx/menus/renderers/VLCRendererItem.h b/modules/gui/macosx/menus/renderers/VLCRendererItem.h
index 1db7e994d2..760f2efb75 100644
--- a/modules/gui/macosx/menus/renderers/VLCRendererItem.h
+++ b/modules/gui/macosx/menus/renderers/VLCRendererItem.h
@@ -23,7 +23,8 @@
#import <Foundation/Foundation.h>
#include <vlc_common.h>
-#include <vlc_playlist_legacy.h>
+
+ at class VLCPlayerController;
/**
\c VLCRendererItem is a simple wrapper class for libvlc’s
@@ -66,10 +67,10 @@
/**
Sets the renderer represented by this \c VLCRendererItem as active
- for the given playlist.
+ for the given player controller.
- \param playlist The playlist for which to set the renderer
+ \param playerController The player controller for which to set the renderer
*/
-- (void)setRendererForPlaylist:(playlist_t*)playlist;
+- (void)setRendererForPlayerController:(VLCPlayerController *)playerController;
@end
diff --git a/modules/gui/macosx/menus/renderers/VLCRendererItem.m b/modules/gui/macosx/menus/renderers/VLCRendererItem.m
index a67ec4afc1..6cf5dc5669 100644
--- a/modules/gui/macosx/menus/renderers/VLCRendererItem.m
+++ b/modules/gui/macosx/menus/renderers/VLCRendererItem.m
@@ -21,7 +21,9 @@
*****************************************************************************/
#import "VLCRendererItem.h"
+
#import "extensions/NSString+Helpers.h"
+#import "playlist/VLCPlayerController.h"
#include <vlc_common.h>
#include <vlc_renderer_discovery.h>
@@ -75,9 +77,9 @@
return vlc_renderer_item_flags(_rendererItem);
}
-- (void)setRendererForPlaylist:(playlist_t*)playlist
+- (void)setRendererForPlayerController:(VLCPlayerController *)playerController
{
- playlist_SetRenderer(playlist, _rendererItem);
+ [playerController setRendererItem:_rendererItem];
}
- (BOOL)isEqual:(id)object
diff --git a/modules/gui/macosx/menus/renderers/VLCRendererMenuController.m b/modules/gui/macosx/menus/renderers/VLCRendererMenuController.m
index 68b898ea0d..149bef848e 100644
--- a/modules/gui/macosx/menus/renderers/VLCRendererMenuController.m
+++ b/modules/gui/macosx/menus/renderers/VLCRendererMenuController.m
@@ -25,6 +25,8 @@
#import "main/VLCMain.h"
#import "menus/renderers/VLCRendererItem.h"
+#import "playlist/VLCPlaylistController.h"
+#import "playlist/VLCPlayerController.h"
#include <vlc_renderer_discovery.h>
@@ -68,13 +70,11 @@
- (void)loadRendererDiscoveries
{
- playlist_t *playlist = pl_Get(p_intf);
-
// Service Discovery subnodes
char **ppsz_longnames;
char **ppsz_names;
- if (vlc_rd_get_names(playlist, &ppsz_names, &ppsz_longnames) != VLC_SUCCESS) {
+ if (vlc_rd_get_names(VLC_OBJECT(p_intf), &ppsz_names, &ppsz_longnames) != VLC_SUCCESS) {
return;
}
char **ppsz_name = ppsz_names;
@@ -162,24 +162,16 @@
[sender setState:NSOnState];
_selectedItem = sender;
- VLCRendererItem* item = [sender representedObject];
- playlist_t *playlist = pl_Get(p_intf);
-
- if (!playlist)
- return;
+ VLCRendererItem *item = [sender representedObject];
+ VLCPlayerController *playerController = [[[VLCMain sharedInstance] playlistController] playerController];
if (item) {
- [item setRendererForPlaylist:playlist];
+ [item setRendererForPlayerController:playerController];
} else {
- [self unsetRendererForPlaylist:playlist];
+ [playerController setRendererItem:NULL];
}
}
-- (void)unsetRendererForPlaylist:(playlist_t*)playlist
-{
- playlist_SetRenderer(playlist, NULL);
-}
-
#pragma mark VLCRendererDiscovery delegate methods
- (void)addedRendererItem:(VLCRendererItem *)item from:(VLCRendererDiscovery *)sender
{
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.h b/modules/gui/macosx/playlist/VLCPlayerController.h
index e44f76ec79..df3507d871 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.h
+++ b/modules/gui/macosx/playlist/VLCPlayerController.h
@@ -134,6 +134,12 @@ extern NSString *VLCPlayerSubtitlesDelayChanged;
*/
extern NSString *VLCPlayerRecordingChanged;
+/**
+ * Listen to VLCPlayerRendererChanged to be notified if the renderer (such as a Chromecast device) changes
+ * @note the affected playser object will be the obejct of the notification
+ */
+extern NSString *VLCPlayerRendererChanged;
+
extern NSString *VLCPlayerInputStats;
/**
* Listen to VLCPlayerStatisticsUpdated to be notified if the playback statistics state of the current media update
@@ -491,6 +497,13 @@ extern NSString *VLCPlayerMuteChanged;
- (void)toggleRecord;
/**
+ * set / get the renderer for the current player
+ * @warning the returned vlc_renderer_item_t * must be released with vlc_renderer_item_release().
+ * @note listen to VLCPlayerRendererChanged to be notified about changes
+ */
+ at property (readwrite, nonatomic, nullable) vlc_renderer_item_t *rendererItem;
+
+/**
* the latest available playback statistics
* @return an instance of VLCInputStats holding the data
* @note listen to VLCPlayerStatisticsUpdated to be notified about changes to this property
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.m b/modules/gui/macosx/playlist/VLCPlayerController.m
index b19e1f4cbf..f7c0aaf6b2 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.m
+++ b/modules/gui/macosx/playlist/VLCPlayerController.m
@@ -50,6 +50,7 @@ NSString *VLCPlayerAudioDelayChanged = @"VLCPlayerAudioDelayChanged";
NSString *VLCPlayerSubtitlesDelayChanged = @"VLCPlayerSubtitlesDelayChanged";
NSString *VLCPlayerSubtitleTextScalingFactorChanged = @"VLCPlayerSubtitleTextScalingFactorChanged";
NSString *VLCPlayerRecordingChanged = @"VLCPlayerRecordingChanged";
+NSString *VLCPlayerRendererChanged = @"VLCPlayerRendererChanged";
NSString *VLCPlayerInputStats = @"VLCPlayerInputStats";
NSString *VLCPlayerStatisticsUpdated = @"VLCPlayerStatisticsUpdated";
NSString *VLCPlayerFullscreenChanged = @"VLCPlayerFullscreenChanged";
@@ -92,6 +93,7 @@ NSString *VLCPlayerMuteChanged = @"VLCPlayerMuteChanged";
- (void)teletextPageChanged:(unsigned int)page;
- (void)teletextTransparencyChanged:(BOOL)isTransparent;
- (void)audioDelayChanged:(vlc_tick_t)audioDelay;
+- (void)rendererChanged:(vlc_renderer_item_t *)newRendererItem;
- (void)subtitlesDelayChanged:(vlc_tick_t)subtitlesDelay;
- (void)recordingChanged:(BOOL)recording;
- (void)inputStatsUpdated:(VLCInputStats *)inputStats;
@@ -257,7 +259,18 @@ static void cb_player_subtitle_delay_changed(vlc_player_t *p_player, vlc_tick_t
VLC_UNUSED(p_player);
dispatch_async(dispatch_get_main_queue(), ^{
VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
- [playerController audioDelayChanged:newDelay];
+ [playerController subtitlesDelayChanged:newDelay];
+ });
+}
+
+static void cb_player_renderer_changed(vlc_player_t *p_player,
+ vlc_renderer_item_t *p_new_renderer,
+ void *p_data)
+{
+ VLC_UNUSED(p_player);
+ dispatch_async(dispatch_get_main_queue(), ^{
+ VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
+ [playerController rendererChanged:p_new_renderer];
});
}
@@ -363,7 +376,7 @@ static const struct vlc_player_cbs player_callbacks = {
cb_player_audio_delay_changed,
cb_player_subtitle_delay_changed,
NULL, //cb_player_associated_subs_fps_changed,
- NULL, //cb_player_renderer_changed,
+ cb_player_renderer_changed,
cb_player_record_changed,
NULL, //cb_player_signal_changed,
cb_player_stats_changed,
@@ -1052,6 +1065,20 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
vlc_player_Unlock(_p_player);
}
+- (void)rendererChanged:(vlc_renderer_item_t *)newRenderer
+{
+ _rendererItem = newRenderer;
+ [_defaultNotificationCenter postNotificationName:VLCPlayerRendererChanged
+ object:self];
+}
+
+- (void)setRendererItem:(vlc_renderer_item_t *)rendererItem
+{
+ vlc_player_Lock(_p_player);
+ vlc_player_SetRenderer(_p_player, rendererItem);
+ vlc_player_Unlock(_p_player);
+}
+
- (void)recordingChanged:(BOOL)recording
{
_enableRecording = recording;
More information about the vlc-commits
mailing list