Use correct presentationTimestampUs for VideoFrames in old encoder.

In MediaCodecVideoEncoder, VideoFrame timestamp was used as a
presentation timestamp. With this change timestamp maintained in C++
code is used instead. This matches the behaviour with old frame
callbacks.

Bug: b/72832862
Change-Id: I1f0543ebe837ccac22c83a81a81f3ea128e2a866
Reviewed-on: https://webrtc-review.googlesource.com/47381
Reviewed-by: Anders Carlsson <andersc@webrtc.org>
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21872}
diff --git a/sdk/android/api/org/webrtc/MediaCodecVideoEncoder.java b/sdk/android/api/org/webrtc/MediaCodecVideoEncoder.java
index 2e8b802..bcb4b98 100644
--- a/sdk/android/api/org/webrtc/MediaCodecVideoEncoder.java
+++ b/sdk/android/api/org/webrtc/MediaCodecVideoEncoder.java
@@ -634,10 +634,10 @@
    * Encodes a new style VideoFrame. |bufferIndex| is -1 if we are not encoding in surface mode.
    */
   @CalledByNativeUnchecked
-  boolean encodeFrame(long nativeEncoder, boolean isKeyframe, VideoFrame frame, int bufferIndex) {
+  boolean encodeFrame(long nativeEncoder, boolean isKeyframe, VideoFrame frame, int bufferIndex,
+      long presentationTimestampUs) {
     checkOnMediaCodecThread();
     try {
-      long presentationTimestampUs = TimeUnit.NANOSECONDS.toMicros(frame.getTimestampNs());
       checkKeyFrameRequired(isKeyframe, presentationTimestampUs);
 
       VideoFrame.Buffer buffer = frame.getBuffer();
@@ -649,7 +649,7 @@
         GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
         VideoFrameDrawer.drawTexture(drawer, textureBuffer, new Matrix() /* renderMatrix */, width,
             height, 0 /* viewportX */, 0 /* viewportY */, width, height);
-        eglBase.swapBuffers(frame.getTimestampNs());
+        eglBase.swapBuffers(TimeUnit.MICROSECONDS.toNanos(presentationTimestampUs));
       } else {
         VideoFrame.I420Buffer i420Buffer = buffer.toI420();
         final int chromaHeight = (height + 1) / 2;
diff --git a/sdk/android/src/jni/androidmediaencoder.cc b/sdk/android/src/jni/androidmediaencoder.cc
index 8908b8e..f71b508 100644
--- a/sdk/android/src/jni/androidmediaencoder.cc
+++ b/sdk/android/src/jni/androidmediaencoder.cc
@@ -897,7 +897,7 @@
                                              int input_buffer_index) {
   bool encode_status = Java_MediaCodecVideoEncoder_encodeFrame(
       jni, j_media_codec_video_encoder_, jlongFromPointer(this), key_frame,
-      frame, input_buffer_index);
+      frame, input_buffer_index, current_timestamp_us_);
   if (CheckException(jni)) {
     ALOGE << "Exception in encode frame.";
     ProcessHWError(true /* reset_if_fallback_unavailable */);