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

Support Packed Audio #33

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

dmorn
Copy link

@dmorn dmorn commented Oct 3, 2023

As discussed with @mat-hek, before merging this one we should consider
removing the ID3 parsing code and instead use a library, as there is
code duplication between here and the mp3 decoder.

Right now tests are passing, but

  • only ID3v4 tags are supported
  • only PRIV frames are actually parsed, the rest is skipped (which might be fine)

Only ID3v4 tags are supported and only the PRIV
frames, which are the ones used for synchronization.
Don't ask me why, but this is working correctly
Comment on lines +215 to +216
ns = Membrane.Time.nanoseconds(round(secs * 1_000_000_000))
{id, ns}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ns = Membrane.Time.nanoseconds(round(secs * 1_000_000_000))
{id, ns}
time = round(secs * Membrane.Time.second()))
{id, time}

end

defp parse_id3v4_tag(<<"ID3", version::binary-size(2), _rest::binary>>) do
raise "Unsupported ID3 header version #{inspect(version)}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just skip the header in this case?

{tags, payload} = parse_id3v4_tags(buffer.payload, [])

state =
if state.start_pts == nil do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems it's already checked in update_start_pts

Comment on lines +151 to +158
defp update_start_pts(state, tags) do
start_pts =
Enum.find_value(tags, fn {id, val} ->
if(id == "com.apple.streaming.transportStreamTimestamp", do: val, else: nil)
end)

if start_pts != nil, do: %{state | start_pts: start_pts}, else: state
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defp update_start_pts(state, tags) do
start_pts =
Enum.find_value(tags, fn {id, val} ->
if(id == "com.apple.streaming.transportStreamTimestamp", do: val, else: nil)
end)
if start_pts != nil, do: %{state | start_pts: start_pts}, else: state
end
defp update_start_pts(%{start_pts: nil} = state, tags) do
start_pts =
Enum.find_value(tags, fn {id, val} ->
if id == "com.apple.streaming.transportStreamTimestamp", do: val
end)
%{state | start_pts: start_pts}
end

if start_pts != nil, do: %{state | start_pts: start_pts}, else: state
end

defp correct_pts(buffer, nil), do: %Buffer{buffer | pts: Ratio.to_float(buffer.pts) |> round()}
Copy link
Member

@mat-hek mat-hek Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTS and DTS in buffers aren't ratios anymore, they're Membrane.Time.t (integers underneath)

Comment on lines +108 to +116
actions =
Enum.map(output, fn
{:buffer, buffer} ->
value = correct_pts(buffer, state.start_pts)
{:buffer, {:output, value}}

{action, value} ->
{action, {:output, value}}
end)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's pass already corrected timestamp to ADTS.parse_adts instead

defp correct_pts(buffer, start_pts),
do: %Buffer{buffer | pts: Ratio.add(buffer.pts, start_pts) |> Ratio.to_float() |> round()}

defp parse_id3v4_tags(data, acc) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move all this ID3 parsing to a separate module

max_bit_rate: max_bit_rate
max_bit_rate: max_bit_rate,
# For id3 handling
start_pts: nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
start_pts: nil
pts_offset: nil

@mat-hek mat-hek requested review from bblaszkow06 and removed request for bblaszkow06 October 4, 2023 09:45
@mat-hek
Copy link
Member

mat-hek commented Jan 30, 2024

Hi @dmorn, any update on this?

@dmorn
Copy link
Author

dmorn commented Feb 7, 2024

Hi @mat-hek! Unfortunately not!

@mat-hek
Copy link
Member

mat-hek commented Feb 7, 2024

@dmorn got it, but is that something you still need?

@dmorn
Copy link
Author

dmorn commented Feb 14, 2024

Hi @mat-hek, right now no! Thanks!

@dmorn
Copy link
Author

dmorn commented Feb 14, 2024

... we're very close though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants