Skip to content

Commit

Permalink
address CR
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-hek committed Aug 22, 2024
1 parent cd30dd8 commit a83db58
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
29 changes: 19 additions & 10 deletions lib/membrane_mp4/muxer/isom.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,36 @@ defmodule Membrane.MP4.Muxer.ISOM do
@impl true
def handle_stream_format(
Pad.ref(:input, pad_ref) = pad,
%type{} = stream_format,
stream_format,
ctx,
state
) do
case ctx.pads[pad].stream_format do
case {ctx.pads[pad].stream_format, stream_format} do
# Handle receiving the first stream format on the given pad
nil ->
{nil, new_format} ->
update_in(state, [:pad_to_track, pad_ref], fn track_id ->
Track.new(track_id, stream_format, state.chunk_duration)
Track.new(track_id, new_format, state.chunk_duration)
end)

# Handle receiving a stream format of the same type
%^type{} ->
# If the stream format is identical or remains H264 AVC3 or H265,
# we can be reasonably sure that the stream can still be appended
# to the same MP4
{stream_format, stream_format} ->
state

# otherwise we can assume that output will be corrupted
previos_format ->
{%Membrane.H264{stream_structure: {:avc3, _dcr1}},
%Membrane.H264{stream_structure: {:avc3, _dcr2}}} ->
state

{%Membrane.H265{}, %Membrane.H265{}} ->
state

# Otherwise we can assume that output will be corrupted
{prev_format, new_format} ->
raise """
Unsupported stream_format change on pad #{inspect(pad_ref)}, \
previous format: #{inspect(previos_format)}
new format: #{inspect(stream_format)}
previous format: #{inspect(prev_format)}
new format: #{inspect(new_format)}
"""
end
|> then(&{[], &1})
Expand Down
27 changes: 27 additions & 0 deletions test/membrane_mp4/muxer/isom/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,31 @@ defmodule Membrane.MP4.Muxer.ISOM.IntegrationTest do
perform_test(pid, "two_tracks_fast_start")
end
end

describe "ctts table" do
test "should not be stored when dts and pts values are equal" do
prepare_test("video")

structure = [
child(:file, %Membrane.File.Source{location: "test/fixtures/in_video.h264"})
|> child(:parser, %Membrane.H264.Parser{
generate_best_effort_timestamps: %{framerate: {30, 1}, add_dts_offset: false},
output_stream_structure: :avc1
})
|> child(:muxer, %Membrane.MP4.Muxer.ISOM{chunk_duration: Time.seconds(1)})
|> child(:sink, %Membrane.File.Sink{location: out_path_for("video")})
]

pid = Pipeline.start_link_supervised!(spec: structure)

assert_end_of_stream(pid, :sink, :input)
refute_sink_buffer(pid, :sink, _buffer, 0)

assert :ok == Pipeline.terminate(pid)

assert {parsed_out, <<>>} = out_path_for("video") |> File.read!() |> Container.parse!()
assert Container.get_box(parsed_out, [:moov, :trak, :mdia, :minf, :stbl, :stts])
refute Container.get_box(parsed_out, [:moov, :trak, :mdia, :minf, :stbl, :ctts])
end
end
end

0 comments on commit a83db58

Please sign in to comment.