Skip to content

Commit

Permalink
release v0.15 (#486)
Browse files Browse the repository at this point in the history
* release v0.15.0

* pin membrane rtsp version

* upgrade rtsp

* restore keep alive default value
  • Loading branch information
gBillal authored Oct 1, 2024
1 parent 0b9f397 commit 17d2abe
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 117 deletions.
1 change: 1 addition & 0 deletions apps/ex_nvr/lib/ex_nvr/bif/generator_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ defmodule ExNVR.BIF.GeneratorServer do
BifGenerator: could not generate a bif file.
Exception: #{inspect(exception)}
""")

{:noreply, state}
after
schedule_next_tick()
Expand Down
17 changes: 11 additions & 6 deletions apps/ex_nvr/lib/ex_nvr/disk_monitor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ defmodule ExNVR.DiskMonitor do
end

defp get_device_disk_usage(device) do
[{_mountpoint, total, avail, _percentage}] =
:disksup.get_disk_info(device.storage_config.address)

case total do
0 -> 0
total -> (1 - avail / total) * 100
if Kernel.function_exported?(:disksup, :get_disk_info, 1) do
case :disksup.get_disk_info(device.storage_config.address) do
[] -> 0
[{_mountpoint, 0, _avail, _percentage}] -> 0
[{_mountpoint, total, avail, _percentage}] -> (1 - avail / total) * 100
end
else
:disksup.get_disk_data()
|> Enum.map(fn {mountpoint, _total, usage} -> {to_string(mountpoint), usage} end)
|> Enum.find(&(elem(&1, 0) == device.storage_config.address), {nil, 0})
|> elem(1)
end
end
end
2 changes: 1 addition & 1 deletion apps/ex_nvr/lib/ex_nvr/model/device/storage_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule ExNVR.Model.Device.StorageConfig do
field :address, :string
# full drive
field :full_drive_threshold, :float, default: 95.0
field :full_drive_action, Ecto.Enum, values: [:nothing, :overwrite], default: :nothing
field :full_drive_action, Ecto.Enum, values: [:nothing, :overwrite], default: :overwrite
# Sub stream
field :record_sub_stream, Ecto.Enum, values: [:never, :always], default: :never
end
Expand Down
2 changes: 1 addition & 1 deletion apps/ex_nvr/lib/ex_nvr/onvif.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ defmodule ExNVR.Onvif do
@spec get_media_snapshot_uri!(url(), binary(), opts()) :: response()
@spec get_media_snapshot_uri!(url(), binary()) :: response()
def get_media_snapshot_uri!(url, profile_token, opts \\ []) do
body = %{"ProfileToken" => profile_token, "Protocol" => ""}
body = %{"ProfileToken" => profile_token}
result = call!(url, :get_snapshot_uri, body, opts)
get_in(result, [:get_snapshot_uri_response, :uri])
end
Expand Down
11 changes: 5 additions & 6 deletions 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.14.0",
version: "0.15.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down Expand Up @@ -47,12 +47,11 @@ defmodule ExNVR.MixProject do
{:swoosh, "~> 1.15"},
{:finch, "~> 0.13"},
{:membrane_file_plugin, "~> 0.17.0", override: true},
{:membrane_mp4_plugin, "~> 0.35.0", override: true},
{:membrane_http_adaptive_stream_plugin,
github: "gBillal/membrane_http_adaptive_stream_plugin", ref: "8f75c6b"},
{:membrane_h264_ffmpeg_plugin, "~> 0.31.0"},
{:membrane_mp4_plugin, "~> 0.35.0"},
{:membrane_http_adaptive_stream_plugin, "~> 0.18.0"},
{:membrane_h264_ffmpeg_plugin, "~> 0.32.0"},
{:membrane_h265_ffmpeg_plugin, "~> 0.4.0"},
{:membrane_ffmpeg_swscale_plugin, "~> 0.15.0"},
{:membrane_ffmpeg_swscale_plugin, "~> 0.16.0"},
{:membrane_realtimer_plugin, "~> 0.9.0"},
{:membrane_rtc_engine, "~> 0.22.0"},
{:membrane_rtc_engine_webrtc, "~> 0.8.0"},
Expand Down
14 changes: 8 additions & 6 deletions apps/ex_nvr_rtsp/lib/rtsp/source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,19 @@ defmodule ExNVR.RTSP.Source do
@impl true
def handle_setup(_ctx, state) do
state = ConnectionManager.establish_connection(state)

{:tcp, socket} = List.first(state.tracks).transport
:ok = Membrane.RTSP.transfer_socket_control(state.rtsp_session, self())
:ok = :inet.setopts(socket, buffer: @initial_recv_buffer)

{[start_timer: {:check_recbuf, Time.seconds(10)}], %{state | socket: socket}}
end

@impl true
def handle_playing(_ctx, state) do
Process.send_after(self(), :recv, 0)
{[], ConnectionManager.play(state)}

state = ConnectionManager.play(state)
:ok = Membrane.RTSP.transfer_socket_control(state.rtsp_session, self())
:ok = :inet.setopts(state.socket, buffer: @initial_recv_buffer, active: false)

{[], state}
end

@impl true
Expand Down Expand Up @@ -150,7 +151,8 @@ defmodule ExNVR.RTSP.Source do

@impl true
def handle_info(:keep_alive, _ctx, state) do
{[], ConnectionManager.keep_alive(state)}
Task.start(fn -> ConnectionManager.keep_alive(state) end)
{[], state}
end

@impl true
Expand Down
17 changes: 2 additions & 15 deletions apps/ex_nvr_rtsp/lib/rtsp/source/connection_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule ExNVR.RTSP.Source.ConnectionManager do
end

@spec play(State.t()) :: State.t()
def play(%State{transport: {:udp, _, _}} = state) do
def play(state) do
Membrane.Logger.debug("ConnectionManager: Setting RTSP on play mode")

case RTSP.play(state.rtsp_session) do
Expand All @@ -58,24 +58,11 @@ defmodule ExNVR.RTSP.Source.ConnectionManager do
end
end

def play(%State{transport: :tcp} = state) do
Membrane.Logger.debug("ConnectionManager: Setting RTSP on play mode")

RTSP.play_no_response(state.rtsp_session)
%{state | keep_alive_timer: start_keep_alive_timer(state)}
end

@spec keep_alive(State.t()) :: State.t()
def keep_alive(state) do
Membrane.Logger.debug("Send GET_PARAMETER to keep session alive")

case state.transport do
:tcp ->
RTSP.get_parameter_no_response(state.rtsp_session)

{:udp, _port_range_start, _port_range_end} ->
{:ok, %{status: 200}} = RTSP.get_parameter(state.rtsp_session)
end
{:ok, %{status: 200}} = RTSP.get_parameter(state.rtsp_session)

%{state | keep_alive_timer: start_keep_alive_timer(state)}
end
Expand Down
18 changes: 1 addition & 17 deletions apps/ex_nvr_rtsp/lib/rtsp/source/packet_splitter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,5 @@ defmodule ExNVR.RTSP.Source.PacketSplitter do
end

defp handle_rtsp_response(nil, _response), do: :ok

defp handle_rtsp_response(session, response) do
case RTSP.handle_response(session, response) do
{:ok, %RTSP.Response{status: 200}} ->
:ok

{:ok, %RTSP.Response{status: 401}} ->
RTSP.get_parameter_no_response(session)

{:error, reason} ->
raise """
An error occurred while parsing rtsp response
Response: #{inspect(response)}
Reason: #{inspect(reason)}
"""
end
end
defp handle_rtsp_response(session, response), do: RTSP.handle_response(session, response)
end
4 changes: 2 additions & 2 deletions apps/ex_nvr_rtsp/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ExNvrRtsp.MixProject do
def project do
[
app: :ex_nvr_rtsp,
version: "0.14.0",
version: "0.15.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down Expand Up @@ -33,7 +33,7 @@ defmodule ExNvrRtsp.MixProject do
{:membrane_core, "~> 1.1"},
{:ex_rtp, "~> 0.4.0"},
{:ex_rtcp, "~> 0.4.0"},
{:membrane_rtsp, "~> 0.7.0"},
{:membrane_rtsp, "~> 0.10.0"},
{:membrane_h26x_plugin, "~> 0.10.0"},
{:dialyxir, ">= 0.0.0", only: :dev, runtime: false},
{:credo, ">= 0.0.0", only: :dev, runtime: false},
Expand Down
32 changes: 16 additions & 16 deletions apps/ex_nvr_web/assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions apps/ex_nvr_web/assets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ex_nvr",
"version": "0.14.0",
"version": "0.15.0",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -11,7 +11,7 @@
"dependencies": {
"@jellyfish-dev/membrane-webrtc-js": "^0.6.3",
"d3": "^7.8.5",
"flowbite": "^2.3.0",
"hls.js": "^1.5.7"
"flowbite": "^2.5.1",
"hls.js": "^1.5.15"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ defmodule ExNVRWeb.CoreComponents do
Icons are provided by [heroicons](https://heroicons.com). See `icon/1` for usage.
"""
use Gettext, backend: ExNVRWeb.Gettext
use Phoenix.Component

alias Phoenix.LiveView.JS
import ExNVRWeb.Gettext

@doc """
Renders a modal.
Expand Down
2 changes: 1 addition & 1 deletion apps/ex_nvr_web/lib/ex_nvr_web/gettext.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ defmodule ExNVRWeb.Gettext do
See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage.
"""
use Gettext, otp_app: :ex_nvr_web
use Gettext.Backend, otp_app: :ex_nvr_web
end
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.14.0",
version: "0.15.0",
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.14.0
version: 0.15.0
servers:
- url: '{protocol}://{host}:{port}'
variables:
Expand Down
4 changes: 2 additions & 2 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ if config_env() == :prod do

config :ex_nvr_web, ExNVRWeb.Endpoint,
http: [
ip: {0, 0, 0, 0, 0, 0, 0, 0},
ip: {0, 0, 0, 0},
port: String.to_integer(System.get_env("EXNVR_HTTP_PORT") || "4000")
],
secret_key_base: secret_key_base,
Expand All @@ -108,7 +108,7 @@ if config_env() == :prod do
if enable_ssl do
config :ex_nvr_web, ExNVRWeb.Endpoint,
https: [
ip: {0, 0, 0, 0, 0, 0, 0, 0},
ip: {0, 0, 0, 0},
port: String.to_integer(System.get_env("EXNVR_HTTPS_PORT") || "443"),
cipher_suite: :compatible,
keyfile: System.get_env("EXNVR_SSL_KEY_PATH"),
Expand Down
Loading

0 comments on commit 17d2abe

Please sign in to comment.