Skip to content

Commit 0bd2ef7

Browse files
committed
Timestamps guide
1 parent 3262a1e commit 0bd2ef7

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Timestamps - the stamps in time
2+
3+
In a nutshell, timestamps determine when a given event occurred in time. For
4+
example when you take a photo with your phone, the exact time and date the photo
5+
is taken is recorded - it's a timestamp. When dealing with media we also need a
6+
way to tell when different things need to happen. In Membrane we use two most
7+
common types of timestamps:
8+
9+
* PTS (Presentation Time Stamp) - determines when the media should be
10+
displayed.
11+
* DTS (Decoding Time Stamp) - information for the decoder when the media should
12+
be decoded.
13+
14+
## Time in Membrane
15+
16+
We know that timestamps represent the time of occurrence of an event, but these
17+
concepts are pretty abstract. We need to somehow represent them in the context
18+
of our framework. To represent time - durations, latencies, timestamps, - we
19+
use terms of type `t:Membrane.Time.t/0`:
20+
21+
* To create a term representing some amount of time, we use
22+
`Membrane.Time.<unit>/0` and `Membrane.Time.<unit>s/1` functions. For example to
23+
create a term representing three seconds, we call `Membrane.Time.seconds(3)`.
24+
* To read the amount of time represented, we can use `Membrane.Time.as_<unit>/2`
25+
functions. For example, to get an amount of milliseconds represented by a time,
26+
we call `Membrane.Time.as_milliseconds(some_time)`
27+
28+
## Carriers of timestamps
29+
30+
We now have a way to represent timestamps, but to be useful they have to refer
31+
to something, an event of some sort. As you probably know, media streams in
32+
Membrane are sent between elements packaged in
33+
[Buffers](`t:Membrane.Buffer.t/0`). As we can see in the specification, a buffer
34+
is a struct with 4 fields:
35+
36+
* `:payload` - data contained in the buffer
37+
* `:pts` and `:dts` - timestamps assigned to the buffer
38+
* `:metadata` - metadata describing the contents of the buffer
39+
40+
Buffers often correspond to some units which the stream is composed of, for
41+
example video frames in raw video streams or RTP packets in RTP streams.
42+
These units are the perfect fits to have timestamps assigned to them - and in
43+
most cases they do. For example, a PTS assigned to a buffer containing a
44+
raw video frame determines then the frame should be displayed.

0 commit comments

Comments
 (0)