RTSP串連伺服器和從伺服器接收資料的處理流程

來源:互聯網
上載者:User

RTSP串連伺服器是否成功,以及是否從伺服器接收到實際播放的資料,主要是判斷兩個linux select函數的執行結果。
1.串連伺服器的處理過程

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) { // 正在串連中            sp<AMessage> msg = new AMessage(kWhatCompleteConnection, id());            msg->setMessage("reply", reply);            msg->setInt32("connection-id", mConnectionID);            msg->post();

調用---------->

void ARTSPConnection::onMessageReceived(const sp<AMessage> &msg) {case kWhatCompleteConnection:            onCompleteConnection(msg);

調用----------> 

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(); // 迴圈執行此函數檢查是否connected        return;    }

2.是否接收到伺服器發送的播放資料的處理

2.1 在ARTSPConnection::onCompleteConnection成功串連後,發送檢查接收資料的event

void ARTSPConnection::postReceiveReponseEvent() {    if (mReceiveResponseEventPending) {        return;    }    sp<AMessage> msg = new AMessage(kWhatReceiveResponse, id());    msg->post();    mReceiveResponseEventPending = true;}

調用---------->

2.2 void ARTSPConnection::onMessageReceived(const sp<AMessage> &msg) {
        case kWhatReceiveResponse:
            onReceiveResponse();
            break;
繼續調用---------->
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(); // 迴圈執行此函數}

繼續調用……

2.3.1 bool ARTSPConnection::receiveRTSPReponse() {

--->
  2.3.1.1 bool ARTSPConnection::receiveLine(AString *line) {
  --->
    2.3.1.1.1 status_t ARTSPConnection::receive(void *data, size_t size) { // 每次讀一個字元
    --->
      2.3.1.1.1.1 ssize_t n = recv(mSocket, (uint8_t *)data + offset, size - offset, 0); // 從TCP串連的另一端接收資料
--->  
  2.3.1.2 sp<ABuffer> ARTSPConnection::receiveBinaryData()
  --->
    2.3.1.2.1 status_t ARTSPConnection::receive(void *data, size_t size) { // 每次讀3個字元
    --->
      recv()
    2.3.1.2.2 status_t ARTSPConnection::receive(void *data, size_t size) { // 每次讀buffer->size()個字元
    --->
      recv()      
--->
  2.3.1.3 new ARTSPResponse
--->
  2.3.1.4 receiveLine()
--->
  2.3.1.5 recv() // while (numBytesRead < contentLength)
--->
  2.3.1.6 函數返回
  return isRequest
        ? handleServerRequest(response)
        : notifyResponseListener(response);
        
 附:
SDP: Session Description Protocol
[RFC4566]
http://www.ietf.org/rfc/rfc4566.txt

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.