├── PhoneMiracast ├── src │ ├── javax │ │ └── jmdns │ │ │ ├── impl │ │ │ ├── package-info.java │ │ │ ├── tasks │ │ │ │ ├── package-info.java │ │ │ │ ├── state │ │ │ │ │ ├── package-info.java │ │ │ │ │ ├── Canceler.java │ │ │ │ │ ├── Renewer.java │ │ │ │ │ └── Announcer.java │ │ │ │ ├── resolver │ │ │ │ │ ├── package-info.java │ │ │ │ │ ├── TypeResolver.java │ │ │ │ │ ├── ServiceResolver.java │ │ │ │ │ ├── DNSResolverTask.java │ │ │ │ │ └── ServiceInfoResolver.java │ │ │ │ └── RecordReaper.java │ │ │ ├── constants │ │ │ │ ├── package-info.java │ │ │ │ ├── DNSOptionCode.java │ │ │ │ ├── DNSOperationCode.java │ │ │ │ ├── DNSLabel.java │ │ │ │ ├── DNSRecordClass.java │ │ │ │ ├── DNSResultCode.java │ │ │ │ └── DNSConstants.java │ │ │ ├── DNSListener.java │ │ │ ├── util │ │ │ │ └── NamedThreadFactory.java │ │ │ ├── NetworkTopologyEventImpl.java │ │ │ ├── SocketListener.java │ │ │ ├── ServiceEventImpl.java │ │ │ └── NetworkTopologyDiscoveryImpl.java │ │ │ ├── package-info.java │ │ │ ├── NetworkTopologyListener.java │ │ │ ├── ServiceTypeListener.java │ │ │ ├── NetworkTopologyEvent.java │ │ │ ├── ServiceListener.java │ │ │ └── ServiceEvent.java │ └── com │ │ ├── milink │ │ ├── milink │ │ │ ├── contants │ │ │ │ ├── Xmlns.java │ │ │ │ └── miracast │ │ │ │ │ ├── Actions.java │ │ │ │ │ └── Events.java │ │ │ ├── server │ │ │ │ ├── MiLinkServerListener.java │ │ │ │ └── MiLinkServer.java │ │ │ └── client │ │ │ │ ├── MiLinkClientListener.java │ │ │ │ └── MiLinkClient.java │ │ ├── net │ │ │ └── asio │ │ │ │ └── tcp │ │ │ │ ├── client │ │ │ │ ├── TcpPacket.java │ │ │ │ └── TcpClientListener.java │ │ │ │ └── server │ │ │ │ ├── TcpServerListener.java │ │ │ │ ├── TcpPacket.java │ │ │ │ ├── TcpConn.java │ │ │ │ └── TcpConnPool.java │ │ ├── bonjour │ │ │ ├── serviceinfo │ │ │ │ ├── BonjourServiceInfo.java │ │ │ │ ├── DacpServiceInfo.java │ │ │ │ ├── MiLinkServiceInfo.java │ │ │ │ ├── AirPlayServiceInfo.java │ │ │ │ └── AirTunesServiceInfo.java │ │ │ └── BonjourListener.java │ │ └── miracast │ │ │ └── ScreenMirroring.java │ │ └── test │ │ └── miracast │ │ └── ParamStart.java ├── ic_launcher-web.png ├── libs │ └── armeabi │ │ └── libmiracast.so ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── menu │ │ └── main.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── layout │ │ └── activity_main.xml ├── Android.mk ├── project.properties ├── proguard-project.txt └── AndroidManifest.xml ├── TVMiracast ├── src │ ├── javax │ │ └── jmdns │ │ │ ├── impl │ │ │ ├── package-info.java │ │ │ ├── tasks │ │ │ │ ├── package-info.java │ │ │ │ ├── state │ │ │ │ │ ├── package-info.java │ │ │ │ │ ├── Canceler.java │ │ │ │ │ ├── Renewer.java │ │ │ │ │ └── Announcer.java │ │ │ │ ├── resolver │ │ │ │ │ ├── package-info.java │ │ │ │ │ ├── TypeResolver.java │ │ │ │ │ ├── ServiceResolver.java │ │ │ │ │ ├── DNSResolverTask.java │ │ │ │ │ └── ServiceInfoResolver.java │ │ │ │ └── RecordReaper.java │ │ │ ├── constants │ │ │ │ ├── package-info.java │ │ │ │ ├── DNSOptionCode.java │ │ │ │ ├── DNSOperationCode.java │ │ │ │ ├── DNSLabel.java │ │ │ │ ├── DNSRecordClass.java │ │ │ │ └── DNSResultCode.java │ │ │ ├── DNSListener.java │ │ │ ├── util │ │ │ │ └── NamedThreadFactory.java │ │ │ ├── NetworkTopologyEventImpl.java │ │ │ ├── SocketListener.java │ │ │ ├── ServiceEventImpl.java │ │ │ └── NetworkTopologyDiscoveryImpl.java │ │ │ ├── package-info.java │ │ │ ├── NetworkTopologyListener.java │ │ │ ├── ServiceTypeListener.java │ │ │ ├── NetworkTopologyEvent.java │ │ │ ├── ServiceListener.java │ │ │ └── ServiceEvent.java │ └── com │ │ ├── milink │ │ ├── milink │ │ │ ├── contants │ │ │ │ ├── Xmlns.java │ │ │ │ └── miracast │ │ │ │ │ ├── Actions.java │ │ │ │ │ └── Events.java │ │ │ ├── server │ │ │ │ ├── MiLinkServerListener.java │ │ │ │ └── MiLinkServer.java │ │ │ └── client │ │ │ │ ├── MiLinkClientListener.java │ │ │ │ └── MiLinkClient.java │ │ ├── net │ │ │ └── asio │ │ │ │ └── tcp │ │ │ │ ├── client │ │ │ │ ├── TcpPacket.java │ │ │ │ └── TcpClientListener.java │ │ │ │ └── server │ │ │ │ ├── TcpServerListener.java │ │ │ │ ├── TcpPacket.java │ │ │ │ ├── TcpConn.java │ │ │ │ └── TcpConnPool.java │ │ └── bonjour │ │ │ ├── serviceinfo │ │ │ ├── BonjourServiceInfo.java │ │ │ ├── DacpServiceInfo.java │ │ │ ├── MiLinkServiceInfo.java │ │ │ ├── AirPlayServiceInfo.java │ │ │ └── AirTunesServiceInfo.java │ │ │ └── BonjourListener.java │ │ └── test │ │ └── miracast │ │ └── ParamStart.java ├── ic_launcher-web.png ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── menu │ │ └── main.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── layout │ │ └── activity_main.xml ├── Android.mk ├── .classpath ├── project.properties ├── proguard-project.txt ├── .project └── AndroidManifest.xml └── README.md /PhoneMiracast/src/javax/jmdns/impl/package-info.java: -------------------------------------------------------------------------------- 1 | package javax.jmdns.impl; 2 | 3 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/package-info.java: -------------------------------------------------------------------------------- 1 | package javax.jmdns.impl; 2 | 3 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/tasks/package-info.java: -------------------------------------------------------------------------------- 1 | package javax.jmdns.impl.tasks; 2 | 3 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/tasks/package-info.java: -------------------------------------------------------------------------------- 1 | package javax.jmdns.impl.tasks; 2 | 3 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/constants/package-info.java: -------------------------------------------------------------------------------- 1 | package javax.jmdns.impl.constants; 2 | 3 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/constants/package-info.java: -------------------------------------------------------------------------------- 1 | package javax.jmdns.impl.constants; 2 | 3 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/tasks/state/package-info.java: -------------------------------------------------------------------------------- 1 | package javax.jmdns.impl.tasks.state; 2 | 3 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/tasks/state/package-info.java: -------------------------------------------------------------------------------- 1 | package javax.jmdns.impl.tasks.state; 2 | 3 | -------------------------------------------------------------------------------- /TVMiracast/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackerMi/miracast/HEAD/TVMiracast/ic_launcher-web.png -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/tasks/resolver/package-info.java: -------------------------------------------------------------------------------- 1 | package javax.jmdns.impl.tasks.resolver; 2 | 3 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/tasks/resolver/package-info.java: -------------------------------------------------------------------------------- 1 | package javax.jmdns.impl.tasks.resolver; 2 | 3 | -------------------------------------------------------------------------------- /PhoneMiracast/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackerMi/miracast/HEAD/PhoneMiracast/ic_launcher-web.png -------------------------------------------------------------------------------- /PhoneMiracast/libs/armeabi/libmiracast.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackerMi/miracast/HEAD/PhoneMiracast/libs/armeabi/libmiracast.so -------------------------------------------------------------------------------- /TVMiracast/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackerMi/miracast/HEAD/TVMiracast/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /TVMiracast/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackerMi/miracast/HEAD/TVMiracast/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /TVMiracast/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackerMi/miracast/HEAD/TVMiracast/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /PhoneMiracast/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackerMi/miracast/HEAD/PhoneMiracast/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /PhoneMiracast/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackerMi/miracast/HEAD/PhoneMiracast/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /TVMiracast/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackerMi/miracast/HEAD/TVMiracast/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /PhoneMiracast/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackerMi/miracast/HEAD/PhoneMiracast/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /PhoneMiracast/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackerMi/miracast/HEAD/PhoneMiracast/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/milink/contants/Xmlns.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.contants; 3 | 4 | public class Xmlns { 5 | 6 | public static final String MIRACAST = "http://www.xiaomi.com/milink/miracast"; 7 | } 8 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/milink/contants/Xmlns.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.contants; 3 | 4 | public class Xmlns { 5 | 6 | public static final String MIRACAST = "http://www.xiaomi.com/milink/miracast"; 7 | } 8 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/milink/contants/miracast/Actions.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.contants.miracast; 3 | 4 | public class Actions { 5 | 6 | public static final String START = "start"; 7 | public static final String STOP = "stop"; 8 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/milink/contants/miracast/Actions.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.contants.miracast; 3 | 4 | public class Actions { 5 | 6 | public static final String START = "start"; 7 | public static final String STOP = "stop"; 8 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | this project is google miracast simple implement. 2 | Qualcomm implement can also work. 3 | Usage: 4 | 1. copy the directory of PhoneMiracast and TVMiracast to /project/package/apps/ 5 | 2. enter the directory and use command "mm" to complie it. 6 | -------------------------------------------------------------------------------- /TVMiracast/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /PhoneMiracast/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /TVMiracast/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /PhoneMiracast/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /TVMiracast/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TVMiracast 5 | Settings 6 | Hello world! 7 | 8 | 9 | -------------------------------------------------------------------------------- /TVMiracast/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /PhoneMiracast/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/milink/contants/miracast/Events.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.contants.miracast; 3 | 4 | public class Events { 5 | 6 | public static final String LOADING = "loading"; 7 | public static final String PLAYING = "playing"; 8 | public static final String STOPPED = "stopped"; 9 | } 10 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/milink/contants/miracast/Events.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.contants.miracast; 3 | 4 | public class Events { 5 | 6 | public static final String LOADING = "loading"; 7 | public static final String PLAYING = "playing"; 8 | public static final String STOPPED = "stopped"; 9 | } 10 | -------------------------------------------------------------------------------- /PhoneMiracast/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PhoneMiracast 5 | Settings 6 | Hello world! 7 | 推送 8 | 9 | 10 | -------------------------------------------------------------------------------- /PhoneMiracast/res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /TVMiracast/res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/net/asio/tcp/client/TcpPacket.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.net.asio.tcp.client; 3 | 4 | public class TcpPacket { 5 | 6 | public enum Type { 7 | Unknown, 8 | Exit, 9 | Receive, 10 | Send, 11 | }; 12 | 13 | public Type type = Type.Unknown; 14 | public byte[] data = null; 15 | } 16 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/net/asio/tcp/client/TcpPacket.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.net.asio.tcp.client; 3 | 4 | public class TcpPacket { 5 | 6 | public enum Type { 7 | Unknown, 8 | Exit, 9 | Receive, 10 | Send, 11 | }; 12 | 13 | public Type type = Type.Unknown; 14 | public byte[] data = null; 15 | } 16 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/bonjour/serviceinfo/BonjourServiceInfo.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.bonjour.serviceinfo; 3 | 4 | import java.util.Map; 5 | 6 | public interface BonjourServiceInfo { 7 | 8 | String getServiceName(); 9 | 10 | int getServicePort(); 11 | 12 | String getServiceType(); 13 | 14 | Map getProperties(); 15 | } 16 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/bonjour/serviceinfo/BonjourServiceInfo.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.bonjour.serviceinfo; 3 | 4 | import java.util.Map; 5 | 6 | public interface BonjourServiceInfo { 7 | 8 | String getServiceName(); 9 | 10 | int getServicePort(); 11 | 12 | String getServiceType(); 13 | 14 | Map getProperties(); 15 | } 16 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/net/asio/tcp/server/TcpServerListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.net.asio.tcp.server; 3 | 4 | public interface TcpServerListener { 5 | 6 | void onAccept(TcpServer server, TcpConn conn); 7 | 8 | void onReceived(TcpServer server, TcpConn conn, byte[] data); 9 | 10 | void onConnectionClosed(TcpServer server, TcpConn conn); 11 | } 12 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/net/asio/tcp/server/TcpServerListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.net.asio.tcp.server; 3 | 4 | public interface TcpServerListener { 5 | 6 | void onAccept(TcpServer server, TcpConn conn); 7 | 8 | void onReceived(TcpServer server, TcpConn conn, byte[] data); 9 | 10 | void onConnectionClosed(TcpServer server, TcpConn conn); 11 | } 12 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/net/asio/tcp/client/TcpClientListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.net.asio.tcp.client; 3 | 4 | public interface TcpClientListener { 5 | 6 | void onConnected(TcpClient client); 7 | 8 | void onConnectedFailed(TcpClient client); 9 | 10 | void onDisconnect(TcpClient client); 11 | 12 | void onReceived(TcpClient client, byte[] data); 13 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/net/asio/tcp/client/TcpClientListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.net.asio.tcp.client; 3 | 4 | public interface TcpClientListener { 5 | 6 | void onConnected(TcpClient client); 7 | 8 | void onConnectedFailed(TcpClient client); 9 | 10 | void onDisconnect(TcpClient client); 11 | 12 | void onReceived(TcpClient client, byte[] data); 13 | } -------------------------------------------------------------------------------- /TVMiracast/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /PhoneMiracast/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_MODULE_TAGS := optional 5 | 6 | LOCAL_SRC_FILES := $(call all-java-files-under, src) 7 | 8 | LOCAL_JAVA_LIBRARIES := framework 9 | 10 | LOCAL_PACKAGE_NAME := PhoneMiracast 11 | 12 | LOCAL_CERTIFICATE := platform 13 | 14 | LOCAL_PROGUARD_ENABLED := disabled 15 | 16 | include $(BUILD_PACKAGE) 17 | -------------------------------------------------------------------------------- /PhoneMiracast/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/net/asio/tcp/server/TcpPacket.java: -------------------------------------------------------------------------------- 1 | package com.milink.net.asio.tcp.server; 2 | 3 | public class TcpPacket { 4 | 5 | public enum Type { 6 | Unknown, 7 | Exit, 8 | Accept, 9 | Closed, 10 | Receive, 11 | Send, 12 | }; 13 | 14 | public Type type = Type.Unknown; 15 | public byte[] data = null; 16 | public TcpConn conn = null; 17 | } -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/net/asio/tcp/server/TcpPacket.java: -------------------------------------------------------------------------------- 1 | package com.milink.net.asio.tcp.server; 2 | 3 | public class TcpPacket { 4 | 5 | public enum Type { 6 | Unknown, 7 | Exit, 8 | Accept, 9 | Closed, 10 | Receive, 11 | Send, 12 | }; 13 | 14 | public Type type = Type.Unknown; 15 | public byte[] data = null; 16 | public TcpConn conn = null; 17 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/milink/server/MiLinkServerListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.server; 3 | 4 | import com.milink.milink.common.IQ; 5 | 6 | public interface MiLinkServerListener { 7 | 8 | void onAccept(MiLinkServer server, String ip, int port); 9 | 10 | void onReceived(MiLinkServer server, String ip, int port, IQ iq); 11 | 12 | void onConnectionClosed(MiLinkServer server, String ip, int port); 13 | } -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/milink/server/MiLinkServerListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.server; 3 | 4 | import com.milink.milink.common.IQ; 5 | 6 | public interface MiLinkServerListener { 7 | 8 | void onAccept(MiLinkServer server, String ip, int port); 9 | 10 | void onReceived(MiLinkServer server, String ip, int port, IQ iq); 11 | 12 | void onConnectionClosed(MiLinkServer server, String ip, int port); 13 | } -------------------------------------------------------------------------------- /TVMiracast/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_MODULE_TAGS := optional 5 | 6 | LOCAL_SRC_FILES := $(call all-java-files-under, src) 7 | 8 | LOCAL_JAVA_LIBRARIES := framework 9 | 10 | LOCAL_PACKAGE_NAME := TVMiracast 11 | 12 | LOCAL_CERTIFICATE := platform 13 | 14 | #LOCAL_JNI_SHARED_LIBRARIES := libctsverifier_jni 15 | 16 | LOCAL_PROGUARD_ENABLED := disabled 17 | 18 | include $(BUILD_PACKAGE) 19 | -------------------------------------------------------------------------------- /TVMiracast/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /PhoneMiracast/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/milink/client/MiLinkClientListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.client; 3 | 4 | import com.milink.milink.common.IQ; 5 | 6 | public interface MiLinkClientListener { 7 | 8 | void onConnected(MiLinkClient client); 9 | 10 | void onConnectedFailed(MiLinkClient client); 11 | 12 | void onDisconnect(MiLinkClient client); 13 | 14 | void onReceived(MiLinkClient client, IQ iq); 15 | 16 | void onEvent(MiLinkClient client, IQ iq); 17 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/milink/client/MiLinkClientListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.client; 3 | 4 | import com.milink.milink.common.IQ; 5 | 6 | public interface MiLinkClientListener { 7 | 8 | void onConnected(MiLinkClient client); 9 | 10 | void onConnectedFailed(MiLinkClient client); 11 | 12 | void onDisconnect(MiLinkClient client); 13 | 14 | void onReceived(MiLinkClient client, IQ iq); 15 | 16 | void onEvent(MiLinkClient client, IQ iq); 17 | } -------------------------------------------------------------------------------- /TVMiracast/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/bonjour/BonjourListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.bonjour; 3 | 4 | import java.util.Map; 5 | 6 | public interface BonjourListener { 7 | 8 | void onStarted(); 9 | 10 | void onStartFailed(); 11 | 12 | void onStopped(); 13 | 14 | void onServiceFound( 15 | String name, 16 | String type, 17 | String ip, 18 | int port, 19 | Map properties); 20 | 21 | void onServiceLost(String name, String type, String ip); 22 | } 23 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/bonjour/BonjourListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.bonjour; 3 | 4 | import java.util.Map; 5 | 6 | public interface BonjourListener { 7 | 8 | void onStarted(); 9 | 10 | void onStartFailed(); 11 | 12 | void onStopped(); 13 | 14 | void onServiceFound( 15 | String name, 16 | String type, 17 | String ip, 18 | int port, 19 | Map properties); 20 | 21 | void onServiceLost(String name, String type, String ip); 22 | } 23 | -------------------------------------------------------------------------------- /PhoneMiracast/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /TVMiracast/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | -------------------------------------------------------------------------------- /PhoneMiracast/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/package-info.java: -------------------------------------------------------------------------------- 1 | package javax.jmdns; 2 | 3 | /** 4 | * JmDNS is a Java implementation of multi-cast DNS and can be used for service registration and discovery in local area networks. JmDNS is fully compatible with Apple's Bonjour. The project was originally started in December 2002 by Arthur van Hoff 5 | * at Strangeberry. In November 2003 the project was moved to SourceForge, and the name was changed from JRendezvous to JmDNS for legal reasons. Many thanks to Stuart Cheshire for help and moral support. 6 | *

7 | * http://jmdns.sourceforge.net/ 8 | *

9 | **/ 10 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/package-info.java: -------------------------------------------------------------------------------- 1 | package javax.jmdns; 2 | 3 | /** 4 | * JmDNS is a Java implementation of multi-cast DNS and can be used for service registration and discovery in local area networks. JmDNS is fully compatible with Apple's Bonjour. The project was originally started in December 2002 by Arthur van Hoff 5 | * at Strangeberry. In November 2003 the project was moved to SourceForge, and the name was changed from JRendezvous to JmDNS for legal reasons. Many thanks to Stuart Cheshire for help and moral support. 6 | *

7 | * http://jmdns.sourceforge.net/ 8 | *

9 | **/ 10 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/net/asio/tcp/server/TcpConn.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.net.asio.tcp.server; 3 | 4 | import java.nio.channels.SocketChannel; 5 | 6 | public class TcpConn { 7 | 8 | private SocketChannel mChannel = null; 9 | private String mIp = null; 10 | private int mPort = 0; 11 | 12 | public TcpConn(String ip, int port, SocketChannel channel) { 13 | mIp = ip; 14 | mPort = port; 15 | mChannel = channel; 16 | } 17 | 18 | public SocketChannel getChannel() { 19 | return mChannel; 20 | } 21 | 22 | public String getIp() { 23 | return mIp; 24 | } 25 | 26 | public int getPort() { 27 | return mPort; 28 | } 29 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/net/asio/tcp/server/TcpConn.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.net.asio.tcp.server; 3 | 4 | import java.nio.channels.SocketChannel; 5 | 6 | public class TcpConn { 7 | 8 | private SocketChannel mChannel = null; 9 | private String mIp = null; 10 | private int mPort = 0; 11 | 12 | public TcpConn(String ip, int port, SocketChannel channel) { 13 | mIp = ip; 14 | mPort = port; 15 | mChannel = channel; 16 | } 17 | 18 | public SocketChannel getChannel() { 19 | return mChannel; 20 | } 21 | 22 | public String getIp() { 23 | return mIp; 24 | } 25 | 26 | public int getPort() { 27 | return mPort; 28 | } 29 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/miracast/ScreenMirroring.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.miracast; 3 | 4 | public class ScreenMirroring { 5 | 6 | private static final String TAG = ScreenMirroring.class.getSimpleName(); 7 | 8 | static { 9 | System.loadLibrary("miracast"); 10 | } 11 | 12 | private static final ScreenMirroring single = new ScreenMirroring(); 13 | 14 | public static ScreenMirroring getInstance() { 15 | return single; 16 | } 17 | 18 | private ScreenMirroring() { 19 | } 20 | 21 | @Override 22 | protected void finalize() throws Throwable { 23 | super.finalize(); 24 | } 25 | 26 | public native int start(String ip, int port); 27 | 28 | public native int stop(); 29 | } 30 | -------------------------------------------------------------------------------- /TVMiracast/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /PhoneMiracast/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/DNSListener.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl; 6 | 7 | // REMIND: Listener should follow Java idiom for listener or have a different 8 | // name. 9 | 10 | /** 11 | * DNSListener. Listener for record updates. 12 | * 13 | * @author Werner Randelshofer, Rick Blair 14 | * @version 1.0 May 22, 2004 Created. 15 | */ 16 | interface DNSListener { 17 | /** 18 | * Update a DNS record. 19 | * 20 | * @param dnsCache 21 | * record cache 22 | * @param now 23 | * update date 24 | * @param record 25 | * DNS record 26 | */ 27 | void updateRecord(DNSCache dnsCache, long now, DNSEntry record); 28 | } 29 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/DNSListener.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl; 6 | 7 | // REMIND: Listener should follow Java idiom for listener or have a different 8 | // name. 9 | 10 | /** 11 | * DNSListener. Listener for record updates. 12 | * 13 | * @author Werner Randelshofer, Rick Blair 14 | * @version 1.0 May 22, 2004 Created. 15 | */ 16 | interface DNSListener { 17 | /** 18 | * Update a DNS record. 19 | * 20 | * @param dnsCache 21 | * record cache 22 | * @param now 23 | * update date 24 | * @param record 25 | * DNS record 26 | */ 27 | void updateRecord(DNSCache dnsCache, long now, DNSEntry record); 28 | } 29 | -------------------------------------------------------------------------------- /TVMiracast/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /TVMiracast/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /PhoneMiracast/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/NetworkTopologyListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns; 5 | 6 | import java.util.EventListener; 7 | 8 | /** 9 | * Listener for network topology updates. 10 | * 11 | * @author Cédrik Lime, Pierre Frisch 12 | */ 13 | public interface NetworkTopologyListener extends EventListener { 14 | /** 15 | * A network address has been added.
16 | * 17 | * @param event 18 | * The NetworkTopologyEvent providing the name and fully qualified type of the service. 19 | */ 20 | void inetAddressAdded(NetworkTopologyEvent event); 21 | 22 | /** 23 | * A network address has been removed. 24 | * 25 | * @param event 26 | * The NetworkTopologyEvent providing the name and fully qualified type of the service. 27 | */ 28 | void inetAddressRemoved(NetworkTopologyEvent event); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/NetworkTopologyListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns; 5 | 6 | import java.util.EventListener; 7 | 8 | /** 9 | * Listener for network topology updates. 10 | * 11 | * @author Cédrik Lime, Pierre Frisch 12 | */ 13 | public interface NetworkTopologyListener extends EventListener { 14 | /** 15 | * A network address has been added.
16 | * 17 | * @param event 18 | * The NetworkTopologyEvent providing the name and fully qualified type of the service. 19 | */ 20 | void inetAddressAdded(NetworkTopologyEvent event); 21 | 22 | /** 23 | * A network address has been removed. 24 | * 25 | * @param event 26 | * The NetworkTopologyEvent providing the name and fully qualified type of the service. 27 | */ 28 | void inetAddressRemoved(NetworkTopologyEvent event); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /TVMiracast/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | TVMiracast 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/ServiceTypeListener.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns; 6 | 7 | import java.util.EventListener; 8 | 9 | /** 10 | * Listener for service types. 11 | * 12 | * @author Arthur van Hoff, Werner Randelshofer 13 | */ 14 | public interface ServiceTypeListener extends EventListener { 15 | /** 16 | * A new service type was discovered. 17 | * 18 | * @param event 19 | * The service event providing the fully qualified type of the service. 20 | */ 21 | void serviceTypeAdded(ServiceEvent event); 22 | 23 | /** 24 | * A new subtype for the service type was discovered. 25 | * 26 | *
27 |      * <sub>._sub.<app>.<protocol>.<servicedomain>.<parentdomain>.
28 |      * 
29 | * 30 | * @param event 31 | * The service event providing the fully qualified type of the service with subtype. 32 | * @since 3.2.0 33 | */ 34 | void subTypeForServiceTypeAdded(ServiceEvent event); 35 | } 36 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/ServiceTypeListener.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns; 6 | 7 | import java.util.EventListener; 8 | 9 | /** 10 | * Listener for service types. 11 | * 12 | * @author Arthur van Hoff, Werner Randelshofer 13 | */ 14 | public interface ServiceTypeListener extends EventListener { 15 | /** 16 | * A new service type was discovered. 17 | * 18 | * @param event 19 | * The service event providing the fully qualified type of the service. 20 | */ 21 | void serviceTypeAdded(ServiceEvent event); 22 | 23 | /** 24 | * A new subtype for the service type was discovered. 25 | * 26 | *
27 |      * <sub>._sub.<app>.<protocol>.<servicedomain>.<parentdomain>.
28 |      * 
29 | * 30 | * @param event 31 | * The service event providing the fully qualified type of the service with subtype. 32 | * @since 3.2.0 33 | */ 34 | void subTypeForServiceTypeAdded(ServiceEvent event); 35 | } 36 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/net/asio/tcp/server/TcpConnPool.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.net.asio.tcp.server; 3 | 4 | import java.nio.channels.SocketChannel; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | public class TcpConnPool { 9 | 10 | private Map mConns = new HashMap(); 11 | 12 | public Map getConns() { 13 | return mConns; 14 | } 15 | 16 | public void add(TcpConn conn) { 17 | String id = String.format("%s:%d", conn.getIp(), conn.getPort()); 18 | mConns.put(id, conn); 19 | } 20 | 21 | public void remove(TcpConn conn) { 22 | String id = String.format("%s:%d", conn.getIp(), conn.getPort()); 23 | mConns.remove(id); 24 | } 25 | 26 | public TcpConn getConn(SocketChannel channel) { 27 | for (TcpConn conn : mConns.values()) { 28 | if (conn.getChannel().equals(channel)) 29 | return conn; 30 | } 31 | 32 | return null; 33 | } 34 | 35 | public TcpConn getConn(String ip, int port) { 36 | String id = String.format("%s:%d", ip, port); 37 | return mConns.get(id); 38 | } 39 | } -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/net/asio/tcp/server/TcpConnPool.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.net.asio.tcp.server; 3 | 4 | import java.nio.channels.SocketChannel; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | public class TcpConnPool { 9 | 10 | private Map mConns = new HashMap(); 11 | 12 | public Map getConns() { 13 | return mConns; 14 | } 15 | 16 | public void add(TcpConn conn) { 17 | String id = String.format("%s:%d", conn.getIp(), conn.getPort()); 18 | mConns.put(id, conn); 19 | } 20 | 21 | public void remove(TcpConn conn) { 22 | String id = String.format("%s:%d", conn.getIp(), conn.getPort()); 23 | mConns.remove(id); 24 | } 25 | 26 | public TcpConn getConn(SocketChannel channel) { 27 | for (TcpConn conn : mConns.values()) { 28 | if (conn.getChannel().equals(channel)) 29 | return conn; 30 | } 31 | 32 | return null; 33 | } 34 | 35 | public TcpConn getConn(String ip, int port) { 36 | String id = String.format("%s:%d", ip, port); 37 | return mConns.get(id); 38 | } 39 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/NetworkTopologyEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns; 5 | 6 | import java.net.InetAddress; 7 | import java.util.EventObject; 8 | 9 | /** 10 | * @author Cédrik Lime, Pierre Frisch 11 | */ 12 | public abstract class NetworkTopologyEvent extends EventObject { 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = -8630033521752540987L; 18 | 19 | /** 20 | * Constructs a Service Event. 21 | * 22 | * @param eventSource 23 | * The DNS on which the Event initially occurred. 24 | * @exception IllegalArgumentException 25 | * if source is null. 26 | */ 27 | protected NetworkTopologyEvent(final Object eventSource) { 28 | super(eventSource); 29 | } 30 | 31 | /** 32 | * Returns the JmDNS instance associated with the event or null if it is a generic event. 33 | * 34 | * @return JmDNS instance 35 | */ 36 | public abstract JmDNS getDNS(); 37 | 38 | /** 39 | * The Internet address affected by this event. 40 | * 41 | * @return InetAddress 42 | */ 43 | public abstract InetAddress getInetAddress(); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/NetworkTopologyEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns; 5 | 6 | import java.net.InetAddress; 7 | import java.util.EventObject; 8 | 9 | /** 10 | * @author Cédrik Lime, Pierre Frisch 11 | */ 12 | public abstract class NetworkTopologyEvent extends EventObject { 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = -8630033521752540987L; 18 | 19 | /** 20 | * Constructs a Service Event. 21 | * 22 | * @param eventSource 23 | * The DNS on which the Event initially occurred. 24 | * @exception IllegalArgumentException 25 | * if source is null. 26 | */ 27 | protected NetworkTopologyEvent(final Object eventSource) { 28 | super(eventSource); 29 | } 30 | 31 | /** 32 | * Returns the JmDNS instance associated with the event or null if it is a generic event. 33 | * 34 | * @return JmDNS instance 35 | */ 36 | public abstract JmDNS getDNS(); 37 | 38 | /** 39 | * The Internet address affected by this event. 40 | * 41 | * @return InetAddress 42 | */ 43 | public abstract InetAddress getInetAddress(); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/bonjour/serviceinfo/DacpServiceInfo.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.bonjour.serviceinfo; 3 | 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | public class DacpServiceInfo implements BonjourServiceInfo { 8 | 9 | public static final String SERVICE_TYPE = "_dacp._tcp.local."; 10 | 11 | private String mName = null; 12 | private int mPort = 0; 13 | private Map mProperties = new HashMap(); 14 | 15 | public DacpServiceInfo(String name, int port) { 16 | 17 | mName = name; 18 | mPort = port; 19 | 20 | mProperties.put("txtvers", "1"); 21 | mProperties.put("Ver", "131075"); 22 | mProperties.put("DbId", "63B5E5C0C201542E"); 23 | mProperties.put("OSsi", "0x1F5"); 24 | } 25 | 26 | @Override 27 | public String getServiceName() { 28 | return mName; 29 | } 30 | 31 | @Override 32 | public int getServicePort() { 33 | return mPort; 34 | } 35 | 36 | @Override 37 | public String getServiceType() { 38 | return SERVICE_TYPE; 39 | } 40 | 41 | @Override 42 | public Map getProperties() { 43 | return mProperties; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/bonjour/serviceinfo/DacpServiceInfo.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.bonjour.serviceinfo; 3 | 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | public class DacpServiceInfo implements BonjourServiceInfo { 8 | 9 | public static final String SERVICE_TYPE = "_dacp._tcp.local."; 10 | 11 | private String mName = null; 12 | private int mPort = 0; 13 | private Map mProperties = new HashMap(); 14 | 15 | public DacpServiceInfo(String name, int port) { 16 | 17 | mName = name; 18 | mPort = port; 19 | 20 | mProperties.put("txtvers", "1"); 21 | mProperties.put("Ver", "131075"); 22 | mProperties.put("DbId", "63B5E5C0C201542E"); 23 | mProperties.put("OSsi", "0x1F5"); 24 | } 25 | 26 | @Override 27 | public String getServiceName() { 28 | return mName; 29 | } 30 | 31 | @Override 32 | public int getServicePort() { 33 | return mPort; 34 | } 35 | 36 | @Override 37 | public String getServiceType() { 38 | return SERVICE_TYPE; 39 | } 40 | 41 | @Override 42 | public Map getProperties() { 43 | return mProperties; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/util/NamedThreadFactory.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2012 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.util; 6 | 7 | import java.util.concurrent.Executors; 8 | import java.util.concurrent.ThreadFactory; 9 | 10 | /** 11 | * Custom thread factory which sets the name to make it easier to identify where the pooled threads were created. 12 | * 13 | * @author Trejkaz, Pierre Frisch 14 | */ 15 | public class NamedThreadFactory implements ThreadFactory { 16 | private final ThreadFactory _delegate; 17 | private final String _namePrefix; 18 | 19 | /** 20 | * Constructs the thread factory. 21 | * 22 | * @param namePrefix a prefix to append to thread names (will be separated from the default thread name by a space.) 23 | */ 24 | public NamedThreadFactory(String namePrefix) { 25 | this._namePrefix = namePrefix; 26 | _delegate = Executors.defaultThreadFactory(); 27 | } 28 | 29 | @Override 30 | public Thread newThread(Runnable runnable) { 31 | Thread thread = _delegate.newThread(runnable); 32 | thread.setName(_namePrefix + ' ' + thread.getName()); 33 | return thread; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/util/NamedThreadFactory.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2012 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.util; 6 | 7 | import java.util.concurrent.Executors; 8 | import java.util.concurrent.ThreadFactory; 9 | 10 | /** 11 | * Custom thread factory which sets the name to make it easier to identify where the pooled threads were created. 12 | * 13 | * @author Trejkaz, Pierre Frisch 14 | */ 15 | public class NamedThreadFactory implements ThreadFactory { 16 | private final ThreadFactory _delegate; 17 | private final String _namePrefix; 18 | 19 | /** 20 | * Constructs the thread factory. 21 | * 22 | * @param namePrefix a prefix to append to thread names (will be separated from the default thread name by a space.) 23 | */ 24 | public NamedThreadFactory(String namePrefix) { 25 | this._namePrefix = namePrefix; 26 | _delegate = Executors.defaultThreadFactory(); 27 | } 28 | 29 | @Override 30 | public Thread newThread(Runnable runnable) { 31 | Thread thread = _delegate.newThread(runnable); 32 | thread.setName(_namePrefix + ' ' + thread.getName()); 33 | return thread; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /TVMiracast/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /PhoneMiracast/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 25 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/bonjour/serviceinfo/MiLinkServiceInfo.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.bonjour.serviceinfo; 3 | 4 | import android.util.Log; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.UUID; 9 | 10 | public class MiLinkServiceInfo implements BonjourServiceInfo { 11 | 12 | private static final String TAG = AirPlayServiceInfo.class.getSimpleName(); 13 | 14 | public static final String SERVICE_TYPE = "_milink._tcp.local."; 15 | private static final float SERVICE_VERSION = 1.0f; 16 | private static final int SUPPORT_MIRACAST = 0x0001; 17 | private static final int DEFAULT_FEATURE = SUPPORT_MIRACAST; 18 | 19 | private String mDeviceName = null; 20 | private String mDeviceId = null; 21 | private int mPort = 0; 22 | 23 | private Map mProperties = new HashMap(); 24 | 25 | public MiLinkServiceInfo(byte[] deviceId, String name, int port) { 26 | UUID uuid = UUID.nameUUIDFromBytes(deviceId); 27 | mDeviceId = uuid.toString(); 28 | Log.d(TAG, mDeviceId); 29 | 30 | mDeviceName = name; 31 | mPort = port; 32 | 33 | mProperties.put("version", String.format("%f", SERVICE_VERSION)); 34 | mProperties.put("deviceid", mDeviceId); 35 | mProperties.put("features", String.format("%x", DEFAULT_FEATURE)); 36 | } 37 | 38 | @Override 39 | public String getServiceName() { 40 | return mDeviceName; 41 | } 42 | 43 | @Override 44 | public int getServicePort() { 45 | return mPort; 46 | } 47 | 48 | @Override 49 | public String getServiceType() { 50 | return SERVICE_TYPE; 51 | } 52 | 53 | @Override 54 | public Map getProperties() { 55 | return mProperties; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/bonjour/serviceinfo/MiLinkServiceInfo.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.bonjour.serviceinfo; 3 | 4 | import android.util.Log; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.UUID; 9 | 10 | public class MiLinkServiceInfo implements BonjourServiceInfo { 11 | 12 | private static final String TAG = AirPlayServiceInfo.class.getSimpleName(); 13 | 14 | public static final String SERVICE_TYPE = "_milink._tcp.local."; 15 | private static final float SERVICE_VERSION = 1.0f; 16 | private static final int SUPPORT_MIRACAST = 0x0001; 17 | private static final int DEFAULT_FEATURE = SUPPORT_MIRACAST; 18 | 19 | private String mDeviceName = null; 20 | private String mDeviceId = null; 21 | private int mPort = 0; 22 | 23 | private Map mProperties = new HashMap(); 24 | 25 | public MiLinkServiceInfo(byte[] deviceId, String name, int port) { 26 | UUID uuid = UUID.nameUUIDFromBytes(deviceId); 27 | mDeviceId = uuid.toString(); 28 | Log.d(TAG, mDeviceId); 29 | 30 | mDeviceName = name; 31 | mPort = port; 32 | 33 | mProperties.put("version", String.format("%f", SERVICE_VERSION)); 34 | mProperties.put("deviceid", mDeviceId); 35 | mProperties.put("features", String.format("%x", DEFAULT_FEATURE)); 36 | } 37 | 38 | @Override 39 | public String getServiceName() { 40 | return mDeviceName; 41 | } 42 | 43 | @Override 44 | public int getServicePort() { 45 | return mPort; 46 | } 47 | 48 | @Override 49 | public String getServiceType() { 50 | return SERVICE_TYPE; 51 | } 52 | 53 | @Override 54 | public Map getProperties() { 55 | return mProperties; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/tasks/RecordReaper.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks; 6 | 7 | import java.util.Timer; 8 | import java.util.logging.Level; 9 | import java.util.logging.Logger; 10 | 11 | import javax.jmdns.impl.JmDNSImpl; 12 | import javax.jmdns.impl.constants.DNSConstants; 13 | 14 | /** 15 | * Periodically removes expired entries from the cache. 16 | */ 17 | public class RecordReaper extends DNSTask { 18 | static Logger logger = Logger.getLogger(RecordReaper.class.getName()); 19 | 20 | /** 21 | * @param jmDNSImpl 22 | */ 23 | public RecordReaper(JmDNSImpl jmDNSImpl) { 24 | super(jmDNSImpl); 25 | } 26 | 27 | /* 28 | * (non-Javadoc) 29 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 30 | */ 31 | @Override 32 | public String getName() { 33 | return "RecordReaper(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 34 | } 35 | 36 | /* 37 | * (non-Javadoc) 38 | * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer) 39 | */ 40 | @Override 41 | public void start(Timer timer) { 42 | if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) { 43 | timer.schedule(this, DNSConstants.RECORD_REAPER_INTERVAL, DNSConstants.RECORD_REAPER_INTERVAL); 44 | } 45 | } 46 | 47 | @Override 48 | public void run() { 49 | if (this.getDns().isCanceling() || this.getDns().isCanceled()) { 50 | return; 51 | } 52 | if (logger.isLoggable(Level.FINEST)) { 53 | logger.finest(this.getName() + ".run() JmDNS reaping cache"); 54 | } 55 | 56 | // Remove expired answers from the cache 57 | // ------------------------------------- 58 | this.getDns().cleanCache(); 59 | } 60 | 61 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/tasks/RecordReaper.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks; 6 | 7 | import java.util.Timer; 8 | import java.util.logging.Level; 9 | import java.util.logging.Logger; 10 | 11 | import javax.jmdns.impl.JmDNSImpl; 12 | import javax.jmdns.impl.constants.DNSConstants; 13 | 14 | /** 15 | * Periodically removes expired entries from the cache. 16 | */ 17 | public class RecordReaper extends DNSTask { 18 | static Logger logger = Logger.getLogger(RecordReaper.class.getName()); 19 | 20 | /** 21 | * @param jmDNSImpl 22 | */ 23 | public RecordReaper(JmDNSImpl jmDNSImpl) { 24 | super(jmDNSImpl); 25 | } 26 | 27 | /* 28 | * (non-Javadoc) 29 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 30 | */ 31 | @Override 32 | public String getName() { 33 | return "RecordReaper(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 34 | } 35 | 36 | /* 37 | * (non-Javadoc) 38 | * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer) 39 | */ 40 | @Override 41 | public void start(Timer timer) { 42 | if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) { 43 | timer.schedule(this, DNSConstants.RECORD_REAPER_INTERVAL, DNSConstants.RECORD_REAPER_INTERVAL); 44 | } 45 | } 46 | 47 | @Override 48 | public void run() { 49 | if (this.getDns().isCanceling() || this.getDns().isCanceled()) { 50 | return; 51 | } 52 | if (logger.isLoggable(Level.FINEST)) { 53 | logger.finest(this.getName() + ".run() JmDNS reaping cache"); 54 | } 55 | 56 | // Remove expired answers from the cache 57 | // ------------------------------------- 58 | this.getDns().cleanCache(); 59 | } 60 | 61 | } -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/constants/DNSOptionCode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl.constants; 5 | 6 | /** 7 | * DNS option code. 8 | * 9 | * @author Arthur van Hoff, Pierre Frisch, Rick Blair 10 | */ 11 | public enum DNSOptionCode { 12 | 13 | /** 14 | * Token 15 | */ 16 | Unknown("Unknown", 65535), 17 | /** 18 | * Long-Lived Queries Option [http://files.dns-sd.org/draft-sekar-dns-llq.txt] 19 | */ 20 | LLQ("LLQ", 1), 21 | /** 22 | * Update Leases Option [http://files.dns-sd.org/draft-sekar-dns-ul.txt] 23 | */ 24 | UL("UL", 2), 25 | /** 26 | * Name Server Identifier Option [RFC5001] 27 | */ 28 | NSID("NSID", 3), 29 | /** 30 | * Owner Option [draft-cheshire-edns0-owner-option] 31 | */ 32 | Owner("Owner", 4); 33 | 34 | private final String _externalName; 35 | 36 | private final int _index; 37 | 38 | DNSOptionCode(String name, int index) { 39 | _externalName = name; 40 | _index = index; 41 | } 42 | 43 | /** 44 | * Return the string representation of this type 45 | * 46 | * @return String 47 | */ 48 | public String externalName() { 49 | return _externalName; 50 | } 51 | 52 | /** 53 | * Return the numeric value of this type 54 | * 55 | * @return String 56 | */ 57 | public int indexValue() { 58 | return _index; 59 | } 60 | 61 | /** 62 | * @param optioncode 63 | * @return label 64 | */ 65 | public static DNSOptionCode resultCodeForFlags(int optioncode) { 66 | int maskedIndex = optioncode; 67 | for (DNSOptionCode aCode : DNSOptionCode.values()) { 68 | if (aCode._index == maskedIndex) return aCode; 69 | } 70 | return Unknown; 71 | } 72 | 73 | @Override 74 | public String toString() { 75 | return this.name() + " index " + this.indexValue(); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/constants/DNSOptionCode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl.constants; 5 | 6 | /** 7 | * DNS option code. 8 | * 9 | * @author Arthur van Hoff, Pierre Frisch, Rick Blair 10 | */ 11 | public enum DNSOptionCode { 12 | 13 | /** 14 | * Token 15 | */ 16 | Unknown("Unknown", 65535), 17 | /** 18 | * Long-Lived Queries Option [http://files.dns-sd.org/draft-sekar-dns-llq.txt] 19 | */ 20 | LLQ("LLQ", 1), 21 | /** 22 | * Update Leases Option [http://files.dns-sd.org/draft-sekar-dns-ul.txt] 23 | */ 24 | UL("UL", 2), 25 | /** 26 | * Name Server Identifier Option [RFC5001] 27 | */ 28 | NSID("NSID", 3), 29 | /** 30 | * Owner Option [draft-cheshire-edns0-owner-option] 31 | */ 32 | Owner("Owner", 4); 33 | 34 | private final String _externalName; 35 | 36 | private final int _index; 37 | 38 | DNSOptionCode(String name, int index) { 39 | _externalName = name; 40 | _index = index; 41 | } 42 | 43 | /** 44 | * Return the string representation of this type 45 | * 46 | * @return String 47 | */ 48 | public String externalName() { 49 | return _externalName; 50 | } 51 | 52 | /** 53 | * Return the numeric value of this type 54 | * 55 | * @return String 56 | */ 57 | public int indexValue() { 58 | return _index; 59 | } 60 | 61 | /** 62 | * @param optioncode 63 | * @return label 64 | */ 65 | public static DNSOptionCode resultCodeForFlags(int optioncode) { 66 | int maskedIndex = optioncode; 67 | for (DNSOptionCode aCode : DNSOptionCode.values()) { 68 | if (aCode._index == maskedIndex) return aCode; 69 | } 70 | return Unknown; 71 | } 72 | 73 | @Override 74 | public String toString() { 75 | return this.name() + " index " + this.indexValue(); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/ServiceListener.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns; 6 | 7 | import java.util.EventListener; 8 | 9 | /** 10 | * Listener for service updates. 11 | * 12 | * @author Arthur van Hoff, Werner Randelshofer, Pierre Frisch 13 | */ 14 | public interface ServiceListener extends EventListener { 15 | /** 16 | * A service has been added.
17 | * Note:This event is only the service added event. The service info associated with this event does not include resolution information.
18 | * To get the full resolved information you need to listen to {@link #serviceResolved(ServiceEvent)} or call {@link JmDNS#getServiceInfo(String, String, long)} 19 | * 20 | *
21 |      *  ServiceInfo info = event.getDNS().getServiceInfo(event.getType(), event.getName())
22 |      * 
23 | *

24 | * Please note that service resolution may take a few second to resolve. 25 | *

26 | * 27 | * @param event 28 | * The ServiceEvent providing the name and fully qualified type of the service. 29 | */ 30 | void serviceAdded(ServiceEvent event); 31 | 32 | /** 33 | * A service has been removed. 34 | * 35 | * @param event 36 | * The ServiceEvent providing the name and fully qualified type of the service. 37 | */ 38 | void serviceRemoved(ServiceEvent event); 39 | 40 | /** 41 | * A service has been resolved. Its details are now available in the ServiceInfo record.
42 | * Note:This call back will never be called if the service does not resolve.
43 | * 44 | * @param event 45 | * The ServiceEvent providing the name, the fully qualified type of the service, and the service info record. 46 | */ 47 | void serviceResolved(ServiceEvent event); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/ServiceListener.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns; 6 | 7 | import java.util.EventListener; 8 | 9 | /** 10 | * Listener for service updates. 11 | * 12 | * @author Arthur van Hoff, Werner Randelshofer, Pierre Frisch 13 | */ 14 | public interface ServiceListener extends EventListener { 15 | /** 16 | * A service has been added.
17 | * Note:This event is only the service added event. The service info associated with this event does not include resolution information.
18 | * To get the full resolved information you need to listen to {@link #serviceResolved(ServiceEvent)} or call {@link JmDNS#getServiceInfo(String, String, long)} 19 | * 20 | *
21 |      *  ServiceInfo info = event.getDNS().getServiceInfo(event.getType(), event.getName())
22 |      * 
23 | *

24 | * Please note that service resolution may take a few second to resolve. 25 | *

26 | * 27 | * @param event 28 | * The ServiceEvent providing the name and fully qualified type of the service. 29 | */ 30 | void serviceAdded(ServiceEvent event); 31 | 32 | /** 33 | * A service has been removed. 34 | * 35 | * @param event 36 | * The ServiceEvent providing the name and fully qualified type of the service. 37 | */ 38 | void serviceRemoved(ServiceEvent event); 39 | 40 | /** 41 | * A service has been resolved. Its details are now available in the ServiceInfo record.
42 | * Note:This call back will never be called if the service does not resolve.
43 | * 44 | * @param event 45 | * The ServiceEvent providing the name, the fully qualified type of the service, and the service info record. 46 | */ 47 | void serviceResolved(ServiceEvent event); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/constants/DNSOperationCode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl.constants; 5 | 6 | /** 7 | * DNS operation code. 8 | * 9 | * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair 10 | */ 11 | public enum DNSOperationCode { 12 | /** 13 | * Query [RFC1035] 14 | */ 15 | Query("Query", 0), 16 | /** 17 | * IQuery (Inverse Query, Obsolete) [RFC3425] 18 | */ 19 | IQuery("Inverse Query", 1), 20 | /** 21 | * Status [RFC1035] 22 | */ 23 | Status("Status", 2), 24 | /** 25 | * Unassigned 26 | */ 27 | Unassigned("Unassigned", 3), 28 | /** 29 | * Notify [RFC1996] 30 | */ 31 | Notify("Notify", 4), 32 | /** 33 | * Update [RFC2136] 34 | */ 35 | Update("Update", 5); 36 | 37 | /** 38 | * DNS RCode types are encoded on the last 4 bits 39 | */ 40 | static final int OpCode_MASK = 0x7800; 41 | 42 | private final String _externalName; 43 | 44 | private final int _index; 45 | 46 | DNSOperationCode(String name, int index) { 47 | _externalName = name; 48 | _index = index; 49 | } 50 | 51 | /** 52 | * Return the string representation of this type 53 | * 54 | * @return String 55 | */ 56 | public String externalName() { 57 | return _externalName; 58 | } 59 | 60 | /** 61 | * Return the numeric value of this type 62 | * 63 | * @return String 64 | */ 65 | public int indexValue() { 66 | return _index; 67 | } 68 | 69 | /** 70 | * @param flags 71 | * @return label 72 | */ 73 | public static DNSOperationCode operationCodeForFlags(int flags) { 74 | int maskedIndex = (flags & OpCode_MASK) >> 11; 75 | for (DNSOperationCode aCode : DNSOperationCode.values()) { 76 | if (aCode._index == maskedIndex) return aCode; 77 | } 78 | return Unassigned; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return this.name() + " index " + this.indexValue(); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/constants/DNSOperationCode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl.constants; 5 | 6 | /** 7 | * DNS operation code. 8 | * 9 | * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair 10 | */ 11 | public enum DNSOperationCode { 12 | /** 13 | * Query [RFC1035] 14 | */ 15 | Query("Query", 0), 16 | /** 17 | * IQuery (Inverse Query, Obsolete) [RFC3425] 18 | */ 19 | IQuery("Inverse Query", 1), 20 | /** 21 | * Status [RFC1035] 22 | */ 23 | Status("Status", 2), 24 | /** 25 | * Unassigned 26 | */ 27 | Unassigned("Unassigned", 3), 28 | /** 29 | * Notify [RFC1996] 30 | */ 31 | Notify("Notify", 4), 32 | /** 33 | * Update [RFC2136] 34 | */ 35 | Update("Update", 5); 36 | 37 | /** 38 | * DNS RCode types are encoded on the last 4 bits 39 | */ 40 | static final int OpCode_MASK = 0x7800; 41 | 42 | private final String _externalName; 43 | 44 | private final int _index; 45 | 46 | DNSOperationCode(String name, int index) { 47 | _externalName = name; 48 | _index = index; 49 | } 50 | 51 | /** 52 | * Return the string representation of this type 53 | * 54 | * @return String 55 | */ 56 | public String externalName() { 57 | return _externalName; 58 | } 59 | 60 | /** 61 | * Return the numeric value of this type 62 | * 63 | * @return String 64 | */ 65 | public int indexValue() { 66 | return _index; 67 | } 68 | 69 | /** 70 | * @param flags 71 | * @return label 72 | */ 73 | public static DNSOperationCode operationCodeForFlags(int flags) { 74 | int maskedIndex = (flags & OpCode_MASK) >> 11; 75 | for (DNSOperationCode aCode : DNSOperationCode.values()) { 76 | if (aCode._index == maskedIndex) return aCode; 77 | } 78 | return Unassigned; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return this.name() + " index " + this.indexValue(); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/ServiceEvent.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns; 6 | 7 | import java.util.EventObject; 8 | 9 | /** 10 | * 11 | */ 12 | public abstract class ServiceEvent extends EventObject implements Cloneable { 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = -8558445644541006271L; 18 | 19 | /** 20 | * Constructs a Service Event. 21 | * 22 | * @param eventSource 23 | * The object on which the Event initially occurred. 24 | * @exception IllegalArgumentException 25 | * if source is null. 26 | */ 27 | public ServiceEvent(final Object eventSource) { 28 | super(eventSource); 29 | } 30 | 31 | /** 32 | * Returns the JmDNS instance which originated the event. 33 | * 34 | * @return JmDNS instance 35 | */ 36 | public abstract JmDNS getDNS(); 37 | 38 | /** 39 | * Returns the fully qualified type of the service. 40 | * 41 | * @return type of the service. 42 | */ 43 | public abstract String getType(); 44 | 45 | /** 46 | * Returns the instance name of the service. Always returns null, if the event is sent to a service type listener. 47 | * 48 | * @return name of the service 49 | */ 50 | public abstract String getName(); 51 | 52 | /** 53 | * Returns the service info record, or null if the service could not be resolved. Always returns null, if the event is sent to a service type listener. 54 | * 55 | * @return service info record 56 | * @see javax.jmdns.ServiceEvent#getInfo() 57 | */ 58 | public abstract ServiceInfo getInfo(); 59 | 60 | /* 61 | * (non-Javadoc) 62 | * @see java.lang.Object#clone() 63 | */ 64 | @Override 65 | public ServiceEvent clone() { 66 | try { 67 | return (ServiceEvent) super.clone(); 68 | } catch (CloneNotSupportedException exception) { 69 | // clone is supported 70 | return null; 71 | } 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/ServiceEvent.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns; 6 | 7 | import java.util.EventObject; 8 | 9 | /** 10 | * 11 | */ 12 | public abstract class ServiceEvent extends EventObject implements Cloneable { 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = -8558445644541006271L; 18 | 19 | /** 20 | * Constructs a Service Event. 21 | * 22 | * @param eventSource 23 | * The object on which the Event initially occurred. 24 | * @exception IllegalArgumentException 25 | * if source is null. 26 | */ 27 | public ServiceEvent(final Object eventSource) { 28 | super(eventSource); 29 | } 30 | 31 | /** 32 | * Returns the JmDNS instance which originated the event. 33 | * 34 | * @return JmDNS instance 35 | */ 36 | public abstract JmDNS getDNS(); 37 | 38 | /** 39 | * Returns the fully qualified type of the service. 40 | * 41 | * @return type of the service. 42 | */ 43 | public abstract String getType(); 44 | 45 | /** 46 | * Returns the instance name of the service. Always returns null, if the event is sent to a service type listener. 47 | * 48 | * @return name of the service 49 | */ 50 | public abstract String getName(); 51 | 52 | /** 53 | * Returns the service info record, or null if the service could not be resolved. Always returns null, if the event is sent to a service type listener. 54 | * 55 | * @return service info record 56 | * @see javax.jmdns.ServiceEvent#getInfo() 57 | */ 58 | public abstract ServiceInfo getInfo(); 59 | 60 | /* 61 | * (non-Javadoc) 62 | * @see java.lang.Object#clone() 63 | */ 64 | @Override 65 | public ServiceEvent clone() { 66 | try { 67 | return (ServiceEvent) super.clone(); 68 | } catch (CloneNotSupportedException exception) { 69 | // clone is supported 70 | return null; 71 | } 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/constants/DNSLabel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl.constants; 5 | 6 | /** 7 | * DNS label. 8 | * 9 | * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair 10 | */ 11 | public enum DNSLabel { 12 | /** 13 | * This is unallocated. 14 | */ 15 | Unknown("", 0x80), 16 | /** 17 | * Standard label [RFC 1035] 18 | */ 19 | Standard("standard label", 0x00), 20 | /** 21 | * Compressed label [RFC 1035] 22 | */ 23 | Compressed("compressed label", 0xC0), 24 | /** 25 | * Extended label [RFC 2671] 26 | */ 27 | Extended("extended label", 0x40); 28 | 29 | /** 30 | * DNS label types are encoded on the first 2 bits 31 | */ 32 | static final int LABEL_MASK = 0xC0; 33 | static final int LABEL_NOT_MASK = 0x3F; 34 | 35 | private final String _externalName; 36 | 37 | private final int _index; 38 | 39 | DNSLabel(String name, int index) { 40 | _externalName = name; 41 | _index = index; 42 | } 43 | 44 | /** 45 | * Return the string representation of this type 46 | * 47 | * @return String 48 | */ 49 | public String externalName() { 50 | return _externalName; 51 | } 52 | 53 | /** 54 | * Return the numeric value of this type 55 | * 56 | * @return String 57 | */ 58 | public int indexValue() { 59 | return _index; 60 | } 61 | 62 | /** 63 | * @param index 64 | * @return label 65 | */ 66 | public static DNSLabel labelForByte(int index) { 67 | int maskedIndex = index & LABEL_MASK; 68 | for (DNSLabel aLabel : DNSLabel.values()) { 69 | if (aLabel._index == maskedIndex) return aLabel; 70 | } 71 | return Unknown; 72 | } 73 | 74 | /** 75 | * @param index 76 | * @return masked value 77 | */ 78 | public static int labelValue(int index) { 79 | return index & LABEL_NOT_MASK; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return this.name() + " index " + this.indexValue(); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/constants/DNSLabel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl.constants; 5 | 6 | /** 7 | * DNS label. 8 | * 9 | * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair 10 | */ 11 | public enum DNSLabel { 12 | /** 13 | * This is unallocated. 14 | */ 15 | Unknown("", 0x80), 16 | /** 17 | * Standard label [RFC 1035] 18 | */ 19 | Standard("standard label", 0x00), 20 | /** 21 | * Compressed label [RFC 1035] 22 | */ 23 | Compressed("compressed label", 0xC0), 24 | /** 25 | * Extended label [RFC 2671] 26 | */ 27 | Extended("extended label", 0x40); 28 | 29 | /** 30 | * DNS label types are encoded on the first 2 bits 31 | */ 32 | static final int LABEL_MASK = 0xC0; 33 | static final int LABEL_NOT_MASK = 0x3F; 34 | 35 | private final String _externalName; 36 | 37 | private final int _index; 38 | 39 | DNSLabel(String name, int index) { 40 | _externalName = name; 41 | _index = index; 42 | } 43 | 44 | /** 45 | * Return the string representation of this type 46 | * 47 | * @return String 48 | */ 49 | public String externalName() { 50 | return _externalName; 51 | } 52 | 53 | /** 54 | * Return the numeric value of this type 55 | * 56 | * @return String 57 | */ 58 | public int indexValue() { 59 | return _index; 60 | } 61 | 62 | /** 63 | * @param index 64 | * @return label 65 | */ 66 | public static DNSLabel labelForByte(int index) { 67 | int maskedIndex = index & LABEL_MASK; 68 | for (DNSLabel aLabel : DNSLabel.values()) { 69 | if (aLabel._index == maskedIndex) return aLabel; 70 | } 71 | return Unknown; 72 | } 73 | 74 | /** 75 | * @param index 76 | * @return masked value 77 | */ 78 | public static int labelValue(int index) { 79 | return index & LABEL_NOT_MASK; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return this.name() + " index " + this.indexValue(); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/milink/client/MiLinkClient.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.client; 3 | 4 | import com.milink.milink.common.IQ; 5 | import com.milink.net.asio.tcp.client.TcpClient; 6 | import com.milink.net.asio.tcp.client.TcpClientListener; 7 | 8 | public class MiLinkClient implements TcpClientListener { 9 | 10 | private static final String TAG = MiLinkClient.class.getSimpleName(); 11 | 12 | private TcpClient mClient = null; 13 | private MiLinkClientListener mListener = null; 14 | 15 | public MiLinkClient(MiLinkClientListener listener) { 16 | mClient = new TcpClient(this); 17 | mListener = listener; 18 | } 19 | 20 | public boolean connect(String ip, int port, int millisecond) { 21 | return mClient.connect(ip, port, millisecond); 22 | } 23 | 24 | public boolean disconnect() { 25 | return mClient.disconnect(); 26 | } 27 | 28 | public boolean isConnected() { 29 | return mClient.isConnected(); 30 | } 31 | 32 | public String getSelfIp() { 33 | return mClient.getSelfIp(); 34 | } 35 | 36 | public boolean send(IQ iq) { 37 | boolean result = false; 38 | 39 | do 40 | { 41 | String msg = iq.toString(); 42 | if (msg == null) 43 | break; 44 | 45 | result = mClient.send(msg.getBytes()); 46 | } while (false); 47 | 48 | return result; 49 | } 50 | 51 | @Override 52 | public void onConnected(TcpClient client) { 53 | mListener.onConnected(this); 54 | } 55 | 56 | @Override 57 | public void onConnectedFailed(TcpClient client) { 58 | mListener.onConnectedFailed(this); 59 | } 60 | 61 | @Override 62 | public void onDisconnect(TcpClient client) { 63 | mListener.onDisconnect(this); 64 | } 65 | 66 | @Override 67 | public void onReceived(TcpClient client, byte[] data) { 68 | IQ iq = IQ.create(data); 69 | if (iq == null) 70 | return; 71 | 72 | if (iq.getType() == IQ.Type.Event) { 73 | mListener.onEvent(this, iq); 74 | } 75 | else { 76 | mListener.onReceived(this, iq); 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/milink/client/MiLinkClient.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.client; 3 | 4 | import com.milink.milink.common.IQ; 5 | import com.milink.net.asio.tcp.client.TcpClient; 6 | import com.milink.net.asio.tcp.client.TcpClientListener; 7 | 8 | public class MiLinkClient implements TcpClientListener { 9 | 10 | private static final String TAG = MiLinkClient.class.getSimpleName(); 11 | 12 | private TcpClient mClient = null; 13 | private MiLinkClientListener mListener = null; 14 | 15 | public MiLinkClient(MiLinkClientListener listener) { 16 | mClient = new TcpClient(this); 17 | mListener = listener; 18 | } 19 | 20 | public boolean connect(String ip, int port, int millisecond) { 21 | return mClient.connect(ip, port, millisecond); 22 | } 23 | 24 | public boolean disconnect() { 25 | return mClient.disconnect(); 26 | } 27 | 28 | public boolean isConnected() { 29 | return mClient.isConnected(); 30 | } 31 | 32 | public String getSelfIp() { 33 | return mClient.getSelfIp(); 34 | } 35 | 36 | public boolean send(IQ iq) { 37 | boolean result = false; 38 | 39 | do 40 | { 41 | String msg = iq.toString(); 42 | if (msg == null) 43 | break; 44 | 45 | result = mClient.send(msg.getBytes()); 46 | } while (false); 47 | 48 | return result; 49 | } 50 | 51 | @Override 52 | public void onConnected(TcpClient client) { 53 | mListener.onConnected(this); 54 | } 55 | 56 | @Override 57 | public void onConnectedFailed(TcpClient client) { 58 | mListener.onConnectedFailed(this); 59 | } 60 | 61 | @Override 62 | public void onDisconnect(TcpClient client) { 63 | mListener.onDisconnect(this); 64 | } 65 | 66 | @Override 67 | public void onReceived(TcpClient client, byte[] data) { 68 | IQ iq = IQ.create(data); 69 | if (iq == null) 70 | return; 71 | 72 | if (iq.getType() == IQ.Type.Event) { 73 | mListener.onEvent(this, iq); 74 | } 75 | else { 76 | mListener.onReceived(this, iq); 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/bonjour/serviceinfo/AirPlayServiceInfo.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.bonjour.serviceinfo; 3 | 4 | import android.util.Log; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class AirPlayServiceInfo implements BonjourServiceInfo { 10 | 11 | private static final String TAG = AirPlayServiceInfo.class.getSimpleName(); 12 | 13 | public static final String SERVICE_TYPE = "_airplay._tcp.local."; 14 | 15 | private static final int DEFAULT_PORT = 7000; 16 | 17 | private static final String DEFAULT_FEATURE = "0x100029ff"; 18 | private static final String DEFAULT_MODEL = "AppleTV3,2"; 19 | private static final String DEFAULT_SRCVERS = "150.33"; 20 | 21 | private String mDeviceName = null; 22 | private String mDeviceId = null; 23 | private int mPort = DEFAULT_PORT; 24 | 25 | private Map mProperties = new HashMap(); 26 | 27 | public AirPlayServiceInfo(byte[] deviceId, String name, int port) { 28 | if (deviceId.length != 6) 29 | return; 30 | 31 | mDeviceId = String.format("%02X:%02X:%02X:%02X:%02X:%02X", 32 | deviceId[0], 33 | deviceId[1], 34 | deviceId[2], 35 | deviceId[3], 36 | deviceId[4], 37 | deviceId[5]); 38 | 39 | Log.d(TAG, String.format("deviceId: %s", mDeviceId)); 40 | 41 | mDeviceName = name; 42 | mPort = port; 43 | 44 | mProperties.put("deviceid", mDeviceId); 45 | mProperties.put("features", DEFAULT_FEATURE); 46 | mProperties.put("model", DEFAULT_MODEL); 47 | mProperties.put("rhd", "1.9.8"); 48 | mProperties.put("srcvers", DEFAULT_SRCVERS); 49 | mProperties.put("vv", "1"); 50 | } 51 | 52 | @Override 53 | public String getServiceName() { 54 | return mDeviceName; 55 | } 56 | 57 | @Override 58 | public int getServicePort() { 59 | return mPort; 60 | } 61 | 62 | @Override 63 | public String getServiceType() { 64 | return SERVICE_TYPE; 65 | } 66 | 67 | @Override 68 | public Map getProperties() { 69 | return mProperties; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/bonjour/serviceinfo/AirPlayServiceInfo.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.bonjour.serviceinfo; 3 | 4 | import android.util.Log; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class AirPlayServiceInfo implements BonjourServiceInfo { 10 | 11 | private static final String TAG = AirPlayServiceInfo.class.getSimpleName(); 12 | 13 | public static final String SERVICE_TYPE = "_airplay._tcp.local."; 14 | 15 | private static final int DEFAULT_PORT = 7000; 16 | 17 | private static final String DEFAULT_FEATURE = "0x100029ff"; 18 | private static final String DEFAULT_MODEL = "AppleTV3,2"; 19 | private static final String DEFAULT_SRCVERS = "150.33"; 20 | 21 | private String mDeviceName = null; 22 | private String mDeviceId = null; 23 | private int mPort = DEFAULT_PORT; 24 | 25 | private Map mProperties = new HashMap(); 26 | 27 | public AirPlayServiceInfo(byte[] deviceId, String name, int port) { 28 | if (deviceId.length != 6) 29 | return; 30 | 31 | mDeviceId = String.format("%02X:%02X:%02X:%02X:%02X:%02X", 32 | deviceId[0], 33 | deviceId[1], 34 | deviceId[2], 35 | deviceId[3], 36 | deviceId[4], 37 | deviceId[5]); 38 | 39 | Log.d(TAG, String.format("deviceId: %s", mDeviceId)); 40 | 41 | mDeviceName = name; 42 | mPort = port; 43 | 44 | mProperties.put("deviceid", mDeviceId); 45 | mProperties.put("features", DEFAULT_FEATURE); 46 | mProperties.put("model", DEFAULT_MODEL); 47 | mProperties.put("rhd", "1.9.8"); 48 | mProperties.put("srcvers", DEFAULT_SRCVERS); 49 | mProperties.put("vv", "1"); 50 | } 51 | 52 | @Override 53 | public String getServiceName() { 54 | return mDeviceName; 55 | } 56 | 57 | @Override 58 | public int getServicePort() { 59 | return mPort; 60 | } 61 | 62 | @Override 63 | public String getServiceType() { 64 | return SERVICE_TYPE; 65 | } 66 | 67 | @Override 68 | public Map getProperties() { 69 | return mProperties; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/NetworkTopologyEventImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl; 5 | 6 | import java.net.InetAddress; 7 | 8 | import javax.jmdns.JmDNS; 9 | import javax.jmdns.NetworkTopologyEvent; 10 | import javax.jmdns.NetworkTopologyListener; 11 | 12 | /** 13 | * @author Cédrik Lime, Pierre Frisch 14 | */ 15 | public class NetworkTopologyEventImpl extends NetworkTopologyEvent implements Cloneable { 16 | 17 | /** 18 | * 19 | */ 20 | private static final long serialVersionUID = 1445606146153550463L; 21 | 22 | private final InetAddress _inetAddress; 23 | 24 | /** 25 | * Constructs a Network Topology Event. 26 | * 27 | * @param jmDNS 28 | * @param inetAddress 29 | * @exception IllegalArgumentException 30 | * if source is null. 31 | */ 32 | public NetworkTopologyEventImpl(JmDNS jmDNS, InetAddress inetAddress) { 33 | super(jmDNS); 34 | this._inetAddress = inetAddress; 35 | } 36 | 37 | NetworkTopologyEventImpl(NetworkTopologyListener jmmDNS, InetAddress inetAddress) { 38 | super(jmmDNS); 39 | this._inetAddress = inetAddress; 40 | } 41 | 42 | /* 43 | * (non-Javadoc) 44 | * @see javax.jmdns.NetworkTopologyEvent#getDNS() 45 | */ 46 | @Override 47 | public JmDNS getDNS() { 48 | return (this.getSource() instanceof JmDNS ? (JmDNS) getSource() : null); 49 | } 50 | 51 | /* 52 | * (non-Javadoc) 53 | * @see javax.jmdns.NetworkTopologyEvent#getInetAddress() 54 | */ 55 | @Override 56 | public InetAddress getInetAddress() { 57 | return _inetAddress; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | StringBuilder buf = new StringBuilder(); 63 | buf.append("[" + this.getClass().getSimpleName() + "@" + System.identityHashCode(this) + " "); 64 | buf.append("\n\tinetAddress: '"); 65 | buf.append(this.getInetAddress()); 66 | buf.append("']"); 67 | // buf.append("' source: "); 68 | // buf.append("\n\t" + source + ""); 69 | // buf.append("\n]"); 70 | return buf.toString(); 71 | } 72 | 73 | /* 74 | * (non-Javadoc) 75 | * @see java.lang.Object#clone() 76 | */ 77 | @Override 78 | public NetworkTopologyEventImpl clone() throws CloneNotSupportedException { 79 | return new NetworkTopologyEventImpl(getDNS(), getInetAddress()); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/NetworkTopologyEventImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl; 5 | 6 | import java.net.InetAddress; 7 | 8 | import javax.jmdns.JmDNS; 9 | import javax.jmdns.NetworkTopologyEvent; 10 | import javax.jmdns.NetworkTopologyListener; 11 | 12 | /** 13 | * @author Cédrik Lime, Pierre Frisch 14 | */ 15 | public class NetworkTopologyEventImpl extends NetworkTopologyEvent implements Cloneable { 16 | 17 | /** 18 | * 19 | */ 20 | private static final long serialVersionUID = 1445606146153550463L; 21 | 22 | private final InetAddress _inetAddress; 23 | 24 | /** 25 | * Constructs a Network Topology Event. 26 | * 27 | * @param jmDNS 28 | * @param inetAddress 29 | * @exception IllegalArgumentException 30 | * if source is null. 31 | */ 32 | public NetworkTopologyEventImpl(JmDNS jmDNS, InetAddress inetAddress) { 33 | super(jmDNS); 34 | this._inetAddress = inetAddress; 35 | } 36 | 37 | NetworkTopologyEventImpl(NetworkTopologyListener jmmDNS, InetAddress inetAddress) { 38 | super(jmmDNS); 39 | this._inetAddress = inetAddress; 40 | } 41 | 42 | /* 43 | * (non-Javadoc) 44 | * @see javax.jmdns.NetworkTopologyEvent#getDNS() 45 | */ 46 | @Override 47 | public JmDNS getDNS() { 48 | return (this.getSource() instanceof JmDNS ? (JmDNS) getSource() : null); 49 | } 50 | 51 | /* 52 | * (non-Javadoc) 53 | * @see javax.jmdns.NetworkTopologyEvent#getInetAddress() 54 | */ 55 | @Override 56 | public InetAddress getInetAddress() { 57 | return _inetAddress; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | StringBuilder buf = new StringBuilder(); 63 | buf.append("[" + this.getClass().getSimpleName() + "@" + System.identityHashCode(this) + " "); 64 | buf.append("\n\tinetAddress: '"); 65 | buf.append(this.getInetAddress()); 66 | buf.append("']"); 67 | // buf.append("' source: "); 68 | // buf.append("\n\t" + source + ""); 69 | // buf.append("\n]"); 70 | return buf.toString(); 71 | } 72 | 73 | /* 74 | * (non-Javadoc) 75 | * @see java.lang.Object#clone() 76 | */ 77 | @Override 78 | public NetworkTopologyEventImpl clone() throws CloneNotSupportedException { 79 | return new NetworkTopologyEventImpl(getDNS(), getInetAddress()); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/bonjour/serviceinfo/AirTunesServiceInfo.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.bonjour.serviceinfo; 3 | 4 | import android.util.Log; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class AirTunesServiceInfo implements BonjourServiceInfo { 10 | private static final String TAG = AirTunesServiceInfo.class.getSimpleName(); 11 | 12 | public static final String SERVICE_TYPE = "_raop._tcp.local."; 13 | private static final int DEFAULT_PORT = 5000; 14 | 15 | private static final String DEFAULT_MODEL = "AppleTV3,2"; 16 | private static final String DEFAULT_SRCVERS = "150.33"; 17 | 18 | private String mDeviceId = null; 19 | private String mDeviceName = null; 20 | private int mPort = DEFAULT_PORT; 21 | 22 | private Map mProperties = new HashMap(); 23 | 24 | public AirTunesServiceInfo(byte[] deviceId, String name, int port) { 25 | if (deviceId.length != 6) 26 | return; 27 | 28 | mDeviceId = String.format("%02X%02X%02X%02X%02X%02X", 29 | deviceId[0], 30 | deviceId[1], 31 | deviceId[2], 32 | deviceId[3], 33 | deviceId[4], 34 | deviceId[5]); 35 | Log.d(TAG, String.format("deviceId: %s", mDeviceId)); 36 | 37 | mDeviceName = name; 38 | mPort = port; 39 | 40 | mProperties.put("am", DEFAULT_MODEL); 41 | mProperties.put("ch", "2"); 42 | mProperties.put("cn", "0,1,3"); 43 | mProperties.put("da", "true"); 44 | 45 | mProperties.put("et", "0,3,5"); 46 | mProperties.put("md", "0,1,2"); 47 | mProperties.put("pw", "false"); 48 | mProperties.put("rhd", "1.9.8"); 49 | 50 | mProperties.put("sf", "0x4"); 51 | mProperties.put("sr", "44100"); 52 | mProperties.put("ss", "16"); 53 | mProperties.put("sv", "false"); 54 | 55 | mProperties.put("tp", "UDP"); 56 | mProperties.put("txtvers", "1"); 57 | mProperties.put("vn", "65537"); 58 | mProperties.put("vs", DEFAULT_SRCVERS); 59 | mProperties.put("vv", "1"); 60 | } 61 | 62 | @Override 63 | public String getServiceName() { 64 | return String.format("%s@%s", mDeviceId, mDeviceName); 65 | } 66 | 67 | @Override 68 | public int getServicePort() { 69 | return mPort; 70 | } 71 | 72 | @Override 73 | public String getServiceType() { 74 | return SERVICE_TYPE; 75 | } 76 | 77 | @Override 78 | public Map getProperties() { 79 | return mProperties; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/bonjour/serviceinfo/AirTunesServiceInfo.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.bonjour.serviceinfo; 3 | 4 | import android.util.Log; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class AirTunesServiceInfo implements BonjourServiceInfo { 10 | private static final String TAG = AirTunesServiceInfo.class.getSimpleName(); 11 | 12 | public static final String SERVICE_TYPE = "_raop._tcp.local."; 13 | private static final int DEFAULT_PORT = 5000; 14 | 15 | private static final String DEFAULT_MODEL = "AppleTV3,2"; 16 | private static final String DEFAULT_SRCVERS = "150.33"; 17 | 18 | private String mDeviceId = null; 19 | private String mDeviceName = null; 20 | private int mPort = DEFAULT_PORT; 21 | 22 | private Map mProperties = new HashMap(); 23 | 24 | public AirTunesServiceInfo(byte[] deviceId, String name, int port) { 25 | if (deviceId.length != 6) 26 | return; 27 | 28 | mDeviceId = String.format("%02X%02X%02X%02X%02X%02X", 29 | deviceId[0], 30 | deviceId[1], 31 | deviceId[2], 32 | deviceId[3], 33 | deviceId[4], 34 | deviceId[5]); 35 | Log.d(TAG, String.format("deviceId: %s", mDeviceId)); 36 | 37 | mDeviceName = name; 38 | mPort = port; 39 | 40 | mProperties.put("am", DEFAULT_MODEL); 41 | mProperties.put("ch", "2"); 42 | mProperties.put("cn", "0,1,3"); 43 | mProperties.put("da", "true"); 44 | 45 | mProperties.put("et", "0,3,5"); 46 | mProperties.put("md", "0,1,2"); 47 | mProperties.put("pw", "false"); 48 | mProperties.put("rhd", "1.9.8"); 49 | 50 | mProperties.put("sf", "0x4"); 51 | mProperties.put("sr", "44100"); 52 | mProperties.put("ss", "16"); 53 | mProperties.put("sv", "false"); 54 | 55 | mProperties.put("tp", "UDP"); 56 | mProperties.put("txtvers", "1"); 57 | mProperties.put("vn", "65537"); 58 | mProperties.put("vs", DEFAULT_SRCVERS); 59 | mProperties.put("vv", "1"); 60 | } 61 | 62 | @Override 63 | public String getServiceName() { 64 | return String.format("%s@%s", mDeviceId, mDeviceName); 65 | } 66 | 67 | @Override 68 | public int getServicePort() { 69 | return mPort; 70 | } 71 | 72 | @Override 73 | public String getServiceType() { 74 | return SERVICE_TYPE; 75 | } 76 | 77 | @Override 78 | public Map getProperties() { 79 | return mProperties; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/tasks/resolver/TypeResolver.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks.resolver; 6 | 7 | import java.io.IOException; 8 | 9 | import javax.jmdns.impl.DNSOutgoing; 10 | import javax.jmdns.impl.DNSQuestion; 11 | import javax.jmdns.impl.DNSRecord; 12 | import javax.jmdns.impl.JmDNSImpl; 13 | import javax.jmdns.impl.JmDNSImpl.ServiceTypeEntry; 14 | import javax.jmdns.impl.constants.DNSConstants; 15 | import javax.jmdns.impl.constants.DNSRecordClass; 16 | import javax.jmdns.impl.constants.DNSRecordType; 17 | 18 | /** 19 | * Helper class to resolve service types. 20 | *

21 | * The TypeResolver queries three times consecutively for service types, and then removes itself from the timer. 22 | *

23 | * The TypeResolver will run only if JmDNS is in state ANNOUNCED. 24 | */ 25 | public class TypeResolver extends DNSResolverTask { 26 | 27 | /** 28 | * @param jmDNSImpl 29 | */ 30 | public TypeResolver(JmDNSImpl jmDNSImpl) { 31 | super(jmDNSImpl); 32 | } 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 37 | */ 38 | @Override 39 | public String getName() { 40 | return "TypeResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing) 46 | */ 47 | @Override 48 | protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException { 49 | DNSOutgoing newOut = out; 50 | long now = System.currentTimeMillis(); 51 | for (String type : this.getDns().getServiceTypes().keySet()) { 52 | ServiceTypeEntry typeEntry = this.getDns().getServiceTypes().get(type); 53 | newOut = this.addAnswer(newOut, new DNSRecord.Pointer("_services._dns-sd._udp.local.", DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, typeEntry.getType()), now); 54 | } 55 | return newOut; 56 | } 57 | 58 | /* 59 | * (non-Javadoc) 60 | * @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing) 61 | */ 62 | @Override 63 | protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException { 64 | return this.addQuestion(out, DNSQuestion.newQuestion("_services._dns-sd._udp.local.", DNSRecordType.TYPE_PTR, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 65 | } 66 | 67 | /* 68 | * (non-Javadoc) 69 | * @see javax.jmdns.impl.tasks.Resolver#description() 70 | */ 71 | @Override 72 | protected String description() { 73 | return "querying type"; 74 | } 75 | } -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/tasks/resolver/TypeResolver.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks.resolver; 6 | 7 | import java.io.IOException; 8 | 9 | import javax.jmdns.impl.DNSOutgoing; 10 | import javax.jmdns.impl.DNSQuestion; 11 | import javax.jmdns.impl.DNSRecord; 12 | import javax.jmdns.impl.JmDNSImpl; 13 | import javax.jmdns.impl.JmDNSImpl.ServiceTypeEntry; 14 | import javax.jmdns.impl.constants.DNSConstants; 15 | import javax.jmdns.impl.constants.DNSRecordClass; 16 | import javax.jmdns.impl.constants.DNSRecordType; 17 | 18 | /** 19 | * Helper class to resolve service types. 20 | *

21 | * The TypeResolver queries three times consecutively for service types, and then removes itself from the timer. 22 | *

23 | * The TypeResolver will run only if JmDNS is in state ANNOUNCED. 24 | */ 25 | public class TypeResolver extends DNSResolverTask { 26 | 27 | /** 28 | * @param jmDNSImpl 29 | */ 30 | public TypeResolver(JmDNSImpl jmDNSImpl) { 31 | super(jmDNSImpl); 32 | } 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 37 | */ 38 | @Override 39 | public String getName() { 40 | return "TypeResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing) 46 | */ 47 | @Override 48 | protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException { 49 | DNSOutgoing newOut = out; 50 | long now = System.currentTimeMillis(); 51 | for (String type : this.getDns().getServiceTypes().keySet()) { 52 | ServiceTypeEntry typeEntry = this.getDns().getServiceTypes().get(type); 53 | newOut = this.addAnswer(newOut, new DNSRecord.Pointer("_services._dns-sd._udp.local.", DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, typeEntry.getType()), now); 54 | } 55 | return newOut; 56 | } 57 | 58 | /* 59 | * (non-Javadoc) 60 | * @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing) 61 | */ 62 | @Override 63 | protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException { 64 | return this.addQuestion(out, DNSQuestion.newQuestion("_services._dns-sd._udp.local.", DNSRecordType.TYPE_PTR, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 65 | } 66 | 67 | /* 68 | * (non-Javadoc) 69 | * @see javax.jmdns.impl.tasks.Resolver#description() 70 | */ 71 | @Override 72 | protected String description() { 73 | return "querying type"; 74 | } 75 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/tasks/resolver/ServiceResolver.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks.resolver; 6 | 7 | import java.io.IOException; 8 | 9 | import javax.jmdns.ServiceInfo; 10 | import javax.jmdns.impl.DNSOutgoing; 11 | import javax.jmdns.impl.DNSQuestion; 12 | import javax.jmdns.impl.DNSRecord; 13 | import javax.jmdns.impl.JmDNSImpl; 14 | import javax.jmdns.impl.constants.DNSConstants; 15 | import javax.jmdns.impl.constants.DNSRecordClass; 16 | import javax.jmdns.impl.constants.DNSRecordType; 17 | 18 | /** 19 | * The ServiceResolver queries three times consecutively for services of a given type, and then removes itself from the timer. 20 | *

21 | * The ServiceResolver will run only if JmDNS is in state ANNOUNCED. REMIND: Prevent having multiple service resolvers for the same type in the timer queue. 22 | */ 23 | public class ServiceResolver extends DNSResolverTask { 24 | 25 | private final String _type; 26 | 27 | public ServiceResolver(JmDNSImpl jmDNSImpl, String type) { 28 | super(jmDNSImpl); 29 | this._type = type; 30 | } 31 | 32 | /* 33 | * (non-Javadoc) 34 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 35 | */ 36 | @Override 37 | public String getName() { 38 | return "ServiceResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 39 | } 40 | 41 | /* 42 | * (non-Javadoc) 43 | * @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing) 44 | */ 45 | @Override 46 | protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException { 47 | DNSOutgoing newOut = out; 48 | long now = System.currentTimeMillis(); 49 | for (ServiceInfo info : this.getDns().getServices().values()) { 50 | newOut = this.addAnswer(newOut, new DNSRecord.Pointer(info.getType(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getQualifiedName()), now); 51 | // newOut = this.addAnswer(newOut, new DNSRecord.Service(info.getQualifiedName(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getPriority(), info.getWeight(), info.getPort(), 52 | // this.getDns().getLocalHost().getName()), now); 53 | } 54 | return newOut; 55 | } 56 | 57 | /* 58 | * (non-Javadoc) 59 | * @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing) 60 | */ 61 | @Override 62 | protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException { 63 | DNSOutgoing newOut = out; 64 | newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_type, DNSRecordType.TYPE_PTR, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 65 | // newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_type, DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 66 | return newOut; 67 | } 68 | 69 | /* 70 | * (non-Javadoc) 71 | * @see javax.jmdns.impl.tasks.Resolver#description() 72 | */ 73 | @Override 74 | protected String description() { 75 | return "querying service"; 76 | } 77 | } -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/tasks/resolver/ServiceResolver.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks.resolver; 6 | 7 | import java.io.IOException; 8 | 9 | import javax.jmdns.ServiceInfo; 10 | import javax.jmdns.impl.DNSOutgoing; 11 | import javax.jmdns.impl.DNSQuestion; 12 | import javax.jmdns.impl.DNSRecord; 13 | import javax.jmdns.impl.JmDNSImpl; 14 | import javax.jmdns.impl.constants.DNSConstants; 15 | import javax.jmdns.impl.constants.DNSRecordClass; 16 | import javax.jmdns.impl.constants.DNSRecordType; 17 | 18 | /** 19 | * The ServiceResolver queries three times consecutively for services of a given type, and then removes itself from the timer. 20 | *

21 | * The ServiceResolver will run only if JmDNS is in state ANNOUNCED. REMIND: Prevent having multiple service resolvers for the same type in the timer queue. 22 | */ 23 | public class ServiceResolver extends DNSResolverTask { 24 | 25 | private final String _type; 26 | 27 | public ServiceResolver(JmDNSImpl jmDNSImpl, String type) { 28 | super(jmDNSImpl); 29 | this._type = type; 30 | } 31 | 32 | /* 33 | * (non-Javadoc) 34 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 35 | */ 36 | @Override 37 | public String getName() { 38 | return "ServiceResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 39 | } 40 | 41 | /* 42 | * (non-Javadoc) 43 | * @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing) 44 | */ 45 | @Override 46 | protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException { 47 | DNSOutgoing newOut = out; 48 | long now = System.currentTimeMillis(); 49 | for (ServiceInfo info : this.getDns().getServices().values()) { 50 | newOut = this.addAnswer(newOut, new DNSRecord.Pointer(info.getType(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getQualifiedName()), now); 51 | // newOut = this.addAnswer(newOut, new DNSRecord.Service(info.getQualifiedName(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getPriority(), info.getWeight(), info.getPort(), 52 | // this.getDns().getLocalHost().getName()), now); 53 | } 54 | return newOut; 55 | } 56 | 57 | /* 58 | * (non-Javadoc) 59 | * @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing) 60 | */ 61 | @Override 62 | protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException { 63 | DNSOutgoing newOut = out; 64 | newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_type, DNSRecordType.TYPE_PTR, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 65 | // newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_type, DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 66 | return newOut; 67 | } 68 | 69 | /* 70 | * (non-Javadoc) 71 | * @see javax.jmdns.impl.tasks.Resolver#description() 72 | */ 73 | @Override 74 | protected String description() { 75 | return "querying service"; 76 | } 77 | } -------------------------------------------------------------------------------- /TVMiracast/src/com/milink/milink/server/MiLinkServer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.server; 3 | 4 | import android.util.Log; 5 | 6 | import com.milink.milink.common.IQ; 7 | import com.milink.net.asio.tcp.server.TcpConn; 8 | import com.milink.net.asio.tcp.server.TcpServer; 9 | import com.milink.net.asio.tcp.server.TcpServerListener; 10 | 11 | public class MiLinkServer implements TcpServerListener { 12 | 13 | private static final String TAG = MiLinkServer.class.getSimpleName(); 14 | 15 | private TcpServer mServer = null; 16 | private MiLinkServerListener mListener = null; 17 | private TcpConn mLastConnection = null; 18 | 19 | public MiLinkServer(MiLinkServerListener listener) { 20 | mServer = new TcpServer(0, this); 21 | mListener = listener; 22 | } 23 | 24 | public boolean start() { 25 | return mServer.start(); 26 | } 27 | 28 | public boolean stop() { 29 | return mServer.stop(); 30 | } 31 | 32 | public int getListenPort() { 33 | return mServer.getListenPort(); 34 | } 35 | 36 | public boolean publishEvent(IQ iq) { 37 | boolean result = false; 38 | 39 | do 40 | { 41 | if (mLastConnection == null) 42 | break; 43 | 44 | if (iq.getType() != IQ.Type.Event) 45 | break; 46 | 47 | String msg = iq.toString(); 48 | if (msg == null) 49 | break; 50 | 51 | result = mServer.send(mLastConnection, msg.getBytes()); 52 | } while (false); 53 | 54 | return result; 55 | } 56 | 57 | public boolean send(String ip, int port, IQ iq) { 58 | boolean result = false; 59 | 60 | do 61 | { 62 | String msg = iq.toString(); 63 | if (msg == null) 64 | break; 65 | 66 | TcpConn conn = mServer.getConnPool().getConn(ip, port); 67 | if (conn == null) 68 | break; 69 | 70 | result = mServer.send(conn, msg.getBytes()); 71 | } while (false); 72 | 73 | return result; 74 | } 75 | 76 | @Override 77 | public void onAccept(TcpServer server, TcpConn conn) { 78 | Log.d(TAG, String.format("onAccept: %s:%d", conn.getIp(), conn.getPort())); 79 | 80 | mListener.onAccept(this, conn.getIp(), conn.getPort()); 81 | 82 | if (mLastConnection != null) { 83 | mServer.closeConnection(mLastConnection); 84 | } 85 | 86 | mLastConnection = conn; 87 | } 88 | 89 | @Override 90 | public void onReceived(TcpServer server, TcpConn conn, byte[] data) { 91 | Log.d(TAG, String.format("onReceived: %s:%d", conn.getIp(), conn.getPort())); 92 | 93 | IQ iq = IQ.create(data); 94 | if (iq != null) { 95 | mListener.onReceived(this, conn.getIp(), conn.getPort(), iq); 96 | } 97 | } 98 | 99 | @Override 100 | public void onConnectionClosed(TcpServer server, TcpConn conn) { 101 | Log.d(TAG, String.format("onConnectionClosed: %s:%d", conn.getIp(), conn.getPort())); 102 | 103 | mListener.onConnectionClosed(this, conn.getIp(), conn.getPort()); 104 | 105 | if (mLastConnection.equals(conn)) { 106 | mLastConnection = null; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/milink/milink/server/MiLinkServer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.milink.milink.server; 3 | 4 | import android.util.Log; 5 | 6 | import com.milink.milink.common.IQ; 7 | import com.milink.net.asio.tcp.server.TcpConn; 8 | import com.milink.net.asio.tcp.server.TcpServer; 9 | import com.milink.net.asio.tcp.server.TcpServerListener; 10 | 11 | public class MiLinkServer implements TcpServerListener { 12 | 13 | private static final String TAG = MiLinkServer.class.getSimpleName(); 14 | 15 | private TcpServer mServer = null; 16 | private MiLinkServerListener mListener = null; 17 | private TcpConn mLastConnection = null; 18 | 19 | public MiLinkServer(MiLinkServerListener listener) { 20 | mServer = new TcpServer(0, this); 21 | mListener = listener; 22 | } 23 | 24 | public boolean start() { 25 | return mServer.start(); 26 | } 27 | 28 | public boolean stop() { 29 | return mServer.stop(); 30 | } 31 | 32 | public int getListenPort() { 33 | return mServer.getListenPort(); 34 | } 35 | 36 | public boolean publishEvent(IQ iq) { 37 | boolean result = false; 38 | 39 | do 40 | { 41 | if (mLastConnection == null) 42 | break; 43 | 44 | if (iq.getType() != IQ.Type.Event) 45 | break; 46 | 47 | String msg = iq.toString(); 48 | if (msg == null) 49 | break; 50 | 51 | result = mServer.send(mLastConnection, msg.getBytes()); 52 | } while (false); 53 | 54 | return result; 55 | } 56 | 57 | public boolean send(String ip, int port, IQ iq) { 58 | boolean result = false; 59 | 60 | do 61 | { 62 | String msg = iq.toString(); 63 | if (msg == null) 64 | break; 65 | 66 | TcpConn conn = mServer.getConnPool().getConn(ip, port); 67 | if (conn == null) 68 | break; 69 | 70 | result = mServer.send(conn, msg.getBytes()); 71 | } while (false); 72 | 73 | return result; 74 | } 75 | 76 | @Override 77 | public void onAccept(TcpServer server, TcpConn conn) { 78 | Log.d(TAG, String.format("onAccept: %s:%d", conn.getIp(), conn.getPort())); 79 | 80 | mListener.onAccept(this, conn.getIp(), conn.getPort()); 81 | 82 | if (mLastConnection != null) { 83 | mServer.closeConnection(mLastConnection); 84 | } 85 | 86 | mLastConnection = conn; 87 | } 88 | 89 | @Override 90 | public void onReceived(TcpServer server, TcpConn conn, byte[] data) { 91 | Log.d(TAG, String.format("onReceived: %s:%d", conn.getIp(), conn.getPort())); 92 | 93 | IQ iq = IQ.create(data); 94 | if (iq != null) { 95 | mListener.onReceived(this, conn.getIp(), conn.getPort(), iq); 96 | } 97 | } 98 | 99 | @Override 100 | public void onConnectionClosed(TcpServer server, TcpConn conn) { 101 | Log.d(TAG, String.format("onConnectionClosed: %s:%d", conn.getIp(), conn.getPort())); 102 | 103 | mListener.onConnectionClosed(this, conn.getIp(), conn.getPort()); 104 | 105 | if (mLastConnection.equals(conn)) { 106 | mLastConnection = null; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/SocketListener.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl; 6 | 7 | import java.io.IOException; 8 | import java.net.DatagramPacket; 9 | import java.util.logging.Level; 10 | import java.util.logging.Logger; 11 | 12 | import javax.jmdns.impl.constants.DNSConstants; 13 | 14 | /** 15 | * Listen for multicast packets. 16 | */ 17 | class SocketListener extends Thread { 18 | static Logger logger = Logger.getLogger(SocketListener.class.getName()); 19 | 20 | /** 21 | * 22 | */ 23 | private final JmDNSImpl _jmDNSImpl; 24 | 25 | /** 26 | * @param jmDNSImpl 27 | */ 28 | SocketListener(JmDNSImpl jmDNSImpl) { 29 | super("SocketListener(" + (jmDNSImpl != null ? jmDNSImpl.getName() : "") + ")"); 30 | this.setDaemon(true); 31 | this._jmDNSImpl = jmDNSImpl; 32 | } 33 | 34 | @Override 35 | public void run() { 36 | try { 37 | byte buf[] = new byte[DNSConstants.MAX_MSG_ABSOLUTE]; 38 | DatagramPacket packet = new DatagramPacket(buf, buf.length); 39 | while (!this._jmDNSImpl.isCanceling() && !this._jmDNSImpl.isCanceled()) { 40 | packet.setLength(buf.length); 41 | this._jmDNSImpl.getSocket().receive(packet); 42 | if (this._jmDNSImpl.isCanceling() || this._jmDNSImpl.isCanceled() || this._jmDNSImpl.isClosing() || this._jmDNSImpl.isClosed()) { 43 | break; 44 | } 45 | try { 46 | if (this._jmDNSImpl.getLocalHost().shouldIgnorePacket(packet)) { 47 | continue; 48 | } 49 | 50 | DNSIncoming msg = new DNSIncoming(packet); 51 | if (msg.isValidResponseCode()) { 52 | if (logger.isLoggable(Level.FINEST)) { 53 | logger.finest(this.getName() + ".run() JmDNS in:" + msg.print(true)); 54 | } 55 | if (msg.isQuery()) { 56 | if (packet.getPort() != DNSConstants.MDNS_PORT) { 57 | this._jmDNSImpl.handleQuery(msg, packet.getAddress(), packet.getPort()); 58 | } 59 | this._jmDNSImpl.handleQuery(msg, this._jmDNSImpl.getGroup(), DNSConstants.MDNS_PORT); 60 | } else { 61 | this._jmDNSImpl.handleResponse(msg); 62 | } 63 | } else { 64 | if (logger.isLoggable(Level.FINE)) { 65 | logger.fine(this.getName() + ".run() JmDNS in message with error code:" + msg.print(true)); 66 | } 67 | } 68 | } catch (IOException e) { 69 | logger.log(Level.WARNING, this.getName() + ".run() exception ", e); 70 | } 71 | } 72 | } catch (IOException e) { 73 | if (!this._jmDNSImpl.isCanceling() && !this._jmDNSImpl.isCanceled() && !this._jmDNSImpl.isClosing() && !this._jmDNSImpl.isClosed()) { 74 | logger.log(Level.WARNING, this.getName() + ".run() exception ", e); 75 | this._jmDNSImpl.recover(); 76 | } 77 | } 78 | if (logger.isLoggable(Level.FINEST)) { 79 | logger.finest(this.getName() + ".run() exiting."); 80 | } 81 | } 82 | 83 | public JmDNSImpl getDns() { 84 | return _jmDNSImpl; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/SocketListener.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl; 6 | 7 | import java.io.IOException; 8 | import java.net.DatagramPacket; 9 | import java.util.logging.Level; 10 | import java.util.logging.Logger; 11 | 12 | import javax.jmdns.impl.constants.DNSConstants; 13 | 14 | /** 15 | * Listen for multicast packets. 16 | */ 17 | class SocketListener extends Thread { 18 | static Logger logger = Logger.getLogger(SocketListener.class.getName()); 19 | 20 | /** 21 | * 22 | */ 23 | private final JmDNSImpl _jmDNSImpl; 24 | 25 | /** 26 | * @param jmDNSImpl 27 | */ 28 | SocketListener(JmDNSImpl jmDNSImpl) { 29 | super("SocketListener(" + (jmDNSImpl != null ? jmDNSImpl.getName() : "") + ")"); 30 | this.setDaemon(true); 31 | this._jmDNSImpl = jmDNSImpl; 32 | } 33 | 34 | @Override 35 | public void run() { 36 | try { 37 | byte buf[] = new byte[DNSConstants.MAX_MSG_ABSOLUTE]; 38 | DatagramPacket packet = new DatagramPacket(buf, buf.length); 39 | while (!this._jmDNSImpl.isCanceling() && !this._jmDNSImpl.isCanceled()) { 40 | packet.setLength(buf.length); 41 | this._jmDNSImpl.getSocket().receive(packet); 42 | if (this._jmDNSImpl.isCanceling() || this._jmDNSImpl.isCanceled() || this._jmDNSImpl.isClosing() || this._jmDNSImpl.isClosed()) { 43 | break; 44 | } 45 | try { 46 | if (this._jmDNSImpl.getLocalHost().shouldIgnorePacket(packet)) { 47 | continue; 48 | } 49 | 50 | DNSIncoming msg = new DNSIncoming(packet); 51 | if (msg.isValidResponseCode()) { 52 | if (logger.isLoggable(Level.FINEST)) { 53 | logger.finest(this.getName() + ".run() JmDNS in:" + msg.print(true)); 54 | } 55 | if (msg.isQuery()) { 56 | if (packet.getPort() != DNSConstants.MDNS_PORT) { 57 | this._jmDNSImpl.handleQuery(msg, packet.getAddress(), packet.getPort()); 58 | } 59 | this._jmDNSImpl.handleQuery(msg, this._jmDNSImpl.getGroup(), DNSConstants.MDNS_PORT); 60 | } else { 61 | this._jmDNSImpl.handleResponse(msg); 62 | } 63 | } else { 64 | if (logger.isLoggable(Level.FINE)) { 65 | logger.fine(this.getName() + ".run() JmDNS in message with error code:" + msg.print(true)); 66 | } 67 | } 68 | } catch (IOException e) { 69 | logger.log(Level.WARNING, this.getName() + ".run() exception ", e); 70 | } 71 | } 72 | } catch (IOException e) { 73 | if (!this._jmDNSImpl.isCanceling() && !this._jmDNSImpl.isCanceled() && !this._jmDNSImpl.isClosing() && !this._jmDNSImpl.isClosed()) { 74 | logger.log(Level.WARNING, this.getName() + ".run() exception ", e); 75 | this._jmDNSImpl.recover(); 76 | } 77 | } 78 | if (logger.isLoggable(Level.FINEST)) { 79 | logger.finest(this.getName() + ".run() exiting."); 80 | } 81 | } 82 | 83 | public JmDNSImpl getDns() { 84 | return _jmDNSImpl; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/ServiceEventImpl.java: -------------------------------------------------------------------------------- 1 | // /Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl; 6 | 7 | import javax.jmdns.JmDNS; 8 | import javax.jmdns.ServiceEvent; 9 | import javax.jmdns.ServiceInfo; 10 | 11 | /** 12 | * ServiceEvent. 13 | * 14 | * @author Werner Randelshofer, Rick Blair 15 | */ 16 | /** 17 | * 18 | */ 19 | public class ServiceEventImpl extends ServiceEvent { 20 | /** 21 | * 22 | */ 23 | private static final long serialVersionUID = 7107973622016897488L; 24 | // private static Logger logger = Logger.getLogger(ServiceEvent.class.getName()); 25 | /** 26 | * The type name of the service. 27 | */ 28 | private final String _type; 29 | /** 30 | * The instance name of the service. Or null, if the event was fired to a service type listener. 31 | */ 32 | private final String _name; 33 | /** 34 | * The service info record, or null if the service could be be resolved. This is also null, if the event was fired to a service type listener. 35 | */ 36 | private final ServiceInfo _info; 37 | 38 | /** 39 | * Creates a new instance. 40 | * 41 | * @param jmDNS 42 | * the JmDNS instance which originated the event. 43 | * @param type 44 | * the type name of the service. 45 | * @param name 46 | * the instance name of the service. 47 | * @param info 48 | * the service info record, or null if the service could be be resolved. 49 | */ 50 | public ServiceEventImpl(JmDNSImpl jmDNS, String type, String name, ServiceInfo info) { 51 | super(jmDNS); 52 | this._type = type; 53 | this._name = name; 54 | this._info = info; 55 | } 56 | 57 | /* 58 | * (non-Javadoc) 59 | * @see javax.jmdns.ServiceEvent#getDNS() 60 | */ 61 | @Override 62 | public JmDNS getDNS() { 63 | return (JmDNS) getSource(); 64 | } 65 | 66 | /* 67 | * (non-Javadoc) 68 | * @see javax.jmdns.ServiceEvent#getType() 69 | */ 70 | @Override 71 | public String getType() { 72 | return _type; 73 | } 74 | 75 | /* 76 | * (non-Javadoc) 77 | * @see javax.jmdns.ServiceEvent#getName() 78 | */ 79 | @Override 80 | public String getName() { 81 | return _name; 82 | } 83 | 84 | /* 85 | * (non-Javadoc) 86 | * @see java.util.EventObject#toString() 87 | */ 88 | @Override 89 | public String toString() { 90 | StringBuilder buf = new StringBuilder(); 91 | buf.append("[" + this.getClass().getSimpleName() + "@" + System.identityHashCode(this) + " "); 92 | buf.append("\n\tname: '"); 93 | buf.append(this.getName()); 94 | buf.append("' type: '"); 95 | buf.append(this.getType()); 96 | buf.append("' info: '"); 97 | buf.append(this.getInfo()); 98 | buf.append("']"); 99 | // buf.append("' source: "); 100 | // buf.append("\n\t" + source + ""); 101 | // buf.append("\n]"); 102 | return buf.toString(); 103 | } 104 | 105 | /* 106 | * (non-Javadoc) 107 | * @see javax.jmdns.ServiceEvent#getInfo() 108 | */ 109 | @Override 110 | public ServiceInfo getInfo() { 111 | return _info; 112 | } 113 | 114 | /* 115 | * (non-Javadoc) 116 | * @see javax.jmdns.ServiceEvent#clone() 117 | */ 118 | @Override 119 | public ServiceEventImpl clone() { 120 | ServiceInfoImpl newInfo = new ServiceInfoImpl(this.getInfo()); 121 | return new ServiceEventImpl((JmDNSImpl) this.getDNS(), this.getType(), this.getName(), newInfo); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/ServiceEventImpl.java: -------------------------------------------------------------------------------- 1 | // /Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl; 6 | 7 | import javax.jmdns.JmDNS; 8 | import javax.jmdns.ServiceEvent; 9 | import javax.jmdns.ServiceInfo; 10 | 11 | /** 12 | * ServiceEvent. 13 | * 14 | * @author Werner Randelshofer, Rick Blair 15 | */ 16 | /** 17 | * 18 | */ 19 | public class ServiceEventImpl extends ServiceEvent { 20 | /** 21 | * 22 | */ 23 | private static final long serialVersionUID = 7107973622016897488L; 24 | // private static Logger logger = Logger.getLogger(ServiceEvent.class.getName()); 25 | /** 26 | * The type name of the service. 27 | */ 28 | private final String _type; 29 | /** 30 | * The instance name of the service. Or null, if the event was fired to a service type listener. 31 | */ 32 | private final String _name; 33 | /** 34 | * The service info record, or null if the service could be be resolved. This is also null, if the event was fired to a service type listener. 35 | */ 36 | private final ServiceInfo _info; 37 | 38 | /** 39 | * Creates a new instance. 40 | * 41 | * @param jmDNS 42 | * the JmDNS instance which originated the event. 43 | * @param type 44 | * the type name of the service. 45 | * @param name 46 | * the instance name of the service. 47 | * @param info 48 | * the service info record, or null if the service could be be resolved. 49 | */ 50 | public ServiceEventImpl(JmDNSImpl jmDNS, String type, String name, ServiceInfo info) { 51 | super(jmDNS); 52 | this._type = type; 53 | this._name = name; 54 | this._info = info; 55 | } 56 | 57 | /* 58 | * (non-Javadoc) 59 | * @see javax.jmdns.ServiceEvent#getDNS() 60 | */ 61 | @Override 62 | public JmDNS getDNS() { 63 | return (JmDNS) getSource(); 64 | } 65 | 66 | /* 67 | * (non-Javadoc) 68 | * @see javax.jmdns.ServiceEvent#getType() 69 | */ 70 | @Override 71 | public String getType() { 72 | return _type; 73 | } 74 | 75 | /* 76 | * (non-Javadoc) 77 | * @see javax.jmdns.ServiceEvent#getName() 78 | */ 79 | @Override 80 | public String getName() { 81 | return _name; 82 | } 83 | 84 | /* 85 | * (non-Javadoc) 86 | * @see java.util.EventObject#toString() 87 | */ 88 | @Override 89 | public String toString() { 90 | StringBuilder buf = new StringBuilder(); 91 | buf.append("[" + this.getClass().getSimpleName() + "@" + System.identityHashCode(this) + " "); 92 | buf.append("\n\tname: '"); 93 | buf.append(this.getName()); 94 | buf.append("' type: '"); 95 | buf.append(this.getType()); 96 | buf.append("' info: '"); 97 | buf.append(this.getInfo()); 98 | buf.append("']"); 99 | // buf.append("' source: "); 100 | // buf.append("\n\t" + source + ""); 101 | // buf.append("\n]"); 102 | return buf.toString(); 103 | } 104 | 105 | /* 106 | * (non-Javadoc) 107 | * @see javax.jmdns.ServiceEvent#getInfo() 108 | */ 109 | @Override 110 | public ServiceInfo getInfo() { 111 | return _info; 112 | } 113 | 114 | /* 115 | * (non-Javadoc) 116 | * @see javax.jmdns.ServiceEvent#clone() 117 | */ 118 | @Override 119 | public ServiceEventImpl clone() { 120 | ServiceInfoImpl newInfo = new ServiceInfoImpl(this.getInfo()); 121 | return new ServiceEventImpl((JmDNSImpl) this.getDNS(), this.getType(), this.getName(), newInfo); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/constants/DNSRecordClass.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl.constants; 5 | 6 | import java.util.logging.Level; 7 | import java.util.logging.Logger; 8 | 9 | /** 10 | * DNS Record Class 11 | * 12 | * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair 13 | */ 14 | public enum DNSRecordClass { 15 | /** 16 | * 17 | */ 18 | CLASS_UNKNOWN("?", 0), 19 | /** 20 | * static final Internet 21 | */ 22 | CLASS_IN("in", 1), 23 | /** 24 | * CSNET 25 | */ 26 | CLASS_CS("cs", 2), 27 | /** 28 | * CHAOS 29 | */ 30 | CLASS_CH("ch", 3), 31 | /** 32 | * Hesiod 33 | */ 34 | CLASS_HS("hs", 4), 35 | /** 36 | * Used in DNS UPDATE [RFC 2136] 37 | */ 38 | CLASS_NONE("none", 254), 39 | /** 40 | * Not a DNS class, but a DNS query class, meaning "all classes" 41 | */ 42 | CLASS_ANY("any", 255); 43 | 44 | private static Logger logger = Logger.getLogger(DNSRecordClass.class.getName()); 45 | 46 | /** 47 | * Multicast DNS uses the bottom 15 bits to identify the record class...
48 | * Except for pseudo records like OPT. 49 | */ 50 | public static final int CLASS_MASK = 0x7FFF; 51 | 52 | /** 53 | * For answers the top bit indicates that all other cached records are now invalid.
54 | * For questions it indicates that we should send a unicast response. 55 | */ 56 | public static final int CLASS_UNIQUE = 0x8000; 57 | 58 | /** 59 | * 60 | */ 61 | public static final boolean UNIQUE = true; 62 | 63 | /** 64 | * 65 | */ 66 | public static final boolean NOT_UNIQUE = false; 67 | 68 | private final String _externalName; 69 | 70 | private final int _index; 71 | 72 | DNSRecordClass(String name, int index) { 73 | _externalName = name; 74 | _index = index; 75 | } 76 | 77 | /** 78 | * Return the string representation of this type 79 | * 80 | * @return String 81 | */ 82 | public String externalName() { 83 | return _externalName; 84 | } 85 | 86 | /** 87 | * Return the numeric value of this type 88 | * 89 | * @return String 90 | */ 91 | public int indexValue() { 92 | return _index; 93 | } 94 | 95 | /** 96 | * Checks if the class is unique 97 | * 98 | * @param index 99 | * @return true is the class is unique, false otherwise. 100 | */ 101 | public boolean isUnique(int index) { 102 | return (this != CLASS_UNKNOWN) && ((index & CLASS_UNIQUE) != 0); 103 | } 104 | 105 | /** 106 | * @param name 107 | * @return class for name 108 | */ 109 | public static DNSRecordClass classForName(String name) { 110 | if (name != null) { 111 | String aName = name.toLowerCase(); 112 | for (DNSRecordClass aClass : DNSRecordClass.values()) { 113 | if (aClass._externalName.equals(aName)) return aClass; 114 | } 115 | } 116 | logger.log(Level.WARNING, "Could not find record class for name: " + name); 117 | return CLASS_UNKNOWN; 118 | } 119 | 120 | /** 121 | * @param index 122 | * @return class for name 123 | */ 124 | public static DNSRecordClass classForIndex(int index) { 125 | int maskedIndex = index & CLASS_MASK; 126 | for (DNSRecordClass aClass : DNSRecordClass.values()) { 127 | if (aClass._index == maskedIndex) return aClass; 128 | } 129 | logger.log(Level.WARNING, "Could not find record class for index: " + index); 130 | return CLASS_UNKNOWN; 131 | } 132 | 133 | @Override 134 | public String toString() { 135 | return this.name() + " index " + this.indexValue(); 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/constants/DNSRecordClass.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl.constants; 5 | 6 | import java.util.logging.Level; 7 | import java.util.logging.Logger; 8 | 9 | /** 10 | * DNS Record Class 11 | * 12 | * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair 13 | */ 14 | public enum DNSRecordClass { 15 | /** 16 | * 17 | */ 18 | CLASS_UNKNOWN("?", 0), 19 | /** 20 | * static final Internet 21 | */ 22 | CLASS_IN("in", 1), 23 | /** 24 | * CSNET 25 | */ 26 | CLASS_CS("cs", 2), 27 | /** 28 | * CHAOS 29 | */ 30 | CLASS_CH("ch", 3), 31 | /** 32 | * Hesiod 33 | */ 34 | CLASS_HS("hs", 4), 35 | /** 36 | * Used in DNS UPDATE [RFC 2136] 37 | */ 38 | CLASS_NONE("none", 254), 39 | /** 40 | * Not a DNS class, but a DNS query class, meaning "all classes" 41 | */ 42 | CLASS_ANY("any", 255); 43 | 44 | private static Logger logger = Logger.getLogger(DNSRecordClass.class.getName()); 45 | 46 | /** 47 | * Multicast DNS uses the bottom 15 bits to identify the record class...
48 | * Except for pseudo records like OPT. 49 | */ 50 | public static final int CLASS_MASK = 0x7FFF; 51 | 52 | /** 53 | * For answers the top bit indicates that all other cached records are now invalid.
54 | * For questions it indicates that we should send a unicast response. 55 | */ 56 | public static final int CLASS_UNIQUE = 0x8000; 57 | 58 | /** 59 | * 60 | */ 61 | public static final boolean UNIQUE = true; 62 | 63 | /** 64 | * 65 | */ 66 | public static final boolean NOT_UNIQUE = false; 67 | 68 | private final String _externalName; 69 | 70 | private final int _index; 71 | 72 | DNSRecordClass(String name, int index) { 73 | _externalName = name; 74 | _index = index; 75 | } 76 | 77 | /** 78 | * Return the string representation of this type 79 | * 80 | * @return String 81 | */ 82 | public String externalName() { 83 | return _externalName; 84 | } 85 | 86 | /** 87 | * Return the numeric value of this type 88 | * 89 | * @return String 90 | */ 91 | public int indexValue() { 92 | return _index; 93 | } 94 | 95 | /** 96 | * Checks if the class is unique 97 | * 98 | * @param index 99 | * @return true is the class is unique, false otherwise. 100 | */ 101 | public boolean isUnique(int index) { 102 | return (this != CLASS_UNKNOWN) && ((index & CLASS_UNIQUE) != 0); 103 | } 104 | 105 | /** 106 | * @param name 107 | * @return class for name 108 | */ 109 | public static DNSRecordClass classForName(String name) { 110 | if (name != null) { 111 | String aName = name.toLowerCase(); 112 | for (DNSRecordClass aClass : DNSRecordClass.values()) { 113 | if (aClass._externalName.equals(aName)) return aClass; 114 | } 115 | } 116 | logger.log(Level.WARNING, "Could not find record class for name: " + name); 117 | return CLASS_UNKNOWN; 118 | } 119 | 120 | /** 121 | * @param index 122 | * @return class for name 123 | */ 124 | public static DNSRecordClass classForIndex(int index) { 125 | int maskedIndex = index & CLASS_MASK; 126 | for (DNSRecordClass aClass : DNSRecordClass.values()) { 127 | if (aClass._index == maskedIndex) return aClass; 128 | } 129 | logger.log(Level.WARNING, "Could not find record class for index: " + index); 130 | return CLASS_UNKNOWN; 131 | } 132 | 133 | @Override 134 | public String toString() { 135 | return this.name() + " index " + this.indexValue(); 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /PhoneMiracast/src/com/test/miracast/ParamStart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.test.miracast; 3 | 4 | import org.w3c.dom.DOMException; 5 | import org.w3c.dom.Document; 6 | import org.w3c.dom.Element; 7 | import org.w3c.dom.NodeList; 8 | import org.xml.sax.SAXException; 9 | 10 | import java.io.ByteArrayInputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | 14 | import javax.xml.parsers.DocumentBuilder; 15 | import javax.xml.parsers.DocumentBuilderFactory; 16 | import javax.xml.parsers.ParserConfigurationException; 17 | 18 | public class ParamStart { 19 | 20 | private String mIp = null; 21 | private int mPort = 0; 22 | 23 | public static ParamStart create(byte bytes[]) { 24 | if (bytes == null) 25 | return null; 26 | 27 | ParamStart param = new ParamStart(); 28 | if (!param.load(bytes)) 29 | return null; 30 | 31 | return param; 32 | } 33 | 34 | public static ParamStart create(String ip, int port) { 35 | ParamStart param = new ParamStart(); 36 | param.mIp = ip; 37 | param.mPort = port; 38 | 39 | return param; 40 | } 41 | 42 | public String getIp() { 43 | return mIp; 44 | } 45 | 46 | public void setIp(String mIp) { 47 | this.mIp = mIp; 48 | } 49 | 50 | public int getPort() { 51 | return mPort; 52 | } 53 | 54 | public void setPort(int mPort) { 55 | this.mPort = mPort; 56 | } 57 | 58 | public boolean load(byte bytes[]) { 59 | boolean result = false; 60 | 61 | do { 62 | if (bytes == null) 63 | break; 64 | 65 | InputStream is = new ByteArrayInputStream(bytes); 66 | DocumentBuilderFactory factory = DocumentBuilderFactory 67 | .newInstance(); 68 | 69 | try { 70 | DocumentBuilder builder = factory.newDocumentBuilder(); 71 | Document document = builder.parse(is); 72 | 73 | Element root = document.getDocumentElement(); 74 | if (root == null) 75 | break; 76 | 77 | if (!root.getTagName().equalsIgnoreCase("root")) 78 | break; 79 | 80 | Element tagIp = getTag(root, "ip"); 81 | if (tagIp == null) 82 | break; 83 | 84 | Element tagPort = getTag(root, "port"); 85 | if (tagPort == null) 86 | break; 87 | 88 | mIp = tagIp.getTextContent(); 89 | 90 | try { 91 | mPort = Integer.valueOf(tagPort.getTextContent()); 92 | } catch (NumberFormatException e) { 93 | e.printStackTrace(); 94 | mPort = 0; 95 | } 96 | 97 | result = true; 98 | } catch (ParserConfigurationException e) { 99 | e.printStackTrace(); 100 | } catch (SAXException e) { 101 | e.printStackTrace(); 102 | } catch (DOMException e) { 103 | e.printStackTrace(); 104 | } catch (IOException e) { 105 | e.printStackTrace(); 106 | } 107 | } while (false); 108 | 109 | return result; 110 | } 111 | 112 | private Element getTag(Element node, String tag) { 113 | if (node == null) 114 | return null; 115 | 116 | NodeList tags = node.getElementsByTagName("*"); 117 | for (int i = 0; i < tags.getLength(); ++i) { 118 | Element child = (Element) tags.item(i); 119 | if (child.getTagName().equalsIgnoreCase(tag)) { 120 | return child; 121 | } 122 | } 123 | 124 | return null; 125 | } 126 | 127 | @Override 128 | public String toString() { 129 | String str = String.format("%s%d", mIp, mPort); 130 | return str; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /TVMiracast/src/com/test/miracast/ParamStart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.test.miracast; 3 | 4 | import org.w3c.dom.DOMException; 5 | import org.w3c.dom.Document; 6 | import org.w3c.dom.Element; 7 | import org.w3c.dom.NodeList; 8 | import org.xml.sax.SAXException; 9 | 10 | import java.io.ByteArrayInputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | 14 | import javax.xml.parsers.DocumentBuilder; 15 | import javax.xml.parsers.DocumentBuilderFactory; 16 | import javax.xml.parsers.ParserConfigurationException; 17 | 18 | public class ParamStart { 19 | 20 | private String mIp = null; 21 | private int mPort = 0; 22 | 23 | public static ParamStart create(byte bytes[]) { 24 | if (bytes == null) 25 | return null; 26 | 27 | ParamStart param = new ParamStart(); 28 | if (!param.load(bytes)) 29 | return null; 30 | 31 | return param; 32 | } 33 | 34 | public static ParamStart create(String ip, int port) { 35 | ParamStart param = new ParamStart(); 36 | param.mIp = ip; 37 | param.mPort = port; 38 | 39 | return param; 40 | } 41 | 42 | public String getIp() { 43 | return mIp; 44 | } 45 | 46 | public void setIp(String mIp) { 47 | this.mIp = mIp; 48 | } 49 | 50 | public int getPort() { 51 | return mPort; 52 | } 53 | 54 | public void setPort(int mPort) { 55 | this.mPort = mPort; 56 | } 57 | 58 | public boolean load(byte bytes[]) { 59 | boolean result = false; 60 | 61 | do { 62 | if (bytes == null) 63 | break; 64 | 65 | InputStream is = new ByteArrayInputStream(bytes); 66 | DocumentBuilderFactory factory = DocumentBuilderFactory 67 | .newInstance(); 68 | 69 | try { 70 | DocumentBuilder builder = factory.newDocumentBuilder(); 71 | Document document = builder.parse(is); 72 | 73 | Element root = document.getDocumentElement(); 74 | if (root == null) 75 | break; 76 | 77 | if (!root.getTagName().equalsIgnoreCase("root")) 78 | break; 79 | 80 | Element tagIp = getTag(root, "ip"); 81 | if (tagIp == null) 82 | break; 83 | 84 | Element tagPort = getTag(root, "port"); 85 | if (tagPort == null) 86 | break; 87 | 88 | mIp = tagIp.getTextContent(); 89 | 90 | try { 91 | mPort = Integer.valueOf(tagPort.getTextContent()); 92 | } catch (NumberFormatException e) { 93 | e.printStackTrace(); 94 | mPort = 0; 95 | } 96 | 97 | result = true; 98 | } catch (ParserConfigurationException e) { 99 | e.printStackTrace(); 100 | } catch (SAXException e) { 101 | e.printStackTrace(); 102 | } catch (DOMException e) { 103 | e.printStackTrace(); 104 | } catch (IOException e) { 105 | e.printStackTrace(); 106 | } 107 | } while (false); 108 | 109 | return result; 110 | } 111 | 112 | private Element getTag(Element node, String tag) { 113 | if (node == null) 114 | return null; 115 | 116 | NodeList tags = node.getElementsByTagName("*"); 117 | for (int i = 0; i < tags.getLength(); ++i) { 118 | Element child = (Element) tags.item(i); 119 | if (child.getTagName().equalsIgnoreCase(tag)) { 120 | return child; 121 | } 122 | } 123 | 124 | return null; 125 | } 126 | 127 | @Override 128 | public String toString() { 129 | String str = String.format("%s%d", mIp, mPort); 130 | return str; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/tasks/resolver/DNSResolverTask.java: -------------------------------------------------------------------------------- 1 | // Licensed under Apache License version 2.0 2 | package javax.jmdns.impl.tasks.resolver; 3 | 4 | import java.io.IOException; 5 | import java.util.Timer; 6 | import java.util.logging.Level; 7 | import java.util.logging.Logger; 8 | 9 | import javax.jmdns.impl.DNSOutgoing; 10 | import javax.jmdns.impl.JmDNSImpl; 11 | import javax.jmdns.impl.constants.DNSConstants; 12 | import javax.jmdns.impl.tasks.DNSTask; 13 | 14 | /** 15 | * This is the root class for all resolver tasks. 16 | * 17 | * @author Pierre Frisch 18 | */ 19 | public abstract class DNSResolverTask extends DNSTask { 20 | private static Logger logger = Logger.getLogger(DNSResolverTask.class.getName()); 21 | 22 | /** 23 | * Counts the number of queries being sent. 24 | */ 25 | protected int _count = 0; 26 | 27 | /** 28 | * @param jmDNSImpl 29 | */ 30 | public DNSResolverTask(JmDNSImpl jmDNSImpl) { 31 | super(jmDNSImpl); 32 | } 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see java.lang.Object#toString() 37 | */ 38 | @Override 39 | public String toString() { 40 | return super.toString() + " count: " + _count; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer) 46 | */ 47 | @Override 48 | public void start(Timer timer) { 49 | if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) { 50 | timer.schedule(this, DNSConstants.QUERY_WAIT_INTERVAL, DNSConstants.QUERY_WAIT_INTERVAL); 51 | } 52 | } 53 | 54 | /* 55 | * (non-Javadoc) 56 | * @see java.util.TimerTask#run() 57 | */ 58 | @Override 59 | public void run() { 60 | try { 61 | if (this.getDns().isCanceling() || this.getDns().isCanceled()) { 62 | this.cancel(); 63 | } else { 64 | if (_count++ < 3) { 65 | if (logger.isLoggable(Level.FINER)) { 66 | logger.finer(this.getName() + ".run() JmDNS " + this.description()); 67 | } 68 | DNSOutgoing out = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY); 69 | out = this.addQuestions(out); 70 | if (this.getDns().isAnnounced()) { 71 | out = this.addAnswers(out); 72 | } 73 | if (!out.isEmpty()) { 74 | this.getDns().send(out); 75 | } 76 | } else { 77 | // After three queries, we can quit. 78 | this.cancel(); 79 | } 80 | } 81 | } catch (Throwable e) { 82 | logger.log(Level.WARNING, this.getName() + ".run() exception ", e); 83 | this.getDns().recover(); 84 | } 85 | } 86 | 87 | /** 88 | * Overridden by subclasses to add questions to the message.
89 | * Note: Because of message size limitation the returned message may be different than the message parameter. 90 | * 91 | * @param out 92 | * outgoing message 93 | * @return the outgoing message. 94 | * @exception IOException 95 | */ 96 | protected abstract DNSOutgoing addQuestions(DNSOutgoing out) throws IOException; 97 | 98 | /** 99 | * Overridden by subclasses to add questions to the message.
100 | * Note: Because of message size limitation the returned message may be different than the message parameter. 101 | * 102 | * @param out 103 | * outgoing message 104 | * @return the outgoing message. 105 | * @exception IOException 106 | */ 107 | protected abstract DNSOutgoing addAnswers(DNSOutgoing out) throws IOException; 108 | 109 | /** 110 | * Returns a description of the resolver for debugging 111 | * 112 | * @return resolver description 113 | */ 114 | protected abstract String description(); 115 | 116 | } 117 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/tasks/resolver/DNSResolverTask.java: -------------------------------------------------------------------------------- 1 | // Licensed under Apache License version 2.0 2 | package javax.jmdns.impl.tasks.resolver; 3 | 4 | import java.io.IOException; 5 | import java.util.Timer; 6 | import java.util.logging.Level; 7 | import java.util.logging.Logger; 8 | 9 | import javax.jmdns.impl.DNSOutgoing; 10 | import javax.jmdns.impl.JmDNSImpl; 11 | import javax.jmdns.impl.constants.DNSConstants; 12 | import javax.jmdns.impl.tasks.DNSTask; 13 | 14 | /** 15 | * This is the root class for all resolver tasks. 16 | * 17 | * @author Pierre Frisch 18 | */ 19 | public abstract class DNSResolverTask extends DNSTask { 20 | private static Logger logger = Logger.getLogger(DNSResolverTask.class.getName()); 21 | 22 | /** 23 | * Counts the number of queries being sent. 24 | */ 25 | protected int _count = 0; 26 | 27 | /** 28 | * @param jmDNSImpl 29 | */ 30 | public DNSResolverTask(JmDNSImpl jmDNSImpl) { 31 | super(jmDNSImpl); 32 | } 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see java.lang.Object#toString() 37 | */ 38 | @Override 39 | public String toString() { 40 | return super.toString() + " count: " + _count; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer) 46 | */ 47 | @Override 48 | public void start(Timer timer) { 49 | if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) { 50 | timer.schedule(this, DNSConstants.QUERY_WAIT_INTERVAL, DNSConstants.QUERY_WAIT_INTERVAL); 51 | } 52 | } 53 | 54 | /* 55 | * (non-Javadoc) 56 | * @see java.util.TimerTask#run() 57 | */ 58 | @Override 59 | public void run() { 60 | try { 61 | if (this.getDns().isCanceling() || this.getDns().isCanceled()) { 62 | this.cancel(); 63 | } else { 64 | if (_count++ < 3) { 65 | if (logger.isLoggable(Level.FINER)) { 66 | logger.finer(this.getName() + ".run() JmDNS " + this.description()); 67 | } 68 | DNSOutgoing out = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY); 69 | out = this.addQuestions(out); 70 | if (this.getDns().isAnnounced()) { 71 | out = this.addAnswers(out); 72 | } 73 | if (!out.isEmpty()) { 74 | this.getDns().send(out); 75 | } 76 | } else { 77 | // After three queries, we can quit. 78 | this.cancel(); 79 | } 80 | } 81 | } catch (Throwable e) { 82 | logger.log(Level.WARNING, this.getName() + ".run() exception ", e); 83 | this.getDns().recover(); 84 | } 85 | } 86 | 87 | /** 88 | * Overridden by subclasses to add questions to the message.
89 | * Note: Because of message size limitation the returned message may be different than the message parameter. 90 | * 91 | * @param out 92 | * outgoing message 93 | * @return the outgoing message. 94 | * @exception IOException 95 | */ 96 | protected abstract DNSOutgoing addQuestions(DNSOutgoing out) throws IOException; 97 | 98 | /** 99 | * Overridden by subclasses to add questions to the message.
100 | * Note: Because of message size limitation the returned message may be different than the message parameter. 101 | * 102 | * @param out 103 | * outgoing message 104 | * @return the outgoing message. 105 | * @exception IOException 106 | */ 107 | protected abstract DNSOutgoing addAnswers(DNSOutgoing out) throws IOException; 108 | 109 | /** 110 | * Returns a description of the resolver for debugging 111 | * 112 | * @return resolver description 113 | */ 114 | protected abstract String description(); 115 | 116 | } 117 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/tasks/state/Canceler.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks.state; 6 | 7 | import java.io.IOException; 8 | import java.util.Timer; 9 | import java.util.logging.Logger; 10 | 11 | import javax.jmdns.impl.DNSOutgoing; 12 | import javax.jmdns.impl.DNSRecord; 13 | import javax.jmdns.impl.JmDNSImpl; 14 | import javax.jmdns.impl.ServiceInfoImpl; 15 | import javax.jmdns.impl.constants.DNSConstants; 16 | import javax.jmdns.impl.constants.DNSRecordClass; 17 | import javax.jmdns.impl.constants.DNSState; 18 | 19 | /** 20 | * The Canceler sends two announces with TTL=0 for the specified services. 21 | */ 22 | public class Canceler extends DNSStateTask { 23 | static Logger logger = Logger.getLogger(Canceler.class.getName()); 24 | 25 | public Canceler(JmDNSImpl jmDNSImpl) { 26 | super(jmDNSImpl, 0); 27 | 28 | this.setTaskState(DNSState.CANCELING_1); 29 | this.associate(DNSState.CANCELING_1); 30 | } 31 | 32 | /* 33 | * (non-Javadoc) 34 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 35 | */ 36 | @Override 37 | public String getName() { 38 | return "Canceler(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 39 | } 40 | 41 | /* 42 | * (non-Javadoc) 43 | * @see java.lang.Object#toString() 44 | */ 45 | @Override 46 | public String toString() { 47 | return super.toString() + " state: " + this.getTaskState(); 48 | } 49 | 50 | /* 51 | * (non-Javadoc) 52 | * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer) 53 | */ 54 | @Override 55 | public void start(Timer timer) { 56 | timer.schedule(this, 0, DNSConstants.ANNOUNCE_WAIT_INTERVAL); 57 | } 58 | 59 | /* 60 | * (non-Javadoc) 61 | * @see java.util.TimerTask#cancel() 62 | */ 63 | @Override 64 | public boolean cancel() { 65 | this.removeAssociation(); 66 | 67 | return super.cancel(); 68 | } 69 | 70 | /* 71 | * (non-Javadoc) 72 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#getTaskDescription() 73 | */ 74 | @Override 75 | public String getTaskDescription() { 76 | return "canceling"; 77 | } 78 | 79 | /* 80 | * (non-Javadoc) 81 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#checkRunCondition() 82 | */ 83 | @Override 84 | protected boolean checkRunCondition() { 85 | return true; 86 | } 87 | 88 | /* 89 | * (non-Javadoc) 90 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#createOugoing() 91 | */ 92 | @Override 93 | protected DNSOutgoing createOugoing() { 94 | return new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); 95 | } 96 | 97 | /* 98 | * (non-Javadoc) 99 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForDNS(javax.jmdns.impl.DNSOutgoing) 100 | */ 101 | @Override 102 | protected DNSOutgoing buildOutgoingForDNS(DNSOutgoing out) throws IOException { 103 | DNSOutgoing newOut = out; 104 | for (DNSRecord answer : this.getDns().getLocalHost().answers(DNSRecordClass.CLASS_ANY, DNSRecordClass.UNIQUE, this.getTTL())) { 105 | newOut = this.addAnswer(newOut, null, answer); 106 | } 107 | return newOut; 108 | } 109 | 110 | /* 111 | * (non-Javadoc) 112 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForInfo(javax.jmdns.impl.ServiceInfoImpl, javax.jmdns.impl.DNSOutgoing) 113 | */ 114 | @Override 115 | protected DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException { 116 | DNSOutgoing newOut = out; 117 | for (DNSRecord answer : info.answers(DNSRecordClass.CLASS_ANY, DNSRecordClass.UNIQUE, this.getTTL(), this.getDns().getLocalHost())) { 118 | newOut = this.addAnswer(newOut, null, answer); 119 | } 120 | return newOut; 121 | } 122 | 123 | /* 124 | * (non-Javadoc) 125 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#recoverTask(java.lang.Throwable) 126 | */ 127 | @Override 128 | protected void recoverTask(Throwable e) { 129 | this.getDns().recover(); 130 | } 131 | 132 | /* 133 | * (non-Javadoc) 134 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#advanceTask() 135 | */ 136 | @Override 137 | protected void advanceTask() { 138 | this.setTaskState(this.getTaskState().advance()); 139 | if (!this.getTaskState().isCanceling()) { 140 | cancel(); 141 | } 142 | } 143 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/tasks/state/Canceler.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks.state; 6 | 7 | import java.io.IOException; 8 | import java.util.Timer; 9 | import java.util.logging.Logger; 10 | 11 | import javax.jmdns.impl.DNSOutgoing; 12 | import javax.jmdns.impl.DNSRecord; 13 | import javax.jmdns.impl.JmDNSImpl; 14 | import javax.jmdns.impl.ServiceInfoImpl; 15 | import javax.jmdns.impl.constants.DNSConstants; 16 | import javax.jmdns.impl.constants.DNSRecordClass; 17 | import javax.jmdns.impl.constants.DNSState; 18 | 19 | /** 20 | * The Canceler sends two announces with TTL=0 for the specified services. 21 | */ 22 | public class Canceler extends DNSStateTask { 23 | static Logger logger = Logger.getLogger(Canceler.class.getName()); 24 | 25 | public Canceler(JmDNSImpl jmDNSImpl) { 26 | super(jmDNSImpl, 0); 27 | 28 | this.setTaskState(DNSState.CANCELING_1); 29 | this.associate(DNSState.CANCELING_1); 30 | } 31 | 32 | /* 33 | * (non-Javadoc) 34 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 35 | */ 36 | @Override 37 | public String getName() { 38 | return "Canceler(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 39 | } 40 | 41 | /* 42 | * (non-Javadoc) 43 | * @see java.lang.Object#toString() 44 | */ 45 | @Override 46 | public String toString() { 47 | return super.toString() + " state: " + this.getTaskState(); 48 | } 49 | 50 | /* 51 | * (non-Javadoc) 52 | * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer) 53 | */ 54 | @Override 55 | public void start(Timer timer) { 56 | timer.schedule(this, 0, DNSConstants.ANNOUNCE_WAIT_INTERVAL); 57 | } 58 | 59 | /* 60 | * (non-Javadoc) 61 | * @see java.util.TimerTask#cancel() 62 | */ 63 | @Override 64 | public boolean cancel() { 65 | this.removeAssociation(); 66 | 67 | return super.cancel(); 68 | } 69 | 70 | /* 71 | * (non-Javadoc) 72 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#getTaskDescription() 73 | */ 74 | @Override 75 | public String getTaskDescription() { 76 | return "canceling"; 77 | } 78 | 79 | /* 80 | * (non-Javadoc) 81 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#checkRunCondition() 82 | */ 83 | @Override 84 | protected boolean checkRunCondition() { 85 | return true; 86 | } 87 | 88 | /* 89 | * (non-Javadoc) 90 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#createOugoing() 91 | */ 92 | @Override 93 | protected DNSOutgoing createOugoing() { 94 | return new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); 95 | } 96 | 97 | /* 98 | * (non-Javadoc) 99 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForDNS(javax.jmdns.impl.DNSOutgoing) 100 | */ 101 | @Override 102 | protected DNSOutgoing buildOutgoingForDNS(DNSOutgoing out) throws IOException { 103 | DNSOutgoing newOut = out; 104 | for (DNSRecord answer : this.getDns().getLocalHost().answers(DNSRecordClass.CLASS_ANY, DNSRecordClass.UNIQUE, this.getTTL())) { 105 | newOut = this.addAnswer(newOut, null, answer); 106 | } 107 | return newOut; 108 | } 109 | 110 | /* 111 | * (non-Javadoc) 112 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForInfo(javax.jmdns.impl.ServiceInfoImpl, javax.jmdns.impl.DNSOutgoing) 113 | */ 114 | @Override 115 | protected DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException { 116 | DNSOutgoing newOut = out; 117 | for (DNSRecord answer : info.answers(DNSRecordClass.CLASS_ANY, DNSRecordClass.UNIQUE, this.getTTL(), this.getDns().getLocalHost())) { 118 | newOut = this.addAnswer(newOut, null, answer); 119 | } 120 | return newOut; 121 | } 122 | 123 | /* 124 | * (non-Javadoc) 125 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#recoverTask(java.lang.Throwable) 126 | */ 127 | @Override 128 | protected void recoverTask(Throwable e) { 129 | this.getDns().recover(); 130 | } 131 | 132 | /* 133 | * (non-Javadoc) 134 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#advanceTask() 135 | */ 136 | @Override 137 | protected void advanceTask() { 138 | this.setTaskState(this.getTaskState().advance()); 139 | if (!this.getTaskState().isCanceling()) { 140 | cancel(); 141 | } 142 | } 143 | } -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/constants/DNSResultCode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl.constants; 5 | 6 | /** 7 | * DNS result code. 8 | * 9 | * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair 10 | */ 11 | public enum DNSResultCode { 12 | /** 13 | * Token 14 | */ 15 | Unknown("Unknown", 65535), 16 | /** 17 | * No Error [RFC1035] 18 | */ 19 | NoError("No Error", 0), 20 | /** 21 | * Format Error [RFC1035] 22 | */ 23 | FormErr("Format Error", 1), 24 | /** 25 | * Server Failure [RFC1035] 26 | */ 27 | ServFail("Server Failure", 2), 28 | /** 29 | * Non-Existent Domain [RFC1035] 30 | */ 31 | NXDomain("Non-Existent Domain", 3), 32 | /** 33 | * Not Implemented [RFC1035] 34 | */ 35 | NotImp("Not Implemented", 4), 36 | /** 37 | * Query Refused [RFC1035] 38 | */ 39 | Refused("Query Refused", 5), 40 | /** 41 | * Name Exists when it should not [RFC2136] 42 | */ 43 | YXDomain("Name Exists when it should not", 6), 44 | /** 45 | * RR Set Exists when it should not [RFC2136] 46 | */ 47 | YXRRSet("RR Set Exists when it should not", 7), 48 | /** 49 | * RR Set that should exist does not [RFC2136] 50 | */ 51 | NXRRSet("RR Set that should exist does not", 8), 52 | /** 53 | * Server Not Authoritative for zone [RFC2136]] 54 | */ 55 | NotAuth("Server Not Authoritative for zone", 9), 56 | /** 57 | * Name not contained in zone [RFC2136] 58 | */ 59 | NotZone("NotZone Name not contained in zone", 10), 60 | 61 | ; 62 | 63 | // 0 NoError No Error [RFC1035] 64 | // 1 FormErr Format Error [RFC1035] 65 | // 2 ServFail Server Failure [RFC1035] 66 | // 3 NXDomain Non-Existent Domain [RFC1035] 67 | // 4 NotImp Not Implemented [RFC1035] 68 | // 5 Refused Query Refused [RFC1035] 69 | // 6 YXDomain Name Exists when it should not [RFC2136] 70 | // 7 YXRRSet RR Set Exists when it should not [RFC2136] 71 | // 8 NXRRSet RR Set that should exist does not [RFC2136] 72 | // 9 NotAuth Server Not Authoritative for zone [RFC2136] 73 | // 10 NotZone Name not contained in zone [RFC2136] 74 | // 11-15 Unassigned 75 | // 16 BADVERS Bad OPT Version [RFC2671] 76 | // 16 BADSIG TSIG Signature Failure [RFC2845] 77 | // 17 BADKEY Key not recognized [RFC2845] 78 | // 18 BADTIME Signature out of time window [RFC2845] 79 | // 19 BADMODE Bad TKEY Mode [RFC2930] 80 | // 20 BADNAME Duplicate key name [RFC2930] 81 | // 21 BADALG Algorithm not supported [RFC2930] 82 | // 22 BADTRUNC Bad Truncation [RFC4635] 83 | // 23-3840 Unassigned 84 | // 3841-4095 Reserved for Private Use [RFC5395] 85 | // 4096-65534 Unassigned 86 | // 65535 Reserved, can be allocated by Standards Action [RFC5395] 87 | 88 | /** 89 | * DNS Result Code types are encoded on the last 4 bits 90 | */ 91 | final static int RCode_MASK = 0x0F; 92 | /** 93 | * DNS Extended Result Code types are encoded on the first 8 bits 94 | */ 95 | final static int ExtendedRCode_MASK = 0xFF; 96 | 97 | private final String _externalName; 98 | 99 | private final int _index; 100 | 101 | DNSResultCode(String name, int index) { 102 | _externalName = name; 103 | _index = index; 104 | } 105 | 106 | /** 107 | * Return the string representation of this type 108 | * 109 | * @return String 110 | */ 111 | public String externalName() { 112 | return _externalName; 113 | } 114 | 115 | /** 116 | * Return the numeric value of this type 117 | * 118 | * @return String 119 | */ 120 | public int indexValue() { 121 | return _index; 122 | } 123 | 124 | /** 125 | * @param flags 126 | * @return label 127 | */ 128 | public static DNSResultCode resultCodeForFlags(int flags) { 129 | int maskedIndex = flags & RCode_MASK; 130 | for (DNSResultCode aCode : DNSResultCode.values()) { 131 | if (aCode._index == maskedIndex) return aCode; 132 | } 133 | return Unknown; 134 | } 135 | 136 | public static DNSResultCode resultCodeForFlags(int flags, int extendedRCode) { 137 | int maskedIndex = ((extendedRCode >> 28) & ExtendedRCode_MASK) | (flags & RCode_MASK); 138 | for (DNSResultCode aCode : DNSResultCode.values()) { 139 | if (aCode._index == maskedIndex) return aCode; 140 | } 141 | return Unknown; 142 | } 143 | 144 | @Override 145 | public String toString() { 146 | return this.name() + " index " + this.indexValue(); 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/constants/DNSResultCode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl.constants; 5 | 6 | /** 7 | * DNS result code. 8 | * 9 | * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair 10 | */ 11 | public enum DNSResultCode { 12 | /** 13 | * Token 14 | */ 15 | Unknown("Unknown", 65535), 16 | /** 17 | * No Error [RFC1035] 18 | */ 19 | NoError("No Error", 0), 20 | /** 21 | * Format Error [RFC1035] 22 | */ 23 | FormErr("Format Error", 1), 24 | /** 25 | * Server Failure [RFC1035] 26 | */ 27 | ServFail("Server Failure", 2), 28 | /** 29 | * Non-Existent Domain [RFC1035] 30 | */ 31 | NXDomain("Non-Existent Domain", 3), 32 | /** 33 | * Not Implemented [RFC1035] 34 | */ 35 | NotImp("Not Implemented", 4), 36 | /** 37 | * Query Refused [RFC1035] 38 | */ 39 | Refused("Query Refused", 5), 40 | /** 41 | * Name Exists when it should not [RFC2136] 42 | */ 43 | YXDomain("Name Exists when it should not", 6), 44 | /** 45 | * RR Set Exists when it should not [RFC2136] 46 | */ 47 | YXRRSet("RR Set Exists when it should not", 7), 48 | /** 49 | * RR Set that should exist does not [RFC2136] 50 | */ 51 | NXRRSet("RR Set that should exist does not", 8), 52 | /** 53 | * Server Not Authoritative for zone [RFC2136]] 54 | */ 55 | NotAuth("Server Not Authoritative for zone", 9), 56 | /** 57 | * Name not contained in zone [RFC2136] 58 | */ 59 | NotZone("NotZone Name not contained in zone", 10), 60 | 61 | ; 62 | 63 | // 0 NoError No Error [RFC1035] 64 | // 1 FormErr Format Error [RFC1035] 65 | // 2 ServFail Server Failure [RFC1035] 66 | // 3 NXDomain Non-Existent Domain [RFC1035] 67 | // 4 NotImp Not Implemented [RFC1035] 68 | // 5 Refused Query Refused [RFC1035] 69 | // 6 YXDomain Name Exists when it should not [RFC2136] 70 | // 7 YXRRSet RR Set Exists when it should not [RFC2136] 71 | // 8 NXRRSet RR Set that should exist does not [RFC2136] 72 | // 9 NotAuth Server Not Authoritative for zone [RFC2136] 73 | // 10 NotZone Name not contained in zone [RFC2136] 74 | // 11-15 Unassigned 75 | // 16 BADVERS Bad OPT Version [RFC2671] 76 | // 16 BADSIG TSIG Signature Failure [RFC2845] 77 | // 17 BADKEY Key not recognized [RFC2845] 78 | // 18 BADTIME Signature out of time window [RFC2845] 79 | // 19 BADMODE Bad TKEY Mode [RFC2930] 80 | // 20 BADNAME Duplicate key name [RFC2930] 81 | // 21 BADALG Algorithm not supported [RFC2930] 82 | // 22 BADTRUNC Bad Truncation [RFC4635] 83 | // 23-3840 Unassigned 84 | // 3841-4095 Reserved for Private Use [RFC5395] 85 | // 4096-65534 Unassigned 86 | // 65535 Reserved, can be allocated by Standards Action [RFC5395] 87 | 88 | /** 89 | * DNS Result Code types are encoded on the last 4 bits 90 | */ 91 | final static int RCode_MASK = 0x0F; 92 | /** 93 | * DNS Extended Result Code types are encoded on the first 8 bits 94 | */ 95 | final static int ExtendedRCode_MASK = 0xFF; 96 | 97 | private final String _externalName; 98 | 99 | private final int _index; 100 | 101 | DNSResultCode(String name, int index) { 102 | _externalName = name; 103 | _index = index; 104 | } 105 | 106 | /** 107 | * Return the string representation of this type 108 | * 109 | * @return String 110 | */ 111 | public String externalName() { 112 | return _externalName; 113 | } 114 | 115 | /** 116 | * Return the numeric value of this type 117 | * 118 | * @return String 119 | */ 120 | public int indexValue() { 121 | return _index; 122 | } 123 | 124 | /** 125 | * @param flags 126 | * @return label 127 | */ 128 | public static DNSResultCode resultCodeForFlags(int flags) { 129 | int maskedIndex = flags & RCode_MASK; 130 | for (DNSResultCode aCode : DNSResultCode.values()) { 131 | if (aCode._index == maskedIndex) return aCode; 132 | } 133 | return Unknown; 134 | } 135 | 136 | public static DNSResultCode resultCodeForFlags(int flags, int extendedRCode) { 137 | int maskedIndex = ((extendedRCode >> 28) & ExtendedRCode_MASK) | (flags & RCode_MASK); 138 | for (DNSResultCode aCode : DNSResultCode.values()) { 139 | if (aCode._index == maskedIndex) return aCode; 140 | } 141 | return Unknown; 142 | } 143 | 144 | @Override 145 | public String toString() { 146 | return this.name() + " index " + this.indexValue(); 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/tasks/state/Renewer.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks.state; 6 | 7 | import java.io.IOException; 8 | import java.util.Timer; 9 | import java.util.logging.Logger; 10 | 11 | import javax.jmdns.impl.DNSOutgoing; 12 | import javax.jmdns.impl.DNSRecord; 13 | import javax.jmdns.impl.JmDNSImpl; 14 | import javax.jmdns.impl.ServiceInfoImpl; 15 | import javax.jmdns.impl.constants.DNSConstants; 16 | import javax.jmdns.impl.constants.DNSRecordClass; 17 | import javax.jmdns.impl.constants.DNSState; 18 | 19 | /** 20 | * The Renewer is there to send renewal announcement when the record expire for ours infos. 21 | */ 22 | public class Renewer extends DNSStateTask { 23 | static Logger logger = Logger.getLogger(Renewer.class.getName()); 24 | 25 | public Renewer(JmDNSImpl jmDNSImpl) { 26 | super(jmDNSImpl, defaultTTL()); 27 | 28 | this.setTaskState(DNSState.ANNOUNCED); 29 | this.associate(DNSState.ANNOUNCED); 30 | } 31 | 32 | /* 33 | * (non-Javadoc) 34 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 35 | */ 36 | @Override 37 | public String getName() { 38 | return "Renewer(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 39 | } 40 | 41 | /* 42 | * (non-Javadoc) 43 | * @see java.lang.Object#toString() 44 | */ 45 | @Override 46 | public String toString() { 47 | return super.toString() + " state: " + this.getTaskState(); 48 | } 49 | 50 | /* 51 | * (non-Javadoc) 52 | * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer) 53 | */ 54 | @Override 55 | public void start(Timer timer) { 56 | if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) { 57 | timer.schedule(this, DNSConstants.ANNOUNCED_RENEWAL_TTL_INTERVAL, DNSConstants.ANNOUNCED_RENEWAL_TTL_INTERVAL); 58 | } 59 | } 60 | 61 | @Override 62 | public boolean cancel() { 63 | this.removeAssociation(); 64 | 65 | return super.cancel(); 66 | } 67 | 68 | /* 69 | * (non-Javadoc) 70 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#getTaskDescription() 71 | */ 72 | @Override 73 | public String getTaskDescription() { 74 | return "renewing"; 75 | } 76 | 77 | /* 78 | * (non-Javadoc) 79 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#checkRunCondition() 80 | */ 81 | @Override 82 | protected boolean checkRunCondition() { 83 | return !this.getDns().isCanceling() && !this.getDns().isCanceled(); 84 | } 85 | 86 | /* 87 | * (non-Javadoc) 88 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#createOugoing() 89 | */ 90 | @Override 91 | protected DNSOutgoing createOugoing() { 92 | return new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); 93 | } 94 | 95 | /* 96 | * (non-Javadoc) 97 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForDNS(javax.jmdns.impl.DNSOutgoing) 98 | */ 99 | @Override 100 | protected DNSOutgoing buildOutgoingForDNS(DNSOutgoing out) throws IOException { 101 | DNSOutgoing newOut = out; 102 | for (DNSRecord answer : this.getDns().getLocalHost().answers(DNSRecordClass.CLASS_ANY, DNSRecordClass.UNIQUE, this.getTTL())) { 103 | newOut = this.addAnswer(newOut, null, answer); 104 | } 105 | return newOut; 106 | } 107 | 108 | /* 109 | * (non-Javadoc) 110 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForInfo(javax.jmdns.impl.ServiceInfoImpl, javax.jmdns.impl.DNSOutgoing) 111 | */ 112 | @Override 113 | protected DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException { 114 | DNSOutgoing newOut = out; 115 | for (DNSRecord answer : info.answers(DNSRecordClass.CLASS_ANY, DNSRecordClass.UNIQUE, this.getTTL(), this.getDns().getLocalHost())) { 116 | newOut = this.addAnswer(newOut, null, answer); 117 | } 118 | return newOut; 119 | } 120 | 121 | /* 122 | * (non-Javadoc) 123 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#recoverTask(java.lang.Throwable) 124 | */ 125 | @Override 126 | protected void recoverTask(Throwable e) { 127 | this.getDns().recover(); 128 | } 129 | 130 | /* 131 | * (non-Javadoc) 132 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#advanceTask() 133 | */ 134 | @Override 135 | protected void advanceTask() { 136 | this.setTaskState(this.getTaskState().advance()); 137 | if (!this.getTaskState().isAnnounced()) { 138 | cancel(); 139 | } 140 | } 141 | } -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/tasks/state/Renewer.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks.state; 6 | 7 | import java.io.IOException; 8 | import java.util.Timer; 9 | import java.util.logging.Logger; 10 | 11 | import javax.jmdns.impl.DNSOutgoing; 12 | import javax.jmdns.impl.DNSRecord; 13 | import javax.jmdns.impl.JmDNSImpl; 14 | import javax.jmdns.impl.ServiceInfoImpl; 15 | import javax.jmdns.impl.constants.DNSConstants; 16 | import javax.jmdns.impl.constants.DNSRecordClass; 17 | import javax.jmdns.impl.constants.DNSState; 18 | 19 | /** 20 | * The Renewer is there to send renewal announcement when the record expire for ours infos. 21 | */ 22 | public class Renewer extends DNSStateTask { 23 | static Logger logger = Logger.getLogger(Renewer.class.getName()); 24 | 25 | public Renewer(JmDNSImpl jmDNSImpl) { 26 | super(jmDNSImpl, defaultTTL()); 27 | 28 | this.setTaskState(DNSState.ANNOUNCED); 29 | this.associate(DNSState.ANNOUNCED); 30 | } 31 | 32 | /* 33 | * (non-Javadoc) 34 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 35 | */ 36 | @Override 37 | public String getName() { 38 | return "Renewer(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 39 | } 40 | 41 | /* 42 | * (non-Javadoc) 43 | * @see java.lang.Object#toString() 44 | */ 45 | @Override 46 | public String toString() { 47 | return super.toString() + " state: " + this.getTaskState(); 48 | } 49 | 50 | /* 51 | * (non-Javadoc) 52 | * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer) 53 | */ 54 | @Override 55 | public void start(Timer timer) { 56 | if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) { 57 | timer.schedule(this, DNSConstants.ANNOUNCED_RENEWAL_TTL_INTERVAL, DNSConstants.ANNOUNCED_RENEWAL_TTL_INTERVAL); 58 | } 59 | } 60 | 61 | @Override 62 | public boolean cancel() { 63 | this.removeAssociation(); 64 | 65 | return super.cancel(); 66 | } 67 | 68 | /* 69 | * (non-Javadoc) 70 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#getTaskDescription() 71 | */ 72 | @Override 73 | public String getTaskDescription() { 74 | return "renewing"; 75 | } 76 | 77 | /* 78 | * (non-Javadoc) 79 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#checkRunCondition() 80 | */ 81 | @Override 82 | protected boolean checkRunCondition() { 83 | return !this.getDns().isCanceling() && !this.getDns().isCanceled(); 84 | } 85 | 86 | /* 87 | * (non-Javadoc) 88 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#createOugoing() 89 | */ 90 | @Override 91 | protected DNSOutgoing createOugoing() { 92 | return new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); 93 | } 94 | 95 | /* 96 | * (non-Javadoc) 97 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForDNS(javax.jmdns.impl.DNSOutgoing) 98 | */ 99 | @Override 100 | protected DNSOutgoing buildOutgoingForDNS(DNSOutgoing out) throws IOException { 101 | DNSOutgoing newOut = out; 102 | for (DNSRecord answer : this.getDns().getLocalHost().answers(DNSRecordClass.CLASS_ANY, DNSRecordClass.UNIQUE, this.getTTL())) { 103 | newOut = this.addAnswer(newOut, null, answer); 104 | } 105 | return newOut; 106 | } 107 | 108 | /* 109 | * (non-Javadoc) 110 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForInfo(javax.jmdns.impl.ServiceInfoImpl, javax.jmdns.impl.DNSOutgoing) 111 | */ 112 | @Override 113 | protected DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException { 114 | DNSOutgoing newOut = out; 115 | for (DNSRecord answer : info.answers(DNSRecordClass.CLASS_ANY, DNSRecordClass.UNIQUE, this.getTTL(), this.getDns().getLocalHost())) { 116 | newOut = this.addAnswer(newOut, null, answer); 117 | } 118 | return newOut; 119 | } 120 | 121 | /* 122 | * (non-Javadoc) 123 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#recoverTask(java.lang.Throwable) 124 | */ 125 | @Override 126 | protected void recoverTask(Throwable e) { 127 | this.getDns().recover(); 128 | } 129 | 130 | /* 131 | * (non-Javadoc) 132 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#advanceTask() 133 | */ 134 | @Override 135 | protected void advanceTask() { 136 | this.setTaskState(this.getTaskState().advance()); 137 | if (!this.getTaskState().isAnnounced()) { 138 | cancel(); 139 | } 140 | } 141 | } -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/NetworkTopologyDiscoveryImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl; 5 | 6 | import java.lang.reflect.Method; 7 | import java.net.InetAddress; 8 | import java.net.NetworkInterface; 9 | import java.net.SocketException; 10 | import java.util.Enumeration; 11 | import java.util.HashSet; 12 | import java.util.Set; 13 | import java.util.logging.Level; 14 | import java.util.logging.Logger; 15 | 16 | import javax.jmdns.NetworkTopologyDiscovery; 17 | 18 | /** 19 | * This class implements NetworkTopologyDiscovery. 20 | * 21 | * @author Pierre Frisch 22 | */ 23 | public class NetworkTopologyDiscoveryImpl implements NetworkTopologyDiscovery { 24 | private final static Logger logger = Logger.getLogger(NetworkTopologyDiscoveryImpl.class.getName()); 25 | 26 | private final Method _isUp; 27 | 28 | private final Method _supportsMulticast; 29 | 30 | /** 31 | * 32 | */ 33 | public NetworkTopologyDiscoveryImpl() { 34 | super(); 35 | Method isUp; 36 | try { 37 | isUp = NetworkInterface.class.getMethod("isUp", (Class[]) null); 38 | } catch (Exception exception) { 39 | // We do not want to throw anything if the method does not exist. 40 | isUp = null; 41 | } 42 | _isUp = isUp; 43 | Method supportsMulticast; 44 | try { 45 | supportsMulticast = NetworkInterface.class.getMethod("supportsMulticast", (Class[]) null); 46 | } catch (Exception exception) { 47 | // We do not want to throw anything if the method does not exist. 48 | supportsMulticast = null; 49 | } 50 | _supportsMulticast = supportsMulticast; 51 | } 52 | 53 | /* 54 | * (non-Javadoc) 55 | * @see javax.jmdns.JmmDNS.NetworkTopologyDiscovery#getInetAddresses() 56 | */ 57 | @Override 58 | public InetAddress[] getInetAddresses() { 59 | Set result = new HashSet(); 60 | try { 61 | 62 | for (Enumeration nifs = NetworkInterface.getNetworkInterfaces(); nifs.hasMoreElements();) { 63 | NetworkInterface nif = nifs.nextElement(); 64 | for (Enumeration iaenum = nif.getInetAddresses(); iaenum.hasMoreElements();) { 65 | InetAddress interfaceAddress = iaenum.nextElement(); 66 | if (logger.isLoggable(Level.FINEST)) { 67 | logger.finest("Found NetworkInterface/InetAddress: " + nif + " -- " + interfaceAddress); 68 | } 69 | if (this.useInetAddress(nif, interfaceAddress)) { 70 | result.add(interfaceAddress); 71 | } 72 | } 73 | } 74 | } catch (SocketException se) { 75 | logger.warning("Error while fetching network interfaces addresses: " + se); 76 | } 77 | return result.toArray(new InetAddress[result.size()]); 78 | } 79 | 80 | /* 81 | * (non-Javadoc) 82 | * @see javax.jmdns.JmmDNS.NetworkTopologyDiscovery#useInetAddress(java.net.NetworkInterface, java.net.InetAddress) 83 | */ 84 | @Override 85 | public boolean useInetAddress(NetworkInterface networkInterface, InetAddress interfaceAddress) { 86 | try { 87 | if (_isUp != null) { 88 | try { 89 | if (!((Boolean) _isUp.invoke(networkInterface, (Object[]) null)).booleanValue()) { 90 | return false; 91 | } 92 | } catch (Exception exception) { 93 | // We should hide that exception. 94 | } 95 | } 96 | if (_supportsMulticast != null) { 97 | try { 98 | if (!((Boolean) _supportsMulticast.invoke(networkInterface, (Object[]) null)).booleanValue()) { 99 | return false; 100 | } 101 | } catch (Exception exception) { 102 | // We should hide that exception. 103 | } 104 | } 105 | return true; 106 | } catch (Exception exception) { 107 | return false; 108 | } 109 | } 110 | 111 | /* 112 | * (non-Javadoc) 113 | * @see javax.jmdns.NetworkTopologyDiscovery#lockInetAddress(java.net.InetAddress) 114 | */ 115 | @Override 116 | public void lockInetAddress(InetAddress interfaceAddress) { 117 | // Default implementation does nothing. 118 | } 119 | 120 | /* 121 | * (non-Javadoc) 122 | * @see javax.jmdns.NetworkTopologyDiscovery#unlockInetAddress(java.net.InetAddress) 123 | */ 124 | @Override 125 | public void unlockInetAddress(InetAddress interfaceAddress) { 126 | // Default implementation does nothing. 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/NetworkTopologyDiscoveryImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package javax.jmdns.impl; 5 | 6 | import java.lang.reflect.Method; 7 | import java.net.InetAddress; 8 | import java.net.NetworkInterface; 9 | import java.net.SocketException; 10 | import java.util.Enumeration; 11 | import java.util.HashSet; 12 | import java.util.Set; 13 | import java.util.logging.Level; 14 | import java.util.logging.Logger; 15 | 16 | import javax.jmdns.NetworkTopologyDiscovery; 17 | 18 | /** 19 | * This class implements NetworkTopologyDiscovery. 20 | * 21 | * @author Pierre Frisch 22 | */ 23 | public class NetworkTopologyDiscoveryImpl implements NetworkTopologyDiscovery { 24 | private final static Logger logger = Logger.getLogger(NetworkTopologyDiscoveryImpl.class.getName()); 25 | 26 | private final Method _isUp; 27 | 28 | private final Method _supportsMulticast; 29 | 30 | /** 31 | * 32 | */ 33 | public NetworkTopologyDiscoveryImpl() { 34 | super(); 35 | Method isUp; 36 | try { 37 | isUp = NetworkInterface.class.getMethod("isUp", (Class[]) null); 38 | } catch (Exception exception) { 39 | // We do not want to throw anything if the method does not exist. 40 | isUp = null; 41 | } 42 | _isUp = isUp; 43 | Method supportsMulticast; 44 | try { 45 | supportsMulticast = NetworkInterface.class.getMethod("supportsMulticast", (Class[]) null); 46 | } catch (Exception exception) { 47 | // We do not want to throw anything if the method does not exist. 48 | supportsMulticast = null; 49 | } 50 | _supportsMulticast = supportsMulticast; 51 | } 52 | 53 | /* 54 | * (non-Javadoc) 55 | * @see javax.jmdns.JmmDNS.NetworkTopologyDiscovery#getInetAddresses() 56 | */ 57 | @Override 58 | public InetAddress[] getInetAddresses() { 59 | Set result = new HashSet(); 60 | try { 61 | 62 | for (Enumeration nifs = NetworkInterface.getNetworkInterfaces(); nifs.hasMoreElements();) { 63 | NetworkInterface nif = nifs.nextElement(); 64 | for (Enumeration iaenum = nif.getInetAddresses(); iaenum.hasMoreElements();) { 65 | InetAddress interfaceAddress = iaenum.nextElement(); 66 | if (logger.isLoggable(Level.FINEST)) { 67 | logger.finest("Found NetworkInterface/InetAddress: " + nif + " -- " + interfaceAddress); 68 | } 69 | if (this.useInetAddress(nif, interfaceAddress)) { 70 | result.add(interfaceAddress); 71 | } 72 | } 73 | } 74 | } catch (SocketException se) { 75 | logger.warning("Error while fetching network interfaces addresses: " + se); 76 | } 77 | return result.toArray(new InetAddress[result.size()]); 78 | } 79 | 80 | /* 81 | * (non-Javadoc) 82 | * @see javax.jmdns.JmmDNS.NetworkTopologyDiscovery#useInetAddress(java.net.NetworkInterface, java.net.InetAddress) 83 | */ 84 | @Override 85 | public boolean useInetAddress(NetworkInterface networkInterface, InetAddress interfaceAddress) { 86 | try { 87 | if (_isUp != null) { 88 | try { 89 | if (!((Boolean) _isUp.invoke(networkInterface, (Object[]) null)).booleanValue()) { 90 | return false; 91 | } 92 | } catch (Exception exception) { 93 | // We should hide that exception. 94 | } 95 | } 96 | if (_supportsMulticast != null) { 97 | try { 98 | if (!((Boolean) _supportsMulticast.invoke(networkInterface, (Object[]) null)).booleanValue()) { 99 | return false; 100 | } 101 | } catch (Exception exception) { 102 | // We should hide that exception. 103 | } 104 | } 105 | return true; 106 | } catch (Exception exception) { 107 | return false; 108 | } 109 | } 110 | 111 | /* 112 | * (non-Javadoc) 113 | * @see javax.jmdns.NetworkTopologyDiscovery#lockInetAddress(java.net.InetAddress) 114 | */ 115 | @Override 116 | public void lockInetAddress(InetAddress interfaceAddress) { 117 | // Default implementation does nothing. 118 | } 119 | 120 | /* 121 | * (non-Javadoc) 122 | * @see javax.jmdns.NetworkTopologyDiscovery#unlockInetAddress(java.net.InetAddress) 123 | */ 124 | @Override 125 | public void unlockInetAddress(InetAddress interfaceAddress) { 126 | // Default implementation does nothing. 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/tasks/resolver/ServiceInfoResolver.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks.resolver; 6 | 7 | import java.io.IOException; 8 | 9 | import javax.jmdns.impl.DNSEntry; 10 | import javax.jmdns.impl.DNSOutgoing; 11 | import javax.jmdns.impl.DNSQuestion; 12 | import javax.jmdns.impl.DNSRecord; 13 | import javax.jmdns.impl.JmDNSImpl; 14 | import javax.jmdns.impl.ServiceInfoImpl; 15 | import javax.jmdns.impl.constants.DNSRecordClass; 16 | import javax.jmdns.impl.constants.DNSRecordType; 17 | 18 | /** 19 | * The ServiceInfoResolver queries up to three times consecutively for a service info, and then removes itself from the timer. 20 | *

21 | * The ServiceInfoResolver will run only if JmDNS is in state ANNOUNCED. REMIND: Prevent having multiple service resolvers for the same info in the timer queue. 22 | */ 23 | public class ServiceInfoResolver extends DNSResolverTask { 24 | 25 | private final ServiceInfoImpl _info; 26 | 27 | public ServiceInfoResolver(JmDNSImpl jmDNSImpl, ServiceInfoImpl info) { 28 | super(jmDNSImpl); 29 | this._info = info; 30 | info.setDns(this.getDns()); 31 | this.getDns().addListener(info, DNSQuestion.newQuestion(info.getQualifiedName(), DNSRecordType.TYPE_ANY, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 32 | } 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 37 | */ 38 | @Override 39 | public String getName() { 40 | return "ServiceInfoResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see java.util.TimerTask#cancel() 46 | */ 47 | @Override 48 | public boolean cancel() { 49 | // We should not forget to remove the listener 50 | boolean result = super.cancel(); 51 | if (!_info.isPersistent()) { 52 | this.getDns().removeListener(_info); 53 | } 54 | return result; 55 | } 56 | 57 | /* 58 | * (non-Javadoc) 59 | * @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing) 60 | */ 61 | @Override 62 | protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException { 63 | DNSOutgoing newOut = out; 64 | if (!_info.hasData()) { 65 | long now = System.currentTimeMillis(); 66 | newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN), now); 67 | newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_IN), now); 68 | if (_info.getServer().length() > 0) { 69 | for (DNSEntry addressEntry : this.getDns().getCache().getDNSEntryList(_info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN)) { 70 | newOut = this.addAnswer(newOut, (DNSRecord) addressEntry, now); 71 | } 72 | for (DNSEntry addressEntry : this.getDns().getCache().getDNSEntryList(_info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN)) { 73 | newOut = this.addAnswer(newOut, (DNSRecord) addressEntry, now); 74 | } 75 | } 76 | } 77 | return newOut; 78 | } 79 | 80 | /* 81 | * (non-Javadoc) 82 | * @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing) 83 | */ 84 | @Override 85 | protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException { 86 | DNSOutgoing newOut = out; 87 | if (!_info.hasData()) { 88 | newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 89 | newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 90 | if (_info.getServer().length() > 0) { 91 | newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 92 | newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 93 | } 94 | } 95 | return newOut; 96 | } 97 | 98 | /* 99 | * (non-Javadoc) 100 | * @see javax.jmdns.impl.tasks.Resolver#description() 101 | */ 102 | @Override 103 | protected String description() { 104 | return "querying service info: " + (_info != null ? _info.getQualifiedName() : "null"); 105 | } 106 | 107 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/tasks/resolver/ServiceInfoResolver.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks.resolver; 6 | 7 | import java.io.IOException; 8 | 9 | import javax.jmdns.impl.DNSEntry; 10 | import javax.jmdns.impl.DNSOutgoing; 11 | import javax.jmdns.impl.DNSQuestion; 12 | import javax.jmdns.impl.DNSRecord; 13 | import javax.jmdns.impl.JmDNSImpl; 14 | import javax.jmdns.impl.ServiceInfoImpl; 15 | import javax.jmdns.impl.constants.DNSRecordClass; 16 | import javax.jmdns.impl.constants.DNSRecordType; 17 | 18 | /** 19 | * The ServiceInfoResolver queries up to three times consecutively for a service info, and then removes itself from the timer. 20 | *

21 | * The ServiceInfoResolver will run only if JmDNS is in state ANNOUNCED. REMIND: Prevent having multiple service resolvers for the same info in the timer queue. 22 | */ 23 | public class ServiceInfoResolver extends DNSResolverTask { 24 | 25 | private final ServiceInfoImpl _info; 26 | 27 | public ServiceInfoResolver(JmDNSImpl jmDNSImpl, ServiceInfoImpl info) { 28 | super(jmDNSImpl); 29 | this._info = info; 30 | info.setDns(this.getDns()); 31 | this.getDns().addListener(info, DNSQuestion.newQuestion(info.getQualifiedName(), DNSRecordType.TYPE_ANY, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 32 | } 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 37 | */ 38 | @Override 39 | public String getName() { 40 | return "ServiceInfoResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see java.util.TimerTask#cancel() 46 | */ 47 | @Override 48 | public boolean cancel() { 49 | // We should not forget to remove the listener 50 | boolean result = super.cancel(); 51 | if (!_info.isPersistent()) { 52 | this.getDns().removeListener(_info); 53 | } 54 | return result; 55 | } 56 | 57 | /* 58 | * (non-Javadoc) 59 | * @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing) 60 | */ 61 | @Override 62 | protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException { 63 | DNSOutgoing newOut = out; 64 | if (!_info.hasData()) { 65 | long now = System.currentTimeMillis(); 66 | newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN), now); 67 | newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_IN), now); 68 | if (_info.getServer().length() > 0) { 69 | for (DNSEntry addressEntry : this.getDns().getCache().getDNSEntryList(_info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN)) { 70 | newOut = this.addAnswer(newOut, (DNSRecord) addressEntry, now); 71 | } 72 | for (DNSEntry addressEntry : this.getDns().getCache().getDNSEntryList(_info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN)) { 73 | newOut = this.addAnswer(newOut, (DNSRecord) addressEntry, now); 74 | } 75 | } 76 | } 77 | return newOut; 78 | } 79 | 80 | /* 81 | * (non-Javadoc) 82 | * @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing) 83 | */ 84 | @Override 85 | protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException { 86 | DNSOutgoing newOut = out; 87 | if (!_info.hasData()) { 88 | newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 89 | newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 90 | if (_info.getServer().length() > 0) { 91 | newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 92 | newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 93 | } 94 | } 95 | return newOut; 96 | } 97 | 98 | /* 99 | * (non-Javadoc) 100 | * @see javax.jmdns.impl.tasks.Resolver#description() 101 | */ 102 | @Override 103 | protected String description() { 104 | return "querying service info: " + (_info != null ? _info.getQualifiedName() : "null"); 105 | } 106 | 107 | } -------------------------------------------------------------------------------- /TVMiracast/src/javax/jmdns/impl/tasks/state/Announcer.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks.state; 6 | 7 | import java.io.IOException; 8 | import java.util.Timer; 9 | import java.util.logging.Logger; 10 | 11 | import javax.jmdns.impl.DNSOutgoing; 12 | import javax.jmdns.impl.DNSRecord; 13 | import javax.jmdns.impl.JmDNSImpl; 14 | import javax.jmdns.impl.ServiceInfoImpl; 15 | import javax.jmdns.impl.constants.DNSConstants; 16 | import javax.jmdns.impl.constants.DNSRecordClass; 17 | import javax.jmdns.impl.constants.DNSState; 18 | 19 | /** 20 | * The Announcer sends an accumulated query of all announces, and advances the state of all serviceInfos, for which it has sent an announce. The Announcer also sends announcements and advances the state of JmDNS itself. 21 | *

22 | * When the announcer has run two times, it finishes. 23 | */ 24 | public class Announcer extends DNSStateTask { 25 | static Logger logger = Logger.getLogger(Announcer.class.getName()); 26 | 27 | public Announcer(JmDNSImpl jmDNSImpl) { 28 | super(jmDNSImpl, defaultTTL()); 29 | 30 | this.setTaskState(DNSState.ANNOUNCING_1); 31 | this.associate(DNSState.ANNOUNCING_1); 32 | } 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 37 | */ 38 | @Override 39 | public String getName() { 40 | return "Announcer(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see java.lang.Object#toString() 46 | */ 47 | @Override 48 | public String toString() { 49 | return super.toString() + " state: " + this.getTaskState(); 50 | } 51 | 52 | /* 53 | * (non-Javadoc) 54 | * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer) 55 | */ 56 | @Override 57 | public void start(Timer timer) { 58 | if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) { 59 | timer.schedule(this, DNSConstants.ANNOUNCE_WAIT_INTERVAL, DNSConstants.ANNOUNCE_WAIT_INTERVAL); 60 | } 61 | } 62 | 63 | @Override 64 | public boolean cancel() { 65 | this.removeAssociation(); 66 | 67 | return super.cancel(); 68 | } 69 | 70 | /* 71 | * (non-Javadoc) 72 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#getTaskDescription() 73 | */ 74 | @Override 75 | public String getTaskDescription() { 76 | return "announcing"; 77 | } 78 | 79 | /* 80 | * (non-Javadoc) 81 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#checkRunCondition() 82 | */ 83 | @Override 84 | protected boolean checkRunCondition() { 85 | return !this.getDns().isCanceling() && !this.getDns().isCanceled(); 86 | } 87 | 88 | /* 89 | * (non-Javadoc) 90 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#createOugoing() 91 | */ 92 | @Override 93 | protected DNSOutgoing createOugoing() { 94 | return new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); 95 | } 96 | 97 | /* 98 | * (non-Javadoc) 99 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForDNS(javax.jmdns.impl.DNSOutgoing) 100 | */ 101 | @Override 102 | protected DNSOutgoing buildOutgoingForDNS(DNSOutgoing out) throws IOException { 103 | DNSOutgoing newOut = out; 104 | for (DNSRecord answer : this.getDns().getLocalHost().answers(DNSRecordClass.CLASS_ANY, DNSRecordClass.UNIQUE, this.getTTL())) { 105 | newOut = this.addAnswer(newOut, null, answer); 106 | } 107 | return newOut; 108 | } 109 | 110 | /* 111 | * (non-Javadoc) 112 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForInfo(javax.jmdns.impl.ServiceInfoImpl, javax.jmdns.impl.DNSOutgoing) 113 | */ 114 | @Override 115 | protected DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException { 116 | DNSOutgoing newOut = out; 117 | for (DNSRecord answer : info.answers(DNSRecordClass.CLASS_ANY, DNSRecordClass.UNIQUE, this.getTTL(), this.getDns().getLocalHost())) { 118 | newOut = this.addAnswer(newOut, null, answer); 119 | } 120 | return newOut; 121 | } 122 | 123 | /* 124 | * (non-Javadoc) 125 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#recoverTask(java.lang.Throwable) 126 | */ 127 | @Override 128 | protected void recoverTask(Throwable e) { 129 | this.getDns().recover(); 130 | } 131 | 132 | /* 133 | * (non-Javadoc) 134 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#advanceTask() 135 | */ 136 | @Override 137 | protected void advanceTask() { 138 | this.setTaskState(this.getTaskState().advance()); 139 | if (!this.getTaskState().isAnnouncing()) { 140 | this.cancel(); 141 | 142 | this.getDns().startRenewer(); 143 | } 144 | } 145 | 146 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/tasks/state/Announcer.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.tasks.state; 6 | 7 | import java.io.IOException; 8 | import java.util.Timer; 9 | import java.util.logging.Logger; 10 | 11 | import javax.jmdns.impl.DNSOutgoing; 12 | import javax.jmdns.impl.DNSRecord; 13 | import javax.jmdns.impl.JmDNSImpl; 14 | import javax.jmdns.impl.ServiceInfoImpl; 15 | import javax.jmdns.impl.constants.DNSConstants; 16 | import javax.jmdns.impl.constants.DNSRecordClass; 17 | import javax.jmdns.impl.constants.DNSState; 18 | 19 | /** 20 | * The Announcer sends an accumulated query of all announces, and advances the state of all serviceInfos, for which it has sent an announce. The Announcer also sends announcements and advances the state of JmDNS itself. 21 | *

22 | * When the announcer has run two times, it finishes. 23 | */ 24 | public class Announcer extends DNSStateTask { 25 | static Logger logger = Logger.getLogger(Announcer.class.getName()); 26 | 27 | public Announcer(JmDNSImpl jmDNSImpl) { 28 | super(jmDNSImpl, defaultTTL()); 29 | 30 | this.setTaskState(DNSState.ANNOUNCING_1); 31 | this.associate(DNSState.ANNOUNCING_1); 32 | } 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see javax.jmdns.impl.tasks.DNSTask#getName() 37 | */ 38 | @Override 39 | public String getName() { 40 | return "Announcer(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see java.lang.Object#toString() 46 | */ 47 | @Override 48 | public String toString() { 49 | return super.toString() + " state: " + this.getTaskState(); 50 | } 51 | 52 | /* 53 | * (non-Javadoc) 54 | * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer) 55 | */ 56 | @Override 57 | public void start(Timer timer) { 58 | if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) { 59 | timer.schedule(this, DNSConstants.ANNOUNCE_WAIT_INTERVAL, DNSConstants.ANNOUNCE_WAIT_INTERVAL); 60 | } 61 | } 62 | 63 | @Override 64 | public boolean cancel() { 65 | this.removeAssociation(); 66 | 67 | return super.cancel(); 68 | } 69 | 70 | /* 71 | * (non-Javadoc) 72 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#getTaskDescription() 73 | */ 74 | @Override 75 | public String getTaskDescription() { 76 | return "announcing"; 77 | } 78 | 79 | /* 80 | * (non-Javadoc) 81 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#checkRunCondition() 82 | */ 83 | @Override 84 | protected boolean checkRunCondition() { 85 | return !this.getDns().isCanceling() && !this.getDns().isCanceled(); 86 | } 87 | 88 | /* 89 | * (non-Javadoc) 90 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#createOugoing() 91 | */ 92 | @Override 93 | protected DNSOutgoing createOugoing() { 94 | return new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); 95 | } 96 | 97 | /* 98 | * (non-Javadoc) 99 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForDNS(javax.jmdns.impl.DNSOutgoing) 100 | */ 101 | @Override 102 | protected DNSOutgoing buildOutgoingForDNS(DNSOutgoing out) throws IOException { 103 | DNSOutgoing newOut = out; 104 | for (DNSRecord answer : this.getDns().getLocalHost().answers(DNSRecordClass.CLASS_ANY, DNSRecordClass.UNIQUE, this.getTTL())) { 105 | newOut = this.addAnswer(newOut, null, answer); 106 | } 107 | return newOut; 108 | } 109 | 110 | /* 111 | * (non-Javadoc) 112 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForInfo(javax.jmdns.impl.ServiceInfoImpl, javax.jmdns.impl.DNSOutgoing) 113 | */ 114 | @Override 115 | protected DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException { 116 | DNSOutgoing newOut = out; 117 | for (DNSRecord answer : info.answers(DNSRecordClass.CLASS_ANY, DNSRecordClass.UNIQUE, this.getTTL(), this.getDns().getLocalHost())) { 118 | newOut = this.addAnswer(newOut, null, answer); 119 | } 120 | return newOut; 121 | } 122 | 123 | /* 124 | * (non-Javadoc) 125 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#recoverTask(java.lang.Throwable) 126 | */ 127 | @Override 128 | protected void recoverTask(Throwable e) { 129 | this.getDns().recover(); 130 | } 131 | 132 | /* 133 | * (non-Javadoc) 134 | * @see javax.jmdns.impl.tasks.state.DNSStateTask#advanceTask() 135 | */ 136 | @Override 137 | protected void advanceTask() { 138 | this.setTaskState(this.getTaskState().advance()); 139 | if (!this.getTaskState().isAnnouncing()) { 140 | this.cancel(); 141 | 142 | this.getDns().startRenewer(); 143 | } 144 | } 145 | 146 | } -------------------------------------------------------------------------------- /PhoneMiracast/src/javax/jmdns/impl/constants/DNSConstants.java: -------------------------------------------------------------------------------- 1 | // Copyright 2003-2005 Arthur van Hoff, Rick Blair 2 | // Licensed under Apache License version 2.0 3 | // Original license LGPL 4 | 5 | package javax.jmdns.impl.constants; 6 | 7 | /** 8 | * DNS constants. 9 | * 10 | * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair 11 | */ 12 | public final class DNSConstants { 13 | // http://www.iana.org/assignments/dns-parameters 14 | 15 | // changed to final class - jeffs 16 | public static final String MDNS_GROUP = "224.0.0.251"; 17 | public static final String MDNS_GROUP_IPV6 = "FF02::FB"; 18 | public static final int MDNS_PORT = Integer.parseInt(System.getProperty("net.mdns.port", "5353")); 19 | public static final int DNS_PORT = 53; 20 | public static final int DNS_TTL = 60 * 60; // default one hour TTL 21 | // public static final int DNS_TTL = 120 * 60; // two hour TTL (draft-cheshire-dnsext-multicastdns.txt ch 13) 22 | 23 | public static final int MAX_MSG_TYPICAL = 1460; 24 | public static final int MAX_MSG_ABSOLUTE = 8972; 25 | 26 | public static final int FLAGS_QR_MASK = 0x8000; // Query response mask 27 | public static final int FLAGS_QR_QUERY = 0x0000; // Query 28 | public static final int FLAGS_QR_RESPONSE = 0x8000; // Response 29 | 30 | public static final int FLAGS_OPCODE = 0x7800; // Operation code 31 | public static final int FLAGS_AA = 0x0400; // Authorative answer 32 | public static final int FLAGS_TC = 0x0200; // Truncated 33 | public static final int FLAGS_RD = 0x0100; // Recursion desired 34 | public static final int FLAGS_RA = 0x8000; // Recursion available 35 | 36 | public static final int FLAGS_Z = 0x0040; // Zero 37 | public static final int FLAGS_AD = 0x0020; // Authentic data 38 | public static final int FLAGS_CD = 0x0010; // Checking disabled 39 | public static final int FLAGS_RCODE = 0x000F; // Response code 40 | 41 | // Time Intervals for various functions 42 | 43 | public static final int SHARED_QUERY_TIME = 20; // milliseconds before send shared query 44 | public static final int QUERY_WAIT_INTERVAL = 225; // milliseconds between query loops. 45 | public static final int PROBE_WAIT_INTERVAL = 250; // milliseconds between probe loops. 46 | public static final int RESPONSE_MIN_WAIT_INTERVAL = 20; // minimal wait interval for response. 47 | public static final int RESPONSE_MAX_WAIT_INTERVAL = 115; // maximal wait interval for response 48 | public static final int PROBE_CONFLICT_INTERVAL = 1000; // milliseconds to wait after conflict. 49 | public static final int PROBE_THROTTLE_COUNT = 10; // After x tries go 1 time a sec. on probes. 50 | public static final int PROBE_THROTTLE_COUNT_INTERVAL = 5000; // We only increment the throttle count, if the previous increment is inside this interval. 51 | public static final int ANNOUNCE_WAIT_INTERVAL = 1000; // milliseconds between Announce loops. 52 | public static final int RECORD_REAPER_INTERVAL = 10000; // milliseconds between cache cleanups. 53 | public static final int RECORD_EXPIRY_DELAY = 1; // This is 1s delay used in ttl and therefore in seconds 54 | public static final int KNOWN_ANSWER_TTL = 120; 55 | public static final int ANNOUNCED_RENEWAL_TTL_INTERVAL = DNS_TTL * 500; // 50% of the TTL in milliseconds 56 | 57 | public static final long CLOSE_TIMEOUT = ANNOUNCE_WAIT_INTERVAL * 5L; 58 | public static final long SERVICE_INFO_TIMEOUT = ANNOUNCE_WAIT_INTERVAL * 6L; 59 | 60 | public static final int NETWORK_CHECK_INTERVAL = 10 * 1000; // 10 secondes 61 | 62 | } 63 | --------------------------------------------------------------------------------