Skip to content

Commit

Permalink
Fix a bug with samples from only one track being flushed once the las…
Browse files Browse the repository at this point in the history
…t pad is connected in ISOM demuxer (#91)
  • Loading branch information
varsill authored Sep 26, 2023
1 parent 1eeb5d2 commit 9afa671
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The package can be installed by adding `membrane_mp4_plugin` to your list of dep
```elixir
defp deps do
[
{:membrane_mp4_plugin, "~> 0.30.0"}
{:membrane_mp4_plugin, "~> 0.30.1"}
]
end
```
Expand Down
22 changes: 13 additions & 9 deletions lib/membrane_mp4/demuxer/isom.ex
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,12 @@ defmodule Membrane.MP4.Demuxer.ISOM do
raise "All tracks have corresponding pad already connected"
end

def handle_pad_added(Pad.ref(:output, track_id), ctx, state) do
def handle_pad_added(Pad.ref(:output, _track_id), ctx, state) do
all_pads_connected? = all_pads_connected?(ctx, state)

{actions, state} =
if all_pads_connected? do
{buffer_actions, state} = flush_samples(state, track_id)
{buffer_actions, state} = flush_samples(state)
maybe_stream_format = if state.samples_info != nil, do: get_stream_format(state), else: []
maybe_eos = if state.end_of_stream?, do: get_end_of_stream_actions(ctx), else: []

Expand Down Expand Up @@ -460,15 +460,19 @@ defmodule Membrane.MP4.Demuxer.ISOM do
Range.size(tracks) == length(pads)
end

defp flush_samples(state, track_id) do
buffers =
Map.get(state.buffered_samples, track_id, [])
|> Enum.reverse()
|> Enum.map(fn {buffer, ^track_id} -> buffer end)
defp flush_samples(state) do
actions =
Enum.map(state.buffered_samples, fn {track_id, track_samples} ->
buffers =
track_samples
|> Enum.reverse()
|> Enum.map(fn {buffer, ^track_id} -> buffer end)

actions = [buffer: {Pad.ref(:output, track_id), buffers}]
{:buffer, {Pad.ref(:output, track_id), buffers}}
end)

{actions, put_in(state, [:buffered_samples, track_id], [])}
state = %{state | buffered_samples: %{}}
{actions, state}
end

defp get_end_of_stream_actions(ctx) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Membrane.MP4.Plugin.MixProject do
use Mix.Project

@version "0.30.0"
@version "0.30.1"
@github_url "https://github.com/membraneframework/membrane_mp4_plugin"

def project do
Expand Down

0 comments on commit 9afa671

Please sign in to comment.