There are many heroes on the internet have done a detailed analysis of Darwin, under the purpose of accumulating experience only, will Darwin's learning process to record, at the same time with friends to Exchange learning, today first to analyze Darwin if according to the configuration file monitoring RTSP connection process.
1. Darwin system initialization, Bool16 qtsserver::initialize (..... )
2. Qtsserver::createlisteners (... Based on the address and port in the local XML configuration file, there are two main configuration items:
<pref name= "Bind_ip_addr" >0</PREF>
<list-pref name= "Rtsp_port" type= "UInt16" >
3. void Qtsserver::starttasks () starts listening on the socket list built up in the previous step
Bool16 qtsserver::createlisteners (Bool16 startlisteningnow, qtsserverprefs* inprefs, UInt16 inportoverride) {struct PO rttracking {porttracking (): FPort (0), fipaddr (0), fneedscreating (True) {} UInt16 FPort; Port number UInt32 fipaddr;//address Bool16 fneedscreating;//need to create Rtsplistenersocket, default creation}; porttracking* theporttrackers = NULL; UInt32 thetotalporttrackers = 0; Get the IP addresses from the pref gets the IP address and port number of the configuration file used to listen for RTSP connections UInt32 Thenumaddrs = 0; uint32* Theipaddrs = This->getrtspipaddrs (Inprefs, &thenumaddrs); UInt32 index = 0; Inportoverride This parameter is passed in as a command-line argument, which defaults to 0. -P xxx:specify The default RTSP listening port of the the server if (inportoverride! = 0) {Thetotalporttracker s = Thenumaddrs; One port tracking struct for each IP addr theporttrackers = NEW Porttracking[thetotalporttrackers]; for (index = 0; index < Thenumaddrs; index++) {Theporttrackers[inDex].fport = Inportoverride; THEPORTTRACKERS[INDEX].FIPADDR = Theipaddrs[index]; }} else {UInt32 thenumports = 0; uint16* theports = Getrtspports (Inprefs, &thenumports); Based on <list-pref name= "Rtsp_port" type= "UInt16" in the XML configuration file > get port number thetotalporttrackers = Thenumaddrs * Thenumport S Theporttrackers = NEW porttracking[thetotalporttrackers];//Total number of listeners required: number of ports * IP address number UInt32 currentindex = 0; for (index = 0, index < Thenumaddrs; index++) {for (UInt32 portindex = 0; portindex < Thenumports; portindex++) {Currentindex = (Thenumports * index) + portindex; Theporttrackers[currentindex].fport = Theports[portindex]; THEPORTTRACKERS[CURRENTINDEX].FIPADDR = Theipaddrs[index]; }} Delete [] theports; } delete [] Theipaddrs; Now FiguRe out which of these ports we is *already* listening on. If we already is listening on this port, just move the pointer to the//listener over to the new array tcpliste nersocket** Newlistenerarray = NEW Tcplistenersocket*[thetotalporttrackers]; UInt32 curportindex = 0; for (UInt32 count = 0, Count < thetotalporttrackers; count++) {for (UInt32 count2 = 0; Count2 < fnumliste ners; count2++) {if (flisteners[count2]->getlocalport () = = Theporttrackers[count].fport) && (flisteners[count2]->getlocaladdr () = = theporttrackers[count].fipaddr)) {//If the ip+port has been monitored in the flisteners listener list, then no longer listens; Theporttrackers[count].fneedscreating = false; newlistenerarray[curportindex++] = Flisteners[count2]; Assert (Curportindex <= thetotalporttrackers); Break }}}///create rtsplistenersocket for Ip+port to listen for (UInt32Count3 = 0; Count3 < thetotalporttrackers; count3++) {if (theporttrackers[count3].fneedscreating)//Do not need to listen, the field has been set to false in the previous step. {//Create RTSP listener task; Newlistenerarray[curportindex] = NEW rtsplistenersocket (); Qtss_error err = newlistenerarray[curportindex]->initialize (theporttrackers[count3].fipaddr, thePortTrackers[ Count3].fport); Char theportstr[20]; qtss_sprintf (Theportstr, "%hu", Theporttrackers[count3].fport); If there was a error creating this listener, destroy it and log an error If (STARTLISTENINGN ow) && (err! = qtss_noerr))) Delete Newlistenerarray[curportindex]; if (err = = Eaddrinuse) {qtssmoduleutils::logerror (qtsswarningverbosity, Qtsslistenportinuse, 0, THEPORTSTR) ;} else if (err = = eacces) {qtssmoduleutils::logerror (qtsswarningverbosity, qtsslistenportaccessdenied, 0, thePortStr);} else if (err ! = Qtss_noerr) {qtssmoduleutils::logerror (qtsswarningverbosity, Qtsslistenporterror, 0, theportstr);} else {//Assign the first available port to Fokport, save, and subsequently provide the RTSP listener port via Getokport () for this port; if (Fokport = = 0) {Fokport = Theporttracke Rs[count3].fport;} This listener is successfully created. If you need to listen, start listening to the connection above the socket immediately. if (Startlisteningnow) newlistenerarray[curportindex]->requestevent (ev_re); curportindex++; }}}////will kill the socket in the Flisteners listener list that is not within the profile listening range ~ for (UInt32 count4 = 0; count4 < fnumlisteners; count4++) {Bool16 Deletethisone = true; for (UInt32 count5 = 0; count5 < Curportindex; count5++) {if (newlistenerarray[count5] = = Flisteners [COUNT4]) Deletethisone = false; } if (Deletethisone) flisteners[count4]->signal (task::kkillevent); } //Finally, make your server attributes and Flistener privy to the new ... Finally, the listener list is assigned to Flisteners, and the number of listeners is assigned to fnumlisteners flisteners = Newlistenerarray; Fnumlisteners = Curportindex; UInt32 portindex = 0; Save the list of monitored port numbers with the key value Qtsssvrrtspports for (UInt32 count6 = 0; count6 < fnumlisteners; count6++) {if (fLi STENERS[COUNT6]->GETLOCALADDR ()! = Inaddr_loopback) {UInt16 Theport = Flisteners[count6]->getloca Lport (); (void) This->setvalue (Qtsssvrrtspports, PortIndex, &theport, sizeof (Theport), Qtssdictionary:: KDONTOBEYREADONLY); portindex++; }}//sets the number of port lists; This->setnumvalues (Qtsssvrrtspports, PortIndex); delete [] theporttrackers; Return (fnumlisteners > 0);}
Get the RTSP listener address list from the configuration file, that is, <pref name= "bind_ip_addr" >0</PREF> configuration item, system default is 0, the configuration item may need to be used on the multi-NIC server. In general we can not consider when debugging learning. But the introduction, but also relatively simple.
uint32* Qtsserver::getrtspipaddrs (qtsserverprefs* inprefs, uint32* outnumaddrsptr) {UInt32 NumAddrs = InPrefs->GetN Umvalues (QTSSPREFSRTSPIPADDR);//Gets the number of RTSP listener addresses in the configuration file; uint32* Theipaddrarray = NULL; if (Numaddrs = = 0)//If the configured number of listening addresses is 0, set to Inaddr_any {*outnumaddrsptr = 1; Theipaddrarray = NEW uint32[1]; Theipaddrarray[0] = Inaddr_any;//inaddr_any is the address named 0.0.0.0, which in fact represents an indeterminate address, or "all addresses", "arbitrary addresses". } else {Theipaddrarray = NEW Uint32[numaddrs + 1]; UInt32 arrindex = 0; for (UInt32 theindex = 0, theindex < Numaddrs; theindex++) {//Get the IP addr out of the Prefs Dict Ionary qtss_error theerr = Qtss_noerr; char* theipaddrstr = NULL; Theerr = inprefs->getvalueasstring (qtssprefsrtspipaddr, Theindex, &THEIPADDRSTR); if (theerr! = qtss_noerr) {delete [] theipaddrstr; Break } UInt32 theipaddr = 0; if (theipaddrstr! = NULL) {//IP address is converted from a string to an integral type and converted from network byte order to host byte order theipaddr = Socketutils::convertstr INGTOADDR (THEIPADDRSTR); delete [] theipaddrstr; if (theipaddr! = 0) theipaddrarray[arrindex++] = theipaddr; }} if ((Numaddrs = = 1) && (Arrindex = = 0))//If the number of IP addresses for the configuration file is 1, but cannot be resolved, then the same is monitored in inaddr_any mode theipaddrarray[arrindex++] = Inaddr_any; else theipaddrarray[arrindex++] = Inaddr_loopback; Inaddr_loopback, that is, the binding address Loopbac, is often 127.0.0.1, can only receive 127.0.0.1 above connection request *outnumaddrsptr = Arrindex; } return Theipaddrarray;}
The method to get the list of RTSP listener ports is relatively simple, as follows:
uint16* qtsserver::getrtspports (qtsserverprefs* inprefs, uint32* outnumportsptr) { *outnumportsptr = inPrefs-> Getnumvalues (Qtssprefsrtspports); Gets the array length corresponding to the qtssprefsrtspports; if (*outnumportsptr = = 0) return NULL; uint16* Theportarray = NEW uint16[*outnumportsptr]; Get a list of listening port numbers; for (UInt32 theindex = 0, theindex < *outnumportsptr; theindex++) { //Get the IP addr out of the prefs diction ary UInt32 theLen = sizeof (UInt16); Qtss_error theerr = Qtss_noerr; Theerr = Inprefs->getvalue (Qtssprefsrtspports, Theindex, &theportarray[theindex], &theLen); Assert (Theerr = = Qtss_noerr); } return Theportarray;}
So according to the configuration file of the IP, port, that the corresponding socket has been established, and Startlisteningnow default is False, you need to call Sserver->starttasks () in Runserver, to start monitoring
void Qtsserver::starttasks () { frtcptask = new Rtcptask (); Fstatstask = new Rtpstatsupdatertask (); //Start listening for (UInt32 x = 0; x < Fnumlisteners, + x + +) flisteners[x]->requestevent (ev_re);}
"Darwin Learning note" RTSP Connection listener initialization