2018-05-29 08:56:36 +03:00
|
|
|
/*
|
|
|
|
NAME
|
|
|
|
rtmp.go
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
See Readme.md
|
|
|
|
|
2018-08-24 03:55:36 +03:00
|
|
|
AUTHORS
|
2018-05-29 08:56:36 +03:00
|
|
|
Saxon Nelson-Milton <saxon@ausocean.org>
|
|
|
|
Dan Kortschak <dan@ausocean.org>
|
2019-01-07 08:50:35 +03:00
|
|
|
Alan Noble <alan@ausocean.org>
|
2018-05-29 08:56:36 +03:00
|
|
|
|
|
|
|
LICENSE
|
2019-01-07 08:50:35 +03:00
|
|
|
rtmp.go is Copyright (C) 2017-2019 the Australian Ocean Lab (AusOcean)
|
2018-05-29 08:56:36 +03:00
|
|
|
|
|
|
|
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
|
2018-08-30 14:01:19 +03:00
|
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
2018-08-23 23:44:37 +03:00
|
|
|
|
2018-08-30 14:01:19 +03:00
|
|
|
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-05-29 08:56:36 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
package rtmp
|
|
|
|
|
|
|
|
import (
|
2018-09-06 05:56:35 +03:00
|
|
|
"bytes"
|
2018-09-14 14:58:19 +03:00
|
|
|
"encoding/binary"
|
2018-07-16 06:30:58 +03:00
|
|
|
"errors"
|
2018-07-18 05:51:31 +03:00
|
|
|
"fmt"
|
2019-01-06 02:41:31 +03:00
|
|
|
"io"
|
2018-07-16 06:30:58 +03:00
|
|
|
"log"
|
2018-07-24 15:00:50 +03:00
|
|
|
"math/rand"
|
2019-01-06 07:12:51 +03:00
|
|
|
"net"
|
2018-07-14 08:29:00 +03:00
|
|
|
"strconv"
|
2018-08-11 05:51:22 +03:00
|
|
|
"time"
|
2018-05-29 08:56:36 +03:00
|
|
|
)
|
|
|
|
|
2018-08-08 10:36:16 +03:00
|
|
|
const (
|
|
|
|
minDataSize = 11
|
2019-01-07 06:03:07 +03:00
|
|
|
debugMode = true
|
2018-08-24 00:28:22 +03:00
|
|
|
length = 512
|
2018-07-13 18:43:17 +03:00
|
|
|
)
|
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
const (
|
|
|
|
setDataFrame = "@setDataFrame"
|
|
|
|
|
|
|
|
av__checkbw = "_checkbw"
|
|
|
|
av__onbwcheck = "_onbwcheck"
|
|
|
|
av__onbwdone = "_onbwdone"
|
|
|
|
av__result = "_result"
|
|
|
|
av_app = "app"
|
|
|
|
av_audioCodecs = "audioCodecs"
|
|
|
|
av_capabilities = "capabilities"
|
|
|
|
av_close = "close"
|
|
|
|
av_code = "code"
|
2018-09-06 12:30:28 +03:00
|
|
|
av_connect = "connect"
|
|
|
|
av_createStream = "createStream"
|
2018-09-06 12:01:14 +03:00
|
|
|
av_deleteStream = "deleteStream"
|
|
|
|
av_FCPublish = "FCPublish"
|
|
|
|
av_FCUnpublish = "FCUnpublish"
|
|
|
|
av_flashVer = "flashVer"
|
|
|
|
av_fpad = "fpad"
|
|
|
|
av_level = "level"
|
|
|
|
av_live = "live"
|
|
|
|
av_NetConnection_Connect_InvalidApp = "NetConnection.Connect.InvalidApp"
|
|
|
|
av_NetStream_Failed = "NetStream.Failed"
|
|
|
|
av_NetStream_Pause_Notify = "NetStream.Pause.Notify"
|
|
|
|
av_NetStream_Play_Complete = "NetStream.Play.Complete"
|
|
|
|
av_NetStream_Play_Failed = "NetStream.Play.Failed"
|
|
|
|
av_NetStream_Play_PublishNotify = "NetStream.Play.PublishNotify"
|
|
|
|
av_NetStream_Play_Start = "NetStream.Play.Start"
|
|
|
|
av_NetStream_Play_Stop = "NetStream.Play.Stop"
|
|
|
|
av_NetStream_Play_StreamNotFound = "NetStream.Play.StreamNotFound"
|
|
|
|
av_NetStream_Play_UnpublishNotify = "NetStream.Play.UnpublishNotify"
|
|
|
|
av_NetStream_Publish_Start = "NetStream.Publish.Start"
|
|
|
|
av_NetStream_Seek_Notify = "NetStream.Seek.Notify"
|
|
|
|
av_nonprivate = "nonprivate"
|
|
|
|
av_objectEncoding = "objectEncoding"
|
|
|
|
av_onBWDone = "onBWDone"
|
|
|
|
av_onFCSubscribe = "onFCSubscribe"
|
|
|
|
av_onFCUnsubscribe = "onFCUnsubscribe"
|
|
|
|
av_onStatus = "onStatus"
|
|
|
|
av_pageUrl = "pageUrl"
|
|
|
|
av_ping = "ping"
|
2018-09-06 12:30:28 +03:00
|
|
|
av_play = "play"
|
2018-09-06 12:01:14 +03:00
|
|
|
av_playlist_ready = "playlist_ready"
|
2018-09-06 12:30:28 +03:00
|
|
|
av_publish = "publish"
|
2018-09-06 12:01:14 +03:00
|
|
|
av_releaseStream = "releaseStream"
|
2018-09-06 12:30:28 +03:00
|
|
|
av_secureToken = "secureToken"
|
|
|
|
av_set_playlist = "set_playlist"
|
2018-09-06 12:01:14 +03:00
|
|
|
av_swfUrl = "swfUrl"
|
|
|
|
av_tcUrl = "tcUrl"
|
|
|
|
av_type = "type"
|
|
|
|
av_videoCodecs = "videoCodecs"
|
|
|
|
av_videoFunction = "videoFunction"
|
2018-07-26 10:36:44 +03:00
|
|
|
)
|
2018-07-16 06:30:58 +03:00
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
// RTMP protocol strings.
|
|
|
|
var rtmpProtocolStrings = [...]string{
|
|
|
|
"rtmp",
|
|
|
|
"rtmpt",
|
|
|
|
"rtmpe",
|
|
|
|
"rtmpte",
|
|
|
|
"rtmps",
|
|
|
|
"rtmpts",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"rtmfp",
|
|
|
|
}
|
|
|
|
|
|
|
|
// RTMP errors.
|
2019-01-06 01:50:32 +03:00
|
|
|
var (
|
2019-01-06 04:36:16 +03:00
|
|
|
errUnknownScheme = errors.New("rtmp: unknown scheme")
|
2019-01-07 10:30:42 +03:00
|
|
|
errNotConnected = errors.New("rtmp: not connected")
|
2019-01-06 04:36:16 +03:00
|
|
|
errHandshake = errors.New("rtmp: handshake failed")
|
|
|
|
errConnSend = errors.New("rtmp: connection send error")
|
|
|
|
errConnStream = errors.New("rtmp: connection stream error")
|
2019-01-06 07:12:51 +03:00
|
|
|
errInvalidHeader = errors.New("rtmp: invalid header")
|
|
|
|
errInvalidBody = errors.New("rtmp: invalid body")
|
|
|
|
errTinyPacket = errors.New("rtmp: packet too small")
|
|
|
|
errEncoding = errors.New("rtmp: encoding error")
|
|
|
|
errDecoding = errors.New("rtmp: decoding error")
|
|
|
|
errCopying = errors.New("rtmp: copying error")
|
2019-01-06 01:50:32 +03:00
|
|
|
)
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
// setupURL parses the RTMP URL.
|
|
|
|
func setupURL(s *Session, addr string) (err error) {
|
|
|
|
s.link.protocol, s.link.host, s.link.port, s.link.app, s.link.playpath, err = parseURL(addr)
|
2019-01-06 01:50:32 +03:00
|
|
|
if err != nil {
|
2019-01-06 04:36:16 +03:00
|
|
|
return err
|
2018-07-15 21:09:36 +03:00
|
|
|
}
|
2018-07-19 18:35:21 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.link.tcUrl == "" {
|
|
|
|
if s.link.app != "" {
|
|
|
|
s.link.tcUrl = fmt.Sprintf("%v://%v:%v/%v",
|
2019-01-07 10:30:42 +03:00
|
|
|
rtmpProtocolStrings[s.link.protocol], s.link.host, s.link.port, s.link.app)
|
2019-01-07 08:50:35 +03:00
|
|
|
s.link.lFlags |= RTMP_LF_FTCU
|
2018-07-19 18:35:21 +03:00
|
|
|
} else {
|
2019-01-07 08:50:35 +03:00
|
|
|
s.link.tcUrl = addr
|
2018-07-19 18:35:21 +03:00
|
|
|
}
|
2018-07-15 21:09:36 +03:00
|
|
|
}
|
2018-07-22 17:01:19 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.link.port == 0 {
|
2018-07-19 18:35:21 +03:00
|
|
|
switch {
|
2019-01-07 08:50:35 +03:00
|
|
|
case (s.link.protocol & RTMP_FEATURE_SSL) != 0:
|
|
|
|
s.link.port = 433
|
|
|
|
case (s.link.protocol & RTMP_FEATURE_HTTP) != 0:
|
|
|
|
s.link.port = 80
|
2018-07-19 18:35:21 +03:00
|
|
|
default:
|
2019-01-07 08:50:35 +03:00
|
|
|
s.link.port = 1935
|
2018-07-19 18:35:21 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-06 01:50:32 +03:00
|
|
|
return nil
|
2018-07-15 21:09:36 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
// connect establishes an RTMP connection.
|
2019-01-07 14:15:00 +03:00
|
|
|
func connect(s *Session) error {
|
2019-01-07 08:50:35 +03:00
|
|
|
addr, err := net.ResolveTCPAddr("tcp4", s.link.host+":"+strconv.Itoa(int(s.link.port)))
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
s.link.conn, err = net.DialTCP("tcp4", nil, addr)
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-07-22 16:31:50 +03:00
|
|
|
if debugMode {
|
|
|
|
log.Println("... connected, handshaking...")
|
|
|
|
}
|
2019-01-07 14:15:00 +03:00
|
|
|
err = handshake(s)
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
2019-01-07 10:30:42 +03:00
|
|
|
log.Println("connect: handshake failed")
|
2019-01-06 01:50:32 +03:00
|
|
|
return errHandshake
|
2018-07-22 16:31:50 +03:00
|
|
|
}
|
|
|
|
if debugMode {
|
|
|
|
log.Println("... handshaked...")
|
|
|
|
}
|
2019-01-07 14:15:00 +03:00
|
|
|
err = sendConnectPacket(s)
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
2019-01-07 10:30:42 +03:00
|
|
|
log.Println("connect: sendConnect failed")
|
2019-01-06 01:50:32 +03:00
|
|
|
return errConnSend
|
2018-07-22 16:31:50 +03:00
|
|
|
}
|
2019-01-06 01:50:32 +03:00
|
|
|
return nil
|
2018-07-22 16:31:50 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
// connectStream reads a packet and handles it
|
2019-01-07 14:15:00 +03:00
|
|
|
func connectStream(s *Session) error {
|
2019-01-07 08:50:35 +03:00
|
|
|
var pkt packet
|
2018-08-24 12:20:04 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
for !s.isPlaying && s.isConnected() {
|
2019-01-07 10:30:42 +03:00
|
|
|
err := readPacket(s, &pkt)
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
2018-08-24 12:20:04 +03:00
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
if pkt.bodySize == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2018-08-24 12:20:04 +03:00
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
if pkt.packetType == RTMP_PACKET_TYPE_AUDIO ||
|
|
|
|
pkt.packetType == RTMP_PACKET_TYPE_VIDEO ||
|
|
|
|
pkt.packetType == RTMP_PACKET_TYPE_INFO {
|
|
|
|
log.Println("connectStream: got packet before play()! Ignoring.")
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.body = nil
|
2019-01-07 10:30:42 +03:00
|
|
|
continue
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2019-01-07 10:30:42 +03:00
|
|
|
|
|
|
|
handlePacket(s, &pkt)
|
|
|
|
pkt.body = nil
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2019-01-06 01:50:32 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
if !s.isPlaying {
|
2019-01-06 01:50:32 +03:00
|
|
|
return errConnStream
|
|
|
|
}
|
|
|
|
return nil
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
// handlePacket handles a packet that the client has received.
|
|
|
|
// NB: cases have been commented out that are not currently used by AusOcean
|
|
|
|
func handlePacket(s *Session, pkt *packet) int32 {
|
2019-01-07 08:50:35 +03:00
|
|
|
var hasMediaPacket int32
|
|
|
|
switch pkt.packetType {
|
2018-08-24 12:20:04 +03:00
|
|
|
|
|
|
|
case RTMP_PACKET_TYPE_CHUNK_SIZE:
|
2019-01-07 10:30:42 +03:00
|
|
|
if pkt.bodySize >= 4 {
|
|
|
|
s.inChunkSize = int32(C_AMF_DecodeInt32(pkt.body[:4]))
|
|
|
|
}
|
2018-08-25 16:52:22 +03:00
|
|
|
|
|
|
|
case RTMP_PACKET_TYPE_BYTES_READ_REPORT:
|
2019-01-07 10:30:42 +03:00
|
|
|
s.serverBW = int32(C_AMF_DecodeInt32(pkt.body[:4]))
|
2018-08-25 16:52:22 +03:00
|
|
|
|
|
|
|
case RTMP_PACKET_TYPE_CONTROL:
|
|
|
|
panic("Unsupported packet type RTMP_PACKET_TYPE_CONTROL")
|
2019-01-07 10:30:42 +03:00
|
|
|
|
2018-08-24 12:20:04 +03:00
|
|
|
case RTMP_PACKET_TYPE_SERVER_BW:
|
2019-01-07 10:30:42 +03:00
|
|
|
s.serverBW = int32(C_AMF_DecodeInt32(pkt.body[:4]))
|
2018-08-24 12:20:04 +03:00
|
|
|
|
|
|
|
case RTMP_PACKET_TYPE_CLIENT_BW:
|
2019-01-07 10:30:42 +03:00
|
|
|
s.clientBW = int32(C_AMF_DecodeInt32(pkt.body[:4]))
|
|
|
|
if pkt.bodySize > 4 {
|
|
|
|
s.clientBW2 = pkt.body[4]
|
|
|
|
} else {
|
|
|
|
s.clientBW2 = 0xff
|
|
|
|
}
|
2018-08-24 12:20:04 +03:00
|
|
|
|
2018-08-25 16:52:22 +03:00
|
|
|
case RTMP_PACKET_TYPE_AUDIO:
|
|
|
|
panic("Unsupported packet type RTMP_PACKET_TYPE_AUDIO")
|
2018-08-24 12:20:04 +03:00
|
|
|
|
2018-08-25 16:52:22 +03:00
|
|
|
case RTMP_PACKET_TYPE_VIDEO:
|
|
|
|
panic("Unsupported packet type RTMP_PACKET_TYPE_VIDEO")
|
2018-08-28 12:48:13 +03:00
|
|
|
|
2018-08-25 16:52:22 +03:00
|
|
|
case RTMP_PACKET_TYPE_FLEX_MESSAGE:
|
|
|
|
panic("Unsupported packet type RTMP_PACKET_TYPE_FLEX_MESSAGE")
|
|
|
|
|
|
|
|
case RTMP_PACKET_TYPE_INFO:
|
|
|
|
panic("Unsupported packet type RTMP_PACKET_TYPE_INFO")
|
2018-08-24 12:20:04 +03:00
|
|
|
|
|
|
|
case RTMP_PACKET_TYPE_INVOKE:
|
2019-01-07 10:30:42 +03:00
|
|
|
if debugMode {
|
|
|
|
log.Println("RTMP_PACKET_TYPE_INVOKE:")
|
|
|
|
}
|
|
|
|
err := handleInvoke(s, pkt.body[:pkt.bodySize])
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
2018-09-06 05:20:58 +03:00
|
|
|
// This will never happen with the methods we implement.
|
2018-08-24 12:20:04 +03:00
|
|
|
log.Println("HasMediaPacket")
|
2019-01-07 08:50:35 +03:00
|
|
|
hasMediaPacket = 2
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2018-08-25 16:52:22 +03:00
|
|
|
|
|
|
|
case RTMP_PACKET_TYPE_FLASH_VIDEO:
|
|
|
|
panic("Unsupported packet type RTMP_PACKET_TYPE_FLASH_VIDEO")
|
2018-08-24 12:20:04 +03:00
|
|
|
|
2018-08-25 16:52:22 +03:00
|
|
|
default:
|
|
|
|
// TODO use new logger here
|
2019-01-07 08:50:35 +03:00
|
|
|
// RTMP_Log(RTMP_LOGDEBUG, "%s, unknown packet type received: 0x%02x", __FUNCTION__,pkt.packetType);
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
return hasMediaPacket
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
func readN(s *Session, buf []byte) error {
|
2019-01-07 08:50:35 +03:00
|
|
|
err := s.link.conn.SetReadDeadline(time.Now().Add(time.Second * time.Duration(s.link.timeout)))
|
2019-01-06 02:41:31 +03:00
|
|
|
if err != nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return err
|
2019-01-06 02:41:31 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
n, err := io.ReadFull(s.link.conn, buf)
|
2019-01-06 02:41:31 +03:00
|
|
|
if err != nil {
|
|
|
|
if debugMode {
|
2019-01-07 10:30:42 +03:00
|
|
|
log.Printf("readN error: %v\n", err)
|
2018-07-28 07:57:30 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
s.close()
|
2019-01-06 07:12:51 +03:00
|
|
|
return err
|
2018-07-28 07:57:30 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
s.nBytesIn += int32(n)
|
|
|
|
if s.nBytesIn > (s.nBytesInSent + s.clientBW/10) {
|
2019-01-07 10:30:42 +03:00
|
|
|
err := sendBytesReceived(s)
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2019-01-06 02:41:31 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-06 07:12:51 +03:00
|
|
|
return nil
|
2018-07-28 08:25:25 +03:00
|
|
|
}
|
2018-07-28 07:57:30 +03:00
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
func writeN(s *Session, buf []byte) error {
|
2019-01-07 01:14:04 +03:00
|
|
|
//ToDo: consider using a different timeout for writes than for reads
|
2019-01-07 08:50:35 +03:00
|
|
|
err := s.link.conn.SetWriteDeadline(time.Now().Add(time.Second * time.Duration(s.link.timeout)))
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
_, err = s.link.conn.Write(buf)
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
|
|
|
if debugMode {
|
2019-01-07 10:30:42 +03:00
|
|
|
log.Printf("writeN, RTMP send error: %v\n", err)
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
s.close()
|
2019-01-06 07:12:51 +03:00
|
|
|
return err
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2019-01-06 07:12:51 +03:00
|
|
|
return nil
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 14:15:00 +03:00
|
|
|
func sendConnectPacket(s *Session) error {
|
2018-09-19 06:06:39 +03:00
|
|
|
var pbuf [4096]byte
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt := packet{
|
2019-01-07 14:15:00 +03:00
|
|
|
channel: RTMP_CHANNEL_CONTROL,
|
|
|
|
headerType: RTMP_PACKET_SIZE_LARGE,
|
|
|
|
packetType: RTMP_PACKET_TYPE_INVOKE,
|
|
|
|
header: pbuf[:],
|
|
|
|
body: pbuf[RTMP_MAX_HEADER_SIZE:],
|
2018-09-19 06:06:39 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
enc := pkt.body
|
2018-07-28 15:00:08 +03:00
|
|
|
|
2018-09-19 06:06:39 +03:00
|
|
|
enc = C_AMF_EncodeString(enc, av_connect)
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
s.numInvokes += 1
|
|
|
|
enc = C_AMF_EncodeNumber(enc, float64(s.numInvokes))
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2018-09-19 06:06:39 +03:00
|
|
|
enc[0] = AMF_OBJECT
|
|
|
|
enc = enc[1:]
|
2018-07-28 15:00:08 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
enc = C_AMF_EncodeNamedString(enc, av_app, s.link.app)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.link.protocol&RTMP_FEATURE_WRITE != 0 {
|
2018-09-19 06:06:39 +03:00
|
|
|
enc = C_AMF_EncodeNamedString(enc, av_type, av_nonprivate)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.link.flashVer != "" {
|
|
|
|
enc = C_AMF_EncodeNamedString(enc, av_flashVer, s.link.flashVer)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.link.swfUrl != "" {
|
|
|
|
enc = C_AMF_EncodeNamedString(enc, av_swfUrl, s.link.swfUrl)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.link.tcUrl != "" {
|
|
|
|
enc = C_AMF_EncodeNamedString(enc, av_tcUrl, s.link.tcUrl)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.link.protocol&RTMP_FEATURE_WRITE == 0 {
|
2018-09-19 06:06:39 +03:00
|
|
|
enc = C_AMF_EncodeNamedBoolean(enc, av_fpad, false)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
2018-09-19 06:06:39 +03:00
|
|
|
enc = C_AMF_EncodeNamedNumber(enc, av_capabilities, 15)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
enc = C_AMF_EncodeNamedNumber(enc, av_audioCodecs, s.audioCodecs)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
enc = C_AMF_EncodeNamedNumber(enc, av_videoCodecs, s.videoCodecs)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
2018-09-19 06:06:39 +03:00
|
|
|
enc = C_AMF_EncodeNamedNumber(enc, av_videoFunction, 1)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.link.pageUrl != "" {
|
|
|
|
enc = C_AMF_EncodeNamedString(enc, av_pageUrl, s.link.pageUrl)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.encoding != 0.0 || s.sendEncoding {
|
|
|
|
enc = C_AMF_EncodeNamedNumber(enc, av_objectEncoding, s.encoding)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 06:06:39 +03:00
|
|
|
if copy(enc, []byte{0, 0, AMF_OBJECT_END}) != 3 {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errCopying // TODO: is this even possible?
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
2018-09-19 06:06:39 +03:00
|
|
|
enc = enc[3:]
|
2018-07-26 10:36:44 +03:00
|
|
|
|
|
|
|
/* add auth string */
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.link.auth != "" {
|
|
|
|
enc = C_AMF_EncodeBoolean(enc, s.link.lFlags&RTMP_LF_AUTH != 0)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
enc = C_AMF_EncodeString(enc, s.link.auth)
|
2018-07-26 10:36:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
for i := range s.link.extras.o_props {
|
|
|
|
enc = C_AMF_PropEncode(&s.link.extras.o_props[i], enc)
|
2018-09-15 03:50:44 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-26 10:36:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.bodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc))
|
2018-07-26 10:36:44 +03:00
|
|
|
|
2019-01-07 14:15:00 +03:00
|
|
|
return sendPacket(s, &pkt, true)
|
2018-07-25 04:26:59 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
func sendCreateStream(s *Session) error {
|
2018-08-24 04:13:34 +03:00
|
|
|
var pbuf [256]byte
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt := packet{
|
2019-01-07 14:15:00 +03:00
|
|
|
channel: RTMP_CHANNEL_CONTROL,
|
|
|
|
headerType: RTMP_PACKET_SIZE_MEDIUM,
|
|
|
|
packetType: RTMP_PACKET_TYPE_INVOKE,
|
|
|
|
header: pbuf[:],
|
|
|
|
body: pbuf[RTMP_MAX_HEADER_SIZE:],
|
2018-09-19 06:29:04 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
enc := pkt.body
|
2018-09-19 06:29:04 +03:00
|
|
|
|
|
|
|
enc = C_AMF_EncodeString(enc, av_createStream)
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
s.numInvokes++
|
|
|
|
enc = C_AMF_EncodeNumber(enc, float64(s.numInvokes))
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2018-09-19 06:29:04 +03:00
|
|
|
enc[0] = AMF_NULL
|
|
|
|
enc = enc[1:]
|
2018-08-24 04:13:34 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.bodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc))
|
2018-08-24 04:13:34 +03:00
|
|
|
|
2019-01-07 14:15:00 +03:00
|
|
|
return sendPacket(s, &pkt, true)
|
2018-08-24 04:13:34 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
func sendReleaseStream(s *Session) error {
|
2018-08-24 12:20:04 +03:00
|
|
|
var pbuf [1024]byte
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt := packet{
|
2019-01-07 14:15:00 +03:00
|
|
|
channel: RTMP_CHANNEL_CONTROL,
|
|
|
|
headerType: RTMP_PACKET_SIZE_MEDIUM,
|
|
|
|
packetType: RTMP_PACKET_TYPE_INVOKE,
|
|
|
|
header: pbuf[:],
|
|
|
|
body: pbuf[RTMP_MAX_HEADER_SIZE:],
|
2018-09-19 06:29:04 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
enc := pkt.body
|
2018-09-19 06:29:04 +03:00
|
|
|
|
|
|
|
enc = C_AMF_EncodeString(enc, av_releaseStream)
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
s.numInvokes++
|
|
|
|
enc = C_AMF_EncodeNumber(enc, float64(s.numInvokes))
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2018-09-19 06:29:04 +03:00
|
|
|
enc[0] = AMF_NULL
|
|
|
|
enc = enc[1:]
|
2019-01-07 08:50:35 +03:00
|
|
|
enc = C_AMF_EncodeString(enc, s.link.playpath)
|
2018-08-24 12:20:04 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-08-24 04:13:34 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.bodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc))
|
2018-08-24 04:13:34 +03:00
|
|
|
|
2019-01-07 14:15:00 +03:00
|
|
|
return sendPacket(s, &pkt, false)
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2018-08-24 04:13:34 +03:00
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
func sendFCPublish(s *Session) error {
|
2018-08-24 12:20:04 +03:00
|
|
|
var pbuf [1024]byte
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt := packet{
|
2019-01-07 14:15:00 +03:00
|
|
|
channel: RTMP_CHANNEL_CONTROL,
|
|
|
|
headerType: RTMP_PACKET_SIZE_MEDIUM,
|
|
|
|
packetType: RTMP_PACKET_TYPE_INVOKE,
|
|
|
|
header: pbuf[:],
|
|
|
|
body: pbuf[RTMP_MAX_HEADER_SIZE:],
|
2018-09-19 06:29:04 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
enc := pkt.body
|
2018-09-19 06:29:04 +03:00
|
|
|
|
|
|
|
enc = C_AMF_EncodeString(enc, av_FCPublish)
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
s.numInvokes++
|
|
|
|
enc = C_AMF_EncodeNumber(enc, float64(s.numInvokes))
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2018-09-19 06:29:04 +03:00
|
|
|
enc[0] = AMF_NULL
|
|
|
|
enc = enc[1:]
|
2019-01-07 08:50:35 +03:00
|
|
|
enc = C_AMF_EncodeString(enc, s.link.playpath)
|
2018-08-24 12:20:04 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-08-24 04:13:34 +03:00
|
|
|
}
|
2018-09-19 06:29:04 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.bodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc))
|
2018-08-24 04:13:34 +03:00
|
|
|
|
2019-01-07 14:15:00 +03:00
|
|
|
return sendPacket(s, &pkt, false)
|
2018-08-24 04:13:34 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
func sendFCUnpublish(s *Session) error {
|
2018-09-06 04:56:52 +03:00
|
|
|
var pbuf [1024]byte
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt := packet{
|
2019-01-07 14:15:00 +03:00
|
|
|
channel: RTMP_CHANNEL_CONTROL,
|
|
|
|
headerType: RTMP_PACKET_SIZE_MEDIUM,
|
|
|
|
packetType: RTMP_PACKET_TYPE_INVOKE,
|
|
|
|
header: pbuf[:],
|
|
|
|
body: pbuf[RTMP_MAX_HEADER_SIZE:],
|
2018-09-19 06:29:04 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
enc := pkt.body
|
2018-09-19 06:29:04 +03:00
|
|
|
|
|
|
|
enc = C_AMF_EncodeString(enc, av_FCUnpublish)
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
s.numInvokes++
|
|
|
|
enc = C_AMF_EncodeNumber(enc, float64(s.numInvokes))
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2018-09-19 06:29:04 +03:00
|
|
|
enc[0] = AMF_NULL
|
|
|
|
enc = enc[1:]
|
2019-01-07 08:50:35 +03:00
|
|
|
enc = C_AMF_EncodeString(enc, s.link.playpath)
|
2018-09-06 04:56:52 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-09-06 04:56:52 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.bodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc))
|
2018-09-06 04:56:52 +03:00
|
|
|
|
2019-01-07 14:15:00 +03:00
|
|
|
return sendPacket(s, &pkt, false)
|
2018-08-25 17:43:08 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
func sendPublish(s *Session) error {
|
2018-08-24 12:20:04 +03:00
|
|
|
var pbuf [1024]byte
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt := packet{
|
2019-01-07 14:15:00 +03:00
|
|
|
channel: RTMP_CHANNEL_SOURCE,
|
|
|
|
headerType: RTMP_PACKET_SIZE_LARGE,
|
|
|
|
packetType: RTMP_PACKET_TYPE_INVOKE,
|
|
|
|
header: pbuf[:],
|
|
|
|
body: pbuf[RTMP_MAX_HEADER_SIZE:],
|
2018-09-19 06:29:04 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
enc := pkt.body
|
2018-09-19 06:29:04 +03:00
|
|
|
|
|
|
|
enc = C_AMF_EncodeString(enc, av_publish)
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
s.numInvokes++
|
|
|
|
enc = C_AMF_EncodeNumber(enc, float64(s.numInvokes))
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2018-09-19 06:29:04 +03:00
|
|
|
enc[0] = AMF_NULL
|
|
|
|
enc = enc[1:]
|
2019-01-07 08:50:35 +03:00
|
|
|
enc = C_AMF_EncodeString(enc, s.link.playpath)
|
2018-08-24 12:20:04 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-08-24 04:13:34 +03:00
|
|
|
}
|
2018-09-19 06:29:04 +03:00
|
|
|
enc = C_AMF_EncodeString(enc, av_live)
|
2018-08-24 12:20:04 +03:00
|
|
|
if enc == nil {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errEncoding
|
2018-07-22 16:31:50 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.bodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc))
|
2018-07-22 16:31:50 +03:00
|
|
|
|
2019-01-07 14:15:00 +03:00
|
|
|
return sendPacket(s, &pkt, true)
|
2018-07-22 16:31:50 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
func sendDeleteStream(s *Session, dStreamId float64) error {
|
2018-09-06 05:15:48 +03:00
|
|
|
var pbuf [256]byte
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt := packet{
|
2019-01-07 14:15:00 +03:00
|
|
|
channel: RTMP_CHANNEL_CONTROL,
|
|
|
|
headerType: RTMP_PACKET_SIZE_MEDIUM,
|
|
|
|
packetType: RTMP_PACKET_TYPE_INVOKE,
|
|
|
|
header: pbuf[:],
|
|
|
|
body: pbuf[RTMP_MAX_HEADER_SIZE:],
|
2018-09-19 06:29:04 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
enc := pkt.body
|
2018-09-19 06:29:04 +03:00
|
|
|
|
|
|
|
enc = C_AMF_EncodeString(enc, av_deleteStream)
|
2019-01-06 07:12:51 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
s.numInvokes++
|
|
|
|
enc = C_AMF_EncodeNumber(enc, float64(s.numInvokes))
|
2019-01-06 07:12:51 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2018-09-19 06:29:04 +03:00
|
|
|
enc[0] = AMF_NULL
|
|
|
|
enc = enc[1:]
|
|
|
|
enc = C_AMF_EncodeNumber(enc, dStreamId)
|
2019-01-06 07:12:51 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.bodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc))
|
2018-09-06 05:15:48 +03:00
|
|
|
|
|
|
|
/* no response expected */
|
2019-01-07 14:15:00 +03:00
|
|
|
return sendPacket(s, &pkt, false)
|
2018-09-06 05:15:48 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
// sendBytesReceived tells the server how many bytes the client has received.
|
|
|
|
func sendBytesReceived(s *Session) error {
|
2018-08-24 12:20:04 +03:00
|
|
|
var pbuf [256]byte
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt := packet{
|
2019-01-07 14:15:00 +03:00
|
|
|
channel: RTMP_CHANNEL_BYTES_READ,
|
|
|
|
headerType: RTMP_PACKET_SIZE_MEDIUM,
|
|
|
|
packetType: RTMP_PACKET_TYPE_BYTES_READ_REPORT,
|
|
|
|
header: pbuf[:],
|
|
|
|
body: pbuf[RTMP_MAX_HEADER_SIZE:],
|
2019-01-07 06:03:07 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
enc := pkt.body
|
2019-01-07 06:03:07 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
s.nBytesInSent = s.nBytesIn
|
|
|
|
enc = C_AMF_EncodeInt32(enc, s.nBytesIn)
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.bodySize = 4
|
2018-08-12 12:07:39 +03:00
|
|
|
|
2019-01-07 14:15:00 +03:00
|
|
|
return sendPacket(s, &pkt, false)
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2018-08-12 13:07:56 +03:00
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
func sendCheckBW(s *Session) error {
|
2018-08-24 12:20:04 +03:00
|
|
|
var pbuf [256]byte
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt := packet{
|
2019-01-07 14:15:00 +03:00
|
|
|
channel: RTMP_CHANNEL_CONTROL,
|
|
|
|
headerType: RTMP_PACKET_SIZE_LARGE,
|
|
|
|
packetType: RTMP_PACKET_TYPE_INVOKE,
|
|
|
|
header: pbuf[:],
|
|
|
|
body: pbuf[RTMP_MAX_HEADER_SIZE:],
|
2018-09-19 06:29:04 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
enc := pkt.body
|
2018-09-19 06:29:04 +03:00
|
|
|
|
|
|
|
enc = C_AMF_EncodeString(enc, av__checkbw)
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
s.numInvokes++
|
|
|
|
enc = C_AMF_EncodeNumber(enc, float64(s.numInvokes))
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2018-09-19 06:29:04 +03:00
|
|
|
enc[0] = AMF_NULL
|
|
|
|
enc = enc[1:]
|
2018-08-12 12:07:39 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.bodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc))
|
2018-08-12 13:17:53 +03:00
|
|
|
|
2019-01-07 14:15:00 +03:00
|
|
|
return sendPacket(s, &pkt, false)
|
2018-08-12 13:17:53 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
func eraseMethod(m []method, i int) []method {
|
2018-09-12 04:59:38 +03:00
|
|
|
copy(m[i:], m[i+1:])
|
2019-01-07 08:50:35 +03:00
|
|
|
m[len(m)-1] = method{}
|
2018-09-12 04:59:38 +03:00
|
|
|
return m[:len(m)-1]
|
2018-08-24 16:00:40 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
// int handleInvoke handles a packet invoke request
|
2019-01-07 08:50:35 +03:00
|
|
|
// Side effects: s.isPlaying set to true upon av_NetStream_Publish_Start
|
2019-01-07 10:30:42 +03:00
|
|
|
func handleInvoke(s *Session, body []byte) error {
|
2018-09-19 07:35:42 +03:00
|
|
|
if body[0] != 0x02 {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errInvalidBody
|
2018-08-14 11:52:37 +03:00
|
|
|
}
|
2018-09-12 05:37:43 +03:00
|
|
|
var obj C_AMFObject
|
2018-09-19 07:35:42 +03:00
|
|
|
nRes := C_AMF_Decode(&obj, body, 0)
|
2018-08-14 11:52:37 +03:00
|
|
|
if nRes < 0 {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errDecoding
|
2018-08-14 11:52:37 +03:00
|
|
|
}
|
2018-08-14 10:06:42 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
meth := C_AMFProp_GetString(C_AMF_GetProp(&obj, "", 0))
|
2018-09-12 05:37:43 +03:00
|
|
|
txn := C_AMFProp_GetNumber(C_AMF_GetProp(&obj, "", 1))
|
2018-08-14 06:15:03 +03:00
|
|
|
// TODO use new logger here
|
|
|
|
// RTMP_Log(RTMP_LOGDEBUG, "%s, server invoking <%s>", __FUNCTION__, method.av_val);
|
2018-09-06 11:33:55 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
switch meth {
|
2018-09-06 12:01:14 +03:00
|
|
|
case av__result:
|
2018-09-06 12:30:28 +03:00
|
|
|
var methodInvoked string
|
2019-01-07 08:50:35 +03:00
|
|
|
for i, m := range s.methodCalls {
|
2018-09-12 04:59:38 +03:00
|
|
|
if float64(m.num) == txn {
|
|
|
|
methodInvoked = m.name
|
2019-01-07 10:30:42 +03:00
|
|
|
s.methodCalls = eraseMethod(s.methodCalls, i)
|
2018-09-06 11:33:55 +03:00
|
|
|
break
|
2018-08-14 11:52:37 +03:00
|
|
|
}
|
2018-09-06 11:33:55 +03:00
|
|
|
}
|
2018-09-06 12:30:28 +03:00
|
|
|
if methodInvoked == "" {
|
2018-08-14 16:00:47 +03:00
|
|
|
// TODO use new logger here
|
2018-09-06 11:33:55 +03:00
|
|
|
//RTMP_Log(RTMP_LOGDEBUG, "%s, received result id %f without matching request",
|
|
|
|
//__FUNCTION__, txn);
|
|
|
|
goto leave
|
|
|
|
}
|
|
|
|
// TODO use new logger here
|
|
|
|
//RTMP_Log(RTMP_LOGDEBUG, "%s, received result for method call <%s>", __FUNCTION__,
|
|
|
|
//methodInvoked.av_val);
|
2018-09-06 12:30:28 +03:00
|
|
|
switch methodInvoked {
|
|
|
|
case av_connect:
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.link.token != "" {
|
2018-09-06 11:33:55 +03:00
|
|
|
panic("No support for link token")
|
2018-08-28 12:10:10 +03:00
|
|
|
|
2018-09-06 11:33:55 +03:00
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
if (s.link.protocol & RTMP_FEATURE_WRITE) != 0 {
|
2019-01-07 10:30:42 +03:00
|
|
|
sendReleaseStream(s)
|
|
|
|
sendFCPublish(s)
|
2018-09-06 11:33:55 +03:00
|
|
|
} else {
|
|
|
|
panic("Link protocol has no RTMP_FEATURE_WRITE")
|
|
|
|
}
|
2018-08-28 12:10:10 +03:00
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
sendCreateStream(s)
|
2019-01-07 08:50:35 +03:00
|
|
|
if (s.link.protocol & RTMP_FEATURE_WRITE) == 0 {
|
2018-09-06 11:33:55 +03:00
|
|
|
panic("Link protocol has no RTMP_FEATURE_WRITE")
|
|
|
|
}
|
2018-08-14 16:00:47 +03:00
|
|
|
|
2018-09-06 12:30:28 +03:00
|
|
|
case av_createStream:
|
2019-01-07 08:50:35 +03:00
|
|
|
s.streamID = int32(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, "", 3)))
|
2018-08-28 12:10:10 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.link.protocol&RTMP_FEATURE_WRITE != 0 {
|
2019-01-07 10:30:42 +03:00
|
|
|
sendPublish(s)
|
2018-09-06 11:33:55 +03:00
|
|
|
} else {
|
|
|
|
panic("Link protocol has no RTMP_FEATURE_WRITE")
|
2018-08-14 11:52:37 +03:00
|
|
|
}
|
2018-09-06 11:33:55 +03:00
|
|
|
|
2018-09-06 12:30:28 +03:00
|
|
|
case av_play, av_publish:
|
2018-09-06 11:33:55 +03:00
|
|
|
panic("Unsupported method av_play/av_publish")
|
2018-08-13 05:45:43 +03:00
|
|
|
}
|
2018-09-06 11:33:55 +03:00
|
|
|
//C.free(unsafe.Pointer(methodInvoked.av_val))
|
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av_onBWDone:
|
2019-01-07 08:50:35 +03:00
|
|
|
if s.bwCheckCounter == 0 {
|
2019-01-07 10:30:42 +03:00
|
|
|
sendCheckBW(s)
|
2018-08-14 16:00:47 +03:00
|
|
|
}
|
2018-08-28 12:10:10 +03:00
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av_onFCUnsubscribe, av_onFCSubscribe:
|
2018-08-28 12:10:10 +03:00
|
|
|
panic("Unsupported method av_onFCUnsubscribe/av_onFCSubscribe")
|
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av_ping:
|
2018-08-28 12:10:10 +03:00
|
|
|
panic("Unsupported method av_ping")
|
2018-08-28 12:48:13 +03:00
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av__onbwcheck:
|
2018-08-28 12:10:10 +03:00
|
|
|
panic("Unsupported method av_onbwcheck")
|
2018-08-28 12:48:13 +03:00
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av__onbwdone:
|
2018-08-28 12:10:10 +03:00
|
|
|
panic("Unsupported method av_onbwdone")
|
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av_close:
|
2018-08-28 12:10:10 +03:00
|
|
|
panic("Unsupported method av_close")
|
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av_onStatus:
|
2018-08-28 12:10:10 +03:00
|
|
|
var obj2 C_AMFObject
|
2018-09-06 10:00:39 +03:00
|
|
|
C_AMFProp_GetObject(C_AMF_GetProp(&obj, "", 3), &obj2)
|
2018-09-06 12:01:14 +03:00
|
|
|
code := C_AMFProp_GetString(C_AMF_GetProp(&obj2, av_code, -1))
|
2018-09-06 09:40:15 +03:00
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
level := C_AMFProp_GetString(C_AMF_GetProp(&obj2, av_level, -1)) // Not used.
|
2018-09-06 09:40:15 +03:00
|
|
|
_ = level
|
2018-08-28 12:10:10 +03:00
|
|
|
|
|
|
|
// TODO use new logger
|
|
|
|
// RTMP_Log(RTMP_LOGDEBUG, "%s, onStatus: %s", __FUNCTION__, code.av_val);
|
2018-09-06 11:33:55 +03:00
|
|
|
|
|
|
|
switch code {
|
2018-09-06 12:01:14 +03:00
|
|
|
case av_NetStream_Failed, av_NetStream_Play_Failed,
|
|
|
|
av_NetStream_Play_StreamNotFound, av_NetConnection_Connect_InvalidApp:
|
2018-08-28 12:10:10 +03:00
|
|
|
panic("Unsupported method av_NetStream/av_NetStream_Play_Failed/av_netSTream_Play_StreamNotFound/av_netConnection_Connect_invalidApp")
|
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av_NetStream_Play_Start, av_NetStream_Play_PublishNotify:
|
2018-08-28 12:10:10 +03:00
|
|
|
panic("Unsupported method av_NetStream_Play_Start/av_NetStream_Play_PublishNotify")
|
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av_NetStream_Publish_Start:
|
2019-01-07 08:50:35 +03:00
|
|
|
s.isPlaying = true
|
|
|
|
for i, m := range s.methodCalls {
|
2018-09-12 04:59:38 +03:00
|
|
|
if m.name == av_publish {
|
2019-01-07 10:30:42 +03:00
|
|
|
s.methodCalls = eraseMethod(s.methodCalls, i)
|
2018-08-14 11:52:37 +03:00
|
|
|
break
|
2018-08-13 05:45:43 +03:00
|
|
|
}
|
2018-08-14 11:52:37 +03:00
|
|
|
}
|
2018-08-28 12:10:10 +03:00
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av_NetStream_Play_Complete, av_NetStream_Play_Stop, av_NetStream_Play_UnpublishNotify:
|
2018-08-28 12:10:10 +03:00
|
|
|
panic("Unsupported method av_NetStream_Play_Complete/av_NetStream_Play_Stop/av_NetStream_Play_UnpublishNotify")
|
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av_NetStream_Seek_Notify:
|
2018-08-28 12:10:10 +03:00
|
|
|
panic("Unsupported method av_netStream_Seek_Notify")
|
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av_NetStream_Pause_Notify:
|
2018-08-28 12:10:10 +03:00
|
|
|
panic("Unsupported method av_NetStream_Pause_Notify")
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2018-08-28 12:10:10 +03:00
|
|
|
|
2018-09-06 12:01:14 +03:00
|
|
|
case av_playlist_ready:
|
2018-08-28 12:10:10 +03:00
|
|
|
panic("Unsupported method av_playlist_ready")
|
|
|
|
|
|
|
|
default:
|
2019-01-07 08:50:35 +03:00
|
|
|
panic(fmt.Sprintf("unknown method: %q", meth))
|
2018-08-14 21:49:18 +03:00
|
|
|
}
|
2018-08-24 12:20:04 +03:00
|
|
|
leave:
|
|
|
|
C_AMF_Reset(&obj)
|
2019-01-06 07:12:51 +03:00
|
|
|
return nil
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2018-08-14 21:49:18 +03:00
|
|
|
|
2019-01-07 14:15:00 +03:00
|
|
|
func handshake(s *Session) error {
|
2018-08-24 12:20:04 +03:00
|
|
|
var clientbuf [RTMP_SIG_SIZE + 1]byte
|
2018-09-19 08:27:13 +03:00
|
|
|
clientsig := clientbuf[1:]
|
|
|
|
|
2018-08-24 12:20:04 +03:00
|
|
|
var serversig [RTMP_SIG_SIZE]byte
|
2019-01-07 14:15:00 +03:00
|
|
|
clientbuf[0] = RTMP_CHANNEL_CONTROL
|
2019-01-07 10:30:42 +03:00
|
|
|
binary.BigEndian.PutUint32(clientsig, uint32(time.Now().UnixNano()/1000000))
|
2018-09-19 08:27:13 +03:00
|
|
|
copy(clientsig[4:8], []byte{0, 0, 0, 0})
|
2018-06-27 21:02:16 +03:00
|
|
|
|
2018-08-24 12:20:04 +03:00
|
|
|
for i := 8; i < RTMP_SIG_SIZE; i++ {
|
2018-09-19 08:27:13 +03:00
|
|
|
clientsig[i] = byte(rand.Intn(256))
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2018-07-10 13:36:49 +03:00
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
err := writeN(s, clientbuf[:])
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2018-07-12 22:51:17 +03:00
|
|
|
|
2018-09-19 08:27:13 +03:00
|
|
|
var typ [1]byte
|
2019-01-07 10:30:42 +03:00
|
|
|
err = readN(s, typ[:])
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2018-07-14 15:40:01 +03:00
|
|
|
|
2018-08-24 12:20:04 +03:00
|
|
|
if debugMode {
|
2019-01-07 10:30:42 +03:00
|
|
|
log.Printf("handshake: Type answer: %v\n", typ[0])
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2018-09-19 05:20:46 +03:00
|
|
|
if typ[0] != clientbuf[0] {
|
2019-01-07 10:30:42 +03:00
|
|
|
log.Printf("handshake: type mismatch: client sent %v, server sent: %v\n",
|
2018-08-24 12:20:04 +03:00
|
|
|
clientbuf[0], typ)
|
|
|
|
}
|
2019-01-07 10:30:42 +03:00
|
|
|
err = readN(s, serversig[:])
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-07-05 09:55:46 +03:00
|
|
|
}
|
|
|
|
|
2018-08-24 12:20:04 +03:00
|
|
|
// decode server response
|
2018-09-19 08:27:13 +03:00
|
|
|
suptime := binary.BigEndian.Uint32(serversig[:4])
|
|
|
|
_ = suptime
|
|
|
|
// RTMP_Log(RTMP_LOGDEBUG, "%s: Server Uptime : %d", __FUNCTION__, suptime)
|
|
|
|
// RTMP_Log(RTMP_LOGDEBUG, "%s: FMS Version : %d.%d.%d.%d", __FUNCTION__,
|
|
|
|
// serversig[4], serversig[5], serversig[6], serversig[7])
|
2018-08-11 07:18:21 +03:00
|
|
|
|
2018-08-24 12:20:04 +03:00
|
|
|
// 2nd part of handshake
|
2019-01-07 10:30:42 +03:00
|
|
|
err = writeN(s, serversig[:])
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-08-11 07:18:21 +03:00
|
|
|
}
|
2018-08-24 12:20:04 +03:00
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
err = readN(s, serversig[:])
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
|
|
|
|
2018-09-06 05:56:35 +03:00
|
|
|
if !bytes.Equal(serversig[:RTMP_SIG_SIZE], clientbuf[1:RTMP_SIG_SIZE+1]) {
|
|
|
|
log.Printf("Client signature does not match: %q != %q",
|
|
|
|
serversig[:RTMP_SIG_SIZE], clientbuf[1:RTMP_SIG_SIZE+1])
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2019-01-06 07:12:51 +03:00
|
|
|
return nil
|
2018-08-11 07:18:21 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:30:42 +03:00
|
|
|
// write prepares data to write then sends it.
|
|
|
|
func (s *Session) write(buf []byte) error {
|
2019-01-07 14:15:00 +03:00
|
|
|
pkt := packet{
|
|
|
|
channel: RTMP_CHANNEL_SOURCE,
|
|
|
|
info: s.streamID,
|
|
|
|
}
|
2018-09-15 04:55:07 +03:00
|
|
|
var enc []byte
|
2018-08-24 12:20:04 +03:00
|
|
|
|
2018-09-02 05:02:11 +03:00
|
|
|
for len(buf) != 0 {
|
2019-01-07 08:50:35 +03:00
|
|
|
if pkt.bytesRead == 0 {
|
2019-01-07 14:15:00 +03:00
|
|
|
if len(buf) < minDataSize {
|
2019-01-06 07:12:51 +03:00
|
|
|
return errTinyPacket
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
|
|
|
|
2018-09-01 16:53:07 +03:00
|
|
|
if buf[0] == 'F' && buf[1] == 'L' && buf[2] == 'V' {
|
|
|
|
buf = buf[13:]
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 06:03:07 +03:00
|
|
|
pkt.packetType = buf[0]
|
2018-09-01 16:53:07 +03:00
|
|
|
buf = buf[1:]
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.bodySize = C_AMF_DecodeInt24(buf[:3])
|
2018-09-01 16:53:07 +03:00
|
|
|
buf = buf[3:]
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.timestamp = C_AMF_DecodeInt24(buf[:3])
|
2018-09-01 16:53:07 +03:00
|
|
|
buf = buf[3:]
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.timestamp |= uint32(buf[0]) << 24
|
2018-09-01 16:53:07 +03:00
|
|
|
buf = buf[4:]
|
2018-08-24 12:20:04 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
headerType := uint8(RTMP_PACKET_SIZE_MEDIUM)
|
2019-01-07 06:03:07 +03:00
|
|
|
switch pkt.packetType {
|
|
|
|
case RTMP_PACKET_TYPE_VIDEO, RTMP_PACKET_TYPE_AUDIO:
|
2019-01-07 08:50:35 +03:00
|
|
|
if pkt.timestamp == 0 {
|
|
|
|
headerType = RTMP_PACKET_SIZE_LARGE
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2019-01-07 06:03:07 +03:00
|
|
|
case RTMP_PACKET_TYPE_INFO:
|
2019-01-07 08:50:35 +03:00
|
|
|
headerType = RTMP_PACKET_SIZE_LARGE
|
|
|
|
pkt.bodySize += 16
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2019-01-07 06:03:07 +03:00
|
|
|
|
2019-01-07 12:46:11 +03:00
|
|
|
resizePacket(&pkt, pkt.bodySize, headerType)
|
2018-08-24 12:20:04 +03:00
|
|
|
|
2019-01-07 08:50:35 +03:00
|
|
|
enc = pkt.body[:pkt.bodySize]
|
2019-01-07 06:03:07 +03:00
|
|
|
if pkt.packetType == RTMP_PACKET_TYPE_INFO {
|
2018-09-15 04:55:07 +03:00
|
|
|
enc = C_AMF_EncodeString(enc, setDataFrame)
|
2019-01-06 07:49:58 +03:00
|
|
|
if enc == nil {
|
|
|
|
return errEncoding
|
|
|
|
}
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.bytesRead = uint32(len(pkt.body) - len(enc))
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2019-01-07 08:50:35 +03:00
|
|
|
enc = pkt.body[:pkt.bodySize][pkt.bytesRead:]
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2019-01-07 14:15:00 +03:00
|
|
|
num := int(pkt.bodySize - pkt.bytesRead)
|
2018-09-02 05:02:11 +03:00
|
|
|
if num > len(buf) {
|
|
|
|
num = len(buf)
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
|
|
|
|
2018-09-01 16:53:07 +03:00
|
|
|
copy(enc[:num], buf[:num])
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.bytesRead += uint32(num)
|
2018-09-01 16:53:07 +03:00
|
|
|
buf = buf[num:]
|
2019-01-07 08:50:35 +03:00
|
|
|
if pkt.bytesRead == pkt.bodySize {
|
2019-01-07 14:15:00 +03:00
|
|
|
err := sendPacket(s, &pkt, false)
|
2019-01-07 08:50:35 +03:00
|
|
|
pkt.body = nil
|
|
|
|
pkt.bytesRead = 0
|
2019-01-06 07:12:51 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
2018-09-02 07:01:52 +03:00
|
|
|
if len(buf) < 4 {
|
2019-01-06 07:12:51 +03:00
|
|
|
return nil
|
2018-09-02 07:01:52 +03:00
|
|
|
}
|
2018-09-01 16:53:07 +03:00
|
|
|
buf = buf[4:]
|
2018-08-24 12:20:04 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-06 07:12:51 +03:00
|
|
|
return nil
|
2018-07-15 12:26:59 +03:00
|
|
|
}
|