Calculate capture ntp timestamp in local timebase for decoded audio frame.

BUG=3111
R=stefan@webrtc.org, xians@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/19449005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6205 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc
index 365d4ca..700f5d6 100644
--- a/webrtc/voice_engine/channel.cc
+++ b/webrtc/voice_engine/channel.cc
@@ -15,6 +15,7 @@
 #include "webrtc/modules/audio_processing/include/audio_processing.h"
 #include "webrtc/modules/interface/module_common_types.h"
 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
+#include "webrtc/modules/rtp_rtcp/interface/remote_ntp_time_estimator.h"
 #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h"
 #include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h"
@@ -664,8 +665,7 @@
     // Measure audio level (0-9)
     _outputAudioLevel.ComputeLevel(audioFrame);
 
-    // TODO(wu): Calculate capture NTP time based on RTP timestamp and RTCP SR.
-    audioFrame.ntp_time_ms_ = 0;
+    audioFrame.ntp_time_ms_ = ntp_estimator_->Estimate(audioFrame.timestamp_);
 
     if (!first_frame_arrived_) {
       first_frame_arrived_ = true;
@@ -849,6 +849,7 @@
     _outputExternalMediaCallbackPtr(NULL),
     _timeStamp(0), // This is just an offset, RTP module will add it's own random offset
     _sendTelephoneEventPayloadType(106),
+    ntp_estimator_(new RemoteNtpTimeEstimator(Clock::GetRealTimeClock())),
     jitter_buffer_playout_timestamp_(0),
     playout_timestamp_rtp_(0),
     playout_timestamp_rtcp_(0),
@@ -1875,6 +1876,9 @@
         VE_SOCKET_TRANSPORT_MODULE_ERROR, kTraceWarning,
         "Channel::IncomingRTPPacket() RTCP packet is invalid");
   }
+
+  ntp_estimator_->UpdateRtcpTimestamp(rtp_receiver_->SSRC(),
+                                      _rtpRtcpModule.get());
   return 0;
 }
 
diff --git a/webrtc/voice_engine/channel.h b/webrtc/voice_engine/channel.h
index 7b40ed2..2eba91e 100644
--- a/webrtc/voice_engine/channel.h
+++ b/webrtc/voice_engine/channel.h
@@ -42,6 +42,7 @@
 class FileWrapper;
 class ProcessThread;
 class ReceiveStatistics;
+class RemoteNtpTimeEstimator;
 class RtpDump;
 class RTPPayloadRegistry;
 class RtpReceiver;
@@ -531,6 +532,8 @@
     uint32_t _timeStamp;
     uint8_t _sendTelephoneEventPayloadType;
 
+    scoped_ptr<RemoteNtpTimeEstimator> ntp_estimator_;
+
     // Timestamp of the audio pulled from NetEq.
     uint32_t jitter_buffer_playout_timestamp_;
     uint32_t playout_timestamp_rtp_;