-
Notifications
You must be signed in to change notification settings - Fork 0
Adjust to mpeg_ts v3 API #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
9fe0311
1a3a369
a2d09cc
f8d5067
fc3160f
3211a4b
88d3264
853248a
c16156e
2ec02c9
8c48722
ca855f3
8965ae2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,8 +9,8 @@ defmodule ExHLS.DemuxingEngine.MPEGTS do | |||||||||||||||||||||||||
| alias Membrane.{AAC, H264, RemoteStream} | ||||||||||||||||||||||||||
| alias MPEG.TS.Demuxer | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @enforce_keys [:demuxer, :last_tden_tag] | ||||||||||||||||||||||||||
| defstruct @enforce_keys ++ [track_timestamps_data: %{}] | ||||||||||||||||||||||||||
| @enforce_keys [:demuxer] | ||||||||||||||||||||||||||
| defstruct @enforce_keys ++ [track_timestamps_data: %{}, last_tden_tag: nil, packets_map: %{}] | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # using it a boundary expressed in nanoseconds, instead of the usual 90kHz clock ticks, | ||||||||||||||||||||||||||
| # generates up to 1/10th of ms error per 26.5 hours of stream which is acceptable in | ||||||||||||||||||||||||||
|
|
@@ -19,7 +19,8 @@ defmodule ExHLS.DemuxingEngine.MPEGTS do | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @type t :: %__MODULE__{ | ||||||||||||||||||||||||||
| demuxer: Demuxer.t(), | ||||||||||||||||||||||||||
| last_tden_tag: String.t() | nil | ||||||||||||||||||||||||||
| last_tden_tag: String.t() | nil, | ||||||||||||||||||||||||||
| packets_map: %{(track_id :: non_neg_integer()) => MPEG.TS.Demuxer.Container.t()} | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @impl true | ||||||||||||||||||||||||||
|
|
@@ -28,31 +29,31 @@ defmodule ExHLS.DemuxingEngine.MPEGTS do | |||||||||||||||||||||||||
| # different demuxing engines | ||||||||||||||||||||||||||
| def new(_timestamp_offset_ms) do | ||||||||||||||||||||||||||
| demuxer = Demuxer.new() | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # we need to explicitly override that `waiting_random_access_indicator` as otherwise Demuxer | ||||||||||||||||||||||||||
| # discards all the input data | ||||||||||||||||||||||||||
| # TODO - figure out how to do it properly | ||||||||||||||||||||||||||
| demuxer = %{demuxer | waiting_random_access_indicator: false} | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| %__MODULE__{demuxer: demuxer, last_tden_tag: nil} | ||||||||||||||||||||||||||
| %__MODULE__{demuxer: demuxer} | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @impl true | ||||||||||||||||||||||||||
| def feed!(%__MODULE__{} = demuxing_engine, binary) do | ||||||||||||||||||||||||||
| demuxing_engine | ||||||||||||||||||||||||||
| |> Map.update!(:demuxer, &Demuxer.push_buffer(&1, binary)) | ||||||||||||||||||||||||||
| {new_packets, demuxer} = Demuxer.demux(demuxing_engine.demuxer, binary) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| packets_map = | ||||||||||||||||||||||||||
| Enum.reduce(new_packets, demuxing_engine.packets_map, fn new_packet, packets_map -> | ||||||||||||||||||||||||||
| Map.update(packets_map, new_packet.pid, [new_packet], &(&1 ++ [new_packet])) | ||||||||||||||||||||||||||
| end) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| %{demuxing_engine | demuxer: demuxer, packets_map: packets_map} | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @impl true | ||||||||||||||||||||||||||
| def get_tracks_info(%__MODULE__{} = demuxing_engine) do | ||||||||||||||||||||||||||
| with %{streams: streams} <- demuxing_engine.demuxer.pmt do | ||||||||||||||||||||||||||
| with %{streams: streams} <- demuxing_engine.demuxer do | ||||||||||||||||||||||||||
| tracks_info = | ||||||||||||||||||||||||||
| streams | ||||||||||||||||||||||||||
| |> Enum.flat_map(fn | ||||||||||||||||||||||||||
| {id, %{stream_type: :AAC}} -> | ||||||||||||||||||||||||||
| {id, %{stream_type: :AAC_ADTS}} -> | ||||||||||||||||||||||||||
| [{id, %RemoteStream{content_format: AAC}}] | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| {id, %{stream_type: :H264}} -> | ||||||||||||||||||||||||||
| {id, %{stream_type: :H264_AVC}} -> | ||||||||||||||||||||||||||
| [{id, %RemoteStream{content_format: H264}}] | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| {id, unsupported_stream_info} -> | ||||||||||||||||||||||||||
|
|
@@ -78,49 +79,60 @@ defmodule ExHLS.DemuxingEngine.MPEGTS do | |||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| defp take_packets(demuxing_engine, track_id) do | ||||||||||||||||||||||||||
| case Map.get(demuxing_engine.packets_map, track_id) do | ||||||||||||||||||||||||||
| [packet | rest] -> | ||||||||||||||||||||||||||
| demuxing_engine = put_in(demuxing_engine.packets_map[track_id], rest) | ||||||||||||||||||||||||||
| {[packet], demuxing_engine} | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| _other -> | ||||||||||||||||||||||||||
| {[], demuxing_engine} | ||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| case Map.get(demuxing_engine.packets_map, track_id) do | |
| [packet | rest] -> | |
| demuxing_engine = put_in(demuxing_engine.packets_map[track_id], rest) | |
| {[packet], demuxing_engine} | |
| _other -> | |
| {[], demuxing_engine} | |
| end | |
| get_and_update_in(demuxing_engine.packets_map[track_id], fn | |
| [packet | rest] -> {[packet], rest} | |
| other -> {[], other} | |
| end |
I'd also move this function below pop_chunk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can use get_and_update_in here, as if we were to call take_packets/2 for a track_id which is not yet in packets_map, it would add an empty entry under this track_id key.
(it might happen when track_id is resolved based on PMT, but no PES packet with given track_id has yet arrived)
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for me its unclear if maybe_read_tden_tag(demuxing_engine, packet.payload.pts)
- returns tden tag
- or sets it in
demuxing_engine.last_tden_tag - or both
because this function returns demuxing_engine as well as maybe_tden_tag. What about making it return only demuxing_engine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
QexThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea, done