Skip to content

Commit

Permalink
Merge pull request #63 from membraneframework/migration-to-buffer-wit…
Browse files Browse the repository at this point in the history
…h-pts-dts

Migration to buffer with pts dts
  • Loading branch information
andpodob authored Dec 6, 2021
2 parents 1a524bf + 5ff7867 commit 0ece034
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
5 changes: 2 additions & 3 deletions lib/membrane/rtp/jitter_buffer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,8 @@ defmodule Membrane.RTP.JitterBuffer do
:current -> timestamp_base
end

timestamp = Ratio.div((rtp_timestamp - timestamp_base) * Time.second(), state.clock_rate)
buffer = Bunch.Struct.put_in(buffer, [:metadata, :timestamp], timestamp)
action = {:buffer, {:output, buffer}}
timestamp = div((rtp_timestamp - timestamp_base) * Time.second(), state.clock_rate)
action = {:buffer, {:output, %{buffer | pts: timestamp}}}
state = %{state | timestamp_base: timestamp_base, previous_timestamp: rtp_timestamp}
{action, state}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/membrane/rtp/outbound_packet_tracker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ defmodule Membrane.RTP.OutboundPacketTracker do
align_to: state.alignment
)

buffer = %Buffer{payload: payload, metadata: metadata}
buffer = %Buffer{buffer | payload: payload, metadata: metadata}

{{:ok, buffer: {:output, buffer}}, state}
end
Expand Down
13 changes: 7 additions & 6 deletions lib/membrane/rtp/serializer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Membrane.RTP.Serializer do
"""
use Membrane.Filter

alias Membrane.{Buffer, RTP, RemoteStream}
alias Membrane.{RTP, RemoteStream}

@max_seq_num 65_535
@max_timestamp 0xFFFFFFFF
Expand Down Expand Up @@ -77,11 +77,11 @@ defmodule Membrane.RTP.Serializer do
end

@impl true
def handle_process(:input, %Buffer{payload: payload, metadata: metadata}, _ctx, state) do
{rtp_metadata, metadata} = Map.pop(metadata, :rtp, %{})
def handle_process(:input, buffer, _ctx, state) do
{rtp_metadata, metadata} = Map.pop(buffer.metadata, :rtp, %{})

rtp_offset =
metadata.timestamp
buffer.pts
|> Ratio.mult(state.clock_rate)
|> Membrane.Time.to_seconds()

Expand All @@ -100,8 +100,9 @@ defmodule Membrane.RTP.Serializer do
}

buffer = %Membrane.Buffer{
metadata: Map.put(metadata, :rtp, header),
payload: payload
buffer
| metadata: Map.put(metadata, :rtp, header),
payload: buffer.payload
}

{{:ok, buffer: {:output, buffer}}, state}
Expand Down
9 changes: 5 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ defmodule Membrane.RTP.Plugin.MixProject do

defp deps do
[
{:membrane_core, "~> 0.8.0"},
{:membrane_core, "~> 0.8.0", override: true},
{:membrane_rtp_format, "~> 0.3.1"},
{:membrane_rtp_h264_plugin, "~> 0.6.0", only: :test},
{:membrane_rtp_h264_plugin, "~> 0.7.1"},
{:membrane_rtp_mpegaudio_plugin, "~> 0.7.0", only: :test},
{:membrane_h264_ffmpeg_plugin, "~> 0.14.0", only: :test},
{:membrane_element_pcap, github: "membraneframework/membrane-element-pcap", only: :test},
{:membrane_h264_ffmpeg_plugin, "~> 0.15.0", only: :test},
{:membrane_element_pcap,
github: "membraneframework/membrane-element-pcap", tag: "v0.4.0", only: :test},
{:membrane_element_udp, "~> 0.6.0", only: :test},
{:membrane_hackney_plugin, "~> 0.6.0", only: :test},
{:ex_libsrtp, "~> 0.3.0", optional: true},
Expand Down
14 changes: 7 additions & 7 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"coerce": {:hex, :coerce, "1.0.1", "211c27386315dc2894ac11bc1f413a0e38505d808153367bd5c6e75a4003d096", [:mix], [], "hexpm", "b44a691700f7a1a15b4b7e2ff1fa30bebd669929ac8aa43cffe9e2f8bf051cf1"},
"credo": {:hex, :credo, "1.6.1", "7dc76dcdb764a4316c1596804c48eada9fff44bd4b733a91ccbf0c0f368be61e", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "698607fb5993720c7e93d2d8e76f2175bba024de964e160e2f7151ef3ab82ac5"},
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.17", "6f3c7e94170377ba45241d394389e800fb15adc5de51d0a3cd52ae766aafd63f", [:mix], [], "hexpm", "f93ac89c9feca61c165b264b5837bf82344d13bebc634cd575cb711e2e342023"},
"earmark_parser": {:hex, :earmark_parser, "1.4.18", "e1b2be73eb08a49fb032a0208bf647380682374a725dfb5b9e510def8397f6f2", [:mix], [], "hexpm", "114a0e85ec3cf9e04b811009e73c206394ffecfcc313e0b346de0d557774ee97"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.26.0", "1922164bac0b18b02f84d6f69cab1b93bc3e870e2ad18d5dacb50a9e06b542a3", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2775d66e494a9a48355db7867478ffd997864c61c65a47d31c4949459281c78d"},
"ex_libsrtp": {:hex, :ex_libsrtp, "0.3.0", "964cf207fc44357b9ef103ade78e99004de70df8ee44bf1c8f6a18051d0d3667", [:mix], [{:bunch, "~> 1.3", [hex: :bunch, repo: "hexpm", optional: false]}, {:unifex, "~> 0.7.0", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "62c2c40f6481ee670c864d26aa6496ad851c9b694bbd5367111bc93f3be2e44a"},
"ex_pcap": {:git, "https://github.com/membraneframework/expcap.git", "07c5bfa25280ea6a28d022d3a206ececf9b9913a", []},
"excoveralls": {:hex, :excoveralls, "0.14.4", "295498f1ae47bdc6dce59af9a585c381e1aefc63298d48172efaaa90c3d251db", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e3ab02f2df4c1c7a519728a6f0a747e71d7d6e846020aae338173619217931c1"},
"expcap": {:git, "https://github.com/Hajto/expcap.git", "0608702b7e22c1f3206014dbe3e1d313cdc17f1c", []},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
Expand All @@ -23,17 +24,16 @@
"makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"membrane_caps_audio_mpeg": {:hex, :membrane_caps_audio_mpeg, "0.2.0", "9cf9a63f03e25b31cf31445325aa68e60a07d36ee1e759caa1422fa45df49367", [:mix], [], "hexpm", "f7a80e4841d46164c148be880932ac7425329f4bcc32eb36ad2e47eafe5f23e4"},
"membrane_caps_video_h264": {:hex, :membrane_caps_video_h264, "0.2.0", "ecfe3a83b5e349b6ca56980c543cf3bf2275ccfb7769126fe62798f08fd7a2fe", [:mix], [], "hexpm", "36e447b8fd42cd4ad79bfa4dbf2e7f2ff3a9030c0ffa85ba951d21868a36376b"},
"membrane_caps_video_h264": {:hex, :membrane_caps_video_h264, "0.2.1", "8545074299dc48d8afe106b0be1ecf3097e997f0e9f32557f435c123135050fe", [:mix], [], "hexpm", "a14a8dcd0d2c205ca2cdbe5c7df24ec3e34a027e1caf511a71ca4c72b371b200"},
"membrane_caps_video_raw": {:hex, :membrane_caps_video_raw, "0.1.0", "6aa751b0c338ea6672540b7ec7ad2be0d23bad931b8a8776757da9b279070a3b", [:mix], [], "hexpm", "3f60d65189bd9e3b0ab77e0ebf2e0c1b04d0fd6f67c546fc1d54d9958c362ce4"},
"membrane_common_c": {:hex, :membrane_common_c, "0.10.0", "9db4fa2964039e3cd518b333d27ff7492c9746cd6af5ebd217a101fa1bccbdcd", [:mix], [{:membrane_core, "~> 0.8.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:shmex, "~> 0.4.0", [hex: :shmex, repo: "hexpm", optional: false]}, {:unifex, "~> 0.7.0", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "bb3312f1b25d9eae3226b49d1f0daa6535fe38ac72d8742adb60b4373c531566"},
"membrane_core": {:hex, :membrane_core, "0.8.1", "33df0e4c76c05a2be57042893b05516886462baefdf95b7299e4d2f5db32dea3", [:mix], [{:bunch, "~> 1.3", [hex: :bunch, repo: "hexpm", optional: false]}, {:qex, "~> 0.3", [hex: :qex, repo: "hexpm", optional: false]}, {:ratio, "~> 2.0", [hex: :ratio, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5574db35f08de1e95648f9c3acce38c5f318216c5a5ae5e3f253f7edad8fdc1b"},
"membrane_element_pcap": {:git, "https://github.com/membraneframework/membrane-element-pcap.git", "e9d9c47bc1ed5897250e6463710b4adb0d76c4ed", []},
"membrane_element_pcap": {:git, "https://github.com/membraneframework/membrane-element-pcap.git", "e9d9c47bc1ed5897250e6463710b4adb0d76c4ed", [tag: "v0.4.0"]},
"membrane_element_udp": {:hex, :membrane_element_udp, "0.6.0", "40174620e1e08bb5e0dc498f5b2aec16eb29b6995127e43d1bd45599147d5d9f", [:mix], [{:membrane_core, "~> 0.8.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:mockery, "~> 2.3.0", [hex: :mockery, repo: "hexpm", optional: false]}], "hexpm", "ce7d9941ec65628bba7e8da4d7414cd588fc40c794a2a609859c85cdfcc718e2"},
"membrane_h264_ffmpeg_plugin": {:hex, :membrane_h264_ffmpeg_plugin, "0.14.0", "fed05b26a060e320a17b6c3d268893348406aa4898f630369aab8cfe599a0025", [:mix], [{:bunch, "~> 1.3.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:membrane_caps_video_h264, "~> 0.2.0", [hex: :membrane_caps_video_h264, repo: "hexpm", optional: false]}, {:membrane_caps_video_raw, "~> 0.1.0", [hex: :membrane_caps_video_raw, repo: "hexpm", optional: false]}, {:membrane_common_c, "~> 0.10.0", [hex: :membrane_common_c, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.8.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:ratio, "~> 2.4.0", [hex: :ratio, repo: "hexpm", optional: false]}, {:unifex, "~> 0.7.0", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "8df09cbc7dde5d24639401984ec5a238c401b62bead61ef38945a2ea6e477da7"},
"membrane_h264_ffmpeg_plugin": {:hex, :membrane_h264_ffmpeg_plugin, "0.15.0", "717ffd95f250eedf4f5f66c0f2850a88b6682c54b3a0dfa32181478a4da19fda", [:mix], [{:bunch, "~> 1.3.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:membrane_caps_video_h264, "~> 0.2.0", [hex: :membrane_caps_video_h264, repo: "hexpm", optional: false]}, {:membrane_caps_video_raw, "~> 0.1.0", [hex: :membrane_caps_video_raw, repo: "hexpm", optional: false]}, {:membrane_common_c, "~> 0.10.0", [hex: :membrane_common_c, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.8.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:ratio, "~> 2.4.0", [hex: :ratio, repo: "hexpm", optional: false]}, {:unifex, "~> 0.7.0", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "e70a81e6af2cfbb211893003c2ea92053ad90cebda4392a42363de719cf5ed89"},
"membrane_hackney_plugin": {:hex, :membrane_hackney_plugin, "0.6.0", "f495da8f8d3b55035d2f38a58b18d16549df9453b2e88517def98a6414a34655", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.8.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:mockery, "~> 2.3", [hex: :mockery, repo: "hexpm", optional: false]}], "hexpm", "16beedf5f829b5ba7aa6850882cbd209b1ff5be2dd84ef675c2a31f48837962f"},
"membrane_remote_stream_format": {:hex, :membrane_remote_stream_format, "0.1.0", "2cedb6facd7f4185fc7c0e7c83a614483f98ef1e8d36f4ed5939c935768eb95d", [:mix], [], "hexpm", "a6f01aa51766fe92e12d2cb720176fcff6d2485fb563e51002d8f9ef9a90f894"},
"membrane_rtp_format": {:hex, :membrane_rtp_format, "0.3.1", "c6920fdb58660d90e264fcf3587dbb5994fb2f3643d234e59608c82598baebaf", [:mix], [], "hexpm", "d225f453715d165ded7dcb287c45360a4d653ac4a6d3ff70b4acdd244c45fa84"},
"membrane_rtp_h264_plugin": {:hex, :membrane_rtp_h264_plugin, "0.6.0", "d07249f4866696f9e11f7e214d36b91f9d3ccfdfdfae52da3b990976ed5ecaf5", [:mix], [{:bunch, "~> 1.2", [hex: :bunch, repo: "hexpm", optional: false]}, {:membrane_caps_video_h264, "~> 0.2.0", [hex: :membrane_caps_video_h264, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.8.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:membrane_rtp_format, "~> 0.3.0", [hex: :membrane_rtp_format, repo: "hexpm", optional: false]}], "hexpm", "a99297e9167fa5c82a89546ebae2082d45ba32aad0253376061a5226fda4cd48"},
"membrane_rtp_h264_plugin": {:hex, :membrane_rtp_h264_plugin, "0.7.1", "3efcdd7f00b0e417ceb2fa4bfe2f101dd1f0f62f0e185c3a350817b9ea981a57", [:mix], [{:bunch, "~> 1.2", [hex: :bunch, repo: "hexpm", optional: false]}, {:membrane_caps_video_h264, "~> 0.2.0", [hex: :membrane_caps_video_h264, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.8.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:membrane_rtp_format, "~> 0.3.0", [hex: :membrane_rtp_format, repo: "hexpm", optional: false]}], "hexpm", "ad8d94410d7f464a0cdb26cd8b3f2fd58e619837308cef9ae2e1838a50cb2589"},
"membrane_rtp_mpegaudio_plugin": {:hex, :membrane_rtp_mpegaudio_plugin, "0.7.0", "bb26b4bd290166af311061eda37188502303887e1cd775183bdf73c6ceba8db7", [:mix], [{:membrane_caps_audio_mpeg, "~> 0.2.0", [hex: :membrane_caps_audio_mpeg, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.8.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:membrane_rtp_format, "~> 0.3.0", [hex: :membrane_rtp_format, repo: "hexpm", optional: false]}], "hexpm", "e9ee553a2bab1704acc68b36cd7d099e2126634c6cd9fc7eb5634c656947d3b7"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
Expand All @@ -42,7 +42,7 @@
"numbers": {:hex, :numbers, "5.2.4", "f123d5bb7f6acc366f8f445e10a32bd403c8469bdbce8ce049e1f0972b607080", [:mix], [{:coerce, "~> 1.0", [hex: :coerce, repo: "hexpm", optional: false]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "eeccf5c61d5f4922198395bf87a465b6f980b8b862dd22d28198c5e6fab38582"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"pkt": {:git, "https://github.com/msantos/pkt.git", "8c826b25098b06db8c24805fb1da2d65c14abe06", []},
"qex": {:hex, :qex, "0.5.0", "5a3a9becf67d4006377c4c247ffdaaa8ae5b3634a0caadb788dc24d6125068f4", [:mix], [], "hexpm", "4ad6f6421163cd8204509a119a5c9813cbb969cfb8d802a9dc49b968bffbac2a"},
"qex": {:hex, :qex, "0.5.1", "0d82c0f008551d24fffb99d97f8299afcb8ea9cf99582b770bd004ed5af63fd6", [:mix], [], "hexpm", "935a39fdaf2445834b95951456559e9dc2063d0a055742c558a99987b38d6bab"},
"ratio": {:hex, :ratio, "2.4.2", "c8518f3536d49b1b00d88dd20d49f8b11abb7819638093314a6348139f14f9f9", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:numbers, "~> 5.2.0", [hex: :numbers, repo: "hexpm", optional: false]}], "hexpm", "441ef6f73172a3503de65ccf1769030997b0d533b1039422f1e5e0e0b4cbf89e"},
"secure_random": {:hex, :secure_random, "0.5.1", "c5532b37c89d175c328f5196a0c2a5680b15ebce3e654da37129a9fe40ebf51b", [:mix], [], "hexpm", "1b9754f15e3940a143baafd19da12293f100044df69ea12db5d72878312ae6ab"},
"shmex": {:hex, :shmex, "0.4.0", "8a074a984bbd45808d80eddfa0f037d7dfb4d4046e6566cd40adf41e13decf74", [:mix], [{:bunch_native, "~> 0.4.0", [hex: :bunch_native, repo: "hexpm", optional: false]}, {:bundlex, "~> 0.5.0", [hex: :bundlex, repo: "hexpm", optional: false]}], "hexpm", "1018c4eca1db5352ed4dec4813e1ee212b98fc851e1edd302906892538bbfaa8"},
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/rtp/jitter_buffer/pipeline_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ defmodule Membrane.RTP.JitterBuffer.PipelineTest do
pipeline,
:sink,
%Membrane.Buffer{
metadata: %{rtp: %{sequence_number: ^seq_num, timestamp: _}},
metadata: %{rtp: %{sequence_number: ^seq_num}},
payload: _
},
timeout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Membrane.RTP.JitterBuffer.TimestampsCalculationTest do
end

defp buffers_timestamps(buffers) do
Enum.map(buffers, & &1.metadata.timestamp)
Enum.map(buffers, & &1.pts)
end

defp process_and_receive_buffer_timestamps(buffers, state) do
Expand Down
5 changes: 2 additions & 3 deletions test/support/buffer_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ defmodule Membrane.RTP.BufferFactory do

%Buffer{
payload: <<0, 255>>,
pts: div(seq_num_offset * @timestamp_increment * Membrane.Time.second(), @clock_rate),
metadata: %{
rtp: %{
timestamp: seq_num_offset * @timestamp_increment,
sequence_number: seq_num
},
timestamp:
Ratio.div(seq_num_offset * @timestamp_increment * Membrane.Time.second(), @clock_rate)
}
}
}
end
Expand Down

0 comments on commit 0ece034

Please sign in to comment.