Skip to content

Commit dbe09da

Browse files
committed
DO NOT MERGE: Respond to RTSP server->client requests.
Even if it's just to tell them that we don't support any (this is optional). Change-Id: Iee50b4020f28a47dfbe5d56f1732fe044b3b3655 related-to-bug: 3353752
1 parent 3259d88 commit dbe09da

File tree

2 files changed

+83
-7
lines changed

2 files changed

+83
-7
lines changed

media/libstagefright/rtsp/ARTSPConnection.cpp

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,10 @@ sp<ABuffer> ARTSPConnection::receiveBinaryData() {
545545
return buffer;
546546
}
547547

548+
static bool IsRTSPVersion(const AString &s) {
549+
return s == "RTSP/1.0";
550+
}
551+
548552
bool ARTSPConnection::receiveRTSPReponse() {
549553
AString statusLine;
550554

@@ -584,13 +588,27 @@ bool ARTSPConnection::receiveRTSPReponse() {
584588
return false;
585589
}
586590

587-
AString statusCodeStr(
588-
response->mStatusLine, space1 + 1, space2 - space1 - 1);
591+
bool isRequest = false;
589592

590-
if (!ParseSingleUnsignedLong(
591-
statusCodeStr.c_str(), &response->mStatusCode)
592-
|| response->mStatusCode < 100 || response->mStatusCode > 999) {
593-
return false;
593+
if (!IsRTSPVersion(AString(response->mStatusLine, 0, space1))) {
594+
CHECK(IsRTSPVersion(
595+
AString(
596+
response->mStatusLine,
597+
space2 + 1,
598+
response->mStatusLine.size() - space2 - 1)));
599+
600+
isRequest = true;
601+
602+
response->mStatusCode = 0;
603+
} else {
604+
AString statusCodeStr(
605+
response->mStatusLine, space1 + 1, space2 - space1 - 1);
606+
607+
if (!ParseSingleUnsignedLong(
608+
statusCodeStr.c_str(), &response->mStatusCode)
609+
|| response->mStatusCode < 100 || response->mStatusCode > 999) {
610+
return false;
611+
}
594612
}
595613

596614
AString line;
@@ -680,7 +698,63 @@ bool ARTSPConnection::receiveRTSPReponse() {
680698
}
681699
}
682700

683-
return notifyResponseListener(response);
701+
return isRequest
702+
? handleServerRequest(response)
703+
: notifyResponseListener(response);
704+
}
705+
706+
bool ARTSPConnection::handleServerRequest(const sp<ARTSPResponse> &request) {
707+
// Implementation of server->client requests is optional for all methods
708+
// but we do need to respond, even if it's just to say that we don't
709+
// support the method.
710+
711+
ssize_t space1 = request->mStatusLine.find(" ");
712+
CHECK_GE(space1, 0);
713+
714+
AString response;
715+
response.append("RTSP/1.0 501 Not Implemented\r\n");
716+
717+
ssize_t i = request->mHeaders.indexOfKey("cseq");
718+
719+
if (i >= 0) {
720+
AString value = request->mHeaders.valueAt(i);
721+
722+
unsigned long cseq;
723+
if (!ParseSingleUnsignedLong(value.c_str(), &cseq)) {
724+
return false;
725+
}
726+
727+
response.append("CSeq: ");
728+
response.append(cseq);
729+
response.append("\r\n");
730+
}
731+
732+
response.append("\r\n");
733+
734+
size_t numBytesSent = 0;
735+
while (numBytesSent < response.size()) {
736+
ssize_t n =
737+
send(mSocket, response.c_str() + numBytesSent,
738+
response.size() - numBytesSent, 0);
739+
740+
if (n == 0) {
741+
// Server closed the connection.
742+
LOGE("Server unexpectedly closed the connection.");
743+
744+
return false;
745+
} else if (n < 0) {
746+
if (errno == EINTR) {
747+
continue;
748+
}
749+
750+
LOGE("Error sending rtsp response.");
751+
return false;
752+
}
753+
754+
numBytesSent += (size_t)n;
755+
}
756+
757+
return true;
684758
}
685759

686760
// static

media/libstagefright/rtsp/ARTSPConnection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ struct ARTSPConnection : public AHandler {
109109
status_t findPendingRequest(
110110
const sp<ARTSPResponse> &response, ssize_t *index) const;
111111

112+
bool handleServerRequest(const sp<ARTSPResponse> &request);
113+
112114
static bool ParseSingleUnsignedLong(
113115
const char *from, unsigned long *x);
114116

0 commit comments

Comments
 (0)