Bladeren bron

Add method for getting stats from VLCMedia

Signed-off-by: Pierre d'Herbemont <pdherbemont@free.fr>
Rune Botten 14 jaren geleden
bovenliggende
commit
e5e0bb8169
2 gewijzigde bestanden met toevoegingen van 38 en 4 verwijderingen
  1. 9 3
      Headers/Public/VLCMedia.h
  2. 29 1
      Sources/VLCMedia.m

+ 9 - 3
Headers/Public/VLCMedia.h

@@ -332,15 +332,21 @@ extern NSString *VLCMediaTracksInformationTypeUnknown;
  */
 - (void)parse;
 
-/**************************************************************************
+/**
  * Add options to the media, that will be used to determine how
  * VLCMediaPlayer will read the media. This allow to use VLC advanced
  * reading/streaming options in a per-media basis
  *
  * The options are detailed in vlc --long-help, for instance "--sout-all"
  * And on the web: http://wiki.videolan.org/VLC_command-line_help
-
-**************************************************************************/
+*/
 - (void) addOptions:(NSDictionary*) options;
 
+/**
+ * Getter for statistics information
+ * Returns a NSDictionary with NSNumbers for values.
+ *
+ */
+- (NSDictionary*) stats;
+
 @end

+ 29 - 1
Sources/VLCMedia.m

@@ -240,7 +240,7 @@ static void HandleMediaParsedChanged(const libvlc_event_t * event, void * self)
     libvlc_event_detach(p_em, libvlc_MediaDurationChanged, HandleMediaDurationChanged, self);
     libvlc_event_detach(p_em, libvlc_MediaStateChanged,    HandleMediaStateChanged,    self);
     libvlc_event_detach(p_em, libvlc_MediaSubItemAdded,    HandleMediaSubItemAdded,    self);
-    libvlc_event_detach(p_em, libvlc_MediaParsedChanged,   HandleMediaParsedChanged,    self);
+    libvlc_event_detach(p_em, libvlc_MediaParsedChanged,   HandleMediaParsedChanged,   self);
     [[VLCEventManager sharedManager] cancelCallToObject:self];
 
     // Testing to see if the pointer exists is not required, if the pointer is null
@@ -338,6 +338,34 @@ static void HandleMediaParsedChanged(const libvlc_event_t * event, void * self)
     }
 }
 
+- (NSDictionary*) stats
+{
+    if(!p_md)
+        return NULL;
+
+    NSMutableDictionary *d = [NSMutableDictionary dictionary];
+    libvlc_media_stats_t p_stats;
+    libvlc_media_get_stats(p_md, &p_stats);
+
+    [d setObject:[NSNumber numberWithFloat: p_stats.f_demux_bitrate]       forKey:@"demuxBitrate"];
+    [d setObject:[NSNumber numberWithFloat: p_stats.f_input_bitrate]       forKey:@"inputBitrate"];
+    [d setObject:[NSNumber numberWithFloat: p_stats.f_send_bitrate]        forKey:@"sendBitrate"];
+    [d setObject:[NSNumber numberWithInt:   p_stats.i_decoded_audio]       forKey:@"decodedAudio"];
+    [d setObject:[NSNumber numberWithInt:   p_stats.i_decoded_video]       forKey:@"decodedVideo"];
+    [d setObject:[NSNumber numberWithInt:   p_stats.i_demux_corrupted]     forKey:@"demuxCorrupted"];
+    [d setObject:[NSNumber numberWithInt:   p_stats.i_demux_discontinuity] forKey:@"demuxDiscontinuity"];
+    [d setObject:[NSNumber numberWithInt:   p_stats.i_demux_read_bytes]    forKey:@"demuxReadBytes"];
+    [d setObject:[NSNumber numberWithInt:   p_stats.i_displayed_pictures]  forKey:@"displayedPictures"];
+    [d setObject:[NSNumber numberWithInt:   p_stats.i_lost_abuffers]       forKey:@"lostAbuffers"];
+    [d setObject:[NSNumber numberWithInt:   p_stats.i_lost_pictures]       forKey:@"lostPictures"];
+    [d setObject:[NSNumber numberWithInt:   p_stats.i_played_abuffers]     forKey:@"playedAbuffers"];
+    [d setObject:[NSNumber numberWithInt:   p_stats.i_read_bytes]          forKey:@"readBytes"];
+    [d setObject:[NSNumber numberWithInt:   p_stats.i_sent_bytes]          forKey:@"sentBytes"];
+    [d setObject:[NSNumber numberWithInt:   p_stats.i_sent_packets]        forKey:@"sentPackets"];
+
+    return d;
+}
+
 NSString *VLCMediaTracksInformationCodec = @"codec"; // NSNumber
 NSString *VLCMediaTracksInformationId    = @"id";    // NSNumber
 NSString *VLCMediaTracksInformationType  = @"type";  // NSString