# `Membrane.RTMP.SourceBin`
[🔗](https://github.com/membraneframework/membrane_rtmp_plugin/blob/v0.29.9/lib/membrane_rtmp_plugin/rtmp/source/source_bin.ex#L1)

Bin responsible for demuxing and parsing an RTMP stream.

Outputs single audio and video which are ready for further processing with Membrane Elements.
At this moment only AAC and H264 codecs are supported.

The bin can be used in the following two scenarios:
* by providing the URL on which the client is expected to connect - note, that if the client doesn't
connect on this URL, the bin won't complete its setup
* by spawning `Membrane.RTMPServer`, receiving client reference after client connects on a given `app` and `stream_key`
and passing the client reference to the `Membrane.RTMP.SourceBin`.

## Bin options

Passed via struct `t:Membrane.RTMP.SourceBin.t/0`

- `client_ref`  

  ```
  pid()
  ```
  
  Default value: `nil`  
  A pid of a process acting as a client reference.
  Can be gained with the use of `Membrane.RTMPServer`.

- `url`  

  ```
  String.t()
  ```
  
  Default value: `nil`  
  An URL on which the client is expected to connect, for example:
  rtmp://127.0.0.1:1935/app/stream_key

- `client_timeout`  

  ```
  Membrane.Time.t()
  ```
  
  Default value: `5000000000`  
  Time after which an unused client connection is automatically closed, expressed in `Membrane.Time.t()` units. Defaults to 5 seconds.

## Pads

### `:audio`

Accepted formats:
```
AAC
```

Direction: | `:output`
Availability: | `:on_request`

### `:video`

Accepted formats:
```
H264
```

Direction: | `:output`
Availability: | `:on_request`

# `t`

```elixir
@type t() :: %Membrane.RTMP.SourceBin{
  client_ref: pid(),
  client_timeout: Membrane.Time.t(),
  url: String.t()
}
```

Struct containing options for `Membrane.RTMP.SourceBin`

# `options`

```elixir
@spec options() :: keyword()
```

Returns description of options available for this module

# `pass_control`

```elixir
@spec pass_control(:gen_tcp.socket(), pid()) :: :ok | {:error, atom()}
```

Passes the control of the socket to the `source`.

To succeed, the executing process must be in control of the socket, otherwise `{:error, :not_owner}` is returned.

# `secure_pass_control`

```elixir
@spec secure_pass_control(:ssl.sslsocket(), pid()) :: :ok | {:error, any()}
```

Passes the control of the ssl socket to the `source`.

To succeed, the executing process must be in control of the socket, otherwise `{:error, :not_owner}` is returned.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
