Skip to content

Commit

Permalink
move main pipeline initialization code to handle setup (#325)
Browse files Browse the repository at this point in the history
* Move initialization of main pipeline to handle setup

* Update version
  • Loading branch information
gBillal authored Jan 17, 2024
1 parent 29ecb64 commit bb57859
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
53 changes: 28 additions & 25 deletions apps/ex_nvr/lib/ex_nvr/pipelines/main.ex
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ defmodule ExNVR.Pipelines.Main do
rtc_engine: options[:rtc_engine]
}

{[], state}
end

@impl true
def handle_setup(_ctx, %{device: device} = state) do
common_spec = [
child(:hls_sink, %Output.HLS{
location: Path.join(Utils.hls_dir(device.id), "live"),
Expand All @@ -143,40 +148,38 @@ defmodule ExNVR.Pipelines.Main do
child(:webrtc, %Output.WebRTC{stream_id: device.id})
]

if device.type == :ip do
{stream_uri, sub_stream_uri} = Device.streams(device)
actions =
if device.type == :ip do
{stream_uri, sub_stream_uri} = Device.streams(device)

Membrane.Logger.info("""
Start streaming for
main stream: #{stream_uri}
sub stream: #{sub_stream_uri}
""")
Membrane.Logger.info("""
Start streaming for
main stream: #{stream_uri}
sub stream: #{sub_stream_uri}
""")

spec =
common_spec ++
[child(:rtsp_source, %Source.RTSP{stream_uri: stream_uri})] ++
if sub_stream_uri,
do: build_sub_stream_spec(device, sub_stream_uri),
else: []
spec =
common_spec ++
[child(:rtsp_source, %Source.RTSP{stream_uri: stream_uri})] ++
if sub_stream_uri,
do: build_sub_stream_spec(device, sub_stream_uri),
else: []

{[spec: spec], state}
else
Membrane.Logger.info("""
Start streaming for
location: #{Device.file_location(device)}
""")
[spec: spec]
else
Membrane.Logger.info("""
Start streaming for
location: #{Device.file_location(device)}
""")

{[spec: common_spec ++ build_file_stream_spec(device)], state}
end
end
[spec: common_spec ++ build_file_stream_spec(device)]
end

@impl true
def handle_setup(_ctx, state) do
# Set device state and make last active run inactive
# may happens on application crash
device_state = if state.device.type == :file, do: :recording, else: :failed
Recordings.deactivate_runs(state.device)
{[], maybe_update_device_and_report(state, device_state)}
{actions, maybe_update_device_and_report(state, device_state)}
end

@impl true
Expand Down
2 changes: 1 addition & 1 deletion apps/ex_nvr/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ExNVR.MixProject do
def project do
[
app: :ex_nvr,
version: "0.9.0",
version: "0.9.1",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down
2 changes: 1 addition & 1 deletion apps/ex_nvr_web/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ExNVRWeb.MixProject do
def project do
[
app: :ex_nvr_web,
version: "0.9.0",
version: "0.9.1",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down
2 changes: 1 addition & 1 deletion apps/ex_nvr_web/priv/static/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.0
info:
title: ExNVR API
description: Manage ExNVR via API endpoints
version: 0.9.0
version: 0.9.1
servers:
- url: '{protocol}://{host}:{port}'
variables:
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 ExNVR.Umbrella.MixProject do
use Mix.Project

@version "0.9.0"
@version "0.9.1"

def project do
[
Expand Down

0 comments on commit bb57859

Please sign in to comment.