update neteq 4 to facilitate NACK

BUG=
R=turaj@webrtc.org, turajs@google.com

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4637 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/audio_coding/neteq4/interface/neteq.h b/webrtc/modules/audio_coding/neteq4/interface/neteq.h
index 824b17b..1f1ee67 100644
--- a/webrtc/modules/audio_coding/neteq4/interface/neteq.h
+++ b/webrtc/modules/audio_coding/neteq4/interface/neteq.h
@@ -233,6 +233,10 @@
                                       int* current_memory_size_bytes,
                                       int* max_memory_size_bytes) const = 0;
 
+  // Get sequence number and timestamp of the latest RTP.
+  // This method is to facilitate NACK.
+  virtual int DecodedRtpInfo(int* sequence_number, uint32_t* timestamp) = 0;
+
  protected:
   NetEq() {}
 
diff --git a/webrtc/modules/audio_coding/neteq4/neteq_impl.cc b/webrtc/modules/audio_coding/neteq4/neteq_impl.cc
index 403fccb..279401a 100644
--- a/webrtc/modules/audio_coding/neteq4/neteq_impl.cc
+++ b/webrtc/modules/audio_coding/neteq4/neteq_impl.cc
@@ -87,7 +87,9 @@
       first_packet_(true),
       error_code_(0),
       decoder_error_code_(0),
-      crit_sect_(CriticalSectionWrapper::CreateCriticalSection()) {
+      crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
+      decoded_packet_sequence_number_(-1),
+      decoded_packet_timestamp_(0) {
   if (fs != 8000 && fs != 16000 && fs != 32000 && fs != 48000) {
     LOG(LS_ERROR) << "Sample rate " << fs << " Hz not supported. " <<
         "Changing to 8000 Hz.";
@@ -352,6 +354,15 @@
   first_packet_ = true;
 }
 
+int NetEqImpl::DecodedRtpInfo(int* sequence_number, uint32_t* timestamp) {
+  CriticalSectionScoped lock(crit_sect_);
+  if (decoded_packet_sequence_number_ < 0)
+    return -1;
+  *sequence_number = decoded_packet_sequence_number_;
+  *timestamp = decoded_packet_timestamp_;
+  return 0;
+}
+
 // Methods below this line are private.
 
 
@@ -1662,8 +1673,9 @@
 
     if (first_packet) {
       first_packet = false;
-      prev_sequence_number = packet->header.sequenceNumber;
-      prev_timestamp = packet->header.timestamp;
+      decoded_packet_sequence_number_ = prev_sequence_number =
+          packet->header.sequenceNumber;
+      decoded_packet_timestamp_ = prev_timestamp = packet->header.timestamp;
       prev_payload_type = packet->header.payloadType;
     }
 
diff --git a/webrtc/modules/audio_coding/neteq4/neteq_impl.h b/webrtc/modules/audio_coding/neteq4/neteq_impl.h
index 0d81208..56dde77 100644
--- a/webrtc/modules/audio_coding/neteq4/neteq_impl.h
+++ b/webrtc/modules/audio_coding/neteq4/neteq_impl.h
@@ -167,6 +167,10 @@
                                       int* current_memory_size_bytes,
                                       int* max_memory_size_bytes) const;
 
+  // Get sequence number and timestamp of the latest RTP.
+  // This method is to facilitate NACK.
+  virtual int DecodedRtpInfo(int* sequence_number, uint32_t* timestamp);
+
  private:
   static const int kOutputSizeMs = 10;
   static const int kMaxFrameSize = 2880;  // 60 ms @ 48 kHz.
@@ -318,6 +322,16 @@
   int decoder_error_code_;
   CriticalSectionWrapper* crit_sect_;
 
+  // These values are used by NACK module to estimate time-to-play of
+  // a missing packet. Occasionally, NetEq might decide to decode more
+  // than one packet. Therefore, these values store sequence number and
+  // timestamp of the first packet pulled from the packet buffer. In
+  // such cases, these values do not exactly represent the sequence number
+  // or timestamp associated with a 10ms audio pulled from NetEq. NACK
+  // module is designed to compensate for this.
+  int decoded_packet_sequence_number_;
+  uint32_t decoded_packet_timestamp_;
+
   DISALLOW_COPY_AND_ASSIGN(NetEqImpl);
 };