[vlc-devel] [PATCH 1/2] macosx: Bonjour advertising for AirPlay support

Brendon Justin brendonjustin at gmail.com
Mon Feb 27 22:59:17 CET 2012


Tells Apple devices on the network that they can send video to VLC
via AirPlay.  Does not actually handle the AirPlay protocol.
---
 modules/lua/Modules.am             |   12 +++
 modules/lua/intf.c                 |    3 +
 modules/lua/libs.h                 |    8 ++-
 modules/lua/libs/airplay_bonjour.m |  174 ++++++++++++++++++++++++++++++++++++
 4 files changed, 195 insertions(+), 2 deletions(-)
 create mode 100644 modules/lua/libs/airplay_bonjour.m

diff --git a/modules/lua/Modules.am b/modules/lua/Modules.am
index a96b03f..7ff40e3 100644
--- a/modules/lua/Modules.am
+++ b/modules/lua/Modules.am
@@ -1,3 +1,8 @@
+# Automake forgets to add a proper tag to libtool with Objective-C files.
+# Moreover Libtool should default tag to CC when none is specified but
+# obviously does not. Here is a fix for that.
+LIBTOOL=@LIBTOOL@ --tag=CC
+
 SOURCES_lua = \
 	extension.c \
 	extension.h \
@@ -37,6 +42,8 @@ SOURCES_lua = \
 	libs/xml.c \
 	$(NULL)
 
+LDFLAGS_lua = 
+
 if HAVE_WIN32
 SOURCES_lua += libs/win.c
 else
@@ -45,4 +52,9 @@ SOURCES_lua += libs/win.c
 endif
 endif
 
+if HAVE_DARWIN
+SOURCES_lua += libs/airplay_bonjour.m
+LDFLAGS_lua += -Wl,-framework,Cocoa
+endif
+
 libvlc_LTLIBRARIES += liblua_plugin.la
diff --git a/modules/lua/intf.c b/modules/lua/intf.c
index f7f15b4..2a8fea8 100644
--- a/modules/lua/intf.c
+++ b/modules/lua/intf.c
@@ -257,6 +257,9 @@ static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
 #ifdef WIN32
     luaopen_win( L );
 #endif
+#ifdef __APPLE__
+    luaopen_airplay_bonjour( L );
+#endif
 
     /* clean up */
     lua_pop( L, 1 );
diff --git a/modules/lua/libs.h b/modules/lua/libs.h
index 2b54185..6d57b34 100644
--- a/modules/lua/libs.h
+++ b/modules/lua/libs.h
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * libs.h: VLC Lua wrapper libraries
  *****************************************************************************
- * Copyright (C) 2008 the VideoLAN team
+ * Copyright (C) 2008-2012 the VideoLAN team
  * $Id$
  *
- * Authors: Antoine Cellerier <dionoea at videolan tod org>
+ * Authors: Antoine Cellerier <dionoea at videolan tod org>,
+ *			Brendon Justin <brendonjustin at gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -49,5 +50,8 @@ void luaopen_equalizer( lua_State *L );
 #ifdef WIN32
 void luaopen_win( lua_State *L );
 #endif
+#ifdef __APPLE__
+void luaopen_airplay_bonjour( lua_State *L );
+#endif
 
 #endif
diff --git a/modules/lua/libs/airplay_bonjour.m b/modules/lua/libs/airplay_bonjour.m
new file mode 100644
index 0000000..f5d02e3
--- /dev/null
+++ b/modules/lua/libs/airplay_bonjour.m
@@ -0,0 +1,174 @@
+/*****************************************************************************
+ * airplay_bonjour.m: Broadcasts AirPlay support via bonjour
+ *****************************************************************************
+ * Copyright (C) 2012 the VideoLAN team and authors
+ * $Id$
+ *
+ * Authors: Brendon Justin <brendonjustin at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+
+#include "../vlc.h"
+#include "../libs.h"
+
+#import <Cocoa/Cocoa.h>
+
+/*****************************************************************************
+ * AirplayAnnouncer Helper Class Definition
+ *****************************************************************************/
+
+/*
+Port used for AirPlay support. 6002 is the same port that Airplayer uses,
+but VLC's HTTP server uses 8080 by default, so that's what is used here.
+*/
+#define AIRPLAY_PORT 8080
+
+/*
+The name by which VLC will identify itself to other AirPlay
+devices. @"" will use the system hostname automatically.
+*/
+#define AIRPLAY_HOSTNAME @"VLC"
+
+ at interface AirplayAnnouncer : NSObject <NSNetServiceDelegate>
+{
+    NSNetService *apService;
+    int port;
+    NSMutableArray *services;
+}
+
+- (void)register_bonjour;
+- (void)start;
+- (void)stop;
+
+ at end
+
+/*****************************************************************************
+ * AirplayAnnouncer Helper Class Implementation
+ *****************************************************************************/
+
+ at implementation AirplayAnnouncer
+
+- (id)init 
+{
+    if ((self = [super init]))
+        //  The port used to receive video
+        port = AIRPLAY_PORT;
+    return self;
+}
+
+- (void)dealloc
+{
+    [self stop];
+    [services release];
+    [super dealloc];
+}
+
+- (void)start
+{
+    [self register_bonjour];
+}
+
+- (void)stop
+{
+    for (NSNetService *service in services)
+    {
+        [service stop];
+    }
+}
+
+- (void)register_bonjour
+{
+    apService = [[NSNetService alloc] initWithDomain:@"local."
+                                              type:@"_airplay._tcp"
+                                              name:AIRPLAY_HOSTNAME port:port];
+
+    NSArray *recordObjs = [NSArray arrayWithObjects:@"00:00:00:00:00:00", @"0x77", @"AppleTV2,1", @"101.10", nil];
+    NSArray *recordKeys = [NSArray arrayWithObjects:@"deviceid", @"features", @"model", @"srcvers", nil];
+
+    NSDictionary *txtRecordDict;
+    txtRecordDict = [NSDictionary dictionaryWithObjects:recordObjs
+                                                forKeys:recordKeys];
+    [apService setTXTRecordData:[NSNetService dataFromTXTRecordDictionary:txtRecordDict]];
+
+    if(apService)
+    {
+        [apService setDelegate:self];
+        [apService publish];
+    }
+}
+
+#pragma mark -
+#pragma mark NSNetServiceDelegate functions
+
+// Sent when the service is successfully published
+- (void)netServiceDidPublish:(NSNetService *)netService
+{
+    [services addObject:netService];
+}
+
+ at end
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+
+static int vlclua_airplay_bonjour_register( lua_State * );
+static int vlclua_airplay_bonjour_delete( lua_State * );
+
+/*****************************************************************************
+ * AirPlay Support Broadcaster
+ *****************************************************************************/
+ 
+static int vlclua_airplay_bonjour_register( lua_State *L )
+{
+	vlc_object_t *p_this = vlclua_get_this( L );
+	AirplayAnnouncer *p_announcer = [[AirplayAnnouncer alloc] init];
+    [p_announcer start];
+
+    AirplayAnnouncer **pp_announcer = lua_newuserdata( L, sizeof( AirplayAnnouncer *) );
+    *pp_announcer = p_announcer;
+
+    if( luaL_newmetatable( L, "airplay_bonjour_announcer" ) )
+    {
+    	lua_newtable( L );
+        lua_pushcfunction( L, vlclua_airplay_bonjour_delete );
+        lua_setfield( L, -2, "__gc" );
+    }
+    
+    lua_setmetatable( L, -2 );
+    return 1;
+}
+
+static int vlclua_airplay_bonjour_delete( lua_State *L )
+{
+	AirplayAnnouncer **pp_announcer = (AirplayAnnouncer **)luaL_checkudata( L, 1, "airplay_bonjour_announcer" );
+	[*pp_announcer stop];
+	[*pp_announcer release];
+	return 0;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+void luaopen_airplay_bonjour( lua_State *L )
+{
+    lua_pushcfunction( L, vlclua_airplay_bonjour_register );
+    lua_setfield( L, -2, "airplay_bonjour" );
+}
-- 
1.7.7.5 (Apple Git-26)




More information about the vlc-devel mailing list