[vlc-commits] macosx/player controller: expose playback statistics

Felix Paul Kühne git at videolan.org
Sun Mar 10 19:56:07 CET 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sun Mar 10 19:53:13 2019 +0100| [0b0a571ef15fc8e335b4344690bd25d66b4606be] | committer: Felix Paul Kühne

macosx/player controller: expose playback statistics

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

 modules/gui/macosx/playlist/VLCPlayerController.h | 45 ++++++++++++++++++++
 modules/gui/macosx/playlist/VLCPlayerController.m | 51 ++++++++++++++++++++++-
 2 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/modules/gui/macosx/playlist/VLCPlayerController.h b/modules/gui/macosx/playlist/VLCPlayerController.h
index 2170292f57..aba0b0710d 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.h
+++ b/modules/gui/macosx/playlist/VLCPlayerController.h
@@ -25,6 +25,8 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
+ at class VLCInputStats;
+
 extern NSString *VLCPlayerCurrentMediaItem;
 /**
  * Listen to VLCPlayerCurrentMediaItemChanged to notified if the current media item changes for the player
@@ -120,6 +122,14 @@ extern NSString *VLCPlayerSubtitlesDelayChanged;
  */
 extern NSString *VLCPlayerRecordingChanged;
 
+extern NSString *VLCPlayerInputStats;
+/**
+ * Listen to VLCPlayerStatisticsUpdated to be notified if the playback statistics state of the current media update
+ * @note the affected player object will be the object of the notification
+ * @note the userInfo dictionary will have an instance of VLCInputStats for key VLCPlayerInputStats representating the new state
+ */
+extern NSString *VLCPlayerStatisticsUpdated;
+
 /**
  * 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
@@ -438,6 +448,13 @@ extern NSString *VLCPlayerMuteChanged;
  */
 - (void)toggleRecord;
 
+/**
+ * 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
+ */
+ at property (readonly) VLCInputStats *statistics;
+
 #pragma mark - video output properties
 
 /**
@@ -494,4 +511,32 @@ extern NSString *VLCPlayerMuteChanged;
 
 @end
 
+ at interface VLCInputStats : NSObject
+
+/* Input */
+ at property (readwrite) int64_t inputReadPackets;
+ at property (readwrite) int64_t inputReadBytes;
+ at property (readwrite) float inputBitrate;
+
+/* Demux */
+ at property (readwrite) int64_t demuxReadPackets;
+ at property (readwrite) int64_t demuxReadBytes;
+ at property (readwrite) float demuxBitrate;
+ at property (readwrite) int64_t demuxCorrupted;
+ at property (readwrite) int64_t demuxDiscontinuity;
+
+/* Decoders */
+ at property (readwrite) int64_t decodedAudio;
+ at property (readwrite) int64_t decodedVideo;
+
+/* Vout */
+ at property (readwrite) int64_t displayedPictures;
+ at property (readwrite) int64_t lostPictures;
+
+/* Aout */
+ at property (readwrite) int64_t playedAudioBuffers;
+ at property (readwrite) int64_t lostAudioBuffers;
+
+ at end
+
 NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.m b/modules/gui/macosx/playlist/VLCPlayerController.m
index 2112561881..60174da831 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.m
+++ b/modules/gui/macosx/playlist/VLCPlayerController.m
@@ -41,6 +41,8 @@ NSString *VLCPlayerAudioDelayChanged = @"VLCPlayerAudioDelayChanged";
 NSString *VLCPlayerSubtitlesDelayChanged = @"VLCPlayerSubtitlesDelayChanged";
 NSString *VLCPlayerSubtitleTextScalingFactorChanged = @"VLCPlayerSubtitleTextScalingFactorChanged";
 NSString *VLCPlayerRecordingChanged = @"VLCPlayerRecordingChanged";
+NSString *VLCPlayerInputStats = @"VLCPlayerInputStats";
+NSString *VLCPlayerStatisticsUpdated = @"VLCPlayerStatisticsUpdated";
 NSString *VLCPlayerFullscreenChanged = @"VLCPlayerFullscreenChanged";
 NSString *VLCPlayerWallpaperModeChanged = @"VLCPlayerWallpaperModeChanged";
 NSString *VLCPlayerVolumeChanged = @"VLCPlayerVolumeChanged";
@@ -70,6 +72,7 @@ NSString *VLCPlayerMuteChanged = @"VLCPlayerMuteChanged";
 - (void)audioDelayChanged:(vlc_tick_t)audioDelay;
 - (void)subtitlesDelayChanged:(vlc_tick_t)subtitlesDelay;
 - (void)recordingChanged:(BOOL)recording;
+- (void)inputStatsUpdated:(VLCInputStats *)inputStats;
 - (void)stopActionChanged:(enum vlc_player_media_stopped_action)stoppedAction;
 
 /* video */
@@ -218,6 +221,40 @@ static void cb_player_record_changed(vlc_player_t *p_player, bool recording, voi
     });
 }
 
+static void cb_player_stats_changed(vlc_player_t *p_player,
+                                    const struct input_stats_t *p_stats,
+                                    void *p_data)
+{
+    VLC_UNUSED(p_player);
+
+    /* the provided structure is valid in this context only, so copy all data to our own */
+    VLCInputStats *inputStats = [[VLCInputStats alloc] init];
+
+    inputStats.inputReadPackets = p_stats->i_read_packets;
+    inputStats.inputReadBytes = p_stats->i_read_bytes;
+    inputStats.inputBitrate = p_stats->f_input_bitrate;
+
+    inputStats.demuxReadPackets = p_stats->i_demux_read_packets;
+    inputStats.demuxReadBytes = p_stats->i_demux_read_bytes;
+    inputStats.demuxBitrate = p_stats->f_demux_bitrate;
+    inputStats.demuxCorrupted = p_stats->i_demux_corrupted;
+    inputStats.demuxDiscontinuity = p_stats->i_demux_discontinuity;
+
+    inputStats.decodedAudio = p_stats->i_decoded_audio;
+    inputStats.decodedVideo = p_stats->i_decoded_video;
+
+    inputStats.displayedPictures = p_stats->i_displayed_pictures;
+    inputStats.lostPictures = p_stats->i_lost_pictures;
+
+    inputStats.playedAudioBuffers = p_stats->i_played_abuffers;
+    inputStats.lostAudioBuffers = p_stats->i_lost_abuffers;
+
+    dispatch_async(dispatch_get_main_queue(), ^{
+        VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
+        [playerController inputStatsUpdated:inputStats];
+    });
+}
+
 static void cb_player_media_stopped_action_changed(vlc_player_t *p_player,
                                                    enum vlc_player_media_stopped_action newAction,
                                                    void *p_data)
@@ -251,7 +288,7 @@ static const struct vlc_player_cbs player_callbacks = {
     NULL, //cb_player_renderer_changed,
     cb_player_record_changed,
     NULL, //cb_player_signal_changed,
-    NULL, //cb_player_stats_changed,
+    cb_player_stats_changed,
     NULL, //cb_player_atobloop_changed,
     cb_player_media_stopped_action_changed,
     NULL, //cb_player_item_meta_changed,
@@ -727,6 +764,14 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
                                               object:self];
 }
 
+- (void)inputStatsUpdated:(VLCInputStats *)inputStats
+{
+    _statistics = inputStats;
+    [_defaultNotificationCenter postNotificationName:VLCPlayerStatisticsUpdated
+                                              object:self
+                                            userInfo:@{VLCPlayerInputStats : inputStats}];
+}
+
 - (void)setEnableRecording:(BOOL)enableRecording
 {
     vlc_player_Lock(_p_player);
@@ -819,3 +864,7 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
 }
 
 @end
+
+ at implementation VLCInputStats
+
+ at end



More information about the vlc-commits mailing list