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

Add logs about duration of SDK initialization #23

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
File renamed without changes.
23 changes: 20 additions & 3 deletions lib/agora/agora_sink.ex → lib/agora/sink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Membrane.Agora.Sink do
"""
use Membrane.Sink

require Membrane.Logger
require Membrane.Pad, as: Pad

alias Membrane.Agora.Sink.Native
Expand Down Expand Up @@ -61,10 +62,26 @@ defmodule Membrane.Agora.Sink do
end

@impl true
def handle_setup(_ctx, state) do
{:ok, native_state} =
def handle_playing(_ctx, state) do
native_state =
try do
Native.create(state.app_id, state.token, state.channel_name, state.user_id)
start_time = Membrane.Time.os_time()

{:ok, native_state} =
Native.create(state.app_id, state.token, state.channel_name, state.user_id)

duration = Membrane.Time.os_time() - start_time
duration_ms = Membrane.Time.as_milliseconds(duration, :round)
Membrane.Logger.info("Agora SDK initialization took: #{duration_ms} ms")

if duration_ms > 500 do
Membrane.Logger.warning("""
Agora SDK initialization took #{duration_ms} ms which is longer than expected.
The initial demand made by this sink might be delayed.
""")
end

native_state
rescue
_e in UndefinedFunctionError ->
reraise(
Expand Down
File renamed without changes.
22 changes: 20 additions & 2 deletions lib/agora/agora_source.ex → lib/agora/source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defmodule Membrane.Agora.Source do
"""
use Membrane.Source

require Membrane.Logger

alias Membrane.Agora.Source.Native
alias Membrane.Buffer

Expand Down Expand Up @@ -62,9 +64,25 @@ defmodule Membrane.Agora.Source do

@impl true
def handle_playing(_ctx, state) do
{:ok, native_state} =
native_state =
try do
Native.create(state.app_id, state.token, state.channel_name, state.user_id, self())
start_time = Membrane.Time.os_time()

{:ok, native_state} =
Native.create(state.app_id, state.token, state.channel_name, state.user_id, self())

duration = Membrane.Time.os_time() - start_time
duration_ms = Membrane.Time.as_milliseconds(duration, :round)
Membrane.Logger.info("Agora SDK initialization took: #{duration_ms} ms")

if duration_ms > 500 do
Membrane.Logger.warning("""
Agora SDK initialization took #{duration_ms} ms which is longer than expected.
The initial demand made by this sink might be delayed.
""")
end

native_state
rescue
_e in UndefinedFunctionError ->
reraise(
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions test/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ defmodule Membrane.Agora.IntegrationTest do
custom_args: [audio: output_audio, video: output_video, framerate: framerate]
)

Process.sleep(1_000)

{:ok, _supervisor, sender_pipeline} =
Membrane.Testing.Pipeline.start_link(
module: SenderPipeline,
custom_args: [audio: input_audio, video: input_video, framerate: framerate]
)

assert_start_of_stream(receiver_pipeline, :video_sink, :input, 10_000)
assert_start_of_stream(receiver_pipeline, :video_sink, :input, 15_000)
assert_start_of_stream(receiver_pipeline, :audio_sink)

assert_end_of_stream(sender_pipeline, :sink, Pad.ref(:video, _), 30_000)
assert_end_of_stream(sender_pipeline, :sink, Pad.ref(:audio, _), 30_000)

Membrane.Pipeline.terminate(sender_pipeline)

assert_end_of_stream(receiver_pipeline, :video_sink, :input, 10_000)
assert_end_of_stream(receiver_pipeline, :video_sink, :input, 15_000)
assert_end_of_stream(receiver_pipeline, :audio_sink)

Membrane.Pipeline.terminate(receiver_pipeline)
Expand Down