[erlang-questions] Designing protocol library

Rapsey rapsey@REDACTED
Wed Dec 23 15:53:56 CET 2009


Do you need such a deep API? RTMP is basically RPC + audio/video. So whoever
uses it, that is what he will be doing.
I would put RTMP in its own process, you send messages to it to call
functions tho whomever you are communicating and the RTMP process sends you
messages when the other side is calling you. Same thing with audio/video.

Have you thought about how RTMPT would fit into your design? It's a layer on
top of RTMP and if you plan on doing RTMPE, that is a layer in between.
With RTMPT you have X amount of sockets open to your RTMP session, if your
RTMP state is anything but a simple PID to the RTMP session process, you
will have a very hard time implementing it.


Sergej

On Wed, Dec 23, 2009 at 8:41 AM, Max Lapshin <max.lapshin@REDACTED> wrote:

> Hi everyone, I need help: I want to extract RTMP encode/decode library
> from erlyvideo, but I still don't have clear idea, how would it look
> like.
>
> There are two ideas:
> 1) RTMP library just as HTTP mode of socket should be able to work
> with sockets in active mode (send subscriber messages) and should
> maintain its internal state
> 2) RTMP library should be useable as "pure functional" decoding
> methods just like erlang:decode_packet
>
> It seems for me, that API must look like:
>
> Pure functional part:
>
> -type(rtmp_state, opaque).
> -type(rtmp_message, ...).
>
> decode(State::rtmp_state(), Data::binary()) ->
> {NewState::rtmp_state(), Message::rtmp_message(), Rest::binary()} |
> {State::rtmp_state(), Data::binary()}.
>
> encode(State::rtmp_state(), Message::rtmp_message()) ->
> {NewState::rtmp_state(), Data::binary()}.
>
> It is very important to track state, because RTMP is very, very
> stateful protocol: each incoming message change RTMP decoder state.
>
>
> Active socket part:
>
> type(socket(), port()).
> type(rtmp_mode(), active|passive|once).
> type(rtmp_socket, {socket = socket(), state = rtmp_state(), consumer =
> pid(), mode = rtmp_mode()}).
> connect(Socket::socket()) -> RTMP::rtmp_socket()   — method for client
> connection to RTMP server
> accept(Socket::socket()) -> RTMP::rtmp_socket() — method for server
> accepting new RTMP connection from client
> setopts(RTMP::rtmp_socket(), [{active, true} | {active, once} |
> passive]). — the same as mode for HTTP socket
> send(RTMP::rtmp_socket(), Message::rtmp_message()} — it is very
> important to send this message through API, because sending outside
> messages also modifies state of RTMP encoder
>
> Now, RTMP socket will send messages to opener:
>
> 1) {rtmp, RTMP, connected} — after encrypted handshake passes, this
> message is sent to server side and to client side
> 2) {rtmp, RTMP, Message::rtmp_message()}
> 3) {rtmp, RTMP, disconnected}
>
>
>
> Is such API clear?
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>


More information about the erlang-questions mailing list