From 68048bbc46d2fa70ee7db0a8e6d482f5df01884e Mon Sep 17 00:00:00 2001 From: "feliks.pobiedzinski@swmansion.com" Date: Wed, 9 Jul 2025 16:11:12 +0200 Subject: [PATCH] Allow assuming more stream formats --- README.md | 2 +- lib/transcoder.ex | 44 +++++++++++++++++--------------------------- mix.exs | 2 +- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 511cde0..54510b5 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.0"} + {:membrane_transcoder_plugin, "~> 0.3.1"} ] end ``` diff --git a/lib/transcoder.ex b/lib/transcoder.ex index c6a1420..2398985 100644 --- a/lib/transcoder.ex +++ b/lib/transcoder.ex @@ -10,16 +10,16 @@ defmodule Membrane.Transcoder do * `Membrane.VP8` * `Membrane.VP9` * `Membrane.RawVideo` - * `Membrane.RemoteStream{content_type: Membrane.VP8}` (only as an input stream) - * `Membrane.RemoteStream{content_type: Membrane.VP9}` (only as an input stream) + * `Membrane.RemoteStream{content_format: Membrane.VP8}` (only as an input stream) + * `Membrane.RemoteStream{content_format: Membrane.VP9}` (only as an input stream) The following audio stream formats are supported: * `Membrane.AAC` * `Membrane.Opus` * `Membrane.MPEGAudio` * `Membrane.RawAudio` - * `Membrane.RemoteStream{content_type: Membrane.Opus}` (only as an input stream) - * `Membrane.RemoteStream{content_type: Membrane.MPEGAudio}` (only as an input stream) + * `Membrane.RemoteStream{content_format: Membrane.Opus}` (only as an input stream) + * `Membrane.RemoteStream{content_format: Membrane.MPEGAudio}` (only as an input stream) """ use Membrane.Bin @@ -112,12 +112,15 @@ defmodule Membrane.Transcoder do """ ], assumed_input_stream_format: [ - spec: %Membrane.RemoteStream{content_format: Membrane.MPEGAudio} | nil, + spec: struct() | nil, default: nil, description: """ - Allows to override stream format of the input stream with - `%Membrane.RemoteStream{content_format: Membrane.MPEGAudio}` - If nil, the input stream format won't be overriden. + Allows to override stream format of the input stream. + + Overriding will fail, the stream format sent on the #{inspect(__MODULE__)}'s input + pad is not `Membrane.RemoteStream` + + If nil or not set, the input stream format won't be overriden. """ ] @@ -125,7 +128,7 @@ defmodule Membrane.Transcoder do def handle_init(_ctx, opts) do spec = [ bin_input() - |> maybe_override_input_stream_format(opts.assumed_input_stream_format) + |> maybe_plug_stream_format_changer(opts.assumed_input_stream_format) |> child(:connector, %Membrane.Connector{notify_on_stream_format?: true}), child(:output_funnel, Funnel) |> bin_output() @@ -141,26 +144,13 @@ defmodule Membrane.Transcoder do {[spec: spec], state} end - defp maybe_override_input_stream_format( - builder, - %Membrane.RemoteStream{content_format: Membrane.MPEGAudio} = stream_format - ) do - builder - |> child(:stream_format_changer, %Membrane.Transcoder.StreamFormatChanger{ - stream_format: stream_format - }) - end + defp maybe_plug_stream_format_changer(builder, nil), do: builder - defp maybe_override_input_stream_format(builder, nil) do + defp maybe_plug_stream_format_changer(builder, enforced_stream_format) do builder - end - - defp maybe_override_input_stream_format(_builder, stream_format) do - raise """ - The only input stream format that can be assumed is \ - `%Membrane.RemoteStream{content_format: Membrane.MPEGAudio}`, while you wanted to assume: \ - #{inspect(stream_format)} - """ + |> child(:stream_format_changer, %__MODULE__.StreamFormatChanger{ + stream_format: enforced_stream_format + }) end @impl true diff --git a/mix.exs b/mix.exs index 2975d38..4bfba24 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Membrane.Transcoder.Plugin.Mixfile do use Mix.Project - @version "0.3.0" + @version "0.3.1" @github_url "https://github.com/membraneframework/membrane_transcoder_plugin" def project do