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

Marvin Scholz git at videolan.org
Fri Feb 23 13:26:35 CET 2018


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Fri Feb 23 12:59:16 2018 +0100| [ad7569610cd47253fc7216f5f8282734cf7f86f9] | 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=ad7569610cd47253fc7216f5f8282734cf7f86f9
---

 modules/services_discovery/bonjour.m | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/modules/services_discovery/bonjour.m b/modules/services_discovery/bonjour.m
index f8f4388689..71bf7d96c9 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,20 +307,40 @@ 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",
-                                                                 "", VLC_RENDERER_CAN_VIDEO );
+
+    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",
+                                                                 "", rendererFlags );
     if (p_renderer_item != NULL) {
         vlc_rd_add_item( p_rd, p_renderer_item );
         [_inputItemsForNetServices addObject:[NSValue valueWithPointer:p_renderer_item]];



More information about the vlc-commits mailing list