[vlc-commits] service_discovery/bonjour: Parse Chromecast capabilities

Marvin Scholz git at videolan.org
Fri Feb 23 13:07:10 CET 2018


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Fri Feb 23 12:59:16 2018 +0100| [1a65ed99f51596f75e1bb288915518663077f6d4] | committer: Marvin Scholz

service_discovery/bonjour: Parse Chromecast capabilities

Add support for correctly parsing the Chromecast capability flags and
correctly set VLC_RENDERER_CAN_VIDEO/AUDIO based on those.

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

 modules/services_discovery/bonjour.m | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/modules/services_discovery/bonjour.m b/modules/services_discovery/bonjour.m
index f8f4388689..7ac57f6661 100644
--- a/modules/services_discovery/bonjour.m
+++ b/modules/services_discovery/bonjour.m
@@ -82,6 +82,14 @@ NSString *const VLCBonjourIsRenderer            = @"VLCBonjourIsRenderer";
 NSString *const VLCBonjourRendererFlags         = @"VLCBonjourRendererFlags";
 NSString *const VLCBonjourRendererDemux         = @"VLCBonjourRendererDemux";
 
+/*
+ * For chromecast, the `ca=` is composed from (at least)
+ * 0x01 to indicate video support
+ * 0x04 to indivate audio support
+ */
+#define CHROMECAST_FLAG_VIDEO 0x01
+#define CHROMECAST_FLAG_AUDIO 0x04
+
 #pragma mark -
 #pragma mark Interface definition
 @interface VLCNetServiceDiscoveryController : NSObject <NSNetServiceBrowserDelegate, NSNetServiceDelegate>
@@ -299,19 +307,39 @@ NSString *const VLCBonjourRendererDemux         = @"VLCBonjourRendererDemux";
     NSString *uri = [NSString stringWithFormat:@"%@://%@:%ld", protocol, netService.hostName, netService.port];
     NSDictionary *txtDict = [NSNetService dictionaryFromTXTRecordData:[netService TXTRecordData]];
     NSString *displayName = netService.name;
+    int rendererFlags = 0;
 
     if ([netService.type isEqualToString:@"_googlecast._tcp."]) {
         NSData *modelData = [txtDict objectForKey:@"md"];
         NSData *nameData = [txtDict objectForKey:@"fn"];
+        NSData *flagsData = [txtDict objectForKey:@"ca"];
+
+        // Get CC capability flags from TXT data
+        if (flagsData) {
+            NSString *flagsString = [[NSString alloc] initWithData:flagsData encoding:NSUTF8StringEncoding];
+            NSInteger flags = [flagsString intValue];
+
+            if ((flags & CHROMECAST_FLAG_VIDEO) != 0) {
+                rendererFlags |= VLC_RENDERER_CAN_VIDEO;
+            }
+            if ((flags & CHROMECAST_FLAG_AUDIO) != 0) {
+                rendererFlags |= VLC_RENDERER_CAN_AUDIO;
+            }
+        }
+
+        // Get CC model and name from TXT data
         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", [displayName UTF8String],
-                                                                 [uri UTF8String], NULL, "cc_demux",
+
+    const char *extra_uri = rendererFlags & VLC_RENDERER_CAN_VIDEO ? NULL : "no-video";
+
+    // TODO: Adapt to work with not just chromecast!
+    vlc_renderer_item_t *p_renderer_item = vlc_renderer_item_new("chromecast", [displayName UTF8String],
+                                                                 [uri UTF8String], extra_uri, "cc_demux",
                                                                  "", VLC_RENDERER_CAN_VIDEO );
     if (p_renderer_item != NULL) {
         vlc_rd_add_item( p_rd, p_renderer_item );



More information about the vlc-commits mailing list