Use muldiv crate for timestamp calculations

This commit is contained in:
Sebastian Dröge 2017-08-18 12:55:24 +03:00
parent d68effa8e4
commit 37a673ce24
4 changed files with 14 additions and 3 deletions

7
Cargo.lock generated
View file

@ -221,6 +221,7 @@ version = "0.1.0"
dependencies = [
"flavors 0.2.0 (git+https://github.com/rust-av/flavors.git)",
"gst-plugin 0.1.0",
"muldiv 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"nom 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -449,6 +450,11 @@ dependencies = [
"ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "muldiv"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "native-tls"
version = "0.1.4"
@ -895,6 +901,7 @@ dependencies = [
"checksum mime 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "153f98dde2b135dece079e5478ee400ae1bab13afa52d66590eacfc40e912435"
"checksum mio 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "dbd91d3bfbceb13897065e97b2ef177a09a438cb33612b2d371bf568819a9313"
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
"checksum muldiv 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1cbef5aa2e8cd82a18cc20e26434cc9843e1ef46e55bfabe5bddb022236c5b3e"
"checksum native-tls 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04b781c9134a954c84f0594b9ab3f5606abc516030388e8511887ef4c204a1e5"
"checksum net2 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "3a80f842784ef6c9a958b68b7516bc7e35883c614004dd94959a4dca1b716c09"
"checksum nom 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "06989cbd367e06f787a451f3bc67d8c3e0eaa10b461cc01152ffab24261a31b1"

View file

@ -11,6 +11,7 @@ gst-plugin = { path="../gst-plugin" }
slog = "2.0"
nom = "3.0"
flavors = {git = "https://github.com/rust-av/flavors.git"}
muldiv = "0.1"
[lib]
name = "gstrsflv"

View file

@ -28,6 +28,8 @@ use gst_plugin::bytes::*;
use slog::Logger;
use muldiv::*;
const AUDIO_STREAM_ID: u32 = 0;
const VIDEO_STREAM_ID: u32 = 1;
@ -736,7 +738,7 @@ impl FlvDemux {
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(Some((tag_header.timestamp as u64) * 1000 * 1000));
buffer.set_pts((tag_header.timestamp as u64).mul_div_floor(1000_000, 1));
}
trace!(
@ -911,7 +913,7 @@ impl FlvDemux {
if !is_keyframe {
buffer.set_flags(BUFFER_FLAG_DELTA_UNIT);
}
buffer.set_dts(Some((tag_header.timestamp as u64) * 1000 * 1000));
buffer.set_dts((tag_header.timestamp as u64).mul_div_floor(1000_000, 1));
// Prevent negative numbers
let pts = if cts < 0 && tag_header.timestamp < (-cts) as u32 {
@ -919,7 +921,7 @@ impl FlvDemux {
} else {
((tag_header.timestamp as i64) + (cts as i64)) as u64
};
buffer.set_pts(Some(pts * 1000 * 1000));
buffer.set_pts(pts.mul_div_floor(1000_000, 1));
}
trace!(

View file

@ -16,6 +16,7 @@ extern crate slog;
#[macro_use]
extern crate nom;
extern crate flavors;
extern crate muldiv;
use gst_plugin::plugin::*;
use gst_plugin::demuxer::*;