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. 14
      container/flv/muxer.go
  11. 1
      container/flv/tag.go
  12. 1
      container/ts/muxer.go
  13. 1
      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. 1
      parser/h264/parser_test.go
  20. 5
      parser/parser.go
  21. 3
      protocol/hls/hls.go
  22. 9
      protocol/hls/source.go
  23. 5
      protocol/httpflv/server.go
  24. 7
      protocol/httpflv/writer.go
  25. 5
      protocol/httpopera/http_opera.go
  26. 1
      protocol/rtmp/cache/cache.go
  27. 1
      protocol/rtmp/cache/gop.go
  28. 2
      protocol/rtmp/cache/special.go
  29. 2
      protocol/rtmp/core/chunk_stream_test.go
  30. 3
      protocol/rtmp/core/conn.go
  31. 5
      protocol/rtmp/core/conn_client.go
  32. 5
      protocol/rtmp/core/conn_server.go
  33. 3
      protocol/rtmp/core/conn_test.go
  34. 15
      protocol/rtmp/rtmp.go
  35. 5
      protocol/rtmp/rtmprelay/rtmprelay.go
  36. 5
      protocol/rtmp/rtmprelay/staticrelay.go
  37. 7
      protocol/rtmp/stream.go
  38. 1
      utils/queue/queue.go
  39. 3
      utils/uid/uuid.go

27
.github/workflows/release.yml

@ -0,0 +1,27 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -0,0 +1,9 @@
{
"server": [
{
"appname": "live",
"liveon": "on",
"hlson": "on"
}
]
}

19
Dockerfile

@ -0,0 +1,19 @@ @@ -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 @@ @@ -5,23 +5,26 @@
- 支持常用的传输协议、文件格式、编码格式;
#### 支持的传输协议
- [x] RTMP
- [x] AMF
- [x] HLS
- [x] HTTP-FLV
- RTMP
- AMF
- HLS
- HTTP-FLV
#### 支持的容器格式
- [x] FLV
- [x] TS
- FLV
- TS
#### 支持的编码格式
- [x] H264
- [x] AAC
- [x] MP3
- H264
- AAC
- MP3
## 安装
直接下载编译好的[二进制文件](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`
2. 去 livego 目录中 执行 `go build`

6
av/av.go

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

6
av/rwbase.go

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

1
container/flv/demuxer.go

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

14
container/flv/muxer.go

@ -1,16 +1,17 @@ @@ -1,16 +1,17 @@
package flv
import (
"strings"
"time"
"flag"
"os"
"log"
"fmt"
"github.com/gwuhaolin/livego/utils/uid"
"github.com/gwuhaolin/livego/protocol/amf"
"log"
"os"
"strings"
"time"
"github.com/gwuhaolin/livego/av"
"github.com/gwuhaolin/livego/protocol/amf"
"github.com/gwuhaolin/livego/utils/pio"
"github.com/gwuhaolin/livego/utils/uid"
)
var (
@ -137,6 +138,7 @@ func (writer *FLVWriter) Info() (ret av.Info) { @@ -137,6 +138,7 @@ func (writer *FLVWriter) Info() (ret av.Info) {
ret.Key = writer.app + "/" + writer.title
return
}
type FlvDvr struct{}
func (f *FlvDvr) GetWriter(info av.Info) av.WriteCloser {

1
container/flv/tag.go

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

1
container/ts/muxer.go

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

1
container/ts/muxer_test.go

@ -2,6 +2,7 @@ package ts @@ -2,6 +2,7 @@ package ts
import (
"testing"
"github.com/gwuhaolin/livego/av"
"github.com/stretchr/testify/assert"
)

11
go.mod

@ -0,0 +1,11 @@ @@ -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 @@ @@ -1,11 +0,0 @@
build:
binary: livego
goos:
- windows
- darwin
- linux
- freebsd
goarch:
- amd64
- 386
- arm

10
livego.cfg

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

9
livego.go → main.go

@ -2,14 +2,15 @@ package main @@ -2,14 +2,15 @@ package main
import (
"flag"
"log"
"net"
"time"
"github.com/gwuhaolin/livego/configure"
"github.com/gwuhaolin/livego/protocol/hls"
"github.com/gwuhaolin/livego/protocol/httpflv"
"github.com/gwuhaolin/livego/protocol/httpopera"
"github.com/gwuhaolin/livego/protocol/rtmp"
"log"
"net"
"time"
)
var (
@ -18,7 +19,7 @@ var ( @@ -18,7 +19,7 @@ var (
httpFlvAddr = flag.String("httpflv-addr", ":7001", "HTTP-FLV 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")
configfilename = flag.String("cfgfile", "livego.cfg", "live configure filename")
configfilename = flag.String("cfgfile", ".livego.json", "configure filename")
)
func init() {

1
parser/aac/parser.go

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

1
parser/h264/parser_test.go

@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"testing"
"github.com/stretchr/testify/assert"
)

5
parser/parser.go

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

3
protocol/hls/hls.go

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

9
protocol/hls/source.go

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

5
protocol/httpflv/server.go

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

7
protocol/httpflv/writer.go

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

5
protocol/httpopera/http_opera.go

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

1
protocol/rtmp/cache/cache.go vendored

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

1
protocol/rtmp/cache/gop.go vendored

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

2
protocol/rtmp/cache/special.go vendored

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

2
protocol/rtmp/core/chunk_stream_test.go

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

3
protocol/rtmp/core/conn.go

@ -4,8 +4,9 @@ import ( @@ -4,8 +4,9 @@ import (
"encoding/binary"
"net"
"time"
"github.com/gwuhaolin/livego/utils/pool"
"github.com/gwuhaolin/livego/utils/pio"
"github.com/gwuhaolin/livego/utils/pool"
)
const (

5
protocol/rtmp/core/conn_client.go

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

5
protocol/rtmp/core/conn_server.go

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

3
protocol/rtmp/core/conn_test.go

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

15
protocol/rtmp/rtmp.go

@ -4,17 +4,18 @@ import ( @@ -4,17 +4,18 @@ import (
"errors"
"flag"
"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"
"net"
"net/url"
"reflect"
"strings"
"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 (
@ -286,7 +287,7 @@ func (v *VirWriter) Write(p *av.Packet) (err error) { @@ -286,7 +287,7 @@ func (v *VirWriter) Write(p *av.Packet) (err error) {
}
func (v *VirWriter) SendPacket() error {
Flush := reflect.ValueOf(v.conn).MethodByName("Flush");
Flush := reflect.ValueOf(v.conn).MethodByName("Flush")
var cs core.ChunkStream
for {
p, ok := <-v.packetQueue
@ -315,7 +316,7 @@ func (v *VirWriter) SendPacket() error { @@ -315,7 +316,7 @@ func (v *VirWriter) SendPacket() error {
v.closed = true
return err
}
Flush.Call(nil);
Flush.Call(nil)
} else {
return errors.New("closed")
}

5
protocol/rtmp/rtmprelay/rtmprelay.go

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

5
protocol/rtmp/rtmprelay/staticrelay.go

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

7
protocol/rtmp/stream.go

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

1
utils/queue/queue.go

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

3
utils/uid/uuid.go

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

Loading…
Cancel
Save