2018-08-24 03:55:36 +03:00
|
|
|
/*
|
|
|
|
NAME
|
|
|
|
rtmp_headers.go
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
See Readme.md
|
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
Saxon Nelson-Milton <saxon@ausocean.org>
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
rtmp_headers.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean)
|
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
|
|
|
|
|
|
|
Derived from librtmp under the GNU Lesser General Public License 2.1
|
|
|
|
Copyright (C) 2005-2008 Team XBMC http://www.xbmc.org
|
|
|
|
Copyright (C) 2008-2009 Andrej Stepanchuk
|
|
|
|
Copyright (C) 2009-2010 Howard Chu
|
|
|
|
*/
|
2018-08-24 03:17:11 +03:00
|
|
|
package rtmp
|
|
|
|
|
|
|
|
const (
|
|
|
|
RTMPT_OPEN = iota
|
|
|
|
RTMPT_SEND
|
|
|
|
RTMPT_IDLE
|
|
|
|
RTMPT_CLOSE
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2018-08-26 08:03:34 +03:00
|
|
|
RTMP_PACKET_TYPE_CHUNK_SIZE = 0x01
|
|
|
|
RTMP_PACKET_TYPE_BYTES_READ_REPORT = 0x03
|
|
|
|
RTMP_PACKET_TYPE_CONTROL = 0x04
|
|
|
|
RTMP_PACKET_TYPE_SERVER_BW = 0x05
|
|
|
|
RTMP_PACKET_TYPE_CLIENT_BW = 0x06
|
|
|
|
RTMP_PACKET_TYPE_AUDIO = 0x08
|
|
|
|
RTMP_PACKET_TYPE_VIDEO = 0x09
|
|
|
|
RTMP_PACKET_TYPE_FLEX_STREAM_SEND = 0x0F
|
|
|
|
RTMP_PACKET_TYPE_FLEX_SHARED_OBJECT = 0x10
|
|
|
|
RTMP_PACKET_TYPE_FLEX_MESSAGE = 0x11
|
|
|
|
RTMP_PACKET_TYPE_INFO = 0x12
|
|
|
|
RTMP_PACKET_TYPE_INVOKE = 0x14
|
|
|
|
RTMP_PACKET_TYPE_FLASH_VIDEO = 0x16
|
2018-08-24 03:17:11 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
RTMP_PACKET_SIZE_LARGE = 0
|
|
|
|
RTMP_PACKET_SIZE_MEDIUM = 1
|
|
|
|
RTMP_PACKET_SIZE_SMALL = 2
|
|
|
|
RTMP_PACKET_SIZE_MINIMUM = 3
|
|
|
|
)
|
|
|
|
const (
|
2018-08-26 08:03:34 +03:00
|
|
|
RTMP_READ_HEADER = 0x01
|
|
|
|
RTMP_READ_RESUME = 0x02
|
|
|
|
RTMP_READ_NO_IGNORE = 0x04
|
|
|
|
RTMP_READ_GOTKF = 0x08
|
|
|
|
RTMP_READ_GOTFLVK = 0x10
|
|
|
|
RTMP_READ_SEEKING = 0x20
|
|
|
|
RTMP_READ_COMPLETE = -3
|
|
|
|
RTMP_READ_ERROR = -2
|
|
|
|
RTMP_READ_EOF = -1
|
|
|
|
RTMP_READ_IGNORE = 0
|
2018-08-24 03:17:11 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
RTMP_LF_AUTH = 0x0001 /* using auth param */
|
|
|
|
RTMP_LF_LIVE = 0x0002 /* stream is live */
|
2018-08-26 08:03:34 +03:00
|
|
|
RTMP_LF_SWFV = 0x0004 /* do SWF verification */
|
2018-08-24 03:17:11 +03:00
|
|
|
RTMP_LF_PLST = 0x0008 /* send playlist before play */
|
2018-08-26 08:03:34 +03:00
|
|
|
RTMP_LF_BUFX = 0x0010 /* toggle stream on BufferEmpty msg */
|
2018-08-24 03:17:11 +03:00
|
|
|
RTMP_LF_FTCU = 0x0020 /* free tcUrl on close */
|
|
|
|
RTMP_LF_FAPU = 0x0040 /* free app on close */
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
RTMP_FEATURE_HTTP = 0x01
|
|
|
|
RTMP_FEATURE_ENC = 0x02
|
|
|
|
RTMP_FEATURE_SSL = 0x04
|
|
|
|
RTMP_FEATURE_MFP = 0x08 /* not yet supported */
|
|
|
|
RTMP_FEATURE_WRITE = 0x10 /* publish, not play */
|
2018-08-26 08:03:34 +03:00
|
|
|
RTMP_FEATURE_HTTP2 = 0x20 /* server-side rtmpt */
|
2018-08-24 03:17:11 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
RTMP_PROTOCOL_RTMP = 0
|
|
|
|
RTMP_PROTOCOL_RTMPE = RTMP_FEATURE_ENC
|
|
|
|
RTMP_PROTOCOL_RTMPT = RTMP_FEATURE_HTTP
|
|
|
|
RTMP_PROTOCOL_RTMPS = RTMP_FEATURE_SSL
|
|
|
|
RTMP_PROTOCOL_RTMPTE = (RTMP_FEATURE_HTTP | RTMP_FEATURE_ENC)
|
|
|
|
RTMP_PROTOCOL_RTMPTS = (RTMP_FEATURE_HTTP | RTMP_FEATURE_SSL)
|
|
|
|
RTMP_PROTOCOL_RTMFP = RTMP_FEATURE_MFP
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
RTMP_DEFAULT_CHUNKSIZE = 128
|
|
|
|
RTMP_BUFFER_CACHE_SIZE = (16 * 1024)
|
|
|
|
RTMP_SIG_SIZE = 1536
|
|
|
|
RTMP_LARGE_HEADER_SIZE = 12
|
|
|
|
RTMP_MAX_HEADER_SIZE = 18
|
|
|
|
)
|
|
|
|
|
2018-08-24 04:04:10 +03:00
|
|
|
// typedef struct RTMPChunk
|
|
|
|
// rtmp.h +105
|
|
|
|
type C_RTMPChunk struct {
|
|
|
|
c_headerSize int32
|
|
|
|
c_chunkSize int32
|
|
|
|
c_chunk *byte
|
|
|
|
c_header [RTMP_MAX_HEADER_SIZE]byte
|
|
|
|
}
|
|
|
|
|
2018-08-24 03:17:11 +03:00
|
|
|
// typedef struct RTMPPacket
|
|
|
|
// rtmp.h +113
|
|
|
|
type C_RTMPPacket struct {
|
|
|
|
m_headerType uint8
|
|
|
|
m_packetType uint8
|
|
|
|
m_hasAbsTimestamp uint8
|
|
|
|
m_nChannel int32
|
|
|
|
m_nTimeStamp uint32
|
|
|
|
m_nInfoField2 int32
|
|
|
|
m_nBodySize uint32
|
|
|
|
m_nBytesRead uint32
|
|
|
|
m_chunk *C_RTMPChunk
|
|
|
|
m_body *byte
|
|
|
|
}
|
|
|
|
|
2018-08-24 04:04:10 +03:00
|
|
|
// typedef struct RTMPSockBuf
|
|
|
|
// rtmp.h +127
|
|
|
|
type C_RTMPSockBuf struct {
|
|
|
|
sb_socket int32
|
|
|
|
sb_size int32
|
|
|
|
sb_start *byte
|
|
|
|
sb_buf [RTMP_BUFFER_CACHE_SIZE]byte // port const
|
|
|
|
sb_timedout int32
|
|
|
|
}
|
|
|
|
|
2018-08-26 08:03:34 +03:00
|
|
|
// RTMPPacket_IsReady(a)
|
2018-08-25 15:58:59 +03:00
|
|
|
// rtmp.h +142
|
2018-09-06 12:10:47 +03:00
|
|
|
func C_RTMPPacket_IsReady(p *C_RTMPPacket) bool {
|
|
|
|
return p.m_nBytesRead == p.m_nBodySize
|
2018-08-25 15:58:59 +03:00
|
|
|
}
|
|
|
|
|
2018-08-24 04:04:10 +03:00
|
|
|
// typedef struct RTMP_LNK
|
|
|
|
// rtmp.h +144
|
|
|
|
type C_RTMP_LNK struct {
|
2018-09-09 13:05:56 +03:00
|
|
|
hostname string
|
|
|
|
sockshost string
|
|
|
|
playpath0 string
|
|
|
|
playpath string
|
|
|
|
tcUrl string
|
|
|
|
swfUrl string
|
|
|
|
pageUrl string
|
|
|
|
app string
|
|
|
|
auth string
|
|
|
|
flashVer string
|
|
|
|
token string
|
|
|
|
extras C_AMFObject
|
|
|
|
seekTime int32
|
|
|
|
lFlags int32
|
|
|
|
swfAge int32
|
|
|
|
protocol int32
|
|
|
|
timeout int32
|
|
|
|
socksport uint16
|
|
|
|
port uint16
|
2018-08-24 04:04:10 +03:00
|
|
|
}
|
|
|
|
|
2018-08-24 03:17:11 +03:00
|
|
|
// typedef struct RTMPMethod
|
|
|
|
// rtmp.h +231
|
|
|
|
type C_RTMP_METHOD struct {
|
2018-09-06 12:30:28 +03:00
|
|
|
name string
|
2018-08-24 03:17:11 +03:00
|
|
|
num int32
|
|
|
|
}
|
|
|
|
|
|
|
|
// typedef struct RTMP
|
|
|
|
// rtmp.h +237
|
|
|
|
type C_RTMP struct {
|
|
|
|
m_inChunkSize int32
|
|
|
|
m_outChunkSize int32
|
|
|
|
m_nBWCheckCounter int32
|
|
|
|
m_nBytesIn int32
|
|
|
|
m_nBytesInSent int32
|
|
|
|
m_nBufferMS int32
|
|
|
|
m_stream_id int32
|
|
|
|
m_mediaChannel int32
|
|
|
|
m_pausing int32
|
|
|
|
m_nServerBW int32
|
|
|
|
m_nClientBW int32
|
|
|
|
m_nClientBW2 uint8
|
2018-09-06 05:20:58 +03:00
|
|
|
m_bPlaying bool
|
2018-08-24 03:17:11 +03:00
|
|
|
m_bSendEncoding uint8
|
|
|
|
m_bSendCounter uint8
|
|
|
|
m_numInvokes int32
|
2018-09-12 04:59:38 +03:00
|
|
|
m_methodCalls []C_RTMP_METHOD
|
2018-08-24 03:17:11 +03:00
|
|
|
m_channelsAllocatedIn int32
|
|
|
|
m_channelsAllocatedOut int32
|
|
|
|
m_vecChannelsIn **C_RTMPPacket
|
|
|
|
m_vecChannelsOut **C_RTMPPacket
|
|
|
|
m_channelTimestamp *int32
|
|
|
|
m_fAudioCodecs float64
|
|
|
|
m_fVideoCodecs float64
|
|
|
|
m_fEncoding float64
|
|
|
|
m_fDuration float64
|
|
|
|
m_msgCounter int32
|
|
|
|
m_resplen int32
|
|
|
|
m_unackd int32
|
|
|
|
m_write C_RTMPPacket
|
|
|
|
m_sb C_RTMPSockBuf
|
|
|
|
Link C_RTMP_LNK
|
|
|
|
}
|