diff --git a/modules/video_coding/utility/ivf_file_reader.cc b/modules/video_coding/utility/ivf_file_reader.cc index 85d1fa00d7..13092b5e24 100644 --- a/modules/video_coding/utility/ivf_file_reader.cc +++ b/modules/video_coding/utility/ivf_file_reader.cc @@ -30,6 +30,9 @@ constexpr uint8_t kVp9Header[kCodecTypeBytesCount] = {'V', 'P', '9', '0'}; constexpr uint8_t kAv1Header[kCodecTypeBytesCount] = {'A', 'V', '0', '1'}; constexpr uint8_t kH264Header[kCodecTypeBytesCount] = {'H', '2', '6', '4'}; +// RTP standard required 90kHz clock rate. +constexpr int32_t kRtpClockRateHz = 90000; + } // namespace std::unique_ptr IvfFileReader::Create(FileWrapper file) { @@ -77,13 +80,9 @@ bool IvfFileReader::Reset() { return false; } - uint32_t time_scale = ByteReader::ReadLittleEndian(&ivf_header[16]); - if (time_scale == 1000) { - using_capture_timestamps_ = true; - } else if (time_scale == 90000) { - using_capture_timestamps_ = false; - } else { - RTC_LOG(LS_ERROR) << "Invalid IVF header: Unknown time scale"; + time_scale_ = ByteReader::ReadLittleEndian(&ivf_header[16]); + if (time_scale_ == 0) { + RTC_LOG(LS_ERROR) << "Invalid IVF header: time scale can't be 0"; return false; } @@ -106,8 +105,7 @@ bool IvfFileReader::Reset() { const char* codec_name = CodecTypeToPayloadString(codec_type_); RTC_LOG(LS_INFO) << "Opened IVF file with codec data of type " << codec_name << " at resolution " << width_ << " x " << height_ - << ", using " << (using_capture_timestamps_ ? "1" : "90") - << "kHz clock resolution."; + << ", using " << time_scale_ << "Hz clock resolution."; return true; } @@ -157,12 +155,9 @@ absl::optional IvfFileReader::NextFrame() { } EncodedImage image; - if (using_capture_timestamps_) { - image.capture_time_ms_ = current_timestamp; - image.SetTimestamp(static_cast(90 * current_timestamp)); - } else { - image.SetTimestamp(static_cast(current_timestamp)); - } + image.capture_time_ms_ = current_timestamp; + image.SetTimestamp( + static_cast(current_timestamp * kRtpClockRateHz / time_scale_)); image.SetEncodedData(payload); image.SetSpatialIndex(static_cast(layer_sizes.size()) - 1); for (size_t i = 0; i < layer_sizes.size(); ++i) { diff --git a/modules/video_coding/utility/ivf_file_reader.h b/modules/video_coding/utility/ivf_file_reader.h index 75f2e3ac8c..db4fc25575 100644 --- a/modules/video_coding/utility/ivf_file_reader.h +++ b/modules/video_coding/utility/ivf_file_reader.h @@ -70,7 +70,7 @@ class IvfFileReader { size_t num_read_frames_; uint16_t width_; uint16_t height_; - bool using_capture_timestamps_; + uint32_t time_scale_; FileWrapper file_; absl::optional next_frame_header_;