Skip to content

Commit 304ef61

Browse files
committed
Timestamps guide
1 parent 756d2e3 commit 304ef61

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed
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.

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%{
22
"bunch": {:hex, :bunch, "1.6.1", "5393d827a64d5f846092703441ea50e65bc09f37fd8e320878f13e63d410aec7", [:mix], [], "hexpm", "286cc3add551628b30605efbe2fca4e38cc1bea89bcd0a1a7226920b3364fe4a"},
33
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
4-
"coerce": {:hex, :coerce, "1.0.1", "211c27386315dc2894ac11bc1f413a0e38505d808153367bd5c6e75a4003d096", [:mix], [], "hexpm", "b44a691700f7a1a15b4b7e2ff1fa30bebd669929ac8aa43cffe9e2f8bf051cf1"},
4+
"coerce": {:hex, :coerce, "1.0.2", "5ef791040c92baaa5dd344887563faaeac6e6742573a167493294f8af3672bbe", [:mix], [], "hexpm", "0b3451c729571234fdac478636c298e71d1f2ce1243abed5fa43fa3181b980eb"},
55
"credo": {:hex, :credo, "1.7.10", "6e64fe59be8da5e30a1b96273b247b5cf1cc9e336b5fd66302a64b25749ad44d", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "71fbc9a6b8be21d993deca85bf151df023a3097b01e09a2809d460348561d8cd"},
66
"dialyxir": {:hex, :dialyxir, "1.4.5", "ca1571ac18e0f88d4ab245f0b60fa31ff1b12cbae2b11bd25d207f865e8ae78a", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b0fb08bb8107c750db5c0b324fa2df5ceaa0f9307690ee3c1f6ba5b9eb5d35c3"},
77
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},

0 commit comments

Comments
 (0)