返回

设计手机投屏安卓app(2)

苹果macOS、iOS设备自动发现

设备自动发现功能包括设备接入网络后,自动申报自己的名称,提供哪些服务等.

Bonjour for macOS and iOS

Bonjour, also known as zero-configuration networking, enables automatic discovery of devices and services on a local network using industry standard IP protocols. Bonjour makes it easy to discover, publish, and resolve network services with a sophisticated, easy-to-use programming interface that is accessible from Cocoa, Ruby, Python, and other languages.

Bonjour is not only based on open Internet standards, our implementation is also available as Open Source under the Apache 2.0 license. It is built into most modern printers and many other consumer products.

苹果AirPlay 设备,比如Apple TV通过Bonjour发布自己的两个服务:

  • RAOP
    name value description
    txtvers 1 TXT record version 1
    ch 2 audio channels: stereo
    cn 0,1,2,3 audio codecs
    et 0,3,5 supported encryption types
    md 0,1,2 supported metadata types
    pw false does the speaker require a password?
    sr 44100 audio sample rate: 44100 Hz
    ss 16 audio sample size: 16-bit
    tp UDP supported transport: TCP or UDP
    vs 130.14 server version 130.14
    am AppleTV2,1 device model

java

TXTRecord txtRecord = new TXTRecord();
txtRecord.set("ch", "2");
txtRecord.set("cn", "0,1,2,3");
txtRecord.set("da", "true");
txtRecord.set("et", "0,3,5");
txtRecord.set("vv", "2");
txtRecord.set("ft", "0x5A7FFFF7,0x1E");
txtRecord.set("am", "AppleTV2,1");
txtRecord.set("md", "0,1,2");
txtRecord.set("rhd", "5.6.0.0");
txtRecord.set("pw", "false");
txtRecord.set("sr", "44100");
txtRecord.set("ss", "16");
txtRecord.set("sv", "false");
txtRecord.set("tp", "UDP");
txtRecord.set("txtvers", "1");
txtRecord.set("sf", "0x4");
txtRecord.set("vs", "220.68");
txtRecord.set("vn", "65537");
txtRecord.set("pk", "b07727d6f6cd6e08b58ede525ec3cdeaa252ad9f683feb212ef8a205246554e7");
mRaopRegister = new Register(txtRecord, mDeviceName, "_raop._tcp", "local.", "", 49152);
  • AirPlay service
    name value description
    model AppleTV2,1 device model
    deviceid 58:55:CA:1A:E2:88 MAC address of the device
    features 0x39f7 bitfield of supported features
    pw 1 server is password protected

其中features具体含义如下:

bit name description
0 Video video supported
1 Photo photo supported
2 VideoFairPlay video protected with FairPlay DRM
3 VideoVolumeControl volume control supported for videos
4 VideoHTTPLiveStreams http live streaming supported
5 Slideshow slideshow supported
7 Screen mirroring supported
8 ScreenRotate screen rotation supported
9 Audio audio supported
11 AudioRedundant audio packet redundancy supported
12 FPSAPv2pt5_AES_GCM FairPlay secure auth supported
13 PhotoCaching photo preloading supported

java

TXTRecord txtRecord = new TXTRecord();
txtRecord.set("deviceid", mMacAddress);
txtRecord.set("features", "0x5A7FFFF7,0x1E");
txtRecord.set("srcvers", "220.68");
txtRecord.set("flags", "0x4");
txtRecord.set("vv", "2");
txtRecord.set("model", "AppleTV2,1");
txtRecord.set("pw", "false");
txtRecord.set("rhd", "5.6.0.0");
txtRecord.set("pk", "b07727d6f6cd6e08b58ede525ec3cdeaa252ad9f683feb212ef8a205246554e7");
txtRecord.set("pi", "2e388006-13ba-4041-9a67-25dd4a43d536");
this.mAirplayRegister = new Register(txtRecord, this.mDeviceName, "_airplay._tcp", "local.", "", 7000);