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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The package can be installed by adding `membrane_rtmp_plugin` to your list of de
```elixir
def deps do
[
{:membrane_rtmp_plugin, "~> 0.29.1"}
{:membrane_rtmp_plugin, "~> 0.29.2"}
]
end
```
Expand Down
12 changes: 10 additions & 2 deletions c_src/membrane_rtmp_plugin/sink/rtmp_sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ UNIFEX_TERM init_video_stream(UnifexEnv *env, State *state, int width,

bool ready = is_ready(state);
if (ready && !state->header_written) {
if (avformat_write_header(state->output_ctx, NULL) < 0) {
AVDictionary *options = NULL;
av_dict_set(&options, "flvflags", "no_duration_filesize", 0);
if (avformat_write_header(state->output_ctx, &options) < 0) {
av_dict_free(&options);
return unifex_raise(env, "Failed writing header");
}
av_dict_free(&options);
state->header_written = true;
}
return init_video_stream_result_ok(env, ready, state);
Expand Down Expand Up @@ -132,9 +136,13 @@ UNIFEX_TERM init_audio_stream(UnifexEnv *env, State *state, int channels,

bool ready = is_ready(state);
if (ready && !state->header_written) {
if (avformat_write_header(state->output_ctx, NULL) < 0) {
AVDictionary *options = NULL;
av_dict_set(&options, "flvflags", "no_duration_filesize", 0);
if (avformat_write_header(state->output_ctx, &options) < 0) {
av_dict_free(&options);
return unifex_raise(env, "Failed writing header");
}
av_dict_free(&options);
state->header_written = true;
}
return init_audio_stream_result_ok(env, ready, state);
Expand Down
2 changes: 1 addition & 1 deletion lib/membrane_rtmp_plugin/rtmp/header.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ defmodule Membrane.RTMP.Header do
<<@header_type_3::bitstring, chunk_stream_id::6, rest::binary>>,
previous_headers
) do
previous_header = previous_headers[chunk_stream_id]
%__MODULE__{} = previous_header = previous_headers[chunk_stream_id]

if previous_header.extended_timestamp? do
with {timestamp_delta, _extended_timestamp?, rest} <-
Expand Down
17 changes: 13 additions & 4 deletions lib/membrane_rtmp_plugin/rtmp/message_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ defmodule Membrane.RTMP.MessageHandler do
}
end

defp get_additional_media_events(rtmp_header, additional_media, %{header_sent?: true} = state) do
defp get_additional_media_events(
%Membrane.RTMP.Header{} = rtmp_header,
additional_media,
%{header_sent?: true} = state
) do
# NOTE: we are replacing the type_id from 18 to 8 (script data to audio data) as it carries the
# additional audio track
data = additional_media.media
Expand All @@ -275,7 +279,7 @@ defmodule Membrane.RTMP.MessageHandler do
Map.update!(state, :events, &[event | &1])
end

defp get_additional_media_events(rtmp_header, additional_media, state) do
defp get_additional_media_events(%Membrane.RTMP.Header{} = rtmp_header, additional_media, state) do
data = additional_media.media

header = %Membrane.RTMP.Header{rtmp_header | type_id: 8, body_size: byte_size(data)}
Expand Down Expand Up @@ -336,6 +340,11 @@ defmodule Membrane.RTMP.MessageHandler do
end

@compile {:inline, socket_module: 1}
defp socket_module({:sslsocket, _1, _2}), do: :ssl
defp socket_module(_other), do: :gen_tcp
defp socket_module(socket) when is_tuple(socket) and elem(socket, 0) == :sslsocket do
:ssl
end

defp socket_module(_socket) do
:gen_tcp
end
end
8 changes: 4 additions & 4 deletions lib/membrane_rtmp_plugin/rtmp/message_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ defmodule Membrane.RTMP.MessageParser do

def handle_packet(
packet,
%{state_machine: :connected, buffer: buffer, chunk_size: chunk_size} = state
%__MODULE__{state_machine: :connected, buffer: buffer, chunk_size: chunk_size} = state
) do
payload = buffer <> packet

Expand All @@ -117,7 +117,7 @@ defmodule Membrane.RTMP.MessageParser do

def handle_packet(
packet,
%{state_machine: :handshake, buffer: buffer, handshake: handshake} = state
%__MODULE__{state_machine: :handshake, buffer: buffer, handshake: handshake} = state
) do
payload = buffer <> packet

Expand Down Expand Up @@ -161,7 +161,7 @@ defmodule Membrane.RTMP.MessageParser do

def handle_packet(
packet,
%{state_machine: :connecting, buffer: buffer, chunk_size: chunk_size} = state
%__MODULE__{state_machine: :connecting, buffer: buffer, chunk_size: chunk_size} = state
) do
payload = buffer <> packet

Expand Down Expand Up @@ -269,7 +269,7 @@ defmodule Membrane.RTMP.MessageParser do

defp fsm_transition(:handshake), do: :connecting

defp update_state_with_message(state, header, message, rest) do
defp update_state_with_message(%__MODULE__{} = state, header, message, rest) do
updated_headers = Map.put(state.previous_headers, header.chunk_stream_id, header)

%__MODULE__{
Expand Down
3 changes: 1 addition & 2 deletions lib/membrane_rtmp_plugin/rtmp/sink/sink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ defmodule Membrane.RTMP.Sink do

options = %{options | tracks: Enum.uniq(options.tracks)}

unless length(options.tracks) > 0 and
Enum.all?(options.tracks, &Kernel.in(&1, [:audio, :video])) do
if Enum.any?(options.tracks, &(&1 not in [:audio, :video])) do
raise ArgumentError, "All track have to be either :audio or :video"
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 Membrane.RTMP.Mixfile do
use Mix.Project

@version "0.29.1"
@version "0.29.2"
@github_url "https://github.com/membraneframework/membrane_rtmp_plugin"

def project do
Expand Down
Loading