rtmp v0.2.0 Rtmp.Protocol.RtmpTime

Provides utilities to work with timestamps in an RTMP context.

RTMP timestamps are 32 bits (unsigned) integers and thus roll over every ~50 days. All adjacent timestamps are within 2^31 - 1 milliseconds of each other (e.g. 10000 comes after 4000000000, and 3000000000 comes before 4000000000).

Summary

Functions

Applies the specified delta to a timestamp

Gets the delta between an old RTMP timestamp and a new RTMP timestamp

Converts a timestamp into a valid RTMP timestamp (i.e. rolls it over if it’s too high or too low)

Types

rtmp_timestamp()
rtmp_timestamp() :: 0..2147483647

Functions

apply_delta(timestamp, delta)

Applies the specified delta to a timestamp

Examples

iex> Rtmp.Protocol.RtmpTime.apply_delta(1000, 500) 1500

iex> Rtmp.Protocol.RtmpTime.apply_delta(1000, -500) 500

iex> Rtmp.Protocol.RtmpTime.apply_delta(1000, -2000) 4294966296

iex> Rtmp.Protocol.RtmpTime.apply_delta(4294966296, 2000) 1000

get_delta(previous_timestamp, new_timestamp)

Gets the delta between an old RTMP timestamp and a new RTMP timestamp

Examples

iex> Rtmp.Protocol.RtmpTime.get_delta(4000000000, 4000001000) 1000

iex> Rtmp.Protocol.RtmpTime.get_delta(4000000000, 10000) 294977296

iex> Rtmp.Protocol.RtmpTime.get_delta(4000000000, 3000000000) -1000000000

to_rtmp_timestamp(timestamp)

Converts a timestamp into a valid RTMP timestamp (i.e. rolls it over if it’s too high or too low)

Examples

iex> Rtmp.Protocol.RtmpTime.to_rtmp_timestamp(1000) 1000

iex> Rtmp.Protocol.RtmpTime.to_rtmp_timestamp(-1000) 4294966296

iex> Rtmp.Protocol.RtmpTime.to_rtmp_timestamp(4294968296) 1000