-
Notifications
You must be signed in to change notification settings - Fork 4
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
Don't fail when unknown sample types are encountered #116
Changes from 4 commits
ea7e4e8
995f56a
680cd86
d9adf34
efe5e7a
9f8fbbb
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 |
---|---|---|
|
@@ -430,7 +430,10 @@ defmodule Membrane.MP4.Demuxer.ISOM do | |
end | ||
|
||
defp match_tracks_with_pads(ctx, state) do | ||
sample_tables = state.samples_info.sample_tables | ||
sample_tables = | ||
state.samples_info.sample_tables | ||
|> Enum.reject(fn {_track_id, table} -> table.sample_description == nil end) | ||
|> Enum.into(%{}) | ||
|
||
output_pads_data = | ||
ctx.pads | ||
|
@@ -464,6 +467,9 @@ defmodule Membrane.MP4.Demuxer.ISOM do | |
|
||
kind_to_tracks = | ||
sample_tables | ||
|> Enum.reject(fn {_track_id, table} -> | ||
table.sample_description == nil | ||
end) | ||
|> Enum.group_by( | ||
fn {_track_id, table} -> sample_description_to_kind(table.sample_description) end, | ||
fn {track_id, _table} -> track_id end | ||
|
@@ -500,6 +506,7 @@ defmodule Membrane.MP4.Demuxer.ISOM do | |
|
||
tracks_codecs = | ||
state.samples_info.sample_tables | ||
|> Enum.reject(fn {_track, table} -> table.sample_description == nil end) | ||
|> Enum.map(fn {_track, table} -> table.sample_description.__struct__ end) | ||
|
||
raise """ | ||
|
@@ -512,12 +519,14 @@ defmodule Membrane.MP4.Demuxer.ISOM do | |
defp sample_description_to_kind(%Membrane.H265{}), do: :video | ||
defp sample_description_to_kind(%Membrane.AAC{}), do: :audio | ||
defp sample_description_to_kind(%Membrane.Opus{}), do: :audio | ||
defp sample_description_to_kind(_other), do: :unknown | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the new case used anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If not, let's remove it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's indeed not used, I will remove it |
||
|
||
defp maybe_get_track_notifications(%{pads_linked_before_notification?: true}), do: [] | ||
|
||
defp maybe_get_track_notifications(%{pads_linked_before_notification?: false} = state) do | ||
new_tracks = | ||
state.samples_info.sample_tables | ||
|> Enum.reject(fn {_track_id, table} -> table.sample_description == nil end) | ||
|> Enum.map(fn {track_id, table} -> | ||
pad_id = state.track_to_pad_id[track_id] | ||
{pad_id, table.sample_description} | ||
|
@@ -528,6 +537,7 @@ defmodule Membrane.MP4.Demuxer.ISOM do | |
|
||
defp get_stream_format(state) do | ||
state.samples_info.sample_tables | ||
|> Enum.reject(fn {_track_id, table} -> table.sample_description == nil end) | ||
|> Enum.map(fn {track_id, table} -> | ||
pad_id = state.track_to_pad_id[track_id] | ||
{:stream_format, {Pad.ref(:output, pad_id), table.sample_description}} | ||
|
@@ -639,7 +649,14 @@ defmodule Membrane.MP4.Demuxer.ISOM do | |
defp all_pads_connected?(_ctx, %{samples_info: nil}), do: false | ||
|
||
defp all_pads_connected?(ctx, state) do | ||
tracks = 1..state.samples_info.tracks_number | ||
how_many_unsupported_tracks = | ||
state.samples_info.sample_tables | ||
|> Enum.filter(fn {_track_id, table} -> | ||
table.sample_description == nil | ||
end) | ||
|> length() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use https://hexdocs.pm/elixir/1.12/Enum.html#count/2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
tracks = 1..(state.samples_info.tracks_number - how_many_unsupported_tracks) | ||
|
||
pads = | ||
ctx.pads | ||
|
@@ -653,14 +670,19 @@ defmodule Membrane.MP4.Demuxer.ISOM do | |
|
||
defp flush_samples(state) do | ||
actions = | ||
Enum.map(state.buffered_samples, fn {track_id, track_samples} -> | ||
Enum.flat_map(state.buffered_samples, fn {track_id, track_samples} -> | ||
buffers = | ||
track_samples | ||
|> Enum.reverse() | ||
|> Enum.map(fn {buffer, ^track_id} -> buffer end) | ||
|
||
pad_id = state.track_to_pad_id[track_id] | ||
{:buffer, {Pad.ref(:output, pad_id), buffers}} | ||
|
||
if pad_id != nil do | ||
[buffer: {Pad.ref(:output, pad_id), buffers}] | ||
else | ||
[] | ||
end | ||
end) | ||
|
||
state = %{state | buffered_samples: %{}} | ||
|
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.
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.
And let's extract it to a separate function
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