const int AAH_TXSender::kRetryTrimIntervalUs = 100000;
const int AAH_TXSender::kHeartbeatIntervalUs = 1000000;
const int AAH_TXSender::kRetryBufferCapacity = 100;
+const nsecs_t AAH_TXSender::kHeartbeatTimeout = 600ull * 1000000000ull;
Mutex AAH_TXSender::sLock;
wp<AAH_TXSender> AAH_TXSender::sInstance;
uint32_t AAH_TXSender::sNextEpoch;
bool AAH_TXSender::sNextEpochValid = false;
-AAH_TXSender::AAH_TXSender() : mSocket(-1) { }
+AAH_TXSender::AAH_TXSender() : mSocket(-1) {
+ mLastSentPacketTime = systemTime();
+}
sp<AAH_TXSender> AAH_TXSender::GetInstance() {
Mutex::Autolock autoLock(sLock);
Mutex::Autolock lock(mEndpointLock);
doSendPacket_l(packet, Endpoint(ipAddr, port));
+ mLastSentPacketTime = systemTime();
}
void AAH_TXSender::doSendPacket_l(const sp<TRTPPacket>& packet,
void AAH_TXSender::sendHeartbeats() {
Mutex::Autolock lock(mEndpointLock);
- for (size_t i = 0; i < mEndpointMap.size(); i++) {
- EndpointState* eps = mEndpointMap.editValueAt(i);
- const Endpoint& ep = mEndpointMap.keyAt(i);
+ if (shouldSendHeartbeats_l()) {
+ for (size_t i = 0; i < mEndpointMap.size(); i++) {
+ EndpointState* eps = mEndpointMap.editValueAt(i);
+ const Endpoint& ep = mEndpointMap.keyAt(i);
- sp<TRTPControlPacket> packet = new TRTPControlPacket();
- packet->setCommandID(TRTPControlPacket::kCommandNop);
+ sp<TRTPControlPacket> packet = new TRTPControlPacket();
+ packet->setCommandID(TRTPControlPacket::kCommandNop);
- packet->setExpireTime(systemTime() +
- AAH_TXPlayer::kAAHRetryKeepAroundTimeNs);
- packet->pack();
+ packet->setExpireTime(systemTime() +
+ AAH_TXPlayer::kAAHRetryKeepAroundTimeNs);
+ packet->pack();
- doSendPacket_l(packet, ep);
+ doSendPacket_l(packet, ep);
+ }
}
// schedule the next heartbeat
}
}
+bool AAH_TXSender::shouldSendHeartbeats_l() {
+ // assert(holding endpoint lock)
+ return (systemTime() < (mLastSentPacketTime + kHeartbeatTimeout));
+}
+
// Receiver
// initial 4-byte ID of a retry request packet
const Endpoint& endpoint);
void trimRetryBuffers();
void sendHeartbeats();
+ bool shouldSendHeartbeats_l();
sp<ALooper> mLooper;
sp<AHandlerReflector<AAH_TXSender> > mReflector;
int mSocket;
+ nsecs_t mLastSentPacketTime;
DefaultKeyedVector<Endpoint, EndpointState*> mEndpointMap;
Mutex mEndpointLock;
static const int kRetryTrimIntervalUs;
static const int kHeartbeatIntervalUs;
static const int kRetryBufferCapacity;
+ static const nsecs_t kHeartbeatTimeout;
class RetryReceiver : public Thread {
private: