diff --git a/README.md b/README.md index 5938796..ce9187c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ The package can be installed by adding `ex_hls` to your list of dependencies in ```elixir def deps do [ - {:ex_hls, "~> 0.1.4"} + {:ex_hls, "~> 0.1.5"} ] end ``` @@ -109,6 +109,15 @@ To pop only single elements from the stream containing ExHLS Chunks, you can use Note: If the HLS playlist type is Live (not VoD), you can generate stream from single `ExHLS.Client` instance only once and only from the process, that created that `ExHLS.Client`. If you want to genereate more streams with Live HLS, you have to create a new `ExHLS.Client` each time. +### Debugging + +If you want to see more detailed logs about how `ex_hls` works, add the following line to the config file +of your application: + +```elixir +config :ex_hls, debug_verbose: true +``` + ## Copyright and License Copyright 2025, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=ex_hls) diff --git a/lib/ex_hls/client.ex b/lib/ex_hls/client.ex index 1f31390..ac94623 100644 --- a/lib/ex_hls/client.ex +++ b/lib/ex_hls/client.ex @@ -6,6 +6,7 @@ defmodule ExHLS.Client do use Bunch.Access + require ExHLS.Client.Utils, as: Utils require Logger alias __MODULE__.{Live, Utils, VOD} @@ -78,6 +79,11 @@ defmodule ExHLS.Client do root_playlist_raw_content = Utils.download_or_read_file!(url) + Utils.debug_verbose(""" + [ExHLS.Client] Downloaded root playlist from #{url}. Root playlist content: + #{root_playlist_raw_content} + """) + multivariant_playlist = root_playlist_raw_content |> ExM3U8.deserialize_multivariant_playlist!([]) diff --git a/lib/ex_hls/client/live/reader.ex b/lib/ex_hls/client/live/reader.ex index 99457a3..893c16b 100644 --- a/lib/ex_hls/client/live/reader.ex +++ b/lib/ex_hls/client/live/reader.ex @@ -3,11 +3,10 @@ defmodule ExHLS.Client.Live.Reader do use GenServer + require ExHLS.Client.Utils, as: Utils require Logger alias ExHLS.Client.Live.Forwarder - alias ExHLS.Client.Utils - alias ExM3U8.Tags.{MediaInit, Segment} @spec start_link(String.t(), Forwarder.t(), :ts | :cmaf | nil) :: {:ok, pid()} | {:error, any()} @@ -62,7 +61,7 @@ defmodule ExHLS.Client.Live.Reader do end defp check_media_playlist(state) do - Logger.debug("[ExHLS.Client] Checking media playlist at #{state.media_playlist_url}") + Utils.debug_verbose("[ExHLS.Client] Checking media playlist at #{state.media_playlist_url}") media_playlist = state.media_playlist_url @@ -224,12 +223,10 @@ defmodule ExHLS.Client.Live.Reader do _some_host -> segment.uri end - Logger.debug("[ExHLS.Client] Downloading segment: #{uri}") + Utils.debug_verbose("[ExHLS.Client] Downloading segment: #{uri}") segment_content = Utils.download_or_read_file!(uri) - state = maybe_resolve_demuxing_engine(segment.uri, state) - consume_segment_content(segment_content, state) end diff --git a/lib/ex_hls/client/utils.ex b/lib/ex_hls/client/utils.ex index 4908a7d..7522359 100644 --- a/lib/ex_hls/client/utils.ex +++ b/lib/ex_hls/client/utils.ex @@ -6,16 +6,31 @@ defmodule ExHLS.Client.Utils do alias ExHLS.DemuxingEngine alias Membrane.{AAC, H264, RemoteStream} + @debug_verbose Application.compile_env(:ex_hls, :debug_verbose, false) + + defmacro debug_verbose(message) do + if @debug_verbose do + quote do + require Logger + Logger.debug(unquote(message)) + end + else + quote do + :ok + end + end + end + @spec download_or_read_file!(String.t()) :: binary() def download_or_read_file!(uri_or_path) do case URI.parse(uri_or_path).host do nil -> :ok = await_until_file_exists!(uri_or_path) - Logger.debug("[ExHLS.Client] opening #{uri_or_path}") + debug_verbose("[ExHLS.Client] opening #{uri_or_path}") File.read!(uri_or_path) _host -> - Logger.debug("[ExHLS.Client] downloading #{uri_or_path}") + debug_verbose("[ExHLS.Client] downloading #{uri_or_path}") %{status: 200, body: body} = Req.get!(uri_or_path) body end diff --git a/mix.exs b/mix.exs index 05fc263..82725ec 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule ExHLS.Mixfile do use Mix.Project - @version "0.1.4" + @version "0.1.5" @github_url "https://github.com/membraneframework/ex_hls" def project do