Fix IvfFileReader to support different time scales
Bug: b/237998511 Change-Id: I8e7766b38cfe19b2fb58853c9614e4d32ea34715 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/285087 Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38737}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
bc43fe3a50
commit
c7fc01269e
@ -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> IvfFileReader::Create(FileWrapper file) {
|
||||
@ -77,13 +80,9 @@ bool IvfFileReader::Reset() {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t time_scale = ByteReader<uint32_t>::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<uint32_t>::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<EncodedImage> IvfFileReader::NextFrame() {
|
||||
}
|
||||
|
||||
EncodedImage image;
|
||||
if (using_capture_timestamps_) {
|
||||
image.capture_time_ms_ = current_timestamp;
|
||||
image.SetTimestamp(static_cast<uint32_t>(90 * current_timestamp));
|
||||
} else {
|
||||
image.SetTimestamp(static_cast<uint32_t>(current_timestamp));
|
||||
}
|
||||
image.capture_time_ms_ = current_timestamp;
|
||||
image.SetTimestamp(
|
||||
static_cast<uint32_t>(current_timestamp * kRtpClockRateHz / time_scale_));
|
||||
image.SetEncodedData(payload);
|
||||
image.SetSpatialIndex(static_cast<int>(layer_sizes.size()) - 1);
|
||||
for (size_t i = 0; i < layer_sizes.size(); ++i) {
|
||||
|
||||
@ -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<FrameHeader> next_frame_header_;
|
||||
|
||||
Reference in New Issue
Block a user