Browse Source

- 接入go mod

- 接入docker
- 接入github action自动发布和测试
pull/83/head
吴浩麟 6 years ago
parent
commit
74da8bec14
  1. 27
      .github/workflows/release.yml
  2. 22
      .github/workflows/test.yml
  3. 16
      .goreleaser.yml
  4. 9
      .livego.json
  5. 19
      Dockerfile
  6. 21
      README.md
  7. 6
      av/av.go
  8. 6
      av/rwbase.go
  9. 1
      container/flv/demuxer.go
  10. 18
      container/flv/muxer.go
  11. 1
      container/flv/tag.go
  12. 5
      container/ts/muxer.go
  13. 31
      container/ts/muxer_test.go
  14. 11
      go.mod
  15. 11
      goreleaser.yml
  16. 10
      livego.cfg
  17. 9
      main.go
  18. 1
      parser/aac/parser.go
  19. 6
      parser/h264/parser.go
  20. 9
      parser/h264/parser_test.go
  21. 5
      parser/parser.go
  22. 18
      protocol/amf/decoder_amf3_test.go
  23. 18
      protocol/amf/encoder_amf3_test.go
  24. 3
      protocol/hls/hls.go
  25. 9
      protocol/hls/source.go
  26. 5
      protocol/httpflv/server.go
  27. 7
      protocol/httpflv/writer.go
  28. 5
      protocol/httpopera/http_opera.go
  29. 1
      protocol/rtmp/cache/cache.go
  30. 1
      protocol/rtmp/cache/gop.go
  31. 2
      protocol/rtmp/cache/special.go
  32. 4
      protocol/rtmp/core/chunk_stream.go
  33. 2
      protocol/rtmp/core/chunk_stream_test.go
  34. 5
      protocol/rtmp/core/conn.go
  35. 5
      protocol/rtmp/core/conn_client.go
  36. 5
      protocol/rtmp/core/conn_server.go
  37. 5
      protocol/rtmp/core/conn_test.go
  38. 6
      protocol/rtmp/core/handshake.go
  39. 17
      protocol/rtmp/rtmp.go
  40. 5
      protocol/rtmp/rtmprelay/rtmprelay.go
  41. 5
      protocol/rtmp/rtmprelay/staticrelay.go
  42. 7
      protocol/rtmp/stream.go
  43. 2
      utils/pool/pool.go
  44. 1
      utils/queue/queue.go
  45. 3
      utils/uid/uuid.go

27
.github/workflows/release.yml

@ -0,0 +1,27 @@
name: release
on:
release:
types: [published]
jobs:
goreleaser:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Get dependencies
run: go mod tidy
- name: Go release
uses: goreleaser/goreleaser-action@v1
- name: Docker release
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: gwuhaolin/livego
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

22
.github/workflows/test.yml

@ -0,0 +1,22 @@
name: Test
on: [push]
jobs:
test:
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Get dependencies
run: go mod tidy
- name: Test
run: go test ./...

16
.goreleaser.yml

@ -0,0 +1,16 @@
before:
hooks:
- go mod tidy
builds:
- binary: livego
id: livego
main: ./main.go
goos:
- windows
- darwin
- linux
- freebsd
goarch:
- amd64
- 386
- arm

9
.livego.json

@ -0,0 +1,9 @@
{
"server": [
{
"appname": "live",
"liveon": "on",
"hlson": "on"
}
]
}

19
Dockerfile

@ -0,0 +1,19 @@
FROM golang:latest as builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o livego ./
FROM alpine:latest
LABEL maintainer="gwuhaolin <gwuhaolin@gmail.com>"
ENV RTMP_PORT 1935
ENV HTTP_FLV_PORT 7001
ENV HLS_PORT 7002
ENV HTTP_OPERATION_PORT 8090
COPY --from=builder /app/livego .
EXPOSE ${RTMP_PORT}
EXPOSE ${HTTP_FLV_PORT}
EXPOSE ${HLS_PORT}
EXPOSE ${HTTP_OPERATION_PORT}
CMD ./livego

21
README.md

@ -5,23 +5,26 @@
- 支持常用的传输协议、文件格式、编码格式; - 支持常用的传输协议、文件格式、编码格式;
#### 支持的传输协议 #### 支持的传输协议
- [x] RTMP - RTMP
- [x] AMF - AMF
- [x] HLS - HLS
- [x] HTTP-FLV - HTTP-FLV
#### 支持的容器格式 #### 支持的容器格式
- [x] FLV - FLV
- [x] TS - TS
#### 支持的编码格式 #### 支持的编码格式
- [x] H264 - H264
- [x] AAC - AAC
- [x] MP3 - MP3
## 安装 ## 安装
直接下载编译好的[二进制文件](https://github.com/gwuhaolin/livego/releases)后,在命令行中执行。 直接下载编译好的[二进制文件](https://github.com/gwuhaolin/livego/releases)后,在命令行中执行。
#### 从 Docker 启动
执行`docker run -p 1935:1935 -p 7001:7001 -p 7002:7002 -d --name livego gwuhaolin/livego`启动
#### 从源码编译 #### 从源码编译
1. 下载源码 `git clone https://github.com/gwuhaolin/livego.git` 1. 下载源码 `git clone https://github.com/gwuhaolin/livego.git`
2. 去 livego 目录中 执行 `go build` 2. 去 livego 目录中 执行 `go build`

6
av/av.go

@ -1,7 +1,9 @@
package av package av
import "io" import (
import "fmt" "fmt"
"io"
)
const ( const (
TAG_AUDIO = 8 TAG_AUDIO = 8

6
av/rwbase.go

@ -1,7 +1,9 @@
package av package av
import "time" import (
import "sync" "sync"
"time"
)
type RWBaser struct { type RWBaser struct {
lock sync.Mutex lock sync.Mutex

1
container/flv/demuxer.go

@ -2,6 +2,7 @@ package flv
import ( import (
"errors" "errors"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
) )

18
container/flv/muxer.go

@ -1,16 +1,17 @@
package flv package flv
import ( import (
"strings"
"time"
"flag" "flag"
"os"
"log"
"fmt" "fmt"
"github.com/gwuhaolin/livego/utils/uid" "log"
"github.com/gwuhaolin/livego/protocol/amf" "os"
"strings"
"time"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/protocol/amf"
"github.com/gwuhaolin/livego/utils/pio" "github.com/gwuhaolin/livego/utils/pio"
"github.com/gwuhaolin/livego/utils/uid"
) )
var ( var (
@ -46,7 +47,7 @@ const (
) )
type FLVWriter struct { type FLVWriter struct {
Uid string Uid string
av.RWBaser av.RWBaser
app, title, url string app, title, url string
buf []byte buf []byte
@ -137,6 +138,7 @@ func (writer *FLVWriter) Info() (ret av.Info) {
ret.Key = writer.app + "/" + writer.title ret.Key = writer.app + "/" + writer.title
return return
} }
type FlvDvr struct{} type FlvDvr struct{}
func (f *FlvDvr) GetWriter(info av.Info) av.WriteCloser { func (f *FlvDvr) GetWriter(info av.Info) av.WriteCloser {
@ -164,4 +166,4 @@ func (f *FlvDvr) GetWriter(info av.Info) av.WriteCloser {
writer := NewFLVWriter(paths[0], paths[1], info.URL, w) writer := NewFLVWriter(paths[0], paths[1], info.URL, w)
log.Println("new flv dvr: ", writer.Info()) log.Println("new flv dvr: ", writer.Info())
return writer return writer
} }

1
container/flv/tag.go

@ -2,6 +2,7 @@ package flv
import ( import (
"fmt" "fmt"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
) )

5
container/ts/muxer.go

@ -2,6 +2,7 @@ package ts
import ( import (
"io" "io"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
) )
@ -207,7 +208,7 @@ func (muxer *Muxer) PMT(soundFormat byte, hasVideo bool) []byte {
progInfo = []byte{0x0f, 0xe1, 0x01, 0xf0, 0x00} progInfo = []byte{0x0f, 0xe1, 0x01, 0xf0, 0x00}
} else { } else {
progInfo = []byte{0x1b, 0xe1, 0x00, 0xf0, 0x00, //h264 or h265* progInfo = []byte{0x1b, 0xe1, 0x00, 0xf0, 0x00, //h264 or h265*
0x0f, 0xe1, 0x01, 0xf0, 0x00, //mp3 or aac 0x0f, 0xe1, 0x01, 0xf0, 0x00, //mp3 or aac
} }
} }
pmtHeader[2] = byte(len(progInfo) + 9 + 4) pmtHeader[2] = byte(len(progInfo) + 9 + 4)
@ -236,7 +237,7 @@ func (muxer *Muxer) PMT(soundFormat byte, hasVideo bool) []byte {
copy(muxer.pmt[i:], progInfo[0:]) copy(muxer.pmt[i:], progInfo[0:])
i += len(progInfo) i += len(progInfo)
crc32Value := GenCrc32(muxer.pmt[5: 5+len(pmtHeader)+len(progInfo)]) crc32Value := GenCrc32(muxer.pmt[5 : 5+len(pmtHeader)+len(progInfo)])
muxer.pmt[i] = byte(crc32Value >> 24) muxer.pmt[i] = byte(crc32Value >> 24)
i++ i++
muxer.pmt[i] = byte(crc32Value >> 16) muxer.pmt[i] = byte(crc32Value >> 16)

31
container/ts/muxer_test.go

@ -2,6 +2,7 @@ package ts
import ( import (
"testing" "testing"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -24,8 +25,8 @@ func TestTSEncoder(t *testing.T) {
w := &TestWriter{} w := &TestWriter{}
data := []byte{0xaf, 0x01, 0x21, 0x19, 0xd3, 0x40, 0x7d, 0x0b, 0x6d, 0x44, 0xae, 0x81, data := []byte{0xaf, 0x01, 0x21, 0x19, 0xd3, 0x40, 0x7d, 0x0b, 0x6d, 0x44, 0xae, 0x81,
0x08, 0x00, 0x89, 0xa0, 0x3e, 0x85, 0xb6, 0x92, 0x57, 0x04, 0x80, 0x00, 0x5b, 0xb7, 0x08, 0x00, 0x89, 0xa0, 0x3e, 0x85, 0xb6, 0x92, 0x57, 0x04, 0x80, 0x00, 0x5b, 0xb7,
0x78, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x30, 0x00, 0x06, 0x00, 0x38, 0x78, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x30, 0x00, 0x06, 0x00, 0x38,
} }
p := av.Packet{ p := av.Packet{
IsVideo: false, IsVideo: false,
@ -35,17 +36,17 @@ func TestTSEncoder(t *testing.T) {
at.Equal(err, nil) at.Equal(err, nil)
at.Equal(w.count, 1) at.Equal(w.count, 1)
at.Equal(w.buf, []byte{0x47, 0x41, 0x01, 0x31, 0x81, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, at.Equal(w.buf, []byte{0x47, 0x41, 0x01, 0x31, 0x81, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x30, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x30,
0x80, 0x80, 0x05, 0x21, 0x00, 0x01, 0x00, 0x01, 0xaf, 0x01, 0x21, 0x19, 0xd3, 0x40, 0x7d, 0x80, 0x80, 0x05, 0x21, 0x00, 0x01, 0x00, 0x01, 0xaf, 0x01, 0x21, 0x19, 0xd3, 0x40, 0x7d,
0x0b, 0x6d, 0x44, 0xae, 0x81, 0x08, 0x00, 0x89, 0xa0, 0x3e, 0x85, 0xb6, 0x92, 0x57, 0x04, 0x0b, 0x6d, 0x44, 0xae, 0x81, 0x08, 0x00, 0x89, 0xa0, 0x3e, 0x85, 0xb6, 0x92, 0x57, 0x04,
0x80, 0x00, 0x5b, 0xb7, 0x78, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x30, 0x00, 0x80, 0x00, 0x5b, 0xb7, 0x78, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x30, 0x00,
0x06, 0x00, 0x38}) 0x06, 0x00, 0x38})
} }

11
go.mod

@ -0,0 +1,11 @@
module github.com/gwuhaolin/livego
go 1.13
require (
github.com/kr/pretty v0.1.0 // indirect
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6
github.com/satori/go.uuid v1.2.0
github.com/stretchr/testify v1.4.0
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)

11
goreleaser.yml

@ -1,11 +0,0 @@
build:
binary: livego
goos:
- windows
- darwin
- linux
- freebsd
goarch:
- amd64
- 386
- arm

10
livego.cfg

@ -1,10 +0,0 @@
{
"server": [
{
"appname":"live",
"liveon":"on",
"hlson":"on"
}
]
}

9
livego.go → main.go

@ -2,14 +2,15 @@ package main
import ( import (
"flag" "flag"
"log"
"net"
"time"
"github.com/gwuhaolin/livego/configure" "github.com/gwuhaolin/livego/configure"
"github.com/gwuhaolin/livego/protocol/hls" "github.com/gwuhaolin/livego/protocol/hls"
"github.com/gwuhaolin/livego/protocol/httpflv" "github.com/gwuhaolin/livego/protocol/httpflv"
"github.com/gwuhaolin/livego/protocol/httpopera" "github.com/gwuhaolin/livego/protocol/httpopera"
"github.com/gwuhaolin/livego/protocol/rtmp" "github.com/gwuhaolin/livego/protocol/rtmp"
"log"
"net"
"time"
) )
var ( var (
@ -18,7 +19,7 @@ var (
httpFlvAddr = flag.String("httpflv-addr", ":7001", "HTTP-FLV server listen address") httpFlvAddr = flag.String("httpflv-addr", ":7001", "HTTP-FLV server listen address")
hlsAddr = flag.String("hls-addr", ":7002", "HLS server listen address") hlsAddr = flag.String("hls-addr", ":7002", "HLS server listen address")
operaAddr = flag.String("manage-addr", ":8090", "HTTP manage interface server listen address") operaAddr = flag.String("manage-addr", ":8090", "HTTP manage interface server listen address")
configfilename = flag.String("cfgfile", "livego.cfg", "live configure filename") configfilename = flag.String("cfgfile", ".livego.json", "configure filename")
) )
func init() { func init() {

1
parser/aac/parser.go

@ -3,6 +3,7 @@ package aac
import ( import (
"errors" "errors"
"io" "io"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
) )

6
parser/h264/parser.go

@ -98,7 +98,7 @@ func (parser *Parser) parseSpecificInfo(src []byte) error {
return spsDataError return spsDataError
} }
sps = append(sps, startCode...) sps = append(sps, startCode...)
sps = append(sps, src[8:(8 + seq.spsLen)]...) sps = append(sps, src[8:(8+seq.spsLen)]...)
//get pps //get pps
tmpBuf := src[(8 + seq.spsLen):] tmpBuf := src[(8 + seq.spsLen):]
@ -190,7 +190,7 @@ func (parser *Parser) getAnnexbH264(src []byte, w io.Writer) error {
if err != nil { if err != nil {
return err return err
} }
_, err = w.Write(src[index: index+nalLen]) _, err = w.Write(src[index : index+nalLen])
if err != nil { if err != nil {
return err return err
} }
@ -202,7 +202,7 @@ func (parser *Parser) getAnnexbH264(src []byte, w io.Writer) error {
if err != nil { if err != nil {
return err return err
} }
_, err = parser.pps.Write(src[index: index+nalLen]) _, err = parser.pps.Write(src[index : index+nalLen])
if err != nil { if err != nil {
return err return err
} }

9
parser/h264/parser_test.go

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"errors" "errors"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -20,8 +21,8 @@ func TestH264SeqDemux(t *testing.T) {
err := d.Parse(seq, true, w) err := d.Parse(seq, true, w)
at.Equal(err, nil) at.Equal(err, nil)
at.Equal(d.specificInfo, []byte{0x00, 0x00, 0x00, 0x01, 0x67, 0x4d, 0x00, at.Equal(d.specificInfo, []byte{0x00, 0x00, 0x00, 0x01, 0x67, 0x4d, 0x00,
0x1e, 0xab, 0x40, 0x5a, 0x12, 0x6c, 0x09, 0x28, 0x28, 0x28, 0x2f, 0x1e, 0xab, 0x40, 0x5a, 0x12, 0x6c, 0x09, 0x28, 0x28, 0x28, 0x2f,
0x80, 0x00, 0x01, 0xf4, 0x00, 0x00, 0x61, 0xa8, 0x4a, 0x00, 0x00, 0x00, 0x01, 0x68, 0xde, 0x31, 0x12}) 0x80, 0x00, 0x01, 0xf4, 0x00, 0x00, 0x61, 0xa8, 0x4a, 0x00, 0x00, 0x00, 0x01, 0x68, 0xde, 0x31, 0x12})
} }
func TestH264AnnexbDemux(t *testing.T) { func TestH264AnnexbDemux(t *testing.T) {
@ -62,8 +63,8 @@ func TestH264Mp4Demux(t *testing.T) {
at.Equal(err, nil) at.Equal(err, nil)
at.Equal(w.Len(), 47) at.Equal(w.Len(), 47)
at.Equal(w.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x09, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x67, 0x4d, 0x00, 0x1e, 0xab, 0x40, 0x5a, 0x12, 0x6c, 0x09, 0x28, 0x28, at.Equal(w.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x09, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x67, 0x4d, 0x00, 0x1e, 0xab, 0x40, 0x5a, 0x12, 0x6c, 0x09, 0x28, 0x28,
0x28, 0x2f, 0x80, 0x00, 0x01, 0xf4, 0x00, 0x00, 0x61, 0xa8, 0x4a, 0x00, 0x00, 0x00, 0x01, 0x68, 0x28, 0x2f, 0x80, 0x00, 0x01, 0xf4, 0x00, 0x00, 0x61, 0xa8, 0x4a, 0x00, 0x00, 0x00, 0x01, 0x68,
0xde, 0x31, 0x12, 0x00, 0x00, 0x00, 0x01, 0x65, 0x23}) 0xde, 0x31, 0x12, 0x00, 0x00, 0x00, 0x01, 0x65, 0x23})
} }
func TestH264Mp4DemuxException1(t *testing.T) { func TestH264Mp4DemuxException1(t *testing.T) {

5
parser/parser.go

@ -3,10 +3,11 @@ package parser
import ( import (
"errors" "errors"
"io" "io"
"github.com/gwuhaolin/livego/parser/mp3"
"github.com/gwuhaolin/livego/parser/aac"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/parser/aac"
"github.com/gwuhaolin/livego/parser/h264" "github.com/gwuhaolin/livego/parser/h264"
"github.com/gwuhaolin/livego/parser/mp3"
) )
var ( var (

18
protocol/amf/decoder_amf3_test.go

@ -166,15 +166,15 @@ func TestDecodeAmf3String(t *testing.T) {
func TestDecodeAmf3Array(t *testing.T) { func TestDecodeAmf3Array(t *testing.T) {
buf := bytes.NewReader([]byte{0x09, 0x13, 0x01, buf := bytes.NewReader([]byte{0x09, 0x13, 0x01,
0x06, 0x03, '1', 0x06, 0x03, '1',
0x06, 0x03, '2', 0x06, 0x03, '2',
0x06, 0x03, '3', 0x06, 0x03, '3',
0x06, 0x03, '4', 0x06, 0x03, '4',
0x06, 0x03, '5', 0x06, 0x03, '5',
0x06, 0x03, '6', 0x06, 0x03, '6',
0x06, 0x03, '7', 0x06, 0x03, '7',
0x06, 0x03, '8', 0x06, 0x03, '8',
0x06, 0x03, '9', 0x06, 0x03, '9',
}) })
dec := new(Decoder) dec := new(Decoder)

18
protocol/amf/encoder_amf3_test.go

@ -151,15 +151,15 @@ func TestEncodeAmf3Array(t *testing.T) {
enc := new(Encoder) enc := new(Encoder)
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
expect := []byte{0x09, 0x13, 0x01, expect := []byte{0x09, 0x13, 0x01,
0x06, 0x03, '1', 0x06, 0x03, '1',
0x06, 0x03, '2', 0x06, 0x03, '2',
0x06, 0x03, '3', 0x06, 0x03, '3',
0x06, 0x03, '4', 0x06, 0x03, '4',
0x06, 0x03, '5', 0x06, 0x03, '5',
0x06, 0x03, '6', 0x06, 0x03, '6',
0x06, 0x03, '7', 0x06, 0x03, '7',
0x06, 0x03, '8', 0x06, 0x03, '8',
0x06, 0x03, '9', 0x06, 0x03, '9',
} }
arr := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9"} arr := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9"}

3
protocol/hls/hls.go

@ -3,13 +3,14 @@ package hls
import ( import (
"errors" "errors"
"fmt" "fmt"
"log"
"net" "net"
"net/http" "net/http"
"path" "path"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"log"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
"github.com/orcaman/concurrent-map" "github.com/orcaman/concurrent-map"
) )

9
protocol/hls/source.go

@ -1,15 +1,16 @@
package hls package hls
import ( import (
"fmt"
"time"
"bytes" "bytes"
"log"
"errors" "errors"
"github.com/gwuhaolin/livego/parser" "fmt"
"log"
"time"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/container/flv" "github.com/gwuhaolin/livego/container/flv"
"github.com/gwuhaolin/livego/container/ts" "github.com/gwuhaolin/livego/container/ts"
"github.com/gwuhaolin/livego/parser"
) )
const ( const (

5
protocol/httpflv/server.go

@ -2,12 +2,13 @@ package httpflv
import ( import (
"encoding/json" "encoding/json"
"github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/protocol/rtmp"
"log" "log"
"net" "net"
"net/http" "net/http"
"strings" "strings"
"github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/protocol/rtmp"
) )
type Server struct { type Server struct {

7
protocol/httpflv/writer.go

@ -1,15 +1,16 @@
package httpflv package httpflv
import ( import (
"time"
"errors" "errors"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"github.com/gwuhaolin/livego/utils/uid" "time"
"github.com/gwuhaolin/livego/protocol/amf"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/protocol/amf"
"github.com/gwuhaolin/livego/utils/pio" "github.com/gwuhaolin/livego/utils/pio"
"github.com/gwuhaolin/livego/utils/uid"
) )
const ( const (

5
protocol/httpopera/http_opera.go

@ -3,13 +3,14 @@ package httpopera
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/gwuhaolin/livego/protocol/rtmp/rtmprelay"
"io" "io"
"log"
"net" "net"
"net/http" "net/http"
"log"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/protocol/rtmp" "github.com/gwuhaolin/livego/protocol/rtmp"
"github.com/gwuhaolin/livego/protocol/rtmp/rtmprelay"
) )
type Response struct { type Response struct {

1
protocol/rtmp/cache/cache.go vendored

@ -2,6 +2,7 @@ package cache
import ( import (
"flag" "flag"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
) )

1
protocol/rtmp/cache/gop.go vendored

@ -2,6 +2,7 @@ package cache
import ( import (
"errors" "errors"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
) )

2
protocol/rtmp/cache/special.go vendored

@ -4,8 +4,8 @@ import (
"bytes" "bytes"
"log" "log"
"github.com/gwuhaolin/livego/protocol/amf"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/protocol/amf"
) )
const ( const (

4
protocol/rtmp/core/chunk_stream.go

@ -73,7 +73,7 @@ func (chunkStream *ChunkStream) writeHeader(w *ReadWriter) error {
} }
w.WriteUintLE(chunkStream.StreamID, 4) w.WriteUintLE(chunkStream.StreamID, 4)
END: END:
//Extended Timestamp //Extended Timestamp
if ts >= 0xffffff { if ts >= 0xffffff {
w.WriteUintBE(chunkStream.Timestamp, 4) w.WriteUintBE(chunkStream.Timestamp, 4)
} }
@ -211,7 +211,7 @@ func (chunkStream *ChunkStream) readChunk(r *ReadWriter, chunkSize uint32, pool
size = int(chunkSize) size = int(chunkSize)
} }
buf := chunkStream.Data[chunkStream.index: chunkStream.index+uint32(size)] buf := chunkStream.Data[chunkStream.index : chunkStream.index+uint32(size)]
if _, err := r.Read(buf); err != nil { if _, err := r.Read(buf); err != nil {
return err return err
} }

2
protocol/rtmp/core/chunk_stream_test.go

@ -4,8 +4,8 @@ import (
"bytes" "bytes"
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/gwuhaolin/livego/utils/pool" "github.com/gwuhaolin/livego/utils/pool"
"github.com/stretchr/testify/assert"
) )
func TestChunkRead1(t *testing.T) { func TestChunkRead1(t *testing.T) {

5
protocol/rtmp/core/conn.go

@ -4,12 +4,13 @@ import (
"encoding/binary" "encoding/binary"
"net" "net"
"time" "time"
"github.com/gwuhaolin/livego/utils/pool"
"github.com/gwuhaolin/livego/utils/pio" "github.com/gwuhaolin/livego/utils/pio"
"github.com/gwuhaolin/livego/utils/pool"
) )
const ( const (
_ = iota _ = iota
idSetChunkSize idSetChunkSize
idAbortMessage idAbortMessage
idAck idAck

5
protocol/rtmp/core/conn_client.go

@ -10,9 +10,10 @@ import (
neturl "net/url" neturl "net/url"
"strings" "strings"
"github.com/gwuhaolin/livego/protocol/amf"
"github.com/gwuhaolin/livego/av"
"log" "log"
"github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/protocol/amf"
) )
var ( var (

5
protocol/rtmp/core/conn_server.go

@ -5,9 +5,10 @@ import (
"errors" "errors"
"io" "io"
"github.com/gwuhaolin/livego/protocol/amf"
"github.com/gwuhaolin/livego/av"
"log" "log"
"github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/protocol/amf"
) )
var ( var (

5
protocol/rtmp/core/conn_test.go

@ -4,8 +4,9 @@ import (
"bytes" "bytes"
"io" "io"
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/gwuhaolin/livego/utils/pool" "github.com/gwuhaolin/livego/utils/pool"
"github.com/stretchr/testify/assert"
) )
func TestConnReadNormal(t *testing.T) { func TestConnReadNormal(t *testing.T) {
@ -176,7 +177,7 @@ func TestSetChunksize(t *testing.T) {
//设置chunksize //设置chunksize
chunkBuf := []byte{0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, chunkBuf := []byte{0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x96} 0x00, 0x00, 0x00, 0x96}
conn.rw = NewReadWriter(bytes.NewBuffer(chunkBuf), 1024) conn.rw = NewReadWriter(bytes.NewBuffer(chunkBuf), 1024)
err = conn.Read(&c) err = conn.Read(&c)
at.Equal(err, nil) at.Equal(err, nil)

6
protocol/rtmp/core/handshake.go

@ -124,7 +124,7 @@ func (conn *Conn) HandshakeClient() (err error) {
return return
} }
S1 := S0S1S2[1: 1536+1] S1 := S0S1S2[1 : 1536+1]
if ver := pio.U32BE(S1[4:8]); ver != 0 { if ver := pio.U32BE(S1[4:8]); ver != 0 {
C2 = S1 C2 = S1
} else { } else {
@ -145,13 +145,13 @@ func (conn *Conn) HandshakeServer() (err error) {
C0C1C2 := random[:1536*2+1] C0C1C2 := random[:1536*2+1]
C0 := C0C1C2[:1] C0 := C0C1C2[:1]
C1 := C0C1C2[1: 1536+1] C1 := C0C1C2[1 : 1536+1]
C0C1 := C0C1C2[:1536+1] C0C1 := C0C1C2[:1536+1]
C2 := C0C1C2[1536+1:] C2 := C0C1C2[1536+1:]
S0S1S2 := random[1536*2+1:] S0S1S2 := random[1536*2+1:]
S0 := S0S1S2[:1] S0 := S0S1S2[:1]
S1 := S0S1S2[1: 1536+1] S1 := S0S1S2[1 : 1536+1]
S0S1 := S0S1S2[:1536+1] S0S1 := S0S1S2[:1536+1]
S2 := S0S1S2[1536+1:] S2 := S0S1S2[1536+1:]

17
protocol/rtmp/rtmp.go

@ -4,17 +4,18 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/configure"
"github.com/gwuhaolin/livego/container/flv"
"github.com/gwuhaolin/livego/protocol/rtmp/core"
"github.com/gwuhaolin/livego/utils/uid"
"log" "log"
"net" "net"
"net/url" "net/url"
"reflect" "reflect"
"strings" "strings"
"time" "time"
"github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/configure"
"github.com/gwuhaolin/livego/container/flv"
"github.com/gwuhaolin/livego/protocol/rtmp/core"
"github.com/gwuhaolin/livego/utils/uid"
) )
const ( const (
@ -134,7 +135,7 @@ func (s *Server) handleConn(conn *core.Conn) error {
writer := s.getter.GetWriter(reader.Info()) writer := s.getter.GetWriter(reader.Info())
s.handler.HandleWriter(writer) s.handler.HandleWriter(writer)
} }
flvWriter:=new(flv.FlvDvr) flvWriter := new(flv.FlvDvr)
s.handler.HandleWriter(flvWriter.GetWriter(reader.Info())) s.handler.HandleWriter(flvWriter.GetWriter(reader.Info()))
} else { } else {
writer := NewVirWriter(connServer) writer := NewVirWriter(connServer)
@ -286,7 +287,7 @@ func (v *VirWriter) Write(p *av.Packet) (err error) {
} }
func (v *VirWriter) SendPacket() error { func (v *VirWriter) SendPacket() error {
Flush := reflect.ValueOf(v.conn).MethodByName("Flush"); Flush := reflect.ValueOf(v.conn).MethodByName("Flush")
var cs core.ChunkStream var cs core.ChunkStream
for { for {
p, ok := <-v.packetQueue p, ok := <-v.packetQueue
@ -315,7 +316,7 @@ func (v *VirWriter) SendPacket() error {
v.closed = true v.closed = true
return err return err
} }
Flush.Call(nil); Flush.Call(nil)
} else { } else {
return errors.New("closed") return errors.New("closed")
} }

5
protocol/rtmp/rtmprelay/rtmprelay.go

@ -4,10 +4,11 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/gwuhaolin/livego/protocol/amf"
"github.com/gwuhaolin/livego/protocol/rtmp/core"
"io" "io"
"log" "log"
"github.com/gwuhaolin/livego/protocol/amf"
"github.com/gwuhaolin/livego/protocol/rtmp/core"
) )
var ( var (

5
protocol/rtmp/rtmprelay/staticrelay.go

@ -3,11 +3,12 @@ package rtmprelay
import ( import (
"errors" "errors"
"fmt" "fmt"
"log"
"sync"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/configure" "github.com/gwuhaolin/livego/configure"
"github.com/gwuhaolin/livego/protocol/rtmp/core" "github.com/gwuhaolin/livego/protocol/rtmp/core"
"log"
"sync"
) )
type StaticPush struct { type StaticPush struct {

7
protocol/rtmp/stream.go

@ -2,13 +2,14 @@ package rtmp
import ( import (
"errors" "errors"
"log"
"strings"
"time"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/protocol/rtmp/cache" "github.com/gwuhaolin/livego/protocol/rtmp/cache"
"github.com/gwuhaolin/livego/protocol/rtmp/rtmprelay" "github.com/gwuhaolin/livego/protocol/rtmp/rtmprelay"
"github.com/orcaman/concurrent-map" "github.com/orcaman/concurrent-map"
"log"
"strings"
"time"
) )
var ( var (

2
utils/pool/pool.go

@ -12,7 +12,7 @@ func (pool *Pool) Get(size int) []byte {
pool.pos = 0 pool.pos = 0
pool.buf = make([]byte, maxpoolsize) pool.buf = make([]byte, maxpoolsize)
} }
b := pool.buf[pool.pos: pool.pos+size] b := pool.buf[pool.pos : pool.pos+size]
pool.pos += size pool.pos += size
return b return b
} }

1
utils/queue/queue.go

@ -2,6 +2,7 @@ package queue
import ( import (
"sync" "sync"
"github.com/gwuhaolin/livego/av" "github.com/gwuhaolin/livego/av"
) )

3
utils/uid/uuid.go

@ -2,11 +2,12 @@ package uid
import ( import (
"encoding/base64" "encoding/base64"
"github.com/satori/go.uuid" "github.com/satori/go.uuid"
) )
func NewId() string { func NewId() string {
id, _ := uuid.NewV4() id := uuid.NewV4()
b64 := base64.URLEncoding.EncodeToString(id.Bytes()[:12]) b64 := base64.URLEncoding.EncodeToString(id.Bytes()[:12])
return b64 return b64
} }

Loading…
Cancel
Save