Skip to content

Commit 5d42075

Browse files
theandi666Android (Google) Code Review
authored andcommitted
Merge "DO NOT MERGE: Instead of asserting, remove active streams if their sockets" into ics-mr1
2 parents d9f25bc + 4d7dff1 commit 5d42075

File tree

1 file changed

+47
-15
lines changed

1 file changed

+47
-15
lines changed

media/libstagefright/rtsp/ARTPConnection.cpp

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void ARTPConnection::onRemoveStream(const sp<AMessage> &msg) {
220220
}
221221

222222
if (it == mStreams.end()) {
223-
TRESPASS();
223+
return;
224224
}
225225

226226
mStreams.erase(it);
@@ -274,41 +274,52 @@ void ARTPConnection::onPollStreams() {
274274
}
275275

276276
int res = select(maxSocket + 1, &rs, NULL, NULL, &tv);
277-
CHECK_GE(res, 0);
278277

279278
if (res > 0) {
280-
for (List<StreamInfo>::iterator it = mStreams.begin();
281-
it != mStreams.end(); ++it) {
279+
List<StreamInfo>::iterator it = mStreams.begin();
280+
while (it != mStreams.end()) {
282281
if ((*it).mIsInjected) {
282+
++it;
283283
continue;
284284
}
285285

286+
status_t err = OK;
286287
if (FD_ISSET(it->mRTPSocket, &rs)) {
287-
receive(&*it, true);
288+
err = receive(&*it, true);
288289
}
289-
if (FD_ISSET(it->mRTCPSocket, &rs)) {
290-
receive(&*it, false);
290+
if (err == OK && FD_ISSET(it->mRTCPSocket, &rs)) {
291+
err = receive(&*it, false);
291292
}
293+
294+
if (err == -ECONNRESET) {
295+
// socket failure, this stream is dead, Jim.
296+
297+
LOGW("failed to receive RTP/RTCP datagram.");
298+
it = mStreams.erase(it);
299+
continue;
300+
}
301+
302+
++it;
292303
}
293304
}
294305

295-
postPollEvent();
296-
297306
int64_t nowUs = ALooper::GetNowUs();
298307
if (mLastReceiverReportTimeUs <= 0
299308
|| mLastReceiverReportTimeUs + 5000000ll <= nowUs) {
300309
sp<ABuffer> buffer = new ABuffer(kMaxUDPSize);
301-
for (List<StreamInfo>::iterator it = mStreams.begin();
302-
it != mStreams.end(); ++it) {
310+
List<StreamInfo>::iterator it = mStreams.begin();
311+
while (it != mStreams.end()) {
303312
StreamInfo *s = &*it;
304313

305314
if (s->mIsInjected) {
315+
++it;
306316
continue;
307317
}
308318

309319
if (s->mNumRTCPPacketsReceived == 0) {
310320
// We have never received any RTCP packets on this stream,
311321
// we don't even know where to send a report.
322+
++it;
312323
continue;
313324
}
314325

@@ -327,16 +338,34 @@ void ARTPConnection::onPollStreams() {
327338
if (buffer->size() > 0) {
328339
LOGV("Sending RR...");
329340

330-
ssize_t n = sendto(
341+
ssize_t n;
342+
do {
343+
n = sendto(
331344
s->mRTCPSocket, buffer->data(), buffer->size(), 0,
332345
(const struct sockaddr *)&s->mRemoteRTCPAddr,
333346
sizeof(s->mRemoteRTCPAddr));
347+
} while (n < 0 && errno == EINTR);
348+
349+
if (n <= 0) {
350+
LOGW("failed to send RTCP receiver report (%s).",
351+
n == 0 ? "connection gone" : strerror(errno));
352+
353+
it = mStreams.erase(it);
354+
continue;
355+
}
356+
334357
CHECK_EQ(n, (ssize_t)buffer->size());
335358

336359
mLastReceiverReportTimeUs = nowUs;
337360
}
361+
362+
++it;
338363
}
339364
}
365+
366+
if (!mStreams.empty()) {
367+
postPollEvent();
368+
}
340369
}
341370

342371
status_t ARTPConnection::receive(StreamInfo *s, bool receiveRTP) {
@@ -350,16 +379,19 @@ status_t ARTPConnection::receive(StreamInfo *s, bool receiveRTP) {
350379
(!receiveRTP && s->mNumRTCPPacketsReceived == 0)
351380
? sizeof(s->mRemoteRTCPAddr) : 0;
352381

353-
ssize_t nbytes = recvfrom(
382+
ssize_t nbytes;
383+
do {
384+
nbytes = recvfrom(
354385
receiveRTP ? s->mRTPSocket : s->mRTCPSocket,
355386
buffer->data(),
356387
buffer->capacity(),
357388
0,
358389
remoteAddrLen > 0 ? (struct sockaddr *)&s->mRemoteRTCPAddr : NULL,
359390
remoteAddrLen > 0 ? &remoteAddrLen : NULL);
391+
} while (nbytes < 0 && errno == EINTR);
360392

361-
if (nbytes < 0) {
362-
return -1;
393+
if (nbytes <= 0) {
394+
return -ECONNRESET;
363395
}
364396

365397
buffer->setRange(0, nbytes);

0 commit comments

Comments
 (0)