Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to record with TCP transport (interleaved mode) #52

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

maslowalex
Copy link

No description provided.

@@ -176,10 +180,20 @@ defmodule Membrane.RTSP.Server.Logic do
{response, handler_state} =
state.request_handler.handle_record(state.incoming_media, state.request_handler_state)

tcp_interleaved_mode? =
state.transport_opts[:transport] == :TCP && state.transport_opts[:mode] == :record
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to check for transport[:mode], the fact that this method is called means it wants to record.

else
{response, %{state | request_handler_state: handler_state}}
{response,
%{state | request_handler_state: handler_state, recording?: tcp_interleaved_mode?}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think recording? here should be false because the request failed.

end

@impl true
def handle_info({:rtsp, %Request{} = rtsp_request}, state) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handler should just send the raw rtsp message, no need to parse it beforehand.

Copy link
Author

@maslowalex maslowalex Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is to extract the message from the raw TCP stream. How do we know that the RTSP message we are building is done? Is match on "\r\n\r\n" really enough?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the handler responsibility so he can do the parsing however it wants. You can check here for an example on how it's done on the client side.

However we still need to address the following issue, when an rtsp message is sent to the server, it should parse it and then depending on the returned result, we may need to return control to the server. For example when a client send GET_PARAMETER we can just parse it and send the response, however if it sends PAUSE, we need to start listening for rtsp messages in the server, since the handler is no longer responsible for parsing them.

@impl true
def handle_info({:rtsp, raw_rtsp_request}, state) do
  with {:ok, request} <- Request.parse(raw_rtsp_request) do
    case Logic.process_request(request, state) do
      %Logic.State{recording?: true} = state ->
        {:noreply, state}

      state ->
        handle_continue(:process_client_requests, state)
    end
  end
end

I think it's fine to raise in case the rtsp message is not valid.
Anyway the rtsp session (tcp socket) should only be closed when the client close it even TEARDOWN should not close it.

Copy link
Contributor

@gBillal gBillal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine from my part.
@Noarkhh can you review this.

end

@impl true
def handle_info({:rtsp, %Request{} = rtsp_request}, state) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can delete this.

end

defp do_process_client_requests(state, timeout) do
with {:ok, request} <- get_request(state.socket, timeout) do
case Logic.process_request(request, state) do
%{session_state: :recording} = state ->
%Logic.State{recording?: true} = state ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the field recording?, it's confusing, what about naming it recording_with_tcp? ??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap, I think recording? is confusing in this context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants