rtmp

package module
v0.0.0-...-c023351 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2018 License: MIT Imports: 12 Imported by: 1

README

rtmp

Server implementation of RTMP 1.0 protocol in Go.

Getting Started

Usage is like this:

package main

import (
	"flag"
	"log"

	"github.com/c-bata/rtmp"
)

func main() {
	var addr string
	flag.StringVar(&addr, "addr", ":1935", `TCP address to listen on, ":1935" if empty`)
	flag.Parse()

	log.Printf("Serving RTMP on %s", addr)
	err := rtmp.ListenAndServe(addr)
	if err != nil {
		log.Fatalf("Catch Error: %s", err)
	}
}

Build an example server script via Make and Run it.

$ make build
$ ./bin/server -addr :1935
2018/01/28 17:09:53 Serving RTMP on :1935 (rev-a669378)

After that, you can send a RTMP stream using RTMP client like ffmpeg or Wirecast. In the case of using ffmpeg, please execute a following command.

$ ffmpeg -re -i /path/to/your_video.mp4 -map 0 -c:v libx264 -c:a aac -f flv rtmp://127.0.0.1:1935/appName/appInstance

GIF Animation - Receiving RTMP Stream.

Bibliography

Documentation

Index

Constants

View Source
const (
	CodeNetConnectAppShutdown   CommandCode = "NetConnection.Connect.AppShutdown"
	CodeNetConnectClosed                    = "NetConnection.Connect.Closed"
	CodeNetConnectFailed                    = "NetConnection.Connect.Failed"
	CodeNetConnectIdleTimeout               = "NetConnection.Connect.IdleTimeout"
	CodeNetConnectInvalidApp                = "NetConnection.Connect.InvalidApp"
	CodeNetConnectNetworkChange             = "NetConnection.Connect.NetworkChange"
	CodeNetConnectRejected                  = "NetConnection.Connect.Rejected"
	CodeNetConnectSuccess                   = "NetConnection.Connect.Success"
)
View Source
const (
	WindowAcknowledgementSize = 2500000
	PeerBandWidth             = 2500000
)
View Source
const (
	MessageSetChunkSize              MessageType = 1
	MessageAbort                                 = 2
	MessageAcknowledgement                       = 3
	MessageUserControl                           = 4
	MessageAcknowledgementWindowSize             = 5
	MessageSetPeerBandwidth                      = 6
	MessageAudio                                 = 8
	MessageVideo                                 = 9
	MessageDataAMF3                              = 15
	MessageSharedObjectAMF3                      = 16
	MessageCommandAMF3                           = 17
	MessageDataAMF0                              = 18
	MessageSharedObjectAMF0                      = 19
	MessageCommandAMF0                           = 20
	MessageAggregate                             = 22
)
View Source
const (
	PeerBandwidthLimitTypeHard    PeerBandwidthLimitType = 0
	PeerBandwidthLimitTypeSoft                           = 1
	PeerBandwidthLimitTypeDynamic                        = 2
)

Variables

This section is empty.

Functions

func CreateOnStatusPublishStartMessage

func CreateOnStatusPublishStartMessage(transactionID float64, streamName string) ([]byte, error)

func CreateStreamResponseMessage

func CreateStreamResponseMessage(transactionID float64) ([]byte, error)

func GenerateConnectResult

func GenerateConnectResult(transactionID float64) ([]byte, error)

func GenerateOnFCPublishMessage

func GenerateOnFCPublishMessage(transactionID float64, streamName string) ([]byte, error)

func GenerateSetChunkSize

func GenerateSetChunkSize(chunkSize uint32) ([]byte, error)

func GenerateSetPeerBandwidthChunk

func GenerateSetPeerBandwidthChunk(size uint32, limitType uint8) ([]byte, error)

func GenerateUserStreamBegin

func GenerateUserStreamBegin(streamID uint32) ([]byte, error)

func GenerateWindowAcknowledgementSizeChunk

func GenerateWindowAcknowledgementSizeChunk(size uint32) ([]byte, error)

func ListenAndServe

func ListenAndServe(addr string) error

Types

type BasicHeader

type BasicHeader struct {
	FMT           uint8
	ChunkStreamID uint32
}

type ChunkHeader

type ChunkHeader struct {
	BasicHeader       *BasicHeader
	MessageHeader     *MessageHeader
	ExtendedTimestamp uint32
}

type CommandCode

type CommandCode string

type CommandLevel

type CommandLevel string
const (
	CommandLevelStatus CommandLevel = "status"
	CommandLevelError               = "error"
)

type ConnectionState

type ConnectionState int
const (
	// StateInitialized means both the client and server are uninitialized.
	// The protocol version is sent during this stage.
	StateUninitialized ConnectionState = iota
	// StateVersionSent means both client and server are in the Version Sent state after the Uninitialized state.
	// The client is waiting for the packet S1 and the server is waiting for the packet C1.
	StateVersionSent
	// StateAckSent means the client and the server wait for S2 and C2 respectively.
	StateAckSent
	// StateHandshakeDone means the client and the server exchange messages.
	StateHandshakeDone
	// StateConnectResponseSent means that server has already sent the response for connect command message.
	StateConnectResponseSent
	// StateSentCreateStreamResponse means that server returns _result command message for createStream
	StateSentCreateStreamResponse
	// StatePublishingContent means that server is just receiving content.
	StatePublishingContent
)

type CreateStreamCommand

type CreateStreamCommand struct {
	Name          string
	TransactionID float64
	Properties    map[string]interface{}
	Message       map[string]interface{}
}

func (*CreateStreamCommand) Bytes

func (c *CreateStreamCommand) Bytes() []byte

type MessageHeader

type MessageHeader struct {
	Timestamp       uint32
	TimestampDelta  uint32
	MessageLength   uint32
	MessageTypeID   uint8
	MessageStreamID uint32
}

type MessageType

type MessageType uint8

type NetStreamStatusMessage

type NetStreamStatusMessage struct {
	Name          string
	TransactionID float64
	InfoObject    map[string]interface{}
}

func (*NetStreamStatusMessage) Bytes

func (m *NetStreamStatusMessage) Bytes() []byte

type PeerBandwidthLimitType

type PeerBandwidthLimitType int

type ResultCommand

type ResultCommand struct {
	Name          string
	TransactionID float64
	Properties    map[string]interface{}
	Information   map[string]interface{}
}

func (*ResultCommand) Bytes

func (rc *ResultCommand) Bytes() []byte

type Server

type Server struct {
	Addr     string      // If empty, use ":1935".
	ErrorLog *log.Logger // If nil, logging goes to os.Stderr.
}

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

func (*Server) Serve

func (srv *Server) Serve(l net.Listener) error

Directories

Path Synopsis
_example
proxy command
server command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL