-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d176a6
commit d287c95
Showing
5 changed files
with
112 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
defmodule Membrane.HLS.AACFiller do | ||
use Membrane.Filter | ||
|
||
def_input_pad(:input, | ||
accepted_format: Membrane.AAC | ||
) | ||
|
||
def_output_pad(:output, | ||
accepted_format: Membrane.RemoteStream | ||
) | ||
|
||
def_options( | ||
duration: [ | ||
spec: Membrane.Time.t() | ||
] | ||
) | ||
|
||
def handle_init(_ctx, opts) do | ||
{[], %{duration: opts.duration, format: nil, filled: false}} | ||
end | ||
|
||
def handle_stream_format(:input, format, _ctx, state) do | ||
{[forward: %Membrane.RemoteStream{content_format: Membrane.AAC}], %{state | format: format}} | ||
end | ||
|
||
def handle_buffer(:input, buffer, _ctx, state) do | ||
buffer = %{buffer | pts: nil, dts: nil} | ||
|
||
if state.filled do | ||
{[forward: buffer], state} | ||
else | ||
format = state.format | ||
|
||
silence_buffer = | ||
if Membrane.Time.as_milliseconds(state.duration, :round) > 0 do | ||
duration = | ||
Membrane.Time.as_seconds(state.duration) | ||
|> Ratio.to_float() | ||
|
||
{silence, 0} = | ||
System.cmd( | ||
"ffmpeg", | ||
~w(-f lavfi -i anullsrc=r=#{format.sample_rate} -ac #{format.channels} -t #{duration} -c:a aac -f adts -) | ||
) | ||
|
||
%Membrane.Buffer{ | ||
payload: silence | ||
} | ||
else | ||
nil | ||
end | ||
|
||
{[buffer: {:output, List.wrap(silence_buffer) ++ [buffer]}], %{state | filled: true}} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule Membrane.HLS.TextFiller do | ||
use Membrane.Filter | ||
|
||
def_input_pad(:input, | ||
accepted_format: Membrane.Text | ||
) | ||
|
||
def_output_pad(:output, | ||
accepted_format: Membrane.Text | ||
) | ||
|
||
def_options( | ||
from: [ | ||
spec: Membrane.Time.t() | ||
] | ||
) | ||
|
||
def handle_init(_ctx, opts) do | ||
{[], %{from: opts.from, filled: false}} | ||
end | ||
|
||
def handle_buffer(:input, buffer, _ctx, state) do | ||
if state.filled do | ||
{[forward: buffer], state} | ||
else | ||
Membrane.Logger.debug( | ||
"Generated empty text buffer with a duration of #{buffer.pts - state.from - Membrane.Time.millisecond()}" | ||
) | ||
|
||
silence_buffer = %Membrane.Buffer{ | ||
payload: "", | ||
pts: state.from, | ||
metadata: %{to: buffer.pts - Membrane.Time.millisecond()} | ||
} | ||
|
||
{[buffer: {:output, [silence_buffer, buffer]}], %{state | filled: true}} | ||
end | ||
end | ||
end |
40 changes: 0 additions & 40 deletions
40
lib/membrane/hls/text_filler.ex → lib/membrane/hls/shifter.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters