Skip to content
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

Get current segment number from segment filename when updating HLS storage sequences #134

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions lib/algora/pipeline/storage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ defmodule Algora.Pipeline.Storage do

state =
process_contents(parent_id, name, contents, metadata, ctx, state)
|> update_sequence_numbers(sequence_number, manifest_name)
|> update_sequence_numbers(sequence_number, name, manifest_name)
|> add_partial(name, ctx, partial_name, contents, manifest_name)

{:ok, state}
Expand Down Expand Up @@ -257,20 +257,17 @@ defmodule Algora.Pipeline.Storage do
defp update_sequence_numbers(
%{sequences: sequences} = state,
new_partial_sn,
segment_name,
manifest_name
) do
{segment_sn, partial_sn} = Map.get(sequences, manifest_name, {0, 0})
new_segment? = new_partial_sn < partial_sn
sequence = if new_segment? do
{ segment_sn + 1, new_partial_sn }
else
{ segment_sn, new_partial_sn }
end
{segment_sn, _partial_sn} = Map.get(sequences, manifest_name, {0, 0})
new_segment_sn = get_segment_number_from_name(segment_name)
state = sequences
|> Map.put(manifest_name, sequence)
|> Map.put(manifest_name, {new_segment_sn, new_partial_sn})
|> then(&Map.put(state, :sequences, &1))
# If there is a new segment we want to remove partials that are too old from ets
if new_segment? do

# If there is a new segment we want to remove partials that are too old
if new_segment_sn > segment_sn do
remove_partials(state, manifest_name)
else
state
Expand Down Expand Up @@ -381,4 +378,13 @@ defmodule Algora.Pipeline.Storage do
defp process_contents(_parent_id, _name, _contents, _metadata, _ctx, state) do
state
end

# audio_segment_0_audio_master.m4s
defp get_segment_number_from_name(filename) do
filename
|> String.split("_")
|> Enum.drop(2)
|> List.first()
|> String.to_integer()
end
end