41.
42. mClientSessionID = sessionID; 43.
44. ALOGI(\, sessionID); 45.
46. mState = AWAITING_CLIENT_SETUP; 47.
48. status_t err = sendM1(sessionID); 49. CHECK_EQ(err, (status_t)OK); 50. break; 51. } 52.
53. case ANetworkSession::kWhatData: 54. { 55.
56. break; 57. } 58.
59. case ANetworkSession::kWhatNetworkStall: 60. {
61. break; 62. } 63.
64. default:
65. TRESPASS(); 66. }
67. break; 68. }
这里的reason是kWhatClientConnected,跳过前面不必要的case语句。如果先前已经连上其它的Sink device,这里就先断开之前的连接;如果没有,将新的SessionID赋予给mClientSessionID,并更改状态为AWAITING_CLIENT_SETUP,接着去看sendM1消息,这时候就要开始WifiDisplay M1~M7消息的发送了。
下面列举M1~M7消息的格式,有兴趣的可以去对照代码分析,我们后面着重分析M6(SetUp)和M7(Play)两个消息。 M1 reqeust:
OPTIONS * RTSP/1.0
Date: Tue, 29 Fri 2014 02:41:24 +0000
Server: stagefright/1.2 (Linux;Android 4.4) CSeq: 1
Require: org.wfa.wfd1.0
M1 respose: RTSP/1.0 200 OK CSeq: 1
Date: Fri, Jan 01 2014 09:02:37 GMT
Public: org.wfa.wfd1.0, GET_PARAMETER, SET_PARAMETER
M2 request:
OPTIONS * RTSP/1.0 CSeq: 2
Require: org.wfa.wfd1.0
M2 response: RTSP/1.0 200 OK
Date: Tue, 29 Fri 2014 02:41:25 +0000 Server: stagefright/1.2 (Linux;Android 4.3) CSeq: 2
Public: org.wfa.wfd1.0, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER
M3 request:
GET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0 Date: Tue, 29 Fri 2014 02:41:25 +0000 Server: stagefright/1.2 (Linux;Android 4.3) CSeq: 2
Content-Type: text/parameters Content-Length: 83 wfd_content_protection wfd_video_formats wfd_audio_codecs wfd_client_rtp_ports
M3 response: RTSP/1.0 200 OK CSeq: 2
Content-Length: 124
Content-Type: text/parameters
wfd_audio_codecs: LPCM 00000003 00, AAC 00000007 00
wfd_video_formats: 00 00 02 02 0000FFFF 0FFFFFFF 00000FFF 00 0000 0000 01 none none
wfd_content_protection: none
wfd_client_rtp_ports: RTP/AVP/UDP;unicast 19990 0 mode=play
M4 request:
SET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0 Date: Tue, 29 Fri 2014 02:41:25 +0000 Server: stagefright/1.2 (Linux;Android 4.3) CSeq: 3
Content-Type: text/parameters Content-Length: 247
wfd_video_formats: 00 00 02 02 00000020 00000000 00000000 00 0000 0000 00 none none
wfd_audio_codecs: AAC 00000001 00
wfd_presentation_URL: rtsp://192.168.5.200/wfd1.0/streamid=0 none wfd_client_rtp_ports: RTP/AVP/UDP;unicast 19990 0 mode=play
M4 response: RTSP/1.0 200 OK CSeq: 3
M5 request:
SET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0 Date: Tue, 29 Fri 2014 02:41:25 +0000 Server: stagefright/1.2 (Linux;Android 4.3) CSeq: 4
Content-Type: text/parameters Content-Length: 27
wfd_trigger_method: SETUP
M5 response: RTSP/1.0 200 OK CSeq: 4
M6 request:
SETUP rtsp://192.168.5.200/wfd1.0/streamid=0 RTSP/1.0 CSeq: 3
Transport: RTP/AVP/UDP;unicast;client_port=19990
M6 response:
RTSP/1.0 200 OK
Date: Tue, 29 Fri 2014 02:41:25 +0000 Server: stagefright/1.2 (Linux;Android 4.3) CSeq: 3
Session: 988982966;timeout=30
Transport: RTP/AVP/UDP;unicast;client_port=19990;server_port=22220
我们先来看处理M6 request的方法,代码在onSetupRequest中:
[java] view plain copy 1. status_t WifiDisplaySource::onSetupRequest( 2. int32_t sessionID, 3. int32_t cseq,
4. const sp
6. if (mClientInfo.mPlaybackSessionID != -1) {
7. sendErrorResponse(sessionID, \, cseq); 8. return ERROR_MALFORMED; 9. } 10.
11. int32_t playbackSessionID = makeUniquePlaybackSessionID(); 12.
13. sp notify = new AMessage(kWhatPlaybackSessionNotify, id()); 14. notify->setInt32(\, playbackSessionID); 15. notify->setInt32(\, sessionID); 16.
17. sp
19. mNetSession, notify, mInterfaceAddr, mHDCP, mMediaPath.c_str
());
20.
21. looper()->registerHandler(playbackSession); 22.
23. AString uri;
24. data->getRequestField(1, &uri); 25.
26. if (strncasecmp(\, uri.c_str(), 7)) {
27. sendErrorResponse(sessionID, \, cseq); 28. return ERROR_MALFORMED; 29. }