开源代码:http://code.google.com/p/upnpx/
upnpx是一个支持dlna协议的局域网多媒体共享与播放控制的第三方框架。
http://upnp.org/sdcps-and-certification/resources/sdks/
Good UPnP documentation is available at at the website http://upnp.org. The architecture is described in the following document UPNP Device Architecture Document
A UPnP session exist of several steps:
- 0. Addressing
- 1. Discovery
- 2. Description
- 3. Control
- 4. Eventing
- 5. Presentation
upnpx is an implementation of the UPnP Specifications and has API functions for the different steps. This tutorial give simple examples how to use the upnpx API in order to build your own UPnP Control Point.
This tutorial handles the 6 individual steps and starts at Step 0. Addressing.
0. Addressing
{UPnP specifications: "Through addressing, devices and control points get a network address".}
Basically this means that your device has to get an IP address. Since the OS handles this task we are lucky and don't have to do much. Just be sure you actually are connected to the network and have an IP address before using upnpx.
Next Step 1. Discovery
1. Discovery
{UPnP specifications: "Through discovery, control points find interesting device(s)."}
During Discovery we will search for any UPnP device on the local network. upnpx implements the SSDP protocol (Simple Service Discovery Protocol) and maintains an in-memory database of all devices on the network, it will automatically update this database when new devices are added or removed. Your code can read the database and get notifications when an update is done.
Check the project ./upnpx/projects/xcode3/upnpxdemo/upnpxdemo.xcodeproj to see an example of a functional ssdp implementation:
Basically, there are 3 steps to complete to implement SSDP:
1. Implement the Interface UPnPDBObserver:
#import "UPnPDB.h" @interface RootViewController : UITableViewController <UPnPDBObserver>{ NSArray *mDevices; //BasicUPnPDevice* } //protocol UPnPDBObserver -(void)UPnPDBWillUpdate:(UPnPDB*)sender; -(void)UPnPDBUpdated:(UPnPDB*)sender;
2. Get a pointer to the discovery database via the UPnPManager, register yourself as an observer and tell the SSDP implementation to search for devices by calling searchSSDP:
- (void)viewDidLoad { [super viewDidLoad]; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; UPnPDB* db = [[UPnPManager GetInstance] DB]; mDevices = [db rootDevices]; //BasicUPnPDevice [mDevices retain]; [db addObserver:(UPnPDBObserver*)self]; //Optional; set User Agent [[[UPnPManager GetInstance] SSDP] setUserAgentProduct:@"upnpxdemo/1.0" andOS:@"OSX"]; //Search for UPnP Devices [[[UPnPManager GetInstance] SSDP] searchSSDP]; self.title = @"upnpx demo"; }