WifiDisplaySource.h revision d7bee3a9d2ad76d073d91f0ee36d5ac5f9df480c
1/* 2 * Copyright 2012, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef WIFI_DISPLAY_SOURCE_H_ 18 19#define WIFI_DISPLAY_SOURCE_H_ 20 21#include "ANetworkSession.h" 22 23#include <media/stagefright/foundation/AHandler.h> 24 25namespace android { 26 27struct ParsedMessage; 28 29// Represents the RTSP server acting as a wifi display source. 30// Manages incoming connections, sets up Playback sessions as necessary. 31struct WifiDisplaySource : public AHandler { 32 static const unsigned kWifiDisplayDefaultPort = 7236; 33 34 WifiDisplaySource(const sp<ANetworkSession> &netSession); 35 36 status_t start(int32_t port); 37 status_t stop(); 38 39protected: 40 virtual ~WifiDisplaySource(); 41 virtual void onMessageReceived(const sp<AMessage> &msg); 42 43private: 44 struct PlaybackSession; 45 46 enum { 47 kWhatStart, 48 kWhatRTSPNotify, 49 kWhatStop, 50 kWhatReapDeadClients, 51 kWhatPlaybackSessionNotify, 52 }; 53 54 struct ResponseID { 55 int32_t mSessionID; 56 int32_t mCSeq; 57 58 bool operator<(const ResponseID &other) const { 59 return mSessionID < other.mSessionID 60 || (mSessionID == other.mSessionID 61 && mCSeq < other.mCSeq); 62 } 63 }; 64 65 typedef status_t (WifiDisplaySource::*HandleRTSPResponseFunc)( 66 int32_t sessionID, const sp<ParsedMessage> &msg); 67 68 static const int64_t kReaperIntervalUs = 1000000ll; 69 70 static const int64_t kPlaybackSessionTimeoutSecs = 30; 71 72 static const int64_t kPlaybackSessionTimeoutUs = 73 kPlaybackSessionTimeoutSecs * 1000000ll; 74 75 sp<ANetworkSession> mNetSession; 76 int32_t mSessionID; 77 78 struct ClientInfo { 79 AString mRemoteIP; 80 AString mLocalIP; 81 int32_t mLocalPort; 82 }; 83 KeyedVector<int32_t, ClientInfo> mClientIPs; 84 85 bool mReaperPending; 86 87 int32_t mNextCSeq; 88 89 KeyedVector<ResponseID, HandleRTSPResponseFunc> mResponseHandlers; 90 91 KeyedVector<int32_t, sp<PlaybackSession> > mPlaybackSessions; 92 93 status_t sendM1(int32_t sessionID); 94 status_t sendM3(int32_t sessionID); 95 status_t sendM4(int32_t sessionID); 96 status_t sendM5(int32_t sessionID); 97 98 status_t onReceiveM1Response( 99 int32_t sessionID, const sp<ParsedMessage> &msg); 100 101 status_t onReceiveM3Response( 102 int32_t sessionID, const sp<ParsedMessage> &msg); 103 104 status_t onReceiveM4Response( 105 int32_t sessionID, const sp<ParsedMessage> &msg); 106 107 status_t onReceiveM5Response( 108 int32_t sessionID, const sp<ParsedMessage> &msg); 109 110 void registerResponseHandler( 111 int32_t sessionID, int32_t cseq, HandleRTSPResponseFunc func); 112 113 void onReceiveClientData(const sp<AMessage> &msg); 114 115 void onDescribeRequest( 116 int32_t sessionID, 117 int32_t cseq, 118 const sp<ParsedMessage> &data); 119 120 void onOptionsRequest( 121 int32_t sessionID, 122 int32_t cseq, 123 const sp<ParsedMessage> &data); 124 125 void onSetupRequest( 126 int32_t sessionID, 127 int32_t cseq, 128 const sp<ParsedMessage> &data); 129 130 void onPlayRequest( 131 int32_t sessionID, 132 int32_t cseq, 133 const sp<ParsedMessage> &data); 134 135 void onPauseRequest( 136 int32_t sessionID, 137 int32_t cseq, 138 const sp<ParsedMessage> &data); 139 140 void onTeardownRequest( 141 int32_t sessionID, 142 int32_t cseq, 143 const sp<ParsedMessage> &data); 144 145 void onGetParameterRequest( 146 int32_t sessionID, 147 int32_t cseq, 148 const sp<ParsedMessage> &data); 149 150 void onSetParameterRequest( 151 int32_t sessionID, 152 int32_t cseq, 153 const sp<ParsedMessage> &data); 154 155 void sendErrorResponse( 156 int32_t sessionID, 157 const char *errorDetail, 158 int32_t cseq); 159 160 static void AppendCommonResponse( 161 AString *response, int32_t cseq, int32_t playbackSessionID = -1ll); 162 163 void scheduleReaper(); 164 165 int32_t makeUniquePlaybackSessionID() const; 166 167 sp<PlaybackSession> findPlaybackSession( 168 const sp<ParsedMessage> &data, int32_t *playbackSessionID) const; 169 170 DISALLOW_EVIL_CONSTRUCTORS(WifiDisplaySource); 171}; 172 173} // namespace android 174 175#endif // WIFI_DISPLAY_SOURCE_H_ 176