aom: Cast duration to int64_t before being added to pts

From e4b767c1d3a0417326ce1897312a668d05b0ba39 Mon Sep 17 00:00:00 2001
From: Wan-Teh Chang <[EMAIL REDACTED]>
Date: Wed, 13 Mar 2024 16:22:26 -0700
Subject: [PATCH] Cast duration to int64_t before being added to pts

Also tweak the unit tests.

Bug: aomedia:3510
Change-Id: Ifeccd94fde738455dec8c66faee359752e52b265
---
 av1/av1_cx_iface.c      | 2 +-
 test/encode_api_test.cc | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index ab0d677d4..2b6b1504e 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -3106,7 +3106,7 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
         aom_internal_error(&ppi->error, AOM_CODEC_INVALID_PARAM,
                            "relative pts + duration is too big");
       }
-      aom_codec_pts_t pts_end = ptsvol + duration;
+      aom_codec_pts_t pts_end = ptsvol + (int64_t)duration;
       if (pts_end > INT64_MAX / cpi_data.timestamp_ratio->num) {
         aom_internal_error(
             &ppi->error, AOM_CODEC_INVALID_PARAM,
diff --git a/test/encode_api_test.cc b/test/encode_api_test.cc
index a43fa8f49..a7d5b3aa3 100644
--- a/test/encode_api_test.cc
+++ b/test/encode_api_test.cc
@@ -579,9 +579,9 @@ TEST(EncodeAPI, PtsSmallerThanInitialPts) {
   ASSERT_NE(image, nullptr);
 
   // Encode frame.
-  ASSERT_EQ(aom_codec_encode(&enc, image, 11, 1, 0), AOM_CODEC_OK);
   ASSERT_EQ(aom_codec_encode(&enc, image, 12, 1, 0), AOM_CODEC_OK);
-  // pts (10) is smaller than the initial pts (11).
+  ASSERT_EQ(aom_codec_encode(&enc, image, 13, 1, 0), AOM_CODEC_OK);
+  // pts (10) is smaller than the initial pts (12).
   ASSERT_EQ(aom_codec_encode(&enc, image, 10, 1, 0), AOM_CODEC_INVALID_PARAM);
 
   // Free resources.
@@ -611,7 +611,7 @@ TEST(EncodeAPI, PtsOrDurationTooBig) {
 
   // Encode frame.
   ASSERT_EQ(aom_codec_encode(&enc, image, 0, 1, 0), AOM_CODEC_OK);
-  // pts is too big.
+  // pts, when converted to ticks, is too big.
   ASSERT_EQ(aom_codec_encode(&enc, image, INT64_MAX / 1000000 + 1, 1, 0),
             AOM_CODEC_INVALID_PARAM);
 #if ULONG_MAX > INT64_MAX