diff options
author | Andreas Huber <andih@google.com> | 2013-03-12 11:01:43 -0700 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2013-03-12 13:44:58 -0700 |
commit | d5e56231a598b180a1d898bb7dc61b75580e59a4 (patch) | |
tree | 7bb3e14a2c8212813d6e33cb3c7a8da2470d58f5 /media/libstagefright/wifi-display/TimeSyncer.h | |
parent | e6800cea0678dbc0bf697b44c3e4548b0253085c (diff) | |
download | frameworks_av-d5e56231a598b180a1d898bb7dc61b75580e59a4.zip frameworks_av-d5e56231a598b180a1d898bb7dc61b75580e59a4.tar.gz frameworks_av-d5e56231a598b180a1d898bb7dc61b75580e59a4.tar.bz2 |
Squashed commit of the following:
commit f4edf442741886cdbe071e2d15f6e6247269f7c5
Author: Andreas Huber <andih@google.com>
Date: Tue Mar 12 09:09:18 2013 -0700
Pass additional flags to the sink, use TCP by default in wolfiecast mode.
Change-Id: I41e11a2375d4199656e45c4f149d8441d0016092
commit 6302602ed280a38287f507159abfb40a1da38c5a
Author: Andreas Huber <andih@google.com>
Date: Tue Mar 12 08:51:58 2013 -0700
tweaks
Change-Id: Ie29e422d7258be522f4bb1f6c5afcf74c937e547
commit a38a860e4979ba563cadbaafa21b084439449d26
Author: Andreas Huber <andih@google.com>
Date: Mon Mar 11 16:57:43 2013 -0700
Report average lateness all the way from NuPlayerRenderer...
Change-Id: I2e7700703ae656515e44b9c25610d26c75778111
commit a7d49b11675ea88be4029dd8451d1649db94571d
Author: Andreas Huber <andih@google.com>
Date: Mon Mar 11 14:54:19 2013 -0700
Make TimeSyncer smarter, enable TunnelRenderer
Change-Id: I27377a60cd8feb01589da456967fddd34532c20e
commit 0f214c8ef68179f7b61512c37040939554013151
Author: Andreas Huber <andih@google.com>
Date: Thu Mar 7 15:57:56 2013 -0800
convert source timestamps to sink timestamps, report lateness.
Change-Id: I051a60fbbceca2f7b508ae3dac6e01e402bae39e
commit 04a4f8e16bad09157b5615a5fa45310438955832
Author: Andreas Huber <andih@google.com>
Date: Thu Mar 7 09:00:28 2013 -0800
Sync time between sink and source.
Change-Id: Ie8b4d75c957aa48310e7c81d1279761b9f821efe
commit aebe20e6184e3636a99082f8ece08e708015cb8d
Author: Andreas Huber <andih@google.com>
Date: Wed Mar 6 09:03:12 2013 -0800
play with back pressure
Change-Id: I51eb69257e6a79e76f5f9c75ff99d8adbd083947
Change-Id: Ifdf57228667fed7fc71c5090a2c3f7cea1037c5c
Diffstat (limited to 'media/libstagefright/wifi-display/TimeSyncer.h')
-rw-r--r-- | media/libstagefright/wifi-display/TimeSyncer.h | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/media/libstagefright/wifi-display/TimeSyncer.h b/media/libstagefright/wifi-display/TimeSyncer.h new file mode 100644 index 0000000..0e3aed7 --- /dev/null +++ b/media/libstagefright/wifi-display/TimeSyncer.h @@ -0,0 +1,109 @@ +/* + * Copyright 2013, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TIME_SYNCER_H_ + +#define TIME_SYNCER_H_ + +#include <media/stagefright/foundation/AHandler.h> + +namespace android { + +struct ANetworkSession; + +/* + TimeSyncer allows us to synchronize time between a client and a server. + The client sends a UDP packet containing its send-time to the server, + the server sends that packet back to the client amended with information + about when it was received as well as the time the reply was sent back. + Finally the client receives the reply and has now enough information to + compute the clock offset between client and server assuming that packet + exchange is symmetric, i.e. time for a packet client->server and + server->client is roughly equal. + This exchange is repeated a number of times and the average offset computed + over the 30% of packets that had the lowest roundtrip times. + The offset is determined every 10 secs to account for slight differences in + clock frequency. +*/ +struct TimeSyncer : public AHandler { + enum { + kWhatError, + kWhatTimeOffset, + }; + TimeSyncer( + const sp<ANetworkSession> &netSession, + const sp<AMessage> ¬ify); + + void startServer(unsigned localPort); + void startClient(const char *remoteHost, unsigned remotePort); + +protected: + virtual ~TimeSyncer(); + + virtual void onMessageReceived(const sp<AMessage> &msg); + +private: + enum { + kWhatStartServer, + kWhatStartClient, + kWhatUDPNotify, + kWhatSendPacket, + kWhatTimedOut, + }; + + struct TimeInfo { + int64_t mT1; // client timestamp at send + int64_t mT2; // server timestamp at receive + int64_t mT3; // server timestamp at send + int64_t mT4; // client timestamp at receive + }; + + enum { + kNumPacketsPerBatch = 30, + }; + static const int64_t kTimeoutDelayUs = 500000ll; + static const int64_t kBatchDelayUs = 10000000ll; // every 10 secs + + sp<ANetworkSession> mNetSession; + sp<AMessage> mNotify; + + bool mIsServer; + bool mConnected; + int32_t mUDPSession; + uint32_t mSeqNo; + double mTotalTimeUs; + + Vector<TimeInfo> mHistory; + + int64_t mPendingT1; + int32_t mTimeoutGeneration; + + void postSendPacket(int64_t delayUs = 0ll); + + void postTimeout(); + void cancelTimeout(); + + void notifyError(status_t err); + void notifyOffset(); + + static int CompareRountripTime(const TimeInfo *ti1, const TimeInfo *ti2); + + DISALLOW_EVIL_CONSTRUCTORS(TimeSyncer); +}; + +} // namespace android + +#endif // TIME_SYNCER_H_ |