Skip to content
Merged
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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions lib/ex_hls/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule ExHLS.Client do

use Bunch.Access

require ExHLS.Client.Utils, as: Utils
require Logger

alias __MODULE__.{Live, Utils, VOD}
Expand Down Expand Up @@ -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!([])

Expand Down
9 changes: 3 additions & 6 deletions lib/ex_hls/client/live/reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
19 changes: 17 additions & 2 deletions lib/ex_hls/client/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -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
Expand Down