Creating a test helper class TimestampJumpRtpGenerator

This class provides a way to test with an RTP sequence that make an
arbitrary jump in the timestamp series.

R=tina.legrand@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@7236 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/modules/audio_coding/neteq/tools/rtp_generator.cc b/modules/audio_coding/neteq/tools/rtp_generator.cc
index 17ac209..db9988d 100644
--- a/modules/audio_coding/neteq/tools/rtp_generator.cc
+++ b/modules/audio_coding/neteq/tools/rtp_generator.cc
@@ -44,5 +44,19 @@
   }
 }
 
+uint32_t TimestampJumpRtpGenerator::GetRtpHeader(uint8_t payload_type,
+                                                 size_t payload_length_samples,
+                                                 WebRtcRTPHeader* rtp_header) {
+  uint32_t ret = RtpGenerator::GetRtpHeader(
+      payload_type, payload_length_samples, rtp_header);
+  if (timestamp_ - static_cast<uint32_t>(payload_length_samples) <=
+          jump_from_timestamp_ &&
+      timestamp_ > jump_from_timestamp_) {
+    // We just moved across the |jump_from_timestamp_| timestamp. Do the jump.
+    timestamp_ = jump_to_timestamp_;
+  }
+  return ret;
+}
+
 }  // namespace test
 }  // namespace webrtc
diff --git a/modules/audio_coding/neteq/tools/rtp_generator.h b/modules/audio_coding/neteq/tools/rtp_generator.h
index d3824c8..2280436 100644
--- a/modules/audio_coding/neteq/tools/rtp_generator.h
+++ b/modules/audio_coding/neteq/tools/rtp_generator.h
@@ -34,24 +34,50 @@
         drift_factor_(0.0) {
   }
 
+  virtual ~RtpGenerator() {}
+
   // Writes the next RTP header to |rtp_header|, which will be of type
   // |payload_type|. Returns the send time for this packet (in ms). The value of
   // |payload_length_samples| determines the send time for the next packet.
-  uint32_t GetRtpHeader(uint8_t payload_type, size_t payload_length_samples,
-                        WebRtcRTPHeader* rtp_header);
+  virtual uint32_t GetRtpHeader(uint8_t payload_type,
+                                size_t payload_length_samples,
+                                WebRtcRTPHeader* rtp_header);
 
   void set_drift_factor(double factor);
 
- private:
+ protected:
   uint16_t seq_number_;
   uint32_t timestamp_;
   uint32_t next_send_time_ms_;
   const uint32_t ssrc_;
   const int samples_per_ms_;
   double drift_factor_;
+
+ private:
   DISALLOW_COPY_AND_ASSIGN(RtpGenerator);
 };
 
+class TimestampJumpRtpGenerator : public RtpGenerator {
+ public:
+  TimestampJumpRtpGenerator(int samples_per_ms,
+                            uint16_t start_seq_number,
+                            uint32_t start_timestamp,
+                            uint32_t jump_from_timestamp,
+                            uint32_t jump_to_timestamp)
+      : RtpGenerator(samples_per_ms, start_seq_number, start_timestamp),
+        jump_from_timestamp_(jump_from_timestamp),
+        jump_to_timestamp_(jump_to_timestamp) {}
+
+  uint32_t GetRtpHeader(uint8_t payload_type,
+                        size_t payload_length_samples,
+                        WebRtcRTPHeader* rtp_header) OVERRIDE;
+
+ private:
+  uint32_t jump_from_timestamp_;
+  uint32_t jump_to_timestamp_;
+  DISALLOW_COPY_AND_ASSIGN(TimestampJumpRtpGenerator);
+};
+
 }  // namespace test
 }  // namespace webrtc
 #endif  // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_GENERATOR_H_