Module rml_rtmp::time[][src]

Expand description

RTMP timestamps are 32 byte unsigned integers representing the number of milliseconds from and unknown epoch.

Since it’s meant to support streams that can go on forever, timestamps have to work with time values that overflow and underflow a 32 bit integer but still be able to do comparisons. To support this the RtmpTimestamp struct was created to abstract away the calculations and make it easy to work with RTMP timestamps.

According to the RTMP spec, times are adjacent if they are within 231 - 1 milliseconds of each other.

Examples

Basic arithmetic and comparison support:

use rml_rtmp::time::RtmpTimestamp;

let time1 = RtmpTimestamp::new(10);
let time2 = RtmpTimestamp::new(20);
let time3 = RtmpTimestamp::new(30);
let mut time4 = RtmpTimestamp::new(10);

assert!(time1 < time2);
assert_eq!(time3, time1 + time2);
assert_eq!(time2, time1 + 10);

time4.set(30);
assert_eq!(RtmpTimestamp::new(30), time4);

Value Wrapping support:

use rml_rtmp::time::RtmpTimestamp;

let time1 = RtmpTimestamp::new(10000);
let time2 = RtmpTimestamp::new(4000000000);
let time3 = RtmpTimestamp::new(3000000000);

assert!(time1 > time2);
assert!(time3 < time2);

For ease of use, a RtmpTimestamp can be directly compared to u32s:

use rml_rtmp::time::RtmpTimestamp;

let time = RtmpTimestamp::new(50);

assert!(time < 60);
assert!(time > 20);
assert!(time == 50);

Structs

RtmpTimestamp

The representation of a RTMP timestamp