- [代码] 默认的rtmp地址

- [代码] naza 更新为 0.4.3
- [架构调整] lal 中的服务器更名为 lals
- [其他] 从远端下载 flv 测试文件,跑单元测试
- [其他] 所有源码文件添加 MIT 许可证
- [其他] test.sh 中加入更多 go tool
pull/1/head
q191201771 5 years ago
parent 7ee2aa337d
commit 17a053c3c2

3
.gitignore vendored

@ -6,9 +6,6 @@ coverage.html
/TODO.md
/SECRET.md
/conf/self.conf.json
/lal
/lal_linux
/lal.log
/tmp
/demo/

@ -33,7 +33,7 @@ Go语言编写的流媒体 库 / 客户端 / 服务端
```
app/ ......各种main包的源码文件一个子目录对应一个main包即对应可生成一个可执行文件
|-- lal/ ......[最重要的] 流媒体服务器
|-- lals/ ......[最重要的] 流媒体服务器
|-- flvfile2es ......将本地flv文件分离成h264/avc es流文件以及aac es流文件
|-- flvfile2rtmppush ......rtmp推流客户端输入是本地flv文件文件推送完毕后可循环推送rtmp push流并不断开
|-- httpflvpull ......http-flv拉流客户端
@ -43,7 +43,7 @@ pkg/ ......源码包
|-- aac/ ......音频aac编解码格式相关
|-- avc/ ......视频avc h264编解码格式相关
|-- httpflv/ ......http-flv协议
|-- logic/ ......lal服务器的上层业务
|-- logic/ ......lals服务器的上层业务
|-- rtmp/ ......rtmp协议
bin/ ......可执行文件编译输出目录
conf/ ......配置文件目录
@ -63,7 +63,7 @@ $./build.sh
$git clone https://github.com/q191201771/lal.git && cd lal && ./build.sh
# 运行
$./bin/lal -c conf/lal.conf.json
$./bin/lals -c conf/lals.conf.json
```
#### 配置文件说明
@ -108,7 +108,7 @@ $./bin/lal -c conf/lal.conf.json
**有建议、意见、bug、功能等等欢迎提 issue 啊100% 会回复的。**
lal 服务器目标版本roadmap如下
lals 服务器目标版本roadmap如下
**v1.0.0**

@ -10,12 +10,13 @@ package main
import (
"flag"
"io"
"os"
"github.com/q191201771/lal/pkg/aac"
"github.com/q191201771/lal/pkg/avc"
"github.com/q191201771/lal/pkg/httpflv"
log "github.com/q191201771/naza/pkg/nazalog"
"io"
"os"
)
func main() {

@ -11,13 +11,14 @@ package main
import (
"flag"
"fmt"
"io"
"os"
"time"
"github.com/q191201771/lal/pkg/httpflv"
"github.com/q191201771/lal/pkg/rtmp"
"github.com/q191201771/naza/pkg/bininfo"
log "github.com/q191201771/naza/pkg/nazalog"
"io"
"os"
"time"
)
//rtmp推流客户端输入是本地flv文件文件推送完毕后可循环推送rtmp push流并不断开

@ -10,9 +10,10 @@ package main
import (
"flag"
"os"
"github.com/q191201771/lal/pkg/httpflv"
log "github.com/q191201771/naza/pkg/nazalog"
"os"
)
func main() {

@ -11,14 +11,15 @@ package main
import (
"flag"
"fmt"
"github.com/q191201771/lal/pkg/logic"
"github.com/q191201771/naza/pkg/bininfo"
log "github.com/q191201771/naza/pkg/nazalog"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
"github.com/q191201771/lal/pkg/logic"
"github.com/q191201771/naza/pkg/bininfo"
log "github.com/q191201771/naza/pkg/nazalog"
)
var sm *logic.ServerManager

@ -10,10 +10,11 @@ package main
import (
"flag"
"github.com/q191201771/lal/pkg/httpflv"
log "github.com/q191201771/naza/pkg/nazalog"
"io"
"os"
"github.com/q191201771/lal/pkg/httpflv"
log "github.com/q191201771/naza/pkg/nazalog"
)
// 修改flv文件的一些信息比如某些tag的时间戳后另存文件

@ -10,11 +10,12 @@ package main
import (
"flag"
"os"
"github.com/q191201771/lal/pkg/httpflv"
"github.com/q191201771/lal/pkg/logic"
"github.com/q191201771/lal/pkg/rtmp"
log "github.com/q191201771/naza/pkg/nazalog"
"os"
)
type Obs struct {

@ -23,12 +23,12 @@ LDFlags=" \
-X 'github.com/q191201771/naza/pkg/bininfo.BuildGoVersion=${BuildGoVersion}' \
"
cd ${ROOT_DIR}/app/lal && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/bin/lal &&
cd ${ROOT_DIR}/app/lals && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/bin/lals &&
cd ${ROOT_DIR}/app/flvfile2rtmppush && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/bin/flvfile2rtmppush &&
cd ${ROOT_DIR}/app/flvfile2es && go build -o ${ROOT_DIR}/bin/flvfile2es &&
cd ${ROOT_DIR}/app/httpflvpull && go build -o ${ROOT_DIR}/bin/httpflvpull &&
cd ${ROOT_DIR}/app/modflvfile && go build -o ${ROOT_DIR}/bin/modflvfile &&
cd ${ROOT_DIR}/app/rtmppull && go build -o ${ROOT_DIR}/bin/rtmppull &&
${ROOT_DIR}/bin/lal -v &&
${ROOT_DIR}/bin/lals -v &&
ls -lrt ${ROOT_DIR}/bin &&
echo 'build done.'

@ -1,17 +0,0 @@
{
"sub_idle_timeout": 10,
"gop_cache_num": 2,
"httpflv": {
"sub_listen_addr": ":8080"
},
"rtmp": {
"addr": ":8081"
},
"pull": {
"type": "httpflv",
"addr": "xxx.pull.com",
"connect_timeout": 2,
"read_timeout": 1,
"stop_pull_while_no_sub_timeout": 3000
}
}

@ -4,7 +4,7 @@
},
"log": {
"level": 1,
"filename": "./logs/lal.log",
"filename": "./logs/lals.log",
"is_to_stdout": true,
"is_rotate_daily": true,
"short_file_flag": true

@ -2,4 +2,4 @@ module github.com/q191201771/lal
go 1.12
require github.com/q191201771/naza v0.4.0
require github.com/q191201771/naza v0.4.3

@ -1,2 +1,2 @@
github.com/q191201771/naza v0.4.0 h1:CJAZHYzQUgff7OcBRoykLY26MMRj+wP3Ed01jymXRoE=
github.com/q191201771/naza v0.4.0/go.mod h1:SE14GBGO9mAn6JZl3NlfWGtNOT7xQjxOG7f3YOdBThM=
github.com/q191201771/naza v0.4.3 h1:v7CDH3ONFyrptU8rpUeCakVdN3akxPSChHO4z3CRrAw=
github.com/q191201771/naza v0.4.3/go.mod h1:SE14GBGO9mAn6JZl3NlfWGtNOT7xQjxOG7f3YOdBThM=

@ -10,8 +10,9 @@ package aac
import (
"encoding/hex"
log "github.com/q191201771/naza/pkg/nazalog"
"io"
log "github.com/q191201771/naza/pkg/nazalog"
)
var adts ADTS

@ -10,8 +10,9 @@ package aac
import (
"bytes"
"github.com/q191201771/naza/pkg/assert"
"testing"
"github.com/q191201771/naza/pkg/assert"
)
func TestCaptureAAC(t *testing.T) {

@ -10,8 +10,9 @@ package avc
import (
"errors"
"github.com/q191201771/naza/pkg/bele"
"io"
"github.com/q191201771/naza/pkg/bele"
)
var avcErr = errors.New("avc: fxxk")

@ -10,8 +10,9 @@ package avc
import (
"bytes"
"github.com/q191201771/naza/pkg/assert"
"testing"
"github.com/q191201771/naza/pkg/assert"
)
func TestCaptureAVC(t *testing.T) {

@ -10,14 +10,15 @@ package httpflv
import (
"fmt"
"github.com/q191201771/naza/pkg/connection"
log "github.com/q191201771/naza/pkg/nazalog"
"github.com/q191201771/naza/pkg/unique"
"net"
"net/url"
"strings"
"sync"
"time"
"github.com/q191201771/naza/pkg/connection"
log "github.com/q191201771/naza/pkg/nazalog"
"github.com/q191201771/naza/pkg/unique"
)
type PullSessionConfig struct {

@ -9,9 +9,10 @@
package httpflv
import (
log "github.com/q191201771/naza/pkg/nazalog"
"net"
"sync"
log "github.com/q191201771/naza/pkg/nazalog"
)
type ServerObserver interface {

@ -10,14 +10,15 @@ package httpflv
import (
"bufio"
log "github.com/q191201771/naza/pkg/nazalog"
"github.com/q191201771/naza/pkg/unique"
"net"
url2 "net/url"
"strings"
"sync"
"sync/atomic"
"time"
log "github.com/q191201771/naza/pkg/nazalog"
"github.com/q191201771/naza/pkg/unique"
)
var flvHTTPResponseHeaderStr = "HTTP/1.1 200 OK\r\n" +

@ -9,8 +9,9 @@
package httpflv
import (
"github.com/q191201771/naza/pkg/bele"
"io"
"github.com/q191201771/naza/pkg/bele"
)
// TODO chef: make these const

@ -10,9 +10,10 @@ package logic
import (
"encoding/json"
log "github.com/q191201771/naza/pkg/nazalog"
"github.com/q191201771/naza/pkg/nazajson"
"io/ioutil"
"github.com/q191201771/naza/pkg/nazajson"
log "github.com/q191201771/naza/pkg/nazalog"
)
type Config struct {
@ -62,11 +63,14 @@ func LoadConf(confFile string) (*Config, error) {
if err != nil {
return nil, err
}
if !j.Exist("rtmp.addr") {
config.RTMP.Addr = ":1935"
}
if !j.Exist("log.level") {
config.Log.Level = log.LevelDebug
}
if !j.Exist("log.filename") {
config.Log.Filename = "./logs/lal.log"
config.Log.Filename = "./logs/lals.log"
}
if !j.Exist("log.is_to_stdout") {
config.Log.IsToStdout = true

@ -9,12 +9,13 @@
package logic
import (
"sync"
"time"
"github.com/q191201771/lal/pkg/httpflv"
"github.com/q191201771/lal/pkg/rtmp"
log "github.com/q191201771/naza/pkg/nazalog"
"github.com/q191201771/naza/pkg/unique"
"sync"
"time"
)
type Group struct {

@ -9,11 +9,12 @@
package logic
import (
"sync"
"time"
"github.com/q191201771/lal/pkg/httpflv"
"github.com/q191201771/lal/pkg/rtmp"
log "github.com/q191201771/naza/pkg/nazalog"
"sync"
"time"
)
type ServerManager struct {

@ -15,9 +15,10 @@ package rtmp
import (
"bytes"
"errors"
"io"
"github.com/q191201771/naza/pkg/bele"
log "github.com/q191201771/naza/pkg/nazalog"
"io"
)
var (

@ -10,11 +10,12 @@ package rtmp_test
import (
"bytes"
"strings"
"testing"
. "github.com/q191201771/lal/pkg/rtmp"
"github.com/q191201771/naza/pkg/assert"
"github.com/q191201771/naza/pkg/mockwriter"
"strings"
"testing"
)
func TestAmf0_WriteNumber_ReadNumber(t *testing.T) {

@ -13,9 +13,10 @@ package rtmp
// 读取chunk并组织chunk生成message返回给上层
import (
"github.com/q191201771/naza/pkg/bele"
"io"
"log"
"github.com/q191201771/naza/pkg/bele"
)
type ChunkComposer struct {

@ -11,14 +11,15 @@ package rtmp
import (
"encoding/hex"
"errors"
"github.com/q191201771/naza/pkg/bele"
"github.com/q191201771/naza/pkg/connection"
log "github.com/q191201771/naza/pkg/nazalog"
"github.com/q191201771/naza/pkg/unique"
"net"
"net/url"
"strings"
"time"
"github.com/q191201771/naza/pkg/bele"
"github.com/q191201771/naza/pkg/connection"
log "github.com/q191201771/naza/pkg/nazalog"
"github.com/q191201771/naza/pkg/unique"
)
var ErrClientSessionTimeout = errors.New("rtmp.ClientSession timeout")

@ -10,11 +10,6 @@ package rtmp_test
import (
"bytes"
"github.com/q191201771/lal/pkg/httpflv"
"github.com/q191201771/lal/pkg/logic"
"github.com/q191201771/lal/pkg/rtmp"
"github.com/q191201771/naza/pkg/assert"
log "github.com/q191201771/naza/pkg/nazalog"
"io"
"io/ioutil"
"os"
@ -22,6 +17,12 @@ import (
"sync/atomic"
"testing"
"time"
"github.com/q191201771/lal/pkg/httpflv"
"github.com/q191201771/lal/pkg/logic"
"github.com/q191201771/lal/pkg/rtmp"
"github.com/q191201771/naza/pkg/assert"
log "github.com/q191201771/naza/pkg/nazalog"
)
var (

@ -12,10 +12,11 @@ import (
"bytes"
"crypto/hmac"
"crypto/sha256"
"github.com/q191201771/naza/pkg/bele"
log "github.com/q191201771/naza/pkg/nazalog"
"io"
"time"
"github.com/q191201771/naza/pkg/bele"
log "github.com/q191201771/naza/pkg/nazalog"
)
const version = uint8(3)

@ -10,9 +10,10 @@ package rtmp_test
import (
"bytes"
"testing"
. "github.com/q191201771/lal/pkg/rtmp"
"github.com/q191201771/naza/pkg/assert"
"testing"
)
func TestHandshakeSimple(t *testing.T) {

@ -14,8 +14,9 @@ package rtmp
import (
"bytes"
"github.com/q191201771/naza/pkg/bele"
"io"
"github.com/q191201771/naza/pkg/bele"
)
const (

@ -10,9 +10,10 @@ package rtmp
import (
"bytes"
"testing"
"github.com/q191201771/naza/pkg/assert"
"github.com/q191201771/naza/pkg/mockwriter"
"testing"
)
func TestWriteMessageHandler(t *testing.T) {

@ -9,9 +9,10 @@
package rtmp
import (
log "github.com/q191201771/naza/pkg/nazalog"
"net"
"sync"
log "github.com/q191201771/naza/pkg/nazalog"
)
type ServerObserver interface {

@ -10,12 +10,13 @@ package rtmp
import (
"encoding/hex"
"net"
"strings"
"github.com/q191201771/naza/pkg/bele"
"github.com/q191201771/naza/pkg/connection"
log "github.com/q191201771/naza/pkg/nazalog"
"github.com/q191201771/naza/pkg/unique"
"net"
"strings"
)
// TODO chef: PubSession SubSession

@ -1,44 +1,38 @@
#!/usr/bin/env bash
# 在 macos 下运行 gofmt 检查
uname=$(uname)
if [[ "$uname" == "Darwin" ]]; then
echo "CHEFERASEME run gofmt check..."
gofiles=$(git diff --name-only --diff-filter=ACM | grep '.go$')
if [ ! -z "$gofiles" ]; then
#echo "CHEFERASEME mod gofiles exist:" $gofiles
unformatted=$(gofmt -l $gofiles)
if [ ! -z "$unformatted" ]; then
echo "Go files should be formatted with gofmt. Please run:"
for fn in $unformatted; do
echo " gofmt -w $PWD/$fn"
done
#exit 1
else
echo "Go files be formatted."
fi
else
echo "CHEFERASEME mod gofiles not exist."
fi
echo '-----add_go_license-----'
if command -v add_go_license >/dev/null 2>&1; then
add_go_license -d ./ -e 191201771@qq.com -n Chef
else
echo "CHEFERASEME not run gofmt check..."
echo 'CHEFNOTICEME add_go_license not exist!'
fi
echo '-----gofmt-----'
if command -v gofmt >/dev/null 2>&1; then
gofmt -l ./
gofmt -w ./
else
echo 'CHEFNOTICEME gofmt not exist!'
fi
# 跑 go test 生成测试覆盖率
if [ ! -f "pkg/rtmp/testdata/test.flv" ]; then
echo "CHEFERASEME test.flv not exist."
if [ ! -d "pkg/rtmp/testdata" ]; then
echo "CHEFERASEME mkdir."
mkdir "pkg/rtmp/testdata"
fi
wget https://pengrl.com/images/other/source.200kbps.768x320.flv -O pkg/rtmp/testdata/test.flv
echo '-----goimports-----'
if command -v goimports >/dev/null 2>&1; then
goimports -l ./
goimports -w ./
else
echo "CHEFERASEME test.flv exist."
echo 'CHEFNOTICEME goimports not exist!'
fi
echo "CHEFERASEME run coverage test..."
echo "" > coverage.txt
echo '-----go vet-----'
for d in $(go list ./... | grep -v vendor); do
if command -v go >/dev/null 2>&1; then
go vet $d
else
echo 'CHEFNOTICEME go vet not exist'
fi
done
# 跑 go test 生成测试覆盖率
echo "-----CI coverage-----"
if [ ! -f "pkg/rtmp/testdata/test.flv" ]; then
echo "CHEFERASEME test.flv not exist."
if [ ! -d "pkg/rtmp/testdata" ]; then
@ -50,13 +44,12 @@ else
echo "CHEFERASEME test.flv exist."
fi
for d in $(go list ./... | grep -v vendor | grep lal/pkg); do
echo "" > coverage.txt
for d in $(go list ./... | grep -v vendor | grep pkg); do
go test -race -coverprofile=profile.out -covermode=atomic $d
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
done
# go test -race -coverprofile=profile.out -covermode=atomic && go tool cover -html=profile.out -o coverage.html && open coverage.html
# go test -test.bench=".*"
echo 'done.'

Loading…
Cancel
Save