Skip to content

Commit

Permalink
Adjust to core 1.0 API
Browse files Browse the repository at this point in the history
  • Loading branch information
FelonEkonom committed Nov 13, 2023
1 parent b4707b1 commit 107b693
Show file tree
Hide file tree
Showing 22 changed files with 114 additions and 94 deletions.
12 changes: 7 additions & 5 deletions lib/membrane_mp4/demuxer/isom.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Membrane.MP4.Demuxer.ISOM do
accepted_format:
%RemoteStream{type: :bytestream, content_format: content_format}
when content_format in [nil, MP4],
flow_control: :manual,
demand_unit: :buffers

def_output_pad :output,
Expand All @@ -34,7 +35,8 @@ defmodule Membrane.MP4.Demuxer.ISOM do
},
%Membrane.Opus{self_delimiting?: false}
),
availability: :on_request
availability: :on_request,
flow_control: :manual

def_options optimize_for_non_fast_start?: [
default: false,
Expand Down Expand Up @@ -141,7 +143,7 @@ defmodule Membrane.MP4.Demuxer.ISOM do
{[], state}
end

def handle_process(
def handle_buffer(
:input,
_buffer,
_ctx,
Expand All @@ -154,7 +156,7 @@ defmodule Membrane.MP4.Demuxer.ISOM do
end

@impl true
def handle_process(
def handle_buffer(
:input,
buffer,
ctx,
Expand All @@ -175,7 +177,7 @@ defmodule Membrane.MP4.Demuxer.ISOM do
{buffers ++ redemands, %{state | samples_info: samples_info, partial: rest}}
end

def handle_process(
def handle_buffer(
:input,
buffer,
_ctx,
Expand All @@ -190,7 +192,7 @@ defmodule Membrane.MP4.Demuxer.ISOM do
{[], %{state | samples_info: samples_info, partial: rest}}
end

def handle_process(:input, buffer, ctx, state) do
def handle_buffer(:input, buffer, ctx, state) do
{new_boxes, rest} = Container.parse!(state.partial <> buffer.payload)

state = %{
Expand Down
2 changes: 1 addition & 1 deletion lib/membrane_mp4/demuxer/isom/samples_info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ defmodule Membrane.MP4.Demuxer.ISOM.SamplesInfo do
track_id: track_id,
sample_composition_offset: sample_composition_offset
}) do
use Ratio
use Numbers, overload_operators: true
timescale = samples_info.timescales[track_id]

{dts, pts} =
Expand Down
2 changes: 1 addition & 1 deletion lib/membrane_mp4/helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Membrane.MP4.Helper do
"""
@spec timescalify(Ratio.t() | integer, Ratio.t() | integer) :: integer
def timescalify(time, timescale) do
use Ratio
use Numbers, overload_operators: true
Ratio.trunc(time * timescale / Time.second() + 0.5)
end
end
15 changes: 8 additions & 7 deletions lib/membrane_mp4/muxer/cmaf.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ defmodule Membrane.MP4.Muxer.CMAF do

def_input_pad :input,
availability: :on_request,
flow_control: :manual,
demand_unit: :buffers,
accepted_format:
any_of(
Expand All @@ -109,7 +110,7 @@ defmodule Membrane.MP4.Muxer.CMAF do
%H264{stream_structure: structure, alignment: :au} when H264.is_avc(structure)
)

def_output_pad :output, accepted_format: Membrane.CMAF.Track
def_output_pad :output, accepted_format: Membrane.CMAF.Track, flow_control: :manual

def_options segment_min_duration: [
spec: Membrane.Time.t(),
Expand Down Expand Up @@ -271,8 +272,8 @@ defmodule Membrane.MP4.Muxer.CMAF do
end

@impl true
def handle_process(Pad.ref(:input, _id) = pad, sample, ctx, state) do
use Ratio, comparison: true
def handle_buffer(Pad.ref(:input, _id) = pad, sample, ctx, state) do
use Numbers, overload_operators: true, comparison: true

# In case DTS is not set, use PTS. This is the case for audio tracks or H264 originated
# from an RTP stream. ISO base media file format specification uses DTS for calculating
Expand Down Expand Up @@ -389,7 +390,7 @@ defmodule Membrane.MP4.Muxer.CMAF do
end

defp generate_segment(acc, ctx, state) do
use Ratio, comparison: true
use Numbers, overload_operators: true, comparison: true

tracks_data =
acc
Expand Down Expand Up @@ -510,7 +511,7 @@ defmodule Membrane.MP4.Muxer.CMAF do

# Update the duration of the awaiting sample and insert the current sample into the queue
defp process_buffer_awaiting_duration(state, pad, sample) do
use Ratio
use Numbers, overload_operators: true

prev_sample = state.pad_to_track_data[pad].buffer_awaiting_duration

Expand Down Expand Up @@ -550,8 +551,8 @@ defmodule Membrane.MP4.Muxer.CMAF do
if chunk_target_duration < @min_chunk_duration do
raise """
Chunk target duration is smaller than minimal duration.
Duration: #{Membrane.Time.round_to_milliseconds(chunk_target_duration)}
Minumum: #{Membrane.Time.round_to_milliseconds(@min_chunk_duration)}
Duration: #{Membrane.Time.as_milliseconds(chunk_target_duration, :round)}
Minumum: #{Membrane.Time.as_milliseconds(@min_chunk_duration, :round)}
"""
end

Expand Down
4 changes: 2 additions & 2 deletions lib/membrane_mp4/muxer/cmaf/track_samples_queue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ defmodule Membrane.MP4.Muxer.CMAF.TrackSamplesQueue do
"""
@spec force_collect(t(), Membrane.Time.t()) :: {[Membrane.Buffer.t()], t()}
def force_collect(%__MODULE__{collectable?: false} = queue, max_duration) do
use Ratio, comparison: true
use Numbers, overload_operators: true, comparison: true

{excess_samples, target_samples} =
Enum.split_while(queue.target_samples, &(&1.dts > max_duration))
Enum.split_while(queue.target_samples, &Ratio.gt?(&1.dts, max_duration))

result = Enum.reverse(target_samples)

Expand Down
7 changes: 5 additions & 2 deletions lib/membrane_mp4/muxer/isom.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule Membrane.MP4.Muxer.ISOM do
@mdat_header_size 8

def_input_pad :input,
flow_control: :manual,
demand_unit: :buffers,
accepted_format:
any_of(
Expand All @@ -28,7 +29,9 @@ defmodule Membrane.MP4.Muxer.ISOM do
),
availability: :on_request

def_output_pad :output, accepted_format: %RemoteStream{type: :bytestream, content_format: MP4}
def_output_pad :output,
accepted_format: %RemoteStream{type: :bytestream, content_format: MP4},
flow_control: :manual

def_options fast_start: [
spec: boolean(),
Expand Down Expand Up @@ -130,7 +133,7 @@ defmodule Membrane.MP4.Muxer.ISOM do
end

@impl true
def handle_process(Pad.ref(:input, pad_ref), buffer, _ctx, state) do
def handle_buffer(Pad.ref(:input, pad_ref), buffer, _ctx, state) do
# In case DTS is not set, use PTS. This is the case for audio tracks or H264 originated
# from an RTP stream. ISO base media file format specification uses DTS for calculating
# decoding deltas, and so is the implementation of sample table in this plugin.
Expand Down
4 changes: 2 additions & 2 deletions lib/membrane_mp4/track.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule Membrane.MP4.Track do

@spec completed?(t()) :: boolean()
def completed?(%__MODULE__{} = track) do
use Ratio, comparision: true
use Numbers, overload_operators: true

last_dts = track.sample_table.last_dts
bound = track.chunk_dts_overbound
Expand Down Expand Up @@ -143,7 +143,7 @@ defmodule Membrane.MP4.Track do
end

defp put_durations(track, movie_timescale) do
use Ratio
use Numbers, overload_operators: true

duration =
track.sample_table.decoding_deltas
Expand Down
4 changes: 2 additions & 2 deletions lib/membrane_mp4/track/sample_table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule Membrane.MP4.Track.SampleTable do
def chunk_duration(%{chunk_first_dts: nil}), do: 0

def chunk_duration(sample_table) do
use Ratio
use Numbers, overload_operators: true
sample_table.last_dts - sample_table.chunk_first_dts
end

Expand Down Expand Up @@ -129,7 +129,7 @@ defmodule Membrane.MP4.Track.SampleTable do

defp update_decoding_deltas(sample_table, %Buffer{dts: dts}) do
Map.update!(sample_table, :decoding_deltas, fn previous_deltas ->
use Ratio
use Numbers, overload_operators: true
new_delta = dts - sample_table.last_dts

case previous_deltas do
Expand Down
7 changes: 3 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ defmodule Membrane.MP4.Plugin.MixProject do
{:membrane_h265_format, "~> 0.2.0"},
{:membrane_opus_format, "~> 0.3.0"},
{:membrane_file_plugin, "~> 0.16.0"},
{:membrane_h264_plugin, "~> 0.7.0"},
{:membrane_h264_plugin, "~> 0.9.0"},
{:bunch, "~> 1.5"},
{:membrane_h265_plugin, "~> 0.3.1", only: :test},
{:membrane_aac_plugin, "~> 0.16.0", only: :test},
{:membrane_opus_plugin, "~> 0.17.0", only: :test},
{:membrane_aac_plugin, "~> 0.18.0", only: :test},
{:membrane_opus_plugin, "~> 0.19.0", only: :test},
{:membrane_stream_plugin, "~> 0.4.0", only: :test},
{:membrane_fake_plugin, "~> 0.11.0", only: :test},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
Expand Down
Loading

0 comments on commit 107b693

Please sign in to comment.