[vlc-commits] macosx/player controller: expose track handling

Felix Paul Kühne git at videolan.org
Sat Mar 30 18:45:50 CET 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sat Mar 30 17:41:19 2019 +0100| [9bdb57eff8d7aca2ccd5ed478acd933ae95ae97a] | committer: Felix Paul Kühne

macosx/player controller: expose track handling

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9bdb57eff8d7aca2ccd5ed478acd933ae95ae97a
---

 modules/gui/macosx/playlist/VLCPlayerController.h |  91 +++++++++++++
 modules/gui/macosx/playlist/VLCPlayerController.m | 149 +++++++++++++++++++++-
 2 files changed, 238 insertions(+), 2 deletions(-)

diff --git a/modules/gui/macosx/playlist/VLCPlayerController.h b/modules/gui/macosx/playlist/VLCPlayerController.h
index 09e0a8ab72..59760defad 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.h
+++ b/modules/gui/macosx/playlist/VLCPlayerController.h
@@ -26,6 +26,7 @@
 NS_ASSUME_NONNULL_BEGIN
 
 @class VLCInputStats;
+ at class VLCTrackMetaData;
 
 /**
  * Listen to VLCPlayerCurrentMediaItemChanged to notified if the current media item changes for the player
@@ -159,6 +160,18 @@ extern NSString *VLCPlayerInputStats;
 extern NSString *VLCPlayerStatisticsUpdated;
 
 /**
+ * Listen to VLCPlayerTrackListChanged to be notified of the list of audio/video/SPU tracks changes for the current media
+ * @note the affected player object will be the object of the notification
+ */
+extern NSString *VLCPlayerTrackListChanged;
+
+/**
+ * Listen to VLCPlayerTrackSelectionChanged to be notified if a selected audio/video/SPU track changes for the current media
+ * @note the affected player object will be the object of the notification
+ */
+extern NSString *VLCPlayerTrackSelectionChanged;
+
+/**
  * Listen to VLCPlayerFullscreenChanged to be notified whether the fullscreen state of the video output changes
  * @note the affected player object will be the object of the notification
  */
@@ -589,6 +602,76 @@ extern NSString *VLCPlayerMuteChanged;
  */
 @property (readonly) VLCInputStats *statistics;
 
+#pragma mark - track selection
+
+/**
+ * select a track
+ * @note since tracks are unique, you do not need to specify the type
+ * @note listen to VLCTrackSelectionChanged to be notified once the change occured
+ */
+- (void)selectTrack:(VLCTrackMetaData *)track;
+
+/**
+ * unselect a track
+ * @note since tracks are unique, you do not need to specify the type
+ * @note listen to VLCTrackSelectionChanged to be notified once the change occured
+ */
+- (void)unselectTrack:(VLCTrackMetaData *)track;
+
+/**
+ * unselect any track of a certain category
+ * @param the es_format_category_e category to unselect
+ * @note listen to VLCTrackSelectionChanged to be notified once the change occured
+ */
+- (void)unselectTracksFromCategory:(enum es_format_category_e)category;
+
+/**
+ * cycle to the previous track of a certain category
+ * @param the category, @see es_format_category_e
+ * @note listen to VLCTrackSelectionChanged to be notified once the change occured
+ */
+- (void)selectPreviousTrackForCategory:(enum es_format_category_e)category;
+
+/**
+ * cycle to the next track of a certain category
+ * @param the category, @see es_format_category_e
+ * @note listen to VLCTrackSelectionChanged to be notified once the change occured
+ */
+- (void)selectNextTrackForCategory:(enum es_format_category_e)category;
+
+/**
+ * the number of audio tracks
+ * @note listen to VLCPlayerTrackListChanged to be notified if this value changes
+ */
+ at property (readonly) size_t numberOfAudioTracks;
+
+/**
+ * get a metadata copy of a certain audio track at @param index
+ */
+- (VLCTrackMetaData *)audioTrackAtIndex:(size_t)index;
+
+/**
+ * the number of video tracks
+ * @note listen to VLCPlayerTrackListChanged to be notified if this value changes
+ */
+ at property (readonly) size_t numberOfVideoTracks;
+
+/**
+ * get a metadata copy of a certain video track at @param index
+ */
+- (VLCTrackMetaData *)videoTrackAtIndex:(size_t)index;
+
+/**
+ * the number of subtitle tracks
+ * @note listen to VLCPlayerTrackListChanged to be notified if this value changes
+ */
+ at property (readonly) size_t numberOfSubtitleTracks;
+
+/**
+ * get a metadata copy of a certain subtitle track at @param index
+ */
+- (VLCTrackMetaData *)subtitleTrackAtIndex:(size_t)index;
+
 #pragma mark - video output properties
 
 /**
@@ -723,4 +806,12 @@ extern NSString *VLCPlayerMuteChanged;
 
 @end
 
+ at interface VLCTrackMetaData : NSObject
+
+ at property (readwrite) vlc_es_id_t *esID;
+ at property (readwrite, retain) NSString *name;
+ at property (readwrite) BOOL selected;
+
+ at end
+
 NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.m b/modules/gui/macosx/playlist/VLCPlayerController.m
index 547970e085..886b4a04b2 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.m
+++ b/modules/gui/macosx/playlist/VLCPlayerController.m
@@ -56,6 +56,8 @@ NSString *VLCPlayerRecordingChanged = @"VLCPlayerRecordingChanged";
 NSString *VLCPlayerRendererChanged = @"VLCPlayerRendererChanged";
 NSString *VLCPlayerInputStats = @"VLCPlayerInputStats";
 NSString *VLCPlayerStatisticsUpdated = @"VLCPlayerStatisticsUpdated";
+NSString *VLCPlayerTrackListChanged = @"VLCPlayerTrackListChanged";
+NSString *VLCPlayerTrackSelectionChanged = @"VLCPlayerTrackSelectionChanged";
 NSString *VLCPlayerFullscreenChanged = @"VLCPlayerFullscreenChanged";
 NSString *VLCPlayerWallpaperModeChanged = @"VLCPlayerWallpaperModeChanged";
 NSString *VLCPlayerListOfVideoOutputThreadsChanged = @"VLCPlayerListOfVideoOutputThreadsChanged";
@@ -101,6 +103,8 @@ NSString *VLCPlayerMuteChanged = @"VLCPlayerMuteChanged";
 - (void)subtitlesFPSChanged:(float)subtitlesFPS;
 - (void)recordingChanged:(BOOL)recording;
 - (void)inputStatsUpdated:(VLCInputStats *)inputStats;
+- (void)trackSelectionChanged;
+- (void)trackListChanged;
 - (void)ABLoopStateChanged:(enum vlc_player_abloop)abLoopState;
 - (void)stopActionChanged:(enum vlc_player_media_stopped_action)stoppedAction;
 - (void)metaDataChangedForInput:(input_item_t *)inputItem;
@@ -331,6 +335,30 @@ static void cb_player_stats_changed(vlc_player_t *p_player,
     });
 }
 
+static void cb_player_track_list_changed(vlc_player_t *p_player,
+                                         enum vlc_player_list_action action,
+                                         const struct vlc_player_track *track,
+                                         void *p_data)
+{
+    VLC_UNUSED(p_player); VLC_UNUSED(action); VLC_UNUSED(track);
+    dispatch_async(dispatch_get_main_queue(), ^{
+        VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
+        [playerController trackListChanged];
+    });
+}
+
+static void cb_player_track_selection_changed(vlc_player_t *p_player,
+                                              vlc_es_id_t *unselected_id,
+                                              vlc_es_id_t *selected_id,
+                                              void *p_data)
+{
+    VLC_UNUSED(p_player); VLC_UNUSED(unselected_id); VLC_UNUSED(selected_id);
+    dispatch_async(dispatch_get_main_queue(), ^{
+        VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
+        [playerController trackSelectionChanged];
+    });
+}
+
 static void cb_player_atobloop_changed(vlc_player_t *p_player,
                                        enum vlc_player_abloop new_state,
                                        vlc_tick_t time, float pos,
@@ -388,8 +416,8 @@ static const struct vlc_player_cbs player_callbacks = {
     cb_player_capabilities_changed,
     cb_player_position_changed,
     cb_player_length_changed,
-    NULL, //cb_player_track_list_changed,
-    NULL, //cb_player_track_selection_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_titles_changed,
@@ -1228,6 +1256,114 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
                                             userInfo:@{VLCPlayerInputStats : inputStats}];
 }
 
+#pragma mark - track selection
+- (void)trackSelectionChanged
+{
+    [_defaultNotificationCenter postNotificationName:VLCPlayerTrackSelectionChanged object:self];
+}
+
+- (void)trackListChanged
+{
+    [_defaultNotificationCenter postNotificationName:VLCPlayerTrackListChanged object:nil];
+}
+
+- (void)selectTrack:(VLCTrackMetaData *)track
+{
+    vlc_player_Lock(_p_player);
+    vlc_player_SelectTrack(_p_player, track.esID);
+    vlc_player_Unlock(_p_player);
+}
+
+- (void)unselectTrack:(VLCTrackMetaData *)track
+{
+    vlc_player_Lock(_p_player);
+    vlc_player_UnselectTrack(_p_player, track.esID);
+    vlc_player_Unlock(_p_player);
+}
+
+- (void)unselectTracksFromCategory:(enum es_format_category_e)category
+{
+    vlc_player_Lock(_p_player);
+    vlc_player_UnselectTrackCategory(_p_player, category);
+    vlc_player_Unlock(_p_player);
+}
+
+- (void)selectPreviousTrackForCategory:(enum es_format_category_e)category
+{
+    vlc_player_Lock(_p_player);
+    vlc_player_SelectPrevTrack(_p_player, category);
+    vlc_player_Unlock(_p_player);
+}
+
+- (void)selectNextTrackForCategory:(enum es_format_category_e)category
+{
+    vlc_player_Lock(_p_player);
+    vlc_player_SelectNextTrack(_p_player, category);
+    vlc_player_Unlock(_p_player);
+}
+
+- (size_t)numberOfAudioTracks
+{
+    size_t ret = 0;
+    vlc_player_Lock(_p_player);
+    ret = vlc_player_GetTrackCount(_p_player, AUDIO_ES);
+    vlc_player_Unlock(_p_player);
+    return ret;
+}
+- (VLCTrackMetaData *)audioTrackAtIndex:(size_t)index
+{
+    VLCTrackMetaData *trackMetadata = [[VLCTrackMetaData alloc] init];
+    vlc_player_Lock(_p_player);
+    const struct vlc_player_track *track = vlc_player_GetTrackAt(_p_player, AUDIO_ES, index);
+    trackMetadata.esID = track->es_id;
+    trackMetadata.name = toNSStr(track->name);
+    trackMetadata.selected = track->selected;
+    vlc_player_Unlock(_p_player);
+    return trackMetadata;
+}
+
+- (size_t)numberOfVideoTracks
+{
+    size_t ret = 0;
+    vlc_player_Lock(_p_player);
+    ret = vlc_player_GetTrackCount(_p_player, VIDEO_ES);
+    vlc_player_Unlock(_p_player);
+    return ret;
+}
+
+- (VLCTrackMetaData *)videoTrackAtIndex:(size_t)index
+{
+    VLCTrackMetaData *trackMetadata = [[VLCTrackMetaData alloc] init];
+    vlc_player_Lock(_p_player);
+    const struct vlc_player_track *track = vlc_player_GetTrackAt(_p_player, VIDEO_ES, index);
+    trackMetadata.esID = track->es_id;
+    trackMetadata.name = toNSStr(track->name);
+    trackMetadata.selected = track->selected;
+    vlc_player_Unlock(_p_player);
+    return trackMetadata;
+}
+
+- (size_t)numberOfSubtitleTracks
+{
+    size_t ret = 0;
+    vlc_player_Lock(_p_player);
+    ret = vlc_player_GetTrackCount(_p_player, SPU_ES);
+    vlc_player_Unlock(_p_player);
+    return ret;
+}
+
+- (VLCTrackMetaData *)subtitleTrackAtIndex:(size_t)index
+{
+    VLCTrackMetaData *trackMetadata = [[VLCTrackMetaData alloc] init];
+    vlc_player_Lock(_p_player);
+    const struct vlc_player_track *track = vlc_player_GetTrackAt(_p_player, SPU_ES, index);
+    trackMetadata.esID = track->es_id;
+    trackMetadata.name = toNSStr(track->name);
+    trackMetadata.selected = track->selected;
+    vlc_player_Unlock(_p_player);
+    return trackMetadata;
+}
+
 - (void)ABLoopStateChanged:(enum vlc_player_abloop)abLoopState
 {
     _abLoopState = abLoopState;
@@ -1440,3 +1576,12 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
 @implementation VLCInputStats
 
 @end
+
+ at implementation VLCTrackMetaData
+
+- (NSString *)description
+{
+    return [NSString stringWithFormat:@"%@: name: %@", [VLCTrackMetaData className], self.name];
+}
+
+ at end



More information about the vlc-commits mailing list