Whether the RTSP connects to the server and whether the server receives the actual playback data is mainly used to determine the execution results of the two Linux select functions.
1. process of connecting to the server
Artspconnection: onconnect (const sp <amessage> & MSG) int err =: connect (msocket, (const struct sockaddr *) & remote, sizeof (remote )); logE ("% s l % d err = % d", _ FUNCTION __, _ line __, ERR); If (ERR <0) {If (errno = einprogress) {// In connection sp <amessage> MSG = new amessage (kwhatcompleteconnection, ID (); MSG-> setmessage ("reply ", reply); MSG-> setint32 ("connection-ID", mconnectionid); MSG-> post ();
Call ---------->
void ARTSPConnection::onMessageReceived(const sp<AMessage> &msg) {case kWhatCompleteConnection: onCompleteConnection(msg);
Call ---------->
Artspconnection: oncompleteconnection int res = select (msocket + 1, null, & WS, null, & TV); check_ge (Res, 0); If (RES = 0) {// timed out. not yet connected. logE ("% s l % d-econnaborted", _ FUNCTION __, _ line _); MSG-> post (); // execute this function cyclically to check for connected return ;}
2. Whether to receive the processing of the playback data sent by the server
2.1 After artspconnection: oncompleteconnection is successfully connected, send the event to check the received data
void ARTSPConnection::postReceiveReponseEvent() { if (mReceiveResponseEventPending) { return; } sp<AMessage> msg = new AMessage(kWhatReceiveResponse, id()); msg->post(); mReceiveResponseEventPending = true;}
Call ---------->
2.2 void artspconnection: onmessagereceived (const sp <amessage> & MSG ){
Case kwhatreceiveresponse:
Onreceiveresponse ();
Break;
Continue calling ---------->
2.3
Void artspconnection: onreceiveresponse () {int res = select (msocket + 1, & RS, null, null, & TV ); // LogE ("% s l % d select res = % d", _ FUNCTION __, _ line __, res); check_ge (Res, 0 ); if (RES = 1) {makesocketblocking (msocket, true); bool success = receivertspreponse (); // 2.3.1 makesocketblocking (msocket, false ); logE ("% s l % d select = Success = % d", _ FUNCTION __, _ line __, success); If (! Success) {// something horrible, irreparable has happened. flushpendingrequests (); LogE ("% s l % d Return", _ FUNCTION __, _ line _); Return ;}} postreceivereponseevent (); // execute this function cyclically}
Continue to call ......
2.3.1 bool artspconnection: receivertspreponse (){
--->
2.3.1.1 bool artspconnection: Eline (astring * Line ){
--->
2.3.1.1.1 status_t artspconnection: receive (void * data, size_t size) {// read one character each time
--->
2.3.1.1.1.1 ssize_t n = Recv (msocket, (uint8_t *) Data + offset, size-offset, 0); // receive data from the other end of the TCP Connection
--->
2.3.1.2 sp <abuffer> artspconnection: receivebinarydata ()
--->
2.3.1.2.1 status_t artspconnection: receive (void * data, size_t size) {// read three characters each time
--->
Recv ()
2.3.1.2.2 status_t artspconnection: receive (void * data, size_t size) {// each read buffer-> size () characters
--->
Recv ()
--->
2.3.1.3 new artspresponse
--->
2.3.1.4 Eline ()
--->
2.3.1.5 Recv () // while (numbytesread <contentlength)
--->
2.3.1.6 function return
Return isrequest
? Handleserverrequest (response)
: Policyresponselistener (response );
Appendix:
SDP: Session Description Protocol
[Rfc4566]
Http://www.ietf.org/rfc/rfc4566.txt