[vlc-commits] macosx/player controller: add program support
Felix Paul Kühne
git at videolan.org
Tue Apr 9 22:53:54 CEST 2019
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Tue Apr 9 22:25:36 2019 +0200| [53abf4bbba34c90487b30591a3a05acd117ea078] | committer: Felix Paul Kühne
macosx/player controller: add program support
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=53abf4bbba34c90487b30591a3a05acd117ea078
---
modules/gui/macosx/playlist/VLCPlayerController.h | 53 +++++++++++
modules/gui/macosx/playlist/VLCPlayerController.m | 106 +++++++++++++++++++++-
2 files changed, 157 insertions(+), 2 deletions(-)
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.h b/modules/gui/macosx/playlist/VLCPlayerController.h
index e021779d0c..3509c25d79 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.h
+++ b/modules/gui/macosx/playlist/VLCPlayerController.h
@@ -27,6 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
@class VLCInputStats;
@class VLCTrackMetaData;
+ at class VLCProgramMetaData;
/**
* Listen to VLCPlayerCurrentMediaItemChanged to notified if the current media item changes for the player
@@ -98,6 +99,18 @@ extern NSString *VLCPlayerTitleListChanged;
extern NSString *VLCPlayerChapterSelectionChanged;
/**
+ * Listen to VLCPlayerProgramSelectionChanged to be notified if the selected program of the current media changes
+ * @note the affected player object will be the object of the notification
+ */
+extern NSString *VLCPlayerProgramSelectionChanged;
+
+/**
+ * Listen to VLCPlayerProgramListChanged to be notified if the list of available programs of the current media changes
+ * @note the affected player object will be the object of the notification
+ */
+extern NSString *VLCPlayerProgramListChanged;
+
+/**
* Listen to VLCPlayerABLoopStateChanged to be notified if the A→B loop state changes
* @note the affected player object will be the object of the notification
*/
@@ -530,6 +543,35 @@ extern NSString *VLCPlayerMuteChanged;
- (nullable const struct vlc_player_chapter *)chapterAtIndexForCurrentTitle:(size_t)index;
/**
+ * returns the selected program ID, typically in the range 0 to 32,000
+ * @warning the counter does not necessarily start at 0 nor are programs numbered consecutively
+ * @note listen to VLCPlayerProgramSelectionChanged to be notified about changes to this property
+ */
+ at property (readonly) int selectedProgramID;
+
+/**
+ * select the program defined by the provided VLCProgramMetaData instance
+ * @note listen to VLCPlayerProgramSelectionChanged to be notified once the change takes effect
+ */
+- (void)selectProgram:(VLCProgramMetaData *)program;
+
+/**
+ * returns the number of programs available for the current media
+ * @note listen to VLCPlayerProgramListChanged to be notified about changes to this property
+ */
+ at property (readonly) size_t numberOfPrograms;
+
+/**
+ * returns an instance of VLCProgramMetaData with details about the program at the specified index
+ */
+- (nullable VLCProgramMetaData *)programAtIndex:(size_t)index;
+
+/**
+ * returns an instance of VLCProgramMetaData with details about the program with the specified ID
+ */
+- (nullable VLCProgramMetaData *)programForID:(int)programID;
+
+/**
* exposes whether a teletext menu is available or not
* @note listen to VLCPlayerTeletextMenuAvailable to be notified about changes to this property
*/
@@ -831,4 +873,15 @@ extern NSString *VLCPlayerMuteChanged;
@end
+ at interface VLCProgramMetaData : NSObject
+
+- (instancetype)initWithProgramStructure:(const struct vlc_player_program *)structure;
+
+ at property (readonly) int group_id;
+ at property (readonly) NSString *name;
+ at property (readonly) BOOL selected;
+ at property (readonly) BOOL scrambled;
+
+ at end
+
NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.m b/modules/gui/macosx/playlist/VLCPlayerController.m
index e36494217c..614c0303e7 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.m
+++ b/modules/gui/macosx/playlist/VLCPlayerController.m
@@ -44,6 +44,8 @@ NSString *VLCPlayerLengthChanged = @"VLCPlayerLengthChanged";
NSString *VLCPlayerTitleSelectionChanged = @"VLCPlayerTitleSelectionChanged";
NSString *VLCPlayerTitleListChanged = @"VLCPlayerTitleListChanged";
NSString *VLCPlayerChapterSelectionChanged = @"VLCPlayerChapterSelectionChanged";
+NSString *VLCPlayerProgramSelectionChanged = @"VLCPlayerProgramSelectionChanged";
+NSString *VLCPlayerProgramListChanged = @"VLCPlayerProgramListChanged";
NSString *VLCPlayerABLoopStateChanged = @"VLCPlayerABLoopStateChanged";
NSString *VLCPlayerTeletextMenuAvailable = @"VLCPlayerTeletextMenuAvailable";
NSString *VLCPlayerTeletextEnabled = @"VLCPlayerTeletextEnabled";
@@ -107,6 +109,8 @@ NSString *VLCPlayerMuteChanged = @"VLCPlayerMuteChanged";
- (void)inputStatsUpdated:(VLCInputStats *)inputStats;
- (void)trackSelectionChanged;
- (void)trackListChanged;
+- (void)programListChanged;
+- (void)programSelectionChanged:(int)selectedID;
- (void)ABLoopStateChanged:(enum vlc_player_abloop)abLoopState;
- (void)stopActionChanged:(enum vlc_player_media_stopped_action)stoppedAction;
- (void)metaDataChangedForInput:(input_item_t *)inputItem;
@@ -376,6 +380,30 @@ static void cb_player_track_selection_changed(vlc_player_t *p_player,
});
}
+static void cb_player_program_list_changed(vlc_player_t *p_player,
+ enum vlc_player_list_action action,
+ const struct vlc_player_program *prgm,
+ void *p_data)
+{
+ VLC_UNUSED(p_player); VLC_UNUSED(action); VLC_UNUSED(prgm);
+ dispatch_async(dispatch_get_main_queue(), ^{
+ VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
+ [playerController programListChanged];
+ });
+}
+
+static void cb_player_program_selection_changed(vlc_player_t *p_player,
+ int unselected_id,
+ int selected_id,
+ void *p_data)
+{
+ VLC_UNUSED(p_player); VLC_UNUSED(unselected_id);
+ dispatch_async(dispatch_get_main_queue(), ^{
+ VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
+ [playerController programSelectionChanged:selected_id];
+ });
+}
+
static void cb_player_atobloop_changed(vlc_player_t *p_player,
enum vlc_player_abloop new_state,
vlc_tick_t time, float pos,
@@ -435,8 +463,8 @@ static const struct vlc_player_cbs player_callbacks = {
cb_player_length_changed,
cb_player_track_list_changed,
cb_player_track_selection_changed,
- NULL, //cb_player_program_list_changed,
- NULL, //cb_player_program_selection_changed,
+ cb_player_program_list_changed,
+ cb_player_program_selection_changed,
cb_player_titles_changed,
cb_player_title_selection_changed,
cb_player_chapter_selection_changed,
@@ -1408,6 +1436,59 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
return [self tracksForCategory:SPU_ES];
}
+- (void)programListChanged
+{
+ [_defaultNotificationCenter postNotificationName:VLCPlayerProgramListChanged
+ object:self];
+}
+
+- (void)programSelectionChanged:(int)selectedID
+{
+ _selectedProgramID = selectedID;
+ [_defaultNotificationCenter postNotificationName:VLCPlayerProgramSelectionChanged
+ object:self];
+}
+
+- (void)selectProgram:(VLCProgramMetaData *)program
+{
+ vlc_player_Lock(_p_player);
+ vlc_player_SelectProgram(_p_player, program.group_id);
+ vlc_player_Unlock(_p_player);
+}
+
+- (size_t)numberOfPrograms
+{
+ size_t ret = 0;
+ vlc_player_Lock(_p_player);
+ ret = vlc_player_GetProgramCount(_p_player);
+ vlc_player_Unlock(_p_player);
+ return ret;
+}
+
+- (nullable VLCProgramMetaData *)programAtIndex:(size_t)index
+{
+ VLCProgramMetaData *programMetaData = nil;
+ vlc_player_Lock(_p_player);
+ const struct vlc_player_program *program = vlc_player_GetProgramAt(_p_player, index);
+ if (program != NULL) {
+ programMetaData = [[VLCProgramMetaData alloc] initWithProgramStructure:program];
+ }
+ vlc_player_Unlock(_p_player);
+ return programMetaData;
+}
+
+- (nullable VLCProgramMetaData *)programForID:(int)programID
+{
+ VLCProgramMetaData *programMetaData = nil;
+ vlc_player_Lock(_p_player);
+ const struct vlc_player_program *program = vlc_player_GetProgram(_p_player, programID);
+ if (program != NULL) {
+ programMetaData = [[VLCProgramMetaData alloc] initWithProgramStructure:program];
+ }
+ vlc_player_Unlock(_p_player);
+ return programMetaData;
+}
+
- (void)ABLoopStateChanged:(enum vlc_player_abloop)abLoopState
{
_abLoopState = abLoopState;
@@ -1629,3 +1710,24 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
}
@end
+
+ at implementation VLCProgramMetaData
+
+- (instancetype)initWithProgramStructure:(const struct vlc_player_program *)structure
+{
+ self = [super init];
+ if (structure != NULL) {
+ _group_id = structure->group_id;
+ _name = toNSStr(structure->name);
+ _selected = structure->selected;
+ _scrambled = structure->scrambled;
+ }
+ return self;
+}
+
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"%@: name: %@", [VLCProgramMetaData className], self.name];
+}
+
+ at end
More information about the vlc-commits
mailing list