From ad93be3d5a46973f32663cae68e41ac6dee5b9e3 Mon Sep 17 00:00:00 2001 From: "feliks.pobiedzinski@swmansion.com" Date: Wed, 9 Jul 2025 17:06:05 +0200 Subject: [PATCH 1/2] Allow H26x in remote stream --- README.md | 2 +- lib/transcoder/video.ex | 26 ++++++++++++++++++++++---- mix.exs | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 54510b5..d06ddde 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ The package can be installed by adding `membrane_transcoder_plugin` to your list ```elixir def deps do [ - {:membrane_transcoder_plugin, "~> 0.3.1"} + {:membrane_transcoder_plugin, "~> 0.3.2"} ] end ``` diff --git a/lib/transcoder/video.ex b/lib/transcoder/video.ex index 4b7a64f..afdb112 100644 --- a/lib/transcoder/video.ex +++ b/lib/transcoder/video.ex @@ -8,10 +8,13 @@ defmodule Membrane.Transcoder.Video do @type video_stream_format :: VP8.t() | VP9.t() | H264.t() | H265.t() | RawVideo.t() defguard is_video_format(format) - when is_struct(format) and - (format.__struct__ in [VP8, VP9, H264, H265, RawVideo] or - (format.__struct__ == RemoteStream and format.content_format in [VP8, VP9] and - format.type == :packetized)) + when (is_struct(format) and + (format.__struct__ in [VP8, VP9, H264, H265, RawVideo] or + (format.__struct__ == RemoteStream and + format.content_format in [VP8, VP9] and + format.type == :packetized))) or + (format.__struct__ == RemoteStream and + format.content_format in [H264, H265]) @spec plug_video_transcoding( ChildrenSpec.builder(), @@ -24,6 +27,21 @@ defmodule Membrane.Transcoder.Video do do_plug_video_transcoding(builder, input_format, output_format, transcoding_policy) end + defp do_plug_video_transcoding( + builder, + %RemoteStream{content_format: h26x}, + output_format, + transcoding_policy + ) + when h26x in [H264, H265] do + do_plug_video_transcoding( + builder, + struct!(h26x), + output_format, + transcoding_policy + ) + end + defp do_plug_video_transcoding(builder, %H264{}, %H264{} = output_format, transcoding_policy) when transcoding_policy in [:if_needed, :never] do builder diff --git a/mix.exs b/mix.exs index 4bfba24..633397d 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Membrane.Transcoder.Plugin.Mixfile do use Mix.Project - @version "0.3.1" + @version "0.3.2" @github_url "https://github.com/membraneframework/membrane_transcoder_plugin" def project do From 3d0d79af5b7e5ac345bba061508ad82df9662ebe Mon Sep 17 00:00:00 2001 From: "feliks.pobiedzinski@swmansion.com" Date: Thu, 10 Jul 2025 10:58:16 +0200 Subject: [PATCH 2/2] Refactor guards --- lib/transcoder/audio.ex | 29 +++++++++++++++++++++++------ lib/transcoder/video.ex | 24 ++++++++++++++++++------ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/lib/transcoder/audio.ex b/lib/transcoder/audio.ex index e2dfe5f..8fc56c6 100644 --- a/lib/transcoder/audio.ex +++ b/lib/transcoder/audio.ex @@ -22,13 +22,30 @@ defmodule Membrane.Transcoder.Audio do @type audio_stream_format :: AAC.t() | Opus.t() | Membrane.MPEGAudio.t() | RawAudio.t() + defguardp is_raw_audio_format(format) + when is_struct(format) and format.__struct__ == RawAudio + + defguardp is_aac_format(format) + when is_struct(format) and format.__struct__ == AAC + + defguardp is_opus_format(format) + when is_struct(format) and + (format.__struct__ == Opus or + (format.__struct__ == RemoteStream and + format.content_format == Opus and + format.type == :packetized)) + + defguardp is_mpeg_audio_format(format) + when is_struct(format) and + (format.__struct__ == MPEGAudio or + (format.__struct__ == RemoteStream and + format.content_format == MPEGAudio)) + defguard is_audio_format(format) - when is_struct(format) and - (format.__struct__ in [AAC, Opus, MPEGAudio, RawAudio] or - (format.__struct__ == RemoteStream and - format.content_format == Opus and - format.type == :packetized) or - (format.__struct__ == RemoteStream and format.content_format == MPEGAudio)) + when is_raw_audio_format(format) or + is_aac_format(format) or + is_opus_format(format) or + is_mpeg_audio_format(format) defguard is_opus_compliant(format) when is_map_key(format, :content_type) and format.content_type == :s16le and diff --git a/lib/transcoder/video.ex b/lib/transcoder/video.ex index afdb112..982d4d0 100644 --- a/lib/transcoder/video.ex +++ b/lib/transcoder/video.ex @@ -7,14 +7,26 @@ defmodule Membrane.Transcoder.Video do @type video_stream_format :: VP8.t() | VP9.t() | H264.t() | H265.t() | RawVideo.t() - defguard is_video_format(format) - when (is_struct(format) and - (format.__struct__ in [VP8, VP9, H264, H265, RawVideo] or + defguardp is_raw_video_format(format) + when is_struct(format) and format.__struct__ == RawVideo + + defguardp is_h26x_format(format) + when is_struct(format) and + (format.__struct__ in [H264, H265] or + (format.__struct__ == RemoteStream and + format.content_format in [H264, H265])) + + defguardp is_vpx_format(format) + when is_struct(format) and + (format.__struct__ in [VP8, VP9] or (format.__struct__ == RemoteStream and format.content_format in [VP8, VP9] and - format.type == :packetized))) or - (format.__struct__ == RemoteStream and - format.content_format in [H264, H265]) + format.type == :packetized)) + + defguard is_video_format(format) + when is_h26x_format(format) or + is_vpx_format(format) or + is_raw_video_format(format) @spec plug_video_transcoding( ChildrenSpec.builder(),