rd/bonjour: Use Chromecast name and model from TXT record
authorMarvin Scholz <epirat07@gmail.com>
Sat, 24 Jun 2017 18:15:26 +0000 (20:15 +0200)
committerMarvin Scholz <epirat07@gmail.com>
Sat, 1 Jul 2017 13:20:21 +0000 (15:20 +0200)
Extract the Chromecast name and model from the TXT records ("md", "fn")
and use them as name, if available, to make it easier to identify the
Chromecast.

modules/services_discovery/bonjour.m

index 03552ae..6f7261e 100644 (file)
@@ -301,9 +301,19 @@ NSString *const VLCBonjourRendererDemux         = @"VLCBonjourRendererDemux";
 
     NSString *uri = [NSString stringWithFormat:@"%@://%@:%ld", protocol, netService.hostName, netService.port];
     NSDictionary *txtDict = [NSNetService dictionaryFromTXTRecordData:[netService TXTRecordData]];
-
+    NSString *displayName = netService.name;
+
+    if ([netService.type isEqualToString:@"_googlecast._tcp."]) {
+        NSData *modelData = [txtDict objectForKey:@"md"];
+        NSData *nameData = [txtDict objectForKey:@"fn"];
+        if (modelData && nameData) {
+            NSString *model = [[NSString alloc] initWithData:modelData encoding:NSUTF8StringEncoding];
+            NSString *name = [[NSString alloc] initWithData:nameData encoding:NSUTF8StringEncoding];
+            displayName = [NSString stringWithFormat:@"%@ (%@)", name, model];
+        }
+    }
     // TODO: Detect rendered capabilities and adapt to work with not just chromecast
-    vlc_renderer_item_t *p_renderer_item = vlc_renderer_item_new( "chromecast", [netService.name UTF8String],
+    vlc_renderer_item_t *p_renderer_item = vlc_renderer_item_new( "chromecast", [displayName UTF8String],
                                                                  [uri UTF8String], NULL, "cc_demux",
                                                                  "", VLC_RENDERER_CAN_VIDEO );
     if (p_renderer_item != NULL) {